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

react-autocomplete-input

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-autocomplete-input - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

dist/bundle.js

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

module.exports=function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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)}Object.defineProperty(t,"__esModule",{value:!0});var l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},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},p=function(){function e(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)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),h=n(4),c=r(h),f=n(5),d=n(6),g=r(d),y=n(3),v=r(y);n(2);var b=38,m=40,O=13,w=14,P=27,S=10,k=100,x={Component:h.PropTypes.string,defaultValue:h.PropTypes.string,disabled:h.PropTypes.bool,maxOptions:h.PropTypes.number,onBlur:h.PropTypes.func,onChange:h.PropTypes.func,onKeyDown:h.PropTypes.func,onRequestOptions:h.PropTypes.func,options:h.PropTypes.array,regex:h.PropTypes.string,requestOnlyIfNoOptions:h.PropTypes.bool,spaceRemovers:h.PropTypes.array,trigger:h.PropTypes.string,value:h.PropTypes.any},C={Component:"textarea",defaultValue:"",disabled:!1,maxOptions:6,onBlur:function(){},onChange:function(){},onKeyDown:function(){},onRequestOptions:function(){},options:[],regex:"^[A-Za-z0-9\\-_]+$",requestOnlyIfNoOptions:!0,spaceRemovers:[",",".","!","?"],trigger:"@"},T=function(e){function t(e){i(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.isTrigger=n.isTrigger.bind(n),n.getMatch=n.getMatch.bind(n),n.handleBlur=n.handleBlur.bind(n),n.handleChange=n.handleChange.bind(n),n.handleKeyDown=n.handleKeyDown.bind(n),n.handleResize=n.handleResize.bind(n),n.handleSelection=n.handleSelection.bind(n),n.updateCaretPosition=n.updateCaretPosition.bind(n),n.updateHelper=n.updateHelper.bind(n),n.resetHelper=n.resetHelper.bind(n),n.renderAutocompleteList=n.renderAutocompleteList.bind(n),n.state={helperVisible:!1,left:0,matchLength:0,matchStart:0,options:[],selection:0,top:0,value:null},n.recentValue=e.defaultValue,n}return a(t,e),p(t,[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handleResize)}},{key:"componentWillReceiveProps",value:function(e){e.options.length!==this.props.options.length&&this.updateHelper(this.recentValue,this.state.caret,e.options)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handleResize)}},{key:"getMatch",value:function(e,t,n){for(var r=this.props.trigger.length,o=t-1;o>=0;--o){var i=new RegExp(this.props.regex),s=e.substring(o,t),a=s.match(i);if(!a){if(!r&&1===s.length)return null;var l=o-r+1;if(l<0)return null;if(this.isTrigger(e,l)){var p=function(){var e=s.substring(1,s.length),t=n.filter(function(t){return t.substring(0,e.length)===e}),r=e.length,i=o+1;return{v:{matchLength:r,matchStart:i,options:t}}}();if("object"===("undefined"==typeof p?"undefined":u(p)))return p.v}break}}return null}},{key:"isTrigger",value:function(e,t){var n=this.props.trigger;return!n||!n.length||e.substr(t,n.length)===n}},{key:"handleBlur",value:function(){var e=this;setTimeout(function(){return e.setState({helperVisible:!1})},50),this.props.onBlur()}},{key:"handleChange",value:function(e){var t=this.props,n=t.onChange,r=t.options,o=t.spaceRemovers,i=this.recentValue,s=e.target.value,a=(0,v["default"])(e.target).end;if(s.length||this.setState({helperVisible:!1}),this.recentValue=s,this.setState({caret:a,value:e.target.value}),!s.length||!a)return n(e.target.value);if(o.length&&s.length>2)for(var l=0;l<Math.max(i.length,s.length);++l)if(i[l]!==s[l]){if(l>=2&&" "===s[l-1]&&o.indexOf(s[l-2])===-1&&o.indexOf(s[l])!==-1&&this.getMatch(s.substring(0,l-2).toLowerCase(),a-3,r)){var u=""+s.slice(0,l-1)+s.slice(l,s.length)+" ";return this.updateCaretPosition(l+1),(0,f.findDOMNode)(this.refInput).value=u,this.props.value||this.setState({value:u}),n(u)}break}return this.updateHelper(s,a,r),this.props.value||this.setState({value:e.target.value}),n(e.target.value)}},{key:"handleKeyDown",value:function(e){if(this.state.helperVisible){var t=this.state,n=t.options,r=t.selection;switch(e.keyCode){case P:e.preventDefault(),this.resetHelper();break;case b:e.preventDefault(),this.setState({selection:(n.length+r-1)%n.length});break;case m:e.preventDefault(),this.setState({selection:(r+1)%n.length});break;case w:case O:e.preventDefault(),this.handleSelection(r);break;default:this.props.onKeyDown(e)}}else this.props.onKeyDown(e)}},{key:"handleResize",value:function(){this.setState({helperVisible:!1})}},{key:"handleSelection",value:function(e){var t=this.state,n=t.matchStart,r=t.matchLength,o=t.options,i=this.props.trigger,s=i.length,a=o[e],l=this.recentValue,u=l.substring(0,n-s),p=l.substring(n+r+s,l.length),h={target:(0,f.findDOMNode)(this.refInput)};h.target.value=""+u+i+a+" "+p,this.handleChange(h),this.resetHelper(),this.updateCaretPosition(u.length+a.length+s+1)}},{key:"updateCaretPosition",value:function(e){var t=this;this.setState({caret:e},function(){return(0,y.setCaretPosition)((0,f.findDOMNode)(t.refInput),e)})}},{key:"updateHelper",value:function(e,t,n){var r=(0,f.findDOMNode)(this.refInput),o=this.getMatch(e.toLowerCase(),t,n);if(o){var i=(0,g["default"])(r,t),s=r.getBoundingClientRect(),a=i.top+s.top+15+window.scrollY,u=Math.min(i.left+s.left-S,s.left+s.width-k);o.options.length>1||1===o.options.length&&o.options[0].length!==o.matchLength?this.setState(l({helperVisible:!0,top:a,left:u},o)):(this.props.requestOnlyIfNoOptions&&o.options.length||this.props.onRequestOptions(e.substr(o.matchStart,o.matchLength)),this.resetHelper())}else this.resetHelper()}},{key:"resetHelper",value:function(){this.setState({helperVisible:!1,selection:0})}},{key:"renderAutocompleteList",value:function(){var e=this;if(!this.state.helperVisible)return null;var t=this.state,n=t.left,r=t.matchLength,o=t.options,i=t.selection,s=t.top,a=0===this.props.maxOptions?o.length:this.props.maxOptions,l=o.slice(0,a).map(function(t,n){return c["default"].createElement("li",{className:n===i?"active":null,key:t,onClick:function(){e.handleSelection(n)},onMouseEnter:function(){e.setState({selection:n})}},c["default"].createElement("b",null,t.substr(0,r)),t.substr(r,t.length))});return c["default"].createElement("ul",{className:"react-autocomplete-input",style:{left:n,top:s}},l)}},{key:"render",value:function(){var e=this,t=this.props,n=t.Component,r=t.defaultValue,i=t.disabled,s=t.value,a=o(t,["Component","defaultValue","disabled","value"]),u=Object.assign({},a);Object.keys(this.constructor.propTypes).forEach(function(e){delete u[e]});var p="";return"undefined"!=typeof s&&null!==s?p=s:this.state.value?p=this.state.value:r&&(p=r),c["default"].createElement("span",null,c["default"].createElement(n,l({disabled:i,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,ref:function(t){e.refInput=t},value:p},u)),this.renderAutocompleteList())}}]),t}(c["default"].Component);T.propTypes=x,T.defaultProps=C,t["default"]=T},function(e,t){},function(e,t){e.exports=require("get-input-selection")},function(e,t){e.exports=require("react")},function(e,t){e.exports=require("react-dom")},function(e,t){e.exports=require("textarea-caret")}]);
module.exports=function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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)}Object.defineProperty(t,"__esModule",{value:!0});var l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},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},p=function(){function e(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)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),h=n(4),c=r(h),f=n(5),d=n(6),g=r(d),y=n(3),v=r(y);n(2);var b=38,m=40,O=13,P=14,w=27,S=10,k=100,x={Component:h.PropTypes.string,defaultValue:h.PropTypes.string,disabled:h.PropTypes.bool,maxOptions:h.PropTypes.number,onBlur:h.PropTypes.func,onChange:h.PropTypes.func,onKeyDown:h.PropTypes.func,onRequestOptions:h.PropTypes.func,options:h.PropTypes.array,regex:h.PropTypes.string,requestOnlyIfNoOptions:h.PropTypes.bool,spaceRemovers:h.PropTypes.array,trigger:h.PropTypes.string,value:h.PropTypes.any},C={Component:"textarea",defaultValue:"",disabled:!1,maxOptions:6,onBlur:function(){},onChange:function(){},onKeyDown:function(){},onRequestOptions:function(){},options:[],regex:"^[A-Za-z0-9\\-_]+$",requestOnlyIfNoOptions:!0,spaceRemovers:[",",".","!","?"],trigger:"@"},T=function(e){function t(e){i(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.isTrigger=n.isTrigger.bind(n),n.getMatch=n.getMatch.bind(n),n.handleBlur=n.handleBlur.bind(n),n.handleChange=n.handleChange.bind(n),n.handleKeyDown=n.handleKeyDown.bind(n),n.handleResize=n.handleResize.bind(n),n.handleSelection=n.handleSelection.bind(n),n.updateCaretPosition=n.updateCaretPosition.bind(n),n.updateHelper=n.updateHelper.bind(n),n.resetHelper=n.resetHelper.bind(n),n.renderAutocompleteList=n.renderAutocompleteList.bind(n),n.state={helperVisible:!1,left:0,matchLength:0,matchStart:0,options:[],selection:0,top:0,value:null},n.recentValue=e.defaultValue,n}return a(t,e),p(t,[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handleResize)}},{key:"componentWillReceiveProps",value:function(e){e.options.length!==this.props.options.length&&this.updateHelper(this.recentValue,this.state.caret,e.options)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handleResize)}},{key:"getMatch",value:function(e,t,n){for(var r=this.props.trigger.length,o=t-1;o>=0;--o){var i=new RegExp(this.props.regex),s=e.substring(o,t),a=s.match(i);if(!a){if(!r&&1===s.length)return null;var l=o-r+1;if(l<0)return null;if(this.isTrigger(e,l)){var p=function(){var e=s.substring(1,s.length),t=n.filter(function(t){return t.substring(0,e.length)===e}),r=e.length,i=o+1;return{v:{matchLength:r,matchStart:i,options:t}}}();if("object"===("undefined"==typeof p?"undefined":u(p)))return p.v}break}}return null}},{key:"isTrigger",value:function(e,t){var n=this.props.trigger;return!n||!n.length||e.substr(t,n.length)===n}},{key:"handleBlur",value:function(){var e=this;setTimeout(function(){return e.setState({helperVisible:!1})},50),this.props.onBlur()}},{key:"handleChange",value:function(e){var t=this.props,n=t.onChange,r=t.options,o=t.spaceRemovers,i=this.recentValue,s=e.target.value,a=(0,v.default)(e.target).end;if(s.length||this.setState({helperVisible:!1}),this.recentValue=s,this.setState({caret:a,value:e.target.value}),!s.length||!a)return n(e.target.value);if(o.length&&s.length>2)for(var l=0;l<Math.max(i.length,s.length);++l)if(i[l]!==s[l]){if(l>=2&&" "===s[l-1]&&o.indexOf(s[l-2])===-1&&o.indexOf(s[l])!==-1&&this.getMatch(s.substring(0,l-2).toLowerCase(),a-3,r)){var u=""+s.slice(0,l-1)+s.slice(l,s.length)+" ";return this.updateCaretPosition(l+1),(0,f.findDOMNode)(this.refInput).value=u,this.props.value||this.setState({value:u}),n(u)}break}return this.updateHelper(s,a,r),this.props.value||this.setState({value:e.target.value}),n(e.target.value)}},{key:"handleKeyDown",value:function(e){if(this.state.helperVisible){var t=this.state,n=t.options,r=t.selection;switch(e.keyCode){case w:e.preventDefault(),this.resetHelper();break;case b:e.preventDefault(),this.setState({selection:(n.length+r-1)%n.length});break;case m:e.preventDefault(),this.setState({selection:(r+1)%n.length});break;case P:case O:e.preventDefault(),this.handleSelection(r);break;default:this.props.onKeyDown(e)}}else this.props.onKeyDown(e)}},{key:"handleResize",value:function(){this.setState({helperVisible:!1})}},{key:"handleSelection",value:function(e){var t=this.state,n=t.matchStart,r=t.matchLength,o=t.options,i=this.props.trigger,s=i.length,a=o[e],l=this.recentValue,u=l.substring(0,n-s),p=l.substring(n+r+s,l.length),h={target:(0,f.findDOMNode)(this.refInput)};h.target.value=""+u+i+a+" "+p,this.handleChange(h),this.resetHelper(),this.updateCaretPosition(u.length+a.length+s+1)}},{key:"updateCaretPosition",value:function(e){var t=this;this.setState({caret:e},function(){return(0,y.setCaretPosition)((0,f.findDOMNode)(t.refInput),e)})}},{key:"updateHelper",value:function(e,t,n){var r=(0,f.findDOMNode)(this.refInput),o=this.getMatch(e.toLowerCase(),t,n);if(o){var i=(0,g.default)(r,t),s=r.getBoundingClientRect(),a=i.top+r.offsetTop,u=Math.min(i.left+r.offsetLeft-S,r.offsetLeft+s.width-k);o.options.length>1||1===o.options.length&&o.options[0].length!==o.matchLength?this.setState(l({helperVisible:!0,top:a,left:u},o)):(this.props.requestOnlyIfNoOptions&&o.options.length||this.props.onRequestOptions(e.substr(o.matchStart,o.matchLength)),this.resetHelper())}else this.resetHelper()}},{key:"resetHelper",value:function(){this.setState({helperVisible:!1,selection:0})}},{key:"renderAutocompleteList",value:function(){var e=this;if(!this.state.helperVisible)return null;var t=this.state,n=t.left,r=t.matchLength,o=t.options,i=t.selection,s=t.top,a=0===this.props.maxOptions?o.length:this.props.maxOptions,l=o.slice(0,a).map(function(t,n){return c.default.createElement("li",{className:n===i?"active":null,key:t,onClick:function(){e.handleSelection(n)},onMouseEnter:function(){e.setState({selection:n})}},c.default.createElement("b",null,t.substr(0,r)),t.substr(r,t.length))});return c.default.createElement("ul",{className:"react-autocomplete-input",style:{left:n,top:s}},l)}},{key:"render",value:function(){var e=this,t=this.props,n=t.Component,r=t.defaultValue,i=t.disabled,s=t.value,a=o(t,["Component","defaultValue","disabled","value"]),u=Object.assign({},a);Object.keys(this.constructor.propTypes).forEach(function(e){delete u[e]});var p="";return"undefined"!=typeof s&&null!==s?p=s:this.state.value?p=this.state.value:r&&(p=r),c.default.createElement("span",null,c.default.createElement(n,l({disabled:i,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,ref:function(t){e.refInput=t},value:p},u)),this.renderAutocompleteList())}}]),t}(c.default.Component);T.propTypes=x,T.defaultProps=C,t.default=T},function(e,t){},function(e,t){e.exports=require("get-input-selection")},function(e,t){e.exports=require("react")},function(e,t){e.exports=require("react-dom")},function(e,t){e.exports=require("textarea-caret")}]);
{
"name": "react-autocomplete-input",
"version": "1.0.0",
"version": "1.0.1",
"description": "Autocomplete input field for React",

@@ -5,0 +5,0 @@ "main": "dist/bundle.js",

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