@contentful/field-editor-location 1.2.3 → 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 -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
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "GoogleMapView", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return GoogleMapView;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _emotion = require("emotion");
|
|
13
|
+
const _googlemapreact = _interop_require_default(require("google-map-react"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
const styles = {
|
|
72
|
+
root: (0, _emotion.css)({
|
|
73
|
+
height: '300px',
|
|
74
|
+
width: '100%'
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
const BerlinLocation = {
|
|
78
|
+
lat: 52.5018,
|
|
79
|
+
lng: 13.41115439
|
|
80
|
+
};
|
|
81
|
+
class GoogleMapView extends _react.Component {
|
|
82
|
+
componentDidUpdate() {
|
|
83
|
+
if (this.state.marker && this.state.maps) {
|
|
84
|
+
if (this.props.location) {
|
|
85
|
+
const latLng = new this.state.maps.LatLng(this.props.location.lat, this.props.location.lng);
|
|
86
|
+
this.state.marker.setPosition(latLng);
|
|
87
|
+
this.state.marker.setVisible(true);
|
|
88
|
+
} else {
|
|
89
|
+
this.state.marker.setVisible(false);
|
|
90
|
+
}
|
|
91
|
+
this.state.marker.setDraggable(!this.props.disabled);
|
|
92
|
+
this.state.marker.setCursor(this.props.disabled ? 'not-allowed' : 'auto');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
render() {
|
|
96
|
+
return _react.createElement("div", {
|
|
97
|
+
className: styles.root
|
|
98
|
+
}, _react.createElement(_googlemapreact.default, {
|
|
99
|
+
draggable: !this.props.disabled,
|
|
100
|
+
bootstrapURLKeys: this.props.googleMapsKey ? {
|
|
101
|
+
key: this.props.googleMapsKey
|
|
102
|
+
} : undefined,
|
|
103
|
+
defaultCenter: BerlinLocation,
|
|
104
|
+
center: this.props.location,
|
|
105
|
+
options: {
|
|
106
|
+
scrollwheel: false,
|
|
107
|
+
mapTypeId: 'roadmap'
|
|
108
|
+
},
|
|
109
|
+
defaultZoom: 6,
|
|
110
|
+
yesIWantToUseGoogleMapApiInternals: true,
|
|
111
|
+
onGoogleApiLoaded: this.onGoogleApiLoaded
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
constructor(props){
|
|
115
|
+
super(props);
|
|
116
|
+
_define_property(this, "onGoogleApiLoaded", (event)=>{
|
|
117
|
+
const { maps , map } = event;
|
|
118
|
+
const marker = new maps.Marker({
|
|
119
|
+
map,
|
|
120
|
+
position: map.getCenter(),
|
|
121
|
+
cursor: this.props.disabled ? 'not-allowed' : 'auto',
|
|
122
|
+
draggable: !this.props.disabled,
|
|
123
|
+
visible: Boolean(this.props.location)
|
|
124
|
+
});
|
|
125
|
+
maps.event.addListener(map, 'click', (event)=>{
|
|
126
|
+
if (this.props.disabled || !this.state.marker || !this.state.maps) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.state.marker.setPosition(event.latLng);
|
|
130
|
+
this.state.marker.setVisible(true);
|
|
131
|
+
this.props.onChangeLocation({
|
|
132
|
+
lat: event.latLng.lat(),
|
|
133
|
+
lng: event.latLng.lng()
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
maps.event.addListener(marker, 'dragend', (event)=>{
|
|
137
|
+
this.props.onChangeLocation({
|
|
138
|
+
lat: event.latLng.lat(),
|
|
139
|
+
lng: event.latLng.lng()
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
this.setState({
|
|
143
|
+
marker,
|
|
144
|
+
maps
|
|
145
|
+
}, ()=>{
|
|
146
|
+
this.props.onGoogleApiLoaded({
|
|
147
|
+
maps
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
this.state = {
|
|
152
|
+
marker: undefined,
|
|
153
|
+
maps: undefined
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
LocationEditor: function() {
|
|
13
|
+
return LocationEditor;
|
|
14
|
+
},
|
|
15
|
+
LocationEditorConnected: function() {
|
|
16
|
+
return LocationEditorConnected;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
20
|
+
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
21
|
+
const _deepequal = _interop_require_default(require("deep-equal"));
|
|
22
|
+
const _isNumber = _interop_require_default(require("lodash/isNumber"));
|
|
23
|
+
const _throttle = _interop_require_default(require("lodash/throttle"));
|
|
24
|
+
const _GoogleMapView = require("./GoogleMapView");
|
|
25
|
+
const _LocationSelector = require("./LocationSelector");
|
|
26
|
+
const _types = require("./types");
|
|
27
|
+
function _define_property(obj, key, value) {
|
|
28
|
+
if (key in obj) {
|
|
29
|
+
Object.defineProperty(obj, key, {
|
|
30
|
+
value: value,
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
obj[key] = value;
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
function _interop_require_default(obj) {
|
|
41
|
+
return obj && obj.__esModule ? obj : {
|
|
42
|
+
default: obj
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
46
|
+
if (typeof WeakMap !== "function") return null;
|
|
47
|
+
var cacheBabelInterop = new WeakMap();
|
|
48
|
+
var cacheNodeInterop = new WeakMap();
|
|
49
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
50
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
51
|
+
})(nodeInterop);
|
|
52
|
+
}
|
|
53
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
54
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
58
|
+
return {
|
|
59
|
+
default: obj
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
63
|
+
if (cache && cache.has(obj)) {
|
|
64
|
+
return cache.get(obj);
|
|
65
|
+
}
|
|
66
|
+
var newObj = {};
|
|
67
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
68
|
+
for(var key in obj){
|
|
69
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
70
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
71
|
+
if (desc && (desc.get || desc.set)) {
|
|
72
|
+
Object.defineProperty(newObj, key, desc);
|
|
73
|
+
} else {
|
|
74
|
+
newObj[key] = obj[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
newObj.default = obj;
|
|
79
|
+
if (cache) {
|
|
80
|
+
cache.set(obj, newObj);
|
|
81
|
+
}
|
|
82
|
+
return newObj;
|
|
83
|
+
}
|
|
84
|
+
function toLocationValue(coords) {
|
|
85
|
+
if (coords && (0, _isNumber.default)(coords.lat) && (0, _isNumber.default)(coords.lng)) {
|
|
86
|
+
return {
|
|
87
|
+
lat: coords.lat,
|
|
88
|
+
lon: coords.lng
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class LocationEditor extends _react.Component {
|
|
95
|
+
render() {
|
|
96
|
+
const { mapsObject , localValue } = this.state;
|
|
97
|
+
return _react.createElement("div", {
|
|
98
|
+
"data-test-id": "location-editor"
|
|
99
|
+
}, _react.createElement(_GoogleMapView.GoogleMapView, {
|
|
100
|
+
disabled: this.props.disabled || mapsObject === null,
|
|
101
|
+
googleMapsKey: this.props.googleMapsKey,
|
|
102
|
+
location: localValue,
|
|
103
|
+
onGoogleApiLoaded: ({ maps })=>{
|
|
104
|
+
this.setState({
|
|
105
|
+
mapsObject: maps
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
onChangeLocation: (coords)=>{
|
|
109
|
+
this.setState({
|
|
110
|
+
localValue: coords
|
|
111
|
+
});
|
|
112
|
+
this.props.setValue(toLocationValue(coords));
|
|
113
|
+
}
|
|
114
|
+
}), _react.createElement(_LocationSelector.LocationSelector, {
|
|
115
|
+
disabled: this.props.disabled || mapsObject === null,
|
|
116
|
+
value: localValue,
|
|
117
|
+
view: this.props.selectedView,
|
|
118
|
+
onChangeView: (view)=>{
|
|
119
|
+
this.props.setSelectedView(view);
|
|
120
|
+
},
|
|
121
|
+
onChangeLocation: (coords)=>{
|
|
122
|
+
this.setState({
|
|
123
|
+
localValue: coords
|
|
124
|
+
});
|
|
125
|
+
this.props.setValue(toLocationValue(coords));
|
|
126
|
+
},
|
|
127
|
+
onSearchAddress: this.onSearchAddress,
|
|
128
|
+
onGetAddressFromLocation: this.onGetAddressFromLocation
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
constructor(props){
|
|
132
|
+
super(props);
|
|
133
|
+
_define_property(this, "onSearchAddress", (0, _throttle.default)((value)=>{
|
|
134
|
+
if (!this.state.mapsObject) {
|
|
135
|
+
return Promise.resolve(null);
|
|
136
|
+
}
|
|
137
|
+
const { mapsObject } = this.state;
|
|
138
|
+
if (!value) {
|
|
139
|
+
return Promise.resolve(null);
|
|
140
|
+
}
|
|
141
|
+
return new Promise((resolve)=>{
|
|
142
|
+
const geocoder = new mapsObject.Geocoder();
|
|
143
|
+
geocoder.geocode({
|
|
144
|
+
address: value
|
|
145
|
+
}, resolve, ()=>{
|
|
146
|
+
resolve(null);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}, 300));
|
|
150
|
+
_define_property(this, "onGetAddressFromLocation", (location, value)=>{
|
|
151
|
+
if (!this.state.mapsObject || !location) {
|
|
152
|
+
return Promise.resolve('');
|
|
153
|
+
}
|
|
154
|
+
const { mapsObject } = this.state;
|
|
155
|
+
return new Promise((resolve)=>{
|
|
156
|
+
const geocoder = new mapsObject.Geocoder();
|
|
157
|
+
geocoder.geocode({
|
|
158
|
+
location
|
|
159
|
+
}, (result)=>{
|
|
160
|
+
if (result && result.length > 0) {
|
|
161
|
+
const addresses = result.map((item)=>item.formatted_address);
|
|
162
|
+
resolve(addresses.find((item)=>item === value) || addresses[0]);
|
|
163
|
+
} else {
|
|
164
|
+
resolve('');
|
|
165
|
+
}
|
|
166
|
+
}, ()=>{
|
|
167
|
+
resolve('');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
this.state = {
|
|
172
|
+
localValue: props.value ? {
|
|
173
|
+
lng: props.value.lon,
|
|
174
|
+
lat: props.value.lat
|
|
175
|
+
} : undefined,
|
|
176
|
+
mapsObject: null
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function LocationEditorConnected(props) {
|
|
181
|
+
const { field } = props;
|
|
182
|
+
const googleMapsKey = props.parameters ? props.parameters.instance.googleMapsKey : undefined;
|
|
183
|
+
const [selectedView, setSelectedView] = _react.useState(_types.ViewType.Address);
|
|
184
|
+
return _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
185
|
+
isEqualValues: (value1, value2)=>{
|
|
186
|
+
return (0, _deepequal.default)(value1, value2);
|
|
187
|
+
},
|
|
188
|
+
field: field,
|
|
189
|
+
isInitiallyDisabled: props.isInitiallyDisabled
|
|
190
|
+
}, ({ value , disabled , setValue , externalReset })=>{
|
|
191
|
+
return _react.createElement(LocationEditor, {
|
|
192
|
+
key: `location-editor-${externalReset}`,
|
|
193
|
+
value: value,
|
|
194
|
+
disabled: disabled,
|
|
195
|
+
setValue: setValue,
|
|
196
|
+
googleMapsKey: googleMapsKey,
|
|
197
|
+
selectedView: selectedView,
|
|
198
|
+
setSelectedView: setSelectedView
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
LocationEditorConnected.defaultProps = {
|
|
203
|
+
isInitiallyDisabled: true
|
|
204
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LocationSearchInput", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LocationSearchInput;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
14
|
+
const _emotion = require("emotion");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
21
|
+
if (typeof WeakMap !== "function") return null;
|
|
22
|
+
var cacheBabelInterop = new WeakMap();
|
|
23
|
+
var cacheNodeInterop = new WeakMap();
|
|
24
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
25
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
26
|
+
})(nodeInterop);
|
|
27
|
+
}
|
|
28
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
29
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
33
|
+
return {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
38
|
+
if (cache && cache.has(obj)) {
|
|
39
|
+
return cache.get(obj);
|
|
40
|
+
}
|
|
41
|
+
var newObj = {};
|
|
42
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
|
+
for(var key in obj){
|
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
46
|
+
if (desc && (desc.get || desc.set)) {
|
|
47
|
+
Object.defineProperty(newObj, key, desc);
|
|
48
|
+
} else {
|
|
49
|
+
newObj[key] = obj[key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
newObj.default = obj;
|
|
54
|
+
if (cache) {
|
|
55
|
+
cache.set(obj, newObj);
|
|
56
|
+
}
|
|
57
|
+
return newObj;
|
|
58
|
+
}
|
|
59
|
+
const styles = {
|
|
60
|
+
root: (0, _emotion.css)({
|
|
61
|
+
width: '100%'
|
|
62
|
+
}),
|
|
63
|
+
input: (0, _emotion.css)({
|
|
64
|
+
position: 'relative',
|
|
65
|
+
width: '100%'
|
|
66
|
+
}),
|
|
67
|
+
spinner: (0, _emotion.css)({
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
right: 10,
|
|
70
|
+
top: 10,
|
|
71
|
+
zIndex: 99
|
|
72
|
+
}),
|
|
73
|
+
validationMessage: (0, _emotion.css)({
|
|
74
|
+
marginTop: _f36tokens.default.spacingS
|
|
75
|
+
}),
|
|
76
|
+
suggestion: (0, _emotion.css)({
|
|
77
|
+
position: 'absolute',
|
|
78
|
+
transform: 'translateY(100%)',
|
|
79
|
+
bottom: 0,
|
|
80
|
+
left: 0,
|
|
81
|
+
zIndex: 1
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
function LocationSearchInput(props) {
|
|
85
|
+
const [isSearching, setIsSearching] = _react.useState(false);
|
|
86
|
+
const [address, setAddress] = _react.useState('');
|
|
87
|
+
const [hasError, setHasError] = _react.useState(false);
|
|
88
|
+
const [suggestion, setSuggestion] = _react.useState(null);
|
|
89
|
+
_react.useEffect(()=>{
|
|
90
|
+
setIsSearching(true);
|
|
91
|
+
props.onGetAddressFromLocation(props.value, address).then((address)=>{
|
|
92
|
+
setAddress(address);
|
|
93
|
+
setIsSearching(false);
|
|
94
|
+
});
|
|
95
|
+
}, [
|
|
96
|
+
props.value,
|
|
97
|
+
props.disabled
|
|
98
|
+
]);
|
|
99
|
+
return _react.createElement("div", {
|
|
100
|
+
className: styles.root
|
|
101
|
+
}, _react.createElement("div", {
|
|
102
|
+
className: styles.input
|
|
103
|
+
}, _react.createElement(_f36components.TextInput, {
|
|
104
|
+
testId: "location-editor-search",
|
|
105
|
+
isInvalid: hasError,
|
|
106
|
+
placeholder: "Start typing to find location",
|
|
107
|
+
value: address,
|
|
108
|
+
onChange: (e)=>{
|
|
109
|
+
setAddress(e.target.value);
|
|
110
|
+
setHasError(false);
|
|
111
|
+
setSuggestion(null);
|
|
112
|
+
if (e.target.value === '') {
|
|
113
|
+
props.onChangeLocation(undefined);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setIsSearching(true);
|
|
117
|
+
props.onSearchAddress(e.target.value).then((value)=>{
|
|
118
|
+
setIsSearching(false);
|
|
119
|
+
if (value === null) {
|
|
120
|
+
setHasError(false);
|
|
121
|
+
} else if (value.length === 0) {
|
|
122
|
+
setHasError(true);
|
|
123
|
+
} else {
|
|
124
|
+
setHasError(false);
|
|
125
|
+
setSuggestion({
|
|
126
|
+
address: value[0].formatted_address,
|
|
127
|
+
location: {
|
|
128
|
+
lat: Number(value[0].geometry.location.lat().toString().slice(0, 8)),
|
|
129
|
+
lng: Number(value[0].geometry.location.lng().toString().slice(0, 8))
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
isDisabled: props.disabled
|
|
136
|
+
}), isSearching && _react.createElement(_f36components.Spinner, {
|
|
137
|
+
className: styles.spinner
|
|
138
|
+
}), suggestion && _react.createElement(_f36components.Card, {
|
|
139
|
+
padding: "none",
|
|
140
|
+
className: styles.suggestion
|
|
141
|
+
}, _react.createElement(_f36components.Button, {
|
|
142
|
+
variant: "transparent",
|
|
143
|
+
testId: "location-editor-suggestion",
|
|
144
|
+
onClick: ()=>{
|
|
145
|
+
setAddress(suggestion.address);
|
|
146
|
+
props.onChangeLocation(suggestion.location);
|
|
147
|
+
setSuggestion(null);
|
|
148
|
+
}
|
|
149
|
+
}, suggestion.address)), hasError && _react.createElement(_f36components.ValidationMessage, {
|
|
150
|
+
testId: "location-editor-not-found",
|
|
151
|
+
className: styles.validationMessage
|
|
152
|
+
}, "No results found for ", _react.createElement("strong", null, address), ". Please make sure that address is spelled correctly.")));
|
|
153
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LocationSelector", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LocationSelector;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
14
|
+
const _emotion = require("emotion");
|
|
15
|
+
const _LocationSearchInput = require("./LocationSearchInput");
|
|
16
|
+
const _types = require("./types");
|
|
17
|
+
function _interop_require_default(obj) {
|
|
18
|
+
return obj && obj.__esModule ? obj : {
|
|
19
|
+
default: obj
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
23
|
+
if (typeof WeakMap !== "function") return null;
|
|
24
|
+
var cacheBabelInterop = new WeakMap();
|
|
25
|
+
var cacheNodeInterop = new WeakMap();
|
|
26
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
27
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
28
|
+
})(nodeInterop);
|
|
29
|
+
}
|
|
30
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
31
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
35
|
+
return {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
40
|
+
if (cache && cache.has(obj)) {
|
|
41
|
+
return cache.get(obj);
|
|
42
|
+
}
|
|
43
|
+
var newObj = {};
|
|
44
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
45
|
+
for(var key in obj){
|
|
46
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
47
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
48
|
+
if (desc && (desc.get || desc.set)) {
|
|
49
|
+
Object.defineProperty(newObj, key, desc);
|
|
50
|
+
} else {
|
|
51
|
+
newObj[key] = obj[key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
newObj.default = obj;
|
|
56
|
+
if (cache) {
|
|
57
|
+
cache.set(obj, newObj);
|
|
58
|
+
}
|
|
59
|
+
return newObj;
|
|
60
|
+
}
|
|
61
|
+
const styles = {
|
|
62
|
+
root: (0, _emotion.css)({
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'row',
|
|
65
|
+
marginTop: _f36tokens.default.spacingS,
|
|
66
|
+
alignItems: 'flex-end'
|
|
67
|
+
}),
|
|
68
|
+
main: (0, _emotion.css)({
|
|
69
|
+
flexGrow: 1
|
|
70
|
+
}),
|
|
71
|
+
secondary: (0, _emotion.css)({
|
|
72
|
+
minWidth: '70px',
|
|
73
|
+
textAlign: 'right'
|
|
74
|
+
}),
|
|
75
|
+
inputsRow: (0, _emotion.css)({
|
|
76
|
+
display: 'flex',
|
|
77
|
+
marginTop: _f36tokens.default.spacingS,
|
|
78
|
+
fontSize: _f36tokens.default.fontSizeM,
|
|
79
|
+
color: _f36tokens.default.gray900,
|
|
80
|
+
fontFamily: _f36tokens.default.fontStackPrimary,
|
|
81
|
+
alignItems: 'center'
|
|
82
|
+
}),
|
|
83
|
+
splitter: (0, _emotion.css)({
|
|
84
|
+
width: _f36tokens.default.spacingL
|
|
85
|
+
}),
|
|
86
|
+
clearBtn: (0, _emotion.css)({
|
|
87
|
+
marginBottom: _f36tokens.default.spacingS
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
function LocationSelector(props) {
|
|
91
|
+
return _react.createElement("div", {
|
|
92
|
+
className: styles.root
|
|
93
|
+
}, _react.createElement("div", {
|
|
94
|
+
className: styles.main
|
|
95
|
+
}, _react.createElement(_f36components.Flex, {
|
|
96
|
+
flexDirection: "row"
|
|
97
|
+
}, _react.createElement(_f36components.Radio, {
|
|
98
|
+
className: (0, _emotion.css)({
|
|
99
|
+
flexBasis: '100%'
|
|
100
|
+
}),
|
|
101
|
+
id: _types.ViewType.Address,
|
|
102
|
+
testId: "location-editor-address-radio",
|
|
103
|
+
isDisabled: props.disabled,
|
|
104
|
+
value: _types.ViewType.Address,
|
|
105
|
+
isChecked: props.view === _types.ViewType.Address,
|
|
106
|
+
onChange: ()=>{
|
|
107
|
+
props.onChangeView(_types.ViewType.Address);
|
|
108
|
+
}
|
|
109
|
+
}, "Address"), _react.createElement(_f36components.Radio, {
|
|
110
|
+
className: (0, _emotion.css)({
|
|
111
|
+
flexBasis: '100%'
|
|
112
|
+
}),
|
|
113
|
+
id: _types.ViewType.Coordinates,
|
|
114
|
+
testId: "location-editor-coordinates-radio",
|
|
115
|
+
isDisabled: props.disabled,
|
|
116
|
+
value: _types.ViewType.Coordinates,
|
|
117
|
+
isChecked: props.view === _types.ViewType.Coordinates,
|
|
118
|
+
onChange: ()=>{
|
|
119
|
+
props.onChangeView(_types.ViewType.Coordinates);
|
|
120
|
+
}
|
|
121
|
+
}, "Coordinates")), props.view === _types.ViewType.Address && _react.createElement("div", {
|
|
122
|
+
className: styles.inputsRow
|
|
123
|
+
}, _react.createElement(_LocationSearchInput.LocationSearchInput, {
|
|
124
|
+
onSearchAddress: props.onSearchAddress,
|
|
125
|
+
onGetAddressFromLocation: props.onGetAddressFromLocation,
|
|
126
|
+
disabled: props.disabled,
|
|
127
|
+
value: props.value,
|
|
128
|
+
onChangeLocation: props.onChangeLocation
|
|
129
|
+
})), props.view === _types.ViewType.Coordinates && _react.createElement("div", {
|
|
130
|
+
className: styles.inputsRow
|
|
131
|
+
}, _react.createElement("label", {
|
|
132
|
+
htmlFor: "latitude"
|
|
133
|
+
}, "Latitude"), _react.createElement("div", {
|
|
134
|
+
className: styles.splitter
|
|
135
|
+
}), _react.createElement(_f36components.TextInput, {
|
|
136
|
+
id: "latitude",
|
|
137
|
+
testId: "location-editor-latitude",
|
|
138
|
+
placeholder: "Between -90 and 90",
|
|
139
|
+
isDisabled: props.disabled,
|
|
140
|
+
value: props.value ? String(props.value.lat) : '',
|
|
141
|
+
onChange: (e)=>{
|
|
142
|
+
props.onChangeLocation({
|
|
143
|
+
lng: props.value && props.value.lng !== undefined ? props.value.lng : 0,
|
|
144
|
+
lat: Number(e.target.value) || 0
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
type: "number",
|
|
148
|
+
max: "90",
|
|
149
|
+
min: "-90",
|
|
150
|
+
step: "0.1"
|
|
151
|
+
}), _react.createElement("div", {
|
|
152
|
+
className: styles.splitter
|
|
153
|
+
}), _react.createElement("label", {
|
|
154
|
+
htmlFor: "longitude"
|
|
155
|
+
}, "Longitude"), _react.createElement("div", {
|
|
156
|
+
className: styles.splitter
|
|
157
|
+
}), _react.createElement(_f36components.TextInput, {
|
|
158
|
+
id: "longitude",
|
|
159
|
+
testId: "location-editor-longitude",
|
|
160
|
+
placeholder: "Between -180 and 180",
|
|
161
|
+
isDisabled: props.disabled,
|
|
162
|
+
value: props.value ? String(props.value.lng) : '',
|
|
163
|
+
onChange: (e)=>{
|
|
164
|
+
props.onChangeLocation({
|
|
165
|
+
lat: props.value && props.value.lat !== undefined ? props.value.lat : 0,
|
|
166
|
+
lng: Number(e.target.value) || 0
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
type: "number",
|
|
170
|
+
max: "180",
|
|
171
|
+
min: "-180",
|
|
172
|
+
step: "0.1"
|
|
173
|
+
}))), _react.createElement("div", {
|
|
174
|
+
className: styles.secondary
|
|
175
|
+
}, _react.createElement(_f36components.TextLink, {
|
|
176
|
+
as: "button",
|
|
177
|
+
isDisabled: props.disabled,
|
|
178
|
+
testId: "location-editor-clear",
|
|
179
|
+
className: styles.clearBtn,
|
|
180
|
+
onClick: ()=>{
|
|
181
|
+
props.onChangeLocation(undefined);
|
|
182
|
+
}
|
|
183
|
+
}, "Clear")));
|
|
184
|
+
}
|