@dfds-ui/google-places 2.2.0-alpha.98e68873 → 2.2.0-alpha.9edc847c

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Components using Google places",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "2.2.0-alpha.98e68873",
6
+ "version": "2.2.0-alpha.9edc847c",
7
7
  "sideEffects": false,
8
8
  "main": "./cjs/index.js",
9
9
  "module": "./index.js",
@@ -14,15 +14,15 @@
14
14
  "react-dom": ">= 18.3.1"
15
15
  },
16
16
  "dependencies": {
17
- "@dfds-ui/colors": "2.2.0-alpha.98e68873",
18
- "@dfds-ui/hooks": "2.2.0-alpha.98e68873",
19
- "@dfds-ui/icons": "2.2.0-alpha.98e68873",
20
- "@dfds-ui/react-components": "2.2.0-alpha.98e68873",
17
+ "@dfds-ui/colors": "2.2.0-alpha.9edc847c",
18
+ "@dfds-ui/hooks": "2.2.0-alpha.9edc847c",
19
+ "@dfds-ui/icons": "2.2.0-alpha.9edc847c",
20
+ "@dfds-ui/react-components": "2.2.0-alpha.9edc847c",
21
21
  "@types/googlemaps": "3.43.3",
22
22
  "@types/lodash.debounce": "^4.0.9",
23
23
  "lodash.debounce": "^4.0.8"
24
24
  },
