diff --git a/dist/index.js b/dist/index.js index 5d5dd5f..c3c339e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t){e.exports=require("react")},function(e,t,n){e.exports=n(2)()},function(e,t,n){"use strict";var r=n(3);function o(){}function c(){}c.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,c,a){if(a!==r){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:c,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1),c=n.n(o);function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},c=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function l(e){return e?"PlacesTypeahead__suggestion-".concat(e):null}function s(e){var t=e.place_id,n=e.matched_substrings,r=e.structured_formatting,o=r.main_text,c=r.secondary_text;return function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"google-places-script";if(!document.querySelector("#".concat(n))){var r=document.createElement("script");r.setAttribute("src","https://maps.googleapis.com/maps/api/js?key=".concat(e,"&libraries=places").concat(t?"&callback=".concat(t):"")),r.setAttribute("id",n),document.head.appendChild(r)}}function y(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},c=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function O(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function v(e){for(var t=1;t0&&I(e[0].place_id)):c(t)}),[]),A=Object(r.useCallback)((function(){if(!window.google)throw new Error("[react-google-places-typeahead]: Google maps API not laoded");D.current=new window.google.maps.places.AutocompleteService,b(!0)}),[]);Object(r.useEffect)((function(){!n||window.google?A():window[n]=A}),[]);var R=Object(r.useMemo)((function(){return O.map((function(e){return v({active:T===e.placeId},e)}))}),[T,O]),L=Object(r.useMemo)((function(){return _||R.length>0}),[R,_]),q=Object(r.useCallback)((function(){k([]),I(null)}),[]),K=Object(r.useMemo)((function(){return e=function(e){e?(E(!0),D.current.getQueryPredictions(v({},f,{input:e}),M)):q()},t=a,function(){for(var r=arguments.length,o=new Array(r),c=0;c0?document.addEventListener("click",q):document.removeEventListener("click",q)}),[R]),Object(r.useEffect)((function(){return function(){return document.removeEventListener("click",q)}}),[]);var G=Object(r.useCallback)((function(e){i(e.target.value),D.current&&K(e.target.value)}),[D.current]),U=Object(r.useCallback)((function(e){q(),i(e.description),o(e)}),[]),B=Object(r.useCallback)((function(e){var t=R.length;if(!(_||t<1)&&[S,P,w,j].includes(e.keyCode))switch(e.preventDefault(),e.keyCode){case S:return void q();case P:var n=R.find((function(e){return e.active}));return void U(n);default:var r,o=R.findIndex((function(e){return e.active}))+(r={},m(r,j,-1),m(r,w,1),r)[e.keyCode];o<0?o=t-1:o>=t&&(o=0),I(R[o].placeId)}}),[R,_]),W=Object(r.useCallback)((function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=l(T),n=e.value,r=e.onChange,o=e.onKeyDown,c=y(e,["value","onChange","onKeyDown"]);if(n)throw new Error("[react-google-places-typeahead]: getInputProps does not accept `value`. Use `value` prop instead");if(r)throw new Error("[react-google-places-typeahead]: getInputProps does not accept `onChange`. Use `onChange` prop instead");return v({},c,{role:"combobox","aria-autocomplete":"list","aria-expanded":R.length>1,"aria-activedescendant":t,value:u,disabled:!d,onChange:G,onKeyDown:function(e){B(e),o&&o(e)}})}),[u,B,R,d,T]),N=Object(r.useCallback)((function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.onClick,r=t.onMouseOver,o=y(t,["onClick","onMouseOver"]);return v({},o,{key:e.id,id:l(e.placeId),onClick:function(t){U(e),n&&n(t)},onMouseOver:function(t){I(e.placeId),r&&r(t)}})}),[]);return t({suggestions:R,isLoading:_,showList:L,getInputProps:W,getSuggestionItemProps:N})}k.displayName="GooglePlacesTypeahead",k.defaultProps={onSelect:function(){return null},onError:function(){return null},gMapsCallback:null,debounce:200,searchOptions:{}},k.propTypes={children:c.a.func.isRequired,value:c.a.string.isRequired,onChange:c.a.func.isRequired,onError:c.a.func,gMapsCallback:c.a.string,onSelect:c.a.func,debounce:c.a.number,searchOptions:c.a.shape({bounds:c.a.object,componentRestrictions:c.a.object,location:c.a.object,offset:c.a.oneOfType([c.a.number,c.a.string]),radius:c.a.oneOfType([c.a.number,c.a.string]),types:c.a.array})};t.default=k}]); \ No newline at end of file +module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t){e.exports=require("react")},function(e,t,n){e.exports=n(2)()},function(e,t,n){"use strict";var r=n(3);function o(){}function c(){}c.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,c,a){if(a!==r){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:c,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1),c=n.n(o);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},c=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function i(e){return e?"PlacesTypeahead__suggestion-".concat(e):null}function l(e){var t=e.place_id,n=e.matched_substrings,r=e.structured_formatting,o=r.main_text,c=r.secondary_text;return function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"google-places-script";if(!document.querySelector("#".concat(n))){var r=document.createElement("script");r.setAttribute("src","https://maps.googleapis.com/maps/api/js?key=".concat(e,"&libraries=places").concat(t?"&callback=".concat(t):"")),r.setAttribute("id",n),document.head.appendChild(r)}}function g(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},c=Object.keys(e);for(r=0;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function y(e){for(var t=1;t0&&I(e[0].place_id)):c(t)},[]),R=Object(r.useCallback)(function(){if(!window.google)throw new Error("[react-google-places-typeahead]: Google maps API not laoded");M.current=new window.google.maps.places.AutocompleteService,b(!0)},[]);Object(r.useEffect)(function(){!n||window.google?R():window[n]=R},[]);var A=Object(r.useMemo)(function(){return S.map(function(e){return y({active:T===e.placeId},e)})},[T,S]),L=Object(r.useMemo)(function(){return _||A.length>0},[A,_]),q=Object(r.useCallback)(function(){k([]),I(null)},[]),K=Object(r.useMemo)(function(){return e=function(e){e?(x(!0),M.current.getQueryPredictions(y({},f,{input:e}),D)):q()},t=a,function(){for(var r=arguments.length,o=new Array(r),c=0;c0?document.addEventListener("click",q):document.removeEventListener("click",q)},[A]),Object(r.useEffect)(function(){return function(){return document.removeEventListener("click",q)}},[]);var G=Object(r.useCallback)(function(e){s(e.target.value),M.current&&K(e.target.value)},[M.current]),U=Object(r.useCallback)(function(e){q(),s(e.description),o(e)},[]),B=Object(r.useCallback)(function(e){var t=A.length;if(!(_||t<1)&&[w,j,h,m].includes(e.keyCode))switch(e.preventDefault(),e.keyCode){case w:return void q();case j:var n=A.find(function(e){return e.active});return void U(n);default:var r,o=A.findIndex(function(e){return e.active})+(r={},O(r,m,-1),O(r,h,1),r)[e.keyCode];o<0?o=t-1:o>=t&&(o=0),I(A[o].placeId)}},[A,_]),W=Object(r.useCallback)(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=i(T),n=e.value,r=e.onChange,o=e.onKeyDown,c=g(e,["value","onChange","onKeyDown"]);if(n)throw new Error("[react-google-places-typeahead]: getInputProps does not accept `value`. Use `value` prop instead");if(r)throw new Error("[react-google-places-typeahead]: getInputProps does not accept `onChange`. Use `onChange` prop instead");return y({},c,{role:"combobox","aria-autocomplete":"list","aria-expanded":A.length>1,"aria-activedescendant":t,value:u,disabled:!d,onChange:G,onKeyDown:function(e){B(e),o&&o(e)}})},[u,B,A,d,T]),N=Object(r.useCallback)(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.onClick,r=t.onMouseOver,o=g(t,["onClick","onMouseOver"]);return y({},o,{key:e.id,id:i(e.placeId),onClick:function(t){U(e),n&&n(t)},onMouseOver:function(t){I(e.placeId),r&&r(t)}})},[]);return t({suggestions:A,isLoading:_,showList:L,getInputProps:W,getSuggestionItemProps:N})}P.displayName="GooglePlacesTypeahead",P.defaultProps={onSelect:function(){return null},onError:function(){return null},gMapsCallback:null,debounce:200,searchOptions:{}},P.propTypes={children:c.a.func.isRequired,value:c.a.string.isRequired,onChange:c.a.func.isRequired,onError:c.a.func,gMapsCallback:c.a.string,onSelect:c.a.func,debounce:c.a.number,searchOptions:c.a.shape({bounds:c.a.object,componentRestrictions:c.a.object,location:c.a.object,offset:c.a.oneOfType([c.a.number,c.a.string]),radius:c.a.oneOfType([c.a.number,c.a.string]),types:c.a.array})};t.default=P}]); \ No newline at end of file diff --git a/package.json b/package.json index b5762d3..6efc60a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@netojose/react-google-places-typeahead", - "version": "1.0.1", + "version": "1.0.2", "description": "React component for Google Maps Places Autocomplete", "main": "./dist/index.js", "license": "MIT",