@dfds-ui/google-places 2.0.23 → 2.0.24-alpha.e06bd8a5
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 -29
- package/AddressSelect.js +0 -96
- package/GooglePlaces.d.ts +0 -54
- package/GooglePlaces.js +0 -114
- package/cjs/AddressSelect.d.ts +0 -29
- package/cjs/AddressSelect.js +0 -88
- package/cjs/GooglePlaces.d.ts +0 -54
- package/cjs/GooglePlaces.js +0 -122
- 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.24-alpha.e06bd8a5",
|
|
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.24-alpha.e06bd8a5",
|
|
18
|
+
"@dfds-ui/hooks": "2.0.24-alpha.e06bd8a5",
|
|
19
|
+
"@dfds-ui/icons": "2.0.24-alpha.e06bd8a5",
|
|
20
|
+
"@dfds-ui/react-components": "2.0.24-alpha.e06bd8a5",
|
|
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": "e06bd8a513c02f23e2e7e7d734c05b474f77a6b6",
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
}
|
package/AddressSelect.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="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) => JSX.Element;
|
|
29
|
-
export default AddressSelect;
|
package/AddressSelect.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
var _excluded = ["name", "disabled", "error", "size", "types", "onFocus", "onBlur", "onChange", "location", "radius", "countries"];
|
|
3
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
5
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
7
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
-
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."); }
|
|
9
|
-
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); }
|
|
10
|
-
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; }
|
|
11
|
-
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; }
|
|
12
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
|
-
import React, { useState } from 'react';
|
|
16
|
-
import { AsyncSearchableSelect } from '@dfds-ui/react-components';
|
|
17
|
-
import debounce from 'lodash.debounce';
|
|
18
|
-
import { useAddressPredictions } from './GooglePlaces';
|
|
19
|
-
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
20
|
-
var AddressSelect = function AddressSelect(_ref) {
|
|
21
|
-
var name = _ref.name,
|
|
22
|
-
disabled = _ref.disabled,
|
|
23
|
-
error = _ref.error,
|
|
24
|
-
_ref$size = _ref.size,
|
|
25
|
-
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
26
|
-
types = _ref.types,
|
|
27
|
-
onFocus = _ref.onFocus,
|
|
28
|
-
onBlur = _ref.onBlur,
|
|
29
|
-
onChange = _ref.onChange,
|
|
30
|
-
location = _ref.location,
|
|
31
|
-
radius = _ref.radius,
|
|
32
|
-
_ref$countries = _ref.countries,
|
|
33
|
-
countries = _ref$countries === void 0 ? [] : _ref$countries,
|
|
34
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
35
|
-
var _useState = useState([]),
|
|
36
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
-
predictions = _useState2[0],
|
|
38
|
-
setPredictions = _useState2[1];
|
|
39
|
-
var _useAddressPrediction = useAddressPredictions('', {
|
|
40
|
-
types: types,
|
|
41
|
-
location: location,
|
|
42
|
-
radius: radius,
|
|
43
|
-
components: {
|
|
44
|
-
countries: countries
|
|
45
|
-
}
|
|
46
|
-
}),
|
|
47
|
-
available = _useAddressPrediction.available,
|
|
48
|
-
getPlacePredictions = _useAddressPrediction.getPlacePredictions;
|
|
49
|
-
var loadOptions = /*#__PURE__*/function () {
|
|
50
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, callback) {
|
|
51
|
-
var placePredictions, options;
|
|
52
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
53
|
-
while (1) {
|
|
54
|
-
switch (_context.prev = _context.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
_context.next = 2;
|
|
57
|
-
return getPlacePredictions(input);
|
|
58
|
-
case 2:
|
|
59
|
-
placePredictions = _context.sent;
|
|
60
|
-
setPredictions(placePredictions);
|
|
61
|
-
options = placePredictions.map(function (prediction) {
|
|
62
|
-
return {
|
|
63
|
-
value: prediction.description,
|
|
64
|
-
label: prediction.description,
|
|
65
|
-
prediction: prediction
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
callback(options);
|
|
69
|
-
case 6:
|
|
70
|
-
case "end":
|
|
71
|
-
return _context.stop();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}, _callee);
|
|
75
|
-
}));
|
|
76
|
-
return function loadOptions(_x, _x2) {
|
|
77
|
-
return _ref2.apply(this, arguments);
|
|
78
|
-
};
|
|
79
|
-
}();
|
|
80
|
-
var handleChange = function handleChange(value) {
|
|
81
|
-
if (onChange) {
|
|
82
|
-
onChange(value, predictions);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
return ___EmotionJSX(AsyncSearchableSelect, _extends({
|
|
86
|
-
disabled: disabled || !available,
|
|
87
|
-
name: name,
|
|
88
|
-
error: error,
|
|
89
|
-
size: size,
|
|
90
|
-
onChange: handleChange,
|
|
91
|
-
loadOptions: debounce(loadOptions, 500),
|
|
92
|
-
onFocus: onFocus,
|
|
93
|
-
onBlur: onBlur
|
|
94
|
-
}, rest));
|
|
95
|
-
};
|
|
96
|
-
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,114 +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
|
-
// 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
|
-
};
|
package/cjs/AddressSelect.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="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) => JSX.Element;
|
|
29
|
-
export default AddressSelect;
|
package/cjs/AddressSelect.js
DELETED
|
@@ -1,88 +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
|
-
const _excluded = ["name", "disabled", "error", "size", "types", "onFocus", "onBlur", "onChange", "location", "radius", "countries"];
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
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); }
|
|
15
|
-
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; }
|
|
16
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
18
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
|
-
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."); }
|
|
21
|
-
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); }
|
|
22
|
-
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; }
|
|
23
|
-
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; }
|
|
24
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
26
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
27
|
-
const AddressSelect = _ref => {
|
|
28
|
-
let name = _ref.name,
|
|
29
|
-
disabled = _ref.disabled,
|
|
30
|
-
error = _ref.error,
|
|
31
|
-
_ref$size = _ref.size,
|
|
32
|
-
size = _ref$size === void 0 ? 'medium' : _ref$size,
|
|
33
|
-
types = _ref.types,
|
|
34
|
-
onFocus = _ref.onFocus,
|
|
35
|
-
onBlur = _ref.onBlur,
|
|
36
|
-
onChange = _ref.onChange,
|
|
37
|
-
location = _ref.location,
|
|
38
|
-
radius = _ref.radius,
|
|
39
|
-
_ref$countries = _ref.countries,
|
|
40
|
-
countries = _ref$countries === void 0 ? [] : _ref$countries,
|
|
41
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
42
|
-
const _useState = (0, _react.useState)([]),
|
|
43
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
-
predictions = _useState2[0],
|
|
45
|
-
setPredictions = _useState2[1];
|
|
46
|
-
const _useAddressPrediction = (0, _GooglePlaces.useAddressPredictions)('', {
|
|
47
|
-
types,
|
|
48
|
-
location,
|
|
49
|
-
radius,
|
|
50
|
-
components: {
|
|
51
|
-
countries
|
|
52
|
-
}
|
|
53
|
-
}),
|
|
54
|
-
available = _useAddressPrediction.available,
|
|
55
|
-
getPlacePredictions = _useAddressPrediction.getPlacePredictions;
|
|
56
|
-
const loadOptions = /*#__PURE__*/function () {
|
|
57
|
-
var _ref2 = _asyncToGenerator(function* (input, callback) {
|
|
58
|
-
const placePredictions = yield getPlacePredictions(input);
|
|
59
|
-
setPredictions(placePredictions);
|
|
60
|
-
const options = placePredictions.map(prediction => ({
|
|
61
|
-
value: prediction.description,
|
|
62
|
-
label: prediction.description,
|
|
63
|
-
prediction
|
|
64
|
-
}));
|
|
65
|
-
callback(options);
|
|
66
|
-
});
|
|
67
|
-
return function loadOptions(_x, _x2) {
|
|
68
|
-
return _ref2.apply(this, arguments);
|
|
69
|
-
};
|
|
70
|
-
}();
|
|
71
|
-
const handleChange = value => {
|
|
72
|
-
if (onChange) {
|
|
73
|
-
onChange(value, predictions);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return (0, _react2.jsx)(_reactComponents.AsyncSearchableSelect, _extends({
|
|
77
|
-
disabled: disabled || !available,
|
|
78
|
-
name: name,
|
|
79
|
-
error: error,
|
|
80
|
-
size: size,
|
|
81
|
-
onChange: handleChange,
|
|
82
|
-
loadOptions: (0, _lodash.default)(loadOptions, 500),
|
|
83
|
-
onFocus: onFocus,
|
|
84
|
-
onBlur: onBlur
|
|
85
|
-
}, rest));
|
|
86
|
-
};
|
|
87
|
-
var _default = AddressSelect;
|
|
88
|
-
exports.default = _default;
|
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,122 +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
|
-
// On SSR window does not exist.
|
|
30
|
-
const hasWindow = typeof window !== 'undefined';
|
|
31
|
-
|
|
32
|
-
// We want to prevent the google maps api to be loaded more than once
|
|
33
|
-
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);
|
|
34
|
-
const languageParam = language ? `&language=${language}` : '';
|
|
35
|
-
// NOTE: Google Maps API requires a callback when ran asynchronously. See https://developers.google.com/maps/documentation/javascript/url-params#required_parameters
|
|
36
|
-
// Dummy callback to satisfy Google Maps API.
|
|
37
|
-
const dummyCallback = () => {
|
|
38
|
-
return;
|
|
39
|
-
};
|
|
40
|
-
// @ts-expect-error dummyCallback does not exist on window. A callback is required by Google Maps API.
|
|
41
|
-
if (hasWindow) window.dummyCallback = dummyCallback;
|
|
42
|
-
const callback = hasWindow ? `&callback=dummyCallback` : '';
|
|
43
|
-
const scriptUrl = `https://maps.googleapis.com/maps/api/js?key=${apiKey}&libraries=${libraries}${languageParam}${callback}`;
|
|
44
|
-
const _useScript = (0, _hooks.useScript)(scriptUrl, isGoogleMapsDefined),
|
|
45
|
-
_useScript2 = _slicedToArray(_useScript, 2),
|
|
46
|
-
loaded = _useScript2[0],
|
|
47
|
-
error = _useScript2[1];
|
|
48
|
-
const _useState = (0, _react.useState)(false),
|
|
49
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
50
|
-
available = _useState2[0],
|
|
51
|
-
setAvailable = _useState2[1];
|
|
52
|
-
(0, _react.useEffect)(() => {
|
|
53
|
-
setAvailable(loaded && !error);
|
|
54
|
-
if (error) {
|
|
55
|
-
throw new Error('Google Places API script failed to load');
|
|
56
|
-
}
|
|
57
|
-
}, [loaded, error]);
|
|
58
|
-
return (0, _react2.jsx)(GooglePlacesAPIContext.Provider, {
|
|
59
|
-
value: {
|
|
60
|
-
available
|
|
61
|
-
}
|
|
62
|
-
}, children);
|
|
63
|
-
};
|
|
64
|
-
exports.GooglePlacesAPIProvider = GooglePlacesAPIProvider;
|
|
65
|
-
const useGooglePlacesAPI = () => {
|
|
66
|
-
const context = (0, _react.useContext)(GooglePlacesAPIContext);
|
|
67
|
-
if (context === undefined) {
|
|
68
|
-
throw new Error('useGooglePlaces must be used inside of GooglePlacesAPIProvider');
|
|
69
|
-
}
|
|
70
|
-
return context;
|
|
71
|
-
};
|
|
72
|
-
exports.useGooglePlacesAPI = useGooglePlacesAPI;
|
|
73
|
-
const useAddressPredictions = (input, {
|
|
74
|
-
types,
|
|
75
|
-
location,
|
|
76
|
-
radius,
|
|
77
|
-
components
|
|
78
|
-
}) => {
|
|
79
|
-
const _useState3 = (0, _react.useState)([]),
|
|
80
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
81
|
-
predictions = _useState4[0],
|
|
82
|
-
setPredictions = _useState4[1];
|
|
83
|
-
const _useGooglePlacesAPI = useGooglePlacesAPI(),
|
|
84
|
-
available = _useGooglePlacesAPI.available;
|
|
85
|
-
const autocomplete = (0, _react.useRef)();
|
|
86
|
-
if (!autocomplete.current && available && typeof window !== 'undefined') {
|
|
87
|
-
autocomplete.current = new google.maps.places.AutocompleteService();
|
|
88
|
-
}
|
|
89
|
-
function getPlacePredictions(input) {
|
|
90
|
-
return new Promise(resolve => {
|
|
91
|
-
autocomplete.current.getPlacePredictions({
|
|
92
|
-
input,
|
|
93
|
-
types,
|
|
94
|
-
radius,
|
|
95
|
-
location: location !== undefined ? {
|
|
96
|
-
lat: () => location !== undefined ? location.lat : undefined,
|
|
97
|
-
lng: () => location !== undefined ? location.lng : undefined
|
|
98
|
-
} : undefined,
|
|
99
|
-
componentRestrictions: {
|
|
100
|
-
country: components.countries
|
|
101
|
-
}
|
|
102
|
-
}, predictions => {
|
|
103
|
-
var _predictions;
|
|
104
|
-
predictions = (_predictions = predictions) !== null && _predictions !== void 0 ? _predictions : [];
|
|
105
|
-
setPredictions(predictions);
|
|
106
|
-
resolve(predictions);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
(0, _react.useEffect)(() => {
|
|
111
|
-
if (input !== '') {
|
|
112
|
-
void getPlacePredictions(input);
|
|
113
|
-
}
|
|
114
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
|
-
}, [input]);
|
|
116
|
-
return {
|
|
117
|
-
available,
|
|
118
|
-
predictions,
|
|
119
|
-
getPlacePredictions
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
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
|