google-maps-react-markers 1.4.1 → 2.0.0-alpha.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/LICENCE.md +1 -1
- package/README.md +10 -1
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +171 -0
- package/dist/index.d.ts +171 -2
- package/dist/index.js +7 -574
- package/dist/index.js.map +1 -1
- package/package.json +90 -46
- package/dist/google-map.d.ts +0 -3
- package/dist/google-map.d.ts.map +0 -1
- package/dist/hooks/useGoogleMaps.d.ts +0 -5
- package/dist/hooks/useGoogleMaps.d.ts.map +0 -1
- package/dist/hooks/useMemoCompare.d.ts +0 -10
- package/dist/hooks/useMemoCompare.d.ts.map +0 -1
- package/dist/hooks/useScript.d.ts +0 -10
- package/dist/hooks/useScript.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.js +0 -573
- package/dist/index.modern.js.map +0 -1
- package/dist/map/map.d.ts +0 -34
- package/dist/map/map.d.ts.map +0 -1
- package/dist/map/markers.d.ts +0 -14
- package/dist/map/markers.d.ts.map +0 -1
- package/dist/map/overlay-view.d.ts +0 -23
- package/dist/map/overlay-view.d.ts.map +0 -1
- package/dist/map/overlay.d.ts +0 -18
- package/dist/map/overlay.d.ts.map +0 -1
- package/dist/utils/utils.d.ts +0 -2
- package/dist/utils/utils.d.ts.map +0 -1
package/LICENCE.md
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -30,6 +30,11 @@ The library implements [Google Maps Custom Overlays](https://developers.google.c
|
|
|
30
30
|
[](https://www.buymeacoffee.com/giorgiabosello)
|
|
31
31
|
[](https://www.paypal.me/giorgiabosello)
|
|
32
32
|
|
|
33
|
+
## 🚧 Status
|
|
34
|
+
> **Currently working on a fully typed TypeScript version of the library. It will be released soon. Stay tuned!**
|
|
35
|
+
|
|
36
|
+
Feedbacks are welcome in [this discussion](https://github.com/giorgiabosello/google-maps-react-markers/discussions/109).
|
|
37
|
+
|
|
33
38
|
## 🚀 Demo
|
|
34
39
|
|
|
35
40
|
<a href="https://giorgiabosello.github.io/google-maps-react-markers/" target="blank">
|
|
@@ -61,6 +66,8 @@ npm install --save google-maps-react-markers
|
|
|
61
66
|
## 💻 Usage
|
|
62
67
|
|
|
63
68
|
```jsx
|
|
69
|
+
import GoogleMap from 'google-maps-react-markers'
|
|
70
|
+
|
|
64
71
|
const App = () => {
|
|
65
72
|
const mapRef = useRef(null)
|
|
66
73
|
const [mapReady, setMapReady] = useState(false)
|
|
@@ -193,7 +200,9 @@ Do your changes to `src/` or `docs/src` directory, commits all files (ones in `d
|
|
|
193
200
|
## 💻 Built with
|
|
194
201
|
|
|
195
202
|
- [React](https://reactjs.org/)
|
|
203
|
+
- [TypeScript](https://www.typescriptlang.org/)
|
|
196
204
|
- [Google Maps Custom Overlays](https://developers.google.com/maps/documentation/javascript/customoverlays)
|
|
205
|
+
- [tsup](https://github.com/egoist/tsup): for bundling
|
|
197
206
|
- [ESLint](https://eslint.org/): for linting
|
|
198
207
|
- [Prettier](https://prettier.io/): for code formatting
|
|
199
208
|
|
|
@@ -209,4 +218,4 @@ MIT © [giorgiabosello](https://github.com/giorgiabosello)
|
|
|
209
218
|
<hr>
|
|
210
219
|
<p align="center">
|
|
211
220
|
Developed with ❤️ in Italy 🇮🇹
|
|
212
|
-
</p>
|
|
221
|
+
</p>
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var reactDom = require('react-dom');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
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;
|
|
8
|
+
|
|
9
|
+
module.exports = Ve;
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,aAAA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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"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
google?: any;
|
|
7
|
+
googleMapsCallback?: () => void;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type Map = google.maps.Map;
|
|
11
|
+
type MapsLibrary = typeof google.maps;
|
|
12
|
+
type MapOptions = google.maps.MapOptions;
|
|
13
|
+
type LatLngLiteral = google.maps.LatLngLiteral;
|
|
14
|
+
type LatLngBounds = google.maps.LatLngBounds;
|
|
15
|
+
type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
16
|
+
interface IUseGoogleMaps {
|
|
17
|
+
/**
|
|
18
|
+
* The Google Maps API key.
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Google Maps API callback.
|
|
23
|
+
*/
|
|
24
|
+
callback?: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* The Google Maps API params to be appended to the script URL.
|
|
27
|
+
* @example
|
|
28
|
+
* {
|
|
29
|
+
* language: 'en',
|
|
30
|
+
* region: 'GB',
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
externalApiParams?: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The Google Maps API libraries to be loaded.
|
|
38
|
+
* @default ['places', 'geometry']
|
|
39
|
+
*/
|
|
40
|
+
libraries?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Whether to manage the script loading externally.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
loadScriptExternally?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The status of the script loading.
|
|
48
|
+
* To be used only if `loadScriptExternally` is `true`.
|
|
49
|
+
*/
|
|
50
|
+
status?: UseScriptStatus;
|
|
51
|
+
}
|
|
52
|
+
interface MapContextProps {
|
|
53
|
+
/**
|
|
54
|
+
* The Google Maps instance.
|
|
55
|
+
*/
|
|
56
|
+
map: Map;
|
|
57
|
+
/**
|
|
58
|
+
* The Google Maps API object.
|
|
59
|
+
*/
|
|
60
|
+
maps: MapsLibrary;
|
|
61
|
+
}
|
|
62
|
+
interface EventProps {
|
|
63
|
+
/**
|
|
64
|
+
* The event handler.
|
|
65
|
+
* @param e The event.
|
|
66
|
+
*/
|
|
67
|
+
handler: (e: any) => void;
|
|
68
|
+
/**
|
|
69
|
+
* The HTML Event attribute name.
|
|
70
|
+
* @reference https://www.w3schools.com/tags/ref_eventattributes.asp
|
|
71
|
+
* @example
|
|
72
|
+
* 'onClick'
|
|
73
|
+
*/
|
|
74
|
+
name: string;
|
|
75
|
+
}
|
|
76
|
+
interface onGoogleApiLoadedProps extends MapContextProps {
|
|
77
|
+
/**
|
|
78
|
+
* The ref of the Map.
|
|
79
|
+
*/
|
|
80
|
+
ref: HTMLDivElement | null;
|
|
81
|
+
}
|
|
82
|
+
interface MapProps {
|
|
83
|
+
/**
|
|
84
|
+
* The Markers to be rendered on the map
|
|
85
|
+
*/
|
|
86
|
+
children?: React__default.ReactNode;
|
|
87
|
+
/**
|
|
88
|
+
* The default center of the map.
|
|
89
|
+
*/
|
|
90
|
+
defaultCenter: LatLngLiteral;
|
|
91
|
+
/**
|
|
92
|
+
* The default zoom of the map.
|
|
93
|
+
*/
|
|
94
|
+
defaultZoom: number;
|
|
95
|
+
/**
|
|
96
|
+
* The events to pass to the Google Maps instance (`div`).
|
|
97
|
+
* @type {Array}
|
|
98
|
+
* @example
|
|
99
|
+
* [
|
|
100
|
+
* {
|
|
101
|
+
* name: 'onClick',
|
|
102
|
+
* handler: (event) => { ... }
|
|
103
|
+
* }
|
|
104
|
+
* ]
|
|
105
|
+
*/
|
|
106
|
+
events?: EventProps[];
|
|
107
|
+
/**
|
|
108
|
+
* The callback fired when the map changes (center, zoom, bounds).
|
|
109
|
+
*/
|
|
110
|
+
onChange?: (options: {
|
|
111
|
+
bounds: LatLngBounds;
|
|
112
|
+
center: (number | undefined)[];
|
|
113
|
+
zoom: number;
|
|
114
|
+
}) => void;
|
|
115
|
+
/**
|
|
116
|
+
* The callback fired when the map is loaded.
|
|
117
|
+
*/
|
|
118
|
+
onGoogleApiLoaded?: (props: onGoogleApiLoadedProps) => void;
|
|
119
|
+
/**
|
|
120
|
+
* The options to pass to the Google Maps instance.
|
|
121
|
+
* @reference https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
|
|
122
|
+
*/
|
|
123
|
+
options?: MapOptions;
|
|
124
|
+
/**
|
|
125
|
+
* The style of the map container.
|
|
126
|
+
* @default {
|
|
127
|
+
* width: '100%',
|
|
128
|
+
* height: '100%',
|
|
129
|
+
* left: 0,
|
|
130
|
+
* top: 0,
|
|
131
|
+
* margin: 0,
|
|
132
|
+
* padding: 0,
|
|
133
|
+
* position: 'absolute'
|
|
134
|
+
* }
|
|
135
|
+
*/
|
|
136
|
+
style?: React__default.CSSProperties;
|
|
137
|
+
}
|
|
138
|
+
interface GoogleMapProps extends MapProps, IUseGoogleMaps {
|
|
139
|
+
/**
|
|
140
|
+
* The props to pass to the `div` container element.
|
|
141
|
+
*/
|
|
142
|
+
containerProps?: React__default.HTMLAttributes<HTMLDivElement>;
|
|
143
|
+
/**
|
|
144
|
+
* The content to be rendered when the script fails to load.
|
|
145
|
+
* @default 'Google Maps is on error'
|
|
146
|
+
*/
|
|
147
|
+
errorContent?: React__default.ReactNode;
|
|
148
|
+
/**
|
|
149
|
+
* The content to be rendered when the script is on idle.
|
|
150
|
+
* @default 'Google Maps is on idle'
|
|
151
|
+
*/
|
|
152
|
+
idleContent?: React__default.ReactNode;
|
|
153
|
+
/**
|
|
154
|
+
* The content to be rendered while the script is loading.
|
|
155
|
+
* @default 'Google Maps is loading'
|
|
156
|
+
*/
|
|
157
|
+
loadingContent?: React__default.ReactNode;
|
|
158
|
+
/**
|
|
159
|
+
* The minimum height of the map container.
|
|
160
|
+
* @default 'unset'
|
|
161
|
+
*/
|
|
162
|
+
mapMinHeight?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The Google Maps API script callback
|
|
165
|
+
*/
|
|
166
|
+
scriptCallback?: () => void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
declare const GoogleMap: React.ForwardRefExoticComponent<GoogleMapProps & React.RefAttributes<HTMLDivElement>>;
|
|
170
|
+
|
|
171
|
+
export { GoogleMap as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
google?: any;
|
|
7
|
+
googleMapsCallback?: () => void;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type Map = google.maps.Map;
|
|
11
|
+
type MapsLibrary = typeof google.maps;
|
|
12
|
+
type MapOptions = google.maps.MapOptions;
|
|
13
|
+
type LatLngLiteral = google.maps.LatLngLiteral;
|
|
14
|
+
type LatLngBounds = google.maps.LatLngBounds;
|
|
15
|
+
type UseScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
16
|
+
interface IUseGoogleMaps {
|
|
17
|
+
/**
|
|
18
|
+
* The Google Maps API key.
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Google Maps API callback.
|
|
23
|
+
*/
|
|
24
|
+
callback?: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* The Google Maps API params to be appended to the script URL.
|
|
27
|
+
* @example
|
|
28
|
+
* {
|
|
29
|
+
* language: 'en',
|
|
30
|
+
* region: 'GB',
|
|
31
|
+
* }
|
|
32
|
+
*/
|
|
33
|
+
externalApiParams?: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The Google Maps API libraries to be loaded.
|
|
38
|
+
* @default ['places', 'geometry']
|
|
39
|
+
*/
|
|
40
|
+
libraries?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Whether to manage the script loading externally.
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
loadScriptExternally?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The status of the script loading.
|
|
48
|
+
* To be used only if `loadScriptExternally` is `true`.
|
|
49
|
+
*/
|
|
50
|
+
status?: UseScriptStatus;
|
|
51
|
+
}
|
|
52
|
+
interface MapContextProps {
|
|
53
|
+
/**
|
|
54
|
+
* The Google Maps instance.
|
|
55
|
+
*/
|
|
56
|
+
map: Map;
|
|
57
|
+
/**
|
|
58
|
+
* The Google Maps API object.
|
|
59
|
+
*/
|
|
60
|
+
maps: MapsLibrary;
|
|
61
|
+
}
|
|
62
|
+
interface EventProps {
|
|
63
|
+
/**
|
|
64
|
+
* The event handler.
|
|
65
|
+
* @param e The event.
|
|
66
|
+
*/
|
|
67
|
+
handler: (e: any) => void;
|
|
68
|
+
/**
|
|
69
|
+
* The HTML Event attribute name.
|
|
70
|
+
* @reference https://www.w3schools.com/tags/ref_eventattributes.asp
|
|
71
|
+
* @example
|
|
72
|
+
* 'onClick'
|
|
73
|
+
*/
|
|
74
|
+
name: string;
|
|
75
|
+
}
|
|
76
|
+
interface onGoogleApiLoadedProps extends MapContextProps {
|
|
77
|
+
/**
|
|
78
|
+
* The ref of the Map.
|
|
79
|
+
*/
|
|
80
|
+
ref: HTMLDivElement | null;
|
|
81
|
+
}
|
|
82
|
+
interface MapProps {
|
|
83
|
+
/**
|
|
84
|
+
* The Markers to be rendered on the map
|
|
85
|
+
*/
|
|
86
|
+
children?: React__default.ReactNode;
|
|
87
|
+
/**
|
|
88
|
+
* The default center of the map.
|
|
89
|
+
*/
|
|
90
|
+
defaultCenter: LatLngLiteral;
|
|
91
|
+
/**
|
|
92
|
+
* The default zoom of the map.
|
|
93
|
+
*/
|
|
94
|
+
defaultZoom: number;
|
|
95
|
+
/**
|
|
96
|
+
* The events to pass to the Google Maps instance (`div`).
|
|
97
|
+
* @type {Array}
|
|
98
|
+
* @example
|
|
99
|
+
* [
|
|
100
|
+
* {
|
|
101
|
+
* name: 'onClick',
|
|
102
|
+
* handler: (event) => { ... }
|
|
103
|
+
* }
|
|
104
|
+
* ]
|
|
105
|
+
*/
|
|
106
|
+
events?: EventProps[];
|
|
107
|
+
/**
|
|
108
|
+
* The callback fired when the map changes (center, zoom, bounds).
|
|
109
|
+
*/
|
|
110
|
+
onChange?: (options: {
|
|
111
|
+
bounds: LatLngBounds;
|
|
112
|
+
center: (number | undefined)[];
|
|
113
|
+
zoom: number;
|
|
114
|
+
}) => void;
|
|
115
|
+
/**
|
|
116
|
+
* The callback fired when the map is loaded.
|
|
117
|
+
*/
|
|
118
|
+
onGoogleApiLoaded?: (props: onGoogleApiLoadedProps) => void;
|
|
119
|
+
/**
|
|
120
|
+
* The options to pass to the Google Maps instance.
|
|
121
|
+
* @reference https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions
|
|
122
|
+
*/
|
|
123
|
+
options?: MapOptions;
|
|
124
|
+
/**
|
|
125
|
+
* The style of the map container.
|
|
126
|
+
* @default {
|
|
127
|
+
* width: '100%',
|
|
128
|
+
* height: '100%',
|
|
129
|
+
* left: 0,
|
|
130
|
+
* top: 0,
|
|
131
|
+
* margin: 0,
|
|
132
|
+
* padding: 0,
|
|
133
|
+
* position: 'absolute'
|
|
134
|
+
* }
|
|
135
|
+
*/
|
|
136
|
+
style?: React__default.CSSProperties;
|
|
137
|
+
}
|
|
138
|
+
interface GoogleMapProps extends MapProps, IUseGoogleMaps {
|
|
139
|
+
/**
|
|
140
|
+
* The props to pass to the `div` container element.
|
|
141
|
+
*/
|
|
142
|
+
containerProps?: React__default.HTMLAttributes<HTMLDivElement>;
|
|
143
|
+
/**
|
|
144
|
+
* The content to be rendered when the script fails to load.
|
|
145
|
+
* @default 'Google Maps is on error'
|
|
146
|
+
*/
|
|
147
|
+
errorContent?: React__default.ReactNode;
|
|
148
|
+
/**
|
|
149
|
+
* The content to be rendered when the script is on idle.
|
|
150
|
+
* @default 'Google Maps is on idle'
|
|
151
|
+
*/
|
|
152
|
+
idleContent?: React__default.ReactNode;
|
|
153
|
+
/**
|
|
154
|
+
* The content to be rendered while the script is loading.
|
|
155
|
+
* @default 'Google Maps is loading'
|
|
156
|
+
*/
|
|
157
|
+
loadingContent?: React__default.ReactNode;
|
|
158
|
+
/**
|
|
159
|
+
* The minimum height of the map container.
|
|
160
|
+
* @default 'unset'
|
|
161
|
+
*/
|
|
162
|
+
mapMinHeight?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The Google Maps API script callback
|
|
165
|
+
*/
|
|
166
|
+
scriptCallback?: () => void;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
declare const GoogleMap: React.ForwardRefExoticComponent<GoogleMapProps & React.RefAttributes<HTMLDivElement>>;
|
|
170
|
+
|
|
171
|
+
export { GoogleMap as default };
|