Socket
Socket
Sign inDemoInstall

cpr-select

Package Overview
Dependencies
Maintainers
7
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpr-select - npm Package Compare versions

Comparing version 2.3.0 to 2.3.1

4

build/cpr-select.js

@@ -6,4 +6,4 @@ /*!

* license: MIT
* version: 2.2.4
* version: 2.3.1
*/
!function(e){function t(o){if(n[o])return n[o].exports;var l=n[o]={i:o,l:!1,exports:{}};return e[o].call(l.exports,l,l.exports,t),l.l=!0,l.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function r(e,t){return!!e&&(e===t||r(e.parentElement,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s=n(1),c=function(e){return e&&e.__esModule?e:{default:e}}(s),u=n(2),p="",d=void 0,f=function(e){function t(){var e,n,a,i;o(this,t);for(var s=arguments.length,f=Array(s),g=0;g<s;g++)f[g]=arguments[g];return n=a=l(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(f))),a.state={dialogDisplayed:!1,top:0,focused:!1,close:function(e){r(e.target,a.el)||a.setState({dialogDisplayed:!1,focused:!1})}},a.displayDialog=function(e){a.props.disabled||a.setState({dialogDisplayed:!0})},a.getIndex=function(e){return(0,u.findIndex)(a.props.options,{key:e})},a.onKeyDown=function(e){if(!a.props.disabled){var t=e.which,n=a.state.selectedIndex;9!==t&&e.preventDefault(),13===t?a.selectItem(n):38===t?n<=0?a.setState({dialogDisplayed:!0}):a.setState({dialogDisplayed:!0,selectedIndex:void 0===n?0:n-1}):40===t?n===a.props.options.length-1?a.setState({dialogDisplayed:!0}):a.setState({dialogDisplayed:!0,selectedIndex:n?n+1:0}):27===t?a.setState({dialogDisplayed:!1}):a.highlightByText(e.which)}},a.triggerItemChange=function(){a.props.onChange&&a.props.onChange.call(null,a.props.options[a.state.selectedIndex].key,a.props.options[a.state.selectedIndex],a.state.selectedIndex)},a.selectItem=function(e,t){a.props.disabled||setTimeout(function(){a.setState({selectedIndex:e,focused:!0,dialogDisplayed:!1}),setTimeout(a.triggerItemChange)})},a.positionDialogAndGetTop=function(e,t,n){var o=e.length-t,l=Math.floor(n/36),r=Math.floor((l-1)/2);if(t>r&&o<r+1){if(e.length<l)return 36*t*-1-10-2+"px";a.positionDialog(t,n);return n/-2-15-36*(r-o)+"px"}return t>r?(a.positionDialog(t,n),n/-2-.0075*n):36*t*-1-10-1+"px"},a.positionDialog=function(e,t){setTimeout(function(){var n=a.el.querySelector(".cp-select__menu");if(n){var o=t/2-8;n.scrollTop=36*e-o}})},a.focusSelect=function(){a.state.focused||a.setState({focused:!0})},a.onBlur=function(){a.setState({focused:!1})},a.highlightByText=function(e){p+=String.fromCharCode(e);var t=a.getIndexFromString(p);t>-1&&a.selectItem(t),clearTimeout(d),d=setTimeout(function(){p=""},1e3)},a.getIndexFromString=function(e){return e=e.toLowerCase(),(0,u.findIndex)(a.props.options,function(t){return null!==a.getViewValue(t)&&0===a.getViewValue(t).toLowerCase().indexOf(e)})},a.getViewValue=function(e){return null===e.value||void 0===e.value?null:e.value||e},a.getDialog=function(e,t){if(e){var n=a.state.selectedIndex,o=t.map(function(e,t){return e.separator?c.default.createElement("li",{key:"separator"+t,className:"separator"}):c.default.createElement("li",{key:e.key,className:n===t?"+selected":"",onMouseDown:a.selectItem.bind(a,t)},c.default.createElement("a",{style:null!==e.value?{}:{color:"rgba(0,0,0,0)"}},null!==e.value?e.value:"null"))});setTimeout(function(){try{a.el.querySelector(".cp-select__hidden-input").focus()}catch(e){if(-1===e.message.indexOf("Invariant Violation"))throw new Error(e.message)}},100);var l=a.props.maxHeight||400;return c.default.createElement("div",null,c.default.createElement("ul",{className:"cp-select__menu cps-dropdown-menu",style:{top:a.positionDialogAndGetTop(t,n,l),maxHeight:l+"px"}},o))}},a.render=function(){var e="cp-select",t=a.props.options[a.getIndex(a.props.selected)],n=a;return a.props.disabled&&(e+=" +disabled"),a.state.focused&&!a.props.disabled&&(e+=" +focus"),c.default.createElement("div",{ref:function(e){e&&(n.el=e)},className:"cp-select-outer "+a.props.outerClass,role:"select"},c.default.createElement("input",{className:"cp-select__hidden-input",onFocus:a.focusSelect,onBlur:a.onBlur,onKeyDown:a.onKeyDown}),c.default.createElement("div",{className:e+" "+a.props.selectClass,onClick:a.displayDialog},t?c.default.createElement("div",{className:"cp-select__selected"},t.value):c.default.createElement("div",{className:"cp-select__selected",style:{color:"#afafaf"}},a.props.placeholder),c.default.createElement("div",{className:"cp-select__icon"})),a.getDialog(a.state.dialogDisplayed,a.props.options))},i=n,l(a,i)}return a(t,e),i(t,[{key:"componentWillMount",value:function(){document.body.addEventListener("click",this.state.close)}},{key:"componentWillUnmount",value:function(){document.body.removeEventListener("click",this.state.close)}}]),t}(c.default.Component);t.default=f,"undefined"!=typeof window&&window&&!window.CanopySelect&&(window.CanopySelect=f)},function(e,t){e.exports=React},function(e,t){e.exports=_}]);
!function(e){function t(o){if(n[o])return n[o].exports;var l=n[o]={i:o,l:!1,exports:{}};return e[o].call(l.exports,l,l.exports,t),l.l=!0,l.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function r(e,t){return!!e&&(e===t||r(e.parentElement,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),s=n(1),c=function(e){return e&&e.__esModule?e:{default:e}}(s),u=n(2),p="",d=void 0,f=function(e){function t(){var e,n,a,i;o(this,t);for(var s=arguments.length,f=Array(s),g=0;g<s;g++)f[g]=arguments[g];return n=a=l(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(f))),a.state={dialogDisplayed:!1,top:0,focused:!1,close:function(e){r(e.target,a.el)||a.setState({dialogDisplayed:!1,focused:!1})}},a.displayDialog=function(e){a.props.disabled||a.setState({dialogDisplayed:!0})},a.getIndex=function(e){return(0,u.findIndex)(a.props.options,{key:e})},a.onKeyDown=function(e){if(!a.props.disabled){var t=e.which,n=a.state.selectedIndex;9!==t&&e.preventDefault(),13===t?a.selectItem(n):38===t?n<=0?a.setState({dialogDisplayed:!0}):a.setState({dialogDisplayed:!0,selectedIndex:n-1}):40===t?n===a.props.options.length-1?a.setState({dialogDisplayed:!0}):a.setState({dialogDisplayed:!0,selectedIndex:n+1}):27===t?a.setState({dialogDisplayed:!1}):a.highlightByText(e.which)}},a.triggerItemChange=function(){a.props.onChange&&a.props.onChange.call(null,a.props.options[a.state.selectedIndex].key,a.props.options[a.state.selectedIndex],a.state.selectedIndex)},a.selectItem=function(e,t){a.props.disabled||setTimeout(function(){a.setState({selectedIndex:e,focused:!0,dialogDisplayed:!1}),setTimeout(a.triggerItemChange)})},a.positionDialogAndGetTop=function(e,t,n){var o=e.length-t,l=Math.floor(n/36),r=Math.floor((l-1)/2);if(t>r&&o<r+1){if(e.length<l)return 36*t*-1-10-2+"px";a.positionDialog(t,n);return n/-2-15-36*(r-o)+"px"}return t>r?(a.positionDialog(t,n),n/-2-.0075*n):36*t*-1-10-1+"px"},a.positionDialog=function(e,t){setTimeout(function(){var n=a.el.querySelector(".cp-select__menu");if(n){var o=t/2-8;n.scrollTop=36*e-o}})},a.focusSelect=function(){a.state.focused||a.setState({focused:!0})},a.onBlur=function(){a.setState({focused:!1})},a.highlightByText=function(e){p+=String.fromCharCode(e);var t=a.getIndexFromString(p);t>-1&&a.selectItem(t),clearTimeout(d),d=setTimeout(function(){p=""},1e3)},a.getIndexFromString=function(e){return e=e.toLowerCase(),(0,u.findIndex)(a.props.options,function(t){return null!==a.getViewValue(t)&&0===a.getViewValue(t).toLowerCase().indexOf(e)})},a.getViewValue=function(e){return null===e.value||void 0===e.value?null:e.value||e},a.getDialog=function(e,t){if(e){var n=a.state.selectedIndex,o=t.map(function(e,t){return e.separator?c.default.createElement("li",{key:"separator"+t,className:"separator"}):c.default.createElement("li",{key:e.key,className:n===t?"+selected":"",onMouseDown:a.selectItem.bind(a,t)},c.default.createElement("a",{style:null!==e.value?{}:{color:"rgba(0,0,0,0)"}},null!==e.value?e.value:"null"))});setTimeout(function(){try{a.el.querySelector(".cp-select__hidden-input").focus()}catch(e){if(-1===e.message.indexOf("Invariant Violation"))throw new Error(e.message)}},100);var l=a.props.maxHeight||400;return c.default.createElement("div",null,c.default.createElement("ul",{className:"cp-select__menu cps-dropdown-menu",style:{top:a.positionDialogAndGetTop(t,n,l),maxHeight:l+"px"}},o))}},a.render=function(){var e="cp-select",t=a.props.options[a.getIndex(a.props.selected)],n=a;return a.props.disabled&&(e+=" +disabled"),a.state.focused&&!a.props.disabled&&(e+=" +focus"),c.default.createElement("div",{ref:function(e){e&&(n.el=e)},className:"cp-select-outer "+a.props.outerClass,role:"select"},c.default.createElement("input",{className:"cp-select__hidden-input",onFocus:a.focusSelect,onBlur:a.onBlur,onKeyDown:a.onKeyDown}),c.default.createElement("div",{className:e+" "+a.props.selectClass,onClick:a.displayDialog},t?c.default.createElement("div",{className:"cp-select__selected"},t.value):c.default.createElement("div",{className:"cp-select__selected",style:{color:"#afafaf"}},a.props.placeholder),c.default.createElement("div",{className:"cp-select__icon"})),a.getDialog(a.state.dialogDisplayed,a.props.options))},i=n,l(a,i)}return a(t,e),i(t,[{key:"componentWillMount",value:function(){document.body.addEventListener("click",this.state.close)}},{key:"componentWillUnmount",value:function(){document.body.removeEventListener("click",this.state.close)}},{key:"componentDidMount",value:function(){var e=this.getIndex(this.props.selected);this.setState(function(){return{selectedIndex:-1===e?0:e}})}}]),t}(c.default.Component);t.default=f,"undefined"!=typeof window&&window&&!window.CanopySelect&&(window.CanopySelect=f)},function(e,t){e.exports=React},function(e,t){e.exports=_}]);

@@ -82,3 +82,2 @@ 'use strict';

// up key
if (selectedIndex <= 0) {

@@ -91,7 +90,5 @@ _this.setState({

dialogDisplayed: true,
selectedIndex: selectedIndex === undefined ? 0 : selectedIndex - 1
selectedIndex: selectedIndex - 1
});
}
//positionDialog(scope.collection[scope.selectedIndex]);
} else if (key === 40) {

@@ -107,7 +104,5 @@ // down key

dialogDisplayed: true,
selectedIndex: !selectedIndex ? 0 : selectedIndex + 1
selectedIndex: selectedIndex + 1
});
}
//positionDialog(scope.collection[scope.selectedIndex]);
} else if (key === 27) {

@@ -287,2 +282,12 @@ // escape key

}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
var index = this.getIndex(this.props.selected);
this.setState(function () {
return {
selectedIndex: index === -1 ? 0 : index
};
});
}
}]);

