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