From f896be9e106cba413dd5c0cf9678180631760862 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Mon, 23 Dec 2019 17:22:09 +0000 Subject: [PATCH] Use interfaces in action tests --- .mocharc.yml | 2 +- public/assets/scripts/choices.js | 5896 +++++++++++++------------- public/assets/scripts/choices.min.js | 6 +- src/scripts/actions/choices.test.ts | 20 +- src/scripts/actions/groups.test.ts | 3 +- src/scripts/actions/items.test.ts | 7 +- src/scripts/actions/misc.test.ts | 15 +- 7 files changed, 2951 insertions(+), 2998 deletions(-) diff --git a/.mocharc.yml b/.mocharc.yml index 72fd670..40fed2d 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -2,7 +2,7 @@ require: - 'ts-node/register' - './config/jsdom.js' exit: true -spec: src/**/*.test.ts +spec: src/**/**/*.test.ts extension: - ts - js diff --git a/public/assets/scripts/choices.js b/public/assets/scripts/choices.js index 98a61a7..ce3999d 100644 --- a/public/assets/scripts/choices.js +++ b/public/assets/scripts/choices.js @@ -92,7 +92,7 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 4); +/******/ return __webpack_require__(__webpack_require__.s = 7); /******/ }) /************************************************************************/ /******/ ([ @@ -102,143 +102,321 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; -var isMergeableObject = function isMergeableObject(value) { - return isNonNullObject(value) - && !isSpecial(value) +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var utils_1 = __webpack_require__(1); + +exports.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', + selectedState: 'is-selected', + flippedState: 'is-flipped', + loadingState: 'is-loading', + noResults: 'has-no-results', + noChoices: 'has-no-choices' }; - -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) - }, {}) +exports.DEFAULT_CONFIG = { + items: [], + choices: [], + silent: false, + renderChoiceLimit: -1, + maxItemCount: -1, + addItems: true, + addItemFilter: 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, + sorter: utils_1.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 \"" + utils_1.sanitise(value) + "\""; + }, + maxItemText: function maxItemText(maxItemCount) { + return "Only " + maxItemCount + " values can be added"; + }, + valueComparer: function valueComparer(value1, value2) { + return value1 === value2; + }, + fuseOptions: { + includeScore: true + }, + callbackOnInit: null, + callbackOnCreateTemplates: null, + classNames: exports.DEFAULT_CLASSNAMES }; - -var deepmerge_1 = deepmerge; - -module.exports = deepmerge_1; - +exports.EVENTS = { + showDropdown: 'showDropdown', + hideDropdown: 'hideDropdown', + change: 'change', + choice: 'choice', + search: 'search', + addItem: 'addItem', + removeItem: 'removeItem', + highlightItem: 'highlightItem', + highlightChoice: 'highlightChoice', + unhighlightItem: 'unhighlightItem' +}; +exports.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', + RESET_TO: 'RESET_TO', + SET_IS_LOADING: 'SET_IS_LOADING' +}; +exports.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 +}; +exports.TEXT_TYPE = 'text'; +exports.SELECT_ONE_TYPE = 'select-one'; +exports.SELECT_MULTIPLE_TYPE = 'select-multiple'; +exports.SCROLLING_SPEED = 4; /***/ }), /* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +/* eslint-disable @typescript-eslint/no-explicit-any */ + +exports.getRandomNumber = function (min, max) { + return Math.floor(Math.random() * (max - min) + min); +}; + +exports.generateChars = function (length) { + return Array.from({ + length: length + }, function () { + return exports.getRandomNumber(0, 36).toString(36); + }).join(''); +}; + +exports.generateId = function (element, prefix) { + var id = element.id || element.name && element.name + "-" + exports.generateChars(2) || exports.generateChars(4); + id = id.replace(/(:|\.|\[|\]|,)/g, ''); + id = prefix + "-" + id; + return id; +}; + +exports.getType = function (obj) { + return Object.prototype.toString.call(obj).slice(8, -1); +}; + +exports.isType = function (type, obj) { + return obj !== undefined && obj !== null && exports.getType(obj) === type; +}; + +exports.wrap = function (element, wrapper) { + if (wrapper === void 0) { + wrapper = document.createElement('div'); + } + + if (element.nextSibling) { + element.parentNode && element.parentNode.insertBefore(wrapper, element.nextSibling); + } else { + element.parentNode && element.parentNode.appendChild(wrapper); + } + + return wrapper.appendChild(element); +}; + +exports.getAdjacentEl = function (startEl, selector, direction) { + if (direction === void 0) { + direction = 1; + } + + var prop = (direction > 0 ? 'next' : 'previous') + "ElementSibling"; + var sibling = startEl[prop]; + + while (sibling) { + if (sibling.matches(selector)) { + return sibling; + } + + sibling = sibling[prop]; + } + + return sibling; +}; + +exports.isScrolledIntoView = function (element, parent, direction) { + if (direction === void 0) { + direction = 1; + } + + if (!element) { + return false; + } + + var isVisible; + + if (direction > 0) { + // In view from bottom + isVisible = parent.scrollTop + parent.offsetHeight >= element.offsetTop + element.offsetHeight; + } else { + // In view from top + isVisible = element.offsetTop >= parent.scrollTop; + } + + return isVisible; +}; + +exports.sanitise = function (value) { + if (typeof value !== 'string') { + return value; + } + + return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(e,'"'));var n=this._prepareSearchers(e),r=n.tokenSearchers,o=n.fullSearcher,i=this._search(r,o),a=i.weights,s=i.results;return this._computeScore(a,s),this.options.shouldSort&&this._sort(s),t.limit&&"number"==typeof t.limit&&(s=s.slice(0,t.limit)),this._format(s)}},{key:"_prepareSearchers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=[];if(this.options.tokenize)for(var n=e.split(this.options.tokenSeparator),r=0,o=n.length;r0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,n=this.list,r={},o=[];if("string"==typeof n[0]){for(var i=0,a=n.length;i1)throw new Error("Key weight has to be > 0 and <= 1");d=d.name}else s[d]={weight:1};this._analyze({key:d,value:this.options.getFn(l,d),record:l,index:c},{resultMap:r,results:o,tokenSearchers:e,fullSearcher:t})}return{weights:s,results:o}}},{key:"_analyze",value:function(e,t){var n=e.key,r=e.arrayIndex,o=void 0===r?-1:r,i=e.value,a=e.record,c=e.index,h=t.tokenSearchers,l=void 0===h?[]:h,u=t.fullSearcher,f=void 0===u?[]:u,d=t.resultMap,v=void 0===d?{}:d,p=t.results,g=void 0===p?[]:p;if(null!=i){var y=!1,m=-1,k=0;if("string"==typeof i){this._log("\nKey: ".concat(""===n?"-":n));var S=f.search(i);if(this._log('Full text: "'.concat(i,'", score: ').concat(S.score)),this.options.tokenize){for(var x=i.split(this.options.tokenSeparator),b=[],M=0;M-1&&(P=(P+m)/2),this._log("Score average:",P);var F=!this.options.tokenize||!this.options.matchAllTokens||k>=l.length;if(this._log("\nCheck Matches: ".concat(F)),(y||S.isMatch)&&F){var T=v[c];T?T.output.push({key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}):(v[c]={item:a,output:[{key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}]},g.push(v[c]))}}else if(s(i))for(var z=0,E=i.length;z-1&&(a.arrayIndex=i.arrayIndex),t.matches.push(a)}}}),this.options.includeScore&&o.push(function(e,t){t.score=e.score});for(var i=0,a=e.length;in)return o(e,this.pattern,r);var a=this.options,s=a.location,c=a.distance,h=a.threshold,l=a.findAllMatches,u=a.minMatchCharLength;return i(e,this.pattern,this.patternAlphabet,{location:s,distance:c,threshold:h,findAllMatches:l,minMatchCharLength:u})}}])&&r(t.prototype,n),s&&r(t,s),e}();e.exports=s},function(e,t){var n=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;e.exports=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,o=new RegExp(t.replace(n,"\\$&").replace(r,"|")),i=e.match(o),a=!!i,s=[];if(a)for(var c=0,h=i.length;c=P;z-=1){var E=z-1,K=n[e.charAt(E)];if(K&&(x[E]=1),T[z]=(T[z+1]<<1|1)&K,0!==I&&(T[z]|=(L[z+1]|L[z])<<1|1|L[z+1]),T[z]&C&&(w=r(t,{errors:I,currentLocation:E,expectedLocation:g,distance:h}))<=m){if(m=w,(k=E)<=g)break;P=Math.max(1,2*g-k)}}if(r(t,{errors:I+1,currentLocation:g,expectedLocation:g,distance:h})>m)break;L=T}return{isMatch:k>=0,score:0===w?.001:w,matchedIndices:o(x,p)}}},function(e,t){e.exports=function(e,t){var n=t.errors,r=void 0===n?0:n,o=t.currentLocation,i=void 0===o?0:o,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?100:c,l=r/e.length,u=Math.abs(s-i);return h?l+u/h:u?1:l}},function(e,t){e.exports=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,o=-1,i=0,a=e.length;i=t&&n.push([r,o]),r=-1)}return e[i-1]&&i-r>=t&&n.push([r,i-1]),n}},function(e,t){e.exports=function(e){for(var t={},n=e.length,r=0;r -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 -/** - * @param {number} min - * @param {number} max - * @returns {number} - */ -var getRandomNumber = function getRandomNumber(min, max) { - return Math.floor(Math.random() * (max - min) + min); -}; -/** - * @param {number} length - * @returns {string} - */ - -var generateChars = function generateChars(length) { - return Array.from({ - length: length - }, function () { - return getRandomNumber(0, 36).toString(36); - }).join(''); -}; -/** - * @param {HTMLInputElement | HTMLSelectElement} element - * @param {string} prefix - * @returns {string} - */ - -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; -}; -/** - * @param {any} obj - * @returns {string} - */ - -var getType = function getType(obj) { - return Object.prototype.toString.call(obj).slice(8, -1); -}; -/** - * @param {string} type - * @param {any} obj - * @returns {boolean} - */ - -var isType = function isType(type, obj) { - return obj !== undefined && obj !== null && getType(obj) === type; -}; -/** - * @param {HTMLElement} element - * @param {HTMLElement} [wrapper={HTMLDivElement}] - * @returns {HTMLElement} - */ - -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); -}; -/** - * @param {Element} startEl - * @param {string} selector - * @param {1 | -1} direction - * @returns {Element | undefined} - */ - -var getAdjacentEl = function getAdjacentEl(startEl, selector, direction) { - if (direction === void 0) { - direction = 1; - } - - if (!(startEl instanceof Element) || typeof selector !== 'string') { - return undefined; - } - - var prop = (direction > 0 ? 'next' : 'previous') + "ElementSibling"; - var sibling = startEl[prop]; - - while (sibling) { - if (sibling.matches(selector)) { - return sibling; - } - - sibling = sibling[prop]; - } - - return sibling; -}; -/** - * @param {Element} element - * @param {Element} parent - * @param {-1 | 1} direction - * @returns {boolean} - */ - -var isScrolledIntoView = function isScrolledIntoView(element, parent, direction) { - if (direction === void 0) { - direction = 1; - } - - if (!element) { - return false; - } - - var isVisible; - - if (direction > 0) { - // In view from bottom - isVisible = parent.scrollTop + parent.offsetHeight >= element.offsetTop + element.offsetHeight; - } else { - // In view from top - isVisible = element.offsetTop >= parent.scrollTop; - } - - return isVisible; -}; -/** - * @param {any} value - * @returns {any} - */ - -var sanitise = function sanitise(value) { - if (typeof value !== 'string') { - return value; - } - - return value.replace(/&/g, '&').replace(/>/g, '&rt;').replace(/ (str: string) => Element} - */ - -var strToEl = function () { - var tmpEl = document.createElement('div'); - return function (str) { - var cleanedInput = str.trim(); - tmpEl.innerHTML = cleanedInput; - var firldChild = tmpEl.children[0]; - - while (tmpEl.firstChild) { - tmpEl.removeChild(tmpEl.firstChild); - } - - return firldChild; +var __importDefault = this && this.__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod }; -}(); -/** - * @param {{ label?: string, value: string }} a - * @param {{ label?: string, value: string }} b - * @returns {number} - */ - -var sortByAlpha = function sortByAlpha(_ref, _ref2) { - var value = _ref.value, - _ref$label = _ref.label, - label = _ref$label === void 0 ? value : _ref$label; - var value2 = _ref2.value, - _ref2$label = _ref2.label, - label2 = _ref2$label === void 0 ? value2 : _ref2$label; - return label.localeCompare(label2, [], { - sensitivity: 'base', - ignorePunctuation: true, - numeric: true - }); }; -/** - * @param {{ score: number }} a - * @param {{ score: number }} b - */ -var sortByScore = function sortByScore(a, b) { - return a.score - b.score; -}; -/** - * @param {HTMLElement} element - * @param {string} type - * @param {object} customArgs - */ - -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); -}; -/** - * @param {array} array - * @param {any} value - * @param {string} [key="value"] - * @returns {boolean} - */ - -var existsInArray = function existsInArray(array, value, key) { - if (key === void 0) { - key = 'value'; - } - - return array.some(function (item) { - if (typeof value === 'string') { - return item[key] === value.trim(); - } - - return item[key] === value; - }); -}; -/** - * @param {any} obj - * @returns {any} - */ - -var cloneObject = function cloneObject(obj) { - return JSON.parse(JSON.stringify(obj)); -}; -/** - * Returns an array of keys present on the first but missing on the second object - * @param {object} a - * @param {object} b - * @returns {string[]} - */ - -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 +Object.defineProperty(exports, "__esModule", { + value: true }); -var reducers_rootReducer = function rootReducer(passedState, action) { +var redux_1 = __webpack_require__(3); + +var items_1 = __importDefault(__webpack_require__(14)); + +var groups_1 = __importDefault(__webpack_require__(15)); + +var choices_1 = __importDefault(__webpack_require__(16)); + +var loading_1 = __importDefault(__webpack_require__(17)); + +var utils_1 = __webpack_require__(1); + +exports.defaultState = { + groups: [], + items: [], + choices: [], + loading: false +}; +var appReducer = redux_1.combineReducers({ + items: items_1.default, + groups: groups_1.default, + choices: choices_1.default, + loading: loading_1.default +}); + +var 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; + state = exports.defaultState; } else if (action.type === 'RESET_TO') { - return cloneObject(action.state); + return utils_1.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); } } +exports.default = rootReducer; -function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); -/** - * @typedef {import('../../../types/index').Choices.Choice} Choice - * @typedef {import('../../../types/index').Choices.Group} Group - * @typedef {import('../../../types/index').Choices.Item} Item - */ +var utils_1 = __webpack_require__(1); -var store_Store = -/*#__PURE__*/ +var WrappedElement = +/** @class */ 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 {{ type: string, [x: string]: any }} action Action to trigger - * @return - */ - ; - - _proto.dispatch = function dispatch(action) { - this._store.dispatch(action); - } - /** - * Get store object (wrapping Redux method) - * @returns {object} State - */ - ; - - /** - * Get loading state from store - * @returns {boolean} Loading State - */ - _proto.isLoading = function isLoading() { - return this.state.general.loading; - } - /** - * Get single choice by it's ID - * @param {string} id - * @returns {Choice | undefined} Found choice - */ - ; - - _proto.getChoiceById = function getChoiceById(id) { - return this.activeChoices.find(function (choice) { - return choice.id === parseInt(id, 10); - }); - } - /** - * Get group by group id - * @param {number} id Group ID - * @returns {Group | undefined} Group data - */ - ; - - _proto.getGroupById = function getGroupById(id) { - return this.groups.find(function (group) { - return group.id === id; - }); - }; - - _createClass(Store, [{ - key: "state", - get: function get() { - return this._store.getState(); - } - /** - * Get items from store - * @returns {Item[]} Item objects - */ - - }, { - key: "items", - get: function get() { - return this.state.items; - } - /** - * Get active items from store - * @returns {Item[]} Item objects - */ - - }, { - key: "activeItems", - get: function get() { - return this.items.filter(function (item) { - return item.active === true; - }); - } - /** - * Get highlighted items from store - * @returns {Item[]} Item objects - */ - - }, { - key: "highlightedActiveItems", - get: function get() { - return this.items.filter(function (item) { - return item.active && item.highlighted; - }); - } - /** - * Get choices from store - * @returns {Choice[]} Option objects - */ - - }, { - key: "choices", - get: function get() { - return this.state.choices; - } - /** - * Get active choices from store - * @returns {Choice[]} Option objects - */ - - }, { - key: "activeChoices", - get: function get() { - return this.choices.filter(function (choice) { - return choice.active === true; - }); - } - /** - * Get selectable choices from store - * @returns {Choice[]} 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) - * @returns {Choice[]} Option objects - */ - - }, { - key: "searchableChoices", - get: function get() { - return this.selectableChoices.filter(function (choice) { - return choice.placeholder !== true; - }); - } - /** - * Get placeholder choice from store - * @returns {Choice | undefined} Found placeholder - */ - - }, { - key: "placeholderChoice", - get: function get() { - return [].concat(this.choices).reverse().find(function (choice) { - return choice.placeholder === true; - }); - } - /** - * Get groups from store - * @returns {Group[]} Group objects - */ - - }, { - key: "groups", - get: function get() { - return this.state.groups; - } - /** - * Get active groups from store - * @returns {Group[]} 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 -function dropdown_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 dropdown_createClass(Constructor, protoProps, staticProps) { if (protoProps) dropdown_defineProperties(Constructor.prototype, protoProps); if (staticProps) dropdown_defineProperties(Constructor, staticProps); return Constructor; } - -/** - * @typedef {import('../../../types/index').Choices.passedElement} passedElement - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - */ -var Dropdown = -/*#__PURE__*/ -function () { - /** - * @param {{ - * element: HTMLElement, - * type: passedElement['type'], - * classNames: ClassNames, - * }} args - */ - function Dropdown(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames; - this.element = element; - this.classNames = classNames; - this.type = type; - this.isActive = false; - } - /** - * Bottom position of dropdown in viewport coordinates - * @returns {number} Vertical position - */ - - - var _proto = Dropdown.prototype; - - /** - * Find element that matches passed selector - * @param {string} selector - * @returns {HTMLElement | null} - */ - _proto.getChild = function getChild(selector) { - return this.element.querySelector(selector); - } - /** - * Show dropdown to user by adding active state class - * @returns {this} - */ - ; - - _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 - * @returns {this} - */ - ; - - _proto.hide = function hide() { - this.element.classList.remove(this.classNames.activeState); - this.element.setAttribute('aria-expanded', 'false'); - this.isActive = false; - return this; - }; - - dropdown_createClass(Dropdown, [{ - key: "distanceFromTopWindow", - get: function get() { - return this.element.getBoundingClientRect().bottom; - } - }]); - - return Dropdown; -}(); - - -// CONCATENATED MODULE: ./src/scripts/constants.js - -/** - * @typedef {import('../../types/index').Choices.ClassNames} ClassNames - * @typedef {import('../../types/index').Choices.Options} Options - */ - -/** @type {ClassNames} */ - -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', - selectedState: 'is-selected', - flippedState: 'is-flipped', - loadingState: 'is-loading', - noResults: 'has-no-results', - noChoices: 'has-no-choices' -}; -/** @type {Options} */ - -var DEFAULT_CONFIG = { - items: [], - choices: [], - silent: false, - renderChoiceLimit: -1, - maxItemCount: -1, - addItems: true, - addItemFilter: 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, - sorter: 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"; - }, - valueComparer: function valueComparer(value1, value2) { - return value1 === value2; - }, - 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 TEXT_TYPE = 'text'; -var SELECT_ONE_TYPE = 'select-one'; -var SELECT_MULTIPLE_TYPE = 'select-multiple'; -var SCROLLING_SPEED = 4; -// CONCATENATED MODULE: ./src/scripts/components/container.js - - -/** - * @typedef {import('../../../types/index').Choices.passedElement} passedElement - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - */ - -var container_Container = -/*#__PURE__*/ -function () { - /** - * @param {{ - * element: HTMLElement, - * type: passedElement['type'], - * classNames: ClassNames, - * position - * }} args - */ - function Container(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames, - position = _ref.position; - this.element = element; - this.classNames = classNames; - this.type = type; - this.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); - } - - var _proto = Container.prototype; - - _proto.addEventListeners = function addEventListeners() { - this.element.addEventListener('focus', this._onFocus); - this.element.addEventListener('blur', this._onBlur); - }; - - _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 {boolean} - */ - ; - - _proto.shouldFlip = function shouldFlip(dropdownPos) { - if (typeof dropdownPos !== 'number') { - 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 = !window.matchMedia("(min-height: " + (dropdownPos + 1) + "px)").matches; - } else if (this.position === 'top') { - shouldFlip = true; - } - - return shouldFlip; - } - /** - * @param {string} activeDescendantID - */ - ; - - _proto.setActiveDescendant = function setActiveDescendant(activeDescendantID) { - this.element.setAttribute('aria-activedescendant', activeDescendantID); - }; - - _proto.removeActiveDescendant = function removeActiveDescendant() { - this.element.removeAttribute('aria-activedescendant'); - } - /** - * @param {number} dropdownPos - */ - ; - - _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); - }; - - _proto.enable = function enable() { - this.element.classList.remove(this.classNames.disabledState); - this.element.removeAttribute('aria-disabled'); - - if (this.type === SELECT_ONE_TYPE) { - this.element.setAttribute('tabindex', '0'); - } - - this.isDisabled = false; - }; - - _proto.disable = function disable() { - this.element.classList.add(this.classNames.disabledState); - this.element.setAttribute('aria-disabled', 'true'); - - if (this.type === SELECT_ONE_TYPE) { - this.element.setAttribute('tabindex', '-1'); - } - - this.isDisabled = true; - } - /** - * @param {HTMLElement} element - */ - ; - - _proto.wrap = function wrap(element) { - utils_wrap(element, this.element); - } - /** - * @param {Element} 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); - }; - - _proto.addLoadingState = function addLoadingState() { - this.element.classList.add(this.classNames.loadingState); - this.element.setAttribute('aria-busy', 'true'); - this.isLoading = true; - }; - - _proto.removeLoadingState = function removeLoadingState() { - this.element.classList.remove(this.classNames.loadingState); - this.element.removeAttribute('aria-busy'); - this.isLoading = false; - }; - - _proto._onFocus = function _onFocus() { - this.isFocussed = true; - }; - - _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; } - - - -/** - * @typedef {import('../../../types/index').Choices.passedElement} passedElement - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - */ - -var input_Input = -/*#__PURE__*/ -function () { - /** - * @param {{ - * element: HTMLInputElement, - * type: passedElement['type'], - * classNames: ClassNames, - * preventPaste: boolean - * }} args - */ - function Input(_ref) { - var element = _ref.element, - type = _ref.type, - classNames = _ref.classNames, - preventPaste = _ref.preventPaste; - this.element = element; - this.type = type; - this.classNames = classNames; - this.preventPaste = preventPaste; - this.isFocussed = this.element === document.activeElement; - this.isDisabled = element.disabled; - this._onPaste = this._onPaste.bind(this); - this._onInput = this._onInput.bind(this); - this._onFocus = this._onFocus.bind(this); - this._onBlur = this._onBlur.bind(this); - } - /** - * @param {string} placeholder - */ - - - var _proto = Input.prototype; - - _proto.addEventListeners = function addEventListeners() { - this.element.addEventListener('paste', this._onPaste); - this.element.addEventListener('input', this._onInput, { - passive: true - }); - this.element.addEventListener('focus', this._onFocus, { - passive: true - }); - this.element.addEventListener('blur', this._onBlur, { - passive: true - }); - }; - - _proto.removeEventListeners = function removeEventListeners() { - this.element.removeEventListener('input', this._onInput, { - passive: true - }); - this.element.removeEventListener('paste', this._onPaste); - this.element.removeEventListener('focus', this._onFocus, { - passive: true - }); - this.element.removeEventListener('blur', this._onBlur, { - passive: true - }); - }; - - _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 - * @param {boolean} setWidth - * @returns {this} - */ - ; - - _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 - */ - ; - - _proto.setWidth = function setWidth() { - // Resize input to contents or placeholder - var _this$element = this.element, - style = _this$element.style, - value = _this$element.value, - placeholder = _this$element.placeholder; - style.minWidth = placeholder.length + 1 + "ch"; - style.width = value.length + 1 + "ch"; - } - /** - * @param {string} activeDescendantID - */ - ; - - _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_TYPE) { - this.setWidth(); - } - } - /** - * @param {Event} event - */ - ; - - _proto._onPaste = function _onPaste(event) { - if (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; - } - /** - * @returns {string} - */ - - }, { - key: "value", - get: function get() { - return sanitise(this.element.value); - } - /** - * @param {string} value - */ - , - set: function set(value) { - this.element.value = value; - } - }]); - - return Input; -}(); - - -// CONCATENATED MODULE: ./src/scripts/components/list.js - -/** - * @typedef {import('../../../types/index').Choices.Choice} Choice - */ - -var list_List = -/*#__PURE__*/ -function () { - /** - * @param {{ element: HTMLElement }} args - */ - function List(_ref) { - var element = _ref.element; - this.element = element; - this.scrollPos = this.element.scrollTop; - this.height = this.element.offsetHeight; - } - - var _proto = List.prototype; - - _proto.clear = function clear() { - this.element.innerHTML = ''; - } - /** - * @param {Element | DocumentFragment} node - */ - ; - - _proto.append = function append(node) { - this.element.appendChild(node); - } - /** - * @param {string} selector - * @returns {Element | null} - */ - ; - - _proto.getChild = function getChild(selector) { - return this.element.querySelector(selector); - } - /** - * @returns {boolean} - */ - ; - - _proto.hasChildren = function hasChildren() { - return this.element.hasChildNodes(); - }; - - _proto.scrollToTop = function scrollToTop() { - this.element.scrollTop = 0; - } - /** - * @param {Element} element - * @param {1 | -1} direction - */ - ; - - _proto.scrollToChildElement = function scrollToChildElement(element, direction) { - var _this = this; - - if (!element) { - return; - } - - var listHeight = this.element.offsetHeight; // Scroll position of dropdown - - var listScrollPosition = this.element.scrollTop + listHeight; - var elementHeight = element.offsetHeight; // Distance from bottom of element to top of parent - - var elementPos = element.offsetTop + elementHeight; // Difference between the element and scroll position - - var destination = direction > 0 ? this.element.scrollTop + elementPos - listScrollPosition : element.offsetTop; - requestAnimationFrame(function () { - _this._animateScroll(destination, direction); - }); - } - /** - * @param {number} scrollPos - * @param {number} strength - * @param {number} destination - */ - ; - - _proto._scrollDown = function _scrollDown(scrollPos, strength, destination) { - var easing = (destination - scrollPos) / strength; - var distance = easing > 1 ? easing : 1; - this.element.scrollTop = scrollPos + distance; - } - /** - * @param {number} scrollPos - * @param {number} strength - * @param {number} destination - */ - ; - - _proto._scrollUp = function _scrollUp(scrollPos, strength, destination) { - var easing = (scrollPos - destination) / strength; - var distance = easing > 1 ? easing : 1; - this.element.scrollTop = scrollPos - distance; - } - /** - * @param {*} destination - * @param {*} direction - */ - ; - - _proto._animateScroll = function _animateScroll(destination, direction) { - var _this2 = this; - - var strength = SCROLLING_SPEED; - var choiceListScrollTop = this.element.scrollTop; - var continueAnimation = false; - - if (direction > 0) { - this._scrollDown(choiceListScrollTop, strength, destination); - - if (choiceListScrollTop < destination) { - continueAnimation = true; - } - } else { - this._scrollUp(choiceListScrollTop, strength, destination); - - if (choiceListScrollTop > destination) { - continueAnimation = true; - } - } - - if (continueAnimation) { - requestAnimationFrame(function () { - _this2._animateScroll(destination, 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; } - - -/** - * @typedef {import('../../../types/index').Choices.passedElement} passedElement - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - */ - -var wrapped_element_WrappedElement = -/*#__PURE__*/ -function () { - /** - * @param {{ - * element: HTMLInputElement | HTMLSelectElement, - * classNames: ClassNames, - * }} args - */ - function WrappedElement(_ref) { - var element = _ref.element, - classNames = _ref.classNames; + function WrappedElement(_a) { + var element = _a.element, + classNames = _a.classNames; this.element = element; this.classNames = classNames; @@ -2515,9 +1187,33 @@ function () { this.isDisabled = false; } - var _proto = WrappedElement.prototype; + Object.defineProperty(WrappedElement.prototype, "isActive", { + get: function get() { + return this.element.dataset.choice === 'active'; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WrappedElement.prototype, "dir", { + get: function get() { + return this.element.dir; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WrappedElement.prototype, "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; + }, + enumerable: true, + configurable: true + }); - _proto.conceal = function conceal() { + WrappedElement.prototype.conceal = function () { // Hide passed input this.element.classList.add(this.classNames.input); this.element.hidden = true; // Remove element from tab index @@ -2533,7 +1229,7 @@ function () { this.element.setAttribute('data-choice', 'active'); }; - _proto.reveal = function reveal() { + WrappedElement.prototype.reveal = function () { // Reinstate passed element this.element.classList.remove(this.classNames.input); this.element.hidden = false; @@ -2554,809 +1250,127 @@ function () { this.element.value = this.element.value; // eslint-disable-line no-self-assign }; - _proto.enable = function enable() { + WrappedElement.prototype.enable = function () { this.element.removeAttribute('disabled'); this.element.disabled = false; this.isDisabled = false; }; - _proto.disable = function disable() { + WrappedElement.prototype.disable = function () { this.element.setAttribute('disabled', ''); this.element.disabled = true; this.isDisabled = true; }; - _proto.triggerEvent = function triggerEvent(eventType, data) { - dispatchEvent(this.element, eventType, data); + WrappedElement.prototype.triggerEvent = function (eventType, data) { + utils_1.dispatchEvent(this.element, eventType, data); }; - wrapped_element_createClass(WrappedElement, [{ - key: "isActive", - get: function get() { - return this.element.dataset.choice === 'active'; - } - }, { - key: "dir", - get: function get() { - return this.element.dir; - } - }, { - 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; }(); +exports.default = 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); } } +/***/ }), +/* 6 */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { -function wrapped_input_createClass(Constructor, protoProps, staticProps) { if (protoProps) wrapped_input_defineProperties(Constructor.prototype, protoProps); if (staticProps) wrapped_input_defineProperties(Constructor, staticProps); return Constructor; } +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return symbolObservablePonyfill; }); +function symbolObservablePonyfill(root) { + var result; + var Symbol = root.Symbol; -function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } + if (typeof Symbol === 'function') { + if (Symbol.observable) { + result = Symbol.observable; + } else { + result = Symbol('observable'); + Symbol.observable = result; + } + } else { + result = '@@observable'; + } + + return result; +}; -/** - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - * @typedef {import('../../../types/index').Choices.Item} Item - */ +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { -var WrappedInput = -/*#__PURE__*/ -function (_WrappedElement) { - _inheritsLoose(WrappedInput, _WrappedElement); - - /** - * @param {{ - * element: HTMLInputElement, - * classNames: ClassNames, - * delimiter: string - * }} args - */ - 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; - } - /** - * @returns {string} - */ +module.exports = __webpack_require__(8); - wrapped_input_createClass(WrappedInput, [{ - key: "value", - get: function get() { - return this.element.value; - } - /** - * @param {Item[]} items - */ - , - 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; - } - }]); +/***/ }), +/* 8 */ +/***/ (function(module, exports, __webpack_require__) { - return WrappedInput; -}(wrapped_element_WrappedElement); +"use strict"; -// 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; } - - -/** - * @typedef {import('../../../types/index').Choices.ClassNames} ClassNames - * @typedef {import('../../../types/index').Choices.Item} Item - * @typedef {import('../../../types/index').Choices.Choice} Choice - */ - -var WrappedSelect = -/*#__PURE__*/ -function (_WrappedElement) { - wrapped_select_inheritsLoose(WrappedSelect, _WrappedElement); - - /** - * @param {{ - * element: HTMLSelectElement, - * classNames: ClassNames, - * delimiter: string - * template: function - * }} args - */ - 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 __spreadArrays = this && this.__spreadArrays || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) { + s += arguments[i].length; } - var _proto = WrappedSelect.prototype; - - /** - * @param {DocumentFragment} fragment - */ - _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]'); + for (var r = Array(s), k = 0, i = 0; i < il; i++) { + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) { + r[k] = a[j]; } - /** - * @returns {Element[]} - */ - - }, { - key: "optionGroups", - get: function get() { - return Array.from(this.element.getElementsByTagName('OPTGROUP')); - } - /** - * @returns {Item[] | Choice[]} - */ - - }, { - key: "options", - get: function get() { - return Array.from(this.element.options); - } - /** - * @param {Item[] | Choice[]} 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 - - - - - - - -// CONCATENATED MODULE: ./src/scripts/templates.js -/** - * Helpers to create HTML elements used by Choices - * Can be overridden by providing `callbackOnCreateTemplates` option - * @typedef {import('../../types/index').Choices.Templates} Templates - * @typedef {import('../../types/index').Choices.ClassNames} ClassNames - * @typedef {import('../../types/index').Choices.Options} Options - * @typedef {import('../../types/index').Choices.Item} Item - * @typedef {import('../../types/index').Choices.Choice} Choice - * @typedef {import('../../types/index').Choices.Group} Group - */ -var TEMPLATES = -/** @type {Templates} */ -{ - /** - * @param {Partial} classNames - * @param {"ltr" | "rtl" | "auto"} dir - * @param {boolean} isSelectElement - * @param {boolean} isSelectOneElement - * @param {boolean} searchEnabled - * @param {"select-one" | "select-multiple" | "text"} passedElementType - */ - containerOuter: function containerOuter(_ref, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { - var _containerOuter = _ref.containerOuter; - var div = Object.assign(document.createElement('div'), { - className: _containerOuter - }); - div.dataset.type = passedElementType; - - if (dir) { - div.dir = dir; - } - - if (isSelectOneElement) { - div.tabIndex = 0; - } - - if (isSelectElement) { - div.setAttribute('role', searchEnabled ? 'combobox' : 'listbox'); - - if (searchEnabled) { - div.setAttribute('aria-autocomplete', 'list'); - } - } - - div.setAttribute('aria-haspopup', 'true'); - div.setAttribute('aria-expanded', 'false'); - return div; - }, - - /** - * @param {Partial} classNames - */ - containerInner: function containerInner(_ref2) { - var _containerInner = _ref2.containerInner; - return Object.assign(document.createElement('div'), { - className: _containerInner - }); - }, - - /** - * @param {Partial} classNames - * @param {boolean} isSelectOneElement - */ - itemList: function itemList(_ref3, isSelectOneElement) { - var list = _ref3.list, - listSingle = _ref3.listSingle, - listItems = _ref3.listItems; - return Object.assign(document.createElement('div'), { - className: list + " " + (isSelectOneElement ? listSingle : listItems) - }); - }, - - /** - * @param {Partial} classNames - * @param {string} value - */ - placeholder: function placeholder(_ref4, value) { - var _placeholder = _ref4.placeholder; - return Object.assign(document.createElement('div'), { - className: _placeholder, - innerHTML: value - }); - }, - - /** - * @param {Partial} classNames - * @param {Item} item - * @param {boolean} removeItemButton - */ - item: function item(_ref5, _ref6, removeItemButton) { - var _item = _ref5.item, - button = _ref5.button, - highlightedState = _ref5.highlightedState, - itemSelectable = _ref5.itemSelectable, - placeholder = _ref5.placeholder; - var id = _ref6.id, - value = _ref6.value, - label = _ref6.label, - customProperties = _ref6.customProperties, - active = _ref6.active, - disabled = _ref6.disabled, - highlighted = _ref6.highlighted, - isPlaceholder = _ref6.placeholder; - var div = Object.assign(document.createElement('div'), { - className: _item, - innerHTML: label - }); - Object.assign(div.dataset, { - item: '', - id: id, - value: value, - customProperties: customProperties - }); - - if (active) { - div.setAttribute('aria-selected', 'true'); - } - - if (disabled) { - div.setAttribute('aria-disabled', 'true'); - } - - if (isPlaceholder) { - div.classList.add(placeholder); - } - - div.classList.add(highlighted ? highlightedState : itemSelectable); - - if (removeItemButton) { - if (disabled) { - div.classList.remove(itemSelectable); - } - - div.dataset.deletable = ''; - /** @todo This MUST be localizable, not hardcoded! */ - - var REMOVE_ITEM_TEXT = 'Remove item'; - var removeButton = Object.assign(document.createElement('button'), { - type: 'button', - className: button, - innerHTML: REMOVE_ITEM_TEXT - }); - removeButton.setAttribute('aria-label', REMOVE_ITEM_TEXT + ": '" + value + "'"); - removeButton.dataset.button = ''; - div.appendChild(removeButton); - } - - return div; - }, - - /** - * @param {Partial} classNames - * @param {boolean} isSelectOneElement - */ - choiceList: function choiceList(_ref7, isSelectOneElement) { - var list = _ref7.list; - var div = Object.assign(document.createElement('div'), { - className: list - }); - - if (!isSelectOneElement) { - div.setAttribute('aria-multiselectable', 'true'); - } - - div.setAttribute('role', 'listbox'); - return div; - }, - - /** - * @param {Partial} classNames - * @param {Group} group - */ - choiceGroup: function choiceGroup(_ref8, _ref9) { - var group = _ref8.group, - groupHeading = _ref8.groupHeading, - itemDisabled = _ref8.itemDisabled; - var id = _ref9.id, - value = _ref9.value, - disabled = _ref9.disabled; - var div = Object.assign(document.createElement('div'), { - className: group + " " + (disabled ? itemDisabled : '') - }); - div.setAttribute('role', 'group'); - Object.assign(div.dataset, { - group: '', - id: id, - value: value - }); - - if (disabled) { - div.setAttribute('aria-disabled', 'true'); - } - - div.appendChild(Object.assign(document.createElement('div'), { - className: groupHeading, - innerHTML: value - })); - return div; - }, - - /** - * @param {Partial} classNames - * @param {Choice} choice - * @param {Options['itemSelectText']} selectText - */ - choice: function choice(_ref10, _ref11, selectText) { - var item = _ref10.item, - itemChoice = _ref10.itemChoice, - itemSelectable = _ref10.itemSelectable, - selectedState = _ref10.selectedState, - itemDisabled = _ref10.itemDisabled, - placeholder = _ref10.placeholder; - var id = _ref11.id, - value = _ref11.value, - label = _ref11.label, - groupId = _ref11.groupId, - elementId = _ref11.elementId, - isDisabled = _ref11.disabled, - isSelected = _ref11.selected, - isPlaceholder = _ref11.placeholder; - var div = Object.assign(document.createElement('div'), { - id: elementId, - innerHTML: label, - className: item + " " + itemChoice - }); - - if (isSelected) { - div.classList.add(selectedState); - } - - if (isPlaceholder) { - div.classList.add(placeholder); - } - - div.setAttribute('role', groupId > 0 ? 'treeitem' : 'option'); - Object.assign(div.dataset, { - choice: '', - id: id, - value: value, - selectText: selectText - }); - - if (isDisabled) { - div.classList.add(itemDisabled); - div.dataset.choiceDisabled = ''; - div.setAttribute('aria-disabled', 'true'); - } else { - div.classList.add(itemSelectable); - div.dataset.choiceSelectable = ''; - } - - return div; - }, - - /** - * @param {Partial} classNames - * @param {string} placeholderValue - */ - input: function input(_ref12, placeholderValue) { - var _input = _ref12.input, - inputCloned = _ref12.inputCloned; - var inp = Object.assign(document.createElement('input'), { - type: 'text', - className: _input + " " + inputCloned, - autocomplete: 'off', - autocapitalize: 'off', - spellcheck: false - }); - inp.setAttribute('role', 'textbox'); - inp.setAttribute('aria-autocomplete', 'list'); - inp.setAttribute('aria-label', placeholderValue); - return inp; - }, - - /** - * @param {Partial} classNames - */ - dropdown: function dropdown(_ref13) { - var list = _ref13.list, - listDropdown = _ref13.listDropdown; - var div = document.createElement('div'); - div.classList.add(list, listDropdown); - div.setAttribute('aria-expanded', 'false'); - return div; - }, - - /** - * - * @param {Partial} classNames - * @param {string} innerHTML - * @param {"no-choices" | "no-results" | ""} type - */ - notice: function notice(_ref14, innerHTML, type) { - var item = _ref14.item, - itemChoice = _ref14.itemChoice, - noResults = _ref14.noResults, - noChoices = _ref14.noChoices; - - if (type === void 0) { - type = ''; - } - - var classes = [item, itemChoice]; - - if (type === 'no-choices') { - classes.push(noChoices); - } else if (type === 'no-results') { - classes.push(noResults); - } - - return Object.assign(document.createElement('div'), { - innerHTML: innerHTML, - className: classes.join(' ') - }); - }, - - /** - * @param {Item} option - */ - option: function option(_ref15) { - var label = _ref15.label, - value = _ref15.value, - customProperties = _ref15.customProperties, - active = _ref15.active, - disabled = _ref15.disabled; - var opt = new Option(label, value, false, active); - - if (customProperties) { - opt.dataset.customProperties = customProperties; - } - - opt.disabled = disabled; - return opt; - } -}; -/* harmony default export */ var templates = (TEMPLATES); -// CONCATENATED MODULE: ./src/scripts/actions/choices.js -/** - * @typedef {import('redux').Action} Action - * @typedef {import('../../../types/index').Choices.Choice} Choice - */ - -/** - * @argument {Choice} choice - * @returns {Action & Choice} - */ - -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 - }; -}; -/** - * @argument {Choice[]} results - * @returns {Action & { results: Choice[] }} - */ - -var choices_filterChoices = function filterChoices(results) { - return { - type: ACTION_TYPES.FILTER_CHOICES, - results: results - }; -}; -/** - * @argument {boolean} active - * @returns {Action & { active: boolean }} - */ - -var choices_activateChoices = function activateChoices(active) { - if (active === void 0) { - active = true; } - return { - type: ACTION_TYPES.ACTIVATE_CHOICES, - active: active + return r; +}; + +var __importDefault = this && this.__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod }; }; -/** - * @returns {Action} - */ -var choices_clearChoices = function clearChoices() { - return { - type: ACTION_TYPES.CLEAR_CHOICES - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/items.js - -/** - * @typedef {import('redux').Action} Action - * @typedef {import('../../../types/index').Choices.Item} Item - */ - -/** - * @param {Item} item - * @returns {Action & Item} - */ - -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 - }; -}; -/** - * @param {string} id - * @param {string} choiceId - * @returns {Action & { id: string, choiceId: string }} - */ - -var items_removeItem = function removeItem(id, choiceId) { - return { - type: ACTION_TYPES.REMOVE_ITEM, - id: id, - choiceId: choiceId - }; -}; -/** - * @param {string} id - * @param {boolean} highlighted - * @returns {Action & { id: string, highlighted: boolean }} - */ - -var items_highlightItem = function highlightItem(id, highlighted) { - return { - type: ACTION_TYPES.HIGHLIGHT_ITEM, - id: id, - highlighted: highlighted - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/groups.js - -/** - * @typedef {import('redux').Action} Action - * @typedef {import('../../../types/index').Choices.Group} Group - */ - -/** - * @param {Group} group - * @returns {Action & Group} - */ - -var groups_addGroup = function addGroup(_ref) { - var value = _ref.value, - id = _ref.id, - active = _ref.active, - disabled = _ref.disabled; - return { - type: ACTION_TYPES.ADD_GROUP, - value: value, - id: id, - active: active, - disabled: disabled - }; -}; -// CONCATENATED MODULE: ./src/scripts/actions/misc.js -/** - * @typedef {import('redux').Action} Action - */ - -/** - * @returns {Action} - */ -var clearAll = function clearAll() { - return { - type: 'CLEAR_ALL' - }; -}; -/** - * @param {any} state - * @returns {Action & { state: object }} - */ - -var resetTo = function resetTo(state) { - return { - type: 'RESET_TO', - state: state - }; -}; -/** - * @param {boolean} isLoading - * @returns {Action & { isLoading: boolean }} - */ - -var setIsLoading = function setIsLoading(isLoading) { - return { - type: 'SET_IS_LOADING', - isLoading: isLoading - }; -}; -// CONCATENATED MODULE: ./src/scripts/choices.js -function choices_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 choices_createClass(Constructor, protoProps, staticProps) { if (protoProps) choices_defineProperties(Constructor.prototype, protoProps); if (staticProps) choices_defineProperties(Constructor, staticProps); return Constructor; } +Object.defineProperty(exports, "__esModule", { + value: true +}); +/* eslint-disable @typescript-eslint/no-explicit-any */ +var fuse_js_1 = __importDefault(__webpack_require__(9)); +var deepmerge_1 = __importDefault(__webpack_require__(10)); +var store_1 = __importDefault(__webpack_require__(11)); +var components_1 = __webpack_require__(18); +var constants_1 = __webpack_require__(0); +var templates_1 = __importDefault(__webpack_require__(25)); +var choices_1 = __webpack_require__(26); +var items_1 = __webpack_require__(27); +var groups_1 = __webpack_require__(28); +var misc_1 = __webpack_require__(29); +var utils_1 = __webpack_require__(1); +var reducers_1 = __webpack_require__(4); /** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */ + var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style; -/** - * @typedef {import('../../types/index').Choices.Choice} Choice - * @typedef {import('../../types/index').Choices.Item} Item - * @typedef {import('../../types/index').Choices.Group} Group - * @typedef {import('../../types/index').Choices.Options} Options - */ - -/** @type {Partial} */ - var USER_DEFAULTS = {}; /** * Choices * @author Josh Johnson */ -var choices_Choices = -/*#__PURE__*/ +var Choices = +/** @class */ function () { - choices_createClass(Choices, null, [{ - key: "defaults", - get: function get() { - return Object.preventExtensions({ - get options() { - return USER_DEFAULTS; - }, - - get templates() { - return TEMPLATES; - } - - }); - } - /** - * @param {string | HTMLInputElement | HTMLSelectElement} element - * @param {Partial} userConfig - */ - - }]); - function Choices(element, userConfig) { var _this = this; @@ -3368,15 +1382,14 @@ function () { userConfig = {}; } - /** @type {Partial} */ - this.config = cjs_default.a.all([DEFAULT_CONFIG, Choices.defaults.options, userConfig], // When merging array configs, replace with a copy of the userConfig array, + this.config = deepmerge_1.default.all([constants_1.DEFAULT_CONFIG, Choices.defaults.options, userConfig], // When merging array configs, replace with a copy of the userConfig array, // instead of concatenating with the default array { arrayMerge: function arrayMerge(_, sourceArray) { - return [].concat(sourceArray); + return __spreadArrays(sourceArray); } }); - var invalidConfigOptions = diff(this.config, DEFAULT_CONFIG); + var invalidConfigOptions = utils_1.diff(this.config, constants_1.DEFAULT_CONFIG); if (invalidConfigOptions.length) { console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', ')); @@ -3388,13 +1401,13 @@ function () { throw TypeError('Expected one of the following types text|select-one|select-multiple'); } - this._isTextElement = passedElement.type === TEXT_TYPE; - this._isSelectOneElement = passedElement.type === SELECT_ONE_TYPE; - this._isSelectMultipleElement = passedElement.type === SELECT_MULTIPLE_TYPE; + this._isTextElement = passedElement.type === constants_1.TEXT_TYPE; + this._isSelectOneElement = passedElement.type === constants_1.SELECT_ONE_TYPE; + this._isSelectMultipleElement = passedElement.type === constants_1.SELECT_MULTIPLE_TYPE; this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement; this.config.searchEnabled = this._isSelectMultipleElement || this.config.searchEnabled; - if (!['auto', 'always'].includes(this.config.renderSelectedChoices)) { + if (!['auto', 'always'].includes("" + this.config.renderSelectedChoices)) { this.config.renderSelectedChoices = 'auto'; } @@ -3404,13 +1417,13 @@ function () { } if (this._isTextElement) { - this.passedElement = new WrappedInput({ + this.passedElement = new components_1.WrappedInput({ element: passedElement, classNames: this.config.classNames, delimiter: this.config.delimiter }); } else { - this.passedElement = new WrappedSelect({ + this.passedElement = new components_1.WrappedSelect({ element: passedElement, classNames: this.config.classNames, template: function template(data) { @@ -3420,31 +1433,27 @@ function () { } this.initialised = false; - this._store = new store_Store(); - this._initialState = {}; - this._currentState = {}; - this._prevState = {}; + this._store = new store_1.default(); + this._initialState = reducers_1.defaultState; + this._currentState = reducers_1.defaultState; + this._prevState = reducers_1.defaultState; this._currentValue = ''; - this._canSearch = this.config.searchEnabled; + 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._baseId = utils_1.generateId(this.passedElement.element, 'choices-'); /** * setting direction in cases where it's explicitly set on passedElement * or when calculated direction is different from the document - * @type {HTMLElement['dir']} */ this._direction = this.passedElement.dir; if (!this._direction) { - var _window$getComputedSt = window.getComputedStyle(this.passedElement.element), - elementDirection = _window$getComputedSt.direction; - - var _window$getComputedSt2 = window.getComputedStyle(document.documentElement), - documentDirection = _window$getComputedSt2.direction; + var elementDirection = window.getComputedStyle(this.passedElement.element).direction; + var documentDirection = window.getComputedStyle(document.documentElement).direction; if (elementDirection !== documentDirection) { this._direction = elementDirection; @@ -3453,30 +1462,35 @@ function () { this._idNames = { itemChoice: 'item-choice' - }; // Assign preset groups from passed element + }; - this._presetGroups = this.passedElement.optionGroups; // Assign preset options from passed element + if (this._isSelectElement) { + // Assign preset groups from passed element + this._presetGroups = this.passedElement.optionGroups; // Assign preset options from passed element + + this._presetOptions = this.passedElement.options; + } // Assign preset choices from passed object - this._presetOptions = this.passedElement.options; // Assign preset choices from passed object this._presetChoices = this.config.choices; // Assign preset items from passed object first this._presetItems = this.config.items; // Add any values passed from attribute - if (this.passedElement.value) { - this._presetItems = this._presetItems.concat(this.passedElement.value.split(this.config.delimiter)); + if (this.passedElement.value && this._isTextElement) { + var splitValues = this.passedElement.value.split(this.config.delimiter); + this._presetItems = this._presetItems.concat(splitValues); } // Create array of choices from option elements if (this.passedElement.options) { - this.passedElement.options.forEach(function (o) { + this.passedElement.options.forEach(function (option) { _this._presetChoices.push({ - value: o.value, - label: o.innerHTML, - selected: o.selected, - disabled: o.disabled || o.parentNode.disabled, - placeholder: o.value === '' || o.hasAttribute('placeholder'), - customProperties: o.getAttribute('data-custom-properties') + value: option.value, + label: option.innerHTML, + selected: !!option.selected, + disabled: option.disabled || option.parentNode.disabled, + placeholder: option.value === '' || option.hasAttribute('placeholder'), + customProperties: option.dataset['custom-properties'] }); }); } @@ -3492,7 +1506,7 @@ function () { 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._onSelectKey = this._onSelectKey.bind(this); this._onEnterKey = this._onEnterKey.bind(this); this._onEscapeKey = this._onEscapeKey.bind(this); this._onDirectionKey = this._onDirectionKey.bind(this); @@ -3500,7 +1514,9 @@ function () { if (this.passedElement.isActive) { if (!this.config.silent) { - console.warn('Trying to initialise Choices on element already initialised'); + console.warn('Trying to initialise Choices on element already initialised', { + element: element + }); } this.initialised = true; @@ -3511,9 +1527,24 @@ function () { this.init(); } - var _proto = Choices.prototype; + Object.defineProperty(Choices, "defaults", { + get: function get() { + return Object.preventExtensions({ + get options() { + return USER_DEFAULTS; + }, - _proto.init = function init() { + get templates() { + return templates_1.default; + } + + }); + }, + enumerable: true, + configurable: true + }); + + Choices.prototype.init = function () { if (this.initialised) { return; } @@ -3522,11 +1553,7 @@ function () { 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._createStructure(); this._store.subscribe(this._render); @@ -3548,7 +1575,7 @@ function () { } }; - _proto.destroy = function destroy() { + Choices.prototype.destroy = function () { if (!this.initialised) { return; } @@ -3563,11 +1590,11 @@ function () { this.passedElement.options = this._presetOptions; } - this._templates = null; + this._templates = templates_1.default; this.initialised = false; }; - _proto.enable = function enable() { + Choices.prototype.enable = function () { if (this.passedElement.isDisabled) { this.passedElement.enable(); } @@ -3582,7 +1609,7 @@ function () { return this; }; - _proto.disable = function disable() { + Choices.prototype.disable = function () { if (!this.passedElement.isDisabled) { this.passedElement.disable(); } @@ -3597,28 +1624,28 @@ function () { return this; }; - _proto.highlightItem = function highlightItem(item, runEvent) { + Choices.prototype.highlightItem = function (item, runEvent) { if (runEvent === void 0) { runEvent = true; } - if (!item) { + if (!item || !item.id) { 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; + _a = item.groupId, + groupId = _a === void 0 ? -1 : _a, + _b = item.value, + value = _b === void 0 ? '' : _b, + _c = item.label, + label = _c === void 0 ? '' : _c; var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - this._store.dispatch(items_highlightItem(id, true)); + this._store.dispatch(items_1.highlightItem(id, true)); if (runEvent) { - this.passedElement.triggerEvent(EVENTS.highlightItem, { + this.passedElement.triggerEvent(constants_1.EVENTS.highlightItem, { id: id, value: value, label: label, @@ -3629,23 +1656,23 @@ function () { return this; }; - _proto.unhighlightItem = function unhighlightItem(item) { - if (!item) { + Choices.prototype.unhighlightItem = function (item) { + if (!item || !item.id) { 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; + _a = item.groupId, + groupId = _a === void 0 ? -1 : _a, + _b = item.value, + value = _b === void 0 ? '' : _b, + _c = item.label, + label = _c === void 0 ? '' : _c; var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; - this._store.dispatch(items_highlightItem(id, false)); + this._store.dispatch(items_1.highlightItem(id, false)); - this.passedElement.triggerEvent(EVENTS.highlightItem, { + this.passedElement.triggerEvent(constants_1.EVENTS.highlightItem, { id: id, value: value, label: label, @@ -3654,116 +1681,116 @@ function () { return this; }; - _proto.highlightAll = function highlightAll() { - var _this2 = this; + Choices.prototype.highlightAll = function () { + var _this = this; this._store.items.forEach(function (item) { - return _this2.highlightItem(item); + return _this.highlightItem(item); }); return this; }; - _proto.unhighlightAll = function unhighlightAll() { - var _this3 = this; + Choices.prototype.unhighlightAll = function () { + var _this = this; this._store.items.forEach(function (item) { - return _this3.unhighlightItem(item); + return _this.unhighlightItem(item); }); return this; }; - _proto.removeActiveItemsByValue = function removeActiveItemsByValue(value) { - var _this4 = this; + Choices.prototype.removeActiveItemsByValue = function (value) { + var _this = this; this._store.activeItems.filter(function (item) { return item.value === value; }).forEach(function (item) { - return _this4._removeItem(item); + return _this._removeItem(item); }); return this; }; - _proto.removeActiveItems = function removeActiveItems(excludedId) { - var _this5 = this; + Choices.prototype.removeActiveItems = function (excludedId) { + var _this = this; - this._store.activeItems.filter(function (_ref) { - var id = _ref.id; + this._store.activeItems.filter(function (_a) { + var id = _a.id; return id !== excludedId; }).forEach(function (item) { - return _this5._removeItem(item); + return _this._removeItem(item); }); return this; }; - _proto.removeHighlightedItems = function removeHighlightedItems(runEvent) { - var _this6 = this; + Choices.prototype.removeHighlightedItems = function (runEvent) { + var _this = this; if (runEvent === void 0) { runEvent = false; } this._store.highlightedActiveItems.forEach(function (item) { - _this6._removeItem(item); // If this action was performed by the user + _this._removeItem(item); // If this action was performed by the user // trigger the event if (runEvent) { - _this6._triggerChange(item.value); + _this._triggerChange(item.value); } }); return this; }; - _proto.showDropdown = function showDropdown(preventInputFocus) { - var _this7 = this; + Choices.prototype.showDropdown = function (preventInputFocus) { + var _this = this; if (this.dropdown.isActive) { return this; } requestAnimationFrame(function () { - _this7.dropdown.show(); + _this.dropdown.show(); - _this7.containerOuter.open(_this7.dropdown.distanceFromTopWindow); + _this.containerOuter.open(_this.dropdown.distanceFromTopWindow); - if (!preventInputFocus && _this7._canSearch) { - _this7.input.focus(); + if (!preventInputFocus && _this._canSearch) { + _this.input.focus(); } - _this7.passedElement.triggerEvent(EVENTS.showDropdown, {}); + _this.passedElement.triggerEvent(constants_1.EVENTS.showDropdown, {}); }); return this; }; - _proto.hideDropdown = function hideDropdown(preventInputBlur) { - var _this8 = this; + Choices.prototype.hideDropdown = function (preventInputBlur) { + var _this = this; if (!this.dropdown.isActive) { return this; } requestAnimationFrame(function () { - _this8.dropdown.hide(); + _this.dropdown.hide(); - _this8.containerOuter.close(); + _this.containerOuter.close(); - if (!preventInputBlur && _this8._canSearch) { - _this8.input.removeActiveDescendant(); + if (!preventInputBlur && _this._canSearch) { + _this.input.removeActiveDescendant(); - _this8.input.blur(); + _this.input.blur(); } - _this8.passedElement.triggerEvent(EVENTS.hideDropdown, {}); + _this.passedElement.triggerEvent(constants_1.EVENTS.hideDropdown, {}); }); return this; }; - _proto.getValue = function getValue(valueOnly) { + Choices.prototype.getValue = function (valueOnly) { if (valueOnly === void 0) { valueOnly = false; } @@ -3775,27 +1802,23 @@ function () { }, []); return this._isSelectOneElement ? values[0] : values; - } - /** - * @param {string[] | import('../../types/index').Choices.Item[]} items - */ - ; + }; - _proto.setValue = function setValue(items) { - var _this9 = this; + Choices.prototype.setValue = function (items) { + var _this = this; if (!this.initialised) { return this; } items.forEach(function (value) { - return _this9._setChoiceOrItem(value); + return _this._setChoiceOrItem(value); }); return this; }; - _proto.setChoiceByValue = function setChoiceByValue(value) { - var _this10 = this; + Choices.prototype.setChoiceByValue = function (value) { + var _this = this; if (!this.initialised || this._isTextElement) { return this; @@ -3805,10 +1828,10 @@ function () { var choiceValue = Array.isArray(value) ? value : [value]; // Loop through each value and choiceValue.forEach(function (val) { - return _this10._findAndSelectChoiceByValue(val); + return _this._findAndSelectChoiceByValue(val); }); return this; - } + }; /** * Set choices of select input via an array of objects (or function that returns array of object or promise of it), * a value field name and a label field name. @@ -3818,13 +1841,6 @@ function () { * * **Input types affected:** select-one, select-multiple * - * @template {Choice[] | ((instance: Choices) => object[] | Promise)} T - * @param {T} [choicesArrayOrFetcher] - * @param {string} [value = 'value'] - name of `value` field - * @param {string} [label = 'label'] - name of 'label' field - * @param {boolean} [replaceChoices = false] - whether to replace of add choices - * @returns {this | Promise} - * * @example * ```js * const example = new Choices(element); @@ -3879,10 +1895,10 @@ function () { * }], 'value', 'label', false); * ``` */ - ; - _proto.setChoices = function setChoices(choicesArrayOrFetcher, value, label, replaceChoices) { - var _this11 = this; + + Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices) { + var _this = this; if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; @@ -3919,37 +1935,38 @@ function () { if (typeof choicesArrayOrFetcher === 'function') { // it's a choices fetcher function - var fetcher = choicesArrayOrFetcher(this); + var fetcher_1 = choicesArrayOrFetcher(this); - if (typeof Promise === 'function' && fetcher instanceof Promise) { + if (typeof Promise === 'function' && fetcher_1 instanceof Promise) { // that's a promise // eslint-disable-next-line compat/compat return new Promise(function (resolve) { return requestAnimationFrame(resolve); + }) // eslint-disable-line compat/compat + .then(function () { + return _this._handleLoadingState(true); }).then(function () { - return _this11._handleLoadingState(true); - }).then(function () { - return fetcher; + return fetcher_1; }).then(function (data) { - return _this11.setChoices(data, value, label, replaceChoices); + return _this.setChoices(data, value, label, replaceChoices); }).catch(function (err) { - if (!_this11.config.silent) { + if (!_this.config.silent) { console.error(err); } }).then(function () { - return _this11._handleLoadingState(false); + return _this._handleLoadingState(false); }).then(function () { - return _this11; + return _this; }); } // function returned something else than promise, let's check if it's an array of choices - if (!Array.isArray(fetcher)) { - throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: " + typeof fetcher); + if (!Array.isArray(fetcher_1)) { + throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: " + typeof fetcher_1); } // recursion with results, it's sync and choices were cleared already - return this.setChoices(fetcher, value, label, false); + return this.setChoices(fetcher_1, value, label, false); } if (!Array.isArray(choicesArrayOrFetcher)) { @@ -3962,20 +1979,22 @@ function () { choicesArrayOrFetcher.forEach(function (groupOrChoice) { if (groupOrChoice.choices) { - _this11._addGroup({ - id: parseInt(groupOrChoice.id, 10) || null, + _this._addGroup({ + id: groupOrChoice.id ? parseInt("" + groupOrChoice.id, 10) : null, group: groupOrChoice, 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 + var choice = groupOrChoice; + + _this._addChoice({ + value: choice[value], + label: choice[label], + isSelected: !!choice.selected, + isDisabled: !!choice.disabled, + placeholder: !!choice.placeholder, + customProperties: choice.customProperties }); } }); @@ -3985,32 +2004,32 @@ function () { return this; }; - _proto.clearChoices = function clearChoices() { - this._store.dispatch(choices_clearChoices()); + Choices.prototype.clearChoices = function () { + this._store.dispatch(choices_1.clearChoices()); return this; }; - _proto.clearStore = function clearStore() { - this._store.dispatch(clearAll()); + Choices.prototype.clearStore = function () { + this._store.dispatch(misc_1.clearAll()); return this; }; - _proto.clearInput = function clearInput() { + Choices.prototype.clearInput = function () { var shouldSetInputWidth = !this._isSelectOneElement; this.input.clear(shouldSetInputWidth); if (!this._isTextElement && this._canSearch) { this._isSearching = false; - this._store.dispatch(choices_activateChoices(true)); + this._store.dispatch(choices_1.activateChoices(true)); } return this; }; - _proto._render = function _render() { + Choices.prototype._render = function () { if (this._store.isLoading()) { return; } @@ -4035,18 +2054,18 @@ function () { this._prevState = this._currentState; }; - _proto._renderChoices = function _renderChoices() { - var _this12 = this; + Choices.prototype._renderChoices = function () { + var _this = this; - var _this$_store = this._store, - activeGroups = _this$_store.activeGroups, - activeChoices = _this$_store.activeChoices; + var _a = this._store, + activeGroups = _a.activeGroups, + activeChoices = _a.activeChoices; var choiceListFragment = document.createDocumentFragment(); this.choiceList.clear(); if (this.config.resetScrollPosition) { requestAnimationFrame(function () { - return _this12.choiceList.scrollToTop(); + return _this.choiceList.scrollToTop(); }); } // If we have grouped options @@ -4079,13 +2098,14 @@ function () { this._highlightChoice(); } else { - // ...otherwise show a notice - this.choiceList.append(this._getTemplate('notice', canAddItem.notice)); + var notice = this._getTemplate('notice', canAddItem.notice); + + this.choiceList.append(notice); } } else { // Otherwise show a notice - var dropdownItem; - var notice; + var dropdownItem = void 0; + var notice = void 0; if (this._isSearching) { notice = typeof this.config.noResultsText === 'function' ? this.config.noResultsText() : this.config.noResultsText; @@ -4099,7 +2119,7 @@ function () { } }; - _proto._renderItems = function _renderItems() { + Choices.prototype._renderItems = function () { 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) @@ -4112,8 +2132,8 @@ function () { } }; - _proto._createGroupsFragment = function _createGroupsFragment(groups, choices, fragment) { - var _this13 = this; + Choices.prototype._createGroupsFragment = function (groups, choices, fragment) { + var _this = this; if (fragment === void 0) { fragment = document.createDocumentFragment(); @@ -4121,11 +2141,11 @@ function () { var getGroupChoices = function getGroupChoices(group) { return choices.filter(function (choice) { - if (_this13._isSelectOneElement) { + if (_this._isSelectOneElement) { return choice.groupId === group.id; } - return choice.groupId === group.id && (_this13.config.renderSelectedChoices === 'always' || !choice.selected); + return choice.groupId === group.id && (_this.config.renderSelectedChoices === 'always' || !choice.selected); }); }; // If sorting is enabled, filter groups @@ -4138,18 +2158,18 @@ function () { var groupChoices = getGroupChoices(group); if (groupChoices.length >= 1) { - var dropdownGroup = _this13._getTemplate('choiceGroup', group); + var dropdownGroup = _this._getTemplate('choiceGroup', group); fragment.appendChild(dropdownGroup); - _this13._createChoicesFragment(groupChoices, fragment, true); + _this._createChoicesFragment(groupChoices, fragment, true); } }); return fragment; }; - _proto._createChoicesFragment = function _createChoicesFragment(choices, fragment, withinGroup) { - var _this14 = this; + Choices.prototype._createChoicesFragment = function (choices, fragment, withinGroup) { + var _this = this; if (fragment === void 0) { fragment = document.createDocumentFragment(); @@ -4157,20 +2177,20 @@ function () { 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) - // Create a fragment to store our list items (so we don't have to update the DOM for each item) - var _this$config = this.config, - renderSelectedChoices = _this$config.renderSelectedChoices, - searchResultLimit = _this$config.searchResultLimit, - renderChoiceLimit = _this$config.renderChoiceLimit; - var filter = this._isSearching ? sortByScore : this.config.sorter; + + var _a = this.config, + renderSelectedChoices = _a.renderSelectedChoices, + searchResultLimit = _a.searchResultLimit, + renderChoiceLimit = _a.renderChoiceLimit; + var filter = this._isSearching ? utils_1.sortByScore : this.config.sorter; var appendChoice = function appendChoice(choice) { - var shouldRender = renderSelectedChoices === 'auto' ? _this14._isSelectOneElement || !choice.selected : true; + var shouldRender = renderSelectedChoices === 'auto' ? _this._isSelectOneElement || !choice.selected : true; if (shouldRender) { - var dropdownItem = _this14._getTemplate('choice', choice, _this14.config.itemSelectText); + var dropdownItem = _this._getTemplate('choice', choice, _this.config.itemSelectText); fragment.appendChild(dropdownItem); } @@ -4185,7 +2205,7 @@ function () { } // Split array into placeholders and "normal" choices - var _rendererableChoices$ = rendererableChoices.reduce(function (acc, choice) { + var _b = rendererableChoices.reduce(function (acc, choice) { if (choice.placeholder) { acc.placeholderChoices.push(choice); } else { @@ -4197,8 +2217,8 @@ function () { placeholderChoices: [], normalChoices: [] }), - placeholderChoices = _rendererableChoices$.placeholderChoices, - normalChoices = _rendererableChoices$.normalChoices; // If sorting is enabled or the user is searching, filter choices + placeholderChoices = _b.placeholderChoices, + normalChoices = _b.normalChoices; // If sorting is enabled or the user is searching, filter choices if (this.config.shouldSort || this._isSearching) { @@ -4207,7 +2227,7 @@ function () { var choiceLimit = rendererableChoices.length; // Prepend placeholeder - var sortedChoices = this._isSelectOneElement ? [].concat(placeholderChoices, normalChoices) : normalChoices; + var sortedChoices = this._isSelectOneElement ? __spreadArrays(placeholderChoices, normalChoices) : normalChoices; if (this._isSearching) { choiceLimit = searchResultLimit; @@ -4225,18 +2245,18 @@ function () { return fragment; }; - _proto._createItemsFragment = function _createItemsFragment(items, fragment) { - var _this15 = this; + Choices.prototype._createItemsFragment = function (items, fragment) { + var _this = this; if (fragment === void 0) { fragment = document.createDocumentFragment(); - } + } // Create fragment to add elements to - // Create fragment to add elements to - var _this$config2 = this.config, - shouldSortItems = _this$config2.shouldSortItems, - sorter = _this$config2.sorter, - removeItemButton = _this$config2.removeItemButton; // If sorting is enabled, filter items + + var _a = this.config, + shouldSortItems = _a.shouldSortItems, + sorter = _a.sorter, + removeItemButton = _a.removeItemButton; // If sorting is enabled, filter items if (shouldSortItems && !this._isSelectOneElement) { items.sort(sorter); @@ -4244,7 +2264,10 @@ function () { if (this._isTextElement) { // Update the value of the hidden input - this.passedElement.value = items; + this.passedElement.value = items.map(function (_a) { + var value = _a.value; + return value; + }).join(this.config.delimiter); } else { // Update the options of the hidden input this.passedElement.options = items; @@ -4252,7 +2275,7 @@ function () { var addItemToFragment = function addItemToFragment(item) { // Create new list element - var listItem = _this15._getTemplate('item', item, removeItemButton); // Append it to list + var listItem = _this._getTemplate('item', item, removeItemButton); // Append it to list fragment.appendChild(listItem); @@ -4263,53 +2286,54 @@ function () { return fragment; }; - _proto._triggerChange = function _triggerChange(value) { + Choices.prototype._triggerChange = function (value) { if (value === undefined || value === null) { return; } - this.passedElement.triggerEvent(EVENTS.change, { + this.passedElement.triggerEvent(constants_1.EVENTS.change, { value: value }); }; - _proto._selectPlaceholderChoice = function _selectPlaceholderChoice() { - var placeholderChoice = this._store.placeholderChoice; + Choices.prototype._selectPlaceholderChoice = function (placeholderChoice) { + this._addItem({ + value: placeholderChoice.value, + label: placeholderChoice.label, + choiceId: placeholderChoice.id, + groupId: placeholderChoice.groupId, + placeholder: placeholderChoice.placeholder + }); - if (placeholderChoice) { - this._addItem({ - value: placeholderChoice.value, - label: placeholderChoice.label, - choiceId: placeholderChoice.id, - groupId: placeholderChoice.groupId, - placeholder: placeholderChoice.placeholder - }); - - this._triggerChange(placeholderChoice.value); - } + this._triggerChange(placeholderChoice.value); }; - _proto._handleButtonAction = function _handleButtonAction(activeItems, element) { + Choices.prototype._handleButtonAction = function (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) { + var itemId = element.parentNode && element.parentNode.dataset.id; + var itemToRemove = itemId && activeItems.find(function (item) { return item.id === parseInt(itemId, 10); - }); // Remove item associated with button + }); + + if (!itemToRemove) { + return; + } // Remove item associated with button + this._removeItem(itemToRemove); this._triggerChange(itemToRemove.value); - if (this._isSelectOneElement) { - this._selectPlaceholderChoice(); + if (this._isSelectOneElement && this._store.placeholderChoice) { + this._selectPlaceholderChoice(this._store.placeholderChoice); } }; - _proto._handleItemAction = function _handleItemAction(activeItems, element, hasShiftKey) { - var _this16 = this; + Choices.prototype._handleItemAction = function (activeItems, element, hasShiftKey) { + var _this = this; if (hasShiftKey === void 0) { hasShiftKey = false; @@ -4319,15 +2343,15 @@ function () { return; } - var passedId = element.getAttribute('data-id'); // We only want to select one item with a click + var passedId = element.dataset.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) { - _this16.highlightItem(item); + if (item.id === parseInt("" + passedId, 10) && !item.highlighted) { + _this.highlightItem(item); } else if (!hasShiftKey && item.highlighted) { - _this16.unhighlightItem(item); + _this.unhighlightItem(item); } }); // Focus input as without focus, a user cannot do anything with a // highlighted item @@ -4335,7 +2359,7 @@ function () { this.input.focus(); }; - _proto._handleChoiceAction = function _handleChoiceAction(activeItems, element) { + Choices.prototype._handleChoiceAction = function (activeItems, element) { if (!activeItems || !element) { return; } // If we are clicking on an option @@ -4343,17 +2367,17 @@ function () { var id = element.dataset.id; - var choice = this._store.getChoiceById(id); + var choice = id && this._store.getChoiceById(id); if (!choice) { return; } - var passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : null; + var passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : undefined; var hasActiveDropdown = this.dropdown.isActive; // Update choice keyCode choice.keyCode = passedKeyCode; - this.passedElement.triggerEvent(EVENTS.choice, { + this.passedElement.triggerEvent(constants_1.EVENTS.choice, { choice: choice }); @@ -4383,7 +2407,7 @@ function () { } }; - _proto._handleBackspace = function _handleBackspace(activeItems) { + Choices.prototype._handleBackspace = function (activeItems) { if (!this.config.removeItems || !activeItems) { return; } @@ -4411,15 +2435,15 @@ function () { } }; - _proto._startLoading = function _startLoading() { - this._store.dispatch(setIsLoading(true)); + Choices.prototype._startLoading = function () { + this._store.dispatch(misc_1.setIsLoading(true)); }; - _proto._stopLoading = function _stopLoading() { - this._store.dispatch(setIsLoading(false)); + Choices.prototype._stopLoading = function () { + this._store.dispatch(misc_1.setIsLoading(false)); }; - _proto._handleLoadingState = function _handleLoadingState(setLoading) { + Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } @@ -4433,7 +2457,10 @@ function () { if (this._isSelectOneElement) { if (!placeholderItem) { placeholderItem = this._getTemplate('placeholder', this.config.loadingText); - this.itemList.append(placeholderItem); + + if (placeholderItem) { + this.itemList.append(placeholderItem); + } } else { placeholderItem.innerHTML = this.config.loadingText; } @@ -4445,22 +2472,24 @@ function () { this.containerOuter.removeLoadingState(); if (this._isSelectOneElement) { - placeholderItem.innerHTML = this._placeholderValue || ''; + if (placeholderItem) { + placeholderItem.innerHTML = this._placeholderValue || ''; + } } else { this.input.placeholder = this._placeholderValue || ''; } } }; - _proto._handleSearch = function _handleSearch(value) { + Choices.prototype._handleSearch = function (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 _a = this.config, + searchFloor = _a.searchFloor, + searchChoices = _a.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 @@ -4468,7 +2497,7 @@ function () { if (value && value.length >= searchFloor) { var resultCount = searchChoices ? this._searchChoices(value) : 0; // Trigger search event - this.passedElement.triggerEvent(EVENTS.search, { + this.passedElement.triggerEvent(constants_1.EVENTS.search, { value: value, resultCount: resultCount }); @@ -4476,16 +2505,16 @@ function () { // Otherwise reset choices to active this._isSearching = false; - this._store.dispatch(choices_activateChoices(true)); + this._store.dispatch(choices_1.activateChoices(true)); } }; - _proto._canAddItem = function _canAddItem(activeItems, value) { + Choices.prototype._canAddItem = function (activeItems, value) { var canAddItem = true; var notice = typeof this.config.addItemText === 'function' ? this.config.addItemText(value) : this.config.addItemText; if (!this._isSelectOneElement) { - var isDuplicateValue = existsInArray(activeItems, value); + var isDuplicateValue = utils_1.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 @@ -4511,7 +2540,7 @@ function () { }; }; - _proto._searchChoices = function _searchChoices(value) { + Choices.prototype._searchChoices = function (value) { var newValue = typeof value === 'string' ? value.trim() : value; var currentValue = typeof this._currentValue === 'string' ? this._currentValue.trim() : this._currentValue; @@ -4522,24 +2551,27 @@ function () { var haystack = this._store.searchableChoices; var needle = newValue; - var keys = [].concat(this.config.searchFields); + + var keys = __spreadArrays(this.config.searchFields); + var options = Object.assign(this.config.fuseOptions, { - keys: keys + keys: keys, + includeMatches: true }); - var fuse = new fuse_default.a(haystack, options); - var results = fuse.search(needle); + var fuse = new fuse_js_1.default(haystack, options); + var results = fuse.search(needle); // see https://github.com/krisk/Fuse/issues/303 + this._currentValue = newValue; this._highlightPosition = 0; this._isSearching = true; - this._store.dispatch(choices_filterChoices(results)); + this._store.dispatch(choices_1.filterChoices(results)); return results.length; }; - _proto._addEventListeners = function _addEventListeners() { - var _document = document, - documentElement = _document.documentElement; // capture events - can cancel event processing or propagation + Choices.prototype._addEventListeners = function () { + var documentElement = document.documentElement; // capture events - can cancel event processing or propagation documentElement.addEventListener('touchend', this._onTouchEnd, true); this.containerOuter.element.addEventListener('keydown', this._onKeyDown, true); @@ -4583,9 +2615,8 @@ function () { this.input.addEventListeners(); }; - _proto._removeEventListeners = function _removeEventListeners() { - var _document2 = document, - documentElement = _document2.documentElement; + Choices.prototype._removeEventListeners = function () { + var documentElement = document.documentElement; documentElement.removeEventListener('touchend', this._onTouchEnd, true); this.containerOuter.element.removeEventListener('keydown', this._onKeyDown, true); this.containerOuter.element.removeEventListener('mousedown', this._onMouseDown, true); @@ -4607,15 +2638,9 @@ function () { } this.input.removeEventListeners(); - } - /** - * @param {KeyboardEvent} event - */ - ; - - _proto._onKeyDown = function _onKeyDown(event) { - var _keyDownActions; + }; + Choices.prototype._onKeyDown = function (event) { var keyCode = event.keyCode; var activeItems = this._store.activeItems; var hasFocusedInput = this.input.isFocussed; @@ -4623,15 +2648,15 @@ function () { var hasItems = this.itemList.hasChildren(); var keyString = String.fromCharCode(keyCode); var wasAlphaNumericChar = /[a-zA-Z0-9-_ ]/.test(keyString); - 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 BACK_KEY = constants_1.KEY_CODES.BACK_KEY, + DELETE_KEY = constants_1.KEY_CODES.DELETE_KEY, + ENTER_KEY = constants_1.KEY_CODES.ENTER_KEY, + A_KEY = constants_1.KEY_CODES.A_KEY, + ESC_KEY = constants_1.KEY_CODES.ESC_KEY, + UP_KEY = constants_1.KEY_CODES.UP_KEY, + DOWN_KEY = constants_1.KEY_CODES.DOWN_KEY, + PAGE_UP_KEY = constants_1.KEY_CODES.PAGE_UP_KEY, + PAGE_DOWN_KEY = constants_1.KEY_CODES.PAGE_DOWN_KEY; if (!this._isTextElement && !hasActiveDropdown && wasAlphaNumericChar) { this.showDropdown(); @@ -4644,32 +2669,42 @@ function () { */ this.input.value += keyString.toLowerCase(); } - } // Map keys to key actions + } + switch (keyCode) { + case A_KEY: + return this._onSelectKey(event, hasItems); - 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); + case ENTER_KEY: + return this._onEnterKey(event, activeItems, hasActiveDropdown); - if (keyDownActions[keyCode]) { - keyDownActions[keyCode]({ - event: event, - activeItems: activeItems, - hasFocusedInput: hasFocusedInput, - hasActiveDropdown: hasActiveDropdown, - hasItems: hasItems - }); + case ESC_KEY: + return this._onEscapeKey(hasActiveDropdown); + + case UP_KEY: + case PAGE_UP_KEY: + case DOWN_KEY: + case PAGE_DOWN_KEY: + return this._onDirectionKey(event, hasActiveDropdown); + + case DELETE_KEY: + case BACK_KEY: + return this._onDeleteKey(event, activeItems, hasFocusedInput); + + default: } }; - _proto._onKeyUp = function _onKeyUp(_ref2) { - var target = _ref2.target, - keyCode = _ref2.keyCode; + Choices.prototype._onKeyUp = function (_a) { + var target = _a.target, + keyCode = _a.keyCode; 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 + var backKey = constants_1.KEY_CODES.BACK_KEY, + deleteKey = constants_1.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) { @@ -4685,14 +2720,14 @@ function () { } } else { var wasRemovalKeyCode = keyCode === backKey || keyCode === deleteKey; - var userHasRemovedValue = wasRemovalKeyCode && !target.value; + var userHasRemovedValue = wasRemovalKeyCode && target && !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)); + this._store.dispatch(choices_1.activateChoices(true)); } else if (canSearch) { this._handleSearch(this.input.value); } @@ -4701,9 +2736,7 @@ function () { this._canSearch = this.config.searchEnabled; }; - _proto._onAKey = function _onAKey(_ref3) { - var event = _ref3.event, - hasItems = _ref3.hasItems; + Choices.prototype._onSelectKey = function (event, hasItems) { var ctrlKey = event.ctrlKey, metaKey = event.metaKey; var hasCtrlDownKeyPressed = ctrlKey || metaKey; // If CTRL + A or CMD + A have been pressed and there are items to select @@ -4718,15 +2751,12 @@ function () { } }; - _proto._onEnterKey = function _onEnterKey(_ref4) { - var event = _ref4.event, - activeItems = _ref4.activeItems, - hasActiveDropdown = _ref4.hasActiveDropdown; + Choices.prototype._onEnterKey = function (event, activeItems, hasActiveDropdown) { var target = event.target; - var enterKey = KEY_CODES.ENTER_KEY; - var targetWasButton = target.hasAttribute('data-button'); + var enterKey = constants_1.KEY_CODES.ENTER_KEY; + var targetWasButton = target && target.hasAttribute('data-button'); - if (this._isTextElement && target.value) { + if (this._isTextElement && target && target.value) { var value = this.input.value; var canAddItem = this._canAddItem(activeItems, value); @@ -4769,23 +2799,19 @@ function () { } }; - _proto._onEscapeKey = function _onEscapeKey(_ref5) { - var hasActiveDropdown = _ref5.hasActiveDropdown; - + Choices.prototype._onEscapeKey = function (hasActiveDropdown) { if (hasActiveDropdown) { this.hideDropdown(true); this.containerOuter.focus(); } }; - _proto._onDirectionKey = function _onDirectionKey(_ref6) { - var event = _ref6.event, - hasActiveDropdown = _ref6.hasActiveDropdown; + Choices.prototype._onDirectionKey = function (event, hasActiveDropdown) { var keyCode = event.keyCode, metaKey = event.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 + var downKey = constants_1.KEY_CODES.DOWN_KEY, + pageUpKey = constants_1.KEY_CODES.PAGE_UP_KEY, + pageDownKey = constants_1.KEY_CODES.PAGE_DOWN_KEY; // If up or down key is pressed, traverse through options if (hasActiveDropdown || this._isSelectOneElement) { this.showDropdown(); @@ -4793,7 +2819,7 @@ function () { var directionInt = keyCode === downKey || keyCode === pageDownKey ? 1 : -1; var skipKey = metaKey || keyCode === pageDownKey || keyCode === pageUpKey; var selectableChoiceIdentifier = '[data-choice-selectable]'; - var nextEl; + var nextEl = void 0; if (skipKey) { if (directionInt > 0) { @@ -4805,7 +2831,7 @@ function () { var currentEl = this.dropdown.element.querySelector("." + this.config.classNames.highlightedState); if (currentEl) { - nextEl = getAdjacentEl(currentEl, selectableChoiceIdentifier, directionInt); + nextEl = utils_1.getAdjacentEl(currentEl, selectableChoiceIdentifier, directionInt); } else { nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); } @@ -4814,7 +2840,7 @@ function () { if (nextEl) { // We prevent default to stop the cursor moving // when pressing the arrow - if (!isScrolledIntoView(nextEl, this.choiceList.element, directionInt)) { + if (!utils_1.isScrolledIntoView(nextEl, this.choiceList.element, directionInt)) { this.choiceList.scrollToChildElement(nextEl, directionInt); } @@ -4827,29 +2853,24 @@ function () { } }; - _proto._onDeleteKey = function _onDeleteKey(_ref7) { - var event = _ref7.event, - hasFocusedInput = _ref7.hasFocusedInput, - activeItems = _ref7.activeItems; + Choices.prototype._onDeleteKey = function (event, activeItems, hasFocusedInput) { var target = event.target; // If backspace or delete key is pressed and the input has no value - if (hasFocusedInput && !target.value && !this._isSelectOneElement) { + if (!this._isSelectOneElement && !target.value && hasFocusedInput) { this._handleBackspace(activeItems); event.preventDefault(); } }; - _proto._onTouchMove = function _onTouchMove() { + Choices.prototype._onTouchMove = function () { if (this._wasTap) { this._wasTap = false; } }; - _proto._onTouchEnd = function _onTouchEnd(event) { - var _ref8 = event || event.touches[0], - target = _ref8.target; - + Choices.prototype._onTouchEnd = function (event) { + var target = (event || event.touches[0]).target; var touchWasWithinContainer = this._wasTap && this.containerOuter.element.contains(target); if (touchWasWithinContainer) { @@ -4868,14 +2889,13 @@ function () { } this._wasTap = true; - } + }; /** * Handles mousedown event in capture mode for containetOuter.element - * @param {MouseEvent} event */ - ; - _proto._onMouseDown = function _onMouseDown(event) { + + Choices.prototype._onMouseDown = function (event) { var target = event.target; if (!(target instanceof HTMLElement)) { @@ -4885,9 +2905,7 @@ function () { if (IS_IE11 && this.choiceList.element.contains(target)) { // check if click was on a scrollbar area - var firstChoice = - /** @type {HTMLElement} */ - this.choiceList.element.firstElementChild; + var firstChoice = this.choiceList.element.firstElementChild; var isOnScrollbar = this._direction === 'ltr' ? event.offsetX >= firstChoice.offsetWidth : event.offsetX < firstChoice.offsetLeft; this._isScrollingOnIe = isOnScrollbar; } @@ -4913,23 +2931,23 @@ function () { } event.preventDefault(); - } + }; /** * Handles mouseover event over this.dropdown * @param {MouseEvent} event */ - ; - _proto._onMouseOver = function _onMouseOver(_ref9) { - var target = _ref9.target; + + Choices.prototype._onMouseOver = function (_a) { + var target = _a.target; if (target instanceof HTMLElement && 'choice' in target.dataset) { this._highlightChoice(target); } }; - _proto._onClick = function _onClick(_ref10) { - var target = _ref10.target; + Choices.prototype._onClick = function (_a) { + var target = _a.target; var clickWasWithinContainer = this.containerOuter.element.contains(target); if (clickWasWithinContainer) { @@ -4957,79 +2975,80 @@ function () { } }; - _proto._onFocus = function _onFocus(_ref11) { - var _this17 = this, - _focusActions; + Choices.prototype._onFocus = function (_a) { + var _b; - var target = _ref11.target; - var focusWasWithinContainer = this.containerOuter.element.contains(target); + var _this = this; + + var target = _a.target; + var focusWasWithinContainer = target && this.containerOuter.element.contains(target); if (!focusWasWithinContainer) { return; } - var focusActions = (_focusActions = {}, _focusActions[TEXT_TYPE] = function () { - if (target === _this17.input.element) { - _this17.containerOuter.addFocusState(); + var focusActions = (_b = {}, _b[constants_1.TEXT_TYPE] = function () { + if (target === _this.input.element) { + _this.containerOuter.addFocusState(); } - }, _focusActions[SELECT_ONE_TYPE] = function () { - _this17.containerOuter.addFocusState(); + }, _b[constants_1.SELECT_ONE_TYPE] = function () { + _this.containerOuter.addFocusState(); - if (target === _this17.input.element) { - _this17.showDropdown(true); + if (target === _this.input.element) { + _this.showDropdown(true); } - }, _focusActions[SELECT_MULTIPLE_TYPE] = function () { - if (target === _this17.input.element) { - _this17.showDropdown(true); // If element is a select box, the focused element is the container and the dropdown + }, _b[constants_1.SELECT_MULTIPLE_TYPE] = function () { + if (target === _this.input.element) { + _this.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 - _this17.containerOuter.addFocusState(); + _this.containerOuter.addFocusState(); } - }, _focusActions); + }, _b); focusActions[this.passedElement.element.type](); }; - _proto._onBlur = function _onBlur(_ref12) { - var _this18 = this; + Choices.prototype._onBlur = function (_a) { + var _b; - var target = _ref12.target; - var blurWasWithinContainer = this.containerOuter.element.contains(target); + var _this = this; + + var target = _a.target; + var blurWasWithinContainer = target && this.containerOuter.element.contains(target); if (blurWasWithinContainer && !this._isScrollingOnIe) { - var _blurActions; - var activeItems = this._store.activeItems; - var hasHighlightedItems = activeItems.some(function (item) { + var hasHighlightedItems_1 = activeItems.some(function (item) { return item.highlighted; }); - var blurActions = (_blurActions = {}, _blurActions[TEXT_TYPE] = function () { - if (target === _this18.input.element) { - _this18.containerOuter.removeFocusState(); + var blurActions = (_b = {}, _b[constants_1.TEXT_TYPE] = function () { + if (target === _this.input.element) { + _this.containerOuter.removeFocusState(); - if (hasHighlightedItems) { - _this18.unhighlightAll(); + if (hasHighlightedItems_1) { + _this.unhighlightAll(); } - _this18.hideDropdown(true); + _this.hideDropdown(true); } - }, _blurActions[SELECT_ONE_TYPE] = function () { - _this18.containerOuter.removeFocusState(); + }, _b[constants_1.SELECT_ONE_TYPE] = function () { + _this.containerOuter.removeFocusState(); - if (target === _this18.input.element || target === _this18.containerOuter.element && !_this18._canSearch) { - _this18.hideDropdown(true); + if (target === _this.input.element || target === _this.containerOuter.element && !_this._canSearch) { + _this.hideDropdown(true); } - }, _blurActions[SELECT_MULTIPLE_TYPE] = function () { - if (target === _this18.input.element) { - _this18.containerOuter.removeFocusState(); + }, _b[constants_1.SELECT_MULTIPLE_TYPE] = function () { + if (target === _this.input.element) { + _this.containerOuter.removeFocusState(); - _this18.hideDropdown(true); + _this.hideDropdown(true); - if (hasHighlightedItems) { - _this18.unhighlightAll(); + if (hasHighlightedItems_1) { + _this.unhighlightAll(); } } - }, _blurActions); + }, _b); blurActions[this.passedElement.element.type](); } else { // On IE11, clicking the scollbar blurs our input and thus @@ -5040,12 +3059,12 @@ function () { } }; - _proto._onFormReset = function _onFormReset() { - this._store.dispatch(resetTo(this._initialState)); + Choices.prototype._onFormReset = function () { + this._store.dispatch(misc_1.resetTo(this._initialState)); }; - _proto._highlightChoice = function _highlightChoice(el) { - var _this19 = this; + Choices.prototype._highlightChoice = function (el) { + var _this = this; if (el === void 0) { el = null; @@ -5061,7 +3080,7 @@ function () { var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll("." + this.config.classNames.highlightedState)); // Remove any highlighted choices highlightedChoices.forEach(function (choice) { - choice.classList.remove(_this19.config.classNames.highlightedState); + choice.classList.remove(_this.config.classNames.highlightedState); choice.setAttribute('aria-selected', 'false'); }); @@ -5084,7 +3103,7 @@ function () { passedEl.classList.add(this.config.classNames.highlightedState); passedEl.setAttribute('aria-selected', 'true'); - this.passedElement.triggerEvent(EVENTS.highlightChoice, { + this.passedElement.triggerEvent(constants_1.EVENTS.highlightChoice, { el: passedEl }); @@ -5096,23 +3115,21 @@ function () { } }; - _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; + Choices.prototype._addItem = function (_a) { + var value = _a.value, + _b = _a.label, + label = _b === void 0 ? null : _b, + _c = _a.choiceId, + choiceId = _c === void 0 ? -1 : _c, + _d = _a.groupId, + groupId = _d === void 0 ? -1 : _d, + _e = _a.customProperties, + customProperties = _e === void 0 ? {} : _e, + _f = _a.placeholder, + placeholder = _f === void 0 ? false : _f, + _g = _a.keyCode, + keyCode = _g === void 0 ? -1 : _g; var passedValue = typeof value === 'string' ? value.trim() : value; - var passedKeyCode = keyCode; - var passedCustomProperties = customProperties; var items = this._store.items; var passedLabel = label || passedValue; var passedOptionId = choiceId || -1; @@ -5128,7 +3145,7 @@ function () { passedValue += this.config.appendValue.toString(); } - this._store.dispatch(items_addItem({ + this._store.dispatch(items_1.addItem({ value: passedValue, label: passedLabel, id: id, @@ -5136,7 +3153,7 @@ function () { groupId: groupId, customProperties: customProperties, placeholder: placeholder, - keyCode: passedKeyCode + keyCode: keyCode })); if (this._isSelectOneElement) { @@ -5144,65 +3161,56 @@ function () { } // Trigger change event - this.passedElement.triggerEvent(EVENTS.addItem, { + this.passedElement.triggerEvent(constants_1.EVENTS.addItem, { id: id, value: passedValue, label: passedLabel, - customProperties: passedCustomProperties, - groupValue: group && group.value ? group.value : undefined, - keyCode: passedKeyCode + customProperties: customProperties, + groupValue: group && group.value ? group.value : null, + keyCode: keyCode }); - return this; }; - _proto._removeItem = function _removeItem(item) { - if (!item || !isType('Object', item)) { - return this; - } - + Choices.prototype._removeItem = function (item) { var id = item.id, value = item.value, label = item.label, + customProperties = item.customProperties, choiceId = item.choiceId, groupId = item.groupId; - var group = groupId >= 0 ? this._store.getGroupById(groupId) : null; + var group = groupId && 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 - }); + if (!id || !choiceId) { + return; } - return this; + this._store.dispatch(items_1.removeItem(id, choiceId)); + + this.passedElement.triggerEvent(constants_1.EVENTS.removeItem, { + id: id, + value: value, + label: label, + customProperties: customProperties, + groupValue: group && group.value ? group.value : null + }); }; - _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; + Choices.prototype._addChoice = function (_a) { + var value = _a.value, + _b = _a.label, + label = _b === void 0 ? null : _b, + _c = _a.isSelected, + isSelected = _c === void 0 ? false : _c, + _d = _a.isDisabled, + isDisabled = _d === void 0 ? false : _d, + _e = _a.groupId, + groupId = _e === void 0 ? -1 : _e, + _f = _a.customProperties, + customProperties = _f === void 0 ? {} : _f, + _g = _a.placeholder, + placeholder = _g === void 0 ? false : _g, + _h = _a.keyCode, + keyCode = _h === void 0 ? -1 : _h; if (typeof value === 'undefined' || value === null) { return; @@ -5214,7 +3222,7 @@ function () { var choiceId = choices ? choices.length + 1 : 1; var choiceElementId = this._baseId + "-" + this._idNames.itemChoice + "-" + choiceId; - this._store.dispatch(choices_addChoice({ + this._store.dispatch(choices_1.addChoice({ id: choiceId, groupId: groupId, elementId: choiceElementId, @@ -5238,21 +3246,21 @@ function () { } }; - _proto._addGroup = function _addGroup(_ref15) { - var _this20 = this; + Choices.prototype._addGroup = function (_a) { + var _this = 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 group = _a.group, + id = _a.id, + _b = _a.valueKey, + valueKey = _b === void 0 ? 'value' : _b, + _c = _a.labelKey, + labelKey = _c === void 0 ? 'label' : _c; + var groupChoices = utils_1.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({ + this._store.dispatch(groups_1.addGroup({ value: group.label, id: groupId, active: true, @@ -5262,9 +3270,9 @@ function () { var addGroupChoices = function addGroupChoices(choice) { var isOptDisabled = choice.disabled || choice.parentNode && choice.parentNode.disabled; - _this20._addChoice({ + _this._addChoice({ value: choice[valueKey], - label: isType('Object', choice) ? choice[labelKey] : choice.innerHTML, + label: utils_1.isType('Object', choice) ? choice[labelKey] : choice.innerHTML, isSelected: choice.selected, isDisabled: isOptDisabled, groupId: groupId, @@ -5275,7 +3283,7 @@ function () { groupChoices.forEach(addGroupChoices); } else { - this._store.dispatch(groups_addGroup({ + this._store.dispatch(groups_1.addGroup({ value: group.label, id: group.id, active: false, @@ -5284,66 +3292,63 @@ function () { } }; - _proto._getTemplate = function _getTemplate(template) { - var _this$_templates$temp; + Choices.prototype._getTemplate = function (template) { + var _a; - if (!template) { - return null; + var args = []; + + for (var _i = 1; _i < arguments.length; _i++) { + args[_i - 1] = arguments[_i]; } var classNames = this.config.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 (_this$_templates$temp = this._templates[template]).call.apply(_this$_templates$temp, [this, classNames].concat(args)); + return (_a = this._templates[template]).call.apply(_a, __spreadArrays([this, classNames], args)); }; - _proto._createTemplates = function _createTemplates() { + Choices.prototype._createTemplates = function () { var callbackOnCreateTemplates = this.config.callbackOnCreateTemplates; var userTemplates = {}; if (callbackOnCreateTemplates && typeof callbackOnCreateTemplates === 'function') { - userTemplates = callbackOnCreateTemplates.call(this, strToEl); + userTemplates = callbackOnCreateTemplates.call(this, utils_1.strToEl); } - this._templates = cjs_default()(TEMPLATES, userTemplates); + this._templates = deepmerge_1.default(templates_1.default, userTemplates); }; - _proto._createElements = function _createElements() { - this.containerOuter = new container_Container({ + Choices.prototype._createElements = function () { + this.containerOuter = new components_1.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({ + this.containerInner = new components_1.Container({ element: this._getTemplate('containerInner'), classNames: this.config.classNames, type: this.passedElement.element.type, position: this.config.position }); - this.input = new input_Input({ + this.input = new components_1.Input({ element: this._getTemplate('input', this._placeholderValue), classNames: this.config.classNames, type: this.passedElement.element.type, preventPaste: !this.config.paste }); - this.choiceList = new list_List({ + this.choiceList = new components_1.List({ element: this._getTemplate('choiceList', this._isSelectOneElement) }); - this.itemList = new list_List({ + this.itemList = new components_1.List({ element: this._getTemplate('itemList', this._isSelectOneElement) }); - this.dropdown = new Dropdown({ + this.dropdown = new components_1.Dropdown({ element: this._getTemplate('dropdown'), classNames: this.config.classNames, type: this.passedElement.element.type }); }; - _proto._createStructure = function _createStructure() { + Choices.prototype._createStructure = function () { // Hide original element this.passedElement.conceal(); // Wrap input in container preserving DOM ordering @@ -5392,13 +3397,13 @@ function () { } }; - _proto._addPredefinedGroups = function _addPredefinedGroups(groups) { - var _this21 = this; + Choices.prototype._addPredefinedGroups = function (groups) { + var _this = this; // If we have a placeholder option + - // If we have a placeholder option var placeholderChoice = this.passedElement.placeholderOption; - if (placeholderChoice && placeholderChoice.parentNode.tagName === 'SELECT') { + if (placeholderChoice && placeholderChoice.parentNode && placeholderChoice.parentNode.tagName === 'SELECT') { this._addChoice({ value: placeholderChoice.value, label: placeholderChoice.innerHTML, @@ -5409,17 +3414,17 @@ function () { } groups.forEach(function (group) { - return _this21._addGroup({ + return _this._addGroup({ group: group, id: group.id || null }); }); }; - _proto._addPredefinedChoices = function _addPredefinedChoices(choices) { - var _this22 = this; + Choices.prototype._addPredefinedChoices = function (choices) { + var _this = this; // If sorting is enabled or the user is searching, filter choices + - // If sorting is enabled or the user is searching, filter choices if (this.config.shouldSort) { choices.sort(this.config.sorter); } @@ -5431,15 +3436,16 @@ function () { return choice.disabled === undefined || !choice.disabled; }); choices.forEach(function (choice, index) { - var value = choice.value, + var _a = choice.value, + value = _a === void 0 ? '' : _a, label = choice.label, customProperties = choice.customProperties, placeholder = choice.placeholder; - if (_this22._isSelectElement) { + if (_this._isSelectElement) { // If the choice is actually a group if (choice.choices) { - _this22._addGroup({ + _this._addGroup({ group: choice, id: choice.id || null }); @@ -5450,42 +3456,39 @@ function () { * * Otherwise we pre-select the first enabled choice in the array ("select-one" only) */ - var shouldPreselect = _this22._isSelectOneElement && !hasSelectedChoice && index === firstEnabledChoiceIndex; + var shouldPreselect = _this._isSelectOneElement && !hasSelectedChoice && index === firstEnabledChoiceIndex; var isSelected = shouldPreselect ? true : choice.selected; var isDisabled = choice.disabled; + console.log(isDisabled, choice); - _this22._addChoice({ + _this._addChoice({ value: value, label: label, - isSelected: isSelected, - isDisabled: isDisabled, - customProperties: customProperties, - placeholder: placeholder + isSelected: !!isSelected, + isDisabled: !!isDisabled, + placeholder: !!placeholder, + customProperties: customProperties }); } } else { - _this22._addChoice({ + _this._addChoice({ value: value, label: label, - isSelected: choice.selected, - isDisabled: choice.disabled, - customProperties: customProperties, - placeholder: placeholder + isSelected: !!choice.selected, + isDisabled: !!choice.disabled, + placeholder: !!choice.placeholder, + customProperties: customProperties }); } }); - } - /** - * @param {Item[]} items - */ - ; + }; - _proto._addPredefinedItems = function _addPredefinedItems(items) { - var _this23 = this; + Choices.prototype._addPredefinedItems = function (items) { + var _this = this; items.forEach(function (item) { if (typeof item === 'object' && item.value) { - _this23._addItem({ + _this._addItem({ value: item.value, label: item.label, choiceId: item.id, @@ -5495,17 +3498,17 @@ function () { } if (typeof item === 'string') { - _this23._addItem({ + _this._addItem({ value: item }); } }); }; - _proto._setChoiceOrItem = function _setChoiceOrItem(item) { - var _this24 = this; + Choices.prototype._setChoiceOrItem = function (item) { + var _this = this; - var itemType = getType(item).toLowerCase(); + var itemType = utils_1.getType(item).toLowerCase(); var handleType = { object: function object() { if (!item.value) { @@ -5514,8 +3517,8 @@ function () { // that is then selected. For text inputs we can just add items normally. - if (!_this24._isTextElement) { - _this24._addChoice({ + if (!_this._isTextElement) { + _this._addChoice({ value: item.value, label: item.label, isSelected: true, @@ -5524,7 +3527,7 @@ function () { placeholder: item.placeholder }); } else { - _this24._addItem({ + _this._addItem({ value: item.value, label: item.label, choiceId: item.id, @@ -5534,15 +3537,15 @@ function () { } }, string: function string() { - if (!_this24._isTextElement) { - _this24._addChoice({ + if (!_this._isTextElement) { + _this._addChoice({ value: item, label: item, isSelected: true, isDisabled: false }); } else { - _this24._addItem({ + _this._addItem({ value: item }); } @@ -5551,13 +3554,13 @@ function () { handleType[itemType](); }; - _proto._findAndSelectChoiceByValue = function _findAndSelectChoiceByValue(val) { - var _this25 = this; + Choices.prototype._findAndSelectChoiceByValue = function (value) { + var _this = this; var choices = this._store.choices; // Check 'value' property exists and the choice isn't already selected var foundChoice = choices.find(function (choice) { - return _this25.config.valueComparer(choice.value, val); + return _this.config.valueComparer(choice.value, value); }); if (foundChoice && !foundChoice.selected) { @@ -5573,15 +3576,15 @@ function () { } }; - _proto._generatePlaceholderValue = function _generatePlaceholderValue() { + Choices.prototype._generatePlaceholderValue = function () { if (this._isSelectElement) { var placeholderOption = this.passedElement.placeholderOption; - return placeholderOption ? placeholderOption.text : false; + return placeholderOption ? placeholderOption.text : null; } - var _this$config4 = this.config, - placeholder = _this$config4.placeholder, - placeholderValue = _this$config4.placeholderValue; + var _a = this.config, + placeholder = _a.placeholder, + placeholderValue = _a.placeholderValue; var dataset = this.passedElement.element.dataset; if (placeholder) { @@ -5594,13 +3597,1962 @@ function () { } } - return false; + return null; }; return Choices; }(); -/* harmony default export */ var scripts_choices = __webpack_exports__["default"] = (choices_Choices); +exports.default = Choices; + +/***/ }), +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +/*! + * Fuse.js v3.4.6 - 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(e,t){ true?module.exports=t():undefined}(this,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){e.exports=function(e){return Array.isArray?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,n){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(e,'"'));var n=this._prepareSearchers(e),r=n.tokenSearchers,o=n.fullSearcher,i=this._search(r,o),a=i.weights,s=i.results;return this._computeScore(a,s),this.options.shouldSort&&this._sort(s),t.limit&&"number"==typeof t.limit&&(s=s.slice(0,t.limit)),this._format(s)}},{key:"_prepareSearchers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=[];if(this.options.tokenize)for(var n=e.split(this.options.tokenSeparator),r=0,o=n.length;r0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,n=this.list,r={},o=[];if("string"==typeof n[0]){for(var i=0,a=n.length;i1)throw new Error("Key weight has to be > 0 and <= 1");d=d.name}else s[d]={weight:1};this._analyze({key:d,value:this.options.getFn(l,d),record:l,index:c},{resultMap:r,results:o,tokenSearchers:e,fullSearcher:t})}return{weights:s,results:o}}},{key:"_analyze",value:function(e,t){var n=e.key,r=e.arrayIndex,o=void 0===r?-1:r,i=e.value,a=e.record,c=e.index,h=t.tokenSearchers,l=void 0===h?[]:h,u=t.fullSearcher,f=void 0===u?[]:u,d=t.resultMap,v=void 0===d?{}:d,p=t.results,g=void 0===p?[]:p;if(null!=i){var y=!1,m=-1,k=0;if("string"==typeof i){this._log("\nKey: ".concat(""===n?"-":n));var S=f.search(i);if(this._log('Full text: "'.concat(i,'", score: ').concat(S.score)),this.options.tokenize){for(var x=i.split(this.options.tokenSeparator),b=[],M=0;M-1&&(P=(P+m)/2),this._log("Score average:",P);var F=!this.options.tokenize||!this.options.matchAllTokens||k>=l.length;if(this._log("\nCheck Matches: ".concat(F)),(y||S.isMatch)&&F){var T=v[c];T?T.output.push({key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}):(v[c]={item:a,output:[{key:n,arrayIndex:o,value:i,score:P,matchedIndices:S.matchedIndices}]},g.push(v[c]))}}else if(s(i))for(var z=0,E=i.length;z-1&&(a.arrayIndex=i.arrayIndex),t.matches.push(a)}}}),this.options.includeScore&&o.push(function(e,t){t.score=e.score});for(var i=0,a=e.length;in)return o(e,this.pattern,r);var a=this.options,s=a.location,c=a.distance,h=a.threshold,l=a.findAllMatches,u=a.minMatchCharLength;return i(e,this.pattern,this.patternAlphabet,{location:s,distance:c,threshold:h,findAllMatches:l,minMatchCharLength:u})}}])&&r(t.prototype,n),s&&r(t,s),e}();e.exports=s},function(e,t){var n=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;e.exports=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,o=new RegExp(t.replace(n,"\\$&").replace(r,"|")),i=e.match(o),a=!!i,s=[];if(a)for(var c=0,h=i.length;c=P;z-=1){var E=z-1,K=n[e.charAt(E)];if(K&&(x[E]=1),T[z]=(T[z+1]<<1|1)&K,0!==I&&(T[z]|=(L[z+1]|L[z])<<1|1|L[z+1]),T[z]&C&&(w=r(t,{errors:I,currentLocation:E,expectedLocation:g,distance:h}))<=m){if(m=w,(k=E)<=g)break;P=Math.max(1,2*g-k)}}if(r(t,{errors:I+1,currentLocation:g,expectedLocation:g,distance:h})>m)break;L=T}return{isMatch:k>=0,score:0===w?.001:w,matchedIndices:o(x,p)}}},function(e,t){e.exports=function(e,t){var n=t.errors,r=void 0===n?0:n,o=t.currentLocation,i=void 0===o?0:o,a=t.expectedLocation,s=void 0===a?0:a,c=t.distance,h=void 0===c?100:c,l=r/e.length,u=Math.abs(s-i);return h?l+u/h:u?1:l}},function(e,t){e.exports=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=[],r=-1,o=-1,i=0,a=e.length;i=t&&n.push([r,o]),r=-1)}return e[i-1]&&i-r>=t&&n.push([r,i-1]),n}},function(e,t){e.exports=function(e){for(var t={},n=e.length,r=0;r -1) { + return state.map(function (obj) { + var choice = obj; + + if (choice.id === parseInt("" + addItemAction_1.choiceId, 10)) { + choice.selected = true; + } + + return choice; + }); + } + + return state; + } + + case 'REMOVE_ITEM': + { + var removeItemAction_1 = action; // When an item is removed and it has an associated choice, + // we want to re-enable it so it can be chosen again + + if (removeItemAction_1.choiceId && removeItemAction_1.choiceId > -1) { + return state.map(function (obj) { + var choice = obj; + + if (choice.id === parseInt("" + removeItemAction_1.choiceId, 10)) { + choice.selected = false; + } + + return choice; + }); + } + + return state; + } + + case 'FILTER_CHOICES': + { + var filterChoicesAction_1 = action; + return state.map(function (obj) { + var choice = obj; // Set active state based on whether choice is + // within filtered results + + choice.active = filterChoicesAction_1.results.some(function (_a) { + var item = _a.item, + score = _a.score; + + if (item.id === choice.id) { + choice.score = score; + return true; + } + + return false; + }); + return choice; + }); + } + + case 'ACTIVATE_CHOICES': + { + var activateChoicesAction_1 = action; + return state.map(function (obj) { + var choice = obj; + choice.active = activateChoicesAction_1.active; + return choice; + }); + } + + case 'CLEAR_CHOICES': + { + return exports.defaultState; + } + + default: + { + return state; + } + } +} + +exports.default = choices; + +/***/ }), +/* 17 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.defaultState = false; + +var general = function general(state, action) { + if (state === void 0) { + state = exports.defaultState; + } + + switch (action.type) { + case 'SET_IS_LOADING': + { + return action.isLoading; + } + + default: + { + return state; + } + } +}; + +exports.default = general; + +/***/ }), +/* 18 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var __importDefault = this && this.__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod + }; +}; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var dropdown_1 = __importDefault(__webpack_require__(19)); + +exports.Dropdown = dropdown_1.default; + +var container_1 = __importDefault(__webpack_require__(20)); + +exports.Container = container_1.default; + +var input_1 = __importDefault(__webpack_require__(21)); + +exports.Input = input_1.default; + +var list_1 = __importDefault(__webpack_require__(22)); + +exports.List = list_1.default; + +var wrapped_input_1 = __importDefault(__webpack_require__(23)); + +exports.WrappedInput = wrapped_input_1.default; + +var wrapped_select_1 = __importDefault(__webpack_require__(24)); + +exports.WrappedSelect = wrapped_select_1.default; + +/***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var Dropdown = +/** @class */ +function () { + function Dropdown(_a) { + var element = _a.element, + type = _a.type, + classNames = _a.classNames; + this.element = element; + this.classNames = classNames; + this.type = type; + this.isActive = false; + } + + Object.defineProperty(Dropdown.prototype, "distanceFromTopWindow", { + /** + * Bottom position of dropdown in viewport coordinates + */ + get: function get() { + return this.element.getBoundingClientRect().bottom; + }, + enumerable: true, + configurable: true + }); + + Dropdown.prototype.getChild = function (selector) { + return this.element.querySelector(selector); + }; + /** + * Show dropdown to user by adding active state class + */ + + + Dropdown.prototype.show = function () { + this.element.classList.add(this.classNames.activeState); + this.element.setAttribute('aria-expanded', 'true'); + this.isActive = true; + return this; + }; + /** + * Hide dropdown from user + */ + + + Dropdown.prototype.hide = function () { + this.element.classList.remove(this.classNames.activeState); + this.element.setAttribute('aria-expanded', 'false'); + this.isActive = false; + return this; + }; + + return Dropdown; +}(); + +exports.default = Dropdown; + +/***/ }), +/* 20 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var utils_1 = __webpack_require__(1); + +var constants_1 = __webpack_require__(0); + +var Container = +/** @class */ +function () { + function Container(_a) { + var element = _a.element, + type = _a.type, + classNames = _a.classNames, + position = _a.position; + this.element = element; + this.classNames = classNames; + this.type = type; + this.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); + } + + Container.prototype.addEventListeners = function () { + this.element.addEventListener('focus', this._onFocus); + this.element.addEventListener('blur', this._onBlur); + }; + + Container.prototype.removeEventListeners = function () { + this.element.removeEventListener('focus', this._onFocus); + this.element.removeEventListener('blur', this._onBlur); + }; + /** + * Determine whether container should be flipped based on passed + * dropdown position + */ + + + Container.prototype.shouldFlip = function (dropdownPos) { + if (typeof dropdownPos !== 'number') { + 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 = !window.matchMedia("(min-height: " + (dropdownPos + 1) + "px)").matches; + } else if (this.position === 'top') { + shouldFlip = true; + } + + return shouldFlip; + }; + + Container.prototype.setActiveDescendant = function (activeDescendantID) { + this.element.setAttribute('aria-activedescendant', activeDescendantID); + }; + + Container.prototype.removeActiveDescendant = function () { + this.element.removeAttribute('aria-activedescendant'); + }; + + Container.prototype.open = function (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; + } + }; + + Container.prototype.close = function () { + 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; + } + }; + + Container.prototype.focus = function () { + if (!this.isFocussed) { + this.element.focus(); + } + }; + + Container.prototype.addFocusState = function () { + this.element.classList.add(this.classNames.focusState); + }; + + Container.prototype.removeFocusState = function () { + this.element.classList.remove(this.classNames.focusState); + }; + + Container.prototype.enable = function () { + this.element.classList.remove(this.classNames.disabledState); + this.element.removeAttribute('aria-disabled'); + + if (this.type === constants_1.SELECT_ONE_TYPE) { + this.element.setAttribute('tabindex', '0'); + } + + this.isDisabled = false; + }; + + Container.prototype.disable = function () { + this.element.classList.add(this.classNames.disabledState); + this.element.setAttribute('aria-disabled', 'true'); + + if (this.type === constants_1.SELECT_ONE_TYPE) { + this.element.setAttribute('tabindex', '-1'); + } + + this.isDisabled = true; + }; + + Container.prototype.wrap = function (element) { + utils_1.wrap(element, this.element); + }; + + Container.prototype.unwrap = function (element) { + if (this.element.parentNode) { + // Move passed element outside this element + this.element.parentNode.insertBefore(element, this.element); // Remove this element + + this.element.parentNode.removeChild(this.element); + } + }; + + Container.prototype.addLoadingState = function () { + this.element.classList.add(this.classNames.loadingState); + this.element.setAttribute('aria-busy', 'true'); + this.isLoading = true; + }; + + Container.prototype.removeLoadingState = function () { + this.element.classList.remove(this.classNames.loadingState); + this.element.removeAttribute('aria-busy'); + this.isLoading = false; + }; + + Container.prototype._onFocus = function () { + this.isFocussed = true; + }; + + Container.prototype._onBlur = function () { + this.isFocussed = false; + }; + + return Container; +}(); + +exports.default = Container; + +/***/ }), +/* 21 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var utils_1 = __webpack_require__(1); + +var constants_1 = __webpack_require__(0); + +var Input = +/** @class */ +function () { + function Input(_a) { + var element = _a.element, + type = _a.type, + classNames = _a.classNames, + preventPaste = _a.preventPaste; + this.element = element; + this.type = type; + this.classNames = classNames; + this.preventPaste = preventPaste; + this.isFocussed = this.element.isEqualNode(document.activeElement); + this.isDisabled = element.disabled; + this._onPaste = this._onPaste.bind(this); + this._onInput = this._onInput.bind(this); + this._onFocus = this._onFocus.bind(this); + this._onBlur = this._onBlur.bind(this); + } + + Object.defineProperty(Input.prototype, "placeholder", { + set: function set(placeholder) { + this.element.placeholder = placeholder; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input.prototype, "value", { + get: function get() { + return utils_1.sanitise(this.element.value); + }, + set: function set(value) { + this.element.value = value; + }, + enumerable: true, + configurable: true + }); + + Input.prototype.addEventListeners = function () { + this.element.addEventListener('paste', this._onPaste); + this.element.addEventListener('input', this._onInput, { + passive: true + }); + this.element.addEventListener('focus', this._onFocus, { + passive: true + }); + this.element.addEventListener('blur', this._onBlur, { + passive: true + }); + }; + + Input.prototype.removeEventListeners = function () { + this.element.removeEventListener('input', this._onInput); + this.element.removeEventListener('paste', this._onPaste); + this.element.removeEventListener('focus', this._onFocus); + this.element.removeEventListener('blur', this._onBlur); + }; + + Input.prototype.enable = function () { + this.element.removeAttribute('disabled'); + this.isDisabled = false; + }; + + Input.prototype.disable = function () { + this.element.setAttribute('disabled', ''); + this.isDisabled = true; + }; + + Input.prototype.focus = function () { + if (!this.isFocussed) { + this.element.focus(); + } + }; + + Input.prototype.blur = function () { + if (this.isFocussed) { + this.element.blur(); + } + }; + + Input.prototype.clear = function (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 + */ + + + Input.prototype.setWidth = function () { + // Resize input to contents or placeholder + var _a = this.element, + style = _a.style, + value = _a.value, + placeholder = _a.placeholder; + style.minWidth = placeholder.length + 1 + "ch"; + style.width = value.length + 1 + "ch"; + }; + + Input.prototype.setActiveDescendant = function (activeDescendantID) { + this.element.setAttribute('aria-activedescendant', activeDescendantID); + }; + + Input.prototype.removeActiveDescendant = function () { + this.element.removeAttribute('aria-activedescendant'); + }; + + Input.prototype._onInput = function () { + if (this.type !== constants_1.SELECT_ONE_TYPE) { + this.setWidth(); + } + }; + + Input.prototype._onPaste = function (event) { + if (this.preventPaste) { + event.preventDefault(); + } + }; + + Input.prototype._onFocus = function () { + this.isFocussed = true; + }; + + Input.prototype._onBlur = function () { + this.isFocussed = false; + }; + + return Input; +}(); + +exports.default = Input; + +/***/ }), +/* 22 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var constants_1 = __webpack_require__(0); + +var List = +/** @class */ +function () { + function List(_a) { + var element = _a.element; + this.element = element; + this.scrollPos = this.element.scrollTop; + this.height = this.element.offsetHeight; + } + + List.prototype.clear = function () { + this.element.innerHTML = ''; + }; + + List.prototype.append = function (node) { + this.element.appendChild(node); + }; + + List.prototype.getChild = function (selector) { + return this.element.querySelector(selector); + }; + + List.prototype.hasChildren = function () { + return this.element.hasChildNodes(); + }; + + List.prototype.scrollToTop = function () { + this.element.scrollTop = 0; + }; + + List.prototype.scrollToChildElement = function (element, direction) { + var _this = this; + + if (!element) { + return; + } + + var listHeight = this.element.offsetHeight; // Scroll position of dropdown + + var listScrollPosition = this.element.scrollTop + listHeight; + var elementHeight = element.offsetHeight; // Distance from bottom of element to top of parent + + var elementPos = element.offsetTop + elementHeight; // Difference between the element and scroll position + + var destination = direction > 0 ? this.element.scrollTop + elementPos - listScrollPosition : element.offsetTop; + requestAnimationFrame(function () { + _this._animateScroll(destination, direction); + }); + }; + + List.prototype._scrollDown = function (scrollPos, strength, destination) { + var easing = (destination - scrollPos) / strength; + var distance = easing > 1 ? easing : 1; + this.element.scrollTop = scrollPos + distance; + }; + + List.prototype._scrollUp = function (scrollPos, strength, destination) { + var easing = (scrollPos - destination) / strength; + var distance = easing > 1 ? easing : 1; + this.element.scrollTop = scrollPos - distance; + }; + + List.prototype._animateScroll = function (destination, direction) { + var _this = this; + + var strength = constants_1.SCROLLING_SPEED; + var choiceListScrollTop = this.element.scrollTop; + var continueAnimation = false; + + if (direction > 0) { + this._scrollDown(choiceListScrollTop, strength, destination); + + if (choiceListScrollTop < destination) { + continueAnimation = true; + } + } else { + this._scrollUp(choiceListScrollTop, strength, destination); + + if (choiceListScrollTop > destination) { + continueAnimation = true; + } + } + + if (continueAnimation) { + requestAnimationFrame(function () { + _this._animateScroll(destination, direction); + }); + } + }; + + return List; +}(); + +exports.default = List; + +/***/ }), +/* 23 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var __extends = this && this.__extends || function () { + var _extendStatics = function extendStatics(d, b) { + _extendStatics = Object.setPrototypeOf || { + __proto__: [] + } instanceof Array && function (d, b) { + d.__proto__ = b; + } || function (d, b) { + for (var p in b) { + if (b.hasOwnProperty(p)) d[p] = b[p]; + } + }; + + return _extendStatics(d, b); + }; + + return function (d, b) { + _extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +}(); + +var __importDefault = this && this.__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod + }; +}; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var wrapped_element_1 = __importDefault(__webpack_require__(5)); + +var WrappedInput = +/** @class */ +function (_super) { + __extends(WrappedInput, _super); + + function WrappedInput(_a) { + var element = _a.element, + classNames = _a.classNames, + delimiter = _a.delimiter; + + var _this = _super.call(this, { + element: element, + classNames: classNames + }) || this; + + _this.delimiter = delimiter; + return _this; + } + + Object.defineProperty(WrappedInput.prototype, "value", { + get: function get() { + return this.element.value; + }, + set: function set(value) { + this.element.setAttribute('value', value); + this.element.value = value; + }, + enumerable: true, + configurable: true + }); + return WrappedInput; +}(wrapped_element_1.default); + +exports.default = WrappedInput; + +/***/ }), +/* 24 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +var __extends = this && this.__extends || function () { + var _extendStatics = function extendStatics(d, b) { + _extendStatics = Object.setPrototypeOf || { + __proto__: [] + } instanceof Array && function (d, b) { + d.__proto__ = b; + } || function (d, b) { + for (var p in b) { + if (b.hasOwnProperty(p)) d[p] = b[p]; + } + }; + + return _extendStatics(d, b); + }; + + return function (d, b) { + _extendStatics(d, b); + + function __() { + this.constructor = d; + } + + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +}(); + +var __importDefault = this && this.__importDefault || function (mod) { + return mod && mod.__esModule ? mod : { + "default": mod + }; +}; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var wrapped_element_1 = __importDefault(__webpack_require__(5)); + +var WrappedSelect = +/** @class */ +function (_super) { + __extends(WrappedSelect, _super); + + function WrappedSelect(_a) { + var element = _a.element, + classNames = _a.classNames, + template = _a.template; + + var _this = _super.call(this, { + element: element, + classNames: classNames + }) || this; + + _this.template = template; + return _this; + } + + Object.defineProperty(WrappedSelect.prototype, "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]'); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WrappedSelect.prototype, "optionGroups", { + get: function get() { + return Array.from(this.element.getElementsByTagName('OPTGROUP')); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WrappedSelect.prototype, "options", { + get: function get() { + return Array.from(this.element.options); + }, + set: function set(options) { + var _this = this; + + var fragment = document.createDocumentFragment(); + + var addOptionToFragment = function addOptionToFragment(data) { + // Create a standard select option + var option = _this.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); + }, + enumerable: true, + configurable: true + }); + + WrappedSelect.prototype.appendDocFragment = function (fragment) { + this.element.innerHTML = ''; + this.element.appendChild(fragment); + }; + + return WrappedSelect; +}(wrapped_element_1.default); + +exports.default = WrappedSelect; + +/***/ }), +/* 25 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +/** + * Helpers to create HTML elements used by Choices + * Can be overridden by providing `callbackOnCreateTemplates` option + */ + +var templates = { + containerOuter: function containerOuter(_a, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { + var containerOuter = _a.containerOuter; + var div = Object.assign(document.createElement('div'), { + className: containerOuter + }); + div.dataset.type = passedElementType; + + if (dir) { + div.dir = dir; + } + + if (isSelectOneElement) { + div.tabIndex = 0; + } + + if (isSelectElement) { + div.setAttribute('role', searchEnabled ? 'combobox' : 'listbox'); + + if (searchEnabled) { + div.setAttribute('aria-autocomplete', 'list'); + } + } + + div.setAttribute('aria-haspopup', 'true'); + div.setAttribute('aria-expanded', 'false'); + return div; + }, + containerInner: function containerInner(_a) { + var containerInner = _a.containerInner; + return Object.assign(document.createElement('div'), { + className: containerInner + }); + }, + itemList: function itemList(_a, isSelectOneElement) { + var list = _a.list, + listSingle = _a.listSingle, + listItems = _a.listItems; + return Object.assign(document.createElement('div'), { + className: list + " " + (isSelectOneElement ? listSingle : listItems) + }); + }, + placeholder: function placeholder(_a, value) { + var placeholder = _a.placeholder; + return Object.assign(document.createElement('div'), { + className: placeholder, + innerHTML: value + }); + }, + item: function item(_a, _b, removeItemButton) { + var item = _a.item, + button = _a.button, + highlightedState = _a.highlightedState, + itemSelectable = _a.itemSelectable, + placeholder = _a.placeholder; + var id = _b.id, + value = _b.value, + label = _b.label, + customProperties = _b.customProperties, + active = _b.active, + disabled = _b.disabled, + highlighted = _b.highlighted, + isPlaceholder = _b.placeholder; + var div = Object.assign(document.createElement('div'), { + className: item, + innerHTML: label + }); + Object.assign(div.dataset, { + item: '', + id: id, + value: value, + customProperties: customProperties + }); + + if (active) { + div.setAttribute('aria-selected', 'true'); + } + + if (disabled) { + div.setAttribute('aria-disabled', 'true'); + } + + if (isPlaceholder) { + div.classList.add(placeholder); + } + + div.classList.add(highlighted ? highlightedState : itemSelectable); + + if (removeItemButton) { + if (disabled) { + div.classList.remove(itemSelectable); + } + + div.dataset.deletable = ''; + /** @todo This MUST be localizable, not hardcoded! */ + + var REMOVE_ITEM_TEXT = 'Remove item'; + var removeButton = Object.assign(document.createElement('button'), { + type: 'button', + className: button, + innerHTML: REMOVE_ITEM_TEXT + }); + removeButton.setAttribute('aria-label', REMOVE_ITEM_TEXT + ": '" + value + "'"); + removeButton.dataset.button = ''; + div.appendChild(removeButton); + } + + return div; + }, + choiceList: function choiceList(_a, isSelectOneElement) { + var list = _a.list; + var div = Object.assign(document.createElement('div'), { + className: list + }); + + if (!isSelectOneElement) { + div.setAttribute('aria-multiselectable', 'true'); + } + + div.setAttribute('role', 'listbox'); + return div; + }, + choiceGroup: function choiceGroup(_a, _b) { + var group = _a.group, + groupHeading = _a.groupHeading, + itemDisabled = _a.itemDisabled; + var id = _b.id, + value = _b.value, + disabled = _b.disabled; + var div = Object.assign(document.createElement('div'), { + className: group + " " + (disabled ? itemDisabled : '') + }); + div.setAttribute('role', 'group'); + Object.assign(div.dataset, { + group: '', + id: id, + value: value + }); + + if (disabled) { + div.setAttribute('aria-disabled', 'true'); + } + + div.appendChild(Object.assign(document.createElement('div'), { + className: groupHeading, + innerHTML: value + })); + return div; + }, + choice: function choice(_a, _b, selectText) { + var item = _a.item, + itemChoice = _a.itemChoice, + itemSelectable = _a.itemSelectable, + selectedState = _a.selectedState, + itemDisabled = _a.itemDisabled, + placeholder = _a.placeholder; + var id = _b.id, + value = _b.value, + label = _b.label, + groupId = _b.groupId, + elementId = _b.elementId, + isDisabled = _b.disabled, + isSelected = _b.selected, + isPlaceholder = _b.placeholder; + var div = Object.assign(document.createElement('div'), { + id: elementId, + innerHTML: label, + className: item + " " + itemChoice + }); + + if (isSelected) { + div.classList.add(selectedState); + } + + if (isPlaceholder) { + div.classList.add(placeholder); + } + + div.setAttribute('role', groupId && groupId > 0 ? 'treeitem' : 'option'); + Object.assign(div.dataset, { + choice: '', + id: id, + value: value, + selectText: selectText + }); + + if (isDisabled) { + div.classList.add(itemDisabled); + div.dataset.choiceDisabled = ''; + div.setAttribute('aria-disabled', 'true'); + } else { + div.classList.add(itemSelectable); + div.dataset.choiceSelectable = ''; + } + + return div; + }, + input: function input(_a, placeholderValue) { + var input = _a.input, + inputCloned = _a.inputCloned; + var inp = Object.assign(document.createElement('input'), { + type: 'text', + className: input + " " + inputCloned, + autocomplete: 'off', + autocapitalize: 'off', + spellcheck: false + }); + inp.setAttribute('role', 'textbox'); + inp.setAttribute('aria-autocomplete', 'list'); + inp.setAttribute('aria-label', placeholderValue); + return inp; + }, + dropdown: function dropdown(_a) { + var list = _a.list, + listDropdown = _a.listDropdown; + var div = document.createElement('div'); + div.classList.add(list, listDropdown); + div.setAttribute('aria-expanded', 'false'); + return div; + }, + notice: function notice(_a, innerHTML, type) { + var item = _a.item, + itemChoice = _a.itemChoice, + noResults = _a.noResults, + noChoices = _a.noChoices; + + if (type === void 0) { + type = ''; + } + + var classes = [item, itemChoice]; + + if (type === 'no-choices') { + classes.push(noChoices); + } else if (type === 'no-results') { + classes.push(noResults); + } + + return Object.assign(document.createElement('div'), { + innerHTML: innerHTML, + className: classes.join(' ') + }); + }, + option: function option(_a) { + var label = _a.label, + value = _a.value, + customProperties = _a.customProperties, + active = _a.active, + disabled = _a.disabled; + var opt = new Option(label, value, false, active); + + if (customProperties) { + opt.dataset.customProperties = "" + customProperties; + } + + opt.disabled = !!disabled; + return opt; + } +}; +exports.default = templates; + +/***/ }), +/* 26 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var constants_1 = __webpack_require__(0); + +exports.addChoice = function (_a) { + var value = _a.value, + label = _a.label, + id = _a.id, + groupId = _a.groupId, + disabled = _a.disabled, + elementId = _a.elementId, + customProperties = _a.customProperties, + placeholder = _a.placeholder, + keyCode = _a.keyCode; + return { + type: constants_1.ACTION_TYPES.ADD_CHOICE, + value: value, + label: label, + id: id, + groupId: groupId, + disabled: disabled, + elementId: elementId, + customProperties: customProperties, + placeholder: placeholder, + keyCode: keyCode + }; +}; + +exports.filterChoices = function (results) { + return { + type: constants_1.ACTION_TYPES.FILTER_CHOICES, + results: results + }; +}; + +exports.activateChoices = function (active) { + if (active === void 0) { + active = true; + } + + return { + type: constants_1.ACTION_TYPES.ACTIVATE_CHOICES, + active: active + }; +}; + +exports.clearChoices = function () { + return { + type: constants_1.ACTION_TYPES.CLEAR_CHOICES + }; +}; + +/***/ }), +/* 27 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var constants_1 = __webpack_require__(0); + +exports.addItem = function (_a) { + var value = _a.value, + label = _a.label, + id = _a.id, + choiceId = _a.choiceId, + groupId = _a.groupId, + customProperties = _a.customProperties, + placeholder = _a.placeholder, + keyCode = _a.keyCode; + return { + type: constants_1.ACTION_TYPES.ADD_ITEM, + value: value, + label: label, + id: id, + choiceId: choiceId, + groupId: groupId, + customProperties: customProperties, + placeholder: placeholder, + keyCode: keyCode + }; +}; + +exports.removeItem = function (id, choiceId) { + return { + type: constants_1.ACTION_TYPES.REMOVE_ITEM, + id: id, + choiceId: choiceId + }; +}; + +exports.highlightItem = function (id, highlighted) { + return { + type: constants_1.ACTION_TYPES.HIGHLIGHT_ITEM, + id: id, + highlighted: highlighted + }; +}; + +/***/ }), +/* 28 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var constants_1 = __webpack_require__(0); + +exports.addGroup = function (_a) { + var value = _a.value, + id = _a.id, + active = _a.active, + disabled = _a.disabled; + return { + type: constants_1.ACTION_TYPES.ADD_GROUP, + value: value, + id: id, + active: active, + disabled: disabled + }; +}; + +/***/ }), +/* 29 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var constants_1 = __webpack_require__(0); + +exports.clearAll = function () { + return { + type: constants_1.ACTION_TYPES.CLEAR_ALL + }; +}; + +exports.resetTo = function (state) { + return { + type: constants_1.ACTION_TYPES.RESET_TO, + state: state + }; +}; + +exports.setIsLoading = function (isLoading) { + return { + type: constants_1.ACTION_TYPES.SET_IS_LOADING, + isLoading: isLoading + }; +}; /***/ }) /******/ ])["default"]; diff --git a/public/assets/scripts/choices.min.js b/public/assets/scripts/choices.min.js index 8223c62..eb8462b 100644 --- a/public/assets/scripts/choices.min.js +++ b/public/assets/scripts/choices.min.js @@ -1,11 +1,11 @@ /*! choices.js v9.0.1 | © 2019 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ -window.Choices=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=4)}([function(e,t,i){"use strict";var n=function(e){return function(e){return!!e&&"object"==typeof e}(e)&&!function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===s}(e)}(e)};var s="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function r(e,t){return!1!==t.clone&&t.isMergeableObject(e)?l((i=e,Array.isArray(i)?[]:{}),e,t):e;var i}function o(e,t,i){return e.concat(t).map((function(e){return r(e,i)}))}function a(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter((function(t){return e.propertyIsEnumerable(t)})):[]}(e))}function c(e,t,i){var n={};return i.isMergeableObject(e)&&a(e).forEach((function(t){n[t]=r(e[t],i)})),a(t).forEach((function(s){(function(e,t){try{return t in e&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))}catch(e){return!1}})(e,s)||(i.isMergeableObject(t[s])&&e[s]?n[s]=function(e,t){if(!t.customMerge)return l;var i=t.customMerge(e);return"function"==typeof i?i:l}(s,i)(e[s],t[s],i):n[s]=r(t[s],i))})),n}function l(e,t,i){(i=i||{}).arrayMerge=i.arrayMerge||o,i.isMergeableObject=i.isMergeableObject||n,i.cloneUnlessOtherwiseSpecified=r;var s=Array.isArray(t);return s===Array.isArray(e)?s?i.arrayMerge(e,t,i):c(e,t,i):r(t,i)}l.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce((function(e,i){return l(e,i,t)}),{})};var h=l;e.exports=h},function(e,t,i){"use strict";(function(e,n){var s,r=i(3);s="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==e?e:n;var o=Object(r.a)(s);t.a=o}).call(this,i(5),i(6)(e))},function(e,t,i){ +window.Choices=function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.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 r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));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=7)}([function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(1);t.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",selectedState:"is-selected",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"},t.DEFAULT_CONFIG={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,addItems:!0,addItemFilter: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,sorter:n.sortByAlpha,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 "'+n.sanitise(e)+'"'},maxItemText:function(e){return"Only "+e+" values can be added"},valueComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},callbackOnInit:null,callbackOnCreateTemplates:null,classNames:t.DEFAULT_CLASSNAMES},t.EVENTS={showDropdown:"showDropdown",hideDropdown:"hideDropdown",change:"change",choice:"choice",search:"search",addItem:"addItem",removeItem:"removeItem",highlightItem:"highlightItem",highlightChoice:"highlightChoice",unhighlightItem:"unhighlightItem"},t.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",RESET_TO:"RESET_TO",SET_IS_LOADING:"SET_IS_LOADING"},t.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},t.TEXT_TYPE="text",t.SELECT_ONE_TYPE="select-one",t.SELECT_MULTIPLE_TYPE="select-multiple",t.SCROLLING_SPEED=4},function(e,t,i){"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0}),t.getRandomNumber=function(e,t){return Math.floor(Math.random()*(t-e)+e)},t.generateChars=function(e){return Array.from({length:e},(function(){return t.getRandomNumber(0,36).toString(36)})).join("")},t.generateId=function(e,i){var n=e.id||e.name&&e.name+"-"+t.generateChars(2)||t.generateChars(4);return n=i+"-"+(n=n.replace(/(:|\.|\[|\]|,)/g,""))},t.getType=function(e){return Object.prototype.toString.call(e).slice(8,-1)},t.isType=function(e,i){return null!=i&&t.getType(i)===e},t.wrap=function(e,t){return void 0===t&&(t=document.createElement("div")),e.nextSibling?e.parentNode&&e.parentNode.insertBefore(t,e.nextSibling):e.parentNode&&e.parentNode.appendChild(t),t.appendChild(e)},t.getAdjacentEl=function(e,t,i){void 0===i&&(i=1);for(var n=(i>0?"next":"previous")+"ElementSibling",r=e[n];r;){if(r.matches(t))return r;r=r[n]}return r},t.isScrolledIntoView=function(e,t,i){return void 0===i&&(i=1),!!e&&(i>0?t.scrollTop+t.offsetHeight>=e.offsetTop+e.offsetHeight:e.offsetTop>=t.scrollTop)},t.sanitise=function(e){return"string"!=typeof e?e:e.replace(/&/g,"&").replace(/>/g,"&rt;").replace(/=0?this._store.getGroupById(r):null;return this._store.dispatch(d.highlightItem(i,!0)),t&&this.passedElement.triggerEvent(l.EVENTS.highlightItem,{id:i,value:s,label:c,groupValue:u&&u.value?u.value:null}),this},e.prototype.unhighlightItem=function(e){if(!e||!e.id)return this;var t=e.id,i=e.groupId,n=void 0===i?-1:i,r=e.value,o=void 0===r?"":r,s=e.label,a=void 0===s?"":s,c=n>=0?this._store.getGroupById(n):null;return this._store.dispatch(d.highlightItem(t,!1)),this.passedElement.triggerEvent(l.EVENTS.highlightItem,{id:t,value:o,label:a,groupValue:c&&c.value?c.value:null}),this},e.prototype.highlightAll=function(){var e=this;return this._store.items.forEach((function(t){return e.highlightItem(t)})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.items.forEach((function(t){return e.unhighlightItem(t)})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.activeItems.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.activeItems.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive?this:(requestAnimationFrame((function(){t.dropdown.show(),t.containerOuter.open(t.dropdown.distanceFromTopWindow),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent(l.EVENTS.showDropdown,{})})),this)},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent(l.EVENTS.hideDropdown,{})})),this):this},e.prototype.getValue=function(e){void 0===e&&(e=!1);var t=this._store.activeItems.reduce((function(t,i){var n=e?i.value:i;return t.push(n),t}),[]);return this._isSelectOneElement?t[0]:t},e.prototype.setValue=function(e){var t=this;return this.initialised?(e.forEach((function(e){return t._setChoiceOrItem(e)})),this):this},e.prototype.setChoiceByValue=function(e){var t=this;return!this.initialised||this._isTextElement?this:((Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)})),this)},e.prototype.setChoices=function(e,t,i,n){var r=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===i&&(i="label"),void 0===n&&(n=!1),!this.initialised)throw new ReferenceError("setChoices was called on a non-initialized instance of Choices");if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(n&&this.clearChoices(),"function"==typeof e){var o=e(this);if("function"==typeof Promise&&o instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return r._handleLoadingState(!0)})).then((function(){return o})).then((function(e){return r.setChoices(e,t,i,n)})).catch((function(e){r.config.silent||console.error(e)})).then((function(){return r._handleLoadingState(!1)})).then((function(){return r}));if(!Array.isArray(o))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: "+typeof o);return this.setChoices(o,t,i,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._startLoading(),e.forEach((function(e){if(e.choices)r._addGroup({id:e.id?parseInt(""+e.id,10):null,group:e,valueKey:t,labelKey:i});else{var n=e;r._addChoice({value:n[t],label:n[i],isSelected:!!n.selected,isDisabled:!!n.disabled,placeholder:!!n.placeholder,customProperties:n.customProperties})}})),this._stopLoading(),this},e.prototype.clearChoices=function(){return this._store.dispatch(h.clearChoices()),this},e.prototype.clearStore=function(){return this._store.dispatch(f.clearAll()),this},e.prototype.clearInput=function(){var e=!this._isSelectOneElement;return this.input.clear(e),!this._isTextElement&&this._canSearch&&(this._isSearching=!1,this._store.dispatch(h.activateChoices(!0))),this},e.prototype._render=function(){if(!this._store.isLoading()){this._currentState=this._store.state;var e=this._currentState.choices!==this._prevState.choices||this._currentState.groups!==this._prevState.groups||this._currentState.items!==this._prevState.items,t=this._isSelectElement,i=this._currentState.items!==this._prevState.items;e&&(t&&this._renderChoices(),i&&this._renderItems(),this._prevState=this._currentState)}},e.prototype._renderChoices=function(){var e=this,t=this._store,i=t.activeGroups,n=t.activeChoices,r=document.createDocumentFragment();if(this.choiceList.clear(),this.config.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),i.length>=1&&!this._isSearching){var o=n.filter((function(e){return!0===e.placeholder&&-1===e.groupId}));o.length>=1&&(r=this._createChoicesFragment(o,r)),r=this._createGroupsFragment(i,n,r)}else n.length>=1&&(r=this._createChoicesFragment(n,r));if(r.childNodes&&r.childNodes.length>0){var s=this._store.activeItems,a=this._canAddItem(s,this.input.value);if(a.response)this.choiceList.append(r),this._highlightChoice();else{var c=this._getTemplate("notice",a.notice);this.choiceList.append(c)}}else{var l=void 0;c=void 0;this._isSearching?(c="function"==typeof this.config.noResultsText?this.config.noResultsText():this.config.noResultsText,l=this._getTemplate("notice",c,"no-results")):(c="function"==typeof this.config.noChoicesText?this.config.noChoicesText():this.config.noChoicesText,l=this._getTemplate("notice",c,"no-choices")),this.choiceList.append(l)}},e.prototype._renderItems=function(){var e=this._store.activeItems||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes&&this.itemList.append(t)},e.prototype._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());return this.config.shouldSort&&e.sort(this.config.sorter),e.forEach((function(e){var r=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===n.config.renderSelectedChoices||!t.selected)}))}(e);if(r.length>=1){var o=n._getTemplate("choiceGroup",e);i.appendChild(o),n._createChoicesFragment(r,i,!0)}})),i},e.prototype._createChoicesFragment=function(e,t,i){var r=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var o=this.config,s=o.renderSelectedChoices,a=o.searchResultLimit,c=o.renderChoiceLimit,l=this._isSearching?m.sortByScore:this.config.sorter,u=function(e){if("auto"!==s||(r._isSelectOneElement||!e.selected)){var i=r._getTemplate("choice",e,r.config.itemSelectText);t.appendChild(i)}},h=e;"auto"!==s||this._isSelectOneElement||(h=e.filter((function(e){return!e.selected})));var d=h.reduce((function(e,t){return t.placeholder?e.placeholderChoices.push(t):e.normalChoices.push(t),e}),{placeholderChoices:[],normalChoices:[]}),p=d.placeholderChoices,f=d.normalChoices;(this.config.shouldSort||this._isSearching)&&f.sort(l);var v=h.length,_=this._isSelectOneElement?n(p,f):f;this._isSearching?v=a:c&&c>0&&!i&&(v=c);for(var g=0;g=n){var s=r?this._searchChoices(e):0;this.passedElement.triggerEvent(l.EVENTS.search,{value:e,resultCount:s})}else o&&(this._isSearching=!1,this._store.dispatch(h.activateChoices(!0)))}},e.prototype._canAddItem=function(e,t){var i=!0,n="function"==typeof this.config.addItemText?this.config.addItemText(t):this.config.addItemText;if(!this._isSelectOneElement){var r=m.existsInArray(e,t);this.config.maxItemCount>0&&this.config.maxItemCount<=e.length&&(i=!1,n="function"==typeof this.config.maxItemText?this.config.maxItemText(this.config.maxItemCount):this.config.maxItemText),!this.config.duplicateItemsAllowed&&r&&i&&(i=!1,n="function"==typeof this.config.uniqueItemText?this.config.uniqueItemText(t):this.config.uniqueItemText),this._isTextElement&&this.config.addItems&&i&&"function"==typeof this.config.addItemFilter&&!this.config.addItemFilter(t)&&(i=!1,n="function"==typeof this.config.customAddItemText?this.config.customAddItemText(t):this.config.customAddItemText)}return{response:i,notice:n}},e.prototype._searchChoices=function(e){var t="string"==typeof e?e.trim():e,i="string"==typeof this._currentValue?this._currentValue.trim():this._currentValue;if(t.length<1&&t===i+" ")return 0;var r=this._store.searchableChoices,s=t,a=n(this.config.searchFields),c=Object.assign(this.config.fuseOptions,{keys:a,includeMatches:!0}),l=new o.default(r,c).search(s);return this._currentValue=t,this._highlightPosition=0,this._isSearching=!0,this._store.dispatch(h.filterChoices(l)),l.length},e.prototype._addEventListeners=function(){var e=document.documentElement;e.addEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.addEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(this.containerOuter.element.addEventListener("focus",this._onFocus,{passive:!0}),this.containerOuter.element.addEventListener("blur",this._onBlur,{passive:!0})),this.input.element.addEventListener("keyup",this._onKeyUp,{passive:!0}),this.input.element.addEventListener("focus",this._onFocus,{passive:!0}),this.input.element.addEventListener("blur",this._onBlur,{passive:!0}),this.input.element.form&&this.input.element.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},e.prototype._removeEventListeners=function(){var e=document.documentElement;e.removeEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.removeEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(this.containerOuter.element.removeEventListener("focus",this._onFocus),this.containerOuter.element.removeEventListener("blur",this._onBlur)),this.input.element.removeEventListener("keyup",this._onKeyUp),this.input.element.removeEventListener("focus",this._onFocus),this.input.element.removeEventListener("blur",this._onBlur),this.input.element.form&&this.input.element.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},e.prototype._onKeyDown=function(e){var t=e.keyCode,i=this._store.activeItems,n=this.input.isFocussed,r=this.dropdown.isActive,o=this.itemList.hasChildren(),s=String.fromCharCode(t),a=/[a-zA-Z0-9-_ ]/.test(s),c=l.KEY_CODES.BACK_KEY,u=l.KEY_CODES.DELETE_KEY,h=l.KEY_CODES.ENTER_KEY,d=l.KEY_CODES.A_KEY,p=l.KEY_CODES.ESC_KEY,f=l.KEY_CODES.UP_KEY,m=l.KEY_CODES.DOWN_KEY,v=l.KEY_CODES.PAGE_UP_KEY,_=l.KEY_CODES.PAGE_DOWN_KEY;switch(this._isTextElement||r||!a||(this.showDropdown(),this.input.isFocussed||(this.input.value+=s.toLowerCase())),t){case d:return this._onSelectKey(e,o);case h:return this._onEnterKey(e,i,r);case p:return this._onEscapeKey(r);case f:case v:case m:case _:return this._onDirectionKey(e,r);case u:case c:return this._onDeleteKey(e,i,n)}},e.prototype._onKeyUp=function(e){var t=e.target,i=e.keyCode,n=this.input.value,r=this._store.activeItems,o=this._canAddItem(r,n),s=l.KEY_CODES.BACK_KEY,a=l.KEY_CODES.DELETE_KEY;if(this._isTextElement){if(o.notice&&n){var c=this._getTemplate("notice",o.notice);this.dropdown.element.innerHTML=c.outerHTML,this.showDropdown(!0)}else this.hideDropdown(!0)}else{var u=(i===s||i===a)&&t&&!t.value,d=!this._isTextElement&&this._isSearching,p=this._canSearch&&o.response;u&&d?(this._isSearching=!1,this._store.dispatch(h.activateChoices(!0))):p&&this._handleSearch(this.input.value)}this._canSearch=this.config.searchEnabled},e.prototype._onSelectKey=function(e,t){var i=e.ctrlKey,n=e.metaKey;(i||n)&&t&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},e.prototype._onEnterKey=function(e,t,i){var n=e.target,r=l.KEY_CODES.ENTER_KEY,o=n&&n.hasAttribute("data-button");if(this._isTextElement&&n&&n.value){var s=this.input.value;this._canAddItem(t,s).response&&(this.hideDropdown(!0),this._addItem({value:s}),this._triggerChange(s),this.clearInput())}if(o&&(this._handleButtonAction(t,n),e.preventDefault()),i){var a=this.dropdown.getChild("."+this.config.classNames.highlightedState);a&&(t[0]&&(t[0].keyCode=r),this._handleChoiceAction(t,a)),e.preventDefault()}else this._isSelectOneElement&&(this.showDropdown(),e.preventDefault())},e.prototype._onEscapeKey=function(e){e&&(this.hideDropdown(!0),this.containerOuter.focus())},e.prototype._onDirectionKey=function(e,t){var i=e.keyCode,n=e.metaKey,r=l.KEY_CODES.DOWN_KEY,o=l.KEY_CODES.PAGE_UP_KEY,s=l.KEY_CODES.PAGE_DOWN_KEY;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var a=i===r||i===s?1:-1,c=void 0;if(n||i===s||i===o)c=a>0?this.dropdown.element.querySelector("[data-choice-selectable]:last-of-type"):this.dropdown.element.querySelector("[data-choice-selectable]");else{var u=this.dropdown.element.querySelector("."+this.config.classNames.highlightedState);c=u?m.getAdjacentEl(u,"[data-choice-selectable]",a):this.dropdown.element.querySelector("[data-choice-selectable]")}c&&(m.isScrolledIntoView(c,this.choiceList.element,a)||this.choiceList.scrollToChildElement(c,a),this._highlightChoice(c)),e.preventDefault()}},e.prototype._onDeleteKey=function(e,t,i){var n=e.target;this._isSelectOneElement||n.value||!i||(this._handleBackspace(t),e.preventDefault())},e.prototype._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},e.prototype._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation());this._wasTap=!0},e.prototype._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(_&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild,n="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetX0&&this.unhighlightAll(),this.containerOuter.removeFocusState(),this.hideDropdown(!0))},e.prototype._onFocus=function(e){var t,i=this,n=e.target;n&&this.containerOuter.element.contains(n)&&((t={})[l.TEXT_TYPE]=function(){n===i.input.element&&i.containerOuter.addFocusState()},t[l.SELECT_ONE_TYPE]=function(){i.containerOuter.addFocusState(),n===i.input.element&&i.showDropdown(!0)},t[l.SELECT_MULTIPLE_TYPE]=function(){n===i.input.element&&(i.showDropdown(!0),i.containerOuter.addFocusState())},t)[this.passedElement.element.type]()},e.prototype._onBlur=function(e){var t,i=this,n=e.target;if(n&&this.containerOuter.element.contains(n)&&!this._isScrollingOnIe){var r=this._store.activeItems.some((function(e){return e.highlighted}));((t={})[l.TEXT_TYPE]=function(){n===i.input.element&&(i.containerOuter.removeFocusState(),r&&i.unhighlightAll(),i.hideDropdown(!0))},t[l.SELECT_ONE_TYPE]=function(){i.containerOuter.removeFocusState(),(n===i.input.element||n===i.containerOuter.element&&!i._canSearch)&&i.hideDropdown(!0)},t[l.SELECT_MULTIPLE_TYPE]=function(){n===i.input.element&&(i.containerOuter.removeFocusState(),i.hideDropdown(!0),r&&i.unhighlightAll())},t)[this.passedElement.element.type]()}else this._isScrollingOnIe=!1,this.input.element.focus()},e.prototype._onFormReset=function(){this._store.dispatch(f.resetTo(this._initialState))},e.prototype._highlightChoice=function(e){var t=this;void 0===e&&(e=null);var i=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]"));if(i.length){var n=e;Array.from(this.dropdown.element.querySelectorAll("."+this.config.classNames.highlightedState)).forEach((function(e){e.classList.remove(t.config.classNames.highlightedState),e.setAttribute("aria-selected","false")})),n?this._highlightPosition=i.indexOf(n):(n=i.length>this._highlightPosition?i[this._highlightPosition]:i[i.length-1])||(n=i[0]),n.classList.add(this.config.classNames.highlightedState),n.setAttribute("aria-selected","true"),this.passedElement.triggerEvent(l.EVENTS.highlightChoice,{el:n}),this.dropdown.isActive&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}},e.prototype._addItem=function(e){var t=e.value,i=e.label,n=void 0===i?null:i,r=e.choiceId,o=void 0===r?-1:r,s=e.groupId,a=void 0===s?-1:s,c=e.customProperties,u=void 0===c?{}:c,h=e.placeholder,p=void 0!==h&&h,f=e.keyCode,m=void 0===f?-1:f,v="string"==typeof t?t.trim():t,_=this._store.items,g=n||v,y=o||-1,b=a>=0?this._store.getGroupById(a):null,E=_?_.length+1:1;this.config.prependValue&&(v=this.config.prependValue+v.toString()),this.config.appendValue&&(v+=this.config.appendValue.toString()),this._store.dispatch(d.addItem({value:v,label:g,id:E,choiceId:y,groupId:a,customProperties:u,placeholder:p,keyCode:m})),this._isSelectOneElement&&this.removeActiveItems(E),this.passedElement.triggerEvent(l.EVENTS.addItem,{id:E,value:v,label:g,customProperties:u,groupValue:b&&b.value?b.value:null,keyCode:m})},e.prototype._removeItem=function(e){var t=e.id,i=e.value,n=e.label,r=e.customProperties,o=e.choiceId,s=e.groupId,a=s&&s>=0?this._store.getGroupById(s):null;t&&o&&(this._store.dispatch(d.removeItem(t,o)),this.passedElement.triggerEvent(l.EVENTS.removeItem,{id:t,value:i,label:n,customProperties:r,groupValue:a&&a.value?a.value:null}))},e.prototype._addChoice=function(e){var t=e.value,i=e.label,n=void 0===i?null:i,r=e.isSelected,o=void 0!==r&&r,s=e.isDisabled,a=void 0!==s&&s,c=e.groupId,l=void 0===c?-1:c,u=e.customProperties,d=void 0===u?{}:u,p=e.placeholder,f=void 0!==p&&p,m=e.keyCode,v=void 0===m?-1:m;if(null!=t){var _=this._store.choices,g=n||t,y=_?_.length+1:1,b=this._baseId+"-"+this._idNames.itemChoice+"-"+y;this._store.dispatch(h.addChoice({id:y,groupId:l,elementId:b,value:t,label:g,disabled:a,customProperties:d,placeholder:f,keyCode:v})),o&&this._addItem({value:t,label:g,choiceId:y,customProperties:d,placeholder:f,keyCode:v})}},e.prototype._addGroup=function(e){var t=this,i=e.group,n=e.id,r=e.valueKey,o=void 0===r?"value":r,s=e.labelKey,a=void 0===s?"label":s,c=m.isType("Object",i)?i.choices:Array.from(i.getElementsByTagName("OPTION")),l=n||Math.floor((new Date).valueOf()*Math.random()),u=!!i.disabled&&i.disabled;if(c){this._store.dispatch(p.addGroup({value:i.label,id:l,active:!0,disabled:u}));c.forEach((function(e){var i=e.disabled||e.parentNode&&e.parentNode.disabled;t._addChoice({value:e[o],label:m.isType("Object",e)?e[a]:e.innerHTML,isSelected:e.selected,isDisabled:i,groupId:l,customProperties:e.customProperties,placeholder:e.placeholder})}))}else this._store.dispatch(p.addGroup({value:i.label,id:i.id,active:!1,disabled:i.disabled}))},e.prototype._getTemplate=function(e){for(var t,i=[],r=1;r1&&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:c},{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,c=e.index,l=t.tokenSearchers,h=void 0===l?[]:l,u=t.fullSearcher,d=void 0===u?[]:u,p=t.resultMap,m=void 0===p?{}:p,f=t.results,v=void 0===f?[]:f;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),I=[],S=0;S-1&&(P=(P+_)/2),this._log("Score average:",P);var D=!this.options.tokenize||!this.options.matchAllTokens||b>=h.length;if(this._log("\nCheck Matches: ".concat(D)),(g||y.isMatch)&&D){var M=m[c];M?M.output.push({key:i,arrayIndex:s,value:r,score:P,matchedIndices:y.matchedIndices}):(m[c]={item:o,output:[{key:i,arrayIndex:s,value:r,score:P,matchedIndices:y.matchedIndices}]},v.push(m[c]))}}else if(a(r))for(var N=0,F=r.length;N-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;ri)return s(e,this.pattern,n);var o=this.options,a=o.location,c=o.distance,l=o.threshold,h=o.findAllMatches,u=o.minMatchCharLength;return r(e,this.pattern,this.patternAlphabet,{location:a,distance:c,threshold:l,findAllMatches:h,minMatchCharLength:u})}}])&&n(t.prototype,i),e}();e.exports=a},function(e,t){var i=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;e.exports=function(e,t){var n=arguments.length>2&&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 c=0,l=r.length;c=P;N-=1){var F=N-1,j=i[e.charAt(F)];if(j&&(E[F]=1),M[N]=(M[N+1]<<1|1)&j,0!==T&&(M[N]|=(O[N+1]|O[N])<<1|1|O[N+1]),M[N]&L&&(C=n(t,{errors:T,currentLocation:F,expectedLocation:v,distance:l}))<=_){if(_=C,(b=F)<=v)break;P=Math.max(1,2*v-b)}}if(n(t,{errors:T+1,currentLocation:v,expectedLocation:v,distance:l})>_)break;O=M}return{isMatch:b>=0,score:0===C?.001:C,matchedIndices:s(E,f)}}},function(e,t){e.exports=function(e,t){var i=t.errors,n=void 0===i?0:i,s=t.currentLocation,r=void 0===s?0:s,o=t.expectedLocation,a=void 0===o?0:o,c=t.distance,l=void 0===c?100:c,h=n/e.length,u=Math.abs(a-r);return l?h+u/l:u?1:h}},function(e,t){e.exports=function(){for(var e=arguments.length>0&&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}},function(e,t){e.exports=function(e){for(var t={},i=e.length,n=0;n/g,"&rt;").replace(/-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 f;default:return e}},general:_}),T=function(e,t){var i=e;if("CLEAR_ALL"===t.type)i=void 0;else if("RESET_TO"===t.type)return C(t.state);return L(i,t)};function x(e,t){for(var i=0;i"'+S(e)+'"'},maxItemText:function(e){return"Only "+e+" values can be added"},valueComparer: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",selectedState:"is-selected",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"}},N="showDropdown",F="hideDropdown",j="change",R="choice",H="search",K="addItem",B="removeItem",V="highlightItem",G="highlightChoice",q="ADD_CHOICE",U="FILTER_CHOICES",z="ACTIVATE_CHOICES",W="CLEAR_CHOICES",X="ADD_GROUP",$="ADD_ITEM",J="REMOVE_ITEM",Y="HIGHLIGHT_ITEM",Z=46,Q=8,ee=13,te=65,ie=27,ne=38,se=40,re=33,oe=34,ae="text",ce="select-one",le="select-multiple",he=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,s=e.position;this.element=t,this.classNames=n,this.type=i,this.position=s,this.isOpen=!1,this.isFlipped=!1,this.isFocussed=!1,this.isDisabled=!1,this.isLoading=!1,this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}var t=e.prototype;return t.addEventListeners=function(){this.element.addEventListener("focus",this._onFocus),this.element.addEventListener("blur",this._onBlur)},t.removeEventListeners=function(){this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur)},t.shouldFlip=function(e){if("number"!=typeof e)return!1;var t=!1;return"auto"===this.position?t=!window.matchMedia("(min-height: "+(e+1)+"px)").matches:"top"===this.position&&(t=!0),t},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"),this.type===ce&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},t.disable=function(){this.element.classList.add(this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),this.type===ce&&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 ue(e,t){for(var i=0;i0?this.element.scrollTop+o-s:e.offsetTop;requestAnimationFrame((function(){i._animateScroll(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){var i=this,n=this.element.scrollTop,s=!1;t>0?(this._scrollDown(n,4,e),ne&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}();function me(e,t){for(var i=0;i0?"treeitem":"option"),Object.assign(g.dataset,{choice:"",id:l,value:h,selectText:i}),m?(g.classList.add(a),g.dataset.choiceDisabled="",g.setAttribute("aria-disabled","true")):(g.classList.add(r),g.dataset.choiceSelectable=""),g},input:function(e,t){var i=e.input,n=e.inputCloned,s=Object.assign(document.createElement("input"),{type:"text",className:i+" "+n,autocomplete:"off",autocapitalize:"off",spellcheck:!1});return s.setAttribute("role","textbox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-label",t),s},dropdown:function(e){var t=e.list,i=e.listDropdown,n=document.createElement("div");return n.classList.add(t,i),n.setAttribute("aria-expanded","false"),n},notice:function(e,t,i){var n=e.item,s=e.itemChoice,r=e.noResults,o=e.noChoices;void 0===i&&(i="");var a=[n,s];return"no-choices"===i?a.push(o):"no-results"===i&&a.push(r),Object.assign(document.createElement("div"),{innerHTML:t,className:a.join(" ")})},option:function(e){var t=e.label,i=e.value,n=e.customProperties,s=e.active,r=e.disabled,o=new Option(t,i,!1,s);return n&&(o.dataset.customProperties=n),o.disabled=r,o}},Ee=function(e){return void 0===e&&(e=!0),{type:z,active:e}},Ie=function(e,t){return{type:Y,id:e,highlighted:t}},Se=function(e){var t=e.value,i=e.id,n=e.active,s=e.disabled;return{type:X,value:t,id:i,active:n,disabled:s}},we=function(e){return{type:"SET_IS_LOADING",isLoading:e}};function Oe(e,t){for(var i=0;i=0?this._store.getGroupById(s):null;return this._store.dispatch(Ie(i,!0)),t&&this.passedElement.triggerEvent(V,{id:i,value:o,label:c,groupValue:l&&l.value?l.value:null}),this},r.unhighlightItem=function(e){if(!e)return this;var t=e.id,i=e.groupId,n=void 0===i?-1:i,s=e.value,r=void 0===s?"":s,o=e.label,a=void 0===o?"":o,c=n>=0?this._store.getGroupById(n):null;return this._store.dispatch(Ie(t,!1)),this.passedElement.triggerEvent(V,{id:t,value:r,label:a,groupValue:c&&c.value?c.value:null}),this},r.highlightAll=function(){var e=this;return this._store.items.forEach((function(t){return e.highlightItem(t)})),this},r.unhighlightAll=function(){var e=this;return this._store.items.forEach((function(t){return e.unhighlightItem(t)})),this},r.removeActiveItemsByValue=function(e){var t=this;return this._store.activeItems.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)})),this},r.removeActiveItems=function(e){var t=this;return this._store.activeItems.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)})),this},r.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)})),this},r.showDropdown=function(e){var t=this;return this.dropdown.isActive?this:(requestAnimationFrame((function(){t.dropdown.show(),t.containerOuter.open(t.dropdown.distanceFromTopWindow),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent(N,{})})),this)},r.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent(F,{})})),this):this},r.getValue=function(e){void 0===e&&(e=!1);var t=this._store.activeItems.reduce((function(t,i){var n=e?i.value:i;return t.push(n),t}),[]);return this._isSelectOneElement?t[0]:t},r.setValue=function(e){var t=this;return this.initialised?(e.forEach((function(e){return t._setChoiceOrItem(e)})),this):this},r.setChoiceByValue=function(e){var t=this;return!this.initialised||this._isTextElement?this:((Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)})),this)},r.setChoices=function(e,t,i,n){var s=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===i&&(i="label"),void 0===n&&(n=!1),!this.initialised)throw new ReferenceError("setChoices was called on a non-initialized instance of Choices");if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(n&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return s._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return s.setChoices(e,t,i,n)})).catch((function(e){s.config.silent||console.error(e)})).then((function(){return s._handleLoadingState(!1)})).then((function(){return s}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: "+typeof r);return this.setChoices(r,t,i,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._startLoading(),e.forEach((function(e){e.choices?s._addGroup({id:parseInt(e.id,10)||null,group:e,valueKey:t,labelKey:i}):s._addChoice({value:e[t],label:e[i],isSelected:e.selected,isDisabled:e.disabled,customProperties:e.customProperties,placeholder:e.placeholder})})),this._stopLoading(),this},r.clearChoices=function(){return this._store.dispatch({type:W}),this},r.clearStore=function(){return this._store.dispatch({type:"CLEAR_ALL"}),this},r.clearInput=function(){var e=!this._isSelectOneElement;return this.input.clear(e),!this._isTextElement&&this._canSearch&&(this._isSearching=!1,this._store.dispatch(Ee(!0))),this},r._render=function(){if(!this._store.isLoading()){this._currentState=this._store.state;var e=this._currentState.choices!==this._prevState.choices||this._currentState.groups!==this._prevState.groups||this._currentState.items!==this._prevState.items,t=this._isSelectElement,i=this._currentState.items!==this._prevState.items;e&&(t&&this._renderChoices(),i&&this._renderItems(),this._prevState=this._currentState)}},r._renderChoices=function(){var e=this,t=this._store,i=t.activeGroups,n=t.activeChoices,s=document.createDocumentFragment();if(this.choiceList.clear(),this.config.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),i.length>=1&&!this._isSearching){var r=n.filter((function(e){return!0===e.placeholder&&-1===e.groupId}));r.length>=1&&(s=this._createChoicesFragment(r,s)),s=this._createGroupsFragment(i,n,s)}else n.length>=1&&(s=this._createChoicesFragment(n,s));if(s.childNodes&&s.childNodes.length>0){var o=this._store.activeItems,a=this._canAddItem(o,this.input.value);a.response?(this.choiceList.append(s),this._highlightChoice()):this.choiceList.append(this._getTemplate("notice",a.notice))}else{var c,l;this._isSearching?(l="function"==typeof this.config.noResultsText?this.config.noResultsText():this.config.noResultsText,c=this._getTemplate("notice",l,"no-results")):(l="function"==typeof this.config.noChoicesText?this.config.noChoicesText():this.config.noChoicesText,c=this._getTemplate("notice",l,"no-choices")),this.choiceList.append(c)}},r._renderItems=function(){var e=this._store.activeItems||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes&&this.itemList.append(t)},r._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());return this.config.shouldSort&&e.sort(this.config.sorter),e.forEach((function(e){var s=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===n.config.renderSelectedChoices||!t.selected)}))}(e);if(s.length>=1){var r=n._getTemplate("choiceGroup",e);i.appendChild(r),n._createChoicesFragment(s,i,!0)}})),i},r._createChoicesFragment=function(e,t,i){var n=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var s=this.config,r=s.renderSelectedChoices,o=s.searchResultLimit,a=s.renderChoiceLimit,c=this._isSearching?O:this.config.sorter,l=function(e){if("auto"!==r||(n._isSelectOneElement||!e.selected)){var i=n._getTemplate("choice",e,n.config.itemSelectText);t.appendChild(i)}},h=e;"auto"!==r||this._isSelectOneElement||(h=e.filter((function(e){return!e.selected})));var u=h.reduce((function(e,t){return t.placeholder?e.placeholderChoices.push(t):e.normalChoices.push(t),e}),{placeholderChoices:[],normalChoices:[]}),d=u.placeholderChoices,p=u.normalChoices;(this.config.shouldSort||this._isSearching)&&p.sort(c);var m=h.length,f=this._isSelectOneElement?[].concat(d,p):p;this._isSearching?m=o:a&&a>0&&!i&&(m=a);for(var v=0;v=n){var o=s?this._searchChoices(e):0;this.passedElement.triggerEvent(H,{value:e,resultCount:o})}else r&&(this._isSearching=!1,this._store.dispatch(Ee(!0)))}},r._canAddItem=function(e,t){var i=!0,n="function"==typeof this.config.addItemText?this.config.addItemText(t):this.config.addItemText;if(!this._isSelectOneElement){var s=function(e,t,i){return void 0===i&&(i="value"),e.some((function(e){return"string"==typeof t?e[i]===t.trim():e[i]===t}))}(e,t);this.config.maxItemCount>0&&this.config.maxItemCount<=e.length&&(i=!1,n="function"==typeof this.config.maxItemText?this.config.maxItemText(this.config.maxItemCount):this.config.maxItemText),!this.config.duplicateItemsAllowed&&s&&i&&(i=!1,n="function"==typeof this.config.uniqueItemText?this.config.uniqueItemText(t):this.config.uniqueItemText),this._isTextElement&&this.config.addItems&&i&&"function"==typeof this.config.addItemFilter&&!this.config.addItemFilter(t)&&(i=!1,n="function"==typeof this.config.customAddItemText?this.config.customAddItemText(t):this.config.customAddItemText)}return{response:i,notice:n}},r._searchChoices=function(e){var t="string"==typeof e?e.trim():e,i="string"==typeof this._currentValue?this._currentValue.trim():this._currentValue;if(t.length<1&&t===i+" ")return 0;var n=this._store.searchableChoices,r=t,o=[].concat(this.config.searchFields),a=Object.assign(this.config.fuseOptions,{keys:o}),c=new s.a(n,a).search(r);return this._currentValue=t,this._highlightPosition=0,this._isSearching=!0,this._store.dispatch(function(e){return{type:U,results:e}}(c)),c.length},r._addEventListeners=function(){var e=document.documentElement;e.addEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.addEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(this.containerOuter.element.addEventListener("focus",this._onFocus,{passive:!0}),this.containerOuter.element.addEventListener("blur",this._onBlur,{passive:!0})),this.input.element.addEventListener("keyup",this._onKeyUp,{passive:!0}),this.input.element.addEventListener("focus",this._onFocus,{passive:!0}),this.input.element.addEventListener("blur",this._onBlur,{passive:!0}),this.input.element.form&&this.input.element.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},r._removeEventListeners=function(){var e=document.documentElement;e.removeEventListener("touchend",this._onTouchEnd,!0),this.containerOuter.element.removeEventListener("keydown",this._onKeyDown,!0),this.containerOuter.element.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(this.containerOuter.element.removeEventListener("focus",this._onFocus),this.containerOuter.element.removeEventListener("blur",this._onBlur)),this.input.element.removeEventListener("keyup",this._onKeyUp),this.input.element.removeEventListener("focus",this._onFocus),this.input.element.removeEventListener("blur",this._onBlur),this.input.element.form&&this.input.element.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},r._onKeyDown=function(e){var t,i=e.keyCode,n=this._store.activeItems,s=this.input.isFocussed,r=this.dropdown.isActive,o=this.itemList.hasChildren(),a=String.fromCharCode(i),c=/[a-zA-Z0-9-_ ]/.test(a),l=Z,h=Q,u=ee,d=te,p=ie,m=ne,f=se,v=re,g=oe;this._isTextElement||r||!c||(this.showDropdown(),this.input.isFocussed||(this.input.value+=a.toLowerCase()));var _=((t={})[d]=this._onAKey,t[u]=this._onEnterKey,t[p]=this._onEscapeKey,t[m]=this._onDirectionKey,t[v]=this._onDirectionKey,t[f]=this._onDirectionKey,t[g]=this._onDirectionKey,t[h]=this._onDeleteKey,t[l]=this._onDeleteKey,t);_[i]&&_[i]({event:e,activeItems:n,hasFocusedInput:s,hasActiveDropdown:r,hasItems:o})},r._onKeyUp=function(e){var t=e.target,i=e.keyCode,n=this.input.value,s=this._store.activeItems,r=this._canAddItem(s,n),o=Z,a=Q;if(this._isTextElement){if(r.notice&&n){var c=this._getTemplate("notice",r.notice);this.dropdown.element.innerHTML=c.outerHTML,this.showDropdown(!0)}else this.hideDropdown(!0)}else{var l=(i===o||i===a)&&!t.value,h=!this._isTextElement&&this._isSearching,u=this._canSearch&&r.response;l&&h?(this._isSearching=!1,this._store.dispatch(Ee(!0))):u&&this._handleSearch(this.input.value)}this._canSearch=this.config.searchEnabled},r._onAKey=function(e){var t=e.event,i=e.hasItems,n=t.ctrlKey,s=t.metaKey;(n||s)&&i&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},r._onEnterKey=function(e){var t=e.event,i=e.activeItems,n=e.hasActiveDropdown,s=t.target,r=ee,o=s.hasAttribute("data-button");if(this._isTextElement&&s.value){var a=this.input.value;this._canAddItem(i,a).response&&(this.hideDropdown(!0),this._addItem({value:a}),this._triggerChange(a),this.clearInput())}if(o&&(this._handleButtonAction(i,s),t.preventDefault()),n){var c=this.dropdown.getChild("."+this.config.classNames.highlightedState);c&&(i[0]&&(i[0].keyCode=r),this._handleChoiceAction(i,c)),t.preventDefault()}else this._isSelectOneElement&&(this.showDropdown(),t.preventDefault())},r._onEscapeKey=function(e){e.hasActiveDropdown&&(this.hideDropdown(!0),this.containerOuter.focus())},r._onDirectionKey=function(e){var t,i,n,s=e.event,r=e.hasActiveDropdown,o=s.keyCode,a=s.metaKey,c=se,l=re,h=oe;if(r||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var u,d=o===c||o===h?1:-1;if(a||o===h||o===l)u=d>0?this.dropdown.element.querySelector("[data-choice-selectable]:last-of-type"):this.dropdown.element.querySelector("[data-choice-selectable]");else{var p=this.dropdown.element.querySelector("."+this.config.classNames.highlightedState);u=p?function(e,t,i){if(void 0===i&&(i=1),e instanceof Element&&"string"==typeof t){for(var n=(i>0?"next":"previous")+"ElementSibling",s=e[n];s;){if(s.matches(t))return s;s=s[n]}return s}}(p,"[data-choice-selectable]",d):this.dropdown.element.querySelector("[data-choice-selectable]")}u&&(t=u,i=this.choiceList.element,void 0===(n=d)&&(n=1),t&&(n>0?i.scrollTop+i.offsetHeight>=t.offsetTop+t.offsetHeight:t.offsetTop>=i.scrollTop)||this.choiceList.scrollToChildElement(u,d),this._highlightChoice(u)),s.preventDefault()}},r._onDeleteKey=function(e){var t=e.event,i=e.hasFocusedInput,n=e.activeItems,s=t.target;!i||s.value||this._isSelectOneElement||(this._handleBackspace(n),t.preventDefault())},r._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},r._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation());this._wasTap=!0},r._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(Ce&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild,n="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetX0&&this.unhighlightAll(),this.containerOuter.removeFocusState(),this.hideDropdown(!0))},r._onFocus=function(e){var t,i=this,n=e.target;this.containerOuter.element.contains(n)&&((t={})[ae]=function(){n===i.input.element&&i.containerOuter.addFocusState()},t[ce]=function(){i.containerOuter.addFocusState(),n===i.input.element&&i.showDropdown(!0)},t[le]=function(){n===i.input.element&&(i.showDropdown(!0),i.containerOuter.addFocusState())},t)[this.passedElement.element.type]()},r._onBlur=function(e){var t=this,i=e.target;if(this.containerOuter.element.contains(i)&&!this._isScrollingOnIe){var n,s=this._store.activeItems.some((function(e){return e.highlighted}));((n={})[ae]=function(){i===t.input.element&&(t.containerOuter.removeFocusState(),s&&t.unhighlightAll(),t.hideDropdown(!0))},n[ce]=function(){t.containerOuter.removeFocusState(),(i===t.input.element||i===t.containerOuter.element&&!t._canSearch)&&t.hideDropdown(!0)},n[le]=function(){i===t.input.element&&(t.containerOuter.removeFocusState(),t.hideDropdown(!0),s&&t.unhighlightAll())},n)[this.passedElement.element.type]()}else this._isScrollingOnIe=!1,this.input.element.focus()},r._onFormReset=function(){this._store.dispatch({type:"RESET_TO",state:this._initialState})},r._highlightChoice=function(e){var t=this;void 0===e&&(e=null);var i=Array.from(this.dropdown.element.querySelectorAll("[data-choice-selectable]"));if(i.length){var n=e;Array.from(this.dropdown.element.querySelectorAll("."+this.config.classNames.highlightedState)).forEach((function(e){e.classList.remove(t.config.classNames.highlightedState),e.setAttribute("aria-selected","false")})),n?this._highlightPosition=i.indexOf(n):(n=i.length>this._highlightPosition?i[this._highlightPosition]:i[i.length-1])||(n=i[0]),n.classList.add(this.config.classNames.highlightedState),n.setAttribute("aria-selected","true"),this.passedElement.triggerEvent(G,{el:n}),this.dropdown.isActive&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}},r._addItem=function(e){var t=e.value,i=e.label,n=void 0===i?null:i,s=e.choiceId,r=void 0===s?-1:s,o=e.groupId,a=void 0===o?-1:o,c=e.customProperties,l=void 0===c?null:c,h=e.placeholder,u=void 0!==h&&h,d=e.keyCode,p=void 0===d?null:d,m="string"==typeof t?t.trim():t,f=p,v=l,g=this._store.items,_=n||m,b=r||-1,y=a>=0?this._store.getGroupById(a):null,E=g?g.length+1:1;return this.config.prependValue&&(m=this.config.prependValue+m.toString()),this.config.appendValue&&(m+=this.config.appendValue.toString()),this._store.dispatch(function(e){var t=e.value,i=e.label,n=e.id,s=e.choiceId,r=e.groupId,o=e.customProperties,a=e.placeholder,c=e.keyCode;return{type:$,value:t,label:i,id:n,choiceId:s,groupId:r,customProperties:o,placeholder:a,keyCode:c}}({value:m,label:_,id:E,choiceId:b,groupId:a,customProperties:l,placeholder:u,keyCode:f})),this._isSelectOneElement&&this.removeActiveItems(E),this.passedElement.triggerEvent(K,{id:E,value:m,label:_,customProperties:v,groupValue:y&&y.value?y.value:void 0,keyCode:f}),this},r._removeItem=function(e){if(!e||!I("Object",e))return this;var t=e.id,i=e.value,n=e.label,s=e.choiceId,r=e.groupId,o=r>=0?this._store.getGroupById(r):null;return this._store.dispatch(function(e,t){return{type:J,id:e,choiceId:t}}(t,s)),o&&o.value?this.passedElement.triggerEvent(B,{id:t,value:i,label:n,groupValue:o.value}):this.passedElement.triggerEvent(B,{id:t,value:i,label:n}),this},r._addChoice=function(e){var t=e.value,i=e.label,n=void 0===i?null:i,s=e.isSelected,r=void 0!==s&&s,o=e.isDisabled,a=void 0!==o&&o,c=e.groupId,l=void 0===c?-1:c,h=e.customProperties,u=void 0===h?null:h,d=e.placeholder,p=void 0!==d&&d,m=e.keyCode,f=void 0===m?null:m;if(null!=t){var v=this._store.choices,g=n||t,_=v?v.length+1:1,b=this._baseId+"-"+this._idNames.itemChoice+"-"+_;this._store.dispatch(function(e){var t=e.value,i=e.label,n=e.id,s=e.groupId,r=e.disabled,o=e.elementId,a=e.customProperties,c=e.placeholder,l=e.keyCode;return{type:q,value:t,label:i,id:n,groupId:s,disabled:r,elementId:o,customProperties:a,placeholder:c,keyCode:l}}({id:_,groupId:l,elementId:b,value:t,label:g,disabled:a,customProperties:u,placeholder:p,keyCode:f})),r&&this._addItem({value:t,label:g,choiceId:_,customProperties:u,placeholder:p,keyCode:f})}},r._addGroup=function(e){var t=this,i=e.group,n=e.id,s=e.valueKey,r=void 0===s?"value":s,o=e.labelKey,a=void 0===o?"label":o,c=I("Object",i)?i.choices:Array.from(i.getElementsByTagName("OPTION")),l=n||Math.floor((new Date).valueOf()*Math.random()),h=!!i.disabled&&i.disabled;if(c){this._store.dispatch(Se({value:i.label,id:l,active:!0,disabled:h}));c.forEach((function(e){var i=e.disabled||e.parentNode&&e.parentNode.disabled;t._addChoice({value:e[r],label:I("Object",e)?e[a]:e.innerHTML,isSelected:e.selected,isDisabled:i,groupId:l,customProperties:e.customProperties,placeholder:e.placeholder})}))}else this._store.dispatch(Se({value:i.label,id:i.id,active:!1,disabled:i.disabled}))},r._getTemplate=function(e){var t;if(!e)return null;for(var i=this.config.classNames,n=arguments.length,s=new Array(n>1?n-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:{limit:!1};this._log('---------\nSearch pattern: "'.concat(e,'"'));var i=this._prepareSearchers(e),n=i.tokenSearchers,r=i.fullSearcher,o=this._search(n,r),s=o.weights,a=o.results;return this._computeScore(s,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,r=i.length;n0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1?arguments[1]:void 0,i=this.list,n={},r=[];if("string"==typeof i[0]){for(var o=0,s=i.length;o1)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(u,p),record:u,index:c},{resultMap:n,results:r,tokenSearchers:e,fullSearcher:t})}return{weights:a,results:r}}},{key:"_analyze",value:function(e,t){var i=e.key,n=e.arrayIndex,r=void 0===n?-1:n,o=e.value,s=e.record,c=e.index,l=t.tokenSearchers,u=void 0===l?[]:l,h=t.fullSearcher,d=void 0===h?[]:h,p=t.resultMap,f=void 0===p?{}:p,m=t.results,v=void 0===m?[]:m;if(null!=o){var _=!1,g=-1,y=0;if("string"==typeof o){this._log("\nKey: ".concat(""===i?"-":i));var b=d.search(o);if(this._log('Full text: "'.concat(o,'", score: ').concat(b.score)),this.options.tokenize){for(var E=o.split(this.options.tokenSeparator),S=[],I=0;I-1&&(x=(x+g)/2),this._log("Score average:",x);var N=!this.options.tokenize||!this.options.matchAllTokens||y>=u.length;if(this._log("\nCheck Matches: ".concat(N)),(_||b.isMatch)&&N){var M=f[c];M?M.output.push({key:i,arrayIndex:r,value:o,score:x,matchedIndices:b.matchedIndices}):(f[c]={item:s,output:[{key:i,arrayIndex:r,value:o,score:x,matchedIndices:b.matchedIndices}]},v.push(f[c]))}}else if(a(o))for(var j=0,k=o.length;j-1&&(s.arrayIndex=o.arrayIndex),t.matches.push(s)}}})),this.options.includeScore&&r.push((function(e,t){t.score=e.score}));for(var o=0,s=e.length;oi)return r(e,this.pattern,n);var s=this.options,a=s.location,c=s.distance,l=s.threshold,u=s.findAllMatches,h=s.minMatchCharLength;return o(e,this.pattern,this.patternAlphabet,{location:a,distance:c,threshold:l,findAllMatches:u,minMatchCharLength:h})}}])&&n(t.prototype,i),e}();e.exports=a},function(e,t){var i=/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;e.exports=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:/ +/g,r=new RegExp(t.replace(i,"\\$&").replace(n,"|")),o=e.match(r),s=!!o,a=[];if(s)for(var c=0,l=o.length;c=x;j-=1){var k=j-1,F=i[e.charAt(k)];if(F&&(E[k]=1),M[j]=(M[j+1]<<1|1)&F,0!==L&&(M[j]|=(C[j+1]|C[j])<<1|1|C[j+1]),M[j]&A&&(T=n(t,{errors:L,currentLocation:k,expectedLocation:v,distance:l}))<=g){if(g=T,(y=k)<=v)break;x=Math.max(1,2*v-y)}}if(n(t,{errors:L+1,currentLocation:v,expectedLocation:v,distance:l})>g)break;C=M}return{isMatch:y>=0,score:0===T?.001:T,matchedIndices:r(E,m)}}},function(e,t){e.exports=function(e,t){var i=t.errors,n=void 0===i?0:i,r=t.currentLocation,o=void 0===r?0:r,s=t.expectedLocation,a=void 0===s?0:s,c=t.distance,l=void 0===c?100:c,u=n/e.length,h=Math.abs(a-o);return l?u+h/l:h?1:u}},function(e,t){e.exports=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,i=[],n=-1,r=-1,o=0,s=e.length;o=t&&i.push([n,r]),n=-1)}return e[o-1]&&o-n>=t&&i.push([n,o-1]),i}},function(e,t){e.exports=function(e){for(var t={},i=e.length,n=0;n-1?e.map((function(e){var t=e;return t.id===parseInt(""+s.choiceId,10)&&(t.selected=!0),t})):e;case"REMOVE_ITEM":var a=i;return a.choiceId&&a.choiceId>-1?e.map((function(e){var t=e;return t.id===parseInt(""+a.choiceId,10)&&(t.selected=!1),t})):e;case"FILTER_CHOICES":var c=i;return e.map((function(e){var t=e;return t.active=c.results.some((function(e){var i=e.item,n=e.score;return i.id===t.id&&(t.score=n,!0)})),t}));case"ACTIVATE_CHOICES":var l=i;return e.map((function(e){var t=e;return t.active=l.active,t}));case"CLEAR_CHOICES":return t.defaultState;default:return e}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultState=!1;t.default=function(e,i){switch(void 0===e&&(e=t.defaultState),i.type){case"SET_IS_LOADING":return i.isLoading;default:return e}}},function(e,t,i){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var r=n(i(19));t.Dropdown=r.default;var o=n(i(20));t.Container=o.default;var s=n(i(21));t.Input=s.default;var a=n(i(22));t.List=a.default;var c=n(i(23));t.WrappedInput=c.default;var l=n(i(24));t.WrappedSelect=l.default},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){var t=e.element,i=e.type,n=e.classNames;this.element=t,this.classNames=n,this.type=i,this.isActive=!1}return Object.defineProperty(e.prototype,"distanceFromTopWindow",{get:function(){return this.element.getBoundingClientRect().bottom},enumerable:!0,configurable:!0}),e.prototype.getChild=function(e){return this.element.querySelector(e)},e.prototype.show=function(){return this.element.classList.add(this.classNames.activeState),this.element.setAttribute("aria-expanded","true"),this.isActive=!0,this},e.prototype.hide=function(){return this.element.classList.remove(this.classNames.activeState),this.element.setAttribute("aria-expanded","false"),this.isActive=!1,this},e}();t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(1),r=i(0),o=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,r=e.position;this.element=t,this.classNames=n,this.type=i,this.position=r,this.isOpen=!1,this.isFlipped=!1,this.isFocussed=!1,this.isDisabled=!1,this.isLoading=!1,this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return e.prototype.addEventListeners=function(){this.element.addEventListener("focus",this._onFocus),this.element.addEventListener("blur",this._onBlur)},e.prototype.removeEventListeners=function(){this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur)},e.prototype.shouldFlip=function(e){if("number"!=typeof e)return!1;var t=!1;return"auto"===this.position?t=!window.matchMedia("(min-height: "+(e+1)+"px)").matches:"top"===this.position&&(t=!0),t},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype.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)},e.prototype.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)},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.addFocusState=function(){this.element.classList.add(this.classNames.focusState)},e.prototype.removeFocusState=function(){this.element.classList.remove(this.classNames.focusState)},e.prototype.enable=function(){this.element.classList.remove(this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),this.type===r.SELECT_ONE_TYPE&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){this.element.classList.add(this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),this.type===r.SELECT_ONE_TYPE&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){n.wrap(e,this.element)},e.prototype.unwrap=function(e){this.element.parentNode&&(this.element.parentNode.insertBefore(e,this.element),this.element.parentNode.removeChild(this.element))},e.prototype.addLoadingState=function(){this.element.classList.add(this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){this.element.classList.remove(this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}();t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(1),r=i(0),o=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,r=e.preventPaste;this.element=t,this.type=i,this.classNames=n,this.preventPaste=r,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=t.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.placeholder=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return n.sanitise(this.element.value)},set:function(e){this.element.value=e},enumerable:!0,configurable:!0}),e.prototype.addEventListeners=function(){this.element.addEventListener("paste",this._onPaste),this.element.addEventListener("input",this._onInput,{passive:!0}),this.element.addEventListener("focus",this._onFocus,{passive:!0}),this.element.addEventListener("blur",this._onBlur,{passive:!0})},e.prototype.removeEventListeners=function(){this.element.removeEventListener("input",this._onInput),this.element.removeEventListener("paste",this._onPaste),this.element.removeEventListener("focus",this._onFocus),this.element.removeEventListener("blur",this._onBlur)},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.isDisabled=!0},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.blur=function(){this.isFocussed&&this.element.blur()},e.prototype.clear=function(e){return void 0===e&&(e=!0),this.element.value&&(this.element.value=""),e&&this.setWidth(),this},e.prototype.setWidth=function(){var e=this.element,t=e.style,i=e.value,n=e.placeholder;t.minWidth=n.length+1+"ch",t.width=i.length+1+"ch"},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype._onInput=function(){this.type!==r.SELECT_ONE_TYPE&&this.setWidth()},e.prototype._onPaste=function(e){this.preventPaste&&e.preventDefault()},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}();t.default=o},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(0),r=function(){function e(e){var t=e.element;this.element=t,this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight}return e.prototype.clear=function(){this.element.innerHTML=""},e.prototype.append=function(e){this.element.appendChild(e)},e.prototype.getChild=function(e){return this.element.querySelector(e)},e.prototype.hasChildren=function(){return this.element.hasChildNodes()},e.prototype.scrollToTop=function(){this.element.scrollTop=0},e.prototype.scrollToChildElement=function(e,t){var i=this;if(e){var n=this.element.offsetHeight,r=this.element.scrollTop+n,o=e.offsetHeight,s=e.offsetTop+o,a=t>0?this.element.scrollTop+s-r:e.offsetTop;requestAnimationFrame((function(){i._animateScroll(a,t)}))}},e.prototype._scrollDown=function(e,t,i){var n=(i-e)/t,r=n>1?n:1;this.element.scrollTop=e+r},e.prototype._scrollUp=function(e,t,i){var n=(e-i)/t,r=n>1?n:1;this.element.scrollTop=e-r},e.prototype._animateScroll=function(e,t){var i=this,r=n.SCROLLING_SPEED,o=this.element.scrollTop,s=!1;t>0?(this._scrollDown(o,r,e),oe&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}();t.default=r},function(e,t,i){"use strict";var n,r=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)},function(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}),o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=function(e){function t(t){var i=t.element,n=t.classNames,r=t.delimiter,o=e.call(this,{element:i,classNames:n})||this;return o.delimiter=r,o}return r(t,e),Object.defineProperty(t.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.setAttribute("value",e),this.element.value=e},enumerable:!0,configurable:!0}),t}(o(i(5)).default);t.default=s},function(e,t,i){"use strict";var n,r=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)},function(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}),o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=function(e){function t(t){var i=t.element,n=t.classNames,r=t.template,o=e.call(this,{element:i,classNames:n})||this;return o.template=r,o}return r(t,e),Object.defineProperty(t.prototype,"placeholderOption",{get:function(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"optionGroups",{get:function(){return Array.from(this.element.getElementsByTagName("OPTGROUP"))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"options",{get:function(){return Array.from(this.element.options)},set:function(e){var t=this,i=document.createDocumentFragment();e.forEach((function(e){return n=e,r=t.template(n),void i.appendChild(r);var n,r})),this.appendDocFragment(i)},enumerable:!0,configurable:!0}),t.prototype.appendDocFragment=function(e){this.element.innerHTML="",this.element.appendChild(e)},t}(o(i(5)).default);t.default=s},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n={containerOuter:function(e,t,i,n,r,o){var s=e.containerOuter,a=Object.assign(document.createElement("div"),{className:s});return a.dataset.type=o,t&&(a.dir=t),n&&(a.tabIndex=0),i&&(a.setAttribute("role",r?"combobox":"listbox"),r&&a.setAttribute("aria-autocomplete","list")),a.setAttribute("aria-haspopup","true"),a.setAttribute("aria-expanded","false"),a},containerInner:function(e){var t=e.containerInner;return Object.assign(document.createElement("div"),{className:t})},itemList:function(e,t){var i=e.list,n=e.listSingle,r=e.listItems;return Object.assign(document.createElement("div"),{className:i+" "+(t?n:r)})},placeholder:function(e,t){var i=e.placeholder;return Object.assign(document.createElement("div"),{className:i,innerHTML:t})},item:function(e,t,i){var n=e.item,r=e.button,o=e.highlightedState,s=e.itemSelectable,a=e.placeholder,c=t.id,l=t.value,u=t.label,h=t.customProperties,d=t.active,p=t.disabled,f=t.highlighted,m=t.placeholder,v=Object.assign(document.createElement("div"),{className:n,innerHTML:u});if(Object.assign(v.dataset,{item:"",id:c,value:l,customProperties:h}),d&&v.setAttribute("aria-selected","true"),p&&v.setAttribute("aria-disabled","true"),m&&v.classList.add(a),v.classList.add(f?o:s),i){p&&v.classList.remove(s),v.dataset.deletable="";var _=Object.assign(document.createElement("button"),{type:"button",className:r,innerHTML:"Remove item"});_.setAttribute("aria-label","Remove item: '"+l+"'"),_.dataset.button="",v.appendChild(_)}return v},choiceList:function(e,t){var i=e.list,n=Object.assign(document.createElement("div"),{className:i});return t||n.setAttribute("aria-multiselectable","true"),n.setAttribute("role","listbox"),n},choiceGroup:function(e,t){var i=e.group,n=e.groupHeading,r=e.itemDisabled,o=t.id,s=t.value,a=t.disabled,c=Object.assign(document.createElement("div"),{className:i+" "+(a?r:"")});return c.setAttribute("role","group"),Object.assign(c.dataset,{group:"",id:o,value:s}),a&&c.setAttribute("aria-disabled","true"),c.appendChild(Object.assign(document.createElement("div"),{className:n,innerHTML:s})),c},choice:function(e,t,i){var n=e.item,r=e.itemChoice,o=e.itemSelectable,s=e.selectedState,a=e.itemDisabled,c=e.placeholder,l=t.id,u=t.value,h=t.label,d=t.groupId,p=t.elementId,f=t.disabled,m=t.selected,v=t.placeholder,_=Object.assign(document.createElement("div"),{id:p,innerHTML:h,className:n+" "+r});return m&&_.classList.add(s),v&&_.classList.add(c),_.setAttribute("role",d&&d>0?"treeitem":"option"),Object.assign(_.dataset,{choice:"",id:l,value:u,selectText:i}),f?(_.classList.add(a),_.dataset.choiceDisabled="",_.setAttribute("aria-disabled","true")):(_.classList.add(o),_.dataset.choiceSelectable=""),_},input:function(e,t){var i=e.input,n=e.inputCloned,r=Object.assign(document.createElement("input"),{type:"text",className:i+" "+n,autocomplete:"off",autocapitalize:"off",spellcheck:!1});return r.setAttribute("role","textbox"),r.setAttribute("aria-autocomplete","list"),r.setAttribute("aria-label",t),r},dropdown:function(e){var t=e.list,i=e.listDropdown,n=document.createElement("div");return n.classList.add(t,i),n.setAttribute("aria-expanded","false"),n},notice:function(e,t,i){var n=e.item,r=e.itemChoice,o=e.noResults,s=e.noChoices;void 0===i&&(i="");var a=[n,r];return"no-choices"===i?a.push(s):"no-results"===i&&a.push(o),Object.assign(document.createElement("div"),{innerHTML:t,className:a.join(" ")})},option:function(e){var t=e.label,i=e.value,n=e.customProperties,r=e.active,o=e.disabled,s=new Option(t,i,!1,r);return n&&(s.dataset.customProperties=""+n),s.disabled=!!o,s}};t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(0);t.addChoice=function(e){var t=e.value,i=e.label,r=e.id,o=e.groupId,s=e.disabled,a=e.elementId,c=e.customProperties,l=e.placeholder,u=e.keyCode;return{type:n.ACTION_TYPES.ADD_CHOICE,value:t,label:i,id:r,groupId:o,disabled:s,elementId:a,customProperties:c,placeholder:l,keyCode:u}},t.filterChoices=function(e){return{type:n.ACTION_TYPES.FILTER_CHOICES,results:e}},t.activateChoices=function(e){return void 0===e&&(e=!0),{type:n.ACTION_TYPES.ACTIVATE_CHOICES,active:e}},t.clearChoices=function(){return{type:n.ACTION_TYPES.CLEAR_CHOICES}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(0);t.addItem=function(e){var t=e.value,i=e.label,r=e.id,o=e.choiceId,s=e.groupId,a=e.customProperties,c=e.placeholder,l=e.keyCode;return{type:n.ACTION_TYPES.ADD_ITEM,value:t,label:i,id:r,choiceId:o,groupId:s,customProperties:a,placeholder:c,keyCode:l}},t.removeItem=function(e,t){return{type:n.ACTION_TYPES.REMOVE_ITEM,id:e,choiceId:t}},t.highlightItem=function(e,t){return{type:n.ACTION_TYPES.HIGHLIGHT_ITEM,id:e,highlighted:t}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(0);t.addGroup=function(e){var t=e.value,i=e.id,r=e.active,o=e.disabled;return{type:n.ACTION_TYPES.ADD_GROUP,value:t,id:i,active:r,disabled:o}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=i(0);t.clearAll=function(){return{type:n.ACTION_TYPES.CLEAR_ALL}},t.resetTo=function(e){return{type:n.ACTION_TYPES.RESET_TO,state:e}},t.setIsLoading=function(e){return{type:n.ACTION_TYPES.SET_IS_LOADING,isLoading:e}}}]).default; \ No newline at end of file diff --git a/src/scripts/actions/choices.test.ts b/src/scripts/actions/choices.test.ts index aedb0fd..d023b25 100644 --- a/src/scripts/actions/choices.test.ts +++ b/src/scripts/actions/choices.test.ts @@ -6,15 +6,15 @@ describe('actions/choices', () => { it('returns ADD_CHOICE action', () => { const value = 'test'; const label = 'test'; - const id = 'test'; - const groupId = 'test'; + const id = 1; + const groupId = 1; const disabled = false; - const elementId = 'test'; - const customProperties = 'test'; - const placeholder = 'test'; + const elementId = 1; + const customProperties = { test: true }; + const placeholder = true; const keyCode = 10; - const expectedAction = { + const expectedAction: actions.AddChoiceAction = { type: 'ADD_CHOICE', value, label, @@ -46,7 +46,7 @@ describe('actions/choices', () => { describe('filterChoices action', () => { it('returns FILTER_CHOICES action', () => { const results = Array(10); - const expectedAction = { + const expectedAction: actions.FilterChoicesAction = { type: 'FILTER_CHOICES', results, }; @@ -58,7 +58,7 @@ describe('actions/choices', () => { describe('activateChoices action', () => { describe('not passing active parameter', () => { it('returns ACTIVATE_CHOICES action', () => { - const expectedAction = { + const expectedAction: actions.ActivateChoicesAction = { type: 'ACTIVATE_CHOICES', active: true, }; @@ -70,7 +70,7 @@ describe('actions/choices', () => { describe('passing active parameter', () => { it('returns ACTIVATE_CHOICES action', () => { const active = true; - const expectedAction = { + const expectedAction: actions.ActivateChoicesAction = { type: 'ACTIVATE_CHOICES', active, }; @@ -82,7 +82,7 @@ describe('actions/choices', () => { describe('clearChoices action', () => { it('returns CLEAR_CHOICES action', () => { - const expectedAction = { + const expectedAction: actions.ClearChoicesAction = { type: 'CLEAR_CHOICES', }; diff --git a/src/scripts/actions/groups.test.ts b/src/scripts/actions/groups.test.ts index 0f5e299..f56e29c 100644 --- a/src/scripts/actions/groups.test.ts +++ b/src/scripts/actions/groups.test.ts @@ -8,7 +8,8 @@ describe('actions/groups', () => { const id = 1; const active = true; const disabled = false; - const expectedAction = { + + const expectedAction: actions.AddGroupAction = { type: 'ADD_GROUP', value, id, diff --git a/src/scripts/actions/items.test.ts b/src/scripts/actions/items.test.ts index 6c2528b..28b9ba0 100644 --- a/src/scripts/actions/items.test.ts +++ b/src/scripts/actions/items.test.ts @@ -13,7 +13,7 @@ describe('actions/items', () => { const placeholder = true; const keyCode = 10; - const expectedAction = { + const expectedAction: actions.AddItemAction = { type: 'ADD_ITEM', value, label, @@ -44,7 +44,8 @@ describe('actions/items', () => { it('returns REMOVE_ITEM action', () => { const id = 1; const choiceId = 1; - const expectedAction = { + + const expectedAction: actions.RemoveItemAction = { type: 'REMOVE_ITEM', id, choiceId, @@ -59,7 +60,7 @@ describe('actions/items', () => { const id = 1; const highlighted = true; - const expectedAction = { + const expectedAction: actions.HighlightItemAction = { type: 'HIGHLIGHT_ITEM', id, highlighted, diff --git a/src/scripts/actions/misc.test.ts b/src/scripts/actions/misc.test.ts index 214232c..b1577b4 100644 --- a/src/scripts/actions/misc.test.ts +++ b/src/scripts/actions/misc.test.ts @@ -1,10 +1,11 @@ import { expect } from 'chai'; import * as actions from './misc'; +import { State } from '../interfaces'; describe('actions/misc', () => { describe('clearAll action', () => { it('returns CLEAR_ALL action', () => { - const expectedAction = { + const expectedAction: actions.ClearAllAction = { type: 'CLEAR_ALL', }; @@ -14,15 +15,13 @@ describe('actions/misc', () => { describe('resetTo action', () => { it('returns RESET_TO action', () => { - const state = { + const state: State = { choices: [], items: [], groups: [], - general: { - loading: false, - }, + loading: false, }; - const expectedAction = { + const expectedAction: actions.ResetToAction = { type: 'RESET_TO', state, }; @@ -34,7 +33,7 @@ describe('actions/misc', () => { describe('setIsLoading action', () => { describe('setting loading state to true', () => { it('returns expected action', () => { - const expectedAction = { + const expectedAction: actions.SetIsLoadingAction = { type: 'SET_IS_LOADING', isLoading: true, }; @@ -45,7 +44,7 @@ describe('actions/misc', () => { describe('setting loading state to false', () => { it('returns expected action', () => { - const expectedAction = { + const expectedAction: actions.SetIsLoadingAction = { type: 'SET_IS_LOADING', isLoading: false, };