@contentful/field-editor-location 1.1.9 → 1.2.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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-location@1.1.10...@contentful/field-editor-location@1.2.0) (2023-03-09)
7
+
8
+ ### Features
9
+
10
+ - upgrade google-maps-react [TOL-968] ([#1365](https://github.com/contentful/field-editors/issues/1365)) ([e6ffb47](https://github.com/contentful/field-editors/commit/e6ffb47fa1487ef7d60dc537f89fcb45aa140ce7))
11
+
12
+ ## [1.1.10](https://github.com/contentful/field-editors/compare/@contentful/field-editor-location@1.1.9...@contentful/field-editor-location@1.1.10) (2023-02-21)
13
+
14
+ **Note:** Version bump only for package @contentful/field-editor-location
15
+
6
16
  ## [1.1.9](https://github.com/contentful/field-editors/compare/@contentful/field-editor-location@1.1.8...@contentful/field-editor-location@1.1.9) (2023-02-07)
7
17
 
8
18
  **Note:** Version bump only for package @contentful/field-editor-location
@@ -6,14 +6,14 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var React = require('react');
8
8
  var React__default = _interopDefault(React);
9
- var isNumber = _interopDefault(require('lodash/isNumber'));
10
- var throttle = _interopDefault(require('lodash/throttle'));
11
9
  var fieldEditorShared = require('@contentful/field-editor-shared');
12
10
  var deepEqual = _interopDefault(require('deep-equal'));
11
+ var isNumber = _interopDefault(require('lodash/isNumber'));
12
+ var throttle = _interopDefault(require('lodash/throttle'));
13
13
  var emotion = require('emotion');
14
- var tokens = _interopDefault(require('@contentful/f36-tokens'));
15
- var f36Components = require('@contentful/f36-components');
16
14
  var GoogleMapReact = _interopDefault(require('google-map-react'));
15
+ var f36Components = require('@contentful/f36-components');
16
+ var tokens = _interopDefault(require('@contentful/f36-tokens'));
17
17
 
18
18
  function _inheritsLoose(subClass, superClass) {
19
19
  subClass.prototype = Object.create(superClass.prototype);
@@ -31,14 +31,113 @@ function _setPrototypeOf(o, p) {
31
31
  return _setPrototypeOf(o, p);
32
32
  }
33
33
 
34
- var ViewType;
34
+ var styles = {
35
+ root: /*#__PURE__*/emotion.css({
36
+ height: '300px',
37
+ width: '100%'
38
+ })
39
+ };
40
+ var BerlinLocation = {
41
+ lat: 52.5018,
42
+ lng: 13.41115439
43
+ };
44
+ var GoogleMapView = /*#__PURE__*/function (_React$Component) {
45
+ _inheritsLoose(GoogleMapView, _React$Component);
35
46
 
36
- (function (ViewType) {
37
- ViewType["Address"] = "Address";
38
- ViewType["Coordinates"] = "Coordinates";
39
- })(ViewType || (ViewType = {}));
47
+ function GoogleMapView(props) {
48
+ var _this;
40
49
 
41
- var styles = {
50
+ _this = _React$Component.call(this, props) || this;
51
+
52
+ _this.onGoogleApiLoaded = function (event) {
53
+ var maps = event.maps,
54
+ map = event.map;
55
+ var marker = new maps.Marker({
56
+ map: map,
57
+ position: map.getCenter(),
58
+ cursor: _this.props.disabled ? 'not-allowed' : 'auto',
59
+ draggable: !_this.props.disabled,
60
+ visible: Boolean(_this.props.location)
61
+ });
62
+ maps.event.addListener(map, 'click', function (event) {
63
+ if (_this.props.disabled || !_this.state.marker || !_this.state.maps) {
64
+ return;
65
+ }
66
+
67
+ _this.state.marker.setPosition(event.latLng);
68
+
69
+ _this.state.marker.setVisible(true);
70
+
71
+ _this.props.onChangeLocation({
72
+ lat: event.latLng.lat(),
73
+ lng: event.latLng.lng()
74
+ });
75
+ });
76
+ maps.event.addListener(marker, 'dragend', function (event) {
77
+ _this.props.onChangeLocation({
78
+ lat: event.latLng.lat(),
79
+ lng: event.latLng.lng()
80
+ });
81
+ });
82
+
83
+ _this.setState({
84
+ marker: marker,
85
+ maps: maps
86
+ }, function () {
87
+ _this.props.onGoogleApiLoaded({
88
+ maps: maps
89
+ });
90
+ });
91
+ };
92
+
93
+ _this.state = {
94
+ marker: undefined,
95
+ maps: undefined
96
+ };
97
+ return _this;
98
+ }
99
+
100
+ var _proto = GoogleMapView.prototype;
101
+
102
+ _proto.componentDidUpdate = function componentDidUpdate() {
103
+ if (this.state.marker && this.state.maps) {
104
+ if (this.props.location) {
105
+ var latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
106
+ this.state.marker.setPosition(latLng);
107
+ this.state.marker.setVisible(true);
108
+ } else {
109
+ this.state.marker.setVisible(false);
110
+ }
111
+
112
+ this.state.marker.setDraggable(!this.props.disabled);
113
+ this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
114
+ }
115
+ };
116
+
117
+ _proto.render = function render() {
118
+ return React__default.createElement("div", {
119
+ className: styles.root
120
+ }, React__default.createElement(GoogleMapReact, {
121
+ draggable: !this.props.disabled,
122
+ bootstrapURLKeys: this.props.googleMapsKey ? {
123
+ key: this.props.googleMapsKey
124
+ } : undefined,
125
+ defaultCenter: BerlinLocation,
126
+ center: this.props.location,
127
+ options: {
128
+ scrollwheel: false,
129
+ mapTypeId: 'roadmap'
130
+ },
131
+ defaultZoom: 6,
132
+ yesIWantToUseGoogleMapApiInternals: true,
133
+ onGoogleApiLoaded: this.onGoogleApiLoaded
134
+ }));
135
+ };
136
+
137
+ return GoogleMapView;
138
+ }(React__default.Component);
139
+
140
+ var styles$1 = {
42
141
  root: /*#__PURE__*/emotion.css({
43
142
  width: '100%'
44
143
  }),
@@ -88,9 +187,9 @@ function LocationSearchInput(props) {
88
187
  }); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
89
188
  }, [props.value, props.disabled]);
90
189
  return React__default.createElement("div", {
91
- className: styles.root
190
+ className: styles$1.root
92
191
  }, React__default.createElement("div", {
93
- className: styles.input
192
+ className: styles$1.input
94
193
  }, React__default.createElement(f36Components.TextInput, {
95
194
  testId: "location-editor-search",
96
195
  isInvalid: hasError,
@@ -128,10 +227,10 @@ function LocationSearchInput(props) {
128
227
  },
129
228
  isDisabled: props.disabled
130
229
  }), isSearching && React__default.createElement(f36Components.Spinner, {
131
- className: styles.spinner
230
+ className: styles$1.spinner
132
231
  }), suggestion && React__default.createElement(f36Components.Card, {
133
232
  padding: "none",
134
- className: styles.suggestion
233
+ className: styles$1.suggestion
135
234
  }, React__default.createElement(f36Components.Button, {
136
235
  variant: "transparent",
137
236
  testId: "location-editor-suggestion",
@@ -142,11 +241,18 @@ function LocationSearchInput(props) {
142
241
  }
143
242
  }, suggestion.address)), hasError && React__default.createElement(f36Components.ValidationMessage, {
144
243
  testId: "location-editor-not-found",
145
- className: styles.validationMessage
244
+ className: styles$1.validationMessage
146
245
  }, "No results found for ", React__default.createElement("strong", null, address), ". Please make sure that address is spelled correctly.")));
147
246
  }
148
247
 
149
- var styles$1 = {
248
+ var ViewType;
249
+
250
+ (function (ViewType) {
251
+ ViewType["Address"] = "Address";
252
+ ViewType["Coordinates"] = "Coordinates";
253
+ })(ViewType || (ViewType = {}));
254
+
255
+ var styles$2 = {
150
256
  root: /*#__PURE__*/emotion.css({
151
257
  display: 'flex',
152
258
  flexDirection: 'row',
@@ -177,9 +283,9 @@ var styles$1 = {
177
283
  };
178
284
  function LocationSelector(props) {
179
285
  return React__default.createElement("div", {
180
- className: styles$1.root
286
+ className: styles$2.root
181
287
  }, React__default.createElement("div", {
182
- className: styles$1.main
288
+ className: styles$2.main
183
289
  }, React__default.createElement(f36Components.Flex, {
184
290
  flexDirection: "row"
185
291
  }, React__default.createElement(f36Components.Radio, {
@@ -207,7 +313,7 @@ function LocationSelector(props) {
207
313
  props.onChangeView(ViewType.Coordinates);
208
314
  }
209
315
  }, "Coordinates")), props.view === ViewType.Address && React__default.createElement("div", {
210
- className: styles$1.inputsRow
316
+ className: styles$2.inputsRow
211
317
  }, React__default.createElement(LocationSearchInput, {
212
318
  onSearchAddress: props.onSearchAddress,
213
319
  onGetAddressFromLocation: props.onGetAddressFromLocation,
@@ -215,11 +321,11 @@ function LocationSelector(props) {
215
321
  value: props.value,
216
322
  onChangeLocation: props.onChangeLocation
217
323
  })), props.view === ViewType.Coordinates && React__default.createElement("div", {
218
- className: styles$1.inputsRow
324
+ className: styles$2.inputsRow
219
325
  }, React__default.createElement("label", {
220
326
  htmlFor: "latitude"
221
327
  }, "Latitude"), React__default.createElement("div", {
222
- className: styles$1.splitter
328
+ className: styles$2.splitter
223
329
  }), React__default.createElement(f36Components.TextInput, {
224
330
  id: "latitude",
225
331
  testId: "location-editor-latitude",
@@ -237,11 +343,11 @@ function LocationSelector(props) {
237
343
  min: "-90",
238
344
  step: "0.1"
239
345
  }), React__default.createElement("div", {
240
- className: styles$1.splitter
346
+ className: styles$2.splitter
241
347
  }), React__default.createElement("label", {
242
348
  htmlFor: "longitude"
243
349
  }, "Longitude"), React__default.createElement("div", {
244
- className: styles$1.splitter
350
+ className: styles$2.splitter
245
351
  }), React__default.createElement(f36Components.TextInput, {
246
352
  id: "longitude",
247
353
  testId: "location-editor-longitude",
@@ -259,124 +365,18 @@ function LocationSelector(props) {
259
365
  min: "-180",
260
366
  step: "0.1"
261
367
  }))), React__default.createElement("div", {
262
- className: styles$1.secondary
368
+ className: styles$2.secondary
263
369
  }, React__default.createElement(f36Components.TextLink, {
264
370
  as: "button",
265
371
  isDisabled: props.disabled,
266
372
  testId: "location-editor-clear",
267
- className: styles$1.clearBtn,
373
+ className: styles$2.clearBtn,
268
374
  onClick: function onClick() {
269
375
  props.onChangeLocation(undefined);
270
376
  }
271
377
  }, "Clear")));
272
378
  }
273
379
 
274
- var styles$2 = {
275
- root: /*#__PURE__*/emotion.css({
276
- height: '300px',
277
- width: '100%'
278
- })
279
- };
280
- var BerlinLocation = {
281
- lat: 52.5018,
282
- lng: 13.41115439
283
- };
284
- var GoogleMapView = /*#__PURE__*/function (_React$Component) {
285
- _inheritsLoose(GoogleMapView, _React$Component);
286
-
287
- function GoogleMapView(props) {
288
- var _this;
289
-
290
- _this = _React$Component.call(this, props) || this;
291
-
292
- _this.onGoogleApiLoaded = function (event) {
293
- var maps = event.maps,
294
- map = event.map;
295
- var marker = new maps.Marker({
296
- map: map,
297
- position: map.getCenter(),
298
- cursor: _this.props.disabled ? 'not-allowed' : 'auto',
299
- draggable: !_this.props.disabled,
300
- visible: Boolean(_this.props.location)
301
- });
302
- maps.event.addListener(map, 'click', function (event) {
303
- if (_this.props.disabled || !_this.state.marker || !_this.state.maps) {
304
- return;
305
- }
306
-
307
- _this.state.marker.setPosition(event.latLng);
308
-
309
- _this.state.marker.setVisible(true);
310
-
311
- _this.props.onChangeLocation({
312
- lat: event.latLng.lat(),
313
- lng: event.latLng.lng()
314
- });
315
- });
316
- maps.event.addListener(marker, 'dragend', function (event) {
317
- _this.props.onChangeLocation({
318
- lat: event.latLng.lat(),
319
- lng: event.latLng.lng()
320
- });
321
- });
322
-
323
- _this.setState({
324
- marker: marker,
325
- maps: maps
326
- }, function () {
327
- _this.props.onGoogleApiLoaded({
328
- maps: maps
329
- });
330
- });
331
- };
332
-
333
- _this.state = {
334
- marker: undefined,
335
- maps: undefined
336
- };
337
- return _this;
338
- }
339
-
340
- var _proto = GoogleMapView.prototype;
341
-
342
- _proto.componentDidUpdate = function componentDidUpdate() {
343
- if (this.state.marker && this.state.maps) {
344
- if (this.props.location) {
345
- var latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
346
- this.state.marker.setPosition(latLng);
347
- this.state.marker.setVisible(true);
348
- } else {
349
- this.state.marker.setVisible(false);
350
- }
351
-
352
- this.state.marker.setDraggable(!this.props.disabled);
353
- this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
354
- }
355
- };
356
-
357
- _proto.render = function render() {
358
- return React__default.createElement("div", {
359
- className: styles$2.root
360
- }, React__default.createElement(GoogleMapReact, {
361
- draggable: !this.props.disabled,
362
- bootstrapURLKeys: this.props.googleMapsKey ? {
363
- key: this.props.googleMapsKey
364
- } : undefined,
365
- defaultCenter: BerlinLocation,
366
- center: this.props.location,
367
- options: {
368
- scrollwheel: false,
369
- mapTypeId: 'roadmap'
370
- },
371
- defaultZoom: 6,
372
- yesIWantToUseGoogleMapApiInternals: true,
373
- onGoogleApiLoaded: this.onGoogleApiLoaded
374
- }));
375
- };
376
-
377
- return GoogleMapView;
378
- }(React__default.Component);
379
-
380
380
  function toLocationValue(coords) {
381
381
  if (coords && isNumber(coords.lat) && isNumber(coords.lng)) {
382
382
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"field-editor-location.cjs.development.js","sources":["../src/types.ts","../src/LocationSearchInput.tsx","../src/LocationSelector.tsx","../src/GoogleMapView.tsx","../src/LocationEditor.tsx","../src/index.tsx"],"sourcesContent":["export { Coords } from 'google-map-react';\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';\nimport { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { Button, Card } from '@contentful/f36-components';\nimport { Coords, GeocodeApiResponse } from './types';\n\nimport { Spinner, ValidationMessage, TextInput } from '@contentful/f36-components';\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] =\n 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 {suggestion.address}\n </Button>\n </Card>\n )}\n {hasError && (\n <ValidationMessage\n testId=\"location-editor-not-found\"\n className={styles.validationMessage}>\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';\nimport { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\nimport { LocationSearchInput } from './LocationSearchInput';\n\nimport { Coords, ViewType, GeocodeApiResponse } from './types';\n\nimport { TextLink, TextInput, Radio, Flex } from '@contentful/f36-components';\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 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 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 Clear\n </TextLink>\n </div>\n </div>\n );\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport React from 'react';\nimport { css } from 'emotion';\nimport GoogleMapReact from 'google-map-react';\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","import * as React from 'react';\nimport isNumber from 'lodash/isNumber';\nimport throttle from 'lodash/throttle';\nimport { FieldAPI, FieldConnector, ParametersAPI } from '@contentful/field-editor-shared';\nimport deepEqual from 'deep-equal';\nimport {\n LocationValue,\n ViewType,\n NullableLocationValue,\n Coords,\n GeocodeApiResponse,\n} from './types';\nimport { LocationSelector } from './LocationSelector';\nimport { GoogleMapView } from './GoogleMapView';\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 {({ 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","width","input","position","spinner","right","top","zIndex","validationMessage","marginTop","tokens","spacingS","suggestion","transform","bottom","left","LocationSearchInput","props","React","useState","isSearching","setIsSearching","address","setAddress","hasError","setHasError","setSuggestion","useEffect","onGetAddressFromLocation","value","then","disabled","className","TextInput","testId","isInvalid","placeholder","onChange","e","target","onChangeLocation","undefined","onSearchAddress","length","formatted_address","location","lat","Number","geometry","toString","slice","lng","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","height","BerlinLocation","GoogleMapView","onGoogleApiLoaded","event","maps","map","marker","Marker","getCenter","cursor","draggable","visible","Boolean","addListener","state","setPosition","latLng","setVisible","setState","componentDidUpdate","LatLng","setDraggable","setCursor","render","GoogleMapReact","bootstrapURLKeys","googleMapsKey","key","defaultCenter","center","options","scrollwheel","mapTypeId","defaultZoom","yesIWantToUseGoogleMapApiInternals","Component","toLocationValue","coords","isNumber","lon","LocationEditor","throttle","mapsObject","Promise","resolve","geocoder","Geocoder","geocode","result","addresses","item","find","localValue","setValue","selectedView","setSelectedView","LocationEditorConnected","field","parameters","instance","FieldConnector","isEqualValues","value1","value2","deepEqual","isInitiallyDisabled","externalReset","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAYA,QAAZ;;AAAA,WAAYA;AACVA,EAAAA,mBAAA,YAAA;AACAA,EAAAA,uBAAA,gBAAA;AACD,CAHD,EAAYA,QAAQ,KAARA,QAAQ,KAAA,CAApB;;ACGA,IAAMC,MAAM,GAAG;AACbC,EAAAA,IAAI,eAAEC,WAAG,CAAC;AACRC,IAAAA,KAAK,EAAE;AADC,GAAD,CADI;AAIbC,EAAAA,KA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AAA;AAC7B,WACElJ,mBAAA,CAACwH,cAAD;AAAA;AACE;AACAb,MAAAA,GAAG,uBAAqBuC;AACxBvI,MAAAA,KAAK,EAAEA;AACPE,MAAAA,QAAQ,EAAEA;AACVwH,MAAAA,QAAQ,EAAEA;AACV3B,MAAAA,aAAa,EAAEA;AACf4B,MAAAA,YAAY,EAAEA;AACdC,MAAAA,eAAe,EAAEA;KARnB,CADF;AAYD,GAnBH,CADF;AAuBD;AAEDC,uBAAuB,CAACW,YAAxB,GAAuC;AACrCF,EAAAA,mBAAmB,EAAE;AADgB,CAAvC;;ICnLazB,gBAAc,GAAGgB,uBAAvB;;;;"}
1
+ {"version":3,"file":"field-editor-location.cjs.development.js","sources":["../src/GoogleMapView.tsx","../src/LocationSearchInput.tsx","../src/types.ts","../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","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","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 { 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":["styles","root","css","height","width","BerlinLocation","lat","lng","GoogleMapView","props","onGoogleApiLoaded","event","maps","map","marker","Marker","position","getCenter","cursor","disabled","draggable","visible","Boolean","location","addListener","state","setPosition","latLng","setVisible","onChangeLocation","setState","undefined","componentDidUpdate","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","ViewType","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","Geocoder","geocode","result","addresses","item","find","localValue","setValue","selectedView","setSelectedView","LocationEditorConnected","field","parameters","instance","FieldConnector","isEqualValues","value1","value2","deepEqual","isInitiallyDisabled","externalReset","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAMA,MAAM,GAAG;AACbC,EAAAA,IAAI,eAAEC,WAAG,CAAC;AACRC,IAAAA,MAAM,EAAE,OADA;AAERC,IAAAA,KAAK,EAAE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,MAAD,EAASC,MAAT;AACb,aAAOC,SAAS,CAACF,MAAD,EAASC,MAAT,CAAhB;AACD;AACDN,IAAAA,KAAK,EAAEA;AACPQ,IAAAA,mBAAmB,EAAE7J,KAAK,CAAC6J;GAL7B,EAOG;QAAG3F,cAAAA;QAAOxD,iBAAAA;QAAUuI,iBAAAA;QAAUa,sBAAAA;AAC7B,WACElI,mBAAA,CAACwG,cAAD;AAAA;AACE;AACAnG,MAAAA,GAAG,uBAAqB6H;AACxB5F,MAAAA,KAAK,EAAEA;AACPxD,MAAAA,QAAQ,EAAEA;AACVuI,MAAAA,QAAQ,EAAEA;AACVjH,MAAAA,aAAa,EAAEA;AACfkH,MAAAA,YAAY,EAAEA;AACdC,MAAAA,eAAe,EAAEA;KARnB,CADF;AAYD,GApBH,CADF;AAwBD;AAEDC,uBAAuB,CAACW,YAAxB,GAAuC;AACrCF,EAAAA,mBAAmB,EAAE;AADgB,CAAvC;;ICtLazB,gBAAc,GAAGgB,uBAAvB;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t,a=require("react"),o=e(a),n=e(require("lodash/isNumber")),s=e(require("lodash/throttle")),i=require("@contentful/field-editor-shared"),r=e(require("deep-equal")),l=require("emotion"),d=e(require("@contentful/f36-tokens")),c=require("@contentful/f36-components"),u=e(require("google-map-react"));function p(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}!function(e){e.Address="Address",e.Coordinates="Coordinates"}(t||(t={}));var m={root:l.css({width:"100%"}),input:l.css({position:"relative",width:"100%"}),spinner:l.css({position:"absolute",right:10,top:10,zIndex:99}),validationMessage:l.css({marginTop:d.spacingS}),suggestion:l.css({position:"absolute",transform:"translateY(100%)",bottom:0,left:0,zIndex:1})};function g(e){var t=o.useState(!1),a=t[0],n=t[1],s=o.useState(""),i=s[0],r=s[1],l=o.useState(!1),d=l[0],u=l[1],p=o.useState(null),g=p[0],f=p[1];return o.useEffect((function(){n(!0),e.onGetAddressFromLocation(e.value,i).then((function(e){r(e),n(!1)}))}),[e.value,e.disabled]),o.createElement("div",{className:m.root},o.createElement("div",{className:m.input},o.createElement(c.TextInput,{testId:"location-editor-search",isInvalid:d,placeholder:"Start typing to find location",value:i,onChange:function(t){r(t.target.value),u(!1),f(null),""!==t.target.value?(n(!0),e.onSearchAddress(t.target.value).then((function(e){n(!1),null===e?u(!1):0===e.length?u(!0):(u(!1),f({address:e[0].formatted_address,location:{lat:Number(e[0].geometry.location.lat().toString().slice(0,8)),lng:Number(e[0].geometry.location.lng().toString().slice(0,8))}}))}))):e.onChangeLocation(void 0)},isDisabled:e.disabled}),a&&o.createElement(c.Spinner,{className:m.spinner}),g&&o.createElement(c.Card,{padding:"none",className:m.suggestion},o.createElement(c.Button,{variant:"transparent",testId:"location-editor-suggestion",onClick:function(){r(g.address),e.onChangeLocation(g.location),f(null)}},g.address)),d&&o.createElement(c.ValidationMessage,{testId:"location-editor-not-found",className:m.validationMessage},"No results found for ",o.createElement("strong",null,i),". Please make sure that address is spelled correctly.")))}var f={root:l.css({display:"flex",flexDirection:"row",marginTop:d.spacingS,alignItems:"flex-end"}),main:l.css({flexGrow:1}),secondary:l.css({minWidth:"70px",textAlign:"right"}),inputsRow:l.css({display:"flex",marginTop:d.spacingS,fontSize:d.fontSizeM,color:d.gray900,fontFamily:d.fontStackPrimary,alignItems:"center"}),splitter:l.css({width:d.spacingL}),clearBtn:l.css({marginBottom:d.spacingS})};function v(e){return o.createElement("div",{className:f.root},o.createElement("div",{className:f.main},o.createElement(c.Flex,{flexDirection:"row"},o.createElement(c.Radio,{className:l.css({flexBasis:"100%"}),id:t.Address,testId:"location-editor-address-radio",isDisabled:e.disabled,value:t.Address,isChecked:e.view===t.Address,onChange:function(){e.onChangeView(t.Address)}},"Address"),o.createElement(c.Radio,{className:l.css({flexBasis:"100%"}),id:t.Coordinates,testId:"location-editor-coordinates-radio",isDisabled:e.disabled,value:t.Coordinates,isChecked:e.view===t.Coordinates,onChange:function(){e.onChangeView(t.Coordinates)}},"Coordinates")),e.view===t.Address&&o.createElement("div",{className:f.inputsRow},o.createElement(g,{onSearchAddress:e.onSearchAddress,onGetAddressFromLocation:e.onGetAddressFromLocation,disabled:e.disabled,value:e.value,onChangeLocation:e.onChangeLocation})),e.view===t.Coordinates&&o.createElement("div",{className:f.inputsRow},o.createElement("label",{htmlFor:"latitude"},"Latitude"),o.createElement("div",{className:f.splitter}),o.createElement(c.TextInput,{id:"latitude",testId:"location-editor-latitude",placeholder:"Between -90 and 90",isDisabled:e.disabled,value:e.value?String(e.value.lat):"",onChange:function(t){e.onChangeLocation({lng:e.value&&void 0!==e.value.lng?e.value.lng:0,lat:Number(t.target.value)||0})},type:"number",max:"90",min:"-90",step:"0.1"}),o.createElement("div",{className:f.splitter}),o.createElement("label",{htmlFor:"longitude"},"Longitude"),o.createElement("div",{className:f.splitter}),o.createElement(c.TextInput,{id:"longitude",testId:"location-editor-longitude",placeholder:"Between -180 and 180",isDisabled:e.disabled,value:e.value?String(e.value.lng):"",onChange:function(t){e.onChangeLocation({lat:e.value&&void 0!==e.value.lat?e.value.lat:0,lng:Number(t.target.value)||0})},type:"number",max:"180",min:"-180",step:"0.1"}))),o.createElement("div",{className:f.secondary},o.createElement(c.TextLink,{as:"button",isDisabled:e.disabled,testId:"location-editor-clear",className:f.clearBtn,onClick:function(){e.onChangeLocation(void 0)}},"Clear")))}var h={root:l.css({height:"300px",width:"100%"})},b={lat:52.5018,lng:13.41115439},C=function(e){function t(t){var a;return(a=e.call(this,t)||this).onGoogleApiLoaded=function(e){var t=e.maps,o=e.map,n=new t.Marker({map:o,position:o.getCenter(),cursor:a.props.disabled?"not-allowed":"auto",draggable:!a.props.disabled,visible:Boolean(a.props.location)});t.event.addListener(o,"click",(function(e){!a.props.disabled&&a.state.marker&&a.state.maps&&(a.state.marker.setPosition(e.latLng),a.state.marker.setVisible(!0),a.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()}))})),t.event.addListener(n,"dragend",(function(e){a.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()})})),a.setState({marker:n,maps:t},(function(){a.props.onGoogleApiLoaded({maps:t})}))},a.state={marker:void 0,maps:void 0},a}p(t,e);var a=t.prototype;return a.componentDidUpdate=function(){if(this.state.marker&&this.state.maps){if(this.props.location){var e=new this.state.maps.LatLng(this.props.location.lat,this.props.location.lng);this.state.marker.setPosition(e),this.state.marker.setVisible(!0)}else this.state.marker.setVisible(!1);this.state.marker.setDraggable(!this.props.disabled),this.state.marker.setCursor(this.props.disabled?"not-allowed":"auto")}},a.render=function(){return o.createElement("div",{className:h.root},o.createElement(u,{draggable:!this.props.disabled,bootstrapURLKeys:this.props.googleMapsKey?{key:this.props.googleMapsKey}:void 0,defaultCenter:b,center:this.props.location,options:{scrollwheel:!1,mapTypeId:"roadmap"},defaultZoom:6,yesIWantToUseGoogleMapApiInternals:!0,onGoogleApiLoaded:this.onGoogleApiLoaded}))},t}(o.Component);function L(e){return e&&n(e.lat)&&n(e.lng)?{lat:e.lat,lon:e.lng}:null}var y=function(e){function t(t){var a;return(a=e.call(this,t)||this).onSearchAddress=s((function(e){if(!a.state.mapsObject)return Promise.resolve(null);var t=a.state.mapsObject;return e?new Promise((function(a){(new t.Geocoder).geocode({address:e},a,(function(){a(null)}))})):Promise.resolve(null)}),300),a.onGetAddressFromLocation=function(e,t){if(!a.state.mapsObject||!e)return Promise.resolve("");var o=a.state.mapsObject;return new Promise((function(a){(new o.Geocoder).geocode({location:e},(function(e){if(e&&e.length>0){var o=e.map((function(e){return e.formatted_address}));a(o.find((function(e){return e===t}))||o[0])}else a("")}),(function(){a("")}))}))},a.state={localValue:t.value?{lng:t.value.lon,lat:t.value.lat}:void 0,mapsObject:null},a}return p(t,e),t.prototype.render=function(){var e=this,t=this.state,o=t.mapsObject,n=t.localValue;return a.createElement("div",{"data-test-id":"location-editor"},a.createElement(C,{disabled:this.props.disabled||null===o,googleMapsKey:this.props.googleMapsKey,location:n,onGoogleApiLoaded:function(t){e.setState({mapsObject:t.maps})},onChangeLocation:function(t){e.setState({localValue:t}),e.props.setValue(L(t))}}),a.createElement(v,{disabled:this.props.disabled||null===o,value:n,view:this.props.selectedView,onChangeView:function(t){e.props.setSelectedView(t)},onChangeLocation:function(t){e.setState({localValue:t}),e.props.setValue(L(t))},onSearchAddress:this.onSearchAddress,onGetAddressFromLocation:this.onGetAddressFromLocation}))},t}(a.Component);function E(e){var o=e.field,n=e.parameters?e.parameters.instance.googleMapsKey:void 0,s=a.useState(t.Address),l=s[0],d=s[1];return a.createElement(i.FieldConnector,{isEqualValues:function(e,t){return r(e,t)},field:o,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){return a.createElement(y,{key:"location-editor-"+e.externalReset,value:e.value,disabled:e.disabled,setValue:e.setValue,googleMapsKey:n,selectedView:l,setSelectedView:d})}))}E.defaultProps={isInitiallyDisabled:!0},exports.LocationEditor=E;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),a=e(t),o=require("@contentful/field-editor-shared"),n=e(require("deep-equal")),s=e(require("lodash/isNumber")),i=e(require("lodash/throttle")),r=require("emotion"),l=e(require("google-map-react")),d=require("@contentful/f36-components"),c=e(require("@contentful/f36-tokens"));function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var p,m={root:r.css({height:"300px",width:"100%"})},g={lat:52.5018,lng:13.41115439},f=function(e){function t(t){var a;return(a=e.call(this,t)||this).onGoogleApiLoaded=function(e){var t=e.maps,o=e.map,n=new t.Marker({map:o,position:o.getCenter(),cursor:a.props.disabled?"not-allowed":"auto",draggable:!a.props.disabled,visible:Boolean(a.props.location)});t.event.addListener(o,"click",(function(e){!a.props.disabled&&a.state.marker&&a.state.maps&&(a.state.marker.setPosition(e.latLng),a.state.marker.setVisible(!0),a.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()}))})),t.event.addListener(n,"dragend",(function(e){a.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()})})),a.setState({marker:n,maps:t},(function(){a.props.onGoogleApiLoaded({maps:t})}))},a.state={marker:void 0,maps:void 0},a}u(t,e);var o=t.prototype;return o.componentDidUpdate=function(){if(this.state.marker&&this.state.maps){if(this.props.location){var e=new this.state.maps.LatLng(this.props.location.lat,this.props.location.lng);this.state.marker.setPosition(e),this.state.marker.setVisible(!0)}else this.state.marker.setVisible(!1);this.state.marker.setDraggable(!this.props.disabled),this.state.marker.setCursor(this.props.disabled?"not-allowed":"auto")}},o.render=function(){return a.createElement("div",{className:m.root},a.createElement(l,{draggable:!this.props.disabled,bootstrapURLKeys:this.props.googleMapsKey?{key:this.props.googleMapsKey}:void 0,defaultCenter:g,center:this.props.location,options:{scrollwheel:!1,mapTypeId:"roadmap"},defaultZoom:6,yesIWantToUseGoogleMapApiInternals:!0,onGoogleApiLoaded:this.onGoogleApiLoaded}))},t}(a.Component),v={root:r.css({width:"100%"}),input:r.css({position:"relative",width:"100%"}),spinner:r.css({position:"absolute",right:10,top:10,zIndex:99}),validationMessage:r.css({marginTop:c.spacingS}),suggestion:r.css({position:"absolute",transform:"translateY(100%)",bottom:0,left:0,zIndex:1})};function h(e){var t=a.useState(!1),o=t[0],n=t[1],s=a.useState(""),i=s[0],r=s[1],l=a.useState(!1),c=l[0],u=l[1],p=a.useState(null),m=p[0],g=p[1];return a.useEffect((function(){n(!0),e.onGetAddressFromLocation(e.value,i).then((function(e){r(e),n(!1)}))}),[e.value,e.disabled]),a.createElement("div",{className:v.root},a.createElement("div",{className:v.input},a.createElement(d.TextInput,{testId:"location-editor-search",isInvalid:c,placeholder:"Start typing to find location",value:i,onChange:function(t){r(t.target.value),u(!1),g(null),""!==t.target.value?(n(!0),e.onSearchAddress(t.target.value).then((function(e){n(!1),null===e?u(!1):0===e.length?u(!0):(u(!1),g({address:e[0].formatted_address,location:{lat:Number(e[0].geometry.location.lat().toString().slice(0,8)),lng:Number(e[0].geometry.location.lng().toString().slice(0,8))}}))}))):e.onChangeLocation(void 0)},isDisabled:e.disabled}),o&&a.createElement(d.Spinner,{className:v.spinner}),m&&a.createElement(d.Card,{padding:"none",className:v.suggestion},a.createElement(d.Button,{variant:"transparent",testId:"location-editor-suggestion",onClick:function(){r(m.address),e.onChangeLocation(m.location),g(null)}},m.address)),c&&a.createElement(d.ValidationMessage,{testId:"location-editor-not-found",className:v.validationMessage},"No results found for ",a.createElement("strong",null,i),". Please make sure that address is spelled correctly.")))}!function(e){e.Address="Address",e.Coordinates="Coordinates"}(p||(p={}));var b={root:r.css({display:"flex",flexDirection:"row",marginTop:c.spacingS,alignItems:"flex-end"}),main:r.css({flexGrow:1}),secondary:r.css({minWidth:"70px",textAlign:"right"}),inputsRow:r.css({display:"flex",marginTop:c.spacingS,fontSize:c.fontSizeM,color:c.gray900,fontFamily:c.fontStackPrimary,alignItems:"center"}),splitter:r.css({width:c.spacingL}),clearBtn:r.css({marginBottom:c.spacingS})};function C(e){return a.createElement("div",{className:b.root},a.createElement("div",{className:b.main},a.createElement(d.Flex,{flexDirection:"row"},a.createElement(d.Radio,{className:r.css({flexBasis:"100%"}),id:p.Address,testId:"location-editor-address-radio",isDisabled:e.disabled,value:p.Address,isChecked:e.view===p.Address,onChange:function(){e.onChangeView(p.Address)}},"Address"),a.createElement(d.Radio,{className:r.css({flexBasis:"100%"}),id:p.Coordinates,testId:"location-editor-coordinates-radio",isDisabled:e.disabled,value:p.Coordinates,isChecked:e.view===p.Coordinates,onChange:function(){e.onChangeView(p.Coordinates)}},"Coordinates")),e.view===p.Address&&a.createElement("div",{className:b.inputsRow},a.createElement(h,{onSearchAddress:e.onSearchAddress,onGetAddressFromLocation:e.onGetAddressFromLocation,disabled:e.disabled,value:e.value,onChangeLocation:e.onChangeLocation})),e.view===p.Coordinates&&a.createElement("div",{className:b.inputsRow},a.createElement("label",{htmlFor:"latitude"},"Latitude"),a.createElement("div",{className:b.splitter}),a.createElement(d.TextInput,{id:"latitude",testId:"location-editor-latitude",placeholder:"Between -90 and 90",isDisabled:e.disabled,value:e.value?String(e.value.lat):"",onChange:function(t){e.onChangeLocation({lng:e.value&&void 0!==e.value.lng?e.value.lng:0,lat:Number(t.target.value)||0})},type:"number",max:"90",min:"-90",step:"0.1"}),a.createElement("div",{className:b.splitter}),a.createElement("label",{htmlFor:"longitude"},"Longitude"),a.createElement("div",{className:b.splitter}),a.createElement(d.TextInput,{id:"longitude",testId:"location-editor-longitude",placeholder:"Between -180 and 180",isDisabled:e.disabled,value:e.value?String(e.value.lng):"",onChange:function(t){e.onChangeLocation({lat:e.value&&void 0!==e.value.lat?e.value.lat:0,lng:Number(t.target.value)||0})},type:"number",max:"180",min:"-180",step:"0.1"}))),a.createElement("div",{className:b.secondary},a.createElement(d.TextLink,{as:"button",isDisabled:e.disabled,testId:"location-editor-clear",className:b.clearBtn,onClick:function(){e.onChangeLocation(void 0)}},"Clear")))}function L(e){return e&&s(e.lat)&&s(e.lng)?{lat:e.lat,lon:e.lng}:null}var y=function(e){function a(t){var a;return(a=e.call(this,t)||this).onSearchAddress=i((function(e){if(!a.state.mapsObject)return Promise.resolve(null);var t=a.state.mapsObject;return e?new Promise((function(a){(new t.Geocoder).geocode({address:e},a,(function(){a(null)}))})):Promise.resolve(null)}),300),a.onGetAddressFromLocation=function(e,t){if(!a.state.mapsObject||!e)return Promise.resolve("");var o=a.state.mapsObject;return new Promise((function(a){(new o.Geocoder).geocode({location:e},(function(e){if(e&&e.length>0){var o=e.map((function(e){return e.formatted_address}));a(o.find((function(e){return e===t}))||o[0])}else a("")}),(function(){a("")}))}))},a.state={localValue:t.value?{lng:t.value.lon,lat:t.value.lat}:void 0,mapsObject:null},a}return u(a,e),a.prototype.render=function(){var e=this,a=this.state,o=a.mapsObject,n=a.localValue;return t.createElement("div",{"data-test-id":"location-editor"},t.createElement(f,{disabled:this.props.disabled||null===o,googleMapsKey:this.props.googleMapsKey,location:n,onGoogleApiLoaded:function(t){e.setState({mapsObject:t.maps})},onChangeLocation:function(t){e.setState({localValue:t}),e.props.setValue(L(t))}}),t.createElement(C,{disabled:this.props.disabled||null===o,value:n,view:this.props.selectedView,onChangeView:function(t){e.props.setSelectedView(t)},onChangeLocation:function(t){e.setState({localValue:t}),e.props.setValue(L(t))},onSearchAddress:this.onSearchAddress,onGetAddressFromLocation:this.onGetAddressFromLocation}))},a}(t.Component);function E(e){var a=e.field,s=e.parameters?e.parameters.instance.googleMapsKey:void 0,i=t.useState(p.Address),r=i[0],l=i[1];return t.createElement(o.FieldConnector,{isEqualValues:function(e,t){return n(e,t)},field:a,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){return t.createElement(y,{key:"location-editor-"+e.externalReset,value:e.value,disabled:e.disabled,setValue:e.setValue,googleMapsKey:s,selectedView:r,setSelectedView:l})}))}E.defaultProps={isInitiallyDisabled:!0},exports.LocationEditor=E;
2
2
  //# sourceMappingURL=field-editor-location.cjs.production.min.js.map