From b5c0f1f53a3c68acdc61877c55c23a1fa681375e Mon Sep 17 00:00:00 2001 From: "Chris J. Shull" Date: Tue, 6 Jun 2023 09:01:17 -0700 Subject: [PATCH 1/2] fix: update examples and minimize URLs (#799) --- README.md | 16 +++++++++++++++- examples/index.html | 14 +++++++++++--- src/index.ts | 29 ++++++++++++++++++----------- 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2e239c80..6d1b27ff 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ npm i @googlemaps/js-api-loader Alternatively you may add the umd package directly to the html document using the unpkg link. ```html - + ``` When adding via unpkg, the loader can be accessed at `google.maps.plugins.loader.Loader`. @@ -61,6 +61,20 @@ const mapOptions = { ``` +Using a promise for a specific library. + +```javascript +// Promise for a specific library +loader + .importLibrary('maps') + .then(({Map}) => { + new Map(document.getElementById("map"), mapOptions); + }) + .catch((e) => { + // do something + }); +``` + Using a promise for when the script has loaded. ```javascript diff --git a/examples/index.html b/examples/index.html index a5468f98..9d24ee39 100644 --- a/examples/index.html +++ b/examples/index.html @@ -35,7 +35,6 @@ @@ -55,14 +54,23 @@ apiKey: "", version: "weekly", libraries: ["places"], - nonce: "caffe67d7b989af3a1c7f4a1a6c79bd9fb2b4eb0", }); + // Promise for a specific library + loader + .importLibrary('maps') + .then(({Map}) => { + new Map(document.getElementById("map"), mapOptions); + }) + .catch((e) => { + // do something + }); + // Promise loader .load() .then((google) => { - new google.maps.Map(document.getElementById("map"), mapOptions); + // new google.maps.Map(document.getElementById("map"), mapOptions); }) .catch((e) => { // do something diff --git a/src/index.ts b/src/index.ts index 42fe9093..b0d486ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -492,6 +492,23 @@ export class Loader { return; } + const params = { + key: this.apiKey, + channel: this.channel, + client: this.client, + libraries: this.libraries, + v: this.version, + mapIds: this.mapIds, + language: this.language, + region: this.region, + authReferrerPolicy: this.authReferrerPolicy, + }; + // keep the URL minimal: + Object.keys(params).forEach( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (key) => !(params as any)[key] && delete (params as any)[key] + ); + if (!window?.google?.maps?.importLibrary) { // tweaked copy of https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import // which also sets the url, the id, and the nonce @@ -531,17 +548,7 @@ export class Loader { })); // @ts-ignore d[l] ? console.warn(p + " only loads once. Ignoring:", g) : (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); - })({ - key: this.apiKey, - channel: this.channel, - client: this.client, - libraries: this.libraries, - v: this.version, - mapIds: this.mapIds, - language: this.language, - region: this.region, - authReferrerPolicy: this.authReferrerPolicy, - }); + })(params); /* eslint-enable */ } From 743dd02e146c7d36e0d3fb98bf8a1de14a38129a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 6 Jun 2023 16:02:31 +0000 Subject: [PATCH 2/2] chore(release): 1.16.1 [skip ci] ### [1.16.1](https://github.com/googlemaps/js-api-loader/compare/v1.16.0...v1.16.1) (2023-06-06) ### Bug Fixes * update examples and minimize URLs ([#799](https://github.com/googlemaps/js-api-loader/issues/799)) ([b5c0f1f](https://github.com/googlemaps/js-api-loader/commit/b5c0f1f53a3c68acdc61877c55c23a1fa681375e)) --- package-lock.json | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5f86f161..20e8bae4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@googlemaps/js-api-loader", - "version": "1.16.0", + "version": "1.16.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@googlemaps/js-api-loader", - "version": "1.16.0", + "version": "1.16.1", "license": "Apache-2.0", "dependencies": { "fast-deep-equal": "^3.1.3" @@ -11352,9 +11352,9 @@ } }, "node_modules/typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -20426,9 +20426,9 @@ } }, "typescript": { - "version": "4.9.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", - "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "dev": true }, "unicode-canonical-property-names-ecmascript": { diff --git a/package.json b/package.json index 8cce045d..16a76731 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@googlemaps/js-api-loader", - "version": "1.16.0", + "version": "1.16.1", "description": "Wrapper for the loading of Google Maps JavaScript API script in the browser", "keywords": [ "google",