New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

google-maps-api-react-provider

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-maps-api-react-provider - npm Package Compare versions

Comparing version

to
1.0.0

2

dist/index.js
/*! For license information please see index.js.LICENSE.txt */
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("react"));else if("function"==typeof define&&define.amd)define(["react"],r);else{var t="object"==typeof exports?r(require("react")):r(e.react);for(var i in t)("object"==typeof exports?exports:e)[i]=t[i]}}("undefined"==typeof self?this:self,(e=>(()=>{"use strict";var r={496:r=>{r.exports=e}},t={};function i(e){var o=t[e];if(void 0!==o)return o.exports;var s=t[e]={exports:{}};return r[e](s,s.exports,i),s.exports}i.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return i.d(r,{a:r}),r},i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{i.r(o),i.d(o,{MapsApiProvider:()=>h,useGoogleMapsLibraries:()=>p});var e=i(496),r=i.n(e);var t=function e(r,t){if(r===t)return!0;if(r&&t&&"object"==typeof r&&"object"==typeof t){if(r.constructor!==t.constructor)return!1;var i,o,s;if(Array.isArray(r)){if((i=r.length)!=t.length)return!1;for(o=i;0!=o--;)if(!e(r[o],t[o]))return!1;return!0}if(r.constructor===RegExp)return r.source===t.source&&r.flags===t.flags;if(r.valueOf!==Object.prototype.valueOf)return r.valueOf()===t.valueOf();if(r.toString!==Object.prototype.toString)return r.toString()===t.toString();if((i=(s=Object.keys(r)).length)!==Object.keys(t).length)return!1;for(o=i;0!=o--;)if(!Object.prototype.hasOwnProperty.call(t,s[o]))return!1;for(o=i;0!=o--;){var n=s[o];if(!e(r[n],t[n]))return!1}return!0}return r!=r&&t!=t};const s="__googleMapsScriptId";var n;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(n||(n={}));class a{constructor({apiKey:e,authReferrerPolicy:r,channel:i,client:o,id:n=s,language:l,libraries:c=[],mapIds:h,nonce:p,region:u,retries:d=3,url:g="https://maps.googleapis.com/maps/api/js",version:f}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=e,this.authReferrerPolicy=r,this.channel=i,this.client=o,this.id=n||s,this.language=l,this.libraries=c,this.mapIds=h,this.nonce=p,this.region=u,this.retries=d,this.url=g,this.version=f,a.instance){if(!t(this.options,a.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(a.instance.options)}`);return a.instance}a.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,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?n.FAILURE:this.done?n.SUCCESS:this.loading?n.LOADING:n.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+="?callback=__googleMapsCallback",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(",")}`),this.authReferrerPolicy&&(e+=`&auth_referrer_policy=${this.authReferrerPolicy}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,r)=>{this.loadCallback((t=>{t?r(t.error):e(window.google)}))}))}importLibrary(e){return this.execute(),google.maps.importLibrary(e)}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){var e,r;if(document.getElementById(this.id))return void this.callback();const t={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(t).forEach((e=>!t[e]&&delete t[e])),(null===(r=null===(e=null===window||void 0===window?void 0:window.google)||void 0===e?void 0:e.maps)||void 0===r?void 0:r.importLibrary)||(e=>{let r,t,i,o="The Google Maps JavaScript API",s="google",n="importLibrary",a="__ib__",l=document,c=window;c=c[s]||(c[s]={});const h=c.maps||(c.maps={}),p=new Set,u=new URLSearchParams,d=()=>r||(r=new Promise(((n,c)=>{return d=this,g=void 0,y=function*(){var d;for(i in yield t=l.createElement("script"),t.id=this.id,u.set("libraries",[...p]+""),e)u.set(i.replace(/[A-Z]/g,(e=>"_"+e[0].toLowerCase())),e[i]);u.set("callback",s+".maps."+a),t.src=this.url+"?"+u,h[a]=n,t.onerror=()=>r=c(Error(o+" could not load.")),t.nonce=this.nonce||(null===(d=l.querySelector("script[nonce]"))||void 0===d?void 0:d.nonce)||"",l.head.append(t)},new((f=void 0)||(f=Promise))((function(e,r){function t(e){try{o(y.next(e))}catch(e){r(e)}}function i(e){try{o(y.throw(e))}catch(e){r(e)}}function o(r){var o;r.done?e(r.value):(o=r.value,o instanceof f?o:new f((function(e){e(o)}))).then(t,i)}o((y=y.apply(d,g||[])).next())}));var d,g,f,y})));h[n]?console.warn(o+" only loads once. Ignoring:",e):h[n]=(e,...r)=>p.add(e)&&d().then((()=>h[n](e,...r)))})(t);const i=this.libraries.map((e=>this.importLibrary(e)));i.length||i.push(this.importLibrary("core")),Promise.all(i).then((()=>this.callback()),(e=>{const r=new ErrorEvent("error",{error:e});this.loadErrorCallback(r)}))}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.error(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}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.setScript())}}}const l=r().createContext({}),c=e=>{const{children:t,value:i}=e;return r().createElement(l.Provider,{value:i},t)};const h=t=>{const{apiKey:i,children:o,mapsLibrary:s=!0,placesLibrary:n,geocodingLibrary:l,version:h="weekly"}=t,p=function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)r.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(t[i[o]]=e[i[o]])}return t}(t,["apiKey","children","mapsLibrary","placesLibrary","geocodingLibrary","version"]),[u,d]=(0,e.useState)({});return(0,e.useLayoutEffect)((()=>{const e={},r=new a(Object.assign({apiKey:i,version:h},p));s&&(e.mapsLibrary=r.importLibrary("maps")),n&&(e.placesLibrary=r.importLibrary("places")),d(e)}),[]),r().createElement(c,{value:u},o)},p=function(){return(0,e.useContext)(l)}})(),o})()));
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var r="object"==typeof exports?t(require("react")):t(e.react);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}("undefined"==typeof self?this:self,(e=>(()=>{"use strict";var t={496:t=>{t.exports=e}},r={};function i(e){var o=r[e];if(void 0!==o)return o.exports;var n=r[e]={exports:{}};return t[e](n,n.exports,i),n.exports}i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{i.r(o),i.d(o,{MapsApiProvider:()=>h,useGoogleMapsLibraries:()=>u});var e=i(496),t=i.n(e);var r=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var i,o,n;if(Array.isArray(t)){if((i=t.length)!=r.length)return!1;for(o=i;0!=o--;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((i=(n=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(o=i;0!=o--;)if(!Object.prototype.hasOwnProperty.call(r,n[o]))return!1;for(o=i;0!=o--;){var s=n[o];if(!e(t[s],r[s]))return!1}return!0}return t!=t&&r!=r};const n="__googleMapsScriptId";var s;!function(e){e[e.INITIALIZED=0]="INITIALIZED",e[e.LOADING=1]="LOADING",e[e.SUCCESS=2]="SUCCESS",e[e.FAILURE=3]="FAILURE"}(s||(s={}));class a{constructor({apiKey:e,authReferrerPolicy:t,channel:i,client:o,id:s=n,language:l,libraries:c=[],mapIds:h,nonce:u,region:d,retries:p=3,url:g="https://maps.googleapis.com/maps/api/js",version:f}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=e,this.authReferrerPolicy=t,this.channel=i,this.client=o,this.id=s||n,this.language=l,this.libraries=c,this.mapIds=h,this.nonce=u,this.region=d,this.retries=p,this.url=g,this.version=f,a.instance){if(!r(this.options,a.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(a.instance.options)}`);return a.instance}a.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,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?s.FAILURE:this.done?s.SUCCESS:this.loading?s.LOADING:s.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+="?callback=__googleMapsCallback",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(",")}`),this.authReferrerPolicy&&(e+=`&auth_referrer_policy=${this.authReferrerPolicy}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise(((e,t)=>{this.loadCallback((r=>{r?t(r.error):e(window.google)}))}))}importLibrary(e){return this.execute(),google.maps.importLibrary(e)}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){var e,t;if(document.getElementById(this.id))return void this.callback();const r={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(r).forEach((e=>!r[e]&&delete r[e])),(null===(t=null===(e=null===window||void 0===window?void 0:window.google)||void 0===e?void 0:e.maps)||void 0===t?void 0:t.importLibrary)||(e=>{let t,r,i,o="The Google Maps JavaScript API",n="google",s="importLibrary",a="__ib__",l=document,c=window;c=c[n]||(c[n]={});const h=c.maps||(c.maps={}),u=new Set,d=new URLSearchParams,p=()=>t||(t=new Promise(((s,c)=>{return p=this,g=void 0,y=function*(){var p;for(i in yield r=l.createElement("script"),r.id=this.id,d.set("libraries",[...u]+""),e)d.set(i.replace(/[A-Z]/g,(e=>"_"+e[0].toLowerCase())),e[i]);d.set("callback",n+".maps."+a),r.src=this.url+"?"+d,h[a]=s,r.onerror=()=>t=c(Error(o+" could not load.")),r.nonce=this.nonce||(null===(p=l.querySelector("script[nonce]"))||void 0===p?void 0:p.nonce)||"",l.head.append(r)},new((f=void 0)||(f=Promise))((function(e,t){function r(e){try{o(y.next(e))}catch(e){t(e)}}function i(e){try{o(y.throw(e))}catch(e){t(e)}}function o(t){var o;t.done?e(t.value):(o=t.value,o instanceof f?o:new f((function(e){e(o)}))).then(r,i)}o((y=y.apply(p,g||[])).next())}));var p,g,f,y})));h[s]?console.warn(o+" only loads once. Ignoring:",e):h[s]=(e,...t)=>u.add(e)&&p().then((()=>h[s](e,...t)))})(r);const i=this.libraries.map((e=>this.importLibrary(e)));i.length||i.push(this.importLibrary("core")),Promise.all(i).then((()=>this.callback()),(e=>{const t=new ErrorEvent("error",{error:e});this.loadErrorCallback(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.error(`Failed to load Google Maps script, retrying in ${e} ms.`),setTimeout((()=>{this.deleteScript(),this.setScript()}),e)}else this.onerrorEvent=e,this.callback()}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.setScript())}}}const l=t().createContext({}),c=e=>{const{children:r,value:i}=e;return t().createElement(l.Provider,{value:i},r)};const h=r=>{const{apiKey:i,children:o,version:n="weekly"}=r,s=function(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(r[i[o]]=e[i[o]])}return r}(r,["apiKey","children","version"]),[l,h]=(0,e.useState)({}),u=(0,e.useRef)(new a(Object.assign({apiKey:i,version:n},s)));return t().createElement(c,{value:{googleLibraries:l,addLibrary:function(e){const t=`${e}Library`,r=u.current.importLibrary(e);h(Object.assign(Object.assign({},l),{[t]:r}))}}},o)},u=function(){return(0,e.useContext)(l)}})(),o})()));

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

