@sanity/google-maps-input 2.30.2-shopify.0 → 3.0.0-studio-v3.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.
Files changed (92) hide show
  1. package/README.md +68 -2
  2. package/lib/cjs/index.js +902 -0
  3. package/lib/cjs/index.js.map +1 -0
  4. package/lib/esm/index.js +892 -0
  5. package/lib/esm/index.js.map +1 -0
  6. package/lib/types/index.d.ts +43 -0
  7. package/lib/types/index.d.ts.map +1 -0
  8. package/package.json +71 -19
  9. package/src/@types/css.d.ts +4 -0
  10. package/src/diff/GeopointArrayDiff.tsx +84 -0
  11. package/src/diff/GeopointFieldDiff.styles.tsx +20 -0
  12. package/src/diff/GeopointFieldDiff.tsx +95 -0
  13. package/src/diff/GeopointMove.tsx +48 -0
  14. package/src/diff/resolver.ts +21 -0
  15. package/src/global-workaround.ts +11 -0
  16. package/src/index.tsx +52 -0
  17. package/src/input/GeopointInput.styles.tsx +12 -0
  18. package/src/input/GeopointInput.tsx +176 -0
  19. package/src/input/GeopointSelect.tsx +78 -0
  20. package/src/loader/GoogleMapsLoadProxy.tsx +51 -0
  21. package/src/loader/LoadError.tsx +44 -0
  22. package/src/loader/loadGoogleMapsApi.ts +97 -0
  23. package/src/map/Arrow.tsx +76 -0
  24. package/src/map/Map.styles.tsx +10 -0
  25. package/src/map/Map.tsx +125 -0
  26. package/src/map/Marker.tsx +130 -0
  27. package/src/map/SearchInput.styles.tsx +8 -0
  28. package/src/map/SearchInput.tsx +56 -0
  29. package/src/map/util.ts +14 -0
  30. package/src/types.ts +19 -0
  31. package/.depcheckignore.json +0 -3
  32. package/config.dist.json +0 -9
  33. package/dist/dts/diff/GeopointArrayDiff.d.ts +0 -5
  34. package/dist/dts/diff/GeopointArrayDiff.d.ts.map +0 -1
  35. package/dist/dts/diff/GeopointFieldDiff.d.ts +0 -5
  36. package/dist/dts/diff/GeopointFieldDiff.d.ts.map +0 -1
  37. package/dist/dts/diff/GeopointFieldDiff.styles.d.ts +0 -2
  38. package/dist/dts/diff/GeopointFieldDiff.styles.d.ts.map +0 -1
  39. package/dist/dts/diff/GeopointMove.d.ts +0 -13
  40. package/dist/dts/diff/GeopointMove.d.ts.map +0 -1
  41. package/dist/dts/diff/resolver.d.ts +0 -4
  42. package/dist/dts/diff/resolver.d.ts.map +0 -1
  43. package/dist/dts/input/GeopointInput.d.ts +0 -40
  44. package/dist/dts/input/GeopointInput.d.ts.map +0 -1
  45. package/dist/dts/input/GeopointInput.styles.d.ts +0 -3
  46. package/dist/dts/input/GeopointInput.styles.d.ts.map +0 -1
  47. package/dist/dts/input/GeopointSelect.d.ts +0 -28
  48. package/dist/dts/input/GeopointSelect.d.ts.map +0 -1
  49. package/dist/dts/loader/GoogleMapsLoadProxy.d.ts +0 -14
  50. package/dist/dts/loader/GoogleMapsLoadProxy.d.ts.map +0 -1
  51. package/dist/dts/loader/LoadError.d.ts +0 -10
  52. package/dist/dts/loader/LoadError.d.ts.map +0 -1
  53. package/dist/dts/loader/loadGoogleMapsApi.d.ts +0 -18
  54. package/dist/dts/loader/loadGoogleMapsApi.d.ts.map +0 -1
  55. package/dist/dts/map/Arrow.d.ts +0 -29
  56. package/dist/dts/map/Arrow.d.ts.map +0 -1
  57. package/dist/dts/map/Map.d.ts +0 -37
  58. package/dist/dts/map/Map.d.ts.map +0 -1
  59. package/dist/dts/map/Map.styles.d.ts +0 -2
  60. package/dist/dts/map/Map.styles.d.ts.map +0 -1
  61. package/dist/dts/map/Marker.d.ts +0 -36
  62. package/dist/dts/map/Marker.d.ts.map +0 -1
  63. package/dist/dts/map/SearchInput.d.ts +0 -16
  64. package/dist/dts/map/SearchInput.d.ts.map +0 -1
  65. package/dist/dts/map/SearchInput.styles.d.ts +0 -2
  66. package/dist/dts/map/SearchInput.styles.d.ts.map +0 -1
  67. package/dist/dts/map/util.d.ts +0 -4
  68. package/dist/dts/map/util.d.ts.map +0 -1
  69. package/dist/dts/types.d.ts +0 -14
  70. package/dist/dts/types.d.ts.map +0 -1
  71. package/lib/@types/css.d.js +0 -1
  72. package/lib/diff/GeopointArrayDiff.js +0 -82
  73. package/lib/diff/GeopointFieldDiff.js +0 -97
  74. package/lib/diff/GeopointFieldDiff.styles.js +0 -18
  75. package/lib/diff/GeopointMove.js +0 -55
  76. package/lib/diff/resolver.js +0 -27
  77. package/lib/input/GeopointInput.js +0 -194
  78. package/lib/input/GeopointInput.styles.js +0 -22
  79. package/lib/input/GeopointSelect.js +0 -103
  80. package/lib/loader/GoogleMapsLoadProxy.js +0 -70
  81. package/lib/loader/LoadError.js +0 -43
  82. package/lib/loader/loadGoogleMapsApi.js +0 -81
  83. package/lib/map/Arrow.js +0 -97
  84. package/lib/map/Map.js +0 -147
  85. package/lib/map/Map.styles.js +0 -18
  86. package/lib/map/Marker.js +0 -156
  87. package/lib/map/SearchInput.js +0 -77
  88. package/lib/map/SearchInput.styles.js +0 -18
  89. package/lib/map/util.js +0 -14
  90. package/lib/types.js +0 -5
  91. package/sanity.json +0 -18
  92. package/tsconfig.json +0 -20
