react-datalist-input
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,2 +0,2 @@ | ||
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){e.exports=n(5)()},function(e,t,n){"use strict";e.exports=n(3)},function(e,t,n){"use strict";n.r(t);var r=n(1),o=n.n(r),i=n(0),a=n.n(i);n(7);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var d=function(e){function t(e){var n,r,i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),r=this,i=s(t).call(this,e),n=!i||"object"!==u(i)&&"function"!=typeof i?l(r):i,p(l(n),"onHandleInput",function(e){var t=e.target.value,r=n.props,o=r.items,i=r.match,a=o.filter(function(e){return u(i)===("undefined"==typeof Function?"undefined":u(Function))?i(t,e):n.match(t,e)});n.setState({currentInput:t,matchingItems:a,focusIndex:0,visible:!0})}),p(l(n),"match",function(e,t){return t.label.substr(0,e.length).toUpperCase()===e.toUpperCase()}),p(l(n),"indexOfMatch",function(e,t){return t.label.toUpperCase().indexOf(e.toUpperCase())}),p(l(n),"onHandleKeydown",function(e){var t=n.state,r=t.visible,o=t.focusIndex,i=t.matchingItems;if(r){var a=o;if(40===e.keyCode||9===e.keyCode)(a+=1)>=i.length&&(a=0),n.setState({focusIndex:a}),e.preventDefault();else if(38===e.keyCode)(a-=1)<=-1&&(a=i.length-1),n.setState({focusIndex:a});else if(13===e.keyCode&&o>-1){var u=i[a];n.onSelect(u)}}}),p(l(n),"onClickItem",function(e){for(var t,r=n.state.matchingItems,o=e.currentTarget.children,i=0;i<o.length;i+=1)if("INPUT"===o[i].tagName){t=Number(o[i].value);break}var a=r.find(function(e){return e.key===t});n.onSelect(a)}),p(l(n),"onSelect",function(e){console.log(e);var t=n.state.lastValidItem;t&&e.key===t.key?n.setState({currentInput:e.label,visible:!1,focusIndex:-1}):(n.setState({currentInput:e.label,lastValidItem:e,visible:!1,focusIndex:-1}),(0,n.props.onSelect)(e))}),p(l(n),"renderItemLabel",function(e,t){return o.a.createElement(o.a.Fragment,null,t.label.substr(0,n.indexOfMatch(e,t)),o.a.createElement("strong",null,t.label.substr(n.indexOfMatch(e,t),e.length)),t.label.substr(n.indexOfMatch(e,t)+e.length))}),p(l(n),"renderItems",function(e,t,r,i,a){return o.a.createElement("div",{className:"datalist-items"},t.map(function(t,u){var c=r===u?"datalist-active-item ".concat(i):"",s="".concat(a," ").concat(c,";");return o.a.createElement("div",{onClick:n.onClickItem,className:s,key:t.key,tabIndex:0,role:"button",onKeyUp:function(e){return e.preventDefault()}},n.renderItemLabel(e,t),o.a.createElement("input",{type:"hidden",value:t.key}))}))}),p(l(n),"renderInputField",function(e,t,r){return o.a.createElement("input",{onChange:n.onHandleInput,onKeyDown:n.onHandleKeydown,type:"text",className:"autocomplete-input ".concat(r),placeholder:e,value:t})}),n.state={lastValidItem:void 0,currentInput:"",matchingItems:[],visible:!1,focusIndex:0},n}var n,r,i;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}(t,o.a.Component),n=t,(r=[{key:"render",value:function(){var e=this.state,t=e.currentInput,n=e.matchingItems,r=e.focusIndex,i=e.visible,a=this.props,u=a.placeholder,c=a.inputClassName,s=a.activeItemClassName,l=a.itemClassName,f=a.requiredInputLength,p=t.length>=f;return o.a.createElement("div",{className:"datalist-input"},this.renderInputField(u,t,c),p&&i&&this.renderItems(t,n,r,s,l))}}])&&c(n.prototype,r),i&&c(n,i),t}();d.propTypes={items:a.a.arrayOf(a.a.shape({label:a.a.string.isRequired,key:a.a.number.isRequired})).isRequired,placeholder:a.a.string,onSelect:a.a.func.isRequired,match:a.a.func,inputClassName:a.a.string,itemClassName:a.a.string,activeItemClassName:a.a.string,requiredInputLength:a.a.number},d.defaultProps={placeholder:"",match:void 0,inputClassName:"",itemClassName:"",activeItemClassName:"",requiredInputLength:1},t.default=d},function(e,t,n){"use strict"; | ||
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t,n){e.exports=n(5)()},function(e,t,n){"use strict";e.exports=n(3)},function(e,t,n){"use strict";n.r(t);var r=n(1),o=n.n(r),i=n(0),a=n.n(i);n(7);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var d=function(e){function t(e){var n,r,i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),r=this,i=s(t).call(this,e),n=!i||"object"!==u(i)&&"function"!=typeof i?l(r):i,p(l(n),"onHandleInput",function(e){var t=e.target.value,r=n.props,o=r.items,i=r.match,a=o.filter(function(e){return u(i)===("undefined"==typeof Function?"undefined":u(Function))?i(t,e):n.match(t,e)});n.setState({currentInput:t,matchingItems:a,focusIndex:0,visible:!0})}),p(l(n),"match",function(e,t){return t.label.substr(0,e.length).toUpperCase()===e.toUpperCase()}),p(l(n),"indexOfMatch",function(e,t){return t.label.toUpperCase().indexOf(e.toUpperCase())}),p(l(n),"onHandleKeydown",function(e){var t=n.state,r=t.visible,o=t.focusIndex,i=t.matchingItems;if(r){var a=o;if(40===e.keyCode||9===e.keyCode)(a+=1)>=i.length&&(a=0),n.setState({focusIndex:a}),e.preventDefault();else if(38===e.keyCode)(a-=1)<=-1&&(a=i.length-1),n.setState({focusIndex:a});else if(13===e.keyCode&&o>-1){var u=i[a];n.onSelect(u)}}}),p(l(n),"onClickItem",function(e){for(var t,r=n.state.matchingItems,o=e.currentTarget.children,i=0;i<o.length;i+=1)if("INPUT"===o[i].tagName){t=Number(o[i].value);break}var a=r.find(function(e){return e.key===t});n.onSelect(a)}),p(l(n),"onSelect",function(e){console.log(e);var t=n.state.lastValidItem;t&&e.key===t.key?n.setState({currentInput:e.label,visible:!1,focusIndex:-1}):(n.setState({currentInput:e.label,lastValidItem:e,visible:!1,focusIndex:-1}),(0,n.props.onSelect)(e))}),p(l(n),"renderItemLabel",function(e,t){return o.a.createElement(o.a.Fragment,null,t.label.substr(0,n.indexOfMatch(e,t)),o.a.createElement("strong",null,t.label.substr(n.indexOfMatch(e,t),e.length)),t.label.substr(n.indexOfMatch(e,t)+e.length))}),p(l(n),"renderItems",function(e,t,r,i,a){return o.a.createElement("div",{className:"datalist-items"},t.map(function(t,u){var c=r===u?"datalist-active-item ".concat(i):"",s="".concat(a," ").concat(c,";");return o.a.createElement("div",{onClick:n.onClickItem,className:s,key:t.key,tabIndex:0,role:"button",onKeyUp:function(e){return e.preventDefault()}},n.renderItemLabel(e,t),o.a.createElement("input",{type:"hidden",value:t.key,readOnly:!0}))}))}),p(l(n),"renderInputField",function(e,t,r){return o.a.createElement("input",{onChange:n.onHandleInput,onKeyDown:n.onHandleKeydown,type:"text",className:"autocomplete-input ".concat(r),placeholder:e,value:t})}),n.state={lastValidItem:void 0,currentInput:"",matchingItems:[],visible:!1,focusIndex:0},n}var n,r,i;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}(t,o.a.Component),n=t,(r=[{key:"render",value:function(){var e=this.state,t=e.currentInput,n=e.matchingItems,r=e.focusIndex,i=e.visible,a=this.props,u=a.placeholder,c=a.inputClassName,s=a.activeItemClassName,l=a.itemClassName,f=a.requiredInputLength,p=t.length>=f;return o.a.createElement("div",{className:"datalist-input"},this.renderInputField(u,t,c),p&&i&&this.renderItems(t,n,r,s,l))}}])&&c(n.prototype,r),i&&c(n,i),t}();d.propTypes={items:a.a.arrayOf(a.a.shape({label:a.a.string.isRequired,key:a.a.number.isRequired})).isRequired,placeholder:a.a.string,onSelect:a.a.func.isRequired,match:a.a.func,inputClassName:a.a.string,itemClassName:a.a.string,activeItemClassName:a.a.string,requiredInputLength:a.a.number},d.defaultProps={placeholder:"",match:void 0,inputClassName:"",itemClassName:"",activeItemClassName:"",requiredInputLength:1},t.default=d},function(e,t,n){"use strict"; | ||
/** @license React v16.8.6 | ||
@@ -3,0 +3,0 @@ * react.production.min.js |
{ | ||
"name": "react-datalist-input", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "This package provides a react component as follows: an input field with a drop down menu to pick a possible option based on the current input.", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -172,3 +172,3 @@ import React from 'react'; | ||
{ this.renderItemLabel( currentInput, item )} | ||
<input type="hidden" value={item.key} /> | ||
<input type="hidden" value={item.key} readOnly /> | ||
</div> | ||
@@ -175,0 +175,0 @@ ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
37906
0