esrieact 0.1.0 → 0.2.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.
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import EsriMapImageLayer from "@arcgis/core/layers/MapImageLayer";
3
+ /**
4
+ * A MapImageLayer component
5
+ *
6
+ * ArcGIS JS API Source Components:
7
+ * - [MapImageLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html)
8
+ */
9
+ export declare const MapImageLayer: React.ForwardRefExoticComponent<__esri.MapImageLayerProperties & {
10
+ children?: React.ReactNode;
11
+ } & {
12
+ events?: {} | undefined;
13
+ layerOrder?: number | undefined;
14
+ } & React.RefAttributes<EsriMapImageLayer>>;
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import EsriMapImageLayer from "@arcgis/core/layers/MapImageLayer";
3
+ import { createLayerComponent, } from "./createLayerComponent";
4
+ const createLayer = (properties) => {
5
+ return new EsriMapImageLayer(properties);
6
+ };
7
+ /**
8
+ * A MapImageLayer component
9
+ *
10
+ * ArcGIS JS API Source Components:
11
+ * - [MapImageLayer](https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-MapImageLayer.html)
12
+ */
13
+ export const MapImageLayer = React.forwardRef((properties, ref) => createLayerComponent(createLayer, ref, properties));
@@ -23,7 +23,7 @@ export const createLayerComponent = (createLayer, ref, { children, events, layer
23
23
  */
24
24
  const instance = useMemo(() => {
25
25
  const layer = createLayer(properties);
26
- // If the parent in a GroupLayer (or any EsriInstance that has the .add(layer) method), add it to that,
26
+ // If the parent is a GroupLayer (or any EsriInstance that has the .add(layer) method), add it to that,
27
27
  // otherwise, add directly to the map
28
28
  if (parent && parent.add) {
29
29
  parent.add(layer, layerOrder);
@@ -44,7 +44,12 @@ export const createLayerComponent = (createLayer, ref, { children, events, layer
44
44
  */
45
45
  useEffect(() => {
46
46
  return () => {
47
- map.remove(instance);
47
+ if (parent && parent.remove) {
48
+ parent.remove(instance);
49
+ }
50
+ else {
51
+ map.remove(instance);
52
+ }
48
53
  };
49
54
  }, []);
50
55
  // If no children, there is no need to render a context provider
@@ -9,3 +9,4 @@ export * from "./LayerView";
9
9
  export * from "./WebTileLayer";
10
10
  export * from "./WMSLayer";
11
11
  export * from "./VectorTileLayer";
12
+ export * from "./MapImageLayer";
@@ -9,3 +9,4 @@ export * from "./LayerView";
9
9
  export * from "./WebTileLayer";
10
10
  export * from "./WMSLayer";
11
11
  export * from "./VectorTileLayer";
12
+ export * from "./MapImageLayer";
@@ -69,21 +69,33 @@ interface MapContextProviderProps {
69
69
  children?: ReactNode | ReactNode[];
70
70
  }
71
71
  /**
72
- * Provider which provides the map context to all descedants
72
+ * Provider which provides the map context to all descedants.
73
+ *
74
+ * @Documentation
75
+ * [MapContextProvider](https://slutske22.github.io/esrieact/map-view#mapcontextprovider)
73
76
  */
74
77
  export declare const MapContextProvider: React.FC<MapContextProviderProps>;
75
78
  interface Props extends HTMLAttributes<HTMLDivElement> {
76
79
  /**
77
80
  * Properties passed to the [Map](https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html)
81
+ *
82
+ * @Documentation
83
+ * [MapProperties](https://slutske22.github.io/esrieact/map-view#mapproperties)
78
84
  */
79
85
  MapProperties?: __esri.MapProperties;
80
86
  /**
81
87
  * Properties passed to the [MapView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html)
88
+ *
89
+ * @Documentation
90
+ * [ViewProperties](https://slutske22.github.io/esrieact/map-view#viewproperties)
82
91
  */
83
92
  ViewProperties?: __esri.MapViewProperties & {
84
93
  /**
85
94
  * Events that are attached to the MapView. Can be an event handler function map, or a function of the `view`
86
95
  * which return an event handler function map
96
+ *
97
+ * @Documentation
98
+ * [ViewProperties.events](https://slutske22.github.io/esrieact/map-view#viewpropertiesevents)
87
99
  */
88
100
  events?: ViewEventHandlerFnMap | ((view: __esri.MapView) => ViewEventHandlerFnMap);
89
101
  };
@@ -96,7 +108,10 @@ interface Props extends HTMLAttributes<HTMLDivElement> {
96
108
  * MapView Component for 2D map. Accepts properties for both the Map and the MapView. Renders the container
97
109
  * div, and once mounted, renders the map to it.
98
110
  *
99
- * ***Does not provide its own Map Context, and as such, will fail if you do not manuaaly provide one***
111
+ * ***Does not provide its own Map Context, and as such, will fail if you do not manually provide one***
112
+ *
113
+ * @Documentation
114
+ * [MapViewCore](https://slutske22.github.io/esrieact/map-view#mapviewcore)
100
115
  *
101
116
  * @example
102
117
  * // App.tsx
@@ -132,6 +147,9 @@ export declare const MapViewCore: React.ForwardRefExoticComponent<Props & React.
132
147
  * MapView Component for 2D map. Accepts properties for both the Map and the MapView. Renders the container
133
148
  * div, and once mounted, renders the map to it.
134
149
  *
150
+ * @Documentation
151
+ * [MapView](https://slutske22.github.io/esrieact/map-view)
152
+ *
135
153
  * ArcGIS JS API Source Components:
136
154
  * - [Map](https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html)
137
155
  * - [MapView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html)
@@ -9,7 +9,10 @@ import { useEsriPropertyUpdates, useEvents, } from "../utils";
9
9
  */
10
10
  export const MapContext = React.createContext({});
11
11
  /**
12
- * Provider which provides the map context to all descedants
12
+ * Provider which provides the map context to all descedants.
13
+ *
14
+ * @Documentation
15
+ * [MapContextProvider](https://slutske22.github.io/esrieact/map-view#mapcontextprovider)
13
16
  */
14
17
  export const MapContextProvider = ({ children, }) => {
15
18
  const [map, setMap] = useState(undefined);
@@ -25,7 +28,10 @@ export const MapContextProvider = ({ children, }) => {
25
28
  * MapView Component for 2D map. Accepts properties for both the Map and the MapView. Renders the container
26
29
  * div, and once mounted, renders the map to it.
27
30
  *
28
- * ***Does not provide its own Map Context, and as such, will fail if you do not manuaaly provide one***
31
+ * ***Does not provide its own Map Context, and as such, will fail if you do not manually provide one***
32
+ *
33
+ * @Documentation
34
+ * [MapViewCore](https://slutske22.github.io/esrieact/map-view#mapviewcore)
29
35
  *
30
36
  * @example
31
37
  * // App.tsx
@@ -90,6 +96,9 @@ export const MapViewCore = React.forwardRef((props, ref) => {
90
96
  * MapView Component for 2D map. Accepts properties for both the Map and the MapView. Renders the container
91
97
  * div, and once mounted, renders the map to it.
92
98
  *
99
+ * @Documentation
100
+ * [MapView](https://slutske22.github.io/esrieact/map-view)
101
+ *
93
102
  * ArcGIS JS API Source Components:
94
103
  * - [Map](https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html)
95
104
  * - [MapView](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html)
@@ -101,8 +110,9 @@ export const MapView = React.forwardRef((props, ref) => {
101
110
  * Utility hook to get the undnerlying `map` and `view` instances of a MapView
102
111
  */
103
112
  export const useMap = () => {
104
- const { map, view } = useContext(MapContext);
105
- if (!map || !view) {
113
+ const context = useContext(MapContext);
114
+ const { map, view } = context;
115
+ if (!context) {
106
116
  throw new Error("Cannot find esrieact map context, are you sure your component is a descendent of a MapContext?");
107
117
  }
108
118
  return { map, view };
@@ -3,7 +3,7 @@ interface Props {
3
3
  /**
4
4
  * The symbol to render in HTML
5
5
  */
6
- symbol: __esri.Symbol;
6
+ symbol: __esri.SymbolUnion;
7
7
  /**
8
8
  * HTML rendering options to be passed to `renderPreviewHTML`
9
9
  */
@@ -1,4 +1,4 @@
1
- import { useUpdateEffect } from "usehooks-ts";
1
+ import { useUpdateEffect } from "./useUpdateEffect";
2
2
  import { usePrevious } from "./usePrevious";
3
3
  import { getObjectDiff } from ".";
4
4
  /**
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from "react";
2
2
  export function usePrevious(value) {
3
- const ref = useRef();
3
+ const ref = useRef(undefined);
4
4
  useEffect(() => {
5
5
  ref.current = value;
6
6
  }, [value]);
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * Like useEffect, but skips the initial mount.
4
+ */
5
+ export declare function useUpdateEffect(effect: React.EffectCallback, deps?: React.DependencyList): void;
@@ -0,0 +1,14 @@
1
+ import { useEffect, useRef } from "react";
2
+ /**
3
+ * Like useEffect, but skips the initial mount.
4
+ */
5
+ export function useUpdateEffect(effect, deps) {
6
+ const isFirst = useRef(true);
7
+ useEffect(() => {
8
+ if (isFirst.current) {
9
+ isFirst.current = false;
10
+ return;
11
+ }
12
+ return effect();
13
+ }, deps);
14
+ }
@@ -11,5 +11,6 @@ const createWidget = (properties) => {
11
11
  * - [Expand](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Expand.html)
12
12
  */
13
13
  export const Expand = React.forwardRef((properties, ref) => {
14
+ // @ts-expect-error internal mismatch of arcgis types?
14
15
  return createWidgetComponent(createWidget, ref, properties);
15
16
  });
@@ -11,5 +11,6 @@ const createWidget = (properties) => {
11
11
  * - [Legend](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Legend.html)
12
12
  */
13
13
  export const Legend = React.forwardRef((properties, ref) => {
14
+ // @ts-expect-error internal mismatch of arcgis types?
14
15
  return createWidgetComponent(createWidget, ref, properties);
15
16
  });
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import EsriSearch from "@arcgis/core/widgets/Search";
3
3
  import { createWidgetComponent } from ".";
4
4
  const createSearchWidget = (properties) => {
5
+ // @ts-expect-error internal mismatch of arcgis types?
5
6
  return new EsriSearch(properties);
6
7
  };
7
8
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "esrieact",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
@@ -23,17 +23,16 @@
23
23
  "./widgets/*": "./dist/widgets/*"
24
24
  },
25
25
  "dependencies": {
26
- "lodash.isequal": "^4.5.0",
27
- "usehooks-ts": "^2.9.1"
26
+ "lodash.isequal": "^4.5.0"
28
27
  },
29
28
  "peerDependencies": {
30
- "@arcgis/core": "^4.28.10",
31
- "react": "^18.2.0",
32
- "react-dom": "^18.2.0"
29
+ "@arcgis/core": "^4.30.0",
30
+ "react": "^19.0.0",
31
+ "react-dom": "^19.0.0"
33
32
  },
34
33
  "devDependencies": {
35
- "@types/react": "^18.2.43",
36
- "@types/react-dom": "^18.2.17",
34
+ "@types/react": "^19.0.0",
35
+ "@types/react-dom": "^19.0.0",
37
36
  "typescript": "^5.2.2"
38
37
  }
39
38
  }