@pega/cosmos-react-core 7.0.0-build.13.2 → 7.0.0-build.15.0

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.
Files changed (53) hide show
  1. package/lib/components/ListToolbar/ListToolbar.d.ts +1 -1
  2. package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
  3. package/lib/components/ListToolbar/ListToolbar.js +5 -5
  4. package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
  5. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts +1 -1
  6. package/lib/components/ListToolbar/ListToolbar.test-ids.d.ts.map +1 -1
  7. package/lib/components/ListToolbar/ListToolbar.test-ids.js +4 -1
  8. package/lib/components/ListToolbar/ListToolbar.test-ids.js.map +1 -1
  9. package/lib/components/Location/CurrentLocationButton.d.ts +1 -6
  10. package/lib/components/Location/CurrentLocationButton.d.ts.map +1 -1
  11. package/lib/components/Location/CurrentLocationButton.js +10 -20
  12. package/lib/components/Location/CurrentLocationButton.js.map +1 -1
  13. package/lib/components/Location/Location.types.d.ts +48 -17
  14. package/lib/components/Location/Location.types.d.ts.map +1 -1
  15. package/lib/components/Location/Location.types.js +9 -1
  16. package/lib/components/Location/Location.types.js.map +1 -1
  17. package/lib/components/Location/LocationDisplay.d.ts +5 -4
  18. package/lib/components/Location/LocationDisplay.d.ts.map +1 -1
  19. package/lib/components/Location/LocationDisplay.js +17 -4
  20. package/lib/components/Location/LocationDisplay.js.map +1 -1
  21. package/lib/components/Location/LocationInput.d.ts +22 -17
  22. package/lib/components/Location/LocationInput.d.ts.map +1 -1
  23. package/lib/components/Location/LocationInput.js +36 -14
  24. package/lib/components/Location/LocationInput.js.map +1 -1
  25. package/lib/components/Location/LocationView.d.ts +17 -7
  26. package/lib/components/Location/LocationView.d.ts.map +1 -1
  27. package/lib/components/Location/LocationView.js +34 -38
  28. package/lib/components/Location/LocationView.js.map +1 -1
  29. package/lib/components/Location/index.d.ts +2 -2
  30. package/lib/components/Location/index.d.ts.map +1 -1
  31. package/lib/components/Location/index.js +1 -1
  32. package/lib/components/Location/index.js.map +1 -1
  33. package/lib/components/Location/utils.d.ts +2 -2
  34. package/lib/components/Location/utils.d.ts.map +1 -1
  35. package/lib/components/Location/utils.js +1 -1
  36. package/lib/components/Location/utils.js.map +1 -1
  37. package/lib/hooks/useI18n.d.ts +0 -1
  38. package/lib/hooks/useI18n.d.ts.map +1 -1
  39. package/lib/i18n/default.d.ts +0 -1
  40. package/lib/i18n/default.d.ts.map +1 -1
  41. package/lib/i18n/default.js +1 -2
  42. package/lib/i18n/default.js.map +1 -1
  43. package/lib/i18n/i18n.d.ts +0 -1
  44. package/lib/i18n/i18n.d.ts.map +1 -1
  45. package/lib/styles/GlobalStyle.d.ts +1 -1
  46. package/lib/styles/GlobalStyle.d.ts.map +1 -1
  47. package/lib/styles/GlobalStyle.js +7 -1
  48. package/lib/styles/GlobalStyle.js.map +1 -1
  49. package/package.json +1 -1
  50. package/lib/components/Location/types.d.ts +0 -45
  51. package/lib/components/Location/types.d.ts.map +0 -1
  52. package/lib/components/Location/types.js +0 -10
  53. package/lib/components/Location/types.js.map +0 -1
@@ -1,17 +1,9 @@
1
1
  import type { FC } from 'react';
2
2
  import type { FormControlProps } from '../FormControl';
3
3
  import type { BaseProps, ForwardProps, TestIdProp } from '../../types';
4
- import type BaseLocationProps from './Location.types';
5
- import type { LatLng } from './types';
4
+ import type { Bias, LatLng } from './Location.types';
6
5
  import type { LocationViewProps } from './LocationView';
