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

select-pure

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

select-pure - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

2

es/select-pure.min.js

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

var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var allowedAttributes={value:"data-value",disabled:"data-disabled",class:"class",type:"type"},Element=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return _classCallCheck(this,e),this._node=t instanceof HTMLElement?t:document.createElement(t),this._config={i18n:s},this._setAttributes(n),n.textContent&&this._setTextContent(n.textContent),this}return _createClass(e,[{key:"get",value:function(){return this._node}},{key:"append",value:function(e){return this._node.appendChild(e),this}},{key:"addClass",value:function(e){return this._node.classList.add(e),this}},{key:"removeClass",value:function(e){return this._node.classList.remove(e),this}},{key:"toggleClass",value:function(e){return this._node.classList.toggle(e),this}},{key:"addEventListener",value:function(e,t){return this._node.addEventListener(e,t),this}},{key:"removeEventListener",value:function(e,t){return this._node.removeEventListener(e,t),this}},{key:"setText",value:function(e){return this._setTextContent(e),this}},{key:"getHeight",value:function(){return window.getComputedStyle(this._node).height}},{key:"setTop",value:function(e){return this._node.style.top=e+"px",this}},{key:"focus",value:function(){return this._node.focus(),this}},{key:"_setTextContent",value:function(e){this._node.textContent=e}},{key:"_setAttributes",value:function(e){for(var t in e)allowedAttributes[t]&&e[t]&&this._setAttribute(allowedAttributes[t],e[t])}},{key:"_setAttribute",value:function(e,t){this._node.setAttribute(e,t)}}]),e}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},_createClass$1=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}();function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function _classCallCheck$1(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var SelectPure=function(){function e(t,n){_classCallCheck$1(this,e),this._config=_extends({},n),this._state={opened:!1},this._icons=[],this._boundHandleClick=this._handleClick.bind(this),this._boundUnselectOption=this._unselectOption.bind(this),this._boundSortOptions=this._sortOptions.bind(this),this._body=new Element(document.body),this._create(t),this._setValue()}return _createClass$1(e,[{key:"_create",value:function(e){var t="string"==typeof e?document.querySelector(e):e;this._parent=new Element(t),this._select=new Element("div",{class:"select-pure__select"}),this._label=new Element("span",{class:"select-pure__label"}),this._optionsWrapper=new Element("div",{class:"select-pure__options"}),this._config.multiple&&this._select.addClass("select-pure__select--multiple"),this._options=this._generateOptions(),this._select.addEventListener("click",this._boundHandleClick),this._select.append(this._label.get()),this._select.append(this._optionsWrapper.get()),this._parent.append(this._select.get())}},{key:"_generateOptions",value:function(){var e=this;return this._config.autocomplete&&(this._autocomplete=new Element("input",{class:"select-pure__autocomplete",type:"text"}),this._autocomplete.addEventListener("input",this._boundSortOptions),this._optionsWrapper.append(this._autocomplete.get())),this._config.options.map(function(t){var n=new Element("div",{class:"select-pure__option",value:t.value,textContent:t.label,disabled:t.disabled});return e._optionsWrapper.append(n.get()),n})}},{key:"_handleClick",value:function(e){if(e.stopPropagation(),"select-pure__autocomplete"!==e.target.className){if(this._state.opened){var t=this._options.find(function(t){return t.get()===e.target});return t&&this._setValue(t.get().getAttribute("data-value"),!0),this._select.removeClass("select-pure__select--opened"),this._body.removeEventListener("click",this._boundHandleClick),this._select.addEventListener("click",this._boundHandleClick),void(this._state.opened=!1)}e.target.className!==this._config.icon&&(this._select.addClass("select-pure__select--opened"),this._body.addEventListener("click",this._boundHandleClick),this._select.removeEventListener("click",this._boundHandleClick),this._state.opened=!0,this._autocomplete&&this._autocomplete.focus())}}},{key:"_setValue",value:function(e,t,n){var s=this;if(e&&!n&&(this._config.value=this._config.multiple?this._config.value.concat(e):e),e&&n&&(this._config.value=e),this._options.forEach(function(e){e.removeClass("select-pure__option--selected")}),this._config.multiple){var i=this._config.value.map(function(e){var t=s._config.options.find(function(t){return t.value===e});return s._options.find(function(e){return e.get().getAttribute("data-value")===t.value}).addClass("select-pure__option--selected"),t});this._selectOptions(i,t)}else{var o=this._config.value?this._config.options.find(function(e){return e.value===s._config.value}):this._config.options[0];this._options.find(function(e){return e.get().getAttribute("data-value")===o.value}).addClass("select-pure__option--selected"),this._selectOption(o,t)}}},{key:"_selectOption",value:function(e,t){this._selectedOption=e,this._label.setText(e.label),this._config.onChange&&t&&this._config.onChange(e.value)}},{key:"_selectOptions",value:function(e,t){var n=this;this._label.setText(""),this._icons=e.map(function(e){var t=new Element("span",{class:"select-pure__selected-label",textContent:e.label}),s=new Element("i",{class:n._config.icon,value:e.value});return s.addEventListener("click",n._boundUnselectOption),t.append(s.get()),n._label.append(t.get()),s.get()}),t&&this._optionsWrapper.setTop(Number(this._select.getHeight().split("px")[0])+5)}},{key:"_unselectOption",value:function(e){var t=[].concat(_toConsumableArray(this._config.value)),n=t.indexOf(e.target.getAttribute("data-value"));-1!==n&&t.splice(n,1),this._setValue(t,!0,!0)}},{key:"_sortOptions",value:function(e){this._options.forEach(function(t){t.get().textContent.toLowerCase().startsWith(e.target.value.toLowerCase())?t.removeClass("select-pure__option--hidden"):t.addClass("select-pure__option--hidden")})}}]),e}();export default SelectPure;
var SelectPure=function(){"use strict";var e=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();var t={value:"data-value",disabled:"data-disabled",class:"class",type:"type"},n=function(){function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this._node=e instanceof HTMLElement?e:document.createElement(e),this._config={i18n:i},this._setAttributes(t),t.textContent&&this._setTextContent(t.textContent),this}return e(n,[{key:"get",value:function(){return this._node}},{key:"append",value:function(e){return this._node.appendChild(e),this}},{key:"addClass",value:function(e){return this._node.classList.add(e),this}},{key:"removeClass",value:function(e){return this._node.classList.remove(e),this}},{key:"toggleClass",value:function(e){return this._node.classList.toggle(e),this}},{key:"addEventListener",value:function(e,t){return this._node.addEventListener(e,t),this}},{key:"removeEventListener",value:function(e,t){return this._node.removeEventListener(e,t),this}},{key:"setText",value:function(e){return this._setTextContent(e),this}},{key:"getHeight",value:function(){return window.getComputedStyle(this._node).height}},{key:"setTop",value:function(e){return this._node.style.top=e+"px",this}},{key:"focus",value:function(){return this._node.focus(),this}},{key:"_setTextContent",value:function(e){this._node.textContent=e}},{key:"_setAttributes",value:function(e){for(var n in e)t[n]&&e[n]&&this._setAttribute(t[n],e[n])}},{key:"_setAttribute",value:function(e,t){this._node.setAttribute(e,t)}}]),n}(),i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},s=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();return function(){function e(t,s){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._config=i({},s),this._state={opened:!1},this._icons=[],this._boundHandleClick=this._handleClick.bind(this),this._boundUnselectOption=this._unselectOption.bind(this),this._boundSortOptions=this._sortOptions.bind(this),this._body=new n(document.body),this._create(t),this._setValue()}return s(e,[{key:"_create",value:function(e){var t="string"==typeof e?document.querySelector(e):e;this._parent=new n(t),this._select=new n("div",{class:"select-pure__select"}),this._label=new n("span",{class:"select-pure__label"}),this._optionsWrapper=new n("div",{class:"select-pure__options"}),this._config.multiple&&this._select.addClass("select-pure__select--multiple"),this._options=this._generateOptions(),this._select.addEventListener("click",this._boundHandleClick),this._select.append(this._label.get()),this._select.append(this._optionsWrapper.get()),this._parent.append(this._select.get())}},{key:"_generateOptions",value:function(){var e=this;return this._config.autocomplete&&(this._autocomplete=new n("input",{class:"select-pure__autocomplete",type:"text"}),this._autocomplete.addEventListener("input",this._boundSortOptions),this._optionsWrapper.append(this._autocomplete.get())),this._config.options.map(function(t){var i=new n("div",{class:"select-pure__option",value:t.value,textContent:t.label,disabled:t.disabled});return e._optionsWrapper.append(i.get()),i})}},{key:"_handleClick",value:function(e){if(e.stopPropagation(),"select-pure__autocomplete"!==e.target.className){if(this._state.opened){var t=this._options.find(function(t){return t.get()===e.target});return t&&this._setValue(t.get().getAttribute("data-value"),!0),this._select.removeClass("select-pure__select--opened"),this._body.removeEventListener("click",this._boundHandleClick),this._select.addEventListener("click",this._boundHandleClick),void(this._state.opened=!1)}e.target.className!==this._config.icon&&(this._select.addClass("select-pure__select--opened"),this._body.addEventListener("click",this._boundHandleClick),this._select.removeEventListener("click",this._boundHandleClick),this._state.opened=!0,this._autocomplete&&this._autocomplete.focus())}}},{key:"_setValue",value:function(e,t,n){var i=this;if(e&&!n&&(this._config.value=this._config.multiple?this._config.value.concat(e):e),e&&n&&(this._config.value=e),this._options.forEach(function(e){e.removeClass("select-pure__option--selected")}),this._config.multiple){var s=this._config.value.map(function(e){var t=i._config.options.find(function(t){return t.value===e});return i._options.find(function(e){return e.get().getAttribute("data-value")===t.value}).addClass("select-pure__option--selected"),t});this._selectOptions(s,t)}else{var o=this._config.value?this._config.options.find(function(e){return e.value===i._config.value}):this._config.options[0];this._options.find(function(e){return e.get().getAttribute("data-value")===o.value}).addClass("select-pure__option--selected"),this._selectOption(o,t)}}},{key:"_selectOption",value:function(e,t){this._selectedOption=e,this._label.setText(e.label),this._config.onChange&&t&&this._config.onChange(e.value)}},{key:"_selectOptions",value:function(e,t){var i=this;this._label.setText(""),this._icons=e.map(function(e){var t=new n("span",{class:"select-pure__selected-label",textContent:e.label}),s=new n("i",{class:i._config.icon,value:e.value});return s.addEventListener("click",i._boundUnselectOption),t.append(s.get()),i._label.append(t.get()),s.get()}),t&&this._optionsWrapper.setTop(Number(this._select.getHeight().split("px")[0])+5)}},{key:"_unselectOption",value:function(e){var t=[].concat(function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(this._config.value)),n=t.indexOf(e.target.getAttribute("data-value"));-1!==n&&t.splice(n,1),this._setValue(t,!0,!0)}},{key:"_sortOptions",value:function(e){this._options.forEach(function(t){t.get().textContent.toLowerCase().startsWith(e.target.value.toLowerCase())?t.removeClass("select-pure__option--hidden"):t.addClass("select-pure__option--hidden")})}}]),e}()}();
{
"name": "select-pure",
"version": "0.1.5",
"version": "0.1.6",
"description": "Pure JavaScript select component.",

@@ -5,0 +5,0 @@ "author": {

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