@sanity/google-maps-input 3.0.0-v3-studio.6 → 3.0.0-v3-studio.8

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