@ttoss/google-maps 0.8.4 → 0.8.5
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/esm/index.js +13 -25
- package/dist/index.js +62 -35
- package/package.json +3 -3
package/dist/esm/index.js
CHANGED
|
@@ -3,26 +3,21 @@ import * as React from "react";
|
|
|
3
3
|
|
|
4
4
|
// src/GoogleMapsProvider.tsx
|
|
5
5
|
import { useScript } from "@ttoss/hooks";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
createElement,
|
|
9
|
-
useContext,
|
|
10
|
-
useMemo
|
|
11
|
-
} from "react";
|
|
12
|
-
var GoogleMapsContext = createContext({
|
|
6
|
+
import * as React2 from "react";
|
|
7
|
+
var GoogleMapsContext = React2.createContext({
|
|
13
8
|
status: "idle",
|
|
14
9
|
googleMaps: null
|
|
15
10
|
});
|
|
16
11
|
var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
17
12
|
const src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries == null ? void 0 : libraries.join(",")}`;
|
|
18
13
|
const { status } = useScript(src);
|
|
19
|
-
const googleMaps = useMemo(() => {
|
|
14
|
+
const googleMaps = React2.useMemo(() => {
|
|
20
15
|
if (status === "ready" && window.google.maps) {
|
|
21
16
|
return window.google.maps;
|
|
22
17
|
}
|
|
23
18
|
return null;
|
|
24
19
|
}, [status]);
|
|
25
|
-
const value = useMemo(() => {
|
|
20
|
+
const value = React2.useMemo(() => {
|
|
26
21
|
if (status === "ready" && googleMaps) {
|
|
27
22
|
return {
|
|
28
23
|
status,
|
|
@@ -34,21 +29,18 @@ var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
|
34
29
|
googleMaps: null
|
|
35
30
|
};
|
|
36
31
|
}, [googleMaps, status]);
|
|
37
|
-
return /* @__PURE__ */ createElement(GoogleMapsContext.Provider, {
|
|
32
|
+
return /* @__PURE__ */ React2.createElement(GoogleMapsContext.Provider, {
|
|
38
33
|
value
|
|
39
34
|
}, children);
|
|
40
35
|
};
|
|
41
|
-
var useGoogleMaps = () => useContext(GoogleMapsContext);
|
|
36
|
+
var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
|
|
42
37
|
|
|
43
38
|
// src/useGeocoder.ts
|
|
44
|
-
import
|
|
45
|
-
useMemo as useMemo2,
|
|
46
|
-
useState
|
|
47
|
-
} from "react";
|
|
39
|
+
import * as React3 from "react";
|
|
48
40
|
var useGeocoder = () => {
|
|
49
41
|
const { googleMaps } = useGoogleMaps();
|
|
50
|
-
const [isGeocoderInitialized, setIsGeocoderInitialized] = useState(false);
|
|
51
|
-
const geocoder =
|
|
42
|
+
const [isGeocoderInitialized, setIsGeocoderInitialized] = React3.useState(false);
|
|
43
|
+
const geocoder = React3.useMemo(() => {
|
|
52
44
|
if (googleMaps) {
|
|
53
45
|
const googleMapsGeocoder = new googleMaps.Geocoder();
|
|
54
46
|
setIsGeocoderInitialized(true);
|
|
@@ -60,17 +52,13 @@ var useGeocoder = () => {
|
|
|
60
52
|
};
|
|
61
53
|
|
|
62
54
|
// src/useMap.ts
|
|
63
|
-
import
|
|
64
|
-
useMemo as useMemo3,
|
|
65
|
-
useRef,
|
|
66
|
-
useState as useState2
|
|
67
|
-
} from "react";
|
|
55
|
+
import * as React4 from "react";
|
|
68
56
|
var useMap = (options) => {
|
|
69
|
-
const ref = useRef(null);
|
|
57
|
+
const ref = React4.useRef(null);
|
|
70
58
|
const { googleMaps } = useGoogleMaps();
|
|
71
|
-
const [isMapInitialized, setIsMapInitialized] =
|
|
59
|
+
const [isMapInitialized, setIsMapInitialized] = React4.useState(false);
|
|
72
60
|
const optionsStringify = JSON.stringify(options);
|
|
73
|
-
const map =
|
|
61
|
+
const map = React4.useMemo(() => {
|
|
74
62
|
if (googleMaps && ref.current) {
|
|
75
63
|
const parsedOptions = JSON.parse(optionsStringify);
|
|
76
64
|
const googleMapsMap = new googleMaps.Map(ref.current, parsedOptions);
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
GoogleMapsProvider: () => GoogleMapsProvider,
|
|
33
|
+
useGeocoder: () => useGeocoder,
|
|
34
|
+
useGoogleMaps: () => useGoogleMaps,
|
|
35
|
+
useMap: () => useMap
|
|
36
|
+
});
|
|
10
37
|
|
|
38
|
+
// tsup.inject.js
|
|
39
|
+
var React = __toESM(require("react"));
|
|
11
40
|
|
|
12
|
-
|
|
41
|
+
// src/GoogleMapsProvider.tsx
|
|
42
|
+
var import_hooks = require("@ttoss/hooks");
|
|
43
|
+
var React2 = __toESM(require("react"));
|
|
44
|
+
var GoogleMapsContext = React2.createContext({
|
|
13
45
|
status: "idle",
|
|
14
46
|
googleMaps: null
|
|
15
47
|
});
|
|
16
48
|
var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
17
49
|
const src = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries == null ? void 0 : libraries.join(",")}`;
|
|
18
|
-
const { status } =
|
|
19
|
-
const googleMaps =
|
|
50
|
+
const { status } = (0, import_hooks.useScript)(src);
|
|
51
|
+
const googleMaps = React2.useMemo(() => {
|
|
20
52
|
if (status === "ready" && window.google.maps) {
|
|
21
53
|
return window.google.maps;
|
|
22
54
|
}
|
|
23
55
|
return null;
|
|
24
56
|
}, [status]);
|
|
25
|
-
const value =
|
|
57
|
+
const value = React2.useMemo(() => {
|
|
26
58
|
if (status === "ready" && googleMaps) {
|
|
27
59
|
return {
|
|
28
60
|
status,
|
|
@@ -34,21 +66,18 @@ var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
|
34
66
|
googleMaps: null
|
|
35
67
|
};
|
|
36
68
|
}, [googleMaps, status]);
|
|
37
|
-
return /* @__PURE__ */
|
|
69
|
+
return /* @__PURE__ */ React2.createElement(GoogleMapsContext.Provider, {
|
|
38
70
|
value
|
|
39
71
|
}, children);
|
|
40
72
|
};
|
|
41
|
-
var useGoogleMaps = () =>
|
|
73
|
+
var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
|
|
42
74
|
|
|
43
75
|
// src/useGeocoder.ts
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
var React3 = __toESM(require("react"));
|
|
48
77
|
var useGeocoder = () => {
|
|
49
78
|
const { googleMaps } = useGoogleMaps();
|
|
50
|
-
const [isGeocoderInitialized, setIsGeocoderInitialized] =
|
|
51
|
-
const geocoder =
|
|
79
|
+
const [isGeocoderInitialized, setIsGeocoderInitialized] = React3.useState(false);
|
|
80
|
+
const geocoder = React3.useMemo(() => {
|
|
52
81
|
if (googleMaps) {
|
|
53
82
|
const googleMapsGeocoder = new googleMaps.Geocoder();
|
|
54
83
|
setIsGeocoderInitialized(true);
|
|
@@ -60,17 +89,13 @@ var useGeocoder = () => {
|
|
|
60
89
|
};
|
|
61
90
|
|
|
62
91
|
// src/useMap.ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
var React4 = __toESM(require("react"));
|
|
68
93
|
var useMap = (options) => {
|
|
69
|
-
const ref =
|
|
94
|
+
const ref = React4.useRef(null);
|
|
70
95
|
const { googleMaps } = useGoogleMaps();
|
|
71
|
-
const [isMapInitialized, setIsMapInitialized] =
|
|
96
|
+
const [isMapInitialized, setIsMapInitialized] = React4.useState(false);
|
|
72
97
|
const optionsStringify = JSON.stringify(options);
|
|
73
|
-
const map =
|
|
98
|
+
const map = React4.useMemo(() => {
|
|
74
99
|
if (googleMaps && ref.current) {
|
|
75
100
|
const parsedOptions = JSON.parse(optionsStringify);
|
|
76
101
|
const googleMapsMap = new googleMaps.Map(ref.current, parsedOptions);
|
|
@@ -81,9 +106,11 @@ var useMap = (options) => {
|
|
|
81
106
|
}, [googleMaps, optionsStringify]);
|
|
82
107
|
return { map, ref, isMapInitialized };
|
|
83
108
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
module.exports = __toCommonJS(src_exports);
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
GoogleMapsProvider,
|
|
113
|
+
useGeocoder,
|
|
114
|
+
useGoogleMaps,
|
|
115
|
+
useMap
|
|
116
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/google-maps",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
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.
|
|
34
|
+
"@ttoss/hooks": "^0.8.5",
|
|
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": "
|
|
41
|
+
"gitHead": "41243699cc8ed5eba265e6434ebefbb9d6d91d52"
|
|
42
42
|
}
|