25
- "gitHead": "98e68873ace8ad4db37fd407dfe757396da57ac8",
25
+ "gitHead": "9edc847c21d2f86054d768d1f84d34027ca9d675",
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  }
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { ILocation, IPrediction } from './GooglePlaces';
3
- export declare type AddressSelectProps = {
4
- components?: any;
5
- name: string;
6
- disabled?: boolean;
7
- error?: string;
8
- size?: 'small' | 'medium';
9
- types?: string[];
10
- onFocus?: (event: FocusEvent) => void;
11
- onBlur?: (event: FocusEvent) => void;
12
- onChange?: (changed: {
13
- value: string;
14
- label: string;
15
- }, predictions: IPrediction[]) => void;
16
- location?: ILocation;
17
- radius?: number;
18
- countries?: string[] | string;
19
- placeholder?: string;
20
- assistiveText?: string;
21
- autoFocus?: boolean;
22
- isClearable?: boolean;
23
- /**
24
- * Class name to be assigned to the component
25
- */
26
- className?: string;
27
- };
28
- declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => React.JSX.Element;
29
- export default AddressSelect;
package/AddressSelect.js DELETED
@@ -1,104 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["name", "disabled", "error", "size", "types", "onFocus", "onBlur", "onChange", "location", "radius", "countries"];
3
- 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); }
4
- function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && o.reverse()); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
5
- function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
6
- function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) { r.unshift(t); } return function e() { for (; r.length;) { if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; } return e.done = !0, e; }; }
7
- function _regeneratorAsync(n, e, r, t, o) { var a = _regeneratorAsyncGen(n, e, r, t, o); return a.next().then(function (n) { return n.done ? n.value : a.next(); }); }
8
- function _regeneratorAsyncGen(r, e, t, o, n) { return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise); }
9
- function _regeneratorAsyncIterator(t, e) { function n(r, o, i, f) { try { var c = t[r](o), u = c.value; return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) { n("next", t, i, f); }, function (t) { n("throw", t, i, f); }) : e.resolve(u).then(function (t) { c.value = t, i(c); }, function (t) { return n("throw", t, i, f); }); } catch (t) { f(t); } } var r; this.next || (_regeneratorDefine2(_regeneratorAsyncIterator.prototype), _regeneratorDefine2(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () { return this; })), _regeneratorDefine2(this, "_invoke", function (t, o, i) { function f() { return new e(function (e, r) { n(t, i, e, r); }); } return r = r ? r.then(f, f) : f(); }, !0); }
10
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
11
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
12
- function _OverloadYield(e, d) { this.v = e, this.k = d; }
13
- 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); }
14
- 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); }); }; }
15
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
16
- 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."); }
17
- 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; } }
18
- 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; }
19
- 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; } }
20
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
21
- 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; }
22
- 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; }
23
- import React, { useState } from 'react';
24
- import { AsyncSearchableSelect } from '@dfds-ui/react-components';
25
- import debounce from 'lodash.debounce';
26
- import { useAddressPredictions } from './GooglePlaces';
27
- import { jsx as ___EmotionJSX } from "@emotion/react";
28
- var AddressSelect = function AddressSelect(_ref) {
29
- var name = _ref.name,
30
- disabled = _ref.disabled,
31
- error = _ref.error,
32
- _ref$size = _ref.size,
33
- size = _ref$size === void 0 ? 'medium' : _ref$size,
34
- types = _ref.types,
35
- onFocus = _ref.onFocus,
36
- onBlur = _ref.onBlur,
37
- onChange = _ref.onChange,
38
- location = _ref.location,
39
- radius = _ref.radius,
40
- _ref$countries = _ref.countries,
41
- countries = _ref$countries === void 0 ? [] : _ref$countries,
42
- rest = _objectWithoutProperties(_ref, _excluded);
43
- var _useState = useState([]),
44
- _useState2 = _slicedToArray(_useState, 2),
45
- predictions = _useState2[0],
46
- setPredictions = _useState2[1];
47
- var _useAddressPrediction = useAddressPredictions('', {
48
- types: types,
49
- location: location,
50
- radius: radius,
51
- components: {
52
- countries: countries
53
- }
54
- }),
55
- available = _useAddressPrediction.available,
56
- getPlacePredictions = _useAddressPrediction.getPlacePredictions;
57
- var loadOptions = /*#__PURE__*/function () {
58
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, callback) {
59
- var placePredictions, options;
60
- return _regeneratorRuntime().wrap(function _callee$(_context) {
61
- while (1) {
62
- switch (_context.prev = _context.next) {
63
- case 0:
64
- _context.next = 2;
65
- return getPlacePredictions(input);
66
- case 2:
67
- placePredictions = _context.sent;
68
- setPredictions(placePredictions);
69
- options = placePredictions.map(function (prediction) {
70
- return {
71
- value: prediction.description,
72
- label: prediction.description,
73
- prediction: prediction
74
- };
75
- });
76
- callback(options);
77
- case 6:
78
- case "end":
79
- return _context.stop();
80
- }
81
- }
82
- }, _callee);
83
- }));
84
- return function loadOptions(_x, _x2) {
85
- return _ref2.apply(this, arguments);
86
- };
87
- }();
88
- var handleChange = function handleChange(value) {
89
- if (onChange) {
90
- onChange(value, predictions);
91
- }
92
- };
93
- return ___EmotionJSX(AsyncSearchableSelect, _extends({
94
- disabled: disabled || !available,
95
- name: name,
96
- error: error,
97
- size: size,
98
- onChange: handleChange,
99
- loadOptions: debounce(loadOptions, 500),
100
- onFocus: onFocus,
101
- onBlur: onBlur
102
- }, rest));
103
- };
104
- export default AddressSelect;
package/GooglePlaces.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- export declare const GooglePlacesAPIContext: React.Context<{
3
- available: boolean;
4
- }>;
5
- export interface ILocation {
6
- lat: number;
7
- lng: number;
8
- }
9
- interface IPredictionsOptions {
10
- types?: string[] | undefined;
11
- location?: ILocation | undefined;
12
- radius?: number | undefined;
13
- components: {
14
- countries: string | string[] | undefined;
15
- };
16
- }
17
- interface IPredictionSubstring {
18
- length: number;
19
- offset: number;
20
- }
21
- interface IAutocompleteStructuredFormatting {
22
- main_text: string;
23
- main_text_matched_substrings: IPredictionSubstring[];
24
- secondary_text: string;
25
- }
26
- interface IPredictionTerm {
27
- offset: number;
28
- value: string;
29
- }
30
- export interface IPrediction {
31
- description: string;
32
- matched_substrings: IPredictionSubstring[];
33
- place_id: string;
34
- reference: string;
35
- structured_formatting: IAutocompleteStructuredFormatting;
36
- terms: IPredictionTerm[];
37
- types: string[];
38
- }
39
- export interface IGooglePlacesAPIProviderProps {
40
- children: React.ReactNode;
41
- apiKey: string;
42
- language?: string;
43
- libraries?: string;
44
- }
45
- export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => React.JSX.Element;
46
- export declare const useGooglePlacesAPI: () => {
47
- available: boolean;
48
- };
49
- export declare const useAddressPredictions: (input: string, { types, location, radius, components }: IPredictionsOptions) => {
50
- available: boolean;
51
- predictions: IPrediction[];
52
- getPlacePredictions: (input: string) => Promise<IPrediction[]>;
53
- };
54
- export {};
package/GooglePlaces.js DELETED
@@ -1,114 +0,0 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- 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."); }
3
- 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; } }
4
- 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; }
5
- 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; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
- /// <reference types="@types/googlemaps" />
8
- import React, { createContext, useState, useContext, useRef, useEffect } from 'react';
9
- import { useScript } from '@dfds-ui/hooks';
10
- import { jsx as ___EmotionJSX } from "@emotion/react";
11
- export var GooglePlacesAPIContext = /*#__PURE__*/createContext({
12
- available: false
13
- });
14
- export var GooglePlacesAPIProvider = function GooglePlacesAPIProvider(_ref) {
15
- var _window, _window$google;
16
- var children = _ref.children,
17
- apiKey = _ref.apiKey,
18
- language = _ref.language,
19
- _ref$libraries = _ref.libraries,
20
- libraries = _ref$libraries === void 0 ? 'places' : _ref$libraries;
21
- // On SSR window does not exist.
22
- var hasWindow = typeof window !== 'undefined';
23
-
24
- // We want to prevent the google maps api to be loaded more than once
25
- var 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);
26
- var languageParam = language ? "&language=".concat(language) : '';
27
- // NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
28
- // Dummy callback to satisfy Google Maps API.
29
- var dummyCallback = function dummyCallback() {
30
- return;
31
- };
32
- // @ts-expect-error dummyCallback does not exist on window. A callback is required by Google Maps API.
33
- if (hasWindow) window.dummyCallback = dummyCallback;
34
- var callback = hasWindow ? "&callback=dummyCallback" : '';
35
- var scriptUrl = "https://maps.googleapis.com/maps/api/js?key=".concat(apiKey, "&libraries=").concat(libraries).concat(languageParam).concat(callback);
36
- var _useScript = useScript(scriptUrl, isGoogleMapsDefined),
37
- _useScript2 = _slicedToArray(_useScript, 2),
38
- loaded = _useScript2[0],
39
- error = _useScript2[1];
40
- var _useState = useState(false),
41
- _useState2 = _slicedToArray(_useState, 2),
42
- available = _useState2[0],
43
- setAvailable = _useState2[1];
44
- useEffect(function () {
45
- setAvailable(loaded && !error);
46
- if (error) {
47
- throw new Error('Google Places API script failed to load');
48
- }
49
- }, [loaded, error]);
50
- return ___EmotionJSX(GooglePlacesAPIContext.Provider, {
51
- value: {
52
- available: available
53
- }
54
- }, children);
55
- };
56
- export var useGooglePlacesAPI = function useGooglePlacesAPI() {
57
- var context = useContext(GooglePlacesAPIContext);
58
- if (context === undefined) {
59
- throw new Error('useGooglePlaces must be used inside of GooglePlacesAPIProvider');
60
- }
61
- return context;
62
- };
63
- export var useAddressPredictions = function useAddressPredictions(input, _ref2) {
64
- var types = _ref2.types,
65
- location = _ref2.location,
66
- radius = _ref2.radius,
67
- components = _ref2.components;
68
- var _useState3 = useState([]),
69
- _useState4 = _slicedToArray(_useState3, 2),
70
- predictions = _useState4[0],
71
- setPredictions = _useState4[1];
72
- var _useGooglePlacesAPI = useGooglePlacesAPI(),
73
- available = _useGooglePlacesAPI.available;
74
- var autocomplete = useRef();
75
- if (!autocomplete.current && available && typeof window !== 'undefined') {
76
- autocomplete.current = new google.maps.places.AutocompleteService();
77
- }
78
- function getPlacePredictions(input) {
79
- return new Promise(function (resolve) {
80
- autocomplete.current.getPlacePredictions({
81
- input: input,
82
- types: types,
83
- radius: radius,
84
- location: location !== undefined ? {
85
- lat: function lat() {
86
- return location !== undefined ? location.lat : undefined;
87
- },
88
- lng: function lng() {
89
- return location !== undefined ? location.lng : undefined;
90
- }
91
- } : undefined,
92
- componentRestrictions: {
93
- country: components.countries
94
- }
95
- }, function (predictions) {
96
- var _predictions;
97
- predictions = (_predictions = predictions) !== null && _predictions !== void 0 ? _predictions : [];
98
- setPredictions(predictions);
99
- resolve(predictions);
100
- });
101
- });
102
- }
103
- useEffect(function () {
104
- if (input !== '') {
105
- void getPlacePredictions(input);
106
- }
107
- // eslint-disable-next-line react-hooks/exhaustive-deps
108
- }, [input]);
109
- return {
110
- available: available,
111
- predictions: predictions,
112
- getPlacePredictions: getPlacePredictions
113
- };
114
- };
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { ILocation, IPrediction } from './GooglePlaces';
3
- export declare type AddressSelectProps = {
4
- components?: any;
5
- name: string;
6
- disabled?: boolean;
7
- error?: string;
8
- size?: 'small' | 'medium';
9
- types?: string[];
10
- onFocus?: (event: FocusEvent) => void;
11
- onBlur?: (event: FocusEvent) => void;
12
- onChange?: (changed: {
13
- value: string;
14
- label: string;
15
- }, predictions: IPrediction[]) => void;
16
- location?: ILocation;
17
- radius?: number;
18
- countries?: string[] | string;
19
- placeholder?: string;
20
- assistiveText?: string;
21
- autoFocus?: boolean;
22
- isClearable?: boolean;
23
- /**
24
- * Class name to be assigned to the component
25
- */
26
- className?: string;
27
- };
28
- declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => React.JSX.Element;
29
- export default AddressSelect;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _reactComponents = require("@dfds-ui/react-components");
9
- var _lodash = _interopRequireDefault(require("lodash.debounce"));
10
- var _GooglePlaces = require("./GooglePlaces");
11
- var _react2 = require("@emotion/react");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
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); }
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
- };
51
- const handleChange = value => {
52
- if (onChange) {
53
- onChange(value, predictions);
54
- }
55
- };
56
- return (0, _react2.jsx)(_reactComponents.AsyncSearchableSelect, _extends({
57
- disabled: disabled || !available,
58
- name: name,
59
- error: error,
60
- size: size,
61
- onChange: handleChange,
62
- loadOptions: (0, _lodash.default)(loadOptions, 500),
63
- onFocus: onFocus,
64
- onBlur: onBlur
65
- }, rest));
66
- };
67
- var _default = AddressSelect;
68
- exports.default = _default;
@@ -1,54 +0,0 @@
1
- import React from 'react';
2
- export declare const GooglePlacesAPIContext: React.Context<{
3
- available: boolean;
4
- }>;
5
- export interface ILocation {
6
- lat: number;
7
- lng: number;
8
- }
9
- interface IPredictionsOptions {
10
- types?: string[] | undefined;
11
- location?: ILocation | undefined;
12
- radius?: number | undefined;
13
- components: {
14
- countries: string | string[] | undefined;
15
- };
16
- }
17
- interface IPredictionSubstring {
18
- length: number;
19
- offset: number;
20
- }
21
- interface IAutocompleteStructuredFormatting {
22
- main_text: string;
23
- main_text_matched_substrings: IPredictionSubstring[];
24
- secondary_text: string;
25
- }
26
- interface IPredictionTerm {
27
- offset: number;
28
- value: string;
29
- }
30
- export interface IPrediction {
31
- description: string;
32
- matched_substrings: IPredictionSubstring[];
33
- place_id: string;
34
- reference: string;
35
- structured_formatting: IAutocompleteStructuredFormatting;
36
- terms: IPredictionTerm[];
37
- types: string[];
38
- }
39
- export interface IGooglePlacesAPIProviderProps {
40
- children: React.ReactNode;
41
- apiKey: string;
42
- language?: string;
43
- libraries?: string;
44
- }
45
- export declare const GooglePlacesAPIProvider: ({ children, apiKey, language, libraries, }: IGooglePlacesAPIProviderProps) => React.JSX.Element;
46
- export declare const useGooglePlacesAPI: () => {
47
- available: boolean;
48
- };
49
- export declare const useAddressPredictions: (input: string, { types, location, radius, components }: IPredictionsOptions) => {
50
- available: boolean;
51
- predictions: IPrediction[];
52
- getPlacePredictions: (input: string) => Promise<IPrediction[]>;
53
- };
54
- export {};
@@ -1,107 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useGooglePlacesAPI = exports.useAddressPredictions = exports.GooglePlacesAPIProvider = exports.GooglePlacesAPIContext = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _hooks = require("@dfds-ui/hooks");
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 (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
-
13
- const GooglePlacesAPIContext = /*#__PURE__*/(0, _react.createContext)({
14
- available: false
15
- });
16
- exports.GooglePlacesAPIContext = GooglePlacesAPIContext;
17
- const GooglePlacesAPIProvider = ({
18
- children,
19
- apiKey,
20
- language,
21
- libraries = 'places'
22
- }) => {
23
- // On SSR window does not exist.
24
- const hasWindow = typeof window !== 'undefined';
25
-
26
- // We want to prevent the google maps api to be loaded more than once
27
- const isGoogleMapsDefined = hasWindow && Boolean(window?.google?.maps);
28
- const languageParam = language ? `&language=${language}` : '';
29
- // NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
30
- // Dummy callback to satisfy Google Maps API.
31
- const dummyCallback = () => {
32
- return;
33
- };
34
- // @ts-expect-error dummyCallback does not exist on window. A callback is required by Google Maps API.
35
- if (hasWindow) window.dummyCallback = dummyCallback;
36
- const callback = hasWindow ? `&callback=dummyCallback` : '';
37
- const scriptUrl = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries}${languageParam}${callback}`;
38
- const [loaded, error] = (0, _hooks.useScript)(scriptUrl, isGoogleMapsDefined);
39
- const [available, setAvailable] = (0, _react.useState)(false);
40
- (0, _react.useEffect)(() => {
41
- setAvailable(loaded && !error);
42
- if (error) {
43
- throw new Error('Google Places API script failed to load');
44
- }
45
- }, [loaded, error]);
46
- return (0, _react2.jsx)(GooglePlacesAPIContext.Provider, {
47
- value: {
48
- available
49
- }
50
- }, children);
51
- };
52
- exports.GooglePlacesAPIProvider = GooglePlacesAPIProvider;
53
- const useGooglePlacesAPI = () => {
54
- const context = (0, _react.useContext)(GooglePlacesAPIContext);
55
- if (context === undefined) {
56
- throw new Error('useGooglePlaces must be used inside of GooglePlacesAPIProvider');
57
- }
58
- return context;
59
- };
60
- exports.useGooglePlacesAPI = useGooglePlacesAPI;
61
- const useAddressPredictions = (input, {
62
- types,
63
- location,
64
- radius,
65
- components
66
- }) => {
67
- const [predictions, setPredictions] = (0, _react.useState)([]);
68
- const {
69
- available
70
- } = useGooglePlacesAPI();
71
- const autocomplete = (0, _react.useRef)();
72
- if (!autocomplete.current && available && typeof window !== 'undefined') {
73
- autocomplete.current = new google.maps.places.AutocompleteService();
74
- }
75
- function getPlacePredictions(input) {
76
- return new Promise(resolve => {
77
- autocomplete.current.getPlacePredictions({
78
- input,
79
- types,
80
- radius,
81
- location: location !== undefined ? {
82
- lat: () => location !== undefined ? location.lat : undefined,
83
- lng: () => location !== undefined ? location.lng : undefined
84
- } : undefined,
85
- componentRestrictions: {
86
- country: components.countries
87
- }
88
- }, predictions => {
89
- predictions = predictions ?? [];
90
- setPredictions(predictions);
91
- resolve(predictions);
92
- });
93
- });
94
- }
95
- (0, _react.useEffect)(() => {
96
- if (input !== '') {
97
- void getPlacePredictions(input);
98
- }
99
- // eslint-disable-next-line react-hooks/exhaustive-deps
100
- }, [input]);
101
- return {
102
- available,
103
- predictions,
104
- getPlacePredictions
105
- };
106
- };
107
- exports.useAddressPredictions = useAddressPredictions;
package/cjs/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './GooglePlaces';
2
- export { default as AddressSelect } from './AddressSelect';
3
- export * from './AddressSelect';
package/cjs/index.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- AddressSelect: true
8
- };
9
- Object.defineProperty(exports, "AddressSelect", {
10
- enumerable: true,
11
- get: function () {
12
- return _AddressSelect.default;
13
- }
14
- });
15
- var _GooglePlaces = require("./GooglePlaces");
16
- Object.keys(_GooglePlaces).forEach(function (key) {
17
- if (key === "default" || key === "__esModule") return;
18
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
19
- if (key in exports && exports[key] === _GooglePlaces[key]) return;
20
- Object.defineProperty(exports, key, {
21
- enumerable: true,
22
- get: function () {
23
- return _GooglePlaces[key];
24
- }
25
- });
26
- });
27
- var _AddressSelect = _interopRequireWildcard(require("./AddressSelect"));
28
- Object.keys(_AddressSelect).forEach(function (key) {
29
- if (key === "default" || key === "__esModule") return;
30
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
- if (key in exports && exports[key] === _AddressSelect[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _AddressSelect[key];
36
- }
37
- });
38
- });
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/cjs/typings.d.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
package/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './GooglePlaces';
2
- export { default as AddressSelect } from './AddressSelect';
3
- export * from './AddressSelect';
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './GooglePlaces';
2
- export { default as AddressSelect } from './AddressSelect';
3
- export * from './AddressSelect';
package/typings.d.js DELETED
File without changes