From d4fd4e182178a9d3c65c383090cc21995421dc9e Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 24 Oct 2019 07:55:29 +0100 Subject: [PATCH] Remove built assets from repo --- assets/scripts/choices.js | 6164 --------------------------------- assets/scripts/choices.min.js | 52 - assets/styles/base.css | 190 - assets/styles/base.min.css | 1 - assets/styles/choices.css | 367 -- assets/styles/choices.min.css | 1 - 6 files changed, 6775 deletions(-) delete mode 100644 assets/scripts/choices.js delete mode 100644 assets/scripts/choices.min.js delete mode 100644 assets/styles/base.css delete mode 100644 assets/styles/base.min.css delete mode 100644 assets/styles/choices.css delete mode 100644 assets/styles/choices.min.css diff --git a/assets/scripts/choices.js b/assets/scripts/choices.js deleted file mode 100644 index f106c91d..00000000 --- a/assets/scripts/choices.js +++ /dev/null @@ -1,6164 +0,0 @@ -/*! choices.js v7.1.1 | © 2019 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ -(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["Choices"] = factory(); - else - root["Choices"] = factory(); -})(window, 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 = "/public/assets/scripts/"; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 5); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports, __webpack_require__) { - -var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - Copyright (c) 2017 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/ -/* global define */ - -(function () { - 'use strict'; - - var hasOwn = {}.hasOwnProperty; - - function classNames () { - var classes = []; - - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; - if (!arg) continue; - - var argType = typeof arg; - - if (argType === 'string' || argType === 'number') { - classes.push(arg); - } else if (Array.isArray(arg) && arg.length) { - var inner = classNames.apply(null, arg); - if (inner) { - classes.push(inner); - } - } else if (argType === 'object') { - for (var key in arg) { - if (hasOwn.call(arg, key) && arg[key]) { - classes.push(key); - } - } - } - } - - return classes.join(' '); - } - - if ( true && module.exports) { - classNames.default = classNames; - module.exports = classNames; - } else if (true) { - // register as 'classnames', consistent with npm package name - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { - return classNames; - }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), - __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - } else {} -}()); - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -var isMergeableObject = function isMergeableObject(value) { - return isNonNullObject(value) - && !isSpecial(value) -}; - -function isNonNullObject(value) { - return !!value && typeof value === 'object' -} - -function isSpecial(value) { - var stringValue = Object.prototype.toString.call(value); - - return stringValue === '[object RegExp]' - || stringValue === '[object Date]' - || isReactElement(value) -} - -// see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25 -var canUseSymbol = typeof Symbol === 'function' && Symbol.for; -var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7; - -function isReactElement(value) { - return value.$$typeof === REACT_ELEMENT_TYPE -} - -function emptyTarget(val) { - return Array.isArray(val) ? [] : {} -} - -function cloneUnlessOtherwiseSpecified(value, options) { - return (options.clone !== false && options.isMergeableObject(value)) - ? deepmerge(emptyTarget(value), value, options) - : value -} - -function defaultArrayMerge(target, source, options) { - return target.concat(source).map(function(element) { - return cloneUnlessOtherwiseSpecified(element, options) - }) -} - -function getMergeFunction(key, options) { - if (!options.customMerge) { - return deepmerge - } - var customMerge = options.customMerge(key); - return typeof customMerge === 'function' ? customMerge : deepmerge -} - -function getEnumerableOwnPropertySymbols(target) { - return Object.getOwnPropertySymbols - ? Object.getOwnPropertySymbols(target).filter(function(symbol) { - return target.propertyIsEnumerable(symbol) - }) - : [] -} - -function getKeys(target) { - return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) -} - -// Protects from prototype poisoning and unexpected merging up the prototype chain. -function propertyIsUnsafe(target, key) { - try { - return (key in target) // Properties are safe to merge if they don't exist in the target yet, - && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain, - && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable. - } catch (unused) { - // Counterintuitively, it's safe to merge any property on a target that causes the `in` operator to throw. - // This happens when trying to copy an object in the source over a plain string in the target. - return false - } -} - -function mergeObject(target, source, options) { - var destination = {}; - if (options.isMergeableObject(target)) { - getKeys(target).forEach(function(key) { - destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); - }); - } - getKeys(source).forEach(function(key) { - if (propertyIsUnsafe(target, key)) { - return - } - - if (!options.isMergeableObject(source[key]) || !target[key]) { - destination[key] = cloneUnlessOtherwiseSpecified(source[key], options); - } else { - destination[key] = getMergeFunction(key, options)(target[key], source[key], options); - } - }); - return destination -} - -function deepmerge(target, source, options) { - options = options || {}; - options.arrayMerge = options.arrayMerge || defaultArrayMerge; - options.isMergeableObject = options.isMergeableObject || isMergeableObject; - // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() - // implementations can use it. The caller may not replace it. - options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; - - var sourceIsArray = Array.isArray(source); - var targetIsArray = Array.isArray(target); - var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; - - if (!sourceAndTargetTypesMatch) { - return cloneUnlessOtherwiseSpecified(source, options) - } else if (sourceIsArray) { - return options.arrayMerge(target, source, options) - } else { - return mergeObject(target, source, options) - } -} - -deepmerge.all = function deepmergeAll(array, options) { - if (!Array.isArray(array)) { - throw new Error('first argument should be an array') - } - - return array.reduce(function(prev, next) { - return deepmerge(prev, next, options) - }, {}) -}; - -var deepmerge_1 = deepmerge; - -module.exports = deepmerge_1; - - -/***/ }), -/* 2 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* WEBPACK VAR INJECTION */(function(global, module) {/* harmony import */ var _ponyfill_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); -/* global window */ - - -var root; - -if (typeof self !== 'undefined') { - root = self; -} else if (typeof window !== 'undefined') { - root = window; -} else if (typeof global !== 'undefined') { - root = global; -} else if (true) { - root = module; -} else {} - -var result = Object(_ponyfill_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(root); -/* harmony default export */ __webpack_exports__["a"] = (result); - -/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(7), __webpack_require__(8)(module))) - -/***/ }), -/* 3 */ -/***/ (function(module, exports, __webpack_require__) { - -/*! - * Fuse.js v3.4.2 - Lightweight fuzzy-search (http://fusejs.io) - * - * Copyright (c) 2012-2017 Kirollos Risk (http://kiro.me) - * All Rights Reserved. Apache Software License 2.0 - * - * http://www.apache.org/licenses/LICENSE-2.0 - */ -(function webpackUniversalModuleDefinition(root, factory) { - if(true) - module.exports = factory(); - else {} -})(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 = "./src/index.js"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./src/bitap/bitap_matched_indices.js": -/*!********************************************!*\ - !*** ./src/bitap/bitap_matched_indices.js ***! - \********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = function () { - var matchmask = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var minMatchCharLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; - var matchedIndices = []; - var start = -1; - var end = -1; - var i = 0; - - for (var len = matchmask.length; i < len; i += 1) { - var match = matchmask[i]; - - if (match && start === -1) { - start = i; - } else if (!match && start !== -1) { - end = i - 1; - - if (end - start + 1 >= minMatchCharLength) { - matchedIndices.push([start, end]); - } - - start = -1; - } - } // (i-1 - start) + 1 => i - start - - - if (matchmask[i - 1] && i - start >= minMatchCharLength) { - matchedIndices.push([start, i - 1]); - } - - return matchedIndices; -}; - -/***/ }), - -/***/ "./src/bitap/bitap_pattern_alphabet.js": -/*!*********************************************!*\ - !*** ./src/bitap/bitap_pattern_alphabet.js ***! - \*********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = function (pattern) { - var mask = {}; - var len = pattern.length; - - for (var i = 0; i < len; i += 1) { - mask[pattern.charAt(i)] = 0; - } - - for (var _i = 0; _i < len; _i += 1) { - mask[pattern.charAt(_i)] |= 1 << len - _i - 1; - } - - return mask; -}; - -/***/ }), - -/***/ "./src/bitap/bitap_regex_search.js": -/*!*****************************************!*\ - !*** ./src/bitap/bitap_regex_search.js ***! - \*****************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -var SPECIAL_CHARS_REGEX = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g; - -module.exports = function (text, pattern) { - var tokenSeparator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : / +/g; - var regex = new RegExp(pattern.replace(SPECIAL_CHARS_REGEX, '\\$&').replace(tokenSeparator, '|')); - var matches = text.match(regex); - var isMatch = !!matches; - var matchedIndices = []; - - if (isMatch) { - for (var i = 0, matchesLen = matches.length; i < matchesLen; i += 1) { - var match = matches[i]; - matchedIndices.push([text.indexOf(match), match.length - 1]); - } - } - - return { - // TODO: revisit this score - score: isMatch ? 0.5 : 1, - isMatch: isMatch, - matchedIndices: matchedIndices - }; -}; - -/***/ }), - -/***/ "./src/bitap/bitap_score.js": -/*!**********************************!*\ - !*** ./src/bitap/bitap_score.js ***! - \**********************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = function (pattern, _ref) { - var _ref$errors = _ref.errors, - errors = _ref$errors === void 0 ? 0 : _ref$errors, - _ref$currentLocation = _ref.currentLocation, - currentLocation = _ref$currentLocation === void 0 ? 0 : _ref$currentLocation, - _ref$expectedLocation = _ref.expectedLocation, - expectedLocation = _ref$expectedLocation === void 0 ? 0 : _ref$expectedLocation, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance; - var accuracy = errors / pattern.length; - var proximity = Math.abs(expectedLocation - currentLocation); - - if (!distance) { - // Dodge divide by zero error. - return proximity ? 1.0 : accuracy; - } - - return accuracy + proximity / distance; -}; - -/***/ }), - -/***/ "./src/bitap/bitap_search.js": -/*!***********************************!*\ - !*** ./src/bitap/bitap_search.js ***! - \***********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -var bitapScore = __webpack_require__(/*! ./bitap_score */ "./src/bitap/bitap_score.js"); - -var matchedIndices = __webpack_require__(/*! ./bitap_matched_indices */ "./src/bitap/bitap_matched_indices.js"); - -module.exports = function (text, pattern, patternAlphabet, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng; - var expectedLocation = location; // Set starting location at beginning text and initialize the alphabet. - - var textLen = text.length; // Highest score beyond which we give up. - - var currentThreshold = threshold; // Is there a nearby exact match? (speedup) - - var bestLocation = text.indexOf(pattern, expectedLocation); - var patternLen = pattern.length; // a mask of the matches - - var matchMask = []; - - for (var i = 0; i < textLen; i += 1) { - matchMask[i] = 0; - } - - if (bestLocation !== -1) { - var score = bitapScore(pattern, { - errors: 0, - currentLocation: bestLocation, - expectedLocation: expectedLocation, - distance: distance - }); - currentThreshold = Math.min(score, currentThreshold); // What about in the other direction? (speed up) - - bestLocation = text.lastIndexOf(pattern, expectedLocation + patternLen); - - if (bestLocation !== -1) { - var _score = bitapScore(pattern, { - errors: 0, - currentLocation: bestLocation, - expectedLocation: expectedLocation, - distance: distance - }); - - currentThreshold = Math.min(_score, currentThreshold); - } - } // Reset the best location - - - bestLocation = -1; - var lastBitArr = []; - var finalScore = 1; - var binMax = patternLen + textLen; - var mask = 1 << patternLen - 1; - - for (var _i = 0; _i < patternLen; _i += 1) { - // Scan for the best match; each iteration allows for one more error. - // Run a binary search to determine how far from the match location we can stray - // at this error level. - var binMin = 0; - var binMid = binMax; - - while (binMin < binMid) { - var _score3 = bitapScore(pattern, { - errors: _i, - currentLocation: expectedLocation + binMid, - expectedLocation: expectedLocation, - distance: distance - }); - - if (_score3 <= currentThreshold) { - binMin = binMid; - } else { - binMax = binMid; - } - - binMid = Math.floor((binMax - binMin) / 2 + binMin); - } // Use the result from this iteration as the maximum for the next. - - - binMax = binMid; - var start = Math.max(1, expectedLocation - binMid + 1); - var finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen; // Initialize the bit array - - var bitArr = Array(finish + 2); - bitArr[finish + 1] = (1 << _i) - 1; - - for (var j = finish; j >= start; j -= 1) { - var currentLocation = j - 1; - var charMatch = patternAlphabet[text.charAt(currentLocation)]; - - if (charMatch) { - matchMask[currentLocation] = 1; - } // First pass: exact match - - - bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch; // Subsequent passes: fuzzy match - - if (_i !== 0) { - bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1]; - } - - if (bitArr[j] & mask) { - finalScore = bitapScore(pattern, { - errors: _i, - currentLocation: currentLocation, - expectedLocation: expectedLocation, - distance: distance - }); // This match will almost certainly be better than any existing match. - // But check anyway. - - if (finalScore <= currentThreshold) { - // Indeed it is - currentThreshold = finalScore; - bestLocation = currentLocation; // Already passed `loc`, downhill from here on in. - - if (bestLocation <= expectedLocation) { - break; - } // When passing `bestLocation`, don't exceed our current distance from `expectedLocation`. - - - start = Math.max(1, 2 * expectedLocation - bestLocation); - } - } - } // No hope for a (better) match at greater error levels. - - - var _score2 = bitapScore(pattern, { - errors: _i + 1, - currentLocation: expectedLocation, - expectedLocation: expectedLocation, - distance: distance - }); // console.log('score', score, finalScore) - - - if (_score2 > currentThreshold) { - break; - } - - lastBitArr = bitArr; - } // console.log('FINAL SCORE', finalScore) - // Count exact matches (those with a score of 0) to be "almost" exact - - - return { - isMatch: bestLocation >= 0, - score: finalScore === 0 ? 0.001 : finalScore, - matchedIndices: matchedIndices(matchMask, minMatchCharLength) - }; -}; - -/***/ }), - -/***/ "./src/bitap/index.js": -/*!****************************!*\ - !*** ./src/bitap/index.js ***! - \****************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var bitapRegexSearch = __webpack_require__(/*! ./bitap_regex_search */ "./src/bitap/bitap_regex_search.js"); - -var bitapSearch = __webpack_require__(/*! ./bitap_search */ "./src/bitap/bitap_search.js"); - -var patternAlphabet = __webpack_require__(/*! ./bitap_pattern_alphabet */ "./src/bitap/bitap_pattern_alphabet.js"); - -var Bitap = -/*#__PURE__*/ -function () { - function Bitap(pattern, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$maxPatternLength = _ref.maxPatternLength, - maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength, - _ref$isCaseSensitive = _ref.isCaseSensitive, - isCaseSensitive = _ref$isCaseSensitive === void 0 ? false : _ref$isCaseSensitive, - _ref$tokenSeparator = _ref.tokenSeparator, - tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng; - - _classCallCheck(this, Bitap); - - this.options = { - location: location, - distance: distance, - threshold: threshold, - maxPatternLength: maxPatternLength, - isCaseSensitive: isCaseSensitive, - tokenSeparator: tokenSeparator, - findAllMatches: findAllMatches, - minMatchCharLength: minMatchCharLength - }; - this.pattern = this.options.isCaseSensitive ? pattern : pattern.toLowerCase(); - - if (this.pattern.length <= maxPatternLength) { - this.patternAlphabet = patternAlphabet(this.pattern); - } - } - - _createClass(Bitap, [{ - key: "search", - value: function search(text) { - if (!this.options.isCaseSensitive) { - text = text.toLowerCase(); - } // Exact match - - - if (this.pattern === text) { - return { - isMatch: true, - score: 0, - matchedIndices: [[0, text.length - 1]] - }; - } // When pattern length is greater than the machine word length, just do a a regex comparison - - - var _this$options = this.options, - maxPatternLength = _this$options.maxPatternLength, - tokenSeparator = _this$options.tokenSeparator; - - if (this.pattern.length > maxPatternLength) { - return bitapRegexSearch(text, this.pattern, tokenSeparator); - } // Otherwise, use Bitap algorithm - - - var _this$options2 = this.options, - location = _this$options2.location, - distance = _this$options2.distance, - threshold = _this$options2.threshold, - findAllMatches = _this$options2.findAllMatches, - minMatchCharLength = _this$options2.minMatchCharLength; - return bitapSearch(text, this.pattern, this.patternAlphabet, { - location: location, - distance: distance, - threshold: threshold, - findAllMatches: findAllMatches, - minMatchCharLength: minMatchCharLength - }); - } - }]); - - return Bitap; -}(); // let x = new Bitap("od mn war", {}) -// let result = x.search("Old Man's War") -// console.log(result) - - -module.exports = Bitap; - -/***/ }), - -/***/ "./src/helpers/deep_value.js": -/*!***********************************!*\ - !*** ./src/helpers/deep_value.js ***! - \***********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -var isArray = __webpack_require__(/*! ./is_array */ "./src/helpers/is_array.js"); - -var deepValue = function deepValue(obj, path, list) { - if (!path) { - // If there's no path left, we've gotten to the object we care about. - list.push(obj); - } else { - var dotIndex = path.indexOf('.'); - var firstSegment = path; - var remaining = null; - - if (dotIndex !== -1) { - firstSegment = path.slice(0, dotIndex); - remaining = path.slice(dotIndex + 1); - } - - var value = obj[firstSegment]; - - if (value !== null && value !== undefined) { - if (!remaining && (typeof value === 'string' || typeof value === 'number')) { - list.push(value.toString()); - } else if (isArray(value)) { - // Search each item in the array. - for (var i = 0, len = value.length; i < len; i += 1) { - deepValue(value[i], remaining, list); - } - } else if (remaining) { - // An object. Recurse further. - deepValue(value, remaining, list); - } - } - } - - return list; -}; - -module.exports = function (obj, path) { - return deepValue(obj, path, []); -}; - -/***/ }), - -/***/ "./src/helpers/is_array.js": -/*!*********************************!*\ - !*** ./src/helpers/is_array.js ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -module.exports = function (obj) { - return !Array.isArray ? Object.prototype.toString.call(obj) === '[object Array]' : Array.isArray(obj); -}; - -/***/ }), - -/***/ "./src/index.js": -/*!**********************!*\ - !*** ./src/index.js ***! - \**********************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - -var Bitap = __webpack_require__(/*! ./bitap */ "./src/bitap/index.js"); - -var deepValue = __webpack_require__(/*! ./helpers/deep_value */ "./src/helpers/deep_value.js"); - -var isArray = __webpack_require__(/*! ./helpers/is_array */ "./src/helpers/is_array.js"); - -var Fuse = -/*#__PURE__*/ -function () { - function Fuse(list, _ref) { - var _ref$location = _ref.location, - location = _ref$location === void 0 ? 0 : _ref$location, - _ref$distance = _ref.distance, - distance = _ref$distance === void 0 ? 100 : _ref$distance, - _ref$threshold = _ref.threshold, - threshold = _ref$threshold === void 0 ? 0.6 : _ref$threshold, - _ref$maxPatternLength = _ref.maxPatternLength, - maxPatternLength = _ref$maxPatternLength === void 0 ? 32 : _ref$maxPatternLength, - _ref$caseSensitive = _ref.caseSensitive, - caseSensitive = _ref$caseSensitive === void 0 ? false : _ref$caseSensitive, - _ref$tokenSeparator = _ref.tokenSeparator, - tokenSeparator = _ref$tokenSeparator === void 0 ? / +/g : _ref$tokenSeparator, - _ref$findAllMatches = _ref.findAllMatches, - findAllMatches = _ref$findAllMatches === void 0 ? false : _ref$findAllMatches, - _ref$minMatchCharLeng = _ref.minMatchCharLength, - minMatchCharLength = _ref$minMatchCharLeng === void 0 ? 1 : _ref$minMatchCharLeng, - _ref$id = _ref.id, - id = _ref$id === void 0 ? null : _ref$id, - _ref$keys = _ref.keys, - keys = _ref$keys === void 0 ? [] : _ref$keys, - _ref$shouldSort = _ref.shouldSort, - shouldSort = _ref$shouldSort === void 0 ? true : _ref$shouldSort, - _ref$getFn = _ref.getFn, - getFn = _ref$getFn === void 0 ? deepValue : _ref$getFn, - _ref$sortFn = _ref.sortFn, - sortFn = _ref$sortFn === void 0 ? function (a, b) { - return a.score - b.score; - } : _ref$sortFn, - _ref$tokenize = _ref.tokenize, - tokenize = _ref$tokenize === void 0 ? false : _ref$tokenize, - _ref$matchAllTokens = _ref.matchAllTokens, - matchAllTokens = _ref$matchAllTokens === void 0 ? false : _ref$matchAllTokens, - _ref$includeMatches = _ref.includeMatches, - includeMatches = _ref$includeMatches === void 0 ? false : _ref$includeMatches, - _ref$includeScore = _ref.includeScore, - includeScore = _ref$includeScore === void 0 ? false : _ref$includeScore, - _ref$verbose = _ref.verbose, - verbose = _ref$verbose === void 0 ? false : _ref$verbose; - - _classCallCheck(this, Fuse); - - this.options = { - location: location, - distance: distance, - threshold: threshold, - maxPatternLength: maxPatternLength, - isCaseSensitive: caseSensitive, - tokenSeparator: tokenSeparator, - findAllMatches: findAllMatches, - minMatchCharLength: minMatchCharLength, - id: id, - keys: keys, - includeMatches: includeMatches, - includeScore: includeScore, - shouldSort: shouldSort, - getFn: getFn, - sortFn: sortFn, - verbose: verbose, - tokenize: tokenize, - matchAllTokens: matchAllTokens - }; - this.setCollection(list); - } - - _createClass(Fuse, [{ - key: "setCollection", - value: function setCollection(list) { - this.list = list; - return list; - } - }, { - key: "search", - value: function search(pattern) { - var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { - limit: false - }; - - this._log("---------\nSearch pattern: \"".concat(pattern, "\"")); - - var _this$_prepareSearche = this._prepareSearchers(pattern), - tokenSearchers = _this$_prepareSearche.tokenSearchers, - fullSearcher = _this$_prepareSearche.fullSearcher; - - var _this$_search = this._search(tokenSearchers, fullSearcher), - weights = _this$_search.weights, - results = _this$_search.results; - - this._computeScore(weights, results); - - if (this.options.shouldSort) { - this._sort(results); - } - - if (opts.limit && typeof opts.limit === 'number') { - results = results.slice(0, opts.limit); - } - - return this._format(results); - } - }, { - key: "_prepareSearchers", - value: function _prepareSearchers() { - var pattern = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; - var tokenSearchers = []; - - if (this.options.tokenize) { - // Tokenize on the separator - var tokens = pattern.split(this.options.tokenSeparator); - - for (var i = 0, len = tokens.length; i < len; i += 1) { - tokenSearchers.push(new Bitap(tokens[i], this.options)); - } - } - - var fullSearcher = new Bitap(pattern, this.options); - return { - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }; - } - }, { - key: "_search", - value: function _search() { - var tokenSearchers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var fullSearcher = arguments.length > 1 ? arguments[1] : undefined; - var list = this.list; - var resultMap = {}; - var results = []; // Check the first item in the list, if it's a string, then we assume - // that every item in the list is also a string, and thus it's a flattened array. - - if (typeof list[0] === 'string') { - // Iterate over every item - for (var i = 0, len = list.length; i < len; i += 1) { - this._analyze({ - key: '', - value: list[i], - record: i, - index: i - }, { - resultMap: resultMap, - results: results, - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }); - } - - return { - weights: null, - results: results - }; - } // Otherwise, the first item is an Object (hopefully), and thus the searching - // is done on the values of the keys of each item. - - - var weights = {}; - - for (var _i = 0, _len = list.length; _i < _len; _i += 1) { - var item = list[_i]; // Iterate over every key - - for (var j = 0, keysLen = this.options.keys.length; j < keysLen; j += 1) { - var key = this.options.keys[j]; - - if (typeof key !== 'string') { - weights[key.name] = { - weight: 1 - key.weight || 1 - }; - - if (key.weight <= 0 || key.weight > 1) { - throw new Error('Key weight has to be > 0 and <= 1'); - } - - key = key.name; - } else { - weights[key] = { - weight: 1 - }; - } - - this._analyze({ - key: key, - value: this.options.getFn(item, key), - record: item, - index: _i - }, { - resultMap: resultMap, - results: results, - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }); - } - } - - return { - weights: weights, - results: results - }; - } - }, { - key: "_analyze", - value: function _analyze(_ref2, _ref3) { - var key = _ref2.key, - _ref2$arrayIndex = _ref2.arrayIndex, - arrayIndex = _ref2$arrayIndex === void 0 ? -1 : _ref2$arrayIndex, - value = _ref2.value, - record = _ref2.record, - index = _ref2.index; - var _ref3$tokenSearchers = _ref3.tokenSearchers, - tokenSearchers = _ref3$tokenSearchers === void 0 ? [] : _ref3$tokenSearchers, - _ref3$fullSearcher = _ref3.fullSearcher, - fullSearcher = _ref3$fullSearcher === void 0 ? [] : _ref3$fullSearcher, - _ref3$resultMap = _ref3.resultMap, - resultMap = _ref3$resultMap === void 0 ? {} : _ref3$resultMap, - _ref3$results = _ref3.results, - results = _ref3$results === void 0 ? [] : _ref3$results; - - // Check if the texvaluet can be searched - if (value === undefined || value === null) { - return; - } - - var exists = false; - var averageScore = -1; - var numTextMatches = 0; - - if (typeof value === 'string') { - this._log("\nKey: ".concat(key === '' ? '-' : key)); - - var mainSearchResult = fullSearcher.search(value); - - this._log("Full text: \"".concat(value, "\", score: ").concat(mainSearchResult.score)); - - if (this.options.tokenize) { - var words = value.split(this.options.tokenSeparator); - var scores = []; - - for (var i = 0; i < tokenSearchers.length; i += 1) { - var tokenSearcher = tokenSearchers[i]; - - this._log("\nPattern: \"".concat(tokenSearcher.pattern, "\"")); // let tokenScores = [] - - - var hasMatchInText = false; - - for (var j = 0; j < words.length; j += 1) { - var word = words[j]; - var tokenSearchResult = tokenSearcher.search(word); - var obj = {}; - - if (tokenSearchResult.isMatch) { - obj[word] = tokenSearchResult.score; - exists = true; - hasMatchInText = true; - scores.push(tokenSearchResult.score); - } else { - obj[word] = 1; - - if (!this.options.matchAllTokens) { - scores.push(1); - } - } - - this._log("Token: \"".concat(word, "\", score: ").concat(obj[word])); // tokenScores.push(obj) - - } - - if (hasMatchInText) { - numTextMatches += 1; - } - } - - averageScore = scores[0]; - var scoresLen = scores.length; - - for (var _i2 = 1; _i2 < scoresLen; _i2 += 1) { - averageScore += scores[_i2]; - } - - averageScore = averageScore / scoresLen; - - this._log('Token score average:', averageScore); - } - - var finalScore = mainSearchResult.score; - - if (averageScore > -1) { - finalScore = (finalScore + averageScore) / 2; - } - - this._log('Score average:', finalScore); - - var checkTextMatches = this.options.tokenize && this.options.matchAllTokens ? numTextMatches >= tokenSearchers.length : true; - - this._log("\nCheck Matches: ".concat(checkTextMatches)); // If a match is found, add the item to , including its score - - - if ((exists || mainSearchResult.isMatch) && checkTextMatches) { - // Check if the item already exists in our results - var existingResult = resultMap[index]; - - if (existingResult) { - // Use the lowest score - // existingResult.score, bitapResult.score - existingResult.output.push({ - key: key, - arrayIndex: arrayIndex, - value: value, - score: finalScore, - matchedIndices: mainSearchResult.matchedIndices - }); - } else { - // Add it to the raw result list - resultMap[index] = { - item: record, - output: [{ - key: key, - arrayIndex: arrayIndex, - value: value, - score: finalScore, - matchedIndices: mainSearchResult.matchedIndices - }] - }; - results.push(resultMap[index]); - } - } - } else if (isArray(value)) { - for (var _i3 = 0, len = value.length; _i3 < len; _i3 += 1) { - this._analyze({ - key: key, - arrayIndex: _i3, - value: value[_i3], - record: record, - index: index - }, { - resultMap: resultMap, - results: results, - tokenSearchers: tokenSearchers, - fullSearcher: fullSearcher - }); - } - } - } - }, { - key: "_computeScore", - value: function _computeScore(weights, results) { - this._log('\n\nComputing score:\n'); - - for (var i = 0, len = results.length; i < len; i += 1) { - var output = results[i].output; - var scoreLen = output.length; - var currScore = 1; - var bestScore = 1; - - for (var j = 0; j < scoreLen; j += 1) { - var weight = weights ? weights[output[j].key].weight : 1; - var score = weight === 1 ? output[j].score : output[j].score || 0.001; - var nScore = score * weight; - - if (weight !== 1) { - bestScore = Math.min(bestScore, nScore); - } else { - output[j].nScore = nScore; - currScore *= nScore; - } - } - - results[i].score = bestScore === 1 ? currScore : bestScore; - - this._log(results[i]); - } - } - }, { - key: "_sort", - value: function _sort(results) { - this._log('\n\nSorting....'); - - results.sort(this.options.sortFn); - } - }, { - key: "_format", - value: function _format(results) { - var finalOutput = []; - - if (this.options.verbose) { - var cache = []; - - this._log('\n\nOutput:\n\n', JSON.stringify(results, function (key, value) { - if (_typeof(value) === 'object' && value !== null) { - if (cache.indexOf(value) !== -1) { - // Circular reference found, discard key - return; - } // Store value in our collection - - - cache.push(value); - } - - return value; - })); - - cache = null; - } - - var transformers = []; - - if (this.options.includeMatches) { - transformers.push(function (result, data) { - var output = result.output; - data.matches = []; - - for (var i = 0, len = output.length; i < len; i += 1) { - var item = output[i]; - - if (item.matchedIndices.length === 0) { - continue; - } - - var obj = { - indices: item.matchedIndices, - value: item.value - }; - - if (item.key) { - obj.key = item.key; - } - - if (item.hasOwnProperty('arrayIndex') && item.arrayIndex > -1) { - obj.arrayIndex = item.arrayIndex; - } - - data.matches.push(obj); - } - }); - } - - if (this.options.includeScore) { - transformers.push(function (result, data) { - data.score = result.score; - }); - } - - for (var i = 0, len = results.length; i < len; i += 1) { - var result = results[i]; - - if (this.options.id) { - result.item = this.options.getFn(result.item, this.options.id)[0]; - } - - if (!transformers.length) { - finalOutput.push(result.item); - continue; - } - - var data = { - item: result.item - }; - - for (var j = 0, _len2 = transformers.length; j < _len2; j += 1) { - transformers[j](result, data); - } - - finalOutput.push(data); - } - - return finalOutput; - } - }, { - key: "_log", - value: function _log() { - if (this.options.verbose) { - var _console; - - (_console = console).log.apply(_console, arguments); - } - } - }]); - - return Fuse; -}(); - -module.exports = Fuse; - -/***/ }) - -/******/ }); -}); - -/***/ }), -/* 4 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return symbolObservablePonyfill; }); -function symbolObservablePonyfill(root) { - var result; - var Symbol = root.Symbol; - - if (typeof Symbol === 'function') { - if (Symbol.observable) { - result = Symbol.observable; - } else { - result = Symbol('observable'); - Symbol.observable = result; - } - } else { - result = '@@observable'; - } - - return result; -}; - - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { - -module.exports = __webpack_require__(9); - - -/***/ }), -/* 6 */ -/***/ (function(module, exports) { - -window.delegateEvent = function delegateEvent() { - var events; - var addedListenerTypes; - - if (typeof events === 'undefined') { - events = new Map(); - } - - if (typeof addedListenerTypes === 'undefined') { - addedListenerTypes = []; - } - - function _callback(event) { - var type = events.get(event.type); - if (!type) return; - type.forEach(function (fn) { - return fn(event); - }); - } - - return { - add: function add(type, fn) { - // Cache list of events. - if (events.has(type)) { - events.get(type).push(fn); - } else { - events.set(type, [fn]); - } // Setup events. - - - if (addedListenerTypes.indexOf(type) === -1) { - document.documentElement.addEventListener(type, _callback, true); - addedListenerTypes.push(type); - } - }, - remove: function remove(type, fn) { - if (!events.get(type)) return; - events.set(type, events.get(type).filter(function (item) { - return item !== fn; - })); - - if (!events.get(type).length) { - addedListenerTypes.splice(addedListenerTypes.indexOf(type), 1); - } - } - }; -}(); - -/***/ }), -/* 7 */ -/***/ (function(module, exports) { - -var g; - -// This works in non-strict mode -g = (function() { - return this; -})(); - -try { - // This works if eval is allowed (see CSP) - g = g || new Function("return this")(); -} catch (e) { - // This works if the window reference is available - if (typeof window === "object") g = window; -} - -// g can still be undefined, but nothing to do about it... -// We return undefined, instead of nothing here, so it's -// easier to handle this case. if(!global) { ...} - -module.exports = g; - - -/***/ }), -/* 8 */ -/***/ (function(module, exports) { - -module.exports = function(originalModule) { - if (!originalModule.webpackPolyfill) { - var module = Object.create(originalModule); - // module.parent = undefined by default - if (!module.children) module.children = []; - Object.defineProperty(module, "loaded", { - enumerable: true, - get: function() { - return module.l; - } - }); - Object.defineProperty(module, "id", { - enumerable: true, - get: function() { - return module.i; - } - }); - Object.defineProperty(module, "exports", { - enumerable: true - }); - module.webpackPolyfill = 1; - } - return module; -}; - - -/***/ }), -/* 9 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); - -// EXTERNAL MODULE: ./node_modules/fuse.js/dist/fuse.js -var dist_fuse = __webpack_require__(3); -var fuse_default = /*#__PURE__*/__webpack_require__.n(dist_fuse); - -// EXTERNAL MODULE: ./node_modules/deepmerge/dist/cjs.js -var cjs = __webpack_require__(1); -var cjs_default = /*#__PURE__*/__webpack_require__.n(cjs); - -// EXTERNAL MODULE: ./src/scripts/lib/delegate-events.js -var delegate_events = __webpack_require__(6); - -// EXTERNAL MODULE: ./node_modules/symbol-observable/es/index.js -var es = __webpack_require__(2); - -// CONCATENATED MODULE: ./node_modules/redux/es/redux.js - - -/** - * These are private action types reserved by Redux. - * For any unknown actions, you must return the current state. - * If the current state is undefined, you must return the initial state. - * Do not reference these action types directly in your code. - */ -var randomString = function randomString() { - return Math.random().toString(36).substring(7).split('').join('.'); -}; - -var ActionTypes = { - INIT: "@@redux/INIT" + randomString(), - REPLACE: "@@redux/REPLACE" + randomString(), - PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { - return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); - } -}; - -/** - * @param {any} obj The object to inspect. - * @returns {boolean} True if the argument appears to be a plain object. - */ -function isPlainObject(obj) { - if (typeof obj !== 'object' || obj === null) return false; - var proto = obj; - - while (Object.getPrototypeOf(proto) !== null) { - proto = Object.getPrototypeOf(proto); - } - - return Object.getPrototypeOf(obj) === proto; -} - -/** - * Creates a Redux store that holds the state tree. - * The only way to change the data in the store is to call `dispatch()` on it. - * - * There should only be a single store in your app. To specify how different - * parts of the state tree respond to actions, you may combine several reducers - * into a single reducer function by using `combineReducers`. - * - * @param {Function} reducer A function that returns the next state tree, given - * the current state tree and the action to handle. - * - * @param {any} [preloadedState] The initial state. You may optionally specify it - * to hydrate the state from the server in universal apps, or to restore a - * previously serialized user session. - * If you use `combineReducers` to produce the root reducer function, this must be - * an object with the same shape as `combineReducers` keys. - * - * @param {Function} [enhancer] The store enhancer. You may optionally specify it - * to enhance the store with third-party capabilities such as middleware, - * time travel, persistence, etc. The only store enhancer that ships with Redux - * is `applyMiddleware()`. - * - * @returns {Store} A Redux store that lets you read the state, dispatch actions - * and subscribe to changes. - */ - -function createStore(reducer, preloadedState, enhancer) { - var _ref2; - - if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { - throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function.'); - } - - if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { - enhancer = preloadedState; - preloadedState = undefined; - } - - if (typeof enhancer !== 'undefined') { - if (typeof enhancer !== 'function') { - throw new Error('Expected the enhancer to be a function.'); - } - - return enhancer(createStore)(reducer, preloadedState); - } - - if (typeof reducer !== 'function') { - throw new Error('Expected the reducer to be a function.'); - } - - var currentReducer = reducer; - var currentState = preloadedState; - var currentListeners = []; - var nextListeners = currentListeners; - var isDispatching = false; - /** - * This makes a shallow copy of currentListeners so we can use - * nextListeners as a temporary list while dispatching. - * - * This prevents any bugs around consumers calling - * subscribe/unsubscribe in the middle of a dispatch. - */ - - function ensureCanMutateNextListeners() { - if (nextListeners === currentListeners) { - nextListeners = currentListeners.slice(); - } - } - /** - * Reads the state tree managed by the store. - * - * @returns {any} The current state tree of your application. - */ - - - function getState() { - if (isDispatching) { - throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.'); - } - - return currentState; - } - /** - * Adds a change listener. It will be called any time an action is dispatched, - * and some part of the state tree may potentially have changed. You may then - * call `getState()` to read the current state tree inside the callback. - * - * You may call `dispatch()` from a change listener, with the following - * caveats: - * - * 1. The subscriptions are snapshotted just before every `dispatch()` call. - * If you subscribe or unsubscribe while the listeners are being invoked, this - * will not have any effect on the `dispatch()` that is currently in progress. - * However, the next `dispatch()` call, whether nested or not, will use a more - * recent snapshot of the subscription list. - * - * 2. The listener should not expect to see all state changes, as the state - * might have been updated multiple times during a nested `dispatch()` before - * the listener is called. It is, however, guaranteed that all subscribers - * registered before the `dispatch()` started will be called with the latest - * state by the time it exits. - * - * @param {Function} listener A callback to be invoked on every dispatch. - * @returns {Function} A function to remove this change listener. - */ - - - function subscribe(listener) { - if (typeof listener !== 'function') { - throw new Error('Expected the listener to be a function.'); - } - - if (isDispatching) { - throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.'); - } - - var isSubscribed = true; - ensureCanMutateNextListeners(); - nextListeners.push(listener); - return function unsubscribe() { - if (!isSubscribed) { - return; - } - - if (isDispatching) { - throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.'); - } - - isSubscribed = false; - ensureCanMutateNextListeners(); - var index = nextListeners.indexOf(listener); - nextListeners.splice(index, 1); - }; - } - /** - * Dispatches an action. It is the only way to trigger a state change. - * - * The `reducer` function, used to create the store, will be called with the - * current state tree and the given `action`. Its return value will - * be considered the **next** state of the tree, and the change listeners - * will be notified. - * - * The base implementation only supports plain object actions. If you want to - * dispatch a Promise, an Observable, a thunk, or something else, you need to - * wrap your store creating function into the corresponding middleware. For - * example, see the documentation for the `redux-thunk` package. Even the - * middleware will eventually dispatch plain object actions using this method. - * - * @param {Object} action A plain object representing “what changed”. It is - * a good idea to keep actions serializable so you can record and replay user - * sessions, or use the time travelling `redux-devtools`. An action must have - * a `type` property which may not be `undefined`. It is a good idea to use - * string constants for action types. - * - * @returns {Object} For convenience, the same action object you dispatched. - * - * Note that, if you use a custom middleware, it may wrap `dispatch()` to - * return something else (for example, a Promise you can await). - */ - - - function dispatch(action) { - if (!isPlainObject(action)) { - throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); - } - - if (typeof action.type === 'undefined') { - throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); - } - - if (isDispatching) { - throw new Error('Reducers may not dispatch actions.'); - } - - try { - isDispatching = true; - currentState = currentReducer(currentState, action); - } finally { - isDispatching = false; - } - - var listeners = currentListeners = nextListeners; - - for (var i = 0; i < listeners.length; i++) { - var listener = listeners[i]; - listener(); - } - - return action; - } - /** - * Replaces the reducer currently used by the store to calculate the state. - * - * You might need this if your app implements code splitting and you want to - * load some of the reducers dynamically. You might also need this if you - * implement a hot reloading mechanism for Redux. - * - * @param {Function} nextReducer The reducer for the store to use instead. - * @returns {void} - */ - - - function replaceReducer(nextReducer) { - if (typeof nextReducer !== 'function') { - throw new Error('Expected the nextReducer to be a function.'); - } - - currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT. - // Any reducers that existed in both the new and old rootReducer - // will receive the previous state. This effectively populates - // the new state tree with any relevant data from the old one. - - dispatch({ - type: ActionTypes.REPLACE - }); - } - /** - * Interoperability point for observable/reactive libraries. - * @returns {observable} A minimal observable of state changes. - * For more information, see the observable proposal: - * https://github.com/tc39/proposal-observable - */ - - - function observable() { - var _ref; - - var outerSubscribe = subscribe; - return _ref = { - /** - * The minimal observable subscription method. - * @param {Object} observer Any object that can be used as an observer. - * The observer object should have a `next` method. - * @returns {subscription} An object with an `unsubscribe` method that can - * be used to unsubscribe the observable from the store, and prevent further - * emission of values from the observable. - */ - subscribe: function subscribe(observer) { - if (typeof observer !== 'object' || observer === null) { - throw new TypeError('Expected the observer to be an object.'); - } - - function observeState() { - if (observer.next) { - observer.next(getState()); - } - } - - observeState(); - var unsubscribe = outerSubscribe(observeState); - return { - unsubscribe: unsubscribe - }; - } - }, _ref[es["a" /* default */]] = function () { - return this; - }, _ref; - } // When a store is created, an "INIT" action is dispatched so that every - // reducer returns their initial state. This effectively populates - // the initial state tree. - - - dispatch({ - type: ActionTypes.INIT - }); - return _ref2 = { - dispatch: dispatch, - subscribe: subscribe, - getState: getState, - replaceReducer: replaceReducer - }, _ref2[es["a" /* default */]] = observable, _ref2; -} - -/** - * Prints a warning in the console if it exists. - * - * @param {String} message The warning message. - * @returns {void} - */ -function warning(message) { - /* eslint-disable no-console */ - if (typeof console !== 'undefined' && typeof console.error === 'function') { - console.error(message); - } - /* eslint-enable no-console */ - - - try { - // This error was thrown as a convenience so that if you enable - // "break on all exceptions" in your console, - // it would pause the execution at this line. - throw new Error(message); - } catch (e) {} // eslint-disable-line no-empty - -} - -function getUndefinedStateErrorMessage(key, action) { - var actionType = action && action.type; - var actionDescription = actionType && "action \"" + String(actionType) + "\"" || 'an action'; - return "Given " + actionDescription + ", reducer \"" + key + "\" returned undefined. " + "To ignore an action, you must explicitly return the previous state. " + "If you want this reducer to hold no value, you can return null instead of undefined."; -} - -function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) { - var reducerKeys = Object.keys(reducers); - var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer'; - - if (reducerKeys.length === 0) { - return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.'; - } - - if (!isPlainObject(inputState)) { - return "The " + argumentName + " has unexpected type of \"" + {}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\""); - } - - var unexpectedKeys = Object.keys(inputState).filter(function (key) { - return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]; - }); - unexpectedKeys.forEach(function (key) { - unexpectedKeyCache[key] = true; - }); - if (action && action.type === ActionTypes.REPLACE) return; - - if (unexpectedKeys.length > 0) { - return "Unexpected " + (unexpectedKeys.length > 1 ? 'keys' : 'key') + " " + ("\"" + unexpectedKeys.join('", "') + "\" found in " + argumentName + ". ") + "Expected to find one of the known reducer keys instead: " + ("\"" + reducerKeys.join('", "') + "\". Unexpected keys will be ignored."); - } -} - -function assertReducerShape(reducers) { - Object.keys(reducers).forEach(function (key) { - var reducer = reducers[key]; - var initialState = reducer(undefined, { - type: ActionTypes.INIT - }); - - if (typeof initialState === 'undefined') { - throw new Error("Reducer \"" + key + "\" returned undefined during initialization. " + "If the state passed to the reducer is undefined, you must " + "explicitly return the initial state. The initial state may " + "not be undefined. If you don't want to set a value for this reducer, " + "you can use null instead of undefined."); - } - - if (typeof reducer(undefined, { - type: ActionTypes.PROBE_UNKNOWN_ACTION() - }) === 'undefined') { - throw new Error("Reducer \"" + key + "\" returned undefined when probed with a random type. " + ("Don't try to handle " + ActionTypes.INIT + " or other actions in \"redux/*\" ") + "namespace. They are considered private. Instead, you must return the " + "current state for any unknown actions, unless it is undefined, " + "in which case you must return the initial state, regardless of the " + "action type. The initial state may not be undefined, but can be null."); - } - }); -} -/** - * Turns an object whose values are different reducer functions, into a single - * reducer function. It will call every child reducer, and gather their results - * into a single state object, whose keys correspond to the keys of the passed - * reducer functions. - * - * @param {Object} reducers An object whose values correspond to different - * reducer functions that need to be combined into one. One handy way to obtain - * it is to use ES6 `import * as reducers` syntax. The reducers may never return - * undefined for any action. Instead, they should return their initial state - * if the state passed to them was undefined, and the current state for any - * unrecognized action. - * - * @returns {Function} A reducer function that invokes every reducer inside the - * passed object, and builds a state object with the same shape. - */ - - -function combineReducers(reducers) { - var reducerKeys = Object.keys(reducers); - var finalReducers = {}; - - for (var i = 0; i < reducerKeys.length; i++) { - var key = reducerKeys[i]; - - if (false) {} - - if (typeof reducers[key] === 'function') { - finalReducers[key] = reducers[key]; - } - } - - var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same - // keys multiple times. - - var unexpectedKeyCache; - - if (false) {} - - var shapeAssertionError; - - try { - assertReducerShape(finalReducers); - } catch (e) { - shapeAssertionError = e; - } - - return function combination(state, action) { - if (state === void 0) { - state = {}; - } - - if (shapeAssertionError) { - throw shapeAssertionError; - } - - if (false) { var warningMessage; } - - var hasChanged = false; - var nextState = {}; - - for (var _i = 0; _i < finalReducerKeys.length; _i++) { - var _key = finalReducerKeys[_i]; - var reducer = finalReducers[_key]; - var previousStateForKey = state[_key]; - var nextStateForKey = reducer(previousStateForKey, action); - - if (typeof nextStateForKey === 'undefined') { - var errorMessage = getUndefinedStateErrorMessage(_key, action); - throw new Error(errorMessage); - } - - nextState[_key] = nextStateForKey; - hasChanged = hasChanged || nextStateForKey !== previousStateForKey; - } - - return hasChanged ? nextState : state; - }; -} - -function bindActionCreator(actionCreator, dispatch) { - return function () { - return dispatch(actionCreator.apply(this, arguments)); - }; -} -/** - * Turns an object whose values are action creators, into an object with the - * same keys, but with every function wrapped into a `dispatch` call so they - * may be invoked directly. This is just a convenience method, as you can call - * `store.dispatch(MyActionCreators.doSomething())` yourself just fine. - * - * For convenience, you can also pass an action creator as the first argument, - * and get a dispatch wrapped function in return. - * - * @param {Function|Object} actionCreators An object whose values are action - * creator functions. One handy way to obtain it is to use ES6 `import * as` - * syntax. You may also pass a single function. - * - * @param {Function} dispatch The `dispatch` function available on your Redux - * store. - * - * @returns {Function|Object} The object mimicking the original object, but with - * every action creator wrapped into the `dispatch` call. If you passed a - * function as `actionCreators`, the return value will also be a single - * function. - */ - - -function bindActionCreators(actionCreators, dispatch) { - if (typeof actionCreators === 'function') { - return bindActionCreator(actionCreators, dispatch); - } - - if (typeof actionCreators !== 'object' || actionCreators === null) { - throw new Error("bindActionCreators expected an object or a function, instead received " + (actionCreators === null ? 'null' : typeof actionCreators) + ". " + "Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?"); - } - - var boundActionCreators = {}; - - for (var key in actionCreators) { - var actionCreator = actionCreators[key]; - - if (typeof actionCreator === 'function') { - boundActionCreators[key] = bindActionCreator(actionCreator, dispatch); - } - } - - return boundActionCreators; -} - -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 ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); - - if (Object.getOwnPropertySymbols) { - keys.push.apply(keys, Object.getOwnPropertySymbols(object)); - } - - if (enumerableOnly) keys = keys.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - }); - return keys; -} - -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; -} - -/** - * Composes single-argument functions from right to left. The rightmost - * function can take multiple arguments as it provides the signature for - * the resulting composite function. - * - * @param {...Function} funcs The functions to compose. - * @returns {Function} A function obtained by composing the argument functions - * from right to left. For example, compose(f, g, h) is identical to doing - * (...args) => f(g(h(...args))). - */ -function compose() { - for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) { - funcs[_key] = arguments[_key]; - } - - if (funcs.length === 0) { - return function (arg) { - return arg; - }; - } - - if (funcs.length === 1) { - return funcs[0]; - } - - return funcs.reduce(function (a, b) { - return function () { - return a(b.apply(void 0, arguments)); - }; - }); -} - -/** - * Creates a store enhancer that applies middleware to the dispatch method - * of the Redux store. This is handy for a variety of tasks, such as expressing - * asynchronous actions in a concise manner, or logging every action payload. - * - * See `redux-thunk` package as an example of the Redux middleware. - * - * Because middleware is potentially asynchronous, this should be the first - * store enhancer in the composition chain. - * - * Note that each middleware will be given the `dispatch` and `getState` functions - * as named arguments. - * - * @param {...Function} middlewares The middleware chain to be applied. - * @returns {Function} A store enhancer applying the middleware. - */ - -function applyMiddleware() { - for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) { - middlewares[_key] = arguments[_key]; - } - - return function (createStore) { - return function () { - var store = createStore.apply(void 0, arguments); - - var _dispatch = function dispatch() { - throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.'); - }; - - var middlewareAPI = { - getState: store.getState, - dispatch: function dispatch() { - return _dispatch.apply(void 0, arguments); - } - }; - var chain = middlewares.map(function (middleware) { - return middleware(middlewareAPI); - }); - _dispatch = compose.apply(void 0, chain)(store.dispatch); - return _objectSpread2({}, store, { - dispatch: _dispatch - }); - }; - }; -} - -/* - * This is a dummy function to check if the function name has been altered by minification. - * If the function has been minified and NODE_ENV !== 'production', warn the user. - */ - -function isCrushed() {} - -if (false) {} - - - -// CONCATENATED MODULE: ./src/scripts/reducers/items.js -var defaultState = []; -function items_items(state, action) { - if (state === void 0) { - state = defaultState; - } - - switch (action.type) { - case 'ADD_ITEM': - { - // Add object to items array - var newState = [].concat(state, [{ - id: action.id, - choiceId: action.choiceId, - groupId: action.groupId, - value: action.value, - label: action.label, - active: true, - highlighted: false, - customProperties: action.customProperties, - placeholder: action.placeholder || false, - keyCode: null - }]); - return newState.map(function (obj) { - var item = obj; - item.highlighted = false; - return item; - }); - } - - case 'REMOVE_ITEM': - { - // Set item to inactive - return state.map(function (obj) { - var item = obj; - - if (item.id === action.id) { - item.active = false; - } - - return item; - }); - } - - case 'HIGHLIGHT_ITEM': - { - return state.map(function (obj) { - var item = obj; - - if (item.id === action.id) { - item.highlighted = action.highlighted; - } - - return item; - }); - } - - default: - { - return state; - } - } -} -// CONCATENATED MODULE: ./src/scripts/reducers/groups.js -var groups_defaultState = []; -function groups(state, action) { - if (state === void 0) { - state = groups_defaultState; - } - - switch (action.type) { - case 'ADD_GROUP': - { - return [].concat(state, [{ - id: action.id, - value: action.value, - active: action.active, - disabled: action.disabled - }]); - } - - case 'CLEAR_CHOICES': - { - return []; - } - - default: - { - return state; - } - } -} -// CONCATENATED MODULE: ./src/scripts/reducers/choices.js -var choices_defaultState = []; -function choices_choices(state, action) { - if (state === void 0) { - state = choices_defaultState; - } - - switch (action.type) { - case 'ADD_CHOICE': - { - /* - A disabled choice appears in the choice dropdown but cannot be selected - A selected choice has been added to the passed input's value (added as an item) - An active choice appears within the choice dropdown - */ - return [].concat(state, [{ - id: action.id, - elementId: action.elementId, - groupId: action.groupId, - value: action.value, - label: action.label || action.value, - disabled: action.disabled || false, - selected: false, - active: true, - score: 9999, - customProperties: action.customProperties, - placeholder: action.placeholder || false, - keyCode: null - }]); - } - - case 'ADD_ITEM': - { - // If all choices need to be activated - if (action.activateOptions) { - return state.map(function (obj) { - var choice = obj; - choice.active = action.active; - return choice; - }); - } // When an item is added and it has an associated choice, - // we want to disable it so it can't be chosen again - - - if (action.choiceId > -1) { - return state.map(function (obj) { - var choice = obj; - - if (choice.id === parseInt(action.choiceId, 10)) { - choice.selected = true; - } - - return choice; - }); - } - - return state; - } - - case 'REMOVE_ITEM': - { - // When an item is removed and it has an associated choice, - // we want to re-enable it so it can be chosen again - if (action.choiceId > -1) { - return state.map(function (obj) { - var choice = obj; - - if (choice.id === parseInt(action.choiceId, 10)) { - choice.selected = false; - } - - return choice; - }); - } - - return state; - } - - case 'FILTER_CHOICES': - { - return state.map(function (obj) { - var choice = obj; // Set active state based on whether choice is - // within filtered results - - choice.active = action.results.some(function (_ref) { - var item = _ref.item, - score = _ref.score; - - if (item.id === choice.id) { - choice.score = score; - return true; - } - - return false; - }); - return choice; - }); - } - - case 'ACTIVATE_CHOICES': - { - return state.map(function (obj) { - var choice = obj; - choice.active = action.active; - return choice; - }); - } - - case 'CLEAR_CHOICES': - { - return choices_defaultState; - } - - default: - { - return state; - } - } -} -// CONCATENATED MODULE: ./src/scripts/reducers/general.js -var general_defaultState = { - loading: false -}; - -var general = function general(state, action) { - if (state === void 0) { - state = general_defaultState; - } - - switch (action.type) { - case 'SET_IS_LOADING': - { - return { - loading: action.isLoading - }; - } - - default: - { - return state; - } - } -}; - -/* harmony default export */ var reducers_general = (general); -// CONCATENATED MODULE: ./src/scripts/lib/utils.js -var utils_this = undefined; - -var getRandomNumber = function getRandomNumber(min, max) { - return Math.floor(Math.random() * (max - min) + min); -}; -var generateChars = function generateChars(length) { - var chars = ''; - - for (var i = 0; i < length; i++) { - var randomChar = getRandomNumber(0, 36); - chars += randomChar.toString(36); - } - - return chars; -}; -var generateId = function generateId(element, prefix) { - var id = element.id || element.name && element.name + "-" + generateChars(2) || generateChars(4); - id = id.replace(/(:|\.|\[|\]|,)/g, ''); - id = prefix + "-" + id; - return id; -}; -var getType = function getType(obj) { - return Object.prototype.toString.call(obj).slice(8, -1); -}; -var isType = function isType(type, obj) { - return obj !== undefined && obj !== null && getType(obj) === type; -}; -var isElement = function isElement(element) { - return element instanceof Element; -}; -var utils_wrap = function wrap(element, wrapper) { - if (wrapper === void 0) { - wrapper = document.createElement('div'); - } - - if (element.nextSibling) { - element.parentNode.insertBefore(wrapper, element.nextSibling); - } else { - element.parentNode.appendChild(wrapper); - } - - return wrapper.appendChild(element); -}; -var findAncestorByAttrName = function findAncestorByAttrName(el, attr) { - var target = el; - - while (target) { - if (target.hasAttribute(attr)) { - return target; - } - - target = target.parentElement; - } - - return null; -}; -var getAdjacentEl = function getAdjacentEl(startEl, className, direction) { - if (direction === void 0) { - direction = 1; - } - - if (!startEl || !className) { - return; - } - - var parent = startEl.parentNode.parentNode; - var children = Array.from(parent.querySelectorAll(className)); - var startPos = children.indexOf(startEl); - var operatorDirection = direction > 0 ? 1 : -1; - return children[startPos + operatorDirection]; -}; -var isScrolledIntoView = function isScrolledIntoView(el, parent, direction) { - if (direction === void 0) { - direction = 1; - } - - if (!el) { - return; - } - - var isVisible; - - if (direction > 0) { - // In view from bottom - isVisible = parent.scrollTop + parent.offsetHeight >= el.offsetTop + el.offsetHeight; - } else { - // In view from top - isVisible = el.offsetTop >= parent.scrollTop; - } - - return isVisible; -}; -var sanitise = function sanitise(value) { - if (!isType('String', value)) { - return value; - } - - return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/" + sanitise(value) + ""); - testEl.style.position = 'absolute'; - testEl.style.padding = '0'; - testEl.style.top = '-9999px'; - testEl.style.left = '-9999px'; - testEl.style.width = 'auto'; - testEl.style.whiteSpace = 'pre'; - - if (document.body.contains(input) && window.getComputedStyle) { - var inputStyle = window.getComputedStyle(input); - - if (inputStyle) { - testEl.style.fontSize = inputStyle.fontSize; - testEl.style.fontFamily = inputStyle.fontFamily; - testEl.style.fontWeight = inputStyle.fontWeight; - testEl.style.fontStyle = inputStyle.fontStyle; - testEl.style.letterSpacing = inputStyle.letterSpacing; - testEl.style.textTransform = inputStyle.textTransform; - testEl.style.paddingLeft = inputStyle.paddingLeft; - testEl.style.paddingRight = inputStyle.paddingRight; - } - } - - document.body.appendChild(testEl); - requestAnimationFrame(function () { - if (value && testEl.offsetWidth !== input.offsetWidth) { - width = testEl.offsetWidth + 4; - } - - document.body.removeChild(testEl); - callback.call(utils_this, width + "px"); - }); - } else { - callback.call(utils_this, width + "px"); - } -}; -var sortByAlpha = function sortByAlpha(a, b) { - var labelA = ("" + (a.label || a.value)).toLowerCase(); - var labelB = ("" + (b.label || b.value)).toLowerCase(); - - if (labelA < labelB) { - return -1; - } - - if (labelA > labelB) { - return 1; - } - - return 0; -}; -var sortByScore = function sortByScore(a, b) { - return a.score - b.score; -}; -var dispatchEvent = function dispatchEvent(element, type, customArgs) { - if (customArgs === void 0) { - customArgs = null; - } - - var event = new CustomEvent(type, { - detail: customArgs, - bubbles: true, - cancelable: true - }); - return element.dispatchEvent(event); -}; -var getWindowHeight = function getWindowHeight() { - var _document = document, - body = _document.body; - var html = document.documentElement; - return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); -}; -var fetchFromObject = function fetchFromObject(object, path) { - var index = path.indexOf('.'); - - if (index > -1) { - return fetchFromObject(object[path.substring(0, index)], path.substr(index + 1)); - } - - return object[path]; -}; -var isIE11 = function isIE11() { - return !!(navigator.userAgent.match(/Trident/) && navigator.userAgent.match(/rv[ :]11/)); -}; -var existsInArray = function existsInArray(array, value, key) { - if (key === void 0) { - key = 'value'; - } - - return array.some(function (item) { - if (isType('String', value)) { - return item[key] === value.trim(); - } - - return item[key] === value; - }); -}; -var cloneObject = function cloneObject(obj) { - return JSON.parse(JSON.stringify(obj)); -}; -var diff = function diff(a, b) { - var aKeys = Object.keys(a).sort(); - var bKeys = Object.keys(b).sort(); - return aKeys.filter(function (i) { - return bKeys.indexOf(i) < 0; - }); -}; -// CONCATENATED MODULE: ./src/scripts/reducers/index.js - - - - - - -var appReducer = combineReducers({ - items: items_items, - groups: groups, - choices: choices_choices, - general: reducers_general -}); - -var reducers_rootReducer = function rootReducer(passedState, action) { - var state = passedState; // If we are clearing all items, groups and options we reassign - // state and then pass that state to our proper reducer. This isn't - // mutating our actual state - // See: http://stackoverflow.com/a/35641992 - - if (action.type === 'CLEAR_ALL') { - state = undefined; - } else if (action.type === 'RESET_TO') { - return cloneObject(action.state); - } - - return appReducer(state, action); -}; - -/* harmony default export */ var reducers = (reducers_rootReducer); -// CONCATENATED MODULE: ./src/scripts/store/store.js -function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } - - - - -var store_Store = -/*#__PURE__*/ -function () { - function Store() { - this._store = createStore(reducers, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()); - } - /** - * Subscribe store to function call (wrapped Redux method) - * @param {Function} onChange Function to trigger when state changes - * @return - */ - - - var _proto = Store.prototype; - - _proto.subscribe = function subscribe(onChange) { - this._store.subscribe(onChange); - } - /** - * Dispatch event to store (wrapped Redux method) - * @param {Function} action Action function to trigger - * @return - */ - ; - - _proto.dispatch = function dispatch(action) { - this._store.dispatch(action); - } - /** - * Get store object (wrapping Redux method) - * @return {Object} State - */ - ; - - /** - * Get loading state from store - * @return {Boolean} Loading State - */ - _proto.isLoading = function isLoading() { - return this.state.general.loading; - } - /** - * Get single choice by it's ID - * @return {Object} Found choice - */ - ; - - _proto.getChoiceById = function getChoiceById(id) { - if (id) { - return this.activeChoices.find(function (choice) { - return choice.id === parseInt(id, 10); - }); - } - - return false; - } - /** - * Get group by group id - * @param {Number} id Group ID - * @return {Object} Group data - */ - ; - - _proto.getGroupById = function getGroupById(id) { - return this.groups.find(function (group) { - return group.id === parseInt(id, 10); - }); - }; - - _createClass(Store, [{ - key: "state", - get: function get() { - return this._store.getState(); - } - /** - * Get items from store - * @return {Array} Item objects - */ - - }, { - key: "items", - get: function get() { - return this.state.items; - } - /** - * Get active items from store - * @return {Array} Item objects - */ - - }, { - key: "activeItems", - get: function get() { - return this.items.filter(function (item) { - return item.active === true; - }); - } - /** - * Get highlighted items from store - * @return {Array} Item objects - */ - - }, { - key: "highlightedActiveItems", - get: function get() { - return this.items.filter(function (item) { - return item.active && item.highlighted; - }); - } - /** - * Get choices from store - * @return {Array} Option objects - */ - - }, { - key: "choices", - get: function get() { - return this.state.choices; - } - /** - * Get active choices from store - * @return {Array} Option objects - */ - - }, { - key: "activeChoices", - get: function get() { - var choices = this.choices; - var values = choices.filter(function (choice) { - return choice.active === true; - }); - return values; - } - /** - * Get selectable choices from store - * @return {Array} Option objects - */ - - }, { - key: "selectableChoices", - get: function get() { - return this.choices.filter(function (choice) { - return choice.disabled !== true; - }); - } - /** - * Get choices that can be searched (excluding placeholders) - * @return {Array} Option objects - */ - - }, { - key: "searchableChoices", - get: function get() { - return this.selectableChoices.filter(function (choice) { - return choice.placeholder !== true; - }); - } - /** - * Get placeholder choice from store - * @return {Object} Found placeholder - */ - - }, { - key: "placeholderChoice", - get: function get() { - return [].concat(this.choices).reverse().find(function (choice) { - return choice.placeholder === true; - }); - } - /** - * Get groups from store - * @return {Array} Group objects - */ - - }, { - key: "groups", - get: function get() { - return this.state.groups; - } - /** - * Get active groups from store - * @return {Array} Group objects - */ - - }, { - key: "activeGroups", - get: function get() { - var groups = this.groups, - choices = this.choices; - return groups.filter(function (group) { - var isActive = group.active === true && group.disabled === false; - var hasActiveOptions = choices.some(function (choice) { - return choice.active === true && choice.disabled === false; - }); - return isActive && hasActiveOptions; - }, []); - } - }]); - - return Store; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/dropdown.js -var Dropdown = -/*#__PURE__*/ -function () { - function Dropdown(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames; - Object.assign(this, { - element: element, - type: type, - classNames: classNames - }); - this.isActive = false; - } - /** - * Determine how far the top of our element is from - * the top of the window - * @return {Number} Vertical position - */ - - - var _proto = Dropdown.prototype; - - _proto.distanceFromTopWindow = function distanceFromTopWindow() { - this.dimensions = this.element.getBoundingClientRect(); - this.position = Math.ceil(this.dimensions.top + window.pageYOffset + this.element.offsetHeight); - return this.position; - } - /** - * Find element that matches passed selector - * @return {HTMLElement} - */ - ; - - _proto.getChild = function getChild(selector) { - return this.element.querySelector(selector); - } - /** - * Show dropdown to user by adding active state class - * @return {Object} Class instance - * @public - */ - ; - - _proto.show = function show() { - this.element.classList.add(this.classNames.activeState); - this.element.setAttribute('aria-expanded', 'true'); - this.isActive = true; - return this; - } - /** - * Hide dropdown from user - * @return {Object} Class instance - * @public - */ - ; - - _proto.hide = function hide() { - this.element.classList.remove(this.classNames.activeState); - this.element.setAttribute('aria-expanded', 'false'); - this.isActive = false; - return this; - }; - - return Dropdown; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/container.js - - -var container_Container = -/*#__PURE__*/ -function () { - function Container(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames, - position = _ref.position; - Object.assign(this, { - element: element, - classNames: classNames, - type: type, - position: position - }); - this.isOpen = false; - this.isFlipped = false; - this.isFocussed = false; - this.isDisabled = false; - this.isLoading = false; - this._onFocus = this._onFocus.bind(this); - this._onBlur = this._onBlur.bind(this); - } - /** - * Add event listeners - */ - - - var _proto = Container.prototype; - - _proto.addEventListeners = function addEventListeners() { - this.element.addEventListener('focus', this._onFocus); - this.element.addEventListener('blur', this._onBlur); - } - /** - * Remove event listeners - */ - - /** */ - ; - - _proto.removeEventListeners = function removeEventListeners() { - this.element.removeEventListener('focus', this._onFocus); - this.element.removeEventListener('blur', this._onBlur); - } - /** - * Determine whether container should be flipped - * based on passed dropdown position - * @param {Number} dropdownPos - * @returns - */ - ; - - _proto.shouldFlip = function shouldFlip(dropdownPos, windowHeight) { - if (windowHeight === void 0) { - windowHeight = getWindowHeight(); - } - - if (dropdownPos === undefined) { - return false; - } // If flip is enabled and the dropdown bottom position is - // greater than the window height flip the dropdown. - - - var shouldFlip = false; - - if (this.position === 'auto') { - shouldFlip = dropdownPos >= windowHeight; - } else if (this.position === 'top') { - shouldFlip = true; - } - - return shouldFlip; - } - /** - * Set active descendant attribute - * @param {Number} activeDescendant ID of active descendant - */ - ; - - _proto.setActiveDescendant = function setActiveDescendant(activeDescendantID) { - this.element.setAttribute('aria-activedescendant', activeDescendantID); - } - /** - * Remove active descendant attribute - */ - ; - - _proto.removeActiveDescendant = function removeActiveDescendant() { - this.element.removeAttribute('aria-activedescendant'); - }; - - _proto.open = function open(dropdownPos) { - this.element.classList.add(this.classNames.openState); - this.element.setAttribute('aria-expanded', 'true'); - this.isOpen = true; - - if (this.shouldFlip(dropdownPos)) { - this.element.classList.add(this.classNames.flippedState); - this.isFlipped = true; - } - }; - - _proto.close = function close() { - this.element.classList.remove(this.classNames.openState); - this.element.setAttribute('aria-expanded', 'false'); - this.removeActiveDescendant(); - this.isOpen = false; // A dropdown flips if it does not have space within the page - - if (this.isFlipped) { - this.element.classList.remove(this.classNames.flippedState); - this.isFlipped = false; - } - }; - - _proto.focus = function focus() { - if (!this.isFocussed) { - this.element.focus(); - } - }; - - _proto.addFocusState = function addFocusState() { - this.element.classList.add(this.classNames.focusState); - }; - - _proto.removeFocusState = function removeFocusState() { - this.element.classList.remove(this.classNames.focusState); - } - /** - * Remove disabled state - */ - ; - - _proto.enable = function enable() { - this.element.classList.remove(this.classNames.disabledState); - this.element.removeAttribute('aria-disabled'); - - if (this.type === 'select-one') { - this.element.setAttribute('tabindex', '0'); - } - - this.isDisabled = false; - } - /** - * Set disabled state - */ - ; - - _proto.disable = function disable() { - this.element.classList.add(this.classNames.disabledState); - this.element.setAttribute('aria-disabled', 'true'); - - if (this.type === 'select-one') { - this.element.setAttribute('tabindex', '-1'); - } - - this.isDisabled = true; - }; - - _proto.wrap = function wrap(element) { - utils_wrap(element, this.element); - }; - - _proto.unwrap = function unwrap(element) { - // Move passed element outside this element - this.element.parentNode.insertBefore(element, this.element); // Remove this element - - this.element.parentNode.removeChild(this.element); - } - /** - * Add loading state to element - */ - ; - - _proto.addLoadingState = function addLoadingState() { - this.element.classList.add(this.classNames.loadingState); - this.element.setAttribute('aria-busy', 'true'); - this.isLoading = true; - } - /** - * Remove loading state from element - */ - ; - - _proto.removeLoadingState = function removeLoadingState() { - this.element.classList.remove(this.classNames.loadingState); - this.element.removeAttribute('aria-busy'); - this.isLoading = false; - } - /** - * Set focussed state - */ - ; - - _proto._onFocus = function _onFocus() { - this.isFocussed = true; - } - /** - * Remove blurred state - */ - ; - - _proto._onBlur = function _onBlur() { - this.isFocussed = false; - }; - - return Container; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/input.js -function input_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function input_createClass(Constructor, protoProps, staticProps) { if (protoProps) input_defineProperties(Constructor.prototype, protoProps); if (staticProps) input_defineProperties(Constructor, staticProps); return Constructor; } - - - -var input_Input = -/*#__PURE__*/ -function () { - function Input(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames, - placeholderValue = _ref.placeholderValue; - Object.assign(this, { - element: element, - type: type, - classNames: classNames, - placeholderValue: placeholderValue - }); - this.element = element; - this.classNames = classNames; - this.isFocussed = this.element === document.activeElement; - this.isDisabled = false; - this._onPaste = this._onPaste.bind(this); - this._onInput = this._onInput.bind(this); - this._onFocus = this._onFocus.bind(this); - this._onBlur = this._onBlur.bind(this); - } - - var _proto = Input.prototype; - - _proto.addEventListeners = function addEventListeners() { - this.element.addEventListener('input', this._onInput); - this.element.addEventListener('paste', this._onPaste); - this.element.addEventListener('focus', this._onFocus); - this.element.addEventListener('blur', this._onBlur); - - if (this.element.form) { - this.element.form.addEventListener('reset', this._onFormReset); - } - }; - - _proto.removeEventListeners = function removeEventListeners() { - this.element.removeEventListener('input', this._onInput); - this.element.removeEventListener('paste', this._onPaste); - this.element.removeEventListener('focus', this._onFocus); - this.element.removeEventListener('blur', this._onBlur); - - if (this.element.form) { - this.element.form.removeEventListener('reset', this._onFormReset); - } - }; - - _proto.enable = function enable() { - this.element.removeAttribute('disabled'); - this.isDisabled = false; - }; - - _proto.disable = function disable() { - this.element.setAttribute('disabled', ''); - this.isDisabled = true; - }; - - _proto.focus = function focus() { - if (!this.isFocussed) { - this.element.focus(); - } - }; - - _proto.blur = function blur() { - if (this.isFocussed) { - this.element.blur(); - } - } - /** - * Set value of input to blank - * @return {Object} Class instance - * @public - */ - ; - - _proto.clear = function clear(setWidth) { - if (setWidth === void 0) { - setWidth = true; - } - - if (this.element.value) { - this.element.value = ''; - } - - if (setWidth) { - this.setWidth(); - } - - return this; - } - /** - * Set the correct input width based on placeholder - * value or input value - * @return - */ - ; - - _proto.setWidth = function setWidth(enforceWidth) { - var _this = this; - - var callback = function callback(width) { - _this.element.style.width = width; - }; - - if (this._placeholderValue) { - // If there is a placeholder, we only want to set the width of the input when it is a greater - // length than 75% of the placeholder. This stops the input jumping around. - var valueHasDesiredLength = this.element.value.length >= this._placeholderValue.length / 1.25; - - if (this.element.value && valueHasDesiredLength || enforceWidth) { - this.calcWidth(callback); - } - } else { - // If there is no placeholder, resize input to contents - this.calcWidth(callback); - } - }; - - _proto.calcWidth = function calcWidth(callback) { - return calcWidthOfInput(this.element, callback); - }; - - _proto.setActiveDescendant = function setActiveDescendant(activeDescendantID) { - this.element.setAttribute('aria-activedescendant', activeDescendantID); - }; - - _proto.removeActiveDescendant = function removeActiveDescendant() { - this.element.removeAttribute('aria-activedescendant'); - }; - - _proto._onInput = function _onInput() { - if (this.type !== 'select-one') { - this.setWidth(); - } - }; - - _proto._onPaste = function _onPaste(event) { - var target = event.target; - - if (target === this.element && this.preventPaste) { - event.preventDefault(); - } - }; - - _proto._onFocus = function _onFocus() { - this.isFocussed = true; - }; - - _proto._onBlur = function _onBlur() { - this.isFocussed = false; - }; - - input_createClass(Input, [{ - key: "placeholder", - set: function set(placeholder) { - this.element.placeholder = placeholder; - } - }, { - key: "value", - set: function set(value) { - this.element.value = value; - }, - get: function get() { - return sanitise(this.element.value); - } - }]); - - return Input; -}(); - - -// CONCATENATED MODULE: ./src/scripts/constants.js - -var DEFAULT_CLASSNAMES = { - containerOuter: 'choices', - containerInner: 'choices__inner', - input: 'choices__input', - inputCloned: 'choices__input--cloned', - list: 'choices__list', - listItems: 'choices__list--multiple', - listSingle: 'choices__list--single', - listDropdown: 'choices__list--dropdown', - item: 'choices__item', - itemSelectable: 'choices__item--selectable', - itemDisabled: 'choices__item--disabled', - itemChoice: 'choices__item--choice', - placeholder: 'choices__placeholder', - group: 'choices__group', - groupHeading: 'choices__heading', - button: 'choices__button', - activeState: 'is-active', - focusState: 'is-focused', - openState: 'is-open', - disabledState: 'is-disabled', - highlightedState: 'is-highlighted', - hiddenState: 'is-hidden', - flippedState: 'is-flipped', - loadingState: 'is-loading', - noResults: 'has-no-results', - noChoices: 'has-no-choices' -}; -var DEFAULT_CONFIG = { - items: [], - choices: [], - silent: false, - renderChoiceLimit: -1, - maxItemCount: -1, - addItems: true, - addItemFilterFn: null, - removeItems: true, - removeItemButton: false, - editItems: false, - duplicateItemsAllowed: true, - delimiter: ',', - paste: true, - searchEnabled: true, - searchChoices: true, - searchFloor: 1, - searchResultLimit: 4, - searchFields: ['label', 'value'], - position: 'auto', - resetScrollPosition: true, - shouldSort: true, - shouldSortItems: false, - sortFn: sortByAlpha, - placeholder: true, - placeholderValue: null, - searchPlaceholderValue: null, - prependValue: null, - appendValue: null, - renderSelectedChoices: 'auto', - loadingText: 'Loading...', - noResultsText: 'No results found', - noChoicesText: 'No choices to choose from', - itemSelectText: 'Press to select', - uniqueItemText: 'Only unique values can be added', - customAddItemText: 'Only values matching specific conditions can be added', - addItemText: function addItemText(value) { - return "Press Enter to add \"" + sanitise(value) + "\""; - }, - maxItemText: function maxItemText(maxItemCount) { - return "Only " + maxItemCount + " values can be added"; - }, - itemComparer: function itemComparer(choice, item) { - return choice === item; - }, - fuseOptions: { - includeScore: true - }, - callbackOnInit: null, - callbackOnCreateTemplates: null, - classNames: DEFAULT_CLASSNAMES -}; -var EVENTS = { - showDropdown: 'showDropdown', - hideDropdown: 'hideDropdown', - change: 'change', - choice: 'choice', - search: 'search', - addItem: 'addItem', - removeItem: 'removeItem', - highlightItem: 'highlightItem', - highlightChoice: 'highlightChoice' -}; -var ACTION_TYPES = { - ADD_CHOICE: 'ADD_CHOICE', - FILTER_CHOICES: 'FILTER_CHOICES', - ACTIVATE_CHOICES: 'ACTIVATE_CHOICES', - CLEAR_CHOICES: 'CLEAR_CHOICES', - ADD_GROUP: 'ADD_GROUP', - ADD_ITEM: 'ADD_ITEM', - REMOVE_ITEM: 'REMOVE_ITEM', - HIGHLIGHT_ITEM: 'HIGHLIGHT_ITEM', - CLEAR_ALL: 'CLEAR_ALL' -}; -var KEY_CODES = { - BACK_KEY: 46, - DELETE_KEY: 8, - ENTER_KEY: 13, - A_KEY: 65, - ESC_KEY: 27, - UP_KEY: 38, - DOWN_KEY: 40, - PAGE_UP_KEY: 33, - PAGE_DOWN_KEY: 34 -}; -var SCROLLING_SPEED = 4; -// CONCATENATED MODULE: ./src/scripts/components/list.js - - -var list_List = -/*#__PURE__*/ -function () { - function List(_ref) { - var element = _ref.element; - Object.assign(this, { - element: element - }); - this.scrollPos = this.element.scrollTop; - this.height = this.element.offsetHeight; - this.hasChildren = !!this.element.children; - } - - var _proto = List.prototype; - - _proto.clear = function clear() { - this.element.innerHTML = ''; - }; - - _proto.append = function append(node) { - this.element.appendChild(node); - }; - - _proto.getChild = function getChild(selector) { - return this.element.querySelector(selector); - }; - - _proto.scrollToTop = function scrollToTop() { - this.element.scrollTop = 0; - }; - - _proto.scrollToChoice = function scrollToChoice(choice, direction) { - var _this = this; - - if (!choice) { - return; - } - - var dropdownHeight = this.element.offsetHeight; - var choiceHeight = choice.offsetHeight; // Distance from bottom of element to top of parent - - var choicePos = choice.offsetTop + choiceHeight; // Scroll position of dropdown - - var containerScrollPos = this.element.scrollTop + dropdownHeight; // Difference between the choice and scroll position - - var endpoint = direction > 0 ? this.element.scrollTop + choicePos - containerScrollPos : choice.offsetTop; - requestAnimationFrame(function (time) { - _this._animateScroll(time, endpoint, direction); - }); - }; - - _proto._scrollDown = function _scrollDown(scrollPos, strength, endpoint) { - var easing = (endpoint - scrollPos) / strength; - var distance = easing > 1 ? easing : 1; - this.element.scrollTop = scrollPos + distance; - }; - - _proto._scrollUp = function _scrollUp(scrollPos, strength, endpoint) { - var easing = (scrollPos - endpoint) / strength; - var distance = easing > 1 ? easing : 1; - this.element.scrollTop = scrollPos - distance; - }; - - _proto._animateScroll = function _animateScroll(time, endpoint, direction) { - var _this2 = this; - - var strength = SCROLLING_SPEED; - var choiceListScrollTop = this.element.scrollTop; - var continueAnimation = false; - - if (direction > 0) { - this._scrollDown(choiceListScrollTop, strength, endpoint); - - if (choiceListScrollTop < endpoint) { - continueAnimation = true; - } - } else { - this._scrollUp(choiceListScrollTop, strength, endpoint); - - if (choiceListScrollTop > endpoint) { - continueAnimation = true; - } - } - - if (continueAnimation) { - requestAnimationFrame(function () { - _this2._animateScroll(time, endpoint, direction); - }); - } - }; - - return List; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/wrapped-element.js -function wrapped_element_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function wrapped_element_createClass(Constructor, protoProps, staticProps) { if (protoProps) wrapped_element_defineProperties(Constructor.prototype, protoProps); if (staticProps) wrapped_element_defineProperties(Constructor, staticProps); return Constructor; } - - - -var wrapped_element_WrappedElement = -/*#__PURE__*/ -function () { - function WrappedElement(_ref) { - var element = _ref.element, - classNames = _ref.classNames; - Object.assign(this, { - element: element, - classNames: classNames - }); - - if (!isElement(element)) { - throw new TypeError('Invalid element passed'); - } - - this.isDisabled = false; - } - - var _proto = WrappedElement.prototype; - - _proto.conceal = function conceal() { - // Hide passed input - this.element.classList.add(this.classNames.input); - this.element.classList.add(this.classNames.hiddenState); // Remove element from tab index - - this.element.tabIndex = '-1'; // Backup original styles if any - - var origStyle = this.element.getAttribute('style'); - - if (origStyle) { - this.element.setAttribute('data-choice-orig-style', origStyle); - } - - this.element.setAttribute('aria-hidden', 'true'); - this.element.setAttribute('data-choice', 'active'); - }; - - _proto.reveal = function reveal() { - // Reinstate passed element - this.element.classList.remove(this.classNames.input); - this.element.classList.remove(this.classNames.hiddenState); - this.element.removeAttribute('tabindex'); // Recover original styles if any - - var origStyle = this.element.getAttribute('data-choice-orig-style'); - - if (origStyle) { - this.element.removeAttribute('data-choice-orig-style'); - this.element.setAttribute('style', origStyle); - } else { - this.element.removeAttribute('style'); - } - - this.element.removeAttribute('aria-hidden'); - this.element.removeAttribute('data-choice'); // Re-assign values - this is weird, I know - - this.element.value = this.element.value; - }; - - _proto.enable = function enable() { - this.element.removeAttribute('disabled'); - this.element.disabled = false; - this.isDisabled = false; - }; - - _proto.disable = function disable() { - this.element.setAttribute('disabled', ''); - this.element.disabled = true; - this.isDisabled = true; - }; - - _proto.triggerEvent = function triggerEvent(eventType, data) { - dispatchEvent(this.element, eventType, data); - }; - - wrapped_element_createClass(WrappedElement, [{ - key: "value", - get: function get() { - return this.element.value; - }, - set: function set(value) { - // you must define setter here otherwise it will be readonly property - this.element.value = value; - } - }]); - - return WrappedElement; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/wrapped-input.js -function wrapped_input_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function wrapped_input_createClass(Constructor, protoProps, staticProps) { if (protoProps) wrapped_input_defineProperties(Constructor.prototype, protoProps); if (staticProps) wrapped_input_defineProperties(Constructor, staticProps); return Constructor; } - -function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } - - - -var WrappedInput = -/*#__PURE__*/ -function (_WrappedElement) { - _inheritsLoose(WrappedInput, _WrappedElement); - - function WrappedInput(_ref) { - var _this; - - var element = _ref.element, - classNames = _ref.classNames, - delimiter = _ref.delimiter; - _this = _WrappedElement.call(this, { - element: element, - classNames: classNames - }) || this; - _this.delimiter = delimiter; - return _this; - } - - wrapped_input_createClass(WrappedInput, [{ - key: "value", - set: function set(items) { - var itemValues = items.map(function (_ref2) { - var value = _ref2.value; - return value; - }); - var joinedValues = itemValues.join(this.delimiter); - this.element.setAttribute('value', joinedValues); - this.element.value = joinedValues; - }, - get: function get() { - return this.element.value; - } - }]); - - return WrappedInput; -}(wrapped_element_WrappedElement); - - -// CONCATENATED MODULE: ./src/scripts/components/wrapped-select.js -function wrapped_select_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } - -function wrapped_select_createClass(Constructor, protoProps, staticProps) { if (protoProps) wrapped_select_defineProperties(Constructor.prototype, protoProps); if (staticProps) wrapped_select_defineProperties(Constructor, staticProps); return Constructor; } - -function wrapped_select_inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } - - - -var WrappedSelect = -/*#__PURE__*/ -function (_WrappedElement) { - wrapped_select_inheritsLoose(WrappedSelect, _WrappedElement); - - function WrappedSelect(_ref) { - var _this; - - var element = _ref.element, - classNames = _ref.classNames, - template = _ref.template; - _this = _WrappedElement.call(this, { - element: element, - classNames: classNames - }) || this; - _this.template = template; - return _this; - } - - var _proto = WrappedSelect.prototype; - - _proto.appendDocFragment = function appendDocFragment(fragment) { - this.element.innerHTML = ''; - this.element.appendChild(fragment); - }; - - wrapped_select_createClass(WrappedSelect, [{ - key: "placeholderOption", - get: function get() { - return this.element.querySelector('option[value=""]') || // Backward compatibility layer for the non-standard placeholder attribute supported in older versions. - this.element.querySelector('option[placeholder]'); - } - }, { - key: "optionGroups", - get: function get() { - return Array.from(this.element.getElementsByTagName('OPTGROUP')); - } - }, { - key: "options", - get: function get() { - return Array.from(this.element.options); - }, - set: function set(options) { - var _this2 = this; - - var fragment = document.createDocumentFragment(); - - var addOptionToFragment = function addOptionToFragment(data) { - // Create a standard select option - var option = _this2.template(data); // Append it to fragment - - - fragment.appendChild(option); - }; // Add each list item to list - - - options.forEach(function (optionData) { - return addOptionToFragment(optionData); - }); - this.appendDocFragment(fragment); - } - }]); - - return WrappedSelect; -}(wrapped_element_WrappedElement); - - -// CONCATENATED MODULE: ./src/scripts/components/index.js - - - - - - - -// EXTERNAL MODULE: ./node_modules/classnames/index.js -var classnames = __webpack_require__(0); -var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames); - -// CONCATENATED MODULE: ./src/scripts/templates.js - - -var TEMPLATES = { - containerOuter: function containerOuter(globalClasses, direction, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { - var tabIndex = isSelectOneElement ? 'tabindex="0"' : ''; - var role = isSelectElement ? 'role="listbox"' : ''; - var ariaAutoComplete = ''; - - if (isSelectElement && searchEnabled) { - role = 'role="combobox"'; - ariaAutoComplete = 'aria-autocomplete="list"'; - } - - return strToEl("\n \n \n "); - }, - containerInner: function containerInner(globalClasses) { - return strToEl("\n
\n "); - }, - itemList: function itemList(globalClasses, isSelectOneElement) { - var _classNames; - - var localClasses = classnames_default()(globalClasses.list, (_classNames = {}, _classNames[globalClasses.listSingle] = isSelectOneElement, _classNames[globalClasses.listItems] = !isSelectOneElement, _classNames)); - return strToEl("\n
\n "); - }, - placeholder: function placeholder(globalClasses, value) { - return strToEl("\n
\n " + value + "\n
\n "); - }, - item: function item(globalClasses, data, removeItemButton) { - var _classNames2; - - var ariaSelected = data.active ? 'aria-selected="true"' : ''; - var ariaDisabled = data.disabled ? 'aria-disabled="true"' : ''; - var localClasses = classnames_default()(globalClasses.item, (_classNames2 = {}, _classNames2[globalClasses.highlightedState] = data.highlighted, _classNames2[globalClasses.itemSelectable] = !data.highlighted, _classNames2[globalClasses.placeholder] = data.placeholder, _classNames2)); - - if (removeItemButton) { - var _classNames3; - - localClasses = classnames_default()(globalClasses.item, (_classNames3 = {}, _classNames3[globalClasses.highlightedState] = data.highlighted, _classNames3[globalClasses.itemSelectable] = !data.disabled, _classNames3[globalClasses.placeholder] = data.placeholder, _classNames3)); - return strToEl("\n \n " + data.label + "\n Remove item\n \n \n "); - } - - return strToEl("\n \n " + data.label + "\n \n "); - }, - choiceList: function choiceList(globalClasses, isSelectOneElement) { - var ariaMultiSelectable = !isSelectOneElement ? 'aria-multiselectable="true"' : ''; - return strToEl("\n \n \n "); - }, - choiceGroup: function choiceGroup(globalClasses, data) { - var _classNames4; - - var ariaDisabled = data.disabled ? 'aria-disabled="true"' : ''; - var localClasses = classnames_default()(globalClasses.group, (_classNames4 = {}, _classNames4[globalClasses.itemDisabled] = data.disabled, _classNames4)); - return strToEl("\n \n
" + data.value + "
\n \n "); - }, - choice: function choice(globalClasses, data, itemSelectText) { - var _classNames5; - - var role = data.groupId > 0 ? 'role="treeitem"' : 'role="option"'; - var localClasses = classnames_default()(globalClasses.item, globalClasses.itemChoice, (_classNames5 = {}, _classNames5[globalClasses.itemDisabled] = data.disabled, _classNames5[globalClasses.itemSelectable] = !data.disabled, _classNames5[globalClasses.placeholder] = data.placeholder, _classNames5)); - return strToEl("\n \n " + data.label + "\n \n "); - }, - input: function input(globalClasses, placeholderValue) { - var localClasses = classnames_default()(globalClasses.input, globalClasses.inputCloned); - return strToEl("\n \n "); - }, - dropdown: function dropdown(globalClasses) { - var localClasses = classnames_default()(globalClasses.list, globalClasses.listDropdown); - return strToEl("\n \n \n "); - }, - notice: function notice(globalClasses, label, type) { - var _classNames6; - - if (type === void 0) { - type = ''; - } - - var localClasses = classnames_default()(globalClasses.item, globalClasses.itemChoice, (_classNames6 = {}, _classNames6[globalClasses.noResults] = type === 'no-results', _classNames6[globalClasses.noChoices] = type === 'no-choices', _classNames6)); - return strToEl("\n
\n " + label + "\n
\n "); - }, - option: function option(data) { - return strToEl("\n \n "); - } -}; -/* harmony default export */ var templates = (TEMPLATES); -// CONCATENATED MODULE: ./src/scripts/actions/choices.js - -var choices_addChoice = function addChoice(_ref) { - var value = _ref.value, - label = _ref.label, - id = _ref.id, - groupId = _ref.groupId, - disabled = _ref.disabled, - elementId = _ref.elementId, - customProperties = _ref.customProperties, - placeholder = _ref.placeholder, - keyCode = _ref.keyCode; - return { - type: ACTION_TYPES.ADD_CHOICE, - value: value, - label: label, - id: id, - groupId: groupId, - disabled: disabled, - elementId: elementId, - customProperties: customProperties, - placeholder: placeholder, - keyCode: keyCode - }; -}; -var choices_filterChoices = function filterChoices(results) { - return { - type: ACTION_TYPES.FILTER_CHOICES, - results: results - }; -}; -var choices_activateChoices = function activateChoices(active) { - if (active === void 0) { - active = true; - } - - return { - type: ACTION_TYPES.ACTIVATE_CHOICES, - active: active - }; -}; -var choices_clearChoices = function clearChoices() { - return { - type: ACTION_TYPES.CLEAR_CHOICES - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/items.js - -var items_addItem = function addItem(_ref) { - var value = _ref.value, - label = _ref.label, - id = _ref.id, - choiceId = _ref.choiceId, - groupId = _ref.groupId, - customProperties = _ref.customProperties, - placeholder = _ref.placeholder, - keyCode = _ref.keyCode; - return { - type: ACTION_TYPES.ADD_ITEM, - value: value, - label: label, - id: id, - choiceId: choiceId, - groupId: groupId, - customProperties: customProperties, - placeholder: placeholder, - keyCode: keyCode - }; -}; -var items_removeItem = function removeItem(id, choiceId) { - return { - type: ACTION_TYPES.REMOVE_ITEM, - id: id, - choiceId: choiceId - }; -}; -var items_highlightItem = function highlightItem(id, highlighted) { - return { - type: ACTION_TYPES.HIGHLIGHT_ITEM, - id: id, - highlighted: highlighted - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/groups.js - -/* eslint-disable import/prefer-default-export */ - -var groups_addGroup = function addGroup(value, id, active, disabled) { - return { - type: ACTION_TYPES.ADD_GROUP, - value: value, - id: id, - active: active, - disabled: disabled - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/misc.js -var clearAll = function clearAll() { - return { - type: 'CLEAR_ALL' - }; -}; -var resetTo = function resetTo(state) { - return { - type: 'RESET_TO', - state: state - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/general.js -/* eslint-disable import/prefer-default-export */ -var setIsLoading = function setIsLoading(isLoading) { - return { - type: 'SET_IS_LOADING', - isLoading: isLoading - }; -}; -// CONCATENATED MODULE: ./src/scripts/choices.js - - - - - - - - - - - - - -/** - * Choices - * @author Josh Johnson - */ - -var choices_Choices = -/*#__PURE__*/ -function () { - function Choices(element, userConfig) { - var _this = this; - - if (element === void 0) { - element = '[data-choice]'; - } - - if (userConfig === void 0) { - userConfig = {}; - } - - if (isType('String', element)) { - var elements = Array.from(document.querySelectorAll(element)); // If there are multiple elements, create a new instance - // for each element besides the first one (as that already has an instance) - - if (elements.length > 1) { - return this._generateInstances(elements, userConfig); - } - } - - this.config = cjs_default.a.all([DEFAULT_CONFIG, Choices.userDefaults, userConfig], // When merging array configs, replace with a copy of the userConfig array, - // instead of concatenating with the default array - { - arrayMerge: function arrayMerge(destinationArray, sourceArray) { - return [].concat(sourceArray); - } - }); - var invalidConfigOptions = diff(this.config, DEFAULT_CONFIG); - - if (invalidConfigOptions.length) { - console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', ')); - } - - if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) { - this.config.renderSelectedChoices = 'auto'; - } // Retrieve triggering element (i.e. element with 'data-choice' trigger) - - - var passedElement = isType('String', element) ? document.querySelector(element) : element; - - if (!passedElement) { - if (!this.config.silent) { - console.error('Could not find passed element or passed element was of an invalid type'); - } - - return; - } - - this._isTextElement = passedElement.type === 'text'; - this._isSelectOneElement = passedElement.type === 'select-one'; - this._isSelectMultipleElement = passedElement.type === 'select-multiple'; - this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement; - - if (this._isTextElement) { - this.passedElement = new WrappedInput({ - element: passedElement, - classNames: this.config.classNames, - delimiter: this.config.delimiter - }); - } else if (this._isSelectElement) { - this.passedElement = new WrappedSelect({ - element: passedElement, - classNames: this.config.classNames, - template: function template(data) { - return _this.config.templates.option(data); - } - }); - } - - if (!this.passedElement) { - return console.error('Passed element was of an invalid type'); - } - - this.initialised = false; - this._store = new store_Store(this.render); - this._initialState = {}; - this._currentState = {}; - this._prevState = {}; - this._currentValue = ''; - this._canSearch = this.config.searchEnabled; - this._isScrollingOnIe = false; - this._highlightPosition = 0; - this._wasTap = true; - this._placeholderValue = this._generatePlaceholderValue(); - this._baseId = generateId(this.passedElement.element, 'choices-'); - this._direction = this.passedElement.element.getAttribute('dir') || 'ltr'; - this._idNames = { - itemChoice: 'item-choice' - }; // Assign preset choices from passed object - - this._presetChoices = this.config.choices; // Assign preset items from passed object first - - this._presetItems = this.config.items; // Then add any values passed from attribute - - if (this.passedElement.value) { - this._presetItems = this._presetItems.concat(this.passedElement.value.split(this.config.delimiter)); - } - - this._render = this._render.bind(this); - this._onFocus = this._onFocus.bind(this); - this._onBlur = this._onBlur.bind(this); - this._onKeyUp = this._onKeyUp.bind(this); - this._onKeyDown = this._onKeyDown.bind(this); - this._onClick = this._onClick.bind(this); - this._onTouchMove = this._onTouchMove.bind(this); - this._onTouchEnd = this._onTouchEnd.bind(this); - this._onMouseDown = this._onMouseDown.bind(this); - this._onMouseOver = this._onMouseOver.bind(this); - this._onFormReset = this._onFormReset.bind(this); - this._onAKey = this._onAKey.bind(this); - this._onEnterKey = this._onEnterKey.bind(this); - this._onEscapeKey = this._onEscapeKey.bind(this); - this._onDirectionKey = this._onDirectionKey.bind(this); - this._onDeleteKey = this._onDeleteKey.bind(this); - - if (!this.config.silent) { - if (this.config.shouldSortItems === true && this._isSelectOneElement) { - console.warn("shouldSortElements: Type of passed element is 'select-one', falling back to false."); - } // If element has already been initialised with Choices, fail silently - - - if (this.passedElement.element.getAttribute('data-choice') === 'active') { - console.warn('Trying to initialise Choices on element already initialised'); - } - } // Let's go - - - this.init(); - } - /* ======================================== - = Public functions = - ======================================== */ - - - var _proto = Choices.prototype; - - _proto.init = function init() { - if (this.initialised) { - return; - } - - this._createTemplates(); - - this._createElements(); - - this._createStructure(); // Set initial state (We need to clone the state because some reducers - // modify the inner objects properties in the state) 🤢 - - - this._initialState = cloneObject(this._store.state); - - this._store.subscribe(this._render); - - this._render(); - - this._addEventListeners(); - - var shouldDisable = !this.config.addItems || this.passedElement.element.hasAttribute('disabled'); - - if (shouldDisable) { - this.disable(); - } - - this.initialised = true; - var callbackOnInit = this.config.callbackOnInit; // Run callback if it is a function - - if (callbackOnInit && isType('Function', callbackOnInit)) { - callbackOnInit.call(this); - } - }; - - _proto.destroy = function destroy() { - if (!this.initialised) { - return; - } - - this._removeEventListeners(); - - this.passedElement.reveal(); - this.containerOuter.unwrap(this.passedElement.element); - - if (this._isSelectElement) { - this.passedElement.options = this._presetChoices; - } - - this.clearStore(); - this.config.templates = null; - this.initialised = false; - }; - - _proto.enable = function enable() { - if (this.passedElement.isDisabled) { - this.passedElement.enable(); - } - - if (this.containerOuter.isDisabled) { - this._addEventListeners(); - - this.input.enable(); - this.containerOuter.enable(); - } - - return this; - }; - - _proto.disable = function disable() { - if (!this.passedElement.isDisabled) { - this.passedElement.disable(); - } - - if (!this.containerOuter.isDisabled) { - this._removeEventListeners(); - - this.input.disable(); - this.containerOuter.disable(); - } - - return this; - }; - - _proto.highlightItem = function highlightItem(item, runEvent) { - if (runEvent === void 0) { - runEvent = true; - } - - if (!item) { - return this; - } - - var id = item.id, - _item$groupId = item.groupId, - groupId = _item$groupId === void 0 ? -1 : _item$groupId, - _item$value = item.value, - value = _item$value === void 0 ? '' : _item$value, - _item$label = item.label, - label = _item$label === void 0 ? '' : _item$label; - var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - - this._store.dispatch(items_highlightItem(id, true)); - - if (runEvent) { - this.passedElement.triggerEvent(EVENTS.highlightItem, { - id: id, - value: value, - label: label, - groupValue: group && group.value ? group.value : null - }); - } - - return this; - }; - - _proto.unhighlightItem = function unhighlightItem(item) { - if (!item) { - return this; - } - - var id = item.id, - _item$groupId2 = item.groupId, - groupId = _item$groupId2 === void 0 ? -1 : _item$groupId2, - _item$value2 = item.value, - value = _item$value2 === void 0 ? '' : _item$value2, - _item$label2 = item.label, - label = _item$label2 === void 0 ? '' : _item$label2; - var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - - this._store.dispatch(items_highlightItem(id, false)); - - this.passedElement.triggerEvent(EVENTS.highlightItem, { - id: id, - value: value, - label: label, - groupValue: group && group.value ? group.value : null - }); - return this; - }; - - _proto.highlightAll = function highlightAll() { - var _this2 = this; - - this._store.items.forEach(function (item) { - return _this2.highlightItem(item); - }); - - return this; - }; - - _proto.unhighlightAll = function unhighlightAll() { - var _this3 = this; - - this._store.items.forEach(function (item) { - return _this3.unhighlightItem(item); - }); - - return this; - }; - - _proto.removeActiveItemsByValue = function removeActiveItemsByValue(value) { - var _this4 = this; - - this._store.activeItems.filter(function (item) { - return item.value === value; - }).forEach(function (item) { - return _this4._removeItem(item); - }); - - return this; - }; - - _proto.removeActiveItems = function removeActiveItems(excludedId) { - var _this5 = this; - - this._store.activeItems.filter(function (_ref) { - var id = _ref.id; - return id !== excludedId; - }).forEach(function (item) { - return _this5._removeItem(item); - }); - - return this; - }; - - _proto.removeHighlightedItems = function removeHighlightedItems(runEvent) { - var _this6 = this; - - if (runEvent === void 0) { - runEvent = false; - } - - this._store.highlightedActiveItems.forEach(function (item) { - _this6._removeItem(item); // If this action was performed by the user - // trigger the event - - - if (runEvent) { - _this6._triggerChange(item.value); - } - }); - - return this; - }; - - _proto.showDropdown = function showDropdown(preventInputFocus) { - var _this7 = this; - - if (this.dropdown.isActive) { - return this; - } - - requestAnimationFrame(function () { - _this7.dropdown.show(); - - _this7.containerOuter.open(_this7.dropdown.distanceFromTopWindow()); - - if (!preventInputFocus && _this7._canSearch) { - _this7.input.focus(); - } - - _this7.passedElement.triggerEvent(EVENTS.showDropdown, {}); - }); - return this; - }; - - _proto.hideDropdown = function hideDropdown(preventInputBlur) { - var _this8 = this; - - if (!this.dropdown.isActive) { - return this; - } - - requestAnimationFrame(function () { - _this8.dropdown.hide(); - - _this8.containerOuter.close(); - - if (!preventInputBlur && _this8._canSearch) { - _this8.input.removeActiveDescendant(); - - _this8.input.blur(); - } - - _this8.passedElement.triggerEvent(EVENTS.hideDropdown, {}); - }); - return this; - }; - - _proto.getValue = function getValue(valueOnly) { - if (valueOnly === void 0) { - valueOnly = false; - } - - var values = this._store.activeItems.reduce(function (selectedItems, item) { - var itemValue = valueOnly ? item.value : item; - selectedItems.push(itemValue); - return selectedItems; - }, []); - - return this._isSelectOneElement ? values[0] : values; - }; - - _proto.setValue = function setValue(args) { - var _this9 = this; - - if (!this.initialised) { - return this; - } - - [].concat(args).forEach(function (value) { - return _this9._setChoiceOrItem(value); - }); - return this; - }; - - _proto.setChoiceByValue = function setChoiceByValue(value) { - var _this10 = this; - - if (!this.initialised || this._isTextElement) { - return this; - } // If only one value has been passed, convert to array - - - var choiceValue = isType('Array', value) ? value : [value]; // Loop through each value and - - choiceValue.forEach(function (val) { - return _this10._findAndSelectChoiceByValue(val); - }); - return this; - }; - - _proto.setChoices = function setChoices(choices, value, label, replaceChoices) { - var _this11 = this; - - if (choices === void 0) { - choices = []; - } - - if (value === void 0) { - value = ''; - } - - if (label === void 0) { - label = ''; - } - - if (replaceChoices === void 0) { - replaceChoices = false; - } - - if (!this._isSelectElement || !value) { - return this; - } // Clear choices if needed - - - if (replaceChoices) { - this.clearChoices(); - } - - this.containerOuter.removeLoadingState(); - - var addGroupsAndChoices = function addGroupsAndChoices(groupOrChoice) { - if (groupOrChoice.choices) { - _this11._addGroup({ - group: groupOrChoice, - id: groupOrChoice.id || null, - valueKey: value, - labelKey: label - }); - } else { - _this11._addChoice({ - value: groupOrChoice[value], - label: groupOrChoice[label], - isSelected: groupOrChoice.selected, - isDisabled: groupOrChoice.disabled, - customProperties: groupOrChoice.customProperties, - placeholder: groupOrChoice.placeholder - }); - } - }; - - this._setLoading(true); - - choices.forEach(addGroupsAndChoices); - - this._setLoading(false); - - return this; - }; - - _proto.clearChoices = function clearChoices() { - this._store.dispatch(choices_clearChoices()); - }; - - _proto.clearStore = function clearStore() { - this._store.dispatch(clearAll()); - - return this; - }; - - _proto.clearInput = function clearInput() { - var shouldSetInputWidth = !this._isSelectOneElement; - this.input.clear(shouldSetInputWidth); - - if (!this._isTextElement && this._canSearch) { - this._isSearching = false; - - this._store.dispatch(choices_activateChoices(true)); - } - - return this; - }; - - _proto.ajax = function ajax(fn) { - var _this12 = this; - - if (!this.initialised || !this._isSelectElement || !fn) { - return this; - } - - requestAnimationFrame(function () { - return _this12._handleLoadingState(true); - }); - fn(this._ajaxCallback()); - return this; - } - /* ===== End of Public functions ====== */ - - /* ============================================= - = Private functions = - ============================================= */ - ; - - _proto._render = function _render() { - if (this._store.isLoading()) { - return; - } - - this._currentState = this._store.state; - var stateChanged = this._currentState.choices !== this._prevState.choices || this._currentState.groups !== this._prevState.groups || this._currentState.items !== this._prevState.items; - var shouldRenderChoices = this._isSelectElement; - var shouldRenderItems = this._currentState.items !== this._prevState.items; - - if (!stateChanged) { - return; - } - - if (shouldRenderChoices) { - this._renderChoices(); - } - - if (shouldRenderItems) { - this._renderItems(); - } - - this._prevState = this._currentState; - }; - - _proto._renderChoices = function _renderChoices() { - var _this13 = this; - - var _this$_store = this._store, - activeGroups = _this$_store.activeGroups, - activeChoices = _this$_store.activeChoices; - var choiceListFragment = document.createDocumentFragment(); - this.choiceList.clear(); - - if (this.config.resetScrollPosition) { - requestAnimationFrame(function () { - return _this13.choiceList.scrollToTop(); - }); - } // If we have grouped options - - - if (activeGroups.length >= 1 && !this._isSearching) { - // If we have a placeholder choice along with groups - var activePlaceholders = activeChoices.filter(function (activeChoice) { - return activeChoice.placeholder === true && activeChoice.groupId === -1; - }); - - if (activePlaceholders.length >= 1) { - choiceListFragment = this._createChoicesFragment(activePlaceholders, choiceListFragment); - } - - choiceListFragment = this._createGroupsFragment(activeGroups, activeChoices, choiceListFragment); - } else if (activeChoices.length >= 1) { - choiceListFragment = this._createChoicesFragment(activeChoices, choiceListFragment); - } // If we have choices to show - - - if (choiceListFragment.childNodes && choiceListFragment.childNodes.length > 0) { - var activeItems = this._store.activeItems; - - var canAddItem = this._canAddItem(activeItems, this.input.value); // ...and we can select them - - - if (canAddItem.response) { - // ...append them and highlight the first choice - this.choiceList.append(choiceListFragment); - - this._highlightChoice(); - } else { - // ...otherwise show a notice - this.choiceList.append(this._getTemplate('notice', canAddItem.notice)); - } - } else { - // Otherwise show a notice - var dropdownItem; - var notice; - - if (this._isSearching) { - notice = isType('Function', this.config.noResultsText) ? this.config.noResultsText() : this.config.noResultsText; - dropdownItem = this._getTemplate('notice', notice, 'no-results'); - } else { - notice = isType('Function', this.config.noChoicesText) ? this.config.noChoicesText() : this.config.noChoicesText; - dropdownItem = this._getTemplate('notice', notice, 'no-choices'); - } - - this.choiceList.append(dropdownItem); - } - }; - - _proto._renderItems = function _renderItems() { - var activeItems = this._store.activeItems || []; - this.itemList.clear(); // Create a fragment to store our list items - // (so we don't have to update the DOM for each item) - - var itemListFragment = this._createItemsFragment(activeItems); // If we have items to add, append them - - - if (itemListFragment.childNodes) { - this.itemList.append(itemListFragment); - } - }; - - _proto._createGroupsFragment = function _createGroupsFragment(groups, choices, fragment) { - var _this14 = this; - - var groupFragment = fragment || document.createDocumentFragment(); - - var getGroupChoices = function getGroupChoices(group) { - return choices.filter(function (choice) { - if (_this14._isSelectOneElement) { - return choice.groupId === group.id; - } - - return choice.groupId === group.id && (_this14.config.renderSelectedChoices === 'always' || !choice.selected); - }); - }; // If sorting is enabled, filter groups - - - if (this.config.shouldSort) { - groups.sort(this.config.sortFn); - } - - groups.forEach(function (group) { - var groupChoices = getGroupChoices(group); - - if (groupChoices.length >= 1) { - var dropdownGroup = _this14._getTemplate('choiceGroup', group); - - groupFragment.appendChild(dropdownGroup); - - _this14._createChoicesFragment(groupChoices, groupFragment, true); - } - }); - return groupFragment; - }; - - _proto._createChoicesFragment = function _createChoicesFragment(choices, fragment, withinGroup) { - var _this15 = this; - - if (withinGroup === void 0) { - withinGroup = false; - } - - // Create a fragment to store our list items (so we don't have to update the DOM for each item) - var choicesFragment = fragment || document.createDocumentFragment(); - var _this$config = this.config, - renderSelectedChoices = _this$config.renderSelectedChoices, - searchResultLimit = _this$config.searchResultLimit, - renderChoiceLimit = _this$config.renderChoiceLimit; - var filter = this._isSearching ? sortByScore : this.config.sortFn; - - var appendChoice = function appendChoice(choice) { - var shouldRender = renderSelectedChoices === 'auto' ? _this15._isSelectOneElement || !choice.selected : true; - - if (shouldRender) { - var dropdownItem = _this15._getTemplate('choice', choice, _this15.config.itemSelectText); - - choicesFragment.appendChild(dropdownItem); - } - }; - - var rendererableChoices = choices; - - if (renderSelectedChoices === 'auto' && !this._isSelectOneElement) { - rendererableChoices = choices.filter(function (choice) { - return !choice.selected; - }); - } // Split array into placeholders and "normal" choices - - - var _rendererableChoices$ = rendererableChoices.reduce(function (acc, choice) { - if (choice.placeholder) { - acc.placeholderChoices.push(choice); - } else { - acc.normalChoices.push(choice); - } - - return acc; - }, { - placeholderChoices: [], - normalChoices: [] - }), - placeholderChoices = _rendererableChoices$.placeholderChoices, - normalChoices = _rendererableChoices$.normalChoices; // If sorting is enabled or the user is searching, filter choices - - - if (this.config.shouldSort || this._isSearching) { - normalChoices.sort(filter); - } - - var choiceLimit = rendererableChoices.length; // Prepend placeholeder - - var sortedChoices = [].concat(placeholderChoices, normalChoices); - - if (this._isSearching) { - choiceLimit = searchResultLimit; - } else if (renderChoiceLimit > 0 && !withinGroup) { - choiceLimit = renderChoiceLimit; - } // Add each choice to dropdown within range - - - for (var i = 0; i < choiceLimit; i += 1) { - if (sortedChoices[i]) { - appendChoice(sortedChoices[i]); - } - } - - return choicesFragment; - }; - - _proto._createItemsFragment = function _createItemsFragment(items, fragment) { - var _this16 = this; - - if (fragment === void 0) { - fragment = null; - } - - // Create fragment to add elements to - var _this$config2 = this.config, - shouldSortItems = _this$config2.shouldSortItems, - sortFn = _this$config2.sortFn, - removeItemButton = _this$config2.removeItemButton; - var itemListFragment = fragment || document.createDocumentFragment(); // If sorting is enabled, filter items - - if (shouldSortItems && !this._isSelectOneElement) { - items.sort(sortFn); - } - - if (this._isTextElement) { - // Update the value of the hidden input - this.passedElement.value = items; - } else { - // Update the options of the hidden input - this.passedElement.options = items; - } - - var addItemToFragment = function addItemToFragment(item) { - // Create new list element - var listItem = _this16._getTemplate('item', item, removeItemButton); // Append it to list - - - itemListFragment.appendChild(listItem); - }; // Add each list item to list - - - items.forEach(function (item) { - return addItemToFragment(item); - }); - return itemListFragment; - }; - - _proto._triggerChange = function _triggerChange(value) { - if (value === undefined || value === null) { - return; - } - - this.passedElement.triggerEvent(EVENTS.change, { - value: value - }); - }; - - _proto._selectPlaceholderChoice = function _selectPlaceholderChoice() { - var placeholderChoice = this._store.placeholderChoice; - - if (placeholderChoice) { - this._addItem({ - value: placeholderChoice.value, - label: placeholderChoice.label, - choiceId: placeholderChoice.id, - groupId: placeholderChoice.groupId, - placeholder: placeholderChoice.placeholder - }); - - this._triggerChange(placeholderChoice.value); - } - }; - - _proto._handleButtonAction = function _handleButtonAction(activeItems, element) { - if (!activeItems || !element || !this.config.removeItems || !this.config.removeItemButton) { - return; - } - - var itemId = element.parentNode.getAttribute('data-id'); - var itemToRemove = activeItems.find(function (item) { - return item.id === parseInt(itemId, 10); - }); // Remove item associated with button - - this._removeItem(itemToRemove); - - this._triggerChange(itemToRemove.value); - - if (this._isSelectOneElement) { - this._selectPlaceholderChoice(); - } - }; - - _proto._handleItemAction = function _handleItemAction(activeItems, element, hasShiftKey) { - var _this17 = this; - - if (hasShiftKey === void 0) { - hasShiftKey = false; - } - - if (!activeItems || !element || !this.config.removeItems || this._isSelectOneElement) { - return; - } - - var passedId = element.getAttribute('data-id'); // We only want to select one item with a click - // so we deselect any items that aren't the target - // unless shift is being pressed - - activeItems.forEach(function (item) { - if (item.id === parseInt(passedId, 10) && !item.highlighted) { - _this17.highlightItem(item); - } else if (!hasShiftKey && item.highlighted) { - _this17.unhighlightItem(item); - } - }); // Focus input as without focus, a user cannot do anything with a - // highlighted item - - this.input.focus(); - }; - - _proto._handleChoiceAction = function _handleChoiceAction(activeItems, element) { - if (!activeItems || !element) { - return; - } // If we are clicking on an option - - - var id = element.getAttribute('data-id'); - - var choice = this._store.getChoiceById(id); - - var passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : null; - var hasActiveDropdown = this.dropdown.isActive; // Update choice keyCode - - choice.keyCode = passedKeyCode; - this.passedElement.triggerEvent(EVENTS.choice, { - choice: choice - }); - - if (choice && !choice.selected && !choice.disabled) { - var canAddItem = this._canAddItem(activeItems, choice.value); - - if (canAddItem.response) { - this._addItem({ - value: choice.value, - label: choice.label, - choiceId: choice.id, - groupId: choice.groupId, - customProperties: choice.customProperties, - placeholder: choice.placeholder, - keyCode: choice.keyCode - }); - - this._triggerChange(choice.value); - } - } - - this.clearInput(); // We wont to close the dropdown if we are dealing with a single select box - - if (hasActiveDropdown && this._isSelectOneElement) { - this.hideDropdown(true); - this.containerOuter.focus(); - } - }; - - _proto._handleBackspace = function _handleBackspace(activeItems) { - if (!this.config.removeItems || !activeItems) { - return; - } - - var lastItem = activeItems[activeItems.length - 1]; - var hasHighlightedItems = activeItems.some(function (item) { - return item.highlighted; - }); // If editing the last item is allowed and there are not other selected items, - // we can edit the item value. Otherwise if we can remove items, remove all selected items - - if (this.config.editItems && !hasHighlightedItems && lastItem) { - this.input.value = lastItem.value; - this.input.setWidth(); - - this._removeItem(lastItem); - - this._triggerChange(lastItem.value); - } else { - if (!hasHighlightedItems) { - // Highlight last item if none already highlighted - this.highlightItem(lastItem, false); - } - - this.removeHighlightedItems(true); - } - }; - - _proto._setLoading = function _setLoading(isLoading) { - this._store.dispatch(setIsLoading(isLoading)); - }; - - _proto._handleLoadingState = function _handleLoadingState(setLoading) { - if (setLoading === void 0) { - setLoading = true; - } - - var placeholderItem = this.itemList.getChild("." + this.config.classNames.placeholder); - - if (setLoading) { - this.disable(); - this.containerOuter.addLoadingState(); - - if (this._isSelectOneElement) { - if (!placeholderItem) { - placeholderItem = this._getTemplate('placeholder', this.config.loadingText); - this.itemList.append(placeholderItem); - } else { - placeholderItem.innerHTML = this.config.loadingText; - } - } else { - this.input.placeholder = this.config.loadingText; - } - } else { - this.enable(); - this.containerOuter.removeLoadingState(); - - if (this._isSelectOneElement) { - placeholderItem.innerHTML = this._placeholderValue || ''; - } else { - this.input.placeholder = this._placeholderValue || ''; - } - } - }; - - _proto._handleSearch = function _handleSearch(value) { - if (!value || !this.input.isFocussed) { - return; - } - - var choices = this._store.choices; - var _this$config3 = this.config, - searchFloor = _this$config3.searchFloor, - searchChoices = _this$config3.searchChoices; - var hasUnactiveChoices = choices.some(function (option) { - return !option.active; - }); // Check that we have a value to search and the input was an alphanumeric character - - if (value && value.length >= searchFloor) { - var resultCount = searchChoices ? this._searchChoices(value) : 0; // Trigger search event - - this.passedElement.triggerEvent(EVENTS.search, { - value: value, - resultCount: resultCount - }); - } else if (hasUnactiveChoices) { - // Otherwise reset choices to active - this._isSearching = false; - - this._store.dispatch(choices_activateChoices(true)); - } - }; - - _proto._canAddItem = function _canAddItem(activeItems, value) { - var canAddItem = true; - var notice = isType('Function', this.config.addItemText) ? this.config.addItemText(value) : this.config.addItemText; - - if (!this._isSelectOneElement) { - var isDuplicateValue = existsInArray(activeItems, value); - - if (this.config.maxItemCount > 0 && this.config.maxItemCount <= activeItems.length) { - // If there is a max entry limit and we have reached that limit - // don't update - canAddItem = false; - notice = isType('Function', this.config.maxItemText) ? this.config.maxItemText(this.config.maxItemCount) : this.config.maxItemText; - } - - if (!this.config.duplicateItemsAllowed && isDuplicateValue && canAddItem) { - canAddItem = false; - notice = isType('Function', this.config.uniqueItemText) ? this.config.uniqueItemText(value) : this.config.uniqueItemText; - } - - if (this._isTextElement && this.config.addItems && canAddItem && isType('Function', this.config.addItemFilterFn) && !this.config.addItemFilterFn(value)) { - canAddItem = false; - notice = isType('Function', this.config.customAddItemText) ? this.config.customAddItemText(value) : this.config.customAddItemText; - } - } - - return { - response: canAddItem, - notice: notice - }; - }; - - _proto._ajaxCallback = function _ajaxCallback() { - var _this18 = this; - - return function (results, value, label) { - if (!results || !value) { - return; - } - - var parsedResults = isType('Object', results) ? [results] : results; - - if (parsedResults && isType('Array', parsedResults) && parsedResults.length) { - // Remove loading states/text - _this18._handleLoadingState(false); - - _this18._setLoading(true); // Add each result as a choice - - - parsedResults.forEach(function (result) { - if (result.choices) { - _this18._addGroup({ - group: result, - id: result.id || null, - valueKey: value, - labelKey: label - }); - } else { - _this18._addChoice({ - value: fetchFromObject(result, value), - label: fetchFromObject(result, label), - isSelected: result.selected, - isDisabled: result.disabled, - customProperties: result.customProperties, - placeholder: result.placeholder - }); - } - }); - - _this18._setLoading(false); - - if (_this18._isSelectOneElement) { - _this18._selectPlaceholderChoice(); - } - } else { - // No results, remove loading state - _this18._handleLoadingState(false); - } - }; - }; - - _proto._searchChoices = function _searchChoices(value) { - var newValue = isType('String', value) ? value.trim() : value; - var currentValue = isType('String', this._currentValue) ? this._currentValue.trim() : this._currentValue; - - if (newValue.length < 1 && newValue === currentValue + " ") { - return 0; - } // If new value matches the desired length and is not the same as the current value with a space - - - var haystack = this._store.searchableChoices; - var needle = newValue; - var keys = [].concat(this.config.searchFields); - var options = Object.assign(this.config.fuseOptions, { - keys: keys - }); - var fuse = new fuse_default.a(haystack, options); - var results = fuse.search(needle); - this._currentValue = newValue; - this._highlightPosition = 0; - this._isSearching = true; - - this._store.dispatch(choices_filterChoices(results)); - - return results.length; - }; - - _proto._addEventListeners = function _addEventListeners() { - window.delegateEvent.add('keyup', this._onKeyUp); - window.delegateEvent.add('keydown', this._onKeyDown); - window.delegateEvent.add('click', this._onClick); - window.delegateEvent.add('touchmove', this._onTouchMove); - window.delegateEvent.add('touchend', this._onTouchEnd); - window.delegateEvent.add('mousedown', this._onMouseDown); - window.delegateEvent.add('mouseover', this._onMouseOver); - - if (this._isSelectOneElement) { - this.containerOuter.element.addEventListener('focus', this._onFocus); - this.containerOuter.element.addEventListener('blur', this._onBlur); - } - - this.input.element.addEventListener('focus', this._onFocus); - this.input.element.addEventListener('blur', this._onBlur); - - if (this.input.element.form) { - this.input.element.form.addEventListener('reset', this._onFormReset); - } - - this.input.addEventListeners(); - }; - - _proto._removeEventListeners = function _removeEventListeners() { - window.delegateEvent.remove('keyup', this._onKeyUp); - window.delegateEvent.remove('keydown', this._onKeyDown); - window.delegateEvent.remove('click', this._onClick); - window.delegateEvent.remove('touchmove', this._onTouchMove); - window.delegateEvent.remove('touchend', this._onTouchEnd); - window.delegateEvent.remove('mousedown', this._onMouseDown); - window.delegateEvent.remove('mouseover', this._onMouseOver); - - if (this._isSelectOneElement) { - this.containerOuter.element.removeEventListener('focus', this._onFocus); - this.containerOuter.element.removeEventListener('blur', this._onBlur); - } - - this.input.element.removeEventListener('focus', this._onFocus); - this.input.element.removeEventListener('blur', this._onBlur); - - if (this.input.element.form) { - this.input.element.form.removeEventListener('reset', this._onFormReset); - } - - this.input.removeEventListeners(); - }; - - _proto._onKeyDown = function _onKeyDown(event) { - var _keyDownActions; - - var target = event.target, - keyCode = event.keyCode, - ctrlKey = event.ctrlKey, - metaKey = event.metaKey; - - if (target !== this.input.element && !this.containerOuter.element.contains(target)) { - return; - } - - var activeItems = this._store.activeItems; - var hasFocusedInput = this.input.isFocussed; - var hasActiveDropdown = this.dropdown.isActive; - var hasItems = this.itemList.hasChildren; - var keyString = String.fromCharCode(keyCode); - var BACK_KEY = KEY_CODES.BACK_KEY, - DELETE_KEY = KEY_CODES.DELETE_KEY, - ENTER_KEY = KEY_CODES.ENTER_KEY, - A_KEY = KEY_CODES.A_KEY, - ESC_KEY = KEY_CODES.ESC_KEY, - UP_KEY = KEY_CODES.UP_KEY, - DOWN_KEY = KEY_CODES.DOWN_KEY, - PAGE_UP_KEY = KEY_CODES.PAGE_UP_KEY, - PAGE_DOWN_KEY = KEY_CODES.PAGE_DOWN_KEY; - var hasCtrlDownKeyPressed = ctrlKey || metaKey; // If a user is typing and the dropdown is not active - - if (!this._isTextElement && /[a-zA-Z0-9-_ ]/.test(keyString)) { - this.showDropdown(); - } // Map keys to key actions - - - var keyDownActions = (_keyDownActions = {}, _keyDownActions[A_KEY] = this._onAKey, _keyDownActions[ENTER_KEY] = this._onEnterKey, _keyDownActions[ESC_KEY] = this._onEscapeKey, _keyDownActions[UP_KEY] = this._onDirectionKey, _keyDownActions[PAGE_UP_KEY] = this._onDirectionKey, _keyDownActions[DOWN_KEY] = this._onDirectionKey, _keyDownActions[PAGE_DOWN_KEY] = this._onDirectionKey, _keyDownActions[DELETE_KEY] = this._onDeleteKey, _keyDownActions[BACK_KEY] = this._onDeleteKey, _keyDownActions); // If keycode has a function, run it - - if (keyDownActions[keyCode]) { - keyDownActions[keyCode]({ - event: event, - target: target, - keyCode: keyCode, - metaKey: metaKey, - activeItems: activeItems, - hasFocusedInput: hasFocusedInput, - hasActiveDropdown: hasActiveDropdown, - hasItems: hasItems, - hasCtrlDownKeyPressed: hasCtrlDownKeyPressed - }); - } - }; - - _proto._onKeyUp = function _onKeyUp(_ref2) { - var target = _ref2.target, - keyCode = _ref2.keyCode; - - if (target !== this.input.element) { - return; - } - - var value = this.input.value; - var activeItems = this._store.activeItems; - - var canAddItem = this._canAddItem(activeItems, value); - - var backKey = KEY_CODES.BACK_KEY, - deleteKey = KEY_CODES.DELETE_KEY; // We are typing into a text input and have a value, we want to show a dropdown - // notice. Otherwise hide the dropdown - - if (this._isTextElement) { - var canShowDropdownNotice = canAddItem.notice && value; - - if (canShowDropdownNotice) { - var dropdownItem = this._getTemplate('notice', canAddItem.notice); - - this.dropdown.element.innerHTML = dropdownItem.outerHTML; - this.showDropdown(true); - } else { - this.hideDropdown(true); - } - } else { - var userHasRemovedValue = (keyCode === backKey || keyCode === deleteKey) && !target.value; - var canReactivateChoices = !this._isTextElement && this._isSearching; - var canSearch = this._canSearch && canAddItem.response; - - if (userHasRemovedValue && canReactivateChoices) { - this._isSearching = false; - - this._store.dispatch(choices_activateChoices(true)); - } else if (canSearch) { - this._handleSearch(this.input.value); - } - } - - this._canSearch = this.config.searchEnabled; - }; - - _proto._onAKey = function _onAKey(_ref3) { - var hasItems = _ref3.hasItems, - hasCtrlDownKeyPressed = _ref3.hasCtrlDownKeyPressed; - - // If CTRL + A or CMD + A have been pressed and there are items to select - if (hasCtrlDownKeyPressed && hasItems) { - this._canSearch = false; - var shouldHightlightAll = this.config.removeItems && !this.input.value && this.input.element === document.activeElement; - - if (shouldHightlightAll) { - this.highlightAll(); - } - } - }; - - _proto._onEnterKey = function _onEnterKey(_ref4) { - var event = _ref4.event, - target = _ref4.target, - activeItems = _ref4.activeItems, - hasActiveDropdown = _ref4.hasActiveDropdown; - var enterKey = KEY_CODES.ENTER_KEY; - var targetWasButton = target.hasAttribute('data-button'); - - if (this._isTextElement && target.value) { - var value = this.input.value; - - var canAddItem = this._canAddItem(activeItems, value); - - if (canAddItem.response) { - this.hideDropdown(true); - - this._addItem({ - value: value - }); - - this._triggerChange(value); - - this.clearInput(); - } - } - - if (targetWasButton) { - this._handleButtonAction(activeItems, target); - - event.preventDefault(); - } - - if (hasActiveDropdown) { - var highlightedChoice = this.dropdown.getChild("." + this.config.classNames.highlightedState); - - if (highlightedChoice) { - // add enter keyCode value - if (activeItems[0]) { - activeItems[0].keyCode = enterKey; // eslint-disable-line no-param-reassign - } - - this._handleChoiceAction(activeItems, highlightedChoice); - } - - event.preventDefault(); - } else if (this._isSelectOneElement) { - this.showDropdown(); - event.preventDefault(); - } - }; - - _proto._onEscapeKey = function _onEscapeKey(_ref5) { - var hasActiveDropdown = _ref5.hasActiveDropdown; - - if (hasActiveDropdown) { - this.hideDropdown(true); - this.containerOuter.focus(); - } - }; - - _proto._onDirectionKey = function _onDirectionKey(_ref6) { - var event = _ref6.event, - hasActiveDropdown = _ref6.hasActiveDropdown, - keyCode = _ref6.keyCode, - metaKey = _ref6.metaKey; - var downKey = KEY_CODES.DOWN_KEY, - pageUpKey = KEY_CODES.PAGE_UP_KEY, - pageDownKey = KEY_CODES.PAGE_DOWN_KEY; // If up or down key is pressed, traverse through options - - if (hasActiveDropdown || this._isSelectOneElement) { - this.showDropdown(); - this._canSearch = false; - var directionInt = keyCode === downKey || keyCode === pageDownKey ? 1 : -1; - var skipKey = metaKey || keyCode === pageDownKey || keyCode === pageUpKey; - var selectableChoiceIdentifier = '[data-choice-selectable]'; - var nextEl; - - if (skipKey) { - if (directionInt > 0) { - nextEl = Array.from(this.dropdown.element.querySelectorAll(selectableChoiceIdentifier)).pop(); - } else { - nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); - } - } else { - var currentEl = this.dropdown.element.querySelector("." + this.config.classNames.highlightedState); - - if (currentEl) { - nextEl = getAdjacentEl(currentEl, selectableChoiceIdentifier, directionInt); - } else { - nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); - } - } - - if (nextEl) { - // We prevent default to stop the cursor moving - // when pressing the arrow - if (!isScrolledIntoView(nextEl, this.choiceList.element, directionInt)) { - this.choiceList.scrollToChoice(nextEl, directionInt); - } - - this._highlightChoice(nextEl); - } // Prevent default to maintain cursor position whilst - // traversing dropdown options - - - event.preventDefault(); - } - }; - - _proto._onDeleteKey = function _onDeleteKey(_ref7) { - var event = _ref7.event, - target = _ref7.target, - hasFocusedInput = _ref7.hasFocusedInput, - activeItems = _ref7.activeItems; - - // If backspace or delete key is pressed and the input has no value - if (hasFocusedInput && !target.value && !this._isSelectOneElement) { - this._handleBackspace(activeItems); - - event.preventDefault(); - } - }; - - _proto._onTouchMove = function _onTouchMove() { - if (this._wasTap) { - this._wasTap = false; - } - }; - - _proto._onTouchEnd = function _onTouchEnd(event) { - var _ref8 = event || event.touches[0], - target = _ref8.target; - - var touchWasWithinContainer = this._wasTap && this.containerOuter.element.contains(target); - - if (touchWasWithinContainer) { - var containerWasExactTarget = target === this.containerOuter.element || target === this.containerInner.element; - - if (containerWasExactTarget) { - if (this._isTextElement) { - this.input.focus(); - } else if (this._isSelectMultipleElement) { - this.showDropdown(); - } - } // Prevents focus event firing - - - event.stopPropagation(); - } - - this._wasTap = true; - }; - - _proto._onMouseDown = function _onMouseDown(event) { - var target = event.target, - shiftKey = event.shiftKey; // If we have our mouse down on the scrollbar and are on IE11... - - if (this.choiceList.element.contains(target) && isIE11()) { - this._isScrollingOnIe = true; - } - - if (!this.containerOuter.element.contains(target) || target === this.input.element) { - return; - } - - var activeItems = this._store.activeItems; - var hasShiftKey = shiftKey; - var buttonTarget = findAncestorByAttrName(target, 'data-button'); - var itemTarget = findAncestorByAttrName(target, 'data-item'); - var choiceTarget = findAncestorByAttrName(target, 'data-choice'); - - if (buttonTarget) { - this._handleButtonAction(activeItems, buttonTarget); - } else if (itemTarget) { - this._handleItemAction(activeItems, itemTarget, hasShiftKey); - } else if (choiceTarget) { - this._handleChoiceAction(activeItems, choiceTarget); - } - - event.preventDefault(); - }; - - _proto._onMouseOver = function _onMouseOver(_ref9) { - var target = _ref9.target; - var targetWithinDropdown = target === this.dropdown || this.dropdown.element.contains(target); - var shouldHighlightChoice = targetWithinDropdown && target.hasAttribute('data-choice'); - - if (shouldHighlightChoice) { - this._highlightChoice(target); - } - }; - - _proto._onClick = function _onClick(_ref10) { - var target = _ref10.target; - var clickWasWithinContainer = this.containerOuter.element.contains(target); - - if (clickWasWithinContainer) { - if (!this.dropdown.isActive && !this.containerOuter.isDisabled) { - if (this._isTextElement) { - if (document.activeElement !== this.input.element) { - this.input.focus(); - } - } else { - this.showDropdown(); - this.containerOuter.focus(); - } - } else if (this._isSelectOneElement && target !== this.input.element && !this.dropdown.element.contains(target)) { - this.hideDropdown(); - } - } else { - var hasHighlightedItems = this._store.highlightedActiveItems.length > 0; - - if (hasHighlightedItems) { - this.unhighlightAll(); - } - - this.containerOuter.removeFocusState(); - this.hideDropdown(true); - } - }; - - _proto._onFocus = function _onFocus(_ref11) { - var _this19 = this; - - var target = _ref11.target; - var focusWasWithinContainer = this.containerOuter.element.contains(target); - - if (!focusWasWithinContainer) { - return; - } - - var focusActions = { - text: function text() { - if (target === _this19.input.element) { - _this19.containerOuter.addFocusState(); - } - }, - 'select-one': function selectOne() { - _this19.containerOuter.addFocusState(); - - if (target === _this19.input.element) { - _this19.showDropdown(true); - } - }, - 'select-multiple': function selectMultiple() { - if (target === _this19.input.element) { - _this19.showDropdown(true); // If element is a select box, the focused element is the container and the dropdown - // isn't already open, focus and show dropdown - - - _this19.containerOuter.addFocusState(); - } - } - }; - focusActions[this.passedElement.element.type](); - }; - - _proto._onBlur = function _onBlur(_ref12) { - var _this20 = this; - - var target = _ref12.target; - var blurWasWithinContainer = this.containerOuter.element.contains(target); - - if (blurWasWithinContainer && !this._isScrollingOnIe) { - var activeItems = this._store.activeItems; - var hasHighlightedItems = activeItems.some(function (item) { - return item.highlighted; - }); - var blurActions = { - text: function text() { - if (target === _this20.input.element) { - _this20.containerOuter.removeFocusState(); - - if (hasHighlightedItems) { - _this20.unhighlightAll(); - } - - _this20.hideDropdown(true); - } - }, - 'select-one': function selectOne() { - _this20.containerOuter.removeFocusState(); - - if (target === _this20.input.element || target === _this20.containerOuter.element && !_this20._canSearch) { - _this20.hideDropdown(true); - } - }, - 'select-multiple': function selectMultiple() { - if (target === _this20.input.element) { - _this20.containerOuter.removeFocusState(); - - _this20.hideDropdown(true); - - if (hasHighlightedItems) { - _this20.unhighlightAll(); - } - } - } - }; - blurActions[this.passedElement.element.type](); - } else { - // On IE11, clicking the scollbar blurs our input and thus - // closes the dropdown. To stop this, we refocus our input - // if we know we are on IE *and* are scrolling. - this._isScrollingOnIe = false; - this.input.element.focus(); - } - }; - - _proto._onFormReset = function _onFormReset() { - this._store.dispatch(resetTo(this._initialState)); - }; - - _proto._highlightChoice = function _highlightChoice(el) { - var _this21 = this; - - if (el === void 0) { - el = null; - } - - var choices = Array.from(this.dropdown.element.querySelectorAll('[data-choice-selectable]')); - - if (!choices.length) { - return; - } - - var passedEl = el; - var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll("." + this.config.classNames.highlightedState)); // Remove any highlighted choices - - highlightedChoices.forEach(function (choice) { - choice.classList.remove(_this21.config.classNames.highlightedState); - choice.setAttribute('aria-selected', 'false'); - }); - - if (passedEl) { - this._highlightPosition = choices.indexOf(passedEl); - } else { - // Highlight choice based on last known highlight location - if (choices.length > this._highlightPosition) { - // If we have an option to highlight - passedEl = choices[this._highlightPosition]; - } else { - // Otherwise highlight the option before - passedEl = choices[choices.length - 1]; - } - - if (!passedEl) { - passedEl = choices[0]; - } - } - - passedEl.classList.add(this.config.classNames.highlightedState); - passedEl.setAttribute('aria-selected', 'true'); - this.passedElement.triggerEvent(EVENTS.highlightChoice, { - el: passedEl - }); - - if (this.dropdown.isActive) { - // IE11 ignores aria-label and blocks virtual keyboard - // if aria-activedescendant is set without a dropdown - this.input.setActiveDescendant(passedEl.id); - this.containerOuter.setActiveDescendant(passedEl.id); - } - }; - - _proto._addItem = function _addItem(_ref13) { - var value = _ref13.value, - _ref13$label = _ref13.label, - label = _ref13$label === void 0 ? null : _ref13$label, - _ref13$choiceId = _ref13.choiceId, - choiceId = _ref13$choiceId === void 0 ? -1 : _ref13$choiceId, - _ref13$groupId = _ref13.groupId, - groupId = _ref13$groupId === void 0 ? -1 : _ref13$groupId, - _ref13$customProperti = _ref13.customProperties, - customProperties = _ref13$customProperti === void 0 ? null : _ref13$customProperti, - _ref13$placeholder = _ref13.placeholder, - placeholder = _ref13$placeholder === void 0 ? false : _ref13$placeholder, - _ref13$keyCode = _ref13.keyCode, - keyCode = _ref13$keyCode === void 0 ? null : _ref13$keyCode; - var passedValue = isType('String', value) ? value.trim() : value; - var passedKeyCode = keyCode; - var passedCustomProperties = customProperties; - var items = this._store.items; - var passedLabel = label || passedValue; - var passedOptionId = parseInt(choiceId, 10) || -1; - var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - var id = items ? items.length + 1 : 1; // If a prepended value has been passed, prepend it - - if (this.config.prependValue) { - passedValue = this.config.prependValue + passedValue.toString(); - } // If an appended value has been passed, append it - - - if (this.config.appendValue) { - passedValue += this.config.appendValue.toString(); - } - - this._store.dispatch(items_addItem({ - value: passedValue, - label: passedLabel, - id: id, - choiceId: passedOptionId, - groupId: groupId, - customProperties: customProperties, - placeholder: placeholder, - keyCode: passedKeyCode - })); - - if (this._isSelectOneElement) { - this.removeActiveItems(id); - } // Trigger change event - - - this.passedElement.triggerEvent(EVENTS.addItem, { - id: id, - value: passedValue, - label: passedLabel, - customProperties: passedCustomProperties, - groupValue: group && group.value ? group.value : undefined, - keyCode: passedKeyCode - }); - return this; - }; - - _proto._removeItem = function _removeItem(item) { - if (!item || !isType('Object', item)) { - return this; - } - - var id = item.id, - value = item.value, - label = item.label, - choiceId = item.choiceId, - groupId = item.groupId; - var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - - this._store.dispatch(items_removeItem(id, choiceId)); - - if (group && group.value) { - this.passedElement.triggerEvent(EVENTS.removeItem, { - id: id, - value: value, - label: label, - groupValue: group.value - }); - } else { - this.passedElement.triggerEvent(EVENTS.removeItem, { - id: id, - value: value, - label: label - }); - } - - return this; - }; - - _proto._addChoice = function _addChoice(_ref14) { - var value = _ref14.value, - _ref14$label = _ref14.label, - label = _ref14$label === void 0 ? null : _ref14$label, - _ref14$isSelected = _ref14.isSelected, - isSelected = _ref14$isSelected === void 0 ? false : _ref14$isSelected, - _ref14$isDisabled = _ref14.isDisabled, - isDisabled = _ref14$isDisabled === void 0 ? false : _ref14$isDisabled, - _ref14$groupId = _ref14.groupId, - groupId = _ref14$groupId === void 0 ? -1 : _ref14$groupId, - _ref14$customProperti = _ref14.customProperties, - customProperties = _ref14$customProperti === void 0 ? null : _ref14$customProperti, - _ref14$placeholder = _ref14.placeholder, - placeholder = _ref14$placeholder === void 0 ? false : _ref14$placeholder, - _ref14$keyCode = _ref14.keyCode, - keyCode = _ref14$keyCode === void 0 ? null : _ref14$keyCode; - - if (typeof value === 'undefined' || value === null) { - return; - } // Generate unique id - - - var choices = this._store.choices; - var choiceLabel = label || value; - var choiceId = choices ? choices.length + 1 : 1; - var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId; - - this._store.dispatch(choices_addChoice({ - value: value, - label: choiceLabel, - id: choiceId, - groupId: groupId, - disabled: isDisabled, - elementId: choiceElementId, - customProperties: customProperties, - placeholder: placeholder, - keyCode: keyCode - })); - - if (isSelected) { - this._addItem({ - value: value, - label: choiceLabel, - choiceId: choiceId, - customProperties: customProperties, - placeholder: placeholder, - keyCode: keyCode - }); - } - }; - - _proto._addGroup = function _addGroup(_ref15) { - var _this22 = this; - - var group = _ref15.group, - id = _ref15.id, - _ref15$valueKey = _ref15.valueKey, - valueKey = _ref15$valueKey === void 0 ? 'value' : _ref15$valueKey, - _ref15$labelKey = _ref15.labelKey, - labelKey = _ref15$labelKey === void 0 ? 'label' : _ref15$labelKey; - var groupChoices = isType('Object', group) ? group.choices : Array.from(group.getElementsByTagName('OPTION')); - var groupId = id || Math.floor(new Date().valueOf() * Math.random()); - var isDisabled = group.disabled ? group.disabled : false; - - if (groupChoices) { - this._store.dispatch(groups_addGroup(group.label, groupId, true, isDisabled)); - - var addGroupChoices = function addGroupChoices(choice) { - var isOptDisabled = choice.disabled || choice.parentNode && choice.parentNode.disabled; - - _this22._addChoice({ - value: choice[valueKey], - label: isType('Object', choice) ? choice[labelKey] : choice.innerHTML, - isSelected: choice.selected, - isDisabled: isOptDisabled, - groupId: groupId, - customProperties: choice.customProperties, - placeholder: choice.placeholder - }); - }; - - groupChoices.forEach(addGroupChoices); - } else { - this._store.dispatch(groups_addGroup(group.label, group.id, false, group.disabled)); - } - }; - - _proto._getTemplate = function _getTemplate(template) { - var _templates$template; - - if (!template) { - return null; - } - - var _this$config4 = this.config, - templates = _this$config4.templates, - classNames = _this$config4.classNames; - - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } - - return (_templates$template = templates[template]).call.apply(_templates$template, [this, classNames].concat(args)); - }; - - _proto._createTemplates = function _createTemplates() { - var callbackOnCreateTemplates = this.config.callbackOnCreateTemplates; - var userTemplates = {}; - - if (callbackOnCreateTemplates && isType('Function', callbackOnCreateTemplates)) { - userTemplates = callbackOnCreateTemplates.call(this, strToEl); - } - - this.config.templates = cjs_default()(TEMPLATES, userTemplates); - }; - - _proto._createElements = function _createElements() { - this.containerOuter = new container_Container({ - element: this._getTemplate('containerOuter', this._direction, this._isSelectElement, this._isSelectOneElement, this.config.searchEnabled, this.passedElement.element.type), - classNames: this.config.classNames, - type: this.passedElement.element.type, - position: this.config.position - }); - this.containerInner = new container_Container({ - element: this._getTemplate('containerInner'), - classNames: this.config.classNames, - type: this.passedElement.element.type, - position: this.config.position - }); - this.input = new input_Input({ - element: this._getTemplate('input', this._placeholderValue), - classNames: this.config.classNames, - type: this.passedElement.element.type - }); - this.choiceList = new list_List({ - element: this._getTemplate('choiceList', this._isSelectOneElement) - }); - this.itemList = new list_List({ - element: this._getTemplate('itemList', this._isSelectOneElement) - }); - this.dropdown = new Dropdown({ - element: this._getTemplate('dropdown'), - classNames: this.config.classNames, - type: this.passedElement.element.type - }); - }; - - _proto._createStructure = function _createStructure() { - // Hide original element - this.passedElement.conceal(); // Wrap input in container preserving DOM ordering - - this.containerInner.wrap(this.passedElement.element); // Wrapper inner container with outer container - - this.containerOuter.wrap(this.containerInner.element); - - if (this._isSelectOneElement) { - this.input.placeholder = this.config.searchPlaceholderValue || ''; - } else if (this._placeholderValue) { - this.input.placeholder = this._placeholderValue; - this.input.setWidth(true); - } - - this.containerOuter.element.appendChild(this.containerInner.element); - this.containerOuter.element.appendChild(this.dropdown.element); - this.containerInner.element.appendChild(this.itemList.element); - - if (!this._isTextElement) { - this.dropdown.element.appendChild(this.choiceList.element); - } - - if (!this._isSelectOneElement) { - this.containerInner.element.appendChild(this.input.element); - } else if (this.config.searchEnabled) { - this.dropdown.element.insertBefore(this.input.element, this.dropdown.element.firstChild); - } - - if (this._isSelectElement) { - this._addPredefinedChoices(); - } else if (this._isTextElement) { - this._addPredefinedItems(); - } - }; - - _proto._addPredefinedChoices = function _addPredefinedChoices() { - var _this23 = this; - - var passedGroups = this.passedElement.optionGroups; - this._highlightPosition = 0; - this._isSearching = false; - - this._setLoading(true); - - if (passedGroups && passedGroups.length) { - // If we have a placeholder option - var placeholderChoice = this.passedElement.placeholderOption; - - if (placeholderChoice && placeholderChoice.parentNode.tagName === 'SELECT') { - this._addChoice({ - value: placeholderChoice.value, - label: placeholderChoice.innerHTML, - isSelected: placeholderChoice.selected, - isDisabled: placeholderChoice.disabled, - placeholder: true - }); - } - - passedGroups.forEach(function (group) { - return _this23._addGroup({ - group: group, - id: group.id || null - }); - }); - } else { - var passedOptions = this.passedElement.options; - var filter = this.config.sortFn; - var allChoices = this._presetChoices; // Create array of options from option elements - - passedOptions.forEach(function (o) { - allChoices.push({ - value: o.value, - label: o.innerHTML, - selected: o.selected, - disabled: o.disabled || o.parentNode.disabled, - placeholder: o.hasAttribute('placeholder'), - customProperties: o.getAttribute('data-custom-properties') - }); - }); // If sorting is enabled or the user is searching, filter choices - - if (this.config.shouldSort) allChoices.sort(filter); // Determine whether there is a selected choice - - var hasSelectedChoice = allChoices.some(function (choice) { - return choice.selected; - }); - - var handleChoice = function handleChoice(choice, index) { - var value = choice.value, - label = choice.label, - customProperties = choice.customProperties, - placeholder = choice.placeholder; - - if (_this23._isSelectElement) { - // If the choice is actually a group - if (choice.choices) { - _this23._addGroup({ - group: choice, - id: choice.id || null - }); - } else { - // If there is a selected choice already or the choice is not - // the first in the array, add each choice normally - // Otherwise pre-select the first choice in the array if it's a single select - var shouldPreselect = _this23._isSelectOneElement && !hasSelectedChoice && index === 0; - var isSelected = shouldPreselect ? true : choice.selected; - var isDisabled = shouldPreselect ? false : choice.disabled; - - _this23._addChoice({ - value: value, - label: label, - isSelected: isSelected, - isDisabled: isDisabled, - customProperties: customProperties, - placeholder: placeholder - }); - } - } else { - _this23._addChoice({ - value: value, - label: label, - isSelected: choice.selected, - isDisabled: choice.disabled, - customProperties: customProperties, - placeholder: placeholder - }); - } - }; // Add each choice - - - allChoices.forEach(function (choice, index) { - return handleChoice(choice, index); - }); - } - - this._setLoading(false); - }; - - _proto._addPredefinedItems = function _addPredefinedItems() { - var _this24 = this; - - var handlePresetItem = function handlePresetItem(item) { - var itemType = getType(item); - - if (itemType === 'Object' && item.value) { - _this24._addItem({ - value: item.value, - label: item.label, - choiceId: item.id, - customProperties: item.customProperties, - placeholder: item.placeholder - }); - } else if (itemType === 'String') { - _this24._addItem({ - value: item - }); - } - }; - - this._presetItems.forEach(function (item) { - return handlePresetItem(item); - }); - }; - - _proto._setChoiceOrItem = function _setChoiceOrItem(item) { - var _this25 = this; - - var itemType = getType(item).toLowerCase(); - var handleType = { - object: function object() { - if (!item.value) { - return; - } // If we are dealing with a select input, we need to create an option first - // that is then selected. For text inputs we can just add items normally. - - - if (!_this25._isTextElement) { - _this25._addChoice({ - value: item.value, - label: item.label, - isSelected: true, - isDisabled: false, - customProperties: item.customProperties, - placeholder: item.placeholder - }); - } else { - _this25._addItem({ - value: item.value, - label: item.label, - choiceId: item.id, - customProperties: item.customProperties, - placeholder: item.placeholder - }); - } - }, - string: function string() { - if (!_this25._isTextElement) { - _this25._addChoice({ - value: item, - label: item, - isSelected: true, - isDisabled: false - }); - } else { - _this25._addItem({ - value: item - }); - } - } - }; - handleType[itemType](); - }; - - _proto._findAndSelectChoiceByValue = function _findAndSelectChoiceByValue(val) { - var _this26 = this; - - var choices = this._store.choices; // Check 'value' property exists and the choice isn't already selected - - var foundChoice = choices.find(function (choice) { - return _this26.config.itemComparer(choice.value, val); - }); - - if (foundChoice && !foundChoice.selected) { - this._addItem({ - value: foundChoice.value, - label: foundChoice.label, - choiceId: foundChoice.id, - groupId: foundChoice.groupId, - customProperties: foundChoice.customProperties, - placeholder: foundChoice.placeholder, - keyCode: foundChoice.keyCode - }); - } - }; - - _proto._generateInstances = function _generateInstances(elements, config) { - return elements.reduce(function (instances, element) { - instances.push(new Choices(element, config)); - return instances; - }, [this]); - }; - - _proto._generatePlaceholderValue = function _generatePlaceholderValue() { - if (this._isSelectOneElement) { - return false; - } - - return this.config.placeholder ? this.config.placeholderValue || this.passedElement.element.getAttribute('placeholder') : false; - } - /* ===== End of Private functions ====== */ - ; - - return Choices; -}(); - -choices_Choices.userDefaults = {}; -/* harmony default export */ var scripts_choices = __webpack_exports__["default"] = (choices_Choices); - -/***/ }) -/******/ ])["default"]; -}); \ No newline at end of file diff --git a/assets/scripts/choices.min.js b/assets/scripts/choices.min.js deleted file mode 100644 index 17349d35..00000000 --- a/assets/scripts/choices.min.js +++ /dev/null @@ -1,52 +0,0 @@ -/*! choices.js v7.1.1 | © 2019 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Choices=t():e.Choices=t()}(window,(function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)i.d(n,s,function(t){return e[t]}.bind(null,s));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="/public/assets/scripts/",i(i.s=5)}([function(e,t,i){var n; -/*! - Copyright (c) 2017 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/!function(){"use strict";var i={}.hasOwnProperty;function s(){for(var e=[],t=0;t0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=[],n=-1,s=-1,r=0,o=e.length;r=t&&i.push([n,s]),n=-1)}return e[r-1]&&r-n>=t&&i.push([n,r-1]),i}},"./src/bitap/bitap_pattern_alphabet.js": -/*!*********************************************!*\ - !*** ./src/bitap/bitap_pattern_alphabet.js ***! - \*********************************************/ -/*! no static exports found */function(e,t){e.exports=function(e){for(var t={},i=e.length,n=0;n2&&void 0!==arguments[2]?arguments[2]:/ +/g,s=new RegExp(t.replace(i,"\\$&").replace(n,"|")),r=e.match(s),o=!!r,a=[];if(o)for(var l=0,c=r.length;l=D;j-=1){var M=j-1,N=i[e.charAt(M)];if(N&&(E[M]=1),F[j]=(F[j+1]<<1|1)&N,0!==T&&(F[j]|=(C[j+1]|C[j])<<1|1|C[j+1]),F[j]&x&&(O=n(t,{errors:T,currentLocation:M,expectedLocation:v,distance:c}))<=_){if(_=O,(b=M)<=v)break;D=Math.max(1,2*v-b)}}if(n(t,{errors:T+1,currentLocation:v,expectedLocation:v,distance:c})>_)break;C=F}return{isMatch:b>=0,score:0===O?.001:O,matchedIndices:s(E,m)}}},"./src/bitap/index.js": -/*!****************************!*\ - !*** ./src/bitap/index.js ***! - \****************************/ -/*! no static exports found */function(e,t,i){function n(e,t){for(var i=0;ii)return s(e,this.pattern,n);var o=this.options,a=o.location,l=o.distance,c=o.threshold,h=o.findAllMatches,u=o.minMatchCharLength;return r(e,this.pattern,this.patternAlphabet,{location:a,distance:l,threshold:c,findAllMatches:h,minMatchCharLength:u})}}])&&n(t.prototype,i),a&&n(t,a),e}();e.exports=a},"./src/helpers/deep_value.js": -/*!***********************************!*\ - !*** ./src/helpers/deep_value.js ***! - \***********************************/ -/*! no static exports found */function(e,t,i){var n=i(/*! ./is_array */"./src/helpers/is_array.js");e.exports=function(e,t){return function e(t,i,s){if(i){var r=i.indexOf("."),o=i,a=null;-1!==r&&(o=i.slice(0,r),a=i.slice(r+1));var l=t[o];if(null!=l)if(a||"string"!=typeof l&&"number"!=typeof l)if(n(l))for(var c=0,h=l.length;c1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(e,'"'));var i=this._prepareSearchers(e),n=i.tokenSearchers,s=i.fullSearcher,r=this._search(n,s),o=r.weights,a=r.results;return this._computeScore(o,a),this.options.shouldSort&&this._sort(a),t.limit&&"number"==typeof t.limit&&(a=a.slice(0,t.limit)),this._format(a)}},{key:"_prepareSearchers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=[];if(this.options.tokenize)for(var i=e.split(this.options.tokenSeparator),n=0,s=i.length;n0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,i=this.list,n={},s=[];if("string"==typeof i[0]){for(var r=0,o=i.length;r1)throw new Error("Key weight has to be > 0 and <= 1");p=p.name}else a[p]={weight:1};this._analyze({key:p,value:this.options.getFn(h,p),record:h,index:l},{resultMap:n,results:s,tokenSearchers:e,fullSearcher:t})}return{weights:a,results:s}}},{key:"_analyze",value:function(e,t){var i=e.key,n=e.arrayIndex,s=void 0===n?-1:n,r=e.value,o=e.record,l=e.index,c=t.tokenSearchers,h=void 0===c?[]:c,u=t.fullSearcher,d=void 0===u?[]:u,p=t.resultMap,f=void 0===p?{}:p,m=t.results,v=void 0===m?[]:m;if(null!=r){var g=!1,_=-1,b=0;if("string"==typeof r){this._log("\nKey: ".concat(""===i?"-":i));var y=d.search(r);if(this._log('Full text: "'.concat(r,'", score: ').concat(y.score)),this.options.tokenize){for(var E=r.split(this.options.tokenSeparator),S=[],I=0;I-1&&(D=(D+_)/2),this._log("Score average:",D);var P=!this.options.tokenize||!this.options.matchAllTokens||b>=h.length;if(this._log("\nCheck Matches: ".concat(P)),(g||y.isMatch)&&P){var F=f[l];F?F.output.push({key:i,arrayIndex:s,value:r,score:D,matchedIndices:y.matchedIndices}):(f[l]={item:o,output:[{key:i,arrayIndex:s,value:r,score:D,matchedIndices:y.matchedIndices}]},v.push(f[l]))}}else if(a(r))for(var j=0,M=r.length;j-1&&(o.arrayIndex=r.arrayIndex),t.matches.push(o)}}})),this.options.includeScore&&s.push((function(e,t){t.score=e.score}));for(var r=0,o=e.length;r/g,"&rt;").replace(/-1?e(t[i.substring(0,n)],i.substr(n+1)):t[i]},T=function(e){return JSON.parse(JSON.stringify(e))},L=function(e,t){var i=Object.keys(e).sort(),n=Object.keys(t).sort();return i.filter((function(e){return n.indexOf(e)<0}))},k=function(e){for(var t=Object.keys(e),i={},n=0;n-1?e.map((function(e){var i=e;return i.id===parseInt(t.choiceId,10)&&(i.selected=!0),i})):e;case"REMOVE_ITEM":return t.choiceId>-1?e.map((function(e){var i=e;return i.id===parseInt(t.choiceId,10)&&(i.selected=!1),i})):e;case"FILTER_CHOICES":return e.map((function(e){var i=e;return i.active=t.results.some((function(e){var t=e.item,n=e.score;return t.id===i.id&&(i.score=n,!0)})),i}));case"ACTIVATE_CHOICES":return e.map((function(e){var i=e;return i.active=t.active,i}));case"CLEAR_CHOICES":return m;default:return e}},general:_}),D=function(e,t){var i=e;if("CLEAR_ALL"===t.type)i=void 0;else if("RESET_TO"===t.type)return T(t.state);return k(i,t)};function P(e,t){for(var i=0;i=t:"top"===this.position&&(s=!0),s},t.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},t.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},t.open=function(e){this.element.classList.add(this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e)&&(this.element.classList.add(this.classNames.flippedState),this.isFlipped=!0)},t.close=function(){this.element.classList.remove(this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(this.element.classList.remove(this.classNames.flippedState),this.isFlipped=!1)},t.focus=function(){this.isFocussed||this.element.focus()},t.addFocusState=function(){this.element.classList.add(this.classNames.focusState)},t.removeFocusState=function(){this.element.classList.remove(this.classNames.focusState)},t.enable=function(){this.element.classList.remove(this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),"select-one"===this.type&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},t.disable=function(){this.element.classList.add(this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),"select-one"===this.type&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},t.wrap=function(e){!function(e,t){void 0===t&&(t=document.createElement("div")),e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t),t.appendChild(e)}(e,this.element)},t.unwrap=function(e){this.element.parentNode.insertBefore(e,this.element),this.element.parentNode.removeChild(this.element)},t.addLoadingState=function(){this.element.classList.add(this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},t.removeLoadingState=function(){this.element.classList.remove(this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},t._onFocus=function(){this.isFocussed=!0},t._onBlur=function(){this.isFocussed=!1},e}();function N(e,t){for(var i=0;i=this._placeholderValue.length/1.25;(this.element.value&&n||e)&&this.calcWidth(i)}else this.calcWidth(i)},s.calcWidth=function(e){return function(e,t){var i=e.value||e.placeholder,n=e.offsetWidth;if(i){var s=O(""+C(i)+"");if(s.style.position="absolute",s.style.padding="0",s.style.top="-9999px",s.style.left="-9999px",s.style.width="auto",s.style.whiteSpace="pre",document.body.contains(e)&&window.getComputedStyle){var r=window.getComputedStyle(e);r&&(s.style.fontSize=r.fontSize,s.style.fontFamily=r.fontFamily,s.style.fontWeight=r.fontWeight,s.style.fontStyle=r.fontStyle,s.style.letterSpacing=r.letterSpacing,s.style.textTransform=r.textTransform,s.style.paddingLeft=r.paddingLeft,s.style.paddingRight=r.paddingRight)}document.body.appendChild(s),requestAnimationFrame((function(){i&&s.offsetWidth!==e.offsetWidth&&(n=s.offsetWidth+4),document.body.removeChild(s),t.call(void 0,n+"px")}))}else t.call(void 0,n+"px")}(this.element,e)},s.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},s.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},s._onInput=function(){"select-one"!==this.type&&this.setWidth()},s._onPaste=function(e){e.target===this.element&&this.preventPaste&&e.preventDefault()},s._onFocus=function(){this.isFocussed=!0},s._onBlur=function(){this.isFocussed=!1},t=e,(i=[{key:"placeholder",set:function(e){this.element.placeholder=e}},{key:"value",set:function(e){this.element.value=e},get:function(){return C(this.element.value)}}])&&N(t.prototype,i),n&&N(t,n),e}(),R={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,addItems:!0,addItemFilterFn:null,removeItems:!0,removeItemButton:!1,editItems:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sortFn:function(e,t){var i=(""+(e.label||e.value)).toLowerCase(),n=(""+(t.label||t.value)).toLowerCase();return in?1:0},placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'+C(e)+'"'},maxItemText:function(e){return"Only "+e+" values can be added"},itemComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:"choices",containerInner:"choices__inner",input:"choices__input",inputCloned:"choices__input--cloned",list:"choices__list",listItems:"choices__list--multiple",listSingle:"choices__list--single",listDropdown:"choices__list--dropdown",item:"choices__item",itemSelectable:"choices__item--selectable",itemDisabled:"choices__item--disabled",itemChoice:"choices__item--choice",placeholder:"choices__placeholder",group:"choices__group",groupHeading:"choices__heading",button:"choices__button",activeState:"is-active",focusState:"is-focused",openState:"is-open",disabledState:"is-disabled",highlightedState:"is-highlighted",hiddenState:"is-hidden",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"}},B="showDropdown",V="hideDropdown",H="change",G="choice",q="search",W="addItem",U="removeItem",z="highlightItem",X="highlightChoice",Y="ADD_CHOICE",$="FILTER_CHOICES",J="ACTIVATE_CHOICES",Z="CLEAR_CHOICES",Q="ADD_GROUP",ee="ADD_ITEM",te="REMOVE_ITEM",ie="HIGHLIGHT_ITEM",ne=46,se=8,re=13,oe=65,ae=27,le=38,ce=40,he=33,ue=34,de=function(){function e(e){var t=e.element;Object.assign(this,{element:t}),this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight,this.hasChildren=!!this.element.children}var t=e.prototype;return t.clear=function(){this.element.innerHTML=""},t.append=function(e){this.element.appendChild(e)},t.getChild=function(e){return this.element.querySelector(e)},t.scrollToTop=function(){this.element.scrollTop=0},t.scrollToChoice=function(e,t){var i=this;if(e){var n=this.element.offsetHeight,s=e.offsetHeight,r=e.offsetTop+s,o=this.element.scrollTop+n,a=t>0?this.element.scrollTop+r-o:e.offsetTop;requestAnimationFrame((function(e){i._animateScroll(e,a,t)}))}},t._scrollDown=function(e,t,i){var n=(i-e)/t,s=n>1?n:1;this.element.scrollTop=e+s},t._scrollUp=function(e,t,i){var n=(e-i)/t,s=n>1?n:1;this.element.scrollTop=e-s},t._animateScroll=function(e,t,i){var n=this,s=this.element.scrollTop,r=!1;i>0?(this._scrollDown(s,4,t),st&&(r=!0)),r&&requestAnimationFrame((function(){n._animateScroll(e,t,i)}))},e}();function pe(e,t){for(var i=0;i