@dfds-ui/google-places 2.2.0-alpha.e010e72f → 2.2.0-alpha.ea72a60a

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.
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { ILocation, IPrediction } from './GooglePlaces';
3
3
  export declare type AddressSelectProps = {
4
4
  components?: any;
@@ -25,5 +25,5 @@ export declare type AddressSelectProps = {
25
25
  */
26
26
  className?: string;
27
27
  };
28
- declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => JSX.Element;
28
+ declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => React.JSX.Element;
29
29
  export default AddressSelect;
package/GooglePlaces.d.ts CHANGED
@@ -42,7 +42,7 @@ export interface IGooglePlacesAPIProviderProps {
42
42
  language?: string;
43
43
  libraries?: string;
44
44
  }
45
- export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => JSX.Element;
45
+ export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => React.JSX.Element;
46
46
  export declare const useGooglePlacesAPI: () => {
47
47
  available: boolean;
48
48
  };
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { ILocation, IPrediction } from './GooglePlaces';
3
3
  export declare type AddressSelectProps = {
4
4
  components?: any;
@@ -25,5 +25,5 @@ export declare type AddressSelectProps = {
25
25
  */
26
26
  className?: string;
27
27
  };
28
- declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => JSX.Element;
28
+ declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => React.JSX.Element;
29
29
  export default AddressSelect;
@@ -9,64 +9,45 @@ var _reactComponents = require("@dfds-ui/react-components");
9
9
  var _lodash = _interopRequireDefault(require("lodash.debounce"));
10
10
  var _GooglePlaces = require("./GooglePlaces");
11
11
  var _react2 = require("@emotion/react");
12
- const _excluded = ["name", "disabled", "error", "size", "types", "onFocus", "onBlur", "onChange", "location", "radius", "countries"];
13
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
15
14
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
16
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
17
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
18
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
19
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
21
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
22
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
23
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
24
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
25
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
26
- const AddressSelect = _ref => {
27
- let name = _ref.name,
28
- disabled = _ref.disabled,
29
- error = _ref.error,
30
- _ref$size = _ref.size,
31
- size = _ref$size === void 0 ? 'medium' : _ref$size,
32
- types = _ref.types,
33
- onFocus = _ref.onFocus,
34
- onBlur = _ref.onBlur,
35
- onChange = _ref.onChange,
36
- location = _ref.location,
37
- radius = _ref.radius,
38
- _ref$countries = _ref.countries,
39
- countries = _ref$countries === void 0 ? [] : _ref$countries,
40
- rest = _objectWithoutProperties(_ref, _excluded);
41
- const _useState = (0, _react.useState)([]),
42
- _useState2 = _slicedToArray(_useState, 2),
43
- predictions = _useState2[0],
44
- setPredictions = _useState2[1];
45
- const _useAddressPrediction = (0, _GooglePlaces.useAddressPredictions)('', {
46
- types,
47
- location,
48
- radius,
49
- components: {
50
- countries
51
- }
52
- }),
53
- available = _useAddressPrediction.available,
54
- getPlacePredictions = _useAddressPrediction.getPlacePredictions;
55
- const loadOptions = /*#__PURE__*/function () {
56
- var _ref2 = _asyncToGenerator(function* (input, callback) {
57
- const placePredictions = yield getPlacePredictions(input);
58
- setPredictions(placePredictions);
59
- const options = placePredictions.map(prediction => ({
60
- value: prediction.description,
61
- label: prediction.description,
62
- prediction
63
- }));
64
- callback(options);
65
- });
66
- return function loadOptions(_x, _x2) {
67
- return _ref2.apply(this, arguments);
68
- };
69
- }();
15
+ const AddressSelect = ({
16
+ name,
17
+ disabled,
18
+ error,
19
+ size = 'medium',
20
+ types,
21
+ onFocus,
22
+ onBlur,
23
+ onChange,
24
+ location,
25
+ radius,
26
+ countries = [],
27
+ ...rest
28
+ }) => {
29
+ const [predictions, setPredictions] = (0, _react.useState)([]);
30
+ const {
31
+ available,
32
+ getPlacePredictions
33
+ } = (0, _GooglePlaces.useAddressPredictions)('', {
34
+ types,
35
+ location,
36
+ radius,
37
+ components: {
38
+ countries
39
+ }
40
+ });
41
+ const loadOptions = async (input, callback) => {
42
+ const placePredictions = await getPlacePredictions(input);
43
+ setPredictions(placePredictions);
44
+ const options = placePredictions.map(prediction => ({
45
+ value: prediction.description,
46
+ label: prediction.description,
47
+ prediction
48
+ }));
49
+ callback(options);
50
+ };
70
51
  const handleChange = value => {
71
52
  if (onChange) {
72
53
  onChange(value, predictions);
@@ -42,7 +42,7 @@ export interface IGooglePlacesAPIProviderProps {
42
42
  language?: string;
43
43
  libraries?: string;
44
44
  }
45
- export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => JSX.Element;
45
+ export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => React.JSX.Element;
46
46
  export declare const useGooglePlacesAPI: () => {
47
47
  available: boolean;
48
48
  };
@@ -7,13 +7,9 @@ exports.useGooglePlacesAPI = exports.useAddressPredictions = exports.GooglePlace
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _hooks = require("@dfds-ui/hooks");
9
9
  var _react2 = require("@emotion/react");
10
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
12
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /// <reference types="@types/googlemaps" />
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
+ /// <reference types="@types/googlemaps" />
12
+
17
13
  const GooglePlacesAPIContext = /*#__PURE__*/(0, _react.createContext)({
18
14
  available: false
19
15
  });
@@ -24,12 +20,11 @@ const GooglePlacesAPIProvider = ({
24
20
  language,
25
21
  libraries = 'places'
26
22
  }) => {
27
- var _window, _window$google;
28
23
  // On SSR window does not exist.
29
24
  const hasWindow = typeof window !== 'undefined';
30
25
 
31
26
  // We want to prevent the google maps api to be loaded more than once
32
- const isGoogleMapsDefined = hasWindow && Boolean((_window = window) === null || _window === void 0 ? void 0 : (_window$google = _window.google) === null || _window$google === void 0 ? void 0 : _window$google.maps);
27
+ const isGoogleMapsDefined = hasWindow && Boolean(window?.google?.maps);
33
28
  const languageParam = language ? `&language=${language}` : '';
34
29
  // NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
35
30
  // Dummy callback to satisfy Google Maps API.
@@ -40,14 +35,8 @@ const GooglePlacesAPIProvider = ({
40
35
  if (hasWindow) window.dummyCallback = dummyCallback;
41
36
  const callback = hasWindow ? `&callback=dummyCallback` : '';
42
37
  const scriptUrl = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries}${languageParam}${callback}`;
43
- const _useScript = (0, _hooks.useScript)(scriptUrl, isGoogleMapsDefined),
44
- _useScript2 = _slicedToArray(_useScript, 2),
45
- loaded = _useScript2[0],
46
- error = _useScript2[1];
47
- const _useState = (0, _react.useState)(false),
48
- _useState2 = _slicedToArray(_useState, 2),
49
- available = _useState2[0],
50
- setAvailable = _useState2[1];
38
+ const [loaded, error] = (0, _hooks.useScript)(scriptUrl, isGoogleMapsDefined);
39
+ const [available, setAvailable] = (0, _react.useState)(false);
51
40
  (0, _react.useEffect)(() => {
52
41
  setAvailable(loaded && !error);
53
42
  if (error) {
@@ -75,12 +64,10 @@ const useAddressPredictions = (input, {
75
64
  radius,
76
65
  components
77
66
  }) => {
78
- const _useState3 = (0, _react.useState)([]),
79
- _useState4 = _slicedToArray(_useState3, 2),
80
- predictions = _useState4[0],
81
- setPredictions = _useState4[1];
82
- const _useGooglePlacesAPI = useGooglePlacesAPI(),
83
- available = _useGooglePlacesAPI.available;
67
+ const [predictions, setPredictions] = (0, _react.useState)([]);
68
+ const {
69
+ available
70
+ } = useGooglePlacesAPI();
84
71
  const autocomplete = (0, _react.useRef)();
85
72
  if (!autocomplete.current && available && typeof window !== 'undefined') {
86
73
  autocomplete.current = new google.maps.places.AutocompleteService();
@@ -99,8 +86,7 @@ const useAddressPredictions = (input, {
99
86
  country: components.countries
100
87
  }
101
88
  }, predictions => {
102
- var _predictions;
103
- predictions = (_predictions = predictions) !== null && _predictions !== void 0 ? _predictions : [];
89
+ predictions = predictions ?? [];
104
90
  setPredictions(predictions);
105
91
  resolve(predictions);
106
92
  });
package/cjs/index.js CHANGED
@@ -8,7 +8,7 @@ var _exportNames = {
8
8
  };
9
9
  Object.defineProperty(exports, "AddressSelect", {
10
10
  enumerable: true,
11
- get: function get() {
11
+ get: function () {
12
12
  return _AddressSelect.default;
13
13
  }
14
14
  });
@@ -19,7 +19,7 @@ Object.keys(_GooglePlaces).forEach(function (key) {
19
19
  if (key in exports && exports[key] === _GooglePlaces[key]) return;
20
20
  Object.defineProperty(exports, key, {
21
21
  enumerable: true,
22
- get: function get() {
22
+ get: function () {
23
23
  return _GooglePlaces[key];
24
24
  }
25
25
  });
@@ -31,9 +31,9 @@ Object.keys(_AddressSelect).forEach(function (key) {
31
31
  if (key in exports && exports[key] === _AddressSelect[key]) return;
32
32
  Object.defineProperty(exports, key, {
33
33
  enumerable: true,
34
- get: function get() {
34
+ get: function () {
35
35
  return _AddressSelect[key];
36
36
  }
37
37
  });
38
38
  });
39
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
39
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
package/package.json CHANGED
@@ -3,26 +3,26 @@
3
3
  "description": "Components using Google places",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.2.0-alpha.e010e72f",
6
+ "version": "2.2.0-alpha.ea72a60a",
7
7
  "sideEffects": false,
8
8
  "main": "./cjs/index.js",
9
9
  "module": "./index.js",
10
10
  "esnext": "./index.js",
11
11
  "typings": "./index.d.ts",
12
12
  "peerDependencies": {
13
- "react": ">= 17.0.2",
14
- "react-dom": ">= 17.0.2"
13
+ "react": ">= 18.3.1",
14
+ "react-dom": ">= 18.3.1"
15
15
  },
16
16
  "dependencies": {
17
- "@dfds-ui/colors": "2.2.0-alpha.e010e72f",
18
- "@dfds-ui/hooks": "2.2.0-alpha.e010e72f",
19
- "@dfds-ui/icons": "2.2.0-alpha.e010e72f",
20
- "@dfds-ui/react-components": "2.2.0-alpha.e010e72f",
17
+ "@dfds-ui/colors": "2.2.0-alpha.ea72a60a",
18
+ "@dfds-ui/hooks": "2.2.0-alpha.ea72a60a",
19
+ "@dfds-ui/icons": "2.2.0-alpha.ea72a60a",
20
+ "@dfds-ui/react-components": "2.2.0-alpha.ea72a60a",
21
21
  "@types/googlemaps": "3.43.3",
22
- "@types/lodash.debounce": "^4.0.7",
22
+ "@types/lodash.debounce": "^4.0.9",
23
23
  "lodash.debounce": "^4.0.8"
24
24
  },
25
- "gitHead": "e010e72fc63a082f93fa8023dc3c751d4fbf2016",
25
+ "gitHead": "ea72a60a96392ec89dc55677d4e1f6ca13c547c9",
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  }