@formio/js 5.1.0-rc.4 → 5.1.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@
20
20
 
21
21
  /*! @license DOMPurify 3.2.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.3/LICENSE */
22
22
 
23
- /*! formiojs v5.1.0-rc.4 | https://unpkg.com/formiojs@5.1.0-rc.4/LICENSE.txt */
23
+ /*! formiojs v5.1.0-rc.6 | https://unpkg.com/formiojs@5.1.0-rc.6/LICENSE.txt */
24
24
 
25
25
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
26
26
 
@@ -1 +1 @@
1
- export {};
1
+ export { Formio } from "./InlineEmbed";
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Formio = void 0;
3
4
  const InlineEmbed_1 = require("./InlineEmbed");
4
5
  (0, InlineEmbed_1.embed)();
6
+ var InlineEmbed_2 = require("./InlineEmbed");
7
+ Object.defineProperty(exports, "Formio", { enumerable: true, get: function () { return InlineEmbed_2.Formio; } });
@@ -82,6 +82,11 @@ export class GoogleAddressProvider extends AddressProvider {
82
82
  search(): Promise<void>;
83
83
  makeRequest(): Promise<void>;
84
84
  getDisplayValue(address: any): any;
85
+ /**
86
+ * Tries to remove the library if api key for loaded script is different.
87
+ * @param {ProviderOptions} options - The options for the provider.
88
+ */
89
+ tryRemoveLibrary(options?: ProviderOptions): void;
85
90
  }
86
91
  export type AutocompleteOptions = {
87
92
  /**
@@ -8,6 +8,9 @@ exports.GoogleAddressProvider = void 0;
8
8
  const Formio_1 = require("../../Formio");
9
9
  const lodash_1 = __importDefault(require("lodash"));
10
10
  const AddressProvider_1 = require("./AddressProvider");
11
+ const GOOGLE_MAPS_BASE_URL = 'https://maps.googleapis.com';
12
+ const GOOGLE_MAPS_JS_URL = `${GOOGLE_MAPS_BASE_URL}/maps/api/js`;
13
+ const GOOGLE_MAPS_JS_WITH_PARAMS_URL = `${GOOGLE_MAPS_JS_URL}?v=quarterly&libraries=places&loading=async&callback=googleMapsCallback`;
11
14
  /**
12
15
  * @typedef {object} AutocompleteOptions
13
16
  * @property {string[]} fields - The fields to include in the autocomplete response.
@@ -55,10 +58,11 @@ class GoogleAddressProvider extends AddressProvider_1.AddressProvider {
55
58
  var _a;
56
59
  super(options);
57
60
  this.setAutocompleteOptions();
58
- let src = 'https://maps.googleapis.com/maps/api/js?v=quarterly&libraries=places&loading=async&callback=googleMapsCallback';
61
+ let src = GOOGLE_MAPS_JS_WITH_PARAMS_URL;
59
62
  if ((_a = options.params) === null || _a === void 0 ? void 0 : _a.key) {
60
63
  src += `&key=${options.params.key}`;
61
64
  }
65
+ this.tryRemoveLibrary(options);
62
66
  Formio_1.Formio.requireLibrary(this.getLibraryName(), 'google.maps.places', src);
63
67
  }
64
68
  /**
@@ -185,5 +189,23 @@ class GoogleAddressProvider extends AddressProvider_1.AddressProvider {
185
189
  : this.alternativeDisplayValueProperty;
186
190
  return lodash_1.default.get(address, displayedProperty, '');
187
191
  }
192
+ /**
193
+ * Tries to remove the library if api key for loaded script is different.
194
+ * @param {ProviderOptions} options - The options for the provider.
195
+ */
196
+ tryRemoveLibrary(options = {}) {
197
+ var _a, _b, _c;
198
+ if (!Formio_1.Formio.libraries[this.getLibraryName()]) {
199
+ return;
200
+ }
201
+ const existingScript = document.querySelector(`script[src^="${GOOGLE_MAPS_JS_URL}"]`);
202
+ if (existingScript && ((_a = options.params) === null || _a === void 0 ? void 0 : _a.key) && !existingScript.attributes.src.value.endsWith(options.params.key)) {
203
+ const googleMapsScripts = (_b = document.querySelectorAll(`script[src^="${GOOGLE_MAPS_BASE_URL}"]`)) !== null && _b !== void 0 ? _b : [];
204
+ googleMapsScripts.forEach(script => script.parentNode.removeChild(script));
205
+ delete Formio_1.Formio.libraries[this.getLibraryName()];
206
+ (_c = global === null || global === void 0 ? void 0 : global.google) === null || _c === void 0 ? true : delete _c.maps;
207
+ delete global[`${this.getLibraryName()}Callback`];
208
+ }
209
+ }
188
210
  }
