@contentful/field-editor-location 1.2.2 → 1.3.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.
- package/dist/cjs/GoogleMapView.js +156 -0
- package/dist/cjs/LocationEditor.js +204 -0
- package/dist/cjs/LocationSearchInput.js +153 -0
- package/dist/cjs/LocationSelector.js +184 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/types.js +15 -0
- package/dist/esm/GoogleMapView.js +102 -0
- package/dist/esm/LocationEditor.js +142 -0
- package/dist/esm/LocationSearchInput.js +99 -0
- package/dist/esm/LocationSelector.js +130 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.js +5 -0
- package/dist/{GoogleMapView.d.ts → types/GoogleMapView.d.ts} +25 -25
- package/dist/{LocationEditor.d.ts → types/LocationEditor.d.ts} +45 -45
- package/dist/{LocationSearchInput.d.ts → types/LocationSearchInput.d.ts} +11 -11
- package/dist/{LocationSelector.d.ts → types/LocationSelector.d.ts} +13 -13
- package/dist/{index.d.ts → types/index.d.ts} +2 -2
- package/dist/{types.d.ts → types/types.d.ts} +22 -22
- package/package.json +23 -9
- package/CHANGELOG.md +0 -210
- package/dist/field-editor-location.cjs.development.js +0 -545
- package/dist/field-editor-location.cjs.development.js.map +0 -1
- package/dist/field-editor-location.cjs.production.min.js +0 -2
- package/dist/field-editor-location.cjs.production.min.js.map +0 -1
- package/dist/field-editor-location.esm.js +0 -538
- package/dist/field-editor-location.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-location.cjs.production.min.js","sources":["../src/GoogleMapView.tsx","../src/types.ts","../src/LocationSearchInput.tsx","../src/LocationSelector.tsx","../src/LocationEditor.tsx","../src/index.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport React from 'react';\n\nimport { css } from 'emotion';\nimport GoogleMapReact from 'google-map-react';\n\nimport { Coords } from './types';\n\nconst styles = {\n root: css({\n height: '300px',\n width: '100%',\n }),\n};\n\nconst BerlinLocation = {\n lat: 52.5018,\n lng: 13.41115439,\n};\n\ntype GoogleMapViewProps = {\n disabled: boolean;\n location: Coords | undefined;\n onGoogleApiLoaded: ({ maps }: { maps: any }) => void;\n onChangeLocation: (location: Coords) => void;\n googleMapsKey?: string;\n};\n\ntype GoogleMapsViewState = {\n marker: any;\n maps: any;\n};\n\nexport class GoogleMapView extends React.Component<GoogleMapViewProps, GoogleMapsViewState> {\n constructor(props: GoogleMapViewProps) {\n super(props);\n this.state = {\n marker: undefined,\n maps: undefined,\n };\n }\n\n componentDidUpdate() {\n if (this.state.marker && this.state.maps) {\n if (this.props.location) {\n const latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);\n this.state.marker.setPosition(latLng);\n this.state.marker.setVisible(true);\n } else {\n this.state.marker.setVisible(false);\n }\n this.state.marker.setDraggable(!this.props.disabled);\n this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');\n }\n }\n\n onGoogleApiLoaded = (event: { maps: any; map: any }) => {\n const { maps, map } = event;\n const marker = new maps.Marker({\n map,\n position: map.getCenter(),\n cursor: this.props.disabled ? 'not-allowed' : 'auto',\n draggable: !this.props.disabled,\n visible: Boolean(this.props.location),\n });\n\n maps.event.addListener(map, 'click', (event: any) => {\n if (this.props.disabled || !this.state.marker || !this.state.maps) {\n return;\n }\n this.state.marker.setPosition(event.latLng);\n this.state.marker.setVisible(true);\n this.props.onChangeLocation({\n lat: event.latLng.lat(),\n lng: event.latLng.lng(),\n });\n });\n\n maps.event.addListener(marker, 'dragend', (event: any) => {\n this.props.onChangeLocation({\n lat: event.latLng.lat(),\n lng: event.latLng.lng(),\n });\n });\n this.setState({ marker, maps }, () => {\n this.props.onGoogleApiLoaded({ maps });\n });\n };\n\n render() {\n return (\n <div className={styles.root}>\n <GoogleMapReact\n draggable={!this.props.disabled}\n bootstrapURLKeys={\n this.props.googleMapsKey ? { key: this.props.googleMapsKey } : undefined\n }\n defaultCenter={BerlinLocation}\n center={this.props.location}\n options={{\n scrollwheel: false,\n mapTypeId: 'roadmap',\n }}\n defaultZoom={6}\n yesIWantToUseGoogleMapApiInternals\n onGoogleApiLoaded={this.onGoogleApiLoaded}\n />\n </div>\n );\n }\n}\n","export interface Coords {\n lat: number;\n lng: number;\n}\n\nexport type LocationValue = { lat: number; lon: number };\nexport type NullableLocationValue = LocationValue | null | undefined;\n\nexport enum ViewType {\n Address = 'Address',\n Coordinates = 'Coordinates',\n}\n\nexport type GeocodeApiResponse = null | Array<{\n formatted_address: string;\n geometry: {\n location: {\n lat: () => number;\n lng: () => number;\n };\n };\n}>;\n","import React from 'react';\n\nimport { Button, Card, Spinner, ValidationMessage, TextInput } from '@contentful/f36-components';\nimport tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nimport { Coords, GeocodeApiResponse } from './types';\n\nconst styles = {\n root: css({\n width: '100%',\n }),\n input: css({\n position: 'relative',\n width: '100%',\n }),\n spinner: css({\n position: 'absolute',\n right: 10,\n top: 10,\n zIndex: 99,\n }),\n validationMessage: css({\n marginTop: tokens.spacingS,\n }),\n suggestion: css({\n position: 'absolute',\n transform: 'translateY(100%)',\n bottom: 0,\n left: 0,\n zIndex: 1,\n }),\n};\n\ntype LocationSearchInputProps = {\n disabled: boolean;\n value?: Coords;\n onSearchAddress: (term: string) => Promise<GeocodeApiResponse>;\n onGetAddressFromLocation: (coors: Coords | undefined, value: string) => Promise<string>;\n onChangeLocation: (location?: Coords) => void;\n};\n\nexport function LocationSearchInput(props: LocationSearchInputProps) {\n const [isSearching, setIsSearching] = React.useState<boolean>(false);\n const [address, setAddress] = React.useState<string>('');\n const [hasError, setHasError] = React.useState<boolean>(false);\n const [suggestion, setSuggestion] = React.useState<null | {\n address: string;\n location: { lat: number; lng: number };\n }>(null);\n\n React.useEffect(() => {\n setIsSearching(true);\n props.onGetAddressFromLocation(props.value, address).then((address) => {\n setAddress(address);\n setIsSearching(false);\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies\n }, [props.value, props.disabled]);\n\n return (\n <div className={styles.root}>\n <div className={styles.input}>\n <TextInput\n testId=\"location-editor-search\"\n isInvalid={hasError}\n placeholder=\"Start typing to find location\"\n value={address}\n onChange={(e) => {\n setAddress(e.target.value);\n setHasError(false);\n setSuggestion(null);\n\n if (e.target.value === '') {\n props.onChangeLocation(undefined);\n return;\n }\n\n setIsSearching(true);\n props.onSearchAddress(e.target.value).then((value) => {\n setIsSearching(false);\n if (value === null) {\n setHasError(false);\n } else if (value.length === 0) {\n setHasError(true);\n } else {\n setHasError(false);\n setSuggestion({\n address: value[0].formatted_address,\n location: {\n lat: Number(value[0].geometry.location.lat().toString().slice(0, 8)),\n lng: Number(value[0].geometry.location.lng().toString().slice(0, 8)),\n },\n });\n }\n });\n }}\n isDisabled={props.disabled}\n />\n {isSearching && <Spinner className={styles.spinner} />}\n {suggestion && (\n <Card padding=\"none\" className={styles.suggestion}>\n <Button\n variant=\"transparent\"\n testId=\"location-editor-suggestion\"\n onClick={() => {\n setAddress(suggestion.address);\n props.onChangeLocation(suggestion.location);\n setSuggestion(null);\n }}\n >\n {suggestion.address}\n </Button>\n </Card>\n )}\n {hasError && (\n <ValidationMessage\n testId=\"location-editor-not-found\"\n className={styles.validationMessage}\n >\n No results found for <strong>{address}</strong>. Please make sure that address is\n spelled correctly.\n </ValidationMessage>\n )}\n </div>\n </div>\n );\n}\n","import React from 'react';\n\nimport { TextLink, TextInput, Radio, Flex } from '@contentful/f36-components';\nimport tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nimport { LocationSearchInput } from './LocationSearchInput';\nimport { Coords, ViewType, GeocodeApiResponse } from './types';\n\ninterface LocationSelectorProps {\n disabled: boolean;\n value: Coords | undefined;\n view: ViewType;\n onChangeView: (view: ViewType) => void;\n onChangeLocation: (value?: Coords) => void;\n onSearchAddress: (value: string) => Promise<GeocodeApiResponse>;\n onGetAddressFromLocation: (location: Coords | undefined, address: string) => Promise<string>;\n}\n\nconst styles = {\n root: css({\n display: 'flex',\n flexDirection: 'row',\n marginTop: tokens.spacingS,\n alignItems: 'flex-end',\n }),\n main: css({\n flexGrow: 1,\n }),\n secondary: css({\n minWidth: '70px',\n textAlign: 'right',\n }),\n inputsRow: css({\n display: 'flex',\n marginTop: tokens.spacingS,\n fontSize: tokens.fontSizeM,\n color: tokens.gray900,\n fontFamily: tokens.fontStackPrimary,\n alignItems: 'center',\n }),\n splitter: css({\n width: tokens.spacingL,\n }),\n clearBtn: css({\n marginBottom: tokens.spacingS,\n }),\n};\n\nexport function LocationSelector(props: LocationSelectorProps) {\n return (\n <div className={styles.root}>\n <div className={styles.main}>\n <Flex flexDirection=\"row\">\n <Radio\n className={css({ flexBasis: '100%' })}\n id={ViewType.Address}\n testId=\"location-editor-address-radio\"\n isDisabled={props.disabled}\n value={ViewType.Address}\n isChecked={props.view === ViewType.Address}\n onChange={() => {\n props.onChangeView(ViewType.Address);\n }}\n >\n Address\n </Radio>\n <Radio\n className={css({ flexBasis: '100%' })}\n id={ViewType.Coordinates}\n testId=\"location-editor-coordinates-radio\"\n isDisabled={props.disabled}\n value={ViewType.Coordinates}\n isChecked={props.view === ViewType.Coordinates}\n onChange={() => {\n props.onChangeView(ViewType.Coordinates);\n }}\n >\n Coordinates\n </Radio>\n </Flex>\n {props.view === ViewType.Address && (\n <div className={styles.inputsRow}>\n <LocationSearchInput\n onSearchAddress={props.onSearchAddress}\n onGetAddressFromLocation={props.onGetAddressFromLocation}\n disabled={props.disabled}\n value={props.value}\n onChangeLocation={props.onChangeLocation}\n />\n </div>\n )}\n {props.view === ViewType.Coordinates && (\n <div className={styles.inputsRow}>\n <label htmlFor=\"latitude\">Latitude</label>\n <div className={styles.splitter} />\n <TextInput\n id=\"latitude\"\n testId=\"location-editor-latitude\"\n placeholder=\"Between -90 and 90\"\n isDisabled={props.disabled}\n value={props.value ? String(props.value.lat) : ''}\n onChange={(e) => {\n props.onChangeLocation({\n lng: props.value && props.value.lng !== undefined ? props.value.lng : 0,\n lat: Number(e.target.value) || 0,\n });\n }}\n type=\"number\"\n max=\"90\"\n min=\"-90\"\n step=\"0.1\"\n />\n <div className={styles.splitter} />\n <label htmlFor=\"longitude\">Longitude</label>\n <div className={styles.splitter} />\n <TextInput\n id=\"longitude\"\n testId=\"location-editor-longitude\"\n placeholder=\"Between -180 and 180\"\n isDisabled={props.disabled}\n value={props.value ? String(props.value.lng) : ''}\n onChange={(e) => {\n props.onChangeLocation({\n lat: props.value && props.value.lat !== undefined ? props.value.lat : 0,\n lng: Number(e.target.value) || 0,\n });\n }}\n type=\"number\"\n max=\"180\"\n min=\"-180\"\n step=\"0.1\"\n />\n </div>\n )}\n </div>\n <div className={styles.secondary}>\n <TextLink\n as=\"button\"\n isDisabled={props.disabled}\n testId=\"location-editor-clear\"\n className={styles.clearBtn}\n onClick={() => {\n props.onChangeLocation(undefined);\n }}\n >\n Clear\n </TextLink>\n </div>\n </div>\n );\n}\n","import * as React from 'react';\n\nimport { FieldAPI, FieldConnector, ParametersAPI } from '@contentful/field-editor-shared';\nimport deepEqual from 'deep-equal';\nimport isNumber from 'lodash/isNumber';\nimport throttle from 'lodash/throttle';\n\nimport { GoogleMapView } from './GoogleMapView';\nimport { LocationSelector } from './LocationSelector';\nimport {\n LocationValue,\n ViewType,\n NullableLocationValue,\n Coords,\n GeocodeApiResponse,\n} from './types';\n\nexport interface LocationEditorConnectedProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.parameters\n */\n parameters?: ParametersAPI & {\n instance: {\n googleMapsKey?: string;\n };\n };\n}\n\ntype LocationEditorProps = {\n disabled: boolean;\n value: NullableLocationValue;\n setValue: (value: NullableLocationValue) => void;\n googleMapsKey?: string;\n selectedView: ViewType;\n setSelectedView: (view: ViewType) => void;\n};\n\nfunction toLocationValue(coords?: Coords): NullableLocationValue {\n if (coords && isNumber(coords.lat) && isNumber(coords.lng)) {\n return { lat: coords.lat, lon: coords.lng };\n } else {\n return null;\n }\n}\n\nexport class LocationEditor extends React.Component<\n LocationEditorProps,\n {\n localValue?: Coords;\n mapsObject: any; // eslint-disable-line -- TODO: describe this disable @typescript-eslint/no-explicit-any\n }\n> {\n constructor(props: LocationEditorProps) {\n super(props);\n\n this.state = {\n localValue: props.value\n ? {\n lng: props.value.lon,\n lat: props.value.lat,\n }\n : undefined,\n mapsObject: null,\n };\n }\n\n // @ts-expect-error\n onSearchAddress: (value: string) => Promise<GeocodeApiResponse> = throttle((value) => {\n if (!this.state.mapsObject) {\n return Promise.resolve(null);\n }\n const { mapsObject } = this.state;\n if (!value) {\n return Promise.resolve(null);\n }\n return new Promise((resolve) => {\n const geocoder = new mapsObject.Geocoder();\n geocoder.geocode({ address: value }, resolve, () => {\n resolve(null);\n });\n });\n }, 300);\n\n onGetAddressFromLocation = (location: Coords | undefined, value: string): Promise<string> => {\n if (!this.state.mapsObject || !location) {\n return Promise.resolve('');\n }\n const { mapsObject } = this.state;\n return new Promise((resolve) => {\n const geocoder = new mapsObject.Geocoder();\n geocoder.geocode(\n { location },\n (result: GeocodeApiResponse) => {\n if (result && result.length > 0) {\n const addresses = result.map((item) => item.formatted_address);\n resolve(addresses.find((item) => item === value) || addresses[0]);\n } else {\n resolve('');\n }\n },\n () => {\n resolve('');\n }\n );\n });\n };\n\n render() {\n const { mapsObject, localValue } = this.state;\n\n return (\n <div data-test-id=\"location-editor\">\n <GoogleMapView\n disabled={this.props.disabled || mapsObject === null}\n googleMapsKey={this.props.googleMapsKey}\n location={localValue}\n onGoogleApiLoaded={({ maps }) => {\n this.setState({ mapsObject: maps });\n }}\n onChangeLocation={(coords) => {\n this.setState({ localValue: coords });\n this.props.setValue(toLocationValue(coords));\n }}\n />\n <LocationSelector\n disabled={this.props.disabled || mapsObject === null}\n value={localValue}\n view={this.props.selectedView}\n onChangeView={(view) => {\n this.props.setSelectedView(view);\n }}\n onChangeLocation={(coords) => {\n this.setState({ localValue: coords });\n this.props.setValue(toLocationValue(coords));\n }}\n onSearchAddress={this.onSearchAddress}\n onGetAddressFromLocation={this.onGetAddressFromLocation}\n />\n </div>\n );\n }\n}\n\nexport function LocationEditorConnected(props: LocationEditorConnectedProps) {\n const { field } = props;\n const googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;\n const [selectedView, setSelectedView] = React.useState<ViewType>(ViewType.Address);\n\n return (\n <FieldConnector<LocationValue>\n isEqualValues={(value1, value2) => {\n return deepEqual(value1, value2);\n }}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n >\n {({ value, disabled, setValue, externalReset }) => {\n return (\n <LocationEditor\n // on external change reset component completely and init with initial value again\n key={`location-editor-${externalReset}`}\n value={value}\n disabled={disabled}\n setValue={setValue}\n googleMapsKey={googleMapsKey}\n selectedView={selectedView}\n setSelectedView={setSelectedView}\n />\n );\n }}\n </FieldConnector>\n );\n}\n\nLocationEditorConnected.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import { LocationEditorConnected } from './LocationEditor';\n\nexport const LocationEditor = LocationEditorConnected;\n"],"names":["ViewType","styles","root","css","height","width","BerlinLocation","lat","lng","GoogleMapView","props","onGoogleApiLoaded","event","maps","map","marker","Marker","position","getCenter","cursor","_this","disabled","draggable","visible","Boolean","location","addListener","state","setPosition","latLng","setVisible","onChangeLocation","setState","undefined","componentDidUpdate","this","LatLng","setDraggable","setCursor","render","React","className","GoogleMapReact","bootstrapURLKeys","googleMapsKey","key","defaultCenter","center","options","scrollwheel","mapTypeId","defaultZoom","yesIWantToUseGoogleMapApiInternals","Component","input","spinner","right","top","zIndex","validationMessage","marginTop","tokens","spacingS","suggestion","transform","bottom","left","LocationSearchInput","useState","isSearching","setIsSearching","address","setAddress","hasError","setHasError","setSuggestion","useEffect","onGetAddressFromLocation","value","then","TextInput","testId","isInvalid","placeholder","onChange","e","target","onSearchAddress","length","formatted_address","Number","geometry","toString","slice","isDisabled","Spinner","Card","padding","Button","variant","onClick","ValidationMessage","display","flexDirection","alignItems","main","flexGrow","secondary","minWidth","textAlign","inputsRow","fontSize","fontSizeM","color","gray900","fontFamily","fontStackPrimary","splitter","spacingL","clearBtn","marginBottom","LocationSelector","Flex","Radio","flexBasis","id","Address","isChecked","view","onChangeView","Coordinates","htmlFor","String","type","max","min","step","TextLink","as","toLocationValue","coords","isNumber","lon","LocationEditor","throttle","mapsObject","Promise","resolve","Geocoder","geocode","result","addresses","item","find","localValue","_this2","setValue","selectedView","setSelectedView","LocationEditorConnected","field","parameters","instance","FieldConnector","isEqualValues","value1","value2","deepEqual","isInitiallyDisabled","externalReset","defaultProps"],"mappings":"0kBASA,ICDYA,EDCNC,EAAS,CACbC,KAAMC,MAAI,CACRC,OAAQ,QACRC,MAAO,UAILC,EAAiB,CACrBC,IAAK,QACLC,IAAK,aAgBMC,yBACCC,8BACJA,UAqBRC,kBAAoB,SAACC,OACXC,EAAcD,EAAdC,KAAMC,EAAQF,EAARE,IACRC,EAAS,IAAIF,EAAKG,OAAO,CAC7BF,IAAAA,EACAG,SAAUH,EAAII,YACdC,OAAQC,EAAKV,MAAMW,SAAW,cAAgB,OAC9CC,WAAYF,EAAKV,MAAMW,SACvBE,QAASC,QAAQJ,EAAKV,MAAMe,YAG9BZ,EAAKD,MAAMc,YAAYZ,EAAK,SAAS,SAACF,IAChCQ,EAAKV,MAAMW,UAAaD,EAAKO,MAAMZ,QAAWK,EAAKO,MAAMd,SAGxDc,MAAMZ,OAAOa,YAAYhB,EAAMiB,UAC/BF,MAAMZ,OAAOe,YAAW,KACxBpB,MAAMqB,iBAAiB,CAC1BxB,IAAKK,EAAMiB,OAAOtB,MAClBC,IAAKI,EAAMiB,OAAOrB,YAItBK,EAAKD,MAAMc,YAAYX,EAAQ,WAAW,SAACH,KACpCF,MAAMqB,iBAAiB,CAC1BxB,IAAKK,EAAMiB,OAAOtB,MAClBC,IAAKI,EAAMiB,OAAOrB,aAGjBwB,SAAS,CA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AgBC,OAGxCpG,gBAACiF,GACCpG,SAAUc,KAAKzB,MAAMW,UAA2B,OAAf4H,EACjCnE,MAAO4E,EACP1B,KAAM7F,KAAKzB,MAAMmJ,aACjB5B,aAAc,SAACD,GACb2B,EAAKjJ,MAAMoJ,gBAAgB9B,IAE7BjG,iBAAkB,SAAC6G,GACjBe,EAAK3H,SAAS,CAAE0H,WAAYd,IAC5Be,EAAKjJ,MAAMkJ,SAASjB,EAAgBC,KAEtCrD,gBAAiBpD,KAAKoD,gBACtBV,yBAA0B1C,KAAK0C,gCA3FLrC,sBAkGpBuH,EAAwBrJ,OAC9BsJ,EAAUtJ,EAAVsJ,MACFpH,EAAgBlC,EAAMuJ,WAAavJ,EAAMuJ,WAAWC,SAAStH,mBAAgBX,IAC3CO,WAAyBxC,EAAS8H,SAAnE+B,OAAcC,cAGnBtH,gBAAC2H,kBACCC,cAAe,SAACC,EAAQC,UACfC,EAAUF,EAAQC,IAE3BN,MAAOA,EACPQ,oBAAqB9J,EAAM8J,sBAE1B,mBAEGhI,gBAACuG,GAEClG,yBAJyB4H,cAKzB3F,QALFA,MAMEzD,WANKA,SAOLuI,WAPeA,SAQfhH,cAAeA,EACfiH,aAAcA,EACdC,gBAAiBA,OAQ7BC,EAAwBW,aAAe,CACrCF,qBAAqB,0BCvLOT"}
|
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import React__default, { useState, createElement, Component } from 'react';
|
|
2
|
-
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
3
|
-
import deepEqual from 'deep-equal';
|
|
4
|
-
import isNumber from 'lodash-es/isNumber';
|
|
5
|
-
import throttle from 'lodash-es/throttle';
|
|
6
|
-
import { css } from 'emotion';
|
|
7
|
-
import GoogleMapReact from 'google-map-react';
|
|
8
|
-
import { TextInput, Spinner, Card, Button, ValidationMessage, Flex, Radio, TextLink } from '@contentful/f36-components';
|
|
9
|
-
import tokens from '@contentful/f36-tokens';
|
|
10
|
-
|
|
11
|
-
function _inheritsLoose(subClass, superClass) {
|
|
12
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
13
|
-
subClass.prototype.constructor = subClass;
|
|
14
|
-
|
|
15
|
-
_setPrototypeOf(subClass, superClass);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _setPrototypeOf(o, p) {
|
|
19
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
20
|
-
o.__proto__ = p;
|
|
21
|
-
return o;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return _setPrototypeOf(o, p);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var styles = {
|
|
28
|
-
root: /*#__PURE__*/css({
|
|
29
|
-
height: '300px',
|
|
30
|
-
width: '100%'
|
|
31
|
-
})
|
|
32
|
-
};
|
|
33
|
-
var BerlinLocation = {
|
|
34
|
-
lat: 52.5018,
|
|
35
|
-
lng: 13.41115439
|
|
36
|
-
};
|
|
37
|
-
var GoogleMapView = /*#__PURE__*/function (_React$Component) {
|
|
38
|
-
_inheritsLoose(GoogleMapView, _React$Component);
|
|
39
|
-
|
|
40
|
-
function GoogleMapView(props) {
|
|
41
|
-
var _this;
|
|
42
|
-
|
|
43
|
-
_this = _React$Component.call(this, props) || this;
|
|
44
|
-
|
|
45
|
-
_this.onGoogleApiLoaded = function (event) {
|
|
46
|
-
var maps = event.maps,
|
|
47
|
-
map = event.map;
|
|
48
|
-
var marker = new maps.Marker({
|
|
49
|
-
map: map,
|
|
50
|
-
position: map.getCenter(),
|
|
51
|
-
cursor: _this.props.disabled ? 'not-allowed' : 'auto',
|
|
52
|
-
draggable: !_this.props.disabled,
|
|
53
|
-
visible: Boolean(_this.props.location)
|
|
54
|
-
});
|
|
55
|
-
maps.event.addListener(map, 'click', function (event) {
|
|
56
|
-
if (_this.props.disabled || !_this.state.marker || !_this.state.maps) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
_this.state.marker.setPosition(event.latLng);
|
|
61
|
-
|
|
62
|
-
_this.state.marker.setVisible(true);
|
|
63
|
-
|
|
64
|
-
_this.props.onChangeLocation({
|
|
65
|
-
lat: event.latLng.lat(),
|
|
66
|
-
lng: event.latLng.lng()
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
maps.event.addListener(marker, 'dragend', function (event) {
|
|
70
|
-
_this.props.onChangeLocation({
|
|
71
|
-
lat: event.latLng.lat(),
|
|
72
|
-
lng: event.latLng.lng()
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
_this.setState({
|
|
77
|
-
marker: marker,
|
|
78
|
-
maps: maps
|
|
79
|
-
}, function () {
|
|
80
|
-
_this.props.onGoogleApiLoaded({
|
|
81
|
-
maps: maps
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
_this.state = {
|
|
87
|
-
marker: undefined,
|
|
88
|
-
maps: undefined
|
|
89
|
-
};
|
|
90
|
-
return _this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
var _proto = GoogleMapView.prototype;
|
|
94
|
-
|
|
95
|
-
_proto.componentDidUpdate = function componentDidUpdate() {
|
|
96
|
-
if (this.state.marker && this.state.maps) {
|
|
97
|
-
if (this.props.location) {
|
|
98
|
-
var latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
|
|
99
|
-
this.state.marker.setPosition(latLng);
|
|
100
|
-
this.state.marker.setVisible(true);
|
|
101
|
-
} else {
|
|
102
|
-
this.state.marker.setVisible(false);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.state.marker.setDraggable(!this.props.disabled);
|
|
106
|
-
this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
_proto.render = function render() {
|
|
111
|
-
return React__default.createElement("div", {
|
|
112
|
-
className: styles.root
|
|
113
|
-
}, React__default.createElement(GoogleMapReact, {
|
|
114
|
-
draggable: !this.props.disabled,
|
|
115
|
-
bootstrapURLKeys: this.props.googleMapsKey ? {
|
|
116
|
-
key: this.props.googleMapsKey
|
|
117
|
-
} : undefined,
|
|
118
|
-
defaultCenter: BerlinLocation,
|
|
119
|
-
center: this.props.location,
|
|
120
|
-
options: {
|
|
121
|
-
scrollwheel: false,
|
|
122
|
-
mapTypeId: 'roadmap'
|
|
123
|
-
},
|
|
124
|
-
defaultZoom: 6,
|
|
125
|
-
yesIWantToUseGoogleMapApiInternals: true,
|
|
126
|
-
onGoogleApiLoaded: this.onGoogleApiLoaded
|
|
127
|
-
}));
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
return GoogleMapView;
|
|
131
|
-
}(React__default.Component);
|
|
132
|
-
|
|
133
|
-
var styles$1 = {
|
|
134
|
-
root: /*#__PURE__*/css({
|
|
135
|
-
width: '100%'
|
|
136
|
-
}),
|
|
137
|
-
input: /*#__PURE__*/css({
|
|
138
|
-
position: 'relative',
|
|
139
|
-
width: '100%'
|
|
140
|
-
}),
|
|
141
|
-
spinner: /*#__PURE__*/css({
|
|
142
|
-
position: 'absolute',
|
|
143
|
-
right: 10,
|
|
144
|
-
top: 10,
|
|
145
|
-
zIndex: 99
|
|
146
|
-
}),
|
|
147
|
-
validationMessage: /*#__PURE__*/css({
|
|
148
|
-
marginTop: tokens.spacingS
|
|
149
|
-
}),
|
|
150
|
-
suggestion: /*#__PURE__*/css({
|
|
151
|
-
position: 'absolute',
|
|
152
|
-
transform: 'translateY(100%)',
|
|
153
|
-
bottom: 0,
|
|
154
|
-
left: 0,
|
|
155
|
-
zIndex: 1
|
|
156
|
-
})
|
|
157
|
-
};
|
|
158
|
-
function LocationSearchInput(props) {
|
|
159
|
-
var _React$useState = React__default.useState(false),
|
|
160
|
-
isSearching = _React$useState[0],
|
|
161
|
-
setIsSearching = _React$useState[1];
|
|
162
|
-
|
|
163
|
-
var _React$useState2 = React__default.useState(''),
|
|
164
|
-
address = _React$useState2[0],
|
|
165
|
-
setAddress = _React$useState2[1];
|
|
166
|
-
|
|
167
|
-
var _React$useState3 = React__default.useState(false),
|
|
168
|
-
hasError = _React$useState3[0],
|
|
169
|
-
setHasError = _React$useState3[1];
|
|
170
|
-
|
|
171
|
-
var _React$useState4 = React__default.useState(null),
|
|
172
|
-
suggestion = _React$useState4[0],
|
|
173
|
-
setSuggestion = _React$useState4[1];
|
|
174
|
-
|
|
175
|
-
React__default.useEffect(function () {
|
|
176
|
-
setIsSearching(true);
|
|
177
|
-
props.onGetAddressFromLocation(props.value, address).then(function (address) {
|
|
178
|
-
setAddress(address);
|
|
179
|
-
setIsSearching(false);
|
|
180
|
-
}); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
181
|
-
}, [props.value, props.disabled]);
|
|
182
|
-
return React__default.createElement("div", {
|
|
183
|
-
className: styles$1.root
|
|
184
|
-
}, React__default.createElement("div", {
|
|
185
|
-
className: styles$1.input
|
|
186
|
-
}, React__default.createElement(TextInput, {
|
|
187
|
-
testId: "location-editor-search",
|
|
188
|
-
isInvalid: hasError,
|
|
189
|
-
placeholder: "Start typing to find location",
|
|
190
|
-
value: address,
|
|
191
|
-
onChange: function onChange(e) {
|
|
192
|
-
setAddress(e.target.value);
|
|
193
|
-
setHasError(false);
|
|
194
|
-
setSuggestion(null);
|
|
195
|
-
|
|
196
|
-
if (e.target.value === '') {
|
|
197
|
-
props.onChangeLocation(undefined);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
setIsSearching(true);
|
|
202
|
-
props.onSearchAddress(e.target.value).then(function (value) {
|
|
203
|
-
setIsSearching(false);
|
|
204
|
-
|
|
205
|
-
if (value === null) {
|
|
206
|
-
setHasError(false);
|
|
207
|
-
} else if (value.length === 0) {
|
|
208
|
-
setHasError(true);
|
|
209
|
-
} else {
|
|
210
|
-
setHasError(false);
|
|
211
|
-
setSuggestion({
|
|
212
|
-
address: value[0].formatted_address,
|
|
213
|
-
location: {
|
|
214
|
-
lat: Number(value[0].geometry.location.lat().toString().slice(0, 8)),
|
|
215
|
-
lng: Number(value[0].geometry.location.lng().toString().slice(0, 8))
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
},
|
|
221
|
-
isDisabled: props.disabled
|
|
222
|
-
}), isSearching && React__default.createElement(Spinner, {
|
|
223
|
-
className: styles$1.spinner
|
|
224
|
-
}), suggestion && React__default.createElement(Card, {
|
|
225
|
-
padding: "none",
|
|
226
|
-
className: styles$1.suggestion
|
|
227
|
-
}, React__default.createElement(Button, {
|
|
228
|
-
variant: "transparent",
|
|
229
|
-
testId: "location-editor-suggestion",
|
|
230
|
-
onClick: function onClick() {
|
|
231
|
-
setAddress(suggestion.address);
|
|
232
|
-
props.onChangeLocation(suggestion.location);
|
|
233
|
-
setSuggestion(null);
|
|
234
|
-
}
|
|
235
|
-
}, suggestion.address)), hasError && React__default.createElement(ValidationMessage, {
|
|
236
|
-
testId: "location-editor-not-found",
|
|
237
|
-
className: styles$1.validationMessage
|
|
238
|
-
}, "No results found for ", React__default.createElement("strong", null, address), ". Please make sure that address is spelled correctly.")));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
var ViewType;
|
|
242
|
-
|
|
243
|
-
(function (ViewType) {
|
|
244
|
-
ViewType["Address"] = "Address";
|
|
245
|
-
ViewType["Coordinates"] = "Coordinates";
|
|
246
|
-
})(ViewType || (ViewType = {}));
|
|
247
|
-
|
|
248
|
-
var styles$2 = {
|
|
249
|
-
root: /*#__PURE__*/css({
|
|
250
|
-
display: 'flex',
|
|
251
|
-
flexDirection: 'row',
|
|
252
|
-
marginTop: tokens.spacingS,
|
|
253
|
-
alignItems: 'flex-end'
|
|
254
|
-
}),
|
|
255
|
-
main: /*#__PURE__*/css({
|
|
256
|
-
flexGrow: 1
|
|
257
|
-
}),
|
|
258
|
-
secondary: /*#__PURE__*/css({
|
|
259
|
-
minWidth: '70px',
|
|
260
|
-
textAlign: 'right'
|
|
261
|
-
}),
|
|
262
|
-
inputsRow: /*#__PURE__*/css({
|
|
263
|
-
display: 'flex',
|
|
264
|
-
marginTop: tokens.spacingS,
|
|
265
|
-
fontSize: tokens.fontSizeM,
|
|
266
|
-
color: tokens.gray900,
|
|
267
|
-
fontFamily: tokens.fontStackPrimary,
|
|
268
|
-
alignItems: 'center'
|
|
269
|
-
}),
|
|
270
|
-
splitter: /*#__PURE__*/css({
|
|
271
|
-
width: tokens.spacingL
|
|
272
|
-
}),
|
|
273
|
-
clearBtn: /*#__PURE__*/css({
|
|
274
|
-
marginBottom: tokens.spacingS
|
|
275
|
-
})
|
|
276
|
-
};
|
|
277
|
-
function LocationSelector(props) {
|
|
278
|
-
return React__default.createElement("div", {
|
|
279
|
-
className: styles$2.root
|
|
280
|
-
}, React__default.createElement("div", {
|
|
281
|
-
className: styles$2.main
|
|
282
|
-
}, React__default.createElement(Flex, {
|
|
283
|
-
flexDirection: "row"
|
|
284
|
-
}, React__default.createElement(Radio, {
|
|
285
|
-
className: css({
|
|
286
|
-
flexBasis: '100%'
|
|
287
|
-
}),
|
|
288
|
-
id: ViewType.Address,
|
|
289
|
-
testId: "location-editor-address-radio",
|
|
290
|
-
isDisabled: props.disabled,
|
|
291
|
-
value: ViewType.Address,
|
|
292
|
-
isChecked: props.view === ViewType.Address,
|
|
293
|
-
onChange: function onChange() {
|
|
294
|
-
props.onChangeView(ViewType.Address);
|
|
295
|
-
}
|
|
296
|
-
}, "Address"), React__default.createElement(Radio, {
|
|
297
|
-
className: css({
|
|
298
|
-
flexBasis: '100%'
|
|
299
|
-
}),
|
|
300
|
-
id: ViewType.Coordinates,
|
|
301
|
-
testId: "location-editor-coordinates-radio",
|
|
302
|
-
isDisabled: props.disabled,
|
|
303
|
-
value: ViewType.Coordinates,
|
|
304
|
-
isChecked: props.view === ViewType.Coordinates,
|
|
305
|
-
onChange: function onChange() {
|
|
306
|
-
props.onChangeView(ViewType.Coordinates);
|
|
307
|
-
}
|
|
308
|
-
}, "Coordinates")), props.view === ViewType.Address && React__default.createElement("div", {
|
|
309
|
-
className: styles$2.inputsRow
|
|
310
|
-
}, React__default.createElement(LocationSearchInput, {
|
|
311
|
-
onSearchAddress: props.onSearchAddress,
|
|
312
|
-
onGetAddressFromLocation: props.onGetAddressFromLocation,
|
|
313
|
-
disabled: props.disabled,
|
|
314
|
-
value: props.value,
|
|
315
|
-
onChangeLocation: props.onChangeLocation
|
|
316
|
-
})), props.view === ViewType.Coordinates && React__default.createElement("div", {
|
|
317
|
-
className: styles$2.inputsRow
|
|
318
|
-
}, React__default.createElement("label", {
|
|
319
|
-
htmlFor: "latitude"
|
|
320
|
-
}, "Latitude"), React__default.createElement("div", {
|
|
321
|
-
className: styles$2.splitter
|
|
322
|
-
}), React__default.createElement(TextInput, {
|
|
323
|
-
id: "latitude",
|
|
324
|
-
testId: "location-editor-latitude",
|
|
325
|
-
placeholder: "Between -90 and 90",
|
|
326
|
-
isDisabled: props.disabled,
|
|
327
|
-
value: props.value ? String(props.value.lat) : '',
|
|
328
|
-
onChange: function onChange(e) {
|
|
329
|
-
props.onChangeLocation({
|
|
330
|
-
lng: props.value && props.value.lng !== undefined ? props.value.lng : 0,
|
|
331
|
-
lat: Number(e.target.value) || 0
|
|
332
|
-
});
|
|
333
|
-
},
|
|
334
|
-
type: "number",
|
|
335
|
-
max: "90",
|
|
336
|
-
min: "-90",
|
|
337
|
-
step: "0.1"
|
|
338
|
-
}), React__default.createElement("div", {
|
|
339
|
-
className: styles$2.splitter
|
|
340
|
-
}), React__default.createElement("label", {
|
|
341
|
-
htmlFor: "longitude"
|
|
342
|
-
}, "Longitude"), React__default.createElement("div", {
|
|
343
|
-
className: styles$2.splitter
|
|
344
|
-
}), React__default.createElement(TextInput, {
|
|
345
|
-
id: "longitude",
|
|
346
|
-
testId: "location-editor-longitude",
|
|
347
|
-
placeholder: "Between -180 and 180",
|
|
348
|
-
isDisabled: props.disabled,
|
|
349
|
-
value: props.value ? String(props.value.lng) : '',
|
|
350
|
-
onChange: function onChange(e) {
|
|
351
|
-
props.onChangeLocation({
|
|
352
|
-
lat: props.value && props.value.lat !== undefined ? props.value.lat : 0,
|
|
353
|
-
lng: Number(e.target.value) || 0
|
|
354
|
-
});
|
|
355
|
-
},
|
|
356
|
-
type: "number",
|
|
357
|
-
max: "180",
|
|
358
|
-
min: "-180",
|
|
359
|
-
step: "0.1"
|
|
360
|
-
}))), React__default.createElement("div", {
|
|
361
|
-
className: styles$2.secondary
|
|
362
|
-
}, React__default.createElement(TextLink, {
|
|
363
|
-
as: "button",
|
|
364
|
-
isDisabled: props.disabled,
|
|
365
|
-
testId: "location-editor-clear",
|
|
366
|
-
className: styles$2.clearBtn,
|
|
367
|
-
onClick: function onClick() {
|
|
368
|
-
props.onChangeLocation(undefined);
|
|
369
|
-
}
|
|
370
|
-
}, "Clear")));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function toLocationValue(coords) {
|
|
374
|
-
if (coords && isNumber(coords.lat) && isNumber(coords.lng)) {
|
|
375
|
-
return {
|
|
376
|
-
lat: coords.lat,
|
|
377
|
-
lon: coords.lng
|
|
378
|
-
};
|
|
379
|
-
} else {
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
var LocationEditor = /*#__PURE__*/function (_React$Component) {
|
|
385
|
-
_inheritsLoose(LocationEditor, _React$Component);
|
|
386
|
-
|
|
387
|
-
function LocationEditor(props) {
|
|
388
|
-
var _this;
|
|
389
|
-
|
|
390
|
-
_this = _React$Component.call(this, props) || this;
|
|
391
|
-
_this.onSearchAddress = throttle(function (value) {
|
|
392
|
-
if (!_this.state.mapsObject) {
|
|
393
|
-
return Promise.resolve(null);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
var mapsObject = _this.state.mapsObject;
|
|
397
|
-
|
|
398
|
-
if (!value) {
|
|
399
|
-
return Promise.resolve(null);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return new Promise(function (resolve) {
|
|
403
|
-
var geocoder = new mapsObject.Geocoder();
|
|
404
|
-
geocoder.geocode({
|
|
405
|
-
address: value
|
|
406
|
-
}, resolve, function () {
|
|
407
|
-
resolve(null);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
}, 300);
|
|
411
|
-
|
|
412
|
-
_this.onGetAddressFromLocation = function (location, value) {
|
|
413
|
-
if (!_this.state.mapsObject || !location) {
|
|
414
|
-
return Promise.resolve('');
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
var mapsObject = _this.state.mapsObject;
|
|
418
|
-
return new Promise(function (resolve) {
|
|
419
|
-
var geocoder = new mapsObject.Geocoder();
|
|
420
|
-
geocoder.geocode({
|
|
421
|
-
location: location
|
|
422
|
-
}, function (result) {
|
|
423
|
-
if (result && result.length > 0) {
|
|
424
|
-
var addresses = result.map(function (item) {
|
|
425
|
-
return item.formatted_address;
|
|
426
|
-
});
|
|
427
|
-
resolve(addresses.find(function (item) {
|
|
428
|
-
return item === value;
|
|
429
|
-
}) || addresses[0]);
|
|
430
|
-
} else {
|
|
431
|
-
resolve('');
|
|
432
|
-
}
|
|
433
|
-
}, function () {
|
|
434
|
-
resolve('');
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
_this.state = {
|
|
440
|
-
localValue: props.value ? {
|
|
441
|
-
lng: props.value.lon,
|
|
442
|
-
lat: props.value.lat
|
|
443
|
-
} : undefined,
|
|
444
|
-
mapsObject: null
|
|
445
|
-
};
|
|
446
|
-
return _this;
|
|
447
|
-
} // @ts-expect-error
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
var _proto = LocationEditor.prototype;
|
|
451
|
-
|
|
452
|
-
_proto.render = function render() {
|
|
453
|
-
var _this2 = this;
|
|
454
|
-
|
|
455
|
-
var _this$state = this.state,
|
|
456
|
-
mapsObject = _this$state.mapsObject,
|
|
457
|
-
localValue = _this$state.localValue;
|
|
458
|
-
return createElement("div", {
|
|
459
|
-
"data-test-id": "location-editor"
|
|
460
|
-
}, createElement(GoogleMapView, {
|
|
461
|
-
disabled: this.props.disabled || mapsObject === null,
|
|
462
|
-
googleMapsKey: this.props.googleMapsKey,
|
|
463
|
-
location: localValue,
|
|
464
|
-
onGoogleApiLoaded: function onGoogleApiLoaded(_ref) {
|
|
465
|
-
var maps = _ref.maps;
|
|
466
|
-
|
|
467
|
-
_this2.setState({
|
|
468
|
-
mapsObject: maps
|
|
469
|
-
});
|
|
470
|
-
},
|
|
471
|
-
onChangeLocation: function onChangeLocation(coords) {
|
|
472
|
-
_this2.setState({
|
|
473
|
-
localValue: coords
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
_this2.props.setValue(toLocationValue(coords));
|
|
477
|
-
}
|
|
478
|
-
}), createElement(LocationSelector, {
|
|
479
|
-
disabled: this.props.disabled || mapsObject === null,
|
|
480
|
-
value: localValue,
|
|
481
|
-
view: this.props.selectedView,
|
|
482
|
-
onChangeView: function onChangeView(view) {
|
|
483
|
-
_this2.props.setSelectedView(view);
|
|
484
|
-
},
|
|
485
|
-
onChangeLocation: function onChangeLocation(coords) {
|
|
486
|
-
_this2.setState({
|
|
487
|
-
localValue: coords
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
_this2.props.setValue(toLocationValue(coords));
|
|
491
|
-
},
|
|
492
|
-
onSearchAddress: this.onSearchAddress,
|
|
493
|
-
onGetAddressFromLocation: this.onGetAddressFromLocation
|
|
494
|
-
}));
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
return LocationEditor;
|
|
498
|
-
}(Component);
|
|
499
|
-
function LocationEditorConnected(props) {
|
|
500
|
-
var field = props.field;
|
|
501
|
-
var googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;
|
|
502
|
-
|
|
503
|
-
var _React$useState = useState(ViewType.Address),
|
|
504
|
-
selectedView = _React$useState[0],
|
|
505
|
-
setSelectedView = _React$useState[1];
|
|
506
|
-
|
|
507
|
-
return createElement(FieldConnector, {
|
|
508
|
-
isEqualValues: function isEqualValues(value1, value2) {
|
|
509
|
-
return deepEqual(value1, value2);
|
|
510
|
-
},
|
|
511
|
-
field: field,
|
|
512
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
513
|
-
}, function (_ref2) {
|
|
514
|
-
var value = _ref2.value,
|
|
515
|
-
disabled = _ref2.disabled,
|
|
516
|
-
setValue = _ref2.setValue,
|
|
517
|
-
externalReset = _ref2.externalReset;
|
|
518
|
-
return createElement(LocationEditor // on external change reset component completely and init with initial value again
|
|
519
|
-
, {
|
|
520
|
-
// on external change reset component completely and init with initial value again
|
|
521
|
-
key: "location-editor-" + externalReset,
|
|
522
|
-
value: value,
|
|
523
|
-
disabled: disabled,
|
|
524
|
-
setValue: setValue,
|
|
525
|
-
googleMapsKey: googleMapsKey,
|
|
526
|
-
selectedView: selectedView,
|
|
527
|
-
setSelectedView: setSelectedView
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
LocationEditorConnected.defaultProps = {
|
|
532
|
-
isInitiallyDisabled: true
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
var LocationEditor$1 = LocationEditorConnected;
|
|
536
|
-
|
|
537
|
-
export { LocationEditor$1 as LocationEditor };
|
|
538
|
-
//# sourceMappingURL=field-editor-location.esm.js.map
|