react-autocomplete-input
Advanced tools
Comparing version 1.0.24 to 1.0.25
@@ -0,1 +1,4 @@ | ||
### 5th October 2023 - 1.0.25 | ||
- Fixed wrong suggestion list position when text field is scrolled (https://github.com/yury-dymov/react-autocomplete-input/pull/108). Props to fabioimpe | ||
### 29th September 2023 - 1.0.24 | ||
@@ -2,0 +5,0 @@ - Better spacer handling for caret position (https://github.com/yury-dymov/react-autocomplete-input/pull/104/). Props to jaredzwick |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";var e={n:function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,{a:r}),r},d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:function(){return P}}),require("core-js/modules/es.reflect.construct.js"),require("core-js/modules/es.symbol.to-primitive.js"),require("core-js/modules/es.date.to-primitive.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.regexp.constructor.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.array.sort.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.string.match.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.array.index-of.js"),require("core-js/modules/es.array.map.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.object.get-prototype-of.js");var r=require("react"),n=e.n(r),o=require("prop-types"),i=e.n(o),s=require("textarea-caret"),a=e.n(s),u=require("get-input-selection"),l=e.n(u),c=require("lodash.isequal"),f=e.n(c);function p(e){return p="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(e)}var h=["Component","defaultValue","disabled","onBlur","value"];function g(){return g=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t,r){return(t=v(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,v(n.key),n)}}function v(e){var t=function(e,t){if("object"!==p(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!==p(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===p(t)?t:String(t)}function j(e,t){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},j(e,t)}function O(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return S(e)}function S(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function w(e){return w=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},w(e)}var q={Component:i().oneOfType([i().string,i().elementType]),defaultValue:i().string,disabled:i().bool,maxOptions:i().number,onBlur:i().func,onChange:i().func,onKeyDown:i().func,onRequestOptions:i().func,onSelect:i().func,changeOnSelect:i().func,options:i().oneOfType([i().object,i().arrayOf(i().string)]),regex:i().string,matchAny:i().bool,minChars:i().number,requestOnlyIfNoOptions:i().bool,spaceRemovers:i().arrayOf(i().string),spacer:i().string,trigger:i().oneOfType([i().string,i().arrayOf(i().string)]),value:i().string,offsetX:i().number,offsetY:i().number,passThroughEnter:i().bool,passThroughTab:i().bool},k=function(e){!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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&j(e,t)}(p,e);var t,o,i,s,c=(i=p,s=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=w(i);if(s){var r=w(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return O(this,e)});function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),(t=c.call(this,e)).isTrigger=t.isTrigger.bind(S(t)),t.arrayTriggerMatch=t.arrayTriggerMatch.bind(S(t)),t.getMatch=t.getMatch.bind(S(t)),t.handleChange=t.handleChange.bind(S(t)),t.handleKeyDown=t.handleKeyDown.bind(S(t)),t.handleResize=t.handleResize.bind(S(t)),t.handleSelection=t.handleSelection.bind(S(t)),t.updateCaretPosition=t.updateCaretPosition.bind(S(t)),t.updateHelper=t.updateHelper.bind(S(t)),t.resetHelper=t.resetHelper.bind(S(t)),t.renderAutocompleteList=t.renderAutocompleteList.bind(S(t)),t.state={helperVisible:!1,left:0,trigger:null,matchLength:0,matchStart:0,options:[],selection:0,top:0,value:null},t.recentValue=e.defaultValue,t.enableSpaceRemovers=!1,t.refInput=(0,r.createRef)(),t}return t=p,(o=[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handleResize)}},{key:"componentDidUpdate",value:function(e){var t=this.props.options,r=this.state.caret;f()(t,e.options)||this.updateHelper(this.recentValue,r,t)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handleResize)}},{key:"getMatch",value:function(e,t,r){var n=this,o=this.props,i=o.trigger,s=o.matchAny,a=o.regex,u=new RegExp(a),l=i;Array.isArray(l)||(l=new Array(i)),l.sort();var c=r;Array.isArray(r)&&l.forEach((function(e){c[e]=r}));for(var f=this.arrayTriggerMatch(l,u),p=null,h=0;h<f.length;h++)for(var g=f[h],d=g.triggerStr,y=g.triggerMatch,m=g.triggerLength,v=function(){var r=e.substring(j,t).match(u),o=-1;if(m>0){var i=y?j:j-m+1;if(i<0)return"break";if(n.isTrigger(d,e,i)&&(o=i+m),!r&&o<0)return"break"}else{if(r&&j>0)return"continue";if(t-(o=0===j&&r?0:j+1)==0)return"break"}if(o>=0){var a=c[d];if(null==a)return"continue";var l=e.substring(o,t),f=a.filter((function(e){var t=e.toLowerCase().indexOf(l.toLowerCase());return-1!==t&&(s||0===t)})),h=d,g=l.length;p=null===p?{trigger:h,matchStart:o,matchLength:g,options:f}:b(b({},p),{},{trigger:h,matchStart:o,matchLength:g,options:f})}},j=t-1;j>=0;--j){if("break"===v())break}return p}},{key:"arrayTriggerMatch",value:function(e,t){return e.map((function(e){return{triggerStr:e,triggerMatch:e.match(t),triggerLength:e.length}}))}},{key:"isTrigger",value:function(e,t,r){return!e||!e.length||t.substr(r,e.length)===e}},{key:"handleChange",value:function(e){var t=this.props,r=t.onChange,n=t.options,o=t.spaceRemovers,i=t.spacer,s=t.value,a=this.recentValue,u=e.target.value,c=l()(e.target).end;if(u.length||this.setState({helperVisible:!1}),this.recentValue=u,this.setState({caret:c,value:e.target.value}),!u.length||!c)return r(e.target.value);if(this.enableSpaceRemovers&&o.length&&u.length>2&&i.length){for(var f=0;f<Math.max(a.length,u.length);++f)if(a[f]!==u[f]){if(f>=2&&u[f-1]===i&&-1===o.indexOf(u[f-2])&&-1!==o.indexOf(u[f])&&this.getMatch(u.substring(0,f-2),c-3,n)){var p="".concat(u.slice(0,f-1)).concat(u.slice(f,f+1)).concat(u.slice(f-1,f)).concat(u.slice(f+1));return this.updateCaretPosition(f+1),this.refInput.current.value=p,s||this.setState({value:p}),r(p)}break}this.enableSpaceRemovers=!1}return this.updateHelper(u,c,n),s||this.setState({value:e.target.value}),r(e.target.value)}},{key:"handleKeyDown",value:function(e){var t=this.state,r=t.helperVisible,n=t.options,o=t.selection,i=this.props,s=i.onKeyDown,a=i.passThroughEnter,u=i.maxOptions,l=i.passThroughTab,c=u>0?Math.min(n.length,u):n.length;if(r)switch(e.keyCode){case 27:e.preventDefault(),this.resetHelper();break;case 38:e.preventDefault(),c>0&&this.setState({selection:Math.max(0,c+o-1)%c});break;case 40:e.preventDefault(),c>0&&this.setState({selection:(o+1)%c});break;case 14:case 13:a||e.preventDefault(),this.handleSelection(o);break;case 9:l||e.preventDefault(),this.handleSelection(o);break;default:s(e)}else s(e)}},{key:"handleResize",value:function(){this.setState({helperVisible:!1})}},{key:"handleSelection",value:function(e){var t=this.props,r=t.spacer,n=t.onSelect,o=t.changeOnSelect,i=this.state,s=i.matchStart,a=i.matchLength,u=i.options,l=i.trigger,c=u[e],f=this.recentValue,p=0===l.length?"":f.substring(0,s-l.length),h=f.substring(s+a),g={target:this.refInput.current},d=o(l,c);g.target.value="".concat(p).concat(d).concat(r).concat(h),this.handleChange(g),n(g.target.value),this.resetHelper();var b=p.length+d.length+(r?r.length:1);this.updateCaretPosition(b),this.enableSpaceRemovers=!0}},{key:"updateCaretPosition",value:function(e){var t=this;this.setState({caret:e},(function(){return(0,u.setCaretPosition)(t.refInput.current,e)}))}},{key:"updateHelper",value:function(e,t,r){var n=this.refInput.current,o=this.getMatch(e,t,r);if(o){var i=a()(n,t),s=n.getBoundingClientRect(),u=i.top+n.offsetTop,l=Math.min(i.left+n.offsetLeft-10,n.offsetLeft+s.width-100),c=this.props,f=c.minChars,p=c.onRequestOptions,h=c.requestOnlyIfNoOptions;o.matchLength>=f&&(o.options.length>1||1===o.options.length&&(o.options[0].length!==o.matchLength||1===o.options[0].length))?this.setState(b({helperVisible:!0,top:u,left:l},o)):(h&&o.options.length||p(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,t=this.state,r=t.helperVisible,o=t.left,i=t.matchStart,s=t.matchLength,a=t.options,u=t.selection,l=t.top,c=t.value;if(!r)return null;var f=this.props,p=f.maxOptions,h=f.offsetX,g=f.offsetY;if(0===a.length)return null;if(u>=a.length)return this.setState({selection:0}),null;var d=0===p?a.length:p,b=a.slice(0,d).map((function(t,r){var o=t.toLowerCase().indexOf(c.substr(i,s).toLowerCase());return n().createElement("li",{className:r===u?"active":null,key:t,onClick:function(){e.handleSelection(r)},onMouseEnter:function(){e.setState({selection:r})}},t.slice(0,o),n().createElement("strong",null,t.substr(o,s)),t.slice(o+s))}));return n().createElement("ul",{className:"react-autocomplete-input",style:{left:o+h,top:l+g}},b)}},{key:"render",value:function(){var e=this.props,t=e.Component,r=e.defaultValue,o=e.disabled,i=e.onBlur,s=e.value,a=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,h),u=this.state.value,l=Object.assign({},a);Object.keys(q).forEach((function(e){delete l[e]}));var c="";return null!=s?c=s:u?c=u:r&&(c=r),n().createElement(n().Fragment,null,n().createElement(t,g({disabled:o,onBlur:i,onChange:this.handleChange,onKeyDown:this.handleKeyDown,ref:this.refInput,value:c},l)),this.renderAutocompleteList())}}])&&m(t.prototype,o),Object.defineProperty(t,"prototype",{writable:!1}),p}(n().Component);k.propTypes=q,k.defaultProps={Component:"textarea",defaultValue:"",disabled:!1,maxOptions:6,onBlur:function(){},onChange:function(){},onKeyDown:function(){},onRequestOptions:function(){},onSelect:function(){},changeOnSelect:function(e,t){return e+t},options:[],regex:"^[A-Za-z0-9\\-_]+$",matchAny:!1,minChars:0,requestOnlyIfNoOptions:!0,spaceRemovers:[",",".","!","?"],spacer:" ",trigger:"@",offsetX:0,offsetY:0,value:null,passThroughEnter:!1,passThroughTab:!0};var P=k;module.exports=t}(); | ||
!function(){"use strict";var e={n:function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,{a:r}),r},d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:function(){return P}}),require("core-js/modules/es.reflect.construct.js"),require("core-js/modules/es.symbol.to-primitive.js"),require("core-js/modules/es.date.to-primitive.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.number.constructor.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.regexp.constructor.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.array.sort.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.string.match.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.array.index-of.js"),require("core-js/modules/es.array.map.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.object.get-prototype-of.js");var r=require("react"),n=e.n(r),o=require("prop-types"),i=e.n(o),s=require("textarea-caret"),a=e.n(s),u=require("get-input-selection"),l=e.n(u),c=require("lodash.isequal"),f=e.n(c);function p(e){return p="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(e)}var h=["Component","defaultValue","disabled","onBlur","value"];function g(){return g=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){y(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function y(e,t,r){return(t=v(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,v(n.key),n)}}function v(e){var t=function(e,t){if("object"!==p(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!==p(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===p(t)?t:String(t)}function j(e,t){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},j(e,t)}function O(e,t){if(t&&("object"===p(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return S(e)}function S(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function w(e){return w=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},w(e)}var q={Component:i().oneOfType([i().string,i().elementType]),defaultValue:i().string,disabled:i().bool,maxOptions:i().number,onBlur:i().func,onChange:i().func,onKeyDown:i().func,onRequestOptions:i().func,onSelect:i().func,changeOnSelect:i().func,options:i().oneOfType([i().object,i().arrayOf(i().string)]),regex:i().string,matchAny:i().bool,minChars:i().number,requestOnlyIfNoOptions:i().bool,spaceRemovers:i().arrayOf(i().string),spacer:i().string,trigger:i().oneOfType([i().string,i().arrayOf(i().string)]),value:i().string,offsetX:i().number,offsetY:i().number,passThroughEnter:i().bool,passThroughTab:i().bool},k=function(e){!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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&j(e,t)}(p,e);var t,o,i,s,c=(i=p,s=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=w(i);if(s){var r=w(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return O(this,e)});function p(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,p),(t=c.call(this,e)).isTrigger=t.isTrigger.bind(S(t)),t.arrayTriggerMatch=t.arrayTriggerMatch.bind(S(t)),t.getMatch=t.getMatch.bind(S(t)),t.handleChange=t.handleChange.bind(S(t)),t.handleKeyDown=t.handleKeyDown.bind(S(t)),t.handleResize=t.handleResize.bind(S(t)),t.handleSelection=t.handleSelection.bind(S(t)),t.updateCaretPosition=t.updateCaretPosition.bind(S(t)),t.updateHelper=t.updateHelper.bind(S(t)),t.resetHelper=t.resetHelper.bind(S(t)),t.renderAutocompleteList=t.renderAutocompleteList.bind(S(t)),t.state={helperVisible:!1,left:0,trigger:null,matchLength:0,matchStart:0,options:[],selection:0,top:0,value:null},t.recentValue=e.defaultValue,t.enableSpaceRemovers=!1,t.refInput=(0,r.createRef)(),t}return t=p,(o=[{key:"componentDidMount",value:function(){window.addEventListener("resize",this.handleResize)}},{key:"componentDidUpdate",value:function(e){var t=this.props.options,r=this.state.caret;f()(t,e.options)||this.updateHelper(this.recentValue,r,t)}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.handleResize)}},{key:"getMatch",value:function(e,t,r){var n=this,o=this.props,i=o.trigger,s=o.matchAny,a=o.regex,u=new RegExp(a),l=i;Array.isArray(l)||(l=new Array(i)),l.sort();var c=r;Array.isArray(r)&&l.forEach((function(e){c[e]=r}));for(var f=this.arrayTriggerMatch(l,u),p=null,h=0;h<f.length;h++)for(var g=f[h],d=g.triggerStr,y=g.triggerMatch,m=g.triggerLength,v=function(){var r=e.substring(j,t).match(u),o=-1;if(m>0){var i=y?j:j-m+1;if(i<0)return"break";if(n.isTrigger(d,e,i)&&(o=i+m),!r&&o<0)return"break"}else{if(r&&j>0)return"continue";if(t-(o=0===j&&r?0:j+1)==0)return"break"}if(o>=0){var a=c[d];if(null==a)return"continue";var l=e.substring(o,t),f=a.filter((function(e){var t=e.toLowerCase().indexOf(l.toLowerCase());return-1!==t&&(s||0===t)})),h=d,g=l.length;p=null===p?{trigger:h,matchStart:o,matchLength:g,options:f}:b(b({},p),{},{trigger:h,matchStart:o,matchLength:g,options:f})}},j=t-1;j>=0;--j){if("break"===v())break}return p}},{key:"arrayTriggerMatch",value:function(e,t){return e.map((function(e){return{triggerStr:e,triggerMatch:e.match(t),triggerLength:e.length}}))}},{key:"isTrigger",value:function(e,t,r){return!e||!e.length||t.substr(r,e.length)===e}},{key:"handleChange",value:function(e){var t=this.props,r=t.onChange,n=t.options,o=t.spaceRemovers,i=t.spacer,s=t.value,a=this.recentValue,u=e.target.value,c=l()(e.target).end;if(u.length||this.setState({helperVisible:!1}),this.recentValue=u,this.setState({caret:c,value:e.target.value}),!u.length||!c)return r(e.target.value);if(this.enableSpaceRemovers&&o.length&&u.length>2&&i.length){for(var f=0;f<Math.max(a.length,u.length);++f)if(a[f]!==u[f]){if(f>=2&&u[f-1]===i&&-1===o.indexOf(u[f-2])&&-1!==o.indexOf(u[f])&&this.getMatch(u.substring(0,f-2),c-3,n)){var p="".concat(u.slice(0,f-1)).concat(u.slice(f,f+1)).concat(u.slice(f-1,f)).concat(u.slice(f+1));return this.updateCaretPosition(f+1),this.refInput.current.value=p,s||this.setState({value:p}),r(p)}break}this.enableSpaceRemovers=!1}return this.updateHelper(u,c,n),s||this.setState({value:e.target.value}),r(e.target.value)}},{key:"handleKeyDown",value:function(e){var t=this.state,r=t.helperVisible,n=t.options,o=t.selection,i=this.props,s=i.onKeyDown,a=i.passThroughEnter,u=i.maxOptions,l=i.passThroughTab,c=u>0?Math.min(n.length,u):n.length;if(r)switch(e.keyCode){case 27:e.preventDefault(),this.resetHelper();break;case 38:e.preventDefault(),c>0&&this.setState({selection:Math.max(0,c+o-1)%c});break;case 40:e.preventDefault(),c>0&&this.setState({selection:(o+1)%c});break;case 14:case 13:a||e.preventDefault(),this.handleSelection(o);break;case 9:l||e.preventDefault(),this.handleSelection(o);break;default:s(e)}else s(e)}},{key:"handleResize",value:function(){this.setState({helperVisible:!1})}},{key:"handleSelection",value:function(e){var t=this.props,r=t.spacer,n=t.onSelect,o=t.changeOnSelect,i=this.state,s=i.matchStart,a=i.matchLength,u=i.options,l=i.trigger,c=u[e],f=this.recentValue,p=0===l.length?"":f.substring(0,s-l.length),h=f.substring(s+a),g={target:this.refInput.current},d=o(l,c);g.target.value="".concat(p).concat(d).concat(r).concat(h),this.handleChange(g),n(g.target.value),this.resetHelper();var b=p.length+d.length+(r?r.length:1);this.updateCaretPosition(b),this.enableSpaceRemovers=!0}},{key:"updateCaretPosition",value:function(e){var t=this;this.setState({caret:e},(function(){return(0,u.setCaretPosition)(t.refInput.current,e)}))}},{key:"updateHelper",value:function(e,t,r){var n=this.refInput.current,o=this.getMatch(e,t,r);if(o){var i=a()(n,t),s=n.getBoundingClientRect(),u=i.top+n.offsetTop-n.scrollTop,l=Math.min(i.left+n.offsetLeft-10,n.offsetLeft+s.width-100),c=this.props,f=c.minChars,p=c.onRequestOptions,h=c.requestOnlyIfNoOptions;o.matchLength>=f&&(o.options.length>1||1===o.options.length&&(o.options[0].length!==o.matchLength||1===o.options[0].length))?this.setState(b({helperVisible:!0,top:u,left:l},o)):(h&&o.options.length||p(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,t=this.state,r=t.helperVisible,o=t.left,i=t.matchStart,s=t.matchLength,a=t.options,u=t.selection,l=t.top,c=t.value;if(!r)return null;var f=this.props,p=f.maxOptions,h=f.offsetX,g=f.offsetY;if(0===a.length)return null;if(u>=a.length)return this.setState({selection:0}),null;var d=0===p?a.length:p,b=a.slice(0,d).map((function(t,r){var o=t.toLowerCase().indexOf(c.substr(i,s).toLowerCase());return n().createElement("li",{className:r===u?"active":null,key:t,onClick:function(){e.handleSelection(r)},onMouseEnter:function(){e.setState({selection:r})}},t.slice(0,o),n().createElement("strong",null,t.substr(o,s)),t.slice(o+s))}));return n().createElement("ul",{className:"react-autocomplete-input",style:{left:o+h,top:l+g}},b)}},{key:"render",value:function(){var e=this.props,t=e.Component,r=e.defaultValue,o=e.disabled,i=e.onBlur,s=e.value,a=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,h),u=this.state.value,l=Object.assign({},a);Object.keys(q).forEach((function(e){delete l[e]}));var c="";return null!=s?c=s:u?c=u:r&&(c=r),n().createElement(n().Fragment,null,n().createElement(t,g({disabled:o,onBlur:i,onChange:this.handleChange,onKeyDown:this.handleKeyDown,ref:this.refInput,value:c},l)),this.renderAutocompleteList())}}])&&m(t.prototype,o),Object.defineProperty(t,"prototype",{writable:!1}),p}(n().Component);k.propTypes=q,k.defaultProps={Component:"textarea",defaultValue:"",disabled:!1,maxOptions:6,onBlur:function(){},onChange:function(){},onKeyDown:function(){},onRequestOptions:function(){},onSelect:function(){},changeOnSelect:function(e,t){return e+t},options:[],regex:"^[A-Za-z0-9\\-_]+$",matchAny:!1,minChars:0,requestOnlyIfNoOptions:!0,spaceRemovers:[",",".","!","?"],spacer:" ",trigger:"@",offsetX:0,offsetY:0,value:null,passThroughEnter:!1,passThroughTab:!0};var P=k;module.exports=t}(); |
{ | ||
"name": "react-autocomplete-input", | ||
"version": "1.0.24", | ||
"version": "1.0.25", | ||
"description": "Autocomplete input field for React", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
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
28762