@ttoss/google-maps 1.9.6 → 1.11.1
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/README.md +2 -1
- package/dist/esm/index.js +11 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -2
- package/package.json +3 -3
- package/src/GoogleMapsProvider.spec.tsx +31 -1
- package/src/GoogleMapsProvider.tsx +18 -4
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ const Providers: React.FC = ({ children }) => {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
return (
|
|
126
|
-
<GoogleMapsProvider apiKey={apiKey} libraries={['places']}>
|
|
126
|
+
<GoogleMapsProvider apiKey={apiKey} libraries={['places']} language="pt-BR">
|
|
127
127
|
{children}
|
|
128
128
|
</GoogleMapsProvider>
|
|
129
129
|
);
|
|
@@ -224,6 +224,7 @@ export type GoogleMaps = typeof google.maps;
|
|
|
224
224
|
const GoogleMapsProvider: React.FC<{
|
|
225
225
|
apiKey: string;
|
|
226
226
|
libraries?: Libraries[] | undefined;
|
|
227
|
+
language?: string;
|
|
227
228
|
}>;
|
|
228
229
|
|
|
229
230
|
const useGoogleMaps: () =>
|
package/dist/esm/index.js
CHANGED
|
@@ -8,8 +8,17 @@ var GoogleMapsContext = React2.createContext({
|
|
|
8
8
|
status: "idle",
|
|
9
9
|
googleMaps: null
|
|
10
10
|
});
|
|
11
|
-
var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
12
|
-
const src =
|
|
11
|
+
var GoogleMapsProvider = ({ children, apiKey, libraries, language }) => {
|
|
12
|
+
const src = (() => {
|
|
13
|
+
let srcTemp = `https://maps.googleapis.com/maps/api/js?key=${apiKey}`;
|
|
14
|
+
if (libraries) {
|
|
15
|
+
srcTemp = srcTemp + `&libraries=${libraries.join(",")}`;
|
|
16
|
+
}
|
|
17
|
+
if (language) {
|
|
18
|
+
srcTemp = srcTemp + `&language=${language}`;
|
|
19
|
+
}
|
|
20
|
+
return srcTemp;
|
|
21
|
+
})();
|
|
13
22
|
const { status } = useScript(src);
|
|
14
23
|
const googleMaps = React2.useMemo(() => {
|
|
15
24
|
if (status === "ready" && window.google.maps) {
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ declare type Libraries = 'places' | 'visualization' | 'drawing' | 'geometry';
|
|
|
9
9
|
declare const GoogleMapsProvider: React.FC<{
|
|
10
10
|
apiKey: string;
|
|
11
11
|
libraries?: Libraries[];
|
|
12
|
+
/**
|
|
13
|
+
* https://developers.google.com/maps/faq#languagesupport
|
|
14
|
+
*/
|
|
15
|
+
language?: string;
|
|
12
16
|
}>;
|
|
13
17
|
/**
|
|
14
18
|
*
|
package/dist/index.js
CHANGED
|
@@ -45,8 +45,17 @@ var GoogleMapsContext = React2.createContext({
|
|
|
45
45
|
status: "idle",
|
|
46
46
|
googleMaps: null
|
|
47
47
|
});
|
|
48
|
-
var GoogleMapsProvider = ({ children, apiKey, libraries }) => {
|
|
49
|
-
const src =
|
|
48
|
+
var GoogleMapsProvider = ({ children, apiKey, libraries, language }) => {
|
|
49
|
+
const src = (() => {
|
|
50
|
+
let srcTemp = `https://maps.googleapis.com/maps/api/js?key=${apiKey}`;
|
|
51
|
+
if (libraries) {
|
|
52
|
+
srcTemp = srcTemp + `&libraries=${libraries.join(",")}`;
|
|
53
|
+
}
|
|
54
|
+
if (language) {
|
|
55
|
+
srcTemp = srcTemp + `&language=${language}`;
|
|
56
|
+
}
|
|
57
|
+
return srcTemp;
|
|
58
|
+
})();
|
|
50
59
|
const { status } = (0, import_hooks.useScript)(src);
|
|
51
60
|
const googleMaps = React2.useMemo(() => {
|
|
52
61
|
if (status === "ready" && window.google.maps) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/google-maps",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
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": "^1.
|
|
34
|
+
"@ttoss/hooks": "^1.11.1",
|
|
35
35
|
"@types/google.maps": "^3.47.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=17.0.2",
|
|
39
39
|
"react-dom": ">=17.0.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "42b0a90dcb68ae3db12d6923be815c5e93d3d962"
|
|
42
42
|
}
|
|
@@ -23,6 +23,10 @@ beforeAll(() => {
|
|
|
23
23
|
(global.google as unknown) = googleMock;
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
document.querySelectorAll('script')[0]?.remove();
|
|
28
|
+
});
|
|
29
|
+
|
|
26
30
|
const RenderStatus = () => {
|
|
27
31
|
const { status } = useGoogleMaps();
|
|
28
32
|
return (
|
|
@@ -34,9 +38,11 @@ const RenderStatus = () => {
|
|
|
34
38
|
|
|
35
39
|
const loadEvent = new Event('load');
|
|
36
40
|
|
|
41
|
+
const apiKey = 'apiKey';
|
|
42
|
+
|
|
37
43
|
it('should display correct status', () => {
|
|
38
44
|
render(
|
|
39
|
-
<GoogleMapsProvider apiKey=
|
|
45
|
+
<GoogleMapsProvider apiKey={apiKey}>
|
|
40
46
|
<RenderStatus />
|
|
41
47
|
</GoogleMapsProvider>
|
|
42
48
|
);
|
|
@@ -49,3 +55,27 @@ it('should display correct status', () => {
|
|
|
49
55
|
|
|
50
56
|
expect(screen.getByText('ready')).toBeInTheDocument();
|
|
51
57
|
});
|
|
58
|
+
|
|
59
|
+
it.each([
|
|
60
|
+
[{ apiKey }, `https://maps.googleapis.com/maps/api/js?key=${apiKey}`],
|
|
61
|
+
[
|
|
62
|
+
{ apiKey, language: 'pt-BR' },
|
|
63
|
+
`https://maps.googleapis.com/maps/api/js?key=${apiKey}&language=pt-BR`,
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
{ apiKey, language: 'pt-BR', libraries: ['places'] },
|
|
67
|
+
`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places&language=pt-BR`,
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
{ apiKey, language: 'pt-BR', libraries: ['places', 'geometry'] },
|
|
71
|
+
`https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=places,geometry&language=pt-BR`,
|
|
72
|
+
],
|
|
73
|
+
])('Google Maps API src %#', (props, src) => {
|
|
74
|
+
render(
|
|
75
|
+
<GoogleMapsProvider {...(props as any)}>
|
|
76
|
+
<RenderStatus />
|
|
77
|
+
</GoogleMapsProvider>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(document.querySelectorAll('script')[0].src).toEqual(src);
|
|
81
|
+
});
|
|
@@ -28,10 +28,24 @@ type Libraries = 'places' | 'visualization' | 'drawing' | 'geometry';
|
|
|
28
28
|
export const GoogleMapsProvider: React.FC<{
|
|
29
29
|
apiKey: string;
|
|
30
30
|
libraries?: Libraries[];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/**
|
|
32
|
+
* https://developers.google.com/maps/faq#languagesupport
|
|
33
|
+
*/
|
|
34
|
+
language?: string;
|
|
35
|
+
}> = ({ children, apiKey, libraries, language }) => {
|
|
36
|
+
const src = (() => {
|
|
37
|
+
let srcTemp = `https://maps.googleapis.com/maps/api/js?key=${apiKey}`;
|
|
38
|
+
|
|
39
|
+
if (libraries) {
|
|
40
|
+
srcTemp = srcTemp + `&libraries=${libraries.join(',')}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (language) {
|
|
44
|
+
srcTemp = srcTemp + `&language=${language}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return srcTemp;
|
|
48
|
+
})();
|
|
35
49
|
|
|
36
50
|
const { status } = useScript(src);
|
|
37
51
|
|