xertica-ui 1.4.0 → 1.4.2

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.
@@ -119,13 +119,14 @@ function loadGoogleMapsScript(apiKey?: string): Promise<void> {
119
119
  }
120
120
  }
121
121
 
122
- // Verificar se o script já existe com KEY DIFERENTE
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, precisamos recarregar a página
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 reload required');
128
- reject(new Error('API key changed. Please reload the page to apply changes.'));
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*=\"maps.googleapis.com/maps/api/js\"]`) as HTMLScriptElement;
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
- if (isGoogleMapsAlreadyLoaded() && isMarkerLibraryLoaded()) {
406
- resolve();
407
- return;
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
- // Remover script antigo
425
+ // Se chegou aqui e não tem custom elements, podemos tentar recarregar
412
426
  removeExistingScript();
413
427
 
414
428
  // Atualizar singleton
@@ -413,39 +413,47 @@ MapContent.displayName = "MapContent";
413
413
 
414
414
  export const Map = React.forwardRef<HTMLDivElement, MapProps>(
415
415
  (props, ref) => {
416
+ const { isLoaded, loadError } = useGoogleMapsLoader();
416
417
  const effectiveApiKey = props.apiKey || (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.VITE_GOOGLE_MAPS_API_KEY) || "";
417
418
 
418
419
  const isValidKey = effectiveApiKey &&
419
420
  effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" &&
420
421
  effectiveApiKey.startsWith("AIza");
421
422
 
422
- if (!isValidKey) {
423
- // ... (keep existing error state rendering)
424
- return (
425
- <div
426
- ref={ref}
427
- className={cn(
428
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
429
- props.className
430
- )}
431
- style={{ height: props.height || "400px" }}
432
- >
433
- <div className="absolute inset-0 flex items-center justify-center bg-muted">
434
- <div className="text-center space-y-3 p-6">
435
- <div className="w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center">
436
- <svg className="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
437
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
438
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
439
- </svg>
440
- </div>
441
- <p className="text-sm text-muted-foreground">Configure Google Maps API Key in Settings</p>
423
+ if (isLoaded || isValidKey || loadError) {
424
+ return <MapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
425
+ }
426
+
427
+ // Check if the script is injected in the DOM (loading via provider)
428
+ const isScriptInjected = typeof document !== 'undefined' && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
429
+
430
+ if (isScriptInjected) {
431
+ // Let MapContent show the loading skeleton
432
+ return <MapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
433
+ }
434
+
435
+ return (
436
+ <div
437
+ ref={ref}
438
+ className={cn(
439
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
440
+ props.className
441
+ )}
442
+ style={{ height: props.height || "400px" }}
443
+ >
444
+ <div className="absolute inset-0 flex items-center justify-center bg-muted">
445
+ <div className="text-center space-y-3 p-6">
446
+ <div className="w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center">
447
+ <svg className="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
448
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
449
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
450
+ </svg>
442
451
  </div>
452
+ <p className="text-sm text-muted-foreground">Configure Google Maps API Key in Settings</p>
443
453
  </div>
444
454
  </div>
445
- );
446
- }
447
-
448
- return <MapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
455
+ </div>
456
+ );
449
457
  }
450
458
  );
451
459
  Map.displayName = "Map";
@@ -234,46 +234,54 @@ RouteMapContent.displayName = "RouteMapContent";
234
234
 
235
235
  export const RouteMap = React.forwardRef<HTMLDivElement, RouteMapProps>(
236
236
  (props, ref) => {
237
+ const { isLoaded, loadError } = useGoogleMapsLoader();
237
238
  const effectiveApiKey = props.apiKey || (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.VITE_GOOGLE_MAPS_API_KEY) || "";
238
239
 
239
240
  const isValidKey = effectiveApiKey &&
240
241
  effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" &&
241
242
  effectiveApiKey.startsWith("AIza");
242
243
 
243
- if (!isValidKey) {
244
- const {
245
- origin, destination, waypoints, travelMode, height, apiKey,
246
- mapContainerClassName, disableDefaultUI, zoomControl,
247
- streetViewControl, mapTypeControl, fullscreenControl,
248
- onRouteCalculated, ...divProps
249
- } = props;
244
+ if (isLoaded || isValidKey || loadError) {
245
+ return <RouteMapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
246
+ }
250
247
 
251
- return (
252
- <div
253
- ref={ref}
254
- className={cn(
255
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
256
- props.className
257
- )}
258
- style={{ height: props.height || "450px" }}
259
- {...divProps}
260
- >
261
- <div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted">
262
- <div className="text-center space-y-3 p-6">
263
- <div className="w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center">
264
- <svg className="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
265
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
266
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
267
- </svg>
268
- </div>
269
- <p className="text-sm text-muted-foreground">Configure Google Maps API Key in Settings</p>
248
+ // Check if the script is injected in the DOM (loading via provider)
249
+ const isScriptInjected = typeof document !== 'undefined' && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
250
+
251
+ if (isScriptInjected) {
252
+ return <RouteMapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
253
+ }
254
+
255
+ const {
256
+ origin, destination, waypoints, travelMode, height, apiKey,
257
+ mapContainerClassName, disableDefaultUI, zoomControl,
258
+ streetViewControl, mapTypeControl, fullscreenControl,
259
+ onRouteCalculated, ...divProps
260
+ } = props;
261
+
262
+ return (
263
+ <div
264
+ ref={ref}
265
+ className={cn(
266
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
267
+ props.className
268
+ )}
269
+ style={{ height: props.height || "450px" }}
270
+ {...divProps}
271
+ >
272
+ <div className="absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted">
273
+ <div className="text-center space-y-3 p-6">
274
+ <div className="w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center">
275
+ <svg className="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
276
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
277
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
278
+ </svg>
270
279
  </div>
280
+ <p className="text-sm text-muted-foreground">Configure Google Maps API Key in Settings</p>
271
281
  </div>
272
282
  </div>
273
- );
274
- }
275
-
276
- return <RouteMapContent ref={ref} {...props} apiKey={effectiveApiKey} />;
283
+ </div>
284
+ );
277
285
  }
278
286
  );
279
287
  RouteMap.displayName = "RouteMap";
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 reload required");
47991
- reject(new Error("API key changed. Please reload the page to apply changes."));
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
- if (isGoogleMapsAlreadyLoaded() && isMarkerLibraryLoaded()) {
48177
- resolve();
48178
- return;
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 });
@@ -54950,29 +54958,34 @@ const MapContent = React__default.forwardRef(
54950
54958
  MapContent.displayName = "MapContent";
54951
54959
  const Map$1 = React__default.forwardRef(
54952
54960
  (props, ref) => {
54961
+ const { isLoaded, loadError } = useGoogleMapsLoader();
54953
54962
  const effectiveApiKey = props.apiKey || typeof import.meta !== "undefined" && __vite_import_meta_env__$1 && void 0 || "";
54954
54963
  const isValidKey = effectiveApiKey && effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" && effectiveApiKey.startsWith("AIza");
54955
- if (!isValidKey) {
54956
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
54957
- "div",
54958
- {
54959
- ref,
54960
- className: cn(
54961
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
54962
- props.className
54963
- ),
54964
- style: { height: props.height || "400px" },
54965
- children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
54966
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
54967
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
54968
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
54969
- ] }) }),
54970
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
54971
- ] }) })
54972
- }
54973
- );
54964
+ if (isLoaded || isValidKey || loadError) {
54965
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54974
54966
  }
