@ttoss/google-maps 1.20.5 → 1.20.7

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
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
 
3
3
  // tsup.inject.js
4
4
  import * as React from "react";
@@ -6,6 +6,7 @@ import * as React from "react";
6
6
  // src/GoogleMapsProvider.tsx
7
7
  import * as React2 from "react";
8
8
  import { useScript } from "@ttoss/hooks";
9
+ import { jsx } from "react/jsx-runtime";
9
10
  var GoogleMapsContext = React2.createContext({
10
11
  status: "idle",
11
12
  googleMaps: null
@@ -45,9 +46,10 @@ var GoogleMapsProvider = ({
45
46
  googleMaps: null
46
47
  };
47
48
  }, [googleMaps, status]);
48
- return /* @__PURE__ */ React2.createElement(GoogleMapsContext.Provider, {
49
- value
50
- }, children);
49
+ return /* @__PURE__ */ jsx(GoogleMapsContext.Provider, {
50
+ value,
51
+ children
52
+ });
51
53
  };
52
54
  var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
53
55
 
@@ -72,7 +74,10 @@ import * as React4 from "react";
72
74
  import { useCallbackRef } from "use-callback-ref";
73
75
  var useMap = (options = {}) => {
74
76
  const [, forceUpdate] = React4.useState(0);
75
- const ref = useCallbackRef(null, () => forceUpdate((n) => n + 1));
77
+ const ref = useCallbackRef(
78
+ null,
79
+ () => forceUpdate((n) => n + 1)
80
+ );
76
81
  const { googleMaps } = useGoogleMaps();
77
82
  const map = React4.useMemo(() => {
78
83
  if (googleMaps && ref.current) {
@@ -163,52 +168,64 @@ var usePlacesAutocomplete = ({
163
168
  } catch (error) {
164
169
  }
165
170
  }, []);
166
- const fetchPredictions = useCallback(debounce_default((val) => {
167
- var _a;
168
- if (!val) {
169
- clearSuggestions();
170
- return;
171
- }
172
- setSuggestions((prevState) => ({ ...prevState, loading: true }));
173
- let cachedData = {};
174
- try {
175
- cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
176
- } catch (error) {
177
- }
178
- if (cache) {
179
- cachedData = Object.keys(cachedData).reduce((acc, key) => {
180
- if (cachedData[key].maxAge - Date.now() >= 0)
181
- acc[key] = cachedData[key];
182
- return acc;
183
- }, {});
184
- if (cachedData[val]) {
185
- setSuggestions({
186
- loading: false,
187
- status: "OK",
188
- data: cachedData[val].data
189
- });
171
+ const fetchPredictions = useCallback(
172
+ debounce_default((val) => {
173
+ var _a;
174
+ if (!val) {
175
+ clearSuggestions();
190
176
  return;
191
177
  }
192
- }
193
- (_a = asRef == null ? void 0 : asRef.current) == null ? void 0 : _a.getPlacePredictions({ ...requestOptionsRef.current, input: val }, (data, status) => {
194
- setSuggestions({ loading: false, status, data: data || [] });
195
- if (cache && status === "OK") {
196
- cachedData[val] = {
197
- data,
198
- maxAge: Date.now() + cache * 1e3
199
- };
200
- try {
201
- sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
202
- } catch (error) {
178
+ setSuggestions((prevState) => ({ ...prevState, loading: true }));
179
+ let cachedData = {};
180
+ try {
181
+ cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
182
+ } catch (error) {
183
+ }
184
+ if (cache) {
185
+ cachedData = Object.keys(cachedData).reduce(
186
+ (acc, key) => {
187
+ if (cachedData[key].maxAge - Date.now() >= 0)
188
+ acc[key] = cachedData[key];
189
+ return acc;
190
+ },
191
+ {}
192
+ );
193
+ if (cachedData[val]) {
194
+ setSuggestions({
195
+ loading: false,
196
+ status: "OK",
197
+ data: cachedData[val].data
198
+ });
199
+ return;
203
200
  }
204
201
  }
205
- });
206
- }, debounce2), [debounce2, clearSuggestions]);
207
- const setValue = useCallback((val, shouldFetchData = true) => {
208
- setVal(val);
209
- if (asRef.current && shouldFetchData)
210
- fetchPredictions(val);
211
- }, [fetchPredictions]);
202
+ (_a = asRef == null ? void 0 : asRef.current) == null ? void 0 : _a.getPlacePredictions(
203
+ { ...requestOptionsRef.current, input: val },
204
+ (data, status) => {
205
+ setSuggestions({ loading: false, status, data: data || [] });
206
+ if (cache && status === "OK") {
207
+ cachedData[val] = {
208
+ data,
209
+ maxAge: Date.now() + cache * 1e3
210
+ };
211
+ try {
212
+ sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
213
+ } catch (error) {
214
+ }
215
+ }
216
+ }
217
+ );
218
+ }, debounce2),
219
+ [debounce2, clearSuggestions]
220
+ );
221
+ const setValue = useCallback(
222
+ (val, shouldFetchData = true) => {
223
+ setVal(val);
224
+ if (asRef.current && shouldFetchData)
225
+ fetchPredictions(val);
226
+ },
227
+ [fetchPredictions]
228
+ );
212
229
  useEffect2(() => {
213
230
  if (!initOnMount) {
214
231
  return () => null;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -17,7 +18,10 @@ var __copyProps = (to, from, except, desc) => {
17
18
  }
18
19
  return to;
19
20
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
21
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
26
 
23
27
  // src/index.ts
@@ -37,6 +41,7 @@ var React = __toESM(require("react"));
37
41
  // src/GoogleMapsProvider.tsx
38
42
  var React2 = __toESM(require("react"));
39
43
  var import_hooks = require("@ttoss/hooks");
44
+ var import_jsx_runtime = require("react/jsx-runtime");
40
45
  var GoogleMapsContext = React2.createContext({
41
46
  status: "idle",
42
47
  googleMaps: null
@@ -76,9 +81,10 @@ var GoogleMapsProvider = ({
76
81
  googleMaps: null
77
82
  };
78
83
  }, [googleMaps, status]);
79
- return /* @__PURE__ */ React2.createElement(GoogleMapsContext.Provider, {
80
- value
81
- }, children);
84
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GoogleMapsContext.Provider, {
85
+ value,
86
+ children
87
+ });
82
88
  };
83
89
  var useGoogleMaps = () => React2.useContext(GoogleMapsContext);
84
90
 
@@ -103,7 +109,10 @@ var React4 = __toESM(require("react"));
103
109
  var import_use_callback_ref = require("use-callback-ref");
104
110
  var useMap = (options = {}) => {
105
111
  const [, forceUpdate] = React4.useState(0);
106
- const ref = (0, import_use_callback_ref.useCallbackRef)(null, () => forceUpdate((n) => n + 1));
112
+ const ref = (0, import_use_callback_ref.useCallbackRef)(
113
+ null,
114
+ () => forceUpdate((n) => n + 1)
115
+ );
107
116
  const { googleMaps } = useGoogleMaps();
108
117
  const map = React4.useMemo(() => {
109
118
  if (googleMaps && ref.current) {
@@ -194,52 +203,64 @@ var usePlacesAutocomplete = ({
194
203
  } catch (error) {
195
204
  }
196
205
  }, []);
197
- const fetchPredictions = (0, import_react2.useCallback)(debounce_default((val) => {
198
- var _a;
199
- if (!val) {
200
- clearSuggestions();
201
- return;
202
- }
203
- setSuggestions((prevState) => ({ ...prevState, loading: true }));
204
- let cachedData = {};
205
- try {
206
- cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
207
- } catch (error) {
208
- }
209
- if (cache) {
210
- cachedData = Object.keys(cachedData).reduce((acc, key) => {
211
- if (cachedData[key].maxAge - Date.now() >= 0)
212
- acc[key] = cachedData[key];
213
- return acc;
214
- }, {});
215
- if (cachedData[val]) {
216
- setSuggestions({
217
- loading: false,
218
- status: "OK",
219
- data: cachedData[val].data
220
- });
206
+ const fetchPredictions = (0, import_react2.useCallback)(
207
+ debounce_default((val) => {
208
+ var _a;
209
+ if (!val) {
210
+ clearSuggestions();
221
211
  return;
222
212
  }
223
- }
224
- (_a = asRef == null ? void 0 : asRef.current) == null ? void 0 : _a.getPlacePredictions({ ...requestOptionsRef.current, input: val }, (data, status) => {
225
- setSuggestions({ loading: false, status, data: data || [] });
226
- if (cache && status === "OK") {
227
- cachedData[val] = {
228
- data,
229
- maxAge: Date.now() + cache * 1e3
230
- };
231
- try {
232
- sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
233
- } catch (error) {
213
+ setSuggestions((prevState) => ({ ...prevState, loading: true }));
214
+ let cachedData = {};
215
+ try {
216
+ cachedData = JSON.parse(sessionStorage.getItem(upaCacheKey) || "{}");
217
+ } catch (error) {
218
+ }
219
+ if (cache) {
220
+ cachedData = Object.keys(cachedData).reduce(
221
+ (acc, key) => {
222
+ if (cachedData[key].maxAge - Date.now() >= 0)
223
+ acc[key] = cachedData[key];
224
+ return acc;
225
+ },
226
+ {}
227
+ );
228
+ if (cachedData[val]) {
229
+ setSuggestions({
230
+ loading: false,
231
+ status: "OK",
232
+ data: cachedData[val].data
233
+ });
234
+ return;
234
235
  }
235
236
  }
236
- });
237
- }, debounce2), [debounce2, clearSuggestions]);
238
- const setValue = (0, import_react2.useCallback)((val, shouldFetchData = true) => {
239
- setVal(val);
240
- if (asRef.current && shouldFetchData)
241
- fetchPredictions(val);
242
- }, [fetchPredictions]);
237
+ (_a = asRef == null ? void 0 : asRef.current) == null ? void 0 : _a.getPlacePredictions(
238
+ { ...requestOptionsRef.current, input: val },
239
+ (data, status) => {
240
+ setSuggestions({ loading: false, status, data: data || [] });
241
+ if (cache && status === "OK") {
242
+ cachedData[val] = {
243
+ data,
244
+ maxAge: Date.now() + cache * 1e3
245
+ };
246
+ try {
247
+ sessionStorage.setItem(upaCacheKey, JSON.stringify(cachedData));
248
+ } catch (error) {
249
+ }
250
+ }
251
+ }
252
+ );
253
+ }, debounce2),
254
+ [debounce2, clearSuggestions]
255
+ );
256
+ const setValue = (0, import_react2.useCallback)(
257
+ (val, shouldFetchData = true) => {
258
+ setVal(val);
259
+ if (asRef.current && shouldFetchData)
260
+ fetchPredictions(val);
261
+ },
262
+ [fetchPredictions]
263
+ );
243
264
  (0, import_react2.useEffect)(() => {
244
265
  if (!initOnMount) {
245
266
  return () => null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/google-maps",
3
- "version": "1.20.5",
3
+ "version": "1.20.7",
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.20.4",
22
+ "@ttoss/hooks": "^1.20.6",
23
23
  "@types/google.maps": "^3.49.2",
24
24
  "use-callback-ref": "^1.3.0"
25
25
  },
@@ -28,8 +28,8 @@
28
28
  "react-dom": ">=16.8.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@ttoss/config": "^1.18.0",
32
- "@ttoss/test-utils": "^1.16.7"
31
+ "@ttoss/config": "^1.18.2",
32
+ "@ttoss/test-utils": "^1.16.9"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=12"
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "f5cd08c3e4f80d41492f5d56879348b1bc2948cb"
40
+ "gitHead": "4548135614dd048140cece482703445cf436f39f"
41
41
  }