@nuxt/scripts 1.0.0-beta.25 → 1.0.0-beta.26

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.
Files changed (32) hide show
  1. package/dist/client/200.html +1 -1
  2. package/dist/client/404.html +1 -1
  3. package/dist/client/_nuxt/builds/latest.json +1 -1
  4. package/dist/client/_nuxt/builds/meta/33e1ac0e-aba1-4856-8beb-775c426be236.json +1 -0
  5. package/dist/client/index.html +1 -1
  6. package/dist/module.json +1 -1
  7. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +2 -5
  8. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +14 -15
  9. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +2 -5
  10. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.d.vue.ts +1 -4
  11. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue +30 -41
  12. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue.d.ts +1 -4
  13. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsCircle.vue +19 -28
  14. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.vue +18 -22
  15. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsInfoWindow.vue +30 -37
  16. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.d.vue.ts +1 -4
  17. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue +31 -36
  18. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue.d.ts +1 -4
  19. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue +17 -22
  20. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +19 -28
  21. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolygon.vue +19 -28
  22. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolyline.vue +19 -28
  23. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsRectangle.vue +19 -28
  24. package/dist/runtime/components/GoogleMaps/injectionKeys.d.ts +11 -0
  25. package/dist/runtime/components/GoogleMaps/injectionKeys.js +3 -0
  26. package/dist/runtime/components/GoogleMaps/useGoogleMapsResource.d.ts +26 -0
  27. package/dist/runtime/components/GoogleMaps/useGoogleMapsResource.js +37 -0
  28. package/dist/stats.d.mts +18 -1
  29. package/dist/stats.d.ts +18 -1
  30. package/dist/stats.mjs +833 -248
  31. package/package.json +5 -5
  32. package/dist/client/_nuxt/builds/meta/2ec0342e-5e00-4781-82aa-c3c0f9154516.json +0 -1
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"2ec0342e-5e00-4781-82aa-c3c0f9154516",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773850004188,false]</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"33e1ac0e-aba1-4856-8beb-775c426be236",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773896533676,false]</script></body></html>
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"2ec0342e-5e00-4781-82aa-c3c0f9154516",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773850004189,false]</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"33e1ac0e-aba1-4856-8beb-775c426be236",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773896533677,false]</script></body></html>
@@ -1 +1 @@
1
- {"id":"2ec0342e-5e00-4781-82aa-c3c0f9154516","timestamp":1773849998807}
1
+ {"id":"33e1ac0e-aba1-4856-8beb-775c426be236","timestamp":1773896528219}
@@ -0,0 +1 @@
1
+ {"id":"33e1ac0e-aba1-4856-8beb-775c426be236","timestamp":1773896528219,"prerendered":[]}
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"2ec0342e-5e00-4781-82aa-c3c0f9154516",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773850004189,false]</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.C5SUNdim.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DjhmCJlE.js"><script type="module" src="/__nuxt-scripts/_nuxt/DjhmCJlE.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{"nuxt-scripts":{version:"",defaultScriptOptions:{trigger:"onNuxtReady"},googleStaticMapsProxy:"",endpoints:{}}},app:{baseURL:"/__nuxt-scripts",buildId:"33e1ac0e-aba1-4856-8beb-775c426be236",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773896533677,false]</script></body></html>
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16"
6
6
  },
7
- "version": "1.0.0-beta.25",
7
+ "version": "1.0.0-beta.26",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -18,11 +18,8 @@ export interface PlaceholderOptions {
18
18
  signature?: string;
19
19
  }
20
20
  import type { ElementScriptTrigger } from '#nuxt-scripts/types';
21
- import type { HTMLAttributes, ImgHTMLAttributes, InjectionKey, Ref, ReservedProps, ShallowRef } from 'vue';
22
- export declare const MAP_INJECTION_KEY: InjectionKey<{
23
- map: ShallowRef<google.maps.Map | undefined>;
24
- mapsApi: Ref<typeof google.maps | undefined>;
25
- }>;
21
+ import type { HTMLAttributes, ImgHTMLAttributes, Ref, ReservedProps, ShallowRef } from 'vue';
22
+ export { MAP_INJECTION_KEY } from './injectionKeys.js';
26
23
  declare const _default: typeof __VLS_export;
27
24
  export default _default;