189
211
  exports.GoogleAddressProvider = GoogleAddressProvider;
@@ -1 +1 @@
1
- export {};
1
+ export { Formio } from "./InlineEmbed";
@@ -1,2 +1,3 @@
1
1
  import { embed } from './InlineEmbed';
2
2
  embed();
3
+ export { Formio } from './InlineEmbed';
@@ -82,6 +82,11 @@ export class GoogleAddressProvider extends AddressProvider {
82
82
  search(): Promise<void>;
83
83
  makeRequest(): Promise<void>;
84
84
  getDisplayValue(address: any): any;
85
+ /**
86
+ * Tries to remove the library if api key for loaded script is different.
87
+ * @param {ProviderOptions} options - The options for the provider.
88
+ */
89
+ tryRemoveLibrary(options?: ProviderOptions): void;
85
90
  }
86
91
  export type AutocompleteOptions = {
87
92
  /**
@@ -2,6 +2,9 @@
2
2
  import { Formio } from '../../Formio';
3
3
  import _ from 'lodash';
4
4
  import { AddressProvider } from './AddressProvider';
5
+ const GOOGLE_MAPS_BASE_URL = 'https://maps.googleapis.com';
6
+ const GOOGLE_MAPS_JS_URL = `${GOOGLE_MAPS_BASE_URL}/maps/api/js`;
7
+ const GOOGLE_MAPS_JS_WITH_PARAMS_URL = `${GOOGLE_MAPS_JS_URL}?v=quarterly&libraries=places&loading=async&callback=googleMapsCallback`;
5
8
  /**
6
9
  * @typedef {object} AutocompleteOptions
7
10
  * @property {string[]} fields - The fields to include in the autocomplete response.
@@ -48,10 +51,11 @@ export class GoogleAddressProvider extends AddressProvider {
48
51
  constructor(options = {}) {
49
52
  super(options);
50
53
  this.setAutocompleteOptions();
51
- let src = 'https://maps.googleapis.com/maps/api/js?v=quarterly&libraries=places&loading=async&callback=googleMapsCallback';
54
+ let src = GOOGLE_MAPS_JS_WITH_PARAMS_URL;
52
55
  if (options.params?.key) {
53
56
  src += `&key=${options.params.key}`;
54
57
  }
58
+ this.tryRemoveLibrary(options);
55
59
  Formio.requireLibrary(this.getLibraryName(), 'google.maps.places', src);
56
60
  }
57
61
  /**
@@ -178,4 +182,21 @@ export class GoogleAddressProvider extends AddressProvider {
178
182
  : this.alternativeDisplayValueProperty;
179
183
  return _.get(address, displayedProperty, '');
180
184
  }
185
+ /**
186
+ * Tries to remove the library if api key for loaded script is different.
187
+ * @param {ProviderOptions} options - The options for the provider.
188
+ */
189
+ tryRemoveLibrary(options = {}) {
190
+ if (!Formio.libraries[this.getLibraryName()]) {
191
+ return;
192
+ }
193
+ const existingScript = document.querySelector(`script[src^="${GOOGLE_MAPS_JS_URL}"]`);
194
+ if (existingScript && options.params?.key && !existingScript.attributes.src.value.endsWith(options.params.key)) {
195
+ const googleMapsScripts = document.querySelectorAll(`script[src^="${GOOGLE_MAPS_BASE_URL}"]`) ?? [];
196
+ googleMapsScripts.forEach(script => script.parentNode.removeChild(script));
197
+ delete Formio.libraries[this.getLibraryName()];
198
+ delete global?.google?.maps;
199
+ delete global[`${this.getLibraryName()}Callback`];
200
+ }
201
+ }
181
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-rc.4",
3
+ "version": "5.1.0-rc.6",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "@formio/bootstrap": "3.1.0-rc.1",
83
83
  "@formio/choices.js": "^10.2.1",
84
- "@formio/core": "2.4.0-rc.3",
84
+ "@formio/core": "2.4.0-rc.5",
85
85
  "@formio/text-mask-addons": "^3.8.0-formio.4",
86
86
  "@formio/vanilla-text-mask": "^5.1.1-formio.1",
87
87
  "abortcontroller-polyfill": "^1.7.5",