@contentful/field-editor-location 1.2.3 → 1.3.1
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 +24 -11
- package/CHANGELOG.md +0 -214
- package/dist/field-editor-location.cjs.development.js +0 -497
- 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 -490
- package/dist/field-editor-location.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var React__default = _interopDefault(React);
|
|
9
|
-
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
10
|
-
var deepEqual = _interopDefault(require('deep-equal'));
|
|
11
|
-
var isNumber = _interopDefault(require('lodash/isNumber'));
|
|
12
|
-
var throttle = _interopDefault(require('lodash/throttle'));
|
|
13
|
-
var emotion = require('emotion');
|
|
14
|
-
var GoogleMapReact = _interopDefault(require('google-map-react'));
|
|
15
|
-
var f36Components = require('@contentful/f36-components');
|
|
16
|
-
var tokens = _interopDefault(require('@contentful/f36-tokens'));
|
|
17
|
-
|
|
18
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
19
|
-
const styles = {
|
|
20
|
-
root: /*#__PURE__*/emotion.css({
|
|
21
|
-
height: '300px',
|
|
22
|
-
width: '100%'
|
|
23
|
-
})
|
|
24
|
-
};
|
|
25
|
-
const BerlinLocation = {
|
|
26
|
-
lat: 52.5018,
|
|
27
|
-
lng: 13.41115439
|
|
28
|
-
};
|
|
29
|
-
class GoogleMapView extends React__default.Component {
|
|
30
|
-
constructor(props) {
|
|
31
|
-
super(props);
|
|
32
|
-
|
|
33
|
-
this.onGoogleApiLoaded = event => {
|
|
34
|
-
const {
|
|
35
|
-
maps,
|
|
36
|
-
map
|
|
37
|
-
} = event;
|
|
38
|
-
const marker = new maps.Marker({
|
|
39
|
-
map,
|
|
40
|
-
position: map.getCenter(),
|
|
41
|
-
cursor: this.props.disabled ? 'not-allowed' : 'auto',
|
|
42
|
-
draggable: !this.props.disabled,
|
|
43
|
-
visible: Boolean(this.props.location)
|
|
44
|
-
});
|
|
45
|
-
maps.event.addListener(map, 'click', event => {
|
|
46
|
-
if (this.props.disabled || !this.state.marker || !this.state.maps) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.state.marker.setPosition(event.latLng);
|
|
51
|
-
this.state.marker.setVisible(true);
|
|
52
|
-
this.props.onChangeLocation({
|
|
53
|
-
lat: event.latLng.lat(),
|
|
54
|
-
lng: event.latLng.lng()
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
maps.event.addListener(marker, 'dragend', event => {
|
|
58
|
-
this.props.onChangeLocation({
|
|
59
|
-
lat: event.latLng.lat(),
|
|
60
|
-
lng: event.latLng.lng()
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
this.setState({
|
|
64
|
-
marker,
|
|
65
|
-
maps
|
|
66
|
-
}, () => {
|
|
67
|
-
this.props.onGoogleApiLoaded({
|
|
68
|
-
maps
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
this.state = {
|
|
74
|
-
marker: undefined,
|
|
75
|
-
maps: undefined
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
componentDidUpdate() {
|
|
80
|
-
if (this.state.marker && this.state.maps) {
|
|
81
|
-
if (this.props.location) {
|
|
82
|
-
const latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
|
|
83
|
-
this.state.marker.setPosition(latLng);
|
|
84
|
-
this.state.marker.setVisible(true);
|
|
85
|
-
} else {
|
|
86
|
-
this.state.marker.setVisible(false);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
this.state.marker.setDraggable(!this.props.disabled);
|
|
90
|
-
this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
render() {
|
|
95
|
-
return React__default.createElement("div", {
|
|
96
|
-
className: styles.root
|
|
97
|
-
}, React__default.createElement(GoogleMapReact, {
|
|
98
|
-
draggable: !this.props.disabled,
|
|
99
|
-
bootstrapURLKeys: this.props.googleMapsKey ? {
|
|
100
|
-
key: this.props.googleMapsKey
|
|
101
|
-
} : undefined,
|
|
102
|
-
defaultCenter: BerlinLocation,
|
|
103
|
-
center: this.props.location,
|
|
104
|
-
options: {
|
|
105
|
-
scrollwheel: false,
|
|
106
|
-
mapTypeId: 'roadmap'
|
|
107
|
-
},
|
|
108
|
-
defaultZoom: 6,
|
|
109
|
-
yesIWantToUseGoogleMapApiInternals: true,
|
|
110
|
-
onGoogleApiLoaded: this.onGoogleApiLoaded
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const styles$1 = {
|
|
117
|
-
root: /*#__PURE__*/emotion.css({
|
|
118
|
-
width: '100%'
|
|
119
|
-
}),
|
|
120
|
-
input: /*#__PURE__*/emotion.css({
|
|
121
|
-
position: 'relative',
|
|
122
|
-
width: '100%'
|
|
123
|
-
}),
|
|
124
|
-
spinner: /*#__PURE__*/emotion.css({
|
|
125
|
-
position: 'absolute',
|
|
126
|
-
right: 10,
|
|
127
|
-
top: 10,
|
|
128
|
-
zIndex: 99
|
|
129
|
-
}),
|
|
130
|
-
validationMessage: /*#__PURE__*/emotion.css({
|
|
131
|
-
marginTop: tokens.spacingS
|
|
132
|
-
}),
|
|
133
|
-
suggestion: /*#__PURE__*/emotion.css({
|
|
134
|
-
position: 'absolute',
|
|
135
|
-
transform: 'translateY(100%)',
|
|
136
|
-
bottom: 0,
|
|
137
|
-
left: 0,
|
|
138
|
-
zIndex: 1
|
|
139
|
-
})
|
|
140
|
-
};
|
|
141
|
-
function LocationSearchInput(props) {
|
|
142
|
-
const [isSearching, setIsSearching] = React__default.useState(false);
|
|
143
|
-
const [address, setAddress] = React__default.useState('');
|
|
144
|
-
const [hasError, setHasError] = React__default.useState(false);
|
|
145
|
-
const [suggestion, setSuggestion] = React__default.useState(null);
|
|
146
|
-
React__default.useEffect(() => {
|
|
147
|
-
setIsSearching(true);
|
|
148
|
-
props.onGetAddressFromLocation(props.value, address).then(address => {
|
|
149
|
-
setAddress(address);
|
|
150
|
-
setIsSearching(false);
|
|
151
|
-
}); // eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
152
|
-
}, [props.value, props.disabled]);
|
|
153
|
-
return React__default.createElement("div", {
|
|
154
|
-
className: styles$1.root
|
|
155
|
-
}, React__default.createElement("div", {
|
|
156
|
-
className: styles$1.input
|
|
157
|
-
}, React__default.createElement(f36Components.TextInput, {
|
|
158
|
-
testId: "location-editor-search",
|
|
159
|
-
isInvalid: hasError,
|
|
160
|
-
placeholder: "Start typing to find location",
|
|
161
|
-
value: address,
|
|
162
|
-
onChange: e => {
|
|
163
|
-
setAddress(e.target.value);
|
|
164
|
-
setHasError(false);
|
|
165
|
-
setSuggestion(null);
|
|
166
|
-
|
|
167
|
-
if (e.target.value === '') {
|
|
168
|
-
props.onChangeLocation(undefined);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
setIsSearching(true);
|
|
173
|
-
props.onSearchAddress(e.target.value).then(value => {
|
|
174
|
-
setIsSearching(false);
|
|
175
|
-
|
|
176
|
-
if (value === null) {
|
|
177
|
-
setHasError(false);
|
|
178
|
-
} else if (value.length === 0) {
|
|
179
|
-
setHasError(true);
|
|
180
|
-
} else {
|
|
181
|
-
setHasError(false);
|
|
182
|
-
setSuggestion({
|
|
183
|
-
address: value[0].formatted_address,
|
|
184
|
-
location: {
|
|
185
|
-
lat: Number(value[0].geometry.location.lat().toString().slice(0, 8)),
|
|
186
|
-
lng: Number(value[0].geometry.location.lng().toString().slice(0, 8))
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
isDisabled: props.disabled
|
|
193
|
-
}), isSearching && React__default.createElement(f36Components.Spinner, {
|
|
194
|
-
className: styles$1.spinner
|
|
195
|
-
}), suggestion && React__default.createElement(f36Components.Card, {
|
|
196
|
-
padding: "none",
|
|
197
|
-
className: styles$1.suggestion
|
|
198
|
-
}, React__default.createElement(f36Components.Button, {
|
|
199
|
-
variant: "transparent",
|
|
200
|
-
testId: "location-editor-suggestion",
|
|
201
|
-
onClick: () => {
|
|
202
|
-
setAddress(suggestion.address);
|
|
203
|
-
props.onChangeLocation(suggestion.location);
|
|
204
|
-
setSuggestion(null);
|
|
205
|
-
}
|
|
206
|
-
}, suggestion.address)), hasError && React__default.createElement(f36Components.ValidationMessage, {
|
|
207
|
-
testId: "location-editor-not-found",
|
|
208
|
-
className: styles$1.validationMessage
|
|
209
|
-
}, "No results found for ", React__default.createElement("strong", null, address), ". Please make sure that address is spelled correctly.")));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var ViewType;
|
|
213
|
-
|
|
214
|
-
(function (ViewType) {
|
|
215
|
-
ViewType["Address"] = "Address";
|
|
216
|
-
ViewType["Coordinates"] = "Coordinates";
|
|
217
|
-
})(ViewType || (ViewType = {}));
|
|
218
|
-
|
|
219
|
-
const styles$2 = {
|
|
220
|
-
root: /*#__PURE__*/emotion.css({
|
|
221
|
-
display: 'flex',
|
|
222
|
-
flexDirection: 'row',
|
|
223
|
-
marginTop: tokens.spacingS,
|
|
224
|
-
alignItems: 'flex-end'
|
|
225
|
-
}),
|
|
226
|
-
main: /*#__PURE__*/emotion.css({
|
|
227
|
-
flexGrow: 1
|
|
228
|
-
}),
|
|
229
|
-
secondary: /*#__PURE__*/emotion.css({
|
|
230
|
-
minWidth: '70px',
|
|
231
|
-
textAlign: 'right'
|
|
232
|
-
}),
|
|
233
|
-
inputsRow: /*#__PURE__*/emotion.css({
|
|
234
|
-
display: 'flex',
|
|
235
|
-
marginTop: tokens.spacingS,
|
|
236
|
-
fontSize: tokens.fontSizeM,
|
|
237
|
-
color: tokens.gray900,
|
|
238
|
-
fontFamily: tokens.fontStackPrimary,
|
|
239
|
-
alignItems: 'center'
|
|
240
|
-
}),
|
|
241
|
-
splitter: /*#__PURE__*/emotion.css({
|
|
242
|
-
width: tokens.spacingL
|
|
243
|
-
}),
|
|
244
|
-
clearBtn: /*#__PURE__*/emotion.css({
|
|
245
|
-
marginBottom: tokens.spacingS
|
|
246
|
-
})
|
|
247
|
-
};
|
|
248
|
-
function LocationSelector(props) {
|
|
249
|
-
return React__default.createElement("div", {
|
|
250
|
-
className: styles$2.root
|
|
251
|
-
}, React__default.createElement("div", {
|
|
252
|
-
className: styles$2.main
|
|
253
|
-
}, React__default.createElement(f36Components.Flex, {
|
|
254
|
-
flexDirection: "row"
|
|
255
|
-
}, React__default.createElement(f36Components.Radio, {
|
|
256
|
-
className: emotion.css({
|
|
257
|
-
flexBasis: '100%'
|
|
258
|
-
}),
|
|
259
|
-
id: ViewType.Address,
|
|
260
|
-
testId: "location-editor-address-radio",
|
|
261
|
-
isDisabled: props.disabled,
|
|
262
|
-
value: ViewType.Address,
|
|
263
|
-
isChecked: props.view === ViewType.Address,
|
|
264
|
-
onChange: () => {
|
|
265
|
-
props.onChangeView(ViewType.Address);
|
|
266
|
-
}
|
|
267
|
-
}, "Address"), React__default.createElement(f36Components.Radio, {
|
|
268
|
-
className: emotion.css({
|
|
269
|
-
flexBasis: '100%'
|
|
270
|
-
}),
|
|
271
|
-
id: ViewType.Coordinates,
|
|
272
|
-
testId: "location-editor-coordinates-radio",
|
|
273
|
-
isDisabled: props.disabled,
|
|
274
|
-
value: ViewType.Coordinates,
|
|
275
|
-
isChecked: props.view === ViewType.Coordinates,
|
|
276
|
-
onChange: () => {
|
|
277
|
-
props.onChangeView(ViewType.Coordinates);
|
|
278
|
-
}
|
|
279
|
-
}, "Coordinates")), props.view === ViewType.Address && React__default.createElement("div", {
|
|
280
|
-
className: styles$2.inputsRow
|
|
281
|
-
}, React__default.createElement(LocationSearchInput, {
|
|
282
|
-
onSearchAddress: props.onSearchAddress,
|
|
283
|
-
onGetAddressFromLocation: props.onGetAddressFromLocation,
|
|
284
|
-
disabled: props.disabled,
|
|
285
|
-
value: props.value,
|
|
286
|
-
onChangeLocation: props.onChangeLocation
|
|
287
|
-
})), props.view === ViewType.Coordinates && React__default.createElement("div", {
|
|
288
|
-
className: styles$2.inputsRow
|
|
289
|
-
}, React__default.createElement("label", {
|
|
290
|
-
htmlFor: "latitude"
|
|
291
|
-
}, "Latitude"), React__default.createElement("div", {
|
|
292
|
-
className: styles$2.splitter
|
|
293
|
-
}), React__default.createElement(f36Components.TextInput, {
|
|
294
|
-
id: "latitude",
|
|
295
|
-
testId: "location-editor-latitude",
|
|
296
|
-
placeholder: "Between -90 and 90",
|
|
297
|
-
isDisabled: props.disabled,
|
|
298
|
-
value: props.value ? String(props.value.lat) : '',
|
|
299
|
-
onChange: e => {
|
|
300
|
-
props.onChangeLocation({
|
|
301
|
-
lng: props.value && props.value.lng !== undefined ? props.value.lng : 0,
|
|
302
|
-
lat: Number(e.target.value) || 0
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
type: "number",
|
|
306
|
-
max: "90",
|
|
307
|
-
min: "-90",
|
|
308
|
-
step: "0.1"
|
|
309
|
-
}), React__default.createElement("div", {
|
|
310
|
-
className: styles$2.splitter
|
|
311
|
-
}), React__default.createElement("label", {
|
|
312
|
-
htmlFor: "longitude"
|
|
313
|
-
}, "Longitude"), React__default.createElement("div", {
|
|
314
|
-
className: styles$2.splitter
|
|
315
|
-
}), React__default.createElement(f36Components.TextInput, {
|
|
316
|
-
id: "longitude",
|
|
317
|
-
testId: "location-editor-longitude",
|
|
318
|
-
placeholder: "Between -180 and 180",
|
|
319
|
-
isDisabled: props.disabled,
|
|
320
|
-
value: props.value ? String(props.value.lng) : '',
|
|
321
|
-
onChange: e => {
|
|
322
|
-
props.onChangeLocation({
|
|
323
|
-
lat: props.value && props.value.lat !== undefined ? props.value.lat : 0,
|
|
324
|
-
lng: Number(e.target.value) || 0
|
|
325
|
-
});
|
|
326
|
-
},
|
|
327
|
-
type: "number",
|
|
328
|
-
max: "180",
|
|
329
|
-
min: "-180",
|
|
330
|
-
step: "0.1"
|
|
331
|
-
}))), React__default.createElement("div", {
|
|
332
|
-
className: styles$2.secondary
|
|
333
|
-
}, React__default.createElement(f36Components.TextLink, {
|
|
334
|
-
as: "button",
|
|
335
|
-
isDisabled: props.disabled,
|
|
336
|
-
testId: "location-editor-clear",
|
|
337
|
-
className: styles$2.clearBtn,
|
|
338
|
-
onClick: () => {
|
|
339
|
-
props.onChangeLocation(undefined);
|
|
340
|
-
}
|
|
341
|
-
}, "Clear")));
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
function toLocationValue(coords) {
|
|
345
|
-
if (coords && isNumber(coords.lat) && isNumber(coords.lng)) {
|
|
346
|
-
return {
|
|
347
|
-
lat: coords.lat,
|
|
348
|
-
lon: coords.lng
|
|
349
|
-
};
|
|
350
|
-
} else {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
class LocationEditor extends React.Component {
|
|
356
|
-
constructor(props) {
|
|
357
|
-
super(props);
|
|
358
|
-
this.onSearchAddress = throttle(value => {
|
|
359
|
-
if (!this.state.mapsObject) {
|
|
360
|
-
return Promise.resolve(null);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const {
|
|
364
|
-
mapsObject
|
|
365
|
-
} = this.state;
|
|
366
|
-
|
|
367
|
-
if (!value) {
|
|
368
|
-
return Promise.resolve(null);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return new Promise(resolve => {
|
|
372
|
-
const geocoder = new mapsObject.Geocoder();
|
|
373
|
-
geocoder.geocode({
|
|
374
|
-
address: value
|
|
375
|
-
}, resolve, () => {
|
|
376
|
-
resolve(null);
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
}, 300);
|
|
380
|
-
|
|
381
|
-
this.onGetAddressFromLocation = (location, value) => {
|
|
382
|
-
if (!this.state.mapsObject || !location) {
|
|
383
|
-
return Promise.resolve('');
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const {
|
|
387
|
-
mapsObject
|
|
388
|
-
} = this.state;
|
|
389
|
-
return new Promise(resolve => {
|
|
390
|
-
const geocoder = new mapsObject.Geocoder();
|
|
391
|
-
geocoder.geocode({
|
|
392
|
-
location
|
|
393
|
-
}, result => {
|
|
394
|
-
if (result && result.length > 0) {
|
|
395
|
-
const addresses = result.map(item => item.formatted_address);
|
|
396
|
-
resolve(addresses.find(item => item === value) || addresses[0]);
|
|
397
|
-
} else {
|
|
398
|
-
resolve('');
|
|
399
|
-
}
|
|
400
|
-
}, () => {
|
|
401
|
-
resolve('');
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
this.state = {
|
|
407
|
-
localValue: props.value ? {
|
|
408
|
-
lng: props.value.lon,
|
|
409
|
-
lat: props.value.lat
|
|
410
|
-
} : undefined,
|
|
411
|
-
mapsObject: null
|
|
412
|
-
};
|
|
413
|
-
} // @ts-expect-error
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
render() {
|
|
417
|
-
const {
|
|
418
|
-
mapsObject,
|
|
419
|
-
localValue
|
|
420
|
-
} = this.state;
|
|
421
|
-
return React.createElement("div", {
|
|
422
|
-
"data-test-id": "location-editor"
|
|
423
|
-
}, React.createElement(GoogleMapView, {
|
|
424
|
-
disabled: this.props.disabled || mapsObject === null,
|
|
425
|
-
googleMapsKey: this.props.googleMapsKey,
|
|
426
|
-
location: localValue,
|
|
427
|
-
onGoogleApiLoaded: ({
|
|
428
|
-
maps
|
|
429
|
-
}) => {
|
|
430
|
-
this.setState({
|
|
431
|
-
mapsObject: maps
|
|
432
|
-
});
|
|
433
|
-
},
|
|
434
|
-
onChangeLocation: coords => {
|
|
435
|
-
this.setState({
|
|
436
|
-
localValue: coords
|
|
437
|
-
});
|
|
438
|
-
this.props.setValue(toLocationValue(coords));
|
|
439
|
-
}
|
|
440
|
-
}), React.createElement(LocationSelector, {
|
|
441
|
-
disabled: this.props.disabled || mapsObject === null,
|
|
442
|
-
value: localValue,
|
|
443
|
-
view: this.props.selectedView,
|
|
444
|
-
onChangeView: view => {
|
|
445
|
-
this.props.setSelectedView(view);
|
|
446
|
-
},
|
|
447
|
-
onChangeLocation: coords => {
|
|
448
|
-
this.setState({
|
|
449
|
-
localValue: coords
|
|
450
|
-
});
|
|
451
|
-
this.props.setValue(toLocationValue(coords));
|
|
452
|
-
},
|
|
453
|
-
onSearchAddress: this.onSearchAddress,
|
|
454
|
-
onGetAddressFromLocation: this.onGetAddressFromLocation
|
|
455
|
-
}));
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
function LocationEditorConnected(props) {
|
|
460
|
-
const {
|
|
461
|
-
field
|
|
462
|
-
} = props;
|
|
463
|
-
const googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;
|
|
464
|
-
const [selectedView, setSelectedView] = React.useState(ViewType.Address);
|
|
465
|
-
return React.createElement(fieldEditorShared.FieldConnector, {
|
|
466
|
-
isEqualValues: (value1, value2) => {
|
|
467
|
-
return deepEqual(value1, value2);
|
|
468
|
-
},
|
|
469
|
-
field: field,
|
|
470
|
-
isInitiallyDisabled: props.isInitiallyDisabled
|
|
471
|
-
}, ({
|
|
472
|
-
value,
|
|
473
|
-
disabled,
|
|
474
|
-
setValue,
|
|
475
|
-
externalReset
|
|
476
|
-
}) => {
|
|
477
|
-
return React.createElement(LocationEditor // on external change reset component completely and init with initial value again
|
|
478
|
-
, {
|
|
479
|
-
// on external change reset component completely and init with initial value again
|
|
480
|
-
key: `location-editor-${externalReset}`,
|
|
481
|
-
value: value,
|
|
482
|
-
disabled: disabled,
|
|
483
|
-
setValue: setValue,
|
|
484
|
-
googleMapsKey: googleMapsKey,
|
|
485
|
-
selectedView: selectedView,
|
|
486
|
-
setSelectedView: setSelectedView
|
|
487
|
-
});
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
LocationEditorConnected.defaultProps = {
|
|
491
|
-
isInitiallyDisabled: true
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const LocationEditor$1 = LocationEditorConnected;
|
|
495
|
-
|
|
496
|
-
exports.LocationEditor = LocationEditor$1;
|
|
497
|
-
//# sourceMappingURL=field-editor-location.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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","React","Component","constructor","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","className","GoogleMapReact","bootstrapURLKeys","googleMapsKey","key","defaultCenter","center","options","scrollwheel","mapTypeId","defaultZoom","yesIWantToUseGoogleMapApiInternals","input","spinner","right","top","zIndex","validationMessage","marginTop","tokens","spacingS","suggestion","transform","bottom","left","LocationSearchInput","isSearching","setIsSearching","useState","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":";;;;;;;;;;;;;;;;;AAAA;AASA,MAAMA,MAAM,GAAG;AACbC,EAAAA,IAAI,eAAEC,WAAG,CAAC;AACRC,IAAAA,MAAM,EAAE,OADA;AAERC,IAAAA,KAAK,EAAE;AAFC,GAAD;AADI,CAAf;AAOA,MAAMC,cAAc,GAAG;AACrBC,EAAAA,GAAG,EAAE,OADgB;AAErBC,EAAAA,GAAG,EAAE;AAFgB,CAAvB;MAkBaC,sBAAsBC,cAAK,CAACC;AACvCC,EAAAA,YAAYC;AACV,UAAMA,KAAN;;SAqBFC,oBAAqBC,KAAD;AAClB,YAAM;AAAEC,QAAAA,IAAF;AAAQC,QAAAA;AAAR,UAAgBF,KAAtB;AACA,YAAMG,MAAM,GAAG,IAAIF,IAAI,CAACG,MAAT,CAAgB;AAC7BF,QAAAA,GAD6B;AAE7BG,QAAAA,QAAQ,EAAEH,GAAG,CAACI,SAAJ,EAFmB;AAG7BC,QAAAA,MAAM,EAAE,KAAKT,KAAL,CAAWU,QAAX,GAAsB,aAAtB,GAAsC,MAHjB;AA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AAmBpJ,KAAK,CAACoJ,UAAN,CAAiBC,QAAjB,CAA0BtH,aAA7C,GAA6DT,SAAnF;AACA,QAAM,CAAC0H,YAAD,EAAeC,eAAf,IAAkCpJ,cAAA,CAAyB2F,QAAQ,CAACyB,OAAlC,CAAxC;AAEA,SACEpH,mBAAA,CAACyJ,gCAAD;AACEC,IAAAA,aAAa,EAAE,CAACC,MAAD,EAASC,MAAT;AACb,aAAOC,SAAS,CAACF,MAAD,EAASC,MAAT,CAAhB;AACD;AACDN,IAAAA,KAAK,EAAEA;AACPQ,IAAAA,mBAAmB,EAAE3J,KAAK,CAAC2J;GAL7B,EAOG,CAAC;AAAE3F,IAAAA,KAAF;AAAStD,IAAAA,QAAT;AAAmBqI,IAAAA,QAAnB;AAA6Ba,IAAAA;AAA7B,GAAD;AACC,WACE/J,mBAAA,CAACqI,cAAD;AAAA;AACE;AACAlG,MAAAA,GAAG,qBAAqB4H;AACxB5F,MAAAA,KAAK,EAAEA;AACPtD,MAAAA,QAAQ,EAAEA;AACVqI,MAAAA,QAAQ,EAAEA;AACVhH,MAAAA,aAAa,EAAEA;AACfiH,MAAAA,YAAY,EAAEA;AACdC,MAAAA,eAAe,EAAEA;KARnB,CADF;AAYD,GApBH,CADF;AAwBD;AAEDC,uBAAuB,CAACW,YAAxB,GAAuC;AACrCF,EAAAA,mBAAmB,EAAE;AADgB,CAAvC;;MCtLazB,gBAAc,GAAGgB,uBAAvB;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
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),s=require("@contentful/field-editor-shared"),o=e(require("deep-equal")),n=e(require("lodash/isNumber")),i=e(require("lodash/throttle")),l=require("emotion"),r=e(require("google-map-react")),d=require("@contentful/f36-components"),c=e(require("@contentful/f36-tokens"));const p={root:l.css({height:"300px",width:"100%"})},u={lat:52.5018,lng:13.41115439};class m extends a.Component{constructor(e){super(e),this.onGoogleApiLoaded=e=>{const{maps:t,map:a}=e,s=new t.Marker({map:a,position:a.getCenter(),cursor:this.props.disabled?"not-allowed":"auto",draggable:!this.props.disabled,visible:Boolean(this.props.location)});t.event.addListener(a,"click",e=>{!this.props.disabled&&this.state.marker&&this.state.maps&&(this.state.marker.setPosition(e.latLng),this.state.marker.setVisible(!0),this.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()}))}),t.event.addListener(s,"dragend",e=>{this.props.onChangeLocation({lat:e.latLng.lat(),lng:e.latLng.lng()})}),this.setState({marker:s,maps:t},()=>{this.props.onGoogleApiLoaded({maps:t})})},this.state={marker:void 0,maps:void 0}}componentDidUpdate(){if(this.state.marker&&this.state.maps){if(this.props.location){const 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")}}render(){return a.createElement("div",{className:p.root},a.createElement(r,{draggable:!this.props.disabled,bootstrapURLKeys:this.props.googleMapsKey?{key:this.props.googleMapsKey}:void 0,defaultCenter:u,center:this.props.location,options:{scrollwheel:!1,mapTypeId:"roadmap"},defaultZoom:6,yesIWantToUseGoogleMapApiInternals:!0,onGoogleApiLoaded:this.onGoogleApiLoaded}))}}const g={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:c.spacingS}),suggestion:l.css({position:"absolute",transform:"translateY(100%)",bottom:0,left:0,zIndex:1})};function h(e){const[t,s]=a.useState(!1),[o,n]=a.useState(""),[i,l]=a.useState(!1),[r,c]=a.useState(null);return a.useEffect(()=>{s(!0),e.onGetAddressFromLocation(e.value,o).then(e=>{n(e),s(!1)})},[e.value,e.disabled]),a.createElement("div",{className:g.root},a.createElement("div",{className:g.input},a.createElement(d.TextInput,{testId:"location-editor-search",isInvalid:i,placeholder:"Start typing to find location",value:o,onChange:t=>{n(t.target.value),l(!1),c(null),""!==t.target.value?(s(!0),e.onSearchAddress(t.target.value).then(e=>{s(!1),null===e?l(!1):0===e.length?l(!0):(l(!1),c({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}),t&&a.createElement(d.Spinner,{className:g.spinner}),r&&a.createElement(d.Card,{padding:"none",className:g.suggestion},a.createElement(d.Button,{variant:"transparent",testId:"location-editor-suggestion",onClick:()=>{n(r.address),e.onChangeLocation(r.location),c(null)}},r.address)),i&&a.createElement(d.ValidationMessage,{testId:"location-editor-not-found",className:g.validationMessage},"No results found for ",a.createElement("strong",null,o),". Please make sure that address is spelled correctly.")))}var v;!function(e){e.Address="Address",e.Coordinates="Coordinates"}(v||(v={}));const b={root:l.css({display:"flex",flexDirection:"row",marginTop:c.spacingS,alignItems:"flex-end"}),main:l.css({flexGrow:1}),secondary:l.css({minWidth:"70px",textAlign:"right"}),inputsRow:l.css({display:"flex",marginTop:c.spacingS,fontSize:c.fontSizeM,color:c.gray900,fontFamily:c.fontStackPrimary,alignItems:"center"}),splitter:l.css({width:c.spacingL}),clearBtn:l.css({marginBottom:c.spacingS})};function f(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:l.css({flexBasis:"100%"}),id:v.Address,testId:"location-editor-address-radio",isDisabled:e.disabled,value:v.Address,isChecked:e.view===v.Address,onChange:()=>{e.onChangeView(v.Address)}},"Address"),a.createElement(d.Radio,{className:l.css({flexBasis:"100%"}),id:v.Coordinates,testId:"location-editor-coordinates-radio",isDisabled:e.disabled,value:v.Coordinates,isChecked:e.view===v.Coordinates,onChange:()=>{e.onChangeView(v.Coordinates)}},"Coordinates")),e.view===v.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===v.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: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: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:()=>{e.onChangeLocation(void 0)}},"Clear")))}function C(e){return e&&n(e.lat)&&n(e.lng)?{lat:e.lat,lon:e.lng}:null}class L extends t.Component{constructor(e){super(e),this.onSearchAddress=i(e=>{if(!this.state.mapsObject)return Promise.resolve(null);const{mapsObject:t}=this.state;return e?new Promise(a=>{(new t.Geocoder).geocode({address:e},a,()=>{a(null)})}):Promise.resolve(null)},300),this.onGetAddressFromLocation=(e,t)=>{if(!this.state.mapsObject||!e)return Promise.resolve("");const{mapsObject:a}=this.state;return new Promise(s=>{(new a.Geocoder).geocode({location:e},e=>{if(e&&e.length>0){const a=e.map(e=>e.formatted_address);s(a.find(e=>e===t)||a[0])}else s("")},()=>{s("")})})},this.state={localValue:e.value?{lng:e.value.lon,lat:e.value.lat}:void 0,mapsObject:null}}render(){const{mapsObject:e,localValue:a}=this.state;return t.createElement("div",{"data-test-id":"location-editor"},t.createElement(m,{disabled:this.props.disabled||null===e,googleMapsKey:this.props.googleMapsKey,location:a,onGoogleApiLoaded:({maps:e})=>{this.setState({mapsObject:e})},onChangeLocation:e=>{this.setState({localValue:e}),this.props.setValue(C(e))}}),t.createElement(f,{disabled:this.props.disabled||null===e,value:a,view:this.props.selectedView,onChangeView:e=>{this.props.setSelectedView(e)},onChangeLocation:e=>{this.setState({localValue:e}),this.props.setValue(C(e))},onSearchAddress:this.onSearchAddress,onGetAddressFromLocation:this.onGetAddressFromLocation}))}}function E(e){const{field:a}=e,n=e.parameters?e.parameters.instance.googleMapsKey:void 0,[i,l]=t.useState(v.Address);return t.createElement(s.FieldConnector,{isEqualValues:(e,t)=>o(e,t),field:a,isInitiallyDisabled:e.isInitiallyDisabled},({value:e,disabled:a,setValue:s,externalReset:o})=>t.createElement(L,{key:"location-editor-"+o,value:e,disabled:a,setValue:s,googleMapsKey:n,selectedView:i,setSelectedView:l}))}E.defaultProps={isInitiallyDisabled:!0},exports.LocationEditor=E;
|
|
2
|
-
//# sourceMappingURL=field-editor-location.cjs.production.min.js.map
|