@mapcomponents/ra-geospatial 1.0.4 → 1.5.1-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.babelrc +12 -0
  2. package/.storybook/main.ts +25 -0
  3. package/.storybook/manager.js +6 -0
  4. package/.storybook/mapcomponents_logo.png +0 -0
  5. package/.storybook/preview.ts +27 -0
  6. package/.storybook/style.css +20 -0
  7. package/.storybook/wheregroupTheme.js +9 -0
  8. package/README.md +71 -1
  9. package/assets/ra_geospatial_screenshots.png +0 -0
  10. package/eslint.config.cjs +3 -0
  11. package/index.html +16 -0
  12. package/package.json +21 -35
  13. package/project.json +14 -0
  14. package/public/favicon.ico +0 -0
  15. package/public/logo.png +0 -0
  16. package/public/manifest.json +25 -0
  17. package/src/components/GeospatialInput.stories.tsx +83 -0
  18. package/src/components/GeospatialInput.tsx +14 -17
  19. package/src/components/GeospatialInputMap.tsx +175 -170
  20. package/src/components/GeospatialShow.stories.tsx +84 -0
  21. package/src/components/GeospatialShow.tsx +14 -17
  22. package/src/components/GeospatialShowMap.tsx +53 -58
  23. package/src/contexts/DataContext.jsx +66 -0
  24. package/src/contexts/dataProvider.tsx +30 -0
  25. package/src/contexts/lsDataProvider.js +138 -0
  26. package/src/decorators/ReactAdminDefaultDecorator.tsx +40 -0
  27. package/src/index.ts +2 -2
  28. package/src/layout/GisLayout.jsx +90 -0
  29. package/src/ra_components/Poi.tsx +42 -0
  30. package/src/ra_components/Property.tsx +42 -0
  31. package/src/ra_components/Route.tsx +42 -0
  32. package/src/ra_components/raGeospatialProps.ts +5 -0
  33. package/src/ra_components/raGeospatialWebGisProps.ts +5 -0
  34. package/src/types.d.ts +3 -2
  35. package/tsconfig.json +7 -101
  36. package/tsconfig.lib.json +29 -0
  37. package/vite.config.ts +49 -0
  38. package/dist/index.esm.js +0 -155
  39. package/dist/index.esm.js.map +0 -1
  40. package/package-lock.json +0 -16564
  41. package/rollup.config.js +0 -50
