@ballistix.digital/react-components 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { ArrowPathIcon, ChevronDownIcon, EllipsisVerticalIcon, ExclamationCircleIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronUpDownIcon, HomeIcon, ArrowLongLeftIcon, ArrowLongRightIcon } from '@heroicons/react/20/solid';
3
3
  import { set, get, noop as noop$1, indexOf, pick, isEmpty, some, forEach, assign, map } from 'lodash';
4
4
  import get$1 from 'lodash/get';
5
- import React, { useState, useMemo, Children, Fragment, useEffect, useCallback, forwardRef, useImperativeHandle, useRef, useReducer } from 'react';
5
+ import React, { useState, useMemo, Children, Fragment, useEffect, useCallback, forwardRef, useImperativeHandle, useRef, useReducer, createElement, PureComponent, Component } from 'react';
6
6
  import { library } from '@fortawesome/fontawesome-svg-core';
7
7
  import { fab } from '@fortawesome/free-brands-svg-icons';
8
8
  import { fal } from '@fortawesome/pro-light-svg-icons';
@@ -35,15 +35,15 @@ PERFORMANCE OF THIS SOFTWARE.
35
35
  /* global Reflect, Promise, SuppressedError, Symbol */
36
36
 
37
37
 
38
- var __assign = function() {
39
- __assign = Object.assign || function __assign(t) {
38
+ var __assign$1 = function() {
39
+ __assign$1 = Object.assign || function __assign(t) {
40
40
  for (var s, i = 1, n = arguments.length; i < n; i++) {
41
41
  s = arguments[i];
42
42
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
43
43
  }
44
44
  return t;
45
45
  };
46
- return __assign.apply(this, arguments);
46
+ return __assign$1.apply(this, arguments);
47
47
  };
48
48
 
49
49
  function __awaiter(thisArg, _arguments, P, generator) {
@@ -1322,14 +1322,14 @@ var TableList = function (props) {
1322
1322
  }).map(function (key) {
1323
1323
  var _a;
1324
1324
  return (_a = {}, _a[key] = false, _a);
1325
- }).reduce(function (a, b) { return (__assign(__assign({}, a), b)); });
1325
+ }).reduce(function (a, b) { return (__assign$1(__assign$1({}, a), b)); });
1326
1326
  var current = defaultVisibility
1327
1327
  .map(function (key) {
1328
1328
  var _a;
1329
1329
  return (_a = {}, _a[key] = true, _a);
1330
1330
  })
1331
- .reduce(function (a, b) { return (__assign(__assign({}, a), b)); });
1332
- return setVisibility(__assign(__assign({}, base), current));
1331
+ .reduce(function (a, b) { return (__assign$1(__assign$1({}, a), b)); });
1332
+ return setVisibility(__assign$1(__assign$1({}, base), current));
1333
1333
  }
1334
1334
  }
1335
1335
  var savedColumnOrder = (_a = state === null || state === void 0 ? void 0 : state.split(',').map(function (id) { return id.replace('-', ''); })) !== null && _a !== void 0 ? _a : [];