54975
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54967
+ const isScriptInjected = typeof document !== "undefined" && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
54968
+ if (isScriptInjected) {
54969
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54970
+ }
54971
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
54972
+ "div",
54973
+ {
54974
+ ref,
54975
+ className: cn(
54976
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
54977
+ props.className
54978
+ ),
54979
+ style: { height: props.height || "400px" },
54980
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
54981
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
54982
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
54983
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
54984
+ ] }) }),
54985
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
54986
+ ] }) })
54987
+ }
54988
+ );
54976
54989
  }
54977
54990
  );
54978
54991
  Map$1.displayName = "Map";
@@ -71070,46 +71083,51 @@ const RouteMapContent = React__default.forwardRef(
71070
71083
  RouteMapContent.displayName = "RouteMapContent";
71071
71084
  const RouteMap = React__default.forwardRef(
71072
71085
  (props, ref) => {
71086
+ const { isLoaded, loadError } = useGoogleMapsLoader();
71073
71087
  const effectiveApiKey = props.apiKey || typeof import.meta !== "undefined" && __vite_import_meta_env__ && void 0 || "";
71074
71088
  const isValidKey = effectiveApiKey && effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" && effectiveApiKey.startsWith("AIza");
71075
- if (!isValidKey) {
71076
- const {
71077
- origin,
71078
- destination,
71079
- waypoints,
71080
- travelMode,
71081
- height,
71082
- apiKey,
71083
- mapContainerClassName,
71084
- disableDefaultUI,
71085
- zoomControl,
71086
- streetViewControl,
71087
- mapTypeControl,
71088
- fullscreenControl,
71089
- onRouteCalculated,
71090
- ...divProps
71091
- } = props;
71092
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
71093
- "div",
71094
- {
71095
- ref,
71096
- className: cn(
71097
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
71098
- props.className
71099
- ),
71100
- style: { height: props.height || "450px" },
71101
- ...divProps,
71102
- children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
71103
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
71104
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
71105
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
71106
- ] }) }),
71107
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
71108
- ] }) })
71109
- }
71110
- );
71089
+ if (isLoaded || isValidKey || loadError) {
71090
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71091
+ }
71092
+ const isScriptInjected = typeof document !== "undefined" && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
71093
+ if (isScriptInjected) {
71094
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71111
71095
  }