@@ -0,0 +1,29 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": [
6
+ "node",
7
+ "@nx/react/typings/cssmodule.d.ts",
8
+ "@nx/react/typings/image.d.ts",
9
+ "vite/client"
10
+ ]
11
+ },
12
+ "exclude": [
13
+ "**/*.spec.ts",
14
+ "**/*.test.ts",
15
+ "**/*.spec.tsx",
16
+ "**/*.test.tsx",
17
+ "**/*.spec.js",
18
+ "**/*.test.js",
19
+ "**/*.spec.jsx",
20
+ "**/*.test.jsx",
21
+ "src/**/*.spec.ts",
22
+ "src/**/*.test.ts",
23
+ "**/*.stories.ts",
24
+ "**/*.stories.js",
25
+ "**/*.stories.jsx",
26
+ "**/*.stories.tsx"
27
+ ],
28
+ "include": ["src/**/*", "../react-maplibre/src/**/*"]
29
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,49 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+ import react from '@vitejs/plugin-react';
4
+ import dts from 'vite-plugin-dts';
5
+ import * as path from 'path';
6
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
7
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
8
+
9
+ export default defineConfig(() => ({
10
+ root: __dirname,
11
+ cacheDir: '../../node_modules/.vite/packages/ra-geospatial',
12
+ plugins: [
13
+ react(),
14
+ nxViteTsPaths(),
15
+ nxCopyAssetsPlugin(['*.md']),
16
+ dts({
17
+ entryRoot: 'src',
18
+ tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
19
+ pathsToAliases: false,
20
+ }),
21
+ ],
22
+ // Uncomment this if you are using workers.
23
+ // worker: {
24
+ // plugins: [ nxViteTsPaths() ],
25
+ // },
26
+ // Configuration for building your library.
27
+ // See: https://vitejs.dev/guide/build.html#library-mode
28
+ build: {
29
+ outDir: '../../dist/packages/ra-geospatial',
30
+ emptyOutDir: true,
31
+ reportCompressedSize: true,
32
+ commonjsOptions: {
33
+ transformMixedEsModules: true,
34
+ },
35
+ lib: {
36
+ // Could also be a dictionary or array of multiple entry points.
37
+ entry: 'src/index.ts',
38
+ name: '@mapcomponents/ra-geospatial',
39
+ fileName: 'index',
40
+ // Change this to the formats you want to support.
41
+ // Don't forget to update your package.json as well.
42
+ formats: ['es' as const],
43
+ },
44
+ rollupOptions: {
45
+ // External packages that should not be bundled into your library.
46
+ external: ['react', 'react-dom', 'react/jsx-runtime'],
47
+ },
48
+ },
49
+ }));
package/dist/index.esm.js DELETED
@@ -1,155 +0,0 @@
1
- import React, { useState, useEffect } from 'react';
2
- import { useMap, MapLibreMap, MlGeoJsonLayer, MlFeatureEditor, MapComponentsProvider } from '@mapcomponents/react-maplibre';
3
- import { useRecordContext, useInput } from 'react-admin';
4
- import { parse, stringify } from 'wellknown';
5
- import { centroid } from '@turf/turf';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
-
22
- function __rest(s, e) {
23
- var t = {};
24
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25
- t[p] = s[p];
26
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
27
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
29
- t[p[i]] = s[p[i]];
30
- }
31
- return t;
32
- }
33
-
34
- function GeospatialInputMap(props) {
35
- var _a, _b;
36
- const source = props === null || props === void 0 ? void 0 : props.source;
37
- const record = useRecordContext();
38
- const mapHook = useMap({ mapId: props === null || props === void 0 ? void 0 : props.mapId });
39
- const [geojson, setGeojson] = useState();
40
- const [oldGeoJson, setOldGeoJson] = useState();
41
- const _c = useInput(props), _d = _c.field, { name, onChange } = _d; __rest(_d, ["name", "onChange"]);
42
- useEffect(() => {
43
- if (typeof record === "undefined" || !record[source])
44
- return;
45
- let _geoJson = {
46
- type: "Feature",
47
- properties: {},
48
- geometry: parse(record[source]),
49
- };
50
- setGeojson(_geoJson);
51
- setOldGeoJson(_geoJson);
52
- }, [record, props.source]);
53
- useEffect(() => {
54
- var _a;
55
- if (!mapHook.map)
56
- return;
57
- if (typeof record !== "undefined" && record[source]) {
58
- const _center = centroid(parse(record[source]));
59
- if ((_a = _center === null || _center === void 0 ? void 0 : _center.geometry) === null || _a === void 0 ? void 0 : _a.coordinates) {
60
- mapHook.map.setCenter(_center.geometry.coordinates);
61
- }
62
- }
63
- }, [mapHook.map]);
64
- return (React.createElement(React.Fragment, null,
65
- props.embeddedMap && (React.createElement(MapLibreMap, Object.assign({}, props === null || props === void 0 ? void 0 : props.MapLibreMapProps, { options: Object.assign({ zoom: 14, style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json", center: [0, 0] }, (_a = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _a === void 0 ? void 0 : _a.options), style: Object.assign({ width: "100%", height: "400px" }, (_b = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _b === void 0 ? void 0 : _b.style) }))),
66
- props.type === "point" && (React.createElement(React.Fragment, null,
67
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
68
- "circle-radius": 8,
69
- "circle-color": "#6f6f96",
70
- "circle-stroke-color": "white",
71
- "circle-stroke-width": 3,
72
- "circle-opacity": 0.8,
73
- }, type: "circle", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
74
- React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_point", onChange: (_geojson) => {
75
- if (typeof _geojson[0] !== "undefined") {
76
- onChange(stringify(_geojson[0]));
77
- }
78
- } }))),
79
- props.type === "polygon" && (React.createElement(React.Fragment, null,
80
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
81
- "fill-color": "#6f6f96",
82
- "fill-opacity": 0.6,
83
- }, type: "fill", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
84
- React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_polygon", onChange: (_geojson) => {
85
- if (typeof _geojson[0] !== "undefined") {
86
- onChange(stringify(_geojson[0]));
87
- }
88
- } }))),
89
- props.type === "line" && (React.createElement(React.Fragment, null,
90
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
91
- "line-width": 6,
92
- "line-color": "#6f6f96",
93
- "line-opacity": 0.6,
94
- }, type: "line", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
95
- React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_line_string", onChange: (_geojson) => {
96
- if (typeof _geojson[0] !== "undefined") {
97
- onChange(stringify(_geojson[0]));
98
- }
99
- } })))));
100
- }
101
- GeospatialInputMap.defaultProps = {
102
- type: "point",
103
- embeddedMap: true,
104
- };
105
-
106
- function GeospatialInput(props) {
107
- return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
108
- React.createElement(GeospatialInputMap, Object.assign({}, props)))) : (React.createElement(GeospatialInputMap, Object.assign({}, props)))));
109
- }
110
- GeospatialInput.defaultProps = {
111
- embeddedMap: true,
112
- };
113
-
114
- function GeospatialShowMap(props) {
115
- var _a, _b;
116
- const source = props.source;
117
- const record = useRecordContext();
118
- const mapHook = useMap();
119
- const [geojson, setGeojson] = useState();
120
- useEffect(() => {
121
- if (!(record === null || record === void 0 ? void 0 : record[source]))
122
- return;
123
- const _geometry = parse(record[source]);
124
- if (_geometry) {
125
- setGeojson({
126
- type: "Feature",
127
- properties: {},
128
- geometry: _geometry,
129
- });
130
- }
131
- }, [record]);
132
- useEffect(() => {
133
- var _a;
134
- if (!mapHook.map || !geojson)
135
- return;
136
- const _center = centroid(geojson);
137
- if ((_a = _center === null || _center === void 0 ? void 0 : _center.geometry) === null || _a === void 0 ? void 0 : _a.coordinates) {
138
- mapHook.map.setCenter(_center.geometry.coordinates);
139
- }
140
- }, [mapHook.map, geojson]);
141
- return (React.createElement(React.Fragment, null,
142
- props.embeddedMap && (React.createElement(MapLibreMap, Object.assign({}, props === null || props === void 0 ? void 0 : props.MapLibreMapProps, { options: Object.assign({ zoom: 14, style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json", center: [0, 0] }, (_a = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _a === void 0 ? void 0 : _a.options), style: Object.assign({ width: "100%", height: "400px" }, (_b = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _b === void 0 ? void 0 : _b.style) }))),
143
- geojson && React.createElement(MlGeoJsonLayer, { geojson: geojson })));
144
- }
145
-
146
- function GeospatialShow(props) {
147
- return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
148
- React.createElement(GeospatialShowMap, Object.assign({}, props)))) : (React.createElement(GeospatialShowMap, Object.assign({}, props)))));
149
- }
150
- GeospatialShow.defaultProps = {
151
- embeddedMap: true,
152
- };
153
-
154
- export { GeospatialInput as RaGeospatialInput, GeospatialShow as RaGeospatialShow };
155
- //# sourceMappingURL=index.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}