@aws-amplify/ui-react-geo 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,72 @@
1
- import{__rest as r}from"tslib";import e,{useRef as t,useEffect as o}from"react";import i from"maplibre-gl";import{createAmplifyGeocoder as n}from"maplibre-gl-js-amplify";import{useMap as l,useControl as m}from"react-map-gl";const p={maplibregl:i,marker:{color:"#3FB1CE"},popup:!0,showResultMarkers:{color:"#3FB1CE"},showResultsWhileTyping:!0},s="geocoder-container",a=e=>{var{position:t="top-right"}=e,o=r(e,["position"]);return m((()=>n(o)),{position:t}),null},c=r=>{const i=t(!1);return o((()=>{i.current||(n(r).addTo(`#${s}`),i.current=!0)}),[r]),e.createElement("div",{id:s})},u=r=>{const{current:t}=l();return t?e.createElement(a,Object.assign({},p,r)):e.createElement(c,Object.assign({},p,r))};export{u as LocationSearch};
1
+ import React, { useRef, useEffect } from 'react';
2
+ import maplibregl from 'maplibre-gl';
3
+ import { createAmplifyGeocoder } from 'maplibre-gl-js-amplify';
4
+ import { useMap, useControl } from 'react-map-gl';
5
+ import { useSetUserAgent } from '@aws-amplify/ui-react-core';
6
+ import { VERSION } from '../../version.mjs';
7
+
8
+ const LOCATION_SEARCH_OPTIONS = {
9
+ maplibregl,
10
+ marker: { color: '#3FB1CE' },
11
+ popup: true,
12
+ showResultMarkers: { color: '#3FB1CE' },
13
+ showResultsWhileTyping: true,
14
+ };
15
+ const LOCATION_SEARCH_CONTAINER = 'geocoder-container';
16
+ const LocationSearchControl = ({ position = 'top-right', ...props }) => {
17
+ useControl(() => createAmplifyGeocoder(props), {
18
+ position,
19
+ });
20
+ return null;
21
+ };
22
+ const LocationSearchStandalone = (props) => {
23
+ const hasMounted = useRef(false);
24
+ useEffect(() => {
25
+ if (!hasMounted.current) {
26
+ createAmplifyGeocoder(props).addTo(`#${LOCATION_SEARCH_CONTAINER}`);
27
+ hasMounted.current = true;
28
+ }
29
+ }, [props]);
30
+ return React.createElement("div", { id: LOCATION_SEARCH_CONTAINER });
31
+ };
32
+ /**
33
+ * The `<LocationSearch>` component provides location search.
34
+ *
35
+ * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#location-search)
36
+ *
37
+ * @example
38
+ * // Used as a map control:
39
+ * function App() {
40
+ * return (
41
+ * <MapView>
42
+ * <LocationSearch />
43
+ * </MapView>
44
+ * );
45
+ * }
46
+ *
47
+ * @example
48
+ * // Used as a standalone component:
49
+ * function App() {
50
+ * return <LocationSearch />;
51
+ * }
52
+ */
53
+ const LocationSearch = (props) => {
54
+ const { current: map } = useMap();
55
+ useSetUserAgent({
56
+ componentName: 'LocationSearch',
57
+ packageName: 'react-geo',
58
+ version: VERSION,
59
+ });
60
+ /**
61
+ * This logic determines whether the LocationSearch exists as part of a Map component or if it is a standalone component.
62
+ * The `useControl` hook inside `LocationSearchControl` from `react-map-gl` makes it easy to add a control to a map,
63
+ * but throws an error if that map doesn't exist. If the map doesn't exist, the LocationSearch is mounted to a container
64
+ * upon rendering inside the `LocationSearchStandalone`.
65
+ */
66
+ if (map) {
67
+ return React.createElement(LocationSearchControl, { ...LOCATION_SEARCH_OPTIONS, ...props });
68
+ }
69
+ return React.createElement(LocationSearchStandalone, { ...LOCATION_SEARCH_OPTIONS, ...props });
70
+ };
71
+
72
+ export { LocationSearch };
@@ -1 +1,62 @@
1
- import{__rest as e,__awaiter as i}from"tslib";import o,{forwardRef as r,useMemo as t,useState as l,useEffect as a}from"react";import n from"maplibre-gl";import{AmplifyMapLibreRequest as m}from"maplibre-gl-js-amplify";import s from"react-map-gl";import{Amplify as p,Auth as v}from"aws-amplify";const f=r(((r,f)=>{var c,{mapLib:d,mapStyle:u,style:g}=r,y=e(r,["mapLib","mapStyle","style"]);const b=p.configure(),w=t((()=>{var e,i,o,r;return null!==(r=null!==(i=null===(e=b.geo)||void 0===e?void 0:e.amazon_location_service)&&void 0!==i?i:null===(o=b.geo)||void 0===o?void 0:o.AmazonLocationService)&&void 0!==r?r:{}}),[b]),[h,L]=l(),S=t((()=>Object.assign({height:"100vh",position:"relative",width:"100vw"},g)),[g]);return a((()=>{i(void 0,void 0,void 0,(function*(){const e=yield v.currentUserCredentials();if(e){const{region:i}=w,{transformRequest:o}=new m(e,i);L((()=>o))}}))}),[w]),h?o.createElement(s,Object.assign({},y,{mapLib:null!=d?d:n,mapStyle:null!=u?u:null===(c=w.maps)||void 0===c?void 0:c.default,ref:f,style:S,transformRequest:h,fog:y.fog,terrain:y.terrain})):null}));f.displayName="MapView";export{f as MapView};
1
+ import { Amplify } from 'aws-amplify';
2
+ import { fetchAuthSession } from 'aws-amplify/auth';
3
+ import React, { forwardRef, useMemo, useState, useEffect } from 'react';
4
+ import maplibregl from 'maplibre-gl';
5
+ import { AmplifyMapLibreRequest } from 'maplibre-gl-js-amplify';
6
+ import ReactMapGL from 'react-map-gl';
7
+
8
+ /**
9
+ * The `MapView` component uses [react-map-gl](https://visgl.github.io/react-map-gl/) and
10
+ * [maplibre-gl-js](https://visgl.github.io/react-map-gl/) to provide an interactive map using
11
+ * [Amplify Geo APIs](https://docs.amplify.aws/lib/geo/getting-started/q/platform/js/) powered by
12
+ * [Amazon Location Service](https://aws.amazon.com/location/). Since `MapView` is a wrapper of the
13
+ * [react-map-gl default Map](https://visgl.github.io/react-map-gl/docs/api-reference/map/), it accepts the same
14
+ * properties except `transformRequest` which is set by Amplify.
15
+ *
16
+ * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#mapview)
17
+ *
18
+ * @example
19
+ * // Basic usage of MapView:
20
+ * function App() {
21
+ * return <MapView />
22
+ * }
23
+ */
24
+ const MapView = forwardRef(({ mapLib, mapStyle, style, ...props }, ref) => {
25
+ const geoConfig = useMemo(() => {
26
+ return (Amplify.getConfig().Geo?.LocationService ??
27
+ {});
28
+ }, []);
29
+ const [transformRequest, setTransformRequest] = useState();
30
+ const styleProps = useMemo(() => ({
31
+ height: '100vh',
32
+ position: 'relative',
33
+ width: '100vw',
34
+ ...style,
35
+ }), [style]);
36
+ /**
37
+ * The transformRequest is a callback used by react-map-gl before it makes a request for an external URL. It signs
38
+ * the request with AWS Sigv4 Auth, provided valid credentials, and is how we integrate react-map-gl with Amplify Geo
39
+ * and Amazon Location Service. Once the transformRequest is created, we render the map.
40
+ */
41
+ useEffect(() => {
42
+ (async () => {
43
+ const { credentials } = await fetchAuthSession();
44
+ if (credentials && geoConfig) {
45
+ const { region } = geoConfig;
46
+ const { transformRequest: amplifyTransformRequest } = new AmplifyMapLibreRequest(credentials, region);
47
+ setTransformRequest(() => amplifyTransformRequest);
48
+ }
49
+ })();
50
+ }, [geoConfig]);
51
+ /**
52
+ * The mapLib property is used by react-map-gl@v7 to override the underlying map library. The default library is
53
+ * mapbox-gl-js, which uses its own copyrighted license. We override the map library with the BSD-licensed
54
+ * maplibre-gl-js.
55
+ *
56
+ * The default mapStyle we use is just the map ID provided by aws-exports.
57
+ */
58
+ return transformRequest ? (React.createElement(ReactMapGL, { ...props, mapLib: mapLib ?? maplibregl, mapStyle: mapStyle ?? geoConfig?.maps?.default, ref: ref, style: styleProps, transformRequest: transformRequest, fog: props.fog, terrain: props.terrain })) : null;
59
+ });
60
+ MapView.displayName = 'MapView';
61
+
62
+ export { MapView };
@@ -1 +1,2 @@
1
- export{MapView}from"./components/MapView/MapView.mjs";export{LocationSearch}from"./components/LocationSearch/LocationSearch.mjs";
1
+ export { MapView } from './components/MapView/MapView.mjs';
2
+ export { LocationSearch } from './components/LocationSearch/LocationSearch.mjs';
@@ -0,0 +1,3 @@
1
+ const VERSION = '1.0.2';
2
+
3
+ export { VERSION };
package/dist/index.js CHANGED
@@ -1 +1,140 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react"),r=require("maplibre-gl"),i=require("maplibre-gl-js-amplify"),o=require("react-map-gl"),a=require("aws-amplify");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=l(t),s=l(r),u=l(o);const c=t.forwardRef(((r,o)=>{var l,{mapLib:c,mapStyle:p,style:d}=r,f=e.__rest(r,["mapLib","mapStyle","style"]);const m=a.Amplify.configure(),v=t.useMemo((()=>{var e,t,r,i;return null!==(i=null!==(t=null===(e=m.geo)||void 0===e?void 0:e.amazon_location_service)&&void 0!==t?t:null===(r=m.geo)||void 0===r?void 0:r.AmazonLocationService)&&void 0!==i?i:{}}),[m]),[g,y]=t.useState(),b=t.useMemo((()=>Object.assign({height:"100vh",position:"relative",width:"100vw"},d)),[d]);return t.useEffect((()=>{e.__awaiter(void 0,void 0,void 0,(function*(){const e=yield a.Auth.currentUserCredentials();if(e){const{region:t}=v,{transformRequest:r}=new i.AmplifyMapLibreRequest(e,t);y((()=>r))}}))}),[v]),g?n.default.createElement(u.default,Object.assign({},f,{mapLib:null!=c?c:s.default,mapStyle:null!=p?p:null===(l=v.maps)||void 0===l?void 0:l.default,ref:o,style:b,transformRequest:g,fog:f.fog,terrain:f.terrain})):null}));c.displayName="MapView";const p={maplibregl:s.default,marker:{color:"#3FB1CE"},popup:!0,showResultMarkers:{color:"#3FB1CE"},showResultsWhileTyping:!0},d="geocoder-container",f=t=>{var{position:r="top-right"}=t,a=e.__rest(t,["position"]);return o.useControl((()=>i.createAmplifyGeocoder(a)),{position:r}),null},m=e=>{const r=t.useRef(!1);return t.useEffect((()=>{r.current||(i.createAmplifyGeocoder(e).addTo(`#${d}`),r.current=!0)}),[e]),n.default.createElement("div",{id:d})};exports.LocationSearch=e=>{const{current:t}=o.useMap();return t?n.default.createElement(f,Object.assign({},p,e)):n.default.createElement(m,Object.assign({},p,e))},exports.MapView=c;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var awsAmplify = require('aws-amplify');
6
+ var auth = require('aws-amplify/auth');
7
+ var React = require('react');
8
+ var maplibregl = require('maplibre-gl');
9
+ var maplibreGlJsAmplify = require('maplibre-gl-js-amplify');
10
+ var ReactMapGL = require('react-map-gl');
11
+ var uiReactCore = require('@aws-amplify/ui-react-core');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
16
+ var maplibregl__default = /*#__PURE__*/_interopDefaultLegacy(maplibregl);
17
+ var ReactMapGL__default = /*#__PURE__*/_interopDefaultLegacy(ReactMapGL);
18
+
19
+ /**
20
+ * The `MapView` component uses [react-map-gl](https://visgl.github.io/react-map-gl/) and
21
+ * [maplibre-gl-js](https://visgl.github.io/react-map-gl/) to provide an interactive map using
22
+ * [Amplify Geo APIs](https://docs.amplify.aws/lib/geo/getting-started/q/platform/js/) powered by
23
+ * [Amazon Location Service](https://aws.amazon.com/location/). Since `MapView` is a wrapper of the
24
+ * [react-map-gl default Map](https://visgl.github.io/react-map-gl/docs/api-reference/map/), it accepts the same
25
+ * properties except `transformRequest` which is set by Amplify.
26
+ *
27
+ * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#mapview)
28
+ *
29
+ * @example
30
+ * // Basic usage of MapView:
31
+ * function App() {
32
+ * return <MapView />
33
+ * }
34
+ */
35
+ const MapView = React.forwardRef(({ mapLib, mapStyle, style, ...props }, ref) => {
36
+ const geoConfig = React.useMemo(() => {
37
+ return (awsAmplify.Amplify.getConfig().Geo?.LocationService ??
38
+ {});
39
+ }, []);
40
+ const [transformRequest, setTransformRequest] = React.useState();
41
+ const styleProps = React.useMemo(() => ({
42
+ height: '100vh',
43
+ position: 'relative',
44
+ width: '100vw',
45
+ ...style,
46
+ }), [style]);
47
+ /**
48
+ * The transformRequest is a callback used by react-map-gl before it makes a request for an external URL. It signs
49
+ * the request with AWS Sigv4 Auth, provided valid credentials, and is how we integrate react-map-gl with Amplify Geo
50
+ * and Amazon Location Service. Once the transformRequest is created, we render the map.
51
+ */
52
+ React.useEffect(() => {
53
+ (async () => {
54
+ const { credentials } = await auth.fetchAuthSession();
55
+ if (credentials && geoConfig) {
56
+ const { region } = geoConfig;
57
+ const { transformRequest: amplifyTransformRequest } = new maplibreGlJsAmplify.AmplifyMapLibreRequest(credentials, region);
58
+ setTransformRequest(() => amplifyTransformRequest);
59
+ }
60
+ })();
61
+ }, [geoConfig]);
62
+ /**
63
+ * The mapLib property is used by react-map-gl@v7 to override the underlying map library. The default library is
64
+ * mapbox-gl-js, which uses its own copyrighted license. We override the map library with the BSD-licensed
65
+ * maplibre-gl-js.
66
+ *
67
+ * The default mapStyle we use is just the map ID provided by aws-exports.
68
+ */
69
+ return transformRequest ? (React__default["default"].createElement(ReactMapGL__default["default"], { ...props, mapLib: mapLib ?? maplibregl__default["default"], mapStyle: mapStyle ?? geoConfig?.maps?.default, ref: ref, style: styleProps, transformRequest: transformRequest, fog: props.fog, terrain: props.terrain })) : null;
70
+ });
71
+ MapView.displayName = 'MapView';
72
+
73
+ const VERSION = '1.0.2';
74
+
75
+ const LOCATION_SEARCH_OPTIONS = {
76
+ maplibregl: maplibregl__default["default"],
77
+ marker: { color: '#3FB1CE' },
78
+ popup: true,
79
+ showResultMarkers: { color: '#3FB1CE' },
80
+ showResultsWhileTyping: true,
81
+ };
82
+ const LOCATION_SEARCH_CONTAINER = 'geocoder-container';
83
+ const LocationSearchControl = ({ position = 'top-right', ...props }) => {
84
+ ReactMapGL.useControl(() => maplibreGlJsAmplify.createAmplifyGeocoder(props), {
85
+ position,
86
+ });
87
+ return null;
88
+ };
89
+ const LocationSearchStandalone = (props) => {
90
+ const hasMounted = React.useRef(false);
91
+ React.useEffect(() => {
92
+ if (!hasMounted.current) {
93
+ maplibreGlJsAmplify.createAmplifyGeocoder(props).addTo(`#${LOCATION_SEARCH_CONTAINER}`);
94
+ hasMounted.current = true;
95
+ }
96
+ }, [props]);
97
+ return React__default["default"].createElement("div", { id: LOCATION_SEARCH_CONTAINER });
98
+ };
99
+ /**
100
+ * The `<LocationSearch>` component provides location search.
101
+ *
102
+ * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/geo#location-search)
103
+ *
104
+ * @example
105
+ * // Used as a map control:
106
+ * function App() {
107
+ * return (
108
+ * <MapView>
109
+ * <LocationSearch />
110
+ * </MapView>
111
+ * );
112
+ * }
113
+ *
114
+ * @example
115
+ * // Used as a standalone component:
116
+ * function App() {
117
+ * return <LocationSearch />;
118
+ * }
119
+ */
120
+ const LocationSearch = (props) => {
121
+ const { current: map } = ReactMapGL.useMap();
122
+ uiReactCore.useSetUserAgent({
123
+ componentName: 'LocationSearch',
124
+ packageName: 'react-geo',
125
+ version: VERSION,
126
+ });
127
+ /**
128
+ * This logic determines whether the LocationSearch exists as part of a Map component or if it is a standalone component.
129
+ * The `useControl` hook inside `LocationSearchControl` from `react-map-gl` makes it easy to add a control to a map,
130
+ * but throws an error if that map doesn't exist. If the map doesn't exist, the LocationSearch is mounted to a container
131
+ * upon rendering inside the `LocationSearchStandalone`.
132
+ */
133
+ if (map) {
134
+ return React__default["default"].createElement(LocationSearchControl, { ...LOCATION_SEARCH_OPTIONS, ...props });
135
+ }
136
+ return React__default["default"].createElement(LocationSearchStandalone, { ...LOCATION_SEARCH_OPTIONS, ...props });
137
+ };
138
+
139
+ exports.LocationSearch = LocationSearch;
140
+ exports.MapView = MapView;
@@ -0,0 +1 @@
1
+ export declare const VERSION = "1.0.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-geo",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -35,45 +35,25 @@
35
35
  "prebuild": "rimraf dist",
