@sanity/google-maps-input 2.25.4 → 2.26.1-purple-unicorn.560
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/diff/resolver.js +7 -0
- package/input/GeopointInput.js +7 -0
- package/lib/_Marker-20984c4d.cjs +331 -0
- package/lib/_Marker-20984c4d.cjs.map +1 -0
- package/lib/_Marker-96f5387c.js +302 -0
- package/lib/_Marker-96f5387c.js.map +1 -0
- package/lib/_reExport.js +19 -0
- package/lib/diff/resolver.cjs +204 -0
- package/lib/diff/resolver.cjs.map +1 -0
- package/lib/diff/resolver.js +169 -17
- package/lib/diff/resolver.js.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointArrayDiff.d.ts +4 -4
- package/lib/dts/src/diff/GeopointArrayDiff.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointFieldDiff.d.ts +4 -4
- package/lib/dts/src/diff/GeopointFieldDiff.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointFieldDiff.styles.d.ts +1 -1
- package/lib/dts/src/diff/GeopointFieldDiff.styles.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointMove.d.ts +12 -12
- package/lib/dts/src/diff/GeopointMove.d.ts.map +1 -0
- package/lib/dts/src/diff/resolver.d.ts +4 -0
- package/lib/dts/src/diff/resolver.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointInput.d.ts +27 -39
- package/lib/dts/src/input/GeopointInput.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointInput.styles.d.ts +2 -2
- package/lib/dts/src/input/GeopointInput.styles.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointSelect.d.ts +27 -27
- package/lib/dts/src/input/GeopointSelect.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/GoogleMapsLoadProxy.d.ts +13 -13
- package/lib/dts/src/loader/GoogleMapsLoadProxy.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/LoadError.d.ts +9 -9
- package/lib/dts/src/loader/LoadError.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/loadGoogleMapsApi.d.ts +17 -17
- package/lib/dts/src/loader/loadGoogleMapsApi.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Arrow.d.ts +28 -28
- package/lib/dts/src/map/Arrow.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Map.d.ts +36 -36
- package/lib/dts/src/map/Map.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Map.styles.d.ts +1 -1
- package/lib/dts/src/map/Map.styles.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Marker.d.ts +33 -35
- package/lib/dts/src/map/Marker.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/SearchInput.d.ts +15 -15
- package/lib/dts/src/map/SearchInput.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/SearchInput.styles.d.ts +1 -1
- package/lib/dts/src/map/SearchInput.styles.d.ts.map +1 -0
- package/{dist/dts → lib/dts/src}/map/util.d.ts +3 -3
- package/lib/dts/src/map/util.d.ts.map +1 -0
- package/lib/dts/src/types.d.ts +17 -0
- package/lib/dts/src/types.d.ts.map +1 -0
- package/lib/input/GeopointInput.cjs +228 -0
- package/lib/input/GeopointInput.cjs.map +1 -0
- package/lib/input/GeopointInput.js +198 -190
- package/lib/input/GeopointInput.js.map +1 -0
- package/package.json +34 -11
- package/src/@types/css.d.ts +4 -0
- package/src/diff/GeopointArrayDiff.tsx +83 -0
- package/src/diff/GeopointFieldDiff.styles.tsx +20 -0
- package/src/diff/GeopointFieldDiff.tsx +94 -0
- package/src/diff/GeopointMove.tsx +49 -0
- package/src/diff/resolver.ts +21 -0
- package/src/input/GeopointInput.styles.tsx +12 -0
- package/src/input/GeopointInput.tsx +221 -0
- package/src/input/GeopointSelect.tsx +78 -0
- package/src/loader/GoogleMapsLoadProxy.tsx +49 -0
- package/src/loader/LoadError.tsx +44 -0
- package/src/loader/loadGoogleMapsApi.ts +93 -0
- package/src/map/Arrow.tsx +76 -0
- package/src/map/Map.styles.tsx +10 -0
- package/src/map/Map.tsx +125 -0
- package/src/map/Marker.tsx +130 -0
- package/src/map/SearchInput.styles.tsx +8 -0
- package/src/map/SearchInput.tsx +56 -0
- package/src/map/util.ts +14 -0
- package/src/types.ts +19 -0
- package/.depcheckignore.json +0 -3
- package/dist/dts/diff/GeopointArrayDiff.d.ts.map +0 -1
- package/dist/dts/diff/GeopointFieldDiff.d.ts.map +0 -1
- package/dist/dts/diff/GeopointFieldDiff.styles.d.ts.map +0 -1
- package/dist/dts/diff/GeopointMove.d.ts.map +0 -1
- package/dist/dts/diff/resolver.d.ts +0 -4
- package/dist/dts/diff/resolver.d.ts.map +0 -1
- package/dist/dts/input/GeopointInput.d.ts.map +0 -1
- package/dist/dts/input/GeopointInput.styles.d.ts.map +0 -1
- package/dist/dts/input/GeopointSelect.d.ts.map +0 -1
- package/dist/dts/loader/GoogleMapsLoadProxy.d.ts.map +0 -1
- package/dist/dts/loader/LoadError.d.ts.map +0 -1
- package/dist/dts/loader/loadGoogleMapsApi.d.ts.map +0 -1
- package/dist/dts/map/Arrow.d.ts.map +0 -1
- package/dist/dts/map/Map.d.ts.map +0 -1
- package/dist/dts/map/Map.styles.d.ts.map +0 -1
- package/dist/dts/map/Marker.d.ts.map +0 -1
- package/dist/dts/map/SearchInput.d.ts.map +0 -1
- package/dist/dts/map/SearchInput.styles.d.ts.map +0 -1
- package/dist/dts/map/util.d.ts.map +0 -1
- package/dist/dts/types.d.ts +0 -14
- package/dist/dts/types.d.ts.map +0 -1
- package/lib/@types/css.d.js +0 -1
- package/lib/diff/GeopointArrayDiff.js +0 -82
- package/lib/diff/GeopointFieldDiff.js +0 -97
- package/lib/diff/GeopointFieldDiff.styles.js +0 -18
- package/lib/diff/GeopointMove.js +0 -55
- package/lib/input/GeopointInput.styles.js +0 -22
- package/lib/input/GeopointSelect.js +0 -103
- package/lib/loader/GoogleMapsLoadProxy.js +0 -70
- package/lib/loader/LoadError.js +0 -43
- package/lib/loader/loadGoogleMapsApi.js +0 -81
- package/lib/map/Arrow.js +0 -97
- package/lib/map/Map.js +0 -147
- package/lib/map/Map.styles.js +0 -18
- package/lib/map/Marker.js +0 -156
- package/lib/map/SearchInput.js +0 -77
- package/lib/map/SearchInput.styles.js +0 -18
- package/lib/map/util.js +0 -14
- package/lib/types.js +0 -5
- package/tsconfig.json +0 -20
|
@@ -1,194 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
constructor(props) {
|
|
52
|
-
super(props);
|
|
53
|
-
|
|
54
|
-
_defineProperty(this, "_geopointInputId", (0, _uniqueId2.default)('GeopointInput'));
|
|
55
|
-
|
|
56
|
-
_defineProperty(this, "editButton", void 0);
|
|
57
|
-
|
|
58
|
-
_defineProperty(this, "setEditButton", el => {
|
|
59
|
-
this.editButton = el;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
_defineProperty(this, "handleFocus", event => {
|
|
63
|
-
this.props.onFocus(event);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
_defineProperty(this, "handleBlur", () => {
|
|
67
|
-
this.props.onBlur();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
_defineProperty(this, "handleToggleModal", () => {
|
|
71
|
-
var _this$props = this.props,
|
|
72
|
-
onFocus = _this$props.onFocus,
|
|
73
|
-
onBlur = _this$props.onBlur;
|
|
74
|
-
this.setState(prevState => ({
|
|
75
|
-
modalOpen: !prevState.modalOpen
|
|
76
|
-
}), () => {
|
|
77
|
-
if (this.state.modalOpen) {
|
|
78
|
-
onFocus(['$']);
|
|
79
|
-
} else {
|
|
80
|
-
onBlur();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
_defineProperty(this, "handleCloseModal", () => {
|
|
86
|
-
this.setState({
|
|
87
|
-
modalOpen: false
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
_defineProperty(this, "handleChange", latLng => {
|
|
92
|
-
var _this$props2 = this.props,
|
|
93
|
-
type = _this$props2.type,
|
|
94
|
-
onChange = _this$props2.onChange;
|
|
95
|
-
onChange(_patchEvent.PatchEvent.from([(0, _patchEvent.setIfMissing)({
|
|
96
|
-
_type: type.name
|
|
97
|
-
}), (0, _patchEvent.set)(latLng.lat(), ['lat']), (0, _patchEvent.set)(latLng.lng(), ['lng'])]));
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
_defineProperty(this, "handleClear", () => {
|
|
101
|
-
var onChange = this.props.onChange;
|
|
102
|
-
onChange(_patchEvent.PatchEvent.from((0, _patchEvent.unset)()));
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
this.state = {
|
|
106
|
-
modalOpen: false
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
focus() {
|
|
111
|
-
if (this.editButton) {
|
|
112
|
-
this.editButton.focus();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
render() {
|
|
117
|
-
var _this$props3 = this.props,
|
|
118
|
-
value = _this$props3.value,
|
|
119
|
-
compareValue = _this$props3.compareValue,
|
|
120
|
-
readOnly = _this$props3.readOnly,
|
|
121
|
-
type = _this$props3.type,
|
|
122
|
-
markers = _this$props3.markers,
|
|
123
|
-
level = _this$props3.level,
|
|
124
|
-
presence = _this$props3.presence;
|
|
125
|
-
var modalOpen = this.state.modalOpen;
|
|
126
|
-
|
|
127
|
-
if (!_googleMapsInput.default || !_googleMapsInput.default.apiKey) {
|
|
128
|
-
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("p", null, "The ", /*#__PURE__*/_react.default.createElement("a", {
|
|
129
|
-
href: "https://sanity.io/docs/schema-types/geopoint-type"
|
|
130
|
-
}, "Geopoint type"), " needs a Google Maps API key with access to:"), /*#__PURE__*/_react.default.createElement("ul", null, /*#__PURE__*/_react.default.createElement("li", null, "Google Maps JavaScript API"), /*#__PURE__*/_react.default.createElement("li", null, "Google Places API Web Service"), /*#__PURE__*/_react.default.createElement("li", null, "Google Static Maps API")), /*#__PURE__*/_react.default.createElement("p", null, "Please enter the API key with access to these services in", /*#__PURE__*/_react.default.createElement("code", {
|
|
131
|
-
style: {
|
|
132
|
-
whiteSpace: 'nowrap'
|
|
133
|
-
}
|
|
134
|
-
}, "`<project-root>/config/@sanity/google-maps-input.json`")));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return /*#__PURE__*/_react.default.createElement(_components.FormFieldSet, {
|
|
138
|
-
level: level,
|
|
139
|
-
title: type.title,
|
|
140
|
-
description: type.description,
|
|
141
|
-
onFocus: this.handleFocus,
|
|
142
|
-
onBlur: this.handleBlur,
|
|
143
|
-
__unstable_presence: presence,
|
|
144
|
-
__unstable_changeIndicator: false,
|
|
145
|
-
__unstable_markers: markers
|
|
146
|
-
}, /*#__PURE__*/_react.default.createElement("div", null, value && /*#__PURE__*/_react.default.createElement(_changeIndicators.ChangeIndicatorCompareValueProvider, {
|
|
147
|
-
value: value,
|
|
148
|
-
compareValue: compareValue
|
|
149
|
-
}, /*#__PURE__*/_react.default.createElement(_changeIndicators.ChangeIndicator, {
|
|
150
|
-
compareDeep: true
|
|
151
|
-
}, /*#__PURE__*/_react.default.createElement(_GeopointInput.PreviewImage, {
|
|
152
|
-
src: getStaticImageUrl(value),
|
|
153
|
-
alt: "Map location"
|
|
154
|
-
}))), !readOnly && /*#__PURE__*/_react.default.createElement(_ui.Box, {
|
|
155
|
-
marginTop: 4
|
|
156
|
-
}, /*#__PURE__*/_react.default.createElement(_ui.Grid, {
|
|
157
|
-
columns: 2,
|
|
158
|
-
gap: 2
|
|
159
|
-
}, /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
160
|
-
mode: "ghost",
|
|
161
|
-
icon: value && _icons.EditIcon,
|
|
162
|
-
padding: 3,
|
|
163
|
-
ref: this.setEditButton,
|
|
164
|
-
text: value ? 'Edit' : 'Set location',
|
|
165
|
-
onClick: this.handleToggleModal
|
|
166
|
-
}), value && /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
167
|
-
tone: "critical",
|
|
168
|
-
icon: _icons.TrashIcon,
|
|
169
|
-
padding: 3,
|
|
170
|
-
mode: "ghost",
|
|
171
|
-
text: 'Remove',
|
|
172
|
-
onClick: this.handleClear
|
|
173
|
-
}))), modalOpen && /*#__PURE__*/_react.default.createElement(_ui.Dialog, {
|
|
174
|
-
id: "".concat(this._geopointInputId, "_dialog"),
|
|
175
|
-
onClose: this.handleCloseModal,
|
|
176
|
-
header: "Place the marker on the map",
|
|
177
|
-
width: 1
|
|
178
|
-
}, /*#__PURE__*/_react.default.createElement(_GeopointInput.DialogInnerContainer, null, /*#__PURE__*/_react.default.createElement(_GoogleMapsLoadProxy.GoogleMapsLoadProxy, null, api => /*#__PURE__*/_react.default.createElement(_GeopointSelect.GeopointSelect, {
|
|
179
|
-
api: api,
|
|
180
|
-
value: value,
|
|
181
|
-
onChange: readOnly ? undefined : this.handleChange,
|
|
182
|
-
defaultLocation: _googleMapsInput.default.defaultLocation,
|
|
183
|
-
defaultZoom: _googleMapsInput.default.defaultZoom
|
|
184
|
-
}))))));
|
|
185
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { uniqueId } from 'lodash';
|
|
4
|
+
import { TextInput, Box, Grid, Button, Dialog } from '@sanity/ui';
|
|
5
|
+
import { EditIcon, TrashIcon } from '@sanity/icons';
|
|
6
|
+
import config from 'config:@sanity/google-maps-input';
|
|
7
|
+
import { FormFieldSet, ChangeIndicatorCompareValueProvider, ChangeIndicator } from '@sanity/base/components';
|
|
8
|
+
import { PatchEvent, setIfMissing, set, unset } from '@sanity/base/form';
|
|
9
|
+
import { G as GoogleMap, M as Marker, a as GoogleMapsLoadProxy } from '../_Marker-96f5387c.js';
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
import 'rxjs';
|
|
12
|
+
|
|
13
|
+
const WrapperContainer = styled.div `
|
|
14
|
+
position: absolute;
|
|
15
|
+
right: 10px;
|
|
16
|
+
top: 10px;
|
|
17
|
+
width: 220px;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
class SearchInput extends React.PureComponent {
|
|
21
|
+
searchInputRef = React.createRef();
|
|
22
|
+
autoComplete;
|
|
23
|
+
handleChange = () => {
|
|
24
|
+
if (!this.autoComplete) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.props.onChange(this.autoComplete.getPlace());
|
|
28
|
+
if (this.searchInputRef.current) {
|
|
29
|
+
this.searchInputRef.current.value = '';
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
componentDidMount() {
|
|
33
|
+
const input = this.searchInputRef.current;
|
|
34
|
+
if (!input) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const { api, map } = this.props;
|
|
38
|
+
const { Circle, places, event } = api;
|
|
39
|
+
const searchBounds = new Circle({ center: map.getCenter(), radius: 100 }).getBounds();
|
|
40
|
+
this.autoComplete = new places.Autocomplete(input, {
|
|
41
|
+
bounds: searchBounds,
|
|
42
|
+
types: [], // return all kinds of places
|
|
43
|
+
});
|
|
44
|
+
event.addListener(this.autoComplete, 'place_changed', this.handleChange);
|
|
45
|
+
}
|
|
46
|
+
render() {
|
|
47
|
+
return (React.createElement(WrapperContainer, null,
|
|
48
|
+
React.createElement(TextInput, { name: "place", ref: this.searchInputRef, placeholder: "Search for place or address", padding: 4 })));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
186
51
|
|
|
52
|
+
const fallbackLatLng = { lat: 40.7058254, lng: -74.1180863 };
|
|
53
|
+
class GeopointSelect extends React__default.PureComponent {
|
|
54
|
+
static defaultProps = {
|
|
55
|
+
defaultZoom: 8,
|
|
56
|
+
defaultLocation: { lng: 10.74609, lat: 59.91273 },
|
|
57
|
+
};
|
|
58
|
+
mapRef = React__default.createRef();
|
|
59
|
+
getCenter() {
|
|
60
|
+
const { value = {}, defaultLocation = {} } = this.props;
|
|
61
|
+
const point = { ...fallbackLatLng, ...defaultLocation, ...value };
|
|
62
|
+
return point;
|
|
63
|
+
}
|
|
64
|
+
handlePlaceChanged = (place) => {
|
|
65
|
+
if (!place.geometry) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.setValue(place.geometry.location);
|
|
69
|
+
};
|
|
70
|
+
handleMarkerDragEnd = (event) => {
|
|
71
|
+
this.setValue(event.latLng);
|
|
72
|
+
};
|
|
73
|
+
handleMapClick = (event) => {
|
|
74
|
+
this.setValue(event.latLng);
|
|
75
|
+
};
|
|
76
|
+
setValue(geoPoint) {
|
|
77
|
+
if (this.props.onChange) {
|
|
78
|
+
this.props.onChange(geoPoint);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
render() {
|
|
82
|
+
const { api, defaultZoom, value, onChange } = this.props;
|
|
83
|
+
return (React__default.createElement(GoogleMap, { api: api, location: this.getCenter(), onClick: this.handleMapClick, defaultZoom: defaultZoom }, (map) => (React__default.createElement(React__default.Fragment, null,
|
|
84
|
+
React__default.createElement(SearchInput, { api: api, map: map, onChange: this.handlePlaceChanged }),
|
|
85
|
+
value && (React__default.createElement(Marker, { api: api, map: map, position: value, onMove: onChange ? this.handleMarkerDragEnd : undefined }))))));
|
|
86
|
+
}
|
|
187
87
|
}
|
|
188
88
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
89
|
+
const PreviewImage = styled.img `
|
|
90
|
+
width: 100%;
|
|
91
|
+
height: auto;
|
|
92
|
+
vertical-align: top;
|
|
93
|
+
`;
|
|
94
|
+
const DialogInnerContainer = styled.div `
|
|
95
|
+
height: 40rem;
|
|
96
|
+
width: 50rem;
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
// @todo: remove the following line when part imports has been removed from this file
|
|
100
|
+
const getStaticImageUrl = (value) => {
|
|
101
|
+
const loc = `${value.lat},${value.lng}`;
|
|
102
|
+
const params = {
|
|
103
|
+
key: config.apiKey,
|
|
104
|
+
center: loc,
|
|
105
|
+
markers: loc,
|
|
106
|
+
zoom: 13,
|
|
107
|
+
scale: 2,
|
|
108
|
+
size: '640x300',
|
|
109
|
+
};
|
|
110
|
+
const qs = Object.keys(params).reduce((res, param) => {
|
|
111
|
+
return res.concat(`${param}=${encodeURIComponent(params[param])}`);
|
|
112
|
+
}, []);
|
|
113
|
+
return `https://maps.googleapis.com/maps/api/staticmap?${qs.join('&')}`;
|
|
114
|
+
};
|
|
115
|
+
class GeopointInput extends React__default.PureComponent {
|
|
116
|
+
_geopointInputId = uniqueId('GeopointInput');
|
|
117
|
+
static defaultProps = {
|
|
118
|
+
validation: [],
|
|
119
|
+
};
|
|
120
|
+
editButton;
|
|
121
|
+
constructor(props) {
|
|
122
|
+
super(props);
|
|
123
|
+
this.state = {
|
|
124
|
+
modalOpen: false,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
setEditButton = (el) => {
|
|
128
|
+
this.editButton = el;
|
|
129
|
+
};
|
|
130
|
+
focus() {
|
|
131
|
+
if (this.editButton) {
|
|
132
|
+
this.editButton.focus();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
handleFocus = (event) => {
|
|
136
|
+
this.props.onFocus(event);
|
|
137
|
+
};
|
|
138
|
+
handleBlur = () => {
|
|
139
|
+
this.props.onBlur?.();
|
|
140
|
+
};
|
|
141
|
+
handleToggleModal = () => {
|
|
142
|
+
const { onFocus, onBlur } = this.props;
|
|
143
|
+
this.setState((prevState) => ({ modalOpen: !prevState.modalOpen }), () => {
|
|
144
|
+
if (this.state.modalOpen) {
|
|
145
|
+
onFocus(['$']);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
onBlur?.();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
handleCloseModal = () => {
|
|
153
|
+
this.setState({ modalOpen: false });
|
|
154
|
+
};
|
|
155
|
+
handleChange = (latLng) => {
|
|
156
|
+
const { type, onChange } = this.props;
|
|
157
|
+
onChange(PatchEvent.from([
|
|
158
|
+
setIfMissing({
|
|
159
|
+
_type: type.name,
|
|
160
|
+
}),
|
|
161
|
+
set(latLng.lat(), ['lat']),
|
|
162
|
+
set(latLng.lng(), ['lng']),
|
|
163
|
+
]));
|
|
164
|
+
};
|
|
165
|
+
handleClear = () => {
|
|
166
|
+
const { onChange } = this.props;
|
|
167
|
+
onChange(PatchEvent.from(unset()));
|
|
168
|
+
};
|
|
169
|
+
render() {
|
|
170
|
+
const { value, compareValue, readOnly, type, validation, level, presence } = this.props;
|
|
171
|
+
const { modalOpen } = this.state;
|
|
172
|
+
if (!config || !config.apiKey) {
|
|
173
|
+
return (React__default.createElement("div", null,
|
|
174
|
+
React__default.createElement("p", null,
|
|
175
|
+
"The ",
|
|
176
|
+
React__default.createElement("a", { href: "https://sanity.io/docs/schema-types/geopoint-type" }, "Geopoint type"),
|
|
177
|
+
" needs a Google Maps API key with access to:"),
|
|
178
|
+
React__default.createElement("ul", null,
|
|
179
|
+
React__default.createElement("li", null, "Google Maps JavaScript API"),
|
|
180
|
+
React__default.createElement("li", null, "Google Places API Web Service"),
|
|
181
|
+
React__default.createElement("li", null, "Google Static Maps API")),
|
|
182
|
+
React__default.createElement("p", null,
|
|
183
|
+
"Please enter the API key with access to these services in",
|
|
184
|
+
React__default.createElement("code", { style: { whiteSpace: 'nowrap' } }, "`<project-root>/config/@sanity/google-maps-input.json`"))));
|
|
185
|
+
}
|
|
186
|
+
return (React__default.createElement(FormFieldSet, { level: level, title: type.title, description: type.description, onFocus: this.handleFocus, onBlur: this.handleBlur, __unstable_presence: presence, __unstable_changeIndicator: false, validation: validation },
|
|
187
|
+
React__default.createElement("div", null,
|
|
188
|
+
value && (React__default.createElement(ChangeIndicatorCompareValueProvider, { value: value, compareValue: compareValue },
|
|
189
|
+
React__default.createElement(ChangeIndicator, { compareDeep: true },
|
|
190
|
+
React__default.createElement(PreviewImage, { src: getStaticImageUrl(value), alt: "Map location" })))),
|
|
191
|
+
!readOnly && (React__default.createElement(Box, { marginTop: 4 },
|
|
192
|
+
React__default.createElement(Grid, { columns: 2, gap: 2 },
|
|
193
|
+
React__default.createElement(Button, { mode: "ghost", icon: value && EditIcon, padding: 3, ref: this.setEditButton, text: value ? 'Edit' : 'Set location', onClick: this.handleToggleModal }),
|
|
194
|
+
value && (React__default.createElement(Button, { tone: "critical", icon: TrashIcon, padding: 3, mode: "ghost", text: 'Remove', onClick: this.handleClear }))))),
|
|
195
|
+
modalOpen && (React__default.createElement(Dialog, { id: `${this._geopointInputId}_dialog`, onClose: this.handleCloseModal, header: "Place the marker on the map", width: 1 },
|
|
196
|
+
React__default.createElement(DialogInnerContainer, null,
|
|
197
|
+
React__default.createElement(GoogleMapsLoadProxy, null, (api) => (React__default.createElement(GeopointSelect, { api: api, value: value || undefined, onChange: readOnly ? undefined : this.handleChange, defaultLocation: config.defaultLocation, defaultZoom: config.defaultZoom })))))))));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
192
200
|
|
|
193
|
-
|
|
194
|
-
|
|
201
|
+
export { GeopointInput as default };
|
|
202
|
+
//# sourceMappingURL=GeopointInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeopointInput.js","sources":["../../src/map/SearchInput.styles.tsx","../../src/map/SearchInput.tsx","../../src/input/GeopointSelect.tsx","../../src/input/GeopointInput.styles.tsx","../../src/input/GeopointInput.tsx"],"sourcesContent":["import styled from 'styled-components'\n\nexport const WrapperContainer = styled.div`\n position: absolute;\n right: 10px;\n top: 10px;\n width: 220px;\n`\n","import * as React from 'react'\nimport {TextInput} from '@sanity/ui'\nimport {WrapperContainer} from './SearchInput.styles'\n\ninterface Props {\n api: typeof window.google.maps\n map: google.maps.Map\n onChange: (result: google.maps.places.PlaceResult) => void\n}\n\nexport class SearchInput extends React.PureComponent<Props> {\n searchInputRef = React.createRef<HTMLInputElement>()\n autoComplete: google.maps.places.Autocomplete | undefined\n\n handleChange = () => {\n if (!this.autoComplete) {\n return\n }\n\n this.props.onChange(this.autoComplete.getPlace())\n\n if (this.searchInputRef.current) {\n this.searchInputRef.current.value = ''\n }\n }\n\n componentDidMount() {\n const input = this.searchInputRef.current\n if (!input) {\n return\n }\n\n const {api, map} = this.props\n const {Circle, places, event} = api\n const searchBounds = new Circle({center: map.getCenter(), radius: 100}).getBounds()\n this.autoComplete = new places.Autocomplete(input, {\n bounds: searchBounds,\n types: [], // return all kinds of places\n })\n\n event.addListener(this.autoComplete, 'place_changed', this.handleChange)\n }\n\n render() {\n return (\n <WrapperContainer>\n <TextInput\n name=\"place\"\n ref={this.searchInputRef}\n placeholder=\"Search for place or address\"\n padding={4}\n />\n </WrapperContainer>\n )\n }\n}\n","import React from 'react'\nimport {SearchInput} from '../map/SearchInput'\nimport {GoogleMap} from '../map/Map'\nimport {Marker} from '../map/Marker'\nimport {LatLng, Geopoint} from '../types'\n\nconst fallbackLatLng: LatLng = {lat: 40.7058254, lng: -74.1180863}\n\ninterface SelectProps {\n api: typeof window.google.maps\n value?: Geopoint\n onChange?: (latLng: google.maps.LatLng) => void\n defaultLocation?: LatLng\n defaultZoom?: number\n}\n\nexport class GeopointSelect extends React.PureComponent<SelectProps> {\n static defaultProps = {\n defaultZoom: 8,\n defaultLocation: {lng: 10.74609, lat: 59.91273},\n }\n\n mapRef = React.createRef<HTMLDivElement>()\n\n getCenter() {\n const {value = {}, defaultLocation = {}} = this.props\n const point: LatLng = {...fallbackLatLng, ...defaultLocation, ...value}\n return point\n }\n\n handlePlaceChanged = (place: google.maps.places.PlaceResult) => {\n if (!place.geometry) {\n return\n }\n\n this.setValue(place.geometry.location)\n }\n\n handleMarkerDragEnd = (event: google.maps.MapMouseEvent) => {\n this.setValue(event.latLng)\n }\n\n handleMapClick = (event: google.maps.MapMouseEvent) => {\n this.setValue(event.latLng)\n }\n\n setValue(geoPoint: google.maps.LatLng) {\n if (this.props.onChange) {\n this.props.onChange(geoPoint)\n }\n }\n\n render() {\n const {api, defaultZoom, value, onChange} = this.props\n return (\n <GoogleMap\n api={api}\n location={this.getCenter()}\n onClick={this.handleMapClick}\n defaultZoom={defaultZoom}\n >\n {(map) => (\n <>\n <SearchInput api={api} map={map} onChange={this.handlePlaceChanged} />\n {value && (\n <Marker\n api={api}\n map={map}\n position={value}\n onMove={onChange ? this.handleMarkerDragEnd : undefined}\n />\n )}\n </>\n )}\n </GoogleMap>\n )\n }\n}\n","import styled from 'styled-components'\n\nexport const PreviewImage = styled.img`\n width: 100%;\n height: auto;\n vertical-align: top;\n`\n\nexport const DialogInnerContainer = styled.div`\n height: 40rem;\n width: 50rem;\n`\n","// @todo: remove the following line when part imports has been removed from this file\n///<reference types=\"@sanity/types/parts\" />\n\nimport React from 'react'\nimport {uniqueId} from 'lodash'\nimport {Box, Grid, Button, Dialog} from '@sanity/ui'\nimport {TrashIcon, EditIcon} from '@sanity/icons'\nimport config from 'config:@sanity/google-maps-input'\nimport {\n FormFieldSet,\n ChangeIndicatorCompareValueProvider,\n ChangeIndicator,\n} from '@sanity/base/components'\nimport {FormInputProps, PatchEvent, set, setIfMissing, unset} from '@sanity/base/form'\nimport {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'\nimport {Geopoint, GeopointSchemaType} from '../types'\nimport {GeopointSelect} from './GeopointSelect'\nimport {PreviewImage, DialogInnerContainer} from './GeopointInput.styles'\n\nconst getStaticImageUrl = (value) => {\n const loc = `${value.lat},${value.lng}`\n const params = {\n key: config.apiKey,\n center: loc,\n markers: loc,\n zoom: 13,\n scale: 2,\n size: '640x300',\n }\n\n const qs = Object.keys(params).reduce((res, param) => {\n return res.concat(`${param}=${encodeURIComponent(params[param])}`)\n }, [] as string[])\n\n return `https://maps.googleapis.com/maps/api/staticmap?${qs.join('&')}`\n}\n\ntype GeopointInputProps = FormInputProps<Geopoint, GeopointSchemaType>\n\n// @todo\n// interface Focusable {\n// focus: () => void\n// }\ntype Focusable = any\n\ninterface InputState {\n modalOpen: boolean\n}\n\nclass GeopointInput extends React.PureComponent<GeopointInputProps, InputState> {\n _geopointInputId = uniqueId('GeopointInput')\n\n static defaultProps = {\n validation: [],\n }\n\n editButton: Focusable | undefined\n\n constructor(props) {\n super(props)\n\n this.state = {\n modalOpen: false,\n }\n }\n\n setEditButton = (el: Focusable) => {\n this.editButton = el\n }\n\n focus() {\n if (this.editButton) {\n this.editButton.focus()\n }\n }\n\n handleFocus = (event) => {\n this.props.onFocus(event)\n }\n\n handleBlur = () => {\n this.props.onBlur?.()\n }\n\n handleToggleModal = () => {\n const {onFocus, onBlur} = this.props\n this.setState(\n (prevState) => ({modalOpen: !prevState.modalOpen}),\n () => {\n if (this.state.modalOpen) {\n onFocus(['$'])\n } else {\n onBlur?.()\n }\n }\n )\n }\n\n handleCloseModal = () => {\n this.setState({modalOpen: false})\n }\n\n handleChange = (latLng: google.maps.LatLng) => {\n const {type, onChange} = this.props\n onChange(\n PatchEvent.from([\n setIfMissing({\n _type: type.name,\n }),\n set(latLng.lat(), ['lat']),\n set(latLng.lng(), ['lng']),\n ])\n )\n }\n\n handleClear = () => {\n const {onChange} = this.props\n onChange(PatchEvent.from(unset()))\n }\n\n render() {\n const {value, compareValue, readOnly, type, validation, level, presence} = this.props\n const {modalOpen} = this.state\n\n if (!config || !config.apiKey) {\n return (\n <div>\n <p>\n The <a href=\"https://sanity.io/docs/schema-types/geopoint-type\">Geopoint type</a> needs\n a Google Maps API key with access to:\n </p>\n <ul>\n <li>Google Maps JavaScript API</li>\n <li>Google Places API Web Service</li>\n <li>Google Static Maps API</li>\n </ul>\n <p>\n Please enter the API key with access to these services in\n <code style={{whiteSpace: 'nowrap'}}>\n `<project-root>/config/@sanity/google-maps-input.json`\n </code>\n </p>\n </div>\n )\n }\n\n return (\n <FormFieldSet\n level={level}\n title={type.title}\n description={type.description}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n __unstable_presence={presence}\n __unstable_changeIndicator={false}\n validation={validation}\n >\n <div>\n {value && (\n <ChangeIndicatorCompareValueProvider value={value} compareValue={compareValue}>\n <ChangeIndicator compareDeep>\n <PreviewImage src={getStaticImageUrl(value)} alt=\"Map location\" />\n </ChangeIndicator>\n </ChangeIndicatorCompareValueProvider>\n )}\n\n {!readOnly && (\n <Box marginTop={4}>\n <Grid columns={2} gap={2}>\n <Button\n mode=\"ghost\"\n icon={value && EditIcon}\n padding={3}\n ref={this.setEditButton}\n text={value ? 'Edit' : 'Set location'}\n onClick={this.handleToggleModal}\n />\n\n {value && (\n <Button\n tone=\"critical\"\n icon={TrashIcon}\n padding={3}\n mode=\"ghost\"\n text={'Remove'}\n onClick={this.handleClear}\n />\n )}\n </Grid>\n </Box>\n )}\n\n {modalOpen && (\n <Dialog\n id={`${this._geopointInputId}_dialog`}\n onClose={this.handleCloseModal}\n header=\"Place the marker on the map\"\n width={1}\n >\n <DialogInnerContainer>\n <GoogleMapsLoadProxy>\n {(api) => (\n <GeopointSelect\n api={api}\n value={value || undefined}\n onChange={readOnly ? undefined : this.handleChange}\n defaultLocation={config.defaultLocation}\n defaultZoom={config.defaultZoom}\n />\n )}\n </GoogleMapsLoadProxy>\n </DialogInnerContainer>\n </Dialog>\n )}\n </div>\n </FormFieldSet>\n )\n }\n}\n\nexport default GeopointInput\n"],"names":["React"],"mappings":";;;;;;;;;;;;AAEO,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA,CAAA;;;;;CAKzC;;ACGY,MAAA,WAAY,SAAQ,KAAK,CAAC,aAAoB,CAAA;AACzD,IAAA,cAAc,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAA;AACpD,IAAA,YAAY,CAA6C;IAEzD,YAAY,GAAG,MAAK;AAClB,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,OAAM;AACP,SAAA;AAED,QAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAA;AAEjD,QAAA,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAA;AACvC,SAAA;AACH,KAAC,CAAA;IAED,iBAAiB,GAAA;AACf,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAA;QACzC,IAAI,CAAC,KAAK,EAAE;YACV,OAAM;AACP,SAAA;QAED,MAAM,EAAC,GAAG,EAAE,GAAG,EAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QAC7B,MAAM,EAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAC,GAAG,GAAG,CAAA;QACnC,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,EAAC,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC,SAAS,EAAE,CAAA;QACnF,IAAI,CAAC,YAAY,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK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,EACrC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAC/B,CAAA;AAED,wBAAA,KAAK,KACJA,cAAC,CAAA,aAAA,CAAA,MAAM,IACL,IAAI,EAAC,UAAU,EACf,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,CAAC,EACV,IAAI,EAAC,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,IAAI,CAAC,WAAW,EAAA,CACzB,CACH,CACI,CACH,CACP;gBAEA,SAAS,KACRA,cAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EACL,EAAE,EAAE,CAAA,EAAG,IAAI,CAAC,gBAAgB,CAAA,OAAA,CAAS,EACrC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAC9B,MAAM,EAAC,6BAA6B,EACpC,KAAK,EAAE,CAAC,EAAA;AAER,oBAAAA,cAAA,CAAA,aAAA,CAAC,oBAAoB,EAAA,IAAA;wBACnBA,cAAC,CAAA,aAAA,CAAA,mBAAmB,EACjB,IAAA,EAAA,CAAC,GAAG,MACHA,cAAC,CAAA,aAAA,CAAA,cAAc,EACb,EAAA,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,IAAI,SAAS,EACzB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,YAAY,EAClD,eAAe,EAAE,MAAM,CAAC,eAAe,EACvC,WAAW,EAAE,MAAM,CAAC,WAAW,EAAA,CAC/B,CACH,CACmB,CACD,CAChB,CACV,CACG,CACO,EAChB;KACF;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/google-maps-input",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.1-purple-unicorn.560+8672b3b5e3",
|
|
4
4
|
"description": "Sanity plugin providing input handlers for geo-related input types using Google Maps",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"
|
|
5
|
+
"main": "lib/input/GeopointInput.cjs",
|
|
6
|
+
"module": "lib/input/GeopointInput.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./input/GeopointInput": {
|
|
9
|
+
"source": "./src/input/GeopointInput.tsx",
|
|
10
|
+
"require": "./lib/input/GeopointInput.cjs",
|
|
11
|
+
"default": "./lib/input/GeopointInput.js"
|
|
12
|
+
},
|
|
13
|
+
"./diff/resolver": {
|
|
14
|
+
"source": "./src/diff/resolver.ts",
|
|
15
|
+
"require": "./lib/diff/resolver.cjs",
|
|
16
|
+
"default": "./lib/diff/resolver.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"types": "./lib/dts/src/input/GeopointInput.d.ts",
|
|
7
20
|
"author": "Sanity.io <hello@sanity.io>",
|
|
8
21
|
"license": "MIT",
|
|
9
22
|
"scripts": {
|
|
10
|
-
"
|
|
23
|
+
"build": "../../../bin/pkg-utils bundle",
|
|
24
|
+
"clean": "rimraf lib",
|
|
25
|
+
"_exports:check": "../../../bin/pkg-utils exports-check",
|
|
26
|
+
"exports:clean": "../../../bin/pkg-utils exports-clean",
|
|
27
|
+
"exports:generate": "../../../bin/pkg-utils exports-generate",
|
|
28
|
+
"postbuild": "run-s exports:generate",
|
|
29
|
+
"prebuild": "yarn clean",
|
|
30
|
+
"watch": "../../../bin/pkg-utils bundle --watch"
|
|
11
31
|
},
|
|
12
32
|
"keywords": [
|
|
13
33
|
"sanity",
|
|
@@ -19,20 +39,23 @@
|
|
|
19
39
|
"sanity-plugin"
|
|
20
40
|
],
|
|
21
41
|
"dependencies": {
|
|
22
|
-
"@sanity/field": "2.25.4",
|
|
23
42
|
"@sanity/icons": "^1.2.1",
|
|
24
|
-
"@sanity/types": "2.
|
|
25
|
-
"@sanity/ui": "^0.37.
|
|
26
|
-
"lodash": "^4.17.
|
|
43
|
+
"@sanity/types": "2.26.1-purple-unicorn.560+8672b3b5e3",
|
|
44
|
+
"@sanity/ui": "^0.37.5",
|
|
45
|
+
"lodash": "^4.17.21",
|
|
27
46
|
"rxjs": "^6.5.3"
|
|
28
47
|
},
|
|
29
48
|
"devDependencies": {
|
|
30
|
-
"@sanity/base": "2.
|
|
49
|
+
"@sanity/base": "2.26.1-purple-unicorn.560+8672b3b5e3",
|
|
50
|
+
"@sanity/form-builder": "2.26.1-purple-unicorn.560+8672b3b5e3",
|
|
31
51
|
"@types/googlemaps": "^3.43.0",
|
|
32
|
-
"
|
|
52
|
+
"react": "17.0.2",
|
|
53
|
+
"rimraf": "^3.0.2",
|
|
54
|
+
"styled-components": "^5.2.0"
|
|
33
55
|
},
|
|
34
56
|
"peerDependencies": {
|
|
35
57
|
"@sanity/base": "^2.0.0",
|
|
58
|
+
"@sanity/form-builder": "^2.27",
|
|
36
59
|
"react": "^16.9 || ^17",
|
|
37
60
|
"react-dom": "^16.9 || ^17",
|
|
38
61
|
"styled-components": "^5.2.0"
|
|
@@ -46,5 +69,5 @@
|
|
|
46
69
|
"url": "https://github.com/sanity-io/sanity/issues"
|
|
47
70
|
},
|
|
48
71
|
"homepage": "https://www.sanity.io/",
|
|
49
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "8672b3b5e39b2aeea500d16ac197b068ba7c943c"
|
|
50
73
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
ArrayDiff,
|
|
4
|
+
ObjectDiff,
|
|
5
|
+
Diff,
|
|
6
|
+
DiffProps as GenericDiffProps,
|
|
7
|
+
DiffComponent,
|
|
8
|
+
} from '@sanity/base/field'
|
|
9
|
+
import {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'
|
|
10
|
+
import {GoogleMap} from '../map/Map'
|
|
11
|
+
import {Geopoint} from '../types'
|
|
12
|
+
import {GeopointMove} from './GeopointMove'
|
|
13
|
+
import {RootContainer} from './GeopointFieldDiff.styles'
|
|
14
|
+
|
|
15
|
+
export type DiffProps = GenericDiffProps<ArrayDiff<Geopoint>>
|
|
16
|
+
|
|
17
|
+
export const GeopointArrayDiff: DiffComponent<ArrayDiff<Geopoint>> = ({diff, schemaType}) => {
|
|
18
|
+
return (
|
|
19
|
+
<RootContainer>
|
|
20
|
+
<GoogleMapsLoadProxy>
|
|
21
|
+
{(api) => <GeopointDiff api={api} diff={diff} schemaType={schemaType} />}
|
|
22
|
+
</GoogleMapsLoadProxy>
|
|
23
|
+
</RootContainer>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function GeopointDiff({api, diff}: DiffProps & {api: typeof window.google.maps}) {
|
|
28
|
+
const fromValue = (diff.fromValue || []).filter(hasCoordinates)
|
|
29
|
+
const toValue = (diff.toValue || []).filter(hasCoordinates)
|
|
30
|
+
if (fromValue.length === 0 && toValue.length === 0) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const bounds = getBounds(fromValue, toValue, api)
|
|
35
|
+
return (
|
|
36
|
+
<GoogleMap
|
|
37
|
+
api={api}
|
|
38
|
+
location={bounds.getCenter().toJSON()}
|
|
39
|
+
mapTypeControl={false}
|
|
40
|
+
controlSize={20}
|
|
41
|
+
bounds={bounds}
|
|
42
|
+
>
|
|
43
|
+
{(map) => (
|
|
44
|
+
<>
|
|
45
|
+
{diff.items.map(({toIndex, diff: pointDiff}) => {
|
|
46
|
+
if (!isChangeDiff(pointDiff)) {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<GeopointMove
|
|
52
|
+
key={toIndex}
|
|
53
|
+
api={api}
|
|
54
|
+
map={map}
|
|
55
|
+
diff={pointDiff}
|
|
56
|
+
label={`${toIndex}`}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
})}
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
62
|
+
</GoogleMap>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isChangeDiff(diff: Diff): diff is ObjectDiff<Geopoint> {
|
|
67
|
+
return diff.action !== 'unchanged' && diff.type === 'object'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function hasCoordinates(point: Partial<Geopoint>): point is Geopoint {
|
|
71
|
+
return typeof point.lat === 'number' && typeof point.lng === 'number'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getBounds(
|
|
75
|
+
fromValue: google.maps.LatLngLiteral[] | null | undefined,
|
|
76
|
+
toValue: google.maps.LatLngLiteral[] | null | undefined,
|
|
77
|
+
api: typeof window.google.maps
|
|
78
|
+
): google.maps.LatLngBounds {
|
|
79
|
+
const bounds = new api.LatLngBounds()
|
|
80
|
+
const points = [...(fromValue || []), ...(toValue || [])]
|
|
81
|
+
points.forEach((point) => bounds.extend(point))
|
|
82
|
+
return bounds
|
|
83
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
export const RootContainer = styled.div`
|
|
4
|
+
position: relative;
|
|
5
|
+
min-height: 200px;
|
|
6
|
+
|
|
7
|
+
&:empty {
|
|
8
|
+
background-color: var(--card-skeleton-color-from);
|
|
9
|
+
display: table;
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&:empty:after {
|
|
14
|
+
content: 'Missing/invalid data';
|
|
15
|
+
display: table-cell;
|
|
16
|
+
vertical-align: middle;
|
|
17
|
+
text-align: center;
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
`
|