arrow on edge
This commit is contained in:
parent
24f05126c1
commit
4d19883cc7
1 changed files with 29 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import { cloneDeep } from "lodash";
|
||||||
import {
|
import {
|
||||||
Edge,
|
Edge,
|
||||||
EdgeChange,
|
EdgeChange,
|
||||||
|
MarkerType,
|
||||||
Node,
|
Node,
|
||||||
NodeChange,
|
NodeChange,
|
||||||
addEdge,
|
addEdge,
|
||||||
|
|
@ -9,6 +10,7 @@ import {
|
||||||
applyNodeChanges,
|
applyNodeChanges,
|
||||||
} from "reactflow";
|
} from "reactflow";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
import { INPUT_TYPES, OUTPUT_TYPES } from "../constants/constants";
|
||||||
import { updateFlowInDatabase } from "../controllers/API";
|
import { updateFlowInDatabase } from "../controllers/API";
|
||||||
import {
|
import {
|
||||||
NodeDataType,
|
NodeDataType,
|
||||||
|
|
@ -27,6 +29,7 @@ import {
|
||||||
} from "../utils/reactflowUtils";
|
} from "../utils/reactflowUtils";
|
||||||
import { getInputsAndOutputs } from "../utils/storeUtils";
|
import { getInputsAndOutputs } from "../utils/storeUtils";
|
||||||
import useAlertStore from "./alertStore";
|
import useAlertStore from "./alertStore";
|
||||||
|
import { useDarkStore } from "./darkStore";
|
||||||
import useFlowsManagerStore from "./flowsManagerStore";
|
import useFlowsManagerStore from "./flowsManagerStore";
|
||||||
|
|
||||||
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
// this is our useStore hook that we can use in our components to get parts of the store and call actions
|
||||||
|
|
@ -296,6 +299,29 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
},
|
},
|
||||||
getFilterEdge: [],
|
getFilterEdge: [],
|
||||||
onConnect: (connection) => {
|
onConnect: (connection) => {
|
||||||
|
const dark = useDarkStore.getState().dark;
|
||||||
|
const commonMarkerProps = {
|
||||||
|
type: MarkerType.ArrowClosed,
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
color: dark ? "#555555" : "#000000",
|
||||||
|
};
|
||||||
|
|
||||||
|
const inputTypes = INPUT_TYPES;
|
||||||
|
const outputTypes = OUTPUT_TYPES;
|
||||||
|
|
||||||
|
const findNode = useFlowStore
|
||||||
|
.getState()
|
||||||
|
.nodes.find(
|
||||||
|
(node) => node.id === connection.source || node.id === connection.target
|
||||||
|
);
|
||||||
|
const sourceType = findNode?.data?.type;
|
||||||
|
let isIo = false;
|
||||||
|
if (sourceType) {
|
||||||
|
isIo = inputTypes.has(sourceType);
|
||||||
|
isIo = outputTypes.has(sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
let newEdges: Edge[] = [];
|
let newEdges: Edge[] = [];
|
||||||
get().setEdges((oldEdges) => {
|
get().setEdges((oldEdges) => {
|
||||||
newEdges = addEdge(
|
newEdges = addEdge(
|
||||||
|
|
@ -314,9 +340,12 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
animated:
|
animated:
|
||||||
(scapeJSONParse(connection.targetHandle!) as targetHandleType)
|
(scapeJSONParse(connection.targetHandle!) as targetHandleType)
|
||||||
.type === "Text",
|
.type === "Text",
|
||||||
|
markerEnd: isIo ? { ...commonMarkerProps } : undefined,
|
||||||
|
markerStart: isIo ? { ...commonMarkerProps } : undefined,
|
||||||
},
|
},
|
||||||
oldEdges
|
oldEdges
|
||||||
);
|
);
|
||||||
|
|
||||||
return newEdges;
|
return newEdges;
|
||||||
});
|
});
|
||||||
useFlowsManagerStore
|
useFlowsManagerStore
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue