esrieact 0.2.0 → 0.2.1
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/dist/layers/GeoJSONLayer.d.ts +27 -0
- package/dist/layers/GeoJSONLayer.js +13 -0
- package/dist/layers/GraphicsLayer.d.ts +14 -1
- package/dist/layers/index.d.ts +1 -0
- package/dist/layers/index.js +1 -0
- package/dist/widgets/createWidgetComponent.d.ts +4 -2
- package/dist/widgets/createWidgetComponent.js +21 -4
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import EsriGeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer";
|
|
3
|
+
/**
|
|
4
|
+
* An event handler function map specific to a GeoJSONLayer
|
|
5
|
+
*/
|
|
6
|
+
export type GeoJSONLayerEventHandlerFnMap = Partial<{
|
|
7
|
+
refresh: __esri.GeoJSONLayerRefreshEventHandler;
|
|
8
|
+
edits: __esri.GeoJSONLayerEditsEventHandler;
|
|
9
|
+
"layerview-create": __esri.GeoJSONLayerLayerviewCreateEventHandler;
|
|
10
|
+
"layerview-create-error": __esri.GeoJSONLayerLayerviewCreateErrorEventHandler;
|
|
11
|
+
"layerview-destroy": __esri.GeoJSONLayerLayerviewDestroyEventHandler;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* The GeoJSONLayer React component
|
|
15
|
+
*/
|
|
16
|
+
export declare const GeoJSONLayer: React.ForwardRefExoticComponent<__esri.GeoJSONLayerProperties & {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
} & {
|
|
19
|
+
events?: Partial<{
|
|
20
|
+
refresh: __esri.GeoJSONLayerRefreshEventHandler;
|
|
21
|
+
edits: __esri.GeoJSONLayerEditsEventHandler;
|
|
22
|
+
"layerview-create": __esri.GeoJSONLayerLayerviewCreateEventHandler;
|
|
23
|
+
"layerview-create-error": __esri.GeoJSONLayerLayerviewCreateErrorEventHandler;
|
|
24
|
+
"layerview-destroy": __esri.GeoJSONLayerLayerviewDestroyEventHandler;
|
|
25
|
+
}> | undefined;
|
|
26
|
+
layerOrder?: number | undefined;
|
|
27
|
+
} & React.RefAttributes<EsriGeoJSONLayer>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import EsriGeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer";
|
|
3
|
+
import { createLayerComponent, } from "./createLayerComponent";
|
|
4
|
+
/**
|
|
5
|
+
* Function that takes in properties of a GeoJSONLayer, and returns the GeoJSONLayer instance
|
|
6
|
+
*/
|
|
7
|
+
const createLayer = (properties) => {
|
|
8
|
+
return new EsriGeoJSONLayer(properties);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The GeoJSONLayer React component
|
|
12
|
+
*/
|
|
13
|
+
export const GeoJSONLayer = React.forwardRef((properties, ref) => createLayerComponent(createLayer, ref, properties));
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import EsriGraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
|
|
3
|
+
export type GraphicsLayerEventHandlerFnMap = Partial<{
|
|
4
|
+
refresh: __esri.FeatureLayerRefreshEventHandler;
|
|
5
|
+
edits: __esri.FeatureLayerEditsEventHandler;
|
|
6
|
+
"layerview-create": __esri.FeatureLayerLayerviewCreateEventHandler;
|
|
7
|
+
"layerview-create-error": __esri.FeatureLayerLayerviewCreateErrorEventHandler;
|
|
8
|
+
"layerview-destroy": __esri.FeatureLayerLayerviewDestroyEventHandler;
|
|
9
|
+
}>;
|
|
3
10
|
/**
|
|
4
11
|
* A GraphicsLayer component
|
|
5
12
|
*
|
|
@@ -9,6 +16,12 @@ import EsriGraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
|
|
|
9
16
|
export declare const GraphicsLayer: React.ForwardRefExoticComponent<__esri.GraphicsLayerProperties & {
|
|
10
17
|
children?: React.ReactNode;
|
|
11
18
|
} & {
|
|
12
|
-
events?: {
|
|
19
|
+
events?: Partial<{
|
|
20
|
+
refresh: __esri.FeatureLayerRefreshEventHandler;
|
|
21
|
+
edits: __esri.FeatureLayerEditsEventHandler;
|
|
22
|
+
"layerview-create": __esri.FeatureLayerLayerviewCreateEventHandler;
|
|
23
|
+
"layerview-create-error": __esri.FeatureLayerLayerviewCreateErrorEventHandler;
|
|
24
|
+
"layerview-destroy": __esri.FeatureLayerLayerviewDestroyEventHandler;
|
|
25
|
+
}> | undefined;
|
|
13
26
|
layerOrder?: number | undefined;
|
|
14
27
|
} & React.RefAttributes<EsriGraphicsLayer>>;
|
package/dist/layers/index.d.ts
CHANGED
package/dist/layers/index.js
CHANGED
|
@@ -4,7 +4,9 @@ import EsriWidget from "@arcgis/core/widgets/Widget";
|
|
|
4
4
|
* Properties that can be applied to any ESRIEACT Widget component. Extends from
|
|
5
5
|
* esri's WidgetProperties to include child components and the widget position
|
|
6
6
|
*/
|
|
7
|
-
export type WidgetComponentProps<T extends __esri.WidgetProperties = __esri.WidgetProperties
|
|
7
|
+
export type WidgetComponentProps<T extends __esri.WidgetProperties = __esri.WidgetProperties & {
|
|
8
|
+
view?: __esri.MapView;
|
|
9
|
+
}, E extends Record<string, Function> = {}> = React.PropsWithChildren<T> & {
|
|
8
10
|
events?: E;
|
|
9
11
|
position?: string | __esri.UIAddPosition;
|
|
10
12
|
};
|
|
@@ -26,4 +28,4 @@ export declare const WidgetContext: React.Context<EsriWidget>;
|
|
|
26
28
|
* @param properties The widget properties
|
|
27
29
|
* @returns A context provider whose context is the instance to be passed to children, or if there are no children, returns null
|
|
28
30
|
*/
|
|
29
|
-
export declare function createWidgetComponent<P extends WidgetComponentProps>(createWidget: CreateWidgetFunction, ref: Ref<EsriWidget>, { children, events, position, ...properties }: P): import("react/jsx-runtime").JSX.Element | null;
|
|
31
|
+
export declare function createWidgetComponent<P extends WidgetComponentProps>(createWidget: CreateWidgetFunction, ref: Ref<EsriWidget>, { children, events, position, view, ...properties }: P): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useImperativeHandle, useMemo, } from "react";
|
|
2
|
+
import React, { createContext, useContext, useEffect, useImperativeHandle, useMemo, useRef, } from "react";
|
|
3
3
|
import Expand from "@arcgis/core/widgets/Expand";
|
|
4
4
|
import { useMap } from "..";
|
|
5
5
|
import { useEsriPropertyUpdates, useEvents } from "../utils";
|
|
@@ -16,9 +16,10 @@ export const WidgetContext = createContext({});
|
|
|
16
16
|
* @param properties The widget properties
|
|
17
17
|
* @returns A context provider whose context is the instance to be passed to children, or if there are no children, returns null
|
|
18
18
|
*/
|
|
19
|
-
export function createWidgetComponent(createWidget, ref, { children, events, position, ...properties }) {
|
|
19
|
+
export function createWidgetComponent(createWidget, ref, { children, events, position, view: viewFromProps, ...properties }) {
|
|
20
20
|
const { view } = useMap();
|
|
21
21
|
const parentWidgetContext = useContext(WidgetContext);
|
|
22
|
+
const childrenRef = useRef(null);
|
|
22
23
|
const instance = useMemo(() => {
|
|
23
24
|
const instance = createWidget({ ...properties, view });
|
|
24
25
|
if (parentWidgetContext instanceof Expand) {
|
|
@@ -29,10 +30,23 @@ export function createWidgetComponent(createWidget, ref, { children, events, pos
|
|
|
29
30
|
view.ui.add(instance, position);
|
|
30
31
|
}
|
|
31
32
|
return instance;
|
|
32
|
-
}, []);
|
|
33
|
+
}, [view]);
|
|
33
34
|
useImperativeHandle(ref, () => instance);
|
|
34
35
|
useEsriPropertyUpdates(instance, properties);
|
|
35
36
|
useEvents(instance, events);
|
|
37
|
+
/**
|
|
38
|
+
* Check if children is a singular HTML element and assign its ref to instance.content,
|
|
39
|
+
* enables dev to make arbitrary UI elements children of an Expand widget
|
|
40
|
+
*/
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (children && childrenRef.current && instance) {
|
|
43
|
+
if (React.isValidElement(children)) {
|
|
44
|
+
if (instance instanceof Expand) {
|
|
45
|
+
instance.content = childrenRef.current;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [children, instance]);
|
|
36
50
|
/**
|
|
37
51
|
* Remove widget on unmount
|
|
38
52
|
*/
|
|
@@ -43,5 +57,8 @@ export function createWidgetComponent(createWidget, ref, { children, events, pos
|
|
|
43
57
|
}, []);
|
|
44
58
|
if (!children)
|
|
45
59
|
return null;
|
|
46
|
-
|
|
60
|
+
// Pass ref to the child element - works for both HTML elements and forwardRef components
|
|
61
|
+
return (_jsx(WidgetContext.Provider, { value: instance, children: React.cloneElement(children, {
|
|
62
|
+
ref: childrenRef,
|
|
63
|
+
}) }));
|
|
47
64
|
}
|