Socket
Socket
Sign inDemoInstall

@dylmye/mui-google-places-autocomplete

Package Overview
Dependencies
99
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.9 to 0.2.10

2

lib/index.es.js

@@ -15,3 +15,3 @@ import e,{useRef as t,useCallback as n,useEffect as o,forwardRef as r,useState as i,useImperativeHandle as s}from"react";import{Autocomplete as a,TextField as l,Grid as c,Box as u,Typography as p}from"@mui/material";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function g(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function d(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}var h=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var s=i[r];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n};var m;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(m||(m={}));class f{constructor({apiKey:e,channel:t,client:n,id:o="__googleMapsScriptId",libraries:r=[],language:i,region:s,version:a,mapIds:l,nonce:c,retries:u=3,url:p="https://maps.googleapis.com/maps/api/js"}){if(this.CALLBACK="__googleMapsCallback",this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.version=a,this.apiKey=e,this.channel=t,this.client=n,this.id=o||"__googleMapsScriptId",this.libraries=r,this.language=i,this.region=s,this.mapIds=l,this.nonce=c,this.retries=u,this.url=p,f.instance){if(!h(this.options,f.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(f.instance.options)}`);return f.instance}f.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url}}get status(){return this.errors.length?m.FAILURE:this.done?m.SUCCESS:this.loading?m.LOADING:m.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+=`?callback=${this.CALLBACK}`,this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`&region=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,t)=>{this.loadCallback((n=>{n?t(n.error):e(window.google)}))}))}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){if(document.getElementById(this.id))return void this.callback();const e=this.createUrl(),t=document.createElement("script");t.id=this.id,t.type="text/javascript",t.src=e,t.onerror=this.loadErrorCallback.bind(this),t.defer=!0,t.async=!0,this.nonce&&(t.nonce=this.nonce),document.head.appendChild(t)}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const e=this.errors.length*Math.pow(2,this.errors.length);console.log(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}setCallback(){window.__googleMapsCallback=this.callback.bind(this)}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((e=>{e(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setCallback(),this.setScript())}}}var w=r(((r,h)=>{var{inputValue:m,setInputValue:w,value:b,setValue:y,apiKey:v="",apiOptions:O={},autocompletionRequest:I={},debounce:S=300,minLengthAutocomplete:E=0,onLoadFailed:k=console.error,withSessionToken:j=!1,label:L,inputProps:C={}}=r,_=g(r,["inputValue","setInputValue","value","setValue","apiKey","apiOptions","autocompletionRequest","debounce","minLengthAutocomplete","onLoadFailed","withSessionToken","label","inputProps"]);const[x,A]=i(void 0),[T,P]=i(void 0),[G,K]=i([]),[$,V]=i(!1),[F,N]=i(),[R]=function(e,r,i){void 0===i&&(i={});var s=i.maxWait,a=t(null),l=t([]),c=i.leading,u=void 0===i.trailing||i.trailing,p=t(!1),g=t(null),d=t(!1),h=t(e);h.current=e;var m=n((function(){clearTimeout(g.current),clearTimeout(a.current),a.current=null,l.current=[],g.current=null,p.current=!1}),[]);o((function(){return d.current=!1,function(){d.current=!0}}),[]);var f=n((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];l.current=e,clearTimeout(g.current),p.current&&(p.current=!1),g.current||!c||p.current||(h.current.apply(h,e),p.current=!0),g.current=setTimeout((function(){var t=!0;c&&p.current&&(t=!1),m(),!d.current&&u&&t&&h.current.apply(h,e)}),r),s&&!a.current&&u&&(a.current=setTimeout((function(){var e=l.current;m(),d.current||h.current.apply(null,e)}),s))}),[s,r,m,c,u]),w=n((function(){g.current&&(h.current.apply(null,l.current),m())}),[m]);return[f,m,w]}(((e,t)=>{if(!x||e.length<E)return t([]);V(!0);const n=Object.assign({},I);x.getPlacePredictions(((e,t,n)=>{const{bounds:o,location:r}=e,i=g(e,["bounds","location"]),s=Object.assign({input:t},i);return n&&(s.sessionToken=n),o&&(s.bounds=new google.maps.LatLngBounds(...o)),r&&(s.location=new google.maps.LatLng(r)),s})(n,e,j&&T),(e=>{t(e||[]),V(!1)}))}),S),U=()=>{if(!window.google)throw new Error("[mui-google-places-autocomplete]: Google script not loaded");if(!window.google.maps)throw new Error("[mui-google-places-autocomplete]: Google maps script not loaded");if(!window.google.maps.places)throw new Error("[mui-google-places-autocomplete]: Google maps places script not loaded");A(new window.google.maps.places.AutocompleteService),P(new google.maps.places.AutocompleteSessionToken)};return s(h,(()=>({getSessionToken:()=>T,refreshSessionToken:()=>{P(new google.maps.places.AutocompleteSessionToken)}})),[T]),o((()=>{v?d(void 0,void 0,void 0,(function*(){try{window.google&&window.google.maps&&window.google.maps.places||(yield new f(Object.assign({apiKey:v},Object.assign({libraries:["places"]},O))).load()),U()}catch(e){k(e)}})):U()}),[]),o((()=>{x&&R(m,K)}),[m]),e.createElement(a,Object.assign({autoComplete:!0,includeInputInList:!0,filterSelectedOptions:!0,noOptionsText:"Nothing found",onChange:(e,t)=>{t&&K([t,...G]),y?y(t):N(t)},onInputChange:(e,t)=>{w(t)},loading:$},_,{options:G,value:null!=b?b:F,renderInput:t=>e.createElement(l,Object.assign({},t,C,{label:L,fullWidth:!0})),renderOption:(t,n)=>{const o=[{text:n.structured_formatting.main_text}];return e.createElement("li",Object.assign({},t),e.createElement(c,{container:!0,alignItems:"center"},e.createElement(c,{item:!0,sx:{width:"calc(100%)",wordWrap:"break-word"}},o.map(((t,n)=>e.createElement(u,{key:n,component:"span"},t.text))),e.createElement(p,{variant:"body2",color:"text.secondary"},n.structured_formatting.secondary_text))))},getOptionLabel:e=>"string"==typeof e?e:e.description,isOptionEqualToValue:(e,t)=>!!t&&e.description===(null==t?void 0:t.description)}))}));const b=t=>{var{field:n,form:{setFieldValue:o,isSubmitting:r}}=t,s=g(t,["field","form"]);const[a,l]=i((null==n?void 0:n.value)?{description:n.value,matched_substrings:[],place_id:"",structured_formatting:{main_text:"",main_text_matched_substrings:[],secondary_text:""},terms:[],types:[]}:null);return e.createElement(w,Object.assign({inputValue:n.value,setInputValue:e=>o(n.name,e),value:a,setValue:l,disabled:r},s))},y=e=>new Promise(((t,n)=>{try{return t({lat:e.geometry.location.lat(),lng:e.geometry.location.lng()})}catch(e){return n(e)}})),v=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({address:e},((e,t)=>t!==n?r(t):o(e)))}))},O=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({location:e},((e,t)=>t!==n?r(t):o(e)))}))},I=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({placeId:e},((e,t)=>t!==n?r(t):o(e)))}))};export{b as GooglePlacesAutocompleteField,w as default,v as geocodeByAddress,O as geocodeByLatLng,I as geocodeByPlaceId,y as getLatLng};
***************************************************************************** */function g(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function d(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}var h=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var s=i[r];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n};var m;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(m||(m={}));class f{constructor({apiKey:e,channel:t,client:n,id:o="__googleMapsScriptId",libraries:r=[],language:i,region:s,version:a,mapIds:l,nonce:c,retries:u=3,url:p="https://maps.googleapis.com/maps/api/js"}){if(this.CALLBACK="__googleMapsCallback",this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.version=a,this.apiKey=e,this.channel=t,this.client=n,this.id=o||"__googleMapsScriptId",this.libraries=r,this.language=i,this.region=s,this.mapIds=l,this.nonce=c,this.retries=u,this.url=p,f.instance){if(!h(this.options,f.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(f.instance.options)}`);return f.instance}f.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url}}get status(){return this.errors.length?m.FAILURE:this.done?m.SUCCESS:this.loading?m.LOADING:m.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+=`?callback=${this.CALLBACK}`,this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`&region=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,t)=>{this.loadCallback((n=>{n?t(n.error):e(window.google)}))}))}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){if(document.getElementById(this.id))return void this.callback();const e=this.createUrl(),t=document.createElement("script");t.id=this.id,t.type="text/javascript",t.src=e,t.onerror=this.loadErrorCallback.bind(this),t.defer=!0,t.async=!0,this.nonce&&(t.nonce=this.nonce),document.head.appendChild(t)}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const e=this.errors.length*Math.pow(2,this.errors.length);console.log(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}setCallback(){window.__googleMapsCallback=this.callback.bind(this)}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((e=>{e(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setCallback(),this.setScript())}}}var w=r(((r,h)=>{var{inputValue:m,setInputValue:w,value:b,setValue:y,apiKey:v="",apiOptions:O={},autocompletionRequest:I={},debounce:S=300,minLengthAutocomplete:E=0,onLoadFailed:k=console.error,withSessionToken:j=!1,label:L,inputProps:C={}}=r,_=g(r,["inputValue","setInputValue","value","setValue","apiKey","apiOptions","autocompletionRequest","debounce","minLengthAutocomplete","onLoadFailed","withSessionToken","label","inputProps"]);const[x,A]=i(void 0),[T,P]=i(void 0),[G,K]=i([]),[$,V]=i(!1),[F,N]=i(null),[R]=function(e,r,i){void 0===i&&(i={});var s=i.maxWait,a=t(null),l=t([]),c=i.leading,u=void 0===i.trailing||i.trailing,p=t(!1),g=t(null),d=t(!1),h=t(e);h.current=e;var m=n((function(){clearTimeout(g.current),clearTimeout(a.current),a.current=null,l.current=[],g.current=null,p.current=!1}),[]);o((function(){return d.current=!1,function(){d.current=!0}}),[]);var f=n((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];l.current=e,clearTimeout(g.current),p.current&&(p.current=!1),g.current||!c||p.current||(h.current.apply(h,e),p.current=!0),g.current=setTimeout((function(){var t=!0;c&&p.current&&(t=!1),m(),!d.current&&u&&t&&h.current.apply(h,e)}),r),s&&!a.current&&u&&(a.current=setTimeout((function(){var e=l.current;m(),d.current||h.current.apply(null,e)}),s))}),[s,r,m,c,u]),w=n((function(){g.current&&(h.current.apply(null,l.current),m())}),[m]);return[f,m,w]}(((e,t)=>{if(!x||e.length<E)return t([]);V(!0);const n=Object.assign({},I);x.getPlacePredictions(((e,t,n)=>{const{bounds:o,location:r}=e,i=g(e,["bounds","location"]),s=Object.assign({input:t},i);return n&&(s.sessionToken=n),o&&(s.bounds=new google.maps.LatLngBounds(...o)),r&&(s.location=new google.maps.LatLng(r)),s})(n,e,j&&T),(e=>{t(e||[]),V(!1)}))}),S),U=()=>{if(!window.google)throw new Error("[mui-google-places-autocomplete]: Google script not loaded");if(!window.google.maps)throw new Error("[mui-google-places-autocomplete]: Google maps script not loaded");if(!window.google.maps.places)throw new Error("[mui-google-places-autocomplete]: Google maps places script not loaded");A(new window.google.maps.places.AutocompleteService),P(new google.maps.places.AutocompleteSessionToken)};return s(h,(()=>({getSessionToken:()=>T,refreshSessionToken:()=>{P(new google.maps.places.AutocompleteSessionToken)}})),[T]),o((()=>{v?d(void 0,void 0,void 0,(function*(){try{window.google&&window.google.maps&&window.google.maps.places||(yield new f(Object.assign({apiKey:v},Object.assign({libraries:["places"]},O))).load()),U()}catch(e){k(e)}})):U()}),[]),o((()=>{x&&R(m,K)}),[m]),e.createElement(a,Object.assign({autoComplete:!0,includeInputInList:!0,filterSelectedOptions:!0,noOptionsText:"Nothing found",onChange:(e,t)=>{t&&K([t,...G]),y?y(t):N(t)},onInputChange:(e,t)=>{w(t)},loading:$},_,{options:G,value:null!=b?b:F,renderInput:t=>e.createElement(l,Object.assign({},t,C,{label:L,fullWidth:!0})),renderOption:(t,n)=>{const o=[{text:n.structured_formatting.main_text}];return e.createElement("li",Object.assign({},t),e.createElement(c,{container:!0,alignItems:"center"},e.createElement(c,{item:!0,sx:{width:"calc(100%)",wordWrap:"break-word"}},o.map(((t,n)=>e.createElement(u,{key:n,component:"span"},t.text))),e.createElement(p,{variant:"body2",color:"text.secondary"},n.structured_formatting.secondary_text))))},getOptionLabel:e=>"string"==typeof e?e:e.description,isOptionEqualToValue:(e,t)=>!!t&&e.description===(null==t?void 0:t.description)}))}));const b=t=>{var{field:n,form:{setFieldValue:o,isSubmitting:r}}=t,s=g(t,["field","form"]);const[a,l]=i((null==n?void 0:n.value)?{description:n.value,matched_substrings:[],place_id:"",structured_formatting:{main_text:"",main_text_matched_substrings:[],secondary_text:""},terms:[],types:[]}:null);return e.createElement(w,Object.assign({inputValue:n.value,setInputValue:e=>o(n.name,e),value:null!=a?a:null,setValue:l,disabled:r},s))},y=e=>new Promise(((t,n)=>{try{return t({lat:e.geometry.location.lat(),lng:e.geometry.location.lng()})}catch(e){return n(e)}})),v=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({address:e},((e,t)=>t!==n?r(t):o(e)))}))},O=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({location:e},((e,t)=>t!==n?r(t):o(e)))}))},I=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({placeId:e},((e,t)=>t!==n?r(t):o(e)))}))};export{b as GooglePlacesAutocompleteField,w as default,v as geocodeByAddress,O as geocodeByLatLng,I as geocodeByPlaceId,y as getLatLng};
//# sourceMappingURL=index.es.js.map

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@mui/material");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(e);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@mui/material");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e);
/*! *****************************************************************************

@@ -15,3 +15,3 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(o[n[r]]=e[n[r]])}return o}function i(e,t,o,n){return new(o||(o=Promise))((function(r,i){function s(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))}var s=function e(t,o){if(t===o)return!0;if(t&&o&&"object"==typeof t&&"object"==typeof o){if(t.constructor!==o.constructor)return!1;var n,r,i;if(Array.isArray(t)){if((n=t.length)!=o.length)return!1;for(r=n;0!=r--;)if(!e(t[r],o[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===o.source&&t.flags===o.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===o.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===o.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(o).length)return!1;for(r=n;0!=r--;)if(!Object.prototype.hasOwnProperty.call(o,i[r]))return!1;for(r=n;0!=r--;){var s=i[r];if(!e(t[s],o[s]))return!1}return!0}return t!=t&&o!=o};var a;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(a||(a={}));class l{constructor({apiKey:e,channel:t,client:o,id:n="__googleMapsScriptId",libraries:r=[],language:i,region:a,version:c,mapIds:u,nonce:d,retries:p=3,url:g="https://maps.googleapis.com/maps/api/js"}){if(this.CALLBACK="__googleMapsCallback",this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.version=c,this.apiKey=e,this.channel=t,this.client=o,this.id=n||"__googleMapsScriptId",this.libraries=r,this.language=i,this.region=a,this.mapIds=u,this.nonce=d,this.retries=p,this.url=g,l.instance){if(!s(this.options,l.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(l.instance.options)}`);return l.instance}l.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url}}get status(){return this.errors.length?a.FAILURE:this.done?a.SUCCESS:this.loading?a.LOADING:a.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+=`?callback=${this.CALLBACK}`,this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`&region=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,t)=>{this.loadCallback((o=>{o?t(o.error):e(window.google)}))}))}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){if(document.getElementById(this.id))return void this.callback();const e=this.createUrl(),t=document.createElement("script");t.id=this.id,t.type="text/javascript",t.src=e,t.onerror=this.loadErrorCallback.bind(this),t.defer=!0,t.async=!0,this.nonce&&(t.nonce=this.nonce),document.head.appendChild(t)}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const e=this.errors.length*Math.pow(2,this.errors.length);console.log(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}setCallback(){window.__googleMapsCallback=this.callback.bind(this)}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((e=>{e(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setCallback(),this.setScript())}}}var c=e.forwardRef(((o,s)=>{var{inputValue:a,setInputValue:c,value:u,setValue:d,apiKey:p="",apiOptions:g={},autocompletionRequest:h={},debounce:f=300,minLengthAutocomplete:m=0,onLoadFailed:b=console.error,withSessionToken:w=!1,label:y,inputProps:v={}}=o,O=r(o,["inputValue","setInputValue","value","setValue","apiKey","apiOptions","autocompletionRequest","debounce","minLengthAutocomplete","onLoadFailed","withSessionToken","label","inputProps"]);const[S,I]=e.useState(void 0),[E,k]=e.useState(void 0),[x,L]=e.useState([]),[j,C]=e.useState(!1),[A,_]=e.useState(),[T]=function(t,o,n){void 0===n&&(n={});var r=n.maxWait,i=e.useRef(null),s=e.useRef([]),a=n.leading,l=void 0===n.trailing||n.trailing,c=e.useRef(!1),u=e.useRef(null),d=e.useRef(!1),p=e.useRef(t);p.current=t;var g=e.useCallback((function(){clearTimeout(u.current),clearTimeout(i.current),i.current=null,s.current=[],u.current=null,c.current=!1}),[]);e.useEffect((function(){return d.current=!1,function(){d.current=!0}}),[]);var h=e.useCallback((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];s.current=e,clearTimeout(u.current),c.current&&(c.current=!1),u.current||!a||c.current||(p.current.apply(p,e),c.current=!0),u.current=setTimeout((function(){var t=!0;a&&c.current&&(t=!1),g(),!d.current&&l&&t&&p.current.apply(p,e)}),o),r&&!i.current&&l&&(i.current=setTimeout((function(){var e=s.current;g(),d.current||p.current.apply(null,e)}),r))}),[r,o,g,a,l]),f=e.useCallback((function(){u.current&&(p.current.apply(null,s.current),g())}),[g]);return[h,g,f]}(((e,t)=>{if(!S||e.length<m)return t([]);C(!0);const o=Object.assign({},h);S.getPlacePredictions(((e,t,o)=>{const{bounds:n,location:i}=e,s=r(e,["bounds","location"]),a=Object.assign({input:t},s);return o&&(a.sessionToken=o),n&&(a.bounds=new google.maps.LatLngBounds(...n)),i&&(a.location=new google.maps.LatLng(i)),a})(o,e,w&&E),(e=>{t(e||[]),C(!1)}))}),f),P=()=>{if(!window.google)throw new Error("[mui-google-places-autocomplete]: Google script not loaded");if(!window.google.maps)throw new Error("[mui-google-places-autocomplete]: Google maps script not loaded");if(!window.google.maps.places)throw new Error("[mui-google-places-autocomplete]: Google maps places script not loaded");I(new window.google.maps.places.AutocompleteService),k(new google.maps.places.AutocompleteSessionToken)};return e.useImperativeHandle(s,(()=>({getSessionToken:()=>E,refreshSessionToken:()=>{k(new google.maps.places.AutocompleteSessionToken)}})),[E]),e.useEffect((()=>{p?i(void 0,void 0,void 0,(function*(){try{window.google&&window.google.maps&&window.google.maps.places||(yield new l(Object.assign({apiKey:p},Object.assign({libraries:["places"]},g))).load()),P()}catch(e){b(e)}})):P()}),[]),e.useEffect((()=>{S&&T(a,L)}),[a]),n.default.createElement(t.Autocomplete,Object.assign({autoComplete:!0,includeInputInList:!0,filterSelectedOptions:!0,noOptionsText:"Nothing found",onChange:(e,t)=>{t&&L([t,...x]),d?d(t):_(t)},onInputChange:(e,t)=>{c(t)},loading:j},O,{options:x,value:null!=u?u:A,renderInput:e=>n.default.createElement(t.TextField,Object.assign({},e,v,{label:y,fullWidth:!0})),renderOption:(e,o)=>{const r=[{text:o.structured_formatting.main_text}];return n.default.createElement("li",Object.assign({},e),n.default.createElement(t.Grid,{container:!0,alignItems:"center"},n.default.createElement(t.Grid,{item:!0,sx:{width:"calc(100%)",wordWrap:"break-word"}},r.map(((e,o)=>n.default.createElement(t.Box,{key:o,component:"span"},e.text))),n.default.createElement(t.Typography,{variant:"body2",color:"text.secondary"},o.structured_formatting.secondary_text))))},getOptionLabel:e=>"string"==typeof e?e:e.description,isOptionEqualToValue:(e,t)=>!!t&&e.description===(null==t?void 0:t.description)}))}));exports.GooglePlacesAutocompleteField=t=>{var{field:o,form:{setFieldValue:i,isSubmitting:s}}=t,a=r(t,["field","form"]);const[l,u]=e.useState((null==o?void 0:o.value)?{description:o.value,matched_substrings:[],place_id:"",structured_formatting:{main_text:"",main_text_matched_substrings:[],secondary_text:""},terms:[],types:[]}:null);return n.default.createElement(c,Object.assign({inputValue:o.value,setInputValue:e=>i(o.name,e),value:l,setValue:u,disabled:s},a))},exports.default=c,exports.geocodeByAddress=e=>{const t=new window.google.maps.Geocoder,{OK:o}=window.google.maps.GeocoderStatus;return new Promise(((n,r)=>{t.geocode({address:e},((e,t)=>t!==o?r(t):n(e)))}))},exports.geocodeByLatLng=e=>{const t=new window.google.maps.Geocoder,{OK:o}=window.google.maps.GeocoderStatus;return new Promise(((n,r)=>{t.geocode({location:e},((e,t)=>t!==o?r(t):n(e)))}))},exports.geocodeByPlaceId=e=>{const t=new window.google.maps.Geocoder,{OK:o}=window.google.maps.GeocoderStatus;return new Promise(((n,r)=>{t.geocode({placeId:e},((e,t)=>t!==o?r(t):n(e)))}))},exports.getLatLng=e=>new Promise(((t,o)=>{try{return t({lat:e.geometry.location.lat(),lng:e.geometry.location.lng()})}catch(e){return o(e)}}));
***************************************************************************** */function r(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}function i(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))}var s=function e(t,n){if(t===n)return!0;if(t&&n&&"object"==typeof t&&"object"==typeof n){if(t.constructor!==n.constructor)return!1;var o,r,i;if(Array.isArray(t)){if((o=t.length)!=n.length)return!1;for(r=o;0!=r--;)if(!e(t[r],n[r]))return!1;return!0}if(t.constructor===RegExp)return t.source===n.source&&t.flags===n.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===n.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===n.toString();if((o=(i=Object.keys(t)).length)!==Object.keys(n).length)return!1;for(r=o;0!=r--;)if(!Object.prototype.hasOwnProperty.call(n,i[r]))return!1;for(r=o;0!=r--;){var s=i[r];if(!e(t[s],n[s]))return!1}return!0}return t!=t&&n!=n};var a;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(a||(a={}));class l{constructor({apiKey:e,channel:t,client:n,id:o="__googleMapsScriptId",libraries:r=[],language:i,region:a,version:c,mapIds:u,nonce:d,retries:p=3,url:g="https://maps.googleapis.com/maps/api/js"}){if(this.CALLBACK="__googleMapsCallback",this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.version=c,this.apiKey=e,this.channel=t,this.client=n,this.id=o||"__googleMapsScriptId",this.libraries=r,this.language=i,this.region=a,this.mapIds=u,this.nonce=d,this.retries=p,this.url=g,l.instance){if(!s(this.options,l.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(l.instance.options)}`);return l.instance}l.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url}}get status(){return this.errors.length?a.FAILURE:this.done?a.SUCCESS:this.loading?a.LOADING:a.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+=`?callback=${this.CALLBACK}`,this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`&region=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,t)=>{this.loadCallback((n=>{n?t(n.error):e(window.google)}))}))}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){if(document.getElementById(this.id))return void this.callback();const e=this.createUrl(),t=document.createElement("script");t.id=this.id,t.type="text/javascript",t.src=e,t.onerror=this.loadErrorCallback.bind(this),t.defer=!0,t.async=!0,this.nonce&&(t.nonce=this.nonce),document.head.appendChild(t)}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const e=this.errors.length*Math.pow(2,this.errors.length);console.log(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}setCallback(){window.__googleMapsCallback=this.callback.bind(this)}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach((e=>{e(this.onerrorEvent)})),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version)return console.warn("Google Maps already loaded outside @googlemaps/js-api-loader.This may result in undesirable behavior as options and script parameters may not match."),void this.callback();this.loading||(this.loading=!0,this.setCallback(),this.setScript())}}}var c=e.forwardRef(((n,s)=>{var{inputValue:a,setInputValue:c,value:u,setValue:d,apiKey:p="",apiOptions:g={},autocompletionRequest:h={},debounce:f=300,minLengthAutocomplete:m=0,onLoadFailed:b=console.error,withSessionToken:w=!1,label:y,inputProps:v={}}=n,O=r(n,["inputValue","setInputValue","value","setValue","apiKey","apiOptions","autocompletionRequest","debounce","minLengthAutocomplete","onLoadFailed","withSessionToken","label","inputProps"]);const[S,I]=e.useState(void 0),[E,k]=e.useState(void 0),[x,L]=e.useState([]),[j,C]=e.useState(!1),[A,_]=e.useState(null),[T]=function(t,n,o){void 0===o&&(o={});var r=o.maxWait,i=e.useRef(null),s=e.useRef([]),a=o.leading,l=void 0===o.trailing||o.trailing,c=e.useRef(!1),u=e.useRef(null),d=e.useRef(!1),p=e.useRef(t);p.current=t;var g=e.useCallback((function(){clearTimeout(u.current),clearTimeout(i.current),i.current=null,s.current=[],u.current=null,c.current=!1}),[]);e.useEffect((function(){return d.current=!1,function(){d.current=!0}}),[]);var h=e.useCallback((function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];s.current=e,clearTimeout(u.current),c.current&&(c.current=!1),u.current||!a||c.current||(p.current.apply(p,e),c.current=!0),u.current=setTimeout((function(){var t=!0;a&&c.current&&(t=!1),g(),!d.current&&l&&t&&p.current.apply(p,e)}),n),r&&!i.current&&l&&(i.current=setTimeout((function(){var e=s.current;g(),d.current||p.current.apply(null,e)}),r))}),[r,n,g,a,l]),f=e.useCallback((function(){u.current&&(p.current.apply(null,s.current),g())}),[g]);return[h,g,f]}(((e,t)=>{if(!S||e.length<m)return t([]);C(!0);const n=Object.assign({},h);S.getPlacePredictions(((e,t,n)=>{const{bounds:o,location:i}=e,s=r(e,["bounds","location"]),a=Object.assign({input:t},s);return n&&(a.sessionToken=n),o&&(a.bounds=new google.maps.LatLngBounds(...o)),i&&(a.location=new google.maps.LatLng(i)),a})(n,e,w&&E),(e=>{t(e||[]),C(!1)}))}),f),P=()=>{if(!window.google)throw new Error("[mui-google-places-autocomplete]: Google script not loaded");if(!window.google.maps)throw new Error("[mui-google-places-autocomplete]: Google maps script not loaded");if(!window.google.maps.places)throw new Error("[mui-google-places-autocomplete]: Google maps places script not loaded");I(new window.google.maps.places.AutocompleteService),k(new google.maps.places.AutocompleteSessionToken)};return e.useImperativeHandle(s,(()=>({getSessionToken:()=>E,refreshSessionToken:()=>{k(new google.maps.places.AutocompleteSessionToken)}})),[E]),e.useEffect((()=>{p?i(void 0,void 0,void 0,(function*(){try{window.google&&window.google.maps&&window.google.maps.places||(yield new l(Object.assign({apiKey:p},Object.assign({libraries:["places"]},g))).load()),P()}catch(e){b(e)}})):P()}),[]),e.useEffect((()=>{S&&T(a,L)}),[a]),o.default.createElement(t.Autocomplete,Object.assign({autoComplete:!0,includeInputInList:!0,filterSelectedOptions:!0,noOptionsText:"Nothing found",onChange:(e,t)=>{t&&L([t,...x]),d?d(t):_(t)},onInputChange:(e,t)=>{c(t)},loading:j},O,{options:x,value:null!=u?u:A,renderInput:e=>o.default.createElement(t.TextField,Object.assign({},e,v,{label:y,fullWidth:!0})),renderOption:(e,n)=>{const r=[{text:n.structured_formatting.main_text}];return o.default.createElement("li",Object.assign({},e),o.default.createElement(t.Grid,{container:!0,alignItems:"center"},o.default.createElement(t.Grid,{item:!0,sx:{width:"calc(100%)",wordWrap:"break-word"}},r.map(((e,n)=>o.default.createElement(t.Box,{key:n,component:"span"},e.text))),o.default.createElement(t.Typography,{variant:"body2",color:"text.secondary"},n.structured_formatting.secondary_text))))},getOptionLabel:e=>"string"==typeof e?e:e.description,isOptionEqualToValue:(e,t)=>!!t&&e.description===(null==t?void 0:t.description)}))}));exports.GooglePlacesAutocompleteField=t=>{var{field:n,form:{setFieldValue:i,isSubmitting:s}}=t,a=r(t,["field","form"]);const[l,u]=e.useState((null==n?void 0:n.value)?{description:n.value,matched_substrings:[],place_id:"",structured_formatting:{main_text:"",main_text_matched_substrings:[],secondary_text:""},terms:[],types:[]}:null);return o.default.createElement(c,Object.assign({inputValue:n.value,setInputValue:e=>i(n.name,e),value:null!=l?l:null,setValue:u,disabled:s},a))},exports.default=c,exports.geocodeByAddress=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({address:e},((e,t)=>t!==n?r(t):o(e)))}))},exports.geocodeByLatLng=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({location:e},((e,t)=>t!==n?r(t):o(e)))}))},exports.geocodeByPlaceId=e=>{const t=new window.google.maps.Geocoder,{OK:n}=window.google.maps.GeocoderStatus;return new Promise(((o,r)=>{t.geocode({placeId:e},((e,t)=>t!==n?r(t):o(e)))}))},exports.getLatLng=e=>new Promise(((t,n)=>{try{return t({lat:e.geometry.location.lat(),lng:e.geometry.location.lng()})}catch(e){return n(e)}}));
//# sourceMappingURL=index.js.map
{
"name": "@dylmye/mui-google-places-autocomplete",
"version": "0.2.9",
"version": "0.2.10",
"description": "Google places autocomplete input for MUI library in React.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/dylmye/mui-google-places-autocomplete",

{
"name": "@dylmye/mui-google-places-autocomplete",
"version": "0.2.9",
"version": "0.2.10",
"description": "Google places autocomplete input for MUI library in React.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/dylmye/mui-google-places-autocomplete",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc