@pega/cosmos-react-core 9.0.0-build.7.4 → 9.0.0-build.8.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 (38) hide show
  1. package/lib/components/ListToolbar/ListToolbar.types.d.ts +5 -1
  2. package/lib/components/ListToolbar/ListToolbar.types.d.ts.map +1 -1
  3. package/lib/components/ListToolbar/ListToolbar.types.js.map +1 -1
  4. package/lib/components/Location/CurrentLocationButton.d.ts.map +1 -1
  5. package/lib/components/Location/CurrentLocationButton.js +4 -2
  6. package/lib/components/Location/CurrentLocationButton.js.map +1 -1
  7. package/lib/components/Location/GoogleMapsAPI.d.ts +43 -0
  8. package/lib/components/Location/GoogleMapsAPI.d.ts.map +1 -0
  9. package/lib/components/Location/GoogleMapsAPI.js +244 -0
  10. package/lib/components/Location/GoogleMapsAPI.js.map +1 -0
  11. package/lib/components/Location/Location.types.d.ts +3 -2
  12. package/lib/components/Location/Location.types.d.ts.map +1 -1
  13. package/lib/components/Location/Location.types.js.map +1 -1
  14. package/lib/components/Location/LocationAPI.types.d.ts +23 -0
  15. package/lib/components/Location/LocationAPI.types.d.ts.map +1 -0
  16. package/lib/components/Location/LocationAPI.types.js +2 -0
  17. package/lib/components/Location/LocationAPI.types.js.map +1 -0
  18. package/lib/components/Location/LocationDisplay.d.ts.map +1 -1
  19. package/lib/components/Location/LocationDisplay.js +5 -3
  20. package/lib/components/Location/LocationDisplay.js.map +1 -1
  21. package/lib/components/Location/LocationInput.d.ts.map +1 -1
  22. package/lib/components/Location/LocationInput.js +23 -20
  23. package/lib/components/Location/LocationInput.js.map +1 -1
  24. package/lib/components/Location/LocationView.d.ts.map +1 -1
  25. package/lib/components/Location/LocationView.js +8 -5
  26. package/lib/components/Location/LocationView.js.map +1 -1
  27. package/lib/components/Location/index.d.ts +2 -1
  28. package/lib/components/Location/index.d.ts.map +1 -1
  29. package/lib/components/Location/index.js +2 -1
  30. package/lib/components/Location/index.js.map +1 -1
  31. package/lib/components/Location/utils.d.ts +3 -19
  32. package/lib/components/Location/utils.d.ts.map +1 -1
  33. package/lib/components/Location/utils.js +7 -161
  34. package/lib/components/Location/utils.js.map +1 -1
  35. package/lib/styles/GlobalStyle.d.ts.map +1 -1
  36. package/lib/styles/GlobalStyle.js +3 -0
  37. package/lib/styles/GlobalStyle.js.map +1 -1
  38. package/package.json +2 -2
@@ -101,13 +101,17 @@ export interface ListToolbarProps extends BaseProps, TestIdProp {
101
101
  search?: SearchInputProps;
102
102
  /** Total returned results related for a given search. Optional indication of a selected item count. */
103
103
  count?: {
104
- total?: number;
104
+ total: number;
105
105
  /**
106
106
  * If true renders + next to total number.
107
107
  * @default false
108
108
  */
109
109
  totalHasMore?: boolean;
110
110
  selected?: number;
111
+ } | {
112
+ selected: number;
113
+ total?: never;
114
+ totalHasMore?: never;
111
115
  };
112
116
  /** Additional actions region */
113
117
  additionalActions?: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"ListToolbar.types.d.ts","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,+BAA+B;IAC/B,IAAI,EAAE,MAAM,C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AE,MAAM,CAAC;KACnB,CAAC;IACF,gCAAgC;IAChC,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IAClD,yDAAyD;IACzD,IAAI,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IAChD,0DAA0D;IAC1D,KAAK,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IACjD,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,0CAA0C;IAC1C,gBAAgB,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
1
+ {"version":3,"file":"ListToolbar.types.d.ts","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,UAAU,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,EAAE,EAAE,MAAM,CAAC;IACX,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;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,EAAE,KAAK,CAAC;KACtB,CAAC;IACN,gCAAgC;IAChC,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,2DAA2D;IAC3D,MAAM,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IAClD,yDAAyD;IACzD,IAAI,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IAChD,0DAA0D;IAC1D,KAAK,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAAC;IACjD,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,0CAA0C;IAC1C,gBAAgB,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"ListToolbar.types.js","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MouseEvent, Ref, ComponentType, ReactNode } from 'react';\n\nimport type { SearchInputProps } from '../SearchInput';\nimport type { MenuGroupProps, MenuProps } from '../Menu';\nimport type {\n Action,\n BaseProps,\n DeferInfer,\n ExcludeStrict,\n HeadingTag,\n TestIdProp\n} from '../../types';\nimport type { AvatarProps } from '../Avatar';\nimport type { FormControlProps } from '../FormControl';\n\nexport interface ViewProps {\n /** Unique, stable identifier of this view. */\n id: string;\n /** Label text of this view. */\n text: string;\n /** Flag indicating whether this view is currently selected. */\n selected: boolean;\n /** A count to assist with number of associated items. */\n count?: number;\n /** A visual to assist identifying an item. */\n visual?: Pick<AvatarProps, 'name' | 'icon' | 'imageSrc' | 'status'>;\n}\n\nexport interface ViewGroupProps {\n /** Label text of the group. */\n text: MenuGroupProps['label'];\n /** Array of items belonging to the group. */\n items: ViewProps[];\n}\n\nexport interface ViewSelectorProps {\n /** A list of pre-defined data views. */\n views: (ViewProps | ViewGroupProps)[];\n /** Called when a view is selected. */\n onViewSelect: MenuProps['onItemClick'];\n /** Determines which view is the default. */\n defaultId?: string;\n /** Determines which view is the default in the app. */\n appDefaultId?: string;\n}\n\nexport interface QueryOption {\n /** A count representing the number of applied conditions within the query option. */\n count?: number;\n}\n\nexport interface QueryOptionDialogProps<P extends object = any> extends QueryOption {\n /** A component to render the content portion of the query option dialog. */\n renderer: ComponentType<P>;\n /**\n * A props object that will be passed to the content renderer.\n */\n rendererProps?: DeferInfer<P>;\n /**\n * Called when the user explicitly or implicitly cancels(closes) the query dialog.\n * Returning false will block the dialog from closing.\n */\n onCancel: () => boolean | void;\n /**\n * Called when the user explicitly applies the query option conditions.\n * Returning false will block the dialog from closing.\n */\n onSubmit: () => boolean | void;\n}\n\n/** Optionally provide query option presets. */\nexport interface PresetMenuProps extends QueryOption {\n /** Mode defining whether menu selection is single or multi mode. */\n mode?: ExcludeStrict<MenuProps['mode'], 'action'>;\n /** Items of the menu. */\n items: { id: string; text: string; selected: boolean; icon?: string }[];\n /** Callback invoked on item selection. Passes the item id as an argument. */\n onItemClick: MenuProps['onItemClick'];\n}\nexport type QueryOptionId = 'filter' | 'sort' | 'group';\n\nexport interface ListToolbarProps extends BaseProps, TestIdProp {\n /** Renders a simple text name of table */\n name: string;\n /**\n * Uses specific heading tag for header.\n * @default h3\n */\n headingTag?: HeadingTag;\n /** Renders a simple view heading text or view selection menu. */\n viewSelector?: ViewSelectorProps;\n /** Props related to list used as a form control. */\n formControlProps?: Pick<FormControlProps, 'required' | 'additionalInfo' | 'info' | 'status'>;\n /** Props related to new item creation button. */\n createNew?: {\n /** Label of the new item creation button. */\n label?: string;\n /** Callback that will render a Create new button and is fired when that button is clicked. */\n onClick: (e: MouseEvent) => void;\n };\n /** Props related to keyboard instructions. */\n keyboardInstructions?: ReactNode;\n /** Props related to wrap button. */\n wrap?: {\n /** value which holds the status of the wrap */\n enabled?: boolean;\n /** Callback that will fire to wrap the content when that button is clicked. */\n onClick: (e: MouseEvent) => void;\n };\n /** Props related to the Search Input. */\n search?: SearchInputProps;\n /** Total returned results related for a given search. Optional indication of a selected item count. */\n count?: {\n total?: number;\n /**\n * If true renders + next to total number.\n * @default false\n */\n totalHasMore?: boolean;\n selected?: number;\n };\n /** Additional actions region */\n additionalActions?: ReactNode;\n /** Custom Rendering or available presets for filtering. */\n filter?: QueryOptionDialogProps | PresetMenuProps;\n /** Custom Rendering or available presets for sorting. */\n sort?: QueryOptionDialogProps | PresetMenuProps;\n /** Custom Rendering or available presets for grouping. */\n group?: QueryOptionDialogProps | PresetMenuProps;\n /** Top level dataset actions. */\n actions?: Action[];\n /** Ref for the actions button element. */\n actionsButtonRef?: Ref<HTMLButtonElement>;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
1
+ {"version":3,"file":"ListToolbar.types.js","sourceRoot":"","sources":["../../../src/components/ListToolbar/ListToolbar.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MouseEvent, Ref, ComponentType, ReactNode } from 'react';\n\nimport type { SearchInputProps } from '../SearchInput';\nimport type { MenuGroupProps, MenuProps } from '../Menu';\nimport type {\n Action,\n BaseProps,\n DeferInfer,\n ExcludeStrict,\n HeadingTag,\n TestIdProp\n} from '../../types';\nimport type { AvatarProps } from '../Avatar';\nimport type { FormControlProps } from '../FormControl';\n\nexport interface ViewProps {\n /** Unique, stable identifier of this view. */\n id: string;\n /** Label text of this view. */\n text: string;\n /** Flag indicating whether this view is currently selected. */\n selected: boolean;\n /** A count to assist with number of associated items. */\n count?: number;\n /** A visual to assist identifying an item. */\n visual?: Pick<AvatarProps, 'name' | 'icon' | 'imageSrc' | 'status'>;\n}\n\nexport interface ViewGroupProps {\n /** Label text of the group. */\n text: MenuGroupProps['label'];\n /** Array of items belonging to the group. */\n items: ViewProps[];\n}\n\nexport interface ViewSelectorProps {\n /** A list of pre-defined data views. */\n views: (ViewProps | ViewGroupProps)[];\n /** Called when a view is selected. */\n onViewSelect: MenuProps['onItemClick'];\n /** Determines which view is the default. */\n defaultId?: string;\n /** Determines which view is the default in the app. */\n appDefaultId?: string;\n}\n\nexport interface QueryOption {\n /** A count representing the number of applied conditions within the query option. */\n count?: number;\n}\n\nexport interface QueryOptionDialogProps<P extends object = any> extends QueryOption {\n /** A component to render the content portion of the query option dialog. */\n renderer: ComponentType<P>;\n /**\n * A props object that will be passed to the content renderer.\n */\n rendererProps?: DeferInfer<P>;\n /**\n * Called when the user explicitly or implicitly cancels(closes) the query dialog.\n * Returning false will block the dialog from closing.\n */\n onCancel: () => boolean | void;\n /**\n * Called when the user explicitly applies the query option conditions.\n * Returning false will block the dialog from closing.\n */\n onSubmit: () => boolean | void;\n}\n\n/** Optionally provide query option presets. */\nexport interface PresetMenuProps extends QueryOption {\n /** Mode defining whether menu selection is single or multi mode. */\n mode?: ExcludeStrict<MenuProps['mode'], 'action'>;\n /** Items of the menu. */\n items: { id: string; text: string; selected: boolean; icon?: string }[];\n /** Callback invoked on item selection. Passes the item id as an argument. */\n onItemClick: MenuProps['onItemClick'];\n}\n\nexport type QueryOptionId = 'filter' | 'sort' | 'group';\n\nexport interface ListToolbarProps extends BaseProps, TestIdProp {\n /** Renders a simple text name of table */\n name: string;\n /**\n * Uses specific heading tag for header.\n * @default h3\n */\n headingTag?: HeadingTag;\n /** Renders a simple view heading text or view selection menu. */\n viewSelector?: ViewSelectorProps;\n /** Props related to list used as a form control. */\n formControlProps?: Pick<FormControlProps, 'required' | 'additionalInfo' | 'info' | 'status'>;\n /** Props related to new item creation button. */\n createNew?: {\n /** Label of the new item creation button. */\n label?: string;\n /** Callback that will render a Create new button and is fired when that button is clicked. */\n onClick: (e: MouseEvent) => void;\n };\n /** Props related to keyboard instructions. */\n keyboardInstructions?: ReactNode;\n /** Props related to wrap button. */\n wrap?: {\n /** value which holds the status of the wrap */\n enabled?: boolean;\n /** Callback that will fire to wrap the content when that button is clicked. */\n onClick: (e: MouseEvent) => void;\n };\n /** Props related to the Search Input. */\n search?: SearchInputProps;\n /** Total returned results related for a given search. Optional indication of a selected item count. */\n count?:\n | {\n total: number;\n /**\n * If true renders + next to total number.\n * @default false\n */\n totalHasMore?: boolean;\n selected?: number;\n }\n | {\n selected: number;\n total?: never;\n totalHasMore?: never;\n };\n /** Additional actions region */\n additionalActions?: ReactNode;\n /** Custom Rendering or available presets for filtering. */\n filter?: QueryOptionDialogProps | PresetMenuProps;\n /** Custom Rendering or available presets for sorting. */\n sort?: QueryOptionDialogProps | PresetMenuProps;\n /** Custom Rendering or available presets for grouping. */\n group?: QueryOptionDialogProps | PresetMenuProps;\n /** Top level dataset actions. */\n actions?: Action[];\n /** Ref for the actions button element. */\n actionsButtonRef?: Ref<HTMLButtonElement>;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CurrentLocationButton.d.ts","sourceRoot":"","sources":["../../../src/components/Location/CurrentLocationButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAahC,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,aAAa,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAEhE,MAAM,MAAM,0BAA0B,GAAG;IACvC,sFAAsF;IACtF,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,QAAA,MAAM,qBAAqB,EAAE,EAAE,CAAC,0BAA0B,CAqDzD,CAAC;AACF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"CurrentLocationButton.d.ts","sourceRoot":"","sources":["../../../src/components/Location/CurrentLocationButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAahC,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,aAAa,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAEhE,MAAM,MAAM,0BAA0B,GAAG;IACvC,sFAAsF;IACtF,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,2CAA2C;IAC3C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,QAAA,MAAM,qBAAqB,EAAE,EAAE,CAAC,0BAA0B,CAuDzD,CAAC;AACF,eAAe,qBAAqB,CAAC"}
@@ -6,7 +6,7 @@ import Icon, { registerIcon } from '../Icon';
6
6
  import * as locationIcon from '../Icon/icons/location.icon';
7
7
  import Button from '../Button';
8
8
  import MapsContext from './MapsContext';
9
- import { getNavigatorPosition, getAddress, loadMapsAPI } from './utils';
9
+ import { getNavigatorPosition, loadMapsAPI } from './utils';
10
10
  registerIcon(locationIcon);
11
11
  const CurrentLocationButton = ({ onResolve, onError }) => {
12
12
  const t = useI18n();
@@ -21,7 +21,9 @@ const CurrentLocationButton = ({ onResolve, onError }) => {
21
21
  setCurrentLocationDisabled(true);
22
22
  throw error;
23
23
  })
24
- .then(([navigatorPosition]) => getAddress(navigatorPosition))
24
+ .then(([navigatorPosition, mapAPIObj]) => {
25
+ return mapAPIObj.getAddress(navigatorPosition);
26
+ })
25
27
  .then(address => {
26
28
  onResolve?.(address);
27
29
  })
@@ -1 +1 @@
1
- {"version":3,"file":"CurrentLocationButton.js","sourceRoot":"","sources":["../../../src/components/Location/CurrentLocationButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGrE,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE,YAAY,CAAC,YAAY,CAAC,CAAC;AAuB3B,MAAM,qBAAqB,GAAmC,CAAC,EAC7D,SAAS,EACT,OAAO,EACoB,EAAE,EAAE;IAC/B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,CAAC,uBAAuB,EAAE,0BAA0B,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,UAAU,EAAE,CAAC;IAEjC,MAAM,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,CAAC,GAAG,CAAC,CAAC,oBAAoB,EAAE,EAAE,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC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ACJ,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,qBAAqB,CAAC","sourcesContent":["import { useCallback, useContext, useEffect, useState } from 'react';\nimport type { FC } from 'react';\n\nimport Tooltip from '../Tooltip';\nimport { useElement, useI18n } from '../../hooks';\nimport Icon, { registerIcon } from '../Icon';\nimport * as locationIcon from '../Icon/icons/location.icon';\nimport Button from '../Button';\n\nimport MapsContext from './MapsContext';\nimport { getNavigatorPosition, getAddress, loadMapsAPI } from './utils';\n\nregisterIcon(locationIcon);\n\ninterface OnChangeAddressValue {\n name: string;\n address?: string;\n latitude?: number;\n longitude?: number;\n}\n\ninterface OnChangeCoordsValue {\n latitude: number;\n longitude: number;\n}\n\ntype OnChangeValue = OnChangeAddressValue | OnChangeCoordsValue;\n\nexport type CurrentLocationButtonProps = {\n /** Callback fired after click on my current location button if location was found. */\n onResolve?: (value: OnChangeValue) => void;\n /** Callback fired when an error occurs. */\n onError?: (error: Error) => void;\n};\n\nconst CurrentLocationButton: FC<CurrentLocationButtonProps> = ({\n onResolve,\n onError\n}: CurrentLocationButtonProps) => {\n const t = useI18n();\n const { name, ...providerOpts } = useContext(MapsContext);\n const [currentLocationDisabled, setCurrentLocationDisabled] = useState(false);\n const [busy, setBusy] = useState(false);\n const [el, setEl] = useElement();\n\n const getCurrentLocation = useCallback(() => {\n setBusy(true);\n Promise.all([getNavigatorPosition(), loadMapsAPI(name, providerOpts)])\n .catch(error => {\n setCurrentLocationDisabled(true);\n throw error;\n })\n .then(([navigatorPosition]) => getAddress(navigatorPosition))\n .then(address => {\n onResolve?.(address);\n })\n .catch(error => onError?.(error))\n .finally(() => setBusy(false));\n }, [onResolve, onError]);\n\n useEffect(() => {\n navigator.permissions?.query({ name: 'geolocation' }).then(result => {\n if (result.state === 'denied') {\n setCurrentLocationDisabled(true);\n }\n });\n }, []);\n\n return (\n <>\n <Button\n ref={setEl}\n variant='simple'\n icon\n onClick={getCurrentLocation}\n aria-label={t('my_current_location_button_a11y')}\n disabled={currentLocationDisabled}\n loading={busy}\n >\n <Icon name='location' />\n </Button>\n {el && currentLocationDisabled && (\n <Tooltip shown target={el}>\n {t('allow_location_permissions_text')}\n </Tooltip>\n )}\n </>\n );\n};\nexport default CurrentLocationButton;\n"]}
1
+ {"version":3,"file":"CurrentLocationButton.js","sourceRoot":"","sources":["../../../src/components/Location/CurrentLocationButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGrE,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAC;AAC5D,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE5D,YAAY,CAAC,YAAY,CAAC,CAAC;AAuB3B,MAAM,qBAAqB,GAAmC,CAAC,EAC7D,SAAS,EACT,OAAO,EACoB,EAAE,EAAE;IAC/B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IACpB,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,CAAC,uBAAuB,EAAE,0BAA0B,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9E,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,GAAG,UAAU,EAAE,CAAC;IAEjC,MAAM,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC1C,OAAO,CAAC,IAAI,CAAC,CAAC;QAC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R,EAAE,IAAI,uBAAuB,IAAI,CAChC,KAAC,OAAO,IAAC,KAAK,QAAC,MAAM,EAAE,EAAE,YACtB,CAAC,CAAC,iCAAiC,CAAC,GAC7B,CACX,IACA,CACJ,CAAC;AACJ,CAAC,CAAC;AACF,eAAe,qBAAqB,CAAC","sourcesContent":["import { useCallback, useContext, useEffect, useState } from 'react';\nimport type { FC } from 'react';\n\nimport Tooltip from '../Tooltip';\nimport { useElement, useI18n } from '../../hooks';\nimport Icon, { registerIcon } from '../Icon';\nimport * as locationIcon from '../Icon/icons/location.icon';\nimport Button from '../Button';\n\nimport MapsContext from './MapsContext';\nimport { getNavigatorPosition, loadMapsAPI } from './utils';\n\nregisterIcon(locationIcon);\n\ninterface OnChangeAddressValue {\n name: string;\n address?: string;\n latitude?: number;\n longitude?: number;\n}\n\ninterface OnChangeCoordsValue {\n latitude: number;\n longitude: number;\n}\n\ntype OnChangeValue = OnChangeAddressValue | OnChangeCoordsValue;\n\nexport type CurrentLocationButtonProps = {\n /** Callback fired after click on my current location button if location was found. */\n onResolve?: (value: OnChangeValue) => void;\n /** Callback fired when an error occurs. */\n onError?: (error: Error) => void;\n};\n\nconst CurrentLocationButton: FC<CurrentLocationButtonProps> = ({\n onResolve,\n onError\n}: CurrentLocationButtonProps) => {\n const t = useI18n();\n const { name, ...providerOpts } = useContext(MapsContext);\n const [currentLocationDisabled, setCurrentLocationDisabled] = useState(false);\n const [busy, setBusy] = useState(false);\n const [el, setEl] = useElement();\n\n const getCurrentLocation = useCallback(() => {\n setBusy(true);\n Promise.all([getNavigatorPosition(), loadMapsAPI(name, providerOpts)])\n .catch(error => {\n setCurrentLocationDisabled(true);\n throw error;\n })\n .then(([navigatorPosition, mapAPIObj]) => {\n return mapAPIObj.getAddress(navigatorPosition);\n })\n .then(address => {\n onResolve?.(address);\n })\n .catch(error => onError?.(error))\n .finally(() => setBusy(false));\n }, [onResolve, onError]);\n\n useEffect(() => {\n navigator.permissions?.query({ name: 'geolocation' }).then(result => {\n if (result.state === 'denied') {\n setCurrentLocationDisabled(true);\n }\n });\n }, []);\n\n return (\n <>\n <Button\n ref={setEl}\n variant='simple'\n icon\n onClick={getCurrentLocation}\n aria-label={t('my_current_location_button_a11y')}\n disabled={currentLocationDisabled}\n loading={busy}\n >\n <Icon name='location' />\n </Button>\n {el && currentLocationDisabled && (\n <Tooltip shown target={el}>\n {t('allow_location_permissions_text')}\n </Tooltip>\n )}\n </>\n );\n};\nexport default CurrentLocationButton;\n"]}
@@ -0,0 +1,43 @@
1
+ import { type Bias, type LatLng, type Location } from './Location.types';
2
+ import type { LocationAPI } from './LocationAPI.types';
3
+ export default class GoogleMapsAPI implements LocationAPI {
4
+ private version;
5
+ /** Returns coordinations for given input: either coords, address or current position. */
6
+ getCoords: (coords: string | "current" | LatLng, mapElement?: HTMLDivElement) => Promise<LatLng>;
7
+ getPlace: (location: string, mapElement?: HTMLDivElement) => Promise<LatLng>;
8
+ getPlaceById: (placeId: string, sessionToken?: google.maps.places.AutocompleteSessionToken, mapElement?: HTMLDivElement) => Promise<Location>;
9
+ getAddress: (coords: LatLng) => Promise<{
10
+ name: string;
11
+ address?: string;
12
+ latitude: number;
13
+ longitude: number;
14
+ }>;
15
+ getPlacePredictionsUtil: (location: string, bias?: Bias) => Promise<{
16
+ placeSuggestions: {
17
+ placeId: string;
18
+ mainText: string;
19
+ secondaryText: string;
20
+ }[];
21
+ token: google.maps.places.AutocompleteSessionToken;
22
+ }>;
23
+ getPlaceSuggestionsUtil: (location: string, bias?: Bias) => Promise<{
24
+ placeSuggestions: {
25
+ placeId: string;
26
+ mainText: string;
27
+ secondaryText: string;
28
+ }[];
29
+ token: google.maps.places.AutocompleteSessionToken;
30
+ }>;
31
+ /** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)
32
+ * and session token (valid for multiple queries, followed by one place selection).
33
+ */
34
+ getPlacePredictions: (location: string, bias?: Bias) => Promise<{
35
+ placeSuggestions: {
36
+ placeId: string;
37
+ mainText: string;
38
+ secondaryText: string;
39
+ }[];
40
+ token: google.maps.places.AutocompleteSessionToken;
41
+ }>;
42
+ }
43
+ //# sourceMappingURL=GoogleMapsAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsAPI.d.ts","sourceRoot":"","sources":["../../../src/components/Location/GoogleMapsAPI.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,IAAI,EACT,KAAK,MAAM,EACX,KAAK,QAAQ,EACd,MAAM,kBAAkB,CAAC;AAS1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,WAAW;IACvD,OAAO,CAAC,OAAO,CAAqB;IAEpC,yFAAyF;IACzF,SAAS,GACP,QAAQ,MAAM,GAAG,SAAS,GAAG,MAAM,EACnC,aAAa,cAAc,KAC1B,OAAO,CAAC,MAAM,CAAC,CAuChB;IAEF,QAAQ,GACN,UAAU,MAAM,EAChB,aAAY,cAA8C,KACzD,OAAO,CAAC,MAAM,CAAC,CAsBhB;IAEF,YAAY,GACV,SAAS,MAAM,EACf,eAAc,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAA4E,EAC7G,aAAY,cAA8C,KACzD,OAAO,CAAC,QAAQ,CAAC,CAmBlB;IAEF,UAAU,GACR,QAAQ,MAAM,KACb,OAAO,CAAC;QACT,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAkCA;IAEF,uBAAuB,GACrB,UAAU,MAAM,EAChB,OAAM,IAAS,KACd,OAAO,CAAC;QACT,gBAAgB,EAAE;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;YACjB,aAAa,EAAE,MAAM,CAAC;SACvB,EAAE,CAAC;QACJ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;KACpD,CAAC,CA8CA;IAEF,uBAAuB,GACrB,UAAU,MAAM,EAChB,OAAM,IAAS,KACd,OAAO,CAAC;QACT,gBAAgB,EAAE;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;YACjB,aAAa,EAAE,MAAM,CAAC;SACvB,EAAE,CAAC;QACJ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;KACpD,CAAC,CA2DA;IAEF;;OAEG;IACH,mBAAmB,GACjB,UAAU,MAAM,EAChB,OAAO,IAAI,KACV,OAAO,CAAC;QACT,gBAAgB,EAAE;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;YACjB,aAAa,EAAE,MAAM,CAAC;SACvB,EAAE,CAAC;QACJ,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;KACpD,CAAC,CAkBA;CACH"}
@@ -0,0 +1,244 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ import { CoordsCannotBeParsedError, GeocoderFailedError, LocationNotFoundError, QUERY_FIELDS, QUERY_TYPES } from './Location.types';
3
+ import { getNavigatorPosition, isValueDegreeFormatCoordinate, isValueDMCoordinate, isValueDMSCoordinate, parseDMS, toGoogleLatLng } from './utils';
4
+ export default class GoogleMapsAPI {
5
+ version = 'v2';
6
+ /** Returns coordinations for given input: either coords, address or current position. */
7
+ getCoords = async (coords, mapElement) => {
8
+ if (coords === '' || coords === undefined)
9
+ throw new Error();
10
+ if (coords === 'current')
11
+ return getNavigatorPosition();
12
+ let location;
13
+ if (typeof coords === 'string') {
14
+ let latLng = [];
15
+ if (isValueDMSCoordinate(coords) ||
16
+ isValueDMCoordinate(coords) ||
17
+ isValueDegreeFormatCoordinate(coords)) {
18
+ latLng = parseDMS(coords);
19
+ }
20
+ else {
21
+ let splitter;
22
+ if (coords.includes(', ')) {
23
+ splitter = ', ';
24
+ }
25
+ else if (coords.includes(',')) {
26
+ splitter = ',';
27
+ }
28
+ else if (coords.includes(' ')) {
29
+ splitter = ' ';
30
+ }
31
+ else {
32
+ splitter = ', ';
33
+ }
34
+ latLng = coords.split(splitter).map(Number);
35
+ }
36
+ const [lat, lng] = latLng;
37
+ if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined)
38
+ return this.getPlace(coords, mapElement);
39
+ location = { latitude: lat, longitude: lng };
40
+ }
41
+ else {
42
+ location = coords;
43
+ }
44
+ if (Number.isFinite(location.latitude) && Number.isFinite(location.longitude))
45
+ return location;
46
+ throw new Error(CoordsCannotBeParsedError);
47
+ };
48
+ getPlace = async (location, mapElement = document.createElement('div')) => {
49
+ const placesService = new google.maps.places.PlacesService(mapElement);
50
+ const { placeSuggestions, token } = await this.getPlacePredictions(location);
51
+ return new Promise((resolve, reject) => {
52
+ placesService.getDetails({
53
+ placeId: placeSuggestions[0]?.placeId,
54
+ fields: QUERY_FIELDS,
55
+ sessionToken: token
56
+ }, (place, pStatus) => {
57
+ if (pStatus === google.maps.places.PlacesServiceStatus.OK) {
58
+ resolve({
59
+ latitude: place?.geometry?.location?.lat() ?? NaN,
60
+ longitude: place?.geometry?.location?.lng() ?? NaN
61
+ });
62
+ }
63
+ else {
64
+ reject(new Error(LocationNotFoundError));
65
+ }
66
+ });
67
+ });
68
+ };
69
+ getPlaceById = async (placeId, sessionToken = new google.maps.places.AutocompleteSessionToken(), mapElement = document.createElement('div')) => {
70
+ const placesService = new google.maps.places.PlacesService(mapElement);
71
+ return new Promise((resolve, reject) => {
72
+ placesService.getDetails({ placeId, fields: QUERY_FIELDS, sessionToken }, (place, pStatus) => {
73
+ if (pStatus === google.maps.places.PlacesServiceStatus.OK) {
74
+ resolve({
75
+ name: place?.name,
76
+ address: place?.formatted_address,
77
+ latitude: place?.geometry?.location?.lat(),
78
+ longitude: place?.geometry?.location?.lng()
79
+ });
80
+ }
81
+ else {
82
+ reject(new Error(LocationNotFoundError));
83
+ }
84
+ });
85
+ });
86
+ };
87
+ getAddress = async (coords) => {
88
+ const location = {
89
+ lat: coords.latitude,
90
+ lng: coords.longitude
91
+ };
92
+ const geocoder = new google.maps.Geocoder();
93
+ return new Promise((resolve, reject) => {
94
+ geocoder.geocode({ location }, (results, status) => {
95
+ if (status === 'OK') {
96
+ const [result] = results ?? [];
97
+ if (result) {
98
+ resolve({
99
+ name: result.formatted_address,
100
+ address: result.formatted_address,
101
+ ...(result.geometry && {
102
+ latitude: result.geometry.location.lat(),
103
+ longitude: result.geometry.location.lng()
104
+ })
105
+ });
106
+ }
107
+ else {
108
+ resolve({
109
+ name: `${coords.latitude}, ${coords.longitude}`,
110
+ latitude: coords.latitude,
111
+ longitude: coords.longitude
112
+ });
113
+ }
114
+ }
115
+ else {
116
+ reject(new Error(`${GeocoderFailedError}: ${status}`));
117
+ }
118
+ });
119
+ });
120
+ };
121
+ getPlacePredictionsUtil = async (location, bias = {}) => {
122
+ const autocompleteService = new google.maps.places.AutocompleteService();
123
+ const optionalParams = {};
124
+ if (bias?.location) {
125
+ if (bias?.location.center === 'current') {
126
+ await getNavigatorPosition()
127
+ .then(coords => {
128
+ optionalParams.location = toGoogleLatLng(coords);
129
+ if (bias.location)
130
+ optionalParams.radius = bias.location.radius;
131
+ })
132
+ // no-op user didn't allow location
133
+ .catch(() => { });
134
+ }
135
+ else {
136
+ optionalParams.location = toGoogleLatLng(bias.location.center);
137
+ optionalParams.radius = bias.location.radius;
138
+ }
139
+ }
140
+ if (bias?.bounds) {
141
+ const [sw, ne] = bias.bounds;
142
+ optionalParams.bounds = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));
143
+ }
144
+ return new Promise((resolve, reject) => {
145
+ const token = new google.maps.places.AutocompleteSessionToken();
146
+ autocompleteService.getPlacePredictions({
147
+ input: location,
148
+ types: QUERY_TYPES,
149
+ sessionToken: token,
150
+ ...optionalParams
151
+ }, (placePredictions, status) => {
152
+ if (status === google.maps.places.PlacesServiceStatus.OK) {
153
+ const res = placePredictions?.map(p => ({
154
+ placeId: p.place_id,
155
+ mainText: p.structured_formatting.main_text,
156
+ secondaryText: p.structured_formatting.secondary_text
157
+ }));
158
+ resolve({ placeSuggestions: res?.length ? res : [], token });
159
+ }
160
+ else {
161
+ reject(new Error(LocationNotFoundError));
162
+ }
163
+ });
164
+ });
165
+ };
166
+ getPlaceSuggestionsUtil = async (location, bias = {}) => {
167
+ const { AutocompleteSuggestion } = google.maps.places;
168
+ const optionalParams = {};
169
+ if (bias?.location) {
170
+ if (bias?.location.center === 'current') {
171
+ await getNavigatorPosition()
172
+ .then(coords => {
173
+ const b = new google.maps.Circle({
174
+ center: toGoogleLatLng(coords)
175
+ });
176
+ if (bias.location) {
177
+ b.setRadius(bias.location.radius);
178
+ }
179
+ optionalParams.locationBias = b;
180
+ })
181
+ // no-op user didn't allow location
182
+ .catch(() => { });
183
+ }
184
+ else {
185
+ optionalParams.locationBias = new google.maps.Circle({
186
+ center: toGoogleLatLng(bias.location.center),
187
+ radius: bias.location.radius
188
+ });
189
+ }
190
+ }
191
+ if (bias?.bounds) {
192
+ const [sw, ne] = bias.bounds;
193
+ optionalParams.locationRestriction = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));
194
+ }
195
+ const token = new google.maps.places.AutocompleteSessionToken();
196
+ const rp = {
197
+ input: location,
198
+ sessionToken: token,
199
+ ...optionalParams
200
+ };
201
+ return new Promise((resolve, reject) => {
202
+ AutocompleteSuggestion.fetchAutocompleteSuggestions(rp)
203
+ .then(({ suggestions }) => {
204
+ const res = suggestions
205
+ ?.map(s => s.placePrediction)
206
+ .filter(p => p !== null)
207
+ .map(p => ({
208
+ placeId: p.placeId,
209
+ mainText: p.mainText?.text ?? '',
210
+ secondaryText: p.secondaryText?.text ?? ''
211
+ }));
212
+ resolve({ placeSuggestions: res ?? [], token });
213
+ })
214
+ .catch(() => {
215
+ reject(new Error(LocationNotFoundError));
216
+ });
217
+ });
218
+ };
219
+ /** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)
220
+ * and session token (valid for multiple queries, followed by one place selection).
221
+ */
222
+ getPlacePredictions = async (location, bias) => {
223
+ return new Promise((resolve, reject) => {
224
+ try {
225
+ if (this.version === 'v2') {
226
+ resolve(this.getPlaceSuggestionsUtil(location, bias));
227
+ }
228
+ else {
229
+ resolve(this.getPlacePredictionsUtil(location, bias));
230
+ }
231
+ }
232
+ catch (error) {
233
+ if (this.version === 'v2') {
234
+ if (error instanceof Error && 'name' in Error && error.name === 'RPCError') {
235
+ this.version = 'v1';
236
+ resolve(this.getPlacePredictions(location, bias));
237
+ }
238
+ reject(error);
239
+ }
240
+ }
241
+ });
242
+ };
243
+ }
244
+ //# sourceMappingURL=GoogleMapsAPI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsAPI.js","sourceRoot":"","sources":["../../../src/components/Location/GoogleMapsAPI.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EAIZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,mBAAmB,EACnB,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB,MAAM,CAAC,OAAO,OAAO,aAAa;IACxB,OAAO,GAAgB,IAAI,CAAC;IAEpC,yFAAyF;IACzF,SAAS,GAAG,KAAK,EACf,MAAmC,EACnC,UAA2B,EACV,EAAE;QACnB,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,EAAE,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,oBAAoB,EAAE,CAAC;QAExD,IAAI,QAAgB,CAAC;QACrB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,C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AC;IACL,CAAC,CAAC;CACH","sourcesContent":["/* eslint-disable class-methods-use-this */\nimport {\n CoordsCannotBeParsedError,\n GeocoderFailedError,\n LocationNotFoundError,\n QUERY_FIELDS,\n QUERY_TYPES,\n type Bias,\n type LatLng,\n type Location\n} from './Location.types';\nimport {\n getNavigatorPosition,\n isValueDegreeFormatCoordinate,\n isValueDMCoordinate,\n isValueDMSCoordinate,\n parseDMS,\n toGoogleLatLng\n} from './utils';\nimport type { LocationAPI } from './LocationAPI.types';\n\nexport default class GoogleMapsAPI implements LocationAPI {\n private version: 'v1' | 'v2' = 'v2';\n\n /** Returns coordinations for given input: either coords, address or current position. */\n getCoords = async (\n coords: string | 'current' | LatLng,\n mapElement?: HTMLDivElement\n ): Promise<LatLng> => {\n if (coords === '' || coords === undefined) throw new Error();\n if (coords === 'current') return getNavigatorPosition();\n\n let location: LatLng;\n if (typeof coords === 'string') {\n let latLng: number[] = [];\n if (\n isValueDMSCoordinate(coords) ||\n isValueDMCoordinate(coords) ||\n isValueDegreeFormatCoordinate(coords)\n ) {\n latLng = parseDMS(coords);\n } else {\n let splitter;\n if (coords.includes(', ')) {\n splitter = ', ';\n } else if (coords.includes(',')) {\n splitter = ',';\n } else if (coords.includes(' ')) {\n splitter = ' ';\n } else {\n splitter = ', ';\n }\n\n latLng = coords.split(splitter).map(Number);\n }\n\n const [lat, lng] = latLng;\n if (Number.isNaN(lat) || Number.isNaN(lng) || lat === undefined || lng === undefined)\n return this.getPlace(coords, mapElement);\n location = { latitude: lat, longitude: lng };\n } else {\n location = coords;\n }\n\n if (Number.isFinite(location.latitude) && Number.isFinite(location.longitude)) return location;\n\n throw new Error(CoordsCannotBeParsedError);\n };\n\n getPlace = async (\n location: string,\n mapElement: HTMLDivElement = document.createElement('div')\n ): Promise<LatLng> => {\n const placesService = new google.maps.places.PlacesService(mapElement);\n const { placeSuggestions, token } = await this.getPlacePredictions(location);\n return new Promise((resolve, reject) => {\n placesService.getDetails(\n {\n placeId: placeSuggestions[0]?.placeId,\n fields: QUERY_FIELDS,\n sessionToken: token\n },\n (place, pStatus) => {\n if (pStatus === google.maps.places.PlacesServiceStatus.OK) {\n resolve({\n latitude: place?.geometry?.location?.lat() ?? NaN,\n longitude: place?.geometry?.location?.lng() ?? NaN\n });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n }\n );\n });\n };\n\n getPlaceById = async (\n placeId: string,\n sessionToken: google.maps.places.AutocompleteSessionToken = new google.maps.places.AutocompleteSessionToken(),\n mapElement: HTMLDivElement = document.createElement('div')\n ): Promise<Location> => {\n const placesService = new google.maps.places.PlacesService(mapElement);\n return new Promise((resolve, reject) => {\n placesService.getDetails(\n { placeId, fields: QUERY_FIELDS, sessionToken },\n (place, pStatus) => {\n if (pStatus === google.maps.places.PlacesServiceStatus.OK) {\n resolve({\n name: place?.name,\n address: place?.formatted_address,\n latitude: place?.geometry?.location?.lat(),\n longitude: place?.geometry?.location?.lng()\n });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n }\n );\n });\n };\n\n getAddress = async (\n coords: LatLng\n ): Promise<{\n name: string;\n address?: string;\n latitude: number;\n longitude: number;\n }> => {\n const location = {\n lat: coords.latitude,\n lng: coords.longitude\n };\n const geocoder = new google.maps.Geocoder();\n return new Promise((resolve, reject) => {\n geocoder.geocode(\n { location },\n (results: google.maps.GeocoderResult[] | null, status: google.maps.GeocoderStatus) => {\n if (status === 'OK') {\n const [result] = results ?? [];\n if (result) {\n resolve({\n name: result.formatted_address,\n address: result.formatted_address,\n ...(result.geometry && {\n latitude: result.geometry.location.lat(),\n longitude: result.geometry.location.lng()\n })\n });\n } else {\n resolve({\n name: `${coords.latitude}, ${coords.longitude}`,\n latitude: coords.latitude,\n longitude: coords.longitude\n });\n }\n } else {\n reject(new Error(`${GeocoderFailedError}: ${status}`));\n }\n }\n );\n });\n };\n\n getPlacePredictionsUtil = async (\n location: string,\n bias: Bias = {}\n ): Promise<{\n placeSuggestions: {\n placeId: string;\n mainText: string;\n secondaryText: string;\n }[];\n token: google.maps.places.AutocompleteSessionToken;\n }> => {\n const autocompleteService = new google.maps.places.AutocompleteService();\n const optionalParams: Partial<google.maps.places.AutocompletionRequest> = {};\n if (bias?.location) {\n if (bias?.location.center === 'current') {\n await getNavigatorPosition()\n .then(coords => {\n optionalParams.location = toGoogleLatLng(coords);\n if (bias.location) optionalParams.radius = bias.location.radius;\n })\n // no-op user didn't allow location\n .catch(() => {});\n } else {\n optionalParams.location = toGoogleLatLng(bias.location.center);\n optionalParams.radius = bias.location.radius;\n }\n }\n\n if (bias?.bounds) {\n const [sw, ne] = bias.bounds;\n optionalParams.bounds = new google.maps.LatLngBounds(toGoogleLatLng(sw), toGoogleLatLng(ne));\n }\n return new Promise((resolve, reject) => {\n const token = new google.maps.places.AutocompleteSessionToken();\n autocompleteService.getPlacePredictions(\n {\n input: location,\n types: QUERY_TYPES,\n sessionToken: token,\n ...optionalParams\n },\n (placePredictions, status) => {\n if (status === google.maps.places.PlacesServiceStatus.OK) {\n const res = placePredictions?.map(p => ({\n placeId: p.place_id,\n mainText: p.structured_formatting.main_text,\n secondaryText: p.structured_formatting.secondary_text\n }));\n\n resolve({ placeSuggestions: res?.length ? res : [], token });\n } else {\n reject(new Error(LocationNotFoundError));\n }\n }\n );\n });\n };\n\n getPlaceSuggestionsUtil = async (\n location: string,\n bias: Bias = {}\n ): Promise<{\n placeSuggestions: {\n placeId: string;\n mainText: string;\n secondaryText: string;\n }[];\n token: google.maps.places.AutocompleteSessionToken;\n }> => {\n const { AutocompleteSuggestion } = google.maps.places;\n const optionalParams: Partial<google.maps.places.AutocompleteRequest> = {};\n if (bias?.location) {\n if (bias?.location.center === 'current') {\n await getNavigatorPosition()\n .then(coords => {\n const b = new google.maps.Circle({\n center: toGoogleLatLng(coords)\n });\n\n if (bias.location) {\n b.setRadius(bias.location.radius);\n }\n optionalParams.locationBias = b;\n })\n // no-op user didn't allow location\n .catch(() => {});\n } else {\n optionalParams.locationBias = new google.maps.Circle({\n center: toGoogleLatLng(bias.location.center),\n radius: bias.location.radius\n });\n }\n }\n\n if (bias?.bounds) {\n const [sw, ne] = bias.bounds;\n optionalParams.locationRestriction = new google.maps.LatLngBounds(\n toGoogleLatLng(sw),\n toGoogleLatLng(ne)\n );\n }\n\n const token = new google.maps.places.AutocompleteSessionToken();\n\n const rp: google.maps.places.AutocompleteRequest = {\n input: location,\n sessionToken: token,\n ...optionalParams\n };\n\n return new Promise((resolve, reject) => {\n AutocompleteSuggestion.fetchAutocompleteSuggestions(rp)\n .then(({ suggestions }) => {\n const res = suggestions\n ?.map(s => s.placePrediction)\n .filter(p => p !== null)\n .map(p => ({\n placeId: p.placeId,\n mainText: p.mainText?.text ?? '',\n secondaryText: p.secondaryText?.text ?? ''\n }));\n resolve({ placeSuggestions: res ?? [], token });\n })\n .catch(() => {\n reject(new Error(LocationNotFoundError));\n });\n });\n };\n\n /** Returns an array of place prediction objects ('place' can be an establishment, geographic location, or prominent point of interest)\n * and session token (valid for multiple queries, followed by one place selection).\n */\n getPlacePredictions = async (\n location: string,\n bias?: Bias\n ): Promise<{\n placeSuggestions: {\n placeId: string;\n mainText: string;\n secondaryText: string;\n }[];\n token: google.maps.places.AutocompleteSessionToken;\n }> => {\n return new Promise((resolve, reject) => {\n try {\n if (this.version === 'v2') {\n resolve(this.getPlaceSuggestionsUtil(location, bias));\n } else {\n resolve(this.getPlacePredictionsUtil(location, bias));\n }\n } catch (error) {\n if (this.version === 'v2') {\n if (error instanceof Error && 'name' in Error && error.name === 'RPCError') {\n this.version = 'v1';\n resolve(this.getPlacePredictions(location, bias));\n }\n reject(error);\n }\n }\n });\n };\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  /// <reference types="google.maps" preserve="true" />
2
2
  import type { ReactNode } from 'react';
3
+ import type { LocationAPI } from './LocationAPI.types';
3
4
  export declare type LatLng = {
4
5
  /** The latitude representation. */
5
6
  latitude: ReturnType<google.maps.LatLng['lat']>;
@@ -27,8 +28,8 @@ export declare type ProviderOpts = {
27
28
  };
28
29
  export interface MapsProvider {
29
30
  name: string;
30
- loadAPI: (options: ProviderOpts) => Promise<void>;
31
- loadedPromise: Promise<void> | null;
31
+ loadAPI: (options: ProviderOpts) => Promise<LocationAPI>;
32
+ loadedPromise: Promise<LocationAPI> | null;
32
33
  loadedApiKey: string;
33
34
  }
34
35
  export declare const QUERY_FIELDS: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"Location.types.d.ts","sourceRoot":"","sources":["../../../src/components/Location/Location.types.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,CAAC,OAAO,MAAM,MAAM,GAAG;IAC3B,mCAAmC;IACnC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,oCAAoC;IACpC,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,IAAI,GAAG;IACzB;uGACmG;IACnG,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,EAAE;QACT,8CAA8C;QAC9C,oEAAoE;QACpE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;QAC3B,yCAAyC;QACzC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEF,MAAM,CAAC,OAAO,MAAM,YAAY,GAAG;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,OAAO,EAAE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M,CAAC,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC","sourcesContent":["/// <reference types=\"google.maps\" preserve=\"true\" />\n\nimport type { ReactNode } from 'react';\n\nexport declare type LatLng = {\n /** The latitude representation. */\n latitude: ReturnType<google.maps.LatLng['lat']>;\n /** The longitude representation. */\n longitude: ReturnType<google.maps.LatLng['lng']>;\n};\n\nexport declare type Bias = {\n /** Predictions will be biased towards, but not restricted to, the given bounds. Both location and radius will be ignored if bounds is set.\n * Array stores south-west coordinate of bounding box and north-east coordinate of bounding box. */\n bounds?: [LatLng, LatLng];\n /** Predictions will be biased towards the given location and radius. */\n location?: {\n /** Must to provide both center and radius. */\n /** Location coordinate or current (means user current location). */\n center: LatLng | 'current';\n /** The radius is specified in meters. */\n radius: number;\n };\n};\n\nexport declare type ProviderOpts = {\n apiKey?: string;\n region?: string;\n language?: string;\n [key: string]: unknown;\n};\n\nexport interface MapsProvider {\n name: string;\n loadAPI: (options: ProviderOpts) => Promise<void>;\n loadedPromise: Promise<void> | null;\n loadedApiKey: string;\n}\n\nexport const QUERY_FIELDS = ['name', 'formatted_address', 'geometry.location', 'place_id'];\nexport const QUERY_TYPES = ['establishment', 'geocode'];\n\nexport const LocationNotFoundError = 'Location not found';\nexport const GeolocationUnsupportedError = 'Geolocation unsupported';\nexport const GoogleMapsAPINotFoundError = 'Cannot load Google Maps API';\nexport const IsNotAnObjectError = 'Provider data given is not an object';\nexport const ProviderNotSupportedError = 'Not supported maps provider given';\nexport const CoordsCannotBeParsedError = 'Coords cannot be parsed!';\nexport const GeocoderFailedError = 'Geocoder failed due to';\n\nexport interface Location {\n name?: google.maps.places.PlaceResult['name'];\n address?: google.maps.places.PlaceResult['formatted_address'];\n latitude?: ReturnType<google.maps.LatLng['lat']>;\n longitude?: ReturnType<google.maps.LatLng['lng']>;\n}\n\nexport interface Pin extends LatLng {\n title?: string;\n content?: ReactNode;\n selected?: boolean;\n}\n"]}
1
+ {"version":3,"file":"Location.types.js","sourceRoot":"","sources":["../../../src/components/Location/Location.types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAyCrD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,CAAC,CAAC;AAC3F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAC1D,MAAM,CAAC,MAAM,2BAA2B,GAAG,yBAAyB,CAAC;AACrE,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AACxE,MAAM,CAAC,MAAM,kBAAkB,GAAG,sCAAsC,CAAC;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,0BAA0B,CAAC;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,wBAAwB,CAAC","sourcesContent":["/// <reference types=\"google.maps\" preserve=\"true\" />\n\nimport type { ReactNode } from 'react';\n\nimport type { LocationAPI } from './LocationAPI.types';\n\nexport declare type LatLng = {\n /** The latitude representation. */\n latitude: ReturnType<google.maps.LatLng['lat']>;\n /** The longitude representation. */\n longitude: ReturnType<google.maps.LatLng['lng']>;\n};\n\nexport declare type Bias = {\n /** Predictions will be biased towards, but not restricted to, the given bounds. Both location and radius will be ignored if bounds is set.\n * Array stores south-west coordinate of bounding box and north-east coordinate of bounding box. */\n bounds?: [LatLng, LatLng];\n /** Predictions will be biased towards the given location and radius. */\n location?: {\n /** Must to provide both center and radius. */\n /** Location coordinate or current (means user current location). */\n center: LatLng | 'current';\n /** The radius is specified in meters. */\n radius: number;\n };\n};\n\nexport declare type ProviderOpts = {\n apiKey?: string;\n region?: string;\n language?: string;\n [key: string]: unknown;\n};\n\nexport interface MapsProvider {\n name: string;\n loadAPI: (options: ProviderOpts) => Promise<LocationAPI>;\n loadedPromise: Promise<LocationAPI> | null;\n loadedApiKey: string;\n}\n\nexport const QUERY_FIELDS = ['name', 'formatted_address', 'geometry.location', 'place_id'];\nexport const QUERY_TYPES = ['establishment', 'geocode'];\n\nexport const LocationNotFoundError = 'Location not found';\nexport const GeolocationUnsupportedError = 'Geolocation unsupported';\nexport const GoogleMapsAPINotFoundError = 'Cannot load Google Maps API';\nexport const IsNotAnObjectError = 'Provider data given is not an object';\nexport const ProviderNotSupportedError = 'Not supported maps provider given';\nexport const CoordsCannotBeParsedError = 'Coords cannot be parsed!';\nexport const GeocoderFailedError = 'Geocoder failed due to';\n\nexport interface Location {\n name?: google.maps.places.PlaceResult['name'];\n address?: google.maps.places.PlaceResult['formatted_address'];\n latitude?: ReturnType<google.maps.LatLng['lat']>;\n longitude?: ReturnType<google.maps.LatLng['lng']>;\n}\n\nexport interface Pin extends LatLng {\n title?: string;\n content?: ReactNode;\n selected?: boolean;\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { Bias, LatLng, Location } from './Location.types';
2
+ type SessionToken = google.maps.places.AutocompleteSessionToken;
3
+ export interface LocationAPI {
4
+ getCoords: (coords: string | 'current' | LatLng, mapElement?: HTMLDivElement) => Promise<LatLng>;
5
+ getAddress: (coords: LatLng) => Promise<{
6
+ name: string;
7
+ address?: string;
8
+ latitude: number;
9
+ longitude: number;
10
+ }>;
11
+ getPlaceById: (placeId: string, sessionToken?: SessionToken, mapElement?: HTMLDivElement) => Promise<Location>;
12
+ getPlace: (location: string, mapElement: HTMLDivElement) => Promise<LatLng>;
13
+ getPlacePredictions: (location: string, bias?: Bias) => Promise<{
14
+ placeSuggestions: {
15
+ placeId: string;
16
+ mainText: string;
17
+ secondaryText: string;
18
+ }[];
19
+ token: SessionToken;
20
+ }>;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=LocationAPI.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocationAPI.types.d.ts","sourceRoot":"","sources":["../../../src/components/Location/LocationAPI.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE/D,KAAK,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC;AAEhE,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACjG,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;QACtC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,YAAY,EAAE,CACZ,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,CAAC,EAAE,cAAc,KACxB,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5E,mBAAmB,EAAE,CACnB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,IAAI,KACR,OAAO,CAAC;QACX,gBAAgB,EAAE;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,MAAM,CAAC;YACjB,aAAa,EAAE,MAAM,CAAC;SACvB,EAAE,CAAC;QACJ,KAAK,EAAE,YAAY,CAAC;KACrB,CAAC,CAAC;CACJ"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=LocationAPI.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocationAPI.types.js","sourceRoot":"","sources":["../../../src/components/Location/LocationAPI.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Bias, LatLng, Location } from './Location.types';\n\ntype SessionToken = google.maps.places.AutocompleteSessionToken;\n\nexport interface LocationAPI {\n getCoords: (coords: string | 'current' | LatLng, mapElement?: HTMLDivElement) => Promise<LatLng>;\n getAddress: (coords: LatLng) => Promise<{\n name: string;\n address?: string;\n latitude: number;\n longitude: number;\n }>;\n getPlaceById: (\n placeId: string,\n sessionToken?: SessionToken,\n mapElement?: HTMLDivElement\n ) => Promise<Location>;\n getPlace: (location: string, mapElement: HTMLDivElement) => Promise<LatLng>;\n getPlacePredictions: (\n location: string,\n bias?: Bias\n ) => Promise<{\n placeSuggestions: {\n placeId: string;\n mainText: string;\n secondaryText: string;\n }[];\n token: SessionToken;\n }>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LocationDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Location/LocationDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAIlD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAI9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IACpC,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,GAAG,eAAe,CAAC,CAAC;CAChD;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAkE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"LocationDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Location/LocationDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAIlD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAI9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IACpC,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,GAAG,eAAe,CAAC,CAAC;CAChD;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAoE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -5,7 +5,7 @@ import Link from '../Link';
5
5
  import NoValue from '../NoValue/NoValue';
6
6
  import LocationView from './LocationView';
7
7
  import MapsContext from './MapsContext';
8
- import { getCoords, loadMapsAPI } from './utils';
8
+ import { loadMapsAPI } from './utils';
9
9
  const LocationDisplay = forwardRef(function LocationDisplay({ value, displayText, variant = 'text-map', height = '25rem', zoomLevel = 13, ...restProps }, ref) {
10
10
  const { name, ...providerOpts } = useContext(MapsContext);
11
11
  const [location, setLocation] = useState();
@@ -15,8 +15,10 @@ const LocationDisplay = forwardRef(function LocationDisplay({ value, displayText
15
15
  if (['text-map', 'map'].includes(variant) && value) {
16
16
  (async () => {
17
17
  setLoading(true);
18
- await loadMapsAPI(name, providerOpts);
19
- setLocation(await getCoords(value));
18
+ const mapAPIObj = await loadMapsAPI(name, providerOpts);
19
+ if (mapAPIObj) {
20
+ setLocation(await mapAPIObj.getCoords(value));
21
+ }
20
22
  setLoading(false);
21
23
  })();
22
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LocationDisplay.js","sourceRoot":"","sources":["../../../src/components/Location/LocationDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpE,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA0BjD,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,WAAW,EACX,OAAO,GAAG,UAAU,EACpB,MAAM,GAAG,OAAO,EAChB,SAAS,GAAG,EAAE,EACd,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAC1D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAA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AS,EAAE,CAC9E,EAAE,YAEF,WAAW,IAAI,WAAW,GACtB,CACR,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,GAAG,EAAE,GAA2B,KAAM,SAAS,YAClD,WAAW,IAAI,WAAW,GACtB,CACR,CAAC,EACH,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,CAChD,KAAC,YAAY,IACX,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAChC,iBAAiB,QACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,CACH,IACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, useContext, useEffect, useState } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\n\nimport Text from '../Text';\nimport Link from '../Link';\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport NoValue from '../NoValue/NoValue';\n\nimport LocationView from './LocationView';\nimport type { LocationViewProps } from './LocationView';\nimport MapsContext from './MapsContext';\nimport type { LatLng } from './Location.types';\nimport { getCoords, loadMapsAPI } from './utils';\n\nexport interface LocationDisplayProps extends BaseProps {\n /** Location address or coordinates */\n value?: string | 'current' | LatLng;\n /** The text to be displayed. */\n displayText?: string;\n /**\n * Controls styling of the field.\n * @default 'text-map'\n */\n variant?: 'text-map' | 'text' | 'map';\n /**\n * Height of the map container.\n * @default '25rem'\n */\n height?: LocationViewProps['height'];\n /**\n * How much the map should zoom.\n * @default 13\n */\n zoomLevel?: LocationViewProps['zoomLevel'];\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement | HTMLSpanElement>;\n}\n\nconst LocationDisplay: ForwardRefForwardPropsComponent<LocationDisplayProps> = forwardRef(\n function LocationDisplay(\n {\n value,\n displayText,\n variant = 'text-map',\n height = '25rem',\n zoomLevel = 13,\n ...restProps\n }: PropsWithoutRef<LocationDisplayProps>,\n ref: LocationDisplayProps['ref']\n ) {\n const { name, ...providerOpts } = useContext(MapsContext);\n const [location, setLocation] = useState<LatLng>();\n const [loading, setLoading] = useState(false);\n\n const valueString =\n typeof value === 'string' ? value : `${value?.latitude}, ${value?.longitude}`;\n\n useEffect(() => {\n if (['text-map', 'map'].includes(variant) && value) {\n (async () => {\n setLoading(true);\n await loadMapsAPI(name, providerOpts);\n setLocation(await getCoords(value));\n setLoading(false);\n })();\n }\n }, [variant, value]);\n\n return !value ? (\n <Text ref={ref as Ref<HTMLSpanElement>} {...restProps} aria-hidden>\n <NoValue />\n </Text>\n ) : (\n <>\n {(variant === 'text' || variant === 'text-map') &&\n (name === 'google' ? (\n <Link\n ref={ref as Ref<HTMLAnchorElement>}\n {...restProps}\n target='_blank'\n rel='noopener noreferrer'\n href={`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(\n typeof value === 'string' ? value : `${value?.latitude}, ${value?.longitude}`\n )}`}\n >\n {displayText || valueString}\n </Link>\n ) : (\n <Text ref={ref as Ref<HTMLSpanElement>} {...restProps}>\n {displayText || valueString}\n </Text>\n ))}\n {(variant === 'text-map' || variant === 'map') && (\n <LocationView\n pins={location ? [location] : []}\n centerMapOnChange\n height={height}\n zoomLevel={zoomLevel}\n loading={loading}\n />\n )}\n </>\n );\n }\n);\n\nexport default LocationDisplay;\n"]}
1
+ {"version":3,"file":"LocationDisplay.js","sourceRoot":"","sources":["../../../src/components/Location/LocationDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpE,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAE1C,OAAO,WAAW,MAAM,e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AA2B,KAAM,SAAS,iCACnD,KAAC,OAAO,KAAG,GACN,CACR,CAAC,CAAC,CAAC,CACF,8BACG,CAAC,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,UAAU,CAAC;gBAC7C,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CACnB,KAAC,IAAI,IACH,GAAG,EAAE,GAA6B,KAC9B,SAAS,EACb,MAAM,EAAC,QAAQ,EACf,GAAG,EAAC,qBAAqB,EACzB,IAAI,EAAE,mDAAmD,kBAAkB,CACzE,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,QAAQ,KAAK,KAAK,EAAE,SAAS,EAAE,CAC9E,EAAE,YAEF,WAAW,IAAI,WAAW,GACtB,CACR,CAAC,CAAC,CAAC,CACF,KAAC,IAAI,IAAC,GAAG,EAAE,GAA2B,KAAM,SAAS,YAClD,WAAW,IAAI,WAAW,GACtB,CACR,CAAC,EACH,CAAC,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,CAChD,KAAC,YAAY,IACX,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAChC,iBAAiB,QACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,CACH,IACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, useContext, useEffect, useState } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\n\nimport Text from '../Text';\nimport Link from '../Link';\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport NoValue from '../NoValue/NoValue';\n\nimport LocationView from './LocationView';\nimport type { LocationViewProps } from './LocationView';\nimport MapsContext from './MapsContext';\nimport type { LatLng } from './Location.types';\nimport { loadMapsAPI } from './utils';\n\nexport interface LocationDisplayProps extends BaseProps {\n /** Location address or coordinates */\n value?: string | 'current' | LatLng;\n /** The text to be displayed. */\n displayText?: string;\n /**\n * Controls styling of the field.\n * @default 'text-map'\n */\n variant?: 'text-map' | 'text' | 'map';\n /**\n * Height of the map container.\n * @default '25rem'\n */\n height?: LocationViewProps['height'];\n /**\n * How much the map should zoom.\n * @default 13\n */\n zoomLevel?: LocationViewProps['zoomLevel'];\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement | HTMLSpanElement>;\n}\n\nconst LocationDisplay: ForwardRefForwardPropsComponent<LocationDisplayProps> = forwardRef(\n function LocationDisplay(\n {\n value,\n displayText,\n variant = 'text-map',\n height = '25rem',\n zoomLevel = 13,\n ...restProps\n }: PropsWithoutRef<LocationDisplayProps>,\n ref: LocationDisplayProps['ref']\n ) {\n const { name, ...providerOpts } = useContext(MapsContext);\n const [location, setLocation] = useState<LatLng>();\n const [loading, setLoading] = useState(false);\n\n const valueString =\n typeof value === 'string' ? value : `${value?.latitude}, ${value?.longitude}`;\n\n useEffect(() => {\n if (['text-map', 'map'].includes(variant) && value) {\n (async () => {\n setLoading(true);\n const mapAPIObj = await loadMapsAPI(name, providerOpts);\n if (mapAPIObj) {\n setLocation(await mapAPIObj.getCoords(value));\n }\n setLoading(false);\n })();\n }\n }, [variant, value]);\n\n return !value ? (\n <Text ref={ref as Ref<HTMLSpanElement>} {...restProps} aria-hidden>\n <NoValue />\n </Text>\n ) : (\n <>\n {(variant === 'text' || variant === 'text-map') &&\n (name === 'google' ? (\n <Link\n ref={ref as Ref<HTMLAnchorElement>}\n {...restProps}\n target='_blank'\n rel='noopener noreferrer'\n href={`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(\n typeof value === 'string' ? value : `${value?.latitude}, ${value?.longitude}`\n )}`}\n >\n {displayText || valueString}\n </Link>\n ) : (\n <Text ref={ref as Ref<HTMLSpanElement>} {...restProps}>\n {displayText || valueString}\n </Text>\n ))}\n {(variant === 'text-map' || variant === 'map') && (\n <LocationView\n pins={location ? [location] : []}\n centerMapOnChange\n height={height}\n zoomLevel={zoomLevel}\n loading={loading}\n />\n )}\n </>\n );\n }\n);\n\nexport default LocationDisplay;\n"]}
@@ -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;AAgBvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,MAAM,WAAW,kBAAmB,SAAQ,SAAS,EAAE,gBAAgB,EAAE,UAAU;IACjF;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,yGAAyG;IACzG,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAK,IAAI,CAAC;IACX;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,8DAA8D;IAC9D,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ;;;OAGG;IACH,GAAG,C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