@dfds-ui/google-places 2.0.5 → 2.0.6-alpha.5572bc2f
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 +6 -6
- package/AddressSelect.d.ts +0 -28
- package/GooglePlaces.d.ts +0 -54
- package/GooglePlaces.js +0 -111
- package/cjs/AddressSelect.d.ts +0 -28
- package/cjs/GooglePlaces.d.ts +0 -54
- package/cjs/GooglePlaces.js +0 -119
- package/cjs/index.d.ts +0 -3
- package/cjs/index.js +0 -40
- package/cjs/typings.d.js +0 -1
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/typings.d.js +0 -0
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.0.
|
|
6
|
+
"version": "2.0.6-alpha.5572bc2f",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"main": "./cjs/index.js",
|
|
9
9
|
"module": "./index.js",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"react-dom": ">= 17.0.2"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@dfds-ui/colors": "2.0.
|
|
18
|
-
"@dfds-ui/hooks": "2.0.
|
|
19
|
-
"@dfds-ui/icons": "2.0.
|
|
20
|
-
"@dfds-ui/react-components": "2.0.
|
|
17
|
+
"@dfds-ui/colors": "2.0.6-alpha.5572bc2f",
|
|
18
|
+
"@dfds-ui/hooks": "2.0.6-alpha.5572bc2f",
|
|
19
|
+
"@dfds-ui/icons": "2.0.6-alpha.5572bc2f",
|
|
20
|
+
"@dfds-ui/react-components": "2.0.6-alpha.5572bc2f",
|
|
21
21
|
"@types/googlemaps": "3.43.3",
|
|
22
22
|
"@types/lodash.debounce": "^4.0.7",
|
|
23
23
|
"lodash.debounce": "^4.0.8"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "5572bc2fdf5f83fd37a9b0aa45508b7b834e5632",
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
}
|
package/AddressSelect.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ILocation, IPrediction } from './GooglePlaces';
|
|
3
|
-
export declare type AddressSelectProps = {
|
|
4
|
-
name: string;
|
|
5
|
-
disabled?: boolean;
|
|
6
|
-
error?: string;
|
|
7
|
-
size?: 'small' | 'medium';
|
|
8
|
-
types?: string[];
|
|
9
|
-
onFocus?: (event: FocusEvent) => void;
|
|
10
|
-
onBlur?: (event: FocusEvent) => void;
|
|
11
|
-
onChange?: (changed: {
|
|
12
|
-
value: string;
|
|
13
|
-
label: string;
|
|
14
|
-
}, predictions: IPrediction[]) => void;
|
|
15
|
-
location?: ILocation;
|
|
16
|
-
radius?: number;
|
|
17
|
-
countries?: string[] | string;
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
assistiveText?: string;
|
|
20
|
-
autoFocus?: boolean;
|
|
21
|
-
isClearable?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Class name to be assigned to the component
|
|
24
|
-
*/
|
|
25
|
-
className?: string;
|
|
26
|
-
};
|
|
27
|
-
declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => JSX.Element;
|
|
28
|
-
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) => 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,111 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
5
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
6
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
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
|
-
// We want to prevent the google maps api to be loaded more than once
|
|
22
|
-
var isGoogleMapsDefined = typeof window !== 'undefined' && Boolean((_window = window) === null || _window === void 0 ? void 0 : (_window$google = _window.google) === null || _window$google === void 0 ? void 0 : _window$google.maps);
|
|
23
|
-
var languageParam = language ? "&language=".concat(language) : '';
|
|
24
|
-
// NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
|
|
25
|
-
// Dummy callback to satisfy Google Maps API.
|
|
26
|
-
var dummyCallback = function dummyCallback() {
|
|
27
|
-
return;
|
|
28
|
-
};
|
|
29
|
-
// @ts-expect-error dummyCallback does not exist on window. A callback is required by Google Maps API.
|
|
30
|
-
window.dummyCallback = dummyCallback;
|
|
31
|
-
var callback = "&callback=dummyCallback";
|
|
32
|
-
var scriptUrl = "https://maps.googleapis.com/maps/api/js?key=".concat(apiKey, "&libraries=").concat(libraries).concat(languageParam).concat(callback);
|
|
33
|
-
var _useScript = useScript(scriptUrl, isGoogleMapsDefined),
|
|
34
|
-
_useScript2 = _slicedToArray(_useScript, 2),
|
|
35
|
-
loaded = _useScript2[0],
|
|
36
|
-
error = _useScript2[1];
|
|
37
|
-
var _useState = useState(false),
|
|
38
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
-
available = _useState2[0],
|
|
40
|
-
setAvailable = _useState2[1];
|
|
41
|
-
useEffect(function () {
|
|
42
|
-
setAvailable(loaded && !error);
|
|
43
|
-
if (error) {
|
|
44
|
-
throw new Error('Google Places API script failed to load');
|
|
45
|
-
}
|
|
46
|
-
}, [loaded, error]);
|
|
47
|
-
return ___EmotionJSX(GooglePlacesAPIContext.Provider, {
|
|
48
|
-
value: {
|
|
49
|
-
available: available
|
|
50
|
-
}
|
|
51
|
-
}, children);
|
|
52
|
-
};
|
|
53
|
-
export var useGooglePlacesAPI = function useGooglePlacesAPI() {
|
|
54
|
-
var context = useContext(GooglePlacesAPIContext);
|
|
55
|
-
if (context === undefined) {
|
|
56
|
-
throw new Error('useGooglePlaces must be used inside of GooglePlacesAPIProvider');
|
|
57
|
-
}
|
|
58
|
-
return context;
|
|
59
|
-
};
|
|
60
|
-
export var useAddressPredictions = function useAddressPredictions(input, _ref2) {
|
|
61
|
-
var types = _ref2.types,
|
|
62
|
-
location = _ref2.location,
|
|
63
|
-
radius = _ref2.radius,
|
|
64
|
-
components = _ref2.components;
|
|
65
|
-
var _useState3 = useState([]),
|
|
66
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
67
|
-
predictions = _useState4[0],
|
|
68
|
-
setPredictions = _useState4[1];
|
|
69
|
-
var _useGooglePlacesAPI = useGooglePlacesAPI(),
|
|
70
|
-
available = _useGooglePlacesAPI.available;
|
|
71
|
-
var autocomplete = 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(function (resolve) {
|
|
77
|
-
autocomplete.current.getPlacePredictions({
|
|
78
|
-
input: input,
|
|
79
|
-
types: types,
|
|
80
|
-
radius: radius,
|
|
81
|
-
location: location !== undefined ? {
|
|
82
|
-
lat: function lat() {
|
|
83
|
-
return location !== undefined ? location.lat : undefined;
|
|
84
|
-
},
|
|
85
|
-
lng: function lng() {
|
|
86
|
-
return location !== undefined ? location.lng : undefined;
|
|
87
|
-
}
|
|
88
|
-
} : undefined,
|
|
89
|
-
componentRestrictions: {
|
|
90
|
-
country: components.countries
|
|
91
|
-
}
|
|
92
|
-
}, function (predictions) {
|
|
93
|
-
var _predictions;
|
|
94
|
-
predictions = (_predictions = predictions) !== null && _predictions !== void 0 ? _predictions : [];
|
|
95
|
-
setPredictions(predictions);
|
|
96
|
-
resolve(predictions);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
useEffect(function () {
|
|
101
|
-
if (input !== '') {
|
|
102
|
-
void getPlacePredictions(input);
|
|
103
|
-
}
|
|
104
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
}, [input]);
|
|
106
|
-
return {
|
|
107
|
-
available: available,
|
|
108
|
-
predictions: predictions,
|
|
109
|
-
getPlacePredictions: getPlacePredictions
|
|
110
|
-
};
|
|
111
|
-
};
|
package/cjs/AddressSelect.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ILocation, IPrediction } from './GooglePlaces';
|
|
3
|
-
export declare type AddressSelectProps = {
|
|
4
|
-
name: string;
|
|
5
|
-
disabled?: boolean;
|
|
6
|
-
error?: string;
|
|
7
|
-
size?: 'small' | 'medium';
|
|
8
|
-
types?: string[];
|
|
9
|
-
onFocus?: (event: FocusEvent) => void;
|
|
10
|
-
onBlur?: (event: FocusEvent) => void;
|
|
11
|
-
onChange?: (changed: {
|
|
12
|
-
value: string;
|
|
13
|
-
label: string;
|
|
14
|
-
}, predictions: IPrediction[]) => void;
|
|
15
|
-
location?: ILocation;
|
|
16
|
-
radius?: number;
|
|
17
|
-
countries?: string[] | string;
|
|
18
|
-
placeholder?: string;
|
|
19
|
-
assistiveText?: string;
|
|
20
|
-
autoFocus?: boolean;
|
|
21
|
-
isClearable?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Class name to be assigned to the component
|
|
24
|
-
*/
|
|
25
|
-
className?: string;
|
|
26
|
-
};
|
|
27
|
-
declare const AddressSelect: ({ name, disabled, error, size, types, onFocus, onBlur, onChange, location, radius, countries, ...rest }: AddressSelectProps) => JSX.Element;
|
|
28
|
-
export default AddressSelect;
|
package/cjs/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) => 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/cjs/GooglePlaces.js
DELETED
|
@@ -1,119 +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 _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
-
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."); }
|
|
14
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
const GooglePlacesAPIContext = /*#__PURE__*/(0, _react.createContext)({
|
|
19
|
-
available: false
|
|
20
|
-
});
|
|
21
|
-
exports.GooglePlacesAPIContext = GooglePlacesAPIContext;
|
|
22
|
-
const GooglePlacesAPIProvider = ({
|
|
23
|
-
children,
|
|
24
|
-
apiKey,
|
|
25
|
-
language,
|
|
26
|
-
libraries = 'places'
|
|
27
|
-
}) => {
|
|
28
|
-
var _window, _window$google;
|
|
29
|
-
// We want to prevent the google maps api to be loaded more than once
|
|
30
|
-
const isGoogleMapsDefined = typeof window !== 'undefined' && Boolean((_window = window) === null || _window === void 0 ? void 0 : (_window$google = _window.google) === null || _window$google === void 0 ? void 0 : _window$google.maps);
|
|
31
|
-
const languageParam = language ? `&language=${language}` : '';
|
|
32
|
-
// NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
|
|
33
|
-
// Dummy callback to satisfy Google Maps API.
|
|
34
|
-
const dummyCallback = () => {
|
|
35
|
-
return;
|
|
36
|
-
};
|
|
37
|
-
// @ts-expect-error dummyCallback does not exist on window. A callback is required by Google Maps API.
|
|
38
|
-
window.dummyCallback = dummyCallback;
|
|
39
|
-
const callback = `&callback=dummyCallback`;
|
|
40
|
-
const scriptUrl = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries}${languageParam}${callback}`;
|
|
41
|
-
const _useScript = (0, _hooks.useScript)(scriptUrl, isGoogleMapsDefined),
|
|
42
|
-
_useScript2 = _slicedToArray(_useScript, 2),
|
|
43
|
-
loaded = _useScript2[0],
|
|
44
|
-
error = _useScript2[1];
|
|
45
|
-
const _useState = (0, _react.useState)(false),
|
|
46
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
47
|
-
available = _useState2[0],
|
|
48
|
-
setAvailable = _useState2[1];
|
|
49
|
-
(0, _react.useEffect)(() => {
|
|
50
|
-
setAvailable(loaded && !error);
|
|
51
|
-
if (error) {
|
|
52
|
-
throw new Error('Google Places API script failed to load');
|
|
53
|
-
}
|
|
54
|
-
}, [loaded, error]);
|
|
55
|
-
return (0, _react2.jsx)(GooglePlacesAPIContext.Provider, {
|
|
56
|
-
value: {
|
|
57
|
-
available
|
|
58
|
-
}
|
|
59
|
-
}, children);
|
|
60
|
-
};
|
|
61
|
-
exports.GooglePlacesAPIProvider = GooglePlacesAPIProvider;
|
|
62
|
-
const useGooglePlacesAPI = () => {
|
|
63
|
-
const context = (0, _react.useContext)(GooglePlacesAPIContext);
|
|
64
|
-
if (context === undefined) {
|
|
65
|
-
throw new Error('useGooglePlaces must be used inside of GooglePlacesAPIProvider');
|
|
66
|
-
}
|
|
67
|
-
return context;
|
|
68
|
-
};
|
|
69
|
-
exports.useGooglePlacesAPI = useGooglePlacesAPI;
|
|
70
|
-
const useAddressPredictions = (input, {
|
|
71
|
-
types,
|
|
72
|
-
location,
|
|
73
|
-
radius,
|
|
74
|
-
components
|
|
75
|
-
}) => {
|
|
76
|
-
const _useState3 = (0, _react.useState)([]),
|
|
77
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
-
predictions = _useState4[0],
|
|
79
|
-
setPredictions = _useState4[1];
|
|
80
|
-
const _useGooglePlacesAPI = useGooglePlacesAPI(),
|
|
81
|
-
available = _useGooglePlacesAPI.available;
|
|
82
|
-
const autocomplete = (0, _react.useRef)();
|
|
83
|
-
if (!autocomplete.current && available && typeof window !== 'undefined') {
|
|
84
|
-
autocomplete.current = new google.maps.places.AutocompleteService();
|
|
85
|
-
}
|
|
86
|
-
function getPlacePredictions(input) {
|
|
87
|
-
return new Promise(resolve => {
|
|
88
|
-
autocomplete.current.getPlacePredictions({
|
|
89
|
-
input,
|
|
90
|
-
types,
|
|
91
|
-
radius,
|
|
92
|
-
location: location !== undefined ? {
|
|
93
|
-
lat: () => location !== undefined ? location.lat : undefined,
|
|
94
|
-
lng: () => location !== undefined ? location.lng : undefined
|
|
95
|
-
} : undefined,
|
|
96
|
-
componentRestrictions: {
|
|
97
|
-
country: components.countries
|
|
98
|
-
}
|
|
99
|
-
}, predictions => {
|
|
100
|
-
var _predictions;
|
|
101
|
-
predictions = (_predictions = predictions) !== null && _predictions !== void 0 ? _predictions : [];
|
|
102
|
-
setPredictions(predictions);
|
|
103
|
-
resolve(predictions);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
(0, _react.useEffect)(() => {
|
|
108
|
-
if (input !== '') {
|
|
109
|
-
void getPlacePredictions(input);
|
|
110
|
-
}
|
|
111
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
112
|
-
}, [input]);
|
|
113
|
-
return {
|
|
114
|
-
available,
|
|
115
|
-
predictions,
|
|
116
|
-
getPlacePredictions
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
exports.useAddressPredictions = useAddressPredictions;
|
package/cjs/index.d.ts
DELETED
package/cjs/index.js
DELETED
|
@@ -1,40 +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 get() {
|
|
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 get() {
|
|
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 get() {
|
|
35
|
-
return _AddressSelect[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
40
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/cjs/typings.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/index.d.ts
DELETED
package/index.js
DELETED
package/typings.d.js
DELETED
|
File without changes
|