7
- export interface LocationInputProps extends LocationViewProps, BaseLocationProps, BaseProps, FormControlProps, TestIdProp {
8
- /** Button when clicked will show additional information for the location input */
9
- additionalInfo?: FormControlProps['additionalInfo'];
10
- /**
11
- * Only select coordinates on map clicks.
12
- * @default false
13
- */
14
- onlyCoordinates?: boolean;
6
+ export interface LocationInputProps extends BaseProps, FormControlProps, TestIdProp {
15
7
  /**
16
8
  * Get user current location on component first render.
17
9
  * @default false
@@ -29,13 +21,6 @@ export interface LocationInputProps extends LocationViewProps, BaseLocationProps
29
21
  * The argument passed back is the component's value prop.
30
22
  */
31
23
  onBlur?: (value: string) => void;
32
- /**
33
- * Set to true renders the map view below input.
34
- * @default false
35
- */
36
- showMap?: boolean;
37
- /** Location coordinates used for the map view. */
38
- location?: LatLng | string;
39
24
  /** Callback fired when user chooses location from the dropdown of suggestions or submits input value. */
40
25
  onSelect?: (value: {
41
26
  name?: string;
@@ -43,6 +28,26 @@ export interface LocationInputProps extends LocationViewProps, BaseLocationProps
43
28
  latitude?: number;
44
29
  longitude?: number;
45
30
  }) => void;
31
+ /**
32
+ * Only select coordinates on map clicks.
33
+ * @default false
34
+ */
35
+ onlyCoordinates?: boolean;
36
+ /** Biasing query results towards user location/preference. */
37
+ bias?: Bias;
38
+ /**
39
+ * Set to true renders the map view below input.
40
+ * @default false
41
+ */
42
+ map?: {
43
+ /** Location coordinates used for the map view. */
44
+ location?: LatLng;
45
+ height: LocationViewProps['height'];
46
+ zoomLevel?: LocationViewProps['zoomLevel'];
47
+ onClick?: LocationViewProps['onClick'];
48
+ };
49
+ /** Callback fired when an error occurs. This function gets called with one argument of type Error. */
50
+ onError?: (error: Error) => void;
46
51
  }
47
52
  declare const _default: FC<LocationInputProps & ForwardProps> & {
48
53
  getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly ["control", "label", "info", "additional-info", "suggestion-accept", "suggestion-reject"]>;
@@ -1 +1 @@
1
- {"version":3,"file":"LocationInput.d.ts","sourceRoot":"","sources":["../../../src/components/Location/LocationInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,EAAE,EAAwB,MAAM,OAAO,CAAC;AAQnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAcvE,OAAO,KAAK,iBAAiB,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,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, useCallback, useContext, useEffect, useState } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import ComboBox from '../ComboBox';
5
- import { useI18n, useTestIds } from '../../hooks';
5
+ import { useI18n, useTestIds, useUID } from '../../hooks';
6
6
  import { createUID, withTestIds } from '../../utils';
7
7
  import FormField from '../FormField';
8
8
  import Flex from '../Flex';
9
+ import { defaultThemeProp } from '../../theme';
9
10
  import PoweredByGoogleImage from './PoweredByGoogleImage';
10
11
  import CurrentLocationButton from './CurrentLocationButton';
11
12
  import MapsContext from './MapsContext';
12
- import { getAddress, getCoords, getPlaceById, getPlacePredictions, isValueACoordinate, loadMapsAPI } from './utils';
13
+ import { getAddress, getCoords, getNavigatorPosition, getPlaceById, getPlacePredictions, isValueACoordinate, loadMapsAPI } from './utils';
13
14
  import LocationView, { StyledLocationView } from './LocationView';
14
15
  import { getLocationInputTestIds } from './Location.test-ids';
16
+ const StyledLocationInput = styled(ComboBox) `
17
+ z-index: 1;
18
+ `;
19
+ StyledLocationInput.defaultProps = defaultThemeProp;
15
20
  const StyledLocationMap = styled.div `
16
21
  ${StyledLocationView} {
17
22
  border-top-left-radius: 0;
18
23
  border-top-right-radius: 0;
19
24
  }
20
25
  `;
26
+ StyledLocationMap.defaultProps = defaultThemeProp;
21
27
  const LocationInput = forwardRef(function LocationInput(props, ref) {
22
- const { testId, label, labelHidden, id = createUID(), location = '', value = '', info, status, required, readOnly, disabled, additionalInfo, onSelect, onError, onChange, bias, showMap, defaultToCurrentLocation, centerMapOnChange, height, zoomLevel, onClick, onBlur, onlyCoordinates = false, ...restProps } = props;
28
+ const uid = useUID();
29
+ const { testId, label, labelHidden, id = uid, value = '', info, status, required, readOnly, disabled, additionalInfo, onSelect, onError, onChange, onBlur, bias, defaultToCurrentLocation, onlyCoordinates = false, map, ...restProps } = props;
23
30
  const testIds = useTestIds(testId, getLocationInputTestIds);
24
31
  const { name, ...providerOpts } = useContext(MapsContext);
25
32
  const t = useI18n();
26
33
  const [placePredictionMenuItems, setPlacePredictionMenuItems] = useState([]);
27
34
  const [filterValue, setFilterValue] = useState('');
35
+ const [mapLoading, setMapLoading] = useState(false);
36
+ useEffect(() => {
37
+ (async () => {
38
+ if (defaultToCurrentLocation) {
39
+ setMapLoading(true);
40
+ await loadMapsAPI(name, providerOpts);
41
+ const navigatorPosition = await getNavigatorPosition();
42
+ const currentLocationAddress = await getAddress(navigatorPosition);
43
+ setMapLoading(false);
44
+ onSelect?.(currentLocationAddress);
45
+ }
46
+ })();
47
+ }, []);
28
48
  useEffect(() => {
29
49
  (async () => {
30
50
  try {
@@ -134,20 +154,22 @@ const LocationInput = forwardRef(function LocationInput(props, ref) {
134
154
  onChange?.(e.target.value);
135
155
  }, [onChange]);
136
156
  const onMapClick = useCallback((placeInfo) => {
157
+ if (readOnly)
158
+ return;
137
159
  if (onlyCoordinates) {
138
160
  const coords = {
139
161
  latitude: placeInfo.latitude,
140
162
  longitude: placeInfo.longitude
141
163
  };
142
164
  onSelect?.(coords);
143
- onClick?.(coords);
165
+ map?.onClick?.(coords);
144
166
  }
145
167
  else {
146
168
  onSelect?.(placeInfo);
147
- onClick?.(placeInfo);
169
+ map?.onClick?.(placeInfo);
148
170
  }
149
- }, [onSelect, onClick, onlyCoordinates]);
150
- const Comp = (_jsxs(_Fragment, { children: [_jsx(ComboBox, { "data-testid": testIds.control, placeholder: t('location_input_placeholder'), menu: filterValue
171
+ }, [readOnly, onSelect, map?.onClick, onlyCoordinates]);
172
+ const Comp = (_jsxs(_Fragment, { children: [_jsx(ComboBox, { as: StyledLocationInput, "data-testid": testIds.control, placeholder: t('location_input_placeholder'), menu: filterValue
151
173
  ? {
152
174
  items: placePredictionMenuItems.concat([
153
175
  {
@@ -155,26 +177,26 @@ const LocationInput = forwardRef(function LocationInput(props, ref) {
155
177
  primary: t('use_input_value', [filterValue]),
156
178
  onClick: () => {
157
179
  setFilterValue('');
158
- onSelect?.({ name: filterValue, address: filterValue });
180
+ onSelect?.({ name: filterValue });
159
181
  }
160
182
  }
161
183
  ]),
162
184
  emptyText: t('location_not_found_text'),
163
185
  mode: 'action',
164
- footer: !showMap && (_jsx(Flex, { container: { justify: 'end' }, children: _jsx(PoweredByGoogleImage, {}) }))
186
+ footer: !map && (_jsx(Flex, { container: { justify: 'end' }, children: _jsx(PoweredByGoogleImage, {}) }))
165
187
  }
166
188
  : undefined, actions: !disabled &&
167
- !readOnly && (_jsx(CurrentLocationButton, { defaultToCurrentLocation: defaultToCurrentLocation, onError: onError, onChange: a => {
168
- if (onlyCoordinates && a.longitude && a.latitude) {
169
- onSelect?.({ latitude: a.latitude, longitude: a.longitude });
189
+ !readOnly && (_jsx(CurrentLocationButton, { onError: onError, onResolve: resolved => {
190
+ if (onlyCoordinates) {
191
+ onSelect?.({ latitude: resolved.latitude, longitude: resolved.longitude });
170
192
  }
171
193
  else {
172
- onSelect?.(a);
194
+ onSelect?.(resolved);
173
195
  }
174
196
  } })), onChange: onInputChange, onBlur: () => {
175
197
  setFilterValue('');
176
198
  onBlur?.(value);
177
- }, value: value, required: required, disabled: disabled, readOnly: readOnly, status: status, ...restProps }), showMap && (_jsx(StyledLocationMap, { children: _jsx(LocationView, { location: location, onClick: onMapClick, onError: onError, bias: bias, disabled: disabled, centerMapOnChange: centerMapOnChange, height: height, zoomLevel: zoomLevel }) }))] }));
199
+ }, value: value, required: required, disabled: disabled, readOnly: readOnly, status: status, ...restProps }), map && (_jsx(StyledLocationMap, { children: _jsx(LocationView, { ...map, pins: map.location ? [{ ...map.location }] : [], onClick: onMapClick, onError: onError, disabled: disabled, loading: mapLoading, centerMapOnChange: true }) }))] }));
178
200
  return label ? (_jsx(FormField, { testId: testIds, label: label, labelHidden: labelHidden, id: id, info: info, status: status, ref: ref, required: required, disabled: disabled, additionalInfo: additionalInfo, children: Comp })) : (Comp);
179
201
  });
180
202
  export default withTestIds(LocationInput, getLocationInputTestIds);
@@ -1 +1 @@
1
- {"version":3,"file":"LocationInput.js","sourceRoot":"","sources":["../../../src/components/Location/LocationInput.tsx"],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AQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,KACV,SAAS,GACb,EACD,OAAO,IAAI,CACV,KAAC,iBAAiB,cAChB,KAAC,YAAY,IACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GACpB,GACgB,CACrB,IACA,CACJ,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,YAE7B,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useContext, useEffect, useState } from 'react';\nimport type { ChangeEvent, FC, PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport ComboBox from '../ComboBox';\nimport type { MenuItemProps, MenuProps } from '../Menu';\nimport { useI18n, useTestIds } from '../../hooks';\nimport { createUID, withTestIds } from '../../utils';\nimport FormField from '../FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { BaseProps, ForwardProps, TestIdProp } from '../../types';\nimport Flex from '../Flex';\n\nimport PoweredByGoogleImage from './PoweredByGoogleImage';\nimport CurrentLocationButton from './CurrentLocationButton';\nimport MapsContext from './MapsContext';\nimport {\n getAddress,\n getCoords,\n getPlaceById,\n getPlacePredictions,\n isValueACoordinate,\n loadMapsAPI\n} from './utils';\nimport type BaseLocationProps from './Location.types';\nimport type { LatLng } from './types';\nimport LocationView, { StyledLocationView } from './LocationView';\nimport type { LocationViewProps } from './LocationView';\nimport { getLocationInputTestIds } from './Location.test-ids';\n\nexport interface LocationInputProps\n extends LocationViewProps,\n BaseLocationProps,\n BaseProps,\n FormControlProps,\n TestIdProp {\n /** Button when clicked will show additional information for the location input */\n additionalInfo?: FormControlProps['additionalInfo'];\n /**\n * Only select coordinates on map clicks.\n * @default false\n */\n onlyCoordinates?: boolean;\n /**\n * Get user current location on component first render.\n * @default false\n */\n defaultToCurrentLocation?: boolean;\n /** The value of the location field. */\n value?: string;\n /**\n * Callback fired on every change of the location input.\n * The argument passed back is the component's value prop.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the control's input loses focus.\n * The argument passed back is the component's value prop.\n */\n onBlur?: (value: string) => void;\n /**\n * Set to true renders the map view below input.\n * @default false\n */\n showMap?: boolean;\n /** Location coordinates used for the map view. */\n location?: LatLng | string;\n /** Callback fired when user chooses location from the dropdown of suggestions or submits input value. */\n onSelect?: (value: {\n name?: string;\n address?: string;\n latitude?: number;\n longitude?: number;\n }) => void;\n}\n\nconst StyledLocationMap = styled.div`\n ${StyledLocationView} {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n }\n`;\n\nconst LocationInput: FC<LocationInputProps & ForwardProps> = forwardRef(function LocationInput(\n props: PropsWithoutRef<LocationInputProps>,\n ref: Ref<HTMLInputElement>\n) {\n const {\n testId,\n label,\n labelHidden,\n id = createUID(),\n location = '',\n value = '',\n info,\n status,\n required,\n readOnly,\n disabled,\n additionalInfo,\n onSelect,\n onError,\n onChange,\n bias,\n showMap,\n defaultToCurrentLocation,\n centerMapOnChange,\n height,\n zoomLevel,\n onClick,\n onBlur,\n onlyCoordinates = false,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getLocationInputTestIds);\n\n const { name, ...providerOpts } = useContext(MapsContext);\n const t = useI18n();\n const [placePredictionMenuItems, setPlacePredictionMenuItems] = useState<MenuProps['items']>([]);\n\n const [filterValue, setFilterValue] = useState('');\n\n useEffect(() => {\n (async () => {\n try {\n await loadMapsAPI(name, providerOpts);\n if (filterValue) {\n if (onlyCoordinates) {\n const { latitude, longitude } = await getCoords(filterValue);\n setPlacePredictionMenuItems([\n {\n primary: t('exact_location'),\n secondary: [`${latitude}, ${longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ latitude, longitude });\n }\n }\n ]);\n } else {\n if (isValueACoordinate(filterValue)) {\n const { latitude, longitude } = await getCoords(filterValue);\n const { name: addressName, address } = await getAddress({ latitude, longitude });\n const menuItems = [\n {\n primary: t('exact_location'),\n secondary: [`${latitude}, ${longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({\n latitude,\n longitude\n });\n }\n },\n {\n primary: addressName,\n secondary: [address],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ name: addressName, address, latitude, longitude });\n }\n }\n ];\n setPlacePredictionMenuItems(menuItems);\n return;\n }\n const { placePredictions, token } = await getPlacePredictions(filterValue, bias);\n if (placePredictions.length === 1) {\n const exactLocation = await getPlaceById(placePredictions[0].place_id, token);\n const menuItems = placePredictions.map(item => ({\n id: item.place_id,\n primary: item.structured_formatting.main_text,\n secondary: [item.structured_formatting.secondary_text],\n onClick: (menuItemId: MenuItemProps['id']) => {\n getPlaceById(menuItemId, token).then(menuItemLocation => {\n setFilterValue('');\n onSelect?.(menuItemLocation);\n });\n }\n }));\n if (exactLocation) {\n menuItems.push({\n primary: t('exact_location'),\n secondary: [`${exactLocation.latitude}, ${exactLocation.longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({\n latitude: exactLocation.latitude,\n longitude: exactLocation.longitude\n });\n }\n });\n }\n setPlacePredictionMenuItems(menuItems);\n } else {\n setPlacePredictionMenuItems(\n placePredictions.map(item => ({\n id: item.place_id,\n primary: item.structured_formatting.main_text,\n secondary: [item.structured_formatting.secondary_text],\n onClick: (menuItemId: MenuItemProps['id']) => {\n getPlaceById(menuItemId, token).then(menuItemLocation => {\n setFilterValue('');\n onSelect?.(menuItemLocation);\n });\n }\n }))\n );\n }\n }\n } else {\n setPlacePredictionMenuItems([]);\n }\n } catch (e: any) {\n setPlacePredictionMenuItems([]);\n onError?.(e);\n }\n })();\n }, [filterValue, bias, onError, onSelect, onlyCoordinates]);\n\n const onInputChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n setFilterValue(e.target.value);\n onChange?.(e.target.value);\n },\n [onChange]\n );\n\n const onMapClick = useCallback(\n (placeInfo: { latitude: number; longitude: number; name?: string; address?: string }) => {\n if (onlyCoordinates) {\n const coords = {\n latitude: placeInfo.latitude,\n longitude: placeInfo.longitude\n };\n onSelect?.(coords);\n onClick?.(coords);\n } else {\n onSelect?.(placeInfo);\n onClick?.(placeInfo);\n }\n },\n [onSelect, onClick, onlyCoordinates]\n );\n\n const Comp = (\n <>\n <ComboBox\n data-testid={testIds.control}\n placeholder={t('location_input_placeholder')}\n menu={\n filterValue\n ? {\n items: placePredictionMenuItems.concat([\n {\n id: createUID(),\n primary: t('use_input_value', [filterValue]),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ name: filterValue, address: filterValue });\n }\n }\n ]),\n emptyText: t('location_not_found_text'),\n mode: 'action',\n footer: !showMap && (\n <Flex container={{ justify: 'end' }}>\n <PoweredByGoogleImage />\n </Flex>\n )\n }\n : undefined\n }\n actions={\n !disabled &&\n !readOnly && (\n <CurrentLocationButton\n defaultToCurrentLocation={defaultToCurrentLocation}\n onError={onError}\n onChange={a => {\n if (onlyCoordinates && a.longitude && a.latitude) {\n onSelect?.({ latitude: a.latitude, longitude: a.longitude });\n } else {\n onSelect?.(a);\n }\n }}\n />\n )\n }\n onChange={onInputChange}\n onBlur={() => {\n setFilterValue('');\n onBlur?.(value);\n }}\n value={value}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n {...restProps}\n />\n {showMap && (\n <StyledLocationMap>\n <LocationView\n location={location}\n onClick={onMapClick}\n onError={onError}\n bias={bias}\n disabled={disabled}\n centerMapOnChange={centerMapOnChange}\n height={height}\n zoomLevel={zoomLevel}\n />\n </StyledLocationMap>\n )}\n </>\n );\n\n return label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n status={status}\n ref={ref}\n required={required}\n disabled={disabled}\n additionalInfo={additionalInfo}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n});\n\nexport default withTestIds(LocationInput, getLocationInputTestIds);\n"]}
1
+ {"version":3,"file":"LocationInput.js","sourceRoot":"","sources":["../../../src/components/Location/LocationInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,SAAS,MAAM,cAAc,CAAC;AAGrC,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,oBAAoB,MAAM,wBAAwB,CAAC;AAC1D,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,YAAY,EAAE,EAAE,kB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ACZ,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,KACV,SAAS,GACb,EACD,GAAG,IAAI,CACN,KAAC,iBAAiB,cAChB,KAAC,YAAY,OACP,GAAG,EACP,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAC/C,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,UAAU,EACnB,iBAAiB,SACjB,GACgB,CACrB,IACA,CACJ,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,YAE7B,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useContext, useEffect, useState } from 'react';\nimport type { ChangeEvent, FC, PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport ComboBox from '../ComboBox';\nimport type { MenuItemProps, MenuProps } from '../Menu';\nimport { useI18n, useTestIds, useUID } from '../../hooks';\nimport { createUID, withTestIds } from '../../utils';\nimport FormField from '../FormField';\nimport type { FormControlProps } from '../FormControl';\nimport type { BaseProps, ForwardProps, TestIdProp } from '../../types';\nimport Flex from '../Flex';\nimport { defaultThemeProp } from '../../theme';\n\nimport PoweredByGoogleImage from './PoweredByGoogleImage';\nimport CurrentLocationButton from './CurrentLocationButton';\nimport MapsContext from './MapsContext';\nimport {\n getAddress,\n getCoords,\n getNavigatorPosition,\n getPlaceById,\n getPlacePredictions,\n isValueACoordinate,\n loadMapsAPI\n} from './utils';\nimport type { Bias, LatLng } from './Location.types';\nimport LocationView, { StyledLocationView } from './LocationView';\nimport type { LocationViewProps } from './LocationView';\nimport { getLocationInputTestIds } from './Location.test-ids';\n\nexport interface LocationInputProps extends BaseProps, FormControlProps, TestIdProp {\n /**\n * Get user current location on component first render.\n * @default false\n */\n defaultToCurrentLocation?: boolean;\n /** The value of the location field. */\n value?: string;\n /**\n * Callback fired on every change of the location input.\n * The argument passed back is the component's value prop.\n */\n onChange?: (value: string) => void;\n /**\n * Callback fired when the control's input loses focus.\n * The argument passed back is the component's value prop.\n */\n onBlur?: (value: string) => void;\n /** Callback fired when user chooses location from the dropdown of suggestions or submits input value. */\n onSelect?: (value: {\n name?: string;\n address?: string;\n latitude?: number;\n longitude?: number;\n }) => void;\n /**\n * Only select coordinates on map clicks.\n * @default false\n */\n onlyCoordinates?: boolean;\n /** Biasing query results towards user location/preference. */\n bias?: Bias;\n /**\n * Set to true renders the map view below input.\n * @default false\n */\n map?: {\n /** Location coordinates used for the map view. */\n location?: LatLng;\n height: LocationViewProps['height'];\n zoomLevel?: LocationViewProps['zoomLevel'];\n onClick?: LocationViewProps['onClick'];\n };\n /** Callback fired when an error occurs. This function gets called with one argument of type Error. */\n onError?: (error: Error) => void;\n}\n\nconst StyledLocationInput = styled(ComboBox)`\n z-index: 1;\n`;\n\nStyledLocationInput.defaultProps = defaultThemeProp;\n\nconst StyledLocationMap = styled.div`\n ${StyledLocationView} {\n border-top-left-radius: 0;\n border-top-right-radius: 0;\n }\n`;\n\nStyledLocationMap.defaultProps = defaultThemeProp;\n\nconst LocationInput: FC<LocationInputProps & ForwardProps> = forwardRef(function LocationInput(\n props: PropsWithoutRef<LocationInputProps>,\n ref: Ref<HTMLInputElement>\n) {\n const uid = useUID();\n const {\n testId,\n label,\n labelHidden,\n id = uid,\n value = '',\n info,\n status,\n required,\n readOnly,\n disabled,\n additionalInfo,\n onSelect,\n onError,\n onChange,\n onBlur,\n bias,\n defaultToCurrentLocation,\n onlyCoordinates = false,\n map,\n ...restProps\n } = props;\n\n const testIds = useTestIds(testId, getLocationInputTestIds);\n\n const { name, ...providerOpts } = useContext(MapsContext);\n const t = useI18n();\n const [placePredictionMenuItems, setPlacePredictionMenuItems] = useState<MenuProps['items']>([]);\n const [filterValue, setFilterValue] = useState('');\n const [mapLoading, setMapLoading] = useState(false);\n\n useEffect(() => {\n (async () => {\n if (defaultToCurrentLocation) {\n setMapLoading(true);\n await loadMapsAPI(name, providerOpts);\n const navigatorPosition = await getNavigatorPosition();\n const currentLocationAddress = await getAddress(navigatorPosition);\n setMapLoading(false);\n onSelect?.(currentLocationAddress);\n }\n })();\n }, []);\n\n useEffect(() => {\n (async () => {\n try {\n await loadMapsAPI(name, providerOpts);\n if (filterValue) {\n if (onlyCoordinates) {\n const { latitude, longitude } = await getCoords(filterValue);\n setPlacePredictionMenuItems([\n {\n primary: t('exact_location'),\n secondary: [`${latitude}, ${longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ latitude, longitude });\n }\n }\n ]);\n } else {\n if (isValueACoordinate(filterValue)) {\n const { latitude, longitude } = await getCoords(filterValue);\n const { name: addressName, address } = await getAddress({ latitude, longitude });\n const menuItems = [\n {\n primary: t('exact_location'),\n secondary: [`${latitude}, ${longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({\n latitude,\n longitude\n });\n }\n },\n {\n primary: addressName,\n secondary: [address],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ name: addressName, address, latitude, longitude });\n }\n }\n ];\n setPlacePredictionMenuItems(menuItems);\n return;\n }\n const { placePredictions, token } = await getPlacePredictions(filterValue, bias);\n if (placePredictions.length === 1) {\n const exactLocation = await getPlaceById(placePredictions[0].place_id, token);\n const menuItems = placePredictions.map(item => ({\n id: item.place_id,\n primary: item.structured_formatting.main_text,\n secondary: [item.structured_formatting.secondary_text],\n onClick: (menuItemId: MenuItemProps['id']) => {\n getPlaceById(menuItemId, token).then(menuItemLocation => {\n setFilterValue('');\n onSelect?.(menuItemLocation);\n });\n }\n }));\n if (exactLocation) {\n menuItems.push({\n primary: t('exact_location'),\n secondary: [`${exactLocation.latitude}, ${exactLocation.longitude}`],\n id: createUID(),\n onClick: () => {\n setFilterValue('');\n onSelect?.({\n latitude: exactLocation.latitude,\n longitude: exactLocation.longitude\n });\n }\n });\n }\n setPlacePredictionMenuItems(menuItems);\n } else {\n setPlacePredictionMenuItems(\n placePredictions.map(item => ({\n id: item.place_id,\n primary: item.structured_formatting.main_text,\n secondary: [item.structured_formatting.secondary_text],\n onClick: (menuItemId: MenuItemProps['id']) => {\n getPlaceById(menuItemId, token).then(menuItemLocation => {\n setFilterValue('');\n onSelect?.(menuItemLocation);\n });\n }\n }))\n );\n }\n }\n } else {\n setPlacePredictionMenuItems([]);\n }\n } catch (e: any) {\n setPlacePredictionMenuItems([]);\n onError?.(e);\n }\n })();\n }, [filterValue, bias, onError, onSelect, onlyCoordinates]);\n\n const onInputChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n setFilterValue(e.target.value);\n onChange?.(e.target.value);\n },\n [onChange]\n );\n\n const onMapClick = useCallback(\n (placeInfo: { latitude: number; longitude: number; name?: string; address?: string }) => {\n if (readOnly) return;\n\n if (onlyCoordinates) {\n const coords = {\n latitude: placeInfo.latitude,\n longitude: placeInfo.longitude\n };\n onSelect?.(coords);\n map?.onClick?.(coords);\n } else {\n onSelect?.(placeInfo);\n map?.onClick?.(placeInfo);\n }\n },\n [readOnly, onSelect, map?.onClick, onlyCoordinates]\n );\n\n const Comp = (\n <>\n <ComboBox\n as={StyledLocationInput}\n data-testid={testIds.control}\n placeholder={t('location_input_placeholder')}\n menu={\n filterValue\n ? {\n items: placePredictionMenuItems.concat([\n {\n id: createUID(),\n primary: t('use_input_value', [filterValue]),\n onClick: () => {\n setFilterValue('');\n onSelect?.({ name: filterValue });\n }\n }\n ]),\n emptyText: t('location_not_found_text'),\n mode: 'action',\n footer: !map && (\n <Flex container={{ justify: 'end' }}>\n <PoweredByGoogleImage />\n </Flex>\n )\n }\n : undefined\n }\n actions={\n !disabled &&\n !readOnly && (\n <CurrentLocationButton\n onError={onError}\n onResolve={resolved => {\n if (onlyCoordinates) {\n onSelect?.({ latitude: resolved.latitude, longitude: resolved.longitude });\n } else {\n onSelect?.(resolved);\n }\n }}\n />\n )\n }\n onChange={onInputChange}\n onBlur={() => {\n setFilterValue('');\n onBlur?.(value);\n }}\n value={value}\n required={required}\n disabled={disabled}\n readOnly={readOnly}\n status={status}\n {...restProps}\n />\n {map && (\n <StyledLocationMap>\n <LocationView\n {...map}\n pins={map.location ? [{ ...map.location }] : []}\n onClick={onMapClick}\n onError={onError}\n disabled={disabled}\n loading={mapLoading}\n centerMapOnChange\n />\n </StyledLocationMap>\n )}\n </>\n );\n\n return label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n status={status}\n ref={ref}\n required={required}\n disabled={disabled}\n additionalInfo={additionalInfo}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n});\n\nexport default withTestIds(LocationInput, getLocationInputTestIds);\n"]}
@@ -1,19 +1,18 @@
1
1
  import type { FC } from 'react';
2
2
  import type { BaseProps } from '../../types';
3
- import type { LatLng } from './types';
4
- import type BaseLocationProps from './Location.types';
3
+ import type { LatLng, Pin } from './Location.types';
5
4
  export declare const StyledLocationError: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<Omit<import("../Badges").StatusProps, "ref"> & import("react").RefAttributes<HTMLSpanElement>> & {
6
5
  getTestIds: (testIdProp?: string | undefined) => import("../../types").TestIdsRecord<readonly []>;
7
6
  }, import("styled-components").DefaultTheme, {}, never>;
8
7
  export declare const StyledLocationView: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {
9
8
  height?: string | undefined;
10
9
  }, never>;
11
- export interface LocationViewProps extends BaseLocationProps, BaseProps {
10
+ export interface LocationViewProps extends BaseProps {
12
11
  /**
13
- * Location string as either coordinates, name of a place, or 'current' for the current location.
14
- * @default 'current'
12
+ * Array of location objects.
13
+ * @default []
15
14
  */
16
- location?: LatLng | string | 'current';
15
+ pins?: Pin[];
17
16
  /**
18
17
  * Set to true to always center the map when the selected location changes. Toggling this from false to true will re-center map on the last pinned location.
19
18
  * @default false
@@ -30,10 +29,21 @@ export interface LocationViewProps extends BaseLocationProps, BaseProps {
30
29
  */
31
30
  zoomLevel?: number;
32
31
  /** Callback fired when user clicks on a location on the map. This function will be passed the coordinates of the location that was clicked. */
33
- onClick?: (coords: LatLng & {
32
+ onClick?: (locationData: LatLng & {
34
33
  name?: string;
35
34
  address?: string;
36
35
  }) => void;
36
+ /**
37
+ * Renders loading indicator when true. Informs the user location resolution is in progress.
38
+ */
39
+ loading?: boolean;
40
+ /**
41
+ * Disables dragging and clicking when true.
42
+ * @default false
43
+ */
44
+ disabled?: boolean;
45
+ /** Callback fired when an error occurs. This function gets called with one argument of type Error. */
46
+ onError?: (error: Error) => void;
37
47
  }
38
48
  declare const LocationView: FC<LocationViewProps>;
39
49
  export default LocationView;
@@ -1 +1 @@
1
- {"version":3,"file":"LocationView.d.ts","sourceRoot":"","sources":["../../../src/components/Location/LocationView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAO,MAAM,OAAO,CAAC;AAGrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAStC,OAAO,KAAK,iBAAiB,MAAM,kBAAkB,CAAC;AAGtD,eAAO,MAAM,mBAAmB;;uDAK/B,CAAC;AAIF,eAAO,MAAM,kBAAkB;;S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AE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,KACE,IAAI,CAAC;IACV;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,sGAAsG;IACtG,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAeD,QAAA,MAAM,YAAY,EAAE,EAAE,CAAC,iBAAiB,CA8HvC,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -4,7 +4,7 @@ import styled, { css } from 'styled-components';
4
4
  import { defaultThemeProp } from '../../theme';
5
5
  import Progress from '../Progress';
6
6
  import { Status } from '../Badges';
7
- import { loadMapsAPI, getCoords, toGoogleLatLng, getPlaceById, isLatLngObject, getAddress } from './utils';
7
+ import { loadMapsAPI, toGoogleLatLng, getPlaceById, isLatLngObject, getAddress } from './utils';
8
8
  import MapsContext from './MapsContext';
9
9
  export const StyledLocationError = styled(Status) `
10
10
  position: absolute;
@@ -25,7 +25,7 @@ export const StyledLocationView = styled.div(props => {
25
25
  `;
26
26
  });
27
27
  StyledLocationView.defaultProps = defaultThemeProp;
28
- const StyledMap = styled.div(({ height, disabled, status, eMessage, theme: { base: { 'disabled-opacity': disabledOpacity } } }) => {
28
+ const StyledMap = styled.div(({ height, disabled, status, theme: { base: { 'disabled-opacity': disabledOpacity } } }) => {
29
29
  return css `
30
30
  height: ${height};
31
31
  ${disabled &&
@@ -33,7 +33,6 @@ const StyledMap = styled.div(({ height, disabled, status, eMessage, theme: { bas
33
33
  opacity: ${disabledOpacity};
34
34
  `}
35
35
  ${status === 'error' &&
36
- eMessage &&
37
36
  css `
38
37
  opacity: ${disabledOpacity};
39
38
  `}
@@ -49,14 +48,16 @@ var LoadStatus;
49
48
  const hasPlaceId = (obj) => {
50
49
  return typeof obj === 'object' && obj.placeId && typeof obj.placeId === 'string';
51
50
  };
51
+ /* cSpell:ignore 'ABCDEFGHIJKLMNOPQRSTUVWYZ' */
52
+ const markerLabels = 'ABCDEFGHIJKLMNOPQRSTUVWYZ';
52
53
  const LocationView = (props) => {
53
- const { location = 'current', zoomLevel = 13, height = '25rem', centerMapOnChange = false, onClick, onError, disabled = false, ...restProps } = props;
54
+ const { pins = [], zoomLevel = 13, height = '25rem', centerMapOnChange = false, onClick, onError, disabled = false, loading = false, ...restProps } = props;
54
55
  const { name, ...providerOpts } = useContext(MapsContext);
55
56
  const [status, setStatus] = useState(LoadStatus.Init);
56
57
  const [eMessage, setEMessage] = useState('');
57
58
  const mapElemRef = useRef();
58
59
  const map = useRef();
59
- const marker = useRef();
60
+ const markers = useRef([]);
60
61
  const onMapClick = (e) => {
61
62
  if (!isLatLngObject(e.latLng))
62
63
  return;
@@ -88,11 +89,6 @@ const LocationView = (props) => {
88
89
  draggableCursor: 'auto',
89
90
  draggingCursor: 'move'
90
91
  });
91
- marker.current = new google.maps.Marker({
92
- map: map.current,
93
- position
94
- });
95
- marker.current?.setVisible(false);
96
92
  }
97
93
  };
98
94
  useEffect(() => {
@@ -102,10 +98,10 @@ const LocationView = (props) => {
102
98
  return () => google.maps.event.removeListener(l);
103
99
  }, [onClick, map.current]);
104
100
  useEffect(() => {
105
- let unMounted = false;
101
+ let mounted = true;
106
102
  loadMapsAPI(name, providerOpts)
107
103
  .then(() => {
108
- if (!unMounted) {
104
+ if (mounted) {
109
105
  initialize();
110
106
  setStatus(LoadStatus.Ready);
111
107
  }
@@ -116,38 +112,38 @@ const LocationView = (props) => {
116
112
  onError?.(error);
117
113
  });
118
114
  return () => {
119
- unMounted = true;
115
+ mounted = false;
120
116
  if (map.current)
121
117
  google.maps.event.clearInstanceListeners(map.current);
122
118
  };
123
119
  }, []);
124
120
  useEffect(() => {
125
- getCoords(location)
126
- .then(coords => {
127
- if (map.current) {
128
- map.current.setOptions({
129
- zoom: zoomLevel,
130
- draggable: !disabled
131
- });
132
- const googleLatLng = toGoogleLatLng(coords);
133
- marker.current?.setPosition(googleLatLng);
134
- marker.current?.setVisible(true);
135
- if (centerMapOnChange) {
136
- map.current.setCenter(googleLatLng);
137
- }
138
- if (status !== LoadStatus.Ready)
139
- setStatus(LoadStatus.Ready);
140
- }
141
- })
142
- .catch((error) => {
143
- if (status !== LoadStatus.Error)
144
- setStatus(LoadStatus.Error);
145
- marker.current?.setVisible(false);
146
- setEMessage(error.message);
147
- onError?.(error);
121
+ if (status !== LoadStatus.Ready || !map.current)
122
+ return;
123
+ const bounds = new google.maps.LatLngBounds();
124
+ markers.current = pins.map(({ latitude, longitude, title }, index) => {
125
+ const gCoords = toGoogleLatLng({ latitude, longitude });
126
+ const marker = new google.maps.Marker({
127
+ map: map.current,
128
+ position: gCoords,
129
+ label: pins.length > 1 ? markerLabels[index % markerLabels.length] : undefined,
130
+ title
131
+ });
132
+ bounds.extend(gCoords);
133
+ return marker;
148
134
  });
149
- }, [location, status, zoomLevel, disabled, centerMapOnChange, onError]);
150
- return (_jsxs(StyledLocationView, { height: height, children: [_jsx(StyledMap, { ref: mapElemRef, height: height, disabled: disabled, status: status, eMessage: eMessage, ...restProps }), status === LoadStatus.Init && _jsx(Progress, { placement: 'local' }), status === LoadStatus.Error && eMessage && (_jsx(StyledLocationError, { "aria-label": eMessage, variant: 'info', children: eMessage }))] }));
135
+ if (centerMapOnChange) {
136
+ if (pins.length === 1) {
137
+ map.current.setCenter(toGoogleLatLng(pins[0]));
138
+ map.current.setZoom(zoomLevel);
139
+ }
140
+ else if (pins.length > 1) {
141
+ map.current.fitBounds(bounds);
142
+ }
143
+ }
144
+ return () => markers.current.forEach(m => m.setMap(null));
145
+ }, [JSON.stringify(pins), status, zoomLevel, disabled, centerMapOnChange, onError]);
146
+ return (_jsxs(StyledLocationView, { height: height, children: [_jsx(StyledMap, { ref: mapElemRef, height: height, disabled: disabled, status: status, ...restProps }), (status === LoadStatus.Init || loading) && _jsx(Progress, { placement: 'local' }), status === LoadStatus.Error && eMessage && (_jsx(StyledLocationError, { "aria-label": eMessage, variant: 'info', children: eMessage }))] }));
151
147
  };
152
148
  export default LocationView;
153
149
  //# sourceMappingURL=LocationView.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LocationView.js","sourceRoot":"","sources":["../../../src/components/Location/LocationView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEhE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAGnC,OAAO,EACL,WAAW,EACX,SAAS,EACT,cAAc,EACd,YAAY,EACZ,cAAc,EACd,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;;CAKhD,CAAC;AAEF,mBAAmB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAsB,KAAK,CAAC,EAAE;IACxE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAEhC,OAAO,GAAG,CAAA;cACE,MAAM;;;qBAGC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC;;;GAG7C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAkB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEnD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAM1B,CAAC,EACC,MAAM,EACN,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,kBAAkB,EAAE,eAAe,EAAE,EAC9C,EACF,EAA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,KAAC,QAAQ,IAAC,SAAS,EAAC,OAAO,GAAG,EAC5D,MAAM,KAAK,UAAU,CAAC,KAAK,IAAI,QAAQ,IAAI,CAC1C,KAAC,mBAAmB,kBAAa,QAAQ,EAAE,OAAO,EAAC,MAAM,YACtD,QAAQ,GACW,CACvB,IACkB,CACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useContext, useRef, useState, useEffect } from 'react';\nimport type { FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Progress from '../Progress';\nimport { Status } from '../Badges';\n\nimport type { LatLng } from './types';\nimport {\n loadMapsAPI,\n getCoords,\n toGoogleLatLng,\n getPlaceById,\n isLatLngObject,\n getAddress\n} from './utils';\nimport type BaseLocationProps from './Location.types';\nimport MapsContext from './MapsContext';\n\nexport const StyledLocationError = styled(Status)`\n position: absolute;\n top: 40%;\n left: 50%;\n transform: translate(-50%, -50%);\n`;\n\nStyledLocationError.defaultProps = defaultThemeProp;\n\nexport const StyledLocationView = styled.div<{ height?: string }>(props => {\n const { height, theme } = props;\n\n return css`\n height: ${height};\n position: relative;\n flex: auto;\n border-radius: ${theme.base['border-radius']};\n mask-image: radial-gradient(white, black);\n -webkit-mask-image: radial-gradient(white, black);\n `;\n});\n\nStyledLocationView.defaultProps = defaultThemeProp;\n\nconst StyledMap = styled.div<{\n height?: string;\n status: string;\n disabled: boolean;\n eMessage: string;\n}>(\n ({\n height,\n disabled,\n status,\n eMessage,\n theme: {\n base: { 'disabled-opacity': disabledOpacity }\n }\n }) => {\n return css`\n height: ${height};\n ${disabled &&\n css`\n opacity: ${disabledOpacity};\n `}\n ${status === 'error' &&\n eMessage &&\n css`\n opacity: ${disabledOpacity};\n `}\n `;\n }\n);\n\nStyledMap.defaultProps = defaultThemeProp;\n\nexport interface LocationViewProps extends BaseLocationProps, BaseProps {\n /**\n * Location string as either coordinates, name of a place, or 'current' for the current location.\n * @default 'current'\n */\n location?: LatLng | string | 'current';\n\n /**\n * Set to true to always center the map when the selected location changes. Toggling this from false to true will re-center map on the last pinned location.\n * @default false\n */\n centerMapOnChange?: boolean;\n /**\n * Height of the map container.\n * @default '25rem'\n */\n height?: string;\n /**\n * How much the map should zoom.\n * @default 13\n */\n zoomLevel?: number;\n /** Callback fired when user clicks on a location on the map. This function will be passed the coordinates of the location that was clicked. */\n onClick?: (\n coords: LatLng & {\n name?: string;\n address?: string;\n }\n ) => void;\n}\n\nenum LoadStatus {\n Init = 'init',\n Ready = 'ready',\n Error = 'error'\n}\n\nconst hasPlaceId = (obj: any): obj is google.maps.IconMouseEvent & { placeId: string } => {\n return typeof obj === 'object' && obj.placeId && typeof obj.placeId === 'string';\n};\n\nconst LocationView: FC<LocationViewProps> = (props: LocationViewProps) => {\n const {\n location = 'current',\n zoomLevel = 13,\n height = '25rem',\n centerMapOnChange = false,\n onClick,\n onError,\n disabled = false,\n ...restProps\n } = props;\n const { name, ...providerOpts } = useContext(MapsContext);\n const [status, setStatus] = useState<LoadStatus>(LoadStatus.Init);\n const [eMessage, setEMessage] = useState('');\n const mapElemRef = useRef<HTMLDivElement>();\n const map = useRef<google.maps.Map>();\n const marker = useRef<google.maps.Marker>();\n\n const onMapClick = (e: google.maps.MapMouseEvent) => {\n if (!isLatLngObject(e.latLng)) return;\n\n if (hasPlaceId(e)) {\n getPlaceById(e.placeId).then(placeInfo => {\n onClick?.({\n ...placeInfo,\n latitude: e.latLng!.lat(),\n longitude: e.latLng!.lng()\n });\n });\n } else {\n getAddress({\n latitude: e.latLng.lat(),\n longitude: e.latLng.lng()\n })\n .then(onClick)\n .catch(err => onError?.(err));\n }\n };\n\n const initialize = () => {\n if (mapElemRef.current) {\n const position = toGoogleLatLng({ latitude: 0, longitude: 0 });\n map.current = new google.maps.Map(mapElemRef.current, {\n center: position,\n zoom: 2,\n draggable: !disabled,\n draggableCursor: 'auto',\n draggingCursor: 'move'\n });\n marker.current = new google.maps.Marker({\n map: map.current,\n position\n });\n marker.current?.setVisible(false);\n }\n };\n\n useEffect(() => {\n if (!onClick || !map.current) return;\n\n const l = map.current.addListener('click', onMapClick);\n return () => google.maps.event.removeListener(l);\n }, [onClick, map.current]);\n\n useEffect(() => {\n let unMounted = false;\n loadMapsAPI(name, providerOpts)\n .then(() => {\n if (!unMounted) {\n initialize();\n setStatus(LoadStatus.Ready);\n }\n })\n .catch((error: Error) => {\n setStatus(LoadStatus.Error);\n setEMessage(error.message);\n onError?.(error);\n });\n\n return () => {\n unMounted = true;\n if (map.current) google.maps.event.clearInstanceListeners(map.current);\n };\n }, []);\n\n useEffect(() => {\n getCoords(location!)\n .then(coords => {\n if (map.current) {\n map.current.setOptions({\n zoom: zoomLevel,\n draggable: !disabled\n });\n const googleLatLng = toGoogleLatLng(coords);\n\n marker.current?.setPosition(googleLatLng);\n marker.current?.setVisible(true);\n\n if (centerMapOnChange) {\n map.current.setCenter(googleLatLng);\n }\n if (status !== LoadStatus.Ready) setStatus(LoadStatus.Ready);\n }\n })\n .catch((error: Error) => {\n if (status !== LoadStatus.Error) setStatus(LoadStatus.Error);\n marker.current?.setVisible(false);\n setEMessage(error.message);\n onError?.(error);\n });\n }, [location, status, zoomLevel, disabled, centerMapOnChange, onError]);\n\n return (\n <StyledLocationView height={height}>\n <StyledMap\n ref={mapElemRef as Ref<HTMLDivElement>}\n height={height}\n disabled={disabled}\n status={status}\n eMessage={eMessage}\n {...restProps}\n />\n {status === LoadStatus.Init && <Progress placement='local' />}\n {status === LoadStatus.Error && eMessage && (\n <StyledLocationError aria-label={eMessage} variant='info'>\n {eMessage}\n </StyledLocationError>\n )}\n </StyledLocationView>\n );\n};\n\nexport default LocationView;\n"]}
1
+ {"version":3,"file":"LocationView.js","sourceRoot":"","sources":["../../../src/components/Location/LocationView.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAA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OAAO,GAAG,EACzE,MAAM,KAAK,UAAU,CAAC,KAAK,IAAI,QAAQ,IAAI,CAC1C,KAAC,mBAAmB,kBAAa,QAAQ,EAAE,OAAO,EAAC,MAAM,YACtD,QAAQ,GACW,CACvB,IACkB,CACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useContext, useRef, useState, useEffect } from 'react';\nimport type { FC, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type { BaseProps } from '../../types';\nimport { defaultThemeProp } from '../../theme';\nimport Progress from '../Progress';\nimport { Status } from '../Badges';\n\nimport type { LatLng, Pin } from './Location.types';\nimport { loadMapsAPI, toGoogleLatLng, getPlaceById, isLatLngObject, getAddress } from './utils';\nimport MapsContext from './MapsContext';\n\nexport const StyledLocationError = styled(Status)`\n position: absolute;\n top: 40%;\n left: 50%;\n transform: translate(-50%, -50%);\n`;\n\nStyledLocationError.defaultProps = defaultThemeProp;\n\nexport const StyledLocationView = styled.div<{ height?: string }>(props => {\n const { height, theme } = props;\n\n return css`\n height: ${height};\n position: relative;\n flex: auto;\n border-radius: ${theme.base['border-radius']};\n mask-image: radial-gradient(white, black);\n -webkit-mask-image: radial-gradient(white, black);\n `;\n});\n\nStyledLocationView.defaultProps = defaultThemeProp;\n\nconst StyledMap = styled.div<{\n height?: string;\n status: string;\n disabled: boolean;\n}>(\n ({\n height,\n disabled,\n status,\n theme: {\n base: { 'disabled-opacity': disabledOpacity }\n }\n }) => {\n return css`\n height: ${height};\n ${disabled &&\n css`\n opacity: ${disabledOpacity};\n `}\n ${status === 'error' &&\n css`\n opacity: ${disabledOpacity};\n `}\n `;\n }\n);\n\nStyledMap.defaultProps = defaultThemeProp;\n\nexport interface LocationViewProps extends BaseProps {\n /**\n * Array of location objects.\n * @default []\n */\n pins?: Pin[];\n /**\n * Set to true to always center the map when the selected location changes. Toggling this from false to true will re-center map on the last pinned location.\n * @default false\n */\n centerMapOnChange?: boolean;\n /**\n * Height of the map container.\n * @default '25rem'\n */\n height?: string;\n /**\n * How much the map should zoom.\n * @default 13\n */\n zoomLevel?: number;\n /** Callback fired when user clicks on a location on the map. This function will be passed the coordinates of the location that was clicked. */\n onClick?: (\n locationData: LatLng & {\n name?: string;\n address?: string;\n }\n ) => void;\n /**\n * Renders loading indicator when true. Informs the user location resolution is in progress.\n */\n loading?: boolean;\n /**\n * Disables dragging and clicking when true.\n * @default false\n */\n disabled?: boolean;\n\n /** Callback fired when an error occurs. This function gets called with one argument of type Error. */\n onError?: (error: Error) => void;\n}\n\nenum LoadStatus {\n Init = 'init',\n Ready = 'ready',\n Error = 'error'\n}\n\nconst hasPlaceId = (obj: any): obj is google.maps.IconMouseEvent & { placeId: string } => {\n return typeof obj === 'object' && obj.placeId && typeof obj.placeId === 'string';\n};\n\n/* cSpell:ignore 'ABCDEFGHIJKLMNOPQRSTUVWYZ' */\nconst markerLabels = 'ABCDEFGHIJKLMNOPQRSTUVWYZ';\n\nconst LocationView: FC<LocationViewProps> = (props: LocationViewProps) => {\n const {\n pins = [],\n zoomLevel = 13,\n height = '25rem',\n centerMapOnChange = false,\n onClick,\n onError,\n disabled = false,\n loading = false,\n ...restProps\n } = props;\n const { name, ...providerOpts } = useContext(MapsContext);\n const [status, setStatus] = useState<LoadStatus>(LoadStatus.Init);\n const [eMessage, setEMessage] = useState('');\n const mapElemRef = useRef<HTMLDivElement>();\n const map = useRef<google.maps.Map>();\n const markers = useRef<google.maps.Marker[]>([]);\n\n const onMapClick = (e: google.maps.MapMouseEvent) => {\n if (!isLatLngObject(e.latLng)) return;\n\n if (hasPlaceId(e)) {\n getPlaceById(e.placeId).then(placeInfo => {\n onClick?.({\n ...placeInfo,\n latitude: e.latLng!.lat(),\n longitude: e.latLng!.lng()\n });\n });\n } else {\n getAddress({\n latitude: e.latLng.lat(),\n longitude: e.latLng.lng()\n })\n .then(onClick)\n .catch(err => onError?.(err));\n }\n };\n\n const initialize = () => {\n if (mapElemRef.current) {\n const position = toGoogleLatLng({ latitude: 0, longitude: 0 });\n map.current = new google.maps.Map(mapElemRef.current, {\n center: position,\n zoom: 2,\n draggable: !disabled,\n draggableCursor: 'auto',\n draggingCursor: 'move'\n });\n }\n };\n\n useEffect(() => {\n if (!onClick || !map.current) return;\n\n const l = map.current.addListener('click', onMapClick);\n return () => google.maps.event.removeListener(l);\n }, [onClick, map.current]);\n\n useEffect(() => {\n let mounted = true;\n loadMapsAPI(name, providerOpts)\n .then(() => {\n if (mounted) {\n initialize();\n setStatus(LoadStatus.Ready);\n }\n })\n .catch((error: Error) => {\n setStatus(LoadStatus.Error);\n setEMessage(error.message);\n onError?.(error);\n });\n\n return () => {\n mounted = false;\n if (map.current) google.maps.event.clearInstanceListeners(map.current);\n };\n }, []);\n\n useEffect(() => {\n if (status !== LoadStatus.Ready || !map.current) return;\n\n const bounds = new google.maps.LatLngBounds();\n markers.current = pins.map(({ latitude, longitude, title }, index) => {\n const gCoords = toGoogleLatLng({ latitude, longitude });\n const marker = new google.maps.Marker({\n map: map.current,\n position: gCoords,\n label: pins.length > 1 ? markerLabels[index % markerLabels.length] : undefined,\n title\n });\n bounds.extend(gCoords);\n return marker;\n });\n\n if (centerMapOnChange) {\n if (pins.length === 1) {\n map.current.setCenter(toGoogleLatLng(pins[0]));\n map.current.setZoom(zoomLevel);\n } else if (pins.length > 1) {\n map.current.fitBounds(bounds);\n }\n }\n\n return () => markers.current.forEach(m => m.setMap(null));\n }, [JSON.stringify(pins), status, zoomLevel, disabled, centerMapOnChange, onError]);\n\n return (\n <StyledLocationView height={height}>\n <StyledMap\n ref={mapElemRef as Ref<HTMLDivElement>}\n height={height}\n disabled={disabled}\n status={status}\n {...restProps}\n />\n {(status === LoadStatus.Init || loading) && <Progress placement='local' />}\n {status === LoadStatus.Error && eMessage && (\n <StyledLocationError aria-label={eMessage} variant='info'>\n {eMessage}\n </StyledLocationError>\n )}\n </StyledLocationView>\n );\n};\n\nexport default LocationView;\n"]}
@@ -5,6 +5,6 @@ export type { LocationViewProps } from './LocationView';
5
5
  export { default as MapsContext } from './MapsContext';
6
6
  export { default as LocationDisplay } from './LocationDisplay';
7
7
  export type { LocationDisplayProps } from './LocationDisplay';
8
- export type { LatLng } from './types';
9
- export { isValueACoordinate } from './utils';
8
+ export type { LatLng, Pin } from './Location.types';
9
+ export { isValueACoordinate, getCoords } from './utils';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Location/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Location/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
@@ -2,5 +2,5 @@ export { default as LocationInput } from './LocationInput';
2
2
  export { default as LocationView } from './LocationView';
3
3
  export { default as MapsContext } from './MapsContext';
4
4
  export { default as LocationDisplay } from './LocationDisplay';
5
- export { isValueACoordinate } from './utils';
5
+ export { isValueACoordinate, getCoords } from './utils';
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Location/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export { default as LocationInput } from './LocationInput';\nexport type { LocationInputProps } from './LocationInput';\nexport { default as LocationView } from './LocationView';\nexport type { LocationViewProps } from './LocationView';\nexport { default as MapsContext } from './MapsContext';\nexport { default as LocationDisplay } from './LocationDisplay';\nexport type { LocationDisplayProps } from './LocationDisplay';\nexport type { LatLng } from './types';\nexport { isValueACoordinate } from './utils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Location/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export { default as LocationInput } from './LocationInput';\nexport type { LocationInputProps } from './LocationInput';\nexport { default as LocationView } from './LocationView';\nexport type { LocationViewProps } from './LocationView';\nexport { default as MapsContext } from './MapsContext';\nexport { default as LocationDisplay } from './LocationDisplay';\nexport type { LocationDisplayProps } from './LocationDisplay';\nexport type { LatLng, Pin } from './Location.types';\nexport { isValueACoordinate, getCoords } from './utils';\n"]}
@@ -1,5 +1,5 @@
1
1
  /// <reference types="google.maps" />
2
- import type { Bias, LatLng, ProviderOpts, Location } from './types';
2
+ import type { Bias, LatLng, ProviderOpts, Location } from './Location.types';
3
3
  export declare function loadMapsAPI(name?: string, opts?: ProviderOpts): Promise<void>;
4
4
  /**
5
5
  * Identifies coordinates in degree format
@@ -37,7 +37,7 @@ export declare function getPlacePredictions(location: string, bias?: Bias): Prom
37
37
  export declare function getPlace(location: string, mapElement?: HTMLDivElement): Promise<LatLng>;
38
38
  export declare function getPlaceById(placeId: string, sessionToken?: google.maps.places.AutocompleteSessionToken, mapElement?: HTMLDivElement): Promise<Location>;
39
39
  /** Returns coordinations for given input: either coords, address or current position. */
40
- export declare function getCoords(coords: string | LatLng, mapElement?: HTMLDivElement): Promise<LatLng>;
40
+ export declare function getCoords(coords: string | 'current' | LatLng, mapElement?: HTMLDivElement): Promise<LatLng>;
41
41
  export declare function getAddress(coords: LatLng): Promise<{
42
42
  name: string;
43
43
  address?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Location/utils.ts"],"names":[],"mappings":";AAaA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAgB,YAAY,EA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jE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,IAAS,GACd,OAAO,CAAC;IACT,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;IAC9D,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;CACpD,CAAC,CAwCD;AAED,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,GAAE,cAA8C,GACzD,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAA4E,EAC7G,UAAU,GAAE,cAA8C,GACzD,OAAO,CAAC,QAAQ,CAAC,CAgBnB;AAED,yFAAyF;AACzF,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EACnC,UAAU,CAAC,EAAE,cAAc,GAC1B,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAkClF;AAED,eAAO,MAAM,cAAc,QAAS,GAAG,8BAStC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { hasProp, loadScript } from '../../utils';
2
- import { CoordsCannotBeParsedError, GeocoderFailedError, GeolocationUnsupportedError, GoogleMapsAPINotFoundError, IsNotAnObjectError, LocationNotFoundError, ProviderNotSupportedError, QUERY_FIELDS, QUERY_TYPES } from './types';
2
+ import { CoordsCannotBeParsedError, GeocoderFailedError, GeolocationUnsupportedError, GoogleMapsAPINotFoundError, IsNotAnObjectError, LocationNotFoundError, ProviderNotSupportedError, QUERY_FIELDS, QUERY_TYPES } from './Location.types';
3
3
  const GOOGLE_MAPS_SCRIPT_ID = 'google-map';
4
4
  const DegreeRegexChunks = [
5
5
  /^[-+]?/,