@ttoss/google-maps 1.22.9 → 1.22.10

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 CHANGED
@@ -7,7 +7,7 @@ import * as React from "react";
7
7
  import * as React2 from "react";
8
8
  import { useScript } from "@ttoss/hooks";
9
9
  import { jsx } from "react/jsx-runtime";
10
- var GoogleMapsContext = React2.createContext({
10
+ var GoogleMapsContext = /*#__PURE__*/React2.createContext({
11
11
  status: "idle",
12
12
  googleMaps: null
13
13
  });
@@ -27,7 +27,9 @@ var GoogleMapsProvider = ({
27
27
  }
28
28
  return srcTemp;
29
29
  })();
30
- const { status } = useScript(src);
30
+ const {
31
+ status
32
+ } = useScript(src);
31
33
  const googleMaps = React2.useMemo(() => {
32
34
  if (status === "ready" && window.google.maps) {
33
35
  return window.google.maps;
@@ -46,14 +48,19 @@ var GoogleMapsProvider = ({
46
48
  googleMaps: null
47
49
  };
48
50
  }, [googleMaps, status]);
49
- return /* @__PURE__ */ jsx(GoogleMapsContext.Provider, { value, children });
51
+ return /* @__PURE__ */jsx(GoogleMapsContext.Provider, {
52
+ value,
53
+ children
54
+ });
50
55
  };
51
56
  var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
52
57
 
53
58
  // src/useGeocoder.ts
54
59
  import * as React3 from "react";
55
60
  var useGeocoder = () => {
56
- const { googleMaps } = useGoogleMaps();
61
+ const {
62
+ googleMaps
63
+ } = useGoogleMaps();
57
64
  const [isGeocoderInitialized, setIsGeocoderInitialized] = React3.useState(false);
58
65
  const geocoder = React3.useMemo(() => {
59
66
  if (googleMaps) {
@@ -63,7 +70,10 @@ var useGeocoder = () => {
63
70
  }
64
71
  return null;
65
72
  }, [googleMaps]);
66
- return { geocoder, isGeocoderInitialized };
73
+ return {
74
+ geocoder,
75
+ isGeocoderInitialized
76
+ };
67
77
  };
68
78
 
69
79
  // src/useMap.ts
@@ -71,11 +81,10 @@ import * as React4 from "react";
71
81
  import { useCallbackRef } from "use-callback-ref";
72
82
  var useMap = (options = {}) => {
73
83
  const [, forceUpdate] = React4.useState(0);
74
- const ref = useCallbackRef(
75
- null,
76
- () => forceUpdate((n) => n + 1)
77
- );
78
- const { googleMaps } = useGoogleMaps();
84
+ const ref = useCallbackRef(null, () => forceUpdate(n => n + 1));
85
+ const {
86
+ googleMaps
87
+ } = useGoogleMaps();
79
88
  const map = React4.useMemo(() => {
80
89
  if (googleMaps && ref.current) {
81
90
  return new googleMaps.Map(ref.current, options);
@@ -120,7 +129,7 @@ var debounce_default = debounce;
120
129
 
121
130
  // src/usePlacesAutocomplete/useLatest.ts
122
131
  import { useRef } from "react";
123
- var useLatest_default = (val) => {
132
+ var useLatest_default = val => {
124
133
  const ref = useRef(val);
125
134
  ref.current = val;
126
135
  return ref;
@@ -145,16 +154,19 @@ var usePlacesAutocomplete = ({
145
154
  });
146
155
  const asRef = useRef2(null);
147
156
  const requestOptionsRef = useLatest_default(requestOptions);
148
- const { googleMaps } = useGoogleMaps();
157
+ const {
158
+ googleMaps
159
+ } = useGoogleMaps();
149
160
  const googleMapsRef = useLatest_default(googleMaps);
150
161
  const upaCacheKey = cacheKey ? `upa-${cacheKey}` : "upa";
151
162
  const init = useCallback(() => {
152
- if (asRef.current)
153
- return;
163
+ if (asRef.current) return;
154
164
  if (!googleMaps) {
155
165
  return;
156
166
  }
157
- const { current: gMaps } = googleMapsRef;
167
+ const {
168
+ current: gMaps
169
+ } = googleMapsRef;
158
170
  const placesLib = gMaps?.places || googleMaps.places;
159
171
  if (!placesLib) {
160
172
  return;
@@ -163,71 +175,68 @@ var usePlacesAutocomplete = ({
163
175
  setReady(true);
164
176
  }, [googleMaps]);
165
177
  const clearSuggestions = useCallback(() => {
166
- setSuggestions({ loading: false, status: "", data: [] });
178
+ setSuggestions({
179
+ loading: false,
180
+ status: "",
181
+ data: []
182
+ });
167
183
  }, []);
168
184
  const clearCache = useCallback(() => {
169
185
  try {
170
186
  sessionStorage.removeItem(upaCacheKey);
171
- } catch (error) {
172
- }
187
+ } catch (error) {}
173
188
  }, []);
174
- const fetchPredictions = useCallback(
175
- debounce_default((val) => {
176
- if (!val) {
177
- clearSuggestions();
189
+ const fetchPredictions = useCallback(debounce_default(val => {
190
+ if (!val) {
191
+ clearSuggestions();
192
+ return;
193
+ }
194
+ setSuggestions(prevState => ({
195
+ ...prevState,
196
+ loading: true
197
+ }));
198
+ let cachedData = {};
199
+ try {
200
+ cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
201
+ } catch (error) {}
202
+ if (cache) {
203
+ cachedData = Object.keys(cachedData).reduce((acc, key) => {
204
+ if (cachedData[key].maxAge - Date.now() >= 0) acc[key] = cachedData[key];
205
+ return acc;
206
+ }, {});
207
+ if (cachedData[val]) {
208
+ setSuggestions({
209
+ loading: false,
210
+ status: "OK",
211
+ data: cachedData[val].data
212
+ });
178
213
  return;
179
214
  }
180
- setSuggestions((prevState) => ({ ...prevState, loading: true }));
181
- let cachedData = {};
182
- try {
183
- cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
184
- } catch (error) {
185
- }
186
- if (cache) {
187
- cachedData = Object.keys(cachedData).reduce(
188
- (acc, key) => {
189
- if (cachedData[key].maxAge - Date.now() >= 0)
190
- acc[key] = cachedData[key];
191
- return acc;
192
- },
193
- {}
194
- );
195
- if (cachedData[val]) {
196
- setSuggestions({
197
- loading: false,
198
- status: "OK",
199
- data: cachedData[val].data
200
- });
201
- return;
202
- }
215
+ }
216
+ asRef?.current?.getPlacePredictions({
217
+ ...requestOptionsRef.current,
218
+ input: val
219
+ }, (data, status) => {
220
+ setSuggestions({
221
+ loading: false,
222
+ status,
223
+ data: data || []
224
+ });
225
+ if (cache && status === "OK") {
226
+ cachedData[val] = {
227
+ data,
228
+ maxAge: Date.now() + cache * 1e3
229
+ };
230
+ try {
231
+ sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
232
+ } catch (error) {}
203
233
  }
204
- asRef?.current?.getPlacePredictions(
205
- { ...requestOptionsRef.current, input: val },
206
- (data, status) => {
207
- setSuggestions({ loading: false, status, data: data || [] });
208
- if (cache && status === "OK") {
209
- cachedData[val] = {
210
- data,
211
- maxAge: Date.now() + cache * 1e3
212
- };
213
- try {
214
- sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
215
- } catch (error) {
216
- }
217
- }
218
- }
219
- );
220
- }, debounce2),
221
- [debounce2, clearSuggestions]
222
- );
223
- const setValue = useCallback(
224
- (val, shouldFetchData = true) => {
225
- setVal(val);
226
- if (asRef.current && shouldFetchData)
227
- fetchPredictions(val);
228
- },
229
- [fetchPredictions]
230
- );
234
+ });
235
+ }, debounce2), [debounce2, clearSuggestions]);
236
+ const setValue = useCallback((val, shouldFetchData = true) => {
237
+ setVal(val);
238
+ if (asRef.current && shouldFetchData) fetchPredictions(val);
239
+ }, [fetchPredictions]);
231
240
  useEffect2(() => {
232
241
  if (!initOnMount) {
233
242
  return () => null;
@@ -238,8 +247,7 @@ var usePlacesAutocomplete = ({
238
247
  init();
239
248
  }
240
249
  return () => {
241
- if (window[callbackName])
242
- delete window[callbackName];
250
+ if (window[callbackName]) delete window[callbackName];
243
251
  };
244
252
  }, [callbackName, init]);
245
253
  return {
@@ -252,10 +260,4 @@ var usePlacesAutocomplete = ({
252
260
  init
253
261
  };
254
262
  };
255
- export {
256
- GoogleMapsProvider,
257
- useGeocoder,
258
- useGoogleMaps,
259
- useMap,
260
- usePlacesAutocomplete
261
- };
263
+ export { GoogleMapsProvider, useGeocoder, useGoogleMaps, useMap, usePlacesAutocomplete };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  "use strict";
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,26 +8,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
12
15
  };
13
16
  var __copyProps = (to, from, except, desc) => {
14
17
  if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
18
22
  }
19
23
  return to;
20
24
  };
21
25
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
+ value: mod,
32
+ enumerable: true
33
+ }) : target, mod));
34
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
35
+ value: true
36
+ }), mod);
30
37
 
31
38
  // src/index.ts
32
39
  var src_exports = {};
@@ -66,7 +73,9 @@ var GoogleMapsProvider = ({
66
73
  }
67
74
  return srcTemp;
68
75
  })();
69
- const { status } = (0, import_hooks.useScript)(src);
76
+ const {
77
+ status
78
+ } = (0, import_hooks.useScript)(src);
70
79
  const googleMaps = React2.useMemo(() => {
71
80
  if (status === "ready" && window.google.maps) {
72
81
  return window.google.maps;
@@ -85,14 +94,19 @@ var GoogleMapsProvider = ({
85
94
  googleMaps: null
86
95
  };
87
96
  }, [googleMaps, status]);
88
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GoogleMapsContext.Provider, { value, children });
97
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(GoogleMapsContext.Provider, {
98
+ value,
99
+ children
100
+ });
89
101
  };
90
102
  var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
91
103
 
92
104
  // src/useGeocoder.ts
93
105
  var React3 = __toESM(require("react"));
94
106
  var useGeocoder = () => {
95
- const { googleMaps } = useGoogleMaps();
107
+ const {
108
+ googleMaps
109
+ } = useGoogleMaps();
96
110
  const [isGeocoderInitialized, setIsGeocoderInitialized] = React3.useState(false);
97
111
  const geocoder = React3.useMemo(() => {
98
112
  if (googleMaps) {
@@ -102,7 +116,10 @@ var useGeocoder = () => {
102
116
  }
103
117
  return null;
104
118
  }, [googleMaps]);
105
- return { geocoder, isGeocoderInitialized };
119
+ return {
120
+ geocoder,
121
+ isGeocoderInitialized
122
+ };
106
123
  };
107
124
 
108
125
  // src/useMap.ts
@@ -110,11 +127,10 @@ var React4 = __toESM(require("react"));
110
127
  var import_use_callback_ref = require("use-callback-ref");
111
128
  var useMap = (options = {}) => {
112
129
  const [, forceUpdate] = React4.useState(0);
113
- const ref = (0, import_use_callback_ref.useCallbackRef)(
114
- null,
115
- () => forceUpdate((n) => n + 1)
116
- );
117
- const { googleMaps } = useGoogleMaps();
130
+ const ref = (0, import_use_callback_ref.useCallbackRef)(null, () => forceUpdate(n => n + 1));
131
+ const {
132
+ googleMaps
133
+ } = useGoogleMaps();
118
134
  const map = React4.useMemo(() => {
119
135
  if (googleMaps && ref.current) {
120
136
  return new googleMaps.Map(ref.current, options);
@@ -159,7 +175,7 @@ var debounce_default = debounce;
159
175
 
160
176
  // src/usePlacesAutocomplete/useLatest.ts
161
177
  var import_react = require("react");
162
- var useLatest_default = (val) => {
178
+ var useLatest_default = val => {
163
179
  const ref = (0, import_react.useRef)(val);
164
180
  ref.current = val;
165
181
  return ref;
@@ -184,16 +200,19 @@ var usePlacesAutocomplete = ({
184
200
  });
185
201
  const asRef = (0, import_react2.useRef)(null);
186
202
  const requestOptionsRef = useLatest_default(requestOptions);
187
- const { googleMaps } = useGoogleMaps();
203
+ const {
204
+ googleMaps
205
+ } = useGoogleMaps();
188
206
  const googleMapsRef = useLatest_default(googleMaps);
189
207
  const upaCacheKey = cacheKey ? `upa-${cacheKey}` : "upa";
190
208
  const init = (0, import_react2.useCallback)(() => {
191
- if (asRef.current)
192
- return;
209
+ if (asRef.current) return;
193
210
  if (!googleMaps) {
194
211
  return;
195
212
  }
196
- const { current: gMaps } = googleMapsRef;
213
+ const {
214
+ current: gMaps
215
+ } = googleMapsRef;
197
216
  const placesLib = gMaps?.places || googleMaps.places;
198
217
  if (!placesLib) {
199
218
  return;
@@ -202,71 +221,68 @@ var usePlacesAutocomplete = ({
202
221
  setReady(true);
203
222
  }, [googleMaps]);
204
223
  const clearSuggestions = (0, import_react2.useCallback)(() => {
205
- setSuggestions({ loading: false, status: "", data: [] });
224
+ setSuggestions({
225
+ loading: false,
226
+ status: "",
227
+ data: []
228
+ });
206
229
  }, []);
207
230
  const clearCache = (0, import_react2.useCallback)(() => {
208
231
  try {
209
232
  sessionStorage.removeItem(upaCacheKey);
210
- } catch (error) {
211
- }
233
+ } catch (error) {}
212
234
  }, []);
213
- const fetchPredictions = (0, import_react2.useCallback)(
214
- debounce_default((val) => {
215
- if (!val) {
216
- clearSuggestions();
235
+ const fetchPredictions = (0, import_react2.useCallback)(debounce_default(val => {
236
+ if (!val) {
237
+ clearSuggestions();
238
+ return;
239
+ }
240
+ setSuggestions(prevState => ({
241
+ ...prevState,
242
+ loading: true
243
+ }));
244
+ let cachedData = {};
245
+ try {
246
+ cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
247
+ } catch (error) {}
248
+ if (cache) {
249
+ cachedData = Object.keys(cachedData).reduce((acc, key) => {
250
+ if (cachedData[key].maxAge - Date.now() >= 0) acc[key] = cachedData[key];
251
+ return acc;
252
+ }, {});
253
+ if (cachedData[val]) {
254
+ setSuggestions({
255
+ loading: false,
256
+ status: "OK",
257
+ data: cachedData[val].data
258
+ });
217
259
  return;
218
260
  }
219
- setSuggestions((prevState) => ({ ...prevState, loading: true }));
220
- let cachedData = {};
221
- try {
222
- cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
223
- } catch (error) {
224
- }
225
- if (cache) {
226
- cachedData = Object.keys(cachedData).reduce(
227
- (acc, key) => {
228
- if (cachedData[key].maxAge - Date.now() >= 0)
229
- acc[key] = cachedData[key];
230
- return acc;
231
- },
232
- {}
233
- );
234
- if (cachedData[val]) {
235
- setSuggestions({
236
- loading: false,
237
- status: "OK",
238
- data: cachedData[val].data
239
- });
240
- return;
241
- }
261
+ }
262
+ asRef?.current?.getPlacePredictions({
263
+ ...requestOptionsRef.current,
264
+ input: val
265
+ }, (data, status) => {
266
+ setSuggestions({
267
+ loading: false,
268
+ status,
269
+ data: data || []
270
+ });
271
+ if (cache && status === "OK") {
272
+ cachedData[val] = {
273
+ data,
274
+ maxAge: Date.now() + cache * 1e3
275
+ };
276
+ try {
277
+ sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
278
+ } catch (error) {}
242
279
  }
243
- asRef?.current?.getPlacePredictions(
244
- { ...requestOptionsRef.current, input: val },
245
- (data, status) => {
246
- setSuggestions({ loading: false, status, data: data || [] });
247
- if (cache && status === "OK") {
248
- cachedData[val] = {
249
- data,
250
- maxAge: Date.now() + cache * 1e3
251
- };
252
- try {
253
- sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
254
- } catch (error) {
255
- }
256
- }
257
- }
258
- );
259
- }, debounce2),
260
- [debounce2, clearSuggestions]
261
- );
262
- const setValue = (0, import_react2.useCallback)(
263
- (val, shouldFetchData = true) => {
264
- setVal(val);
265
- if (asRef.current && shouldFetchData)
266
- fetchPredictions(val);
267
- },
268
- [fetchPredictions]
269
- );
280
+ });
281
+ }, debounce2), [debounce2, clearSuggestions]);
282
+ const setValue = (0, import_react2.useCallback)((val, shouldFetchData = true) => {
283
+ setVal(val);
284
+ if (asRef.current && shouldFetchData) fetchPredictions(val);
285
+ }, [fetchPredictions]);
270
286
  (0, import_react2.useEffect)(() => {
271
287
  if (!initOnMount) {
272
288
  return () => null;
@@ -277,8 +293,7 @@ var usePlacesAutocomplete = ({
277
293
  init();
278
294
  }
279
295
  return () => {
280
- if (window[callbackName])
281
- delete window[callbackName];
296
+ if (window[callbackName]) delete window[callbackName];
282
297
  };
283
298
  }, [callbackName, init]);
284
299
  return {
@@ -298,4 +313,4 @@ var usePlacesAutocomplete = ({
298
313
  useGoogleMaps,
299
314
  useMap,
300
315
  usePlacesAutocomplete
301
- });
316
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/google-maps",
3
- "version": "1.22.9",
3
+ "version": "1.22.10",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "typings": "dist/index.d.ts",
21
21
  "dependencies": {
22
- "@ttoss/hooks": "^1.21.9",
22
+ "@ttoss/hooks": "^1.21.10",
23
23
  "@types/google.maps": "^3.49.2",
24
24
  "use-callback-ref": "^1.3.0"
25
25
  },
@@ -28,11 +28,11 @@
28
28
  "react-dom": ">=16.8.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@ttoss/config": "^1.29.1",
32
- "@ttoss/test-utils": "^1.20.8"
31
+ "@ttoss/config": "^1.29.2",
32
+ "@ttoss/test-utils": "^1.20.9"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "ee0c2e51d38f37f997c020d4303cf90be720ecb0"
37
+ "gitHead": "0609bb0f6e6a1c0999c29e7a5c8f8ebb1c6d3d7a"
38
38
  }