xertica-ui 1.4.0 → 1.4.1
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.
- package/components/ui/google-maps-loader.tsx +26 -12
- package/dist/index.es.js +14 -6
- package/dist/index.umd.js +14 -6
- package/package.json +1 -1
|
@@ -119,13 +119,14 @@ function loadGoogleMapsScript(apiKey?: string): Promise<void> {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
// Verificar se o script já existe
|
|
122
|
+
// Verificar se o script já existe
|
|
123
123
|
const existing = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`) as HTMLScriptElement;
|
|
124
124
|
if (existing) {
|
|
125
|
-
// Se existe mas com chave diferente,
|
|
125
|
+
// Se existe mas com chave diferente, logar aviso. Não podemos recarregar com SPA se componentes já foram definidos.
|
|
126
126
|
if (!existing.src.includes(`key=${apiKey}`)) {
|
|
127
|
-
console.warn('[GoogleMapsLoader] API key changed, page
|
|
128
|
-
|
|
127
|
+
console.warn('[GoogleMapsLoader] API key changed, but Google Maps cannot be reloaded without a full page refresh because custom elements are already defined.');
|
|
128
|
+
// Don't reject, just resolve to keep the app working with the old key until refresh
|
|
129
|
+
resolve();
|
|
129
130
|
return;
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -134,7 +135,6 @@ function loadGoogleMapsScript(apiKey?: string): Promise<void> {
|
|
|
134
135
|
resolve();
|
|
135
136
|
} else {
|
|
136
137
|
existing.addEventListener('load', () => {
|
|
137
|
-
// Aguardar um pouco para garantir que todas as bibliotecas foram carregadas
|
|
138
138
|
setTimeout(() => {
|
|
139
139
|
if (isMarkerLibraryLoaded()) {
|
|
140
140
|
resolve();
|
|
@@ -148,6 +148,13 @@ function loadGoogleMapsScript(apiKey?: string): Promise<void> {
|
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// Prevenir reinjeção se customElements já tem gmp-map (garantia final)
|
|
152
|
+
if (typeof customElements !== 'undefined' && customElements.get('gmp-map')) {
|
|
153
|
+
console.warn('[GoogleMapsLoader] gmp-map is already defined in customElements. Skipping script injection.');
|
|
154
|
+
resolve();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
151
158
|
// Criar novo script
|
|
152
159
|
const script = document.createElement('script');
|
|
153
160
|
const params = new URLSearchParams({
|
|
@@ -399,16 +406,23 @@ export function reloadGoogleMaps(newApiKey: string): Promise<void> {
|
|
|
399
406
|
}
|
|
400
407
|
|
|
401
408
|
// Verificar se a key atual é a mesma
|
|
402
|
-
const existingScript = document.querySelector(`script[src
|
|
409
|
+
const existingScript = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`) as HTMLScriptElement;
|
|
403
410
|
if (existingScript && existingScript.src.includes(`key=${newApiKey}`)) {
|
|
404
|
-
// Mesma key, apenas resolver
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
411
|
+
// Mesma key, apenas resolver (ou esperar carregar)
|
|
412
|
+
resolve();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Se a chave for diferente, NÃO PODEMOS remover o script e adicionar outro
|
|
417
|
+
// se o Google Maps já definiu custom elements. Isso causa o erro:
|
|
418
|
+
// "Element with name 'gmp-...' already defined"
|
|
419
|
+
if (typeof customElements !== 'undefined' && customElements.get('gmp-map')) {
|
|
420
|
+
console.warn('[GoogleMapsLoader] Cannot reload map API dynamically because custom elements (gmp-map) are already registered. A full page reload is required to apply the new API key.');
|
|
421
|
+
resolve(); // Resolver para não quebrar a UI
|
|
422
|
+
return;
|
|
409
423
|
}
|
|
410
424
|
|
|
411
|
-
//
|
|
425
|
+
// Se chegou aqui e não tem custom elements, podemos tentar recarregar
|
|
412
426
|
removeExistingScript();
|
|
413
427
|
|
|
414
428
|
// Atualizar singleton
|
package/dist/index.es.js
CHANGED
|
@@ -47987,8 +47987,8 @@ function loadGoogleMapsScript(apiKey) {
|
|
|
47987
47987
|
const existing = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`);
|
|
47988
47988
|
if (existing) {
|
|
47989
47989
|
if (!existing.src.includes(`key=${apiKey}`)) {
|
|
47990
|
-
console.warn("[GoogleMapsLoader] API key changed, page
|
|
47991
|
-
|
|
47990
|
+
console.warn("[GoogleMapsLoader] API key changed, but Google Maps cannot be reloaded without a full page refresh because custom elements are already defined.");
|
|
47991
|
+
resolve();
|
|
47992
47992
|
return;
|
|
47993
47993
|
}
|
|
47994
47994
|
if (isGoogleMapsAlreadyLoaded() && isMarkerLibraryLoaded()) {
|
|
@@ -48007,6 +48007,11 @@ function loadGoogleMapsScript(apiKey) {
|
|
|
48007
48007
|
}
|
|
48008
48008
|
return;
|
|
48009
48009
|
}
|
|
48010
|
+
if (typeof customElements !== "undefined" && customElements.get("gmp-map")) {
|
|
48011
|
+
console.warn("[GoogleMapsLoader] gmp-map is already defined in customElements. Skipping script injection.");
|
|
48012
|
+
resolve();
|
|
48013
|
+
return;
|
|
48014
|
+
}
|
|
48010
48015
|
const script = document.createElement("script");
|
|
48011
48016
|
const params = new URLSearchParams({
|
|
48012
48017
|
key: apiKey,
|
|
@@ -48173,10 +48178,13 @@ function reloadGoogleMaps(newApiKey) {
|
|
|
48173
48178
|
}
|
|
48174
48179
|
const existingScript = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`);
|
|
48175
48180
|
if (existingScript && existingScript.src.includes(`key=${newApiKey}`)) {
|
|
48176
|
-
|
|
48177
|
-
|
|
48178
|
-
|
|
48179
|
-
|
|
48181
|
+
resolve();
|
|
48182
|
+
return;
|
|
48183
|
+
}
|
|
48184
|
+
if (typeof customElements !== "undefined" && customElements.get("gmp-map")) {
|
|
48185
|
+
console.warn("[GoogleMapsLoader] Cannot reload map API dynamically because custom elements (gmp-map) are already registered. A full page reload is required to apply the new API key.");
|
|
48186
|
+
resolve();
|
|
48187
|
+
return;
|
|
48180
48188
|
}
|
|
48181
48189
|
removeExistingScript();
|
|
48182
48190
|
updateSingleton({ isLoaded: false, loadError: void 0 });
|
package/dist/index.umd.js
CHANGED
|
@@ -48006,8 +48006,8 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
48006
48006
|
const existing = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`);
|
|
48007
48007
|
if (existing) {
|
|
48008
48008
|
if (!existing.src.includes(`key=${apiKey}`)) {
|
|
48009
|
-
console.warn("[GoogleMapsLoader] API key changed, page
|
|
48010
|
-
|
|
48009
|
+
console.warn("[GoogleMapsLoader] API key changed, but Google Maps cannot be reloaded without a full page refresh because custom elements are already defined.");
|
|
48010
|
+
resolve();
|
|
48011
48011
|
return;
|
|
48012
48012
|
}
|
|
48013
48013
|
if (isGoogleMapsAlreadyLoaded() && isMarkerLibraryLoaded()) {
|
|
@@ -48026,6 +48026,11 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
48026
48026
|
}
|
|
48027
48027
|
return;
|
|
48028
48028
|
}
|
|
48029
|
+
if (typeof customElements !== "undefined" && customElements.get("gmp-map")) {
|
|
48030
|
+
console.warn("[GoogleMapsLoader] gmp-map is already defined in customElements. Skipping script injection.");
|
|
48031
|
+
resolve();
|
|
48032
|
+
return;
|
|
48033
|
+
}
|
|
48029
48034
|
const script = document.createElement("script");
|
|
48030
48035
|
const params = new URLSearchParams({
|
|
48031
48036
|
key: apiKey,
|
|
@@ -48192,10 +48197,13 @@ For more information, see https://radix-ui.com/primitives/docs/components/${titl
|
|
|
48192
48197
|
}
|
|
48193
48198
|
const existingScript = document.querySelector(`script[src*="maps.googleapis.com/maps/api/js"]`);
|
|
48194
48199
|
if (existingScript && existingScript.src.includes(`key=${newApiKey}`)) {
|
|
48195
|
-
|
|
48196
|
-
|
|
48197
|
-
|
|
48198
|
-
|
|
48200
|
+
resolve();
|
|
48201
|
+
return;
|
|
48202
|
+
}
|
|
48203
|
+
if (typeof customElements !== "undefined" && customElements.get("gmp-map")) {
|
|
48204
|
+
console.warn("[GoogleMapsLoader] Cannot reload map API dynamically because custom elements (gmp-map) are already registered. A full page reload is required to apply the new API key.");
|
|
48205
|
+
resolve();
|
|
48206
|
+
return;
|
|
48199
48207
|
}
|
|
48200
48208
|
removeExistingScript();
|
|
48201
48209
|
updateSingleton({ isLoaded: false, loadError: void 0 });
|