@sanity/google-maps-input 2.29.1 → 2.29.4-purple-unicorn.509
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/diff/resolver.js +7 -0
- package/input/GeopointInput.js +7 -0
- package/lib/_Marker-353730d0.js +301 -0
- package/lib/_Marker-353730d0.js.map +1 -0
- package/lib/_Marker-ee551fa7.cjs +330 -0
- package/lib/_Marker-ee551fa7.cjs.map +1 -0
- package/lib/_reExport.js +19 -0
- package/lib/diff/resolver.cjs +203 -0
- package/lib/diff/resolver.cjs.map +1 -0
- package/lib/diff/resolver.js +168 -17
- package/lib/diff/resolver.js.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointArrayDiff.d.ts +4 -4
- package/lib/dts/src/diff/GeopointArrayDiff.d.ts.map +1 -0
- package/lib/dts/src/diff/GeopointArrayDiff.js +36 -0
- package/lib/dts/src/diff/GeopointArrayDiff.js.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointFieldDiff.d.ts +4 -4
- package/lib/dts/src/diff/GeopointFieldDiff.d.ts.map +1 -0
- package/lib/dts/src/diff/GeopointFieldDiff.js +51 -0
- package/lib/dts/src/diff/GeopointFieldDiff.js.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointFieldDiff.styles.d.ts +1 -1
- package/lib/dts/src/diff/GeopointFieldDiff.styles.d.ts.map +1 -0
- package/lib/dts/src/diff/GeopointFieldDiff.styles.js +20 -0
- package/lib/dts/src/diff/GeopointFieldDiff.styles.js.map +1 -0
- package/{dist/dts → lib/dts/src}/diff/GeopointMove.d.ts +12 -12
- package/lib/dts/src/diff/GeopointMove.d.ts.map +1 -0
- package/lib/dts/src/diff/GeopointMove.js +16 -0
- package/lib/dts/src/diff/GeopointMove.js.map +1 -0
- package/lib/dts/src/diff/resolver.d.ts +4 -0
- package/lib/dts/src/diff/resolver.d.ts.map +1 -0
- package/lib/dts/src/diff/resolver.js +15 -0
- package/lib/dts/src/diff/resolver.js.map +1 -0
- package/lib/dts/src/index.d.ts +13 -0
- package/lib/dts/src/index.d.ts.map +1 -0
- package/lib/dts/src/index.js +44 -0
- package/lib/dts/src/index.js.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointInput.d.ts +27 -39
- package/lib/dts/src/input/GeopointInput.d.ts.map +1 -0
- package/lib/dts/src/input/GeopointInput.js +112 -0
- package/lib/dts/src/input/GeopointInput.js.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointInput.styles.d.ts +2 -2
- package/lib/dts/src/input/GeopointInput.styles.d.ts.map +1 -0
- package/lib/dts/src/input/GeopointInput.styles.js +11 -0
- package/lib/dts/src/input/GeopointInput.styles.js.map +1 -0
- package/{dist/dts → lib/dts/src}/input/GeopointSelect.d.ts +27 -27
- package/lib/dts/src/input/GeopointSelect.d.ts.map +1 -0
- package/lib/dts/src/input/GeopointSelect.js +44 -0
- package/lib/dts/src/input/GeopointSelect.js.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/GoogleMapsLoadProxy.d.ts +13 -13
- package/lib/dts/src/loader/GoogleMapsLoadProxy.d.ts.map +1 -0
- package/lib/dts/src/loader/GoogleMapsLoadProxy.js +39 -0
- package/lib/dts/src/loader/GoogleMapsLoadProxy.js.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/LoadError.d.ts +9 -9
- package/lib/dts/src/loader/LoadError.d.ts.map +1 -0
- package/lib/dts/src/loader/LoadError.js +22 -0
- package/lib/dts/src/loader/LoadError.js.map +1 -0
- package/{dist/dts → lib/dts/src}/loader/loadGoogleMapsApi.d.ts +17 -17
- package/lib/dts/src/loader/loadGoogleMapsApi.d.ts.map +1 -0
- package/lib/dts/src/loader/loadGoogleMapsApi.js +49 -0
- package/lib/dts/src/loader/loadGoogleMapsApi.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Arrow.d.ts +28 -28
- package/lib/dts/src/map/Arrow.d.ts.map +1 -0
- package/lib/dts/src/map/Arrow.js +53 -0
- package/lib/dts/src/map/Arrow.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Map.d.ts +36 -36
- package/lib/dts/src/map/Map.d.ts.map +1 -0
- package/lib/dts/src/map/Map.js +87 -0
- package/lib/dts/src/map/Map.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Map.styles.d.ts +1 -1
- package/lib/dts/src/map/Map.styles.d.ts.map +1 -0
- package/lib/dts/src/map/Map.styles.js +10 -0
- package/lib/dts/src/map/Map.styles.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/Marker.d.ts +33 -35
- package/lib/dts/src/map/Marker.d.ts.map +1 -0
- package/lib/dts/src/map/Marker.js +94 -0
- package/lib/dts/src/map/Marker.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/SearchInput.d.ts +15 -15
- package/lib/dts/src/map/SearchInput.d.ts.map +1 -0
- package/lib/dts/src/map/SearchInput.js +37 -0
- package/lib/dts/src/map/SearchInput.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/SearchInput.styles.d.ts +1 -1
- package/lib/dts/src/map/SearchInput.styles.d.ts.map +1 -0
- package/lib/dts/src/map/SearchInput.styles.js +8 -0
- package/lib/dts/src/map/SearchInput.styles.js.map +1 -0
- package/{dist/dts → lib/dts/src}/map/util.d.ts +3 -3
- package/lib/dts/src/map/util.d.ts.map +1 -0
- package/lib/dts/src/map/util.js +8 -0
- package/lib/dts/src/map/util.js.map +1 -0
- package/lib/dts/src/schemaTypes.d.ts +18 -0
- package/lib/dts/src/schemaTypes.d.ts.map +1 -0
- package/lib/dts/src/schemaTypes.js +25 -0
- package/lib/dts/src/schemaTypes.js.map +1 -0
- package/lib/dts/src/types.d.ts +17 -0
- package/lib/dts/src/types.d.ts.map +1 -0
- package/lib/dts/src/types.js +2 -0
- package/lib/dts/src/types.js.map +1 -0
- package/lib/dts/tsconfig.tsbuildinfo +1 -0
- package/lib/input/GeopointInput.cjs +227 -0
- package/lib/input/GeopointInput.cjs.map +1 -0
- package/lib/input/GeopointInput.js +197 -190
- package/lib/input/GeopointInput.js.map +1 -0
- package/package.json +46 -12
- 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 +48 -0
- package/src/diff/resolver.ts +21 -0
- package/src/input/GeopointInput.styles.tsx +12 -0
- package/src/input/GeopointInput.tsx +219 -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 +91 -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 +130 -0
- package/src/map/SearchInput.styles.tsx +8 -0
- package/src/map/SearchInput.tsx +56 -0
- package/src/map/util.ts +14 -0
- package/src/types.ts +19 -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.map +0 -1
- package/dist/dts/diff/GeopointMove.d.ts.map +0 -1
- package/dist/dts/diff/resolver.d.ts +0 -4
- 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.map +0 -1
- 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.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.map +0 -1
- package/dist/dts/map/util.d.ts.map +0 -1
- package/dist/dts/types.d.ts +0 -14
- package/dist/dts/types.d.ts.map +0 -1
- package/lib/@types/css.d.js +0 -1
- package/lib/diff/GeopointArrayDiff.js +0 -82
- package/lib/diff/GeopointFieldDiff.js +0 -97
- package/lib/diff/GeopointFieldDiff.styles.js +0 -18
- package/lib/diff/GeopointMove.js +0 -55
- package/lib/input/GeopointInput.styles.js +0 -22
- package/lib/input/GeopointSelect.js +0 -103
- package/lib/loader/GoogleMapsLoadProxy.js +0 -70
- package/lib/loader/LoadError.js +0 -43
- package/lib/loader/loadGoogleMapsApi.js +0 -81
- package/lib/map/Arrow.js +0 -97
- package/lib/map/Map.js +0 -147
- package/lib/map/Map.styles.js +0 -18
- package/lib/map/Marker.js +0 -156
- package/lib/map/SearchInput.js +0 -77
- package/lib/map/SearchInput.styles.js +0 -18
- package/lib/map/util.js +0 -14
- package/lib/types.js +0 -5
- package/tsconfig.json +0 -20
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeopointInput.js","sources":["../../src/map/SearchInput.styles.tsx","../../src/map/SearchInput.tsx","../../src/input/GeopointSelect.tsx","../../src/input/GeopointInput.styles.tsx","../../src/input/GeopointInput.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","import * as React from 'react'\nimport {TextInput} from '@sanity/ui'\nimport {WrapperContainer} from './SearchInput.styles'\n\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","import React from 'react'\nimport {SearchInput} from '../map/SearchInput'\nimport {GoogleMap} from '../map/Map'\nimport {Marker} from '../map/Marker'\nimport {LatLng, Geopoint} from '../types'\n\nconst fallbackLatLng: LatLng = {lat: 40.7058254, lng: -74.1180863}\n\ninterface SelectProps {\n api: typeof window.google.maps\n value?: Geopoint\n onChange?: (latLng: google.maps.LatLng) => void\n defaultLocation?: LatLng\n defaultZoom?: number\n}\n\nexport class GeopointSelect extends React.PureComponent<SelectProps> {\n static defaultProps = {\n defaultZoom: 8,\n defaultLocation: {lng: 10.74609, lat: 59.91273},\n }\n\n mapRef = React.createRef<HTMLDivElement>()\n\n getCenter() {\n const {value = {}, defaultLocation = {}} = this.props\n const point: LatLng = {...fallbackLatLng, ...defaultLocation, ...value}\n return point\n }\n\n handlePlaceChanged = (place: google.maps.places.PlaceResult) => {\n if (!place.geometry) {\n return\n }\n\n this.setValue(place.geometry.location)\n }\n\n handleMarkerDragEnd = (event: google.maps.MapMouseEvent) => {\n this.setValue(event.latLng)\n }\n\n handleMapClick = (event: google.maps.MapMouseEvent) => {\n this.setValue(event.latLng)\n }\n\n setValue(geoPoint: google.maps.LatLng) {\n if (this.props.onChange) {\n this.props.onChange(geoPoint)\n }\n }\n\n render() {\n const {api, defaultZoom, value, onChange} = this.props\n return (\n <GoogleMap\n api={api}\n location={this.getCenter()}\n onClick={this.handleMapClick}\n defaultZoom={defaultZoom}\n >\n {(map) => (\n <>\n <SearchInput api={api} map={map} onChange={this.handlePlaceChanged} />\n {value && (\n <Marker\n api={api}\n map={map}\n position={value}\n onMove={onChange ? this.handleMarkerDragEnd : undefined}\n />\n )}\n </>\n )}\n </GoogleMap>\n )\n }\n}\n","import styled from 'styled-components'\n\nexport const PreviewImage = styled.img`\n width: 100%;\n height: auto;\n vertical-align: top;\n`\n\nexport const DialogInnerContainer = styled.div`\n height: 40rem;\n width: 50rem;\n`\n","import React from 'react'\nimport {uniqueId} from 'lodash'\nimport {Box, Grid, Button, Dialog} from '@sanity/ui'\nimport {TrashIcon, EditIcon} from '@sanity/icons'\n// @ts-expect-error TODO: remove the types eventually\nimport config from 'config:@sanity/google-maps-input'\nimport {\n FormFieldSet,\n ChangeIndicatorCompareValueProvider,\n ChangeIndicator,\n} from '@sanity/base/_unstable'\nimport {FormInputProps, PatchEvent, set, setIfMissing, unset} from '@sanity/base/form'\nimport {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'\nimport {Geopoint, GeopointSchemaType} from '../types'\nimport {GeopointSelect} from './GeopointSelect'\nimport {PreviewImage, DialogInnerContainer} from './GeopointInput.styles'\n\nconst getStaticImageUrl = (value) => {\n const loc = `${value.lat},${value.lng}`\n const params = {\n key: config.apiKey,\n center: loc,\n markers: loc,\n zoom: 13,\n scale: 2,\n size: '640x300',\n }\n\n const qs = Object.keys(params).reduce((res, param) => {\n return res.concat(`${param}=${encodeURIComponent(params[param])}`)\n }, [] as string[])\n\n return `https://maps.googleapis.com/maps/api/staticmap?${qs.join('&')}`\n}\n\ntype GeopointInputProps = FormInputProps<Geopoint, GeopointSchemaType>\n\n// @todo\n// interface Focusable {\n// focus: () => void\n// }\ntype Focusable = any\n\ninterface InputState {\n modalOpen: boolean\n}\n\nclass GeopointInput extends React.PureComponent<GeopointInputProps, InputState> {\n _geopointInputId = uniqueId('GeopointInput')\n\n static defaultProps = {\n validation: [],\n }\n\n editButton: Focusable | undefined\n\n constructor(props) {\n super(props)\n\n this.state = {\n modalOpen: false,\n }\n }\n\n setEditButton = (el: Focusable) => {\n this.editButton = el\n }\n\n focus() {\n if (this.editButton) {\n this.editButton.focus()\n }\n }\n\n handleFocus = (event) => {\n this.props.onFocus(event)\n }\n\n handleBlur = () => {\n this.props.onBlur?.()\n }\n\n handleToggleModal = () => {\n const {onFocus, onBlur} = this.props\n this.setState(\n (prevState) => ({modalOpen: !prevState.modalOpen}),\n () => {\n if (this.state.modalOpen) {\n onFocus(['$'])\n } else {\n onBlur?.()\n }\n }\n )\n }\n\n handleCloseModal = () => {\n this.setState({modalOpen: false})\n }\n\n handleChange = (latLng: google.maps.LatLng) => {\n const {type, onChange} = this.props\n onChange(\n PatchEvent.from([\n setIfMissing({\n _type: type.name,\n }),\n set(latLng.lat(), ['lat']),\n set(latLng.lng(), ['lng']),\n ])\n )\n }\n\n handleClear = () => {\n const {onChange} = this.props\n onChange(PatchEvent.from(unset()))\n }\n\n render() {\n const {value, compareValue, readOnly, type, validation, level, presence} = this.props\n const {modalOpen} = this.state\n\n if (!config || !config.apiKey) {\n return (\n <div>\n <p>\n The <a href=\"https://sanity.io/docs/schema-types/geopoint-type\">Geopoint type</a> needs\n a Google Maps API key with access to:\n </p>\n <ul>\n <li>Google Maps JavaScript API</li>\n <li>Google Places API Web Service</li>\n <li>Google Static Maps API</li>\n </ul>\n <p>\n Please enter the API key with access to these services in\n <code style={{whiteSpace: 'nowrap'}}>\n `<project-root>/config/@sanity/google-maps-input.json`\n </code>\n </p>\n </div>\n )\n }\n\n return (\n <FormFieldSet\n level={level}\n title={type.title}\n description={type.description}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n __unstable_presence={presence}\n __unstable_changeIndicator={false}\n validation={validation}\n >\n <div>\n {value && (\n <ChangeIndicatorCompareValueProvider value={value} compareValue={compareValue}>\n <ChangeIndicator compareDeep>\n <PreviewImage src={getStaticImageUrl(value)} alt=\"Map location\" />\n </ChangeIndicator>\n </ChangeIndicatorCompareValueProvider>\n )}\n\n {!readOnly && (\n <Box marginTop={4}>\n <Grid columns={2} gap={2}>\n <Button\n mode=\"ghost\"\n icon={value && EditIcon}\n padding={3}\n ref={this.setEditButton}\n text={value ? 'Edit' : 'Set location'}\n onClick={this.handleToggleModal}\n />\n\n {value && (\n <Button\n tone=\"critical\"\n icon={TrashIcon}\n padding={3}\n mode=\"ghost\"\n text={'Remove'}\n onClick={this.handleClear}\n />\n )}\n </Grid>\n </Box>\n )}\n\n {modalOpen && (\n <Dialog\n id={`${this._geopointInputId}_dialog`}\n onClose={this.handleCloseModal}\n header=\"Place the marker on the map\"\n width={1}\n >\n <DialogInnerContainer>\n <GoogleMapsLoadProxy>\n {(api) => (\n <GeopointSelect\n api={api}\n value={value || undefined}\n onChange={readOnly ? undefined : this.handleChange}\n defaultLocation={config.defaultLocation}\n defaultZoom={config.defaultZoom}\n />\n )}\n </GoogleMapsLoadProxy>\n </DialogInnerContainer>\n </Dialog>\n )}\n </div>\n </FormFieldSet>\n )\n }\n}\n\nexport default GeopointInput\n"],"names":["React"],"mappings":";;;;;;;;;;;;AAEO,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA,CAAA;;;;;CAKzC;;ACGY,MAAA,WAAY,SAAQ,KAAK,CAAC,aAAoB,CAAA;AACzD,IAAA,cAAc,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAA;AACpD,IAAA,YAAY,CAA6C;IAEzD,YAAY,GAAG,MAAK;AAClB,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;YACtB,OAAM;AACP,SAAA;AAED,QAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAA;AAEjD,QAAA,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;YAC/B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,KA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AG,EACR,KAAK,EAAE,KAAK,IAAI,SAAS,EACzB,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,YAAY,EAClD,eAAe,EAAE,MAAM,CAAC,eAAe,EACvC,WAAW,EAAE,MAAM,CAAC,WAAW,EAAA,CAC/B,CACH,CACmB,CACD,CAChB,CACV,CACG,CACO,EAChB;KACF;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/google-maps-input",
|
|
3
|
-
"version": "2.29.
|
|
3
|
+
"version": "2.29.4-purple-unicorn.509+183505a0b3",
|
|
4
4
|
"description": "Sanity plugin providing input handlers for geo-related input types using Google Maps",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"
|
|
5
|
+
"main": "lib/input/GeopointInput.cjs",
|
|
6
|
+
"module": "lib/input/GeopointInput.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./input/GeopointInput": {
|
|
9
|
+
"source": "./src/input/GeopointInput.tsx",
|
|
10
|
+
"require": "./lib/input/GeopointInput.cjs",
|
|
11
|
+
"default": "./lib/input/GeopointInput.js"
|
|
12
|
+
},
|
|
13
|
+
"./diff/resolver": {
|
|
14
|
+
"source": "./src/diff/resolver.ts",
|
|
15
|
+
"require": "./lib/diff/resolver.cjs",
|
|
16
|
+
"default": "./lib/diff/resolver.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"types": "./lib/dts/src/input/GeopointInput.d.ts",
|
|
20
|
+
"//": "the typesVersion config below is a workaround for TypeScript's lack of support for package exports",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"*": {
|
|
23
|
+
"input/GeopointInput": [
|
|
24
|
+
"./lib/dts/src/input/GeopointInput.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"schema": [
|
|
27
|
+
"./lib/dts/src/schema.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"diff/resolver": [
|
|
30
|
+
"./lib/dts/src/diff/resolver.d.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
7
34
|
"author": "Sanity.io <hello@sanity.io>",
|
|
8
35
|
"license": "MIT",
|
|
9
36
|
"scripts": {
|
|
10
|
-
"
|
|
37
|
+
"build": "../../../bin/pkg-utils bundle",
|
|
38
|
+
"clean": "rimraf lib",
|
|
39
|
+
"_exports:check": "../../../bin/pkg-utils exports-check",
|
|
40
|
+
"exports:clean": "../../../bin/pkg-utils exports-clean",
|
|
41
|
+
"exports:generate": "../../../bin/pkg-utils exports-generate",
|
|
42
|
+
"postbuild": "run-s exports:generate",
|
|
43
|
+
"watch": "../../../bin/pkg-utils bundle --watch"
|
|
11
44
|
},
|
|
12
45
|
"keywords": [
|
|
13
46
|
"sanity",
|
|
@@ -19,17 +52,18 @@
|
|
|
19
52
|
"sanity-plugin"
|
|
20
53
|
],
|
|
21
54
|
"dependencies": {
|
|
22
|
-
"@sanity/
|
|
23
|
-
"@sanity/
|
|
24
|
-
"@sanity/
|
|
25
|
-
"
|
|
26
|
-
"lodash": "^4.17.15",
|
|
55
|
+
"@sanity/icons": "^1.2.8",
|
|
56
|
+
"@sanity/types": "2.29.4-purple-unicorn.509+183505a0b3",
|
|
57
|
+
"@sanity/ui": "^0.37.8",
|
|
58
|
+
"lodash": "^4.17.21",
|
|
27
59
|
"rxjs": "^6.5.3"
|
|
28
60
|
},
|
|
29
61
|
"devDependencies": {
|
|
30
|
-
"@sanity/base": "2.29.
|
|
62
|
+
"@sanity/base": "2.29.4-purple-unicorn.509+183505a0b3",
|
|
31
63
|
"@types/googlemaps": "^3.43.0",
|
|
32
|
-
"
|
|
64
|
+
"react": "17.0.2",
|
|
65
|
+
"rimraf": "^3.0.2",
|
|
66
|
+
"styled-components": "^5.2.0"
|
|
33
67
|
},
|
|
34
68
|
"peerDependencies": {
|
|
35
69
|
"@sanity/base": "^2.0.0",
|
|
@@ -46,5 +80,5 @@
|
|
|
46
80
|
"url": "https://github.com/sanity-io/sanity/issues"
|
|
47
81
|
},
|
|
48
82
|
"homepage": "https://www.sanity.io/",
|
|
49
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "183505a0b3ea400181bff4f4370c146374b58068"
|
|
50
84
|
}
|
|
@@ -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/base/_unstable'
|
|
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/base/_unstable'
|
|
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,48 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {useUserColor, ObjectDiff} from '@sanity/base/_unstable'
|
|
3
|
+
import {Marker} from '../map/Marker'
|
|
4
|
+
import {Arrow} from '../map/Arrow'
|
|
5
|
+
import {Geopoint} from '../types'
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
api: typeof window.google.maps
|
|
9
|
+
map: google.maps.Map
|
|
10
|
+
diff: ObjectDiff<Geopoint>
|
|
11
|
+
label?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function GeopointMove({diff, api, map, label}: Props) {
|
|
15
|
+
const {fromValue: from, toValue: to} = diff
|
|
16
|
+
const annotation = diff.isChanged ? diff.annotation : undefined
|
|
17
|
+
const userColor = useUserColor(annotation ? annotation.author : null) || undefined
|
|
18
|
+
const fromRef = React.useRef<google.maps.Marker>()
|
|
19
|
+
const toRef = React.useRef<google.maps.Marker>()
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<>
|
|
23
|
+
{from && (
|
|
24
|
+
<Marker
|
|
25
|
+
api={api}
|
|
26
|
+
map={map}
|
|
27
|
+
position={from}
|
|
28
|
+
zIndex={0}
|
|
29
|
+
opacity={0.55}
|
|
30
|
+
markerRef={fromRef}
|
|
31
|
+
color={userColor}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
{from && to && <Arrow api={api} map={map} from={from} to={to} zIndex={1} color={userColor} />}
|
|
35
|
+
{to && (
|
|
36
|
+
<Marker
|
|
37
|
+
api={api}
|
|
38
|
+
map={map}
|
|
39
|
+
position={to}
|
|
40
|
+
zIndex={2}
|
|
41
|
+
markerRef={toRef}
|
|
42
|
+
label={label}
|
|
43
|
+
color={userColor}
|
|
44
|
+
/>
|
|
45
|
+
)}
|
|
46
|
+
</>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {DiffComponentResolver} from '@sanity/base/_unstable'
|
|
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
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {uniqueId} from 'lodash'
|
|
3
|
+
import {Box, Grid, Button, Dialog} from '@sanity/ui'
|
|
4
|
+
import {TrashIcon, EditIcon} from '@sanity/icons'
|
|
5
|
+
// @ts-expect-error TODO: remove the types eventually
|
|
6
|
+
import config from 'config:@sanity/google-maps-input'
|
|
7
|
+
import {
|
|
8
|
+
FormFieldSet,
|
|
9
|
+
ChangeIndicatorCompareValueProvider,
|
|
10
|
+
ChangeIndicator,
|
|
11
|
+
} from '@sanity/base/_unstable'
|
|
12
|
+
import {FormInputProps, PatchEvent, set, setIfMissing, unset} from '@sanity/base/form'
|
|
13
|
+
import {GoogleMapsLoadProxy} from '../loader/GoogleMapsLoadProxy'
|
|
14
|
+
import {Geopoint, GeopointSchemaType} from '../types'
|
|
15
|
+
import {GeopointSelect} from './GeopointSelect'
|
|
16
|
+
import {PreviewImage, DialogInnerContainer} from './GeopointInput.styles'
|
|
17
|
+
|
|
18
|
+
const getStaticImageUrl = (value) => {
|
|
19
|
+
const loc = `${value.lat},${value.lng}`
|
|
20
|
+
const params = {
|
|
21
|
+
key: config.apiKey,
|
|
22
|
+
center: loc,
|
|
23
|
+
markers: loc,
|
|
24
|
+
zoom: 13,
|
|
25
|
+
scale: 2,
|
|
26
|
+
size: '640x300',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const qs = Object.keys(params).reduce((res, param) => {
|
|
30
|
+
return res.concat(`${param}=${encodeURIComponent(params[param])}`)
|
|
31
|
+
}, [] as string[])
|
|
32
|
+
|
|
33
|
+
return `https://maps.googleapis.com/maps/api/staticmap?${qs.join('&')}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type GeopointInputProps = FormInputProps<Geopoint, GeopointSchemaType>
|
|
37
|
+
|
|
38
|
+
// @todo
|
|
39
|
+
// interface Focusable {
|
|
40
|
+
// focus: () => void
|
|
41
|
+
// }
|
|
42
|
+
type Focusable = any
|
|
43
|
+
|
|
44
|
+
interface InputState {
|
|
45
|
+
modalOpen: boolean
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class GeopointInput extends React.PureComponent<GeopointInputProps, InputState> {
|
|
49
|
+
_geopointInputId = uniqueId('GeopointInput')
|
|
50
|
+
|
|
51
|
+
static defaultProps = {
|
|
52
|
+
validation: [],
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
editButton: Focusable | undefined
|
|
56
|
+
|
|
57
|
+
constructor(props) {
|
|
58
|
+
super(props)
|
|
59
|
+
|
|
60
|
+
this.state = {
|
|
61
|
+
modalOpen: false,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setEditButton = (el: Focusable) => {
|
|
66
|
+
this.editButton = el
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
focus() {
|
|
70
|
+
if (this.editButton) {
|
|
71
|
+
this.editButton.focus()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
handleFocus = (event) => {
|
|
76
|
+
this.props.onFocus(event)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
handleBlur = () => {
|
|
80
|
+
this.props.onBlur?.()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
handleToggleModal = () => {
|
|
84
|
+
const {onFocus, onBlur} = this.props
|
|
85
|
+
this.setState(
|
|
86
|
+
(prevState) => ({modalOpen: !prevState.modalOpen}),
|
|
87
|
+
() => {
|
|
88
|
+
if (this.state.modalOpen) {
|
|
89
|
+
onFocus(['$'])
|
|
90
|
+
} else {
|
|
91
|
+
onBlur?.()
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
handleCloseModal = () => {
|
|
98
|
+
this.setState({modalOpen: false})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
handleChange = (latLng: google.maps.LatLng) => {
|
|
102
|
+
const {type, onChange} = this.props
|
|
103
|
+
onChange(
|
|
104
|
+
PatchEvent.from([
|
|
105
|
+
setIfMissing({
|
|
106
|
+
_type: type.name,
|
|
107
|
+
}),
|
|
108
|
+
set(latLng.lat(), ['lat']),
|
|
109
|
+
set(latLng.lng(), ['lng']),
|
|
110
|
+
])
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
handleClear = () => {
|
|
115
|
+
const {onChange} = this.props
|
|
116
|
+
onChange(PatchEvent.from(unset()))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
render() {
|
|
120
|
+
const {value, compareValue, readOnly, type, validation, level, presence} = this.props
|
|
121
|
+
const {modalOpen} = this.state
|
|
122
|
+
|
|
123
|
+
if (!config || !config.apiKey) {
|
|
124
|
+
return (
|
|
125
|
+
<div>
|
|
126
|
+
<p>
|
|
127
|
+
The <a href="https://sanity.io/docs/schema-types/geopoint-type">Geopoint type</a> needs
|
|
128
|
+
a Google Maps API key with access to:
|
|
129
|
+
</p>
|
|
130
|
+
<ul>
|
|
131
|
+
<li>Google Maps JavaScript API</li>
|
|
132
|
+
<li>Google Places API Web Service</li>
|
|
133
|
+
<li>Google Static Maps API</li>
|
|
134
|
+
</ul>
|
|
135
|
+
<p>
|
|
136
|
+
Please enter the API key with access to these services in
|
|
137
|
+
<code style={{whiteSpace: 'nowrap'}}>
|
|
138
|
+
`<project-root>/config/@sanity/google-maps-input.json`
|
|
139
|
+
</code>
|
|
140
|
+
</p>
|
|
141
|
+
</div>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<FormFieldSet
|
|
147
|
+
level={level}
|
|
148
|
+
title={type.title}
|
|
149
|
+
description={type.description}
|
|
150
|
+
onFocus={this.handleFocus}
|
|
151
|
+
onBlur={this.handleBlur}
|
|
152
|
+
__unstable_presence={presence}
|
|
153
|
+
__unstable_changeIndicator={false}
|
|
154
|
+
validation={validation}
|
|
155
|
+
>
|
|
156
|
+
<div>
|
|
157
|
+
{value && (
|
|
158
|
+
<ChangeIndicatorCompareValueProvider value={value} compareValue={compareValue}>
|
|
159
|
+
<ChangeIndicator compareDeep>
|
|
160
|
+
<PreviewImage src={getStaticImageUrl(value)} alt="Map location" />
|
|
161
|
+
</ChangeIndicator>
|
|
162
|
+
</ChangeIndicatorCompareValueProvider>
|
|
163
|
+
)}
|
|
164
|
+
|
|
165
|
+
{!readOnly && (
|
|
166
|
+
<Box marginTop={4}>
|
|
167
|
+
<Grid columns={2} gap={2}>
|
|
168
|
+
<Button
|
|
169
|
+
mode="ghost"
|
|
170
|
+
icon={value && EditIcon}
|
|
171
|
+
padding={3}
|
|
172
|
+
ref={this.setEditButton}
|
|
173
|
+
text={value ? 'Edit' : 'Set location'}
|
|
174
|
+
onClick={this.handleToggleModal}
|
|
175
|
+
/>
|
|
176
|
+
|
|
177
|
+
{value && (
|
|
178
|
+
<Button
|
|
179
|
+
tone="critical"
|
|
180
|
+
icon={TrashIcon}
|
|
181
|
+
padding={3}
|
|
182
|
+
mode="ghost"
|
|
183
|
+
text={'Remove'}
|
|
184
|
+
onClick={this.handleClear}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
</Grid>
|
|
188
|
+
</Box>
|
|
189
|
+
)}
|
|
190
|
+
|
|
191
|
+
{modalOpen && (
|
|
192
|
+
<Dialog
|
|
193
|
+
id={`${this._geopointInputId}_dialog`}
|
|
194
|
+
onClose={this.handleCloseModal}
|
|
195
|
+
header="Place the marker on the map"
|
|
196
|
+
width={1}
|
|
197
|
+
>
|
|
198
|
+
<DialogInnerContainer>
|
|
199
|
+
<GoogleMapsLoadProxy>
|
|
200
|
+
{(api) => (
|
|
201
|
+
<GeopointSelect
|
|
202
|
+
api={api}
|
|
203
|
+
value={value || undefined}
|
|
204
|
+
onChange={readOnly ? undefined : this.handleChange}
|
|
205
|
+
defaultLocation={config.defaultLocation}
|
|
206
|
+
defaultZoom={config.defaultZoom}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
209
|
+
</GoogleMapsLoadProxy>
|
|
210
|
+
</DialogInnerContainer>
|
|
211
|
+
</Dialog>
|
|
212
|
+
)}
|
|
213
|
+
</div>
|
|
214
|
+
</FormFieldSet>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default GeopointInput
|