vlite3 1.4.27 → 1.4.30

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.
@@ -0,0 +1,50 @@
1
+ export interface GoogleMapCoordinate {
2
+ lat: number;
3
+ lng: number;
4
+ }
5
+ export interface GoogleMapMarker extends GoogleMapCoordinate {
6
+ id?: string | number;
7
+ title?: string;
8
+ label?: string;
9
+ }
10
+ export interface GoogleMapOptions {
11
+ disableDefaultUI?: boolean;
12
+ draggable?: boolean;
13
+ fullscreenControl?: boolean;
14
+ mapId?: string;
15
+ mapTypeControl?: boolean;
16
+ scrollwheel?: boolean;
17
+ streetViewControl?: boolean;
18
+ zoomControl?: boolean;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface GoogleMapProps {
22
+ apiKey?: string;
23
+ center?: GoogleMapCoordinate | null;
24
+ markers?: GoogleMapMarker[];
25
+ zoom?: number;
26
+ height?: string | number;
27
+ width?: string | number;
28
+ options?: GoogleMapOptions;
29
+ ariaLabel?: string;
30
+ loadingText?: string;
31
+ errorText?: string;
32
+ }
33
+ export type GoogleMapErrorCode = 'invalid-api-key' | 'invalid-center' | 'invalid-markers' | 'loader-conflict' | 'load-failed' | 'ssr-unavailable';
34
+ export interface GoogleMapError {
35
+ code: GoogleMapErrorCode;
36
+ message: string;
37
+ cause?: unknown;
38
+ }
39
+ export interface GoogleMapReadyEvent {
40
+ map: unknown;
41
+ }
42
+ export interface GoogleMapClickEvent {
43
+ coordinate: GoogleMapCoordinate | null;
44
+ nativeEvent: unknown;
45
+ }
46
+ export interface GoogleMapMarkerClickEvent {
47
+ marker: GoogleMapMarker;
48
+ index: number;
49
+ nativeEvent: unknown;
50
+ }
@@ -89,6 +89,9 @@ export interface VLiteConfig {
89
89
  datetime?: {
90
90
  format?: string;
91
91
  };
92
+ googleMap?: {
93
+ apiKey?: string;
94
+ };
92
95
  /**
93
96
  * Global Empty component configuration.
94
97
  * Sets the default variant used when no `variant` prop is passed locally.
package/types/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './styles.ts';
9
9
  export * from './config.type';
10
10
  export * from './list.type';
11
11
  export * from './progressbar.ts';
12
+ export * from './GoogleMap.type';
@@ -0,0 +1,41 @@
1
+ import { GoogleMapError } from '../types/GoogleMap.type';
2
+ interface GoogleMapsApi {
3
+ maps: {
4
+ Map: new (element: HTMLElement, options: Record<string, unknown>) => GoogleMapInstance;
5
+ Marker: new (options: Record<string, unknown>) => GoogleMapMarkerInstance;
6
+ event: {
7
+ clearInstanceListeners(instance: unknown): void;
8
+ trigger(instance: unknown, eventName: string): void;
9
+ };
10
+ };
11
+ }
12
+ export interface GoogleMapListener {
13
+ remove(): void;
14
+ }
15
+ export interface GoogleMapInstance {
16
+ addListener(eventName: string, handler: (event?: any) => void): GoogleMapListener;
17
+ getCenter(): {
18
+ lat(): number;
19
+ lng(): number;
20
+ } | undefined;
21
+ getZoom(): number | undefined;
22
+ setCenter(center: {
23
+ lat: number;
24
+ lng: number;
25
+ }): void;
26
+ setOptions(options: Record<string, unknown>): void;
27
+ setZoom(zoom: number): void;
28
+ }
29
+ export interface GoogleMapMarkerInstance {
30
+ addListener(eventName: string, handler: (event?: any) => void): GoogleMapListener;
31
+ setLabel(label: string | null): void;
32
+ setMap(map: GoogleMapInstance | null): void;
33
+ setPosition(position: {
34
+ lat: number;
35
+ lng: number;
36
+ }): void;
37
+ setTitle(title: string | null): void;
38
+ }
39
+ export declare function onGoogleMapsAuthFailure(handler: (error: GoogleMapError) => void): () => void;
40
+ export declare function loadGoogleMaps(apiKey: string): Promise<GoogleMapsApi>;
41
+ export {};
@@ -0,0 +1,47 @@
1
+ let t = null, d = null;
2
+ const s = /* @__PURE__ */ new Set();
3
+ let p = !1;
4
+ function l(e, n, a) {
5
+ return { code: e, message: n, cause: a };
6
+ }
7
+ function f() {
8
+ if (p || typeof window > "u") return;
9
+ p = !0;
10
+ const e = window.gm_authFailure;
11
+ window.gm_authFailure = () => {
12
+ const n = l(
13
+ "invalid-api-key",
14
+ "Google Maps rejected the API key. Check its validity and Maps JavaScript API restrictions."
15
+ );
16
+ s.forEach((a) => a(n)), typeof e == "function" && e();
17
+ };
18
+ }
19
+ function g(e) {
20
+ return f(), s.add(e), () => s.delete(e);
21
+ }
22
+ function w(e) {
23
+ if (typeof window > "u" || typeof document > "u")
24
+ return Promise.reject(
25
+ l("ssr-unavailable", "Google Maps can only be initialized in a browser.")
26
+ );
27
+ const n = window.google;
28
+ return n?.maps?.Map ? Promise.resolve(n) : t ? d !== e ? Promise.reject(
29
+ l(
30
+ "loader-conflict",
31
+ "Google Maps is already loading with a different API key on this page."
32
+ )
33
+ ) : t : (d = e, f(), t = new Promise((a, u) => {
34
+ const r = `__vliteGoogleMapsReady_${Date.now()}`, o = document.createElement("script"), c = () => delete window[r];
35
+ window[r] = () => {
36
+ c();
37
+ const i = window.google;
38
+ i?.maps?.Map ? a(i) : u(l("load-failed", "Google Maps loaded without the Maps API."));
39
+ }, o.id = "vlite3-google-maps-script", o.async = !0, o.defer = !0, o.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(e)}&callback=${r}&loading=async`, o.onerror = (i) => {
40
+ c(), t = null, d = null, o.remove(), u(l("load-failed", "Google Maps could not be loaded.", i));
41
+ }, document.head.appendChild(o);
42
+ }), t);
43
+ }
44
+ export {
45
+ w as loadGoogleMaps,
46
+ g as onGoogleMapsAuthFailure
47
+ };