@sanity/google-maps-input 2.30.2-shopify.2 → 3.0.0-studio-v3.0

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