@@ -1977,7 +1977,7 @@ var List$1 = function (props) {
1977
1977
  var handleCalculateActiveAccessor = function (items) {
1978
1978
  var _a;
1979
1979
  var result = active;
1980
- var currentItem = (_a = Children.map(children, function (child) { return (__assign({}, child.props)); })) === null || _a === void 0 ? void 0 : _a.find(function (tab) { return tab === null || tab === void 0 ? void 0 : tab.isCurrent; });
1980
+ var currentItem = (_a = Children.map(children, function (child) { return (__assign$1({}, child.props)); })) === null || _a === void 0 ? void 0 : _a.find(function (tab) { return tab === null || tab === void 0 ? void 0 : tab.isCurrent; });
1981
1981
  if (currentItem === null || currentItem === void 0 ? void 0 : currentItem.href) {
1982
1982
  result = currentItem === null || currentItem === void 0 ? void 0 : currentItem.accessor;
1983
1983
  }
@@ -3772,7 +3772,7 @@ var FILES_TO_IGNORE = [
3772
3772
  function fromEvent(evt) {
3773
3773
  return __awaiter(this, void 0, void 0, function () {
3774
3774
  return __generator(this, function (_a) {
3775
- if (isObject(evt) && isDataTransfer(evt.dataTransfer)) {
3775
+ if (isObject$1(evt) && isDataTransfer(evt.dataTransfer)) {
3776
3776
  return [2 , getDataTransferFiles(evt.dataTransfer, evt.type)];
3777
3777
  }
3778
3778
  else if (isChangeEvt(evt)) {
@@ -3786,12 +3786,12 @@ function fromEvent(evt) {
3786
3786
  });
3787
3787
  }
3788
3788
  function isDataTransfer(value) {
3789
- return isObject(value);
3789
+ return isObject$1(value);
3790
3790
  }
3791
3791
  function isChangeEvt(value) {
3792
- return isObject(value) && isObject(value.target);
3792
+ return isObject$1(value) && isObject$1(value.target);
3793
3793
  }
3794
- function isObject(v) {
3794
+ function isObject$1(v) {
3795
3795
  return typeof v === 'object' && v !== null;
3796
3796
  }
3797
3797
  function getInputFiles(evt) {
@@ -4707,7 +4707,7 @@ var FileInputGroupForm = function (props) {
4707
4707
  };
4708
4708
  var styles = handleGenerateStyle();
4709
4709
  var input = getInputProps();
4710
- return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", __assign({ className: styles.body }, getRootProps(), { children: [children && children({ value: value, isDragging: isDragging }), jsx("input", { name: name, accept: input.accept, multiple: input.multiple, onChange: input.onChange, ref: input === null || input === void 0 ? void 0 : input.ref, style: input.style, tabIndex: input.tabIndex, type: input.type, onBlur: onBlur })] })), jsxs("div", { className: styles.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles.description, children: description })), error && isTouched && jsx("p", { className: styles.error, children: error })] })] }));
4710
+ return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", __assign$1({ className: styles.body }, getRootProps(), { children: [children && children({ value: value, isDragging: isDragging }), jsx("input", { name: name, accept: input.accept, multiple: input.multiple, onChange: input.onChange, ref: input === null || input === void 0 ? void 0 : input.ref, style: input.style, tabIndex: input.tabIndex, type: input.type, onBlur: onBlur })] })), jsxs("div", { className: styles.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles.description, children: description })), error && isTouched && jsx("p", { className: styles.error, children: error })] })] }));
4711
4711
  };
4712
4712
 
4713
4713
  var base$2 = {
@@ -9678,16 +9678,899 @@ var styles$1 = {
9678
9678
  disabled: disabled$1,
9679
9679
  };
9680
9680
 
9681
+ var classnames$1 = {exports: {}};
9682
+
9683
+ (function (module) {
9684
+ (function () {
9685
+ var hasOwn = {}.hasOwnProperty;
9686
+ function classNames() {
9687
+ var classes = [];
9688
+ for (var i = 0; i < arguments.length; i++) {
9689
+ var arg = arguments[i];
9690
+ if (!arg) continue;
9691
+ var argType = typeof arg;
9692
+ if (argType === 'string' || argType === 'number') {
9693
+ classes.push(arg);
9694
+ } else if (Array.isArray(arg)) {
9695
+ if (arg.length) {
9696
+ var inner = classNames.apply(null, arg);
9697
+ if (inner) {
9698
+ classes.push(inner);
9699
+ }
9700
+ }
9701
+ } else if (argType === 'object') {
9702
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
9703
+ classes.push(arg.toString());
9704
+ continue;
9705
+ }
9706
+ for (var key in arg) {
9707
+ if (hasOwn.call(arg, key) && arg[key]) {
9708
+ classes.push(key);
9709
+ }
9710
+ }
9711
+ }
9712
+ }
9713
+ return classes.join(' ');
9714
+ }
9715
+ if (module.exports) {
9716
+ classNames.default = classNames;
9717
+ module.exports = classNames;
9718
+ } else {
9719
+ window.classNames = classNames;
9720
+ }
9721
+ }());
9722
+ } (classnames$1));
9723
+ var classnamesExports = classnames$1.exports;
9724
+ var classnames = getDefaultExportFromCjs(classnamesExports);
9725
+
9726
+ var FUNC_ERROR_TEXT = 'Expected a function';
9727
+ var NAN = 0 / 0;
9728
+ var symbolTag = '[object Symbol]';
9729
+ var reTrim = /^\s+|\s+$/g;
9730
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
9731
+ var reIsBinary = /^0b[01]+$/i;
9732
+ var reIsOctal = /^0o[0-7]+$/i;
9733
+ var freeParseInt = parseInt;
9734
+ var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
9735
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
9736
+ var root = freeGlobal || freeSelf || Function('return this')();
9737
+ var objectProto = Object.prototype;
9738
+ var objectToString = objectProto.toString;
9739
+ var nativeMax = Math.max,
9740
+ nativeMin = Math.min;
9741
+ var now = function() {
9742
+ return root.Date.now();
9743
+ };
9744
+ function debounce(func, wait, options) {
9745
+ var lastArgs,
9746
+ lastThis,
9747
+ maxWait,
9748
+ result,
9749
+ timerId,
9750
+ lastCallTime,
9751
+ lastInvokeTime = 0,
9752
+ leading = false,
9753
+ maxing = false,
9754
+ trailing = true;
9755
+ if (typeof func != 'function') {
9756
+ throw new TypeError(FUNC_ERROR_TEXT);
9757
+ }
9758
+ wait = toNumber(wait) || 0;
9759
+ if (isObject(options)) {
9760
+ leading = !!options.leading;
9761
+ maxing = 'maxWait' in options;
9762
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
9763
+ trailing = 'trailing' in options ? !!options.trailing : trailing;
9764
+ }
9765
+ function invokeFunc(time) {
9766
+ var args = lastArgs,
9767
+ thisArg = lastThis;
9768
+ lastArgs = lastThis = undefined;
9769
+ lastInvokeTime = time;
9770
+ result = func.apply(thisArg, args);
9771
+ return result;
9772
+ }
9773
+ function leadingEdge(time) {
9774
+ lastInvokeTime = time;
9775
+ timerId = setTimeout(timerExpired, wait);
9776
+ return leading ? invokeFunc(time) : result;
9777
+ }
9778
+ function remainingWait(time) {
9779
+ var timeSinceLastCall = time - lastCallTime,
9780
+ timeSinceLastInvoke = time - lastInvokeTime,
9781
+ result = wait - timeSinceLastCall;
9782
+ return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
9783
+ }
9784
+ function shouldInvoke(time) {
9785
+ var timeSinceLastCall = time - lastCallTime,
9786
+ timeSinceLastInvoke = time - lastInvokeTime;
9787
+ return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
9788
+ (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
9789
+ }
9790
+ function timerExpired() {
9791
+ var time = now();
9792
+ if (shouldInvoke(time)) {
9793
+ return trailingEdge(time);
9794
+ }
9795
+ timerId = setTimeout(timerExpired, remainingWait(time));
9796
+ }
9797
+ function trailingEdge(time) {
9798
+ timerId = undefined;
9799
+ if (trailing && lastArgs) {
9800
+ return invokeFunc(time);
9801
+ }
9802
+ lastArgs = lastThis = undefined;
9803
+ return result;
9804
+ }
9805
+ function cancel() {
9806
+ if (timerId !== undefined) {
9807
+ clearTimeout(timerId);
9808
+ }
9809
+ lastInvokeTime = 0;
9810
+ lastArgs = lastCallTime = lastThis = timerId = undefined;
9811
+ }
9812
+ function flush() {
9813
+ return timerId === undefined ? result : trailingEdge(now());
9814
+ }
9815
+ function debounced() {
9816
+ var time = now(),
9817
+ isInvoking = shouldInvoke(time);
9818
+ lastArgs = arguments;
9819
+ lastThis = this;
9820
+ lastCallTime = time;
9821
+ if (isInvoking) {
9822
+ if (timerId === undefined) {
9823
+ return leadingEdge(lastCallTime);
9824
+ }
9825
+ if (maxing) {
9826
+ timerId = setTimeout(timerExpired, wait);
9827
+ return invokeFunc(lastCallTime);
9828
+ }
9829
+ }
9830
+ if (timerId === undefined) {
9831
+ timerId = setTimeout(timerExpired, wait);
9832
+ }
9833
+ return result;
9834
+ }
9835
+ debounced.cancel = cancel;
9836
+ debounced.flush = flush;
9837
+ return debounced;
9838
+ }
9839
+ function isObject(value) {
9840
+ var type = typeof value;
9841
+ return !!value && (type == 'object' || type == 'function');
9842
+ }
9843
+ function isObjectLike(value) {
9844
+ return !!value && typeof value == 'object';
9845
+ }
9846
+ function isSymbol(value) {
9847
+ return typeof value == 'symbol' ||
9848
+ (isObjectLike(value) && objectToString.call(value) == symbolTag);
9849
+ }
9850
+ function toNumber(value) {
9851
+ if (typeof value == 'number') {
9852
+ return value;
9853
+ }
9854
+ if (isSymbol(value)) {
9855
+ return NAN;
9856
+ }
9857
+ if (isObject(value)) {
9858
+ var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
9859
+ value = isObject(other) ? (other + '') : other;
9860
+ }
9861
+ if (typeof value != 'string') {
9862
+ return value === 0 ? value : +value;
9863
+ }
9864
+ value = value.replace(reTrim, '');
9865
+ var isBinary = reIsBinary.test(value);
9866
+ return (isBinary || reIsOctal.test(value))
9867
+ ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
9868
+ : (reIsBadHex.test(value) ? NAN : +value);
9869
+ }
9870
+ var lodash_debounce = debounce;
9871
+ var debounce$1 = getDefaultExportFromCjs(lodash_debounce);
9872
+
9873
+ var extendStatics = function(d, b) {
9874
+ extendStatics = Object.setPrototypeOf ||
9875
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9876
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
9877
+ return extendStatics(d, b);
9878
+ };
9879
+ function __extends(d, b) {
9880
+ extendStatics(d, b);
9881
+ function __() { this.constructor = d; }
9882
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9883
+ }
9884
+ var __assign = function() {
9885
+ __assign = Object.assign || function __assign(t) {
9886
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9887
+ s = arguments[i];
9888
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
9889
+ }
9890
+ return t;
9891
+ };
9892
+ return __assign.apply(this, arguments);
9893
+ };
9894
+ var defaults = {
9895
+ autoActivateFirstSuggest: false,
9896
+ disabled: false,
9897
+ fixtures: [],
9898
+ getSuggestLabel: function (suggest) { return suggest.description; },
9899
+ highlightMatch: true,
9900
+ ignoreEnter: false,
9901
+ ignoreTab: false,
9902
+ initialValue: '',
9903
+ maxFixtures: 10,
9904
+ minLength: 1,
9905
+ onKeyDown: function () { },
9906
+ onKeyPress: function () { },
9907
+ placeholder: 'Search places',
9908
+ queryDelay: 250,
9909
+ skipSuggest: function () { return false; },
9910
+ style: {},
9911
+ inputType: 'text'
9912
+ };
9913
+ var allowedAttributes = [
9914
+ 'autoCapitalize',
9915
+ 'autoComplete',
9916
+ 'autoCorrect',
9917
+ 'autoFocus',
9918
+ 'disabled',
9919
+ 'form',
9920
+ 'formAction',
9921
+ 'formEncType',
9922
+ 'formMethod',
9923
+ 'formNoValidate',
9924
+ 'formTarget',
9925
+ 'height',
9926
+ 'inputMode',
9927
+ 'maxLength',
9928
+ 'name',
9929
+ 'onClick',
9930
+ 'onContextMenu',
9931
+ 'onCopy',
9932
+ 'onCut',
9933
+ 'onDoubleClick',
9934
+ 'onMouseDown',
9935
+ 'onMouseEnter',
9936
+ 'onMouseLeave',
9937
+ 'onMouseMove',
9938
+ 'onMouseOut',
9939
+ 'onMouseOver',
9940
+ 'onMouseUp',
9941
+ 'onPaste',
9942
+ 'pattern',
9943
+ 'placeholder',
9944
+ 'readOnly',
9945
+ 'required',
9946
+ 'size',
9947
+ 'spellCheck',
9948
+ 'tabIndex',
9949
+ 'title',
9950
+ 'aria-atomic',
9951
+ 'aria-busy',
9952
+ 'aria-controls',
9953
+ 'aria-current',
9954
+ 'aria-describedby',
9955
+ 'aria-details',
9956
+ 'aria-disabled',
9957
+ 'aria-dropeffect',
9958
+ 'aria-errormessage',
9959
+ 'aria-flowto',
9960
+ 'aria-grabbed',
9961
+ 'aria-haspopup',
9962
+ 'aria-hidden',
9963
+ 'aria-invalid',
9964
+ 'aria-keyshortcuts',
9965
+ 'aria-label',
9966
+ 'aria-labelledby',
9967
+ 'aria-live',
9968
+ 'aria-owns',
9969
+ 'aria-relevant',
9970
+ 'aria-roledescription',
9971
+ 'aria-activedescendant',
9972
+ 'aria-autocomplete',
9973
+ 'aria-multiline',
9974
+ 'aria-placeholder',
9975
+ 'aria-readonly',
9976
+ 'aria-required'
9977
+ ];
9978
+ function filterInputAttributes (props) {
9979
+ var attributes = {};
9980
+ Object.keys(props).forEach(function (attribute) {
9981
+ var isDataAttribute = attribute.startsWith('data-');
9982
+ var isAllowedAttribute = allowedAttributes.includes(attribute);
9983
+ if (isAllowedAttribute || isDataAttribute) {
9984
+ attributes[attribute] = props[attribute];
9985
+ }
9986
+ });
9987
+ return attributes;
9988
+ }
9989
+ var Input = (function (_super) {
9990
+ __extends(Input, _super);
9991
+ function Input(props) {
9992
+ var _this = _super.call(this, props) || this;
9993
+ _this.input = null;
9994
+ _this.onChange = _this.onChange.bind(_this);
9995
+ _this.onInputKeyDown = _this.onInputKeyDown.bind(_this);
9996
+ return _this;
9997
+ }
9998
+ Input.prototype.onChange = function () {
9999
+ if (this.input) {
10000
+ this.props.onChange(this.input.value);
10001
+ }
10002
+ };
10003
+ Input.prototype.onInputKeyDown = function (event) {
10004
+ if (this.props.onKeyDown) {
10005
+ this.props.onKeyDown(event);
10006
+ }
10007
+ switch (event.which) {
10008
+ case 40:
10009
+ if (!event.shiftKey) {
10010
+ event.preventDefault();
10011
+ this.props.onNext();
10012
+ }
10013
+ break;
10014
+ case 38:
10015
+ if (!event.shiftKey) {
10016
+ event.preventDefault();
10017
+ this.props.onPrev();
10018
+ }
10019
+ break;
10020
+ case 13:
10021
+ if (this.props.doNotSubmitOnEnter) {
10022
+ event.preventDefault();
10023
+ }
10024
+ if (!this.props.ignoreEnter) {
10025
+ this.props.onSelect();
10026
+ }
10027
+ break;
10028
+ case 9:
10029
+ if (!this.props.ignoreTab) {
10030
+ this.props.onSelect();
10031
+ }
10032
+ break;
10033
+ case 27:
10034
+ this.props.onEscape();
10035
+ break;
10036
+ }
10037
+ };
10038
+ Input.prototype.focus = function () {
10039
+ if (this.input) {
10040
+ this.input.focus();
10041
+ }
10042
+ };
10043
+ Input.prototype.blur = function () {
10044
+ if (this.input) {
10045
+ this.input.blur();
10046
+ }
10047
+ };
10048
+ Input.prototype.render = function () {
10049
+ var _this = this;
10050
+ var attributes = filterInputAttributes(this.props);
10051
+ var classes = classnames('geosuggest__input', this.props.className);
10052
+ var shouldRenderLabel = this.props.label && this.props.id;
10053
+ if (!attributes.tabIndex) {
10054
+ attributes.tabIndex = 0;
10055
+ }
10056
+ return (createElement(Fragment, null,
10057
+ shouldRenderLabel && (createElement("label", { className: "geosuggest__label", htmlFor: this.props.id }, this.props.label)),
10058
+ createElement("input", __assign({ className: classes, id: "geosuggest__input" + (this.props.id ? "--" + this.props.id : ''), ref: function (i) { return (_this.input = i); }, type: this.props.inputType }, attributes, { value: this.props.value, style: this.props.style, onKeyDown: this.onInputKeyDown, onChange: this.onChange, onKeyPress: this.props.onKeyPress, onFocus: this.props.onFocus, onBlur: this.props.onBlur, role: "combobox", "aria-expanded": !this.props.isSuggestsHidden, "aria-activedescendant": this.props.activeSuggest
10059
+ ? this.props.activeSuggest.placeId
10060
+ :
10061
+ undefined, "aria-owns": this.props.listId }))));
10062
+ };
10063
+ Input.defaultProps = {
10064
+ activeSuggest: null,
10065
+ autoComplete: 'nope',
10066
+ className: '',
10067
+ isSuggestsHidden: true,
10068
+ listId: '',
10069
+ inputType: 'text',
10070
+ onBlur: function () { },
10071
+ onChange: function () { },
10072
+ onEscape: function () { },
10073
+ onFocus: function () { },
10074
+ onKeyDown: function () { },
10075
+ onKeyPress: function () { },
10076
+ onNext: function () { },
10077
+ onPrev: function () { },
10078
+ onSelect: function () { },
10079
+ value: ''
10080
+ };
10081
+ return Input;
10082
+ }(PureComponent));
10083
+ var default_1 = (function (_super) {
10084
+ __extends(default_1, _super);
10085
+ function default_1(props) {
10086
+ var _this = _super.call(this, props) || this;
10087
+ _this.ref = null;
10088
+ _this.onClick = _this.onClick.bind(_this);
10089
+ return _this;
10090
+ }
10091
+ default_1.prototype.makeBold = function (element, key) {
10092
+ return (createElement("b", { className: "geosuggest__item__matched-text", key: key }, element));
10093
+ };
10094
+ default_1.prototype.formatMatchedText = function (userInput, suggest) {
10095
+ if (!userInput || !suggest.matchedSubstrings) {
10096
+ return suggest.label;
10097
+ }
10098
+ var start = suggest.matchedSubstrings.offset;
10099
+ var length = suggest.matchedSubstrings.length;
10100
+ var end = start + length;
10101
+ var boldPart = this.makeBold(suggest.label.substring(start, end), suggest.label);
10102
+ var pre = '';
10103
+ var post = '';
10104
+ if (start > 0) {
10105
+ pre = suggest.label.slice(0, start);
10106
+ }
10107
+ if (end < suggest.label.length) {
10108
+ post = suggest.label.slice(end);
10109
+ }
10110
+ return (createElement("span", null,
10111
+ pre,
10112
+ boldPart,
10113
+ post));
10114
+ };
10115
+ default_1.prototype.componentDidUpdate = function (prevProps) {
10116
+ if (!prevProps.isActive && this.props.isActive) {
10117
+ this.scrollIfNeeded();
10118
+ }
10119
+ };
10120
+ default_1.prototype.scrollIfNeeded = function () {
10121
+ var element = this.ref;
10122
+ var parent = element && element.parentElement;
10123
+ if (!element || !parent) {
10124
+ return;
10125
+ }
10126
+ var overTop = element.offsetTop - parent.offsetTop < parent.scrollTop;
10127
+ var overBottom = element.offsetTop - parent.offsetTop + element.clientHeight >
10128
+ parent.scrollTop + parent.clientHeight;
10129
+ if (overTop || overBottom) {
10130
+ parent.scrollTop =
10131
+ element.offsetTop -
10132
+ parent.offsetTop -
10133
+ parent.clientHeight / 2 +
10134
+ element.clientHeight / 2;
10135
+ }
10136
+ };
10137
+ default_1.prototype.onClick = function (event) {
10138
+ event.preventDefault();
10139
+ this.props.onSelect(this.props.suggest);
10140
+ };
10141
+ default_1.prototype.render = function () {
10142
+ var _a;
10143
+ var _this = this;
10144
+ var suggest = this.props.suggest;
10145
+ var classes = classnames('geosuggest__item', this.props.className, this.props.suggestItemClassName, { 'geosuggest__item--active': this.props.isActive }, (_a = {},
10146
+ _a[this.props.activeClassName || ''] = this.props.activeClassName
10147
+ ? this.props.isActive
10148
+ : null,
10149
+ _a));
10150
+ var content = suggest.label;
10151
+ if (this.props.renderSuggestItem) {
10152
+ content = this.props.renderSuggestItem(suggest, this.props.userInput);
10153
+ }
10154
+ else if (this.props.isHighlightMatch) {
10155
+ content = this.formatMatchedText(this.props.userInput, suggest);
10156
+ }
10157
+ return (createElement("li", { className: classes, ref: function (li) { return (_this.ref = li); }, style: this.props.style, onMouseDown: this.props.onMouseDown, onMouseOut: this.props.onMouseOut, onClick: this.onClick, role: "option", "aria-selected": this.props.isActive, id: suggest.placeId }, content));
10158
+ };
10159
+ return default_1;
10160
+ }(PureComponent));
10161
+ var default_1$1 = (function (_super) {
10162
+ __extends(default_1$1, _super);
10163
+ function default_1$1() {
10164
+ return _super !== null && _super.apply(this, arguments) || this;
10165
+ }
10166
+ default_1$1.prototype.isHidden = function () {
10167
+ return this.props.isHidden || this.props.suggests.length === 0;
10168
+ };
10169
+ default_1$1.prototype.componentDidUpdate = function (prevProps) {
10170
+ if (prevProps.suggests !== this.props.suggests) {
10171
+ if (this.props.suggests.length === 0) {
10172
+ this.props.onSuggestNoResults();
10173
+ }
10174
+ }
10175
+ };
10176
+ default_1$1.prototype.render = function () {
10177
+ var _a;
10178
+ var _this = this;
10179
+ var classes = classnames('geosuggest__suggests', this.props.suggestsClassName, { 'geosuggest__suggests--hidden': this.isHidden() }, (_a = {},
10180
+ _a[this.props.hiddenClassName || ''] = this.props.hiddenClassName
10181
+ ? this.isHidden()
10182
+ : null,
10183
+ _a));
10184
+ return (createElement("ul", { className: classes, style: this.props.style, role: "listbox", id: this.props.listId }, this.props.suggests.map(function (suggest) {
10185
+ var isActive = (_this.props.activeSuggest &&
10186
+ suggest.placeId === _this.props.activeSuggest.placeId) ||
10187
+ false;
10188
+ return (createElement(default_1, { key: suggest.placeId, className: suggest.className || '', userInput: _this.props.userInput, isHighlightMatch: _this.props.isHighlightMatch, suggest: suggest, style: _this.props.suggestItemStyle, suggestItemClassName: _this.props.suggestItemClassName, isActive: isActive, activeClassName: _this.props.suggestItemActiveClassName, onMouseDown: _this.props.onSuggestMouseDown, onMouseOut: _this.props.onSuggestMouseOut, onSelect: _this.props.onSuggestSelect, renderSuggestItem: _this.props.renderSuggestItem }));
10189
+ })));
10190
+ };
10191
+ return default_1$1;
10192
+ }(PureComponent));
10193
+ function escapeRegExp(str) {
10194
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
10195
+ }
10196
+ var default_1$2 = (function (_super) {
10197
+ __extends(default_1, _super);
10198
+ function default_1(props) {
10199
+ var _this = _super.call(this, props) || this;
10200
+ _this.googleMaps = null;
10201
+ _this.autocompleteService = null;
10202
+ _this.placesService = null;
10203
+ _this.sessionToken = undefined;
10204
+ _this.geocoder = null;
10205
+ _this.input = null;
10206
+ _this.state = {
10207
+ activeSuggest: null,
10208
+ ignoreBlur: false,
10209
+ isLoading: false,
10210
+ isSuggestsHidden: true,
10211
+ suggests: [],
10212
+ userInput: props.initialValue || ''
10213
+ };
10214
+ _this.onInputChange = _this.onInputChange.bind(_this);
10215
+ _this.onAfterInputChange = _this.onAfterInputChange.bind(_this);
10216
+ _this.onInputFocus = _this.onInputFocus.bind(_this);
10217
+ _this.onInputBlur = _this.onInputBlur.bind(_this);
10218
+ _this.onNext = _this.onNext.bind(_this);
10219
+ _this.onPrev = _this.onPrev.bind(_this);
10220
+ _this.onSelect = _this.onSelect.bind(_this);
10221
+ _this.onSuggestMouseDown = _this.onSuggestMouseDown.bind(_this);
10222
+ _this.onSuggestMouseOut = _this.onSuggestMouseOut.bind(_this);
10223
+ _this.onSuggestNoResults = _this.onSuggestNoResults.bind(_this);
10224
+ _this.hideSuggests = _this.hideSuggests.bind(_this);
10225
+ _this.selectSuggest = _this.selectSuggest.bind(_this);
10226
+ _this.listId = "geosuggest__list" + (props.id ? "--" + props.id : '');
10227
+ if (props.queryDelay) {
10228
+ _this.onAfterInputChange = debounce$1(_this.onAfterInputChange, props.queryDelay);
10229
+ }
10230
+ return _this;
10231
+ }
10232
+ default_1.prototype.componentDidUpdate = function (prevProps) {
10233
+ if (prevProps.initialValue !== this.props.initialValue) {
10234
+ this.setState({ userInput: this.props.initialValue || '' });
10235
+ }
10236
+ if (JSON.stringify(prevProps.fixtures) !== JSON.stringify(this.props.fixtures)) {
10237
+ this.searchSuggests();
10238
+ }
10239
+ };
10240
+ default_1.prototype.componentDidMount = function () {
10241
+ if (typeof window === 'undefined') {
10242
+ return;
10243
+ }
10244
+ var googleMaps = this.props.googleMaps ||
10245
+ (window.google && window.google.maps) ||
10246
+ this.googleMaps;
10247
+ if (!googleMaps) {
10248
+ if (console) {
10249
+ console.error('Google maps API was not found in the page.');
10250
+ }
10251
+ return;
10252
+ }
10253
+ this.googleMaps = googleMaps;
10254
+ this.autocompleteService = new googleMaps.places.AutocompleteService();
10255
+ this.placesService = new googleMaps.places.PlacesService(document.createElement('div'));
10256
+ this.sessionToken = new googleMaps.places.AutocompleteSessionToken();
10257
+ this.geocoder = new googleMaps.Geocoder();
10258
+ };
10259
+ default_1.prototype.componentWillUnmount = function () {
10260
+ clearTimeout(this.timer);
10261
+ };
10262
+ default_1.prototype.onInputChange = function (userInput) {
10263
+ if (!userInput) {
10264
+ if (this.props.onSuggestSelect) {
10265
+ this.props.onSuggestSelect();
10266
+ }
10267
+ }
10268
+ this.setState({ userInput: userInput }, this.onAfterInputChange);
10269
+ };
10270
+ default_1.prototype.onAfterInputChange = function () {
10271
+ this.showSuggests();
10272
+ if (this.props.onChange) {
10273
+ this.props.onChange(this.state.userInput);
10274
+ }
10275
+ };
10276
+ default_1.prototype.onInputFocus = function () {
10277
+ if (this.props.onFocus) {
10278
+ this.props.onFocus();
10279
+ }
10280
+ this.showSuggests();
10281
+ };
10282
+ default_1.prototype.onInputBlur = function () {
10283
+ if (!this.state.ignoreBlur) {
10284
+ this.hideSuggests();
10285
+ }
10286
+ };
10287
+ default_1.prototype.onNext = function () {
10288
+ this.activateSuggest('next');
10289
+ };
10290
+ default_1.prototype.onPrev = function () {
10291
+ this.activateSuggest('prev');
10292
+ };
10293
+ default_1.prototype.onSelect = function () {
10294
+ this.selectSuggest(this.state.activeSuggest);
10295
+ };
10296
+ default_1.prototype.onSuggestMouseDown = function () {
10297
+ this.setState({ ignoreBlur: true });
10298
+ };
10299
+ default_1.prototype.onSuggestMouseOut = function () {
10300
+ this.setState({ ignoreBlur: false });
10301
+ };
10302
+ default_1.prototype.onSuggestNoResults = function () {
10303
+ if (this.props.onSuggestNoResults) {
10304
+ this.props.onSuggestNoResults(this.state.userInput);
10305
+ }
10306
+ };
10307
+ default_1.prototype.focus = function () {
10308
+ if (this.input) {
10309
+ this.input.focus();
10310
+ }
10311
+ };
10312
+ default_1.prototype.blur = function () {
10313
+ if (this.input) {
10314
+ this.input.blur();
10315
+ }
10316
+ };
10317
+ default_1.prototype.update = function (userInput) {
10318
+ this.setState({ userInput: userInput });
10319
+ if (this.props.onChange) {
10320
+ this.props.onChange(userInput);
10321
+ }
10322
+ };
10323
+ default_1.prototype.clear = function () {
10324
+ this.setState({ userInput: '' }, this.hideSuggests);
10325
+ };
10326
+ default_1.prototype.searchSuggests = function () {
10327
+ var _this = this;
10328
+ if (!this.state.userInput) {
10329
+ this.updateSuggests();
10330
+ return;
10331
+ }
10332
+ var options = {
10333
+ input: this.state.userInput,
10334
+ sessionToken: this.sessionToken
10335
+ };
10336
+ var inputLength = this.state.userInput.length;
10337
+ var isShorterThanMinLength = this.props.minLength && inputLength < this.props.minLength;
10338
+ if (isShorterThanMinLength) {
10339
+ this.updateSuggests();
10340
+ return;
10341
+ }
10342
+ var _a = this.props, location = _a.location, radius = _a.radius, bounds = _a.bounds, types = _a.types, country = _a.country;
10343
+ if (location)
10344
+ options.location = location;
10345
+ if (radius)
10346
+ options.radius = Number(this.props.radius);
10347
+ if (bounds)
10348
+ options.bounds = bounds;
10349
+ if (types)
10350
+ options.types = types;
10351
+ if (country)
10352
+ options.componentRestrictions = { country: country };
10353
+ this.setState({ isLoading: true }, function () {
10354
+ if (!_this.autocompleteService) {
10355
+ _this.setState({ isLoading: false });
10356
+ return;
10357
+ }
10358
+ _this.autocompleteService.getPlacePredictions(options, function (suggestsGoogle) {
10359
+ _this.setState({ isLoading: false });
10360
+ _this.updateSuggests(suggestsGoogle || [],
10361
+ function () {
10362
+ if (_this.props.autoActivateFirstSuggest &&
10363
+ !_this.state.activeSuggest) {
10364
+ _this.activateSuggest('next');
10365
+ }
10366
+ });
10367
+ });
10368
+ });
10369
+ };
10370
+ default_1.prototype.updateSuggests = function (suggestsGoogle,
10371
+ callback) {
10372
+ var _this = this;
10373
+ if (suggestsGoogle === void 0) { suggestsGoogle = []; }
10374
+ if (callback === void 0) { callback = function () { }; }
10375
+ var suggests = [];
10376
+ var userInput = this.state.userInput;
10377
+ var _a = this.props, skipSuggest = _a.skipSuggest, maxFixtures = _a.maxFixtures, fixtures = _a.fixtures;
10378
+ var regex = new RegExp(escapeRegExp(userInput), 'gim');
10379
+ var fixturesSearched = 0;
10380
+ var activeSuggest = null;
10381
+ if (fixtures) {
10382
+ fixtures.forEach(function (fixture) {
10383
+ if (maxFixtures && fixturesSearched >= maxFixtures) {
10384
+ return;
10385
+ }
10386
+ if (skipSuggest &&
10387
+ !skipSuggest(fixture) &&
10388
+ fixture.label.match(regex)) {
10389
+ fixturesSearched++;
10390
+ suggests.push(__assign(__assign({}, fixture), { isFixture: true, matchedSubstrings: {
10391
+ length: userInput.length,
10392
+ offset: fixture.label.indexOf(userInput)
10393
+ }, placeId: fixture.placeId || fixture.label }));
10394
+ }
10395
+ });
10396
+ }
10397
+ suggestsGoogle.forEach(function (suggest) {
10398
+ if (skipSuggest && !skipSuggest(suggest)) {
10399
+ suggests.push({
10400
+ description: suggest.description,
10401
+ isFixture: false,
10402
+ label: _this.props.getSuggestLabel
10403
+ ? _this.props.getSuggestLabel(suggest)
10404
+ : '',
10405
+ matchedSubstrings: suggest.matched_substrings[0],
10406
+ placeId: suggest.place_id
10407
+ });
10408
+ }
10409
+ });
10410
+ activeSuggest = this.updateActiveSuggest(suggests);
10411
+ if (this.props.onUpdateSuggests) {
10412
+ this.props.onUpdateSuggests(suggests, activeSuggest);
10413
+ }
10414
+ this.setState({ suggests: suggests, activeSuggest: activeSuggest }, callback);
10415
+ };
10416
+ default_1.prototype.updateActiveSuggest = function (suggests) {
10417
+ if (suggests === void 0) { suggests = []; }
10418
+ var activeSuggest = this.state.activeSuggest;
10419
+ if (activeSuggest) {
10420
+ var newSuggest = suggests.filter(function (listedSuggest) {
10421
+ return activeSuggest &&
10422
+ activeSuggest.placeId === listedSuggest.placeId &&
10423
+ activeSuggest.isFixture === listedSuggest.isFixture;
10424
+ })[0];
10425
+ activeSuggest = newSuggest || null;
10426
+ }
10427
+ return activeSuggest;
10428
+ };
10429
+ default_1.prototype.showSuggests = function () {
10430
+ this.searchSuggests();
10431
+ this.setState({ isSuggestsHidden: false });
10432
+ };
10433
+ default_1.prototype.hideSuggests = function () {
10434
+ var _this = this;
10435
+ if (this.props.onBlur) {
10436
+ this.props.onBlur(this.state.userInput);
10437
+ }
10438
+ this.timer = window.setTimeout(function () {
10439
+ _this.setState({
10440
+ activeSuggest: null,
10441
+ isSuggestsHidden: true
10442
+ });
10443
+ }, 100);
10444
+ };
10445
+ default_1.prototype.activateSuggest = function (direction) {
10446
+ if (this.state.isSuggestsHidden) {
10447
+ this.showSuggests();
10448
+ return;
10449
+ }
10450
+ var suggestsCount = this.state.suggests.length - 1;
10451
+ var next = direction === 'next';
10452
+ var newActiveSuggest = null;
10453
+ var newIndex = 0;
10454
+ var i = 0;
10455
+ for (i; i <= suggestsCount; i++) {
10456
+ if (this.state.suggests[i] === this.state.activeSuggest) {
10457
+ newIndex = next ? i + 1 : i - 1;
10458
+ }
10459
+ }
10460
+ if (!this.state.activeSuggest) {
10461
+ newIndex = next ? 0 : suggestsCount;
10462
+ }
10463
+ if (newIndex >= 0 && newIndex <= suggestsCount) {
10464
+ newActiveSuggest = this.state.suggests[newIndex];
10465
+ }
10466
+ if (this.props.onActivateSuggest) {
10467
+ this.props.onActivateSuggest(newActiveSuggest);
10468
+ }
10469
+ this.setState({ activeSuggest: newActiveSuggest });
10470
+ };
10471
+ default_1.prototype.selectSuggest = function (suggestToSelect) {
10472
+ var suggest = suggestToSelect || {
10473
+ isFixture: true,
10474
+ label: this.state.userInput,
10475
+ placeId: this.state.userInput
10476
+ };
10477
+ if (!suggestToSelect &&
10478
+ this.props.autoActivateFirstSuggest &&
10479
+ this.state.suggests.length > 0) {
10480
+ suggest = this.state.suggests[0];
10481
+ }
10482
+ this.setState({
10483
+ isSuggestsHidden: true,
10484
+ userInput: typeof suggest.label !== 'object'
10485
+ ? suggest.label
10486
+ : suggest.description || ''
10487
+ });
10488
+ if (suggest.location) {
10489
+ this.setState({ ignoreBlur: false });
10490
+ if (this.props.onSuggestSelect) {
10491
+ this.props.onSuggestSelect(suggest);
10492
+ }
10493
+ return;
10494
+ }
10495
+ this.geocodeSuggest(suggest);
10496
+ };
10497
+ default_1.prototype.geocodeSuggest = function (suggestToGeocode) {
10498
+ var _this = this;
10499
+ if (!this.geocoder) {
10500
+ return;
10501
+ }
10502
+ if (suggestToGeocode.placeId &&
10503
+ !suggestToGeocode.isFixture &&
10504
+ this.placesService) {
10505
+ var options = {
10506
+ placeId: suggestToGeocode.placeId,
10507
+ sessionToken: this.sessionToken
10508
+ };
10509
+ if (this.props.placeDetailFields) {
10510
+ options.fields = this.props.placeDetailFields;
10511
+ options.fields.unshift('geometry');
10512
+ }
10513
+ this.placesService.getDetails(options, function (results, status) {
10514
+ if (status === _this.googleMaps.places.PlacesServiceStatus.OK) {
10515
+ var gmaps = results;
10516
+ var location_1 = (gmaps.geometry &&
10517
+ gmaps.geometry.location);
10518
+ var suggest = __assign(__assign({}, suggestToGeocode), { gmaps: gmaps, location: {
10519
+ lat: location_1.lat(),
10520
+ lng: location_1.lng()
10521
+ } });
10522
+ _this.sessionToken = new google.maps.places.AutocompleteSessionToken();
10523
+ if (_this.props.onSuggestSelect) {
10524
+ _this.props.onSuggestSelect(suggest);
10525
+ }
10526
+ }
10527
+ });
10528
+ }
10529
+ else {
10530
+ var options = {
10531
+ address: suggestToGeocode.label,
10532
+ bounds: this.props.bounds,
10533
+ componentRestrictions: this.props.country
10534
+ ? { country: this.props.country }
10535
+ :
10536
+ undefined,
10537
+ location: this.props.location
10538
+ };
10539
+ this.geocoder.geocode(options, function (results, status) {
10540
+ if (status === _this.googleMaps.GeocoderStatus.OK) {
10541
+ var gmaps = results[0];
10542
+ var location_2 = (gmaps.geometry &&
10543
+ gmaps.geometry.location);
10544
+ var suggest = __assign(__assign({}, suggestToGeocode), { gmaps: gmaps, location: {
10545
+ lat: location_2.lat(),
10546
+ lng: location_2.lng()
10547
+ } });
10548
+ if (_this.props.onSuggestSelect) {
10549
+ _this.props.onSuggestSelect(suggest);
10550
+ }
10551
+ }
10552
+ });
10553
+ }
10554
+ };
10555
+ default_1.prototype.render = function () {
10556
+ var _this = this;
10557
+ var attributes = filterInputAttributes(this.props);
10558
+ var classes = classnames('geosuggest', this.props.className, {
10559
+ 'geosuggest--loading': this.state.isLoading
10560
+ });
10561
+ var input = (createElement(Input, __assign({ className: this.props.inputClassName, ref: function (i) { return (_this.input = i); }, value: this.state.userInput, doNotSubmitOnEnter: !this.state.isSuggestsHidden, ignoreTab: this.props.ignoreTab, ignoreEnter: this.props.ignoreEnter, style: this.props.style && this.props.style.input, onChange: this.onInputChange, onFocus: this.onInputFocus, onBlur: this.onInputBlur, onKeyDown: this.props.onKeyDown, onKeyPress: this.props.onKeyPress, inputType: this.props.inputType, onNext: this.onNext, onPrev: this.onPrev, onSelect: this.onSelect, onEscape: this.hideSuggests, isSuggestsHidden: this.state.isSuggestsHidden, activeSuggest: this.state.activeSuggest, label: this.props.label, id: this.props.id, listId: this.listId }, attributes)));
10562
+ var suggestionsList = (createElement(default_1$1, { isHidden: this.state.isSuggestsHidden, style: this.props.style && this.props.style.suggests, suggestItemStyle: this.props.style && this.props.style.suggestItem, userInput: this.state.userInput, isHighlightMatch: Boolean(this.props.highlightMatch), suggestsClassName: this.props.suggestsClassName, suggestItemClassName: this.props.suggestItemClassName, suggests: this.state.suggests, hiddenClassName: this.props.suggestsHiddenClassName, suggestItemActiveClassName: this.props.suggestItemActiveClassName, activeSuggest: this.state.activeSuggest, onSuggestNoResults: this.onSuggestNoResults, onSuggestMouseDown: this.onSuggestMouseDown, onSuggestMouseOut: this.onSuggestMouseOut, onSuggestSelect: this.selectSuggest, renderSuggestItem: this.props.renderSuggestItem, listId: this.listId }));
10563
+ return (createElement("div", { className: classes, id: this.props.id },
10564
+ createElement("div", { className: "geosuggest__input-wrapper" }, input),
10565
+ createElement("div", { className: "geosuggest__suggests-wrapper" }, suggestionsList)));
10566
+ };
10567
+ default_1.defaultProps = defaults;
10568
+ return default_1;
10569
+ }(Component));
10570
+
9681
10571
  var AddressInputGroupForm = function (props) {
9682
- var _a = props.name, name = _a === void 0 ? 'address-input' : _a, label = props.label, description = props.description,
9683
- // placeholder,
9684
- required = props.required,
9685
- // value,
9686
- error = props.error, _b = props.type, type = _b === void 0 ? 'normal' : _b, isDisabled = props.isDisabled, _c = props.isRequired, isRequired = _c === void 0 ? false : _c, _d = props.isTouched, isTouched = _d === void 0 ? false : _d,
9687
- // onChange,
9688
- // onFocus,
9689
- // onBlur,
9690
- stylesOverrides = props.styles;
10572
+ var _a, _b, _c;
10573
+ var _d = props.name, name = _d === void 0 ? 'address-input' : _d, label = props.label, description = props.description, placeholder = props.placeholder, required = props.required, value = props.value, error = props.error, _e = props.type, type = _e === void 0 ? 'normal' : _e, isDisabled = props.isDisabled, _f = props.isRequired, isRequired = _f === void 0 ? false : _f, _g = props.isTouched, isTouched = _g === void 0 ? false : _g, onChange = props.onChange, onFocus = props.onFocus, onBlur = props.onBlur, stylesOverrides = props.styles;
9691
10574
  var isValid = error === undefined;
9692
10575
  var handleGenerateStyle = function () {
9693
10576
  var result = deepCopyObject(styles.base);
@@ -9698,23 +10581,80 @@ var AddressInputGroupForm = function (props) {
9698
10581
  return result;
9699
10582
  };
9700
10583
  var styles$1 = handleGenerateStyle();
9701
- // const mapValueToAddress = (
9702
- // value: TAddressInputGroupFormValue | undefined,
9703
- // ) => {
9704
- // if (!value) {
9705
- // return undefined;
9706
- // }
9707
- // const { country, city, street, houseNumber } = value;
9708
- // return `${street ?? ''}${houseNumber ? ' ' + houseNumber : ''}${
9709
- // city ? ', ' + city : ''
9710
- // }${country ? ', ' + country : ''}`;
9711
- // };
10584
+ var mapValueToAddress = function (value) {
10585
+ if (!value) {
10586
+ return undefined;
10587
+ }
10588
+ var country = value.country, city = value.city, street = value.street, houseNumber = value.houseNumber;
10589
+ return "".concat(street !== null && street !== void 0 ? street : '').concat(houseNumber ? ' ' + houseNumber : '').concat(city ? ', ' + city : '').concat(country ? ', ' + country : '');
10590
+ };
9712
10591
  // useEffect(() => {
9713
10592
  // if (form.values[name]) {
9714
10593
  // onChange && onChange(form.values[name]);
9715
10594
  // }
9716
10595
  // }, [form.values, name, onChange]);
9717
- return (jsxs("div", { className: styles$1.container, children: [jsxs("div", { className: styles$1.head, children: [label && (jsx("label", { htmlFor: name, className: styles$1.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles$1.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsx("div", { className: styles$1.body }), jsxs("div", { className: styles$1.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles$1.description, children: description })), error && isTouched && jsx("p", { className: styles$1.error, children: error })] })] }));
10596
+ return (jsxs("div", { className: styles$1.container, children: [jsxs("div", { className: styles$1.head, children: [label && (jsx("label", { htmlFor: name, className: styles$1.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles$1.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsx("div", { className: styles$1.body, children: jsx(default_1$2, { types: ['address'], queryDelay: 100, placeholder: placeholder, initialValue: mapValueToAddress(value), inputClassName: styles$1 === null || styles$1 === void 0 ? void 0 : styles$1.input, suggestsClassName: (_a = styles$1.geosuggest) === null || _a === void 0 ? void 0 : _a.suggestsClassName, suggestItemClassName: (_b = styles$1.geosuggest) === null || _b === void 0 ? void 0 : _b.suggestItemClassName, suggestsHiddenClassName: (_c = styles$1.geosuggest) === null || _c === void 0 ? void 0 : _c.suggestsHiddenClassName, onChange: function (value) {
10597
+ if (value === '') {
10598
+ onChange(null);
10599
+ }
10600
+ }, onFocus: onFocus,
10601
+ // suggestItemActiveClassName={
10602
+ // styles.geosuggest?.suggestItemActiveClassName
10603
+ // }
10604
+ autoComplete: "off", placeDetailFields: ['address_components'], onSuggestSelect: function (e) {
10605
+ var _a, _b, _c, _d, _e;
10606
+ var components = (_a = e === null || e === void 0 ? void 0 : e.gmaps) === null || _a === void 0 ? void 0 : _a.address_components;
10607
+ var handleExtractValueWithKey = function (key) {
10608
+ var _a;
10609
+ return (_a = components === null || components === void 0 ? void 0 : components.find(function (component) {
10610
+ return component.types.includes(key);
10611
+ })) === null || _a === void 0 ? void 0 : _a.long_name;
10612
+ };
10613
+ var street = handleExtractValueWithKey('route');
10614
+ var city = handleExtractValueWithKey('locality');
10615
+ var country = handleExtractValueWithKey('country');
10616
+ var zipCode = handleExtractValueWithKey('postal_code');
10617
+ var houseNumber = handleExtractValueWithKey('street_number');
10618
+ var busNumber = handleExtractValueWithKey('post_box');
10619
+ var location = {
10620
+ street: street,
10621
+ city: city,
10622
+ country: country,
10623
+ zipCode: zipCode,
10624
+ houseNumber: houseNumber,
10625
+ busNumber: busNumber,
10626
+ lat: (_c = (_b = e === null || e === void 0 ? void 0 : e.location) === null || _b === void 0 ? void 0 : _b.lat) !== null && _c !== void 0 ? _c : 0,
10627
+ lng: (_e = (_d = e === null || e === void 0 ? void 0 : e.location) === null || _d === void 0 ? void 0 : _d.lng) !== null && _e !== void 0 ? _e : 0,
10628
+ };
10629
+ onChange && onChange(location);
10630
+ }, onBlur: function (e) {
10631
+ var _a, _b, _c, _d, _e;
10632
+ var components = (_a = e === null || e === void 0 ? void 0 : e.gmaps) === null || _a === void 0 ? void 0 : _a.address_components;
10633
+ var handleExtractValueWithKey = function (key) {
10634
+ var _a;
10635
+ return (_a = components === null || components === void 0 ? void 0 : components.find(function (component) {
10636
+ return component.types.includes(key);
10637
+ })) === null || _a === void 0 ? void 0 : _a.long_name;
10638
+ };
10639
+ var street = handleExtractValueWithKey('route');
10640
+ var city = handleExtractValueWithKey('locality');
10641
+ var country = handleExtractValueWithKey('country');
10642
+ var zipCode = handleExtractValueWithKey('postal_code');
10643
+ var houseNumber = handleExtractValueWithKey('street_number');
10644
+ var busNumber = handleExtractValueWithKey('post_box');
10645
+ var location = {
10646
+ street: street,
10647
+ city: city,
10648
+ country: country,
10649
+ zipCode: zipCode,
10650
+ houseNumber: houseNumber,
10651
+ busNumber: busNumber,
10652
+ lat: (_c = (_b = e === null || e === void 0 ? void 0 : e.location) === null || _b === void 0 ? void 0 : _b.lat) !== null && _c !== void 0 ? _c : 0,
10653
+ lng: (_e = (_d = e === null || e === void 0 ? void 0 : e.location) === null || _d === void 0 ? void 0 : _d.lng) !== null && _e !== void 0 ? _e : 0,
10654
+ info: value === null || value === void 0 ? void 0 : value.info,
10655
+ };
10656
+ onBlur && onBlur(location);
10657
+ }, children: jsx(Fragment$1, {}) }) }), jsxs("div", { className: styles$1.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles$1.description, children: description })), error && isTouched && jsx("p", { className: styles$1.error, children: error })] })] }));
9718
10658
  };
9719
10659
 
9720
10660
  var base = {