71112
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71096
+ const {
71097
+ origin,
71098
+ destination,
71099
+ waypoints,
71100
+ travelMode,
71101
+ height,
71102
+ apiKey,
71103
+ mapContainerClassName,
71104
+ disableDefaultUI,
71105
+ zoomControl,
71106
+ streetViewControl,
71107
+ mapTypeControl,
71108
+ fullscreenControl,
71109
+ onRouteCalculated,
71110
+ ...divProps
71111
+ } = props;
71112
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
71113
+ "div",
71114
+ {
71115
+ ref,
71116
+ className: cn(
71117
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
71118
+ props.className
71119
+ ),
71120
+ style: { height: props.height || "450px" },
71121
+ ...divProps,
71122
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
71123
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
71124
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
71125
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
71126
+ ] }) }),
71127
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
71128
+ ] }) })
71129
+ }
71130
+ );
71113
71131
  }
71114
71132
  );
71115
71133
  RouteMap.displayName = "RouteMap";
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 reload required");
48010
- reject(new Error("API key changed. Please reload the page to apply changes."));
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
- if (isGoogleMapsAlreadyLoaded() && isMarkerLibraryLoaded()) {
48196
- resolve();
48197
- return;
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 });
@@ -54969,29 +54977,34 @@ Defaulting to \`null\`.`;
54969
54977
  MapContent.displayName = "MapContent";
54970
54978
  const Map$1 = React.forwardRef(
54971
54979
  (props, ref) => {
54980
+ const { isLoaded, loadError } = useGoogleMapsLoader();
54972
54981
  const effectiveApiKey = props.apiKey || typeof { url: typeof document === "undefined" && typeof location === "undefined" ? require("url").pathToFileURL(__filename).href : typeof document === "undefined" ? location.href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.umd.js", document.baseURI).href } !== "undefined" && __vite_import_meta_env__$1 && void 0 || "";
54973
54982
  const isValidKey = effectiveApiKey && effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" && effectiveApiKey.startsWith("AIza");
54974
- if (!isValidKey) {
54975
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
54976
- "div",
54977
- {
54978
- ref,
54979
- className: cn(
54980
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
54981
- props.className
54982
- ),
54983
- style: { height: props.height || "400px" },
54984
- children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
54985
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
54986
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
54987
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
54988
- ] }) }),
54989
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
54990
- ] }) })
54991
- }
54992
- );
54983
+ if (isLoaded || isValidKey || loadError) {
54984
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54993
54985
  }
