kollapsminoriteten/wp-content/plugins/jetpack/_inc/blocks/map/view.min.js

1 line
16 KiB
JavaScript

!function(){var e={3197:function(e){e.exports=function(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e},e.exports.default=e.exports,e.exports.__esModule=!0},796:function(e,t,o){"use strict";o.r(t);var n=window.wp.domReady,r=o.n(n),a=o(3197),i=o.n(a),s=window.wp.element,l=window.wp.i18n,c=window.lodash,p=window.wp.components;function d(e){const t=e.ownerDocument;return{currentDoc:t,currentWindow:t.defaultView||t.parentWindow}}class m extends s.Component{constructor(...e){super(...e),i()(this,"handleClick",(()=>{const{onClick:e}=this.props;e(this)})),i()(this,"getPoint",(()=>{const{point:e}=this.props;return[e.coordinates.longitude,e.coordinates.latitude]}))}componentDidMount(){this.renderMarker()}componentWillUnmount(){this.marker&&this.marker.remove()}componentDidUpdate(){this.renderMarker()}renderMarker(){const{map:e,point:t,mapboxgl:o,markerColor:n,mapRef:r}=this.props,{handleClick:a}=this,i=[t.coordinates.longitude,t.coordinates.latitude],{currentDoc:s}=d(r.current),l=this.marker?this.marker.getElement():s.createElement("div");this.marker?this.marker.setLngLat(i):(l.className="wp-block-jetpack-map-marker",this.marker=new o.Marker(l).setLngLat(i).setOffset([0,-19]).addTo(e),this.marker.getElement().addEventListener("click",a)),l.innerHTML='<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" viewBox="0 0 32 38" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g fill-rule="evenodd"><path id="d" d="m16 38s16-11.308 16-22-7.1634-16-16-16-16 5.3076-16 16 16 22 16 22z" fill="'+n+'" mask="url(#c)"/></g></svg>'}render(){return null}}m.defaultProps={point:{},map:null,markerColor:"#000000",mapboxgl:null,onClick:()=>{}};var u=m;class h extends s.Component{constructor(...e){super(...e),i()(this,"closeClick",(()=>{this.props.unsetActiveMarker()}))}componentDidMount(){const{mapboxgl:e}=this.props;this.el=document.createElement("DIV"),this.infowindow=new e.Popup({closeButton:!0,closeOnClick:!1,offset:{left:[0,0],top:[0,5],right:[0,0],bottom:[0,-40]}}),this.infowindow.setDOMContent(this.el),this.infowindow.on("close",this.closeClick)}componentDidUpdate(e){this.props.activeMarker!==e.activeMarker&&(this.props.activeMarker?this.openWindow():this.closeWindow())}render(){return this.el?(0,s.createPortal)(this.props.children,this.el):null}openWindow(){const{map:e,activeMarker:t}=this.props;this.infowindow.setLngLat(t.getPoint()).addTo(e)}closeWindow(){this.infowindow.remove()}}h.defaultProps={unsetActiveMarker:()=>{},activeMarker:null,map:null,mapboxgl:null};var g=h;var f=JSON.parse('[{"id":"mapbox-gl-js","file":"node_modules/mapbox-gl/dist/mapbox-gl.js","version":"1.13.0"},{"id":"mapbox-gl-css","file":"node_modules/mapbox-gl/dist/mapbox-gl.css","version":"1.13.0"}]');const __=l.__;class k extends s.Component{constructor(){super(...arguments),i()(this,"onMarkerClick",(e=>{const{onMarkerClick:t}=this.props;this.setState({activeMarker:e}),t()})),i()(this,"onMapClick",(()=>{this.setState({activeMarker:null})})),i()(this,"clearCurrentMarker",(()=>{this.setState({activeMarker:null})})),i()(this,"updateActiveMarker",(e=>{const{points:t}=this.props,{activeMarker:o}=this.state,{index:n}=o.props,r=t.slice(0);(0,c.assign)(r[n],e),this.props.onSetPoints(r)})),i()(this,"deleteActiveMarker",(()=>{const{points:e}=this.props,{activeMarker:t}=this.state,{index:o}=t.props,n=e.slice(0);n.splice(o,1),this.props.onSetPoints(n),this.setState({activeMarker:null})})),i()(this,"sizeMap",(()=>{const{mapHeight:e}=this.props,{map:t}=this.state,o=this.mapRef.current;if(e)o.style.height=e+"px";else{const e=o.offsetWidth,t=window.location.search.indexOf("map-block-counter")>-1?window.innerHeight:.8*window.innerHeight,n=Math.min(e*(3/4),t);o.style.height=n+"px"}t.resize(),this.setBoundsByMarkers()})),i()(this,"updateZoom",(()=>{const{zoom:e}=this.props,{map:t}=this.state;t.setZoom(e),t.updateZoom(e)})),i()(this,"setBoundsByMarkers",(()=>{const{admin:e,onSetMapCenter:t,onSetZoom:o,points:n,zoom:r}=this.props,{map:a,activeMarker:i,mapboxgl:s,zoomControl:l,boundsSetProgrammatically:c}=this.state;if(!a)return;if(n.length&&e?a.dragPan.disable():a.dragPan.enable(),!n.length)return;if(i)return;const p=new s.LngLatBounds;if(n.forEach((e=>{p.extend([e.coordinates.longitude,e.coordinates.latitude])})),t(p.getCenter()),n.length>1){a.fitBounds(p,{padding:{top:80,bottom:80,left:40,right:40}}),this.setState({boundsSetProgrammatically:!0});try{a.removeControl(l)}catch(d){}}else{if(a.setCenter(p.getCenter()),c){const e=12;a.setZoom(e),o(e)}else a.setZoom(parseInt(r,10));a.addControl(l),this.setState({boundsSetProgrammatically:!1})}})),i()(this,"scriptsLoaded",(()=>{const{mapCenter:e,points:t}=this.props;this.setState({loaded:!0}),t.length,this.initMap(e)})),i()(this,"googlePoint2Mapbox",(e=>e.hasOwnProperty("lat")&&e.hasOwnProperty("lng")?e:{lat:e.latitude||0,lng:e.longitude||0})),this.state={map:null,fit_to_bounds:!1,loaded:!1,mapboxgl:null},this.mapRef=(0,s.createRef)(),this.debouncedSizeMap=(0,c.debounce)(this.sizeMap,250)}render(){const{points:e,admin:t,children:o,markerColor:n}=this.props,{map:r,activeMarker:a,mapboxgl:i}=this.state,{onMarkerClick:l,deleteActiveMarker:d,updateActiveMarker:m}=this,h=(0,c.get)(a,"props.point")||{},{title:f,caption:k}=h,b=s.Children.map(o,(e=>{if("AddPoint"===(0,c.get)(e,"props.tagName"))return e})),w=r&&i&&e.map(((e,t)=>(0,s.createElement)(u,{mapRef:this.mapRef,key:t,point:e,index:t,map:r,mapboxgl:i,markerColor:n,onClick:l}))),v=i&&(0,s.createElement)(g,{activeMarker:a,map:r,mapboxgl:i,unsetActiveMarker:()=>this.setState({activeMarker:null})},a&&t&&(0,s.createElement)(s.Fragment,null,(0,s.createElement)(p.TextControl,{label:__("Marker Title","jetpack"),value:f,onChange:e=>m({title:e})}),(0,s.createElement)(p.TextareaControl,{className:"wp-block-jetpack-map__marker-caption",label:__("Marker Caption","jetpack"),value:k,rows:"2",tag:"textarea",onChange:e=>m({caption:e})}),(0,s.createElement)(p.Button,{onClick:d,className:"wp-block-jetpack-map__delete-btn"},(0,s.createElement)(p.Dashicon,{icon:"trash",size:"15"})," ",__("Delete Marker","jetpack"))),a&&!t&&(0,s.createElement)(s.Fragment,null,(0,s.createElement)("h3",null,f),(0,s.createElement)("p",null,k)));return(0,s.createElement)(s.Fragment,null,(0,s.createElement)("div",{className:"wp-block-jetpack-map__gm-container",ref:this.mapRef},w),v,b)}componentDidMount(){const{apiKey:e}=this.props;e&&this.loadMapLibraries()}componentWillUnmount(){this.debouncedSizeMap.cancel(),window.removeEventListener("resize",this.debouncedSizeMap)}componentDidUpdate(e){const{admin:t,apiKey:o,children:n,points:r,mapStyle:a,mapDetails:i,scrollToZoom:s,showFullscreenButton:l}=this.props,{map:c,fullscreenControl:p}=this.state;o&&o.length>0&&o!==e.apiKey&&this.loadMapLibraries(),n!==e.children&&!1!==n&&this.clearCurrentMarker(),r!==e.points&&this.setBoundsByMarkers(),r.length!==e.points.length&&this.clearCurrentMarker(),a===e.mapStyle&&i===e.mapDetails||c.setStyle(this.getMapStyle()),s!==e.scrollToZoom&&(s?c.scrollZoom.enable():c.scrollZoom.disable()),l!==e.showFullscreenButton&&(l?(c.addControl(p),t&&p._fullscreenButton&&(p._fullscreenButton.disabled=!0)):c.removeControl(p))}getMapStyle(){const{mapStyle:e,mapDetails:t}=this.props;return function(e,t){return{default:{details:"mapbox://styles/automattic/cjolkhmez0qdd2ro82dwog1in",no_details:"mapbox://styles/automattic/cjolkci3905d82soef4zlmkdo"},black_and_white:{details:"mapbox://styles/automattic/cjolkixvv0ty42spgt2k4j434",no_details:"mapbox://styles/automattic/cjolkgc540tvj2spgzzoq37k4"},satellite:{details:"mapbox://styles/mapbox/satellite-streets-v10",no_details:"mapbox://styles/mapbox/satellite-v9"},terrain:{details:"mapbox://styles/automattic/cjolkf8p405fh2soet2rdt96b",no_details:"mapbox://styles/automattic/cjolke6fz12ys2rpbpvgl12ha"}}[e][t?"details":"no_details"]}(e,t)}getMapType(){const{mapStyle:e}=this.props;switch(e){case"satellite":return"HYBRID";case"terrain":return"TERRAIN";case"black_and_white":default:return"ROADMAP"}}loadMapLibraries(){const{apiKey:e}=this.props,{currentWindow:t}=d(this.mapRef.current);!function(e,t,o){const n=`${window.Jetpack_Block_Assets_Base_Url.url}editor-assets`,{currentDoc:r}=d(o),a=r.getElementsByTagName("head")[0];e.forEach((e=>{const[o,i]=e.file.split("/").pop().split(".");if("css"===i){if(r.getElementById(e.id))return;const t=r.createElement("link");t.id=e.id,t.rel="stylesheet",t.href=`${n}/${o}-${e.version}.${i}`,a.appendChild(t)}if("js"===i){const s=t[e.id]?t[e.id]:null;if(r.getElementById(e.id))return s();const l=r.createElement("script");l.id=e.id,l.type="text/javascript",l.src=`${n}/${o}-${e.version}.${i}`,l.onload=s,a.appendChild(l)}}))}(f,{"mapbox-gl-js":()=>{(function(e,t){return new Promise((o=>{const n=()=>{e[t]?o(e[t]):e.requestAnimationFrame(n)};n()}))})(t,"mapboxgl").then((t=>{t.accessToken=e,this.setState({mapboxgl:t},this.scriptsLoaded)}))}},this.mapRef.current)}initMap(e){const{mapboxgl:t}=this.state,{zoom:o,onMapLoaded:n,onError:r,scrollToZoom:a,showFullscreenButton:i,admin:s}=this.props;let l=null;try{l=new t.Map({container:this.mapRef.current,style:this.getMapStyle(),center:this.googlePoint2Mapbox(e),zoom:parseInt(o,10),pitchWithRotate:!1,attributionControl:!1,dragRotate:!1})}catch(d){return void r("mapbox_error",d.message)}a||l.scrollZoom.disable();const c=new t.FullscreenControl;l.on("error",(e=>{r("mapbox_error",e.error.message)}));const p=new t.NavigationControl({showCompass:!1,showZoom:!0});l.on("zoomend",(()=>{this.props.onSetZoom(l.getZoom())})),l.on("moveend",(()=>{const{onSetMapCenter:e,points:t}=this.props;t.length<1&&e(l.getCenter())})),l.getCanvas().addEventListener("click",this.onMapClick),this.setState({map:l,zoomControl:p,fullscreenControl:c},(()=>{this.debouncedSizeMap(),l.addControl(p),i&&(l.addControl(c),s&&c._fullscreenButton&&(c._fullscreenButton.disabled=!0)),this.mapRef.current.addEventListener("alignmentChanged",this.debouncedSizeMap),l.resize(),n(),this.setState({loaded:!0}),window.addEventListener("resize",this.debouncedSizeMap)}))}}k.defaultProps={points:[],mapStyle:"default",zoom:13,onSetZoom:()=>{},onSetMapCenter:()=>{},onMapLoaded:()=>{},onMarkerClick:()=>{},onError:()=>{},markerColor:"red",apiKey:null,mapCenter:{}};var b=k,w=o(6932),v=o(5107),y=o(5765),M=o(4140);const x=l.__,_x=l._x,C={name:"map",prefix:"jetpack",title:x("Map","jetpack"),icon:(0,s.createElement)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",role:"img","aria-hidden":"true",focusable:"false"},(0,s.createElement)("path",{fill:"none",d:"M0 0h24v24H0V0z"}),(0,s.createElement)("path",{d:"M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z"})),category:"embed",keywords:[_x("maps","block search term","jetpack"),_x("location","block search term","jetpack"),_x("navigation","block search term","jetpack")],description:x("Add an interactive map showing one or more locations.","jetpack"),attributes:{align:{type:"string"},points:{type:"array",default:[]},mapDetails:{type:"boolean",default:!0},zoom:{type:"integer",default:13},mapCenter:{type:"object",default:{longitude:-122.41941550000001,latitude:37.7749295}},markerColor:{type:"string",default:"red"},preview:{type:"boolean",default:!1},scrollToZoom:{type:"boolean",default:!1},mapHeight:{type:"integer"},showFullscreenButton:{type:"boolean",default:!0}},supports:{defaultStylePicker:!1,html:!1},styles:[{name:"default",label:x("Basic","jetpack"),preview:w,isDefault:!0},{name:"black_and_white",label:x("Black and white","jetpack"),preview:v},{name:"satellite",label:x("Satellite","jetpack"),preview:y},{name:"terrain",label:x("Terrain","jetpack"),preview:M}],validAlignments:["center","wide","full"],markerIcon:(0,s.createElement)("svg",{width:"14",height:"20",viewBox:"0 0 14 20",xmlns:"http://www.w3.org/2000/svg"},(0,s.createElement)("g",{id:"Page-1",fill:"none",fillRule:"evenodd"},(0,s.createElement)("g",{id:"outline-add_location-24px",transform:"translate(-5 -2)"},(0,s.createElement)("polygon",{id:"Shape",points:"0 0 24 0 24 24 0 24"}),(0,s.createElement)("path",{d:"M12,2 C8.14,2 5,5.14 5,9 C5,14.25 12,22 12,22 C12,22 19,14.25 19,9 C19,5.14 15.86,2 12,2 Z M7,9 C7,6.24 9.24,4 12,4 C14.76,4 17,6.24 17,9 C17,11.88 14.12,16.19 12,18.88 C9.92,16.21 7,11.85 7,9 Z M13,6 L11,6 L11,8 L9,8 L9,10 L11,10 L11,12 L13,12 L13,10 L15,10 L15,8 L13,8 L13,6 Z",id:"Shape",fill:"#000",fillRule:"nonzero"})))),example:{attributes:{preview:!0}}};var _=class{blockIterator(e,t){t.forEach((t=>{this.initializeFrontendReactBlocks(t.component,t.options,e)}))}initializeFrontendReactBlocks(e,t={},o){const{attributes:n,name:r,prefix:a}=t.settings,{selector:i}=t,l=`.wp-block-${(a&&a.length?`${a}/${r}`:r).replace("/","-")}`,p=o.querySelectorAll(l);for(const d of p){if("true"===d.getAttribute("data-jetpack-block-initialized"))continue;const o=this.extractAttributesFromContainer(d,n);(0,c.assign)(o,t.props);const r=this.extractChildrenFromContainer(d),a=(0,s.createElement)(e,o,r);(0,s.render)(a,i?d.querySelector(i):d),d.setAttribute("data-jetpack-block-initialized",!0)}}extractAttributesFromContainer(e,t){const o={};for(const r in t){const a=t[r],i="data-"+(0,c.kebabCase)(r);if(o[r]=e.getAttribute(i),"boolean"===a.type&&(o[r]="false"!==o[r]&&!!o[r]),"array"===a.type||"object"===a.type)try{o[r]=JSON.parse(o[r])}catch(n){o[r]=null}}return o}extractChildrenFromContainer(e){return[...e.childNodes].map((e=>{const t={};for(let o=0;o<e.attributes.length;o++){const n=e.attributes[o];t[n.nodeName]=n.nodeValue}return t.dangerouslySetInnerHTML={__html:e.innerHTML},(0,s.createElement)(e.tagName.toLowerCase(),t)}))}},S=window.wp.tokenList,j=o.n(S);function E(e,t){const o=function(e,t){for(const o of new(j())(t).values()){if(-1===o.indexOf("is-style-"))continue;const t=o.substring(9),n=(0,c.find)(e,{name:t});if(n)return n}return(0,c.find)(e,"isDefault")}(e,t);return o?o.name:null}r()((function(){(new _).blockIterator(document,[{component:b,options:{settings:{...C,attributes:{...C.attributes,mapStyle:E(C.styles,C.className),apiKey:{type:"string",default:""}}}}}])}))},5630:function(e,t,o){"object"==typeof window&&window.Jetpack_Block_Assets_Base_Url&&window.Jetpack_Block_Assets_Base_Url.url&&(o.p=window.Jetpack_Block_Assets_Base_Url.url)},9326:function(e,t,o){"use strict";o(5630)},5107:function(e,t,o){"use strict";e.exports=o.p+"images/map-theme_black_and_white-b6ad81a7dd09d09fb34d.jpg"},6932:function(e,t,o){"use strict";e.exports=o.p+"images/map-theme_default-b53ccdf170e5ac873ff0.jpg"},5765:function(e,t,o){"use strict";e.exports=o.p+"images/map-theme_satellite-cc50c608e244f90d18dc.jpg"},4140:function(e,t,o){"use strict";e.exports=o.p+"images/map-theme_terrain-ac291441b3461820747d.jpg"}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,o),a.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},function(){var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e+"../"}(),o(9326);var n=o(796),r=window;for(var a in n)r[a]=n[a];n.__esModule&&Object.defineProperty(r,"__esModule",{value:!0})}();