@babylonjs/shared-ui-components 5.32.0 → 5.32.2
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/components/layout/FlexibleTabsContainer.modules.scss +1 -0
- package/components/reactGraphSystem/GraphConnectorHandle.d.ts +43 -0
- package/components/reactGraphSystem/GraphConnectorHandle.js +38 -0
- package/components/reactGraphSystem/GraphConnectorHandle.js.map +1 -0
- package/components/reactGraphSystem/GraphConnectorHandle.modules.scss +12 -0
- package/components/reactGraphSystem/GraphContainer.d.ts +10 -0
- package/components/reactGraphSystem/GraphContainer.js +12 -0
- package/components/reactGraphSystem/GraphContainer.js.map +1 -0
- package/components/reactGraphSystem/GraphContainer.modules.scss +8 -0
- package/components/reactGraphSystem/GraphContextManager.d.ts +10 -0
- package/components/reactGraphSystem/GraphContextManager.js +3 -0
- package/components/reactGraphSystem/GraphContextManager.js.map +1 -0
- package/components/reactGraphSystem/GraphLine.d.ts +40 -0
- package/components/reactGraphSystem/GraphLine.js +19 -0
- package/components/reactGraphSystem/GraphLine.js.map +1 -0
- package/components/reactGraphSystem/GraphLinesContainer.d.ts +16 -0
- package/components/reactGraphSystem/GraphLinesContainer.js +22 -0
- package/components/reactGraphSystem/GraphLinesContainer.js.map +1 -0
- package/components/reactGraphSystem/GraphNode.d.ts +13 -0
- package/components/reactGraphSystem/GraphNode.js +22 -0
- package/components/reactGraphSystem/GraphNode.js.map +1 -0
- package/components/reactGraphSystem/GraphNode.modules.scss +22 -0
- package/components/reactGraphSystem/GraphNodesContainer.d.ts +9 -0
- package/components/reactGraphSystem/GraphNodesContainer.js +32 -0
- package/components/reactGraphSystem/GraphNodesContainer.js.map +1 -0
- package/components/reactGraphSystem/NodeRenderer.d.ts +69 -0
- package/components/reactGraphSystem/NodeRenderer.js +70 -0
- package/components/reactGraphSystem/NodeRenderer.js.map +1 -0
- package/components/reactGraphSystem/useGraphContext.d.ts +5 -0
- package/components/reactGraphSystem/useGraphContext.js +11 -0
- package/components/reactGraphSystem/useGraphContext.js.map +1 -0
- package/package.json +1 -1
@@ -0,0 +1,43 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
/**
|
3
|
+
* Props for the connector
|
4
|
+
*/
|
5
|
+
export interface IGraphConnectorHandlerProps {
|
6
|
+
/**
|
7
|
+
* id of the parent node
|
8
|
+
*/
|
9
|
+
parentId: string;
|
10
|
+
/**
|
11
|
+
* x position of the parent node
|
12
|
+
*/
|
13
|
+
parentX: number;
|
14
|
+
/**
|
15
|
+
* y position of the parent node
|
16
|
+
*/
|
17
|
+
parentY: number;
|
18
|
+
/**
|
19
|
+
* x position of the connector relative to the parent node
|
20
|
+
*/
|
21
|
+
offsetX?: number;
|
22
|
+
/**
|
23
|
+
* y position of the connector relative to the parent node
|
24
|
+
*/
|
25
|
+
offsetY?: number;
|
26
|
+
/**
|
27
|
+
* width of the parent node
|
28
|
+
*/
|
29
|
+
parentWidth: number;
|
30
|
+
/**
|
31
|
+
* height of the parent node
|
32
|
+
*/
|
33
|
+
parentHeight: number;
|
34
|
+
/**
|
35
|
+
* id of the container where its parent node is
|
36
|
+
*/
|
37
|
+
parentContainerId: string;
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* This component is used to initiate a connection between two nodes. Simply
|
41
|
+
* drag the handle in a node and drop it in another node to create a connection.
|
42
|
+
*/
|
43
|
+
export declare const GraphConnectorHandler: FC<IGraphConnectorHandlerProps>;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useCallback } from "react";
|
3
|
+
import { useDrag, useDrop } from "react-dnd";
|
4
|
+
import { ClassNames } from "../classNames.js";
|
5
|
+
import style from "./GraphConnectorHandle.modules.scss";
|
6
|
+
import { useGraphContext } from "./useGraphContext.js";
|
7
|
+
/**
|
8
|
+
* This component is used to initiate a connection between two nodes. Simply
|
9
|
+
* drag the handle in a node and drop it in another node to create a connection.
|
10
|
+
*/
|
11
|
+
export const GraphConnectorHandler = ({ parentId, parentX, parentY, offsetX = 0, offsetY = 0, parentWidth, parentHeight, parentContainerId }) => {
|
12
|
+
const { onNodesConnected } = useGraphContext();
|
13
|
+
const centerX = offsetX + parentWidth / 2;
|
14
|
+
const centerY = offsetY + parentHeight / 2;
|
15
|
+
const [, dragRef] = useDrag(() => ({
|
16
|
+
type: "connector",
|
17
|
+
item: { parentId, x: parentX + centerX, y: parentY + centerY, parentContainerId },
|
18
|
+
canDrag: () => parentX !== undefined && parentY !== undefined,
|
19
|
+
}), [parentId, parentX, parentY]);
|
20
|
+
const [{ isOver }, dropRef] = useDrop(() => ({
|
21
|
+
accept: "connector",
|
22
|
+
collect: (monitor) => ({
|
23
|
+
isOver: monitor.isOver(),
|
24
|
+
}),
|
25
|
+
canDrop: (item) => {
|
26
|
+
return item.parentContainerId === parentContainerId;
|
27
|
+
},
|
28
|
+
drop: (item) => {
|
29
|
+
onNodesConnected && onNodesConnected(item.parentId, parentId);
|
30
|
+
},
|
31
|
+
}));
|
32
|
+
const attachRef = useCallback((ref) => {
|
33
|
+
dragRef(ref);
|
34
|
+
dropRef(ref);
|
35
|
+
}, [dragRef, dropRef]);
|
36
|
+
return _jsx("div", { ref: attachRef, className: ClassNames({ handle: true, hovered: isOver }, style), style: { top: centerY + "px", left: centerX + "px" } });
|
37
|
+
};
|
38
|
+
//# sourceMappingURL=GraphConnectorHandle.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphConnectorHandle.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphConnectorHandle.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,MAAM,qCAAqC,CAAC;AACxD,OAAO,EAAE,eAAe,E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AAC,CAAC;QAClE,CAAC;KACJ,CAAC,CAAC,CAAC;IACJ,MAAM,SAAS,GAAG,WAAW,CACzB,CAAC,GAAG,EAAE,EAAE;QACJ,OAAO,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,EACD,CAAC,OAAO,EAAE,OAAO,CAAC,CACrB,CAAC;IACF,OAAO,cAAK,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,GAAI,CAAC;AAC1J,CAAC,CAAC","sourcesContent":["import type { FC } from \"react\";\r\nimport { useCallback } from \"react\";\r\nimport type { DropTargetMonitor } from \"react-dnd\";\r\nimport { useDrag, useDrop } from \"react-dnd\";\r\nimport { ClassNames } from \"../classNames\";\r\nimport style from \"./GraphConnectorHandle.modules.scss\";\r\nimport { useGraphContext } from \"./useGraphContext\";\r\n\r\n/**\r\n * Props for the connector\r\n */\r\nexport interface IGraphConnectorHandlerProps {\r\n /**\r\n * id of the parent node\r\n */\r\n parentId: string;\r\n /**\r\n * x position of the parent node\r\n */\r\n parentX: number;\r\n /**\r\n * y position of the parent node\r\n */\r\n parentY: number;\r\n /**\r\n * x position of the connector relative to the parent node\r\n */\r\n offsetX?: number;\r\n /**\r\n * y position of the connector relative to the parent node\r\n */\r\n offsetY?: number;\r\n /**\r\n * width of the parent node\r\n */\r\n parentWidth: number;\r\n /**\r\n * height of the parent node\r\n */\r\n parentHeight: number;\r\n /**\r\n * id of the container where its parent node is\r\n */\r\n parentContainerId: string;\r\n}\r\n\r\n/**\r\n * This component is used to initiate a connection between two nodes. Simply\r\n * drag the handle in a node and drop it in another node to create a connection.\r\n */\r\nexport const GraphConnectorHandler: FC<IGraphConnectorHandlerProps> = ({ parentId, parentX, parentY, offsetX = 0, offsetY = 0, parentWidth, parentHeight, parentContainerId }) => {\r\n const { onNodesConnected } = useGraphContext();\r\n const centerX = offsetX + parentWidth / 2;\r\n const centerY = offsetY + parentHeight / 2;\r\n const [, dragRef] = useDrag(\r\n () => ({\r\n type: \"connector\",\r\n item: { parentId, x: parentX + centerX, y: parentY + centerY, parentContainerId },\r\n canDrag: () => parentX !== undefined && parentY !== undefined,\r\n }),\r\n [parentId, parentX, parentY]\r\n );\r\n const [{ isOver }, dropRef] = useDrop(() => ({\r\n accept: \"connector\",\r\n collect: (monitor: DropTargetMonitor) => ({\r\n isOver: monitor.isOver(),\r\n }),\r\n canDrop: (item: any) => {\r\n return item.parentContainerId === parentContainerId;\r\n },\r\n drop: (item: any) => {\r\n onNodesConnected && onNodesConnected(item.parentId, parentId);\r\n },\r\n }));\r\n const attachRef = useCallback(\r\n (ref) => {\r\n dragRef(ref);\r\n dropRef(ref);\r\n },\r\n [dragRef, dropRef]\r\n );\r\n return <div ref={attachRef} className={ClassNames({ handle: true, hovered: isOver }, style)} style={{ top: centerY + \"px\", left: centerX + \"px\" }} />;\r\n};\r\n"]}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
export interface IGraphContainerProps {
|
3
|
+
}
|
4
|
+
/**
|
5
|
+
* This component is just a simple container to keep the nodes and lines containers
|
6
|
+
* together
|
7
|
+
* @param props
|
8
|
+
* @returns
|
9
|
+
*/
|
10
|
+
export declare const GraphContainer: FC<IGraphContainerProps>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import style from "./GraphContainer.modules.scss";
|
3
|
+
/**
|
4
|
+
* This component is just a simple container to keep the nodes and lines containers
|
5
|
+
* together
|
6
|
+
* @param props
|
7
|
+
* @returns
|
8
|
+
*/
|
9
|
+
export const GraphContainer = (props) => {
|
10
|
+
return _jsx("div", { className: style.container, children: props.children });
|
11
|
+
};
|
12
|
+
//# sourceMappingURL=GraphContainer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphContainer.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphContainer.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,+BAA+B,CAAC;AAIlD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAA6B,CAAC,KAAK,EAAE,EAAE;IAC9D,OAAO,cAAK,SAAS,EAAE,KAAK,CAAC,SAAS,YAAG,KAAK,CAAC,QAAQ,GAAO,CAAC;AACnE,CAAC,CAAC","sourcesContent":["import type { FC } from \"react\";\r\nimport style from \"./GraphContainer.modules.scss\";\r\n\r\nexport interface IGraphContainerProps {}\r\n\r\n/**\r\n * This component is just a simple container to keep the nodes and lines containers\r\n * together\r\n * @param props\r\n * @returns\r\n */\r\nexport const GraphContainer: FC<IGraphContainerProps> = (props) => {\r\n return <div className={style.container}>{props.children}</div>;\r\n};\r\n"]}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
/**
|
3
|
+
* this context is used to pass callbacks to the graph nodes and connections
|
4
|
+
*/
|
5
|
+
export interface IGraphContext {
|
6
|
+
onNodesConnected?: (sourceId: string, targetId: string) => void;
|
7
|
+
onLineSelected?: (lineId: string) => void;
|
8
|
+
onNodeSelected?: (nodeId: string) => void;
|
9
|
+
}
|
10
|
+
export declare const GraphContextManager: import("react").Context<IGraphContext>;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphContextManager.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphContextManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAWtC,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAgB,EAAE,CAAC,CAAC","sourcesContent":["import { createContext } from \"react\";\r\n\r\n/**\r\n * this context is used to pass callbacks to the graph nodes and connections\r\n */\r\nexport interface IGraphContext {\r\n onNodesConnected?: (sourceId: string, targetId: string) => void;\r\n onLineSelected?: (lineId: string) => void;\r\n onNodeSelected?: (nodeId: string) => void;\r\n}\r\n\r\nexport const GraphContextManager = createContext<IGraphContext>({});\r\n"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
/**
|
3
|
+
* props for the GraphLine component
|
4
|
+
*/
|
5
|
+
export interface IGraphLineProps {
|
6
|
+
/**
|
7
|
+
* id of the line. temporary lines can have no id
|
8
|
+
*/
|
9
|
+
id?: string;
|
10
|
+
/**
|
11
|
+
* starting x pos of the line
|
12
|
+
*/
|
13
|
+
x1: number;
|
14
|
+
/**
|
15
|
+
* ending x pos of the line
|
16
|
+
*/
|
17
|
+
x2: number;
|
18
|
+
/**
|
19
|
+
* starting y pos of the line
|
20
|
+
*/
|
21
|
+
y1: number;
|
22
|
+
/**
|
23
|
+
* ending y pos of the line
|
24
|
+
*/
|
25
|
+
y2: number;
|
26
|
+
/**
|
27
|
+
* is the line selected
|
28
|
+
*/
|
29
|
+
selected?: boolean;
|
30
|
+
/**
|
31
|
+
* does the line have a direction
|
32
|
+
*/
|
33
|
+
directional?: boolean;
|
34
|
+
}
|
35
|
+
export declare const MarkerArrowId = "arrow";
|
36
|
+
/**
|
37
|
+
* This component draws a SVG line between two points, with an optional marker
|
38
|
+
* indicating direction
|
39
|
+
*/
|
40
|
+
export declare const GraphLine: FC<IGraphLineProps>;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useGraphContext } from "./useGraphContext.js";
|
3
|
+
export const MarkerArrowId = "arrow";
|
4
|
+
/**
|
5
|
+
* This component draws a SVG line between two points, with an optional marker
|
6
|
+
* indicating direction
|
7
|
+
*/
|
8
|
+
export const GraphLine = (props) => {
|
9
|
+
const { id, x1, x2, y1, y2, selected, directional = true } = props;
|
10
|
+
const { onLineSelected } = useGraphContext();
|
11
|
+
// Line is only selectable when it has an id
|
12
|
+
const onClick = () => {
|
13
|
+
id && onLineSelected && onLineSelected(id);
|
14
|
+
};
|
15
|
+
const xm = (x1 + x2) / 2;
|
16
|
+
const ym = (y1 + y2) / 2;
|
17
|
+
return (_jsx("path", { d: `M ${x1} ${y1} L ${xm} ${ym} L ${x2} ${y2}`, strokeWidth: 3, stroke: selected ? "yellow" : "black", onClick: onClick, markerMid: directional ? `url(#${MarkerArrowId})` : "" }));
|
18
|
+
};
|
19
|
+
//# sourceMappingURL=GraphLine.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphLine.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphLine.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmCpD,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAwB,CAAC,KAAsB,EAAE,EAAE;IACrE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnE,MAAM,EAAE,cAAc,EAAE,GAAG,eAAe,EAAE,CAAC;IAE7C,4CAA4C;IAC5C,MAAM,OAAO,GAAG,GAAG,EAAE;QACjB,EAAE,IAAI,cAAc,IAAI,cAAc,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEF,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAEzB,OAAO,CACH,eACI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAC9C,WAAW,EAAE,CAAC,EACd,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EACrC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,aAAa,GAAG,CAAC,CAAC,CAAC,EAAE,GACxD,CACL,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FC } from \"react\";\r\nimport { useGraphContext } from \"./useGraphContext\";\r\n/**\r\n * props for the GraphLine component\r\n */\r\nexport interface IGraphLineProps {\r\n /**\r\n * id of the line. temporary lines can have no id\r\n */\r\n id?: string;\r\n /**\r\n * starting x pos of the line\r\n */\r\n x1: number;\r\n /**\r\n * ending x pos of the line\r\n */\r\n x2: number;\r\n /**\r\n * starting y pos of the line\r\n */\r\n y1: number;\r\n /**\r\n * ending y pos of the line\r\n */\r\n y2: number;\r\n /**\r\n * is the line selected\r\n */\r\n selected?: boolean;\r\n /**\r\n * does the line have a direction\r\n */\r\n directional?: boolean;\r\n}\r\n\r\nexport const MarkerArrowId = \"arrow\";\r\n\r\n/**\r\n * This component draws a SVG line between two points, with an optional marker\r\n * indicating direction\r\n */\r\nexport const GraphLine: FC<IGraphLineProps> = (props: IGraphLineProps) => {\r\n const { id, x1, x2, y1, y2, selected, directional = true } = props;\r\n const { onLineSelected } = useGraphContext();\r\n\r\n // Line is only selectable when it has an id\r\n const onClick = () => {\r\n id && onLineSelected && onLineSelected(id);\r\n };\r\n\r\n const xm = (x1 + x2) / 2;\r\n const ym = (y1 + y2) / 2;\r\n\r\n return (\r\n <path\r\n d={`M ${x1} ${y1} L ${xm} ${ym} L ${x2} ${y2}`}\r\n strokeWidth={3}\r\n stroke={selected ? \"yellow\" : \"black\"}\r\n onClick={onClick}\r\n markerMid={directional ? `url(#${MarkerArrowId})` : \"\"}\r\n />\r\n );\r\n};\r\n"]}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
/**
|
3
|
+
* props for the GraphLineContainer
|
4
|
+
*/
|
5
|
+
export interface IGraphLinesContainerProps {
|
6
|
+
/**
|
7
|
+
* id of the container
|
8
|
+
*/
|
9
|
+
id: string;
|
10
|
+
}
|
11
|
+
/**
|
12
|
+
* this component handles the dragging of new connections
|
13
|
+
* @param props
|
14
|
+
* @returns
|
15
|
+
*/
|
16
|
+
export declare const GraphLinesContainer: FC<IGraphLinesContainerProps>;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useDrop } from "react-dnd";
|
3
|
+
import { GraphLine, MarkerArrowId } from "./GraphLine.js";
|
4
|
+
/**
|
5
|
+
* this component handles the dragging of new connections
|
6
|
+
* @param props
|
7
|
+
* @returns
|
8
|
+
*/
|
9
|
+
export const GraphLinesContainer = (props) => {
|
10
|
+
const [{ start, delta }, dropRef] = useDrop(() => ({
|
11
|
+
accept: "connector",
|
12
|
+
canDrop: (item) => {
|
13
|
+
return item.parentContainerId === props.id;
|
14
|
+
},
|
15
|
+
collect: (monitor) => ({
|
16
|
+
start: monitor.getItem(),
|
17
|
+
delta: monitor.getDifferenceFromInitialOffset(),
|
18
|
+
}),
|
19
|
+
}));
|
20
|
+
return (_jsxs("svg", { width: "100%", height: "100%", ref: dropRef, children: [_jsx("defs", { children: _jsx("marker", { id: MarkerArrowId, markerWidth: "15", markerHeight: "15", refX: "5", refY: "5", orient: "auto", children: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", stroke: "black" }) }) }), props.children, start && start.parentContainerId === props.id && start.x !== undefined && start.y !== undefined && delta && (_jsx(GraphLine, { x1: start.x, y1: start.y, x2: start.x + delta.x, y2: start.y + delta.y, selected: false }))] }));
|
21
|
+
};
|
22
|
+
//# sourceMappingURL=GraphLinesContainer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphLinesContainer.js","sourceRoot":"","sources":["../../../../../../d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E,EAAE,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,GAAI,CACzG,IACC,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FC } from \"react\";\r\nimport type { DropTargetMonitor } from \"react-dnd\";\r\nimport { useDrop } from \"react-dnd\";\r\nimport { GraphLine, MarkerArrowId } from \"./GraphLine\";\r\n\r\n/**\r\n * props for the GraphLineContainer\r\n */\r\nexport interface IGraphLinesContainerProps {\r\n /**\r\n * id of the container\r\n */\r\n id: string;\r\n}\r\n\r\n/**\r\n * this component handles the dragging of new connections\r\n * @param props\r\n * @returns\r\n */\r\nexport const GraphLinesContainer: FC<IGraphLinesContainerProps> = (props) => {\r\n const [{ start, delta }, dropRef] = useDrop(() => ({\r\n accept: \"connector\",\r\n canDrop: (item: any) => {\r\n return item.parentContainerId === props.id;\r\n },\r\n collect: (monitor: DropTargetMonitor) => ({\r\n start: monitor.getItem() as any,\r\n delta: monitor.getDifferenceFromInitialOffset() as any,\r\n }),\r\n }));\r\n return (\r\n <svg width=\"100%\" height=\"100%\" ref={dropRef}>\r\n <defs>\r\n <marker id={MarkerArrowId} markerWidth=\"15\" markerHeight=\"15\" refX=\"5\" refY=\"5\" orient=\"auto\">\r\n <path d=\"M 0 0 L 10 5 L 0 10 z\" stroke=\"black\" />\r\n </marker>\r\n </defs>\r\n {props.children}\r\n {start && start.parentContainerId === props.id && start.x !== undefined && start.y !== undefined && delta && (\r\n <GraphLine x1={start.x} y1={start.y} x2={start.x + delta.x} y2={start.y + delta.y} selected={false} />\r\n )}\r\n </svg>\r\n );\r\n};\r\n"]}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
export interface IGraphNodeProps {
|
3
|
+
id: string;
|
4
|
+
name: string;
|
5
|
+
x: number;
|
6
|
+
y: number;
|
7
|
+
selected?: boolean;
|
8
|
+
width?: number;
|
9
|
+
height?: number;
|
10
|
+
highlighted?: boolean;
|
11
|
+
parentContainerId: string;
|
12
|
+
}
|
13
|
+
export declare const GraphNode: FC<IGraphNodeProps>;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useDrag } from "react-dnd";
|
3
|
+
import { ClassNames } from "../classNames.js";
|
4
|
+
import { GraphConnectorHandler } from "./GraphConnectorHandle.js";
|
5
|
+
import style from "./GraphNode.modules.scss";
|
6
|
+
import { useGraphContext } from "./useGraphContext.js";
|
7
|
+
export const GraphNode = (props) => {
|
8
|
+
const { id, name, x, y, selected, width = 100, height = 40, highlighted, parentContainerId } = props;
|
9
|
+
const { onNodeSelected } = useGraphContext();
|
10
|
+
const [, dragRef] = useDrag(() => ({
|
11
|
+
type: "node",
|
12
|
+
item: { id, parentContainerId },
|
13
|
+
collect: (monitor) => ({
|
14
|
+
isDrag: !!monitor.isDragging(),
|
15
|
+
}),
|
16
|
+
}), []);
|
17
|
+
const onClick = () => {
|
18
|
+
onNodeSelected && onNodeSelected(id);
|
19
|
+
};
|
20
|
+
return (_jsx("div", { ref: dragRef, className: ClassNames({ node: true, selected, highlighted }, style), style: { left: x, top: y, minWidth: width + "px", minHeight: height + "px" }, onClick: onClick, children: _jsxs("div", { className: style.container, children: [_jsx("h2", { children: name }), _jsx(GraphConnectorHandler, { parentContainerId: parentContainerId, parentId: id, parentX: x, parentY: y, offsetY: -height / 2, parentWidth: width, parentHeight: height }), props.children] }) }));
|
21
|
+
};
|
22
|
+
//# sourceMappingURL=GraphNode.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphNode.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphNode.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAA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,EAAE,KAAK,CAAC,SAAS,aAC3B,uBAAK,IAAI,GAAM,EACf,KAAC,qBAAqB,IAClB,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,EAAE,EACZ,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC,EACpB,WAAW,EAAE,KAAK,EAClB,YAAY,EAAE,MAAM,GACtB,EACD,KAAK,CAAC,QAAQ,IACb,GACJ,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { FC } from \"react\";\r\nimport { useDrag } from \"react-dnd\";\r\nimport { ClassNames } from \"../classNames\";\r\nimport { GraphConnectorHandler } from \"./GraphConnectorHandle\";\r\nimport style from \"./GraphNode.modules.scss\";\r\nimport { useGraphContext } from \"./useGraphContext\";\r\n\r\nexport interface IGraphNodeProps {\r\n id: string;\r\n name: string;\r\n x: number;\r\n y: number;\r\n selected?: boolean;\r\n width?: number;\r\n height?: number;\r\n highlighted?: boolean;\r\n parentContainerId: string;\r\n}\r\n\r\nexport const GraphNode: FC<IGraphNodeProps> = (props) => {\r\n const { id, name, x, y, selected, width = 100, height = 40, highlighted, parentContainerId } = props;\r\n const { onNodeSelected } = useGraphContext();\r\n\r\n const [, dragRef] = useDrag(\r\n () => ({\r\n type: \"node\",\r\n item: { id, parentContainerId },\r\n collect: (monitor) => ({\r\n isDrag: !!monitor.isDragging(),\r\n }),\r\n }),\r\n []\r\n );\r\n\r\n const onClick = () => {\r\n onNodeSelected && onNodeSelected(id);\r\n };\r\n\r\n return (\r\n <div\r\n ref={dragRef}\r\n className={ClassNames({ node: true, selected, highlighted }, style)}\r\n style={{ left: x, top: y, minWidth: width + \"px\", minHeight: height + \"px\" }}\r\n onClick={onClick}\r\n >\r\n <div className={style.container}>\r\n <h2>{name}</h2>\r\n <GraphConnectorHandler\r\n parentContainerId={parentContainerId}\r\n parentId={id}\r\n parentX={x}\r\n parentY={y}\r\n offsetY={-height / 2}\r\n parentWidth={width}\r\n parentHeight={height}\r\n />\r\n {props.children}\r\n </div>\r\n </div>\r\n );\r\n};\r\n"]}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
.node {
|
2
|
+
position: absolute;
|
3
|
+
background-color: #666666;
|
4
|
+
display: flex;
|
5
|
+
justify-content: center;
|
6
|
+
border: 1px solid #000000;
|
7
|
+
}
|
8
|
+
|
9
|
+
.selected {
|
10
|
+
border: 2px solid #ffffff;
|
11
|
+
}
|
12
|
+
|
13
|
+
.highlighted {
|
14
|
+
border: 2px solid hsl(64, 100%, 61%);
|
15
|
+
}
|
16
|
+
|
17
|
+
.container {
|
18
|
+
position: relative;
|
19
|
+
width: 100%;
|
20
|
+
height: 100%;
|
21
|
+
text-align: center;
|
22
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { FC } from "react";
|
2
|
+
export interface IGraphContainerProps {
|
3
|
+
onNodeMoved: (id: string, x: number, y: number) => void;
|
4
|
+
id: string;
|
5
|
+
}
|
6
|
+
/**
|
7
|
+
* This component contains all the nodes and handles their dragging
|
8
|
+
*/
|
9
|
+
export declare const GraphNodesContainer: FC<IGraphContainerProps>;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { Vector2 } from "@babylonjs/core/Maths/math.js";
|
3
|
+
import { useEffect, useRef } from "react";
|
4
|
+
import { useDragLayer } from "react-dnd";
|
5
|
+
/**
|
6
|
+
* This component contains all the nodes and handles their dragging
|
7
|
+
*/
|
8
|
+
export const GraphNodesContainer = (props) => {
|
9
|
+
const lastDragPos = useRef(null);
|
10
|
+
const { currentOffset, item, isDragging } = useDragLayer((monitor) => ({
|
11
|
+
currentOffset: monitor.getSourceClientOffset(),
|
12
|
+
item: monitor.getItem(),
|
13
|
+
isDragging: monitor.isDragging(),
|
14
|
+
}));
|
15
|
+
useEffect(() => {
|
16
|
+
var _a;
|
17
|
+
if (currentOffset && item) {
|
18
|
+
if (lastDragPos.current) {
|
19
|
+
const delta = new Vector2(currentOffset.x, currentOffset.y).subtract(lastDragPos.current);
|
20
|
+
(_a = props.onNodeMoved) === null || _a === void 0 ? void 0 : _a.call(props, item.id, delta.x, delta.y);
|
21
|
+
}
|
22
|
+
lastDragPos.current = new Vector2(currentOffset.x, currentOffset.y);
|
23
|
+
}
|
24
|
+
}, [currentOffset, item]);
|
25
|
+
useEffect(() => {
|
26
|
+
if (!isDragging) {
|
27
|
+
lastDragPos.current = null;
|
28
|
+
}
|
29
|
+
}, [isDragging]);
|
30
|
+
return _jsx("div", { children: props.children });
|
31
|
+
};
|
32
|
+
//# sourceMappingURL=GraphNodesContainer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"GraphNodesContainer.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/GraphNodesContainer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,sCAAwB;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAMzC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA6B,CAAC,KAAK,EAAE,EAAE;IACnE,MAAM,WAAW,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAEpD,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACnE,aAAa,EAAE,OAAO,CAAC,qBAAqB,EAAE;QAC9C,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE;QACvB,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;KACnC,CAAC,CAAC,CAAC;IAEJ,SAAS,CAAC,GAAG,EAAE;;QACX,IAAI,aAAa,IAAI,IAAI,EAAE;YACvB,IAAI,WAAW,CAAC,OAAO,EAAE;gBACrB,MAAM,KAAK,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;gBAC1F,MAAA,KAAK,CAAC,WAAW,sDAAG,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;aAClD;YACD,WAAW,CAAC,OAAO,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;SACvE;IACL,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1B,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,UAAU,EAAE;YACb,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;SAC9B;IACL,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACjB,OAAO,wBAAM,KAAK,CAAC,QAAQ,GAAO,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { Vector2 } from \"core/Maths/math\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { FC } from \"react\";\r\nimport { useEffect, useRef } from \"react\";\r\nimport { useDragLayer } from \"react-dnd\";\r\nexport interface IGraphContainerProps {\r\n onNodeMoved: (id: string, x: number, y: number) => void;\r\n id: string;\r\n}\r\n\r\n/**\r\n * This component contains all the nodes and handles their dragging\r\n */\r\nexport const GraphNodesContainer: FC<IGraphContainerProps> = (props) => {\r\n const lastDragPos = useRef<Nullable<Vector2>>(null);\r\n\r\n const { currentOffset, item, isDragging } = useDragLayer((monitor) => ({\r\n currentOffset: monitor.getSourceClientOffset(),\r\n item: monitor.getItem(),\r\n isDragging: monitor.isDragging(),\r\n }));\r\n\r\n useEffect(() => {\r\n if (currentOffset && item) {\r\n if (lastDragPos.current) {\r\n const delta = new Vector2(currentOffset.x, currentOffset.y).subtract(lastDragPos.current);\r\n props.onNodeMoved?.(item.id, delta.x, delta.y);\r\n }\r\n lastDragPos.current = new Vector2(currentOffset.x, currentOffset.y);\r\n }\r\n }, [currentOffset, item]);\r\n useEffect(() => {\r\n if (!isDragging) {\r\n lastDragPos.current = null;\r\n }\r\n }, [isDragging]);\r\n return <div>{props.children}</div>;\r\n};\r\n"]}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import type { ComponentType } from "react";
|
2
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
3
|
+
export declare type IVisualRecordsType = Record<string, {
|
4
|
+
x: number;
|
5
|
+
y: number;
|
6
|
+
}>;
|
7
|
+
export declare type IConnectionType = {
|
8
|
+
id: string;
|
9
|
+
sourceId: string;
|
10
|
+
targetId: string;
|
11
|
+
};
|
12
|
+
export declare type ICustomDataType = {
|
13
|
+
type: string;
|
14
|
+
value: any;
|
15
|
+
};
|
16
|
+
export declare type INodeType = {
|
17
|
+
id: string;
|
18
|
+
label: string;
|
19
|
+
customData?: ICustomDataType;
|
20
|
+
};
|
21
|
+
/**
|
22
|
+
* props for the node renderer
|
23
|
+
*/
|
24
|
+
export interface INodeRendererProps {
|
25
|
+
/**
|
26
|
+
* array of connections between nodes
|
27
|
+
*/
|
28
|
+
connections: IConnectionType[];
|
29
|
+
/**
|
30
|
+
* function called when a new connection is created
|
31
|
+
*/
|
32
|
+
updateConnections: (sourceId: string, targetId: string) => void;
|
33
|
+
/**
|
34
|
+
* function called when a connection is deleted
|
35
|
+
*/
|
36
|
+
deleteLine: (lineId: string) => void;
|
37
|
+
/**
|
38
|
+
* function called when a node is deleted
|
39
|
+
*/
|
40
|
+
deleteNode: (nodeId: string) => void;
|
41
|
+
/**
|
42
|
+
* array of all nodes
|
43
|
+
*/
|
44
|
+
nodes: INodeType[];
|
45
|
+
/**
|
46
|
+
* id of the node to highlight
|
47
|
+
*/
|
48
|
+
highlightedNode?: Nullable<string>;
|
49
|
+
/**
|
50
|
+
* function to be called if a node is selected
|
51
|
+
*/
|
52
|
+
selectNode?: (nodeId: Nullable<string>) => void;
|
53
|
+
/**
|
54
|
+
* id of this renderer
|
55
|
+
*/
|
56
|
+
id: string;
|
57
|
+
/**
|
58
|
+
* optional list of custom components to be rendered inside nodes of
|
59
|
+
* a certain type
|
60
|
+
*/
|
61
|
+
customComponents?: Record<string, ComponentType<any>>;
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* This component is a bridge between the app logic related to the graph, and the actual rendering
|
65
|
+
* of it. It manages the nodes' positions and selection states.
|
66
|
+
* @param props
|
67
|
+
* @returns
|
68
|
+
*/
|
69
|
+
export declare const NodeRenderer: (props: INodeRendererProps) => JSX.Element;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { useState, useEffect, useMemo } from "react";
|
3
|
+
import { GraphContainer } from "./GraphContainer.js";
|
4
|
+
import { GraphLine } from "./GraphLine.js";
|
5
|
+
import { GraphNode } from "./GraphNode.js";
|
6
|
+
import { GraphNodesContainer } from "./GraphNodesContainer.js";
|
7
|
+
import { GraphLinesContainer } from "./GraphLinesContainer.js";
|
8
|
+
import { GraphContextManager } from "./GraphContextManager.js";
|
9
|
+
const fullscreenStyle = { width: "100%", height: "100%" };
|
10
|
+
/**
|
11
|
+
* This component is a bridge between the app logic related to the graph, and the actual rendering
|
12
|
+
* of it. It manages the nodes' positions and selection states.
|
13
|
+
* @param props
|
14
|
+
* @returns
|
15
|
+
*/
|
16
|
+
export const NodeRenderer = (props) => {
|
17
|
+
const { nodes, connections, updateConnections, highlightedNode } = props;
|
18
|
+
// Store the nodes positions
|
19
|
+
const [pos, setPos] = useState({});
|
20
|
+
const [selectedLine, setSelectedLine] = useState(null);
|
21
|
+
const [selectedNode, setSelectedNode] = useState(null);
|
22
|
+
const updatePos = (id, x, y) => {
|
23
|
+
setPos((currentPos) => {
|
24
|
+
const currPos = currentPos[id] || { x: 0, y: 0 };
|
25
|
+
currentPos[id] = { x: currPos.x + x, y: currPos.y + y };
|
26
|
+
return { ...currentPos };
|
27
|
+
});
|
28
|
+
};
|
29
|
+
const onNodesConnected = (sourceId, targetId) => {
|
30
|
+
updateConnections(sourceId, targetId);
|
31
|
+
};
|
32
|
+
const onLineSelected = (lineId) => {
|
33
|
+
setSelectedLine(lineId);
|
34
|
+
setSelectedNode(null);
|
35
|
+
};
|
36
|
+
const onNodeSelected = (nodeId) => {
|
37
|
+
setSelectedNode(nodeId);
|
38
|
+
setSelectedLine(null);
|
39
|
+
};
|
40
|
+
useEffect(() => {
|
41
|
+
props.selectNode && props.selectNode(selectedNode);
|
42
|
+
}, [selectedNode]);
|
43
|
+
const onKeyDown = (evt) => {
|
44
|
+
if (evt.key === "Delete") {
|
45
|
+
if (selectedLine) {
|
46
|
+
props.deleteLine(selectedLine);
|
47
|
+
}
|
48
|
+
else if (selectedNode) {
|
49
|
+
props.deleteNode(selectedNode);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
};
|
53
|
+
useEffect(() => {
|
54
|
+
document.addEventListener("keydown", onKeyDown);
|
55
|
+
return () => {
|
56
|
+
document.removeEventListener("keydown", onKeyDown);
|
57
|
+
};
|
58
|
+
}, [selectedLine, selectedNode]);
|
59
|
+
const graphContext = useMemo(() => ({ updatePos, onNodesConnected, onLineSelected, onNodeSelected }), []);
|
60
|
+
return (_jsx("div", { style: fullscreenStyle, children: _jsx(GraphContextManager.Provider, { value: graphContext, children: _jsxs(GraphContainer, { children: [_jsx(GraphNodesContainer, { id: props.id, onNodeMoved: updatePos, children: nodes.map(({ id, label, customData }) => {
|
61
|
+
const posInRecord = pos[id] || { x: 0, y: 0 };
|
62
|
+
const CustomComponent = customData && customData.type && props.customComponents && props.customComponents[customData.type];
|
63
|
+
return (_jsx(GraphNode, { parentContainerId: props.id, id: id, name: label, x: posInRecord.x, y: posInRecord.y, selected: id === selectedNode, highlighted: id === highlightedNode, children: CustomComponent && _jsx(CustomComponent, { ...customData.value }) }, id));
|
64
|
+
}) }), _jsx(GraphLinesContainer, { id: props.id, children: connections.map(({ id, sourceId, targetId }) => {
|
65
|
+
const sourcePos = pos[sourceId] || { x: 0, y: 0 };
|
66
|
+
const targetPos = pos[targetId] || { x: 0, y: 0 };
|
67
|
+
return _jsx(GraphLine, { id: id, x1: sourcePos.x, y1: sourcePos.y, x2: targetPos.x, y2: targetPos.y, selected: id === selectedLine }, id);
|
68
|
+
}) })] }) }) }));
|
69
|
+
};
|
70
|
+
//# sourceMappingURL=NodeRenderer.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"NodeRenderer.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/NodeRenderer.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,MAAM,eAAe,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAkD1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAyB,EAAE,EAAE;IACtD,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IACzE,4BAA4B;IAC5B,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAqB,EAAE,CAAC,CAAC;IACvD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IACtE,MAAM,CAAC,YAAY,EAA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,EAChB,CAAC,EAAE,WAAW,CAAC,CAAC,EAChB,QAAQ,EAAE,EAAE,KAAK,YAAY,EAC7B,WAAW,EAAE,EAAE,KAAK,eAAe,YAElC,eAAe,IAAI,KAAC,eAAe,OAAK,UAAU,CAAC,KAAK,GAAI,IARxD,EAAE,CASC,CACf,CAAC;wBACN,CAAC,CAAC,GACgB,EACtB,KAAC,mBAAmB,IAAC,EAAE,EAAE,KAAK,CAAC,EAAE,YAC5B,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE;4BAC5C,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;4BAClD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;4BAClD,OAAO,KAAC,SAAS,IAAU,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,KAAK,YAAY,IAA7G,EAAE,CAA+G,CAAC;wBAC7I,CAAC,CAAC,GACgB,IACT,GACU,GAC7B,CACT,CAAC;AACN,CAAC,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\r\nimport { useState, useEffect, useMemo } from \"react\";\r\nimport { GraphContainer } from \"./GraphContainer\";\r\nimport { GraphLine } from \"./GraphLine\";\r\nimport { GraphNode } from \"./GraphNode\";\r\nimport { GraphNodesContainer } from \"./GraphNodesContainer\";\r\nimport { GraphLinesContainer } from \"./GraphLinesContainer\";\r\nimport { GraphContextManager } from \"./GraphContextManager\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\nconst fullscreenStyle = { width: \"100%\", height: \"100%\" };\r\n\r\nexport type IVisualRecordsType = Record<string, { x: number; y: number }>;\r\nexport type IConnectionType = { id: string; sourceId: string; targetId: string };\r\nexport type ICustomDataType = { type: string; value: any };\r\nexport type INodeType = { id: string; label: string; customData?: ICustomDataType };\r\n\r\n/**\r\n * props for the node renderer\r\n */\r\nexport interface INodeRendererProps {\r\n /**\r\n * array of connections between nodes\r\n */\r\n connections: IConnectionType[];\r\n /**\r\n * function called when a new connection is created\r\n */\r\n updateConnections: (sourceId: string, targetId: string) => void;\r\n /**\r\n * function called when a connection is deleted\r\n */\r\n deleteLine: (lineId: string) => void;\r\n /**\r\n * function called when a node is deleted\r\n */\r\n deleteNode: (nodeId: string) => void;\r\n /**\r\n * array of all nodes\r\n */\r\n nodes: INodeType[];\r\n /**\r\n * id of the node to highlight\r\n */\r\n highlightedNode?: Nullable<string>;\r\n /**\r\n * function to be called if a node is selected\r\n */\r\n selectNode?: (nodeId: Nullable<string>) => void;\r\n /**\r\n * id of this renderer\r\n */\r\n id: string;\r\n /**\r\n * optional list of custom components to be rendered inside nodes of\r\n * a certain type\r\n */\r\n customComponents?: Record<string, ComponentType<any>>;\r\n}\r\n\r\n/**\r\n * This component is a bridge between the app logic related to the graph, and the actual rendering\r\n * of it. It manages the nodes' positions and selection states.\r\n * @param props\r\n * @returns\r\n */\r\nexport const NodeRenderer = (props: INodeRendererProps) => {\r\n const { nodes, connections, updateConnections, highlightedNode } = props;\r\n // Store the nodes positions\r\n const [pos, setPos] = useState<IVisualRecordsType>({});\r\n const [selectedLine, setSelectedLine] = useState<string | null>(null);\r\n const [selectedNode, setSelectedNode] = useState<string | null>(null);\r\n\r\n const updatePos = (id: string, x: number, y: number) => {\r\n setPos((currentPos) => {\r\n const currPos = currentPos[id] || { x: 0, y: 0 };\r\n currentPos[id] = { x: currPos.x + x, y: currPos.y + y };\r\n return { ...currentPos };\r\n });\r\n };\r\n\r\n const onNodesConnected = (sourceId: string, targetId: string) => {\r\n updateConnections(sourceId, targetId);\r\n };\r\n\r\n const onLineSelected = (lineId: string) => {\r\n setSelectedLine(lineId);\r\n setSelectedNode(null);\r\n };\r\n\r\n const onNodeSelected = (nodeId: string) => {\r\n setSelectedNode(nodeId);\r\n setSelectedLine(null);\r\n };\r\n\r\n useEffect(() => {\r\n props.selectNode && props.selectNode(selectedNode);\r\n }, [selectedNode]);\r\n\r\n const onKeyDown = (evt: KeyboardEvent) => {\r\n if (evt.key === \"Delete\") {\r\n if (selectedLine) {\r\n props.deleteLine(selectedLine);\r\n } else if (selectedNode) {\r\n props.deleteNode(selectedNode);\r\n }\r\n }\r\n };\r\n\r\n useEffect(() => {\r\n document.addEventListener(\"keydown\", onKeyDown);\r\n return () => {\r\n document.removeEventListener(\"keydown\", onKeyDown);\r\n };\r\n }, [selectedLine, selectedNode]);\r\n\r\n const graphContext = useMemo(() => ({ updatePos, onNodesConnected, onLineSelected, onNodeSelected }), []);\r\n return (\r\n <div style={fullscreenStyle}>\r\n <GraphContextManager.Provider value={graphContext}>\r\n <GraphContainer>\r\n <GraphNodesContainer id={props.id} onNodeMoved={updatePos}>\r\n {nodes.map(({ id, label, customData }) => {\r\n const posInRecord = pos[id] || { x: 0, y: 0 };\r\n const CustomComponent = customData && customData.type && props.customComponents && props.customComponents[customData.type];\r\n return (\r\n <GraphNode\r\n parentContainerId={props.id}\r\n key={id}\r\n id={id}\r\n name={label}\r\n x={posInRecord.x}\r\n y={posInRecord.y}\r\n selected={id === selectedNode}\r\n highlighted={id === highlightedNode}\r\n >\r\n {CustomComponent && <CustomComponent {...customData.value} />}\r\n </GraphNode>\r\n );\r\n })}\r\n </GraphNodesContainer>\r\n <GraphLinesContainer id={props.id}>\r\n {connections.map(({ id, sourceId, targetId }) => {\r\n const sourcePos = pos[sourceId] || { x: 0, y: 0 };\r\n const targetPos = pos[targetId] || { x: 0, y: 0 };\r\n return <GraphLine key={id} id={id} x1={sourcePos.x} y1={sourcePos.y} x2={targetPos.x} y2={targetPos.y} selected={id === selectedLine} />;\r\n })}\r\n </GraphLinesContainer>\r\n </GraphContainer>\r\n </GraphContextManager.Provider>\r\n </div>\r\n );\r\n};\r\n"]}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { useContext } from "react";
|
2
|
+
import { GraphContextManager } from "./GraphContextManager.js";
|
3
|
+
/**
|
4
|
+
* utility hook to assist using the graph context
|
5
|
+
* @returns
|
6
|
+
*/
|
7
|
+
export const useGraphContext = () => {
|
8
|
+
const context = useContext(GraphContextManager);
|
9
|
+
return context;
|
10
|
+
};
|
11
|
+
//# sourceMappingURL=useGraphContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useGraphContext.js","sourceRoot":"","sources":["../../../../../../dev/sharedUiComponents/src/components/reactGraphSystem/useGraphContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE;IAChC,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { useContext } from \"react\";\r\nimport { GraphContextManager } from \"./GraphContextManager\";\r\n\r\n/**\r\n * utility hook to assist using the graph context\r\n * @returns\r\n */\r\nexport const useGraphContext = () => {\r\n const context = useContext(GraphContextManager);\r\n return context;\r\n};\r\n"]}
|