Choices/assets/scripts/dist/choices.min.js

2 lines
45 KiB
JavaScript
Raw Normal View History

!function(t){function e(n){if(i[n])return i[n].exports;var s=i[n]={exports:{},id:n,loaded:!1};return t[n].call(s.exports,s,s.exports,e),s.loaded=!0,s.exports}var i={};return e.m=t,e.c=i,e.p="/assets/scripts/dist/",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t){if(Array.isArray(t)){for(var e=0,i=Array(t.length);e<t.length;e++)i[e]=t[e];return i}return Array.from(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Choices=void 0;var r=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=i(2),l=i(3),c=i(4),u=n(c),d=i(5),h=n(d),p=e.Choices=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?"[data-choice]":arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(o(this,t),(0,l.isType)("String",e)){var n=document.querySelectorAll(e);if(n.length>1)for(var s=1;s<n.length;s++){var r=n[s];new t(r,i)}}var a={items:[],addItems:!0,removeItems:!0,removeButton:!1,editItems:!1,maxItems:!1,delimiter:",",allowDuplicates:!0,allowPaste:!0,allowSearch:!0,_regexFilter:!1,placeholder:!0,placeholderValue:"",prependValue:!1,appendValue:!1,selectAll:!0,loadingText:"Loading...",templates:{},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",itemOption:"choices__item--option",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",selectedState:"is-selected"},callbackOnInit:function(){},callbackOnRemoveItem:function(){},callbackOnAddItem:function(){}};this.options=(0,l.extend)(a,i),this.store=new h.default(this._render),this.initialised=!1,this.currentState={},this.prevState={},this.currentValue="",this.passedElement=(0,l.isType)("String",e)?document.querySelector(e):e,this.highlightPosition=0,this.canSearch=this.options.allowSearch,this.presetItems=this.options.items,""!==this.passedElement.value&&(this.presetItems=this.presetItems.concat(this.passedElement.value.split(this.options.delimiter))),this.init=this.init.bind(this),this._render=this._render.bind(this),this.destroy=this.destroy.bind(this),this.disable=this.disable.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this);var c="querySelector"in document&&"addEventListener"in document&&"classList"in document.createElement("div");c||console.error("Choices: Your browser doesn't support Choices");var u=this.passedElement&&["select-one","select-multiple","text"].includes(this.passedElement.type);u?this.init():console.error("Choices: Incompatible input passed")}return r(t,[{key:"init",value:function(t){this.initialised!==!0&&(this.initialised=!0,this._createTemplates(),this._createInput(),this.store.subscribe(this._render),this._render(),this._addEventListeners(),(t=this.options.callbackOnInit)&&((0,l.isType)("Function",t)?t():console.error("callbackOnInit: Callback is not a function")))}},{key:"destroy",value:function(){this.passedElement.classList.remove(this.options.classNames.input,this.options.classNames.hiddenState),this.passedElement.tabIndex="",this.passedElement.removeAttribute("style","disp
for(m=this.tokenSearchers[_],g=[],E=0;E<r.length;E++)y=r[E],b=m.search(y),b.isMatch?(I=!0,g.push(b.score),l.push(b.score)):(g.push(1),l.push(1));w.verbose&&i("Token scores:",g)}for(h=l[0],f=l.length,_=1;f>_;_++)h+=l[_];h/=f,w.verbose&&i("Token score average:",h)}v=this.fullSeacher.search(e),w.verbose&&i("Full text score:",v.score),p=v.score,void 0!==h&&(p=(p+h)/2),w.verbose&&i("Score average:",p),(I||v.isMatch)&&(d=this.resultMap[s],d?d.output.push({key:t,score:p,matchedIndices:v.matchedIndices}):(this.resultMap[s]={item:n,output:[{key:t,score:p,matchedIndices:v.matchedIndices}]},this.results.push(this.resultMap[s])))}else if(o(e))for(_=0;_<e.length;_++)this._analyze(t,e[_],n,s)},n.prototype._computeScore=function(){var t,e,n,s,o,r,a,l,c,u=this._keyMap,d=this.results;for(this.options.verbose&&i("\n\nComputing score:\n"),t=0;t<d.length;t++){for(n=0,s=d[t].output,o=s.length,l=1,e=0;o>e;e++)r=s[e].score,a=u?u[s[e].key].weight:1,c=r*a,1!==a?l=Math.min(l,c):(n+=c,s[e].nScore=c);1===l?d[t].score=n/o:d[t].score=l,this.options.verbose&&i(d[t])}},n.prototype._sort=function(){var t=this.options;t.shouldSort&&(t.verbose&&i("\n\nSorting...."),this.results.sort(t.sortFn))},n.prototype._format=function(){var t,e,n,s,o,r=this.options,a=r.getFn,l=[],c=this.results,u=r.include;for(r.verbose&&i("\n\nOutput:\n\n",c),s=r.id?function(t){c[t].item=a(c[t].item,r.id,[])[0]}:function(){},o=function(t){var e,i,n,s,o,r=c[t];if(u.length>0){if(e={item:r.item},-1!==u.indexOf("matches"))for(n=r.output,e.matches=[],i=0;i<n.length;i++)s=n[i],o={indices:s.matchedIndices},s.key&&(o.key=s.key),e.matches.push(o);-1!==u.indexOf("score")&&(e.score=c[t].score)}else e=r.item;return e},e=0,n=c.length;n>e;e++)s(e),t=o(e),l.push(t);return l},r.defaultOptions={location:0,distance:100,threshold:.6,maxPatternLength:32},r.prototype._calculatePatternAlphabet=function(){var t={},e=0;for(e=0;e<this.patternLen;e++)t[this.pattern.charAt(e)]=0;for(e=0;e<this.patternLen;e++)t[this.pattern.charAt(e)]|=1<<this.pattern.length-e-1;return t},r.prototype._bitapScore=function(t,e){var i=t/this.patternLen,n=Math.abs(this.options.location-e);return this.options.distance?i+n/this.options.distance:n?1:i},r.prototype.search=function(t){var e,i,n,s,o,r,l,c,u,d,h,p,f,v,m,g,y,b,_,E,w,I,S=this.options;if(t=S.caseSensitive?t:t.toLowerCase(),this.pattern===t)return{isMatch:!0,score:0,matchedIndices:[[0,t.length-1]]};if(this.patternLen>S.maxPatternLength){if(y=t.match(new RegExp(this.pattern.replace(a,"|"))),b=!!y)for(E=[],e=0,w=y.length;w>e;e++)I=y[e],E.push([t.indexOf(I),I.length-1]);return{isMatch:b,score:b?.5:1,matchedIndices:E}}for(s=S.location,n=t.length,o=S.threshold,r=t.indexOf(this.pattern,s),_=[],e=0;n>e;e++)_[e]=0;for(-1!=r&&(o=Math.min(this._bitapScore(0,r),o),r=t.lastIndexOf(this.pattern,s+this.patternLen),-1!=r&&(o=Math.min(this._bitapScore(0,r),o))),r=-1,m=1,g=[],u=this.patternLen+n,e=0;e<this.patternLen;e++){for(l=0,c=u;c>l;)this._bitapScore(e,s+c)<=o?l=c:u=c,c=Math.floor((u-l)/2+l);for(u=c,d=Math.max(1,s-c+1),h=Math.min(s+c,n)+this.patternLen,p=Array(h+2),p[h+1]=(1<<e)-1,i=h;i>=d;i--)if(v=this.patternAlphabet[t.charAt(i-1)],v&&(_[i-1]=1),0===e?p[i]=(p[i+1]<<1|1)&v:p[i]=(p[i+1]<<1|1)&v|((f[i+1]|f[i])<<1|1)|f[i+1],p[i]&this.matchmask&&(m=this._bitapScore(e,i-1),o>=m)){if(o=m,r=i-1,g.push(r),!(r>s))break;d=Math.max(1,2*s-r)}if(this._bitapScore(e+1,s)>o)break;f=p}return E=this._getMatchedIndices(_),{isMatch:r>=0,score:0===m?.001:m,matchedIndices:E}},r.prototype._getMatchedIndices=function(t){for(var e,i=[],n=-1,s=-1,o=0,r=r=t.length;r>o;o++)e=t[o],e&&-1===n?n=o:e||-1===n||(s=o-1,i.push([n,s]),n=-1);return t[o-1]&&i.push([n,o-1]),i},t.exports=n}(this)},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0}),e.Store=void 0;var o=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return functi