import type { GoogleMapsLibraries } from "../provider";
declare function useGoogleMapsLibraries(): GoogleMapsLibraries;
import type { GoogleMapsProviderValueType } from "../provider";
declare function useGoogleMapsLibraries(): GoogleMapsProviderValueType;
export default useGoogleMapsLibraries;

@@ -6,8 +6,4 @@ import React from "react";

apiKey: string;
mapsLibrary?: boolean;
placesLibrary?: boolean;
geocodingLibrary?: boolean;
markerLibrary?: boolean;
}
declare const MapsApiProvider: (props: MapsProps) => React.JSX.Element;
export default MapsApiProvider;
/// <reference types="google.maps" />
import React from "react";
declare const googleMapsContext: React.Context<any>;
type LibraryNames = "maps" | "places";
interface GoogleMapsLibraries {

@@ -10,5 +11,9 @@ mapsLibrary?: Promise<google.maps.MapsLibrary>;

}
interface GoogleMapsProviderValueType {
googleLibraries: GoogleMapsLibraries;
addLibrary: (libraryName: LibraryNames) => void;
}
interface GoogleMapsProviderProps {
children: React.ReactElement | React.ReactNode | React.JSX.Element;
value: GoogleMapsLibraries;
value: GoogleMapsProviderValueType;
}

@@ -18,2 +23,2 @@ declare const GoogleMapsProvider: (props: GoogleMapsProviderProps) => React.JSX.Element;

export { googleMapsContext };
export type { GoogleMapsLibraries };
export type { GoogleMapsLibraries, GoogleMapsProviderValueType, LibraryNames };
{
"name": "google-maps-api-react-provider",
"version": "0.1.2",
"version": "1.0.0",
"description": "React.js Google Maps API integration",

@@ -64,3 +64,7 @@ "main": "./dist",

"webpack-cli": "^5.1.4"
},
"peerDependencies": {
"react": ">= 16.8",
"react-dom": ">= 16.8"
}
}
# google-maps-api-react-provider package
![example workflow](https://github.com/github/docs/actions/workflows/main.yml/badge.svg)
<a href="https://www.npmjs.com/package/google-maps-api-react-provider">
<img alt="npm version" src="https://img.shields.io/npm/v/google-maps-api-react-provider"/>
</a>

@@ -5,0 +7,0 @@ This library is the root library for using components from the google-maps-api-react ecosystem in our code. The **MapsApiProvider** component provides child components with access to [Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript).

Sorry, the diff of this file is not supported yet