Update dependencies and improve build system

This commit is contained in:
Fawad Mirzad
2021-02-13 17:30:46 +01:00
parent 04431e1b39
commit 9a20c42459
57 changed files with 8395 additions and 1064 deletions

View File

@@ -1,47 +1,44 @@
import lazy from './utils/lazyValue'
import {loadGmapApi} from './manager'
import {createApp} from 'vue'
import { loadGmapApi } from './manager'
import { createApp } from 'vue'
import Marker from './components/marker'
import Polyline from './components/polyline'
import Polygon from './components/polygon'
import Circle from './components/circle'
import Rectangle from './components/rectangle'
import GmapCluster from './components/cluster'
// Vue component imports
import GmapCluster from './components/cluster.vue'
import InfoWindow from './components/infoWindow.vue'
import Map from './components/map.vue'
import StreetViewPanorama from './components/streetViewPanorama.vue'
import PlaceInput from './components/placeInput.vue'
import Autocomplete from './components/autocomplete.vue'
import MapElementMixin from './components/mapElementMixin'
import MapElementFactory from './components/mapElementFactory'
import MountableMixin from './utils/mountableMixin'
// HACK: Cluster should be loaded conditionally
// However in the web version, it's not possible to write
// `import 'vue2-google-maps/src/components/cluster'`, so we need to
// import it anyway (but we don't have to register it)
// Therefore we use babel-plugin-transform-inline-environment-variables to
// set BUILD_DEV to truthy / falsy
const Cluster = (process.env.BUILD_DEV === '1')
? undefined
: (s => s.default || s)(require('./components/cluster'))
let GmapApi = null
// export everything
export {loadGmapApi, Marker, Polyline, Polygon, Circle, Cluster, Rectangle,
InfoWindow, Map, PlaceInput, MapElementMixin, MapElementFactory, Autocomplete,
MountableMixin, StreetViewPanorama}
export {
loadGmapApi,
Marker,
Polyline,
Polygon,
Circle,
GmapCluster,
Rectangle,
InfoWindow,
Map,
MapElementMixin,
MapElementFactory,
Autocomplete,
MountableMixin,
}
export function install (Vue, options) {
export function install(Vue, options) {
// Set defaults
options = {
installComponents: true,
autobindAllEvents: false,
...options
...options,
}
// Update the global `GmapApi`. This will allow
@@ -49,7 +46,11 @@ export function install (Vue, options) {
// via:
// import {gmapApi} from 'vue2-google-maps'
// export default { computed: { google: gmapApi } }
GmapApi = createApp({data: {gmapApi: null}});
GmapApi = createApp({
data: function () {
return { gmapApi: null }
},
})
const defaultResizeBus = createApp()
@@ -58,11 +59,11 @@ export function install (Vue, options) {
let gmapApiPromiseLazy = makeGmapApiPromiseLazy(options)
Vue.mixin({
created () {
created() {
this.$gmapDefaultResizeBus = defaultResizeBus
this.$gmapOptions = options
this.$gmapApiPromiseLazy = gmapApiPromiseLazy
}
},
})
Vue.$gmapDefaultResizeBus = defaultResizeBus
Vue.$gmapApiPromiseLazy = gmapApiPromiseLazy
@@ -77,22 +78,23 @@ export function install (Vue, options) {
Vue.component('GmapCircle', Circle)
Vue.component('GmapRectangle', Rectangle)
Vue.component('GmapAutocomplete', Autocomplete)
Vue.component('GmapPlaceInput', PlaceInput)
Vue.component('GmapStreetViewPanorama', StreetViewPanorama)
}
}
function makeGmapApiPromiseLazy (options) {
function makeGmapApiPromiseLazy(options) {
// Things to do once the API is loaded
function onApiLoaded () {
function onApiLoaded() {
GmapApi.gmapApi = {}
return window.google
}
if (options.load) { // If library should load the API
return lazy(() => { // Load the
if (options.load) {
// If library should load the API
return lazy(() => {
// Load the
// This will only be evaluated once
if (typeof window === 'undefined') { // server side -- never resolve this promise
if (typeof window === 'undefined') {
// server side -- never resolve this promise
return new Promise(() => {}).then(onApiLoaded)
} else {
return new Promise((resolve, reject) => {
@@ -102,11 +104,11 @@ function makeGmapApiPromiseLazy (options) {
} catch (err) {
reject(err)
}
})
.then(onApiLoaded)
}).then(onApiLoaded)
}
})
} else { // If library should not handle API, provide
} else {
// If library should not handle API, provide
// end-users with the global `vueGoogleMapsInit: () => undefined`
// when the Google Maps API has been loaded
const promise = new Promise((resolve) => {
@@ -121,6 +123,6 @@ function makeGmapApiPromiseLazy (options) {
}
}
export function gmapApi () {
export function gmapApi() {
return GmapApi.gmapApi && window.google
}