@@ -0,0 +1,902 @@
1
+ var $dyHF6$reactjsxruntime = require("react/jsx-runtime");
2
+ var $dyHF6$react = require("react");
3
+ var $dyHF6$sanity = require("sanity");
4
+ var $dyHF6$lodash = require("lodash");
5
+ var $dyHF6$sanityui = require("@sanity/ui");
6
+ var $dyHF6$sanityicons = require("@sanity/icons");
7
+ var $dyHF6$sanity_unstable = require("sanity/_unstable");
8
+ var $dyHF6$sanityform = require("sanity/form");
9
+ var $dyHF6$rxjs = require("rxjs");
10
+ var $dyHF6$styledcomponents = require("styled-components");
11
+
12
+ function $parcel$export(e, n, v, s) {
13
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
+ }
15
+ function $parcel$interopDefault(a) {
16
+ return a && a.__esModule ? a.default : a;
17
+ }
18
+
19
+ $parcel$export(module.exports, "googleMapsInput", () => $329a1cedcedb1349$export$626ae7d0cf8f9143);
20
+ $parcel$export(module.exports, "GeopointArrayDiff", () => $5245dd3554e263be$export$2d0695678527b4cc);
21
+ $parcel$export(module.exports, "GeopointFieldDiff", () => $59d44c8f30c12966$export$6b7bf6aeccd8ac3f);
22
+ $parcel$export(module.exports, "GeopointInput", () => $6c4d418093d85b71$export$2e2bcd8739ae039);
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ const $f83c917b838af6fc$var$callbackName = "___sanity_googleMapsApiCallback";
37
+ const $f83c917b838af6fc$var$authFailureCallbackName = "gm_authFailure";
38
+ const $f83c917b838af6fc$var$locale = typeof window !== "undefined" && window.navigator.language || "en";
39
+ let $f83c917b838af6fc$var$subject;
40
+ function $f83c917b838af6fc$export$616f2ff2d07a5991(config) {
41
+ const selectedLocale = config.defaultLocale || $f83c917b838af6fc$var$locale || "en-US";
42
+ if ($f83c917b838af6fc$var$subject) return $f83c917b838af6fc$var$subject;
43
+ $f83c917b838af6fc$var$subject = new (0, $dyHF6$rxjs.BehaviorSubject)({
44
+ loadState: "loading"
45
+ });
46
+ window[$f83c917b838af6fc$var$authFailureCallbackName] = ()=>{
47
+ delete window[$f83c917b838af6fc$var$authFailureCallbackName];
48
+ $f83c917b838af6fc$var$subject.next({
49
+ loadState: "authError"
50
+ });
51
+ };
52
+ window[$f83c917b838af6fc$var$callbackName] = ()=>{
53
+ delete window[$f83c917b838af6fc$var$callbackName];
54
+ $f83c917b838af6fc$var$subject.next({
55
+ loadState: "loaded",
56
+ api: window.google.maps
57
+ });
58
+ };
59
+ const script = document.createElement("script");
60
+ script.onerror = (event, source, lineno, colno, error)=>$f83c917b838af6fc$var$subject.next({
61
+ loadState: "loadError",
62
+ error: $f83c917b838af6fc$var$coeerceError(event, error)
63
+ });
64
+ script.src = `https://maps.googleapis.com/maps/api/js?key=${config.apiKey}&libraries=places&callback=${$f83c917b838af6fc$var$callbackName}&language=${selectedLocale}`;
65
+ document.getElementsByTagName("head")[0].appendChild(script);
66
+ return $f83c917b838af6fc$var$subject;
67
+ }
68
+ function $f83c917b838af6fc$var$coeerceError(event, error) {
69
+ if (error) return error;
70
+ if (typeof event === "string") return new Error(event);
71
+ return new Error($f83c917b838af6fc$var$isErrorEvent(event) ? event.message : "Failed to load Google Maps API");
72
+ }
73
+ function $f83c917b838af6fc$var$isErrorEvent(event) {
74
+ if (typeof event !== "object" || event === null) return false;
75
+ if (!("message" in event)) return false;
76
+ return typeof event.message === "string";
77
+ }
78
+
79
+
80
+
81
+
82
+
83
+ function $53fff27a5374fe8c$export$58a097931cd8d64d(props) {
84
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$sanityui.Card), {
85
+ tone: "critical",
86
+ radius: 1,
87
+ children: [
88
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Box), {
89
+ as: "header",
90
+ paddingX: 4,
91
+ paddingTop: 4,
92
+ paddingBottom: 1,
93
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Text), {
94
+ as: "h2",
95
+ weight: "bold",
96
+ children: "Google Maps failed to load"
97
+ })
98
+ }),
99
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Box), {
100
+ paddingX: 4,
101
+ paddingTop: 4,
102
+ paddingBottom: 1,
103
+ children: props.isAuthError ? /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)($53fff27a5374fe8c$var$AuthError, {}) : /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$reactjsxruntime.Fragment), {
104
+ children: [
105
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Text), {
106
+ as: "h3",
107
+ children: "Error details:"
108
+ }),
109
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("pre", {
110
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Code), {
111
+ size: 1,
112
+ children: "error" in props && props.error?.message
113
+ })
114
+ })
115
+ ]
116
+ })
117
+ })
118
+ ]
119
+ });
120
+ }
121
+ function $53fff27a5374fe8c$var$AuthError() {
122
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$sanityui.Text), {
123
+ children: [
124
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("p", {
125
+ children: "The error appears to be related to authentication"
126
+ }),
127
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("p", {
128
+ children: "Common causes include:"
129
+ }),
130
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)("ul", {
131
+ children: [
132
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
133
+ children: "Incorrect API key"
134
+ }),
135
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
136
+ children: "Referer not allowed"
137
+ }),
138
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
139
+ children: "Missing authentication scope"
140
+ })
141
+ ]
142
+ }),
143
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("p", {
144
+ children: "Check the browser developer tools for more information."
145
+ })
146
+ ]
147
+ });
148
+ }
149
+
150
+
151
+ class $ffeb69a200895c22$export$a628545bcf173896 extends (0, ($parcel$interopDefault($dyHF6$react))).Component {
152
+ constructor(props){
153
+ super(props);
154
+ this.state = {
155
+ loadState: "loading"
156
+ };
157
+ let sync = true;
158
+ this.loadSubscription = (0, $f83c917b838af6fc$export$616f2ff2d07a5991)(props.config).subscribe((loadState)=>{
159
+ if (sync) this.state = loadState;
160
+ else this.setState(loadState);
161
+ });
162
+ sync = false;
163
+ }
164
+ componentWillUnmount() {
165
+ if (this.loadSubscription) this.loadSubscription.unsubscribe();
166
+ }
167
+ render() {
168
+ switch(this.state.loadState){
169
+ case "loadError":
170
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $53fff27a5374fe8c$export$58a097931cd8d64d), {
171
+ error: this.state.error,
172
+ isAuthError: false
173
+ });
174
+ case "authError":
175
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $53fff27a5374fe8c$export$58a097931cd8d64d), {
176
+ isAuthError: true
177
+ });
178
+ case "loading":
179
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("div", {
180
+ children: "Loading Google Maps API"
181
+ });
182
+ case "loaded":
183
+ return this.props.children(this.state.api) || null;
184
+ default:
185
+ return null;
186
+ }
187
+ }
188
+ }
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+ const $d1c3432f7dd52338$export$be3daefb18c346ac = (0, ($parcel$interopDefault($dyHF6$styledcomponents))).div`
198
+ position: absolute;
199
+ right: 10px;
200
+ top: 10px;
201
+ width: 220px;
202
+ `;
203
+
204
+
205
+ class $06ee1f282087006d$export$55d7609a8f1eccd2 extends $dyHF6$react.PureComponent {
206
+ searchInputRef = /*#__PURE__*/ $dyHF6$react.createRef();
207
+ handleChange = ()=>{
208
+ if (!this.autoComplete) return;
209
+ this.props.onChange(this.autoComplete.getPlace());
210
+ if (this.searchInputRef.current) this.searchInputRef.current.value = "";
211
+ };
212
+ componentDidMount() {
213
+ const input = this.searchInputRef.current;
214
+ if (!input) return;
215
+ const { api: api , map: map } = this.props;
216
+ const { Circle: Circle , places: places , event: event } = api;
217
+ const searchBounds = new Circle({
218
+ center: map.getCenter(),
219
+ radius: 100
220
+ }).getBounds();
221
+ this.autoComplete = new places.Autocomplete(input, {
222
+ bounds: searchBounds,
223
+ types: []
224
+ });
225
+ event.addListener(this.autoComplete, "place_changed", this.handleChange);
226
+ }
227
+ render() {
228
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $d1c3432f7dd52338$export$be3daefb18c346ac), {
229
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.TextInput), {
230
+ name: "place",
231
+ ref: this.searchInputRef,
232
+ placeholder: "Search for place or address",
233
+ padding: 4
234
+ })
235
+ });
236
+ }
237
+ }
238
+
239
+
240
+
241
+
242
+ function $97ec7b8b370674b5$export$ad553d4d3a617f20(latLng1, latLng2) {
243
+ const lat1 = typeof latLng1.lat === "function" ? latLng1.lat() : latLng1.lat;
244
+ const lng1 = typeof latLng1.lng === "function" ? latLng1.lng() : latLng1.lng;
245
+ const lat2 = typeof latLng2.lat === "function" ? latLng2.lat() : latLng2.lat;
246
+ const lng2 = typeof latLng2.lng === "function" ? latLng2.lng() : latLng2.lng;
247
+ return lat1 === lat2 && lng1 === lng2;
248
+ }
249
+
250
+
251
+
252
+ const $c49746d4a5875a1e$export$23f3dfd47374502b = (0, ($parcel$interopDefault($dyHF6$styledcomponents))).div`
253
+ position: absolute;
254
+ top: 0;
255
+ left: 0;
256
+ height: 100%;
257
+ width: 100%;
258
+ box-sizing: border-box;
259
+ `;
260
+
261
+
262
+ class $b4ba0a9d820dad94$export$4ad1bae46276c5ce extends (0, ($parcel$interopDefault($dyHF6$react))).PureComponent {
263
+ static defaultProps = {
264
+ defaultZoom: 8,
265
+ scrollWheel: true
266
+ };
267
+ state = {
268
+ map: undefined
269
+ };
270
+ mapRef = /*#__PURE__*/ (0, ($parcel$interopDefault($dyHF6$react))).createRef();
271
+ mapEl = null;
272
+ componentDidMount() {
273
+ this.attachClickHandler();
274
+ }
275
+ attachClickHandler = ()=>{
276
+ const map = this.state.map;
277
+ if (!map) return;
278
+ const { api: api , onClick: onClick } = this.props;
279
+ const { event: event } = api;
280
+ if (this.clickHandler) this.clickHandler.remove();
281
+ if (onClick) this.clickHandler = event.addListener(map, "click", onClick);
282
+ };
283
+ componentDidUpdate(prevProps) {
284
+ const map = this.state.map;
285
+ if (!map) return;
286
+ const { onClick: onClick , location: location , bounds: bounds } = this.props;
287
+ if (prevProps.onClick !== onClick) this.attachClickHandler();
288
+ if (!(0, $97ec7b8b370674b5$export$ad553d4d3a617f20)(prevProps.location, location)) map.panTo(this.getCenter());
289
+ if (bounds && (!prevProps.bounds || !bounds.equals(prevProps.bounds))) map.fitBounds(bounds);
290
+ }
291
+ componentWillUnmount() {
292
+ if (this.clickHandler) this.clickHandler.remove();
293
+ }
294
+ getCenter() {
295
+ const { location: location , api: api } = this.props;
296
+ return new api.LatLng(location.lat, location.lng);
297
+ }
298
+ constructMap(el) {
299
+ const { defaultZoom: defaultZoom , api: api , mapTypeControl: mapTypeControl , controlSize: controlSize , bounds: bounds , scrollWheel: scrollWheel } = this.props;
300
+ const map = new api.Map(el, {
301
+ zoom: defaultZoom,
302
+ center: this.getCenter(),
303
+ scrollwheel: scrollWheel,
304
+ streetViewControl: false,
305
+ mapTypeControl: mapTypeControl,
306
+ controlSize: controlSize
307
+ });
308
+ if (bounds) map.fitBounds(bounds);
309
+ return map;
310
+ }
311
+ setMapElement = (element)=>{
312
+ if (element && element !== this.mapEl) {
313
+ const map = this.constructMap(element);
314
+ this.setState({
315
+ map: map
316
+ }, this.attachClickHandler);
317
+ }
318
+ this.mapEl = element;
319
+ };
320
+ render() {
321
+ const { children: children } = this.props;
322
+ const { map: map } = this.state;
323
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$reactjsxruntime.Fragment), {
324
+ children: [
325
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $c49746d4a5875a1e$export$23f3dfd47374502b), {
326
+ ref: this.setMapElement
327
+ }),
328
+ children && map ? children(map) : null
329
+ ]
330
+ });
331
+ }
332
+ }
333
+
334
+
335
+
336
+
337
+ const $03ff3d51ebf52598$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";
338
+ class $03ff3d51ebf52598$export$e98856a975cab58e extends $dyHF6$react.PureComponent {
339
+ eventHandlers = {};
340
+ componentDidMount() {
341
+ const { position: position , api: api , map: map , onMove: onMove , zIndex: zIndex , opacity: opacity , label: label , markerRef: markerRef , color: color } = this.props;
342
+ const { Marker: GMarker } = api;
343
+ let icon;
344
+ if (color) icon = {
345
+ path: $03ff3d51ebf52598$var$markerPath,
346
+ fillOpacity: 1,
347
+ fillColor: color.background,
348
+ strokeColor: color.border,
349
+ strokeWeight: 2,
350
+ anchor: new api.Point(10, 35),
351
+ labelOrigin: new api.Point(10, 11)
352
+ };
353
+ this.marker = new GMarker({
354
+ draggable: Boolean(onMove),
355
+ position: position,
356
+ map: map,
357
+ zIndex: zIndex,
358
+ opacity: opacity,
359
+ label: label,
360
+ icon: icon
361
+ });
362
+ if (markerRef) markerRef.current = this.marker;
363
+ this.attachMoveHandler();
364
+ this.attachClickHandler();
365
+ }
366
+ componentDidUpdate(prevProps) {
367
+ if (!this.marker) return;
368
+ const { position: position , onMove: onMove , label: label , zIndex: zIndex , opacity: opacity , map: map } = this.props;
369
+ if (prevProps.onMove !== onMove) this.attachMoveHandler();
370
+ if (!(0, $97ec7b8b370674b5$export$ad553d4d3a617f20)(prevProps.position, position)) this.marker.setPosition(position);
371
+ if (prevProps.label !== label) this.marker.setLabel(label || null);
372
+ if (prevProps.zIndex !== zIndex) this.marker.setZIndex(zIndex || null);
373
+ if (prevProps.opacity !== opacity) this.marker.setOpacity(opacity || null);
374
+ if (prevProps.map !== map) this.marker.setMap(map);
375
+ }
376
+ componentWillUnmount() {
377
+ if (this.eventHandlers.move) this.eventHandlers.move.remove();
378
+ if (this.marker) this.marker.setMap(null);
379
+ }
380
+ attachMoveHandler() {
381
+ const { api: api , onMove: onMove } = this.props;
382
+ if (this.eventHandlers.move) this.eventHandlers.move.remove();
383
+ if (this.marker && onMove) this.eventHandlers.move = api.event.addListener(this.marker, "dragend", onMove);
384
+ }
385
+ attachClickHandler() {
386
+ const { api: api , onClick: onClick } = this.props;
387
+ if (this.eventHandlers.click) this.eventHandlers.click.remove();
388
+ if (this.marker && onClick) this.eventHandlers.click = api.event.addListener(this.marker, "click", onClick);
389
+ }
390
+ // eslint-disable-next-line class-methods-use-this
391
+ render() {
392
+ return null;
393
+ }
394
+ }
395
+
396
+
397
+ const $a24f16af03c18a4b$var$fallbackLatLng = {
398
+ lat: 40.7058254,
399
+ lng: -74.1180863
400
+ };
401
+ class $a24f16af03c18a4b$export$9a2476e65b6b92a7 extends (0, ($parcel$interopDefault($dyHF6$react))).PureComponent {
402
+ static defaultProps = {
403
+ defaultZoom: 8,
404
+ defaultLocation: {
405
+ lng: 10.74609,
406
+ lat: 59.91273
407
+ }
408
+ };
409
+ mapRef = /*#__PURE__*/ (0, ($parcel$interopDefault($dyHF6$react))).createRef();
410
+ getCenter() {
411
+ const { value: value = {} , defaultLocation: defaultLocation = {} } = this.props;
412
+ const point = {
413
+ ...$a24f16af03c18a4b$var$fallbackLatLng,
414
+ ...defaultLocation,
415
+ ...value
416
+ };
417
+ return point;
418
+ }
419
+ handlePlaceChanged = (place)=>{
420
+ if (!place.geometry?.location) return;
421
+ this.setValue(place.geometry.location);
422
+ };
423
+ handleMarkerDragEnd = (event)=>{
424
+ if (event.latLng) this.setValue(event.latLng);
425
+ };
426
+ handleMapClick = (event)=>{
427
+ if (event.latLng) this.setValue(event.latLng);
428
+ };
429
+ setValue(geoPoint) {
430
+ if (this.props.onChange) this.props.onChange(geoPoint);
431
+ }
432
+ render() {
433
+ const { api: api , defaultZoom: defaultZoom , value: value , onChange: onChange } = this.props;
434
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $b4ba0a9d820dad94$export$4ad1bae46276c5ce), {
435
+ api: api,
436
+ location: this.getCenter(),
437
+ onClick: this.handleMapClick,
438
+ defaultZoom: defaultZoom,
439
+ children: (map)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$reactjsxruntime.Fragment), {
440
+ children: [
441
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $06ee1f282087006d$export$55d7609a8f1eccd2), {
442
+ api: api,
443
+ map: map,
444
+ onChange: this.handlePlaceChanged
445
+ }),
446
+ value && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $03ff3d51ebf52598$export$e98856a975cab58e), {
447
+ api: api,
448
+ map: map,
449
+ position: value,
450
+ onMove: onChange ? this.handleMarkerDragEnd : undefined
451
+ })
452
+ ]
453
+ })
454
+ });
455
+ }
456
+ }
457
+
458
+
459
+
460
+ const $116268a9005e03a0$export$1c4ad7c095d42d37 = (0, ($parcel$interopDefault($dyHF6$styledcomponents))).img`
461
+ width: 100%;
462
+ height: auto;
463
+ vertical-align: top;
464
+ `;
465
+ const $116268a9005e03a0$export$ffa61c425f593078 = (0, ($parcel$interopDefault($dyHF6$styledcomponents))).div`
466
+ height: 40rem;
467
+ width: 50rem;
468
+ `;
469
+
470
+
471
+ let $28797477c09ece12$var$config;
472
+ function $28797477c09ece12$export$ee3fba7cd2f8c355() {
473
+ return $28797477c09ece12$var$config;
474
+ }
475
+ function $28797477c09ece12$export$a9c6c3563e9053d(newConfig) {
476
+ $28797477c09ece12$var$config = newConfig;
477
+ }
478
+
479
+
480
+ const $6c4d418093d85b71$var$getStaticImageUrl = (value, apiKey)=>{
481
+ const loc = `${value.lat},${value.lng}`;
482
+ const params = {
483
+ key: apiKey,
484
+ center: loc,
485
+ markers: loc,
486
+ zoom: 13,
487
+ scale: 2,
488
+ size: "640x300"
489
+ };
490
+ const qs = Object.keys(params).reduce((res, param)=>{
491
+ return res.concat(`${param}=${encodeURIComponent(params[param])}`);
492
+ }, []);
493
+ return `https://maps.googleapis.com/maps/api/staticmap?${qs.join("&")}`;
494
+ };
495
+ class $6c4d418093d85b71$var$GeopointInput extends (0, ($parcel$interopDefault($dyHF6$react))).PureComponent {
496
+ _geopointInputId = (0, $dyHF6$lodash.uniqueId)("GeopointInput");
497
+ constructor(props){
498
+ super(props);
499
+ this.state = {
500
+ modalOpen: false
501
+ };
502
+ }
503
+ setEditButton = (el)=>{
504
+ this.editButton = el;
505
+ };
506
+ focus() {
507
+ if (this.editButton) this.editButton.focus();
508
+ }
509
+ handleToggleModal = ()=>{
510
+ this.setState((prevState)=>({
511
+ modalOpen: !prevState.modalOpen
512
+ }));
513
+ };
514
+ handleCloseModal = ()=>{
515
+ this.setState({
516
+ modalOpen: false
517
+ });
518
+ };
519
+ handleChange = (latLng)=>{
520
+ const { schemaType: schemaType , onChange: onChange } = this.props;
521
+ onChange([
522
+ (0, $dyHF6$sanityform.setIfMissing)({
523
+ _type: schemaType.name
524
+ }),
525
+ (0, $dyHF6$sanityform.set)(latLng.lat(), [
526
+ "lat"
527
+ ]),
528
+ (0, $dyHF6$sanityform.set)(latLng.lng(), [
529
+ "lng"
530
+ ]),
531
+ ]);
532
+ };
533
+ handleClear = ()=>{
534
+ const { onChange: onChange } = this.props;
535
+ onChange((0, $dyHF6$sanityform.unset)());
536
+ };
537
+ render() {
538
+ const { value: value , readOnly: readOnly , compareValue: compareValue , geoConfig: config } = this.props;
539
+ const { modalOpen: modalOpen } = this.state;
540
+ if (!config || !config.apiKey) return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)("div", {
541
+ children: [
542
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)("p", {
543
+ children: [
544
+ "The ",
545
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("a", {
546
+ href: "https://sanity.io/docs/schema-types/geopoint-type",
547
+ children: "Geopoint type"
548
+ }),
549
+ " needs a Google Maps API key with access to:"
550
+ ]
551
+ }),
552
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)("ul", {
553
+ children: [
554
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
555
+ children: "Google Maps JavaScript API"
556
+ }),
557
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
558
+ children: "Google Places API Web Service"
559
+ }),
560
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("li", {
561
+ children: "Google Static Maps API"
562
+ })
563
+ ]
564
+ }),
565
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("p", {
566
+ children: "Please enter the API key with access to these services in your googleMapsInput plugin config."
567
+ })
568
+ ]
569
+ });
570
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$reactjsxruntime.Fragment), {
571
+ children: [
572
+ value && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanity_unstable.ChangeIndicatorCompareValueProvider), {
573
+ value: value,
574
+ compareValue: compareValue,
575
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanity_unstable.ChangeIndicator), {
576
+ compareDeep: true,
577
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $116268a9005e03a0$export$1c4ad7c095d42d37), {
578
+ src: $6c4d418093d85b71$var$getStaticImageUrl(value, config.apiKey),
579
+ alt: "Map location"
580
+ })
581
+ })
582
+ }),
583
+ !readOnly && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Box), {
584
+ marginTop: 4,
585
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$sanityui.Grid), {
586
+ columns: 2,
587
+ gap: 2,
588
+ children: [
589
+ /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Button), {
590
+ mode: "ghost",
591
+ icon: value && (0, $dyHF6$sanityicons.EditIcon),
592
+ padding: 3,
593
+ ref: this.setEditButton,
594
+ text: value ? "Edit" : "Set location",
595
+ onClick: this.handleToggleModal
596
+ }),
597
+ value && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Button), {
598
+ tone: "critical",
599
+ icon: (0, $dyHF6$sanityicons.TrashIcon),
600
+ padding: 3,
601
+ mode: "ghost",
602
+ text: "Remove",
603
+ onClick: this.handleClear
604
+ })
605
+ ]
606
+ })
607
+ }),
608
+ modalOpen && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanityui.Dialog), {
609
+ id: `${this._geopointInputId}_dialog`,
610
+ onClose: this.handleCloseModal,
611
+ header: "Place the marker on the map",
612
+ width: 1,
613
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $116268a9005e03a0$export$ffa61c425f593078), {
614
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $ffeb69a200895c22$export$a628545bcf173896), {
615
+ config: (0, $28797477c09ece12$export$ee3fba7cd2f8c355)(),
616
+ children: (api)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $a24f16af03c18a4b$export$9a2476e65b6b92a7), {
617
+ api: api,
618
+ value: value || undefined,
619
+ onChange: readOnly ? undefined : this.handleChange,
620
+ defaultLocation: config.defaultLocation,
621
+ defaultZoom: config.defaultZoom
622
+ })
623
+ })
624
+ })
625
+ })
626
+ ]
627
+ });
628
+ }
629
+ }
630
+ var $6c4d418093d85b71$export$2e2bcd8739ae039 = $6c4d418093d85b71$var$GeopointInput;
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+ class $2336979407935278$export$21b07c8f274aebd5 extends $dyHF6$react.PureComponent {
645
+ eventHandlers = {};
646
+ componentDidMount() {
647
+ const { from: from , to: to , api: api , map: map , zIndex: zIndex , onClick: onClick , color: color , arrowRef: arrowRef } = this.props;
648
+ const lineSymbol = {
649
+ path: api.SymbolPath.FORWARD_OPEN_ARROW
650
+ };
651
+ this.line = new api.Polyline({
652
+ map: map,
653
+ zIndex: zIndex,
654
+ path: [
655
+ from,
656
+ to
657
+ ],
658
+ icons: [
659
+ {
660
+ icon: lineSymbol,
661
+ offset: "50%"
662
+ }
663
+ ],
664
+ strokeOpacity: 0.55,
665
+ strokeColor: color ? color.text : "black"
666
+ });
667
+ if (onClick) this.eventHandlers.click = api.event.addListener(this.line, "click", onClick);
668
+ if (arrowRef) arrowRef.current = this.line;
669
+ }
670
+ componentDidUpdate(prevProps) {
671
+ if (!this.line) return;
672
+ const { from: from , to: to , map: map } = this.props;
673
+ if (!(0, $97ec7b8b370674b5$export$ad553d4d3a617f20)(prevProps.from, from) || !(0, $97ec7b8b370674b5$export$ad553d4d3a617f20)(prevProps.to, to)) this.line.setPath([
674
+ from,
675
+ to
676
+ ]);
677
+ if (prevProps.map !== map) this.line.setMap(map);
678
+ }
679
+ componentWillUnmount() {
680
+ if (this.line) this.line.setMap(null);
681
+ if (this.eventHandlers.click) this.eventHandlers.click.remove();
682
+ }
683
+ // eslint-disable-next-line class-methods-use-this
684
+ render() {
685
+ return null;
686
+ }
687
+ }
688
+
689
+
690
+ function $a4e9fc866b2a477c$export$f432217b31ec4a77({ diff: diff , api: api , map: map , label: label }) {
691
+ const { fromValue: from , toValue: to } = diff;
692
+ const annotation = diff.isChanged ? diff.annotation : undefined;
693
+ const userColor = (0, $dyHF6$sanity_unstable.useUserColor)(annotation ? annotation.author : null) || undefined;
694
+ const fromRef = $dyHF6$react.useRef();
695
+ const toRef = $dyHF6$react.useRef();
696
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsxs)((0, $dyHF6$reactjsxruntime.Fragment), {
697
+ children: [
698
+ from && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $03ff3d51ebf52598$export$e98856a975cab58e), {
699
+ api: api,
700
+ map: map,
701
+ position: from,
702
+ zIndex: 0,
703
+ opacity: 0.55,
704
+ markerRef: fromRef,
705
+ color: userColor
706
+ }),
707
+ from && to && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $2336979407935278$export$21b07c8f274aebd5), {
708
+ api: api,
709
+ map: map,
710
+ from: from,
711
+ to: to,
712
+ zIndex: 1,
713
+ color: userColor
714
+ }),
715
+ to && /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $03ff3d51ebf52598$export$e98856a975cab58e), {
716
+ api: api,
717
+ map: map,
718
+ position: to,
719
+ zIndex: 2,
720
+ markerRef: toRef,
721
+ label: label,
722
+ color: userColor
723
+ })
724
+ ]
725
+ });
726
+ }
727
+
728
+
729
+
730
+ const $c02dd8e49e4bafdc$export$35b4f62b8f8d707c = (0, ($parcel$interopDefault($dyHF6$styledcomponents))).div`
731
+ position: relative;
732
+ min-height: 200px;
733
+
734
+ &:empty {
735
+ background-color: var(--card-skeleton-color-from);
736
+ display: table;
737
+ width: 100%;
738
+ }
739
+
740
+ &:empty:after {
741
+ content: 'Missing/invalid data';
742
+ display: table-cell;
743
+ vertical-align: middle;
744
+ text-align: center;
745
+ position: relative;
746
+ }
747
+ `;
748
+
749
+
750
+
751
+ const $5245dd3554e263be$export$2d0695678527b4cc = ({ diff: diff , schemaType: schemaType })=>{
752
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $c02dd8e49e4bafdc$export$35b4f62b8f8d707c), {
753
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $ffeb69a200895c22$export$a628545bcf173896), {
754
+ config: (0, $28797477c09ece12$export$ee3fba7cd2f8c355)(),
755
+ children: (api)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)($5245dd3554e263be$var$GeopointDiff, {
756
+ api: api,
757
+ diff: diff,
758
+ schemaType: schemaType
759
+ })
760
+ })
761
+ });
762
+ };
763
+ function $5245dd3554e263be$var$GeopointDiff({ api: api , diff: diff }) {
764
+ const fromValue = (diff.fromValue || []).filter($5245dd3554e263be$var$hasCoordinates);
765
+ const toValue = (diff.toValue || []).filter($5245dd3554e263be$var$hasCoordinates);
766
+ if (fromValue.length === 0 && toValue.length === 0) return null;
767
+ const bounds = $5245dd3554e263be$var$getBounds(fromValue, toValue, api);
768
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $b4ba0a9d820dad94$export$4ad1bae46276c5ce), {
769
+ api: api,
770
+ location: bounds.getCenter().toJSON(),
771
+ mapTypeControl: false,
772
+ controlSize: 20,
773
+ bounds: bounds,
774
+ children: (map)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$reactjsxruntime.Fragment), {
775
+ children: diff.items.map(({ toIndex: toIndex , diff: pointDiff })=>{
776
+ if (!$5245dd3554e263be$var$isChangeDiff(pointDiff)) return null;
777
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $a4e9fc866b2a477c$export$f432217b31ec4a77), {
778
+ api: api,
779
+ map: map,
780
+ diff: pointDiff,
781
+ label: `${toIndex}`
782
+ }, toIndex);
783
+ })
784
+ })
785
+ });
786
+ }
787
+ function $5245dd3554e263be$var$isChangeDiff(diff) {
788
+ return diff.action !== "unchanged" && diff.type === "object";
789
+ }
790
+ function $5245dd3554e263be$var$hasCoordinates(point) {
791
+ return typeof point.lat === "number" && typeof point.lng === "number";
792
+ }
793
+ function $5245dd3554e263be$var$getBounds(fromValue, toValue, api) {
794
+ const bounds = new api.LatLngBounds();
795
+ const points = [
796
+ ...fromValue || [],
797
+ ...toValue || []
798
+ ];
799
+ points.forEach((point)=>bounds.extend(point));
800
+ return bounds;
801
+ }
802
+
803
+
804
+
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+ const $59d44c8f30c12966$export$6b7bf6aeccd8ac3f = ({ diff: diff , schemaType: schemaType })=>{
813
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $c02dd8e49e4bafdc$export$35b4f62b8f8d707c), {
814
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $ffeb69a200895c22$export$a628545bcf173896), {
815
+ config: (0, $28797477c09ece12$export$ee3fba7cd2f8c355)(),
816
+ children: (api)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)($59d44c8f30c12966$var$GeopointDiff, {
817
+ api: api,
818
+ diff: diff,
819
+ schemaType: schemaType
820
+ })
821
+ })
822
+ });
823
+ };
824
+ function $59d44c8f30c12966$var$GeopointDiff({ api: api , diff: diff }) {
825
+ const { fromValue: fromValue , toValue: toValue } = diff;
826
+ const annotation = (0, $dyHF6$sanity_unstable.getAnnotationAtPath)(diff, [
827
+ "lat"
828
+ ]) || (0, $dyHF6$sanity_unstable.getAnnotationAtPath)(diff, [
829
+ "lng"
830
+ ]) || (0, $dyHF6$sanity_unstable.getAnnotationAtPath)(diff, []);
831
+ const center = $59d44c8f30c12966$var$getCenter(diff, api);
832
+ const bounds = fromValue && toValue ? $59d44c8f30c12966$var$getBounds(fromValue, toValue, api) : undefined;
833
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $dyHF6$sanity_unstable.DiffTooltip), {
834
+ annotations: annotation ? [
835
+ annotation
836
+ ] : [],
837
+ description: $59d44c8f30c12966$var$getAction(diff),
838
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)("div", {
839
+ children: /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $b4ba0a9d820dad94$export$4ad1bae46276c5ce), {
840
+ api: api,
841
+ location: center,
842
+ mapTypeControl: false,
843
+ controlSize: 20,
844
+ bounds: bounds,
845
+ scrollWheel: false,
846
+ children: (map)=>/*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $a4e9fc866b2a477c$export$f432217b31ec4a77), {
847
+ api: api,
848
+ map: map,
849
+ diff: diff
850
+ })
851
+ })
852
+ })
853
+ });
854
+ }
855
+ function $59d44c8f30c12966$var$getBounds(fromValue, toValue, api) {
856
+ return new api.LatLngBounds().extend(fromValue).extend(toValue);
857
+ }
858
+ function $59d44c8f30c12966$var$getCenter(diff, api) {
859
+ const { fromValue: fromValue , toValue: toValue } = diff;
860
+ if (fromValue && toValue) return $59d44c8f30c12966$var$getBounds(fromValue, toValue, api).getCenter().toJSON();
861
+ if (fromValue) return fromValue;
862
+ if (toValue) return toValue;
863
+ throw new Error("Neither a from or a to value present");
864
+ }
865
+ function $59d44c8f30c12966$var$getAction(diff) {
866
+ const { fromValue: fromValue , toValue: toValue } = diff;
867
+ if (fromValue && toValue) return "Moved";
868
+ else if (fromValue) return "Removed";
869
+ else if (toValue) return "Added";
870
+ return "Unchanged";
871
+ }
872
+
873
+
874
+ const $329a1cedcedb1349$export$626ae7d0cf8f9143 = (0, $dyHF6$sanity.createPlugin)((config)=>{
875
+ (0, $28797477c09ece12$export$a9c6c3563e9053d)(config);
876
+ return {
877
+ name: "google-maps-input",
878
+ form: {
879
+ renderInput: (props)=>{
880
+ if ($329a1cedcedb1349$var$isGeopoint(props.schemaType)) {
881
+ const castedProps = props;
882
+ return /*#__PURE__*/ (0, $dyHF6$reactjsxruntime.jsx)((0, $6c4d418093d85b71$export$2e2bcd8739ae039), {
883
+ ...castedProps,
884
+ geoConfig: config
885
+ });
886
+ }
887
+ return undefined;
888
+ }
889
+ }
890
+ };
891
+ });
892
+ function $329a1cedcedb1349$var$isGeopoint(schemaType) {
893
+ return $329a1cedcedb1349$var$isType("geopoint", schemaType);
894
+ }
895
+ function $329a1cedcedb1349$var$isType(name, schema) {
896
+ if (schema?.name === name) return true;
897
+ else if (!schema?.name) return false;
898
+ return $329a1cedcedb1349$var$isType(name, schema?.type);
899
+ }
900
+
901
+
902
+ //# sourceMappingURL=index.js.map