Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slim-select

Package Overview
Dependencies
Maintainers
1
Versions
111
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slim-select - npm Package Compare versions

Comparing version 1.6.1 to 1.6.2

src/docs/assets/images/check-mark.svg

29

dist/slimselect.js

@@ -172,2 +172,13 @@ (function webpackUniversalModuleDefinition(root, factory) {

exports.isValueInArrayOfObjects = isValueInArrayOfObjects;
function highlight(text, search, className) {
text = text.trim();
var textLower = text.trim().toLowerCase();
search = search.trim().toLowerCase();
var index = textLower.indexOf(search);
if (index >= 0) {
text = text.substring(0, index) + ("<span class=\"" + className + "\">") + text.substring(index, index + search.length) + '</span>' + text.substring(index + search.length);
}
return text;
}
exports.highlight = highlight;

@@ -209,2 +220,3 @@

searchText: info.searchText,
searchHighlight: info.searchHighlight,
closeOnSelect: info.closeOnSelect,

@@ -537,2 +549,3 @@ showContent: info.showContent,

this.showSearch = true;
this.searchHighlight = false;
this.closeOnSelect = true;

@@ -559,2 +572,3 @@ this.showContent = 'auto'; // options: auto, up, down

this.search = 'ss-search';
this.searchHighlighter = 'ss-search-highlight';
this.addable = 'ss-addable';

@@ -573,2 +587,3 @@ this.list = 'ss-list';

this.showSearch = (info.showSearch === false ? false : true);
this.searchHighlight = (info.searchHighlight === true ? true : false);
this.closeOnSelect = (info.closeOnSelect === false ? false : true);

@@ -1320,3 +1335,8 @@ if (info.showContent) {

else {
_this.main.search(target.value);
if (_this.main.config.showSearch) {
_this.main.search(target.value);
}
else {
input.value = '';
}
}

@@ -1523,3 +1543,8 @@ e.preventDefault();

option.dataset.id = data.id;
option.innerHTML = data.innerHTML;
if (this.main.config.searchHighlight && this.main.slim && this.main.slim.search.input.value.trim() !== '') {
option.innerHTML = helper_1.highlight(data.innerHTML, this.main.slim.search.input.value, this.main.config.searchHighlighter);
}
else {
option.innerHTML = data.innerHTML;
}
var master = this;

@@ -1526,0 +1551,0 @@ option.onclick = function (e) {

2

dist/slimselect.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SlimSelect=t():e.SlimSelect=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var i={};return t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/",t(t.s=1)}([function(e,t,i){"use strict";function n(e,t,i){function n(e,t){return i&&console.log(e),t&&e&&e.classList&&e.classList.contains(t)?e:null}function s(e,t){return e&&e!==document?n(e,t)?e:s(e.parentNode,t):null}return void 0===i&&(i=!1),i&&console.log(t),n(e,t)||s(e,t)}function s(e,t){var i=e.scrollTop+e.offsetTop,n=i+e.clientHeight,s=t.offsetTop,a=s+t.clientHeight;s<i?e.scrollTop-=i-s:a>n&&(e.scrollTop+=a-n)}function a(e,t,i){var n=e.offsetHeight,s=e.getBoundingClientRect(),a=i?s.top:s.top-n,o=i?s.bottom:s.bottom+n;return a<=0?"below":o>=window.innerHeight?"above":i?t:"below"}function o(e,t,i){void 0===t&&(t=100),void 0===i&&(i=!1);var n;return function(){var s=this,a=arguments,o=function(){n=null,i||e.apply(s,a)},l=i&&!n;clearTimeout(n),n=setTimeout(o,t),l&&e.apply(s,a)}}function l(e,t,i){if(!Array.isArray(e))return e[t]===i;for(var n=0;n<e.length;n++)if(e[n]&&e[n][t]&&e[n][t]===i)return!0;return!1}t.__esModule=!0,t.hasClassInTree=n,t.ensureElementInView=s,t.putContent=a,t.debounce=o,t.isValueInArrayOfObjects=l},function(e,t,i){"use strict";t.__esModule=!0,i(2),i(3);var n=i(4),s=i(0),a=i(5),o=i(6),l=i(7),r=function(){function e(e){var t=this;this.addable=null,this.beforeOnChange=null,this.onChange=null,this.validate(e);var i="string"==typeof e.select?document.querySelector(e.select):e.select;i.dataset.ssid&&this.destroy(i.dataset.ssid),e.addable&&(this.addable=e.addable),this.config=new n.default({select:i,showSearch:e.showSearch,searchText:e.searchText,closeOnSelect:e.closeOnSelect,showContent:e.showContent,placeholderText:e.placeholder,isEnabled:e.isEnabled}),this.select=new a.default({select:i,main:this}),this.data=new o.default({main:this}),this.slim=new l.default({main:this}),this.select.element.parentNode.insertBefore(this.slim.container,this.select.element.nextSibling),e.data?this.setData(e.data):this.render(),document.addEventListener("click",function(e){s.hasClassInTree(e.target,t.config.id)||t.close()}),window.addEventListener("scroll",s.debounce(function(e){t.data.contentOpen&&"auto"===t.config.showContent&&("above"===s.putContent(t.slim.content,t.data.contentPosition,t.data.contentOpen)?t.moveContentAbove():t.moveContentBelow())}),!1),e.beforeOnChange&&(this.beforeOnChange=e.beforeOnChange),e.onChange&&(this.onChange=e.onChange)}return e.prototype.validate=function(e){var t="string"==typeof e.select?document.querySelector(e.select):e.select;if(!t)throw new Error("Could not find select element");if("SELECT"!==t.tagName)throw new Error("Element isnt of type select")},e.prototype.set=function(e,t,i,n){void 0===t&&(t="value"),void 0===i&&(i=!0),void 0===n&&(n=!0),this.config.isMultiple&&!Array.isArray(e)?this.data.addToSelected(e,t):this.data.setSelected(e,t),this.select.setValue(),this.data.onDataChange(),this.render(),i&&this.close()},e.prototype.setData=function(e){if(!o.validateData(e))return void console.error("Validation problem on: #"+this.select.element.id);var t=JSON.parse(JSON.stringify(e));this.select.create(t),this.data.parseSelectData(),this.data.setSelectedFromSelect(),this.render()},e.prototype.addData=function(e){if(!o.validateData([e]))return void console.error("Validation problem on: #"+this.select.element.id);var t=this.data.newOption(e);this.data.add(t),this.select.create(this.data.data),this.data.parseSelectData(),this.data.setSelectedFromSelect(),this.render()},e.prototype.open=function(){this.config.isEnabled&&(this.slim.search.input.focus(),this.data.contentOpen||(this.config.isMultiple?this.slim.multiSelected.plus.classList.add("ss-cross"):(this.slim.singleSelected.arrowIcon.arrow.classList.remove("arrow-down"),this.slim.singleSelected.arrowIcon.arrow.classList.add("arrow-up")),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add("above"===this.data.contentPosition?this.config.openAbove:this.config.openBelow),this.slim.content.classList.add(this.config.open),"up"===this.config.showContent.toLowerCase()?this.moveContentAbove():"down"===this.config.showContent.toLowerCase()?this.moveContentBelow():"above"===s.putContent(this.slim.content,this.data.contentPosition,this.data.contentOpen)?this.moveContentAbove():this.moveContentBelow(),this.data.contentOpen=!0))},e.prototype.close=function(){var e=this;this.data.contentOpen&&(this.config.isMultiple?(this.slim.multiSelected.container.classList.remove(this.config.openAbove),this.slim.multiSelected.container.classList.remove(this.config.openBelow),this.slim.multiSelected.plus.classList.remove("ss-cross")):(this.slim.singleSelected.container.classList.remove(this.config.openAbove),this.slim.singleSelected.container.classList.remove(this.config.openBelow),this.slim.singleSelected.arrowIcon.arrow.classList.add("arrow-down"),this.slim.singleSelected.arrowIcon.arrow.classList.remove("arrow-up")),this.slim.content.classList.remove(this.config.open),this.data.contentOpen=!1,this.search(""),setTimeout(function(){e.slim.content.removeAttribute("style"),e.data.contentPosition="below",e.slim[e.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(e.config.openAbove),e.slim[e.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(e.config.openBelow)},300))},e.prototype.moveContentAbove=function(){var e=this.config.isMultiple?this.slim.multiSelected.container.offsetHeight:this.slim.singleSelected.container.offsetHeight,t=this.slim.content.offsetHeight,i=e+t-1;this.slim.content.style.margin="-"+i+"px 0 0 0",this.slim.content.style["transform-origin"]="center bottom",this.data.contentPosition="above",this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(this.config.openBelow),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add(this.config.openAbove)},e.prototype.moveContentBelow=function(){this.slim.content.removeAttribute("style"),this.data.contentPosition="below",this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(this.config.openAbove),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add(this.config.openBelow)},e.prototype.enable=function(){this.config.isEnabled=!0,this.config.isMultiple?this.slim.multiSelected.container.classList.remove(this.config.disabled):this.slim.singleSelected.container.classList.remove(this.config.disabled),this.select.disconnectMutationObserver(),this.select.element.disabled=!1,this.slim.search.input.disabled=!1,this.select.observeMutationObserver()},e.prototype.disable=function(){this.config.isEnabled=!1,this.config.isMultiple?this.slim.multiSelected.container.classList.add(this.config.disabled):this.slim.singleSelected.container.classList.add(this.config.disabled),this.select.disconnectMutationObserver(),this.select.element.disabled=!0,this.slim.search.input.disabled=!0,this.select.observeMutationObserver()},e.prototype.search=function(e){this.data.searchValue!==e&&(this.slim.search.input.value=e,this.data.search(e),this.render())},e.prototype.render=function(){this.config.isMultiple?this.slim.values():this.slim.placeholder(),this.slim.options()},e.prototype.destroy=function(e){void 0===e&&(e=null);var t=e?document.querySelector("."+e):this.slim.container,i=e?document.querySelector("[data-ssid="+e+"]"):this.select.element;t&&i&&(i.style.display=null,delete i.dataset.ssid,t.parentElement&&t.parentElement.removeChild(t))},e}();t.default=r,e.exports=r},function(e,t){},function(e,t){try{var i=new window.CustomEvent("test");if(i.preventDefault(),!0!==i.defaultPrevented)throw new Error("Could not prevent default")}catch(e){var n=function(e,t){var i,n;return t=t||{bubbles:!1,cancelable:!1,detail:void 0},i=document.createEvent("CustomEvent"),i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n=i.preventDefault,i.preventDefault=function(){n.call(this);try{Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})}catch(e){this.defaultPrevented=!0}},i};n.prototype=window.Event.prototype,window.CustomEvent=n}},function(e,t,i){"use strict";t.__esModule=!0;var n=function(){function e(e){this.id="",this.isMultiple=!1,this.showSearch=!0,this.closeOnSelect=!0,this.showContent="auto",this.searchText="No Results",this.placeholderText="Select Value",this.isEnabled=!0,this.main="ss-main",this.singleSelected="ss-single-selected",this.arrow="ss-arrow",this.multiSelected="ss-multi-selected",this.add="ss-add",this.plus="ss-plus",this.values="ss-values",this.value="ss-value",this.valueText="ss-value-text",this.valueDelete="ss-value-delete",this.content="ss-content",this.open="ss-open",this.openAbove="ss-open-above",this.openBelow="ss-open-below",this.search="ss-search",this.addable="ss-addable",this.list="ss-list",this.optgroup="ss-optgroup",this.optgroupLabel="ss-optgroup-label",this.option="ss-option",this.highlighted="ss-highlighted",this.disabled="ss-disabled",this.hide="ss-hide",this.id="ss-"+Math.floor(1e5*Math.random()),this.style=e.select.style.cssText,this.class=e.select.classList,this.isMultiple=e.select.multiple,this.showSearch=!1!==e.showSearch,this.closeOnSelect=!1!==e.closeOnSelect,e.showContent&&(this.showContent=e.showContent),this.isEnabled=!1!==e.isEnabled,e.searchText&&(this.searchText=e.searchText),e.placeholderText&&(this.placeholderText=e.placeholderText)}return e}();t.default=n},function(e,t,i){"use strict";t.__esModule=!0;var n=function(){function e(e){this.element=e.select,this.main=e.main,this.element.disabled&&(this.main.config.isEnabled=!1),this.addAttributes(),this.addEventListeners(),this.addMutationObserver()}return e.prototype.setValue=function(){if(this.main.data.getSelected()){if(this.main.config.isMultiple)for(var e=this.main.data.getSelected(),t=this.element.options,i=0;i<t.length;i++){var n=t[i];n.selected=!1;for(var s=0;s<e.length;s++)e[s].value===n.value&&(n.selected=!0)}else{var e=this.main.data.getSelected();this.element.value=e?e.value:""}this.main.data.isOnChangeEnabled=!1,this.element.dispatchEvent(new CustomEvent("change")),this.main.data.isOnChangeEnabled=!0}},e.prototype.addAttributes=function(){this.element.tabIndex=-1,this.element.style.display="none",this.element.dataset.ssid=this.main.config.id},e.prototype.addEventListeners=function(){var e=this;this.element.addEventListener("change",function(t){e.main.data.setSelectedFromSelect(),e.main.render()})},e.prototype.addMutationObserver=function(){var e=this;this.mutationObserver=new MutationObserver(function(t){e.main.data.parseSelectData(),e.main.data.setSelectedFromSelect(),e.main.render()}),this.observeMutationObserver()},e.prototype.observeMutationObserver=function(){this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,characterData:!0})},e.prototype.disconnectMutationObserver=function(){this.mutationObserver.disconnect()},e.prototype.create=function(e){this.element.innerHTML="";for(var t=0;t<e.length;t++)if(e[t].hasOwnProperty("options")){var i=e[t],n=document.createElement("optgroup");n.label=i.label;for(var s=0;s<i.options.length;s++)n.appendChild(this.createOption(i.options[s]));this.element.appendChild(n)}else this.element.appendChild(this.createOption(e[t]))},e.prototype.createOption=function(e){var t=document.createElement("option");return t.value=e.value||e.text,t.innerHTML=e.innerHTML||e.text,e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),e.placeholder&&t.setAttribute("data-placeholder","true"),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach(function(i){t.setAttribute("data-"+i,e.data[i])}),t},e}();t.default=n},function(e,t,i){"use strict";function n(e){if(!e)return void console.error("Data must be an array of objects");for(var t=!1,i=0,n=0;n<e.length;n++)if(e[n].hasOwnProperty("label")){if(e[n].hasOwnProperty("options"))for(var a=e[n],o=a.options,l=0;l<o.length;l++)(t=s(o[l]))||i++}else{var r=e[n];t=s(r),t||i++}return 0===i}function s(e){return void 0!==e.text||(console.error("Data object option must have at least have a text value. Check object: "+JSON.stringify(e)),!1)}t.__esModule=!0;var a=function(){function e(e){this.contentOpen=!1,this.contentPosition="below",this.isOnChangeEnabled=!0,this.main=e.main,this.searchValue="",this.data=[],this.filtered=null,this.parseSelectData(),this.setSelectedFromSelect()}return e.prototype.newOption=function(e){return{id:e.id?e.id:String(Math.floor(1e8*Math.random())),value:e.value?e.value:"",text:e.text?e.text:"",innerHTML:e.innerHTML?e.innerHTML:"",selected:!!e.selected&&e.selected,disabled:!!e.disabled&&e.disabled,placeholder:e.placeholder?e.placeholder:"",data:e.data?e.data:{}}},e.prototype.add=function(e){var t={id:String(Math.floor(1e8*Math.random())),value:e.value,text:e.text,innerHTML:"",selected:!1,disabled:!1,placeholder:"",data:{}};this.data.push(t)},e.prototype.parseSelectData=function(){this.data=[];for(var e=this.main.select.element,t=e.childNodes,i=0;i<t.length;i++)if("OPTGROUP"===t[i].nodeName){for(var n=t[i],s={label:n.label,options:[]},a=t[i].childNodes,o=0;o<a.length;o++)"OPTION"===a[o].nodeName&&s.options.push(this.pullOptionData(a[o]));this.data.push(s)}else"OPTION"===t[i].nodeName&&this.data.push(this.pullOptionData(t[i]))},e.prototype.pullOptionData=function(e){return{id:!!e.dataset&&e.dataset.id||String(Math.floor(1e8*Math.random())),value:e.value,text:e.text,innerHTML:e.innerHTML,selected:e.selected,disabled:e.disabled,placeholder:e.dataset.placeholder||null,data:e.dataset}},e.prototype.setSelectedFromSelect=function(){var e=this.main.select.element.options;if(this.main.config.isMultiple){for(var t=[],i=0;i<e.length;i++){var n=e[i];n.selected&&t.push(this.getObjectFromData(n.value,"value").id)}this.setSelected(t,"id")}else if(-1!==e.selectedIndex){var n=e[e.selectedIndex],s=n.value;this.setSelected(s,"value")}},e.prototype.setSelected=function(e,t){void 0===t&&(t="id");for(var i=0;i<this.data.length;i++)if(this.data[i].hasOwnProperty("label")){if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i].options,s=0;s<n.length;s++)n[s].selected=this.shouldBeSelected(n[s],e,t)}else this.data[i].selected=this.shouldBeSelected(this.data[i],e,t)},e.prototype.shouldBeSelected=function(e,t,i){if(void 0===i&&(i="id"),Array.isArray(t)){for(var n=0;n<t.length;n++)if(String(e[i])===String(t[n]))return!0}else if(String(e[i])===String(t))return!0;return!1},e.prototype.getSelected=function(){for(var e=null,t=[],i=0;i<this.data.length;i++)if(this.data[i].hasOwnProperty("label")){if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i].options,s=0;s<n.length;s++)n[s].selected&&(this.main.config.isMultiple?t.push(n[s]):e=n[s])}else this.data[i].selected&&(this.main.config.isMultiple?t.push(this.data[i]):e=this.data[i]);return this.main.config.isMultiple?t:e},e.prototype.addToSelected=function(e,t){if(void 0===t&&(t="id"),this.main.config.isMultiple){for(var i=[],n=this.getSelected(),s=0;s<n.length;s++)i.push(n[s][t]);i.push(e),this.setSelected(i,t)}},e.prototype.removeFromSelected=function(e,t){if(void 0===t&&(t="id"),this.main.config.isMultiple){for(var i=[],n=this.getSelected(),s=0;s<n.length;s++)String(n[s][t])!==String(e)&&i.push(n[s][t]);this.setSelected(i,t)}},e.prototype.onDataChange=function(){this.main.onChange&&this.isOnChangeEnabled&&this.main.onChange(JSON.parse(JSON.stringify(this.getSelected())))},e.prototype.getObjectFromData=function(e,t){void 0===t&&(t="id");for(var i=0;i<this.data.length;i++){if(t in this.data[i]&&String(this.data[i][t])===String(e))return this.data[i];if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i],s=0;s<n.options.length;s++)if(String(n.options[s][t])===String(e))return n.options[s]}return null},e.prototype.search=function(e){if(this.searchValue=e,""===e.trim())return void(this.filtered=null);var t=this.data.slice(0);e=e.trim().toLowerCase();var i=t.map(function(t){if(t.hasOwnProperty("options")){var i=t,n=i.options.filter(function(t){return-1!==t.text.toLowerCase().indexOf(e)});if(0!==n.length){var s=Object.assign({},i);return s.options=n,s}}if(t.hasOwnProperty("text")){if(-1!==t.text.toLowerCase().indexOf(e))return t}return null});this.filtered=i.filter(function(e){return e})},e}();t.default=a,t.validateData=n,t.validateOption=s},function(e,t,i){"use strict";t.__esModule=!0;var n=i(0),s=function(){function e(e){this.main=e.main,this.container=this.containerDiv(),this.content=this.contentDiv(),this.search=this.searchDiv(),this.list=this.listDiv(),this.options(),this.main.config.isMultiple?(this.multiSelected=this.multiSelectedDiv(),this.container.appendChild(this.multiSelected.container)):(this.singleSelected=this.singleSelectedDiv(),this.container.appendChild(this.singleSelected.container)),this.container.appendChild(this.content),this.content.appendChild(this.search.container),this.content.appendChild(this.list)}return e.prototype.containerDiv=function(){var e=document.createElement("div");e.classList.add(this.main.config.id),e.classList.add(this.main.config.main),e.style.cssText=this.main.config.style;for(var t=0;t<this.main.config.class.length;t++)e.classList.add(this.main.config.class[t]);return e},e.prototype.singleSelectedDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.singleSelected);var i=document.createElement("span");i.classList.add("placeholder"),t.appendChild(i);var n=document.createElement("span");n.classList.add(this.main.config.arrow);var s=document.createElement("span");return s.classList.add("arrow-down"),n.appendChild(s),t.appendChild(n),t.onclick=function(){e.main.config.isEnabled&&(e.main.data.contentOpen?e.main.close():e.main.open())},{container:t,placeholder:i,arrowIcon:{container:n,arrow:s}}},e.prototype.placeholder=function(){var e=this.main.data.getSelected();if(e&&e.placeholder){var t=document.createElement("span");t.classList.add(this.main.config.disabled),t.innerHTML=this.main.config.placeholderText,this.singleSelected.placeholder.innerHTML=t.outerHTML}else this.singleSelected.placeholder.innerHTML=e?e.innerHTML||e.text:""},e.prototype.multiSelectedDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.multiSelected);var i=document.createElement("div");i.classList.add(this.main.config.values),t.appendChild(i);var n=document.createElement("div");n.classList.add(this.main.config.add);var s=document.createElement("span");return s.classList.add(this.main.config.plus),s.onclick=function(t){e.main.data.contentOpen&&(e.main.close(),t.stopPropagation())},n.appendChild(s),t.appendChild(n),t.onclick=function(t){if(e.main.config.isEnabled){t.target.classList.contains(e.main.config.valueDelete)||e.main.open()}},{container:t,values:i,add:n,plus:s}},e.prototype.values=function(){if(this.main.config.isMultiple){for(var e,t=this.multiSelected.values.childNodes,i=this.main.data.getSelected(),n=0;n<t.length;n++){e=!0;for(var s=t[n],a=0;a<i.length;a++)String(i[a].id)===String(s.dataset.id)&&(e=!1);if(e){var o=t[n];o.classList.add("ss-out"),this.multiSelected.values.removeChild(o)}}for(var a=0;a<i.length;a++){e=!1;for(var n=0;n<t.length;n++){var s=t[n];i[a].id===s.dataset.id&&(e=!0)}e||(0===t.length?this.multiSelected.values.appendChild(this.valueDiv(i[a])):0===a?this.multiSelected.values.insertBefore(this.valueDiv(i[a]),t[a]):t[a-1].insertAdjacentElement("afterend",this.valueDiv(i[a])))}if(0===i.length){var l=document.createElement("span");l.classList.add(this.main.config.disabled),l.innerHTML=this.main.config.placeholderText,this.multiSelected.values.innerHTML=l.outerHTML}}},e.prototype.valueDiv=function(e){var t=this,i=document.createElement("div");i.classList.add(this.main.config.value),i.dataset.id=e.id;var n=document.createElement("span");n.classList.add(this.main.config.valueText),n.innerHTML=e.text,i.appendChild(n);var s=document.createElement("span");return s.classList.add(this.main.config.valueDelete),s.innerHTML="x",s.onclick=function(i){if(i.preventDefault(),i.stopPropagation(),t.main.config.isEnabled)if(t.main.beforeOnChange){for(var n=t.main.data.getSelected(),s=JSON.parse(JSON.stringify(n)),a=0;a<s.length;a++)s[a].id===e.id&&s.splice(a,1);var o=t.main.beforeOnChange(s);!1!==o&&(t.main.data.removeFromSelected(e.id,"id"),t.main.render(),t.main.select.setValue())}else t.main.data.removeFromSelected(e.id,"id"),t.main.render(),t.main.select.setValue(),t.main.data.onDataChange()},i.appendChild(s),i},e.prototype.contentDiv=function(){var e=document.createElement("div");return e.classList.add(this.main.config.content),e},e.prototype.searchDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.search),this.main.config.showSearch||t.classList.add(this.main.config.hide);var i=document.createElement("input");if(i.type="search",i.placeholder="Search",i.tabIndex=0,i.onclick=function(t){setTimeout(function(){""===t.target.value&&e.main.search("")},10)},i.onkeydown=function(t){"ArrowUp"===t.key?(e.main.open(),e.highlightUp(),t.preventDefault()):"ArrowDown"===t.key?(e.main.open(),e.highlightDown(),t.preventDefault()):"Tab"===t.key?e.main.close():"Enter"===t.key&&t.preventDefault()},i.onkeyup=function(t){var i=t.target;if("Enter"===t.key){if(e.main.addable&&t.ctrlKey)return n.click(),t.preventDefault(),void t.stopPropagation();var s=e.list.querySelector("."+e.main.config.highlighted);s&&s.click()}else"ArrowUp"===t.key||"ArrowDown"===t.key||("Escape"===t.key?e.main.close():e.main.search(i.value));t.preventDefault(),t.stopPropagation()},i.onfocus=function(){e.main.open()},t.appendChild(i),this.main.addable){var n=document.createElement("div");n.classList.add(this.main.config.addable),n.innerHTML="+",n.onclick=function(t){t.preventDefault(),t.stopPropagation();var i=e.search.input.value;if(""===i.trim())return void e.search.input.focus();var n=e.main.addable(i);if(n){var s=e.main.data.newOption({text:n,value:n});e.main.addData(s),e.main.search(""),setTimeout(function(){e.main.set(n,"value",!1,!1)},100),e.main.config.closeOnSelect&&setTimeout(function(){e.main.close()},100)}},t.appendChild(n)}return{container:t,input:i,addable:n}},e.prototype.highlightUp=function(){var e=this.list.querySelector("."+this.main.config.highlighted),t=null;if(e)for(t=e.previousSibling;null!==t&&t.classList.contains(this.main.config.disabled);)t=t.previousSibling;else{var i=this.list.querySelectorAll("."+this.main.config.option+":not(."+this.main.config.disabled+")");t=i[i.length-1]}if(t&&t.classList.contains(this.main.config.optgroupLabel)&&(t=null),null===t){var s=e.parentNode;if(s.classList.contains(this.main.config.optgroup)&&s.previousSibling){var a=s.previousSibling.querySelectorAll("."+this.main.config.option+":not(."+this.main.config.disabled+")");a.length&&(t=a[a.length-1])}}t&&(e&&e.classList.remove(this.main.config.highlighted),t.classList.add(this.main.config.highlighted),n.ensureElementInView(this.list,t))},e.prototype.highlightDown=function(){var e=this.list.querySelector("."+this.main.config.highlighted),t=null;if(e)for(t=e.nextSibling;null!==t&&t.classList.contains(this.main.config.disabled);)t=t.nextSibling;else t=this.list.querySelector("."+this.main.config.option+":not(."+this.main.config.disabled+")");if(null===t&&null!==e){var i=e.parentNode;if(i.classList.contains(this.main.config.optgroup)&&i.nextSibling){t=i.nextSibling.querySelector("."+this.main.config.option+":not(."+this.main.config.disabled+")")}}t&&(e&&e.classList.remove(this.main.config.highlighted),t.classList.add(this.main.config.highlighted),n.ensureElementInView(this.list,t))},e.prototype.listDiv=function(){var e=document.createElement("div");return e.classList.add(this.main.config.list),e.onmousewheel=function(t){var i=e.scrollTop,n=e.scrollHeight,s=e.offsetHeight,a="DOMMouseScroll"==t.type?-40*t.detail:t.wheelDelta,o=a>0,l=function(){return t.stopPropagation(),t.preventDefault(),t.returnValue=!1,!1};return!o&&-a>n-s-i?(e.scrollTop=n,l()):o&&a>i?(e.scrollTop=0,l()):void 0},e},e.prototype.options=function(){var e=this.main.data.filtered||this.main.data.data;if(this.list.innerHTML="",0===e.length){var t=document.createElement("div");return t.classList.add(this.main.config.option),t.classList.add(this.main.config.disabled),t.innerHTML=this.main.config.searchText,void this.list.appendChild(t)}for(var i=0;i<e.length;i++)if(e[i].hasOwnProperty("label")){var n=e[i],s=document.createElement("div");s.classList.add(this.main.config.optgroup);var a=document.createElement("div");a.classList.add(this.main.config.optgroupLabel),a.innerHTML=n.label,s.appendChild(a);for(var o=n.options,l=0;l<o.length;l++)s.appendChild(this.option(o[l]));this.list.appendChild(s)}else this.list.appendChild(this.option(e[i]))},e.prototype.option=function(e){if(e.placeholder){var t=document.createElement("div");return t.classList.add(this.main.config.option),t.classList.add(this.main.config.hide),t}var i=document.createElement("div");i.classList.add(this.main.config.option);var s=this.main.data.getSelected();i.dataset.id=e.id,i.innerHTML=e.innerHTML;var a=this;return i.onclick=function(e){e.preventDefault(),e.stopPropagation();var t=this,i=t.dataset.id;if(a.main.beforeOnChange){var n=void 0,o=JSON.parse(JSON.stringify(a.main.data.getObjectFromData(i)));o.selected=!0,a.main.config.isMultiple?(n=JSON.parse(JSON.stringify(s)),n.push(o)):n=JSON.parse(JSON.stringify(o));!1!==a.main.beforeOnChange(n)&&a.main.set(i,"id",a.main.config.closeOnSelect)}else a.main.set(i,"id",a.main.config.closeOnSelect)},(e.disabled||s&&n.isValueInArrayOfObjects(s,"id",e.id))&&(i.onclick=null,i.classList.add(this.main.config.disabled)),i},e}();t.default=s}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.SlimSelect=t():e.SlimSelect=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var i={};return t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/",t(t.s=1)}([function(e,t,i){"use strict";function n(e,t,i){function n(e,t){return i&&console.log(e),t&&e&&e.classList&&e.classList.contains(t)?e:null}function s(e,t){return e&&e!==document?n(e,t)?e:s(e.parentNode,t):null}return void 0===i&&(i=!1),i&&console.log(t),n(e,t)||s(e,t)}function s(e,t){var i=e.scrollTop+e.offsetTop,n=i+e.clientHeight,s=t.offsetTop,a=s+t.clientHeight;s<i?e.scrollTop-=i-s:a>n&&(e.scrollTop+=a-n)}function a(e,t,i){var n=e.offsetHeight,s=e.getBoundingClientRect(),a=i?s.top:s.top-n,o=i?s.bottom:s.bottom+n;return a<=0?"below":o>=window.innerHeight?"above":i?t:"below"}function o(e,t,i){void 0===t&&(t=100),void 0===i&&(i=!1);var n;return function(){var s=this,a=arguments,o=function(){n=null,i||e.apply(s,a)},l=i&&!n;clearTimeout(n),n=setTimeout(o,t),l&&e.apply(s,a)}}function l(e,t,i){if(!Array.isArray(e))return e[t]===i;for(var n=0;n<e.length;n++)if(e[n]&&e[n][t]&&e[n][t]===i)return!0;return!1}function r(e,t,i){e=e.trim();var n=e.trim().toLowerCase();t=t.trim().toLowerCase();var s=n.indexOf(t);return s>=0&&(e=e.substring(0,s)+'<span class="'+i+'">'+e.substring(s,s+t.length)+"</span>"+e.substring(s+t.length)),e}t.__esModule=!0,t.hasClassInTree=n,t.ensureElementInView=s,t.putContent=a,t.debounce=o,t.isValueInArrayOfObjects=l,t.highlight=r},function(e,t,i){"use strict";t.__esModule=!0,i(2),i(3);var n=i(4),s=i(0),a=i(5),o=i(6),l=i(7),r=function(){function e(e){var t=this;this.addable=null,this.beforeOnChange=null,this.onChange=null,this.validate(e);var i="string"==typeof e.select?document.querySelector(e.select):e.select;i.dataset.ssid&&this.destroy(i.dataset.ssid),e.addable&&(this.addable=e.addable),this.config=new n.default({select:i,showSearch:e.showSearch,searchText:e.searchText,searchHighlight:e.searchHighlight,closeOnSelect:e.closeOnSelect,showContent:e.showContent,placeholderText:e.placeholder,isEnabled:e.isEnabled}),this.select=new a.default({select:i,main:this}),this.data=new o.default({main:this}),this.slim=new l.default({main:this}),this.select.element.parentNode.insertBefore(this.slim.container,this.select.element.nextSibling),e.data?this.setData(e.data):this.render(),document.addEventListener("click",function(e){s.hasClassInTree(e.target,t.config.id)||t.close()}),window.addEventListener("scroll",s.debounce(function(e){t.data.contentOpen&&"auto"===t.config.showContent&&("above"===s.putContent(t.slim.content,t.data.contentPosition,t.data.contentOpen)?t.moveContentAbove():t.moveContentBelow())}),!1),e.beforeOnChange&&(this.beforeOnChange=e.beforeOnChange),e.onChange&&(this.onChange=e.onChange)}return e.prototype.validate=function(e){var t="string"==typeof e.select?document.querySelector(e.select):e.select;if(!t)throw new Error("Could not find select element");if("SELECT"!==t.tagName)throw new Error("Element isnt of type select")},e.prototype.set=function(e,t,i,n){void 0===t&&(t="value"),void 0===i&&(i=!0),void 0===n&&(n=!0),this.config.isMultiple&&!Array.isArray(e)?this.data.addToSelected(e,t):this.data.setSelected(e,t),this.select.setValue(),this.data.onDataChange(),this.render(),i&&this.close()},e.prototype.setData=function(e){if(!o.validateData(e))return void console.error("Validation problem on: #"+this.select.element.id);var t=JSON.parse(JSON.stringify(e));this.select.create(t),this.data.parseSelectData(),this.data.setSelectedFromSelect(),this.render()},e.prototype.addData=function(e){if(!o.validateData([e]))return void console.error("Validation problem on: #"+this.select.element.id);var t=this.data.newOption(e);this.data.add(t),this.select.create(this.data.data),this.data.parseSelectData(),this.data.setSelectedFromSelect(),this.render()},e.prototype.open=function(){this.config.isEnabled&&(this.slim.search.input.focus(),this.data.contentOpen||(this.config.isMultiple?this.slim.multiSelected.plus.classList.add("ss-cross"):(this.slim.singleSelected.arrowIcon.arrow.classList.remove("arrow-down"),this.slim.singleSelected.arrowIcon.arrow.classList.add("arrow-up")),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add("above"===this.data.contentPosition?this.config.openAbove:this.config.openBelow),this.slim.content.classList.add(this.config.open),"up"===this.config.showContent.toLowerCase()?this.moveContentAbove():"down"===this.config.showContent.toLowerCase()?this.moveContentBelow():"above"===s.putContent(this.slim.content,this.data.contentPosition,this.data.contentOpen)?this.moveContentAbove():this.moveContentBelow(),this.data.contentOpen=!0))},e.prototype.close=function(){var e=this;this.data.contentOpen&&(this.config.isMultiple?(this.slim.multiSelected.container.classList.remove(this.config.openAbove),this.slim.multiSelected.container.classList.remove(this.config.openBelow),this.slim.multiSelected.plus.classList.remove("ss-cross")):(this.slim.singleSelected.container.classList.remove(this.config.openAbove),this.slim.singleSelected.container.classList.remove(this.config.openBelow),this.slim.singleSelected.arrowIcon.arrow.classList.add("arrow-down"),this.slim.singleSelected.arrowIcon.arrow.classList.remove("arrow-up")),this.slim.content.classList.remove(this.config.open),this.data.contentOpen=!1,this.search(""),setTimeout(function(){e.slim.content.removeAttribute("style"),e.data.contentPosition="below",e.slim[e.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(e.config.openAbove),e.slim[e.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(e.config.openBelow)},300))},e.prototype.moveContentAbove=function(){var e=this.config.isMultiple?this.slim.multiSelected.container.offsetHeight:this.slim.singleSelected.container.offsetHeight,t=this.slim.content.offsetHeight,i=e+t-1;this.slim.content.style.margin="-"+i+"px 0 0 0",this.slim.content.style["transform-origin"]="center bottom",this.data.contentPosition="above",this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(this.config.openBelow),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add(this.config.openAbove)},e.prototype.moveContentBelow=function(){this.slim.content.removeAttribute("style"),this.data.contentPosition="below",this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.remove(this.config.openAbove),this.slim[this.config.isMultiple?"multiSelected":"singleSelected"].container.classList.add(this.config.openBelow)},e.prototype.enable=function(){this.config.isEnabled=!0,this.config.isMultiple?this.slim.multiSelected.container.classList.remove(this.config.disabled):this.slim.singleSelected.container.classList.remove(this.config.disabled),this.select.disconnectMutationObserver(),this.select.element.disabled=!1,this.slim.search.input.disabled=!1,this.select.observeMutationObserver()},e.prototype.disable=function(){this.config.isEnabled=!1,this.config.isMultiple?this.slim.multiSelected.container.classList.add(this.config.disabled):this.slim.singleSelected.container.classList.add(this.config.disabled),this.select.disconnectMutationObserver(),this.select.element.disabled=!0,this.slim.search.input.disabled=!0,this.select.observeMutationObserver()},e.prototype.search=function(e){this.data.searchValue!==e&&(this.slim.search.input.value=e,this.data.search(e),this.render())},e.prototype.render=function(){this.config.isMultiple?this.slim.values():this.slim.placeholder(),this.slim.options()},e.prototype.destroy=function(e){void 0===e&&(e=null);var t=e?document.querySelector("."+e):this.slim.container,i=e?document.querySelector("[data-ssid="+e+"]"):this.select.element;t&&i&&(i.style.display=null,delete i.dataset.ssid,t.parentElement&&t.parentElement.removeChild(t))},e}();t.default=r,e.exports=r},function(e,t){},function(e,t){try{var i=new window.CustomEvent("test");if(i.preventDefault(),!0!==i.defaultPrevented)throw new Error("Could not prevent default")}catch(e){var n=function(e,t){var i,n;return t=t||{bubbles:!1,cancelable:!1,detail:void 0},i=document.createEvent("CustomEvent"),i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n=i.preventDefault,i.preventDefault=function(){n.call(this);try{Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})}catch(e){this.defaultPrevented=!0}},i};n.prototype=window.Event.prototype,window.CustomEvent=n}},function(e,t,i){"use strict";t.__esModule=!0;var n=function(){function e(e){this.id="",this.isMultiple=!1,this.showSearch=!0,this.searchHighlight=!1,this.closeOnSelect=!0,this.showContent="auto",this.searchText="No Results",this.placeholderText="Select Value",this.isEnabled=!0,this.main="ss-main",this.singleSelected="ss-single-selected",this.arrow="ss-arrow",this.multiSelected="ss-multi-selected",this.add="ss-add",this.plus="ss-plus",this.values="ss-values",this.value="ss-value",this.valueText="ss-value-text",this.valueDelete="ss-value-delete",this.content="ss-content",this.open="ss-open",this.openAbove="ss-open-above",this.openBelow="ss-open-below",this.search="ss-search",this.searchHighlighter="ss-search-highlight",this.addable="ss-addable",this.list="ss-list",this.optgroup="ss-optgroup",this.optgroupLabel="ss-optgroup-label",this.option="ss-option",this.highlighted="ss-highlighted",this.disabled="ss-disabled",this.hide="ss-hide",this.id="ss-"+Math.floor(1e5*Math.random()),this.style=e.select.style.cssText,this.class=e.select.classList,this.isMultiple=e.select.multiple,this.showSearch=!1!==e.showSearch,this.searchHighlight=!0===e.searchHighlight,this.closeOnSelect=!1!==e.closeOnSelect,e.showContent&&(this.showContent=e.showContent),this.isEnabled=!1!==e.isEnabled,e.searchText&&(this.searchText=e.searchText),e.placeholderText&&(this.placeholderText=e.placeholderText)}return e}();t.default=n},function(e,t,i){"use strict";t.__esModule=!0;var n=function(){function e(e){this.element=e.select,this.main=e.main,this.element.disabled&&(this.main.config.isEnabled=!1),this.addAttributes(),this.addEventListeners(),this.addMutationObserver()}return e.prototype.setValue=function(){if(this.main.data.getSelected()){if(this.main.config.isMultiple)for(var e=this.main.data.getSelected(),t=this.element.options,i=0;i<t.length;i++){var n=t[i];n.selected=!1;for(var s=0;s<e.length;s++)e[s].value===n.value&&(n.selected=!0)}else{var e=this.main.data.getSelected();this.element.value=e?e.value:""}this.main.data.isOnChangeEnabled=!1,this.element.dispatchEvent(new CustomEvent("change")),this.main.data.isOnChangeEnabled=!0}},e.prototype.addAttributes=function(){this.element.tabIndex=-1,this.element.style.display="none",this.element.dataset.ssid=this.main.config.id},e.prototype.addEventListeners=function(){var e=this;this.element.addEventListener("change",function(t){e.main.data.setSelectedFromSelect(),e.main.render()})},e.prototype.addMutationObserver=function(){var e=this;this.mutationObserver=new MutationObserver(function(t){e.main.data.parseSelectData(),e.main.data.setSelectedFromSelect(),e.main.render()}),this.observeMutationObserver()},e.prototype.observeMutationObserver=function(){this.mutationObserver.observe(this.element,{attributes:!0,childList:!0,characterData:!0})},e.prototype.disconnectMutationObserver=function(){this.mutationObserver.disconnect()},e.prototype.create=function(e){this.element.innerHTML="";for(var t=0;t<e.length;t++)if(e[t].hasOwnProperty("options")){var i=e[t],n=document.createElement("optgroup");n.label=i.label;for(var s=0;s<i.options.length;s++)n.appendChild(this.createOption(i.options[s]));this.element.appendChild(n)}else this.element.appendChild(this.createOption(e[t]))},e.prototype.createOption=function(e){var t=document.createElement("option");return t.value=e.value||e.text,t.innerHTML=e.innerHTML||e.text,e.selected&&(t.selected=e.selected),e.disabled&&(t.disabled=!0),e.placeholder&&t.setAttribute("data-placeholder","true"),e.data&&"object"==typeof e.data&&Object.keys(e.data).forEach(function(i){t.setAttribute("data-"+i,e.data[i])}),t},e}();t.default=n},function(e,t,i){"use strict";function n(e){if(!e)return void console.error("Data must be an array of objects");for(var t=!1,i=0,n=0;n<e.length;n++)if(e[n].hasOwnProperty("label")){if(e[n].hasOwnProperty("options"))for(var a=e[n],o=a.options,l=0;l<o.length;l++)(t=s(o[l]))||i++}else{var r=e[n];t=s(r),t||i++}return 0===i}function s(e){return void 0!==e.text||(console.error("Data object option must have at least have a text value. Check object: "+JSON.stringify(e)),!1)}t.__esModule=!0;var a=function(){function e(e){this.contentOpen=!1,this.contentPosition="below",this.isOnChangeEnabled=!0,this.main=e.main,this.searchValue="",this.data=[],this.filtered=null,this.parseSelectData(),this.setSelectedFromSelect()}return e.prototype.newOption=function(e){return{id:e.id?e.id:String(Math.floor(1e8*Math.random())),value:e.value?e.value:"",text:e.text?e.text:"",innerHTML:e.innerHTML?e.innerHTML:"",selected:!!e.selected&&e.selected,disabled:!!e.disabled&&e.disabled,placeholder:e.placeholder?e.placeholder:"",data:e.data?e.data:{}}},e.prototype.add=function(e){var t={id:String(Math.floor(1e8*Math.random())),value:e.value,text:e.text,innerHTML:"",selected:!1,disabled:!1,placeholder:"",data:{}};this.data.push(t)},e.prototype.parseSelectData=function(){this.data=[];for(var e=this.main.select.element,t=e.childNodes,i=0;i<t.length;i++)if("OPTGROUP"===t[i].nodeName){for(var n=t[i],s={label:n.label,options:[]},a=t[i].childNodes,o=0;o<a.length;o++)"OPTION"===a[o].nodeName&&s.options.push(this.pullOptionData(a[o]));this.data.push(s)}else"OPTION"===t[i].nodeName&&this.data.push(this.pullOptionData(t[i]))},e.prototype.pullOptionData=function(e){return{id:!!e.dataset&&e.dataset.id||String(Math.floor(1e8*Math.random())),value:e.value,text:e.text,innerHTML:e.innerHTML,selected:e.selected,disabled:e.disabled,placeholder:e.dataset.placeholder||null,data:e.dataset}},e.prototype.setSelectedFromSelect=function(){var e=this.main.select.element.options;if(this.main.config.isMultiple){for(var t=[],i=0;i<e.length;i++){var n=e[i];n.selected&&t.push(this.getObjectFromData(n.value,"value").id)}this.setSelected(t,"id")}else if(-1!==e.selectedIndex){var n=e[e.selectedIndex],s=n.value;this.setSelected(s,"value")}},e.prototype.setSelected=function(e,t){void 0===t&&(t="id");for(var i=0;i<this.data.length;i++)if(this.data[i].hasOwnProperty("label")){if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i].options,s=0;s<n.length;s++)n[s].selected=this.shouldBeSelected(n[s],e,t)}else this.data[i].selected=this.shouldBeSelected(this.data[i],e,t)},e.prototype.shouldBeSelected=function(e,t,i){if(void 0===i&&(i="id"),Array.isArray(t)){for(var n=0;n<t.length;n++)if(String(e[i])===String(t[n]))return!0}else if(String(e[i])===String(t))return!0;return!1},e.prototype.getSelected=function(){for(var e=null,t=[],i=0;i<this.data.length;i++)if(this.data[i].hasOwnProperty("label")){if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i].options,s=0;s<n.length;s++)n[s].selected&&(this.main.config.isMultiple?t.push(n[s]):e=n[s])}else this.data[i].selected&&(this.main.config.isMultiple?t.push(this.data[i]):e=this.data[i]);return this.main.config.isMultiple?t:e},e.prototype.addToSelected=function(e,t){if(void 0===t&&(t="id"),this.main.config.isMultiple){for(var i=[],n=this.getSelected(),s=0;s<n.length;s++)i.push(n[s][t]);i.push(e),this.setSelected(i,t)}},e.prototype.removeFromSelected=function(e,t){if(void 0===t&&(t="id"),this.main.config.isMultiple){for(var i=[],n=this.getSelected(),s=0;s<n.length;s++)String(n[s][t])!==String(e)&&i.push(n[s][t]);this.setSelected(i,t)}},e.prototype.onDataChange=function(){this.main.onChange&&this.isOnChangeEnabled&&this.main.onChange(JSON.parse(JSON.stringify(this.getSelected())))},e.prototype.getObjectFromData=function(e,t){void 0===t&&(t="id");for(var i=0;i<this.data.length;i++){if(t in this.data[i]&&String(this.data[i][t])===String(e))return this.data[i];if(this.data[i].hasOwnProperty("options"))for(var n=this.data[i],s=0;s<n.options.length;s++)if(String(n.options[s][t])===String(e))return n.options[s]}return null},e.prototype.search=function(e){if(this.searchValue=e,""===e.trim())return void(this.filtered=null);var t=this.data.slice(0);e=e.trim().toLowerCase();var i=t.map(function(t){if(t.hasOwnProperty("options")){var i=t,n=i.options.filter(function(t){return-1!==t.text.toLowerCase().indexOf(e)});if(0!==n.length){var s=Object.assign({},i);return s.options=n,s}}if(t.hasOwnProperty("text")){if(-1!==t.text.toLowerCase().indexOf(e))return t}return null});this.filtered=i.filter(function(e){return e})},e}();t.default=a,t.validateData=n,t.validateOption=s},function(e,t,i){"use strict";t.__esModule=!0;var n=i(0),s=function(){function e(e){this.main=e.main,this.container=this.containerDiv(),this.content=this.contentDiv(),this.search=this.searchDiv(),this.list=this.listDiv(),this.options(),this.main.config.isMultiple?(this.multiSelected=this.multiSelectedDiv(),this.container.appendChild(this.multiSelected.container)):(this.singleSelected=this.singleSelectedDiv(),this.container.appendChild(this.singleSelected.container)),this.container.appendChild(this.content),this.content.appendChild(this.search.container),this.content.appendChild(this.list)}return e.prototype.containerDiv=function(){var e=document.createElement("div");e.classList.add(this.main.config.id),e.classList.add(this.main.config.main),e.style.cssText=this.main.config.style;for(var t=0;t<this.main.config.class.length;t++)e.classList.add(this.main.config.class[t]);return e},e.prototype.singleSelectedDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.singleSelected);var i=document.createElement("span");i.classList.add("placeholder"),t.appendChild(i);var n=document.createElement("span");n.classList.add(this.main.config.arrow);var s=document.createElement("span");return s.classList.add("arrow-down"),n.appendChild(s),t.appendChild(n),t.onclick=function(){e.main.config.isEnabled&&(e.main.data.contentOpen?e.main.close():e.main.open())},{container:t,placeholder:i,arrowIcon:{container:n,arrow:s}}},e.prototype.placeholder=function(){var e=this.main.data.getSelected();if(e&&e.placeholder){var t=document.createElement("span");t.classList.add(this.main.config.disabled),t.innerHTML=this.main.config.placeholderText,this.singleSelected.placeholder.innerHTML=t.outerHTML}else this.singleSelected.placeholder.innerHTML=e?e.innerHTML||e.text:""},e.prototype.multiSelectedDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.multiSelected);var i=document.createElement("div");i.classList.add(this.main.config.values),t.appendChild(i);var n=document.createElement("div");n.classList.add(this.main.config.add);var s=document.createElement("span");return s.classList.add(this.main.config.plus),s.onclick=function(t){e.main.data.contentOpen&&(e.main.close(),t.stopPropagation())},n.appendChild(s),t.appendChild(n),t.onclick=function(t){if(e.main.config.isEnabled){t.target.classList.contains(e.main.config.valueDelete)||e.main.open()}},{container:t,values:i,add:n,plus:s}},e.prototype.values=function(){if(this.main.config.isMultiple){for(var e,t=this.multiSelected.values.childNodes,i=this.main.data.getSelected(),n=0;n<t.length;n++){e=!0;for(var s=t[n],a=0;a<i.length;a++)String(i[a].id)===String(s.dataset.id)&&(e=!1);if(e){var o=t[n];o.classList.add("ss-out"),this.multiSelected.values.removeChild(o)}}for(var a=0;a<i.length;a++){e=!1;for(var n=0;n<t.length;n++){var s=t[n];i[a].id===s.dataset.id&&(e=!0)}e||(0===t.length?this.multiSelected.values.appendChild(this.valueDiv(i[a])):0===a?this.multiSelected.values.insertBefore(this.valueDiv(i[a]),t[a]):t[a-1].insertAdjacentElement("afterend",this.valueDiv(i[a])))}if(0===i.length){var l=document.createElement("span");l.classList.add(this.main.config.disabled),l.innerHTML=this.main.config.placeholderText,this.multiSelected.values.innerHTML=l.outerHTML}}},e.prototype.valueDiv=function(e){var t=this,i=document.createElement("div");i.classList.add(this.main.config.value),i.dataset.id=e.id;var n=document.createElement("span");n.classList.add(this.main.config.valueText),n.innerHTML=e.text,i.appendChild(n);var s=document.createElement("span");return s.classList.add(this.main.config.valueDelete),s.innerHTML="x",s.onclick=function(i){if(i.preventDefault(),i.stopPropagation(),t.main.config.isEnabled)if(t.main.beforeOnChange){for(var n=t.main.data.getSelected(),s=JSON.parse(JSON.stringify(n)),a=0;a<s.length;a++)s[a].id===e.id&&s.splice(a,1);var o=t.main.beforeOnChange(s);!1!==o&&(t.main.data.removeFromSelected(e.id,"id"),t.main.render(),t.main.select.setValue())}else t.main.data.removeFromSelected(e.id,"id"),t.main.render(),t.main.select.setValue(),t.main.data.onDataChange()},i.appendChild(s),i},e.prototype.contentDiv=function(){var e=document.createElement("div");return e.classList.add(this.main.config.content),e},e.prototype.searchDiv=function(){var e=this,t=document.createElement("div");t.classList.add(this.main.config.search),this.main.config.showSearch||t.classList.add(this.main.config.hide);var i=document.createElement("input");if(i.type="search",i.placeholder="Search",i.tabIndex=0,i.onclick=function(t){setTimeout(function(){""===t.target.value&&e.main.search("")},10)},i.onkeydown=function(t){"ArrowUp"===t.key?(e.main.open(),e.highlightUp(),t.preventDefault()):"ArrowDown"===t.key?(e.main.open(),e.highlightDown(),t.preventDefault()):"Tab"===t.key?e.main.close():"Enter"===t.key&&t.preventDefault()},i.onkeyup=function(t){var s=t.target;if("Enter"===t.key){if(e.main.addable&&t.ctrlKey)return n.click(),t.preventDefault(),void t.stopPropagation();var a=e.list.querySelector("."+e.main.config.highlighted);a&&a.click()}else"ArrowUp"===t.key||"ArrowDown"===t.key||("Escape"===t.key?e.main.close():e.main.config.showSearch?e.main.search(s.value):i.value="");t.preventDefault(),t.stopPropagation()},i.onfocus=function(){e.main.open()},t.appendChild(i),this.main.addable){var n=document.createElement("div");n.classList.add(this.main.config.addable),n.innerHTML="+",n.onclick=function(t){t.preventDefault(),t.stopPropagation();var i=e.search.input.value;if(""===i.trim())return void e.search.input.focus();var n=e.main.addable(i);if(n){var s=e.main.data.newOption({text:n,value:n});e.main.addData(s),e.main.search(""),setTimeout(function(){e.main.set(n,"value",!1,!1)},100),e.main.config.closeOnSelect&&setTimeout(function(){e.main.close()},100)}},t.appendChild(n)}return{container:t,input:i,addable:n}},e.prototype.highlightUp=function(){var e=this.list.querySelector("."+this.main.config.highlighted),t=null;if(e)for(t=e.previousSibling;null!==t&&t.classList.contains(this.main.config.disabled);)t=t.previousSibling;else{var i=this.list.querySelectorAll("."+this.main.config.option+":not(."+this.main.config.disabled+")");t=i[i.length-1]}if(t&&t.classList.contains(this.main.config.optgroupLabel)&&(t=null),null===t){var s=e.parentNode;if(s.classList.contains(this.main.config.optgroup)&&s.previousSibling){var a=s.previousSibling.querySelectorAll("."+this.main.config.option+":not(."+this.main.config.disabled+")");a.length&&(t=a[a.length-1])}}t&&(e&&e.classList.remove(this.main.config.highlighted),t.classList.add(this.main.config.highlighted),n.ensureElementInView(this.list,t))},e.prototype.highlightDown=function(){var e=this.list.querySelector("."+this.main.config.highlighted),t=null;if(e)for(t=e.nextSibling;null!==t&&t.classList.contains(this.main.config.disabled);)t=t.nextSibling;else t=this.list.querySelector("."+this.main.config.option+":not(."+this.main.config.disabled+")");if(null===t&&null!==e){var i=e.parentNode;if(i.classList.contains(this.main.config.optgroup)&&i.nextSibling){t=i.nextSibling.querySelector("."+this.main.config.option+":not(."+this.main.config.disabled+")")}}t&&(e&&e.classList.remove(this.main.config.highlighted),t.classList.add(this.main.config.highlighted),n.ensureElementInView(this.list,t))},e.prototype.listDiv=function(){var e=document.createElement("div");return e.classList.add(this.main.config.list),e.onmousewheel=function(t){var i=e.scrollTop,n=e.scrollHeight,s=e.offsetHeight,a="DOMMouseScroll"==t.type?-40*t.detail:t.wheelDelta,o=a>0,l=function(){return t.stopPropagation(),t.preventDefault(),t.returnValue=!1,!1};return!o&&-a>n-s-i?(e.scrollTop=n,l()):o&&a>i?(e.scrollTop=0,l()):void 0},e},e.prototype.options=function(){var e=this.main.data.filtered||this.main.data.data;if(this.list.innerHTML="",0===e.length){var t=document.createElement("div");return t.classList.add(this.main.config.option),t.classList.add(this.main.config.disabled),t.innerHTML=this.main.config.searchText,void this.list.appendChild(t)}for(var i=0;i<e.length;i++)if(e[i].hasOwnProperty("label")){var n=e[i],s=document.createElement("div");s.classList.add(this.main.config.optgroup);var a=document.createElement("div");a.classList.add(this.main.config.optgroupLabel),a.innerHTML=n.label,s.appendChild(a);for(var o=n.options,l=0;l<o.length;l++)s.appendChild(this.option(o[l]));this.list.appendChild(s)}else this.list.appendChild(this.option(e[i]))},e.prototype.option=function(e){if(e.placeholder){var t=document.createElement("div");return t.classList.add(this.main.config.option),t.classList.add(this.main.config.hide),t}var i=document.createElement("div");i.classList.add(this.main.config.option);var s=this.main.data.getSelected();i.dataset.id=e.id,this.main.config.searchHighlight&&this.main.slim&&""!==this.main.slim.search.input.value.trim()?i.innerHTML=n.highlight(e.innerHTML,this.main.slim.search.input.value,this.main.config.searchHighlighter):i.innerHTML=e.innerHTML;var a=this;return i.onclick=function(e){e.preventDefault(),e.stopPropagation();var t=this,i=t.dataset.id;if(a.main.beforeOnChange){var n=void 0,o=JSON.parse(JSON.stringify(a.main.data.getObjectFromData(i)));o.selected=!0,a.main.config.isMultiple?(n=JSON.parse(JSON.stringify(s)),n.push(o)):n=JSON.parse(JSON.stringify(o));!1!==a.main.beforeOnChange(n)&&a.main.set(i,"id",a.main.config.closeOnSelect)}else a.main.set(i,"id",a.main.config.closeOnSelect)},(e.disabled||s&&n.isValueInArrayOfObjects(s,"id",e.id))&&(i.onclick=null,i.classList.add(this.main.config.disabled)),i},e}();t.default=s}])});
{
"name": "slim-select",
"description": "Slim advanced select dropdown",
"version": "1.6.1",
"version": "1.6.2",
"author": "Brian Voelker <brian@webiswhatido.com> (http://webiswhatido.com)",

@@ -25,3 +25,4 @@ "homepage": "https://slimselectjs.com",

"dropdown",
"search"
"search",
"multiselect"
],

@@ -32,7 +33,8 @@ "scripts": {

"devDependencies": {
"chance": "^1.0.12",
"chance": "^1.0.13",
"clipboard": "^1.7.1",
"custom-event-polyfill": "^0.3.0",
"highlightjs": "^9.10.0",
"prismjs": "^1.9.0",
"vue-build": "^2.2.0"
}
}

@@ -54,5 +54,2 @@ # Slim Select

## Roadmap
- Refining search
## Testing

@@ -59,0 +56,0 @@ Browser testing has been provided by

@@ -6,4 +6,7 @@ import Vue from 'vue'

import routerList from 'docs/router.js'
import Prism from 'prismjs'
import Normalizer from 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace'
import 'prismjs/plugins/toolbar/prism-toolbar'
import 'prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard'
import hljs from 'highlightjs'
import './google-analytics.js'

@@ -14,25 +17,14 @@

Vue.directive('highlightjs', {
deep: true,
bind: function (el, binding) {
// on first bind, highlight all targets
let targets = el.querySelectorAll('code')
for (var i = 0; i < targets.length; i++) {
// if a value is directly assigned to the directive, use this
// instead of the element content.
if (binding.value) {
targets[i].innerHTML = binding.value
}
hljs.highlightBlock(targets[i])
}
},
componentUpdated: function (el, binding) {
// after an update, re-fill the content and then highlight
let targets = el.querySelectorAll('code')
for (var i = 0; i < targets.length; i++) {
if (binding.value) {
targets[i].innerHTML = binding.value
hljs.highlightBlock(targets[i])
}
}
/* eslint-disable no-new */
new Normalizer({
'remove-trailing': true,
'remove-indent': true,
'left-trim': true,
'right-trim': true
})
// new Copy()
Vue.mixin({
updated () {
Prism.highlightAll()
}

@@ -45,3 +37,2 @@ })

/* eslint-disable no-new */
new Vue({

@@ -48,0 +39,0 @@ router,

@@ -5,2 +5,3 @@ interface constructor {

searchText: string
searchHighlight: boolean
closeOnSelect: boolean

@@ -18,2 +19,3 @@ showContent: string

showSearch: boolean = true
searchHighlight: boolean = false
closeOnSelect: boolean = true

@@ -41,2 +43,3 @@ showContent: string = 'auto' // options: auto, up, down

readonly search: string = 'ss-search'
readonly searchHighlighter: string = 'ss-search-highlight'
readonly addable: string = 'ss-addable'

@@ -58,2 +61,3 @@ readonly list: string = 'ss-list'

this.showSearch = (info.showSearch === false ? false : true)
this.searchHighlight = (info.searchHighlight === true ? true : false)
this.closeOnSelect = (info.closeOnSelect === false ? false : true)

@@ -60,0 +64,0 @@ if (info.showContent) {this.showContent = info.showContent}

@@ -80,1 +80,13 @@ export function hasClassInTree (element, className, output = false) {

}
export function highlight (text: string, search: string, className: string): string {
text = text.trim()
let textLower = text.trim().toLowerCase()
search = search.trim().toLowerCase()
let index = textLower.indexOf(search)
if (index >= 0) {
text = text.substring(0, index) + `<span class="${className}">` + text.substring(index, index + search.length) + '</span>' + text.substring(index + search.length)
}
return text
}

@@ -17,3 +17,3 @@ import './slimselect.scss'

searchText: string
addable: Function
searchHighlight: boolean
closeOnSelect: boolean

@@ -23,4 +23,5 @@ showContent: string

isEnabled: boolean
// Events
addable: Function
beforeOnChange: Function

@@ -52,2 +53,3 @@ onChange: Function

searchText: info.searchText,
searchHighlight: info.searchHighlight,
closeOnSelect: info.closeOnSelect,

@@ -54,0 +56,0 @@ showContent: info.showContent,

import SlimSelect from './index'
import {ensureElementInView, isValueInArrayOfObjects} from './helper'
import {ensureElementInView, isValueInArrayOfObjects, highlight} from './helper'
import {option, optgroup, dataObject} from './data'

@@ -323,3 +323,7 @@ import select from './select';

} else {
this.main.search(target.value)
if (this.main.config.showSearch) {
this.main.search(target.value)
} else {
input.value = ''
}
}

@@ -540,3 +544,7 @@ e.preventDefault()

option.dataset.id = data.id
option.innerHTML = data.innerHTML
if (this.main.config.searchHighlight && this.main.slim && this.main.slim.search.input.value.trim() !== '') {
option.innerHTML = highlight(data.innerHTML, this.main.slim.search.input.value, this.main.config.searchHighlighter)
} else {
option.innerHTML = data.innerHTML
}
let master = this

@@ -543,0 +551,0 @@ option.onclick = function (e) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc