google-maps-react-markers 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4,7 +4,7 @@ var react = require('react');
4
4
  var reactDom = require('react-dom');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
 
7
- var S={};function Y(e){let r=document.querySelector(`script[src="${e}"]`),a=r==null?void 0:r.getAttribute("data-status");return {node:r,status:a}}function W(e={src:"",attributes:{},callbacks:{onLoadCallback:()=>{},onErrorCallback:()=>{}},elementIdToAppend:""},r,a={removeOnUnmount:!1,shouldPreventLoad:!1}){let[l,s]=react.useState(()=>!e.src||a!=null&&a.shouldPreventLoad?"idle":typeof window>"u"?"loading":S[e.src]??"loading");return react.useEffect(()=>{var u,n,m;if(r){s(r);return}if(!(e!=null&&e.src)||a!=null&&a.shouldPreventLoad)return;let i=S[e.src];if(i==="ready"||i==="error"){s(i);return}let c=Y(e.src),t=c.node;if(t){let p=c.status??i??"loading";switch(p){case"loading":case"ready":(n=e.callbacks)!=null&&n.onLoadCallback&&e.callbacks.onLoadCallback();break;case"error":(m=e.callbacks)!=null&&m.onErrorCallback&&e.callbacks.onErrorCallback();break;}s(p);}else {t=document.createElement("script"),t.src=e.src,t.async=!0,t.setAttribute("data-status","loading"),e.attributes&&Object.entries(e.attributes).length>0&&Object.entries(e.attributes).map(([g,d])=>t==null?void 0:t.setAttribute(g,d)),e.elementIdToAppend&&document.getElementById(e.elementIdToAppend)?(u=document.getElementById(e.elementIdToAppend))==null||u.appendChild(t):document.body.appendChild(t);let p=g=>{let d=g.type==="load"?"ready":"error";t==null||t.setAttribute("data-status",d);};t.addEventListener("load",p),t.addEventListener("error",p);}let o=p=>{var d,f;let g=p.type==="load"?"ready":"error";p.type==="load"?(d=e.callbacks)!=null&&d.onLoadCallback&&e.callbacks.onLoadCallback():(f=e.callbacks)!=null&&f.onErrorCallback&&e.callbacks.onErrorCallback(),s(g),S[e.src]=g;};return t.addEventListener("load",o),t.addEventListener("error",o),()=>{t&&(t.removeEventListener("load",o),t.removeEventListener("error",o)),t&&(a!=null&&a.removeOnUnmount)&&t.remove();}},[e,r,l]),l}var O=W;var T=({apiKey:e,libraries:r=[],loadScriptExternally:a=!1,status:l="idle",externalApiParams:s,callback:i})=>{var o;typeof window<"u"&&(window.googleMapsCallback=i);let c=(o=new URLSearchParams(s))==null?void 0:o.toString(),t=e?{src:`https://maps.googleapis.com/maps/api/js?key=${e}&callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}${c?`&${c}`:""}`,attributes:{id:"googleMapsApi"}}:{src:`https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}`,attributes:{id:"googleMapsApi"}};return O(t,a?l:void 0)};var H=(e,r,a=1e-6)=>{if(e&&r){for(let l=0;l!==e.length;++l)if(Math.abs(e[l]-r[l])>a)return !1;return !0}return !1};var _=(e,r)=>{let a=react.useRef(),l=a.current,s=r(l,e);return react.useEffect(()=>{s||(a.current=e);}),s?l:e},x=_;var k=e=>{try{return {lat:e==null?void 0:e.lat(),lng:e==null?void 0:e.lng()}}catch{return e}},K=({container:e,pane:r,position:a,maps:l,drag:s})=>{class i extends google.maps.OverlayView{onAdd=()=>{var u;let t=this;s!=null&&s.draggable&&(this.get("map").getDiv().addEventListener("mouseleave",()=>{google.maps.event.trigger(this.container,"mouseup");}),this.container.addEventListener("mousedown",n=>{var m;this.container.style.cursor="grabbing",(m=t.map)==null||m.set("draggable",!1),t.set("origin",n),s.onDragStart(n,{latLng:k(this.position)}),t.moveHandler=this.get("map").getDiv().addEventListener("mousemove",p=>{let g=t.get("origin"),d=g.clientX-p.clientX,f=g.clientY-p.clientY,b=t.getProjection().fromLatLngToDivPixel(t.position);if(b===null)return;let v=t.getProjection().fromDivPixelToLatLng(new l.Point(b.x-d,b.y-f));t.set("position",v),t.set("origin",p),t.draw(),s.onDrag(p,{latLng:k(v)});});}),this.container.addEventListener("mouseup",n=>{var m;(m=t.map)==null||m.set("draggable",!0),this.container.style.cursor="default",t.moveHandler&&(google.maps.event.removeListener(t.moveHandler),t.moveHandler=null),s.onDragEnd(n,{latLng:k(t.position)});}));let o=(u=this.getPanes())==null?void 0:u[this.pane];o==null||o.classList.add("google-map-markers-overlay"),o==null||o.appendChild(this.container);};draw=()=>{let o=this.getProjection().fromLatLngToDivPixel(this.position);o!==null&&(this.container.style.transform=`translate(${o.x}px, ${o.y}px)`,this.container.style.width="0px",this.container.style.height="0px");};onRemove=()=>{this.container.parentNode!==null&&(google.maps.event.clearInstanceListeners(this.container),this.container.parentNode.removeChild(this.container));};container;pane;position;map=this.getMap();moveHandler;constructor(t,o,u){super(),this.container=t,this.pane=o,this.position=u,this.moveHandler=null;}}return new i(e,r,a)},U=K;var ee=({pane:e="floatPane",position:r,map:a,maps:l,zIndex:s=0,children:i,drag:c})=>{let t=react.useMemo(()=>{let n=document.createElement("div");return n.style.position="absolute",n},[]),o=react.useMemo(()=>U({container:t,pane:e,position:r,maps:l,drag:c}),[t,c,l,e,r]),u=x(i==null?void 0:i.props,(n,m)=>n&&n.lat===m.lat&&n.lng===m.lng);return react.useEffect(()=>!o.map&&a?(o==null||o.setMap(a),()=>{o==null||o.setMap(null);}):()=>{},[a,u]),react.useEffect(()=>{t.style.zIndex=`${s}`;},[s,t]),reactDom.createPortal(i,t)},G=ee;var P=()=>{},ae=({children:e,map:r,maps:a})=>{let l=react.useMemo(()=>!r||!a?[]:react.Children.map(e,s=>{if(react.isValidElement(s)){let i={lat:s.props.lat,lng:s.props.lng},{zIndex:c,draggable:t=!1,onDragStart:o=P,onDrag:u=P,onDragEnd:n=P}=s.props||{};return s=react.cloneElement(s,{...s.props,draggable:void 0,onDragStart:void 0,onDrag:void 0,onDragEnd:void 0}),jsxRuntime.jsx(G,{position:new a.LatLng(i.lat,i.lng),map:r,maps:a,zIndex:c,drag:{draggable:t,onDragStart:o,onDrag:u,onDragEnd:n},children:s})}return null}),[e,r,a]);return jsxRuntime.jsx("div",{children:l})},R=ae;function le({children:e=null,style:r={width:"100%",height:"100%",left:0,top:0,margin:0,padding:0,position:"absolute"},defaultCenter:a,defaultZoom:l,onGoogleApiLoaded:s,onChange:i,options:c={},events:t=[]}){let o=react.useRef(null),u=react.useRef(),[n,m]=react.useState(),[p,g]=react.useState(),[d,f]=react.useState(!1),b=react.useCallback(()=>{var v,y;try{if(!n)return;let E=n.getZoom()??l,M=n.getBounds(),F=[(v=n.getCenter())==null?void 0:v.lng(),(y=n.getCenter())==null?void 0:y.lat()],L=M==null?void 0:M.getNorthEast(),h=M==null?void 0:M.getSouthWest();if(!L||!h||!M)return;let D=[h.lng(),h.lat(),L.lng(),L.lat()];H(D,u.current)||(i&&i({zoom:E,center:F,bounds:M}),u.current=D);}catch(E){console.error(E);}},[n,i]);return react.useEffect(()=>{o.current&&!n&&(m(new google.maps.Map(o.current,{center:a,zoom:l,...c})),g(google.maps));},[a,l,n,o,c]),react.useEffect(()=>{n&&(d||(s&&p&&s({map:n,maps:p,ref:o.current}),f(!0)),google.maps.event.clearListeners(n,"idle"),google.maps.event.addListener(n,"idle",b));},[d,n,p,i,s,b]),react.useEffect(()=>()=>{n&&google.maps.event.clearListeners(n,"idle");},[n]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{ref:o,style:r,className:"google-map",...t==null?void 0:t.reduce((v,{name:y,handler:E})=>(v[y]=E,v),{})}),e&&n&&p&&jsxRuntime.jsx(R,{map:n,maps:p,children:e})]})}var q=le;var ue=react.forwardRef(({apiKey:e="",libraries:r=["places","geometry"],children:a=null,loadingContent:l="Google Maps is loading",idleContent:s="Google Maps is on idle",errorContent:i="Google Maps is on error",mapMinHeight:c="unset",containerProps:t={},loadScriptExternally:o=!1,status:u="idle",scriptCallback:n=()=>{},externalApiParams:m={},...p},g)=>{let d={ready:jsxRuntime.jsx(q,{...p,children:a}),loading:l,idle:s,error:i},f=T({apiKey:e,libraries:r,loadScriptExternally:o,status:u,externalApiParams:m,callback:n});return jsxRuntime.jsx("div",{ref:g,style:{height:"100%",width:"100%",overflow:"hidden",position:"relative",minHeight:c},...t,children:d[f]||null})}),B=ue;var Ve=B;
7
+ var S={};function Y(e){let r=document.querySelector(`script[src="${e}"]`),a=r==null?void 0:r.getAttribute("data-status");return {node:r,status:a}}function W(e={src:"",attributes:{},callbacks:{onLoadCallback:()=>{},onErrorCallback:()=>{}},elementIdToAppend:""},r,a={removeOnUnmount:!1,shouldPreventLoad:!1}){let[l,s]=react.useState(()=>!e.src||a!=null&&a.shouldPreventLoad?"idle":typeof window>"u"?"loading":S[e.src]??"loading");return react.useEffect(()=>{var u,n,m;if(r){s(r);return}if(!(e!=null&&e.src)||a!=null&&a.shouldPreventLoad)return;let i=S[e.src];if(i==="ready"||i==="error"){s(i);return}let c=Y(e.src),t=c.node;if(t){let p=c.status??i??"loading";switch(p){case"loading":case"ready":(n=e.callbacks)!=null&&n.onLoadCallback&&e.callbacks.onLoadCallback();break;case"error":(m=e.callbacks)!=null&&m.onErrorCallback&&e.callbacks.onErrorCallback();break;}s(p);}else {t=document.createElement("script"),t.src=e.src,t.async=!0,t.setAttribute("data-status","loading"),e.attributes&&Object.entries(e.attributes).length>0&&Object.entries(e.attributes).map(([g,d])=>t==null?void 0:t.setAttribute(g,d)),e.elementIdToAppend&&document.getElementById(e.elementIdToAppend)?(u=document.getElementById(e.elementIdToAppend))==null||u.appendChild(t):document.body.appendChild(t);let p=g=>{let d=g.type==="load"?"ready":"error";t==null||t.setAttribute("data-status",d);};t.addEventListener("load",p),t.addEventListener("error",p);}let o=p=>{var d,f;let g=p.type==="load"?"ready":"error";p.type==="load"?(d=e.callbacks)!=null&&d.onLoadCallback&&e.callbacks.onLoadCallback():(f=e.callbacks)!=null&&f.onErrorCallback&&e.callbacks.onErrorCallback(),s(g),S[e.src]=g;};return t.addEventListener("load",o),t.addEventListener("error",o),()=>{t&&(t.removeEventListener("load",o),t.removeEventListener("error",o)),t&&(a!=null&&a.removeOnUnmount)&&t.remove();}},[e,r,l]),l}var O=W;var T=({apiKey:e,libraries:r=[],loadScriptExternally:a=!1,status:l="idle",externalApiParams:s,callback:i})=>{var o;typeof window<"u"&&(window.googleMapsCallback=i);let c=(o=new URLSearchParams(s))==null?void 0:o.toString(),t=e?{src:`https://maps.googleapis.com/maps/api/js?key=${e}&callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}${c?`&${c}`:""}`,attributes:{id:"googleMapsApi"}}:{src:`https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}`,attributes:{id:"googleMapsApi"}};return O(t,a?l:void 0)};var x=(e,r,a=1e-6)=>{if(e&&r){for(let l=0;l!==e.length;++l)if(Math.abs(e[l]-r[l])>a)return !1;return !0}return !1};var _=(e,r)=>{let a=react.useRef(),l=a.current,s=r(l,e);return react.useEffect(()=>{s||(a.current=e);}),s?l:e},H=_;var k=e=>{try{return {lat:e==null?void 0:e.lat(),lng:e==null?void 0:e.lng()}}catch{return e}},K=({container:e,pane:r,position:a,maps:l,drag:s})=>{class i extends google.maps.OverlayView{onAdd=()=>{var u;let t=this;s!=null&&s.draggable&&(this.get("map").getDiv().addEventListener("mouseleave",()=>{google.maps.event.trigger(this.container,"mouseup");}),this.container.addEventListener("mousedown",n=>{var m;this.container.style.cursor="grabbing",(m=t.map)==null||m.set("draggable",!1),t.set("origin",n),s.onDragStart(n,{latLng:k(this.position)}),t.moveHandler=this.get("map").getDiv().addEventListener("mousemove",p=>{let g=t.get("origin"),d=g.clientX-p.clientX,f=g.clientY-p.clientY,b=t.getProjection().fromLatLngToDivPixel(t.position);if(b===null)return;let v=t.getProjection().fromDivPixelToLatLng(new l.Point(b.x-d,b.y-f));t.set("position",v),t.set("origin",p),t.draw(),s.onDrag(p,{latLng:k(v)});});}),this.container.addEventListener("mouseup",n=>{var m;(m=t.map)==null||m.set("draggable",!0),this.container.style.cursor="default",t.moveHandler&&(google.maps.event.removeListener(t.moveHandler),t.moveHandler=null),s.onDragEnd(n,{latLng:k(t.position)});}));let o=(u=this.getPanes())==null?void 0:u[this.pane];o==null||o.classList.add("google-map-markers-overlay"),o==null||o.appendChild(this.container);};draw=()=>{let o=this.getProjection().fromLatLngToDivPixel(this.position);o!==null&&(this.container.style.transform=`translate(${o.x}px, ${o.y}px)`,this.container.style.width="0px",this.container.style.height="0px");};onRemove=()=>{this.container.parentNode!==null&&(google.maps.event.clearInstanceListeners(this.container),this.container.parentNode.removeChild(this.container));};container;pane;position;map=this.getMap();moveHandler;constructor(t,o,u){super(),this.container=t,this.pane=o,this.position=u,this.moveHandler=null;}}return new i(e,r,a)},U=K;var ee=({pane:e="floatPane",position:r,map:a,maps:l,zIndex:s=0,children:i,drag:c})=>{let t=react.useMemo(()=>{let n=document.createElement("div");return n.style.position="absolute",n},[]),o=react.useMemo(()=>U({container:t,pane:e,position:r,maps:l,drag:c}),[t,c,l,e,r]),u=H(i==null?void 0:i.props,(n,m)=>n&&n.lat===m.lat&&n.lng===m.lng);return react.useEffect(()=>!o.map&&a?(o==null||o.setMap(a),()=>{o==null||o.setMap(null);}):()=>{},[a,u]),react.useEffect(()=>{t.style.zIndex=`${s}`;},[s,t]),reactDom.createPortal(i,t)},G=ee;var P=()=>{},ae=({children:e,map:r,maps:a})=>{let l=react.useMemo(()=>!r||!a?[]:react.Children.map(e,s=>{if(react.isValidElement(s)){let i={lat:s.props.lat,lng:s.props.lng},{zIndex:c,draggable:t=!1,onDragStart:o=P,onDrag:u=P,onDragEnd:n=P}=s.props||{};return s=react.cloneElement(s,{...s.props,draggable:void 0,onDragStart:void 0,onDrag:void 0,onDragEnd:void 0}),jsxRuntime.jsx(G,{position:new a.LatLng(i.lat,i.lng),map:r,maps:a,zIndex:c,drag:{draggable:t,onDragStart:o,onDrag:u,onDragEnd:n},children:s})}return null}),[e,r,a]);return jsxRuntime.jsx("div",{children:l})},R=ae;function le({children:e=null,style:r={width:"100%",height:"100%",left:0,top:0,margin:0,padding:0,position:"absolute"},defaultCenter:a,defaultZoom:l,onGoogleApiLoaded:s,onChange:i,options:c={},events:t=[]}){let o=react.useRef(null),u=react.useRef(),[n,m]=react.useState(),[p,g]=react.useState(),[d,f]=react.useState(!1),b=react.useCallback(()=>{var v,y;try{if(!n)return;let E=n.getZoom()??l,M=n.getBounds(),F=[(v=n.getCenter())==null?void 0:v.lng(),(y=n.getCenter())==null?void 0:y.lat()],L=M==null?void 0:M.getNorthEast(),h=M==null?void 0:M.getSouthWest();if(!L||!h||!M)return;let D=[h.lng(),h.lat(),L.lng(),L.lat()];x(D,u.current)||(i&&i({zoom:E,center:F,bounds:M}),u.current=D);}catch(E){console.error(E);}},[n,i]);return react.useEffect(()=>{o.current&&!n&&(m(new google.maps.Map(o.current,{center:a,zoom:l,...c})),g(google.maps));},[a,l,n,o,c]),react.useEffect(()=>{n&&(d||(s&&p&&s({map:n,maps:p,ref:o.current}),f(!0)),google.maps.event.clearListeners(n,"idle"),google.maps.event.addListener(n,"idle",b));},[d,n,p,i,s,b]),react.useEffect(()=>()=>{n&&google.maps.event.clearListeners(n,"idle");},[n]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{ref:o,style:r,className:"google-map",...t==null?void 0:t.reduce((v,{name:y,handler:E})=>(v[y]=E,v),{})}),e&&n&&p&&jsxRuntime.jsx(R,{map:n,maps:p,children:e})]})}var q=le;var ue=react.forwardRef(({apiKey:e="",libraries:r=["places","geometry"],children:a=null,loadingContent:l="Google Maps is loading",idleContent:s="Google Maps is on idle",errorContent:i="Google Maps is on error",mapMinHeight:c="unset",containerProps:t={},loadScriptExternally:o=!1,status:u="idle",scriptCallback:n=()=>{},externalApiParams:m={},...p},g)=>{let d={ready:jsxRuntime.jsx(q,{...p,children:a}),loading:l,idle:s,error:i},f=T({apiKey:e,libraries:r,loadScriptExternally:o,status:u,externalApiParams:m,callback:n});return jsxRuntime.jsx("div",{ref:g,style:{height:"100%",width:"100%",overflow:"hidden",position:"relative",minHeight:c},...t,children:d[f]||null})}),B=ue;var Ve=B;
8
8
 
9
9
  module.exports = Ve;