@@ -289,0 +294,0 @@

{
"name": "cpr-select",
"version": "2.3.0",
"version": "2.3.1",
"description": "A consistently styled cross-browser and keyboard friendly select component",

@@ -5,0 +5,0 @@ "main": "lib/select.js",

@@ -36,2 +36,9 @@ import React from 'react';

componentDidMount() {
let index = this.getIndex(this.props.selected);
this.setState(() => ({
selectedIndex: index === -1 ? 0 : index,
}));
}
displayDialog = (e) => {

@@ -62,3 +69,2 @@ if (this.props.disabled) return;

} else if(key === 38) { // up key
if (selectedIndex <= 0) {

@@ -71,10 +77,8 @@ this.setState({

dialogDisplayed: true,
selectedIndex: selectedIndex === undefined ? 0 : selectedIndex - 1
selectedIndex: selectedIndex - 1
});
}
//positionDialog(scope.collection[scope.selectedIndex]);
} else if (key === 40) { // down key
} else if(key === 40) { // down key
if (selectedIndex === this.props.options.length - 1) {

@@ -87,8 +91,5 @@ this.setState({

dialogDisplayed: true,
selectedIndex: !selectedIndex ? 0 : selectedIndex + 1
selectedIndex: selectedIndex + 1
});
}
//positionDialog(scope.collection[scope.selectedIndex]);
} else if(key === 27) { // escape key

@@ -95,0 +96,0 @@ this.setState({

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