28
25
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -8,7 +8,8 @@ import { hash } from "ohash";
8
8
  import { withQuery } from "ufo";
9
9
  import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef, toRaw, watch } from "vue";
10
10
  import ScriptAriaLoadingIndicator from "../ScriptAriaLoadingIndicator.vue";
11
- export const MAP_INJECTION_KEY = /* @__PURE__ */ Symbol("map");
11
+ import { MAP_INJECTION_KEY } from "./injectionKeys";
12
+ export { MAP_INJECTION_KEY } from "./injectionKeys";
12
13
  </script>
13
14
 
14
15
  <script setup>
@@ -78,14 +79,11 @@ const mapMarkers = ref(/* @__PURE__ */ new Map());
78
79
  function isLocationQuery(s) {
79
80
  return typeof s === "string" && (s.split(",").length > 2 || s.includes("+"));
80
81
  }
81
- function resetMapMarkerMap(_marker) {
82
- return new Promise(async (resolve) => {
83
- const marker = _marker instanceof Promise ? await _marker : _marker;
84
- if (marker) {
85
- marker.setMap(null);
86
- }
87
- resolve();
88
- });
82
+ async function resetMapMarkerMap(_marker) {
83
+ const marker = _marker instanceof Promise ? await _marker : _marker;
84
+ if (marker) {
85
+ marker.setMap(null);
86
+ }
89
87
  }
90
88
  function normalizeAdvancedMapMarkerOptions(_options) {
91
89
  const opts = typeof _options === "string" ? {
@@ -109,13 +107,12 @@ async function createAdvancedMapMarker(_options) {
109
107
  const key = hash({ position: normalizedOptions.position });
110
108
  if (mapMarkers.value.has(key))
111
109
  return mapMarkers.value.get(key);
112
- const p = new Promise(async (resolve) => {
113
- const lib = await importLibrary("marker");
110
+ const p = importLibrary("marker").then((lib) => {
114
111
  const mapMarkerOptions = {
115
112
  ...toRaw(normalizedOptions),
116
113
  map: toRaw(map.value)
117
114
  };
118
- resolve(new lib.AdvancedMarkerElement(mapMarkerOptions));
115
+ return new lib.AdvancedMarkerElement(mapMarkerOptions);
119
116
  });
120
117
  mapMarkers.value.set(key, p);
121
118
  return p;
@@ -367,12 +364,14 @@ const rootAttrs = computed(() => {
367
364
  ...trigger instanceof Promise ? trigger.ssrAttrs || {} : {}
368
365
  });
369
366
  });
370
- onBeforeUnmount(async () => {
371
- await Promise.all(Array.from(mapMarkers.value.entries(), ([, marker]) => resetMapMarkerMap(marker)));
372
- mapMarkers.value.clear();
367
+ onBeforeUnmount(() => {
373
368
  map.value?.unbindAll();
374
369
  map.value = void 0;
375
370
  mapEl.value?.firstChild?.remove();
371
+ libraries.clear();
372
+ queryToLatLngCache.clear();
373
+ Promise.all(Array.from(mapMarkers.value.entries(), ([, marker]) => resetMapMarkerMap(marker)));
374
+ mapMarkers.value.clear();
376
375
  });
377
376
  </script>
378
377
 
@@ -18,11 +18,8 @@ export interface PlaceholderOptions {
18
18
  signature?: string;
19
19
  }
20
20
  import type { ElementScriptTrigger } from '#nuxt-scripts/types';
21
- import type { HTMLAttributes, ImgHTMLAttributes, InjectionKey, Ref, ReservedProps, ShallowRef } from 'vue';
22
- export declare const MAP_INJECTION_KEY: InjectionKey<{
23
- map: ShallowRef<google.maps.Map | undefined>;
24
- mapsApi: Ref<typeof google.maps | undefined>;
25
- }>;
21
+ import type { HTMLAttributes, ImgHTMLAttributes, Ref, ReservedProps, ShallowRef } from 'vue';
22
+ export { MAP_INJECTION_KEY } from './injectionKeys.js';
26
23
  declare const _default: typeof __VLS_export;
27
24
  export default _default;
28
25
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -1,7 +1,4 @@
1
- import type { InjectionKey, ShallowRef } from 'vue';
2
- export declare const ADVANCED_MARKER_ELEMENT_INJECTION_KEY: InjectionKey<{
3
- advancedMarkerElement: ShallowRef<google.maps.marker.AdvancedMarkerElement | undefined>;
4
- }>;
1
+ export { ADVANCED_MARKER_ELEMENT_INJECTION_KEY } from './injectionKeys.js';
5
2
  declare const _default: typeof __VLS_export;
6
3
  export default _default;
7
4
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -1,9 +1,9 @@
1
1
  <script>
2
- import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted, provide, ref, shallowRef } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
2
+ import { inject, provide, watch } from "vue";
3
+ import { ADVANCED_MARKER_ELEMENT_INJECTION_KEY } from "./injectionKeys";
5
4
  import { MARKER_CLUSTERER_INJECTION_KEY } from "./ScriptGoogleMapsMarkerClusterer.vue";
6
- export const ADVANCED_MARKER_ELEMENT_INJECTION_KEY = /* @__PURE__ */ Symbol("marker");
5
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
6
+ export { ADVANCED_MARKER_ELEMENT_INJECTION_KEY } from "./injectionKeys";
7
7
  </script>
8
8
 
9
9
  <script setup>
@@ -36,51 +36,40 @@ const eventsWithMapMouseEventPayload = [
36
36
  "mouseover",
37
37
  "mouseup"
38
38
  ];
39
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
40
39
  const markerClustererContext = inject(MARKER_CLUSTERER_INJECTION_KEY, void 0);
41
- const advancedMarkerElement = shallowRef(void 0);
42
- const isUnmounted = ref(false);
43
- whenever(() => mapContext?.map.value && mapContext.mapsApi.value, async () => {
44
- await mapContext.mapsApi.value.importLibrary("marker");
45
- if (isUnmounted.value)
46
- return;
47
- advancedMarkerElement.value = new mapContext.mapsApi.value.marker.AdvancedMarkerElement(props.options);
48
- setupAdvancedMarkerElementEventListeners(advancedMarkerElement.value);
49
- if (markerClustererContext?.markerClusterer.value) {
50
- markerClustererContext.markerClusterer.value.addMarker(advancedMarkerElement.value);
51
- } else {
52
- advancedMarkerElement.value.map = mapContext.map.value;
53
- }
54
- whenever(() => props.options, (options) => {
55
- if (advancedMarkerElement.value && options) {
56
- Object.assign(advancedMarkerElement.value, options);
40
+ const advancedMarkerElement = useGoogleMapsResource({
41
+ async create({ mapsApi, map }) {
42
+ await mapsApi.importLibrary("marker");
43
+ const marker = new mapsApi.marker.AdvancedMarkerElement(props.options);
44
+ setupEventListeners(marker);
45
+ if (markerClustererContext?.markerClusterer.value) {
46
+ markerClustererContext.markerClusterer.value.addMarker(marker);
47
+ } else {
48
+ marker.map = map;
49
+ }
50
+ return marker;
51
+ },
52
+ cleanup(marker, { mapsApi }) {
53
+ mapsApi.event.clearInstanceListeners(marker);
54
+ if (markerClustererContext?.markerClusterer.value) {
55
+ markerClustererContext.markerClusterer.value.removeMarker(marker);
56
+ } else {
57
+ marker.map = null;
57
58
  }
58
- }, {
59
- deep: true
60
- });
61
- }, {
62
- immediate: true,
63
- once: true
64
- });
65
- onUnmounted(() => {
66
- isUnmounted.value = true;
67
- if (!advancedMarkerElement.value || !mapContext?.mapsApi.value) {
68
- return;
69
- }
70
- mapContext.mapsApi.value.event.clearInstanceListeners(advancedMarkerElement.value);
71
- if (markerClustererContext) {
72
- markerClustererContext.markerClusterer.value?.removeMarker(advancedMarkerElement.value);
73
- } else {
74
- advancedMarkerElement.value.map = null;
75
59
  }
76
60
  });
61
+ watch(() => props.options, (options) => {
62
+ if (advancedMarkerElement.value && options) {
63
+ Object.assign(advancedMarkerElement.value, options);
64
+ }
65
+ }, { deep: true });
77
66
  provide(ADVANCED_MARKER_ELEMENT_INJECTION_KEY, { advancedMarkerElement });
78
- function setupAdvancedMarkerElementEventListeners(advancedMarkerElement2) {
67
+ function setupEventListeners(marker) {
79
68
  eventsWithoutPayload.forEach((event) => {
80
- advancedMarkerElement2.addListener(event, () => emit(event));
69
+ marker.addListener(event, () => emit(event));
81
70
  });
82
71
  eventsWithMapMouseEventPayload.forEach((event) => {
83
- advancedMarkerElement2.addListener(event, (payload) => emit(event, payload));
72
+ marker.addListener(event, (payload) => emit(event, payload));
84
73
  });
85
74
  }
86
75
  </script>
@@ -1,7 +1,4 @@
1
- import type { InjectionKey, ShallowRef } from 'vue';
2
- export declare const ADVANCED_MARKER_ELEMENT_INJECTION_KEY: InjectionKey<{
3
- advancedMarkerElement: ShallowRef<google.maps.marker.AdvancedMarkerElement | undefined>;
4
- }>;
1
+ export { ADVANCED_MARKER_ELEMENT_INJECTION_KEY } from './injectionKeys.js';
5
2
  declare const _default: typeof __VLS_export;
6
3
  export default _default;
7
4
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -1,7 +1,6 @@
1
1
  <script setup>
2
- import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
2
+ import { watch } from "vue";
3
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
5
4
  const props = defineProps({
6
5
  options: { type: Object, required: false }
7
6
  });
@@ -23,36 +22,28 @@ const eventsWithMapMouseEventPayload = [
23
22
  "mouseup",
24
23
  "rightclick"
25
24
  ];
26
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
27
- let circle;
28
- whenever(() => mapContext?.map.value && mapContext.mapsApi.value, () => {
29
- circle = new mapContext.mapsApi.value.Circle({
30
- map: mapContext.map.value,
31
- ...props.options
32
- });
33
- setupCircleEventListeners(circle);
34
- whenever(() => props.options, (options) => {
35
- circle?.setOptions(options);
36
- }, {
37
- deep: true
38
- });
39
- }, {
40
- immediate: true,
41
- once: true
42
- });
43
- onUnmounted(() => {
44
- if (!circle || !mapContext?.mapsApi.value) {
45
- return;
25
+ const circle = useGoogleMapsResource({
26
+ create({ mapsApi, map }) {
27
+ const c = new mapsApi.Circle({ map, ...props.options });
28
+ setupEventListeners(c);
29
+ return c;
30
+ },
31
+ cleanup(c, { mapsApi }) {
32
+ mapsApi.event.clearInstanceListeners(c);
33
+ c.setMap(null);
46
34
  }
47
- mapContext.mapsApi.value.event.clearInstanceListeners(circle);
48
- circle.setMap(null);
49
35
  });
50
- function setupCircleEventListeners(circle2) {
36
+ watch(() => props.options, (options) => {
37
+ if (circle.value && options) {
38
+ circle.value.setOptions(options);
39
+ }
40
+ }, { deep: true });
41
+ function setupEventListeners(c) {
51
42
  eventsWithoutPayload.forEach((event) => {
52
- circle2.addListener(event, () => emit(event));
43
+ c.addListener(event, () => emit(event));
53
44
  });
54
45
  eventsWithMapMouseEventPayload.forEach((event) => {
55
- circle2.addListener(event, (payload) => emit(event, payload));
46
+ c.addListener(event, (payload) => emit(event, payload));
56
47
  });
57
48
  }
58
49
  </script>
@@ -1,30 +1,26 @@
1
1
  <script setup>
2
- import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
2
+ import { watch } from "vue";
3
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
5
4
  const props = defineProps({
6
5
  options: { type: Object, required: false }
7
6
  });
8
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
9
- let heatmapLayer;
10
- whenever(() => mapContext?.map.value && mapContext.mapsApi.value, async () => {
11
- await mapContext.mapsApi.value.importLibrary("visualization");
12
- heatmapLayer = new mapContext.mapsApi.value.visualization.HeatmapLayer({
13
- map: mapContext.map.value,
14
- ...props.options
15
- });
16
- whenever(() => props.options, (options) => {
17
- heatmapLayer?.setOptions(options);
18
- }, {
19
- deep: true
20
- });
21
- }, {
22
- immediate: true,
23
- once: true
24
- });
25
- onUnmounted(() => {
26
- heatmapLayer?.setMap(null);
7
+ const heatmapLayer = useGoogleMapsResource({
8
+ async create({ mapsApi, map }) {
9
+ await mapsApi.importLibrary("visualization");
10
+ return new mapsApi.visualization.HeatmapLayer({
11
+ map,
12
+ ...props.options
13
+ });
14
+ },
15
+ cleanup(layer) {
16
+ layer.setMap(null);
17
+ }
27
18
  });
19
+ watch(() => props.options, (options) => {
20
+ if (heatmapLayer.value && options) {
21
+ heatmapLayer.value.setOptions(options);
22
+ }
23
+ }, { deep: true });
28
24
  </script>
29
25
 
30
26
  <template>
@@ -1,9 +1,7 @@
1
1
  <script setup>
2
- import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted, useTemplateRef } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
5
- import { ADVANCED_MARKER_ELEMENT_INJECTION_KEY } from "./ScriptGoogleMapsAdvancedMarkerElement.vue";
6
- import { MARKER_INJECTION_KEY } from "./ScriptGoogleMapsMarker.vue";
2
+ import { inject, useTemplateRef, watch } from "vue";
3
+ import { ADVANCED_MARKER_ELEMENT_INJECTION_KEY, MARKER_INJECTION_KEY } from "./injectionKeys";
4
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
7
5
  const props = defineProps({
8
6
  options: { type: null, required: false }
9
7
  });
@@ -19,58 +17,53 @@ const infoWindowEvents = [
19
17
  "visible",
20
18
  "zindex_changed"
21
19
  ];
22
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
23
20
  const markerContext = inject(MARKER_INJECTION_KEY, void 0);
24
21
  const advancedMarkerElementContext = inject(ADVANCED_MARKER_ELEMENT_INJECTION_KEY, void 0);
25
22
  const infoWindowContainer = useTemplateRef("info-window-container");
26
- let infoWindow;
27
- whenever(
28
- () => mapContext?.map.value && mapContext.mapsApi.value && infoWindowContainer.value,
29
- () => {
30
- infoWindow = new mapContext.mapsApi.value.InfoWindow({
23
+ let markerClickListener;
24
+ const infoWindow = useGoogleMapsResource({
25
+ ready: () => !!infoWindowContainer.value,
26
+ create({ mapsApi, map }) {
27
+ const iw = new mapsApi.InfoWindow({
31
28
  content: infoWindowContainer.value,
32
29
  ...props.options
33
30
  });
34
- setupInfoWindowEventListeners(infoWindow);
31
+ setupEventListeners(iw);
35
32
  if (markerContext?.marker.value) {
36
- markerContext.marker.value.addListener("click", () => {
37
- infoWindow.open({
33
+ markerClickListener = markerContext.marker.value.addListener("click", () => {
34
+ iw.open({
38
35
  anchor: markerContext.marker.value,
39
- map: mapContext.map.value
36
+ map
40
37
  });
41
38
  });
42
39
  } else if (advancedMarkerElementContext?.advancedMarkerElement.value) {
43
- advancedMarkerElementContext.advancedMarkerElement.value.addListener("click", () => {
44
- infoWindow.open({
40
+ markerClickListener = advancedMarkerElementContext.advancedMarkerElement.value.addListener("click", () => {
41
+ iw.open({
45
42
  anchor: advancedMarkerElementContext.advancedMarkerElement.value,
46
- map: mapContext.map.value
43
+ map
47
44
  });
48
45
  });
49
46
  } else {
50
- infoWindow.setPosition(props.options?.position);
51
- infoWindow.open(mapContext.map.value);
47
+ iw.setPosition(props.options?.position);
48
+ iw.open(map);
52
49
  }
53
- whenever(() => props.options, (options) => {
54
- infoWindow?.setOptions(options);
55
- }, {
56
- deep: true
57
- });
50
+ return iw;
58
51
  },
59
- {
60
- immediate: true,
61
- once: true
62
- }
63
- );
64
- onUnmounted(() => {
65
- if (!infoWindow || !mapContext?.mapsApi.value) {
66
- return;
52
+ cleanup(iw, { mapsApi }) {
53
+ markerClickListener?.remove();
54
+ markerClickListener = void 0;
55
+ mapsApi.event.clearInstanceListeners(iw);
56
+ iw.close();
67
57
  }
68
- mapContext.mapsApi.value.event.clearInstanceListeners(infoWindow);
69
- infoWindow.close();
70
58
  });
71
- function setupInfoWindowEventListeners(infoWindow2) {
59
+ watch(() => props.options, (options) => {
60
+ if (infoWindow.value && options) {
61
+ infoWindow.value.setOptions(options);
62
+ }
63
+ }, { deep: true });
64
+ function setupEventListeners(iw) {
72
65
  infoWindowEvents.forEach((event) => {
73
- infoWindow2.addListener(event, () => emit(event));
66
+ iw.addListener(event, () => emit(event));
74
67
  });
75
68
  }
76
69
  </script>
@@ -1,7 +1,4 @@
1
- import type { InjectionKey, ShallowRef } from 'vue';
2
- export declare const MARKER_INJECTION_KEY: InjectionKey<{
3
- marker: ShallowRef<google.maps.Marker | undefined>;
4
- }>;
1
+ export { MARKER_INJECTION_KEY } from './injectionKeys.js';
5
2
  declare const _default: typeof __VLS_export;
6
3
  export default _default;
7
4
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -1,9 +1,9 @@
1
1
  <script>
2
- import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted, provide, shallowRef } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
2
+ import { inject, provide, watch } from "vue";
3
+ import { MARKER_INJECTION_KEY } from "./injectionKeys";
5
4
  import { MARKER_CLUSTERER_INJECTION_KEY } from "./ScriptGoogleMapsMarkerClusterer.vue";
6
- export const MARKER_INJECTION_KEY = /* @__PURE__ */ Symbol("marker");
5
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
6
+ export { MARKER_INJECTION_KEY } from "./injectionKeys";
7
7
  </script>
8
8
 
9
9
  <script setup>
@@ -36,46 +36,41 @@ const eventsWithMapMouseEventPayload = [
36
36
  "mouseover",
37
37
  "mouseup"
38
38
  ];
39
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
40
39
  const markerClustererContext = inject(MARKER_CLUSTERER_INJECTION_KEY, void 0);
41
- const marker = shallowRef(void 0);
42
- whenever(() => mapContext?.map.value && mapContext.mapsApi.value, () => {
43
- marker.value = new mapContext.mapsApi.value.Marker(props.options);
44
- setupMarkerEventListeners(marker.value);
45
- if (markerClustererContext?.markerClusterer.value) {
46
- markerClustererContext.markerClusterer.value.addMarker(marker.value, true);
47
- markerClustererContext.requestRerender();
48
- } else {
49
- marker.value.setMap(mapContext.map.value);
40
+ const marker = useGoogleMapsResource({
41
+ create({ mapsApi, map }) {
42
+ const m = new mapsApi.Marker(props.options);
43
+ setupEventListeners(m);
44
+ if (markerClustererContext?.markerClusterer.value) {
45
+ markerClustererContext.markerClusterer.value.addMarker(m, true);
46
+ markerClustererContext.requestRerender();
47
+ } else {
48
+ m.setMap(map);
49
+ }
50
+ return m;
51
+ },
52
+ cleanup(m, { mapsApi }) {
53
+ mapsApi.event.clearInstanceListeners(m);
54
+ if (markerClustererContext?.markerClusterer.value) {
55
+ markerClustererContext.markerClusterer.value.removeMarker(m, true);
56
+ markerClustererContext.requestRerender();
57
+ } else {
58
+ m.setMap(null);
59
+ }
50
60
  }
51
- whenever(() => props.options, (options) => {
52
- marker.value?.setOptions(options);
53
- }, {
54
- deep: true
55
- });
56
- }, {
57
- immediate: true,
58
- once: true
59
61
  });
60
- onUnmounted(() => {
61
- if (!marker.value || !mapContext?.mapsApi.value) {
62
- return;
63
- }
64
- mapContext.mapsApi.value.event.clearInstanceListeners(marker.value);
65
- if (markerClustererContext?.markerClusterer.value) {
66
- markerClustererContext.markerClusterer.value.removeMarker(marker.value, true);
67
- markerClustererContext.requestRerender();
68
- } else {
69
- marker.value.setMap(null);
62
+ watch(() => props.options, (options) => {
63
+ if (marker.value && options) {
64
+ marker.value.setOptions(options);
70
65
  }
71
- });
66
+ }, { deep: true });
72
67
  provide(MARKER_INJECTION_KEY, { marker });
73
- function setupMarkerEventListeners(marker2) {
68
+ function setupEventListeners(m) {
74
69
  eventsWithoutPayload.forEach((event) => {
75
- marker2.addListener(event, () => emit(event));
70
+ m.addListener(event, () => emit(event));
76
71
  });
77
72
  eventsWithMapMouseEventPayload.forEach((event) => {
78
- marker2.addListener(event, (payload) => emit(event, payload));
73
+ m.addListener(event, (payload) => emit(event, payload));
79
74
  });
80
75
  }
81
76
  </script>
@@ -1,7 +1,4 @@
1
- import type { InjectionKey, ShallowRef } from 'vue';
2
- export declare const MARKER_INJECTION_KEY: InjectionKey<{
3
- marker: ShallowRef<google.maps.Marker | undefined>;
4
- }>;
1
+ export { MARKER_INJECTION_KEY } from './injectionKeys.js';
5
2
  declare const _default: typeof __VLS_export;
6
3
  export default _default;
7
4
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  import { whenever } from "@vueuse/core";
3
- import { inject, onUnmounted, provide, shallowRef } from "vue";
4
- import { MAP_INJECTION_KEY } from "./ScriptGoogleMaps.vue";
3
+ import { provide, shallowRef } from "vue";
4
+ import { useGoogleMapsResource } from "./useGoogleMapsResource";
5
5
  export const MARKER_CLUSTERER_INJECTION_KEY = /* @__PURE__ */ Symbol("marker-clusterer");
6
6
  </script>
7
7
 
@@ -15,18 +15,20 @@ const markerClustererEvents = [
15
15
  "clusteringbegin",
16
16
  "clusteringend"
17
17
  ];
18
- const mapContext = inject(MAP_INJECTION_KEY, void 0);
19
- const markerClusterer = shallowRef(void 0);
20
- whenever(() => mapContext?.map.value, async (map) => {
21
- const { MarkerClusterer } = await import("@googlemaps/markerclusterer");
22
- markerClusterer.value = new MarkerClusterer({
23
- map,
24
- ...props.options
25
- });
26
- setupMarkerClustererEventListeners(markerClusterer.value);
27
- }, {
28
- immediate: true,
29
- once: true
18
+ const markerClusterer = useGoogleMapsResource({
19
+ async create({ map }) {
20
+ const { MarkerClusterer } = await import("@googlemaps/markerclusterer");
21
+ const clusterer = new MarkerClusterer({
22
+ map,
23
+ ...props.options
24
+ });
25
+ setupEventListeners(clusterer);
26
+ return clusterer;
27
+ },
28
+ cleanup(clusterer, { mapsApi }) {
29
+ mapsApi.event.clearInstanceListeners(clusterer);
30
+ clusterer.setMap(null);
31
+ }
30
32
  });
31
33
  const markerClustererNeedsRerender = shallowRef(false);
32
34
  function requestRerender() {
@@ -36,13 +38,6 @@ whenever(() => markerClustererNeedsRerender.value && markerClusterer.value, () =
36
38
  markerClusterer.value.render();
37
39
  markerClustererNeedsRerender.value = false;
38
40
  });
39
- onUnmounted(() => {
40
- if (!markerClusterer.value || !mapContext?.mapsApi.value) {
41
- return;
42
- }
43
- mapContext.mapsApi.value.event.clearInstanceListeners(markerClusterer.value);
44
- markerClusterer.value.setMap(null);
45
- });
46
41
  provide(
47
42
  MARKER_CLUSTERER_INJECTION_KEY,
48
43
  {
@@ -50,7 +45,7 @@ provide(
50
45
  requestRerender
51
46
  }
52
47
  );
53
- function setupMarkerClustererEventListeners(clusterer) {
48
+ function setupEventListeners(clusterer) {
54
49
  markerClustererEvents.forEach((event) => {
55
50
  clusterer.addListener(event, () => emit(event, clusterer));
56
51
  });