10
10
  //# sourceMappingURL=out.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/google-map.tsx","../src/map/hooks/useScript.ts","../src/map/hooks/useGoogleMaps.ts","../src/map/map.tsx","../src/utils/utils.ts","../src/map/markers.tsx","../src/map/overlay-view.tsx","../src/map/hooks/useMemoCompare.ts","../src/map/overlay.tsx","../src/index.ts"],"names":["forwardRef","useEffect","useState","cachedScriptStatuses","getScriptNode","src","node","status","useScript","script","forcedStatus","options","setStatus","_a","_b","_c","cachedScriptStatus","scriptToAdd","scriptNode","currentScriptStatus","key","value","setAttributeFromEvent","event","scriptStatus","setStateFromEvent","newStatus","useScript_default","useGoogleMaps","apiKey","libraries","loadScriptExternally","externalApiParams","callback","apiParams","useCallback","useRef","isArraysEqualEps","arrayA","arrayB","eps","i","Children","cloneElement","isValidElement","useMemo","createPortal","useMemoCompare","next","compare","previousRef","previous","isEqual","useMemoCompare_default","getLatLng","LatLng","createOverlay","container","pane","position","maps","drag","Overlay","that","e","evt","origin","left","top","pos","latLng","currentPane","point","overlay_default","OverlayView","map","zIndex","children","div","overlay","childrenProps","prev","overlay_view_default","jsx","noop","MapMarkers","markers","child","draggable","onDragStart","onDrag","onDragEnd","markers_default","Fragment","jsxs","MapComponent","style","defaultCenter","defaultZoom","onGoogleApiLoaded","onChange","events","mapRef","prevBoundsRef","setMap","setMaps","googleApiCalled","setGoogleApiCalled","onIdle","zoom","bounds","centerLatLng","ne","sw","boundsArray","acc","name","handler","map_default","GoogleMap","loadingContent","idleContent","errorContent","mapMinHeight","containerProps","statusProp","scriptCallback","props","ref","renderers","google_map_default","src_default"],"mappings":"AAAA,OAAS,cAAAA,OAAkB,QCC3B,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QAIpC,IAAMC,EAAoE,CAAC,EAE3E,SAASC,EAAcC,EAAa,CACnC,IAAMC,EAAiC,SAAS,cAAc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oogleMaps } from './map/hooks/useGoogleMaps'\nimport MapComponent from './map/map'\nimport { GoogleMapProps } from './utils/types'\n\nconst GoogleMap = forwardRef<HTMLDivElement, GoogleMapProps>(\n\t(\n\t\t{\n\t\t\tapiKey = '',\n\t\t\tlibraries = ['places', 'geometry'],\n\t\t\tchildren = null,\n\t\t\tloadingContent = 'Google Maps is loading',\n\t\t\tidleContent = 'Google Maps is on idle',\n\t\t\terrorContent = 'Google Maps is on error',\n\t\t\tmapMinHeight = 'unset',\n\t\t\tcontainerProps = {},\n\t\t\tloadScriptExternally = false,\n\t\t\tstatus: statusProp = 'idle',\n\t\t\tscriptCallback = () => {},\n\t\t\texternalApiParams = {},\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst renderers = {\n\t\t\tready: <MapComponent {...props}>{children}</MapComponent>,\n\t\t\tloading: loadingContent,\n\t\t\tidle: idleContent,\n\t\t\terror: errorContent,\n\t\t}\n\n\t\tconst status = useGoogleMaps({\n\t\t\tapiKey,\n\t\t\tlibraries,\n\t\t\tloadScriptExternally,\n\t\t\tstatus: statusProp,\n\t\t\texternalApiParams,\n\t\t\tcallback: scriptCallback,\n\t\t})\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tstyle={{ height: '100%', width: '100%', overflow: 'hidden', position: 'relative', minHeight: mapMinHeight }}\n\t\t\t\t{...containerProps}\n\t\t\t>\n\t\t\t\t{renderers[status] || null}\n\t\t\t</div>\n\t\t)\n\t},\n)\n\nexport default GoogleMap\n","/* eslint-disable no-unused-expressions */\nimport { useEffect, useState } from 'react'\nimport { ScriptProps, UseScriptOptions, UseScriptStatus } from '../../utils/types'\n\n// Cached script statuses\nconst cachedScriptStatuses: Record<string, UseScriptStatus | undefined> = {}\n\nfunction getScriptNode(src: string) {\n\tconst node: HTMLScriptElement | null = document.querySelector(`script[src=\"${src}\"]`)\n\tconst status = node?.getAttribute('data-status') as UseScriptStatus | undefined\n\n\treturn {\n\t\tnode,\n\t\tstatus,\n\t}\n}\n\n/**\n * @description Hook to load external script.\n * @param {Object} script - Script to load.\n * @param {string} script.src - Script source.\n * @param {Object} [script.attributes] - Attributes to add to the script tag.\n * @param {Object} [script.callbacks] - Callbacks executed on completion.\n * @param {Function} [script.callbacks.onLoadCallback] - Callback executed on completion in case of success.\n * @param {Function} [script.callbacks.onErrorCallback] - Callbacks executed on completion in case of error.\n * @param {string} [script.elementIdToAppend] - HTML element id to append the script to. Default is HTML HEAD.\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n *\n * @example\n * const status = useScript({\n * \t\tsrc: \"https://script-to-load.js\",\n * \t\tattributes: { id: \"scriptId\", class: \"script-class\" },\n * \t\tcallbacks: {\n * \t\t\tonLoadCallback: onLoadFunc,\n * \t\t\tonErrorCallback: onErrorFunc,\n * \t\t},\n * \t\telementIdToAppend: \"script-container\"\n * }, undefined, { removeOnUnmount: true, shouldPreventLoad: false })\n */\n\nfunction useScript(\n\t// eslint-disable-next-line default-param-last\n\tscript: ScriptProps = {\n\t\tsrc: '',\n\t\tattributes: {},\n\t\tcallbacks: { onLoadCallback: () => {}, onErrorCallback: () => {} },\n\t\telementIdToAppend: '',\n\t},\n\tforcedStatus?: UseScriptStatus,\n\toptions: UseScriptOptions = { removeOnUnmount: false, shouldPreventLoad: false },\n): 'idle' | 'loading' | 'ready' | 'error' {\n\tconst [status, setStatus] = useState<UseScriptStatus>(() => {\n\t\tif (!script.src || options?.shouldPreventLoad) {\n\t\t\treturn 'idle'\n\t\t}\n\n\t\tif (typeof window === 'undefined') {\n\t\t\t// SSR Handling - always return 'loading'\n\t\t\treturn 'loading'\n\t\t}\n\n\t\treturn cachedScriptStatuses[script.src] ?? 'loading'\n\t})\n\n\tuseEffect(\n\t\t() => {\n\t\t\tif (forcedStatus) {\n\t\t\t\tsetStatus(forcedStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (!script?.src || options?.shouldPreventLoad) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst cachedScriptStatus = cachedScriptStatuses[script.src]\n\t\t\tif (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {\n\t\t\t\t// If the script is already cached, set its status immediately\n\t\t\t\tsetStatus(cachedScriptStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Fetch existing script element by src\n\t\t\t// It may have been added by another instance of this hook\n\t\t\tconst scriptToAdd = getScriptNode(script.src)\n\t\t\tlet scriptNode = scriptToAdd.node\n\n\t\t\tif (!scriptNode) {\n\t\t\t\t// Create script element and add it to document body\n\t\t\t\tscriptNode = document.createElement('script')\n\t\t\t\tscriptNode.src = script.src\n\t\t\t\tscriptNode.async = true\n\t\t\t\tscriptNode.setAttribute('data-status', 'loading')\n\t\t\t\t// Add other script attributes, if they exist\n\t\t\t\tscript.attributes && Object.entries(script.attributes).length > 0\n\t\t\t\t\t? Object.entries(script.attributes).map(([key, value]) => scriptNode?.setAttribute(key, value))\n\t\t\t\t\t: null\n\t\t\t\tif (script.elementIdToAppend && document.getElementById(script.elementIdToAppend)) {\n\t\t\t\t\tdocument.getElementById(script.elementIdToAppend)?.appendChild(scriptNode)\n\t\t\t\t} else {\n\t\t\t\t\tdocument.body.appendChild(scriptNode)\n\t\t\t\t}\n\n\t\t\t\t// Store status in attribute on script\n\t\t\t\t// This can be read by other instances of this hook\n\t\t\t\tconst setAttributeFromEvent = (event: Event) => {\n\t\t\t\t\tconst scriptStatus: UseScriptStatus = event.type === 'load' ? 'ready' : 'error'\n\n\t\t\t\t\tscriptNode?.setAttribute('data-status', scriptStatus)\n\t\t\t\t}\n\n\t\t\t\tscriptNode.addEventListener('load', setAttributeFromEvent)\n\t\t\t\tscriptNode.addEventListener('error', setAttributeFromEvent)\n\t\t\t} else {\n\t\t\t\t// Grab existing script status from attribute and set to state.\n\t\t\t\tconst currentScriptStatus = scriptToAdd.status ?? cachedScriptStatus ?? 'loading'\n\n\t\t\t\tswitch (currentScriptStatus) {\n\t\t\t\t\tcase 'loading':\n\t\t\t\t\tcase 'ready':\n\t\t\t\t\t\tscript.callbacks?.onLoadCallback ? script.callbacks.onLoadCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\tscript.callbacks?.onErrorCallback ? script.callbacks.onErrorCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// loading: do nothing\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tsetStatus(currentScriptStatus)\n\t\t\t}\n\n\t\t\t// Script event handler to update status in state\n\t\t\t// Note: Even if the script already exists we still need to add\n\t\t\t// event handlers to update the state for this hook instance.\n\t\t\tconst setStateFromEvent = (event: Event) => {\n\t\t\t\tconst newStatus = event.type === 'load' ? 'ready' : 'error'\n\t\t\t\tevent.type === 'load'\n\t\t\t\t\t? script.callbacks?.onLoadCallback\n\t\t\t\t\t\t? script.callbacks.onLoadCallback()\n\t\t\t\t\t\t: null\n\t\t\t\t\t: script.callbacks?.onErrorCallback\n\t\t\t\t\t? script.callbacks.onErrorCallback()\n\t\t\t\t\t: null\n\n\t\t\t\tsetStatus(newStatus)\n\t\t\t\tcachedScriptStatuses[script.src] = newStatus\n\t\t\t}\n\t\t\t// Add event listeners\n\t\t\tscriptNode.addEventListener('load', setStateFromEvent)\n\t\t\tscriptNode.addEventListener('error', setStateFromEvent)\n\t\t\t// Remove event listeners on cleanup\n\t\t\t// eslint-disable-next-line consistent-return\n\t\t\treturn () => {\n\t\t\t\tif (scriptNode) {\n\t\t\t\t\tscriptNode.removeEventListener('load', setStateFromEvent)\n\t\t\t\t\tscriptNode.removeEventListener('error', setStateFromEvent)\n\t\t\t\t}\n\n\t\t\t\tif (scriptNode && options?.removeOnUnmount) {\n\t\t\t\t\tscriptNode.remove()\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Re-run useEffect if script changes\n\t\t[script, forcedStatus, status],\n\t)\n\n\treturn status\n}\n\nexport default useScript\n","import { IUseGoogleMaps, UseScriptStatus } from '../../utils/types'\nimport useScript from './useScript'\n\n/**\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n */\nexport const useGoogleMaps = ({\n\tapiKey,\n\tlibraries = [],\n\tloadScriptExternally = false,\n\tstatus = 'idle',\n\texternalApiParams,\n\tcallback,\n}: IUseGoogleMaps): UseScriptStatus => {\n\tif (typeof window !== 'undefined') window.googleMapsCallback = callback\n\tconst apiParams = new URLSearchParams(externalApiParams)?.toString()\n\tconst script = apiKey\n\t\t? {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=googleMapsCallback&libraries=${libraries?.join(\n\t\t\t\t\t',',\n\t\t\t\t)}${apiParams ? `&${apiParams}` : ''}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\t\t: {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${libraries?.join(',')}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\n\treturn useScript(script, loadScriptExternally ? status : undefined)\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport { EventProps, Map, MapProps, MapsLibrary } from '../utils/types'\nimport { isArraysEqualEps } from '../utils/utils'\nimport MapMarkers from './markers'\n\nfunction MapComponent({\n\tchildren = null,\n\tstyle = {\n\t\twidth: '100%',\n\t\theight: '100%',\n\t\tleft: 0,\n\t\ttop: 0,\n\t\tmargin: 0,\n\t\tpadding: 0,\n\t\tposition: 'absolute',\n\t},\n\tdefaultCenter,\n\tdefaultZoom,\n\tonGoogleApiLoaded,\n\tonChange,\n\toptions = {},\n\tevents = [],\n}: MapProps) {\n\tconst mapRef = useRef<HTMLDivElement>(null)\n\tconst prevBoundsRef = useRef<number[] | undefined>()\n\tconst [map, setMap] = useState<Map>()\n\tconst [maps, setMaps] = useState<MapsLibrary>()\n\tconst [googleApiCalled, setGoogleApiCalled] = useState<boolean>(false)\n\n\tconst onIdle = useCallback(() => {\n\t\ttry {\n\t\t\tif (!map) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst zoom = map.getZoom() ?? defaultZoom\n\t\t\tconst bounds = map.getBounds()\n\t\t\tconst centerLatLng = [map.getCenter()?.lng(), map.getCenter()?.lat()]\n\n\t\t\tconst ne = bounds?.getNorthEast()\n\t\t\tconst sw = bounds?.getSouthWest()\n\n\t\t\tif (!ne || !sw || !bounds) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// east, north, south, west\n\t\t\tconst boundsArray = [sw.lng(), sw.lat(), ne.lng(), ne.lat()]\n\n\t\t\tif (!isArraysEqualEps(boundsArray, prevBoundsRef.current)) {\n\t\t\t\tif (onChange) {\n\t\t\t\t\tonChange({\n\t\t\t\t\t\tzoom,\n\t\t\t\t\t\tcenter: centerLatLng,\n\t\t\t\t\t\tbounds,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tprevBoundsRef.current = boundsArray\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(e)\n\t\t}\n\t}, [map, onChange])\n\n\tuseEffect(() => {\n\t\tif (mapRef.current && !map) {\n\t\t\tsetMap(\n\t\t\t\tnew google.maps.Map(mapRef.current as HTMLElement, {\n\t\t\t\t\tcenter: defaultCenter,\n\t\t\t\t\tzoom: defaultZoom,\n\t\t\t\t\t...(options as google.maps.MapOptions),\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsetMaps(google.maps)\n\t\t}\n\t}, [defaultCenter, defaultZoom, map, mapRef, options])\n\n\tuseEffect(() => {\n\t\tif (map) {\n\t\t\tif (!googleApiCalled) {\n\t\t\t\tif (onGoogleApiLoaded && maps) onGoogleApiLoaded({ map, maps, ref: mapRef.current })\n\t\t\t\tsetGoogleApiCalled(true)\n\t\t\t}\n\n\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t// Idle event is fired when the map becomes idle after panning or zooming.\n\t\t\tgoogle.maps.event.addListener(map, 'idle', onIdle)\n\t\t}\n\t}, [googleApiCalled, map, maps, onChange, onGoogleApiLoaded, onIdle])\n\n\tuseEffect(\n\t\t() =>\n\t\t\t// clear listeners on unmount\n\t\t\t() => {\n\t\t\t\tif (map) {\n\t\t\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t\t}\n\t\t\t},\n\t\t[map],\n\t)\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={mapRef}\n\t\t\t\tstyle={style}\n\t\t\t\tclassName=\"google-map\"\n\t\t\t\t// spread the events as props\n\t\t\t\t{...events?.reduce(\n\t\t\t\t\t(acc, { name, handler }: EventProps) => {\n\t\t\t\t\t\tacc[name] = handler\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t},\n\t\t\t\t\t{} as { [key: string]: any },\n\t\t\t\t)}\n\t\t\t/>\n\t\t\t{children && map && maps && (\n\t\t\t\t<MapMarkers map={map} maps={maps}>\n\t\t\t\t\t{children}\n\t\t\t\t</MapMarkers>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nexport default MapComponent\n","export const isArraysEqualEps = (arrayA: number[], arrayB?: number[], eps = 0.000001): boolean => {\n\tif (arrayA && arrayB) {\n\t\tfor (let i = 0; i !== arrayA.length; ++i) {\n\t\t\tif (Math.abs(arrayA[i] - arrayB[i]) > eps) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\treturn false\n}\n","import { Children, cloneElement, isValidElement, useMemo } from 'react'\nimport { MapMarkersProps } from '../utils/types'\nimport OverlayView from './overlay-view'\n\nconst noop = () => {}\n\nconst MapMarkers = ({ children, map, maps }: MapMarkersProps) => {\n\tconst markers = useMemo(() => {\n\t\tif (!map || !maps) return []\n\n\t\treturn Children.map(children, (child) => {\n\t\t\tif (isValidElement(child)) {\n\t\t\t\tconst latLng = { lat: child.props.lat, lng: child.props.lng } as google.maps.LatLngLiteral\n\t\t\t\tconst { zIndex, draggable = false, onDragStart = noop, onDrag = noop, onDragEnd = noop } = child.props || {}\n\n\t\t\t\t// clone child without draggable props\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\tchild = cloneElement(child, {\n\t\t\t\t\t...child.props,\n\t\t\t\t\tdraggable: undefined,\n\t\t\t\t\tonDragStart: undefined,\n\t\t\t\t\tonDrag: undefined,\n\t\t\t\t\tonDragEnd: undefined,\n\t\t\t\t})\n\n\t\t\t\treturn (\n\t\t\t\t\t<OverlayView\n\t\t\t\t\t\tposition={new maps.LatLng(latLng.lat, latLng.lng)}\n\t\t\t\t\t\tmap={map}\n\t\t\t\t\t\tmaps={maps}\n\t\t\t\t\t\tzIndex={zIndex}\n\t\t\t\t\t\tdrag={{\n\t\t\t\t\t\t\tdraggable,\n\t\t\t\t\t\t\tonDragStart,\n\t\t\t\t\t\t\tonDrag,\n\t\t\t\t\t\t\tonDragEnd,\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{child}\n\t\t\t\t\t</OverlayView>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn null\n\t\t})\n\t}, [children, map, maps])\n\n\treturn <div>{markers}</div>\n}\n\nexport default MapMarkers\n","import { useEffect, useMemo } from 'react'\nimport { createPortal } from 'react-dom'\nimport { OverlayViewProps } from '../utils/types'\nimport useMemoCompare from './hooks/useMemoCompare'\nimport createOverlay from './overlay'\n\nconst OverlayView = ({ pane = 'floatPane', position, map, maps, zIndex = 0, children, drag }: OverlayViewProps) => {\n\tconst container = useMemo<HTMLDivElement>(() => {\n\t\t// eslint-disable-next-line no-undef\n\t\tconst div = document.createElement('div') as HTMLDivElement\n\t\tdiv.style.position = 'absolute'\n\t\treturn div as HTMLDivElement\n\t}, [])\n\n\tconst overlay = useMemo(\n\t\t() => createOverlay({ container, pane, position, maps, drag }),\n\t\t[container, drag, maps, pane, position],\n\t)\n\n\t// Because React does not do deep comparisons, a custom hook is used.\n\t// This fixes the issue where the overlay is not updated when the position changes.\n\tconst childrenProps = useMemoCompare(\n\t\tchildren?.props as any,\n\t\t(prev: { lat: any; lng: any }, next: { lat: any; lng: any }) =>\n\t\t\tprev && prev.lat === next.lat && prev.lng === next.lng,\n\t)\n\n\tuseEffect(() => {\n\t\tif (!overlay.map && map) {\n\t\t\toverlay?.setMap(map)\n\t\t\treturn () => {\n\t\t\t\toverlay?.setMap(null)\n\t\t\t}\n\t\t}\n\t\treturn () => {}\n\t\t// overlay depends on map, so we don't need to add it to the dependency array\n\t\t// otherwise, it will re-render the overlay every time the map changes\n\t\t// ? added childrenProps to the dependency array to re-render the overlay when the children props change.\n\t}, [map, childrenProps])\n\n\t// to move the container to the foreground and background\n\tuseEffect(() => {\n\t\tcontainer.style.zIndex = `${zIndex}`\n\t}, [zIndex, container])\n\n\treturn createPortal(children, container)\n}\n\nexport default OverlayView\n","import { useEffect, useRef } from 'react'\n\n/**\n * A hook that compares the previous and current values of a reference.\n * @param {any} next - the current value of the reference\n * @param {function} compare - a function that compares the previous and current values\n * @returns {any} the previous value of the reference\n * @ref https://usehooks.com/useMemoCompare/\n */\nconst useMemoCompare = (next: any, compare: Function): any => {\n\t// Ref for storing previous value\n\tconst previousRef = useRef()\n\tconst previous = previousRef.current\n\t// Pass previous and next value to compare function\n\t// to determine whether to consider them equal.\n\tconst isEqual = compare(previous, next)\n\t// If not equal update previousRef to next value.\n\t// We only update if not equal so that this hook continues to return\n\t// the same old value if compare keeps returning true.\n\tuseEffect(() => {\n\t\tif (!isEqual) {\n\t\t\tpreviousRef.current = next\n\t\t}\n\t})\n\t// Finally, if equal then return the previous value\n\treturn isEqual ? previous : next\n}\n\nexport default useMemoCompare\n","import { Pane, createOverlayProps } from '../utils/types'\n\n// return lat, lng from LatLngLiteral\nconst getLatLng = (LatLng: google.maps.LatLng | null) => {\n\ttry {\n\t\tconst latLng = { lat: LatLng?.lat(), lng: LatLng?.lng() } as google.maps.LatLngLiteral\n\t\treturn latLng\n\t} catch (e) {\n\t\treturn LatLng\n\t}\n}\n\nconst createOverlay = ({ container, pane, position, maps, drag }: createOverlayProps) => {\n\tclass Overlay extends google.maps.OverlayView {\n\t\t/**\n\t\t * onAdd is called when the map's panes are ready and the overlay has been\n\t\t * added to the map.\n\t\t */\n\t\tonAdd = () => {\n\t\t\tconst that = this\n\t\t\t// manage draggable\n\t\t\tif (drag?.draggable) {\n\t\t\t\tthis.get('map')\n\t\t\t\t\t.getDiv()\n\t\t\t\t\t.addEventListener('mouseleave', () => {\n\t\t\t\t\t\tgoogle.maps.event.trigger(this.container, 'mouseup')\n\t\t\t\t\t})\n\t\t\t\tthis.container.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\t\t\tthis.container.style.cursor = 'grabbing'\n\t\t\t\t\tthat.map?.set('draggable', false)\n\t\t\t\t\tthat.set('origin', e)\n\n\t\t\t\t\tdrag.onDragStart(e, { latLng: getLatLng(this.position) })\n\n\t\t\t\t\t// eslint-disable-next-line no-shadow\n\t\t\t\t\tthat.moveHandler = this.get('map')\n\t\t\t\t\t\t.getDiv()\n\t\t\t\t\t\t.addEventListener('mousemove', (evt: MouseEvent) => {\n\t\t\t\t\t\t\tconst origin = that.get('origin')\n\t\t\t\t\t\t\tconst left = origin.clientX - evt.clientX\n\t\t\t\t\t\t\tconst top = origin.clientY - evt.clientY\n\t\t\t\t\t\t\tconst pos = that.getProjection().fromLatLngToDivPixel(that.position)\n\t\t\t\t\t\t\tif (pos === null) return\n\t\t\t\t\t\t\tconst latLng = that.getProjection().fromDivPixelToLatLng(new maps.Point(pos.x - left, pos.y - top))\n\t\t\t\t\t\t\tthat.set('position', latLng)\n\t\t\t\t\t\t\tthat.set('origin', evt)\n\t\t\t\t\t\t\tthat.draw()\n\t\t\t\t\t\t\tdrag.onDrag(evt, { latLng: getLatLng(latLng) })\n\t\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tthis.container.addEventListener('mouseup', (e) => {\n\t\t\t\t\tthat.map?.set('draggable', true)\n\t\t\t\t\tthis.container.style.cursor = 'default'\n\t\t\t\t\tif (that.moveHandler) {\n\t\t\t\t\t\tgoogle.maps.event.removeListener(that.moveHandler)\n\t\t\t\t\t\tthat.moveHandler = null\n\t\t\t\t\t}\n\t\t\t\t\tdrag.onDragEnd(e, { latLng: getLatLng(that.position) })\n\t\t\t\t})\n\t\t\t}\n\t\t\t// Add the element to the pane.\n\t\t\tconst currentPane = this.getPanes()?.[this.pane] as HTMLElement\n\t\t\tcurrentPane?.classList.add('google-map-markers-overlay')\n\t\t\tcurrentPane?.appendChild(this.container)\n\t\t}\n\n\t\tdraw = () => {\n\t\t\tconst projection = this.getProjection() as google.maps.MapCanvasProjection\n\t\t\t// Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.\n\t\t\tconst point = projection.fromLatLngToDivPixel(this.position) as google.maps.Point\n\t\t\tif (point === null) return\n\t\t\tthis.container.style.transform = `translate(${point.x}px, ${point.y}px)`\n\t\t\tthis.container.style.width = '0px'\n\t\t\tthis.container.style.height = '0px'\n\t\t}\n\n\t\t/**\n\t\t * The onRemove() method will be called automatically from the API if\n\t\t * we ever set the overlay's map property to 'null'.\n\t\t */\n\t\tonRemove = () => {\n\t\t\tif (this.container.parentNode !== null) {\n\t\t\t\t// remove DOM listeners\n\t\t\t\tgoogle.maps.event.clearInstanceListeners(this.container)\n\t\t\t\tthis.container.parentNode.removeChild(this.container)\n\t\t\t}\n\t\t}\n\n\t\tpublic container: HTMLDivElement\n\n\t\tpublic pane: Pane\n\n\t\tpublic position: google.maps.LatLng\n\n\t\tpublic map = this.getMap()\n\n\t\tpublic moveHandler: google.maps.MapsEventListener | null\n\n\t\t// eslint-disable-next-line no-shadow\n\t\tconstructor(container: HTMLDivElement, pane: Pane, position: google.maps.LatLng) {\n\t\t\tsuper()\n\n\t\t\t// Initialize all properties.\n\t\t\tthis.container = container\n\t\t\tthis.pane = pane\n\t\t\tthis.position = position\n\n\t\t\tthis.moveHandler = null\n\t\t}\n\t}\n\n\treturn new Overlay(container, pane, position)\n}\n\nexport default createOverlay\n","import GoogleMap from './google-map'\n\nexport default GoogleMap\n"]}
1
+ {"version":3,"sources":["../src/google-map.tsx","../src/map/hooks/useScript.ts","../src/map/hooks/useGoogleMaps.ts","../src/map/map.tsx","../src/utils/utils.ts","../src/map/markers.tsx","../src/map/overlay-view.tsx","../src/map/hooks/useMemoCompare.ts","../src/map/overlay.tsx","../src/index.ts"],"names":["forwardRef","useEffect","useState","cachedScriptStatuses","getScriptNode","src","node","status","useScript","script","forcedStatus","options","setStatus","_a","_b","_c","cachedScriptStatus","scriptToAdd","scriptNode","currentScriptStatus","key","value","setAttributeFromEvent","event","scriptStatus","setStateFromEvent","newStatus","useScript_default","useGoogleMaps","apiKey","libraries","loadScriptExternally","externalApiParams","callback","apiParams","useCallback","useRef","isArraysEqualEps","arrayA","arrayB","eps","i","Children","cloneElement","isValidElement","useMemo","createPortal","useMemoCompare","next","compare","previousRef","previous","isEqual","useMemoCompare_default","getLatLng","LatLng","createOverlay","container","pane","position","maps","drag","Overlay","that","e","evt","origin","left","top","pos","latLng","currentPane","point","overlay_default","OverlayView","map","zIndex","children","div","overlay","childrenProps","prev","overlay_view_default","jsx","noop","MapMarkers","markers","child","draggable","onDragStart","onDrag","onDragEnd","markers_default","Fragment","jsxs","MapComponent","style","defaultCenter","defaultZoom","onGoogleApiLoaded","onChange","events","mapRef","prevBoundsRef","setMap","setMaps","googleApiCalled","setGoogleApiCalled","onIdle","zoom","bounds","centerLatLng","ne","sw","boundsArray","acc","name","handler","map_default","GoogleMap","loadingContent","idleContent","errorContent","mapMinHeight","containerProps","statusProp","scriptCallback","props","ref","renderers","google_map_default","src_default"],"mappings":"AAAA,OAAS,cAAAA,OAAkB,QCC3B,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QAIpC,IAAMC,EAAoE,CAAC,EAE3E,SAASC,EAAcC,EAAa,CACnC,IAAMC,EAAiC,SAAS,cAAc,eAAeD,CAAG,IAAI,EAC9EE,EAASD,GAAA,YAAAA,EAAM,aAAa,eAElC,MAAO,CACN,KA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,IAAKmB,EACL,MAAON,EACP,UAAU,aAET,GAAGK,GAAA,YAAAA,EAAQ,OACX,CAACc,EAAK,CAAE,KAAAC,EAAM,QAAAC,CAAQ,KACrBF,EAAIC,CAAI,EAAIC,EACLF,GAER,CAAC,GAEH,EACCtC,GAAYF,GAAOf,GACnBuB,EAACS,EAAA,CAAW,IAAKjB,EAAK,KAAMf,EAC1B,SAAAiB,EACF,GAEF,CAEF,CAEA,IAAOyC,EAAQvB,GHrGL,cAAAZ,MAAA,oBApBV,IAAMoC,GAAYvH,GACjB,CACC,CACC,OAAA6B,EAAS,GACT,UAAAC,EAAY,CAAC,SAAU,UAAU,EACjC,SAAA+C,EAAW,KACX,eAAA2C,EAAiB,yBACjB,YAAAC,EAAc,yBACd,aAAAC,EAAe,0BACf,aAAAC,EAAe,QACf,eAAAC,EAAiB,CAAC,EAClB,qBAAA7F,EAAuB,GACvB,OAAQ8F,EAAa,OACrB,eAAAC,EAAiB,IAAM,CAAC,EACxB,kBAAA9F,EAAoB,CAAC,EACrB,GAAG+F,CACJ,EACAC,IACI,CACJ,IAAMC,EAAY,CACjB,MAAO9C,EAACmC,EAAA,CAAc,GAAGS,EAAQ,SAAAlD,EAAS,EAC1C,QAAS2C,EACT,KAAMC,EACN,MAAOC,CACR,EAEMnH,EAASqB,EAAc,CAC5B,OAAAC,EACA,UAAAC,EACA,qBAAAC,EACA,OAAQ8F,EACR,kBAAA7F,EACA,SAAU8F,CACX,CAAC,EAED,OACC3C,EAAC,OACA,IAAK6C,EACL,MAAO,CAAE,OAAQ,OAAQ,MAAO,OAAQ,SAAU,SAAU,SAAU,WAAY,UAAWL,CAAa,EACzG,GAAGC,EAEH,SAAAK,EAAU1H,CAAM,GAAK,KACvB,CAEF,CACD,EAEO2H,EAAQX,GShDf,IAAOY,GAAQD","sourcesContent":["import { forwardRef } from 'react'\nimport { useGoogleMaps } from './map/hooks/useGoogleMaps'\nimport MapComponent from './map/map'\nimport { GoogleMapProps } from './utils/types'\n\nconst GoogleMap = forwardRef<HTMLDivElement, GoogleMapProps>(\n\t(\n\t\t{\n\t\t\tapiKey = '',\n\t\t\tlibraries = ['places', 'geometry'],\n\t\t\tchildren = null,\n\t\t\tloadingContent = 'Google Maps is loading',\n\t\t\tidleContent = 'Google Maps is on idle',\n\t\t\terrorContent = 'Google Maps is on error',\n\t\t\tmapMinHeight = 'unset',\n\t\t\tcontainerProps = {},\n\t\t\tloadScriptExternally = false,\n\t\t\tstatus: statusProp = 'idle',\n\t\t\tscriptCallback = () => {},\n\t\t\texternalApiParams = {},\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst renderers = {\n\t\t\tready: <MapComponent {...props}>{children}</MapComponent>,\n\t\t\tloading: loadingContent,\n\t\t\tidle: idleContent,\n\t\t\terror: errorContent,\n\t\t}\n\n\t\tconst status = useGoogleMaps({\n\t\t\tapiKey,\n\t\t\tlibraries,\n\t\t\tloadScriptExternally,\n\t\t\tstatus: statusProp,\n\t\t\texternalApiParams,\n\t\t\tcallback: scriptCallback,\n\t\t})\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tstyle={{ height: '100%', width: '100%', overflow: 'hidden', position: 'relative', minHeight: mapMinHeight }}\n\t\t\t\t{...containerProps}\n\t\t\t>\n\t\t\t\t{renderers[status] || null}\n\t\t\t</div>\n\t\t)\n\t},\n)\n\nexport default GoogleMap\n","/* eslint-disable no-unused-expressions */\nimport { useEffect, useState } from 'react'\nimport { ScriptProps, UseScriptOptions, UseScriptStatus } from '../../utils/types'\n\n// Cached script statuses\nconst cachedScriptStatuses: Record<string, UseScriptStatus | undefined> = {}\n\nfunction getScriptNode(src: string) {\n\tconst node: HTMLScriptElement | null = document.querySelector(`script[src=\"${src}\"]`)\n\tconst status = node?.getAttribute('data-status') as UseScriptStatus | undefined\n\n\treturn {\n\t\tnode,\n\t\tstatus,\n\t}\n}\n\n/**\n * @description Hook to load external script.\n * @param {Object} script - Script to load.\n * @param {string} script.src - Script source.\n * @param {Object} [script.attributes] - Attributes to add to the script tag.\n * @param {Object} [script.callbacks] - Callbacks executed on completion.\n * @param {Function} [script.callbacks.onLoadCallback] - Callback executed on completion in case of success.\n * @param {Function} [script.callbacks.onErrorCallback] - Callbacks executed on completion in case of error.\n * @param {string} [script.elementIdToAppend] - HTML element id to append the script to. Default is HTML HEAD.\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n *\n * @example\n * const status = useScript({\n * \t\tsrc: \"https://script-to-load.js\",\n * \t\tattributes: { id: \"scriptId\", class: \"script-class\" },\n * \t\tcallbacks: {\n * \t\t\tonLoadCallback: onLoadFunc,\n * \t\t\tonErrorCallback: onErrorFunc,\n * \t\t},\n * \t\telementIdToAppend: \"script-container\"\n * }, undefined, { removeOnUnmount: true, shouldPreventLoad: false })\n */\n\nfunction useScript(\n\t// eslint-disable-next-line default-param-last\n\tscript: ScriptProps = {\n\t\tsrc: '',\n\t\tattributes: {},\n\t\tcallbacks: { onLoadCallback: () => {}, onErrorCallback: () => {} },\n\t\telementIdToAppend: '',\n\t},\n\tforcedStatus?: UseScriptStatus,\n\toptions: UseScriptOptions = { removeOnUnmount: false, shouldPreventLoad: false },\n): 'idle' | 'loading' | 'ready' | 'error' {\n\tconst [status, setStatus] = useState<UseScriptStatus>(() => {\n\t\tif (!script.src || options?.shouldPreventLoad) {\n\t\t\treturn 'idle'\n\t\t}\n\n\t\tif (typeof window === 'undefined') {\n\t\t\t// SSR Handling - always return 'loading'\n\t\t\treturn 'loading'\n\t\t}\n\n\t\treturn cachedScriptStatuses[script.src] ?? 'loading'\n\t})\n\n\tuseEffect(\n\t\t() => {\n\t\t\tif (forcedStatus) {\n\t\t\t\tsetStatus(forcedStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (!script?.src || options?.shouldPreventLoad) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst cachedScriptStatus = cachedScriptStatuses[script.src]\n\t\t\tif (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {\n\t\t\t\t// If the script is already cached, set its status immediately\n\t\t\t\tsetStatus(cachedScriptStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Fetch existing script element by src\n\t\t\t// It may have been added by another instance of this hook\n\t\t\tconst scriptToAdd = getScriptNode(script.src)\n\t\t\tlet scriptNode = scriptToAdd.node\n\n\t\t\tif (!scriptNode) {\n\t\t\t\t// Create script element and add it to document body\n\t\t\t\tscriptNode = document.createElement('script')\n\t\t\t\tscriptNode.src = script.src\n\t\t\t\tscriptNode.async = true\n\t\t\t\tscriptNode.setAttribute('data-status', 'loading')\n\t\t\t\t// Add other script attributes, if they exist\n\t\t\t\tscript.attributes && Object.entries(script.attributes).length > 0\n\t\t\t\t\t? Object.entries(script.attributes).map(([key, value]) => scriptNode?.setAttribute(key, value))\n\t\t\t\t\t: null\n\t\t\t\tif (script.elementIdToAppend && document.getElementById(script.elementIdToAppend)) {\n\t\t\t\t\tdocument.getElementById(script.elementIdToAppend)?.appendChild(scriptNode)\n\t\t\t\t} else {\n\t\t\t\t\tdocument.body.appendChild(scriptNode)\n\t\t\t\t}\n\n\t\t\t\t// Store status in attribute on script\n\t\t\t\t// This can be read by other instances of this hook\n\t\t\t\tconst setAttributeFromEvent = (event: Event) => {\n\t\t\t\t\tconst scriptStatus: UseScriptStatus = event.type === 'load' ? 'ready' : 'error'\n\n\t\t\t\t\tscriptNode?.setAttribute('data-status', scriptStatus)\n\t\t\t\t}\n\n\t\t\t\tscriptNode.addEventListener('load', setAttributeFromEvent)\n\t\t\t\tscriptNode.addEventListener('error', setAttributeFromEvent)\n\t\t\t} else {\n\t\t\t\t// Grab existing script status from attribute and set to state.\n\t\t\t\tconst currentScriptStatus = scriptToAdd.status ?? cachedScriptStatus ?? 'loading'\n\n\t\t\t\tswitch (currentScriptStatus) {\n\t\t\t\t\tcase 'loading':\n\t\t\t\t\tcase 'ready':\n\t\t\t\t\t\tscript.callbacks?.onLoadCallback ? script.callbacks.onLoadCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\tscript.callbacks?.onErrorCallback ? script.callbacks.onErrorCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// loading: do nothing\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tsetStatus(currentScriptStatus)\n\t\t\t}\n\n\t\t\t// Script event handler to update status in state\n\t\t\t// Note: Even if the script already exists we still need to add\n\t\t\t// event handlers to update the state for this hook instance.\n\t\t\tconst setStateFromEvent = (event: Event) => {\n\t\t\t\tconst newStatus = event.type === 'load' ? 'ready' : 'error'\n\t\t\t\tevent.type === 'load'\n\t\t\t\t\t? script.callbacks?.onLoadCallback\n\t\t\t\t\t\t? script.callbacks.onLoadCallback()\n\t\t\t\t\t\t: null\n\t\t\t\t\t: script.callbacks?.onErrorCallback\n\t\t\t\t\t? script.callbacks.onErrorCallback()\n\t\t\t\t\t: null\n\n\t\t\t\tsetStatus(newStatus)\n\t\t\t\tcachedScriptStatuses[script.src] = newStatus\n\t\t\t}\n\t\t\t// Add event listeners\n\t\t\tscriptNode.addEventListener('load', setStateFromEvent)\n\t\t\tscriptNode.addEventListener('error', setStateFromEvent)\n\t\t\t// Remove event listeners on cleanup\n\t\t\t// eslint-disable-next-line consistent-return\n\t\t\treturn () => {\n\t\t\t\tif (scriptNode) {\n\t\t\t\t\tscriptNode.removeEventListener('load', setStateFromEvent)\n\t\t\t\t\tscriptNode.removeEventListener('error', setStateFromEvent)\n\t\t\t\t}\n\n\t\t\t\tif (scriptNode && options?.removeOnUnmount) {\n\t\t\t\t\tscriptNode.remove()\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Re-run useEffect if script changes\n\t\t[script, forcedStatus, status],\n\t)\n\n\treturn status\n}\n\nexport default useScript\n","import { IUseGoogleMaps, UseScriptStatus } from '../../utils/types'\nimport useScript from './useScript'\n\n/**\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n */\nexport const useGoogleMaps = ({\n\tapiKey,\n\tlibraries = [],\n\tloadScriptExternally = false,\n\tstatus = 'idle',\n\texternalApiParams,\n\tcallback,\n}: IUseGoogleMaps): UseScriptStatus => {\n\tif (typeof window !== 'undefined') window.googleMapsCallback = callback\n\tconst apiParams = new URLSearchParams(externalApiParams)?.toString()\n\tconst script = apiKey\n\t\t? {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=googleMapsCallback&libraries=${libraries?.join(\n\t\t\t\t\t',',\n\t\t\t\t)}${apiParams ? `&${apiParams}` : ''}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\t\t: {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${libraries?.join(',')}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\n\treturn useScript(script, loadScriptExternally ? status : undefined)\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport { EventProps, Map, MapProps, MapsLibrary } from '../utils/types'\nimport { isArraysEqualEps } from '../utils/utils'\nimport MapMarkers from './markers'\n\nfunction MapComponent({\n\tchildren = null,\n\tstyle = {\n\t\twidth: '100%',\n\t\theight: '100%',\n\t\tleft: 0,\n\t\ttop: 0,\n\t\tmargin: 0,\n\t\tpadding: 0,\n\t\tposition: 'absolute',\n\t},\n\tdefaultCenter,\n\tdefaultZoom,\n\tonGoogleApiLoaded,\n\tonChange,\n\toptions = {},\n\tevents = [],\n}: MapProps) {\n\tconst mapRef = useRef<HTMLDivElement>(null)\n\tconst prevBoundsRef = useRef<number[] | undefined>()\n\tconst [map, setMap] = useState<Map>()\n\tconst [maps, setMaps] = useState<MapsLibrary>()\n\tconst [googleApiCalled, setGoogleApiCalled] = useState<boolean>(false)\n\n\tconst onIdle = useCallback(() => {\n\t\ttry {\n\t\t\tif (!map) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst zoom = map.getZoom() ?? defaultZoom\n\t\t\tconst bounds = map.getBounds()\n\t\t\tconst centerLatLng = [map.getCenter()?.lng(), map.getCenter()?.lat()]\n\n\t\t\tconst ne = bounds?.getNorthEast()\n\t\t\tconst sw = bounds?.getSouthWest()\n\n\t\t\tif (!ne || !sw || !bounds) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// east, north, south, west\n\t\t\tconst boundsArray = [sw.lng(), sw.lat(), ne.lng(), ne.lat()]\n\n\t\t\tif (!isArraysEqualEps(boundsArray, prevBoundsRef.current)) {\n\t\t\t\tif (onChange) {\n\t\t\t\t\tonChange({\n\t\t\t\t\t\tzoom,\n\t\t\t\t\t\tcenter: centerLatLng,\n\t\t\t\t\t\tbounds,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tprevBoundsRef.current = boundsArray\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(e)\n\t\t}\n\t}, [map, onChange])\n\n\tuseEffect(() => {\n\t\tif (mapRef.current && !map) {\n\t\t\tsetMap(\n\t\t\t\tnew google.maps.Map(mapRef.current as HTMLElement, {\n\t\t\t\t\tcenter: defaultCenter,\n\t\t\t\t\tzoom: defaultZoom,\n\t\t\t\t\t...(options as google.maps.MapOptions),\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsetMaps(google.maps)\n\t\t}\n\t}, [defaultCenter, defaultZoom, map, mapRef, options])\n\n\tuseEffect(() => {\n\t\tif (map) {\n\t\t\tif (!googleApiCalled) {\n\t\t\t\tif (onGoogleApiLoaded && maps) onGoogleApiLoaded({ map, maps, ref: mapRef.current })\n\t\t\t\tsetGoogleApiCalled(true)\n\t\t\t}\n\n\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t// Idle event is fired when the map becomes idle after panning or zooming.\n\t\t\tgoogle.maps.event.addListener(map, 'idle', onIdle)\n\t\t}\n\t}, [googleApiCalled, map, maps, onChange, onGoogleApiLoaded, onIdle])\n\n\tuseEffect(\n\t\t() =>\n\t\t\t// clear listeners on unmount\n\t\t\t() => {\n\t\t\t\tif (map) {\n\t\t\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t\t}\n\t\t\t},\n\t\t[map],\n\t)\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={mapRef}\n\t\t\t\tstyle={style}\n\t\t\t\tclassName=\"google-map\"\n\t\t\t\t// spread the events as props\n\t\t\t\t{...events?.reduce(\n\t\t\t\t\t(acc, { name, handler }: EventProps) => {\n\t\t\t\t\t\tacc[name] = handler\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t},\n\t\t\t\t\t{} as { [key: string]: any },\n\t\t\t\t)}\n\t\t\t/>\n\t\t\t{children && map && maps && (\n\t\t\t\t<MapMarkers map={map} maps={maps}>\n\t\t\t\t\t{children}\n\t\t\t\t</MapMarkers>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nexport default MapComponent\n","export const isArraysEqualEps = (arrayA: number[], arrayB?: number[], eps = 0.000001): boolean => {\n\tif (arrayA && arrayB) {\n\t\tfor (let i = 0; i !== arrayA.length; ++i) {\n\t\t\tif (Math.abs(arrayA[i] - arrayB[i]) > eps) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\treturn false\n}\n","import { Children, cloneElement, isValidElement, useMemo } from 'react'\nimport { MapMarkersProps } from '../utils/types'\nimport OverlayView from './overlay-view'\n\nconst noop = () => {}\n\nconst MapMarkers = ({ children, map, maps }: MapMarkersProps) => {\n\tconst markers = useMemo(() => {\n\t\tif (!map || !maps) return []\n\n\t\treturn Children.map(children, (child) => {\n\t\t\tif (isValidElement(child)) {\n\t\t\t\tconst latLng = { lat: child.props.lat, lng: child.props.lng } as google.maps.LatLngLiteral\n\t\t\t\tconst { zIndex, draggable = false, onDragStart = noop, onDrag = noop, onDragEnd = noop } = child.props || {}\n\n\t\t\t\t// clone child without draggable props\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\tchild = cloneElement(child, {\n\t\t\t\t\t...child.props,\n\t\t\t\t\tdraggable: undefined,\n\t\t\t\t\tonDragStart: undefined,\n\t\t\t\t\tonDrag: undefined,\n\t\t\t\t\tonDragEnd: undefined,\n\t\t\t\t})\n\n\t\t\t\treturn (\n\t\t\t\t\t<OverlayView\n\t\t\t\t\t\tposition={new maps.LatLng(latLng.lat, latLng.lng)}\n\t\t\t\t\t\tmap={map}\n\t\t\t\t\t\tmaps={maps}\n\t\t\t\t\t\tzIndex={zIndex}\n\t\t\t\t\t\tdrag={{\n\t\t\t\t\t\t\tdraggable,\n\t\t\t\t\t\t\tonDragStart,\n\t\t\t\t\t\t\tonDrag,\n\t\t\t\t\t\t\tonDragEnd,\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{child}\n\t\t\t\t\t</OverlayView>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn null\n\t\t})\n\t}, [children, map, maps])\n\n\treturn <div>{markers}</div>\n}\n\nexport default MapMarkers\n","import { useEffect, useMemo } from 'react'\nimport { createPortal } from 'react-dom'\nimport { OverlayViewProps } from '../utils/types'\nimport useMemoCompare from './hooks/useMemoCompare'\nimport createOverlay from './overlay'\n\nconst OverlayView = ({ pane = 'floatPane', position, map, maps, zIndex = 0, children, drag }: OverlayViewProps) => {\n\tconst container = useMemo<HTMLDivElement>(() => {\n\t\t// eslint-disable-next-line no-undef\n\t\tconst div = document.createElement('div') as HTMLDivElement\n\t\tdiv.style.position = 'absolute'\n\t\treturn div as HTMLDivElement\n\t}, [])\n\n\tconst overlay = useMemo(\n\t\t() => createOverlay({ container, pane, position, maps, drag }),\n\t\t[container, drag, maps, pane, position],\n\t)\n\n\t// Because React does not do deep comparisons, a custom hook is used.\n\t// This fixes the issue where the overlay is not updated when the position changes.\n\tconst childrenProps = useMemoCompare(\n\t\tchildren?.props as any,\n\t\t(prev: { lat: any; lng: any }, next: { lat: any; lng: any }) =>\n\t\t\tprev && prev.lat === next.lat && prev.lng === next.lng,\n\t)\n\n\tuseEffect(() => {\n\t\tif (!overlay.map && map) {\n\t\t\toverlay?.setMap(map)\n\t\t\treturn () => {\n\t\t\t\toverlay?.setMap(null)\n\t\t\t}\n\t\t}\n\t\treturn () => {}\n\t\t// overlay depends on map, so we don't need to add it to the dependency array\n\t\t// otherwise, it will re-render the overlay every time the map changes\n\t\t// ? added childrenProps to the dependency array to re-render the overlay when the children props change.\n\t}, [map, childrenProps])\n\n\t// to move the container to the foreground and background\n\tuseEffect(() => {\n\t\tcontainer.style.zIndex = `${zIndex}`\n\t}, [zIndex, container])\n\n\treturn createPortal(children, container)\n}\n\nexport default OverlayView\n","import { useEffect, useRef } from 'react'\n\n/**\n * A hook that compares the previous and current values of a reference.\n * @param {any} next - the current value of the reference\n * @param {function} compare - a function that compares the previous and current values\n * @returns {any} the previous value of the reference\n * @ref https://usehooks.com/useMemoCompare/\n */\nconst useMemoCompare = (next: any, compare: Function): any => {\n\t// Ref for storing previous value\n\tconst previousRef = useRef()\n\tconst previous = previousRef.current\n\t// Pass previous and next value to compare function\n\t// to determine whether to consider them equal.\n\tconst isEqual = compare(previous, next)\n\t// If not equal update previousRef to next value.\n\t// We only update if not equal so that this hook continues to return\n\t// the same old value if compare keeps returning true.\n\tuseEffect(() => {\n\t\tif (!isEqual) {\n\t\t\tpreviousRef.current = next\n\t\t}\n\t})\n\t// Finally, if equal then return the previous value\n\treturn isEqual ? previous : next\n}\n\nexport default useMemoCompare\n","import { Pane, createOverlayProps } from '../utils/types'\n\n// return lat, lng from LatLngLiteral\nconst getLatLng = (LatLng: google.maps.LatLng | null) => {\n\ttry {\n\t\tconst latLng = { lat: LatLng?.lat(), lng: LatLng?.lng() } as google.maps.LatLngLiteral\n\t\treturn latLng\n\t} catch (e) {\n\t\treturn LatLng\n\t}\n}\n\nconst createOverlay = ({ container, pane, position, maps, drag }: createOverlayProps) => {\n\tclass Overlay extends google.maps.OverlayView {\n\t\t/**\n\t\t * onAdd is called when the map's panes are ready and the overlay has been\n\t\t * added to the map.\n\t\t */\n\t\tonAdd = () => {\n\t\t\tconst that = this\n\t\t\t// manage draggable\n\t\t\tif (drag?.draggable) {\n\t\t\t\tthis.get('map')\n\t\t\t\t\t.getDiv()\n\t\t\t\t\t.addEventListener('mouseleave', () => {\n\t\t\t\t\t\tgoogle.maps.event.trigger(this.container, 'mouseup')\n\t\t\t\t\t})\n\t\t\t\tthis.container.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\t\t\tthis.container.style.cursor = 'grabbing'\n\t\t\t\t\tthat.map?.set('draggable', false)\n\t\t\t\t\tthat.set('origin', e)\n\n\t\t\t\t\tdrag.onDragStart(e, { latLng: getLatLng(this.position) })\n\n\t\t\t\t\t// eslint-disable-next-line no-shadow\n\t\t\t\t\tthat.moveHandler = this.get('map')\n\t\t\t\t\t\t.getDiv()\n\t\t\t\t\t\t.addEventListener('mousemove', (evt: MouseEvent) => {\n\t\t\t\t\t\t\tconst origin = that.get('origin')\n\t\t\t\t\t\t\tconst left = origin.clientX - evt.clientX\n\t\t\t\t\t\t\tconst top = origin.clientY - evt.clientY\n\t\t\t\t\t\t\tconst pos = that.getProjection().fromLatLngToDivPixel(that.position)\n\t\t\t\t\t\t\tif (pos === null) return\n\t\t\t\t\t\t\tconst latLng = that.getProjection().fromDivPixelToLatLng(new maps.Point(pos.x - left, pos.y - top))\n\t\t\t\t\t\t\tthat.set('position', latLng)\n\t\t\t\t\t\t\tthat.set('origin', evt)\n\t\t\t\t\t\t\tthat.draw()\n\t\t\t\t\t\t\tdrag.onDrag(evt, { latLng: getLatLng(latLng) })\n\t\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tthis.container.addEventListener('mouseup', (e) => {\n\t\t\t\t\tthat.map?.set('draggable', true)\n\t\t\t\t\tthis.container.style.cursor = 'default'\n\t\t\t\t\tif (that.moveHandler) {\n\t\t\t\t\t\tgoogle.maps.event.removeListener(that.moveHandler)\n\t\t\t\t\t\tthat.moveHandler = null\n\t\t\t\t\t}\n\t\t\t\t\tdrag.onDragEnd(e, { latLng: getLatLng(that.position) })\n\t\t\t\t})\n\t\t\t}\n\t\t\t// Add the element to the pane.\n\t\t\tconst currentPane = this.getPanes()?.[this.pane] as HTMLElement\n\t\t\tcurrentPane?.classList.add('google-map-markers-overlay')\n\t\t\tcurrentPane?.appendChild(this.container)\n\t\t}\n\n\t\tdraw = () => {\n\t\t\tconst projection = this.getProjection() as google.maps.MapCanvasProjection\n\t\t\t// Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.\n\t\t\tconst point = projection.fromLatLngToDivPixel(this.position) as google.maps.Point\n\t\t\tif (point === null) return\n\t\t\tthis.container.style.transform = `translate(${point.x}px, ${point.y}px)`\n\t\t\tthis.container.style.width = '0px'\n\t\t\tthis.container.style.height = '0px'\n\t\t}\n\n\t\t/**\n\t\t * The onRemove() method will be called automatically from the API if\n\t\t * we ever set the overlay's map property to 'null'.\n\t\t */\n\t\tonRemove = () => {\n\t\t\tif (this.container.parentNode !== null) {\n\t\t\t\t// remove DOM listeners\n\t\t\t\tgoogle.maps.event.clearInstanceListeners(this.container)\n\t\t\t\tthis.container.parentNode.removeChild(this.container)\n\t\t\t}\n\t\t}\n\n\t\tpublic container: HTMLDivElement\n\n\t\tpublic pane: Pane\n\n\t\tpublic position: google.maps.LatLng\n\n\t\tpublic map = this.getMap()\n\n\t\tpublic moveHandler: google.maps.MapsEventListener | null\n\n\t\t// eslint-disable-next-line no-shadow\n\t\tconstructor(container: HTMLDivElement, pane: Pane, position: google.maps.LatLng) {\n\t\t\tsuper()\n\n\t\t\t// Initialize all properties.\n\t\t\tthis.container = container\n\t\t\tthis.pane = pane\n\t\t\tthis.position = position\n\n\t\t\tthis.moveHandler = null\n\t\t}\n\t}\n\n\treturn new Overlay(container, pane, position)\n}\n\nexport default createOverlay\n","import GoogleMap from './google-map'\n\nexport * from './utils/types'\n\nexport default GoogleMap\n"]}
package/dist/index.d.cts CHANGED
@@ -7,12 +7,45 @@ declare global {
7
7
  googleMapsCallback?: () => void;
8
8
  }
