@ttoss/google-maps 0.8.4 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/google-maps",
3
- "version": "0.8.4",
3
+ "version": "0.9.2",
4
4
  "author": "ttoss",
5
5
  "contributors": [
6
6
  {
@@ -31,12 +31,12 @@
31
31
  "build": "tsup"
32
32
  },
33
33
  "dependencies": {
34
- "@ttoss/hooks": "^0.8.4",
34
+ "@ttoss/hooks": "^0.9.2",
35
35
  "@types/google.maps": "^3.45.6"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "react": ">=16.8.0",
39
39
  "react-dom": ">=16.8.0"
40
40
  },
41
- "gitHead": "9d8124a3110e71122dbdeebc791bac649e43791c"
41
+ "gitHead": "6a904124b42ad72f3ba318ec42b861f803acb218"
42
42
  }
package/dist/esm/index.js DELETED
@@ -1,89 +0,0 @@
1
- // tsup.inject.js
2
- import * as React from "react";
3
-
4
- // src/GoogleMapsProvider.tsx
5
- import { useScript } from "@ttoss/hooks";
6
- import {
7
- createContext,
8
- createElement,
9
- useContext,
10
- useMemo
11
- } from "react";
12
- var GoogleMapsContext = createContext({
13
- status: "idle",
14
- googleMaps: null
15
- });
16
- var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
17
- const src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries == null ? void 0 : libraries.join(",")}`;
18
- const { status } = useScript(src);
19
- const googleMaps = useMemo(() => {
20
- if (status === "ready" && window.google.maps) {
21
- return window.google.maps;
22
- }
23
- return null;
24
- }, [status]);
25
- const value = useMemo(() => {
26
- if (status === "ready" && googleMaps) {
27
- return {
28
- status,
29
- googleMaps
30
- };
31
- }
32
- return {
33
- status,
34
- googleMaps: null
35
- };
36
- }, [googleMaps, status]);
37
- return /* @__PURE__ */ createElement(GoogleMapsContext.Provider, {
38
- value
39
- }, children);
40
- };
41
- var useGoogleMaps = () => useContext(GoogleMapsContext);
42
-
43
- // src/useGeocoder.ts
44
- import {
45
- useMemo as useMemo2,
46
- useState
47
- } from "react";
48
- var useGeocoder = () => {
49
- const { googleMaps } = useGoogleMaps();
50
- const [isGeocoderInitialized, setIsGeocoderInitialized] = useState(false);
51
- const geocoder = useMemo2(() => {
52
- if (googleMaps) {
53
- const googleMapsGeocoder = new googleMaps.Geocoder();
54
- setIsGeocoderInitialized(true);
55
- return googleMapsGeocoder;
56
- }
57
- return null;
58
- }, [googleMaps]);
59
- return { geocoder, isGeocoderInitialized };
60
- };
61
-
62
- // src/useMap.ts
63
- import {
64
- useMemo as useMemo3,
65
- useRef,
66
- useState as useState2
67
- } from "react";
68
- var useMap = (options) => {
69
- const ref = useRef(null);
70
- const { googleMaps } = useGoogleMaps();
71
- const [isMapInitialized, setIsMapInitialized] = useState2(false);
72
- const optionsStringify = JSON.stringify(options);
73
- const map = useMemo3(() => {
74
- if (googleMaps && ref.current) {
75
- const parsedOptions = JSON.parse(optionsStringify);
76
- const googleMapsMap = new googleMaps.Map(ref.current, parsedOptions);
77
- setIsMapInitialized(true);
78
- return googleMapsMap;
79
- }
80
- return null;
81
- }, [googleMaps, optionsStringify]);
82
- return { map, ref, isMapInitialized };
83
- };
84
- export {
85
- GoogleMapsProvider,
86
- useGeocoder,
87
- useGoogleMaps,
88
- useMap
89
- };
package/dist/index.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { ScriptStatus } from '@ttoss/hooks';
2
- import * as React from 'react';
3
-
4
- declare type Extends<T, U extends T> = U;
5
- declare type GoogleMaps = typeof google.maps;
6
- declare type LoadedMapsStatus = Extends<ScriptStatus, 'ready'>;
7
- declare type NotLoadedMapStatus = Extends<ScriptStatus, 'idle' | 'error' | 'loading'>;
8
- declare type Libraries = 'places' | 'visualization' | 'drawing' | 'geometry';
9
- declare const GoogleMapsProvider: React.FC<{
10
- apiKey: string;
11
- libraries?: Libraries[];
12
- }>;
13
- /**
14
- *
15
- * @returns param.googleMaps: GoogleMaps - returns the google maps object which
16
- * provides access to the [Google Maps API](https://developers.google.com/maps/documentation/javascript/overview).
17
- */
18
- declare const useGoogleMaps: () => {
19
- status: LoadedMapsStatus;
20
- googleMaps: GoogleMaps;
21
- } | {
22
- status: NotLoadedMapStatus;
23
- googleMaps: null;
24
- };
25
-
26
- declare const useGeocoder: () => {
27
- geocoder: google.maps.Geocoder | null;
28
- isGeocoderInitialized: boolean;
29
- };
30
-
31
- declare const useMap: (options: google.maps.MapOptions) => {
32
- map: google.maps.Map | null;
33
- ref: React.RefObject<HTMLDivElement>;
34
- isMapInitialized: boolean;
35
- };
36
-
37
- export { GoogleMapsProvider, useGeocoder, useGoogleMaps, useMap };
package/dist/index.js DELETED
@@ -1,89 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// tsup.inject.js
2
- var _react = require('react'); var React = _interopRequireWildcard(_react);
3
-
4
- // src/GoogleMapsProvider.tsx
5
- var _hooks = require('@ttoss/hooks');
6
-
7
-
8
-
9
-
10
-
11
-
12
- var GoogleMapsContext = _react.createContext.call(void 0, {
13
- status: "idle",
14
- googleMaps: null
15
- });
16
- var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
17
- const src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries == null ? void 0 : libraries.join(",")}`;
18
- const { status } = _hooks.useScript.call(void 0, src);
19
- const googleMaps = _react.useMemo.call(void 0, () => {
20
- if (status === "ready" && window.google.maps) {
21
- return window.google.maps;
22
- }
23
- return null;
24
- }, [status]);
25
- const value = _react.useMemo.call(void 0, () => {
26
- if (status === "ready" && googleMaps) {
27
- return {
28
- status,
29
- googleMaps
30
- };
31
- }
32
- return {
33
- status,
34
- googleMaps: null
35
- };
36
- }, [googleMaps, status]);
37
- return /* @__PURE__ */ _react.createElement.call(void 0, GoogleMapsContext.Provider, {
38
- value
39
- }, children);
40
- };
41
- var useGoogleMaps = () => _react.useContext.call(void 0, GoogleMapsContext);
42
-
43
- // src/useGeocoder.ts
44
-
45
-
46
-
47
-
48
- var useGeocoder = () => {
49
- const { googleMaps } = useGoogleMaps();
50
- const [isGeocoderInitialized, setIsGeocoderInitialized] = _react.useState.call(void 0, false);
51
- const geocoder = _react.useMemo.call(void 0, () => {
52
- if (googleMaps) {
53
- const googleMapsGeocoder = new googleMaps.Geocoder();
54
- setIsGeocoderInitialized(true);
55
- return googleMapsGeocoder;
56
- }
57
- return null;
58
- }, [googleMaps]);
59
- return { geocoder, isGeocoderInitialized };
60
- };
61
-
62
- // src/useMap.ts
63
-
64
-
65
-
66
-
67
-
68
- var useMap = (options) => {
69
- const ref = _react.useRef.call(void 0, null);
70
- const { googleMaps } = useGoogleMaps();
71
- const [isMapInitialized, setIsMapInitialized] = _react.useState.call(void 0, false);
72
- const optionsStringify = JSON.stringify(options);
73
- const map = _react.useMemo.call(void 0, () => {
74
- if (googleMaps && ref.current) {
75
- const parsedOptions = JSON.parse(optionsStringify);
76
- const googleMapsMap = new googleMaps.Map(ref.current, parsedOptions);
77
- setIsMapInitialized(true);
78
- return googleMapsMap;
79
- }
80
- return null;
81
- }, [googleMaps, optionsStringify]);
82
- return { map, ref, isMapInitialized };
83
- };
84
-
85
-
86
-
87
-
88
-
89
- exports.GoogleMapsProvider = GoogleMapsProvider; exports.useGeocoder = useGeocoder; exports.useGoogleMaps = useGoogleMaps; exports.useMap = useMap;