diff --git a/assets/dist/abstract_map_controller.d.ts b/assets/dist/abstract_map_controller.d.ts index e4d3f3f..42e7649 100644 --- a/assets/dist/abstract_map_controller.d.ts +++ b/assets/dist/abstract_map_controller.d.ts @@ -1,19 +1,20 @@ import { Controller } from '@hotwired/stimulus'; -export type Point = { + +type Point = { lat: number; lng: number; }; -export type Identifier = string; -export type WithIdentifier> = T & { +type Identifier = string; +type WithIdentifier> = T & { '@id': Identifier; }; type ExtraData = Record; -export declare const IconTypes: { +declare const IconTypes: { readonly Url: "url"; readonly Svg: "svg"; readonly UxIcon: "ux-icon"; }; -export type Icon = { +type Icon = { width: number; height: number; } & ({ @@ -27,7 +28,7 @@ export type Icon = { type: typeof IconTypes.Svg; html: string; }); -export type MapDefinition = { +type MapDefinition = { center: Point | null; zoom: number | null; minZoom: number | null; @@ -36,7 +37,7 @@ export type MapDefinition = { bridgeOptions?: BridgeMapOptions; extra: ExtraData; }; -export type MarkerDefinition = WithIdentifier<{ +type MarkerDefinition = WithIdentifier<{ position: Point; title: string | null; infoWindow?: Omit, 'position'>; @@ -45,7 +46,7 @@ export type MarkerDefinition = Wit bridgeOptions?: BridgeMarkerOptions; extra: ExtraData; }>; -export type PolygonDefinition = WithIdentifier<{ +type PolygonDefinition = WithIdentifier<{ infoWindow?: Omit, 'position'>; points: Array | Array>; title: string | null; @@ -53,7 +54,7 @@ export type PolygonDefinition = W bridgeOptions?: BridgePolygonOptions; extra: ExtraData; }>; -export type PolylineDefinition = WithIdentifier<{ +type PolylineDefinition = WithIdentifier<{ infoWindow?: Omit, 'position'>; points: Array; title: string | null; @@ -61,7 +62,7 @@ export type PolylineDefinition = bridgeOptions?: BridgePolylineOptions; extra: ExtraData; }>; -export type CircleDefinition = WithIdentifier<{ +type CircleDefinition = WithIdentifier<{ infoWindow?: Omit, 'position'>; center: Point; radius: number; @@ -70,7 +71,7 @@ export type CircleDefinition = Wit bridgeOptions?: BridgeCircleOptions; extra: ExtraData; }>; -export type RectangleDefinition = WithIdentifier<{ +type RectangleDefinition = WithIdentifier<{ infoWindow?: Omit, 'position'>; southWest: Point; northEast: Point; @@ -79,7 +80,7 @@ export type RectangleDefinition bridgeOptions?: BridgeRectangleOptions; extra: ExtraData; }>; -export type InfoWindowDefinition = { +type InfoWindowDefinition = { headerContent: string | null; content: string | null; position: Point; @@ -89,7 +90,7 @@ export type InfoWindowDefinition = { bridgeOptions?: BridgeInfoWindowOptions; extra: ExtraData; }; -export default abstract class extends Controller { +declare abstract class export_default extends Controller { static values: { providerOptions: ObjectConstructor; center: ObjectConstructor; @@ -192,4 +193,5 @@ export default abstract class this.createMarker({ definition })); + this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); + this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); + this.circlesValue.forEach((definition) => this.createCircle({ definition })); + this.rectanglesValue.forEach((definition) => this.createRectangle({ definition })); + if (this.fitBoundsToMarkersValue) { + this.doFitBoundsToMarkers(); } - connect() { - const extra = this.hasExtraValue ? this.extraValue : {}; - const mapDefinition = { - center: this.hasCenterValue ? this.centerValue : null, - zoom: this.hasZoomValue ? this.zoomValue : null, - minZoom: this.hasMinZoomValue ? this.minZoomValue : null, - maxZoom: this.hasMaxZoomValue ? this.maxZoomValue : null, - options: this.optionsValue, - extra, - }; - this.dispatchEvent('pre-connect', mapDefinition); - this.createMarker = this.createDrawingFactory('marker', this.markers, this.doCreateMarker.bind(this)); - this.createPolygon = this.createDrawingFactory('polygon', this.polygons, this.doCreatePolygon.bind(this)); - this.createPolyline = this.createDrawingFactory('polyline', this.polylines, this.doCreatePolyline.bind(this)); - this.createCircle = this.createDrawingFactory('circle', this.circles, this.doCreateCircle.bind(this)); - this.createRectangle = this.createDrawingFactory('rectangle', this.rectangles, this.doCreateRectangle.bind(this)); - this.map = this.doCreateMap({ definition: mapDefinition }); - this.markersValue.forEach((definition) => this.createMarker({ definition })); - this.polygonsValue.forEach((definition) => this.createPolygon({ definition })); - this.polylinesValue.forEach((definition) => this.createPolyline({ definition })); - this.circlesValue.forEach((definition) => this.createCircle({ definition })); - this.rectanglesValue.forEach((definition) => this.createRectangle({ definition })); - if (this.fitBoundsToMarkersValue) { - this.doFitBoundsToMarkers(); - } - this.dispatchEvent('connect', { - map: this.map, - markers: [...this.markers.values()], - polygons: [...this.polygons.values()], - polylines: [...this.polylines.values()], - circles: [...this.circles.values()], - rectangles: [...this.rectangles.values()], - infoWindows: this.infoWindows, - extra, - }); - this.isConnected = true; + this.dispatchEvent("connect", { + map: this.map, + markers: [...this.markers.values()], + polygons: [...this.polygons.values()], + polylines: [...this.polylines.values()], + circles: [...this.circles.values()], + rectangles: [...this.rectangles.values()], + infoWindows: this.infoWindows, + extra + }); + this.isConnected = true; + } + //region Public API + createInfoWindow({ + definition, + element + }) { + this.dispatchEvent("info-window:before-create", { definition, element }); + const infoWindow = this.doCreateInfoWindow({ definition, element }); + this.dispatchEvent("info-window:after-create", { infoWindow, definition, element }); + this.infoWindows.push(infoWindow); + return infoWindow; + } + markersValueChanged() { + if (!this.isConnected) { + return; } - createInfoWindow({ definition, element, }) { - this.dispatchEvent('info-window:before-create', { definition, element }); - const infoWindow = this.doCreateInfoWindow({ definition, element }); - this.dispatchEvent('info-window:after-create', { infoWindow, definition, element }); - this.infoWindows.push(infoWindow); - return infoWindow; + this.onDrawChanged(this.markers, this.markersValue, this.createMarker, this.doRemoveMarker); + if (this.fitBoundsToMarkersValue) { + this.doFitBoundsToMarkers(); } - markersValueChanged() { - if (!this.isConnected) { - return; - } - this.onDrawChanged(this.markers, this.markersValue, this.createMarker, this.doRemoveMarker); - if (this.fitBoundsToMarkersValue) { - this.doFitBoundsToMarkers(); - } + } + polygonsValueChanged() { + if (!this.isConnected) { + return; } - polygonsValueChanged() { - if (!this.isConnected) { - return; - } - this.onDrawChanged(this.polygons, this.polygonsValue, this.createPolygon, this.doRemovePolygon); + this.onDrawChanged(this.polygons, this.polygonsValue, this.createPolygon, this.doRemovePolygon); + } + polylinesValueChanged() { + if (!this.isConnected) { + return; } - polylinesValueChanged() { - if (!this.isConnected) { - return; - } - this.onDrawChanged(this.polylines, this.polylinesValue, this.createPolyline, this.doRemovePolyline); + this.onDrawChanged(this.polylines, this.polylinesValue, this.createPolyline, this.doRemovePolyline); + } + circlesValueChanged() { + if (!this.isConnected) { + return; } - circlesValueChanged() { - if (!this.isConnected) { - return; - } - this.onDrawChanged(this.circles, this.circlesValue, this.createCircle, this.doRemoveCircle); + this.onDrawChanged(this.circles, this.circlesValue, this.createCircle, this.doRemoveCircle); + } + rectanglesValueChanged() { + if (!this.isConnected) { + return; } - rectanglesValueChanged() { - if (!this.isConnected) { - return; - } - this.onDrawChanged(this.rectangles, this.rectanglesValue, this.createRectangle, this.doRemoveRectangle); - } - createDrawingFactory(type, draws, factory) { - const eventBefore = `${type}:before-create`; - const eventAfter = `${type}:after-create`; - return ({ definition }) => { - this.dispatchEvent(eventBefore, { definition }); - if (typeof definition.rawOptions !== 'undefined') { - console.warn(`[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`, definition); - } - const drawing = factory({ definition }); - this.dispatchEvent(eventAfter, { [type]: drawing, definition }); - draws.set(definition['@id'], drawing); - return drawing; - }; - } - onDrawChanged(draws, newDrawDefinitions, factory, remover) { - const idsToRemove = new Set(draws.keys()); - newDrawDefinitions.forEach((definition) => { - idsToRemove.delete(definition['@id']); - }); - idsToRemove.forEach((id) => { - const draw = draws.get(id); - remover(draw); - draws.delete(id); - }); - newDrawDefinitions.forEach((definition) => { - if (!draws.has(definition['@id'])) { - factory({ definition }); - } - }); - } -} -default_1.values = { - providerOptions: Object, - center: Object, - zoom: Number, - minZoom: Number, - maxZoom: Number, - fitBoundsToMarkers: Boolean, - markers: Array, - polygons: Array, - polylines: Array, - circles: Array, - rectangles: Array, - options: Object, - extra: Object, + this.onDrawChanged(this.rectangles, this.rectanglesValue, this.createRectangle, this.doRemoveRectangle); + } + createDrawingFactory(type, draws, factory) { + const eventBefore = `${type}:before-create`; + const eventAfter = `${type}:after-create`; + return ({ definition }) => { + this.dispatchEvent(eventBefore, { definition }); + if (typeof definition.rawOptions !== "undefined") { + console.warn( + `[Symfony UX Map] The event "${eventBefore}" added a deprecated "rawOptions" property to the definition, it will be removed in a next major version, replace it with "bridgeOptions" instead.`, + definition + ); + } + const drawing = factory({ definition }); + this.dispatchEvent(eventAfter, { [type]: drawing, definition }); + draws.set(definition["@id"], drawing); + return drawing; + }; + } + onDrawChanged(draws, newDrawDefinitions, factory, remover) { + const idsToRemove = new Set(draws.keys()); + newDrawDefinitions.forEach((definition) => { + idsToRemove.delete(definition["@id"]); + }); + idsToRemove.forEach((id) => { + const draw = draws.get(id); + remover(draw); + draws.delete(id); + }); + newDrawDefinitions.forEach((definition) => { + if (!draws.has(definition["@id"])) { + factory({ definition }); + } + }); + } + //endregion +}; +abstract_map_controller_default.values = { + providerOptions: Object, + center: Object, + zoom: Number, + minZoom: Number, + maxZoom: Number, + fitBoundsToMarkers: Boolean, + markers: Array, + polygons: Array, + polylines: Array, + circles: Array, + rectangles: Array, + options: Object, + extra: Object +}; +export { + IconTypes, + abstract_map_controller_default as default }; - -export { IconTypes, default_1 as default };