9
9
  }
10
+ type MapMouseEvent = google.maps.MapMouseEvent;
10
11
  type Map = google.maps.Map;
11
12
  type MapsLibrary = typeof google.maps;
13
+ type MapPanes = google.maps.MapPanes;
12
14
  type MapOptions = google.maps.MapOptions;
15
+ type LatLng = google.maps.LatLng;
13
16
  type LatLngLiteral = google.maps.LatLngLiteral;
14
17
  type LatLngBounds = google.maps.LatLngBounds;
18
+ type LatLngBoundsLiteral = google.maps.LatLngBoundsLiteral;
19
+ /**
20
+ * The drag configuration of the overlay.
21
+ */
22
+ type Drag = {
23
+ /**
24
+ * Whether the overlay is draggable.
25
+ * @default false
26
+ */
27
+ draggable: boolean;
28
+ /**
29
+ * Callback fired repeatedly when the overlay is dragged.
30
+ * @param e The event.
31
+ * @param props The props.
32
+ */
33
+ onDrag: (e: MouseEvent, props: {}) => void;
34
+ /**
35
+ * Callback fired when the drag has ended.
36
+ * @param e The event.
37
+ * @param props The props.
38
+ */
39
+ onDragEnd: (e: MouseEvent, props: {}) => void;
40
+ /**
41
+ * Callback fired when the drag has started.
42
+ * @param e The event.
43
+ * @param props The props.
44
+ */
45
+ onDragStart: (e: MouseEvent, props: {}) => void;
46
+ };
15
47
  type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
48
+ type Pane = 'floatPane' | 'mapPane' | 'markerLayer' | 'overlayLayer' | 'overlayMouseTarget';
16
49
  interface IUseGoogleMaps {
17
50
  /**
18
51
  * The Google Maps API key.
@@ -49,6 +82,42 @@ interface IUseGoogleMaps {
49
82
  */
50
83
  status?: UseScriptStatus;
51
84
  }
85
+ interface ScriptProps {
86
+ /**
87
+ * The attributes to be passed to the script element.
88
+ */
89
+ attributes?: {
90
+ [key: string]: string;
91
+ };
92
+ /**
93
+ * The callback to be called when the script has loaded
94
+ * successfully or has failed to load.
95
+ */
96
+ callbacks?: {
97
+ onErrorCallback?: () => void;
98
+ onLoadCallback?: () => void;
99
+ };
100
+ /**
101
+ * The ID of the HTML element where the script will be appended.
102
+ * If not provided, the script will be appended to the `body` element.
103
+ */
104
+ elementIdToAppend?: string;
105
+ /**
106
+ * The URL of the script to be loaded.
107
+ */
108
+ src: string;
109
+ }
110
+ interface UseScriptOptions {
111
+ /**
112
+ * Whether to remove the script when the component unmounts.
113
+ */
114
+ removeOnUnmount?: boolean;
115
+ /**
116
+ * Whether to prevent the script from loading.
117
+ * @default false
118
+ */
119
+ shouldPreventLoad?: boolean;
120
+ }
52
121
  interface MapContextProps {
53
122
  /**
54
123
  * The Google Maps instance.
@@ -59,6 +128,55 @@ interface MapContextProps {
59
128
  */
60
129
  maps: MapsLibrary;
61
130
  }
131
+ interface OverlayViewProps extends MapContextProps {
132
+ /**
133
+ * The children to be rendered within the overlay.
134
+ */
135
+ children?: React__default.ReactElement;
136
+ /**
137
+ * The drag configuration of the overlay.
138
+ * @default { draggable: false }
139
+ */
140
+ drag?: Drag;
141
+ /**
142
+ * The map pane in which to render the overlay.
143
+ * @default 'floatPane'
144
+ */
145
+ pane?: Pane | undefined;
146
+ /**
147
+ * The geographical coordinates of the overlay.
148
+ */
149
+ position: LatLng;
150
+ /**
151
+ * The z-index of the overlay.
152
+ * @default 0
153
+ */
154
+ zIndex?: number | 0;
155
+ }
156
+ interface createOverlayProps {
157
+ /**
158
+ * The HTML container element in which to render the overlay.
159
+ */
160
+ container: HTMLDivElement;
161
+ /**
162
+ * The drag configuration of the overlay.
163
+ * @default { draggable: false }
164
+ */
165
+ drag?: Drag;
166
+ /**
167
+ * The Google Maps API object.
168
+ */
169
+ maps: MapContextProps['maps'];
170
+ /**
171
+ * The map pane in which to render the overlay.
172
+ * @default 'floatPane'
173
+ */
174
+ pane: Pane;
175
+ /**
176
+ * The geographical coordinates of the overlay.
177
+ */
178
+ position: LatLng;
179
+ }
62
180
  interface EventProps {
63
181
  /**
64
182
  * The event handler.
@@ -79,6 +197,12 @@ interface onGoogleApiLoadedProps extends MapContextProps {
79
197
  */
80
198
  ref: HTMLDivElement | null;
81
199
  }
