@sanity/google-maps-input 2.35.1 → 2.36.0-v2-studio.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +11 -1
- package/{dist/dts → dts}/diff/GeopointArrayDiff.d.ts +1 -2
- package/{dist/dts → dts}/diff/GeopointFieldDiff.d.ts +1 -2
- package/dts/diff/GeopointFieldDiff.styles.d.ts +1 -0
- package/{dist/dts → dts}/diff/GeopointMove.d.ts +0 -1
- package/{dist/dts → dts}/diff/resolver.d.ts +0 -1
- package/{dist/dts → dts}/input/GeopointInput.d.ts +26 -2
- package/dts/input/GeopointInput.styles.d.ts +2 -0
- package/dts/input/GeopointSelect.d.ts +52 -0
- package/{dist/dts → dts}/loader/GoogleMapsLoadProxy.d.ts +0 -1
- package/{dist/dts → dts}/loader/LoadError.d.ts +1 -2
- package/{dist/dts → dts}/loader/loadGoogleMapsApi.d.ts +1 -2
- package/{dist/dts → dts}/map/Arrow.d.ts +2 -1
- package/{dist/dts → dts}/map/Map.d.ts +2 -1
- package/dts/map/Map.styles.d.ts +1 -0
- package/{dist/dts → dts}/map/Marker.d.ts +3 -1
- package/{dist/dts → dts}/map/SearchInput.d.ts +2 -1
- package/dts/map/SearchInput.styles.d.ts +1 -0
- package/{dist/dts → dts}/map/util.d.ts +0 -1
- package/{dist/dts → dts}/types.d.ts +1 -2
- package/lib/@types/css.d.js +2 -1
- package/lib/@types/css.d.js.map +1 -0
- package/lib/diff/GeopointArrayDiff.js +2 -1
- package/lib/diff/GeopointArrayDiff.js.map +1 -0
- package/lib/diff/GeopointFieldDiff.js +2 -1
- package/lib/diff/GeopointFieldDiff.js.map +1 -0
- package/lib/diff/GeopointFieldDiff.styles.js +2 -1
- package/lib/diff/GeopointFieldDiff.styles.js.map +1 -0
- package/lib/diff/GeopointMove.js +2 -1
- package/lib/diff/GeopointMove.js.map +1 -0
- package/lib/diff/resolver.js +2 -1
- package/lib/diff/resolver.js.map +1 -0
- package/lib/input/GeopointInput.js +4 -3
- package/lib/input/GeopointInput.js.map +1 -0
- package/lib/input/GeopointInput.styles.js +2 -1
- package/lib/input/GeopointInput.styles.js.map +1 -0
- package/lib/input/GeopointSelect.js +2 -1
- package/lib/input/GeopointSelect.js.map +1 -0
- package/lib/loader/GoogleMapsLoadProxy.js +2 -1
- package/lib/loader/GoogleMapsLoadProxy.js.map +1 -0
- package/lib/loader/LoadError.js +2 -1
- package/lib/loader/LoadError.js.map +1 -0
- package/lib/loader/loadGoogleMapsApi.js +2 -1
- package/lib/loader/loadGoogleMapsApi.js.map +1 -0
- package/lib/map/Arrow.js +2 -1
- package/lib/map/Arrow.js.map +1 -0
- package/lib/map/Map.js +2 -1
- package/lib/map/Map.js.map +1 -0
- package/lib/map/Map.styles.js +2 -1
- package/lib/map/Map.styles.js.map +1 -0
- package/lib/map/Marker.js +2 -1
- package/lib/map/Marker.js.map +1 -0
- package/lib/map/SearchInput.js +2 -1
- package/lib/map/SearchInput.js.map +1 -0
- package/lib/map/SearchInput.styles.js +2 -1
- package/lib/map/SearchInput.styles.js.map +1 -0
- package/lib/map/util.js +2 -1
- package/lib/map/util.js.map +1 -0
- package/lib/types.js +1 -4
- package/lib/types.js.map +1 -0
- package/package.json +53 -22
- package/src/@types/css.d.ts +4 -0
- package/src/diff/GeopointArrayDiff.tsx +83 -0
- package/src/diff/GeopointFieldDiff.styles.tsx +20 -0
- package/src/diff/GeopointFieldDiff.tsx +94 -0
- package/src/diff/GeopointMove.tsx +49 -0
- package/src/diff/resolver.ts +21 -0
- package/src/input/GeopointInput.styles.tsx +12 -0
- package/src/input/GeopointInput.tsx +231 -0
- package/src/input/GeopointSelect.tsx +78 -0
- package/src/loader/GoogleMapsLoadProxy.tsx +49 -0
- package/src/loader/LoadError.tsx +44 -0
- package/src/loader/loadGoogleMapsApi.ts +93 -0
- package/src/map/Arrow.tsx +76 -0
- package/src/map/Map.styles.tsx +10 -0
- package/src/map/Map.tsx +125 -0
- package/src/map/Marker.tsx +132 -0
- package/src/map/SearchInput.styles.tsx +8 -0
- package/src/map/SearchInput.tsx +55 -0
- package/src/map/util.ts +14 -0
- package/src/types.ts +16 -0
- package/.depcheckignore.json +0 -3
- package/dist/dts/diff/GeopointArrayDiff.d.ts.map +0 -1
- package/dist/dts/diff/GeopointFieldDiff.d.ts.map +0 -1
- package/dist/dts/diff/GeopointFieldDiff.styles.d.ts +0 -2
- package/dist/dts/diff/GeopointFieldDiff.styles.d.ts.map +0 -1
- package/dist/dts/diff/GeopointMove.d.ts.map +0 -1
- package/dist/dts/diff/resolver.d.ts.map +0 -1
- package/dist/dts/input/GeopointInput.d.ts.map +0 -1
- package/dist/dts/input/GeopointInput.styles.d.ts +0 -3
- package/dist/dts/input/GeopointInput.styles.d.ts.map +0 -1
- package/dist/dts/input/GeopointSelect.d.ts +0 -28
- package/dist/dts/input/GeopointSelect.d.ts.map +0 -1
- package/dist/dts/loader/GoogleMapsLoadProxy.d.ts.map +0 -1
- package/dist/dts/loader/LoadError.d.ts.map +0 -1
- package/dist/dts/loader/loadGoogleMapsApi.d.ts.map +0 -1
- package/dist/dts/map/Arrow.d.ts.map +0 -1
- package/dist/dts/map/Map.d.ts.map +0 -1
- package/dist/dts/map/Map.styles.d.ts +0 -2
- package/dist/dts/map/Map.styles.d.ts.map +0 -1
- package/dist/dts/map/Marker.d.ts.map +0 -1
- package/dist/dts/map/SearchInput.d.ts.map +0 -1
- package/dist/dts/map/SearchInput.styles.d.ts +0 -2
- package/dist/dts/map/SearchInput.styles.d.ts.map +0 -1
- package/dist/dts/map/util.d.ts.map +0 -1
- package/dist/dts/types.d.ts.map +0 -1
- package/tsconfig.json +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Marker.js","names":["markerPath","Marker","React","PureComponent","componentDidMount","props","position","api","map","onMove","zIndex","opacity","label","markerRef","color","GMarker","icon","path","fillOpacity","fillColor","background","strokeColor","border","strokeWeight","anchor","Point","labelOrigin","marker","draggable","Boolean","current","attachMoveHandler","attachClickHandler","componentDidUpdate","prevProps","latLngAreEqual","setPosition","setLabel","setZIndex","setOpacity","setMap","componentWillUnmount","eventHandlers","move","remove","event","addListener","onClick","click","render"],"sources":["../../src/map/Marker.tsx"],"sourcesContent":["import * as React from 'react'\nimport {LatLng} from '../types'\nimport {latLngAreEqual} from './util'\n\nconst markerPath =\n 'M 3.052 3.7 C 1.56 5.293 0.626 7.612 0.663 9.793 C 0.738 14.352 2.793 16.077 6.078 22.351 C 7.263 25.111 8.497 28.032 9.672 32.871 C 9.835 33.584 9.994 34.246 10.069 34.305 C 10.143 34.362 10.301 33.697 10.465 32.983 C 11.639 28.145 12.875 25.226 14.059 22.466 C 17.344 16.192 19.398 14.466 19.474 9.908 C 19.511 7.727 18.574 5.405 17.083 3.814 C 15.379 1.994 12.809 0.649 10.069 0.593 C 7.328 0.536 4.756 1.882 3.052 3.7 Z'\n\ninterface Props {\n api: typeof window.google.maps\n map: google.maps.Map\n onMove?: (event: google.maps.MapMouseEvent) => void\n onClick?: (event: google.maps.MapMouseEvent) => void\n onMouseOver?: (event: google.maps.MapMouseEvent) => void\n onMouseOut?: (event: google.maps.MapMouseEvent) => void\n position: LatLng | google.maps.LatLng\n zIndex?: number\n opacity?: number\n label?: string\n markerRef?: React.MutableRefObject<google.maps.Marker | undefined>\n color?: {background: string; border: string; text: string}\n}\n\nexport class Marker extends React.PureComponent<Props> {\n marker: google.maps.Marker | undefined\n\n eventHandlers: {\n move?: google.maps.MapsEventListener\n click?: google.maps.MapsEventListener\n } = {}\n\n componentDidMount() {\n const {position, api, map, onMove, zIndex, opacity, label, markerRef, color} = this.props\n const {Marker: GMarker} = api\n\n let icon: google.maps.ReadonlySymbol | undefined\n if (color) {\n icon = {\n path: markerPath,\n fillOpacity: 1,\n fillColor: color.background,\n strokeColor: color.border,\n strokeWeight: 2,\n anchor: new api.Point(10, 35),\n labelOrigin: new api.Point(10, 11),\n }\n }\n\n this.marker = new GMarker({\n draggable: Boolean(onMove),\n position,\n map,\n zIndex,\n opacity,\n label,\n icon,\n })\n\n if (markerRef) {\n markerRef.current = this.marker\n }\n\n this.attachMoveHandler()\n this.attachClickHandler()\n }\n\n componentDidUpdate(prevProps: Props) {\n if (!this.marker) {\n return\n }\n\n const {position, onMove, label, zIndex, opacity, map} = this.props\n\n if (prevProps.onMove !== onMove) {\n this.attachMoveHandler()\n }\n\n if (!latLngAreEqual(prevProps.position, position)) {\n this.marker.setPosition(position)\n }\n\n if (prevProps.label !== label) {\n this.marker.setLabel(label || null)\n }\n\n if (prevProps.zIndex !== zIndex) {\n this.marker.setZIndex(zIndex || null)\n }\n\n if (prevProps.opacity !== opacity) {\n this.marker.setOpacity(opacity || null)\n }\n\n if (prevProps.map !== map) {\n this.marker.setMap(map)\n }\n }\n\n componentWillUnmount() {\n if (this.eventHandlers.move) {\n this.eventHandlers.move.remove()\n }\n\n if (this.marker) {\n this.marker.setMap(null)\n }\n }\n\n attachMoveHandler() {\n const {api, onMove} = this.props\n if (this.eventHandlers.move) {\n this.eventHandlers.move.remove()\n }\n if (this.marker && onMove) {\n this.eventHandlers.move = api.event.addListener(this.marker, 'dragend', onMove)\n }\n }\n\n attachClickHandler() {\n const {api, onClick} = this.props\n if (this.eventHandlers.click) {\n this.eventHandlers.click.remove()\n }\n if (this.marker && onClick) {\n this.eventHandlers.click = api.event.addListener(this.marker, 'click', onClick)\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n render() {\n return null\n }\n}\n"],"mappings":";;;;;;AAAA;AAEA;AAAqC;AAAA;AAAA;AAErC,IAAMA,UAAU,GACd,yaAAya;AAiBpa,MAAMC,MAAM,SAASC,KAAK,CAACC,aAAa,CAAQ;EAAA;IAAA;IAAA;IAAA,uCAMjD,CAAC,CAAC;EAAA;EAENC,iBAAiB,GAAG;IAClB,kBAA+E,IAAI,CAACC,KAAK;MAAlFC,QAAQ,eAARA,QAAQ;MAAEC,GAAG,eAAHA,GAAG;MAAEC,GAAG,eAA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IlB,MAAM,EAAE;MACzB,IAAI,CAACiC,aAAa,CAACC,IAAI,GAAGpC,GAAG,CAACsC,KAAK,CAACC,WAAW,CAAC,IAAI,CAACnB,MAAM,EAAE,SAAS,EAAElB,MAAM,CAAC;IACjF;EACF;EAEAuB,kBAAkB,GAAG;IACnB,mBAAuB,IAAI,CAAC3B,KAAK;MAA1BE,GAAG,gBAAHA,GAAG;MAAEwC,OAAO,gBAAPA,OAAO;IACnB,IAAI,IAAI,CAACL,aAAa,CAACM,KAAK,EAAE;MAC5B,IAAI,CAACN,aAAa,CAACM,KAAK,CAACJ,MAAM,EAAE;IACnC;IACA,IAAI,IAAI,CAACjB,MAAM,IAAIoB,OAAO,EAAE;MAC1B,IAAI,CAACL,aAAa,CAACM,KAAK,GAAGzC,GAAG,CAACsC,KAAK,CAACC,WAAW,CAAC,IAAI,CAACnB,MAAM,EAAE,OAAO,EAAEoB,OAAO,CAAC;IACjF;EACF;;EAEA;EACAE,MAAM,GAAG;IACP,OAAO,IAAI;EACb;AACF;AAAC"}
|
package/lib/map/SearchInput.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchInput.js","names":["SearchInput","React","PureComponent","createRef","autoComplete","props","onChange","getPlace","searchInputRef","current","value","componentDidMount","input","api","map","Circle","places","event","searchBounds","center","getCenter","radius","getBounds","Autocomplete","bounds","types","addListener","handleChange","render"],"sources":["../../src/map/SearchInput.tsx"],"sourcesContent":["import * as React from 'react'\nimport {TextInput} from '@sanity/ui'\nimport {WrapperContainer} from './SearchInput.styles'\ninterface Props {\n api: typeof window.google.maps\n map: google.maps.Map\n onChange: (result: google.maps.places.PlaceResult) => void\n}\n\nexport class SearchInput extends React.PureComponent<Props> {\n searchInputRef = React.createRef<HTMLInputElement>()\n autoComplete: google.maps.places.Autocomplete | undefined\n\n handleChange = () => {\n if (!this.autoComplete) {\n return\n }\n\n this.props.onChange(this.autoComplete.getPlace())\n\n if (this.searchInputRef.current) {\n this.searchInputRef.current.value = ''\n }\n }\n\n componentDidMount() {\n const input = this.searchInputRef.current\n if (!input) {\n return\n }\n\n const {api, map} = this.props\n const {Circle, places, event} = api\n const searchBounds = new Circle({center: map.getCenter(), radius: 100}).getBounds()\n this.autoComplete = new places.Autocomplete(input, {\n bounds: searchBounds,\n types: [], // return all kinds of places\n })\n\n event.addListener(this.autoComplete, 'place_changed', this.handleChange)\n }\n\n render() {\n return (\n <WrapperContainer>\n <TextInput\n name=\"place\"\n ref={this.searchInputRef}\n placeholder=\"Search for place or address\"\n padding={4}\n />\n </WrapperContainer>\n )\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAAqD;AAAA;AAAA;AAO9C,MAAMA,WAAW,SAASC,KAAK,CAACC,aAAa,CAAQ;EAAA;IAAA;IAAA,qDACzCD,KAAK,CAACE,SAAS,EAAoB;IAAA;IAAA,sCAGrC,MAAM;MACnB,IAAI,CAAC,IAAI,CAACC,YAAY,EAAE;QACtB;MACF;MAEA,IAAI,CAACC,KAAK,CAACC,QAAQ,CAAC,IAAI,CAACF,YAAY,CAACG,QAAQ,EAAE,CAAC;MAEjD,IAAI,IAAI,CAACC,cAAc,CAACC,OAAO,EAAE;QAC/B,IAAI,CAACD,cAAc,CAACC,OAAO,CAACC,KAAK,GAAG,EAAE;MACxC;IACF,CAAC;EAAA;EAEDC,iBAAiB,GAAG;IAClB,IAAMC,KAAK,GAAG,IAAI,CAACJ,cAAc,CAACC,OAAO;IACzC,IAAI,CAACG,KAAK,EAAE;MACV;IACF;IAEA,kBAAmB,IAAI,CAACP,KAAK;MAAtBQ,GAAG,eAAHA,GAAG;MAAEC,GAAG,eAAHA,GAAG;IACf,IAAOC,MAAM,GAAmBF,GAAG,CAA5BE,MAAM;MAAEC,MAAM,GAAWH,GAAG,CAApBG,MAAM;MAAEC,KAAK,GAAIJ,GAAG,CAAZI,KAAK;IAC5B,IAAMC,YAAY,GAAG,IAAIH,MAAM,CAAC;MAACI,MAAM,EAAEL,GAAG,CAACM,SAAS,EAAE;MAAEC,MAAM,EAAE;IAAG,CAAC,CAAC,CAACC,SAAS,EAAE;IACnF,IAAI,CAAClB,YAAY,GAAG,IAAIY,MAAM,CAACO,YAAY,CAACX,KAAK,EAAE;MACjDY,MAAM,EAAEN,YAAY;MACpBO,KAAK,EAAE,EAAE,CAAE;IACb,CAAC,CAAC;;IAEFR,KAAK,CAACS,WAAW,CAAC,IAAI,CAACtB,YAAY,EAAE,eAAe,EAAE,IAAI,CAACuB,YAAY,CAAC;EAC1E;EAEAC,MAAM,GAAG;IACP,oBACE,oBAAC,6BAAgB,qBACf,oBAAC,aAAS;MACR,IAAI,EAAC,OAAO;MACZ,GAAG,EAAE,IAAI,CAACpB,cAAe;MACzB,WAAW,EAAC,6BAA6B;MACzC,OAAO,EAAE;IAAE,EACX,CACe;EAEvB;AACF;AAAC"}
|
|
@@ -9,4 +9,5 @@ var _templateObject;
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
11
11
|
var WrapperContainer = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n right: 10px;\n top: 10px;\n width: 220px;\n"])));
|
|
12
|
-
exports.WrapperContainer = WrapperContainer;
|
|
12
|
+
exports.WrapperContainer = WrapperContainer;
|
|
13
|
+
//# sourceMappingURL=SearchInput.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchInput.styles.js","names":["WrapperContainer","styled","div"],"sources":["../../src/map/SearchInput.styles.tsx"],"sourcesContent":["import styled from 'styled-components'\n\nexport const WrapperContainer = styled.div`\n position: absolute;\n right: 10px;\n top: 10px;\n width: 220px;\n`\n"],"mappings":";;;;;;AAAA;AAAsC;AAAA;AAAA;AAE/B,IAAMA,gBAAgB,GAAGC,yBAAM,CAACC,GAAG,6IAKzC;AAAA"}
|
package/lib/map/util.js
CHANGED
|
@@ -10,4 +10,5 @@ function latLngAreEqual(latLng1, latLng2) {
|
|
|
10
10
|
var lat2 = typeof latLng2.lat === 'function' ? latLng2.lat() : latLng2.lat;
|
|
11
11
|
var lng2 = typeof latLng2.lng === 'function' ? latLng2.lng() : latLng2.lng;
|
|
12
12
|
return lat1 === lat2 && lng1 === lng2;
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","names":["latLngAreEqual","latLng1","latLng2","lat1","lat","lng1","lng","lat2","lng2"],"sources":["../../src/map/util.ts"],"sourcesContent":["import {LatLng} from '../types'\n\nexport function latLngAreEqual(\n latLng1: LatLng | google.maps.LatLng,\n latLng2: LatLng | google.maps.LatLng\n) {\n const lat1 = typeof latLng1.lat === 'function' ? latLng1.lat() : latLng1.lat\n const lng1 = typeof latLng1.lng === 'function' ? latLng1.lng() : latLng1.lng\n\n const lat2 = typeof latLng2.lat === 'function' ? latLng2.lat() : latLng2.lat\n const lng2 = typeof latLng2.lng === 'function' ? latLng2.lng() : latLng2.lng\n\n return lat1 === lat2 && lng1 === lng2\n}\n"],"mappings":";;;;;;AAEO,SAASA,cAAc,CAC5BC,OAAoC,EACpCC,OAAoC,EACpC;EACA,IAAMC,IAAI,GAAG,OAAOF,OAAO,CAACG,GAAG,KAAK,UAAU,GAAGH,OAAO,CAACG,GAAG,EAAE,GAAGH,OAAO,CAACG,GAAG;EAC5E,IAAMC,IAAI,GAAG,OAAOJ,OAAO,CAACK,GAAG,KAAK,UAAU,GAAGL,OAAO,CAACK,GAAG,EAAE,GAAGL,OAAO,CAACK,GAAG;EAE5E,IAAMC,IAAI,GAAG,OAAOL,OAAO,CAACE,GAAG,KAAK,UAAU,GAAGF,OAAO,CAACE,GAAG,EAAE,GAAGF,OAAO,CAACE,GAAG;EAC5E,IAAMI,IAAI,GAAG,OAAON,OAAO,CAACI,GAAG,KAAK,UAAU,GAAGJ,OAAO,CAACI,GAAG,EAAE,GAAGJ,OAAO,CAACI,GAAG;EAE5E,OAAOH,IAAI,KAAKI,IAAI,IAAIF,IAAI,KAAKG,IAAI;AACvC"}
|
package/lib/types.js
CHANGED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import {ObjectSchemaType} from '@sanity/field/diff'\n\nexport interface LatLng {\n lat: number\n lng: number\n}\n\nexport interface Geopoint {\n _type: 'geopoint'\n _key?: string\n lat: number\n lng: number\n alt?: number\n}\n\nexport type GeopointSchemaType = ObjectSchemaType<Geopoint>\n"],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/google-maps-input",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.36.0-v2-studio.1",
|
|
4
4
|
"description": "Sanity plugin providing input handlers for geo-related input types using Google Maps",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "./dist/dts",
|
|
7
|
-
"author": "Sanity.io <hello@sanity.io>",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"clean": "rimraf lib dest"
|
|
11
|
-
},
|
|
12
5
|
"keywords": [
|
|
13
6
|
"sanity",
|
|
14
7
|
"cms",
|
|
@@ -18,8 +11,36 @@
|
|
|
18
11
|
"google-maps-input",
|
|
19
12
|
"sanity-plugin"
|
|
20
13
|
],
|
|
14
|
+
"homepage": "https://www.sanity.io/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/sanity-io/google-maps-input/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git@github.com:sanity-io/google-maps-input.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
24
|
+
"main": "lib/input/GeopointInput.js",
|
|
25
|
+
"types": "./dts/input/GeopointInput.d.ts",
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"dts",
|
|
29
|
+
"src",
|
|
30
|
+
"sanity.json",
|
|
31
|
+
"config.dist.json"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"prebuild": "npm run clean",
|
|
35
|
+
"build": "tsc --declaration --emitDeclarationOnly && sanipack build",
|
|
36
|
+
"clean": "rimraf lib",
|
|
37
|
+
"lint": "eslint .",
|
|
38
|
+
"prepare": "husky install",
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
|
+
"watch": "sanipack build --watch"
|
|
41
|
+
},
|
|
21
42
|
"dependencies": {
|
|
22
|
-
"@sanity/field": "2.35.
|
|
43
|
+
"@sanity/field": "2.35.2",
|
|
23
44
|
"@sanity/icons": "^1.3.4",
|
|
24
45
|
"@sanity/types": "2.35.0",
|
|
25
46
|
"@sanity/ui": "^0.37.22",
|
|
@@ -27,24 +48,34 @@
|
|
|
27
48
|
"rxjs": "^6.5.3"
|
|
28
49
|
},
|
|
29
50
|
"devDependencies": {
|
|
30
|
-
"@
|
|
51
|
+
"@commitlint/cli": "^17.3.0",
|
|
52
|
+
"@commitlint/config-conventional": "^17.3.0",
|
|
53
|
+
"@sanity/base": "2.35.2",
|
|
54
|
+
"@sanity/semantic-release-preset": "^2.0.1",
|
|
31
55
|
"@types/googlemaps": "^3.43.0",
|
|
32
|
-
"
|
|
56
|
+
"@types/styled-components": "5.1.26",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
58
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
59
|
+
"eslint": "^8.27.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-config-sanity": "^6.0.0",
|
|
62
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
+
"eslint-plugin-react": "^7.31.10",
|
|
64
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
65
|
+
"husky": "^8.0.1",
|
|
66
|
+
"lint-staged": "^13.0.3",
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
|
+
"prettier-plugin-packagejson": "^2.3.0",
|
|
69
|
+
"prop-types": "^15.8.1",
|
|
70
|
+
"react": "17.0.1",
|
|
71
|
+
"rimraf": "^2.7.1",
|
|
72
|
+
"sanipack": "^2.1.0",
|
|
73
|
+
"styled-components": "^5.2.0"
|
|
33
74
|
},
|
|
34
75
|
"peerDependencies": {
|
|
35
76
|
"@sanity/base": "^2.0.0",
|
|
36
77
|
"react": "^16.9 || ^17",
|
|
37
78
|
"react-dom": "^16.9 || ^17",
|
|
38
79
|
"styled-components": "^5.2.0"
|
|
39
|
-
}
|
|
40
|
-
"repository": {
|
|
41
|
-
"type": "git",
|
|
42
|
-
"url": "git+https://github.com/sanity-io/sanity.git",
|
|
43
|
-
"directory": "packages/@sanity/google-maps-input"
|
|
44
|
-
},
|
|
45
|
-
"bugs": {
|
|
46
|
-
"url": "https://github.com/sanity-io/sanity/issues"
|
|
47
|
-
},
|
|
48
|
-
"homepage": "https://www.sanity.io/",
|
|
49
|
-
"gitHead": "25de30f0d2076592dec64e492e07eb7e2853252b"
|
|
80
|
+
}
|
|
50
81
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
ArrayDiff,
|
|
4
|
+
ObjectDiff,
|
|
5
|
+
Diff,
|
|
6
|
+
DiffProps as GenericDiffProps,
|
|
7
|
+
DiffComponent,
|
|
8
|
+
} from '@sanity/field/diff'
|
|
9
|
+
import {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'
|
|
10
|
+
import {GoogleMap} from '../map/Map'
|
|
11
|
+
import {Geopoint} from '../types'
|
|
12
|
+
import {GeopointMove} from './GeopointMove'
|
|
13
|
+
import {RootContainer} from './GeopointFieldDiff.styles'
|
|
14
|
+
|
|
15
|
+
export type DiffProps = GenericDiffProps<ArrayDiff<Geopoint>>
|
|
16
|
+
|
|
17
|
+
export const GeopointArrayDiff: DiffComponent<ArrayDiff<Geopoint>> = ({diff, schemaType}) => {
|
|
18
|
+
return (
|
|
19
|
+
<RootContainer>
|
|
20
|
+
<GoogleMapsLoadProxy>
|
|
21
|
+
{(api) => <GeopointDiff api={api} diff={diff} schemaType={schemaType} />}
|
|
22
|
+
</GoogleMapsLoadProxy>
|
|
23
|
+
</RootContainer>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function GeopointDiff({api, diff}: DiffProps & {api: typeof window.google.maps}) {
|
|
28
|
+
const fromValue = (diff.fromValue || []).filter(hasCoordinates)
|
|
29
|
+
const toValue = (diff.toValue || []).filter(hasCoordinates)
|
|
30
|
+
if (fromValue.length === 0 && toValue.length === 0) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const bounds = getBounds(fromValue, toValue, api)
|
|
35
|
+
return (
|
|
36
|
+
<GoogleMap
|
|
37
|
+
api={api}
|
|
38
|
+
location={bounds.getCenter().toJSON()}
|
|
39
|
+
mapTypeControl={false}
|
|
40
|
+
controlSize={20}
|
|
41
|
+
bounds={bounds}
|
|
42
|
+
>
|
|
43
|
+
{(map) => (
|
|
44
|
+
<>
|
|
45
|
+
{diff.items.map(({toIndex, diff: pointDiff}) => {
|
|
46
|
+
if (!isChangeDiff(pointDiff)) {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<GeopointMove
|
|
52
|
+
key={toIndex}
|
|
53
|
+
api={api}
|
|
54
|
+
map={map}
|
|
55
|
+
diff={pointDiff}
|
|
56
|
+
label={`${toIndex}`}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
})}
|
|
60
|
+
</>
|
|
61
|
+
)}
|
|
62
|
+
</GoogleMap>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isChangeDiff(diff: Diff): diff is ObjectDiff<Geopoint> {
|
|
67
|
+
return diff.action !== 'unchanged' && diff.type === 'object'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function hasCoordinates(point: Partial<Geopoint>): point is Geopoint {
|
|
71
|
+
return typeof point.lat === 'number' && typeof point.lng === 'number'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getBounds(
|
|
75
|
+
fromValue: google.maps.LatLngLiteral[] | null | undefined,
|
|
76
|
+
toValue: google.maps.LatLngLiteral[] | null | undefined,
|
|
77
|
+
api: typeof window.google.maps
|
|
78
|
+
): google.maps.LatLngBounds {
|
|
79
|
+
const bounds = new api.LatLngBounds()
|
|
80
|
+
const points = [...(fromValue || []), ...(toValue || [])]
|
|
81
|
+
points.forEach((point) => bounds.extend(point))
|
|
82
|
+
return bounds
|
|
83
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
export const RootContainer = styled.div`
|
|
4
|
+
position: relative;
|
|
5
|
+
min-height: 200px;
|
|
6
|
+
|
|
7
|
+
&:empty {
|
|
8
|
+
background-color: var(--card-skeleton-color-from);
|
|
9
|
+
display: table;
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&:empty:after {
|
|
14
|
+
content: 'Missing/invalid data';
|
|
15
|
+
display: table-cell;
|
|
16
|
+
vertical-align: middle;
|
|
17
|
+
text-align: center;
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
`
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
DiffComponent,
|
|
4
|
+
ObjectDiff,
|
|
5
|
+
DiffProps as GenericDiffProps,
|
|
6
|
+
DiffTooltip,
|
|
7
|
+
getAnnotationAtPath,
|
|
8
|
+
} from '@sanity/field/diff'
|
|
9
|
+
import {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'
|
|
10
|
+
import {GoogleMap} from '../map/Map'
|
|
11
|
+
import {Geopoint} from '../types'
|
|
12
|
+
import {GeopointMove} from './GeopointMove'
|
|
13
|
+
import {RootContainer} from './GeopointFieldDiff.styles'
|
|
14
|
+
|
|
15
|
+
export type DiffProps = GenericDiffProps<ObjectDiff<Geopoint>>
|
|
16
|
+
|
|
17
|
+
export const GeopointFieldDiff: DiffComponent<ObjectDiff<Geopoint>> = ({diff, schemaType}) => {
|
|
18
|
+
return (
|
|
19
|
+
<RootContainer>
|
|
20
|
+
<GoogleMapsLoadProxy>
|
|
21
|
+
{(api) => <GeopointDiff api={api} diff={diff} schemaType={schemaType} />}
|
|
22
|
+
</GoogleMapsLoadProxy>
|
|
23
|
+
</RootContainer>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function GeopointDiff({api, diff}: DiffProps & {api: typeof window.google.maps}) {
|
|
28
|
+
const {fromValue, toValue} = diff
|
|
29
|
+
const annotation =
|
|
30
|
+
getAnnotationAtPath(diff, ['lat']) ||
|
|
31
|
+
getAnnotationAtPath(diff, ['lng']) ||
|
|
32
|
+
getAnnotationAtPath(diff, [])
|
|
33
|
+
|
|
34
|
+
const center = getCenter(diff, api)
|
|
35
|
+
const bounds = fromValue && toValue ? getBounds(fromValue, toValue, api) : undefined
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<DiffTooltip annotations={annotation ? [annotation] : []} description={getAction(diff)}>
|
|
39
|
+
<div>
|
|
40
|
+
<GoogleMap
|
|
41
|
+
api={api}
|
|
42
|
+
location={center}
|
|
43
|
+
mapTypeControl={false}
|
|
44
|
+
controlSize={20}
|
|
45
|
+
bounds={bounds}
|
|
46
|
+
scrollWheel={false}
|
|
47
|
+
>
|
|
48
|
+
{(map) => <GeopointMove api={api} map={map} diff={diff} />}
|
|
49
|
+
</GoogleMap>
|
|
50
|
+
</div>
|
|
51
|
+
</DiffTooltip>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getBounds(
|
|
56
|
+
fromValue: google.maps.LatLngLiteral,
|
|
57
|
+
toValue: google.maps.LatLngLiteral,
|
|
58
|
+
api: typeof window.google.maps
|
|
59
|
+
): google.maps.LatLngBounds {
|
|
60
|
+
return new api.LatLngBounds().extend(fromValue).extend(toValue)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getCenter(
|
|
64
|
+
diff: DiffProps['diff'],
|
|
65
|
+
api: typeof window.google.maps
|
|
66
|
+
): google.maps.LatLngLiteral {
|
|
67
|
+
const {fromValue, toValue} = diff
|
|
68
|
+
if (fromValue && toValue) {
|
|
69
|
+
return getBounds(fromValue, toValue, api).getCenter().toJSON()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (fromValue) {
|
|
73
|
+
return fromValue
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (toValue) {
|
|
77
|
+
return toValue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
throw new Error('Neither a from or a to value present')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getAction(diff: ObjectDiff<Geopoint>) {
|
|
84
|
+
const {fromValue, toValue} = diff
|
|
85
|
+
if (fromValue && toValue) {
|
|
86
|
+
return 'Moved'
|
|
87
|
+
} else if (fromValue) {
|
|
88
|
+
return 'Removed'
|
|
89
|
+
} else if (toValue) {
|
|
90
|
+
return 'Added'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return 'Unchanged'
|
|
94
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {useUserColor} from '@sanity/base/user-color'
|
|
3
|
+
import {ObjectDiff} from '@sanity/field/diff'
|
|
4
|
+
import {Marker} from '../map/Marker'
|
|
5
|
+
import {Arrow} from '../map/Arrow'
|
|
6
|
+
import {Geopoint} from '../types'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
api: typeof window.google.maps
|
|
10
|
+
map: google.maps.Map
|
|
11
|
+
diff: ObjectDiff<Geopoint>
|
|
12
|
+
label?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function GeopointMove({diff, api, map, label}: Props) {
|
|
16
|
+
const {fromValue: from, toValue: to} = diff
|
|
17
|
+
const annotation = diff.isChanged ? diff.annotation : undefined
|
|
18
|
+
const userColor = useUserColor(annotation ? annotation.author : null) || undefined
|
|
19
|
+
const fromRef = React.useRef<google.maps.Marker>()
|
|
20
|
+
const toRef = React.useRef<google.maps.Marker>()
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
{from && (
|
|
25
|
+
<Marker
|
|
26
|
+
api={api}
|
|
27
|
+
map={map}
|
|
28
|
+
position={from}
|
|
29
|
+
zIndex={0}
|
|
30
|
+
opacity={0.55}
|
|
31
|
+
markerRef={fromRef}
|
|
32
|
+
color={userColor}
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
{from && to && <Arrow api={api} map={map} from={from} to={to} zIndex={1} color={userColor} />}
|
|
36
|
+
{to && (
|
|
37
|
+
<Marker
|
|
38
|
+
api={api}
|
|
39
|
+
map={map}
|
|
40
|
+
position={to}
|
|
41
|
+
zIndex={2}
|
|
42
|
+
markerRef={toRef}
|
|
43
|
+
label={label}
|
|
44
|
+
color={userColor}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
47
|
+
</>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {DiffComponentResolver} from '@sanity/field/diff'
|
|
2
|
+
import {GeopointFieldDiff} from './GeopointFieldDiff'
|
|
3
|
+
import {GeopointArrayDiff} from './GeopointArrayDiff'
|
|
4
|
+
|
|
5
|
+
const diffResolver: DiffComponentResolver = function diffResolver({schemaType}) {
|
|
6
|
+
if (schemaType.name === 'geopoint') {
|
|
7
|
+
return GeopointFieldDiff
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (
|
|
11
|
+
schemaType.jsonType === 'array' &&
|
|
12
|
+
schemaType.of.length === 1 &&
|
|
13
|
+
schemaType.of[0].name === 'geopoint'
|
|
14
|
+
) {
|
|
15
|
+
return GeopointArrayDiff
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default diffResolver
|