esrieact 0.1.1 → 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";
@@ -110,8 +110,9 @@ export const MapView = React.forwardRef((props, ref) => {
110
110
  * Utility hook to get the undnerlying `map` and `view` instances of a MapView
111
111
  */
112
112
  export const useMap = () => {
113
- const { map, view } = useContext(MapContext);
114
- if (!map || !view) {
113
+ const context = useContext(MapContext);
114
+ const { map, view } = context;
115
+ if (!context) {
115
116
  throw new Error("Cannot find esrieact map context, are you sure your component is a descendent of a MapContext?");
116
117
  }
117
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.1",
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
  }