36
36
  "size": "yarn size-limit",
37
37
  "test": "jest",
38
- "test:ci": "yarn test && yarn check:esm",
39
38
  "test:watch": "yarn test --watch",
40
39
  "typecheck": "tsc --noEmit"
41
40
  },
42
41
  "dependencies": {
42
+ "@aws-amplify/ui-react-core": "3.0.0",
43
43
  "mapbox-gl": "1.13.1",
44
44
  "maplibre-gl": "2.1.9",
45
- "maplibre-gl-js-amplify": "^3.1.0",
45
+ "maplibre-gl-js-amplify": "^4.0.0",
46
46
  "react-map-gl": "7.0.23",
47
- "tslib": "2.4.1"
47
+ "tslib": "^2.5.2"
48
48
  },
49
49
  "peerDependencies": {
50
- "aws-amplify": "^5.0.1",
51
- "react": ">= 16.14.0",
52
- "react-dom": ">= 16.14.0"
50
+ "@aws-amplify/geo": "^3.0.2",
51
+ "aws-amplify": "^6.0.2",
52
+ "react": "^16.14.0 || ^17.0 || ^18.0",
53
+ "react-dom": "^16.14.0 || ^17.0 || ^18.0"
53
54
  },
54
55
  "devDependencies": {
55
- "@aws-amplify/eslint-config-amplify-ui": "0.0.0",
56
- "@rollup/plugin-typescript": "^8.3.1",
57
- "@size-limit/preset-big-lib": "^8.2.6",
58
- "@testing-library/jest-dom": "^5.14.1",
59
- "@testing-library/react": "^12.0.0",
60
- "@testing-library/react-hooks": "^7.0.1",
61
- "@testing-library/user-event": "^13.2.1",
62
- "@types/jest": "^26.0.23",
63
- "@types/mapbox__mapbox-gl-draw": "^1.3.3",
64
- "@types/react": "^17.0.2",
65
- "@types/testing-library__jest-dom": "^5.14.1",
66
- "eslint": "^8.44.0",
67
- "jest": "^27.0.4",
68
- "react": "^17.0.2",
69
- "react-dom": "^17.0.2",
70
- "rimraf": "^3.0.2",
71
- "rollup": "^2.70.0",
72
- "rollup-plugin-node-externals": "^4.1.1",
73
- "rollup-plugin-styles": "^4.0.0",
74
- "rollup-plugin-terser": "^7.0.2",
75
- "size-limit": "^8.2.6",
76
- "ts-jest": "^27.0.3"
56
+ "@types/mapbox__mapbox-gl-draw": "^1.3.3"
77
57
  },
78
58
  "sideEffects": [
79
59
  "dist/**/*.css"