@contentful/field-editor-location 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/GoogleMapView.js +156 -0
- package/dist/cjs/LocationEditor.js +204 -0
- package/dist/cjs/LocationSearchInput.js +153 -0
- package/dist/cjs/LocationSelector.js +184 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/types.js +15 -0
- package/dist/esm/GoogleMapView.js +102 -0
- package/dist/esm/LocationEditor.js +142 -0
- package/dist/esm/LocationSearchInput.js +99 -0
- package/dist/esm/LocationSelector.js +130 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/types.js +5 -0
- package/dist/{GoogleMapView.d.ts → types/GoogleMapView.d.ts} +25 -25
- package/dist/{LocationEditor.d.ts → types/LocationEditor.d.ts} +45 -45
- package/dist/{LocationSearchInput.d.ts → types/LocationSearchInput.d.ts} +11 -11
- package/dist/{LocationSelector.d.ts → types/LocationSelector.d.ts} +13 -13
- package/dist/{index.d.ts → types/index.d.ts} +2 -2
- package/dist/{types.d.ts → types/types.d.ts} +22 -22
- package/package.json +23 -9
- package/CHANGELOG.md +0 -210
- package/dist/field-editor-location.cjs.development.js +0 -545
- package/dist/field-editor-location.cjs.development.js.map +0 -1
- package/dist/field-editor-location.cjs.production.min.js +0 -2
- package/dist/field-editor-location.cjs.production.min.js.map +0 -1
- package/dist/field-editor-location.esm.js +0 -538
- package/dist/field-editor-location.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LocationEditor", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LocationEditor;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _LocationEditor = require("./LocationEditor");
|
|
12
|
+
const LocationEditor = _LocationEditor.LocationEditorConnected;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ViewType", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ViewType;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var ViewType;
|
|
12
|
+
(function(ViewType) {
|
|
13
|
+
ViewType["Address"] = "Address";
|
|
14
|
+
ViewType["Coordinates"] = "Coordinates";
|
|
15
|
+
})(ViewType || (ViewType = {}));
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { css } from 'emotion';
|
|
16
|
+
import GoogleMapReact from 'google-map-react';
|
|
17
|
+
const styles = {
|
|
18
|
+
root: css({
|
|
19
|
+
height: '300px',
|
|
20
|
+
width: '100%'
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
const BerlinLocation = {
|
|
24
|
+
lat: 52.5018,
|
|
25
|
+
lng: 13.41115439
|
|
26
|
+
};
|
|
27
|
+
export class GoogleMapView extends React.Component {
|
|
28
|
+
componentDidUpdate() {
|
|
29
|
+
if (this.state.marker && this.state.maps) {
|
|
30
|
+
if (this.props.location) {
|
|
31
|
+
const latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
|
|
32
|
+
this.state.marker.setPosition(latLng);
|
|
33
|
+
this.state.marker.setVisible(true);
|
|
34
|
+
} else {
|
|
35
|
+
this.state.marker.setVisible(false);
|
|
36
|
+
}
|
|
37
|
+
this.state.marker.setDraggable(!this.props.disabled);
|
|
38
|
+
this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
42
|
+
return React.createElement("div", {
|
|
43
|
+
className: styles.root
|
|
44
|
+
}, React.createElement(GoogleMapReact, {
|
|
45
|
+
draggable: !this.props.disabled,
|
|
46
|
+
bootstrapURLKeys: this.props.googleMapsKey ? {
|
|
47
|
+
key: this.props.googleMapsKey
|
|
48
|
+
} : undefined,
|
|
49
|
+
defaultCenter: BerlinLocation,
|
|
50
|
+
center: this.props.location,
|
|
51
|
+
options: {
|
|
52
|
+
scrollwheel: false,
|
|
53
|
+
mapTypeId: 'roadmap'
|
|
54
|
+
},
|
|
55
|
+
defaultZoom: 6,
|
|
56
|
+
yesIWantToUseGoogleMapApiInternals: true,
|
|
57
|
+
onGoogleApiLoaded: this.onGoogleApiLoaded
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
constructor(props){
|
|
61
|
+
super(props);
|
|
62
|
+
_define_property(this, "onGoogleApiLoaded", (event)=>{
|
|
63
|
+
const { maps , map } = event;
|
|
64
|
+
const marker = new maps.Marker({
|
|
65
|
+
map,
|
|
66
|
+
position: map.getCenter(),
|
|
67
|
+
cursor: this.props.disabled ? 'not-allowed' : 'auto',
|
|
68
|
+
draggable: !this.props.disabled,
|
|
69
|
+
visible: Boolean(this.props.location)
|
|
70
|
+
});
|
|
71
|
+
maps.event.addListener(map, 'click', (event)=>{
|
|
72
|
+
if (this.props.disabled || !this.state.marker || !this.state.maps) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.state.marker.setPosition(event.latLng);
|
|
76
|
+
this.state.marker.setVisible(true);
|
|
77
|
+
this.props.onChangeLocation({
|
|
78
|
+
lat: event.latLng.lat(),
|
|
79
|
+
lng: event.latLng.lng()
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
maps.event.addListener(marker, 'dragend', (event)=>{
|
|
83
|
+
this.props.onChangeLocation({
|
|
84
|
+
lat: event.latLng.lat(),
|
|
85
|
+
lng: event.latLng.lng()
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
this.setState({
|
|
89
|
+
marker,
|
|
90
|
+
maps
|
|
91
|
+
}, ()=>{
|
|
92
|
+
this.props.onGoogleApiLoaded({
|
|
93
|
+
maps
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
this.state = {
|
|
98
|
+
marker: undefined,
|
|
99
|
+
maps: undefined
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
16
|
+
import deepEqual from 'deep-equal';
|
|
17
|
+
import isNumber from 'lodash/isNumber';
|
|
18
|
+
import throttle from 'lodash/throttle';
|
|
19
|
+
import { GoogleMapView } from './GoogleMapView';
|
|
20
|
+
import { LocationSelector } from './LocationSelector';
|
|
21
|
+
import { ViewType } from './types';
|
|
22
|
+
function toLocationValue(coords) {
|
|
23
|
+
if (coords && isNumber(coords.lat) && isNumber(coords.lng)) {
|
|
24
|
+
return {
|
|
25
|
+
lat: coords.lat,
|
|
26
|
+
lon: coords.lng
|
|
27
|
+
};
|
|
28
|
+
} else {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class LocationEditor extends React.Component {
|
|
33
|
+
render() {
|
|
34
|
+
const { mapsObject , localValue } = this.state;
|
|
35
|
+
return React.createElement("div", {
|
|
36
|
+
"data-test-id": "location-editor"
|
|
37
|
+
}, React.createElement(GoogleMapView, {
|
|
38
|
+
disabled: this.props.disabled || mapsObject === null,
|
|
39
|
+
googleMapsKey: this.props.googleMapsKey,
|
|
40
|
+
location: localValue,
|
|
41
|
+
onGoogleApiLoaded: ({ maps })=>{
|
|
42
|
+
this.setState({
|
|
43
|
+
mapsObject: maps
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
onChangeLocation: (coords)=>{
|
|
47
|
+
this.setState({
|
|
48
|
+
localValue: coords
|
|
49
|
+
});
|
|
50
|
+
this.props.setValue(toLocationValue(coords));
|
|
51
|
+
}
|
|
52
|
+
}), React.createElement(LocationSelector, {
|
|
53
|
+
disabled: this.props.disabled || mapsObject === null,
|
|
54
|
+
value: localValue,
|
|
55
|
+
view: this.props.selectedView,
|
|
56
|
+
onChangeView: (view)=>{
|
|
57
|
+
this.props.setSelectedView(view);
|
|
58
|
+
},
|
|
59
|
+
onChangeLocation: (coords)=>{
|
|
60
|
+
this.setState({
|
|
61
|
+
localValue: coords
|
|
62
|
+
});
|
|
63
|
+
this.props.setValue(toLocationValue(coords));
|
|
64
|
+
},
|
|
65
|
+
onSearchAddress: this.onSearchAddress,
|
|
66
|
+
onGetAddressFromLocation: this.onGetAddressFromLocation
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
constructor(props){
|
|
70
|
+
super(props);
|
|
71
|
+
_define_property(this, "onSearchAddress", throttle((value)=>{
|
|
72
|
+
if (!this.state.mapsObject) {
|
|
73
|
+
return Promise.resolve(null);
|
|
74
|
+
}
|
|
75
|
+
const { mapsObject } = this.state;
|
|
76
|
+
if (!value) {
|
|
77
|
+
return Promise.resolve(null);
|
|
78
|
+
}
|
|
79
|
+
return new Promise((resolve)=>{
|
|
80
|
+
const geocoder = new mapsObject.Geocoder();
|
|
81
|
+
geocoder.geocode({
|
|
82
|
+
address: value
|
|
83
|
+
}, resolve, ()=>{
|
|
84
|
+
resolve(null);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}, 300));
|
|
88
|
+
_define_property(this, "onGetAddressFromLocation", (location, value)=>{
|
|
89
|
+
if (!this.state.mapsObject || !location) {
|
|
90
|
+
return Promise.resolve('');
|
|
91
|
+
}
|
|
92
|
+
const { mapsObject } = this.state;
|
|
93
|
+
return new Promise((resolve)=>{
|
|
94
|
+
const geocoder = new mapsObject.Geocoder();
|
|
95
|
+
geocoder.geocode({
|
|
96
|
+
location
|
|
97
|
+
}, (result)=>{
|
|
98
|
+
if (result && result.length > 0) {
|
|
99
|
+
const addresses = result.map((item)=>item.formatted_address);
|
|
100
|
+
resolve(addresses.find((item)=>item === value) || addresses[0]);
|
|
101
|
+
} else {
|
|
102
|
+
resolve('');
|
|
103
|
+
}
|
|
104
|
+
}, ()=>{
|
|
105
|
+
resolve('');
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
this.state = {
|
|
110
|
+
localValue: props.value ? {
|
|
111
|
+
lng: props.value.lon,
|
|
112
|
+
lat: props.value.lat
|
|
113
|
+
} : undefined,
|
|
114
|
+
mapsObject: null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function LocationEditorConnected(props) {
|
|
119
|
+
const { field } = props;
|
|
120
|
+
const googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;
|
|
121
|
+
const [selectedView, setSelectedView] = React.useState(ViewType.Address);
|
|
122
|
+
return React.createElement(FieldConnector, {
|
|
123
|
+
isEqualValues: (value1, value2)=>{
|
|
124
|
+
return deepEqual(value1, value2);
|
|
125
|
+
},
|
|
126
|
+
field: field,
|
|
127
|
+
isInitiallyDisabled: props.isInitiallyDisabled
|
|
128
|
+
}, ({ value , disabled , setValue , externalReset })=>{
|
|
129
|
+
return React.createElement(LocationEditor, {
|
|
130
|
+
key: `location-editor-${externalReset}`,
|
|
131
|
+
value: value,
|
|
132
|
+
disabled: disabled,
|
|
133
|
+
setValue: setValue,
|
|
134
|
+
googleMapsKey: googleMapsKey,
|
|
135
|
+
selectedView: selectedView,
|
|
136
|
+
setSelectedView: setSelectedView
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
LocationEditorConnected.defaultProps = {
|
|
141
|
+
isInitiallyDisabled: true
|
|
142
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Button, Card, Spinner, TextInput, ValidationMessage } from '@contentful/f36-components';
|
|
3
|
+
import tokens from '@contentful/f36-tokens';
|
|
4
|
+
import { css } from 'emotion';
|
|
5
|
+
const styles = {
|
|
6
|
+
root: css({
|
|
7
|
+
width: '100%'
|
|
8
|
+
}),
|
|
9
|
+
input: css({
|
|
10
|
+
position: 'relative',
|
|
11
|
+
width: '100%'
|
|
12
|
+
}),
|
|
13
|
+
spinner: css({
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
right: 10,
|
|
16
|
+
top: 10,
|
|
17
|
+
zIndex: 99
|
|
18
|
+
}),
|
|
19
|
+
validationMessage: css({
|
|
20
|
+
marginTop: tokens.spacingS
|
|
21
|
+
}),
|
|
22
|
+
suggestion: css({
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
transform: 'translateY(100%)',
|
|
25
|
+
bottom: 0,
|
|
26
|
+
left: 0,
|
|
27
|
+
zIndex: 1
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
export function LocationSearchInput(props) {
|
|
31
|
+
const [isSearching, setIsSearching] = React.useState(false);
|
|
32
|
+
const [address, setAddress] = React.useState('');
|
|
33
|
+
const [hasError, setHasError] = React.useState(false);
|
|
34
|
+
const [suggestion, setSuggestion] = React.useState(null);
|
|
35
|
+
React.useEffect(()=>{
|
|
36
|
+
setIsSearching(true);
|
|
37
|
+
props.onGetAddressFromLocation(props.value, address).then((address)=>{
|
|
38
|
+
setAddress(address);
|
|
39
|
+
setIsSearching(false);
|
|
40
|
+
});
|
|
41
|
+
}, [
|
|
42
|
+
props.value,
|
|
43
|
+
props.disabled
|
|
44
|
+
]);
|
|
45
|
+
return React.createElement("div", {
|
|
46
|
+
className: styles.root
|
|
47
|
+
}, React.createElement("div", {
|
|
48
|
+
className: styles.input
|
|
49
|
+
}, React.createElement(TextInput, {
|
|
50
|
+
testId: "location-editor-search",
|
|
51
|
+
isInvalid: hasError,
|
|
52
|
+
placeholder: "Start typing to find location",
|
|
53
|
+
value: address,
|
|
54
|
+
onChange: (e)=>{
|
|
55
|
+
setAddress(e.target.value);
|
|
56
|
+
setHasError(false);
|
|
57
|
+
setSuggestion(null);
|
|
58
|
+
if (e.target.value === '') {
|
|
59
|
+
props.onChangeLocation(undefined);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
setIsSearching(true);
|
|
63
|
+
props.onSearchAddress(e.target.value).then((value)=>{
|
|
64
|
+
setIsSearching(false);
|
|
65
|
+
if (value === null) {
|
|
66
|
+
setHasError(false);
|
|
67
|
+
} else if (value.length === 0) {
|
|
68
|
+
setHasError(true);
|
|
69
|
+
} else {
|
|
70
|
+
setHasError(false);
|
|
71
|
+
setSuggestion({
|
|
72
|
+
address: value[0].formatted_address,
|
|
73
|
+
location: {
|
|
74
|
+
lat: Number(value[0].geometry.location.lat().toString().slice(0, 8)),
|
|
75
|
+
lng: Number(value[0].geometry.location.lng().toString().slice(0, 8))
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
isDisabled: props.disabled
|
|
82
|
+
}), isSearching && React.createElement(Spinner, {
|
|
83
|
+
className: styles.spinner
|
|
84
|
+
}), suggestion && React.createElement(Card, {
|
|
85
|
+
padding: "none",
|
|
86
|
+
className: styles.suggestion
|
|
87
|
+
}, React.createElement(Button, {
|
|
88
|
+
variant: "transparent",
|
|
89
|
+
testId: "location-editor-suggestion",
|
|
90
|
+
onClick: ()=>{
|
|
91
|
+
setAddress(suggestion.address);
|
|
92
|
+
props.onChangeLocation(suggestion.location);
|
|
93
|
+
setSuggestion(null);
|
|
94
|
+
}
|
|
95
|
+
}, suggestion.address)), hasError && React.createElement(ValidationMessage, {
|
|
96
|
+
testId: "location-editor-not-found",
|
|
97
|
+
className: styles.validationMessage
|
|
98
|
+
}, "No results found for ", React.createElement("strong", null, address), ". Please make sure that address is spelled correctly.")));
|
|
99
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Flex, Radio, TextInput, TextLink } from '@contentful/f36-components';
|
|
3
|
+
import tokens from '@contentful/f36-tokens';
|
|
4
|
+
import { css } from 'emotion';
|
|
5
|
+
import { LocationSearchInput } from './LocationSearchInput';
|
|
6
|
+
import { ViewType } from './types';
|
|
7
|
+
const styles = {
|
|
8
|
+
root: css({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
flexDirection: 'row',
|
|
11
|
+
marginTop: tokens.spacingS,
|
|
12
|
+
alignItems: 'flex-end'
|
|
13
|
+
}),
|
|
14
|
+
main: css({
|
|
15
|
+
flexGrow: 1
|
|
16
|
+
}),
|
|
17
|
+
secondary: css({
|
|
18
|
+
minWidth: '70px',
|
|
19
|
+
textAlign: 'right'
|
|
20
|
+
}),
|
|
21
|
+
inputsRow: css({
|
|
22
|
+
display: 'flex',
|
|
23
|
+
marginTop: tokens.spacingS,
|
|
24
|
+
fontSize: tokens.fontSizeM,
|
|
25
|
+
color: tokens.gray900,
|
|
26
|
+
fontFamily: tokens.fontStackPrimary,
|
|
27
|
+
alignItems: 'center'
|
|
28
|
+
}),
|
|
29
|
+
splitter: css({
|
|
30
|
+
width: tokens.spacingL
|
|
31
|
+
}),
|
|
32
|
+
clearBtn: css({
|
|
33
|
+
marginBottom: tokens.spacingS
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
export function LocationSelector(props) {
|
|
37
|
+
return React.createElement("div", {
|
|
38
|
+
className: styles.root
|
|
39
|
+
}, React.createElement("div", {
|
|
40
|
+
className: styles.main
|
|
41
|
+
}, React.createElement(Flex, {
|
|
42
|
+
flexDirection: "row"
|
|
43
|
+
}, React.createElement(Radio, {
|
|
44
|
+
className: css({
|
|
45
|
+
flexBasis: '100%'
|
|
46
|
+
}),
|
|
47
|
+
id: ViewType.Address,
|
|
48
|
+
testId: "location-editor-address-radio",
|
|
49
|
+
isDisabled: props.disabled,
|
|
50
|
+
value: ViewType.Address,
|
|
51
|
+
isChecked: props.view === ViewType.Address,
|
|
52
|
+
onChange: ()=>{
|
|
53
|
+
props.onChangeView(ViewType.Address);
|
|
54
|
+
}
|
|
55
|
+
}, "Address"), React.createElement(Radio, {
|
|
56
|
+
className: css({
|
|
57
|
+
flexBasis: '100%'
|
|
58
|
+
}),
|
|
59
|
+
id: ViewType.Coordinates,
|
|
60
|
+
testId: "location-editor-coordinates-radio",
|
|
61
|
+
isDisabled: props.disabled,
|
|
62
|
+
value: ViewType.Coordinates,
|
|
63
|
+
isChecked: props.view === ViewType.Coordinates,
|
|
64
|
+
onChange: ()=>{
|
|
65
|
+
props.onChangeView(ViewType.Coordinates);
|
|
66
|
+
}
|
|
67
|
+
}, "Coordinates")), props.view === ViewType.Address && React.createElement("div", {
|
|
68
|
+
className: styles.inputsRow
|
|
69
|
+
}, React.createElement(LocationSearchInput, {
|
|
70
|
+
onSearchAddress: props.onSearchAddress,
|
|
71
|
+
onGetAddressFromLocation: props.onGetAddressFromLocation,
|
|
72
|
+
disabled: props.disabled,
|
|
73
|
+
value: props.value,
|
|
74
|
+
onChangeLocation: props.onChangeLocation
|
|
75
|
+
})), props.view === ViewType.Coordinates && React.createElement("div", {
|
|
76
|
+
className: styles.inputsRow
|
|
77
|
+
}, React.createElement("label", {
|
|
78
|
+
htmlFor: "latitude"
|
|
79
|
+
}, "Latitude"), React.createElement("div", {
|
|
80
|
+
className: styles.splitter
|
|
81
|
+
}), React.createElement(TextInput, {
|
|
82
|
+
id: "latitude",
|
|
83
|
+
testId: "location-editor-latitude",
|
|
84
|
+
placeholder: "Between -90 and 90",
|
|
85
|
+
isDisabled: props.disabled,
|
|
86
|
+
value: props.value ? String(props.value.lat) : '',
|
|
87
|
+
onChange: (e)=>{
|
|
88
|
+
props.onChangeLocation({
|
|
89
|
+
lng: props.value && props.value.lng !== undefined ? props.value.lng : 0,
|
|
90
|
+
lat: Number(e.target.value) || 0
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
type: "number",
|
|
94
|
+
max: "90",
|
|
95
|
+
min: "-90",
|
|
96
|
+
step: "0.1"
|
|
97
|
+
}), React.createElement("div", {
|
|
98
|
+
className: styles.splitter
|
|
99
|
+
}), React.createElement("label", {
|
|
100
|
+
htmlFor: "longitude"
|
|
101
|
+
}, "Longitude"), React.createElement("div", {
|
|
102
|
+
className: styles.splitter
|
|
103
|
+
}), React.createElement(TextInput, {
|
|
104
|
+
id: "longitude",
|
|
105
|
+
testId: "location-editor-longitude",
|
|
106
|
+
placeholder: "Between -180 and 180",
|
|
107
|
+
isDisabled: props.disabled,
|
|
108
|
+
value: props.value ? String(props.value.lng) : '',
|
|
109
|
+
onChange: (e)=>{
|
|
110
|
+
props.onChangeLocation({
|
|
111
|
+
lat: props.value && props.value.lat !== undefined ? props.value.lat : 0,
|
|
112
|
+
lng: Number(e.target.value) || 0
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
type: "number",
|
|
116
|
+
max: "180",
|
|
117
|
+
min: "-180",
|
|
118
|
+
step: "0.1"
|
|
119
|
+
}))), React.createElement("div", {
|
|
120
|
+
className: styles.secondary
|
|
121
|
+
}, React.createElement(TextLink, {
|
|
122
|
+
as: "button",
|
|
123
|
+
isDisabled: props.disabled,
|
|
124
|
+
testId: "location-editor-clear",
|
|
125
|
+
className: styles.clearBtn,
|
|
126
|
+
onClick: ()=>{
|
|
127
|
+
props.onChangeLocation(undefined);
|
|
128
|
+
}
|
|
129
|
+
}, "Clear")));
|
|
130
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Coords } from './types';
|
|
3
|
-
|
|
4
|
-
disabled: boolean;
|
|
5
|
-
location: Coords | undefined;
|
|
6
|
-
onGoogleApiLoaded: ({ maps }: {
|
|
7
|
-
maps: any;
|
|
8
|
-
}) => void;
|
|
9
|
-
onChangeLocation: (location: Coords) => void;
|
|
10
|
-
googleMapsKey?: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
marker: any;
|
|
14
|
-
maps: any;
|
|
15
|
-
};
|
|
16
|
-
export declare class GoogleMapView extends React.Component<GoogleMapViewProps, GoogleMapsViewState> {
|
|
17
|
-
constructor(props: GoogleMapViewProps);
|
|
18
|
-
componentDidUpdate(): void;
|
|
19
|
-
onGoogleApiLoaded: (event: {
|
|
20
|
-
maps: any;
|
|
21
|
-
map: any;
|
|
22
|
-
}) => void;
|
|
23
|
-
render(): JSX.Element;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Coords } from './types';
|
|
3
|
+
type GoogleMapViewProps = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
location: Coords | undefined;
|
|
6
|
+
onGoogleApiLoaded: ({ maps }: {
|
|
7
|
+
maps: any;
|
|
8
|
+
}) => void;
|
|
9
|
+
onChangeLocation: (location: Coords) => void;
|
|
10
|
+
googleMapsKey?: string;
|
|
11
|
+
};
|
|
12
|
+
type GoogleMapsViewState = {
|
|
13
|
+
marker: any;
|
|
14
|
+
maps: any;
|
|
15
|
+
};
|
|
16
|
+
export declare class GoogleMapView extends React.Component<GoogleMapViewProps, GoogleMapsViewState> {
|
|
17
|
+
constructor(props: GoogleMapViewProps);
|
|
18
|
+
componentDidUpdate(): void;
|
|
19
|
+
onGoogleApiLoaded: (event: {
|
|
20
|
+
maps: any;
|
|
21
|
+
map: any;
|
|
22
|
+
}) => void;
|
|
23
|
+
render(): React.JSX.Element;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { FieldAPI, ParametersAPI } from '@contentful/field-editor-shared';
|
|
3
|
-
import { ViewType, NullableLocationValue, Coords, GeocodeApiResponse } from './types';
|
|
4
|
-
export interface LocationEditorConnectedProps {
|
|
5
|
-
/**
|
|
6
|
-
* is the field disabled initially
|
|
7
|
-
*/
|
|
8
|
-
isInitiallyDisabled: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* sdk.field
|
|
11
|
-
*/
|
|
12
|
-
field: FieldAPI;
|
|
13
|
-
/**
|
|
14
|
-
* sdk.parameters
|
|
15
|
-
*/
|
|
16
|
-
parameters?: ParametersAPI & {
|
|
17
|
-
instance: {
|
|
18
|
-
googleMapsKey?: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
disabled: boolean;
|
|
24
|
-
value: NullableLocationValue;
|
|
25
|
-
setValue: (value: NullableLocationValue) => void;
|
|
26
|
-
googleMapsKey?: string;
|
|
27
|
-
selectedView: ViewType;
|
|
28
|
-
setSelectedView: (view: ViewType) => void;
|
|
29
|
-
};
|
|
30
|
-
export declare class LocationEditor extends React.Component<LocationEditorProps, {
|
|
31
|
-
localValue?: Coords;
|
|
32
|
-
mapsObject: any;
|
|
33
|
-
}> {
|
|
34
|
-
constructor(props: LocationEditorProps);
|
|
35
|
-
onSearchAddress: (value: string) => Promise<GeocodeApiResponse>;
|
|
36
|
-
onGetAddressFromLocation: (location: Coords | undefined, value: string) => Promise<string>;
|
|
37
|
-
render(): JSX.Element;
|
|
38
|
-
}
|
|
39
|
-
export declare function LocationEditorConnected(props: LocationEditorConnectedProps): JSX.Element;
|
|
40
|
-
export declare namespace LocationEditorConnected {
|
|
41
|
-
var defaultProps: {
|
|
42
|
-
isInitiallyDisabled: boolean;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FieldAPI, ParametersAPI } from '@contentful/field-editor-shared';
|
|
3
|
+
import { ViewType, NullableLocationValue, Coords, GeocodeApiResponse } from './types';
|
|
4
|
+
export interface LocationEditorConnectedProps {
|
|
5
|
+
/**
|
|
6
|
+
* is the field disabled initially
|
|
7
|
+
*/
|
|
8
|
+
isInitiallyDisabled: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* sdk.field
|
|
11
|
+
*/
|
|
12
|
+
field: FieldAPI;
|
|
13
|
+
/**
|
|
14
|
+
* sdk.parameters
|
|
15
|
+
*/
|
|
16
|
+
parameters?: ParametersAPI & {
|
|
17
|
+
instance: {
|
|
18
|
+
googleMapsKey?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
type LocationEditorProps = {
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
value: NullableLocationValue;
|
|
25
|
+
setValue: (value: NullableLocationValue) => void;
|
|
26
|
+
googleMapsKey?: string;
|
|
27
|
+
selectedView: ViewType;
|
|
28
|
+
setSelectedView: (view: ViewType) => void;
|
|
29
|
+
};
|
|
30
|
+
export declare class LocationEditor extends React.Component<LocationEditorProps, {
|
|
31
|
+
localValue?: Coords;
|
|
32
|
+
mapsObject: any;
|
|
33
|
+
}> {
|
|
34
|
+
constructor(props: LocationEditorProps);
|
|
35
|
+
onSearchAddress: (value: string) => Promise<GeocodeApiResponse>;
|
|
36
|
+
onGetAddressFromLocation: (location: Coords | undefined, value: string) => Promise<string>;
|
|
37
|
+
render(): React.JSX.Element;
|
|
38
|
+
}
|
|
39
|
+
export declare function LocationEditorConnected(props: LocationEditorConnectedProps): React.JSX.Element;
|
|
40
|
+
export declare namespace LocationEditorConnected {
|
|
41
|
+
var defaultProps: {
|
|
42
|
+
isInitiallyDisabled: boolean;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { Coords, GeocodeApiResponse } from './types';
|
|
3
|
-
|
|
4
|
-
disabled: boolean;
|
|
5
|
-
value?: Coords;
|
|
6
|
-
onSearchAddress: (term: string) => Promise<GeocodeApiResponse>;
|
|
7
|
-
onGetAddressFromLocation: (coors: Coords | undefined, value: string) => Promise<string>;
|
|
8
|
-
onChangeLocation: (location?: Coords) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare function LocationSearchInput(props: LocationSearchInputProps): JSX.Element;
|
|
11
|
-
export {};
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Coords, GeocodeApiResponse } from './types';
|
|
3
|
+
type LocationSearchInputProps = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
value?: Coords;
|
|
6
|
+
onSearchAddress: (term: string) => Promise<GeocodeApiResponse>;
|
|
7
|
+
onGetAddressFromLocation: (coors: Coords | undefined, value: string) => Promise<string>;
|
|
8
|
+
onChangeLocation: (location?: Coords) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function LocationSearchInput(props: LocationSearchInputProps): React.JSX.Element;
|
|
11
|
+
export {};
|