@sanity/google-maps-input 0.147.10-ts-client.1 → 1.0.0-v2-studio.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/config.dist.json +1 -0
- package/dts/diff/GeopointArrayDiff.d.ts +4 -0
- package/dts/diff/GeopointFieldDiff.d.ts +4 -0
- package/dts/diff/GeopointFieldDiff.styles.d.ts +1 -0
- package/dts/diff/GeopointMove.d.ts +12 -0
- package/dts/diff/resolver.d.ts +3 -0
- package/dts/input/GeopointInput.d.ts +64 -0
- package/dts/input/GeopointInput.styles.d.ts +2 -0
- package/dts/input/GeopointSelect.d.ts +52 -0
- package/dts/loader/GoogleMapsLoadProxy.d.ts +13 -0
- package/dts/loader/LoadError.d.ts +9 -0
- package/dts/loader/loadGoogleMapsApi.d.ts +17 -0
- package/dts/map/Arrow.d.ts +30 -0
- package/dts/map/Map.d.ts +38 -0
- package/dts/map/Map.styles.d.ts +1 -0
- package/dts/map/Marker.d.ts +38 -0
- package/dts/map/SearchInput.d.ts +17 -0
- package/dts/map/SearchInput.styles.d.ts +1 -0
- package/dts/map/util.d.ts +3 -0
- package/dts/types.d.ts +13 -0
- package/lib/@types/css.d.js +2 -0
- package/lib/@types/css.d.js.map +1 -0
- package/lib/diff/GeopointArrayDiff.js +66 -0
- package/lib/diff/GeopointArrayDiff.js.map +1 -0
- package/lib/diff/GeopointFieldDiff.js +78 -0
- package/lib/diff/GeopointFieldDiff.js.map +1 -0
- package/lib/diff/GeopointFieldDiff.styles.js +13 -0
- package/lib/diff/GeopointFieldDiff.styles.js.map +1 -0
- package/lib/diff/GeopointMove.js +49 -0
- package/lib/diff/GeopointMove.js.map +1 -0
- package/lib/diff/resolver.js +21 -0
- package/lib/diff/resolver.js.map +1 -0
- package/lib/input/GeopointInput.js +163 -0
- package/lib/input/GeopointInput.js.map +1 -0
- package/lib/input/GeopointInput.styles.js +15 -0
- package/lib/input/GeopointInput.styles.js.map +1 -0
- package/lib/input/GeopointSelect.js +81 -0
- package/lib/input/GeopointSelect.js.map +1 -0
- package/lib/loader/GoogleMapsLoadProxy.js +55 -0
- package/lib/loader/GoogleMapsLoadProxy.js.map +1 -0
- package/lib/loader/LoadError.js +37 -0
- package/lib/loader/LoadError.js.map +1 -0
- package/lib/loader/loadGoogleMapsApi.js +65 -0
- package/lib/loader/loadGoogleMapsApi.js.map +1 -0
- package/lib/map/Arrow.js +79 -0
- package/lib/map/Arrow.js.map +1 -0
- package/lib/map/Map.js +114 -0
- package/lib/map/Map.js.map +1 -0
- package/lib/map/Map.styles.js +13 -0
- package/lib/map/Map.styles.js.map +1 -0
- package/lib/map/Marker.js +125 -0
- package/lib/map/Marker.js.map +1 -0
- package/lib/map/SearchInput.js +60 -0
- package/lib/map/SearchInput.js.map +1 -0
- package/lib/map/SearchInput.styles.js +13 -0
- package/lib/map/SearchInput.styles.js.map +1 -0
- package/lib/map/util.js +14 -0
- package/lib/map/util.js.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +63 -27
- package/sanity.json +5 -1
- 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 +231 -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 +132 -0
- package/src/map/SearchInput.styles.tsx +8 -0
- package/src/map/SearchInput.tsx +55 -0
- package/src/map/util.ts +14 -0
- package/src/types.ts +16 -0
- package/example/Main.js +0 -28
- package/example/config/.checksums +0 -4
- package/example/config/@sanity/google-maps-input.json +0 -8
- package/example/sanity.json +0 -33
- package/example/schema.js +0 -22
- package/lib/GeopointInput.js +0 -170
- package/lib/GeopointSelect.js +0 -174
- package/lib/GoogleMapsLoadProxy.js +0 -65
- package/lib/loadGoogleMapsApi.js +0 -36
- package/locale/strings.json +0 -11
- package/styles/GeopointInput.css +0 -28
- package/styles/GeopointSelect.css +0 -27
package/lib/map/Map.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GoogleMap = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _util = require("./util");
|
|
9
|
+
var _Map = require("./Map.styles");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
class GoogleMap extends _react.default.PureComponent {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
_defineProperty(this, "state", {
|
|
16
|
+
map: undefined
|
|
17
|
+
});
|
|
18
|
+
_defineProperty(this, "clickHandler", void 0);
|
|
19
|
+
_defineProperty(this, "mapRef", /*#__PURE__*/_react.default.createRef());
|
|
20
|
+
_defineProperty(this, "mapEl", null);
|
|
21
|
+
_defineProperty(this, "attachClickHandler", () => {
|
|
22
|
+
var map = this.state.map;
|
|
23
|
+
if (!map) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var _this$props = this.props,
|
|
27
|
+
api = _this$props.api,
|
|
28
|
+
onClick = _this$props.onClick;
|
|
29
|
+
var event = api.event;
|
|
30
|
+
if (this.clickHandler) {
|
|
31
|
+
this.clickHandler.remove();
|
|
32
|
+
}
|
|
33
|
+
if (onClick) {
|
|
34
|
+
this.clickHandler = event.addListener(map, 'click', onClick);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
_defineProperty(this, "setMapElement", element => {
|
|
38
|
+
if (element && element !== this.mapEl) {
|
|
39
|
+
var _map = this.constructMap(element);
|
|
40
|
+
this.setState({
|
|
41
|
+
map: _map
|
|
42
|
+
}, this.attachClickHandler);
|
|
43
|
+
}
|
|
44
|
+
this.mapEl = element;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
componentDidMount() {
|
|
48
|
+
this.attachClickHandler();
|
|
49
|
+
}
|
|
50
|
+
componentDidUpdate(prevProps) {
|
|
51
|
+
var map = this.state.map;
|
|
52
|
+
if (!map) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var _this$props2 = this.props,
|
|
56
|
+
onClick = _this$props2.onClick,
|
|
57
|
+
location = _this$props2.location,
|
|
58
|
+
bounds = _this$props2.bounds;
|
|
59
|
+
if (prevProps.onClick !== onClick) {
|
|
60
|
+
this.attachClickHandler();
|
|
61
|
+
}
|
|
62
|
+
if (!(0, _util.latLngAreEqual)(prevProps.location, location)) {
|
|
63
|
+
map.panTo(this.getCenter());
|
|
64
|
+
}
|
|
65
|
+
if (bounds && (!prevProps.bounds || !bounds.equals(prevProps.bounds))) {
|
|
66
|
+
map.fitBounds(bounds);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
componentWillUnmount() {
|
|
70
|
+
if (this.clickHandler) {
|
|
71
|
+
this.clickHandler.remove();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getCenter() {
|
|
75
|
+
var _this$props3 = this.props,
|
|
76
|
+
location = _this$props3.location,
|
|
77
|
+
api = _this$props3.api;
|
|
78
|
+
return new api.LatLng(location.lat, location.lng);
|
|
79
|
+
}
|
|
80
|
+
constructMap(el) {
|
|
81
|
+
var _this$props4 = this.props,
|
|
82
|
+
defaultZoom = _this$props4.defaultZoom,
|
|
83
|
+
api = _this$props4.api,
|
|
84
|
+
mapTypeControl = _this$props4.mapTypeControl,
|
|
85
|
+
controlSize = _this$props4.controlSize,
|
|
86
|
+
bounds = _this$props4.bounds,
|
|
87
|
+
scrollWheel = _this$props4.scrollWheel;
|
|
88
|
+
var map = new api.Map(el, {
|
|
89
|
+
zoom: defaultZoom,
|
|
90
|
+
center: this.getCenter(),
|
|
91
|
+
scrollwheel: scrollWheel,
|
|
92
|
+
streetViewControl: false,
|
|
93
|
+
mapTypeControl,
|
|
94
|
+
controlSize
|
|
95
|
+
});
|
|
96
|
+
if (bounds) {
|
|
97
|
+
map.fitBounds(bounds);
|
|
98
|
+
}
|
|
99
|
+
return map;
|
|
100
|
+
}
|
|
101
|
+
render() {
|
|
102
|
+
var children = this.props.children;
|
|
103
|
+
var map = this.state.map;
|
|
104
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Map.MapContainer, {
|
|
105
|
+
ref: this.setMapElement
|
|
106
|
+
}), children && map ? children(map) : null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.GoogleMap = GoogleMap;
|
|
110
|
+
_defineProperty(GoogleMap, "defaultProps", {
|
|
111
|
+
defaultZoom: 8,
|
|
112
|
+
scrollWheel: true
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=Map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Map.js","names":["GoogleMap","React","PureComponent","map","undefined","createRef","state","props","api","onClick","event","clickHandler","remove","addListener","element","mapEl","constructMap","setState","attachClickHandler","componentDidMount","componentDidUpdate","prevProps","location","bounds","latLngAreEqual","panTo","getCenter","equals","fitBounds","componentWillUnmount","LatLng","lat","lng","el","defaultZoom","mapTypeControl","controlSize","scrollWheel","Map","zoom","center","scrollwheel","streetViewControl","render","children","setMapElement"],"sources":["../../src/map/Map.tsx"],"sourcesContent":["import React from 'react'\nimport {LatLng} from '../types'\nimport {latLngAreEqual} from './util'\nimport {MapContainer} from './Map.styles'\n\ninterface MapProps {\n api: typeof window.google.maps\n location: LatLng\n bounds?: google.maps.LatLngBounds\n defaultZoom?: number\n mapTypeControl?: boolean\n scrollWheel?: boolean\n controlSize?: number\n onClick?: (event: google.maps.MapMouseEvent) => void\n children?: (map: google.maps.Map) => React.ReactElement\n}\n\ninterface MapState {\n map: google.maps.Map | undefined\n}\n\nexport class GoogleMap extends React.PureComponent<MapProps, MapState> {\n static defaultProps = {\n defaultZoom: 8,\n scrollWheel: true,\n }\n\n state: MapState = {map: undefined}\n clickHandler: google.maps.MapsEventListener | undefined\n mapRef = React.createRef<HTMLDivElement>()\n mapEl: HTMLDivElement | null = null\n\n componentDidMount() {\n this.attachClickHandler()\n }\n\n attachClickHandler = () => {\n const map = this.state.map\n if (!map) {\n return\n }\n\n const {api, onClick} = this.props\n const {event} = api\n\n if (this.clickHandler) {\n this.clickHandler.remove()\n }\n\n if (onClick) {\n this.clickHandler = event.addListener(map, 'click', onClick)\n }\n }\n\n componentDidUpdate(prevProps: MapProps) {\n const map = this.state.map\n if (!map) {\n return\n }\n\n const {onClick, location, bounds} = this.props\n\n if (prevProps.onClick !== onClick) {\n this.attachClickHandler()\n }\n\n if (!latLngAreEqual(prevProps.location, location)) {\n map.panTo(this.getCenter())\n }\n\n if (bounds && (!prevProps.bounds || !bounds.equals(prevProps.bounds))) {\n map.fitBounds(bounds)\n }\n }\n\n componentWillUnmount() {\n if (this.clickHandler) {\n this.clickHandler.remove()\n }\n }\n\n getCenter(): google.maps.LatLng {\n const {location, api} = this.props\n return new api.LatLng(location.lat, location.lng)\n }\n\n constructMap(el: HTMLDivElement) {\n const {defaultZoom, api, mapTypeControl, controlSize, bounds, scrollWheel} = this.props\n\n const map = new api.Map(el, {\n zoom: defaultZoom,\n center: this.getCenter(),\n scrollwheel: scrollWheel,\n streetViewControl: false,\n mapTypeControl,\n controlSize,\n })\n\n if (bounds) {\n map.fitBounds(bounds)\n }\n\n return map\n }\n\n setMapElement = (element: HTMLDivElement | null) => {\n if (element && element !== this.mapEl) {\n const map = this.constructMap(element)\n this.setState({map}, this.attachClickHandler)\n }\n\n this.mapEl = element\n }\n\n render() {\n const {children} = this.props\n const {map} = this.state\n return (\n <>\n <MapContainer ref={this.setMapElement} />\n {children && map ? children(map) : null}\n </>\n )\n }\n}\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AAAyC;AAAA;AAkBlC,MAAMA,SAAS,SAASC,cAAK,CAACC,aAAa,CAAqB;EAAA;IAAA;IAAA,+BAMnD;MAACC,GAAG,EAAEC;IAAS,CAAC;IAAA;IAAA,6CAEzBH,cAAK,CAACI,SAAS,EAAkB;IAAA,+BACX,IAAI;IAAA,4CAMd,MAAM;MACzB,IAAMF,GAAG,GAAG,IAAI,CAACG,KAAK,CAACH,GAAG;MAC1B,IAAI,CAACA,GAAG,EAAE;QACR;MACF;MAEA,kBAAuB,IAAI,CAACI,KAAK;QAA1BC,GAAG,eAAHA,GAAG;QAAEC,OAAO,eAAPA,OAAO;MACnB,IAAOC,KAAK,GAAIF,GAAG,CAAZE,KAAK;MAEZ,IAAI,IAAI,CAACC,YAAY,EAAE;QACrB,IAAI,CAACA,YAAY,CAACC,MAAM,EAAE;MAC5B;MAEA,IAAIH,OAAO,EAAE;QACX,IAAI,CAACE,YAAY,GAAGD,KAAK,CAACG,WAAW,CAACV,GAAG,EAAE,OAAO,EAAEM,OAAO,CAAC;MAC9D;IACF,CAAC;IAAA,uCAqDgBK,OAA8B,IAAK;MAClD,IAAIA,OAAO,IAAIA,OAAO,KAAK,IAAI,CAACC,KAAK,EAAE;QACrC,IAAMZ,IAAG,GAAG,IAAI,CAACa,YAAY,CAACF,OAAO,CAAC;QACtC,IAAI,CAACG,QAAQ,CAAC;UAACd,GAAG,EAAHA;QAAG,CAAC,EAAE,IAAI,CAACe,kBAAkB,CAAC;MAC/C;MAEA,IAAI,CAACH,KA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AAE2B,cAAc,gBAAdA,cAAc;MAAEC,WAAW,gBAAXA,WAAW;MAAEb,MAAM,gBAANA,MAAM;MAAEc,WAAW,gBAAXA,WAAW;IAEzE,IAAMlC,GAAG,GAAG,IAAIK,GAAG,CAAC8B,GAAG,CAACL,EAAE,EAAE;MAC1BM,IAAI,EAAEL,WAAW;MACjBM,MAAM,EAAE,IAAI,CAACd,SAAS,EAAE;MACxBe,WAAW,EAAEJ,WAAW;MACxBK,iBAAiB,EAAE,KAAK;MACxBP,cAAc;MACdC;IACF,CAAC,CAAC;IAEF,IAAIb,MAAM,EAAE;MACVpB,GAAG,CAACyB,SAAS,CAACL,MAAM,CAAC;IACvB;IAEA,OAAOpB,GAAG;EACZ;EAWAwC,MAAM,GAAG;IACP,IAAOC,QAAQ,GAAI,IAAI,CAACrC,KAAK,CAAtBqC,QAAQ;IACf,IAAOzC,GAAG,GAAI,IAAI,CAACG,KAAK,CAAjBH,GAAG;IACV,oBACE,yEACE,6BAAC,iBAAY;MAAC,GAAG,EAAE,IAAI,CAAC0C;IAAc,EAAG,EACxCD,QAAQ,IAAIzC,GAAG,GAAGyC,QAAQ,CAACzC,GAAG,CAAC,GAAG,IAAI,CACtC;EAEP;AACF;AAAC;AAAA,gBAvGYH,SAAS,kBACE;EACpBkC,WAAW,EAAE,CAAC;EACdG,WAAW,EAAE;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MapContainer = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _templateObject;
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
11
|
+
var MapContainer = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n"])));
|
|
12
|
+
exports.MapContainer = MapContainer;
|
|
13
|
+
//# sourceMappingURL=Map.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Map.styles.js","names":["MapContainer","styled","div"],"sources":["../../src/map/Map.styles.tsx"],"sourcesContent":["import styled from 'styled-components'\n\nexport const MapContainer = styled.div`\n position: absolute;\n top: 0;\n left: 0;\n height: 100%;\n width: 100%;\n box-sizing: border-box;\n`\n"],"mappings":";;;;;;AAAA;AAAsC;AAAA;AAAA;AAE/B,IAAMA,YAAY,GAAGC,yBAAM,CAACC,GAAG,iLAOrC;AAAA"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Marker = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _util = require("./util");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
var markerPath = 'M 3.052 3.7 C 1.56 5.293 0.626 7.612 0.663 9.793 C 0.738 14.352 2.793 16.077 6.078 22.351 C 7.263 25.111 8.497 28.032 9.672 32.871 C 9.835 33.584 9.994 34.246 10.069 34.305 C 10.143 34.362 10.301 33.697 10.465 32.983 C 11.639 28.145 12.875 25.226 14.059 22.466 C 17.344 16.192 19.398 14.466 19.474 9.908 C 19.511 7.727 18.574 5.405 17.083 3.814 C 15.379 1.994 12.809 0.649 10.069 0.593 C 7.328 0.536 4.756 1.882 3.052 3.7 Z';
|
|
13
|
+
class Marker extends React.PureComponent {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
_defineProperty(this, "marker", void 0);
|
|
17
|
+
_defineProperty(this, "eventHandlers", {});
|
|
18
|
+
}
|
|
19
|
+
componentDidMount() {
|
|
20
|
+
var _this$props = this.props,
|
|
21
|
+
position = _this$props.position,
|
|
22
|
+
api = _this$props.api,
|
|
23
|
+
map = _this$props.map,
|
|
24
|
+
onMove = _this$props.onMove,
|
|
25
|
+
zIndex = _this$props.zIndex,
|
|
26
|
+
opacity = _this$props.opacity,
|
|
27
|
+
label = _this$props.label,
|
|
28
|
+
markerRef = _this$props.markerRef,
|
|
29
|
+
color = _this$props.color;
|
|
30
|
+
var GMarker = api.Marker;
|
|
31
|
+
var icon;
|
|
32
|
+
if (color) {
|
|
33
|
+
icon = {
|
|
34
|
+
path: markerPath,
|
|
35
|
+
fillOpacity: 1,
|
|
36
|
+
fillColor: color.background,
|
|
37
|
+
strokeColor: color.border,
|
|
38
|
+
strokeWeight: 2,
|
|
39
|
+
anchor: new api.Point(10, 35),
|
|
40
|
+
labelOrigin: new api.Point(10, 11)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
this.marker = new GMarker({
|
|
44
|
+
draggable: Boolean(onMove),
|
|
45
|
+
position,
|
|
46
|
+
map,
|
|
47
|
+
zIndex,
|
|
48
|
+
opacity,
|
|
49
|
+
label,
|
|
50
|
+
icon
|
|
51
|
+
});
|
|
52
|
+
if (markerRef) {
|
|
53
|
+
markerRef.current = this.marker;
|
|
54
|
+
}
|
|
55
|
+
this.attachMoveHandler();
|
|
56
|
+
this.attachClickHandler();
|
|
57
|
+
}
|
|
58
|
+
componentDidUpdate(prevProps) {
|
|
59
|
+
if (!this.marker) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
var _this$props2 = this.props,
|
|
63
|
+
position = _this$props2.position,
|
|
64
|
+
onMove = _this$props2.onMove,
|
|
65
|
+
label = _this$props2.label,
|
|
66
|
+
zIndex = _this$props2.zIndex,
|
|
67
|
+
opacity = _this$props2.opacity,
|
|
68
|
+
map = _this$props2.map;
|
|
69
|
+
if (prevProps.onMove !== onMove) {
|
|
70
|
+
this.attachMoveHandler();
|
|
71
|
+
}
|
|
72
|
+
if (!(0, _util.latLngAreEqual)(prevProps.position, position)) {
|
|
73
|
+
this.marker.setPosition(position);
|
|
74
|
+
}
|
|
75
|
+
if (prevProps.label !== label) {
|
|
76
|
+
this.marker.setLabel(label || null);
|
|
77
|
+
}
|
|
78
|
+
if (prevProps.zIndex !== zIndex) {
|
|
79
|
+
this.marker.setZIndex(zIndex || null);
|
|
80
|
+
}
|
|
81
|
+
if (prevProps.opacity !== opacity) {
|
|
82
|
+
this.marker.setOpacity(opacity || null);
|
|
83
|
+
}
|
|
84
|
+
if (prevProps.map !== map) {
|
|
85
|
+
this.marker.setMap(map);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
componentWillUnmount() {
|
|
89
|
+
if (this.eventHandlers.move) {
|
|
90
|
+
this.eventHandlers.move.remove();
|
|
91
|
+
}
|
|
92
|
+
if (this.marker) {
|
|
93
|
+
this.marker.setMap(null);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
attachMoveHandler() {
|
|
97
|
+
var _this$props3 = this.props,
|
|
98
|
+
api = _this$props3.api,
|
|
99
|
+
onMove = _this$props3.onMove;
|
|
100
|
+
if (this.eventHandlers.move) {
|
|
101
|
+
this.eventHandlers.move.remove();
|
|
102
|
+
}
|
|
103
|
+
if (this.marker && onMove) {
|
|
104
|
+
this.eventHandlers.move = api.event.addListener(this.marker, 'dragend', onMove);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
attachClickHandler() {
|
|
108
|
+
var _this$props4 = this.props,
|
|
109
|
+
api = _this$props4.api,
|
|
110
|
+
onClick = _this$props4.onClick;
|
|
111
|
+
if (this.eventHandlers.click) {
|
|
112
|
+
this.eventHandlers.click.remove();
|
|
113
|
+
}
|
|
114
|
+
if (this.marker && onClick) {
|
|
115
|
+
this.eventHandlers.click = api.event.addListener(this.marker, 'click', onClick);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// eslint-disable-next-line class-methods-use-this
|
|
120
|
+
render() {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.Marker = Marker;
|
|
125
|
+
//# sourceMappingURL=Marker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Marker.js","names":["markerPath","Marker","React","PureComponent","componentDidMount","props","position","api","map","onMove","zIndex","opacity","label","markerRef","color","GMarker","icon","path","fillOpacity","fillColor","background","strokeColor","border","strokeWeight","anchor","Point","labelOrigin","marker","draggable","Boolean","current","attachMoveHandler","attachClickHandler","componentDidUpdate","prevProps","latLngAreEqual","setPosition","setLabel","setZIndex","setOpacity","setMap","componentWillUnmount","eventHandlers","move","remove","event","addListener","onClick","click","render"],"sources":["../../src/map/Marker.tsx"],"sourcesContent":["import * as React from 'react'\nimport {LatLng} from '../types'\nimport {latLngAreEqual} from './util'\n\nconst markerPath =\n 'M 3.052 3.7 C 1.56 5.293 0.626 7.612 0.663 9.793 C 0.738 14.352 2.793 16.077 6.078 22.351 C 7.263 25.111 8.497 28.032 9.672 32.871 C 9.835 33.584 9.994 34.246 10.069 34.305 C 10.143 34.362 10.301 33.697 10.465 32.983 C 11.639 28.145 12.875 25.226 14.059 22.466 C 17.344 16.192 19.398 14.466 19.474 9.908 C 19.511 7.727 18.574 5.405 17.083 3.814 C 15.379 1.994 12.809 0.649 10.069 0.593 C 7.328 0.536 4.756 1.882 3.052 3.7 Z'\n\ninterface Props {\n api: typeof window.google.maps\n map: google.maps.Map\n onMove?: (event: google.maps.MapMouseEvent) => void\n onClick?: (event: google.maps.MapMouseEvent) => void\n onMouseOver?: (event: google.maps.MapMouseEvent) => void\n onMouseOut?: (event: google.maps.MapMouseEvent) => void\n position: LatLng | google.maps.LatLng\n zIndex?: number\n opacity?: number\n label?: string\n markerRef?: React.MutableRefObject<google.maps.Marker | undefined>\n color?: {background: string; border: string; text: string}\n}\n\nexport class Marker extends React.PureComponent<Props> {\n marker: google.maps.Marker | undefined\n\n eventHandlers: {\n move?: google.maps.MapsEventListener\n click?: google.maps.MapsEventListener\n } = {}\n\n componentDidMount() {\n const {position, api, map, onMove, zIndex, opacity, label, markerRef, color} = this.props\n const {Marker: GMarker} = api\n\n let icon: google.maps.ReadonlySymbol | undefined\n if (color) {\n icon = {\n path: markerPath,\n fillOpacity: 1,\n fillColor: color.background,\n strokeColor: color.border,\n strokeWeight: 2,\n anchor: new api.Point(10, 35),\n labelOrigin: new api.Point(10, 11),\n }\n }\n\n this.marker = new GMarker({\n draggable: Boolean(onMove),\n position,\n map,\n zIndex,\n opacity,\n label,\n icon,\n })\n\n if (markerRef) {\n markerRef.current = this.marker\n }\n\n this.attachMoveHandler()\n this.attachClickHandler()\n }\n\n componentDidUpdate(prevProps: Props) {\n if (!this.marker) {\n return\n }\n\n const {position, onMove, label, zIndex, opacity, map} = this.props\n\n if (prevProps.onMove !== onMove) {\n this.attachMoveHandler()\n }\n\n if (!latLngAreEqual(prevProps.position, position)) {\n this.marker.setPosition(position)\n }\n\n if (prevProps.label !== label) {\n this.marker.setLabel(label || null)\n }\n\n if (prevProps.zIndex !== zIndex) {\n this.marker.setZIndex(zIndex || null)\n }\n\n if (prevProps.opacity !== opacity) {\n this.marker.setOpacity(opacity || null)\n }\n\n if (prevProps.map !== map) {\n this.marker.setMap(map)\n }\n }\n\n componentWillUnmount() {\n if (this.eventHandlers.move) {\n this.eventHandlers.move.remove()\n }\n\n if (this.marker) {\n this.marker.setMap(null)\n }\n }\n\n attachMoveHandler() {\n const {api, onMove} = this.props\n if (this.eventHandlers.move) {\n this.eventHandlers.move.remove()\n }\n if (this.marker && onMove) {\n this.eventHandlers.move = api.event.addListener(this.marker, 'dragend', onMove)\n }\n }\n\n attachClickHandler() {\n const {api, onClick} = this.props\n if (this.eventHandlers.click) {\n this.eventHandlers.click.remove()\n }\n if (this.marker && onClick) {\n this.eventHandlers.click = api.event.addListener(this.marker, 'click', onClick)\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n render() {\n return null\n }\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAAqC;AAAA;AAAA;AAErC,IAAMA,UAAU,GACd,yaAAya;AAiBpa,MAAMC,MAAM,SAASC,KAAK,CAACC,aAAa,CAAQ;EAAA;IAAA;IAAA;IAAA,uCAMjD,CAAC,CAAC;EAAA;EAENC,iBAAiB,GAAG;IAClB,kBAA+E,IAAI,CAACC,KAAK;MAAlFC,QAAQ,eAARA,QAAQ;MAAEC,GAAG,eAAHA,GAAG;MAAEC,GAAG,eAAHA,GAAG;MAAEC,MAAM,eAANA,MAAM;MAAEC,MAAM,eAANA,MAAM;MAAEC,OAAO,eAAPA,OAAO;MAAEC,KAAK,eAALA,KAAK;MAAEC,SAAS,eAATA,SAAS;MAAEC,KAAK,eAALA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;EACF;EAEAuB,kBAAkB,GAAG;IACnB,mBAAuB,IAAI,CAAC3B,KAAK;MAA1BE,GAAG,gBAAHA,GAAG;MAAEwC,OAAO,gBAAPA,OAAO;IACnB,IAAI,IAAI,CAACL,aAAa,CAACM,KAAK,EAAE;MAC5B,IAAI,CAACN,aAAa,CAACM,KAAK,CAACJ,MAAM,EAAE;IACnC;IACA,IAAI,IAAI,CAACjB,MAAM,IAAIoB,OAAO,EAAE;MAC1B,IAAI,CAACL,aAAa,CAACM,KAAK,GAAGzC,GAAG,CAACsC,KAAK,CAACC,WAAW,CAAC,IAAI,CAACnB,MAAM,EAAE,OAAO,EAAEoB,OAAO,CAAC;IACjF;EACF;;EAEA;EACAE,MAAM,GAAG;IACP,OAAO,IAAI;EACb;AACF;AAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SearchInput = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _ui = require("@sanity/ui");
|
|
9
|
+
var _SearchInput = require("./SearchInput.styles");
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
12
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
class SearchInput extends React.PureComponent {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
_defineProperty(this, "searchInputRef", /*#__PURE__*/React.createRef());
|
|
17
|
+
_defineProperty(this, "autoComplete", void 0);
|
|
18
|
+
_defineProperty(this, "handleChange", () => {
|
|
19
|
+
if (!this.autoComplete) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.props.onChange(this.autoComplete.getPlace());
|
|
23
|
+
if (this.searchInputRef.current) {
|
|
24
|
+
this.searchInputRef.current.value = '';
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
componentDidMount() {
|
|
29
|
+
var input = this.searchInputRef.current;
|
|
30
|
+
if (!input) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var _this$props = this.props,
|
|
34
|
+
api = _this$props.api,
|
|
35
|
+
map = _this$props.map;
|
|
36
|
+
var Circle = api.Circle,
|
|
37
|
+
places = api.places,
|
|
38
|
+
event = api.event;
|
|
39
|
+
var searchBounds = new Circle({
|
|
40
|
+
center: map.getCenter(),
|
|
41
|
+
radius: 100
|
|
42
|
+
}).getBounds();
|
|
43
|
+
this.autoComplete = new places.Autocomplete(input, {
|
|
44
|
+
bounds: searchBounds,
|
|
45
|
+
types: [] // return all kinds of places
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
event.addListener(this.autoComplete, 'place_changed', this.handleChange);
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
return /*#__PURE__*/React.createElement(_SearchInput.WrapperContainer, null, /*#__PURE__*/React.createElement(_ui.TextInput, {
|
|
52
|
+
name: "place",
|
|
53
|
+
ref: this.searchInputRef,
|
|
54
|
+
placeholder: "Search for place or address",
|
|
55
|
+
padding: 4
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.SearchInput = SearchInput;
|
|
60
|
+
//# sourceMappingURL=SearchInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchInput.js","names":["SearchInput","React","PureComponent","createRef","autoComplete","props","onChange","getPlace","searchInputRef","current","value","componentDidMount","input","api","map","Circle","places","event","searchBounds","center","getCenter","radius","getBounds","Autocomplete","bounds","types","addListener","handleChange","render"],"sources":["../../src/map/SearchInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport {TextInput} from '@sanity/ui'\nimport {WrapperContainer} from './SearchInput.styles'\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"],"mappings":";;;;;;AAAA;AACA;AACA;AAAqD;AAAA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,GAAG,EAAE,IAAI,CAACpB,cAAe;MACzB,WAAW,EAAC,6BAA6B;MACzC,OAAO,EAAE;IAAE,EACX,CACe;EAEvB;AACF;AAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WrapperContainer = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _templateObject;
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
11
|
+
var WrapperContainer = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n right: 10px;\n top: 10px;\n width: 220px;\n"])));
|
|
12
|
+
exports.WrapperContainer = WrapperContainer;
|
|
13
|
+
//# sourceMappingURL=SearchInput.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchInput.styles.js","names":["WrapperContainer","styled","div"],"sources":["../../src/map/SearchInput.styles.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"],"mappings":";;;;;;AAAA;AAAsC;AAAA;AAAA;AAE/B,IAAMA,gBAAgB,GAAGC,yBAAM,CAACC,GAAG,6IAKzC;AAAA"}
|
package/lib/map/util.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.latLngAreEqual = latLngAreEqual;
|
|
7
|
+
function latLngAreEqual(latLng1, latLng2) {
|
|
8
|
+
var lat1 = typeof latLng1.lat === 'function' ? latLng1.lat() : latLng1.lat;
|
|
9
|
+
var lng1 = typeof latLng1.lng === 'function' ? latLng1.lng() : latLng1.lng;
|
|
10
|
+
var lat2 = typeof latLng2.lat === 'function' ? latLng2.lat() : latLng2.lat;
|
|
11
|
+
var lng2 = typeof latLng2.lng === 'function' ? latLng2.lng() : latLng2.lng;
|
|
12
|
+
return lat1 === lat2 && lng1 === lng2;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","names":["latLngAreEqual","latLng1","latLng2","lat1","lat","lng1","lng","lat2","lng2"],"sources":["../../src/map/util.ts"],"sourcesContent":["import {LatLng} from '../types'\n\nexport function latLngAreEqual(\n latLng1: LatLng | google.maps.LatLng,\n latLng2: LatLng | google.maps.LatLng\n) {\n const lat1 = typeof latLng1.lat === 'function' ? latLng1.lat() : latLng1.lat\n const lng1 = typeof latLng1.lng === 'function' ? latLng1.lng() : latLng1.lng\n\n const lat2 = typeof latLng2.lat === 'function' ? latLng2.lat() : latLng2.lat\n const lng2 = typeof latLng2.lng === 'function' ? latLng2.lng() : latLng2.lng\n\n return lat1 === lat2 && lng1 === lng2\n}\n"],"mappings":";;;;;;AAEO,SAASA,cAAc,CAC5BC,OAAoC,EACpCC,OAAoC,EACpC;EACA,IAAMC,IAAI,GAAG,OAAOF,OAAO,CAACG,GAAG,KAAK,UAAU,GAAGH,OAAO,CAACG,GAAG,EAAE,GAAGH,OAAO,CAACG,GAAG;EAC5E,IAAMC,IAAI,GAAG,OAAOJ,OAAO,CAACK,GAAG,KAAK,UAAU,GAAGL,OAAO,CAACK,GAAG,EAAE,GAAGL,OAAO,CAACK,GAAG;EAE5E,IAAMC,IAAI,GAAG,OAAOL,OAAO,CAACE,GAAG,KAAK,UAAU,GAAGF,OAAO,CAACE,GAAG,EAAE,GAAGF,OAAO,CAACE,GAAG;EAC5E,IAAMI,IAAI,GAAG,OAAON,OAAO,CAACI,GAAG,KAAK,UAAU,GAAGJ,OAAO,CAACI,GAAG,EAAE,GAAGJ,OAAO,CAACI,GAAG;EAE5E,OAAOH,IAAI,KAAKI,IAAI,IAAIF,IAAI,KAAKG,IAAI;AACvC"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import {ObjectSchemaType} from '@sanity/field/diff'\n\nexport interface LatLng {\n lat: number\n lng: number\n}\n\nexport interface Geopoint {\n _type: 'geopoint'\n _key?: string\n lat: number\n lng: number\n alt?: number\n}\n\nexport type GeopointSchemaType = ObjectSchemaType<Geopoint>\n"],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/google-maps-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-v2-studio.1",
|
|
4
4
|
"description": "Sanity plugin providing input handlers for geo-related input types using Google Maps",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"author": "Sanity.io <hello@sanity.io>",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"clean": "rimraf lib",
|
|
10
|
-
"start": "cd example && sanity start",
|
|
11
|
-
"prepublishOnly": "sanity-check"
|
|
12
|
-
},
|
|
13
5
|
"keywords": [
|
|
14
6
|
"sanity",
|
|
15
7
|
"cms",
|
|
@@ -19,27 +11,71 @@
|
|
|
19
11
|
"google-maps-input",
|
|
20
12
|
"sanity-plugin"
|
|
21
13
|
],
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"@sanity/cli": "0.147.10-ts-client.1+5473a24ff",
|
|
26
|
-
"@sanity/components": "0.147.10-ts-client.1+5473a24ff",
|
|
27
|
-
"@sanity/core": "0.147.10-ts-client.1+5473a24ff",
|
|
28
|
-
"lodash": "^4.17.15",
|
|
29
|
-
"prop-types": "^15.6.0",
|
|
30
|
-
"rimraf": "^2.7.1"
|
|
31
|
-
},
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"react": "^16.9",
|
|
34
|
-
"react-dom": "^16.9"
|
|
14
|
+
"homepage": "https://www.sanity.io/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sanity-io/google-maps-input/issues"
|
|
35
17
|
},
|
|
36
18
|
"repository": {
|
|
37
19
|
"type": "git",
|
|
38
|
-
"url": "git
|
|
20
|
+
"url": "git@github.com:sanity-io/google-maps-input.git"
|
|
39
21
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
24
|
+
"main": "lib/input/GeopointInput.js",
|
|
25
|
+
"types": "./dts/input/GeopointInput.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"dts",
|
|
29
|
+
"src",
|
|
30
|
+
"sanity.json",
|
|
31
|
+
"config.dist.json"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prebuild": "npm run clean",
|
|
35
|
+
"build": "tsc --declaration --emitDeclarationOnly && sanipack build",
|
|
36
|
+
"clean": "rimraf lib",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"prepare": "husky install",
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
|
+
"watch": "sanipack build --watch"
|
|
42
41
|
},
|
|
43
|
-
"
|
|
44
|
-
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@sanity/field": "2.35.2",
|
|
44
|
+
"@sanity/icons": "^1.3.4",
|
|
45
|
+
"@sanity/types": "2.35.0",
|
|
46
|
+
"@sanity/ui": "^0.37.22",
|
|
47
|
+
"lodash": "^4.17.15",
|
|
48
|
+
"rxjs": "^6.5.3"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@commitlint/cli": "^17.3.0",
|
|
52
|
+
"@commitlint/config-conventional": "^17.3.0",
|
|
53
|
+
"@sanity/base": "2.35.2",
|
|
54
|
+
"@sanity/semantic-release-preset": "^2.0.1",
|
|
55
|
+
"@types/googlemaps": "^3.43.0",
|
|
56
|
+
"@types/styled-components": "5.1.26",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
58
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
59
|
+
"eslint": "^8.27.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-config-sanity": "^6.0.0",
|
|
62
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
+
"eslint-plugin-react": "^7.31.10",
|
|
64
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
65
|
+
"husky": "^8.0.1",
|
|
66
|
+
"lint-staged": "^13.0.3",
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
|
+
"prettier-plugin-packagejson": "^2.3.0",
|
|
69
|
+
"prop-types": "^15.8.1",
|
|
70
|
+
"react": "17.0.1",
|
|
71
|
+
"rimraf": "^2.7.1",
|
|
72
|
+
"sanipack": "^2.1.0",
|
|
73
|
+
"styled-components": "^5.2.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"@sanity/base": "^2.0.0",
|
|
77
|
+
"react": "^16.9 || ^17",
|
|
78
|
+
"react-dom": "^16.9 || ^17",
|
|
79
|
+
"styled-components": "^5.2.0"
|
|
80
|
+
}
|
|
45
81
|
}
|
package/sanity.json
CHANGED
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
{
|
|
9
9
|
"name": "part:@sanity/google-maps-input/input/geopoint",
|
|
10
10
|
"implements": "part:@sanity/form-builder/input/geopoint",
|
|
11
|
-
"path": "GeopointInput
|
|
11
|
+
"path": "input/GeopointInput"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"implements": "part:@sanity/base/diff-resolver",
|
|
15
|
+
"path": "diff/resolver"
|
|
12
16
|
}
|
|
13
17
|
]
|
|
14
18
|
}
|
|
@@ -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/field/diff'
|
|
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
|
+
`
|