Skip to content

Commit

Permalink
fix(v3): add type define-emit declarations
Browse files Browse the repository at this point in the history
- Add new events to the component event list
- Improve some jsdoc comments
  • Loading branch information
diegoazh committed Mar 31, 2024
1 parent 9b52709 commit fb29c9c
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 123 deletions.
27 changes: 12 additions & 15 deletions packages/v3/src/components/autocomplete-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
</div>
</template>

<script lang="ts">
export default {
inheritAttrs: false,
};
</script>

<script lang="ts" setup>
import {
bindGoogleMapsEventsToVueEventsOnSetup,
Expand Down Expand Up @@ -78,7 +72,9 @@ const props = withDefaults(
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const gmvAutoCompleteInput = ref<HTMLInputElement | null>(null);
const emits = defineEmits(getComponentEventsConfig('GmvAutocomplete'));
const emits = defineEmits<{
place_changed: [value: google.maps.places.PlaceResult];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -130,12 +126,6 @@ onMounted(() => {
downArrowSimulator(scopedInput);
}
if (typeof google.maps.places.Autocomplete !== 'function') {
throw new Error(
"google.maps.places.Autocomplete is undefined. Did you add 'places' to libraries when loading Google Maps?",
);
}
const autocompleteOptions: IAutoCompleteInputVueComponentProps & {
[key: string]: any;
} = {
Expand All @@ -146,6 +136,13 @@ onMounted(() => {
const { Autocomplete } = (await google.maps.importLibrary(
'places',
)) as google.maps.PlacesLibrary;
if (typeof Autocomplete !== 'function') {
throw new Error(
"google.maps.places.Autocomplete is undefined. Did you add 'places' to libraries when loading Google Maps?",
);
}
autoCompleteInstance = new Autocomplete(scopedInput, autocompleteOptions);
const autoCompletePropsConfig =
Expand All @@ -158,14 +155,14 @@ onMounted(() => {
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
autoCompletePropsConfig,
autoCompleteInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
autoCompleteEventsConfig,
autoCompleteInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
20 changes: 17 additions & 3 deletions packages/v3/src/components/circle-shape.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ const props = withDefaults(
/*******************************************************************************
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const emits = defineEmits(getComponentEventsConfig('GmvCircle'));
const emits = defineEmits<{
center_changed: [];
click: [value: google.maps.MapMouseEvent];
dblclick: [value: google.maps.MapMouseEvent];
drag: [value: google.maps.MapMouseEvent];
dragend: [value: google.maps.MapMouseEvent];
dragstart: [value: google.maps.MapMouseEvent];
mousedown: [value: google.maps.MapMouseEvent];
mousemove: [value: google.maps.MapMouseEvent];
mouseout: [value: google.maps.MapMouseEvent];
mouseover: [value: google.maps.MapMouseEvent];
mouseup: [value: google.maps.MapMouseEvent];
radius_changed: [value: void];
rightclick: [value: google.maps.MapMouseEvent];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -96,13 +110,13 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
circleShapePropsConfig,
circleShapeInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
circleShapeEventsConfig,
circleShapeInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
19 changes: 16 additions & 3 deletions packages/v3/src/components/cluster-icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ const props = withDefaults(
/*******************************************************************************
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const emits = defineEmits(getComponentEventsConfig('GmvCluster'));
const emits = defineEmits<{
clusteringbegin: [];
clusteringend: [];
click: [value: google.maps.MapMouseEvent];
rightclick: [value: google.maps.MapMouseEvent];
dblclick: [value: google.maps.MapMouseEvent];
drag: [value: google.maps.MapMouseEvent];
dragend: [value: google.maps.MapMouseEvent];
dragstart: [value: google.maps.MapMouseEvent];
mousedown: [value: google.maps.MapMouseEvent];
mouseout: [value: google.maps.MapMouseEvent];
mouseover: [value: google.maps.MapMouseEvent];
mouseup: [value: google.maps.MapMouseEvent];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -105,14 +118,14 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
clusterIconPropsConfig,
clusterInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
clusterIconEventsConfig,
clusterInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
16 changes: 13 additions & 3 deletions packages/v3/src/components/drawing-manager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ const props = withDefaults(
/*******************************************************************************
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const emits = defineEmits(getComponentEventsConfig('GmvDrawingManager'));
const emits = defineEmits<{
circlecomplete: [value: google.maps.Circle];
markercomplete: [value: google.maps.Marker];
polygoncomplete: [value: google.maps.Polygon];
polylinecomplete: [value: google.maps.Polyline];
rectanglecomplete: [value: google.maps.Rectangle];
overlaycomplete: [value: google.maps.drawing.OverlayCompleteEvent];
'update:shapes': [value: google.maps.drawing.OverlayCompleteEvent[]];
'added:shape': [value: google.maps.drawing.OverlayCompleteEvent];
'removed:shape': [value: google.maps.drawing.OverlayCompleteEvent];
}>();
const $slots = useSlots();
/*******************************************************************************
Expand Down Expand Up @@ -138,13 +148,13 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
drawingManagerPropsConfig,
drawingManagerInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
drawingManagerEventsConfig,
drawingManagerInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
16 changes: 13 additions & 3 deletions packages/v3/src/components/heatmap-layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { inject, onUnmounted, provide, watch } from 'vue';
* @displayName GmvHeatmapLayer
* @see [source code](/guide/heatmap-layer.html#source-code)
* @see [Official documentation](https://developers.google.com/maps/documentation/javascript/heatmaplayer)
* @see [Official reference](https://developers.google.com/maps/documentation/javascript/reference/visualization#HeatmapLayer)
*/
/*******************************************************************************
Expand Down Expand Up @@ -43,7 +44,15 @@ const props = withDefaults(
/*******************************************************************************
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const emits = defineEmits(getComponentEventsConfig('GmvHeatmapLayer'));
const emits = defineEmits<{
data_changed: [
value:
| google.maps.MVCArray<
google.maps.LatLng | google.maps.visualization.WeightedLocation
>
| (google.maps.LatLng | google.maps.visualization.WeightedLocation)[],
];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -89,14 +98,14 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
heatmapLayerPropsConfig,
heatMapLayerInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
heatmapLayerEventsConfig,
heatMapLayerInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down Expand Up @@ -124,6 +133,7 @@ watch(
if (heatMapLayerInstance) {
if (value && value !== oldValue) {
heatMapLayerInstance.setData(value);
emits('data_changed', value);
}
}
},
Expand Down
26 changes: 13 additions & 13 deletions packages/v3/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Autocomplete from '../components/autocomplete-input.vue';
import Circle from '../components/circle-shape.vue';
import Cluster from '../components/cluster-icon.vue';
import DrawingManager from '../components/drawing-manager.vue';
import HeatmapLayer from '../components/heatmap-layer.vue';
import InfoWindow from '../components/info-window.vue';
import KmlLayer from '../components/kml-layer.vue';
import MapLayer from '../components/map-layer.vue';
import Marker from '../components/marker-icon.vue';
import Polygon from '../components/polygon-shape.vue';
import Polyline from '../components/polyline-shape.vue';
import Rectangle from '../components/rectangle-shape.vue';
import StreetViewPanorama from '../components/street-view-panorama.vue';
import Autocomplete from '@/components/autocomplete-input.vue';
import Circle from '@/components/circle-shape.vue';
import Cluster from '@/components/cluster-icon.vue';
import DrawingManager from '@/components/drawing-manager.vue';
import HeatmapLayer from '@/components/heatmap-layer.vue';
import InfoWindow from '@/components/info-window.vue';
import KmlLayer from '@/components/kml-layer.vue';
import MapLayer from '@/components/map-layer.vue';
import Marker from '@/components/marker-icon.vue';
import Polygon from '@/components/polygon-shape.vue';
import Polyline from '@/components/polyline-shape.vue';
import Rectangle from '@/components/rectangle-shape.vue';
import StreetViewPanorama from '@/components/street-view-panorama.vue';

export {
Autocomplete,
Expand Down
14 changes: 11 additions & 3 deletions packages/v3/src/components/info-window.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ const props = withDefaults(
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const gmvInfoWindow = ref<HTMLElement | null>(null);
const emits = defineEmits(getComponentEventsConfig('GmvInfoWindow'));
const emits = defineEmits<{
close: [];
closeclick: [];
content_changed: [];
domready: [];
position_changed: [];
visible: [];
zindex_changed: [];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -114,14 +122,14 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
infoWindowPropsConfig,
infoWindowInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
infoWindowEventsConfig,
infoWindowInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
10 changes: 7 additions & 3 deletions packages/v3/src/components/kml-layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const props = withDefaults(
/*******************************************************************************
* TEMPLATE REF, ATTRIBUTES, EMITTERS AND SLOTS
******************************************************************************/
const emits = defineEmits(getComponentEventsConfig('GmvKmlLayer'));
const emits = defineEmits<{
click: [value: google.maps.KmlMouseEvent];
defaultviewport_changed: [];
status_changed: [];
}>();
/*******************************************************************************
* INJECT
Expand Down Expand Up @@ -84,13 +88,13 @@ const promise = mapPromise
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
kmlLayerPropsConfig,
kmlLayerInstance,
emits,
emits as any,
props,
);
bindGoogleMapsEventsToVueEventsOnSetup(
kmlLayerEventsConig,
kmlLayerInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down
30 changes: 27 additions & 3 deletions packages/v3/src/components/map-layer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const props = withDefaults(
heading?: number;
isFractionalZoomEnabled?: boolean;
keyboardShortcuts?: boolean;
mapId?: string;
mapTypeControl?: boolean;
mapTypeControlOptions?: google.maps.MapTypeControlOptions;
mapTypeId?: google.maps.MapTypeId;
Expand Down Expand Up @@ -109,7 +110,30 @@ const props = withDefaults(
* TEMPLATE REF, ATTRIBUTES AND EMITTERS
******************************************************************************/
const gmvMap = ref<HTMLElement | null>(null);
const emits = defineEmits(getComponentEventsConfig('GmvMap'));
const emits = defineEmits<{
bounds_changed: [value: google.maps.LatLngBounds | undefined];
center_changed: [value: google.maps.LatLng | undefined];
click: [value: google.maps.MapMouseEvent | google.maps.IconMouseEvent];
contextmenu: [value: google.maps.MapMouseEvent];
dblclick: [value: google.maps.MapMouseEvent];
drag: [];
dragend: [];
dragstart: [];
heading_changed: [];
idle: [];
isfractionalzoomenabled_changed: [];
mapcapabilities_changed: [];
maptypeid_changed: [];
mousemove: [value: google.maps.MapMouseEvent];
mouseout: [value: google.maps.MapMouseEvent];
mouseover: [value: google.maps.MapMouseEvent];
projection_changed: [];
renderingtype_changed: [];
tilesloaded: [];
tilt_changed: [];
zoom_changed: [value: number | undefined];
resize: [];
}>();
/*******************************************************************************
* RECYCLE KEY
Expand Down Expand Up @@ -319,15 +343,15 @@ onMounted(() => {
bindPropsWithGoogleMapsSettersAndGettersOnSetup(
mapLayerPropsConfig,
mapInstance,
emits,
emits as any,
props,
);
// Auto bind all events by default
bindGoogleMapsEventsToVueEventsOnSetup(
mapLayerEventsConfig,
mapInstance,
emits,
emits as any,
excludedEvents,
);
Expand Down

0 comments on commit fb29c9c

Please sign in to comment.