@m4l/gclick 0.34.0 → 0.35.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"TileLayerGoogle.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../../packages/gclick/src/components/maps/components/GpsMap/subcomponents/TileLayers/subcomponents/TileLayerGoogle/TileLayerGoogle.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAwClD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QA+MrE"}
1
+ {"version":3,"file":"TileLayerGoogle.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../../packages/gclick/src/components/maps/components/GpsMap/subcomponents/TileLayers/subcomponents/TileLayerGoogle/TileLayerGoogle.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAwClD;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,QAgPrE"}
@@ -1,74 +1,81 @@
1
- import i, { useEffect as T } from "react";
2
- import { useMap as F } from "react-leaflet";
3
- import { ensureGoogleMutantRegistered as _ } from "../../../../external/googleMutant/index.js";
4
- import b from "leaflet";
5
- import { useMapStore as U } from "../../../../hooks/useMapStore/index.js";
6
- import { deepShallow as x } from "@m4l/components";
7
- import { DARK_STYLES as I } from "./darkStyles.js";
8
- import { loadGoogleMapsLibrary as K } from "./googleMapsLoader.js";
9
- import { createReservedTileLayer as h } from "../../../../external/tileReserve/ReservedTileLayer.js";
10
- import { DEFAULT_TILE_RESERVE_FACTOR as V } from "../../../../external/tileReserve/constants.js";
11
- const Z = [], A = (S) => S === "dark" ? I : Z;
12
- function J(S) {
13
- const l = F(), { mode: g, tileReserveFactor: L = V } = S, G = i.useRef(null), r = i.useRef(null), M = i.useRef(L);
14
- M.current = L;
15
- const R = i.useRef(null), p = i.useRef(A(g));
16
- p.current = A(g);
17
- const { sourceId: c, layer: t, trafficLayer: o, transitLayer: a, bicyclingLayer: n, googleApiKey: v, googleMapVersion: E } = U(
1
+ import t, { useEffect as S } from "react";
2
+ import { useMap as K } from "react-leaflet";
3
+ import { ensureGoogleMutantRegistered as V } from "../../../../external/googleMutant/index.js";
4
+ import _ from "leaflet";
5
+ import { useMapStore as Z } from "../../../../hooks/useMapStore/index.js";
6
+ import { deepShallow as k } from "@m4l/components";
7
+ import { DARK_STYLES as C } from "./darkStyles.js";
8
+ import { subscribeGoogleMapsFailure as D, loadGoogleMapsLibrary as j } from "./googleMapsLoader.js";
9
+ import { createReservedTileLayer as Y } from "../../../../external/tileReserve/ReservedTileLayer.js";
10
+ import { DEFAULT_TILE_RESERVE_FACTOR as J } from "../../../../external/tileReserve/constants.js";
11
+ const P = [], h = (M) => M === "dark" ? C : P;
12
+ function te(M) {
13
+ const s = K(), { mode: g, tileReserveFactor: p = J } = M, [I, U] = t.useState(!1), [w, v] = t.useState(!1), A = t.useRef(null), r = t.useRef(null), b = t.useRef(p);
14
+ b.current = p;
15
+ const G = t.useRef(null), L = t.useRef(h(g));
16
+ L.current = h(g);
17
+ const { sourceId: c, layer: o, trafficLayer: n, transitLayer: l, bicyclingLayer: i, googleApiKey: R, googleMapVersion: E } = Z(
18
18
  (e) => {
19
- const y = e.mapSources.find((m) => m.id === e.currentMapSourceLayer.mapSourceId) || e.mapSources[0], s = y.layers.find((m) => m.id === e.currentMapSourceLayer.mapSourceLayerId) || y.layers[0];
19
+ const a = e.mapSources.find((y) => y.id === e.currentMapSourceLayer.mapSourceId) || e.mapSources[0], u = a.layers.find((y) => y.id === e.currentMapSourceLayer.mapSourceLayerId) || a.layers[0];
20
20
  return {
21
- sourceId: y.id,
22
- layer: s,
23
- trafficLayer: s?.roadSelectedOptions?.trafficLayer || !1,
24
- transitLayer: s?.roadSelectedOptions?.transitLayer || !1,
25
- bicyclingLayer: s?.roadSelectedOptions?.bicyclingLayer || !1,
21
+ sourceId: a.id,
22
+ layer: u,
23
+ trafficLayer: u?.roadSelectedOptions?.trafficLayer || !1,
24
+ transitLayer: u?.roadSelectedOptions?.transitLayer || !1,
25
+ bicyclingLayer: u?.roadSelectedOptions?.bicyclingLayer || !1,
26
26
  googleApiKey: e.googleMapsApiKey,
27
27
  googleMapVersion: e.googleMapVersion
28
28
  };
29
29
  },
30
- x
31
- ), u = o || a || n || g === "dark", d = i.useRef({ trafficLayer: o, transitLayer: a, bicyclingLayer: n }), f = i.useRef({ trafficLayer: o, transitLayer: a, bicyclingLayer: n });
32
- return f.current = { trafficLayer: o, transitLayer: a, bicyclingLayer: n }, T(() => {
30
+ k
31
+ ), d = (n || l || i || g === "dark") && !!R && !I, F = !d || g === "light" && !w, m = t.useRef({ trafficLayer: n, transitLayer: l, bicyclingLayer: i }), f = t.useRef({ trafficLayer: n, transitLayer: l, bicyclingLayer: i });
32
+ return f.current = { trafficLayer: n, transitLayer: l, bicyclingLayer: i }, S(() => {
33
33
  let e;
34
34
  if (c === "google")
35
- return u || (e = h(
36
- t.urlTemplate,
37
- t.options,
38
- M.current
39
- ), t.getTileUrl && (e.getTileUrl = t.getTileUrl), l.addLayer(e), G.current = e, t.options && t.options.maxZoom && l.setMaxZoom(t.options.maxZoom)), () => {
40
- e && (l.removeLayer(e), G.current = null);
35
+ return F && (e = Y(
36
+ o.urlTemplate,
37
+ o.options,
38
+ b.current
39
+ ), o.getTileUrl && (e.getTileUrl = o.getTileUrl), s.addLayer(e), A.current = e, o.options && o.options.maxZoom && s.setMaxZoom(o.options.maxZoom)), () => {
40
+ e && (s.removeLayer(e), A.current = null);
41
41
  };
42
- }, [c, t.urlTemplate, t.options, t.getTileUrl, l, u]), T(() => {
43
- if (c !== "google" || !u || !v)
42
+ }, [c, o.urlTemplate, o.options, o.getTileUrl, s, F]), S(() => {
43
+ if (c !== "google" || !d || !R)
44
44
  return;
45
- let e = null, y = !1;
46
- return _().then(() => K({
47
- apiKey: v,
45
+ let e = null, a = !1;
46
+ const u = () => {
47
+ e && (s.removeLayer(e), e = null, r.current = null), G.current = null;
48
+ }, y = (T) => {
49
+ a || (a = !0, u(), v(!1), U(!0), console.error("[GpsMap] Google Maps JavaScript API unavailable; using base tiles.", T));
50
+ }, x = D(y);
51
+ return V().then(() => j({
52
+ apiKey: R,
48
53
  version: E
49
54
  })).then(() => {
50
- if (y)
55
+ if (a)
51
56
  return;
52
- const s = b.gridLayer.googleMutant, m = b.GridLayer.GoogleMutant;
53
- typeof s != "function" || typeof m != "function" || (e = s({
57
+ const T = _.gridLayer.googleMutant, B = _.GridLayer.GoogleMutant;
58
+ if (typeof T != "function" || typeof B != "function")
59
+ throw new Error("GoogleMutant runtime registration is incomplete.");
60
+ e = T({
54
61
  maxZoom: 22,
55
- type: t.type,
56
- styles: p.current
62
+ type: o.type,
63
+ styles: L.current
57
64
  // ...layer.options,
58
- }), e.setTileReserveFactor(M.current), e.on("spawned", (O) => {
59
- R.current = O.mapObject, O.mapObject.setOptions({ styles: p.current });
60
- }), r.current = e, f.current.trafficLayer && e.addGoogleLayer("TrafficLayer"), f.current.transitLayer && e.addGoogleLayer("TransitLayer"), f.current.bicyclingLayer && e.addGoogleLayer("BicyclingLayer"), d.current = { ...f.current }, l.addLayer(e));
61
- }), () => {
62
- y = !0, e && (l.removeLayer(e), r.current = null), R.current = null;
65
+ }), e.setTileReserveFactor(b.current), e.on("spawned", (O) => {
66
+ a || (G.current = O.mapObject, O.mapObject.setOptions({ styles: L.current }), v(!0));
67
+ }), r.current = e, f.current.trafficLayer && e.addGoogleLayer("TrafficLayer"), f.current.transitLayer && e.addGoogleLayer("TransitLayer"), f.current.bicyclingLayer && e.addGoogleLayer("BicyclingLayer"), m.current = { ...f.current }, s.addLayer(e);
68
+ }).catch(y), () => {
69
+ a = !0, x(), u(), v(!1);
63
70
  };
64
- }, [l, t.type, c, v, E, u]), T(() => {
65
- G.current?.setTileReserveFactor(L), r.current?.setTileReserveFactor(L);
66
- }, [L]), T(() => {
67
- c !== "google" || !u || !R.current || g === "light" || (R.current.setOptions({ styles: p.current }), r.current && (r.current.options.styles = p.current));
68
- }, [c, u, g]), i.useEffect(() => {
69
- c === "google" && r.current && (o !== d.current.trafficLayer && (o ? r.current.addGoogleLayer("TrafficLayer") : o === !1 && r.current.removeGoogleLayer("TrafficLayer")), a !== d.current.transitLayer && (a ? r.current.addGoogleLayer("TransitLayer") : a === !1 && r.current.removeGoogleLayer("TransitLayer")), n !== d.current.bicyclingLayer && (n ? r.current.addGoogleLayer("BicyclingLayer") : n === !1 && r.current.removeGoogleLayer("BicyclingLayer")), d.current = { ...f.current });
70
- }, [o, a, n]), null;
71
+ }, [s, o.type, c, R, E, d]), S(() => {
72
+ A.current?.setTileReserveFactor(p), r.current?.setTileReserveFactor(p);
73
+ }, [p]), S(() => {
74
+ c !== "google" || !d || !G.current || (G.current.setOptions({ styles: L.current }), r.current && (r.current.options.styles = L.current));
75
+ }, [c, d, g]), t.useEffect(() => {
76
+ c === "google" && r.current && (n !== m.current.trafficLayer && (n ? r.current.addGoogleLayer("TrafficLayer") : n === !1 && r.current.removeGoogleLayer("TrafficLayer")), l !== m.current.transitLayer && (l ? r.current.addGoogleLayer("TransitLayer") : l === !1 && r.current.removeGoogleLayer("TransitLayer")), i !== m.current.bicyclingLayer && (i ? r.current.addGoogleLayer("BicyclingLayer") : i === !1 && r.current.removeGoogleLayer("BicyclingLayer")), m.current = { ...f.current });
77
+ }, [n, l, i]), null;
71
78
  }
72
79
  export {
73
- J as TileLayerGoogle
80
+ te as TileLayerGoogle
74
81
  };
@@ -5,6 +5,9 @@ type GoogleMapsLoaderOptions = {
5
5
  type GoogleMapsLoaderState = {
6
6
  pendingPromise: Promise<void> | null;
7
7
  pendingOptions: GoogleMapsLoaderOptions | null;
8
+ authenticationError?: Error;
9
+ failureListeners?: Set<(error: Error) => void>;
10
+ authenticationHandlerInstalled?: boolean;
8
11
  };
9
12
  declare const GCLICK_GOOGLE_MAPS_LOADER_STATE_PROPERTY: "__m4lGoogleMapsLoaderState__";
10
13
  declare global {
@@ -12,6 +15,8 @@ declare global {
12
15
  [GCLICK_GOOGLE_MAPS_LOADER_STATE_PROPERTY]?: GoogleMapsLoaderState;
13
16
  }
14
17
  }
18
+ /** Subscribe maps in every bundle to Google's documented page-wide authentication failure. */
19
+ export declare function subscribeGoogleMapsFailure(listener: (error: Error) => void): () => void;
15
20
  /**
16
21
  * Return whether the Google Maps JavaScript runtime is already available on the page.
17
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"googleMapsLoader.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../../packages/gclick/src/components/maps/components/GpsMap/subcomponents/TileLayers/subcomponents/TileLayerGoogle/googleMapsLoader.ts"],"names":[],"mappings":"AAEA,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,cAAc,EAAE,uBAAuB,GAAG,IAAI,CAAC;CAChD,CAAC;AAEF,QAAA,MAAM,wCAAwC,EAAG,8BAAuC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,CAAC,wCAAwC,CAAC,CAAC,EACzC,qBAAqB,CAAC;KACzB;CACF;AAsCD;;GAEG;AACH,wBAAgB,0BAA0B,YAOzC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,uBAAuB,iBA+BrE"}
1
+ {"version":3,"file":"googleMapsLoader.d.ts","sourceRoot":"","sources":["../../../../../../../../../../../../packages/gclick/src/components/maps/components/GpsMap/subcomponents/TileLayers/subcomponents/TileLayerGoogle/googleMapsLoader.ts"],"names":[],"mappings":"AAEA,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACrC,cAAc,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAC/C,mBAAmB,CAAC,EAAE,KAAK,CAAC;IAC5B,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC;IAC/C,8BAA8B,CAAC,EAAE,OAAO,CAAC;CAC1C,CAAC;AAEF,QAAA,MAAM,wCAAwC,EAAG,8BAAuC,CAAC;AAEzF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,CAAC,wCAAwC,CAAC,CAAC,EACzC,qBAAqB,CAAC;KACzB;CACF;AAoED,8FAA8F;AAC9F,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,cAO1E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,YAQzC;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,uBAAuB,iBAsCrE"}
@@ -1,38 +1,71 @@
1
- import { Loader as s } from "@googlemaps/js-api-loader";
2
- const o = "__m4lGoogleMapsLoaderState__";
3
- function r() {
1
+ import { Loader as d } from "@googlemaps/js-api-loader";
2
+ const s = "__m4lGoogleMapsLoaderState__";
3
+ function l() {
4
4
  return typeof window > "u" ? null : window;
5
5
  }
6
- function a() {
7
- const e = r();
8
- return e ? (e[o] ??= {
6
+ function u(r, e) {
7
+ try {
8
+ r(e);
9
+ } catch (n) {
10
+ console.error("[GpsMap] Google Maps failure listener failed.", n);
11
+ }
12
+ }
13
+ function i() {
14
+ const r = l();
15
+ if (!r)
16
+ return null;
17
+ r[s] ??= {
9
18
  pendingPromise: null,
10
19
  pendingOptions: null
11
- }, e[o]) : null;
20
+ };
21
+ const e = r[s];
22
+ if (e.failureListeners ??= /* @__PURE__ */ new Set(), !e.authenticationHandlerInstalled) {
23
+ const n = r.gm_authFailure;
24
+ r.gm_authFailure = () => {
25
+ if (!e.authenticationError) {
26
+ const o = new Error(
27
+ "Google Maps authentication failed. Reload the page before retrying the JavaScript API."
28
+ );
29
+ e.authenticationError = o, e.failureListeners?.forEach((t) => u(t, o));
30
+ }
31
+ n?.call(r);
32
+ }, e.authenticationHandlerInstalled = !0;
33
+ }
34
+ return e;
12
35
  }
13
- function p() {
14
- const e = r();
15
- return e ? !!e.google?.maps?.Map : !1;
36
+ function p(r) {
37
+ const e = i();
38
+ return e?.failureListeners?.add(r), e?.authenticationError && u(r, e.authenticationError), () => {
39
+ e?.failureListeners?.delete(r);
40
+ };
16
41
  }
17
- function l(e) {
18
- if (p())
19
- return Promise.resolve();
20
- const n = a();
21
- if (!n)
42
+ function c() {
43
+ const r = l();
44
+ return r ? !i()?.authenticationError && typeof r.google?.maps?.Map == "function" : !1;
45
+ }
46
+ function h(r) {
47
+ const e = i();
48
+ if (!e)
22
49
  return Promise.reject(new Error("Google Maps can only load in a browser window."));
23
- if (n.pendingPromise)
24
- return n.pendingPromise;
25
- n.pendingOptions ??= e;
26
- const i = new s({
27
- apiKey: n.pendingOptions.apiKey,
28
- version: n.pendingOptions.version
29
- });
30
- return n.pendingPromise = i.importLibrary("maps").then(() => {
50
+ if (e.authenticationError)
51
+ return Promise.reject(e.authenticationError);
52
+ if (c())
53
+ return Promise.resolve();
54
+ if (e.pendingPromise)
55
+ return e.pendingPromise;
56
+ const n = e.pendingOptions ??= r;
57
+ let o;
58
+ return e.pendingPromise = new Promise((t, a) => {
59
+ o = p(a), new d({
60
+ apiKey: n.apiKey,
61
+ version: n.version
62
+ }).importLibrary("maps").then(() => t(), a);
31
63
  }).catch((t) => {
32
- throw n.pendingPromise = null, n.pendingOptions = null, t;
33
- }), n.pendingPromise;
64
+ throw e.pendingPromise = null, e.pendingOptions = null, t;
65
+ }).finally(() => o?.()), e.pendingPromise;
34
66
  }
35
67
  export {
36
- p as hasLoadedGoogleMapsRuntime,
37
- l as loadGoogleMapsLibrary
68
+ c as hasLoadedGoogleMapsRuntime,
69
+ h as loadGoogleMapsLibrary,
70
+ p as subscribeGoogleMapsFailure
38
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/gclick",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -59,8 +59,8 @@
59
59
  "@mui/material": "5.16.7",
60
60
  "immer": "9.0.21",
61
61
  "react-hook-form": "7.71.1",
62
- "leaflet.markercluster": "1.5.3",
63
62
  "@googlemaps/js-api-loader": "1.16.10",
63
+ "leaflet.markercluster": "1.5.3",
64
64
  "yup": "0.32.11"
65
65
  }
66
66
  }