200
+ interface MapMarkersProps extends MapContextProps {
201
+ /**
202
+ * The Markers to be rendered on the map.
203
+ */
204
+ children: React__default.ReactNode;
205
+ }
82
206
  interface MapProps {
83
207
  /**
84
208
  * The Markers to be rendered on the map
@@ -168,4 +292,4 @@ interface GoogleMapProps extends MapProps, IUseGoogleMaps {
168
292
 
169
293
  declare const GoogleMap: React.ForwardRefExoticComponent<GoogleMapProps & React.RefAttributes<HTMLDivElement>>;
170
294
 
171
- export { GoogleMap as default };
295
+ export { Drag, EventProps, GoogleMapProps, IUseGoogleMaps, LatLng, LatLngBounds, LatLngBoundsLiteral, LatLngLiteral, Map, MapContextProps, MapMarkersProps, MapMouseEvent, MapOptions, MapPanes, MapProps, MapsLibrary, OverlayViewProps, Pane, ScriptProps, UseScriptOptions, UseScriptStatus, createOverlayProps, GoogleMap as default, onGoogleApiLoadedProps };
package/dist/index.d.ts CHANGED
@@ -7,12 +7,45 @@ declare global {
7
7
  googleMapsCallback?: () => void;
8
8
  }
9
9
  }
10
+ type MapMouseEvent = google.maps.MapMouseEvent;
10
11
  type Map = google.maps.Map;
11
12
  type MapsLibrary = typeof google.maps;
13
+ type MapPanes = google.maps.MapPanes;
12
14
  type MapOptions = google.maps.MapOptions;
15
+ type LatLng = google.maps.LatLng;
13
16
  type LatLngLiteral = google.maps.LatLngLiteral;
14
17
  type LatLngBounds = google.maps.LatLngBounds;
18
+ type LatLngBoundsLiteral = google.maps.LatLngBoundsLiteral;
19
+ /**
20
+ * The drag configuration of the overlay.
21
+ */
22
+ type Drag = {
23
+ /**
24
+ * Whether the overlay is draggable.
25
+ * @default false
26
+ */
27
+ draggable: boolean;
28
+ /**
29
+ * Callback fired repeatedly when the overlay is dragged.
30
+ * @param e The event.
31
+ * @param props The props.
32
+ */
33
+ onDrag: (e: MouseEvent, props: {}) => void;
34
+ /**
35
+ * Callback fired when the drag has ended.
36
+ * @param e The event.
37
+ * @param props The props.
38
+ */
39
+ onDragEnd: (e: MouseEvent, props: {}) => void;
40
+ /**
41
+ * Callback fired when the drag has started.
42
+ * @param e The event.
43
+ * @param props The props.
44
+ */
45
+ onDragStart: (e: MouseEvent, props: {}) => void;
46
+ };
15
47
  type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
48
+ type Pane = 'floatPane' | 'mapPane' | 'markerLayer' | 'overlayLayer' | 'overlayMouseTarget';
16
49
  interface IUseGoogleMaps {
17
50
  /**
18
51
  * The Google Maps API key.
@@ -49,6 +82,42 @@ interface IUseGoogleMaps {
49
82
  */
50
83
  status?: UseScriptStatus;
51
84
  }
85
+ interface ScriptProps {
86
+ /**
87
+ * The attributes to be passed to the script element.
88
+ */
89
+ attributes?: {
90
+ [key: string]: string;
91
+ };
92
+ /**
93
+ * The callback to be called when the script has loaded
94
+ * successfully or has failed to load.
95
+ */
96
+ callbacks?: {
97
+ onErrorCallback?: () => void;
98
+ onLoadCallback?: () => void;
99
+ };
100
+ /**
101
+ * The ID of the HTML element where the script will be appended.
102
+ * If not provided, the script will be appended to the `body` element.
103
+ */
104
+ elementIdToAppend?: string;
105
+ /**
106
+ * The URL of the script to be loaded.
107
+ */
108
+ src: string;
109
+ }
110
+ interface UseScriptOptions {
111
+ /**
112
+ * Whether to remove the script when the component unmounts.
113
+ */
114
+ removeOnUnmount?: boolean;
115
+ /**
116
+ * Whether to prevent the script from loading.
117
+ * @default false
118
+ */
119
+ shouldPreventLoad?: boolean;
120
+ }
52
121
  interface MapContextProps {
53
122
  /**
54
123
  * The Google Maps instance.
@@ -59,6 +128,55 @@ interface MapContextProps {
59
128
  */
60
129
  maps: MapsLibrary;
61
130
  }
131
+ interface OverlayViewProps extends MapContextProps {
132
+ /**
133
+ * The children to be rendered within the overlay.
134
+ */
135
+ children?: React__default.ReactElement;
136
+ /**
137
+ * The drag configuration of the overlay.
138
+ * @default { draggable: false }
139
+ */
140
+ drag?: Drag;
141
+ /**
142
+ * The map pane in which to render the overlay.
143
+ * @default 'floatPane'
144
+ */
145
+ pane?: Pane | undefined;
146
+ /**
147
+ * The geographical coordinates of the overlay.
148
+ */
149
+ position: LatLng;
150
+ /**
151
+ * The z-index of the overlay.
152
+ * @default 0
153
+ */
154
+ zIndex?: number | 0;
155
+ }
156
+ interface createOverlayProps {
157
+ /**
158
+ * The HTML container element in which to render the overlay.
159
+ */
160
+ container: HTMLDivElement;
161
+ /**
162
+ * The drag configuration of the overlay.
163
+ * @default { draggable: false }
164
+ */
165
+ drag?: Drag;
166
+ /**
167
+ * The Google Maps API object.
168
+ */
169
+ maps: MapContextProps['maps'];
170
+ /**
171
+ * The map pane in which to render the overlay.
172
+ * @default 'floatPane'
173
+ */
174
+ pane: Pane;
175
+ /**
176
+ * The geographical coordinates of the overlay.
177
+ */
178
+ position: LatLng;
179
+ }
62
180
  interface EventProps {
63
181
  /**
64
182
  * The event handler.
@@ -79,6 +197,12 @@ interface onGoogleApiLoadedProps extends MapContextProps {
79
197
  */
80
198
  ref: HTMLDivElement | null;
81
199
  }
200
+ interface MapMarkersProps extends MapContextProps {
201
+ /**
202
+ * The Markers to be rendered on the map.
203
+ */
204
+ children: React__default.ReactNode;
205
+ }
82
206
  interface MapProps {
83
207
  /**
84
208
  * The Markers to be rendered on the map
@@ -168,4 +292,4 @@ interface GoogleMapProps extends MapProps, IUseGoogleMaps {
168
292
 
169
293
  declare const GoogleMap: React.ForwardRefExoticComponent<GoogleMapProps & React.RefAttributes<HTMLDivElement>>;
170
294
 
171
- export { GoogleMap as default };
295
+ export { Drag, EventProps, GoogleMapProps, IUseGoogleMaps, LatLng, LatLngBounds, LatLngBoundsLiteral, LatLngLiteral, Map, MapContextProps, MapMarkersProps, MapMouseEvent, MapOptions, MapPanes, MapProps, MapsLibrary, OverlayViewProps, Pane, ScriptProps, UseScriptOptions, UseScriptStatus, createOverlayProps, GoogleMap as default, onGoogleApiLoadedProps };
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { forwardRef, useRef, useState, useCallback, useEffect, useMemo, Children
2
2
  import { createPortal } from 'react-dom';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
 
5
- var S={};function Y(e){let r=document.querySelector(`script[src="${e}"]`),a=r==null?void 0:r.getAttribute("data-status");return {node:r,status:a}}function W(e={src:"",attributes:{},callbacks:{onLoadCallback:()=>{},onErrorCallback:()=>{}},elementIdToAppend:""},r,a={removeOnUnmount:!1,shouldPreventLoad:!1}){let[l,s]=useState(()=>!e.src||a!=null&&a.shouldPreventLoad?"idle":typeof window>"u"?"loading":S[e.src]??"loading");return useEffect(()=>{var u,n,m;if(r){s(r);return}if(!(e!=null&&e.src)||a!=null&&a.shouldPreventLoad)return;let i=S[e.src];if(i==="ready"||i==="error"){s(i);return}let c=Y(e.src),t=c.node;if(t){let p=c.status??i??"loading";switch(p){case"loading":case"ready":(n=e.callbacks)!=null&&n.onLoadCallback&&e.callbacks.onLoadCallback();break;case"error":(m=e.callbacks)!=null&&m.onErrorCallback&&e.callbacks.onErrorCallback();break;}s(p);}else {t=document.createElement("script"),t.src=e.src,t.async=!0,t.setAttribute("data-status","loading"),e.attributes&&Object.entries(e.attributes).length>0&&Object.entries(e.attributes).map(([g,d])=>t==null?void 0:t.setAttribute(g,d)),e.elementIdToAppend&&document.getElementById(e.elementIdToAppend)?(u=document.getElementById(e.elementIdToAppend))==null||u.appendChild(t):document.body.appendChild(t);let p=g=>{let d=g.type==="load"?"ready":"error";t==null||t.setAttribute("data-status",d);};t.addEventListener("load",p),t.addEventListener("error",p);}let o=p=>{var d,f;let g=p.type==="load"?"ready":"error";p.type==="load"?(d=e.callbacks)!=null&&d.onLoadCallback&&e.callbacks.onLoadCallback():(f=e.callbacks)!=null&&f.onErrorCallback&&e.callbacks.onErrorCallback(),s(g),S[e.src]=g;};return t.addEventListener("load",o),t.addEventListener("error",o),()=>{t&&(t.removeEventListener("load",o),t.removeEventListener("error",o)),t&&(a!=null&&a.removeOnUnmount)&&t.remove();}},[e,r,l]),l}var O=W;var T=({apiKey:e,libraries:r=[],loadScriptExternally:a=!1,status:l="idle",externalApiParams:s,callback:i})=>{var o;typeof window<"u"&&(window.googleMapsCallback=i);let c=(o=new URLSearchParams(s))==null?void 0:o.toString(),t=e?{src:`https://maps.googleapis.com/maps/api/js?key=${e}&callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}${c?`&${c}`:""}`,attributes:{id:"googleMapsApi"}}:{src:`https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}`,attributes:{id:"googleMapsApi"}};return O(t,a?l:void 0)};var H=(e,r,a=1e-6)=>{if(e&&r){for(let l=0;l!==e.length;++l)if(Math.abs(e[l]-r[l])>a)return !1;return !0}return !1};var _=(e,r)=>{let a=useRef(),l=a.current,s=r(l,e);return useEffect(()=>{s||(a.current=e);}),s?l:e},x=_;var k=e=>{try{return {lat:e==null?void 0:e.lat(),lng:e==null?void 0:e.lng()}}catch{return e}},K=({container:e,pane:r,position:a,maps:l,drag:s})=>{class i extends google.maps.OverlayView{onAdd=()=>{var u;let t=this;s!=null&&s.draggable&&(this.get("map").getDiv().addEventListener("mouseleave",()=>{google.maps.event.trigger(this.container,"mouseup");}),this.container.addEventListener("mousedown",n=>{var m;this.container.style.cursor="grabbing",(m=t.map)==null||m.set("draggable",!1),t.set("origin",n),s.onDragStart(n,{latLng:k(this.position)}),t.moveHandler=this.get("map").getDiv().addEventListener("mousemove",p=>{let g=t.get("origin"),d=g.clientX-p.clientX,f=g.clientY-p.clientY,b=t.getProjection().fromLatLngToDivPixel(t.position);if(b===null)return;let v=t.getProjection().fromDivPixelToLatLng(new l.Point(b.x-d,b.y-f));t.set("position",v),t.set("origin",p),t.draw(),s.onDrag(p,{latLng:k(v)});});}),this.container.addEventListener("mouseup",n=>{var m;(m=t.map)==null||m.set("draggable",!0),this.container.style.cursor="default",t.moveHandler&&(google.maps.event.removeListener(t.moveHandler),t.moveHandler=null),s.onDragEnd(n,{latLng:k(t.position)});}));let o=(u=this.getPanes())==null?void 0:u[this.pane];o==null||o.classList.add("google-map-markers-overlay"),o==null||o.appendChild(this.container);};draw=()=>{let o=this.getProjection().fromLatLngToDivPixel(this.position);o!==null&&(this.container.style.transform=`translate(${o.x}px, ${o.y}px)`,this.container.style.width="0px",this.container.style.height="0px");};onRemove=()=>{this.container.parentNode!==null&&(google.maps.event.clearInstanceListeners(this.container),this.container.parentNode.removeChild(this.container));};container;pane;position;map=this.getMap();moveHandler;constructor(t,o,u){super(),this.container=t,this.pane=o,this.position=u,this.moveHandler=null;}}return new i(e,r,a)},U=K;var ee=({pane:e="floatPane",position:r,map:a,maps:l,zIndex:s=0,children:i,drag:c})=>{let t=useMemo(()=>{let n=document.createElement("div");return n.style.position="absolute",n},[]),o=useMemo(()=>U({container:t,pane:e,position:r,maps:l,drag:c}),[t,c,l,e,r]),u=x(i==null?void 0:i.props,(n,m)=>n&&n.lat===m.lat&&n.lng===m.lng);return useEffect(()=>!o.map&&a?(o==null||o.setMap(a),()=>{o==null||o.setMap(null);}):()=>{},[a,u]),useEffect(()=>{t.style.zIndex=`${s}`;},[s,t]),createPortal(i,t)},G=ee;var P=()=>{},ae=({children:e,map:r,maps:a})=>{let l=useMemo(()=>!r||!a?[]:Children.map(e,s=>{if(isValidElement(s)){let i={lat:s.props.lat,lng:s.props.lng},{zIndex:c,draggable:t=!1,onDragStart:o=P,onDrag:u=P,onDragEnd:n=P}=s.props||{};return s=cloneElement(s,{...s.props,draggable:void 0,onDragStart:void 0,onDrag:void 0,onDragEnd:void 0}),jsx(G,{position:new a.LatLng(i.lat,i.lng),map:r,maps:a,zIndex:c,drag:{draggable:t,onDragStart:o,onDrag:u,onDragEnd:n},children:s})}return null}),[e,r,a]);return jsx("div",{children:l})},R=ae;function le({children:e=null,style:r={width:"100%",height:"100%",left:0,top:0,margin:0,padding:0,position:"absolute"},defaultCenter:a,defaultZoom:l,onGoogleApiLoaded:s,onChange:i,options:c={},events:t=[]}){let o=useRef(null),u=useRef(),[n,m]=useState(),[p,g]=useState(),[d,f]=useState(!1),b=useCallback(()=>{var v,y;try{if(!n)return;let E=n.getZoom()??l,M=n.getBounds(),F=[(v=n.getCenter())==null?void 0:v.lng(),(y=n.getCenter())==null?void 0:y.lat()],L=M==null?void 0:M.getNorthEast(),h=M==null?void 0:M.getSouthWest();if(!L||!h||!M)return;let D=[h.lng(),h.lat(),L.lng(),L.lat()];H(D,u.current)||(i&&i({zoom:E,center:F,bounds:M}),u.current=D);}catch(E){console.error(E);}},[n,i]);return useEffect(()=>{o.current&&!n&&(m(new google.maps.Map(o.current,{center:a,zoom:l,...c})),g(google.maps));},[a,l,n,o,c]),useEffect(()=>{n&&(d||(s&&p&&s({map:n,maps:p,ref:o.current}),f(!0)),google.maps.event.clearListeners(n,"idle"),google.maps.event.addListener(n,"idle",b));},[d,n,p,i,s,b]),useEffect(()=>()=>{n&&google.maps.event.clearListeners(n,"idle");},[n]),jsxs(Fragment,{children:[jsx("div",{ref:o,style:r,className:"google-map",...t==null?void 0:t.reduce((v,{name:y,handler:E})=>(v[y]=E,v),{})}),e&&n&&p&&jsx(R,{map:n,maps:p,children:e})]})}var q=le;var ue=forwardRef(({apiKey:e="",libraries:r=["places","geometry"],children:a=null,loadingContent:l="Google Maps is loading",idleContent:s="Google Maps is on idle",errorContent:i="Google Maps is on error",mapMinHeight:c="unset",containerProps:t={},loadScriptExternally:o=!1,status:u="idle",scriptCallback:n=()=>{},externalApiParams:m={},...p},g)=>{let d={ready:jsx(q,{...p,children:a}),loading:l,idle:s,error:i},f=T({apiKey:e,libraries:r,loadScriptExternally:o,status:u,externalApiParams:m,callback:n});return jsx("div",{ref:g,style:{height:"100%",width:"100%",overflow:"hidden",position:"relative",minHeight:c},...t,children:d[f]||null})}),B=ue;var Ve=B;
5
+ var S={};function Y(e){let r=document.querySelector(`script[src="${e}"]`),a=r==null?void 0:r.getAttribute("data-status");return {node:r,status:a}}function W(e={src:"",attributes:{},callbacks:{onLoadCallback:()=>{},onErrorCallback:()=>{}},elementIdToAppend:""},r,a={removeOnUnmount:!1,shouldPreventLoad:!1}){let[l,s]=useState(()=>!e.src||a!=null&&a.shouldPreventLoad?"idle":typeof window>"u"?"loading":S[e.src]??"loading");return useEffect(()=>{var u,n,m;if(r){s(r);return}if(!(e!=null&&e.src)||a!=null&&a.shouldPreventLoad)return;let i=S[e.src];if(i==="ready"||i==="error"){s(i);return}let c=Y(e.src),t=c.node;if(t){let p=c.status??i??"loading";switch(p){case"loading":case"ready":(n=e.callbacks)!=null&&n.onLoadCallback&&e.callbacks.onLoadCallback();break;case"error":(m=e.callbacks)!=null&&m.onErrorCallback&&e.callbacks.onErrorCallback();break;}s(p);}else {t=document.createElement("script"),t.src=e.src,t.async=!0,t.setAttribute("data-status","loading"),e.attributes&&Object.entries(e.attributes).length>0&&Object.entries(e.attributes).map(([g,d])=>t==null?void 0:t.setAttribute(g,d)),e.elementIdToAppend&&document.getElementById(e.elementIdToAppend)?(u=document.getElementById(e.elementIdToAppend))==null||u.appendChild(t):document.body.appendChild(t);let p=g=>{let d=g.type==="load"?"ready":"error";t==null||t.setAttribute("data-status",d);};t.addEventListener("load",p),t.addEventListener("error",p);}let o=p=>{var d,f;let g=p.type==="load"?"ready":"error";p.type==="load"?(d=e.callbacks)!=null&&d.onLoadCallback&&e.callbacks.onLoadCallback():(f=e.callbacks)!=null&&f.onErrorCallback&&e.callbacks.onErrorCallback(),s(g),S[e.src]=g;};return t.addEventListener("load",o),t.addEventListener("error",o),()=>{t&&(t.removeEventListener("load",o),t.removeEventListener("error",o)),t&&(a!=null&&a.removeOnUnmount)&&t.remove();}},[e,r,l]),l}var O=W;var T=({apiKey:e,libraries:r=[],loadScriptExternally:a=!1,status:l="idle",externalApiParams:s,callback:i})=>{var o;typeof window<"u"&&(window.googleMapsCallback=i);let c=(o=new URLSearchParams(s))==null?void 0:o.toString(),t=e?{src:`https://maps.googleapis.com/maps/api/js?key=${e}&callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}${c?`&${c}`:""}`,attributes:{id:"googleMapsApi"}}:{src:`https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${r==null?void 0:r.join(",")}`,attributes:{id:"googleMapsApi"}};return O(t,a?l:void 0)};var x=(e,r,a=1e-6)=>{if(e&&r){for(let l=0;l!==e.length;++l)if(Math.abs(e[l]-r[l])>a)return !1;return !0}return !1};var _=(e,r)=>{let a=useRef(),l=a.current,s=r(l,e);return useEffect(()=>{s||(a.current=e);}),s?l:e},H=_;var k=e=>{try{return {lat:e==null?void 0:e.lat(),lng:e==null?void 0:e.lng()}}catch{return e}},K=({container:e,pane:r,position:a,maps:l,drag:s})=>{class i extends google.maps.OverlayView{onAdd=()=>{var u;let t=this;s!=null&&s.draggable&&(this.get("map").getDiv().addEventListener("mouseleave",()=>{google.maps.event.trigger(this.container,"mouseup");}),this.container.addEventListener("mousedown",n=>{var m;this.container.style.cursor="grabbing",(m=t.map)==null||m.set("draggable",!1),t.set("origin",n),s.onDragStart(n,{latLng:k(this.position)}),t.moveHandler=this.get("map").getDiv().addEventListener("mousemove",p=>{let g=t.get("origin"),d=g.clientX-p.clientX,f=g.clientY-p.clientY,b=t.getProjection().fromLatLngToDivPixel(t.position);if(b===null)return;let v=t.getProjection().fromDivPixelToLatLng(new l.Point(b.x-d,b.y-f));t.set("position",v),t.set("origin",p),t.draw(),s.onDrag(p,{latLng:k(v)});});}),this.container.addEventListener("mouseup",n=>{var m;(m=t.map)==null||m.set("draggable",!0),this.container.style.cursor="default",t.moveHandler&&(google.maps.event.removeListener(t.moveHandler),t.moveHandler=null),s.onDragEnd(n,{latLng:k(t.position)});}));let o=(u=this.getPanes())==null?void 0:u[this.pane];o==null||o.classList.add("google-map-markers-overlay"),o==null||o.appendChild(this.container);};draw=()=>{let o=this.getProjection().fromLatLngToDivPixel(this.position);o!==null&&(this.container.style.transform=`translate(${o.x}px, ${o.y}px)`,this.container.style.width="0px",this.container.style.height="0px");};onRemove=()=>{this.container.parentNode!==null&&(google.maps.event.clearInstanceListeners(this.container),this.container.parentNode.removeChild(this.container));};container;pane;position;map=this.getMap();moveHandler;constructor(t,o,u){super(),this.container=t,this.pane=o,this.position=u,this.moveHandler=null;}}return new i(e,r,a)},U=K;var ee=({pane:e="floatPane",position:r,map:a,maps:l,zIndex:s=0,children:i,drag:c})=>{let t=useMemo(()=>{let n=document.createElement("div");return n.style.position="absolute",n},[]),o=useMemo(()=>U({container:t,pane:e,position:r,maps:l,drag:c}),[t,c,l,e,r]),u=H(i==null?void 0:i.props,(n,m)=>n&&n.lat===m.lat&&n.lng===m.lng);return useEffect(()=>!o.map&&a?(o==null||o.setMap(a),()=>{o==null||o.setMap(null);}):()=>{},[a,u]),useEffect(()=>{t.style.zIndex=`${s}`;},[s,t]),createPortal(i,t)},G=ee;var P=()=>{},ae=({children:e,map:r,maps:a})=>{let l=useMemo(()=>!r||!a?[]:Children.map(e,s=>{if(isValidElement(s)){let i={lat:s.props.lat,lng:s.props.lng},{zIndex:c,draggable:t=!1,onDragStart:o=P,onDrag:u=P,onDragEnd:n=P}=s.props||{};return s=cloneElement(s,{...s.props,draggable:void 0,onDragStart:void 0,onDrag:void 0,onDragEnd:void 0}),jsx(G,{position:new a.LatLng(i.lat,i.lng),map:r,maps:a,zIndex:c,drag:{draggable:t,onDragStart:o,onDrag:u,onDragEnd:n},children:s})}return null}),[e,r,a]);return jsx("div",{children:l})},R=ae;function le({children:e=null,style:r={width:"100%",height:"100%",left:0,top:0,margin:0,padding:0,position:"absolute"},defaultCenter:a,defaultZoom:l,onGoogleApiLoaded:s,onChange:i,options:c={},events:t=[]}){let o=useRef(null),u=useRef(),[n,m]=useState(),[p,g]=useState(),[d,f]=useState(!1),b=useCallback(()=>{var v,y;try{if(!n)return;let E=n.getZoom()??l,M=n.getBounds(),F=[(v=n.getCenter())==null?void 0:v.lng(),(y=n.getCenter())==null?void 0:y.lat()],L=M==null?void 0:M.getNorthEast(),h=M==null?void 0:M.getSouthWest();if(!L||!h||!M)return;let D=[h.lng(),h.lat(),L.lng(),L.lat()];x(D,u.current)||(i&&i({zoom:E,center:F,bounds:M}),u.current=D);}catch(E){console.error(E);}},[n,i]);return useEffect(()=>{o.current&&!n&&(m(new google.maps.Map(o.current,{center:a,zoom:l,...c})),g(google.maps));},[a,l,n,o,c]),useEffect(()=>{n&&(d||(s&&p&&s({map:n,maps:p,ref:o.current}),f(!0)),google.maps.event.clearListeners(n,"idle"),google.maps.event.addListener(n,"idle",b));},[d,n,p,i,s,b]),useEffect(()=>()=>{n&&google.maps.event.clearListeners(n,"idle");},[n]),jsxs(Fragment,{children:[jsx("div",{ref:o,style:r,className:"google-map",...t==null?void 0:t.reduce((v,{name:y,handler:E})=>(v[y]=E,v),{})}),e&&n&&p&&jsx(R,{map:n,maps:p,children:e})]})}var q=le;var ue=forwardRef(({apiKey:e="",libraries:r=["places","geometry"],children:a=null,loadingContent:l="Google Maps is loading",idleContent:s="Google Maps is on idle",errorContent:i="Google Maps is on error",mapMinHeight:c="unset",containerProps:t={},loadScriptExternally:o=!1,status:u="idle",scriptCallback:n=()=>{},externalApiParams:m={},...p},g)=>{let d={ready:jsx(q,{...p,children:a}),loading:l,idle:s,error:i},f=T({apiKey:e,libraries:r,loadScriptExternally:o,status:u,externalApiParams:m,callback:n});return jsx("div",{ref:g,style:{height:"100%",width:"100%",overflow:"hidden",position:"relative",minHeight:c},...t,children:d[f]||null})}),B=ue;var Ve=B;
6
6
 
7
7
  export { Ve as default };
8
8
  //# sourceMappingURL=out.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/google-map.tsx","../src/map/hooks/useScript.ts","../src/map/hooks/useGoogleMaps.ts","../src/map/map.tsx","../src/utils/utils.ts","../src/map/markers.tsx","../src/map/overlay-view.tsx","../src/map/hooks/useMemoCompare.ts","../src/map/overlay.tsx","../src/index.ts"],"names":["forwardRef","useEffect","useState","cachedScriptStatuses","getScriptNode","src","node","status","useScript","script","forcedStatus","options","setStatus","_a","_b","_c","cachedScriptStatus","scriptToAdd","scriptNode","currentScriptStatus","key","value","setAttributeFromEvent","event","scriptStatus","setStateFromEvent","newStatus","useScript_default","useGoogleMaps","apiKey","libraries","loadScriptExternally","externalApiParams","callback","apiParams","useCallback","useRef","isArraysEqualEps","arrayA","arrayB","eps","i","Children","cloneElement","isValidElement","useMemo","createPortal","useMemoCompare","next","compare","previousRef","previous","isEqual","useMemoCompare_default","getLatLng","LatLng","createOverlay","container","pane","position","maps","drag","Overlay","that","e","evt","origin","left","top","pos","latLng","currentPane","point","overlay_default","OverlayView","map","zIndex","children","div","overlay","childrenProps","prev","overlay_view_default","jsx","noop","MapMarkers","markers","child","draggable","onDragStart","onDrag","onDragEnd","markers_default","Fragment","jsxs","MapComponent","style","defaultCenter","defaultZoom","onGoogleApiLoaded","onChange","events","mapRef","prevBoundsRef","setMap","setMaps","googleApiCalled","setGoogleApiCalled","onIdle","zoom","bounds","centerLatLng","ne","sw","boundsArray","acc","name","handler","map_default","GoogleMap","loadingContent","idleContent","errorContent","mapMinHeight","containerProps","statusProp","scriptCallback","props","ref","renderers","google_map_default","src_default"],"mappings":"AAAA,OAAS,cAAAA,OAAkB,QCC3B,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QAIpC,IAAMC,EAAoE,CAAC,EAE3E,SAASC,EAAcC,EAAa,CACnC,IAAMC,EAAiC,SAAS,cAAc,eAAeD,CAAG,IAAI,EAC9EE,EAASD,GAAA,YAAAA,EAAM,aAAa,eAElC,MAAO,CACN,KAAAA,EACA,OAAAC,CACD,CACD,CAyBA,SAASC,EAERC,EAAsB,CACrB,IAAK,GACL,WAAY,CAAC,EACb,UAAW,CAAE,eAAgB,IAAM,CAAC,EAAG,gBAAiB,IAAM,CAAC,CAAE,EACjE,kBAAmB,EACpB,EACAC,EACAC,EAA4B,CAAE,gBAAiB,GAAO,kBAAmB,EAAM,EACtC,CACzC,GAAM,CAACJ,EAAQK,CAAS,EAAIV,EAA0B,IACjD,CAACO,EAAO,KAAOE,GAAA,MAAAA,EAAS,kBACpB,OA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vH,GACjB,CACC,CACC,OAAA6B,EAAS,GACT,UAAAC,EAAY,CAAC,SAAU,UAAU,EACjC,SAAA+C,EAAW,KACX,eAAA2C,EAAiB,yBACjB,YAAAC,EAAc,yBACd,aAAAC,EAAe,0BACf,aAAAC,EAAe,QACf,eAAAC,EAAiB,CAAC,EAClB,qBAAA7F,EAAuB,GACvB,OAAQ8F,EAAa,OACrB,eAAAC,EAAiB,IAAM,CAAC,EACxB,kBAAA9F,EAAoB,CAAC,EACrB,GAAG+F,CACJ,EACAC,IACI,CACJ,IAAMC,EAAY,CACjB,MAAO9C,EAACmC,EAAA,CAAc,GAAGS,EAAQ,SAAAlD,EAAS,EAC1C,QAAS2C,EACT,KAAMC,EACN,MAAOC,CACR,EAEMnH,EAASqB,EAAc,CAC5B,OAAAC,EACA,UAAAC,EACA,qBAAAC,EACA,OAAQ8F,EACR,kBAAA7F,EACA,SAAU8F,CACX,CAAC,EAED,OACC3C,EAAC,OACA,IAAK6C,EACL,MAAO,CAAE,OAAQ,OAAQ,MAAO,OAAQ,SAAU,SAAU,SAAU,WAAY,UAAWL,CAAa,EACzG,GAAGC,EAEH,SAAAK,EAAU1H,CAAM,GAAK,KACvB,CAEF,CACD,EAEO2H,EAAQX,GSlDf,IAAOY,GAAQD","sourcesContent":["import { forwardRef } from 'react'\nimport { useGoogleMaps } from './map/hooks/useGoogleMaps'\nimport MapComponent from './map/map'\nimport { GoogleMapProps } from './utils/types'\n\nconst GoogleMap = forwardRef<HTMLDivElement, GoogleMapProps>(\n\t(\n\t\t{\n\t\t\tapiKey = '',\n\t\t\tlibraries = ['places', 'geometry'],\n\t\t\tchildren = null,\n\t\t\tloadingContent = 'Google Maps is loading',\n\t\t\tidleContent = 'Google Maps is on idle',\n\t\t\terrorContent = 'Google Maps is on error',\n\t\t\tmapMinHeight = 'unset',\n\t\t\tcontainerProps = {},\n\t\t\tloadScriptExternally = false,\n\t\t\tstatus: statusProp = 'idle',\n\t\t\tscriptCallback = () => {},\n\t\t\texternalApiParams = {},\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst renderers = {\n\t\t\tready: <MapComponent {...props}>{children}</MapComponent>,\n\t\t\tloading: loadingContent,\n\t\t\tidle: idleContent,\n\t\t\terror: errorContent,\n\t\t}\n\n\t\tconst status = useGoogleMaps({\n\t\t\tapiKey,\n\t\t\tlibraries,\n\t\t\tloadScriptExternally,\n\t\t\tstatus: statusProp,\n\t\t\texternalApiParams,\n\t\t\tcallback: scriptCallback,\n\t\t})\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tstyle={{ height: '100%', width: '100%', overflow: 'hidden', position: 'relative', minHeight: mapMinHeight }}\n\t\t\t\t{...containerProps}\n\t\t\t>\n\t\t\t\t{renderers[status] || null}\n\t\t\t</div>\n\t\t)\n\t},\n)\n\nexport default GoogleMap\n","/* eslint-disable no-unused-expressions */\nimport { useEffect, useState } from 'react'\nimport { ScriptProps, UseScriptOptions, UseScriptStatus } from '../../utils/types'\n\n// Cached script statuses\nconst cachedScriptStatuses: Record<string, UseScriptStatus | undefined> = {}\n\nfunction getScriptNode(src: string) {\n\tconst node: HTMLScriptElement | null = document.querySelector(`script[src=\"${src}\"]`)\n\tconst status = node?.getAttribute('data-status') as UseScriptStatus | undefined\n\n\treturn {\n\t\tnode,\n\t\tstatus,\n\t}\n}\n\n/**\n * @description Hook to load external script.\n * @param {Object} script - Script to load.\n * @param {string} script.src - Script source.\n * @param {Object} [script.attributes] - Attributes to add to the script tag.\n * @param {Object} [script.callbacks] - Callbacks executed on completion.\n * @param {Function} [script.callbacks.onLoadCallback] - Callback executed on completion in case of success.\n * @param {Function} [script.callbacks.onErrorCallback] - Callbacks executed on completion in case of error.\n * @param {string} [script.elementIdToAppend] - HTML element id to append the script to. Default is HTML HEAD.\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n *\n * @example\n * const status = useScript({\n * \t\tsrc: \"https://script-to-load.js\",\n * \t\tattributes: { id: \"scriptId\", class: \"script-class\" },\n * \t\tcallbacks: {\n * \t\t\tonLoadCallback: onLoadFunc,\n * \t\t\tonErrorCallback: onErrorFunc,\n * \t\t},\n * \t\telementIdToAppend: \"script-container\"\n * }, undefined, { removeOnUnmount: true, shouldPreventLoad: false })\n */\n\nfunction useScript(\n\t// eslint-disable-next-line default-param-last\n\tscript: ScriptProps = {\n\t\tsrc: '',\n\t\tattributes: {},\n\t\tcallbacks: { onLoadCallback: () => {}, onErrorCallback: () => {} },\n\t\telementIdToAppend: '',\n\t},\n\tforcedStatus?: UseScriptStatus,\n\toptions: UseScriptOptions = { removeOnUnmount: false, shouldPreventLoad: false },\n): 'idle' | 'loading' | 'ready' | 'error' {\n\tconst [status, setStatus] = useState<UseScriptStatus>(() => {\n\t\tif (!script.src || options?.shouldPreventLoad) {\n\t\t\treturn 'idle'\n\t\t}\n\n\t\tif (typeof window === 'undefined') {\n\t\t\t// SSR Handling - always return 'loading'\n\t\t\treturn 'loading'\n\t\t}\n\n\t\treturn cachedScriptStatuses[script.src] ?? 'loading'\n\t})\n\n\tuseEffect(\n\t\t() => {\n\t\t\tif (forcedStatus) {\n\t\t\t\tsetStatus(forcedStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (!script?.src || options?.shouldPreventLoad) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst cachedScriptStatus = cachedScriptStatuses[script.src]\n\t\t\tif (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {\n\t\t\t\t// If the script is already cached, set its status immediately\n\t\t\t\tsetStatus(cachedScriptStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Fetch existing script element by src\n\t\t\t// It may have been added by another instance of this hook\n\t\t\tconst scriptToAdd = getScriptNode(script.src)\n\t\t\tlet scriptNode = scriptToAdd.node\n\n\t\t\tif (!scriptNode) {\n\t\t\t\t// Create script element and add it to document body\n\t\t\t\tscriptNode = document.createElement('script')\n\t\t\t\tscriptNode.src = script.src\n\t\t\t\tscriptNode.async = true\n\t\t\t\tscriptNode.setAttribute('data-status', 'loading')\n\t\t\t\t// Add other script attributes, if they exist\n\t\t\t\tscript.attributes && Object.entries(script.attributes).length > 0\n\t\t\t\t\t? Object.entries(script.attributes).map(([key, value]) => scriptNode?.setAttribute(key, value))\n\t\t\t\t\t: null\n\t\t\t\tif (script.elementIdToAppend && document.getElementById(script.elementIdToAppend)) {\n\t\t\t\t\tdocument.getElementById(script.elementIdToAppend)?.appendChild(scriptNode)\n\t\t\t\t} else {\n\t\t\t\t\tdocument.body.appendChild(scriptNode)\n\t\t\t\t}\n\n\t\t\t\t// Store status in attribute on script\n\t\t\t\t// This can be read by other instances of this hook\n\t\t\t\tconst setAttributeFromEvent = (event: Event) => {\n\t\t\t\t\tconst scriptStatus: UseScriptStatus = event.type === 'load' ? 'ready' : 'error'\n\n\t\t\t\t\tscriptNode?.setAttribute('data-status', scriptStatus)\n\t\t\t\t}\n\n\t\t\t\tscriptNode.addEventListener('load', setAttributeFromEvent)\n\t\t\t\tscriptNode.addEventListener('error', setAttributeFromEvent)\n\t\t\t} else {\n\t\t\t\t// Grab existing script status from attribute and set to state.\n\t\t\t\tconst currentScriptStatus = scriptToAdd.status ?? cachedScriptStatus ?? 'loading'\n\n\t\t\t\tswitch (currentScriptStatus) {\n\t\t\t\t\tcase 'loading':\n\t\t\t\t\tcase 'ready':\n\t\t\t\t\t\tscript.callbacks?.onLoadCallback ? script.callbacks.onLoadCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\tscript.callbacks?.onErrorCallback ? script.callbacks.onErrorCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// loading: do nothing\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tsetStatus(currentScriptStatus)\n\t\t\t}\n\n\t\t\t// Script event handler to update status in state\n\t\t\t// Note: Even if the script already exists we still need to add\n\t\t\t// event handlers to update the state for this hook instance.\n\t\t\tconst setStateFromEvent = (event: Event) => {\n\t\t\t\tconst newStatus = event.type === 'load' ? 'ready' : 'error'\n\t\t\t\tevent.type === 'load'\n\t\t\t\t\t? script.callbacks?.onLoadCallback\n\t\t\t\t\t\t? script.callbacks.onLoadCallback()\n\t\t\t\t\t\t: null\n\t\t\t\t\t: script.callbacks?.onErrorCallback\n\t\t\t\t\t? script.callbacks.onErrorCallback()\n\t\t\t\t\t: null\n\n\t\t\t\tsetStatus(newStatus)\n\t\t\t\tcachedScriptStatuses[script.src] = newStatus\n\t\t\t}\n\t\t\t// Add event listeners\n\t\t\tscriptNode.addEventListener('load', setStateFromEvent)\n\t\t\tscriptNode.addEventListener('error', setStateFromEvent)\n\t\t\t// Remove event listeners on cleanup\n\t\t\t// eslint-disable-next-line consistent-return\n\t\t\treturn () => {\n\t\t\t\tif (scriptNode) {\n\t\t\t\t\tscriptNode.removeEventListener('load', setStateFromEvent)\n\t\t\t\t\tscriptNode.removeEventListener('error', setStateFromEvent)\n\t\t\t\t}\n\n\t\t\t\tif (scriptNode && options?.removeOnUnmount) {\n\t\t\t\t\tscriptNode.remove()\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Re-run useEffect if script changes\n\t\t[script, forcedStatus, status],\n\t)\n\n\treturn status\n}\n\nexport default useScript\n","import { IUseGoogleMaps, UseScriptStatus } from '../../utils/types'\nimport useScript from './useScript'\n\n/**\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n */\nexport const useGoogleMaps = ({\n\tapiKey,\n\tlibraries = [],\n\tloadScriptExternally = false,\n\tstatus = 'idle',\n\texternalApiParams,\n\tcallback,\n}: IUseGoogleMaps): UseScriptStatus => {\n\tif (typeof window !== 'undefined') window.googleMapsCallback = callback\n\tconst apiParams = new URLSearchParams(externalApiParams)?.toString()\n\tconst script = apiKey\n\t\t? {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=googleMapsCallback&libraries=${libraries?.join(\n\t\t\t\t\t',',\n\t\t\t\t)}${apiParams ? `&${apiParams}` : ''}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\t\t: {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${libraries?.join(',')}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\n\treturn useScript(script, loadScriptExternally ? status : undefined)\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport { EventProps, Map, MapProps, MapsLibrary } from '../utils/types'\nimport { isArraysEqualEps } from '../utils/utils'\nimport MapMarkers from './markers'\n\nfunction MapComponent({\n\tchildren = null,\n\tstyle = {\n\t\twidth: '100%',\n\t\theight: '100%',\n\t\tleft: 0,\n\t\ttop: 0,\n\t\tmargin: 0,\n\t\tpadding: 0,\n\t\tposition: 'absolute',\n\t},\n\tdefaultCenter,\n\tdefaultZoom,\n\tonGoogleApiLoaded,\n\tonChange,\n\toptions = {},\n\tevents = [],\n}: MapProps) {\n\tconst mapRef = useRef<HTMLDivElement>(null)\n\tconst prevBoundsRef = useRef<number[] | undefined>()\n\tconst [map, setMap] = useState<Map>()\n\tconst [maps, setMaps] = useState<MapsLibrary>()\n\tconst [googleApiCalled, setGoogleApiCalled] = useState<boolean>(false)\n\n\tconst onIdle = useCallback(() => {\n\t\ttry {\n\t\t\tif (!map) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst zoom = map.getZoom() ?? defaultZoom\n\t\t\tconst bounds = map.getBounds()\n\t\t\tconst centerLatLng = [map.getCenter()?.lng(), map.getCenter()?.lat()]\n\n\t\t\tconst ne = bounds?.getNorthEast()\n\t\t\tconst sw = bounds?.getSouthWest()\n\n\t\t\tif (!ne || !sw || !bounds) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// east, north, south, west\n\t\t\tconst boundsArray = [sw.lng(), sw.lat(), ne.lng(), ne.lat()]\n\n\t\t\tif (!isArraysEqualEps(boundsArray, prevBoundsRef.current)) {\n\t\t\t\tif (onChange) {\n\t\t\t\t\tonChange({\n\t\t\t\t\t\tzoom,\n\t\t\t\t\t\tcenter: centerLatLng,\n\t\t\t\t\t\tbounds,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tprevBoundsRef.current = boundsArray\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(e)\n\t\t}\n\t}, [map, onChange])\n\n\tuseEffect(() => {\n\t\tif (mapRef.current && !map) {\n\t\t\tsetMap(\n\t\t\t\tnew google.maps.Map(mapRef.current as HTMLElement, {\n\t\t\t\t\tcenter: defaultCenter,\n\t\t\t\t\tzoom: defaultZoom,\n\t\t\t\t\t...(options as google.maps.MapOptions),\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsetMaps(google.maps)\n\t\t}\n\t}, [defaultCenter, defaultZoom, map, mapRef, options])\n\n\tuseEffect(() => {\n\t\tif (map) {\n\t\t\tif (!googleApiCalled) {\n\t\t\t\tif (onGoogleApiLoaded && maps) onGoogleApiLoaded({ map, maps, ref: mapRef.current })\n\t\t\t\tsetGoogleApiCalled(true)\n\t\t\t}\n\n\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t// Idle event is fired when the map becomes idle after panning or zooming.\n\t\t\tgoogle.maps.event.addListener(map, 'idle', onIdle)\n\t\t}\n\t}, [googleApiCalled, map, maps, onChange, onGoogleApiLoaded, onIdle])\n\n\tuseEffect(\n\t\t() =>\n\t\t\t// clear listeners on unmount\n\t\t\t() => {\n\t\t\t\tif (map) {\n\t\t\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t\t}\n\t\t\t},\n\t\t[map],\n\t)\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={mapRef}\n\t\t\t\tstyle={style}\n\t\t\t\tclassName=\"google-map\"\n\t\t\t\t// spread the events as props\n\t\t\t\t{...events?.reduce(\n\t\t\t\t\t(acc, { name, handler }: EventProps) => {\n\t\t\t\t\t\tacc[name] = handler\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t},\n\t\t\t\t\t{} as { [key: string]: any },\n\t\t\t\t)}\n\t\t\t/>\n\t\t\t{children && map && maps && (\n\t\t\t\t<MapMarkers map={map} maps={maps}>\n\t\t\t\t\t{children}\n\t\t\t\t</MapMarkers>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nexport default MapComponent\n","export const isArraysEqualEps = (arrayA: number[], arrayB?: number[], eps = 0.000001): boolean => {\n\tif (arrayA && arrayB) {\n\t\tfor (let i = 0; i !== arrayA.length; ++i) {\n\t\t\tif (Math.abs(arrayA[i] - arrayB[i]) > eps) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\treturn false\n}\n","import { Children, cloneElement, isValidElement, useMemo } from 'react'\nimport { MapMarkersProps } from '../utils/types'\nimport OverlayView from './overlay-view'\n\nconst noop = () => {}\n\nconst MapMarkers = ({ children, map, maps }: MapMarkersProps) => {\n\tconst markers = useMemo(() => {\n\t\tif (!map || !maps) return []\n\n\t\treturn Children.map(children, (child) => {\n\t\t\tif (isValidElement(child)) {\n\t\t\t\tconst latLng = { lat: child.props.lat, lng: child.props.lng } as google.maps.LatLngLiteral\n\t\t\t\tconst { zIndex, draggable = false, onDragStart = noop, onDrag = noop, onDragEnd = noop } = child.props || {}\n\n\t\t\t\t// clone child without draggable props\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\tchild = cloneElement(child, {\n\t\t\t\t\t...child.props,\n\t\t\t\t\tdraggable: undefined,\n\t\t\t\t\tonDragStart: undefined,\n\t\t\t\t\tonDrag: undefined,\n\t\t\t\t\tonDragEnd: undefined,\n\t\t\t\t})\n\n\t\t\t\treturn (\n\t\t\t\t\t<OverlayView\n\t\t\t\t\t\tposition={new maps.LatLng(latLng.lat, latLng.lng)}\n\t\t\t\t\t\tmap={map}\n\t\t\t\t\t\tmaps={maps}\n\t\t\t\t\t\tzIndex={zIndex}\n\t\t\t\t\t\tdrag={{\n\t\t\t\t\t\t\tdraggable,\n\t\t\t\t\t\t\tonDragStart,\n\t\t\t\t\t\t\tonDrag,\n\t\t\t\t\t\t\tonDragEnd,\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{child}\n\t\t\t\t\t</OverlayView>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn null\n\t\t})\n\t}, [children, map, maps])\n\n\treturn <div>{markers}</div>\n}\n\nexport default MapMarkers\n","import { useEffect, useMemo } from 'react'\nimport { createPortal } from 'react-dom'\nimport { OverlayViewProps } from '../utils/types'\nimport useMemoCompare from './hooks/useMemoCompare'\nimport createOverlay from './overlay'\n\nconst OverlayView = ({ pane = 'floatPane', position, map, maps, zIndex = 0, children, drag }: OverlayViewProps) => {\n\tconst container = useMemo<HTMLDivElement>(() => {\n\t\t// eslint-disable-next-line no-undef\n\t\tconst div = document.createElement('div') as HTMLDivElement\n\t\tdiv.style.position = 'absolute'\n\t\treturn div as HTMLDivElement\n\t}, [])\n\n\tconst overlay = useMemo(\n\t\t() => createOverlay({ container, pane, position, maps, drag }),\n\t\t[container, drag, maps, pane, position],\n\t)\n\n\t// Because React does not do deep comparisons, a custom hook is used.\n\t// This fixes the issue where the overlay is not updated when the position changes.\n\tconst childrenProps = useMemoCompare(\n\t\tchildren?.props as any,\n\t\t(prev: { lat: any; lng: any }, next: { lat: any; lng: any }) =>\n\t\t\tprev && prev.lat === next.lat && prev.lng === next.lng,\n\t)\n\n\tuseEffect(() => {\n\t\tif (!overlay.map && map) {\n\t\t\toverlay?.setMap(map)\n\t\t\treturn () => {\n\t\t\t\toverlay?.setMap(null)\n\t\t\t}\n\t\t}\n\t\treturn () => {}\n\t\t// overlay depends on map, so we don't need to add it to the dependency array\n\t\t// otherwise, it will re-render the overlay every time the map changes\n\t\t// ? added childrenProps to the dependency array to re-render the overlay when the children props change.\n\t}, [map, childrenProps])\n\n\t// to move the container to the foreground and background\n\tuseEffect(() => {\n\t\tcontainer.style.zIndex = `${zIndex}`\n\t}, [zIndex, container])\n\n\treturn createPortal(children, container)\n}\n\nexport default OverlayView\n","import { useEffect, useRef } from 'react'\n\n/**\n * A hook that compares the previous and current values of a reference.\n * @param {any} next - the current value of the reference\n * @param {function} compare - a function that compares the previous and current values\n * @returns {any} the previous value of the reference\n * @ref https://usehooks.com/useMemoCompare/\n */\nconst useMemoCompare = (next: any, compare: Function): any => {\n\t// Ref for storing previous value\n\tconst previousRef = useRef()\n\tconst previous = previousRef.current\n\t// Pass previous and next value to compare function\n\t// to determine whether to consider them equal.\n\tconst isEqual = compare(previous, next)\n\t// If not equal update previousRef to next value.\n\t// We only update if not equal so that this hook continues to return\n\t// the same old value if compare keeps returning true.\n\tuseEffect(() => {\n\t\tif (!isEqual) {\n\t\t\tpreviousRef.current = next\n\t\t}\n\t})\n\t// Finally, if equal then return the previous value\n\treturn isEqual ? previous : next\n}\n\nexport default useMemoCompare\n","import { Pane, createOverlayProps } from '../utils/types'\n\n// return lat, lng from LatLngLiteral\nconst getLatLng = (LatLng: google.maps.LatLng | null) => {\n\ttry {\n\t\tconst latLng = { lat: LatLng?.lat(), lng: LatLng?.lng() } as google.maps.LatLngLiteral\n\t\treturn latLng\n\t} catch (e) {\n\t\treturn LatLng\n\t}\n}\n\nconst createOverlay = ({ container, pane, position, maps, drag }: createOverlayProps) => {\n\tclass Overlay extends google.maps.OverlayView {\n\t\t/**\n\t\t * onAdd is called when the map's panes are ready and the overlay has been\n\t\t * added to the map.\n\t\t */\n\t\tonAdd = () => {\n\t\t\tconst that = this\n\t\t\t// manage draggable\n\t\t\tif (drag?.draggable) {\n\t\t\t\tthis.get('map')\n\t\t\t\t\t.getDiv()\n\t\t\t\t\t.addEventListener('mouseleave', () => {\n\t\t\t\t\t\tgoogle.maps.event.trigger(this.container, 'mouseup')\n\t\t\t\t\t})\n\t\t\t\tthis.container.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\t\t\tthis.container.style.cursor = 'grabbing'\n\t\t\t\t\tthat.map?.set('draggable', false)\n\t\t\t\t\tthat.set('origin', e)\n\n\t\t\t\t\tdrag.onDragStart(e, { latLng: getLatLng(this.position) })\n\n\t\t\t\t\t// eslint-disable-next-line no-shadow\n\t\t\t\t\tthat.moveHandler = this.get('map')\n\t\t\t\t\t\t.getDiv()\n\t\t\t\t\t\t.addEventListener('mousemove', (evt: MouseEvent) => {\n\t\t\t\t\t\t\tconst origin = that.get('origin')\n\t\t\t\t\t\t\tconst left = origin.clientX - evt.clientX\n\t\t\t\t\t\t\tconst top = origin.clientY - evt.clientY\n\t\t\t\t\t\t\tconst pos = that.getProjection().fromLatLngToDivPixel(that.position)\n\t\t\t\t\t\t\tif (pos === null) return\n\t\t\t\t\t\t\tconst latLng = that.getProjection().fromDivPixelToLatLng(new maps.Point(pos.x - left, pos.y - top))\n\t\t\t\t\t\t\tthat.set('position', latLng)\n\t\t\t\t\t\t\tthat.set('origin', evt)\n\t\t\t\t\t\t\tthat.draw()\n\t\t\t\t\t\t\tdrag.onDrag(evt, { latLng: getLatLng(latLng) })\n\t\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tthis.container.addEventListener('mouseup', (e) => {\n\t\t\t\t\tthat.map?.set('draggable', true)\n\t\t\t\t\tthis.container.style.cursor = 'default'\n\t\t\t\t\tif (that.moveHandler) {\n\t\t\t\t\t\tgoogle.maps.event.removeListener(that.moveHandler)\n\t\t\t\t\t\tthat.moveHandler = null\n\t\t\t\t\t}\n\t\t\t\t\tdrag.onDragEnd(e, { latLng: getLatLng(that.position) })\n\t\t\t\t})\n\t\t\t}\n\t\t\t// Add the element to the pane.\n\t\t\tconst currentPane = this.getPanes()?.[this.pane] as HTMLElement\n\t\t\tcurrentPane?.classList.add('google-map-markers-overlay')\n\t\t\tcurrentPane?.appendChild(this.container)\n\t\t}\n\n\t\tdraw = () => {\n\t\t\tconst projection = this.getProjection() as google.maps.MapCanvasProjection\n\t\t\t// Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.\n\t\t\tconst point = projection.fromLatLngToDivPixel(this.position) as google.maps.Point\n\t\t\tif (point === null) return\n\t\t\tthis.container.style.transform = `translate(${point.x}px, ${point.y}px)`\n\t\t\tthis.container.style.width = '0px'\n\t\t\tthis.container.style.height = '0px'\n\t\t}\n\n\t\t/**\n\t\t * The onRemove() method will be called automatically from the API if\n\t\t * we ever set the overlay's map property to 'null'.\n\t\t */\n\t\tonRemove = () => {\n\t\t\tif (this.container.parentNode !== null) {\n\t\t\t\t// remove DOM listeners\n\t\t\t\tgoogle.maps.event.clearInstanceListeners(this.container)\n\t\t\t\tthis.container.parentNode.removeChild(this.container)\n\t\t\t}\n\t\t}\n\n\t\tpublic container: HTMLDivElement\n\n\t\tpublic pane: Pane\n\n\t\tpublic position: google.maps.LatLng\n\n\t\tpublic map = this.getMap()\n\n\t\tpublic moveHandler: google.maps.MapsEventListener | null\n\n\t\t// eslint-disable-next-line no-shadow\n\t\tconstructor(container: HTMLDivElement, pane: Pane, position: google.maps.LatLng) {\n\t\t\tsuper()\n\n\t\t\t// Initialize all properties.\n\t\t\tthis.container = container\n\t\t\tthis.pane = pane\n\t\t\tthis.position = position\n\n\t\t\tthis.moveHandler = null\n\t\t}\n\t}\n\n\treturn new Overlay(container, pane, position)\n}\n\nexport default createOverlay\n","import GoogleMap from './google-map'\n\nexport default GoogleMap\n"]}
1
+ {"version":3,"sources":["../src/google-map.tsx","../src/map/hooks/useScript.ts","../src/map/hooks/useGoogleMaps.ts","../src/map/map.tsx","../src/utils/utils.ts","../src/map/markers.tsx","../src/map/overlay-view.tsx","../src/map/hooks/useMemoCompare.ts","../src/map/overlay.tsx","../src/index.ts"],"names":["forwardRef","useEffect","useState","cachedScriptStatuses","getScriptNode","src","node","status","useScript","script","forcedStatus","options","setStatus","_a","_b","_c","cachedScriptStatus","scriptToAdd","scriptNode","currentScriptStatus","key","value","setAttributeFromEvent","event","scriptStatus","setStateFromEvent","newStatus","useScript_default","useGoogleMaps","apiKey","libraries","loadScriptExternally","externalApiParams","callback","apiParams","useCallback","useRef","isArraysEqualEps","arrayA","arrayB","eps","i","Children","cloneElement","isValidElement","useMemo","createPortal","useMemoCompare","next","compare","previousRef","previous","isEqual","useMemoCompare_default","getLatLng","LatLng","createOverlay","container","pane","position","maps","drag","Overlay","that","e","evt","origin","left","top","pos","latLng","currentPane","point","overlay_default","OverlayView","map","zIndex","children","div","overlay","childrenProps","prev","overlay_view_default","jsx","noop","MapMarkers","markers","child","draggable","onDragStart","onDrag","onDragEnd","markers_default","Fragment","jsxs","MapComponent","style","defaultCenter","defaultZoom","onGoogleApiLoaded","onChange","events","mapRef","prevBoundsRef","setMap","setMaps","googleApiCalled","setGoogleApiCalled","onIdle","zoom","bounds","centerLatLng","ne","sw","boundsArray","acc","name","handler","map_default","GoogleMap","loadingContent","idleContent","errorContent","mapMinHeight","containerProps","statusProp","scriptCallback","props","ref","renderers","google_map_default","src_default"],"mappings":"AAAA,OAAS,cAAAA,OAAkB,QCC3B,OAAS,aAAAC,EAAW,YAAAC,MAAgB,QAIpC,IAAMC,EAAoE,CAAC,EAE3E,SAASC,EAAcC,EAAa,CACnC,IAAMC,EAAiC,SAAS,cAAc,eAAeD,CAAG,IAAI,EAC9EE,EAASD,GAAA,YAAAA,EAAM,aAAa,eAElC,MAAO,CACN,KAAAA,EACA,OAAAC,CACD,CACD,CAyBA,SAASC,EAERC,EAAsB,CACrB,IAAK,GACL,WAAY,CAAC,EACb,UAAW,CAAE,eAAgB,IAAM,CAAC,EAAG,gBAAiB,IAAM,CAAC,CAAE,EACjE,kBAAmB,EACpB,EACAC,EACAC,EAA4B,CAAE,gBAAiB,GAAO,kBAAmB,EAAM,EACtC,CACzC,GAAM,CAACJ,EAAQK,CAAS,EAAIV,EAA0B,IACjD,CAACO,EAAO,KAAOE,GAAA,MAAAA,EAAS,kBACpB,OAGJ,OAAO,OAAW,IAEd,UAGDR,EAAqBM,EAAO,GAAG,GAAK,SAC3C,EAED,OAAAR,EACC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A+C,EAAW,KACX,eAAA2C,EAAiB,yBACjB,YAAAC,EAAc,yBACd,aAAAC,EAAe,0BACf,aAAAC,EAAe,QACf,eAAAC,EAAiB,CAAC,EAClB,qBAAA7F,EAAuB,GACvB,OAAQ8F,EAAa,OACrB,eAAAC,EAAiB,IAAM,CAAC,EACxB,kBAAA9F,EAAoB,CAAC,EACrB,GAAG+F,CACJ,EACAC,IACI,CACJ,IAAMC,EAAY,CACjB,MAAO9C,EAACmC,EAAA,CAAc,GAAGS,EAAQ,SAAAlD,EAAS,EAC1C,QAAS2C,EACT,KAAMC,EACN,MAAOC,CACR,EAEMnH,EAASqB,EAAc,CAC5B,OAAAC,EACA,UAAAC,EACA,qBAAAC,EACA,OAAQ8F,EACR,kBAAA7F,EACA,SAAU8F,CACX,CAAC,EAED,OACC3C,EAAC,OACA,IAAK6C,EACL,MAAO,CAAE,OAAQ,OAAQ,MAAO,OAAQ,SAAU,SAAU,SAAU,WAAY,UAAWL,CAAa,EACzG,GAAGC,EAEH,SAAAK,EAAU1H,CAAM,GAAK,KACvB,CAEF,CACD,EAEO2H,EAAQX,GShDf,IAAOY,GAAQD","sourcesContent":["import { forwardRef } from 'react'\nimport { useGoogleMaps } from './map/hooks/useGoogleMaps'\nimport MapComponent from './map/map'\nimport { GoogleMapProps } from './utils/types'\n\nconst GoogleMap = forwardRef<HTMLDivElement, GoogleMapProps>(\n\t(\n\t\t{\n\t\t\tapiKey = '',\n\t\t\tlibraries = ['places', 'geometry'],\n\t\t\tchildren = null,\n\t\t\tloadingContent = 'Google Maps is loading',\n\t\t\tidleContent = 'Google Maps is on idle',\n\t\t\terrorContent = 'Google Maps is on error',\n\t\t\tmapMinHeight = 'unset',\n\t\t\tcontainerProps = {},\n\t\t\tloadScriptExternally = false,\n\t\t\tstatus: statusProp = 'idle',\n\t\t\tscriptCallback = () => {},\n\t\t\texternalApiParams = {},\n\t\t\t...props\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst renderers = {\n\t\t\tready: <MapComponent {...props}>{children}</MapComponent>,\n\t\t\tloading: loadingContent,\n\t\t\tidle: idleContent,\n\t\t\terror: errorContent,\n\t\t}\n\n\t\tconst status = useGoogleMaps({\n\t\t\tapiKey,\n\t\t\tlibraries,\n\t\t\tloadScriptExternally,\n\t\t\tstatus: statusProp,\n\t\t\texternalApiParams,\n\t\t\tcallback: scriptCallback,\n\t\t})\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tref={ref}\n\t\t\t\tstyle={{ height: '100%', width: '100%', overflow: 'hidden', position: 'relative', minHeight: mapMinHeight }}\n\t\t\t\t{...containerProps}\n\t\t\t>\n\t\t\t\t{renderers[status] || null}\n\t\t\t</div>\n\t\t)\n\t},\n)\n\nexport default GoogleMap\n","/* eslint-disable no-unused-expressions */\nimport { useEffect, useState } from 'react'\nimport { ScriptProps, UseScriptOptions, UseScriptStatus } from '../../utils/types'\n\n// Cached script statuses\nconst cachedScriptStatuses: Record<string, UseScriptStatus | undefined> = {}\n\nfunction getScriptNode(src: string) {\n\tconst node: HTMLScriptElement | null = document.querySelector(`script[src=\"${src}\"]`)\n\tconst status = node?.getAttribute('data-status') as UseScriptStatus | undefined\n\n\treturn {\n\t\tnode,\n\t\tstatus,\n\t}\n}\n\n/**\n * @description Hook to load external script.\n * @param {Object} script - Script to load.\n * @param {string} script.src - Script source.\n * @param {Object} [script.attributes] - Attributes to add to the script tag.\n * @param {Object} [script.callbacks] - Callbacks executed on completion.\n * @param {Function} [script.callbacks.onLoadCallback] - Callback executed on completion in case of success.\n * @param {Function} [script.callbacks.onErrorCallback] - Callbacks executed on completion in case of error.\n * @param {string} [script.elementIdToAppend] - HTML element id to append the script to. Default is HTML HEAD.\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n *\n * @example\n * const status = useScript({\n * \t\tsrc: \"https://script-to-load.js\",\n * \t\tattributes: { id: \"scriptId\", class: \"script-class\" },\n * \t\tcallbacks: {\n * \t\t\tonLoadCallback: onLoadFunc,\n * \t\t\tonErrorCallback: onErrorFunc,\n * \t\t},\n * \t\telementIdToAppend: \"script-container\"\n * }, undefined, { removeOnUnmount: true, shouldPreventLoad: false })\n */\n\nfunction useScript(\n\t// eslint-disable-next-line default-param-last\n\tscript: ScriptProps = {\n\t\tsrc: '',\n\t\tattributes: {},\n\t\tcallbacks: { onLoadCallback: () => {}, onErrorCallback: () => {} },\n\t\telementIdToAppend: '',\n\t},\n\tforcedStatus?: UseScriptStatus,\n\toptions: UseScriptOptions = { removeOnUnmount: false, shouldPreventLoad: false },\n): 'idle' | 'loading' | 'ready' | 'error' {\n\tconst [status, setStatus] = useState<UseScriptStatus>(() => {\n\t\tif (!script.src || options?.shouldPreventLoad) {\n\t\t\treturn 'idle'\n\t\t}\n\n\t\tif (typeof window === 'undefined') {\n\t\t\t// SSR Handling - always return 'loading'\n\t\t\treturn 'loading'\n\t\t}\n\n\t\treturn cachedScriptStatuses[script.src] ?? 'loading'\n\t})\n\n\tuseEffect(\n\t\t() => {\n\t\t\tif (forcedStatus) {\n\t\t\t\tsetStatus(forcedStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (!script?.src || options?.shouldPreventLoad) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst cachedScriptStatus = cachedScriptStatuses[script.src]\n\t\t\tif (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {\n\t\t\t\t// If the script is already cached, set its status immediately\n\t\t\t\tsetStatus(cachedScriptStatus)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Fetch existing script element by src\n\t\t\t// It may have been added by another instance of this hook\n\t\t\tconst scriptToAdd = getScriptNode(script.src)\n\t\t\tlet scriptNode = scriptToAdd.node\n\n\t\t\tif (!scriptNode) {\n\t\t\t\t// Create script element and add it to document body\n\t\t\t\tscriptNode = document.createElement('script')\n\t\t\t\tscriptNode.src = script.src\n\t\t\t\tscriptNode.async = true\n\t\t\t\tscriptNode.setAttribute('data-status', 'loading')\n\t\t\t\t// Add other script attributes, if they exist\n\t\t\t\tscript.attributes && Object.entries(script.attributes).length > 0\n\t\t\t\t\t? Object.entries(script.attributes).map(([key, value]) => scriptNode?.setAttribute(key, value))\n\t\t\t\t\t: null\n\t\t\t\tif (script.elementIdToAppend && document.getElementById(script.elementIdToAppend)) {\n\t\t\t\t\tdocument.getElementById(script.elementIdToAppend)?.appendChild(scriptNode)\n\t\t\t\t} else {\n\t\t\t\t\tdocument.body.appendChild(scriptNode)\n\t\t\t\t}\n\n\t\t\t\t// Store status in attribute on script\n\t\t\t\t// This can be read by other instances of this hook\n\t\t\t\tconst setAttributeFromEvent = (event: Event) => {\n\t\t\t\t\tconst scriptStatus: UseScriptStatus = event.type === 'load' ? 'ready' : 'error'\n\n\t\t\t\t\tscriptNode?.setAttribute('data-status', scriptStatus)\n\t\t\t\t}\n\n\t\t\t\tscriptNode.addEventListener('load', setAttributeFromEvent)\n\t\t\t\tscriptNode.addEventListener('error', setAttributeFromEvent)\n\t\t\t} else {\n\t\t\t\t// Grab existing script status from attribute and set to state.\n\t\t\t\tconst currentScriptStatus = scriptToAdd.status ?? cachedScriptStatus ?? 'loading'\n\n\t\t\t\tswitch (currentScriptStatus) {\n\t\t\t\t\tcase 'loading':\n\t\t\t\t\tcase 'ready':\n\t\t\t\t\t\tscript.callbacks?.onLoadCallback ? script.callbacks.onLoadCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'error':\n\t\t\t\t\t\tscript.callbacks?.onErrorCallback ? script.callbacks.onErrorCallback() : null\n\t\t\t\t\t\tbreak\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t// loading: do nothing\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tsetStatus(currentScriptStatus)\n\t\t\t}\n\n\t\t\t// Script event handler to update status in state\n\t\t\t// Note: Even if the script already exists we still need to add\n\t\t\t// event handlers to update the state for this hook instance.\n\t\t\tconst setStateFromEvent = (event: Event) => {\n\t\t\t\tconst newStatus = event.type === 'load' ? 'ready' : 'error'\n\t\t\t\tevent.type === 'load'\n\t\t\t\t\t? script.callbacks?.onLoadCallback\n\t\t\t\t\t\t? script.callbacks.onLoadCallback()\n\t\t\t\t\t\t: null\n\t\t\t\t\t: script.callbacks?.onErrorCallback\n\t\t\t\t\t? script.callbacks.onErrorCallback()\n\t\t\t\t\t: null\n\n\t\t\t\tsetStatus(newStatus)\n\t\t\t\tcachedScriptStatuses[script.src] = newStatus\n\t\t\t}\n\t\t\t// Add event listeners\n\t\t\tscriptNode.addEventListener('load', setStateFromEvent)\n\t\t\tscriptNode.addEventListener('error', setStateFromEvent)\n\t\t\t// Remove event listeners on cleanup\n\t\t\t// eslint-disable-next-line consistent-return\n\t\t\treturn () => {\n\t\t\t\tif (scriptNode) {\n\t\t\t\t\tscriptNode.removeEventListener('load', setStateFromEvent)\n\t\t\t\t\tscriptNode.removeEventListener('error', setStateFromEvent)\n\t\t\t\t}\n\n\t\t\t\tif (scriptNode && options?.removeOnUnmount) {\n\t\t\t\t\tscriptNode.remove()\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t// Re-run useEffect if script changes\n\t\t[script, forcedStatus, status],\n\t)\n\n\treturn status\n}\n\nexport default useScript\n","import { IUseGoogleMaps, UseScriptStatus } from '../../utils/types'\nimport useScript from './useScript'\n\n/**\n * @returns {\"idle\" | \"loading\" | \"ready\" | \"error\"} status\n */\nexport const useGoogleMaps = ({\n\tapiKey,\n\tlibraries = [],\n\tloadScriptExternally = false,\n\tstatus = 'idle',\n\texternalApiParams,\n\tcallback,\n}: IUseGoogleMaps): UseScriptStatus => {\n\tif (typeof window !== 'undefined') window.googleMapsCallback = callback\n\tconst apiParams = new URLSearchParams(externalApiParams)?.toString()\n\tconst script = apiKey\n\t\t? {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=googleMapsCallback&libraries=${libraries?.join(\n\t\t\t\t\t',',\n\t\t\t\t)}${apiParams ? `&${apiParams}` : ''}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\t\t: {\n\t\t\t\tsrc: `https://maps.googleapis.com/maps/api/js?callback=googleMapsCallback&libraries=${libraries?.join(',')}`,\n\t\t\t\tattributes: { id: 'googleMapsApi' },\n\t\t }\n\n\treturn useScript(script, loadScriptExternally ? status : undefined)\n}\n","import { useCallback, useEffect, useRef, useState } from 'react'\nimport { EventProps, Map, MapProps, MapsLibrary } from '../utils/types'\nimport { isArraysEqualEps } from '../utils/utils'\nimport MapMarkers from './markers'\n\nfunction MapComponent({\n\tchildren = null,\n\tstyle = {\n\t\twidth: '100%',\n\t\theight: '100%',\n\t\tleft: 0,\n\t\ttop: 0,\n\t\tmargin: 0,\n\t\tpadding: 0,\n\t\tposition: 'absolute',\n\t},\n\tdefaultCenter,\n\tdefaultZoom,\n\tonGoogleApiLoaded,\n\tonChange,\n\toptions = {},\n\tevents = [],\n}: MapProps) {\n\tconst mapRef = useRef<HTMLDivElement>(null)\n\tconst prevBoundsRef = useRef<number[] | undefined>()\n\tconst [map, setMap] = useState<Map>()\n\tconst [maps, setMaps] = useState<MapsLibrary>()\n\tconst [googleApiCalled, setGoogleApiCalled] = useState<boolean>(false)\n\n\tconst onIdle = useCallback(() => {\n\t\ttry {\n\t\t\tif (!map) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tconst zoom = map.getZoom() ?? defaultZoom\n\t\t\tconst bounds = map.getBounds()\n\t\t\tconst centerLatLng = [map.getCenter()?.lng(), map.getCenter()?.lat()]\n\n\t\t\tconst ne = bounds?.getNorthEast()\n\t\t\tconst sw = bounds?.getSouthWest()\n\n\t\t\tif (!ne || !sw || !bounds) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// east, north, south, west\n\t\t\tconst boundsArray = [sw.lng(), sw.lat(), ne.lng(), ne.lat()]\n\n\t\t\tif (!isArraysEqualEps(boundsArray, prevBoundsRef.current)) {\n\t\t\t\tif (onChange) {\n\t\t\t\t\tonChange({\n\t\t\t\t\t\tzoom,\n\t\t\t\t\t\tcenter: centerLatLng,\n\t\t\t\t\t\tbounds,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tprevBoundsRef.current = boundsArray\n\t\t\t}\n\t\t} catch (e) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error(e)\n\t\t}\n\t}, [map, onChange])\n\n\tuseEffect(() => {\n\t\tif (mapRef.current && !map) {\n\t\t\tsetMap(\n\t\t\t\tnew google.maps.Map(mapRef.current as HTMLElement, {\n\t\t\t\t\tcenter: defaultCenter,\n\t\t\t\t\tzoom: defaultZoom,\n\t\t\t\t\t...(options as google.maps.MapOptions),\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsetMaps(google.maps)\n\t\t}\n\t}, [defaultCenter, defaultZoom, map, mapRef, options])\n\n\tuseEffect(() => {\n\t\tif (map) {\n\t\t\tif (!googleApiCalled) {\n\t\t\t\tif (onGoogleApiLoaded && maps) onGoogleApiLoaded({ map, maps, ref: mapRef.current })\n\t\t\t\tsetGoogleApiCalled(true)\n\t\t\t}\n\n\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t// Idle event is fired when the map becomes idle after panning or zooming.\n\t\t\tgoogle.maps.event.addListener(map, 'idle', onIdle)\n\t\t}\n\t}, [googleApiCalled, map, maps, onChange, onGoogleApiLoaded, onIdle])\n\n\tuseEffect(\n\t\t() =>\n\t\t\t// clear listeners on unmount\n\t\t\t() => {\n\t\t\t\tif (map) {\n\t\t\t\t\tgoogle.maps.event.clearListeners(map, 'idle')\n\t\t\t\t}\n\t\t\t},\n\t\t[map],\n\t)\n\n\treturn (\n\t\t<>\n\t\t\t<div\n\t\t\t\tref={mapRef}\n\t\t\t\tstyle={style}\n\t\t\t\tclassName=\"google-map\"\n\t\t\t\t// spread the events as props\n\t\t\t\t{...events?.reduce(\n\t\t\t\t\t(acc, { name, handler }: EventProps) => {\n\t\t\t\t\t\tacc[name] = handler\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t},\n\t\t\t\t\t{} as { [key: string]: any },\n\t\t\t\t)}\n\t\t\t/>\n\t\t\t{children && map && maps && (\n\t\t\t\t<MapMarkers map={map} maps={maps}>\n\t\t\t\t\t{children}\n\t\t\t\t</MapMarkers>\n\t\t\t)}\n\t\t</>\n\t)\n}\n\nexport default MapComponent\n","export const isArraysEqualEps = (arrayA: number[], arrayB?: number[], eps = 0.000001): boolean => {\n\tif (arrayA && arrayB) {\n\t\tfor (let i = 0; i !== arrayA.length; ++i) {\n\t\t\tif (Math.abs(arrayA[i] - arrayB[i]) > eps) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\treturn false\n}\n","import { Children, cloneElement, isValidElement, useMemo } from 'react'\nimport { MapMarkersProps } from '../utils/types'\nimport OverlayView from './overlay-view'\n\nconst noop = () => {}\n\nconst MapMarkers = ({ children, map, maps }: MapMarkersProps) => {\n\tconst markers = useMemo(() => {\n\t\tif (!map || !maps) return []\n\n\t\treturn Children.map(children, (child) => {\n\t\t\tif (isValidElement(child)) {\n\t\t\t\tconst latLng = { lat: child.props.lat, lng: child.props.lng } as google.maps.LatLngLiteral\n\t\t\t\tconst { zIndex, draggable = false, onDragStart = noop, onDrag = noop, onDragEnd = noop } = child.props || {}\n\n\t\t\t\t// clone child without draggable props\n\t\t\t\t// eslint-disable-next-line no-param-reassign\n\t\t\t\tchild = cloneElement(child, {\n\t\t\t\t\t...child.props,\n\t\t\t\t\tdraggable: undefined,\n\t\t\t\t\tonDragStart: undefined,\n\t\t\t\t\tonDrag: undefined,\n\t\t\t\t\tonDragEnd: undefined,\n\t\t\t\t})\n\n\t\t\t\treturn (\n\t\t\t\t\t<OverlayView\n\t\t\t\t\t\tposition={new maps.LatLng(latLng.lat, latLng.lng)}\n\t\t\t\t\t\tmap={map}\n\t\t\t\t\t\tmaps={maps}\n\t\t\t\t\t\tzIndex={zIndex}\n\t\t\t\t\t\tdrag={{\n\t\t\t\t\t\t\tdraggable,\n\t\t\t\t\t\t\tonDragStart,\n\t\t\t\t\t\t\tonDrag,\n\t\t\t\t\t\t\tonDragEnd,\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{child}\n\t\t\t\t\t</OverlayView>\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn null\n\t\t})\n\t}, [children, map, maps])\n\n\treturn <div>{markers}</div>\n}\n\nexport default MapMarkers\n","import { useEffect, useMemo } from 'react'\nimport { createPortal } from 'react-dom'\nimport { OverlayViewProps } from '../utils/types'\nimport useMemoCompare from './hooks/useMemoCompare'\nimport createOverlay from './overlay'\n\nconst OverlayView = ({ pane = 'floatPane', position, map, maps, zIndex = 0, children, drag }: OverlayViewProps) => {\n\tconst container = useMemo<HTMLDivElement>(() => {\n\t\t// eslint-disable-next-line no-undef\n\t\tconst div = document.createElement('div') as HTMLDivElement\n\t\tdiv.style.position = 'absolute'\n\t\treturn div as HTMLDivElement\n\t}, [])\n\n\tconst overlay = useMemo(\n\t\t() => createOverlay({ container, pane, position, maps, drag }),\n\t\t[container, drag, maps, pane, position],\n\t)\n\n\t// Because React does not do deep comparisons, a custom hook is used.\n\t// This fixes the issue where the overlay is not updated when the position changes.\n\tconst childrenProps = useMemoCompare(\n\t\tchildren?.props as any,\n\t\t(prev: { lat: any; lng: any }, next: { lat: any; lng: any }) =>\n\t\t\tprev && prev.lat === next.lat && prev.lng === next.lng,\n\t)\n\n\tuseEffect(() => {\n\t\tif (!overlay.map && map) {\n\t\t\toverlay?.setMap(map)\n\t\t\treturn () => {\n\t\t\t\toverlay?.setMap(null)\n\t\t\t}\n\t\t}\n\t\treturn () => {}\n\t\t// overlay depends on map, so we don't need to add it to the dependency array\n\t\t// otherwise, it will re-render the overlay every time the map changes\n\t\t// ? added childrenProps to the dependency array to re-render the overlay when the children props change.\n\t}, [map, childrenProps])\n\n\t// to move the container to the foreground and background\n\tuseEffect(() => {\n\t\tcontainer.style.zIndex = `${zIndex}`\n\t}, [zIndex, container])\n\n\treturn createPortal(children, container)\n}\n\nexport default OverlayView\n","import { useEffect, useRef } from 'react'\n\n/**\n * A hook that compares the previous and current values of a reference.\n * @param {any} next - the current value of the reference\n * @param {function} compare - a function that compares the previous and current values\n * @returns {any} the previous value of the reference\n * @ref https://usehooks.com/useMemoCompare/\n */\nconst useMemoCompare = (next: any, compare: Function): any => {\n\t// Ref for storing previous value\n\tconst previousRef = useRef()\n\tconst previous = previousRef.current\n\t// Pass previous and next value to compare function\n\t// to determine whether to consider them equal.\n\tconst isEqual = compare(previous, next)\n\t// If not equal update previousRef to next value.\n\t// We only update if not equal so that this hook continues to return\n\t// the same old value if compare keeps returning true.\n\tuseEffect(() => {\n\t\tif (!isEqual) {\n\t\t\tpreviousRef.current = next\n\t\t}\n\t})\n\t// Finally, if equal then return the previous value\n\treturn isEqual ? previous : next\n}\n\nexport default useMemoCompare\n","import { Pane, createOverlayProps } from '../utils/types'\n\n// return lat, lng from LatLngLiteral\nconst getLatLng = (LatLng: google.maps.LatLng | null) => {\n\ttry {\n\t\tconst latLng = { lat: LatLng?.lat(), lng: LatLng?.lng() } as google.maps.LatLngLiteral\n\t\treturn latLng\n\t} catch (e) {\n\t\treturn LatLng\n\t}\n}\n\nconst createOverlay = ({ container, pane, position, maps, drag }: createOverlayProps) => {\n\tclass Overlay extends google.maps.OverlayView {\n\t\t/**\n\t\t * onAdd is called when the map's panes are ready and the overlay has been\n\t\t * added to the map.\n\t\t */\n\t\tonAdd = () => {\n\t\t\tconst that = this\n\t\t\t// manage draggable\n\t\t\tif (drag?.draggable) {\n\t\t\t\tthis.get('map')\n\t\t\t\t\t.getDiv()\n\t\t\t\t\t.addEventListener('mouseleave', () => {\n\t\t\t\t\t\tgoogle.maps.event.trigger(this.container, 'mouseup')\n\t\t\t\t\t})\n\t\t\t\tthis.container.addEventListener('mousedown', (e: MouseEvent) => {\n\t\t\t\t\tthis.container.style.cursor = 'grabbing'\n\t\t\t\t\tthat.map?.set('draggable', false)\n\t\t\t\t\tthat.set('origin', e)\n\n\t\t\t\t\tdrag.onDragStart(e, { latLng: getLatLng(this.position) })\n\n\t\t\t\t\t// eslint-disable-next-line no-shadow\n\t\t\t\t\tthat.moveHandler = this.get('map')\n\t\t\t\t\t\t.getDiv()\n\t\t\t\t\t\t.addEventListener('mousemove', (evt: MouseEvent) => {\n\t\t\t\t\t\t\tconst origin = that.get('origin')\n\t\t\t\t\t\t\tconst left = origin.clientX - evt.clientX\n\t\t\t\t\t\t\tconst top = origin.clientY - evt.clientY\n\t\t\t\t\t\t\tconst pos = that.getProjection().fromLatLngToDivPixel(that.position)\n\t\t\t\t\t\t\tif (pos === null) return\n\t\t\t\t\t\t\tconst latLng = that.getProjection().fromDivPixelToLatLng(new maps.Point(pos.x - left, pos.y - top))\n\t\t\t\t\t\t\tthat.set('position', latLng)\n\t\t\t\t\t\t\tthat.set('origin', evt)\n\t\t\t\t\t\t\tthat.draw()\n\t\t\t\t\t\t\tdrag.onDrag(evt, { latLng: getLatLng(latLng) })\n\t\t\t\t\t\t})\n\t\t\t\t})\n\n\t\t\t\tthis.container.addEventListener('mouseup', (e) => {\n\t\t\t\t\tthat.map?.set('draggable', true)\n\t\t\t\t\tthis.container.style.cursor = 'default'\n\t\t\t\t\tif (that.moveHandler) {\n\t\t\t\t\t\tgoogle.maps.event.removeListener(that.moveHandler)\n\t\t\t\t\t\tthat.moveHandler = null\n\t\t\t\t\t}\n\t\t\t\t\tdrag.onDragEnd(e, { latLng: getLatLng(that.position) })\n\t\t\t\t})\n\t\t\t}\n\t\t\t// Add the element to the pane.\n\t\t\tconst currentPane = this.getPanes()?.[this.pane] as HTMLElement\n\t\t\tcurrentPane?.classList.add('google-map-markers-overlay')\n\t\t\tcurrentPane?.appendChild(this.container)\n\t\t}\n\n\t\tdraw = () => {\n\t\t\tconst projection = this.getProjection() as google.maps.MapCanvasProjection\n\t\t\t// Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.\n\t\t\tconst point = projection.fromLatLngToDivPixel(this.position) as google.maps.Point\n\t\t\tif (point === null) return\n\t\t\tthis.container.style.transform = `translate(${point.x}px, ${point.y}px)`\n\t\t\tthis.container.style.width = '0px'\n\t\t\tthis.container.style.height = '0px'\n\t\t}\n\n\t\t/**\n\t\t * The onRemove() method will be called automatically from the API if\n\t\t * we ever set the overlay's map property to 'null'.\n\t\t */\n\t\tonRemove = () => {\n\t\t\tif (this.container.parentNode !== null) {\n\t\t\t\t// remove DOM listeners\n\t\t\t\tgoogle.maps.event.clearInstanceListeners(this.container)\n\t\t\t\tthis.container.parentNode.removeChild(this.container)\n\t\t\t}\n\t\t}\n\n\t\tpublic container: HTMLDivElement\n\n\t\tpublic pane: Pane\n\n\t\tpublic position: google.maps.LatLng\n\n\t\tpublic map = this.getMap()\n\n\t\tpublic moveHandler: google.maps.MapsEventListener | null\n\n\t\t// eslint-disable-next-line no-shadow\n\t\tconstructor(container: HTMLDivElement, pane: Pane, position: google.maps.LatLng) {\n\t\t\tsuper()\n\n\t\t\t// Initialize all properties.\n\t\t\tthis.container = container\n\t\t\tthis.pane = pane\n\t\t\tthis.position = position\n\n\t\t\tthis.moveHandler = null\n\t\t}\n\t}\n\n\treturn new Overlay(container, pane, position)\n}\n\nexport default createOverlay\n","import GoogleMap from './google-map'\n\nexport * from './utils/types'\n\nexport default GoogleMap\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "google-maps-react-markers",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Google Maps library with markers as react components",
5
5
  "author": "Giorgia Bosello",
6
6
  "license": "MIT",
@@ -67,23 +67,23 @@
67
67
  "node": ">=16"
68
68
  },
69
69
  "devDependencies": {
70
- "@babel/core": "7.22.15",
71
- "@babel/preset-env": "7.22.15",
70
+ "@babel/core": "7.23.0",
71
+ "@babel/preset-env": "7.22.20",
72
72
  "@babel/preset-react": "7.22.15",
73
73
  "@babel/preset-typescript": "7.22.15",
74
- "@commitlint/cli": "17.7.1",
74
+ "@commitlint/cli": "17.7.2",
75
75
  "@commitlint/config-conventional": "17.7.0",
76
76
  "@ryansonshine/commitizen": "4.2.8",
77
77
  "@ryansonshine/cz-conventional-changelog": "3.3.4",
78
78
  "@types/google.maps": "^3.54.0",
79
79
  "@types/node": "20.5.9",
80
- "@types/react": "18.2.21",
80
+ "@types/react": "18.2.24",
81
81
  "@types/react-dom": "18.2.7",
82
82
  "@typescript-eslint/eslint-plugin": "6.6.0",
83
83
  "@typescript-eslint/parser": "6.6.0",
84
84
  "babel-loader": "9.1.3",
85
85
  "concurrently": "8.2.1",
86
- "eslint": "8.48.0",
86
+ "eslint": "8.50.0",
87
87
  "eslint-config-airbnb": "19.0.4",
88
88
  "eslint-config-prettier": "9.0.0",
89
89
  "eslint-plugin-import": "2.28.1",