54994
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54986
+ const isScriptInjected = typeof document !== "undefined" && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
54987
+ if (isScriptInjected) {
54988
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MapContent, { ref, ...props, apiKey: effectiveApiKey });
54989
+ }
54990
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
54991
+ "div",
54992
+ {
54993
+ ref,
54994
+ className: cn(
54995
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
54996
+ props.className
54997
+ ),
54998
+ style: { height: props.height || "400px" },
54999
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
55000
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
55001
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
55002
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
55003
+ ] }) }),
55004
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
55005
+ ] }) })
55006
+ }
55007
+ );
54995
55008
  }
54996
55009
  );
54997
55010
  Map$1.displayName = "Map";
@@ -71089,46 +71102,51 @@ For more information, see https://radix-ui.com/primitives/docs/components/alert-
71089
71102
  RouteMapContent.displayName = "RouteMapContent";
71090
71103
  const RouteMap = React.forwardRef(
71091
71104
  (props, ref) => {
71105
+ const { isLoaded, loadError } = useGoogleMapsLoader();
71092
71106
  const effectiveApiKey = props.apiKey || typeof { url: typeof document === "undefined" && typeof location === "undefined" ? require("url").pathToFileURL(__filename).href : typeof document === "undefined" ? location.href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.umd.js", document.baseURI).href } !== "undefined" && __vite_import_meta_env__ && void 0 || "";
71093
71107
  const isValidKey = effectiveApiKey && effectiveApiKey !== "YOUR_GOOGLE_MAPS_API_KEY_HERE" && effectiveApiKey.startsWith("AIza");
71094
- if (!isValidKey) {
71095
- const {
71096
- origin,
71097
- destination,
71098
- waypoints,
71099
- travelMode,
71100
- height,
71101
- apiKey,
71102
- mapContainerClassName,
71103
- disableDefaultUI,
71104
- zoomControl,
71105
- streetViewControl,
71106
- mapTypeControl,
71107
- fullscreenControl,
71108
- onRouteCalculated,
71109
- ...divProps
71110
- } = props;
71111
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
71112
- "div",
71113
- {
71114
- ref,
71115
- className: cn(
71116
- "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
71117
- props.className
71118
- ),
71119
- style: { height: props.height || "450px" },
71120
- ...divProps,
71121
- children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
71122
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
71123
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
71124
- /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
71125
- ] }) }),
71126
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
71127
- ] }) })
71128
- }
71129
- );
71108
+ if (isLoaded || isValidKey || loadError) {
71109
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71110
+ }
71111
+ const isScriptInjected = typeof document !== "undefined" && !!document.querySelector('script[src*="maps.googleapis.com/maps/api/js"]');
71112
+ if (isScriptInjected) {
71113
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71130
71114
  }
71131
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RouteMapContent, { ref, ...props, apiKey: effectiveApiKey });
71115
+ const {
71116
+ origin,
71117
+ destination,
71118
+ waypoints,
71119
+ travelMode,
71120
+ height,
71121
+ apiKey,
71122
+ mapContainerClassName,
71123
+ disableDefaultUI,
71124
+ zoomControl,
71125
+ streetViewControl,
71126
+ mapTypeControl,
71127
+ fullscreenControl,
71128
+ onRouteCalculated,
71129
+ ...divProps
71130
+ } = props;
71131
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
71132
+ "div",
71133
+ {
71134
+ ref,
71135
+ className: cn(
71136
+ "relative rounded-[var(--radius-card)] border border-border overflow-hidden bg-muted",
71137
+ props.className
71138
+ ),
71139
+ style: { height: props.height || "450px" },
71140
+ ...divProps,
71141
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-gradient-to-br from-muted/50 to-muted", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-center space-y-3 p-6", children: [
71142
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 mx-auto bg-primary/10 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { className: "w-8 h-8 text-primary", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: [
71143
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" }),
71144
+ /* @__PURE__ */ jsxRuntimeExports.jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 11a3 3 0 11-6 0 3 3 0 016 0z" })
71145
+ ] }) }),
71146
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Configure Google Maps API Key in Settings" })
71147
+ ] }) })
71148
+ }
71149
+ );
71132
71150
  }
71133
71151
  );
71134
71152
  RouteMap.displayName = "RouteMap";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xertica-ui",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Xertica UI - Design System completo com componentes React e Tailwind CSS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",