react-geosuggest
Advanced tools
Comparing version 2.13.0 to 2.13.1
@@ -0,1 +1,10 @@ | ||
### 2.13.1 (2020-06-19) | ||
#### Bug Fixes | ||
* use secure URLs (#465) ([86ec9227](https://github.com/ubilabs/react-geosuggest/commit/86ec922751c841293540e5396ce6f201b6149112)) | ||
* use a not random id for the list (#464) ([68da464e](https://github.com/ubilabs/react-geosuggest/commit/68da464e26db7af24a742973df523b4909a1ef10)) | ||
## 2.13.0 (2020-05-08) | ||
@@ -2,0 +11,0 @@ |
@@ -518,3 +518,2 @@ var Geosuggest = (function (React) { | ||
'height', | ||
'id', | ||
'inputMode', | ||
@@ -678,9 +677,12 @@ 'maxLength', | ||
var classes = classnames('geosuggest__input', this.props.className); | ||
var shouldRenderLabel = this.props.label && this.props.id; | ||
if (!attributes.tabIndex) { | ||
attributes.tabIndex = 0; | ||
} | ||
return (React.createElement("input", __assign({ className: classes, ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId }))); | ||
return (React.createElement(React.Fragment, null, | ||
shouldRenderLabel && (React.createElement("label", { className: "geosuggest__label", htmlFor: this.props.id }, this.props.label)), | ||
React.createElement("input", __assign({ className: classes, id: "geosuggest__input" + (this.props.id ? "--" + this.props.id : ''), ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId })))); | ||
}; | ||
@@ -925,3 +927,3 @@ /* eslint-disable @typescript-eslint/no-empty-function */ | ||
_this.selectSuggest = _this.selectSuggest.bind(_this); | ||
_this.listId = "geosuggest__list_" + Math.random().toString(16).slice(2); | ||
_this.listId = "geosuggest__list" + (props.id ? "--" + props.id : ''); | ||
if (props.queryDelay) { | ||
@@ -1333,9 +1335,6 @@ _this.onAfterInputChange = lodash_debounce(_this.onAfterInputChange, props.queryDelay); | ||
}); | ||
var shouldRenderLabel = this.props.label && attributes.id; | ||
var input = (React.createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, listId: this.listId }, attributes))); | ||
var input = (React.createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, label: this.props.label, id: this.props.id, listId: this.listId }, attributes))); | ||
var suggestionsList = (React.createElement(default_1$1, { isHidden: this.state.isSuggestsHidden, style: this.props.style && this.props.style.suggests, suggestItemStyle: this.props.style && this.props.style.suggestItem, userInput: this.state.userInput, isHighlightMatch: Boolean(this.props.highlightMatch), suggestsClassName: this.props.suggestsClassName, suggestItemClassName: this.props.suggestItemClassName, suggests: this.state.suggests, hiddenClassName: this.props.suggestsHiddenClassName, suggestItemActiveClassName: this.props.suggestItemActiveClassName, activeSuggest: this.state.activeSuggest, onSuggestNoResults: this.onSuggestNoResults, onSuggestMouseDown: this.onSuggestMouseDown, onSuggestMouseOut: this.onSuggestMouseOut, onSuggestSelect: this.selectSuggest, renderSuggestItem: this.props.renderSuggestItem, listId: this.listId })); | ||
return (React.createElement("div", { className: classes }, | ||
React.createElement("div", { className: "geosuggest__input-wrapper" }, | ||
shouldRenderLabel && (React.createElement("label", { className: "geosuggest__label", htmlFor: attributes.id }, this.props.label)), | ||
input), | ||
return (React.createElement("div", { className: classes, id: this.props.id }, | ||
React.createElement("div", { className: "geosuggest__input-wrapper" }, input), | ||
React.createElement("div", { className: "geosuggest__suggests-wrapper" }, suggestionsList))); | ||
@@ -1342,0 +1341,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
var Geosuggest=function(u){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])})(t,e)};function n(t,e){function s(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}var c=function(){return(c=Object.assign||function(t){for(var e,s=1,o=arguments.length;s<o;s++)for(var n in e=arguments[s])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,r=(function(t){!function(){var r={}.hasOwnProperty;function u(){for(var t=[],e=0;e<arguments.length;e++){var s=arguments[e];if(s){var o=typeof s;if("string"==o||"number"==o)t.push(s);else if(Array.isArray(s)&&s.length){var n=u.apply(null,s);n&&t.push(n)}else if("object"==o)for(var i in s)r.call(s,i)&&s[i]&&t.push(i)}}return t.join(" ")}t.exports?(u.default=u,t.exports=u):window.classNames=u}()}(e={exports:{}},e.exports),e.exports),i=NaN,a="[object Symbol]",p=/^\s+|\s+$/g,g=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,h=/^0o[0-7]+$/i,d=parseInt,s="object"==typeof t&&t&&t.Object===Object&&t,f="object"==typeof self&&self&&self.Object===Object&&self,S=s||f||Function("return this")(),m=Object.prototype.toString,v=Math.max,y=Math.min,b=function(){return S.Date.now()};function I(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function w(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&m.call(t)==a}(t))return i;if(I(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=I(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(p,"");var s=l.test(t);return s||h.test(t)?d(t.slice(2),s?2:8):g.test(t)?i:+t}var C=function(o,s,t){var n,i,r,u,a,p,g=0,l=!1,c=!1,e=!0;if("function"!=typeof o)throw new TypeError("Expected a function");function h(t){var e=n,s=i;return n=i=void 0,g=t,u=o.apply(s,e)}function d(t){var e=t-p;return void 0===p||s<=e||e<0||c&&r<=t-g}function f(){var t=b();if(d(t))return S(t);a=setTimeout(f,function(t){var e=s-(t-p);return c?y(e,r-(t-g)):e}(t))}function S(t){return a=void 0,e&&n?h(t):(n=i=void 0,u)}function m(){var t=b(),e=d(t);if(n=arguments,i=this,p=t,e){if(void 0===a)return function(t){return g=t,a=setTimeout(f,s),l?h(t):u}(p);if(c)return a=setTimeout(f,s),h(p)}return void 0===a&&(a=setTimeout(f,s)),u}return s=w(s)||0,I(t)&&(l=!!t.leading,r=(c="maxWait"in t)?v(w(t.maxWait)||0,s):r,e="trailing"in t?!!t.trailing:e),m.cancel=function(){void 0!==a&&clearTimeout(a),n=p=i=a=void(g=0)},m.flush=function(){return void 0===a?u:S(b())},m},N={autoActivateFirstSuggest:!1,disabled:!1,fixtures:[],getSuggestLabel:function(t){return t.description},highlightMatch:!0,ignoreEnter:!1,ignoreTab:!1,initialValue:"",maxFixtures:10,minLength:1,onKeyDown:function(){},onKeyPress:function(){},placeholder:"Search places",queryDelay:250,skipSuggest:function(){return!1},style:{}},x=["autoCapitalize","autoComplete","autoCorrect","autoFocus","disabled","form","formAction","formEncType","formMethod","formNoValidate","formTarget","height","id","inputMode","maxLength","name","onClick","onContextMenu","onCopy","onCut","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPaste","pattern","placeholder","readOnly","required","size","spellCheck","tabIndex","title","aria-atomic","aria-busy","aria-controls","aria-current","aria-describedby","aria-details","aria-disabled","aria-dropeffect","aria-errormessage","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription","aria-activedescendant","aria-autocomplete","aria-multiline","aria-placeholder","aria-readonly","aria-required"];function M(s){var o={};return Object.keys(s).forEach(function(t){var e=t.startsWith("data-");(x.includes(t)||e)&&(o[t]=s[t])}),o}var D=function(s){function t(t){var e=s.call(this,t)||this;return e.input=null,e.onChange=e.onChange.bind(e),e.onInputKeyDown=e.onInputKeyDown.bind(e),e}return n(t,s),t.prototype.onChange=function(){this.input&&this.props.onChange(this.input.value)},t.prototype.onInputKeyDown=function(t){switch(this.props.onKeyDown&&this.props.onKeyDown(t),t.which){case 40:t.shiftKey||(t.preventDefault(),this.props.onNext());break;case 38:t.shiftKey||(t.preventDefault(),this.props.onPrev());break;case 13:this.props.doNotSubmitOnEnter&&t.preventDefault(),this.props.ignoreEnter||this.props.onSelect();break;case 9:this.props.ignoreTab||this.props.onSelect();break;case 27:this.props.onEscape()}},t.prototype.focus=function(){this.input&&this.input.focus()},t.prototype.blur=function(){this.input&&this.input.blur()},t.prototype.render=function(){var e=this,t=M(this.props),s=r("geosuggest__input",this.props.className);return t.tabIndex||(t.tabIndex=0),u.createElement("input",c({className:s,ref:function(t){return e.input=t},type:"text"},t,{value:this.props.value,style:this.props.style,onKeyDown:this.onInputKeyDown,onChange:this.onChange,onKeyPress:this.props.onKeyPress,onFocus:this.props.onFocus,onBlur:this.props.onBlur,role:"combobox","aria-expanded":!this.props.isSuggestsHidden,"aria-activedescendant":this.props.activeSuggest?this.props.activeSuggest.placeId:void 0,"aria-owns":this.props.listId}))},t.defaultProps={activeSuggest:null,autoComplete:"nope",className:"",isSuggestsHidden:!0,listId:"",onBlur:function(){},onChange:function(){},onEscape:function(){},onFocus:function(){},onKeyDown:function(){},onKeyPress:function(){},onNext:function(){},onPrev:function(){},onSelect:function(){},value:""},t}(u.PureComponent),T=function(s){function t(t){var e=s.call(this,t)||this;return e.ref=null,e.onClick=e.onClick.bind(e),e}return n(t,s),t.prototype.makeBold=function(t,e){return u.createElement("b",{className:"geosuggest__item__matched-text",key:e},t)},t.prototype.formatMatchedText=function(t,e){if(!t||!e.matchedSubstrings)return e.label;var s=e.matchedSubstrings.offset,o=s+e.matchedSubstrings.length,n=this.makeBold(e.label.substring(s,o),e.label),i="",r="";return 0<s&&(i=e.label.slice(0,s)),o<e.label.length&&(r=e.label.slice(o)),u.createElement("span",null,i,n,r)},t.prototype.componentDidUpdate=function(t){!t.isActive&&this.props.isActive&&this.scrollIfNeeded()},t.prototype.scrollIfNeeded=function(){var t=this.ref,e=t&&t.parentElement;if(t&&e){var s=t.offsetTop-e.offsetTop<e.scrollTop,o=t.offsetTop-e.offsetTop+t.clientHeight>e.scrollTop+e.clientHeight;(s||o)&&(e.scrollTop=t.offsetTop-e.offsetTop-e.clientHeight/2+t.clientHeight/2)}},t.prototype.onClick=function(t){t.preventDefault(),this.props.onSelect(this.props.suggest)},t.prototype.render=function(){var t,e=this,s=this.props.suggest,o=r("geosuggest__item",this.props.className,this.props.suggestItemClassName,{"geosuggest__item--active":this.props.isActive},((t={})[this.props.activeClassName||""]=this.props.activeClassName?this.props.isActive:null,t)),n=s.label;return this.props.renderSuggestItem?n=this.props.renderSuggestItem(s,this.props.userInput):this.props.isHighlightMatch&&(n=this.formatMatchedText(this.props.userInput,s)),u.createElement("li",{className:o,ref:function(t){return e.ref=t},style:this.props.style,onMouseDown:this.props.onMouseDown,onMouseOut:this.props.onMouseOut,onClick:this.onClick,role:"option","aria-selected":this.props.isActive,id:s.placeId},n)},t}(u.PureComponent),O=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.isHidden=function(){return this.props.isHidden||0===this.props.suggests.length},e.prototype.componentDidUpdate=function(t){t.suggests!==this.props.suggests&&0===this.props.suggests.length&&this.props.onSuggestNoResults()},e.prototype.render=function(){var t,s=this,e=r("geosuggest__suggests",this.props.suggestsClassName,{"geosuggest__suggests--hidden":this.isHidden()},((t={})[this.props.hiddenClassName||""]=this.props.hiddenClassName?this.isHidden():null,t));return u.createElement("ul",{className:e,style:this.props.style,role:"listbox",id:this.props.listId},this.props.suggests.map(function(t){var e=s.props.activeSuggest&&t.placeId===s.props.activeSuggest.placeId||!1;return u.createElement(T,{key:t.placeId,className:t.className||"",userInput:s.props.userInput,isHighlightMatch:s.props.isHighlightMatch,suggest:t,style:s.props.suggestItemStyle,suggestItemClassName:s.props.suggestItemClassName,isActive:e,activeClassName:s.props.suggestItemActiveClassName,onMouseDown:s.props.onSuggestMouseDown,onMouseOut:s.props.onSuggestMouseOut,onSelect:s.props.onSuggestSelect,renderSuggestItem:s.props.renderSuggestItem})}))},e}(u.PureComponent);return function(s){function t(t){var e=s.call(this,t)||this;return e.googleMaps=null,e.autocompleteService=null,e.placesService=null,e.sessionToken=void 0,e.geocoder=null,e.input=null,e.state={activeSuggest:null,ignoreBlur:!1,isLoading:!1,isSuggestsHidden:!0,suggests:[],userInput:t.initialValue||""},e.onInputChange=e.onInputChange.bind(e),e.onAfterInputChange=e.onAfterInputChange.bind(e),e.onInputFocus=e.onInputFocus.bind(e),e.onInputBlur=e.onInputBlur.bind(e),e.onNext=e.onNext.bind(e),e.onPrev=e.onPrev.bind(e),e.onSelect=e.onSelect.bind(e),e.onSuggestMouseDown=e.onSuggestMouseDown.bind(e),e.onSuggestMouseOut=e.onSuggestMouseOut.bind(e),e.onSuggestNoResults=e.onSuggestNoResults.bind(e),e.hideSuggests=e.hideSuggests.bind(e),e.selectSuggest=e.selectSuggest.bind(e),e.listId="geosuggest__list_"+Math.random().toString(16).slice(2),t.queryDelay&&(e.onAfterInputChange=C(e.onAfterInputChange,t.queryDelay)),e}return n(t,s),t.prototype.componentDidUpdate=function(t){t.initialValue!==this.props.initialValue&&this.setState({userInput:this.props.initialValue||""}),JSON.stringify(t.fixtures)!==JSON.stringify(this.props.fixtures)&&this.searchSuggests()},t.prototype.componentDidMount=function(){if("undefined"!=typeof window){var t=this.props.googleMaps||window.google&&window.google.maps||this.googleMaps;t?(this.googleMaps=t,this.autocompleteService=new t.places.AutocompleteService,this.placesService=new t.places.PlacesService(document.createElement("div")),this.sessionToken=new t.places.AutocompleteSessionToken,this.geocoder=new t.Geocoder):console&&console.error("Google maps API was not found in the page.")}},t.prototype.componentWillUnmount=function(){clearTimeout(this.timer)},t.prototype.onInputChange=function(t){t||this.props.onSuggestSelect&&this.props.onSuggestSelect(),this.setState({userInput:t},this.onAfterInputChange)},t.prototype.onAfterInputChange=function(){this.showSuggests(),this.props.onChange&&this.props.onChange(this.state.userInput)},t.prototype.onInputFocus=function(){this.props.onFocus&&this.props.onFocus(),this.showSuggests()},t.prototype.onInputBlur=function(){this.state.ignoreBlur||this.hideSuggests()},t.prototype.onNext=function(){this.activateSuggest("next")},t.prototype.onPrev=function(){this.activateSuggest("prev")},t.prototype.onSelect=function(){this.selectSuggest(this.state.activeSuggest)},t.prototype.onSuggestMouseDown=function(){this.setState({ignoreBlur:!0})},t.prototype.onSuggestMouseOut=function(){this.setState({ignoreBlur:!1})},t.prototype.onSuggestNoResults=function(){this.props.onSuggestNoResults&&this.props.onSuggestNoResults(this.state.userInput)},t.prototype.focus=function(){this.input&&this.input.focus()},t.prototype.blur=function(){this.input&&this.input.blur()},t.prototype.update=function(t){this.setState({userInput:t}),this.props.onChange&&this.props.onChange(t)},t.prototype.clear=function(){this.setState({userInput:""},this.hideSuggests)},t.prototype.searchSuggests=function(){var e=this;if(this.state.userInput){var t={input:this.state.userInput,sessionToken:this.sessionToken},s=this.state.userInput.length;if(this.props.minLength&&s<this.props.minLength)this.updateSuggests();else{var o=this.props,n=o.location,i=o.radius,r=o.bounds,u=o.types,a=o.country;n&&(t.location=n),i&&(t.radius=Number(this.props.radius)),r&&(t.bounds=r),u&&(t.types=u),a&&(t.componentRestrictions={country:a}),this.setState({isLoading:!0},function(){e.autocompleteService?e.autocompleteService.getPlacePredictions(t,function(t){e.setState({isLoading:!1}),e.updateSuggests(t||[],function(){e.props.autoActivateFirstSuggest&&!e.state.activeSuggest&&e.activateSuggest("next")})}):e.setState({isLoading:!1})})}}else this.updateSuggests()},t.prototype.updateSuggests=function(t,e){var s=this;void 0===t&&(t=[]),void 0===e&&(e=function(){});var o,n=[],i=this.state.userInput,r=this.props,u=r.skipSuggest,a=r.maxFixtures,p=r.fixtures,g=new RegExp(function(t){return t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}(i),"gim"),l=0;p&&p.forEach(function(t){a&&a<=l||u&&!u(t)&&t.label.match(g)&&(l++,n.push(c(c({},t),{isFixture:!0,matchedSubstrings:{length:i.length,offset:t.label.indexOf(i)},placeId:t.placeId||t.label})))}),t.forEach(function(t){u&&!u(t)&&n.push({description:t.description,isFixture:!1,label:s.props.getSuggestLabel?s.props.getSuggestLabel(t):"",matchedSubstrings:t.matched_substrings[0],placeId:t.place_id})}),o=this.updateActiveSuggest(n),this.props.onUpdateSuggests&&this.props.onUpdateSuggests(n,o),this.setState({suggests:n,activeSuggest:o},e)},t.prototype.updateActiveSuggest=function(t){void 0===t&&(t=[]);var e=this.state.activeSuggest;if(e){var s=t.filter(function(t){return e&&e.placeId===t.placeId&&e.isFixture===t.isFixture})[0];e=s||null}return e},t.prototype.showSuggests=function(){this.searchSuggests(),this.setState({isSuggestsHidden:!1})},t.prototype.hideSuggests=function(){var t=this;this.props.onBlur&&this.props.onBlur(this.state.userInput),this.timer=window.setTimeout(function(){t.setState({activeSuggest:null,isSuggestsHidden:!0})},100)},t.prototype.activateSuggest=function(t){if(this.state.isSuggestsHidden)this.showSuggests();else{for(var e=this.state.suggests.length-1,s="next"===t,o=null,n=0,i=0;i<=e;i++)this.state.suggests[i]===this.state.activeSuggest&&(n=s?i+1:i-1);this.state.activeSuggest||(n=s?0:e),0<=n&&n<=e&&(o=this.state.suggests[n]),this.props.onActivateSuggest&&this.props.onActivateSuggest(o),this.setState({activeSuggest:o})}},t.prototype.selectSuggest=function(t){var e=t||{isFixture:!1,label:this.state.userInput,placeId:this.state.userInput};if(!t&&this.props.autoActivateFirstSuggest&&0<this.state.suggests.length&&(e=this.state.suggests[0]),this.setState({isSuggestsHidden:!0,userInput:"object"!=typeof e.label?e.label:e.description||""}),e.location)return this.setState({ignoreBlur:!1}),void(this.props.onSuggestSelect&&this.props.onSuggestSelect(e));this.geocodeSuggest(e)},t.prototype.geocodeSuggest=function(i){var r=this;if(this.geocoder)if(i.placeId&&!i.isFixture&&this.placesService){var t={placeId:i.placeId,sessionToken:this.sessionToken};this.props.placeDetailFields&&(t.fields=this.props.placeDetailFields,t.fields.unshift("geometry")),this.placesService.getDetails(t,function(t,e){if(e===r.googleMaps.places.PlacesServiceStatus.OK){var s=t,o=s.geometry&&s.geometry.location,n=c(c({},i),{gmaps:s,location:{lat:o.lat(),lng:o.lng()}});r.sessionToken=new google.maps.places.AutocompleteSessionToken,r.props.onSuggestSelect&&r.props.onSuggestSelect(n)}})}else{t={address:i.label,bounds:this.props.bounds,componentRestrictions:this.props.country?{country:this.props.country}:void 0,location:this.props.location};this.geocoder.geocode(t,function(t,e){if(e===r.googleMaps.GeocoderStatus.OK){var s=t[0],o=s.geometry&&s.geometry.location,n=c(c({},i),{gmaps:s,location:{lat:o.lat(),lng:o.lng()}});r.props.onSuggestSelect&&r.props.onSuggestSelect(n)}})}},t.prototype.render=function(){var e=this,t=M(this.props),s=r("geosuggest",this.props.className,{"geosuggest--loading":this.state.isLoading}),o=this.props.label&&t.id,n=u.createElement(D,c({className:this.props.inputClassName,ref:function(t){return e.input=t},value:this.state.userInput,doNotSubmitOnEnter:!this.state.isSuggestsHidden,ignoreTab:this.props.ignoreTab,ignoreEnter:this.props.ignoreEnter,style:this.props.style&&this.props.style.input,onChange:this.onInputChange,onFocus:this.onInputFocus,onBlur:this.onInputBlur,onKeyDown:this.props.onKeyDown,onKeyPress:this.props.onKeyPress,onNext:this.onNext,onPrev:this.onPrev,onSelect:this.onSelect,onEscape:this.hideSuggests,isSuggestsHidden:this.state.isSuggestsHidden,activeSuggest:this.state.activeSuggest,listId:this.listId},t)),i=u.createElement(O,{isHidden:this.state.isSuggestsHidden,style:this.props.style&&this.props.style.suggests,suggestItemStyle:this.props.style&&this.props.style.suggestItem,userInput:this.state.userInput,isHighlightMatch:Boolean(this.props.highlightMatch),suggestsClassName:this.props.suggestsClassName,suggestItemClassName:this.props.suggestItemClassName,suggests:this.state.suggests,hiddenClassName:this.props.suggestsHiddenClassName,suggestItemActiveClassName:this.props.suggestItemActiveClassName,activeSuggest:this.state.activeSuggest,onSuggestNoResults:this.onSuggestNoResults,onSuggestMouseDown:this.onSuggestMouseDown,onSuggestMouseOut:this.onSuggestMouseOut,onSuggestSelect:this.selectSuggest,renderSuggestItem:this.props.renderSuggestItem,listId:this.listId});return u.createElement("div",{className:s},u.createElement("div",{className:"geosuggest__input-wrapper"},o&&u.createElement("label",{className:"geosuggest__label",htmlFor:t.id},this.props.label),n),u.createElement("div",{className:"geosuggest__suggests-wrapper"},i))},t.defaultProps=N,t}(u.Component)}(React); | ||
var Geosuggest=function(u){"use strict";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])})(t,e)};function n(t,e){function s(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}var c=function(){return(c=Object.assign||function(t){for(var e,s=1,o=arguments.length;s<o;s++)for(var n in e=arguments[s])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)},t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,i=(function(t){!function(){var r={}.hasOwnProperty;function u(){for(var t=[],e=0;e<arguments.length;e++){var s=arguments[e];if(s){var o=typeof s;if("string"==o||"number"==o)t.push(s);else if(Array.isArray(s)&&s.length){var n=u.apply(null,s);n&&t.push(n)}else if("object"==o)for(var i in s)r.call(s,i)&&s[i]&&t.push(i)}}return t.join(" ")}t.exports?(u.default=u,t.exports=u):window.classNames=u}()}(e={exports:{}},e.exports),e.exports),r=NaN,p="[object Symbol]",a=/^\s+|\s+$/g,g=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,h=/^0o[0-7]+$/i,d=parseInt,s="object"==typeof t&&t&&t.Object===Object&&t,f="object"==typeof self&&self&&self.Object===Object&&self,S=s||f||Function("return this")(),m=Object.prototype.toString,v=Math.max,y=Math.min,b=function(){return S.Date.now()};function I(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function w(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&m.call(t)==p}(t))return r;if(I(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=I(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(a,"");var s=l.test(t);return s||h.test(t)?d(t.slice(2),s?2:8):g.test(t)?r:+t}var C=function(o,s,t){var n,i,r,u,p,a,g=0,l=!1,c=!1,e=!0;if("function"!=typeof o)throw new TypeError("Expected a function");function h(t){var e=n,s=i;return n=i=void 0,g=t,u=o.apply(s,e)}function d(t){var e=t-a;return void 0===a||s<=e||e<0||c&&r<=t-g}function f(){var t=b();if(d(t))return S(t);p=setTimeout(f,function(t){var e=s-(t-a);return c?y(e,r-(t-g)):e}(t))}function S(t){return p=void 0,e&&n?h(t):(n=i=void 0,u)}function m(){var t=b(),e=d(t);if(n=arguments,i=this,a=t,e){if(void 0===p)return function(t){return g=t,p=setTimeout(f,s),l?h(t):u}(a);if(c)return p=setTimeout(f,s),h(a)}return void 0===p&&(p=setTimeout(f,s)),u}return s=w(s)||0,I(t)&&(l=!!t.leading,r=(c="maxWait"in t)?v(w(t.maxWait)||0,s):r,e="trailing"in t?!!t.trailing:e),m.cancel=function(){void 0!==p&&clearTimeout(p),n=a=i=p=void(g=0)},m.flush=function(){return void 0===p?u:S(b())},m},N={autoActivateFirstSuggest:!1,disabled:!1,fixtures:[],getSuggestLabel:function(t){return t.description},highlightMatch:!0,ignoreEnter:!1,ignoreTab:!1,initialValue:"",maxFixtures:10,minLength:1,onKeyDown:function(){},onKeyPress:function(){},placeholder:"Search places",queryDelay:250,skipSuggest:function(){return!1},style:{}},x=["autoCapitalize","autoComplete","autoCorrect","autoFocus","disabled","form","formAction","formEncType","formMethod","formNoValidate","formTarget","height","inputMode","maxLength","name","onClick","onContextMenu","onCopy","onCut","onDoubleClick","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPaste","pattern","placeholder","readOnly","required","size","spellCheck","tabIndex","title","aria-atomic","aria-busy","aria-controls","aria-current","aria-describedby","aria-details","aria-disabled","aria-dropeffect","aria-errormessage","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription","aria-activedescendant","aria-autocomplete","aria-multiline","aria-placeholder","aria-readonly","aria-required"];function M(s){var o={};return Object.keys(s).forEach(function(t){var e=t.startsWith("data-");(x.includes(t)||e)&&(o[t]=s[t])}),o}var D=function(s){function t(t){var e=s.call(this,t)||this;return e.input=null,e.onChange=e.onChange.bind(e),e.onInputKeyDown=e.onInputKeyDown.bind(e),e}return n(t,s),t.prototype.onChange=function(){this.input&&this.props.onChange(this.input.value)},t.prototype.onInputKeyDown=function(t){switch(this.props.onKeyDown&&this.props.onKeyDown(t),t.which){case 40:t.shiftKey||(t.preventDefault(),this.props.onNext());break;case 38:t.shiftKey||(t.preventDefault(),this.props.onPrev());break;case 13:this.props.doNotSubmitOnEnter&&t.preventDefault(),this.props.ignoreEnter||this.props.onSelect();break;case 9:this.props.ignoreTab||this.props.onSelect();break;case 27:this.props.onEscape()}},t.prototype.focus=function(){this.input&&this.input.focus()},t.prototype.blur=function(){this.input&&this.input.blur()},t.prototype.render=function(){var e=this,t=M(this.props),s=i("geosuggest__input",this.props.className),o=this.props.label&&this.props.id;return t.tabIndex||(t.tabIndex=0),u.createElement(u.Fragment,null,o&&u.createElement("label",{className:"geosuggest__label",htmlFor:this.props.id},this.props.label),u.createElement("input",c({className:s,id:"geosuggest__input"+(this.props.id?"--"+this.props.id:""),ref:function(t){return e.input=t},type:"text"},t,{value:this.props.value,style:this.props.style,onKeyDown:this.onInputKeyDown,onChange:this.onChange,onKeyPress:this.props.onKeyPress,onFocus:this.props.onFocus,onBlur:this.props.onBlur,role:"combobox","aria-expanded":!this.props.isSuggestsHidden,"aria-activedescendant":this.props.activeSuggest?this.props.activeSuggest.placeId:void 0,"aria-owns":this.props.listId})))},t.defaultProps={activeSuggest:null,autoComplete:"nope",className:"",isSuggestsHidden:!0,listId:"",onBlur:function(){},onChange:function(){},onEscape:function(){},onFocus:function(){},onKeyDown:function(){},onKeyPress:function(){},onNext:function(){},onPrev:function(){},onSelect:function(){},value:""},t}(u.PureComponent),T=function(s){function t(t){var e=s.call(this,t)||this;return e.ref=null,e.onClick=e.onClick.bind(e),e}return n(t,s),t.prototype.makeBold=function(t,e){return u.createElement("b",{className:"geosuggest__item__matched-text",key:e},t)},t.prototype.formatMatchedText=function(t,e){if(!t||!e.matchedSubstrings)return e.label;var s=e.matchedSubstrings.offset,o=s+e.matchedSubstrings.length,n=this.makeBold(e.label.substring(s,o),e.label),i="",r="";return 0<s&&(i=e.label.slice(0,s)),o<e.label.length&&(r=e.label.slice(o)),u.createElement("span",null,i,n,r)},t.prototype.componentDidUpdate=function(t){!t.isActive&&this.props.isActive&&this.scrollIfNeeded()},t.prototype.scrollIfNeeded=function(){var t=this.ref,e=t&&t.parentElement;if(t&&e){var s=t.offsetTop-e.offsetTop<e.scrollTop,o=t.offsetTop-e.offsetTop+t.clientHeight>e.scrollTop+e.clientHeight;(s||o)&&(e.scrollTop=t.offsetTop-e.offsetTop-e.clientHeight/2+t.clientHeight/2)}},t.prototype.onClick=function(t){t.preventDefault(),this.props.onSelect(this.props.suggest)},t.prototype.render=function(){var t,e=this,s=this.props.suggest,o=i("geosuggest__item",this.props.className,this.props.suggestItemClassName,{"geosuggest__item--active":this.props.isActive},((t={})[this.props.activeClassName||""]=this.props.activeClassName?this.props.isActive:null,t)),n=s.label;return this.props.renderSuggestItem?n=this.props.renderSuggestItem(s,this.props.userInput):this.props.isHighlightMatch&&(n=this.formatMatchedText(this.props.userInput,s)),u.createElement("li",{className:o,ref:function(t){return e.ref=t},style:this.props.style,onMouseDown:this.props.onMouseDown,onMouseOut:this.props.onMouseOut,onClick:this.onClick,role:"option","aria-selected":this.props.isActive,id:s.placeId},n)},t}(u.PureComponent),O=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.isHidden=function(){return this.props.isHidden||0===this.props.suggests.length},e.prototype.componentDidUpdate=function(t){t.suggests!==this.props.suggests&&0===this.props.suggests.length&&this.props.onSuggestNoResults()},e.prototype.render=function(){var t,s=this,e=i("geosuggest__suggests",this.props.suggestsClassName,{"geosuggest__suggests--hidden":this.isHidden()},((t={})[this.props.hiddenClassName||""]=this.props.hiddenClassName?this.isHidden():null,t));return u.createElement("ul",{className:e,style:this.props.style,role:"listbox",id:this.props.listId},this.props.suggests.map(function(t){var e=s.props.activeSuggest&&t.placeId===s.props.activeSuggest.placeId||!1;return u.createElement(T,{key:t.placeId,className:t.className||"",userInput:s.props.userInput,isHighlightMatch:s.props.isHighlightMatch,suggest:t,style:s.props.suggestItemStyle,suggestItemClassName:s.props.suggestItemClassName,isActive:e,activeClassName:s.props.suggestItemActiveClassName,onMouseDown:s.props.onSuggestMouseDown,onMouseOut:s.props.onSuggestMouseOut,onSelect:s.props.onSuggestSelect,renderSuggestItem:s.props.renderSuggestItem})}))},e}(u.PureComponent);return function(s){function t(t){var e=s.call(this,t)||this;return e.googleMaps=null,e.autocompleteService=null,e.placesService=null,e.sessionToken=void 0,e.geocoder=null,e.input=null,e.state={activeSuggest:null,ignoreBlur:!1,isLoading:!1,isSuggestsHidden:!0,suggests:[],userInput:t.initialValue||""},e.onInputChange=e.onInputChange.bind(e),e.onAfterInputChange=e.onAfterInputChange.bind(e),e.onInputFocus=e.onInputFocus.bind(e),e.onInputBlur=e.onInputBlur.bind(e),e.onNext=e.onNext.bind(e),e.onPrev=e.onPrev.bind(e),e.onSelect=e.onSelect.bind(e),e.onSuggestMouseDown=e.onSuggestMouseDown.bind(e),e.onSuggestMouseOut=e.onSuggestMouseOut.bind(e),e.onSuggestNoResults=e.onSuggestNoResults.bind(e),e.hideSuggests=e.hideSuggests.bind(e),e.selectSuggest=e.selectSuggest.bind(e),e.listId="geosuggest__list"+(t.id?"--"+t.id:""),t.queryDelay&&(e.onAfterInputChange=C(e.onAfterInputChange,t.queryDelay)),e}return n(t,s),t.prototype.componentDidUpdate=function(t){t.initialValue!==this.props.initialValue&&this.setState({userInput:this.props.initialValue||""}),JSON.stringify(t.fixtures)!==JSON.stringify(this.props.fixtures)&&this.searchSuggests()},t.prototype.componentDidMount=function(){if("undefined"!=typeof window){var t=this.props.googleMaps||window.google&&window.google.maps||this.googleMaps;t?(this.googleMaps=t,this.autocompleteService=new t.places.AutocompleteService,this.placesService=new t.places.PlacesService(document.createElement("div")),this.sessionToken=new t.places.AutocompleteSessionToken,this.geocoder=new t.Geocoder):console&&console.error("Google maps API was not found in the page.")}},t.prototype.componentWillUnmount=function(){clearTimeout(this.timer)},t.prototype.onInputChange=function(t){t||this.props.onSuggestSelect&&this.props.onSuggestSelect(),this.setState({userInput:t},this.onAfterInputChange)},t.prototype.onAfterInputChange=function(){this.showSuggests(),this.props.onChange&&this.props.onChange(this.state.userInput)},t.prototype.onInputFocus=function(){this.props.onFocus&&this.props.onFocus(),this.showSuggests()},t.prototype.onInputBlur=function(){this.state.ignoreBlur||this.hideSuggests()},t.prototype.onNext=function(){this.activateSuggest("next")},t.prototype.onPrev=function(){this.activateSuggest("prev")},t.prototype.onSelect=function(){this.selectSuggest(this.state.activeSuggest)},t.prototype.onSuggestMouseDown=function(){this.setState({ignoreBlur:!0})},t.prototype.onSuggestMouseOut=function(){this.setState({ignoreBlur:!1})},t.prototype.onSuggestNoResults=function(){this.props.onSuggestNoResults&&this.props.onSuggestNoResults(this.state.userInput)},t.prototype.focus=function(){this.input&&this.input.focus()},t.prototype.blur=function(){this.input&&this.input.blur()},t.prototype.update=function(t){this.setState({userInput:t}),this.props.onChange&&this.props.onChange(t)},t.prototype.clear=function(){this.setState({userInput:""},this.hideSuggests)},t.prototype.searchSuggests=function(){var e=this;if(this.state.userInput){var t={input:this.state.userInput,sessionToken:this.sessionToken},s=this.state.userInput.length;if(this.props.minLength&&s<this.props.minLength)this.updateSuggests();else{var o=this.props,n=o.location,i=o.radius,r=o.bounds,u=o.types,p=o.country;n&&(t.location=n),i&&(t.radius=Number(this.props.radius)),r&&(t.bounds=r),u&&(t.types=u),p&&(t.componentRestrictions={country:p}),this.setState({isLoading:!0},function(){e.autocompleteService?e.autocompleteService.getPlacePredictions(t,function(t){e.setState({isLoading:!1}),e.updateSuggests(t||[],function(){e.props.autoActivateFirstSuggest&&!e.state.activeSuggest&&e.activateSuggest("next")})}):e.setState({isLoading:!1})})}}else this.updateSuggests()},t.prototype.updateSuggests=function(t,e){var s=this;void 0===t&&(t=[]),void 0===e&&(e=function(){});var o,n=[],i=this.state.userInput,r=this.props,u=r.skipSuggest,p=r.maxFixtures,a=r.fixtures,g=new RegExp(function(t){return t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}(i),"gim"),l=0;a&&a.forEach(function(t){p&&p<=l||u&&!u(t)&&t.label.match(g)&&(l++,n.push(c(c({},t),{isFixture:!0,matchedSubstrings:{length:i.length,offset:t.label.indexOf(i)},placeId:t.placeId||t.label})))}),t.forEach(function(t){u&&!u(t)&&n.push({description:t.description,isFixture:!1,label:s.props.getSuggestLabel?s.props.getSuggestLabel(t):"",matchedSubstrings:t.matched_substrings[0],placeId:t.place_id})}),o=this.updateActiveSuggest(n),this.props.onUpdateSuggests&&this.props.onUpdateSuggests(n,o),this.setState({suggests:n,activeSuggest:o},e)},t.prototype.updateActiveSuggest=function(t){void 0===t&&(t=[]);var e=this.state.activeSuggest;if(e){var s=t.filter(function(t){return e&&e.placeId===t.placeId&&e.isFixture===t.isFixture})[0];e=s||null}return e},t.prototype.showSuggests=function(){this.searchSuggests(),this.setState({isSuggestsHidden:!1})},t.prototype.hideSuggests=function(){var t=this;this.props.onBlur&&this.props.onBlur(this.state.userInput),this.timer=window.setTimeout(function(){t.setState({activeSuggest:null,isSuggestsHidden:!0})},100)},t.prototype.activateSuggest=function(t){if(this.state.isSuggestsHidden)this.showSuggests();else{for(var e=this.state.suggests.length-1,s="next"===t,o=null,n=0,i=0;i<=e;i++)this.state.suggests[i]===this.state.activeSuggest&&(n=s?i+1:i-1);this.state.activeSuggest||(n=s?0:e),0<=n&&n<=e&&(o=this.state.suggests[n]),this.props.onActivateSuggest&&this.props.onActivateSuggest(o),this.setState({activeSuggest:o})}},t.prototype.selectSuggest=function(t){var e=t||{isFixture:!1,label:this.state.userInput,placeId:this.state.userInput};if(!t&&this.props.autoActivateFirstSuggest&&0<this.state.suggests.length&&(e=this.state.suggests[0]),this.setState({isSuggestsHidden:!0,userInput:"object"!=typeof e.label?e.label:e.description||""}),e.location)return this.setState({ignoreBlur:!1}),void(this.props.onSuggestSelect&&this.props.onSuggestSelect(e));this.geocodeSuggest(e)},t.prototype.geocodeSuggest=function(i){var r=this;if(this.geocoder)if(i.placeId&&!i.isFixture&&this.placesService){var t={placeId:i.placeId,sessionToken:this.sessionToken};this.props.placeDetailFields&&(t.fields=this.props.placeDetailFields,t.fields.unshift("geometry")),this.placesService.getDetails(t,function(t,e){if(e===r.googleMaps.places.PlacesServiceStatus.OK){var s=t,o=s.geometry&&s.geometry.location,n=c(c({},i),{gmaps:s,location:{lat:o.lat(),lng:o.lng()}});r.sessionToken=new google.maps.places.AutocompleteSessionToken,r.props.onSuggestSelect&&r.props.onSuggestSelect(n)}})}else{t={address:i.label,bounds:this.props.bounds,componentRestrictions:this.props.country?{country:this.props.country}:void 0,location:this.props.location};this.geocoder.geocode(t,function(t,e){if(e===r.googleMaps.GeocoderStatus.OK){var s=t[0],o=s.geometry&&s.geometry.location,n=c(c({},i),{gmaps:s,location:{lat:o.lat(),lng:o.lng()}});r.props.onSuggestSelect&&r.props.onSuggestSelect(n)}})}},t.prototype.render=function(){var e=this,t=M(this.props),s=i("geosuggest",this.props.className,{"geosuggest--loading":this.state.isLoading}),o=u.createElement(D,c({className:this.props.inputClassName,ref:function(t){return e.input=t},value:this.state.userInput,doNotSubmitOnEnter:!this.state.isSuggestsHidden,ignoreTab:this.props.ignoreTab,ignoreEnter:this.props.ignoreEnter,style:this.props.style&&this.props.style.input,onChange:this.onInputChange,onFocus:this.onInputFocus,onBlur:this.onInputBlur,onKeyDown:this.props.onKeyDown,onKeyPress:this.props.onKeyPress,onNext:this.onNext,onPrev:this.onPrev,onSelect:this.onSelect,onEscape:this.hideSuggests,isSuggestsHidden:this.state.isSuggestsHidden,activeSuggest:this.state.activeSuggest,label:this.props.label,id:this.props.id,listId:this.listId},t)),n=u.createElement(O,{isHidden:this.state.isSuggestsHidden,style:this.props.style&&this.props.style.suggests,suggestItemStyle:this.props.style&&this.props.style.suggestItem,userInput:this.state.userInput,isHighlightMatch:Boolean(this.props.highlightMatch),suggestsClassName:this.props.suggestsClassName,suggestItemClassName:this.props.suggestItemClassName,suggests:this.state.suggests,hiddenClassName:this.props.suggestsHiddenClassName,suggestItemActiveClassName:this.props.suggestItemActiveClassName,activeSuggest:this.state.activeSuggest,onSuggestNoResults:this.onSuggestNoResults,onSuggestMouseDown:this.onSuggestMouseDown,onSuggestMouseOut:this.onSuggestMouseOut,onSuggestSelect:this.selectSuggest,renderSuggestItem:this.props.renderSuggestItem,listId:this.listId});return u.createElement("div",{className:s,id:this.props.id},u.createElement("div",{className:"geosuggest__input-wrapper"},o),u.createElement("div",{className:"geosuggest__suggests-wrapper"},n))},t.defaultProps=N,t}(u.Component)}(React); |
@@ -1,2 +0,2 @@ | ||
import { createElement, PureComponent, Component } from 'react'; | ||
import { createElement, Fragment, PureComponent, Component } from 'react'; | ||
import classnames from 'classnames'; | ||
@@ -86,3 +86,2 @@ import debounce from 'lodash.debounce'; | ||
'height', | ||
'id', | ||
'inputMode', | ||
@@ -246,9 +245,12 @@ 'maxLength', | ||
var classes = classnames('geosuggest__input', this.props.className); | ||
var shouldRenderLabel = this.props.label && this.props.id; | ||
if (!attributes.tabIndex) { | ||
attributes.tabIndex = 0; | ||
} | ||
return (createElement("input", __assign({ className: classes, ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId }))); | ||
return (createElement(Fragment, null, | ||
shouldRenderLabel && (createElement("label", { className: "geosuggest__label", htmlFor: this.props.id }, this.props.label)), | ||
createElement("input", __assign({ className: classes, id: "geosuggest__input" + (this.props.id ? "--" + this.props.id : ''), ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId })))); | ||
}; | ||
@@ -493,3 +495,3 @@ /* eslint-disable @typescript-eslint/no-empty-function */ | ||
_this.selectSuggest = _this.selectSuggest.bind(_this); | ||
_this.listId = "geosuggest__list_" + Math.random().toString(16).slice(2); | ||
_this.listId = "geosuggest__list" + (props.id ? "--" + props.id : ''); | ||
if (props.queryDelay) { | ||
@@ -901,9 +903,6 @@ _this.onAfterInputChange = debounce(_this.onAfterInputChange, props.queryDelay); | ||
}); | ||
var shouldRenderLabel = this.props.label && attributes.id; | ||
var input = (createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, listId: this.listId }, attributes))); | ||
var input = (createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, label: this.props.label, id: this.props.id, listId: this.listId }, attributes))); | ||
var suggestionsList = (createElement(default_1$1, { isHidden: this.state.isSuggestsHidden, style: this.props.style && this.props.style.suggests, suggestItemStyle: this.props.style && this.props.style.suggestItem, userInput: this.state.userInput, isHighlightMatch: Boolean(this.props.highlightMatch), suggestsClassName: this.props.suggestsClassName, suggestItemClassName: this.props.suggestItemClassName, suggests: this.state.suggests, hiddenClassName: this.props.suggestsHiddenClassName, suggestItemActiveClassName: this.props.suggestItemActiveClassName, activeSuggest: this.state.activeSuggest, onSuggestNoResults: this.onSuggestNoResults, onSuggestMouseDown: this.onSuggestMouseDown, onSuggestMouseOut: this.onSuggestMouseOut, onSuggestSelect: this.selectSuggest, renderSuggestItem: this.props.renderSuggestItem, listId: this.listId })); | ||
return (createElement("div", { className: classes }, | ||
createElement("div", { className: "geosuggest__input-wrapper" }, | ||
shouldRenderLabel && (createElement("label", { className: "geosuggest__label", htmlFor: attributes.id }, this.props.label)), | ||
input), | ||
return (createElement("div", { className: classes, id: this.props.id }, | ||
createElement("div", { className: "geosuggest__input-wrapper" }, input), | ||
createElement("div", { className: "geosuggest__suggests-wrapper" }, suggestionsList))); | ||
@@ -910,0 +909,0 @@ }; |
@@ -91,3 +91,2 @@ (function (global, factory) { | ||
'height', | ||
'id', | ||
'inputMode', | ||
@@ -251,9 +250,12 @@ 'maxLength', | ||
var classes = classnames('geosuggest__input', this.props.className); | ||
var shouldRenderLabel = this.props.label && this.props.id; | ||
if (!attributes.tabIndex) { | ||
attributes.tabIndex = 0; | ||
} | ||
return (React.createElement("input", __assign({ className: classes, ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId }))); | ||
return (React.createElement(React.Fragment, null, | ||
shouldRenderLabel && (React.createElement("label", { className: "geosuggest__label", htmlFor: this.props.id }, this.props.label)), | ||
React.createElement("input", __assign({ className: classes, id: "geosuggest__input" + (this.props.id ? "--" + this.props.id : ''), ref: function (i) { return (_this.input = i); }, type: "text" }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest | ||
? this.props.activeSuggest.placeId | ||
: // eslint-disable-next-line no-undefined | ||
undefined, "aria-owns": this.props.listId })))); | ||
}; | ||
@@ -498,3 +500,3 @@ /* eslint-disable @typescript-eslint/no-empty-function */ | ||
_this.selectSuggest = _this.selectSuggest.bind(_this); | ||
_this.listId = "geosuggest__list_" + Math.random().toString(16).slice(2); | ||
_this.listId = "geosuggest__list" + (props.id ? "--" + props.id : ''); | ||
if (props.queryDelay) { | ||
@@ -906,9 +908,6 @@ _this.onAfterInputChange = debounce(_this.onAfterInputChange, props.queryDelay); | ||
}); | ||
var shouldRenderLabel = this.props.label && attributes.id; | ||
var input = (React.createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, listId: this.listId }, attributes))); | ||
var input = (React.createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, label: this.props.label, id: this.props.id, listId: this.listId }, attributes))); | ||
var suggestionsList = (React.createElement(default_1$1, { isHidden: this.state.isSuggestsHidden, style: this.props.style && this.props.style.suggests, suggestItemStyle: this.props.style && this.props.style.suggestItem, userInput: this.state.userInput, isHighlightMatch: Boolean(this.props.highlightMatch), suggestsClassName: this.props.suggestsClassName, suggestItemClassName: this.props.suggestItemClassName, suggests: this.state.suggests, hiddenClassName: this.props.suggestsHiddenClassName, suggestItemActiveClassName: this.props.suggestItemActiveClassName, activeSuggest: this.state.activeSuggest, onSuggestNoResults: this.onSuggestNoResults, onSuggestMouseDown: this.onSuggestMouseDown, onSuggestMouseOut: this.onSuggestMouseOut, onSuggestSelect: this.selectSuggest, renderSuggestItem: this.props.renderSuggestItem, listId: this.listId })); | ||
return (React.createElement("div", { className: classes }, | ||
React.createElement("div", { className: "geosuggest__input-wrapper" }, | ||
shouldRenderLabel && (React.createElement("label", { className: "geosuggest__label", htmlFor: attributes.id }, this.props.label)), | ||
input), | ||
return (React.createElement("div", { className: classes, id: this.props.id }, | ||
React.createElement("div", { className: "geosuggest__input-wrapper" }, input), | ||
React.createElement("div", { className: "geosuggest__suggests-wrapper" }, suggestionsList))); | ||
@@ -915,0 +914,0 @@ }; |
{ | ||
"name": "react-geosuggest", | ||
"version": "2.13.0", | ||
"version": "2.13.1", | ||
"description": "A React autosuggest for the Google Maps Places API.", | ||
@@ -5,0 +5,0 @@ "main": "module/Geosuggest.umd.js", |
# React Geosuggest [![Build Status](https://travis-ci.org/ubilabs/react-geosuggest.svg?branch=master)](https://travis-ci.org/ubilabs/react-geosuggest) | ||
A [React](http://facebook.github.io/react/) autosuggest for the Google Maps Places API. You can also define your own suggests as defaults. Works with [Preact](https://github.com/developit/preact), too. | ||
A [React](https://reactjs.org/) autosuggest for the Google Maps Places API. You can also define your own suggests as defaults. Works with [Preact](https://github.com/developit/preact), too. | ||
@@ -8,3 +8,3 @@ | ||
Live demo: [ubilabs.github.io/react-geosuggest](http://ubilabs.github.io/react-geosuggest/) | ||
Live demo: [ubilabs.github.io/react-geosuggest](https://ubilabs.github.io/react-geosuggest/) | ||
@@ -31,3 +31,3 @@ | ||
The easiest way to use geosuggest is to install it from NPM and include it in your own React build process (using [Browserify](http://browserify.org), [Webpack](http://webpack.github.io/), etc). | ||
The easiest way to use geosuggest is to install it from NPM and include it in your own React build process (using [Webpack](https://webpack.github.io/), [Parcel](https://parceljs.org/), etc). | ||
@@ -74,2 +74,8 @@ You can also use the standalone build by including `dist/react-geosuggest.js` in your page. If you use this, make sure you have already included React, and it is available as a global variable. | ||
#### id | ||
Type: `String` | ||
Default: `''` | ||
Define an ID for the geosuggest. Needed when there are multiple instances on a page. | ||
#### className | ||
@@ -132,3 +138,3 @@ Type: `String` | ||
The types of predictions to be returned. Four types are supported: `establishment` for businesses, `geocode` for addresses, `(regions)` for administrative regions and `(cities)` for localities. If nothing is specified, all types are returned. Consult the Google Docs for [up to date types](https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest). | ||
The types of predictions to be returned. Four types are supported: `establishment` for businesses, `geocode` for addresses, `(regions)` for administrative regions and `(cities)` for localities. If nothing is specified, all types are returned. Consult the Google Docs for [up to date types](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest.types). | ||
@@ -386,3 +392,3 @@ #### fixtures | ||
This component uses [BEM](http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/) for namespacing the CSS classes. So styling should be easy and without conflicts. See the [geosuggest.css](https://github.com/ubilabs/react-geosuggest/blob/master/src/geosuggest.css) for an example styling. | ||
This component uses [BEM](https://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/) for namespacing the CSS classes. So styling should be easy and without conflicts. See the [geosuggest.css](https://github.com/ubilabs/react-geosuggest/blob/master/src/geosuggest.css) for an example styling. | ||
@@ -389,0 +395,0 @@ ### Note: |
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
1006620
419
3269