@ballistix.digital/react-components 0.5.1 → 0.5.3

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