UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

6 lines (5 loc) 6.42 kB
var y=Object.defineProperty;var c=(r,t)=>y(r,"name",{value:t,configurable:!0});var n=function(r,t,e,o){var a=arguments.length,i=a<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,p;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(r,t,e,o);else for(var h=r.length-1;h>=0;h--)(p=r[h])&&(i=(a<3?p(i):a>3?p(t,e,i):p(t,e))||i);return a>3&&i&&Object.defineProperty(t,e,i),i};import"../../config.js";import{addNewInState as f}from"./modules/add-new-in-state.js";import{initOrUpdateElementFromState as C}from"./modules/init-or-update-element-from-state.js";import{debounce as m}from"jodit/esm/core/decorators/debounce/debounce.js";import{hook as v}from"jodit/esm/core/decorators/hook/hook.js";import{wait as u}from"jodit/esm/core/decorators/wait/wait.js";import{watch as l}from"jodit/esm/core/decorators/watch/watch.js";import{uniqueUid as M}from"jodit/esm/core/global.js";import{assert as d}from"jodit/esm/core/helpers/utils/assert.js";import{css as z}from"jodit/esm/core/helpers/utils/css.js";import{UIGroup as b}from"jodit/esm/core/ui/index.js";import{ToolbarCollection as w}from"jodit/esm/modules/toolbar/collection/collection.js";import{STORAGE_KEY as _}from"../../helpers/const.js";const g=class g extends b{className(){return"UIMap"}json(){return JSON.stringify({...this.state,mode:"hand"})}async onReady(){await this.apiLoaded;const t=this.getElm("map-root");d(t!=null,"map-root element does not exists"),this.map=new google.maps.Map(t,{center:{lat:this.state.center[0],lng:this.state.center[1]},zoom:this.state.zoom,mapTypeId:this.state.type}),this.map.addListener("zoom_changed",()=>{var e;this.state.zoom=(e=this.map.getZoom())!==null&&e!==void 0?e:10}),this.map.addListener("center_changed",()=>{var e,o,a,i,p,h;this.state.center=[(a=(o=(e=this.map)===null||e===void 0?void 0:e.getCenter())===null||o===void 0?void 0:o.lat())!==null&&a!==void 0?a:55,(h=(p=(i=this.map)===null||i===void 0?void 0:i.getCenter())===null||p===void 0?void 0:p.lng())!==null&&h!==void 0?h:34]}),this.map.addListener("maptypeid_changed",()=>{const e=this.map.getMapTypeId();e&&(this.state.type=e)}),this.initDrawManager(),this.onChangeElementsList(),this.onChangeSize(),this.onChangeControls(),this.onChangeLayer(),this.onChangeMapType(),this.onChangeMode(),this.mapInitialized=!0,this.j.async.requestIdleCallback(()=>{this.j.e.fire(this,"GoogleMapsIsReady")})}initDrawManager(){try{const t=new google.maps.drawing.DrawingManager;t.setMap(this.map),t.setOptions({drawingControl:!1,polygonOptions:{...this.options.googleMaps.map.defaultStates.polygon,clickable:!0,editable:!0},polylineOptions:{...this.options.googleMaps.map.defaultStates.polyline,clickable:!0,editable:!0},markerOptions:{...this.options.googleMaps.map.defaultStates.marker,clickable:!0},circleOptions:{...this.options.googleMaps.map.defaultStates.circle,clickable:!0,editable:!0}}),this.drawingManager=t,google.maps.event.addListener(t,"overlaycomplete",e=>{e.overlay&&(f.call(this,e.overlay),e.overlay.setMap(null))})}catch{}}changeCreateMode(t){this.state.mode=this.state.mode===t?"hand":t}onChangeMode(){var t;this.j.buffer.set("createMode.gm",this.state.mode),(t=this.drawingManager)===null||t===void 0||t.setDrawingMode(this.state.mode==="hand"?null:this.state.mode),this.j.e.fire("updateToolbar")}onChangeElementsList(){const{state:{elements:t},mapElements:e}=this;t.length<e.length&&e.slice(t.length).forEach(o=>{o.gme.setMap(null)}),e.length=t.length,t.forEach((o,a)=>C.call(this,o,a))}onChangeCenter(){const t=this.map.getCenter();(t?.lat()!==this.state.center[0]||t?.lng()!==this.state.center[1])&&this.map.setCenter({lat:this.state.center[0],lng:this.state.center[1]})}onChangeZoom(){var t;(t=this.map)===null||t===void 0||t.setZoom(this.state.zoom)}onChangeControls(){var t;let e;for(e in this.state.controls)(t=this.map)===null||t===void 0||t.set(e,this.state.controls[e])}onChangeBound(){this.options.googleMaps.saveStateInStorage&&this.j.storage.set(_,{center:this.state.center,size:this.state.size,zoom:this.state.zoom,type:this.state.type,layer:this.state.layer,controls:this.state.controls})}onChangeSize(){const t=this.getElm("map-size");d(t!=null,"map-size element does not exists"),z(t,{width:this.state.size[0],height:this.state.size[1]})}onChangeMapType(){this.map.setMapTypeId(this.state.type)}onChangeLayer(){switch(this.layers.forEach(t=>t.setMap(null)),this.layers.length=0,this.state.layer){case"traffic":this.layers.push(new google.maps.TrafficLayer);break;case"transit":this.layers.push(new google.maps.TransitLayer);break;case"bicycling":this.layers.push(new google.maps.BicyclingLayer);break}this.layers.forEach(t=>t.setMap(this.map))}render(){return`<div> <div class='&__map-root'></div> <div class='&__map-size'></div> <div class='&__map-palette'></div> </div>`}appendChildToContainer(){}constructor(t,e,o){super(t),this.options=o,this.toolbar=new w(this.jodit),this.state={uid:"jd"+M()+new Date().toString().replace(/[^0-9]/g,""),layer:this.options.googleMaps.map.layer,center:this.options.googleMaps.map.defaultCenter,zoom:this.options.googleMaps.map.defaultZoom,size:this.options.googleMaps.map.size,type:this.options.googleMaps.map.type,controls:{zoomControl:!0,mapTypeControl:!0,scaleControl:!0,streetViewControl:!0,rotateControl:!0,fullscreenControl:!0},mode:"hand",elements:[]},this.mapElements=[],this.apiLoaded=null,this.mapInitialized=!1,this.layers=[],Object.assign(this.state,e),this.toolbar.build(["gm.hand","gm.marker","gm.polyline","gm.polygon","gm.circle"]);const a=this.getElm("map-palette");d(a!=null,"palette element does not exists"),a.appendChild(this.toolbar.container)}};c(g,"UIMap");let s=g;n([v("ready")],s.prototype,"onReady",null),n([l("?:changeCreateMode.gm")],s.prototype,"changeCreateMode",null),n([l("state.mode")],s.prototype,"onChangeMode",null),n([l("state.elements")],s.prototype,"onChangeElementsList",null),n([l("state.center"),u(r=>r.mapInitialized),m()],s.prototype,"onChangeCenter",null),n([l("state.zoom"),m()],s.prototype,"onChangeZoom",null),n([l("state.controls")],s.prototype,"onChangeControls",null),n([l(["state.center","state.zoom","state.controls","state.size","state.type","state.layer"]),u(r=>r.mapInitialized),m()],s.prototype,"onChangeBound",null),n([l("state.size"),m()],s.prototype,"onChangeSize",null),n([l("state.type")],s.prototype,"onChangeMapType",null),n([l("state.layer")],s.prototype,"onChangeLayer",null);export{s as UIMap};