google-maps-js-api-loader
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -9,25 +9,9 @@ import type { GoogleMapsLoaderOptions, GoogleMapsLibrary } from "./types"; | ||
} | ||
type OnError = (err: ErrorEvent | Error) => void; | ||
declare class GoogleMapsLoader { | ||
private static _resolve?; | ||
private static _reject?; | ||
private static _options?; | ||
private static [GoogleMapsLoaderStatus.LOADING]?; | ||
private static [GoogleMapsLoaderStatus.LOADED]?; | ||
private static [GoogleMapsLoaderStatus.ERROR]?; | ||
private static _runListeners; | ||
private static _cleanup; | ||
static setOptions(options: GoogleMapsLoaderOptions): void; | ||
/** | ||
* Starts listening for given {@link status} changes and calls the given {@link callback} when it does | ||
* @returns a function that can be used to remove the listener, which can then be invoked in cleanup logic | ||
*/ | ||
static addListener(status: GoogleMapsLoaderStatus.LOADING | GoogleMapsLoaderStatus.LOADED, callback: () => void): () => void; | ||
static addListener(status: GoogleMapsLoaderStatus.ERROR, callback: OnError): () => void; | ||
/** Current status of {@link GoogleMapsLoader} */ | ||
static status: GoogleMapsLoaderStatus; | ||
static readonly status: GoogleMapsLoaderStatus; | ||
/** | ||
* Promise of loading | ||
* | ||
* **Resolves** if {@link load} is success | ||
* **Resolves** if {@link GoogleMapsLoader.load load} is success | ||
* | ||
@@ -37,3 +21,3 @@ * **Rejects** | ||
* - if {@link google.maps} was loaded outside of this library | ||
* - if no options was {@link setOptions set} | ||
* - if no `options` was set | ||
* - if script loading failed | ||
@@ -43,7 +27,16 @@ */ | ||
/** | ||
* On the first call, it starts loading {@link google.maps} with the given {@link options} | ||
* @returns {@link completion} | ||
* Can be called multiple times, only on the first call it starts loading {@link google.maps} script with the given `options` | ||
* @returns {@link GoogleMapsLoader.completion completion} | ||
*/ | ||
static load(): Promise<void>; | ||
} | ||
export default GoogleMapsLoader; | ||
type Identity<T> = T; | ||
interface GoogleMapsLoader extends Identity<typeof GoogleMapsLoader> { | ||
/** | ||
* Sets options for the {@link GoogleMapsLoader} | ||
* @param options - options for {@link google.maps} script loading | ||
*/ | ||
(options: GoogleMapsLoaderOptions): GoogleMapsLoader; | ||
} | ||
declare const googleMapsLoader: GoogleMapsLoader; | ||
export { googleMapsLoader as GoogleMapsLoader }; |
@@ -1,1 +0,1 @@ | ||
function e(e,n){if(!(e instanceof n)){throw new TypeError("Cannot call a class as a function")}}function n(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||false;o.configurable=true;if("value"in o)o.writable=true;Object.defineProperty(e,o.key,o)}}function t(e,t,o){if(t)n(e.prototype,t);if(o)n(e,o);return e}var o=function(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e};var MarkerCluster=function(n){"use strict";var r="__gmlc",a=function e(){},i=function(e,n){var t=function(o,r){if(o){var a=n[o];return a&&(e+="&".concat(r||o,"=").concat(typeof a=="string"?a:a.join(","))),t}return e};return t};var u={NONE:0,LOADING:1,LOADED:2,ERROR:3},c,l,s,f=function(){function n(){e(this,n)}t(n,null,[{key:"_runListeners",value:function e(e,n,t){f.status=e,n(t);var o=f[e].values();for(var r=f[e].size;r--;)o.next().value(t)}},{key:"_cleanup",value:function e(e){f[e].clear(),delete f[e]}},{key:"setOptions",value:function e(e){f._options=e,f.setOptions=a}},{key:"addListener",value:function e(e,n){var t=f[e];return t?(t.add(n),function(){t.delete(n)}):a}},{key:"load",value:function e(){if(!f.status&&(typeof window==="undefined"?"undefined":o(window))<"u"){var e,n=f._options,t=f._reject;if(n?window.google&&google.maps&&(e="google.maps already loaded"):e="no options was set",e)t(new Error(e));else{f._runListeners(1,a),f._cleanup(1);var u=n.retryCount,c=u===void 0?2:u,l=function(e,o){var r=document.createElement("script"),a=document.head;r.type="text/javascript",r.onload=function(){r.onerror=null,r.onload=null},r.onerror=function(n){c--?setTimeout(function(){l(e,o),a.removeChild(r)},o):t(n)},n.defer!==void 0&&(r.defer=n.defer),n.async!==void 0&&(r.async=n.async),n.nonce!==void 0&&(r.nonce=n.nonce),r.src=e,a.appendChild(r)};window[r]=f._resolve,l(i("".concat(n.url||"https://maps.googleapis.com/maps/api/js","?callback=").concat(r),n)("apiKey","key")("version","v")("libraries")("channel")("client")("language")("region")("mapIds","map_ids")("authReferrerPolicy","auth_referrer_policy")(),n.retryDelay||2e3)}delete f._options,delete f._reject,delete f._resolve}return f.completion}}]);return n}(),d=f;c=1,l=2,s=3,d[c]=new Set,d[l]=new Set,d[s]=new Set,d.status=0,d.completion=new Promise(function(e,n){var t=function e(e,n){return function(t){f._runListeners(e,n,t),f._cleanup(2),f._cleanup(3),delete window[r]}};f._resolve=t(2,e),f._reject=t(3,n)});var p=d;n.GoogleMapsLoaderStatus=u;n.default=p;Object.defineProperty(n,"__esModule",{value:true});return n}({}); | ||
function n(n,o){if(n==null)return{};var t=e(n,o);var r,a;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);for(a=0;a<i.length;a++){r=i[a];if(o.indexOf(r)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(n,r))continue;t[r]=n[r]}}return t}function e(n,e){if(n==null)return{};var o={};var t=Object.keys(n);var r,a;for(a=0;a<t.length;a++){r=t[a];if(e.indexOf(r)>=0)continue;o[r]=n[r]}return o}function o(n){"@swc/helpers - typeof";return n&&typeof Symbol!=="undefined"&&n.constructor===Symbol?"symbol":typeof n}var MarkerCluster=function(e){"use strict";var t={NONE:0,LOADING:1,LOADED:2,ERROR:3},r=function(){var e,t,r="__gmlcb",a=new Promise(function(c,u){var l;l=function(){if(t=function(){return a},(typeof window==="undefined"?"undefined":o(window))<"u"){var l;if(e?window.google&&google.maps&&(l="google.maps already loaded"):l="no options was set",l)i.status=3,u(new Error(l));else{i.status=1;var s=e.async,d=e.defer,f=e.nonce,p=e.url,w=n(e,["async","defer","nonce","url"]),v=Object.keys(w).reduce(function(n,e){return"".concat(n,"&").concat(e,"=").concat(w[e])},"".concat(p||"https://maps.googleapis.com/maps/api/js","?callback=").concat(r)),m=function(){window.removeEventListener("online",m);var n=document.createElement("script"),e=document.head;n.type="text/javascript",n.onerror=function(){e.removeChild(n),navigator.onLine?(i.status=3,u(new Error("google.maps could not load"))):window.addEventListener("online",m)},d!=null&&(n.defer=d),s!=null&&(n.async=s),f!=null&&(n.nonce=f),n.src=v,e.appendChild(n)};window[r]=function(){delete window[r],i.status=2,c()},navigator.onLine?m():window.addEventListener("online",m)}}return a},t=l,l}),i=function(n){return e=n,i};return i.status=0,i.completion=a,i.load=function(){return t()},i}();e.GoogleMapsLoader=r;e.GoogleMapsLoaderStatus=t;return e}({}); |
221
index.js
@@ -1,19 +0,1 @@ | ||
// src/utils.ts | ||
var CALLBACK_NAME = "__gmlc"; | ||
var noop = function() { | ||
}; | ||
var getQueryParameterAcc = (url, obj) => { | ||
const add = (key, queryKey) => { | ||
if (key) { | ||
const value = obj[key]; | ||
if (value) { | ||
url += `&${queryKey || key}=${typeof value == "string" ? value : value.join(",")}`; | ||
} | ||
return add; | ||
} | ||
return url; | ||
}; | ||
return add; | ||
}; | ||
// src/index.ts | ||
@@ -26,142 +8,79 @@ var GoogleMapsLoaderStatus = { | ||
}; | ||
var _a, _b, _c; | ||
var _GoogleMapsLoader = class { | ||
static _runListeners(status, fn, arg) { | ||
_GoogleMapsLoader.status = status; | ||
fn(arg); | ||
const iterator = _GoogleMapsLoader[status].values(); | ||
for (let i = _GoogleMapsLoader[status].size; i--; ) { | ||
iterator.next().value(arg); | ||
} | ||
} | ||
static _cleanup(status) { | ||
_GoogleMapsLoader[status].clear(); | ||
delete _GoogleMapsLoader[status]; | ||
} | ||
static setOptions(options) { | ||
_GoogleMapsLoader._options = options; | ||
_GoogleMapsLoader.setOptions = noop; | ||
} | ||
static addListener(status, callback) { | ||
const set = _GoogleMapsLoader[status]; | ||
if (set) { | ||
set.add(callback); | ||
return () => { | ||
set.delete(callback); | ||
}; | ||
} | ||
return noop; | ||
} | ||
/** | ||
* On the first call, it starts loading {@link google.maps} with the given {@link options} | ||
* @returns {@link completion} | ||
*/ | ||
static load() { | ||
if (!_GoogleMapsLoader.status && typeof window != "undefined") { | ||
let errorMessage; | ||
const options = _GoogleMapsLoader._options; | ||
const reject = _GoogleMapsLoader._reject; | ||
if (!options) { | ||
errorMessage = "no options was set"; | ||
} else if (window.google && google.maps) { | ||
errorMessage = "google.maps already loaded"; | ||
} | ||
if (errorMessage) { | ||
reject(new Error(errorMessage)); | ||
} else { | ||
_GoogleMapsLoader._runListeners(1 /* LOADING */, noop); | ||
_GoogleMapsLoader._cleanup(1 /* LOADING */); | ||
let { retryCount = 2 } = options; | ||
const createScript = (url, retryDelay) => { | ||
const script = document.createElement("script"); | ||
const { head } = document; | ||
script.type = "text/javascript"; | ||
script.onload = () => { | ||
script.onerror = null; | ||
script.onload = null; | ||
}; | ||
script.onerror = (err) => { | ||
if (retryCount--) { | ||
setTimeout(() => { | ||
createScript(url, retryDelay); | ||
head.removeChild(script); | ||
}, retryDelay); | ||
} else { | ||
reject(err); | ||
var googleMapsLoader = (() => { | ||
let options; | ||
let load; | ||
const CALLBACK_NAME = "__gmlcb"; | ||
const completion = new Promise((resolve, reject) => { | ||
load = () => { | ||
load = () => completion; | ||
if (typeof window != "undefined") { | ||
let errorMessage; | ||
if (!options) { | ||
errorMessage = "no options was set"; | ||
} else if (window.google && google.maps) { | ||
errorMessage = "google.maps already loaded"; | ||
} | ||
if (errorMessage) { | ||
GoogleMapsLoader.status = 3 /* ERROR */; | ||
reject(new Error(errorMessage)); | ||
} else { | ||
GoogleMapsLoader.status = 1 /* LOADING */; | ||
const { async, defer, nonce, url, ...rest } = options; | ||
const combinedUrl = Object.keys(rest).reduce( | ||
(acc, key) => `${acc}&${key}=${rest[key]}`, | ||
`${url || "https://maps.googleapis.com/maps/api/js"}?callback=${CALLBACK_NAME}` | ||
); | ||
const createScript = () => { | ||
window.removeEventListener("online", createScript); | ||
const script = document.createElement("script"); | ||
const { head } = document; | ||
script.type = "text/javascript"; | ||
script.onerror = () => { | ||
head.removeChild(script); | ||
if (navigator.onLine) { | ||
GoogleMapsLoader.status = 3 /* ERROR */; | ||
reject(new Error("google.maps could not load")); | ||
} else { | ||
window.addEventListener("online", createScript); | ||
} | ||
}; | ||
if (defer != void 0) { | ||
script.defer = defer; | ||
} | ||
if (async != void 0) { | ||
script.async = async; | ||
} | ||
if (nonce != void 0) { | ||
script.nonce = nonce; | ||
} | ||
script.src = combinedUrl; | ||
head.appendChild(script); | ||
}; | ||
if (options.defer !== void 0) { | ||
script.defer = options.defer; | ||
window[CALLBACK_NAME] = () => { | ||
delete window[CALLBACK_NAME]; | ||
GoogleMapsLoader.status = 2 /* LOADED */; | ||
resolve(); | ||
}; | ||
if (navigator.onLine) { | ||
createScript(); | ||
} else { | ||
window.addEventListener("online", createScript); | ||
} | ||
if (options.async !== void 0) { | ||
script.async = options.async; | ||
} | ||
if (options.nonce !== void 0) { | ||
script.nonce = options.nonce; | ||
} | ||
script.src = url; | ||
head.appendChild(script); | ||
}; | ||
window[CALLBACK_NAME] = _GoogleMapsLoader._resolve; | ||
createScript( | ||
getQueryParameterAcc( | ||
`${options.url || "https://maps.googleapis.com/maps/api/js"}?callback=${CALLBACK_NAME}`, | ||
options | ||
)("apiKey", "key")( | ||
"version", | ||
"v" | ||
)("libraries")("channel")("client")("language")("region")( | ||
"mapIds", | ||
"map_ids" | ||
)("authReferrerPolicy", "auth_referrer_policy")(), | ||
options.retryDelay || 2e3 | ||
); | ||
} | ||
} | ||
delete _GoogleMapsLoader._options; | ||
delete _GoogleMapsLoader._reject; | ||
delete _GoogleMapsLoader._resolve; | ||
} | ||
return _GoogleMapsLoader.completion; | ||
} | ||
}; | ||
var GoogleMapsLoader = _GoogleMapsLoader; | ||
_a = 1 /* LOADING */, _b = 2 /* LOADED */, _c = 3 /* ERROR */; | ||
GoogleMapsLoader[_a] = /* @__PURE__ */ new Set(); | ||
GoogleMapsLoader[_b] = /* @__PURE__ */ new Set(); | ||
GoogleMapsLoader[_c] = /* @__PURE__ */ new Set(); | ||
/** Current status of {@link GoogleMapsLoader} */ | ||
GoogleMapsLoader.status = 0 /* NONE */; | ||
/** | ||
* Promise of loading | ||
* | ||
* **Resolves** if {@link load} is success | ||
* | ||
* **Rejects** | ||
* | ||
* - if {@link google.maps} was loaded outside of this library | ||
* - if no options was {@link setOptions set} | ||
* - if script loading failed | ||
*/ | ||
GoogleMapsLoader.completion = new Promise((resolve, reject) => { | ||
function handleSetStatus(status, fn) { | ||
return (arg) => { | ||
_GoogleMapsLoader._runListeners(status, fn, arg); | ||
_GoogleMapsLoader._cleanup(2 /* LOADED */); | ||
_GoogleMapsLoader._cleanup(3 /* ERROR */); | ||
delete window[CALLBACK_NAME]; | ||
return completion; | ||
}; | ||
} | ||
_GoogleMapsLoader._resolve = handleSetStatus( | ||
2 /* LOADED */, | ||
resolve | ||
); | ||
_GoogleMapsLoader._reject = handleSetStatus( | ||
3 /* ERROR */, | ||
reject | ||
); | ||
}); | ||
var src_default = GoogleMapsLoader; | ||
}); | ||
const GoogleMapsLoader = (_options) => { | ||
options = _options; | ||
return GoogleMapsLoader; | ||
}; | ||
GoogleMapsLoader.status = 0 /* NONE */; | ||
GoogleMapsLoader.completion = completion; | ||
GoogleMapsLoader.load = () => load(); | ||
return GoogleMapsLoader; | ||
})(); | ||
export { GoogleMapsLoaderStatus, src_default as default }; | ||
export { googleMapsLoader as GoogleMapsLoader, GoogleMapsLoaderStatus }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,34 @@ | ||
{"name":"google-maps-js-api-loader","version":"2.3.0","author":"","description":"A lightweight JavaScript library for loading the Google Maps JavaScript API","keywords":["google","maps","asynchronous","async","loader","browser"],"repository":{"type":"git","url":"git+https://github.com/Krombik/google-maps-loader.git"},"license":"MIT","bugs":{"url":"https://github.com/Krombik/google-maps-loader/issues"},"homepage":"https://github.com/Krombik/google-maps-loader#readme","engines":{"node":">10"},"publishConfig":{"access":"public"},"main":"./index.cjs","module":"./index.js","types":"./index.d.ts","unpkg":"./index.global.js","sideEffects":false} | ||
{ | ||
"name": "google-maps-js-api-loader", | ||
"version": "3.0.0", | ||
"author": "", | ||
"description": "A lightweight JavaScript library for loading the Google Maps JavaScript API", | ||
"keywords": [ | ||
"google", | ||
"maps", | ||
"asynchronous", | ||
"async", | ||
"loader", | ||
"browser" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Krombik/google-maps-loader.git" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Krombik/google-maps-loader/issues" | ||
}, | ||
"homepage": "https://github.com/Krombik/google-maps-loader#readme", | ||
"engines": { | ||
"node": ">10" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./index.cjs", | ||
"module": "./index.js", | ||
"types": "./index.d.ts", | ||
"unpkg": "./index.global.js", | ||
"sideEffects": false | ||
} |
@@ -1,2 +0,2 @@ | ||
# google-maps-js-api-loader | ||
# google-maps-loader | ||
@@ -10,15 +10,12 @@ ## Description | ||
```ts | ||
import GoogleMapsLoader, { | ||
GoogleMapsLoaderStatus, | ||
} from "google-maps-js-api-loader"; | ||
import { GoogleMapsLoader, GoogleMapsLoaderStatus } from "google-maps-loader"; | ||
GoogleMapsLoader.setOptions({ | ||
apiKey: API_KEY, | ||
GoogleMapsLoader({ | ||
key: API_KEY, | ||
// ...some other options | ||
}); | ||
const unlisten = GoogleMapsLoader.addListener( | ||
GoogleMapsLoaderStatus.LOADED, | ||
() => console.log("google.maps is ready") | ||
); | ||
if (GoogleMapsLoader.status === GoogleMapsLoaderStatus.LOADED) { | ||
console.log("google.maps is ready"); | ||
} | ||
@@ -32,24 +29,22 @@ GoogleMapsLoader.completion.then(() => console.log("google.maps is ready")); | ||
### setOptions | ||
### GoogleMapsLoader | ||
```ts | ||
static setOptions(options: GoogleMapsLoaderOptions): void | ||
function GoogleMapsLoader(options: GoogleMapsLoaderOptions): GoogleMapsLoader; | ||
``` | ||
Loader options should be set before [load](#load) execution | ||
Sets options for a `Google Maps JavaScript API` script, options must be set before [load](#load) is executed | ||
| GoogleMapsLoaderOptions | Description | | | ||
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | | ||
| apiKey | Your [API key](https://developers.google.com/maps/documentation/javascript/get-api-key) | | | ||
| version? | The [version](https://developers.google.com/maps/documentation/javascript/versions) of the `Google Maps JavaScript API` to use | | | ||
| libraries? | Array of additional `Google Maps JavaScript API` [libraries](https://developers.google.com/maps/documentation/javascript/libraries) to load | | | ||
| language? | The [language](https://developers.google.com/maps/documentation/javascript/localization) to use. This affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests. See the [list of supported languages](https://developers.google.com/maps/faq#languagesupport) | | | ||
| region? | The [region](https://developers.google.com/maps/documentation/javascript/localization#Region) code to use. This alters the map's behavior based on a given country or territory | | | ||
| authReferrerPolicy? | Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set `"origin"` to limit the amount of data sent when authorizing requests from the `Google Maps JavaScript API`. This is available starting in version **3.46**. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, `Google Maps JavaScript API` will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified | | | ||
| url? | Use a custom url and path to load the Google Maps API script | | | ||
| nonce? | Adds [nonce attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce) to the script | | | ||
| async? | Adds [async attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async) to the script | | | ||
| defer? | Adds [defer attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer) to the script | | | ||
| retryCount? | Number of retries if script loading fails | `2` | | ||
| retryDelay? | Delay between retries | `2000` | | ||
| GoogleMapsLoaderOptions | Description | | ||
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| key | Your [API key](https://developers.google.com/maps/documentation/javascript/get-api-key) | | ||
| v? | The [version](https://developers.google.com/maps/documentation/javascript/versions) of the `Google Maps JavaScript API` to use | | ||
| libraries? | Array of additional `Google Maps JavaScript API` [libraries](https://developers.google.com/maps/documentation/javascript/libraries) to load | | ||
| language? | The [language](https://developers.google.com/maps/documentation/javascript/localization) to use. This affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests. See the [list of supported languages](https://developers.google.com/maps/faq#languagesupport) | | ||
| region? | The [region](https://developers.google.com/maps/documentation/javascript/localization#Region) code to use. This alters the map's behavior based on a given country or territory | | ||
| auth_referrer_policy? | Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set `"origin"` to limit the amount of data sent when authorizing requests from the `Google Maps JavaScript API`. This is available starting in version **3.46**. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, `Google Maps JavaScript API` will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified | | ||
| url? | Use a custom url and path to load the Google Maps API script | | ||
| nonce? | Adds [nonce attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce) to the script | | ||
| async? | Adds [async attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async) to the script | | ||
| defer? | Adds [defer attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer) to the script | | ||
@@ -64,3 +59,3 @@ --- | ||
On the first call, it starts loading the `Google Maps JavaScript API` with the given [options](#setoptions) | ||
Can be called multiple times, only on the first call it starts loading `Google Maps JavaScript API` script with the given [options](#googlemapsloader) | ||
@@ -101,3 +96,3 @@ Returns [completion](#completion) | ||
- if `Google Maps JavaScript API` was loaded outside of this library | ||
- if no options was [set](#setoptions) | ||
- if no options was [set](#googlemapsloader) | ||
- if script loading failed | ||
@@ -107,23 +102,4 @@ | ||
### addListener | ||
```ts | ||
static addListener( | ||
status: GoogleMapsLoaderStatus.LOADING | GoogleMapsLoaderStatus.LOADED, | ||
callback: () => void | ||
): () => void; | ||
static addListener( | ||
status: GoogleMapsLoaderStatus.ERROR, | ||
callback: (err: ErrorEvent | Error) => void | ||
): () => void; | ||
``` | ||
Starts listening for given `status` changes and calls the given `callback` when it does | ||
Returns a function that can be used to remove the listener, which can then be invoked in cleanup logic | ||
--- | ||
## License | ||
MIT © [Krombik](https://github.com/Krombik) |
@@ -6,3 +6,3 @@ export type GoogleMapsLibrary = "drawing" | "geometry" | "localContext" | "places" | "visualization"; | ||
*/ | ||
apiKey: string; | ||
key: string; | ||
/** | ||
@@ -21,3 +21,3 @@ * @deprecated | ||
*/ | ||
version?: string; | ||
v?: string; | ||
/** | ||
@@ -38,7 +38,7 @@ * Array of additional Maps JavaScript API [libraries](https://developers.google.com/maps/documentation/javascript/libraries) to load | ||
*/ | ||
mapIds?: string[]; | ||
map_ids?: string[]; | ||
/** | ||
* Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set `"origin"` to limit the amount of data sent when authorizing requests from the Maps JavaScript API. This is available starting in version **3.46**. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, Maps JavaScript API will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified | ||
*/ | ||
authReferrerPolicy?: "origin"; | ||
auth_referrer_policy?: "origin"; | ||
/** | ||
@@ -61,12 +61,2 @@ * Use a custom url and path to load the Google Maps API script | ||
defer?: boolean; | ||
/** | ||
* Number of retries if script loading fails | ||
* @default 2 | ||
*/ | ||
retryCount?: number; | ||
/** | ||
* Delay between retries | ||
* @default 2000 | ||
*/ | ||
retryDelay?: number; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
36299
268
101
2