From 264a0cb48602d477f47de88d1169ffc6b611a97b Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Mon, 28 Oct 2019 19:53:24 +0000 Subject: [PATCH] Build --- .eslintignore | 1 + public/assets/scripts/choices.js | 472 ++++++++++++++------------- public/assets/scripts/choices.min.js | 9 +- public/assets/styles/base.css | 12 +- public/assets/styles/base.min.css | 2 +- public/assets/styles/choices.css | 88 +++-- public/assets/styles/choices.min.css | 2 +- 7 files changed, 294 insertions(+), 292 deletions(-) diff --git a/.eslintignore b/.eslintignore index 81acc7f..e6fc5a0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules/ types/ +public/ \ No newline at end of file diff --git a/public/assets/scripts/choices.js b/public/assets/scripts/choices.js index 4207034..fa969aa 100644 --- a/public/assets/scripts/choices.js +++ b/public/assets/scripts/choices.js @@ -92,70 +92,13 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 5); +/******/ return __webpack_require__(__webpack_require__.s = 4); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { -var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! - Copyright (c) 2017 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/ -/* global define */ - -(function () { - 'use strict'; - - var hasOwn = {}.hasOwnProperty; - - function classNames () { - var classes = []; - - for (var i = 0; i < arguments.length; i++) { - var arg = arguments[i]; - if (!arg) continue; - - var argType = typeof arg; - - if (argType === 'string' || argType === 'number') { - classes.push(arg); - } else if (Array.isArray(arg) && arg.length) { - var inner = classNames.apply(null, arg); - if (inner) { - classes.push(inner); - } - } else if (argType === 'object') { - for (var key in arg) { - if (hasOwn.call(arg, key) && arg[key]) { - classes.push(key); - } - } - } - } - - return classes.join(' '); - } - - if ( true && module.exports) { - classNames.default = classNames; - module.exports = classNames; - } else if (true) { - // register as 'classnames', consistent with npm package name - !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { - return classNames; - }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), - __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); - } else {} -}()); - - -/***/ }), -/* 1 */ -/***/ (function(module, exports, __webpack_require__) { - "use strict"; @@ -291,11 +234,11 @@ module.exports = deepmerge_1; /***/ }), -/* 2 */ +/* 1 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(global, module) {/* harmony import */ var _ponyfill_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4); +/* WEBPACK VAR INJECTION */(function(global, module) {/* harmony import */ var _ponyfill_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3); /* global window */ @@ -314,10 +257,10 @@ if (typeof self !== 'undefined') { var result = Object(_ponyfill_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(root); /* harmony default export */ __webpack_exports__["a"] = (result); -/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(7), __webpack_require__(8)(module))) +/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(6), __webpack_require__(7)(module))) /***/ }), -/* 3 */ +/* 2 */ /***/ (function(module, exports, __webpack_require__) { /*! @@ -331,7 +274,7 @@ var result = Object(_ponyfill_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"] !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" + sanitise(value) + ""); - testEl.style.position = 'absolute'; - testEl.style.padding = '0'; - testEl.style.top = '-9999px'; - testEl.style.left = '-9999px'; - testEl.style.width = 'auto'; - testEl.style.whiteSpace = 'pre'; - - if (document.body.contains(input) && window.getComputedStyle) { - var inputStyle = window.getComputedStyle(input); - - if (inputStyle) { - testEl.style.fontSize = inputStyle.fontSize; - testEl.style.fontFamily = inputStyle.fontFamily; - testEl.style.fontWeight = inputStyle.fontWeight; - testEl.style.fontStyle = inputStyle.fontStyle; - testEl.style.letterSpacing = inputStyle.letterSpacing; - testEl.style.textTransform = inputStyle.textTransform; - testEl.style.paddingLeft = inputStyle.paddingLeft; - testEl.style.paddingRight = inputStyle.paddingRight; - } - } - - document.body.appendChild(testEl); - requestAnimationFrame(function () { - if (value && testEl.offsetWidth !== input.offsetWidth) { - width = testEl.offsetWidth + 4; - } - - document.body.removeChild(testEl); - callback.call(utils_this, width + "px"); - }); - } else { - callback.call(utils_this, width + "px"); - } -}; var sortByAlpha = function sortByAlpha(a, b) { var labelA = ("" + (a.label || a.value)).toLowerCase(); var labelB = ("" + (b.label || b.value)).toLowerCase(); @@ -1688,14 +1583,16 @@ function () { } /** * Get single choice by it's ID - * @return {Object} Found choice + * @param {id} string + * @return {import('../../../types/index').Choices.Choice | false} Found choice */ ; _proto.getChoiceById = function getChoiceById(id) { if (id) { + var n = parseInt(id, 10); return this.activeChoices.find(function (choice) { - return choice.id === parseInt(id, 10); + return choice.id === n; }); } @@ -2229,33 +2126,17 @@ function () { /** * Set the correct input width based on placeholder * value or input value - * @return */ ; - _proto.setWidth = function setWidth(enforceWidth) { - var _this = this; - - var callback = function callback(width) { - _this.element.style.width = width; - }; - - if (this._placeholderValue) { - // If there is a placeholder, we only want to set the width of the input when it is a greater - // length than 75% of the placeholder. This stops the input jumping around. - var valueHasDesiredLength = this.element.value.length >= this._placeholderValue.length / 1.25; - - if (this.element.value && valueHasDesiredLength || enforceWidth) { - this.calcWidth(callback); - } - } else { - // If there is no placeholder, resize input to contents - this.calcWidth(callback); - } - }; - - _proto.calcWidth = function calcWidth(callback) { - return calcWidthOfInput(this.element, callback); + _proto.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"; }; _proto.setActiveDescendant = function setActiveDescendant(activeDescendantID) { @@ -2331,7 +2212,6 @@ var DEFAULT_CLASSNAMES = { openState: 'is-open', disabledState: 'is-disabled', highlightedState: 'is-highlighted', - hiddenState: 'is-hidden', flippedState: 'is-flipped', loadingState: 'is-loading', noResults: 'has-no-results', @@ -2551,7 +2431,7 @@ function () { _proto.conceal = function conceal() { // Hide passed input this.element.classList.add(this.classNames.input); - this.element.classList.add(this.classNames.hiddenState); // Remove element from tab index + this.element.hidden = true; // Remove element from tab index this.element.tabIndex = '-1'; // Backup original styles if any @@ -2561,14 +2441,13 @@ function () { this.element.setAttribute('data-choice-orig-style', origStyle); } - this.element.setAttribute('aria-hidden', 'true'); this.element.setAttribute('data-choice', 'active'); }; _proto.reveal = function reveal() { // Reinstate passed element this.element.classList.remove(this.classNames.input); - this.element.classList.remove(this.classNames.hiddenState); + this.element.hidden = false; this.element.removeAttribute('tabindex'); // Recover original styles if any var origStyle = this.element.getAttribute('data-choice-orig-style'); @@ -2580,7 +2459,6 @@ function () { this.element.removeAttribute('style'); } - this.element.removeAttribute('aria-hidden'); this.element.removeAttribute('data-choice'); // Re-assign values - this is weird, I know this.element.value = this.element.value; @@ -2749,92 +2627,217 @@ function (_WrappedElement) { -// EXTERNAL MODULE: ./node_modules/classnames/index.js -var classnames = __webpack_require__(0); -var classnames_default = /*#__PURE__*/__webpack_require__.n(classnames); - // CONCATENATED MODULE: ./src/scripts/templates.js +/** + * Helpers to create HTML elements used by Choices + * Can be overridden by providing `callbackOnCreateTemplates` option + * @typedef {import('../../types/index').Choices.Templates} Templates + */ +var TEMPLATES = +/** @type {Templates} */ +{ + containerOuter: function containerOuter(_ref, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { + var _containerOuter = _ref.containerOuter; + var div = Object.assign(document.createElement('div'), { + className: _containerOuter, + dir: dir + }); + div.dataset.type = passedElementType; + if (isSelectOneElement) div.tabIndex = 0; - -var TEMPLATES = { - containerOuter: function containerOuter(globalClasses, direction, isSelectElement, isSelectOneElement, searchEnabled, passedElementType) { - var tabIndex = isSelectOneElement ? 'tabindex="0"' : ''; - var role = isSelectElement ? 'role="listbox"' : ''; - var ariaAutoComplete = ''; - - if (isSelectElement && searchEnabled) { - role = 'role="combobox"'; - ariaAutoComplete = 'aria-autocomplete="list"'; + if (isSelectElement) { + div.setAttribute('role', searchEnabled ? 'combobox' : 'listbox'); + if (searchEnabled) div.setAttribute('aria-autocomplete', 'list'); } - return strToEl("\n \n \n "); + div.setAttribute('aria-haspopup', 'true'); + div.setAttribute('aria-expanded', 'false'); + return div; }, - containerInner: function containerInner(globalClasses) { - return strToEl("\n
\n "); + containerInner: function containerInner(_ref2) { + var _containerInner = _ref2.containerInner; + return Object.assign(document.createElement('div'), { + className: _containerInner + }); }, - itemList: function itemList(globalClasses, isSelectOneElement) { - var _classNames; - - var localClasses = classnames_default()(globalClasses.list, (_classNames = {}, _classNames[globalClasses.listSingle] = isSelectOneElement, _classNames[globalClasses.listItems] = !isSelectOneElement, _classNames)); - return strToEl("\n
\n "); + 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) + }); }, - placeholder: function placeholder(globalClasses, value) { - return strToEl("\n
\n " + value + "\n
\n "); + placeholder: function placeholder(_ref4, value) { + var _placeholder = _ref4.placeholder; + return Object.assign(document.createElement('div'), { + className: _placeholder, + innerHTML: value + }); }, - item: function item(globalClasses, data, removeItemButton) { - var _classNames2; - - var ariaSelected = data.active ? 'aria-selected="true"' : ''; - var ariaDisabled = data.disabled ? 'aria-disabled="true"' : ''; - var localClasses = classnames_default()(globalClasses.item, (_classNames2 = {}, _classNames2[globalClasses.highlightedState] = data.highlighted, _classNames2[globalClasses.itemSelectable] = !data.highlighted, _classNames2[globalClasses.placeholder] = data.placeholder, _classNames2)); + 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) { - var _classNames3; + if (disabled) div.classList.remove(itemSelectable); + div.dataset.deletable = ''; + /** @todo This MUST be localizable, not hardcoded! */ - localClasses = classnames_default()(globalClasses.item, (_classNames3 = {}, _classNames3[globalClasses.highlightedState] = data.highlighted, _classNames3[globalClasses.itemSelectable] = !data.disabled, _classNames3[globalClasses.placeholder] = data.placeholder, _classNames3)); - return strToEl("\n \n " + data.label + "\n Remove item\n \n \n "); + 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 strToEl("\n \n " + data.label + "\n \n "); + return div; }, - choiceList: function choiceList(globalClasses, isSelectOneElement) { - var ariaMultiSelectable = !isSelectOneElement ? 'aria-multiselectable="true"' : ''; - return strToEl("\n \n \n "); + choiceList: function choiceList(_ref7, isSelectOneElement) { + var list = _ref7.list; + var div = Object.assign(document.createElement('div'), { + className: list, + dir: 'ltr' + }); + if (!isSelectOneElement) div.setAttribute('aria-multiselectable', 'true'); + div.setAttribute('role', 'listbox'); + return div; }, - choiceGroup: function choiceGroup(globalClasses, data) { - var _classNames4; + 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; + }, + choice: function choice(_ref10, _ref11, selectText) { + var item = _ref10.item, + itemChoice = _ref10.itemChoice, + itemSelectable = _ref10.itemSelectable, + itemDisabled = _ref10.itemDisabled, + placeholder = _ref10.placeholder; + var id = _ref11.id, + value = _ref11.value, + label = _ref11.label, + groupId = _ref11.groupId, + elementId = _ref11.elementId, + disabled = _ref11.disabled, + isPlaceholder = _ref11.placeholder; + var div = Object.assign(document.createElement('div'), { + id: elementId, + innerHTML: label, + className: item + " " + itemChoice + " " + (disabled ? itemDisabled : itemSelectable) + " " + (isPlaceholder ? placeholder : '') + }); + div.setAttribute('role', groupId > 0 ? 'treeitem' : 'option'); + Object.assign(div.dataset, { + choice: '', + id: id, + value: value, + selectText: selectText + }); - var ariaDisabled = data.disabled ? 'aria-disabled="true"' : ''; - var localClasses = classnames_default()(globalClasses.group, (_classNames4 = {}, _classNames4[globalClasses.itemDisabled] = data.disabled, _classNames4)); - return strToEl("\n \n
" + data.value + "
\n \n "); - }, - choice: function choice(globalClasses, data, itemSelectText) { - var _classNames5; + if (disabled) { + div.dataset.choiceDisabled = ''; + div.setAttribute('aria-disabled', 'true'); + } else div.dataset.choiceSelectable = ''; - var role = data.groupId > 0 ? 'role="treeitem"' : 'role="option"'; - var localClasses = classnames_default()(globalClasses.item, globalClasses.itemChoice, (_classNames5 = {}, _classNames5[globalClasses.itemDisabled] = data.disabled, _classNames5[globalClasses.itemSelectable] = !data.disabled, _classNames5[globalClasses.placeholder] = data.placeholder, _classNames5)); - return strToEl("\n \n " + data.label + "\n \n "); + return div; }, - input: function input(globalClasses, placeholderValue) { - var localClasses = classnames_default()(globalClasses.input, globalClasses.inputCloned); - return strToEl("\n \n "); + 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; }, - dropdown: function dropdown(globalClasses) { - var localClasses = classnames_default()(globalClasses.list, globalClasses.listDropdown); - return strToEl("\n \n \n "); + 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; }, - notice: function notice(globalClasses, label, type) { - var _classNames6; + 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 localClasses = classnames_default()(globalClasses.item, globalClasses.itemChoice, (_classNames6 = {}, _classNames6[globalClasses.noResults] = type === 'no-results', _classNames6[globalClasses.noChoices] = type === 'no-choices', _classNames6)); - return strToEl("\n
\n " + label + "\n
\n "); + 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(data) { - return strToEl("\n \n "); + 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); @@ -3374,16 +3377,20 @@ function () { }, []); return this._isSelectOneElement ? values[0] : values; - }; + } + /** + * @param {string[] | import('../../types/index').Choices.Item[]} items + */ + ; - _proto.setValue = function setValue(args) { + _proto.setValue = function setValue(items) { var _this9 = this; if (!this.initialised) { return this; } - [].concat(args).forEach(function (value) { + items.forEach(function (value) { return _this9._setChoiceOrItem(value); }); return this; @@ -3612,7 +3619,9 @@ function () { _proto._createGroupsFragment = function _createGroupsFragment(groups, choices, fragment) { var _this14 = this; - var groupFragment = fragment || document.createDocumentFragment(); + if (fragment === void 0) { + fragment = document.createDocumentFragment(); + } var getGroupChoices = function getGroupChoices(group) { return choices.filter(function (choice) { @@ -3635,23 +3644,26 @@ function () { if (groupChoices.length >= 1) { var dropdownGroup = _this14._getTemplate('choiceGroup', group); - groupFragment.appendChild(dropdownGroup); + fragment.appendChild(dropdownGroup); - _this14._createChoicesFragment(groupChoices, groupFragment, true); + _this14._createChoicesFragment(groupChoices, fragment, true); } }); - return groupFragment; + return fragment; }; _proto._createChoicesFragment = function _createChoicesFragment(choices, fragment, withinGroup) { var _this15 = this; + if (fragment === void 0) { + fragment = document.createDocumentFragment(); + } + if (withinGroup === void 0) { withinGroup = false; } // Create a fragment to store our list items (so we don't have to update the DOM for each item) - var choicesFragment = fragment || document.createDocumentFragment(); var _this$config = this.config, renderSelectedChoices = _this$config.renderSelectedChoices, searchResultLimit = _this$config.searchResultLimit, @@ -3664,7 +3676,7 @@ function () { if (shouldRender) { var dropdownItem = _this15._getTemplate('choice', choice, _this15.config.itemSelectText); - choicesFragment.appendChild(dropdownItem); + fragment.appendChild(dropdownItem); } }; @@ -3714,22 +3726,21 @@ function () { } } - return choicesFragment; + return fragment; }; _proto._createItemsFragment = function _createItemsFragment(items, fragment) { var _this16 = this; if (fragment === void 0) { - fragment = null; + fragment = document.createDocumentFragment(); } // Create fragment to add elements to var _this$config2 = this.config, shouldSortItems = _this$config2.shouldSortItems, sortFn = _this$config2.sortFn, - removeItemButton = _this$config2.removeItemButton; - var itemListFragment = fragment || document.createDocumentFragment(); // If sorting is enabled, filter items + removeItemButton = _this$config2.removeItemButton; // If sorting is enabled, filter items if (shouldSortItems && !this._isSelectOneElement) { items.sort(sortFn); @@ -3748,14 +3759,14 @@ function () { var listItem = _this16._getTemplate('item', item, removeItemButton); // Append it to list - itemListFragment.appendChild(listItem); + fragment.appendChild(listItem); }; // Add each list item to list items.forEach(function (item) { return addItemToFragment(item); }); - return itemListFragment; + return fragment; }; _proto._triggerChange = function _triggerChange(value) { @@ -3836,10 +3847,11 @@ function () { } // If we are clicking on an option - var id = element.getAttribute('data-id'); + var id = element.dataset.id; var choice = this._store.getChoiceById(id); + if (!choice) return; var passedKeyCode = activeItems[0] && activeItems[0].keyCode ? activeItems[0].keyCode : null; var hasActiveDropdown = this.dropdown.isActive; // Update choice keyCode @@ -3848,7 +3860,7 @@ function () { choice: choice }); - if (choice && !choice.selected && !choice.disabled) { + if (!choice.selected && !choice.disabled) { var canAddItem = this._canAddItem(activeItems, choice.value); if (canAddItem.response) { @@ -3866,7 +3878,7 @@ function () { } } - this.clearInput(); // We wont to close the dropdown if we are dealing with a single select box + this.clearInput(); // We want to close the dropdown if we are dealing with a single select box if (hasActiveDropdown && this._isSelectOneElement) { this.hideDropdown(true); diff --git a/public/assets/scripts/choices.min.js b/public/assets/scripts/choices.min.js index 61b498b..ea9092b 100644 --- a/public/assets/scripts/choices.min.js +++ b/public/assets/scripts/choices.min.js @@ -1,10 +1,5 @@ /*! choices.js v7.1.5 | © 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=5)}([function(e,t,i){var n; -/*! - Copyright (c) 2017 Jed Watson. - Licensed under the MIT License (MIT), see - http://jedwatson.github.io/classnames -*/!function(){"use strict";var i={}.hasOwnProperty;function s(){for(var e=[],t=0;t1&&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,o=this._search(n,s),r=o.weights,a=o.results;return this._computeScore(r,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 o=0,r=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(h,p),record:h,index:l},{resultMap:n,results:s,tokenSearchers:e,fullSearcher:t})}return{weights:a,results:s}}},{key:"_analyze",value:function(e,t){var i=e.key,n=e.arrayIndex,s=void 0===n?-1:n,o=e.value,r=e.record,l=e.index,c=t.tokenSearchers,h=void 0===c?[]:c,u=t.fullSearcher,d=void 0===u?[]:u,p=t.resultMap,f=void 0===p?{}:p,m=t.results,v=void 0===m?[]:m;if(null!=o){var g=!1,_=-1,b=0;if("string"==typeof o){this._log("\nKey: ".concat(""===i?"-":i));var y=d.search(o);if(this._log('Full text: "'.concat(o,'", score: ').concat(y.score)),this.options.tokenize){for(var E=o.split(this.options.tokenSeparator),S=[],I=0;I-1&&(D=(D+_)/2),this._log("Score average:",D);var P=!this.options.tokenize||!this.options.matchAllTokens||b>=h.length;if(this._log("\nCheck Matches: ".concat(P)),(g||y.isMatch)&&P){var F=f[l];F?F.output.push({key:i,arrayIndex:s,value:o,score:D,matchedIndices:y.matchedIndices}):(f[l]={item:r,output:[{key:i,arrayIndex:s,value:o,score:D,matchedIndices:y.matchedIndices}]},v.push(f[l]))}}else if(a(o))for(var M=0,N=o.length;M-1&&(r.arrayIndex=o.arrayIndex),t.matches.push(r)}}})),this.options.includeScore&&s.push((function(e,t){t.score=e.score}));for(var o=0,r=e.length;oi)return s(e,this.pattern,n);var r=this.options,a=r.location,l=r.distance,c=r.threshold,h=r.findAllMatches,u=r.minMatchCharLength;return o(e,this.pattern,this.patternAlphabet,{location:a,distance:l,threshold:c,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,"|")),o=e.match(s),r=!!o,a=[];if(r)for(var l=0,c=o.length;l=D;M-=1){var N=M-1,j=i[e.charAt(N)];if(j&&(E[N]=1),F[M]=(F[M+1]<<1|1)&j,0!==T&&(F[M]|=(O[M+1]|O[M])<<1|1|O[M+1]),F[M]&x&&(C=n(t,{errors:T,currentLocation:N,expectedLocation:v,distance:c}))<=_){if(_=C,(b=N)<=v)break;D=Math.max(1,2*v-b)}}if(n(t,{errors:T+1,currentLocation:v,expectedLocation:v,distance:c})>_)break;O=F}return{isMatch:b>=0,score:0===C?.001:C,matchedIndices:s(E,m)}}},function(e,t){e.exports=function(e,t){var i=t.errors,n=void 0===i?0:i,s=t.currentLocation,o=void 0===s?0:s,r=t.expectedLocation,a=void 0===r?0:r,l=t.distance,c=void 0===l?100:l,h=n/e.length,u=Math.abs(a-o);return c?h+u/c: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,o=0,r=e.length;o=t&&i.push([n,s]),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/g,"&rt;").replace(/-1?e(t[i.substring(0,n)],i.substr(n+1)):t[i]},T=function(e){return JSON.parse(JSON.stringify(e))},L=function(e,t){var i=Object.keys(e).sort(),n=Object.keys(t).sort();return i.filter((function(e){return n.indexOf(e)<0}))},k=function(e){for(var t=Object.keys(e),i={},n=0;n-1?e.map((function(e){var i=e;return i.id===parseInt(t.choiceId,10)&&(i.selected=!0),i})):e;case"REMOVE_ITEM":return t.choiceId>-1?e.map((function(e){var i=e;return i.id===parseInt(t.choiceId,10)&&(i.selected=!1),i})):e;case"FILTER_CHOICES":return e.map((function(e){var i=e;return i.active=t.results.some((function(e){var t=e.item,n=e.score;return t.id===i.id&&(i.score=n,!0)})),i}));case"ACTIVATE_CHOICES":return e.map((function(e){var i=e;return i.active=t.active,i}));case"CLEAR_CHOICES":return m;default:return e}},general:_}),D=function(e,t){var i=e;if("CLEAR_ALL"===t.type)i=void 0;else if("RESET_TO"===t.type)return T(t.state);return k(i,t)};function P(e,t){for(var i=0;i=t:"top"===this.position&&(s=!0),s},t.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},t.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},t.open=function(e){this.element.classList.add(this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e)&&(this.element.classList.add(this.classNames.flippedState),this.isFlipped=!0)},t.close=function(){this.element.classList.remove(this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(this.element.classList.remove(this.classNames.flippedState),this.isFlipped=!1)},t.focus=function(){this.isFocussed||this.element.focus()},t.addFocusState=function(){this.element.classList.add(this.classNames.focusState)},t.removeFocusState=function(){this.element.classList.remove(this.classNames.focusState)},t.enable=function(){this.element.classList.remove(this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),"select-one"===this.type&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},t.disable=function(){this.element.classList.add(this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),"select-one"===this.type&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},t.wrap=function(e){!function(e,t){void 0===t&&(t=document.createElement("div")),e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t),t.appendChild(e)}(e,this.element)},t.unwrap=function(e){this.element.parentNode.insertBefore(e,this.element),this.element.parentNode.removeChild(this.element)},t.addLoadingState=function(){this.element.classList.add(this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},t.removeLoadingState=function(){this.element.classList.remove(this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},t._onFocus=function(){this.isFocussed=!0},t._onBlur=function(){this.isFocussed=!1},e}();function j(e,t){for(var i=0;i=this._placeholderValue.length/1.25;(this.element.value&&n||e)&&this.calcWidth(i)}else this.calcWidth(i)},s.calcWidth=function(e){return function(e,t){var i=e.value||e.placeholder,n=e.offsetWidth;if(i){var s=C(""+O(i)+"");if(s.style.position="absolute",s.style.padding="0",s.style.top="-9999px",s.style.left="-9999px",s.style.width="auto",s.style.whiteSpace="pre",document.body.contains(e)&&window.getComputedStyle){var o=window.getComputedStyle(e);o&&(s.style.fontSize=o.fontSize,s.style.fontFamily=o.fontFamily,s.style.fontWeight=o.fontWeight,s.style.fontStyle=o.fontStyle,s.style.letterSpacing=o.letterSpacing,s.style.textTransform=o.textTransform,s.style.paddingLeft=o.paddingLeft,s.style.paddingRight=o.paddingRight)}document.body.appendChild(s),requestAnimationFrame((function(){i&&s.offsetWidth!==e.offsetWidth&&(n=s.offsetWidth+4),document.body.removeChild(s),t.call(void 0,n+"px")}))}else t.call(void 0,n+"px")}(this.element,e)},s.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},s.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},s._onInput=function(){"select-one"!==this.type&&this.setWidth()},s._onPaste=function(e){e.target===this.element&&this.preventPaste&&e.preventDefault()},s._onFocus=function(){this.isFocussed=!0},s._onBlur=function(){this.isFocussed=!1},t=e,(i=[{key:"placeholder",set:function(e){this.element.placeholder=e}},{key:"value",set:function(e){this.element.value=e},get:function(){return O(this.element.value)}}])&&j(t.prototype,i),n&&j(t,n),e}(),R={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,addItems:!0,addItemFilterFn:null,removeItems:!0,removeItemButton:!1,editItems:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sortFn:function(e,t){var i=(""+(e.label||e.value)).toLowerCase(),n=(""+(t.label||t.value)).toLowerCase();return in?1:0},placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'+O(e)+'"'},maxItemText:function(e){return"Only "+e+" values can be added"},itemComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:"choices",containerInner:"choices__inner",input:"choices__input",inputCloned:"choices__input--cloned",list:"choices__list",listItems:"choices__list--multiple",listSingle:"choices__list--single",listDropdown:"choices__list--dropdown",item:"choices__item",itemSelectable:"choices__item--selectable",itemDisabled:"choices__item--disabled",itemChoice:"choices__item--choice",placeholder:"choices__placeholder",group:"choices__group",groupHeading:"choices__heading",button:"choices__button",activeState:"is-active",focusState:"is-focused",openState:"is-open",disabledState:"is-disabled",highlightedState:"is-highlighted",hiddenState:"is-hidden",flippedState:"is-flipped",loadingState:"is-loading",noResults:"has-no-results",noChoices:"has-no-choices"}},B="showDropdown",V="hideDropdown",H="change",G="choice",q="search",W="addItem",U="removeItem",z="highlightItem",X="highlightChoice",Y="ADD_CHOICE",$="FILTER_CHOICES",J="ACTIVATE_CHOICES",Z="CLEAR_CHOICES",Q="ADD_GROUP",ee="ADD_ITEM",te="REMOVE_ITEM",ie="HIGHLIGHT_ITEM",ne=46,se=8,oe=13,re=65,ae=27,le=38,ce=40,he=33,ue=34,de=function(){function e(e){var t=e.element;Object.assign(this,{element:t}),this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight,this.hasChildren=!!this.element.children}var t=e.prototype;return t.clear=function(){this.element.innerHTML=""},t.append=function(e){this.element.appendChild(e)},t.getChild=function(e){return this.element.querySelector(e)},t.scrollToTop=function(){this.element.scrollTop=0},t.scrollToChoice=function(e,t){var i=this;if(e){var n=this.element.offsetHeight,s=e.offsetHeight,o=e.offsetTop+s,r=this.element.scrollTop+n,a=t>0?this.element.scrollTop+o-r:e.offsetTop;requestAnimationFrame((function(e){i._animateScroll(e,a,t)}))}},t._scrollDown=function(e,t,i){var n=(i-e)/t,s=n>1?n:1;this.element.scrollTop=e+s},t._scrollUp=function(e,t,i){var n=(e-i)/t,s=n>1?n:1;this.element.scrollTop=e-s},t._animateScroll=function(e,t,i){var n=this,s=this.element.scrollTop,o=!1;i>0?(this._scrollDown(s,4,t),st&&(o=!0)),o&&requestAnimationFrame((function(){n._animateScroll(e,t,i)}))},e}();function pe(e,t){for(var i=0;i