Fixed nodes cant be dropped when refreshing page
This commit is contained in:
parent
bacab7dbc1
commit
9ec2fe445d
1 changed files with 5 additions and 15 deletions
|
|
@ -242,33 +242,23 @@ export default function Page({
|
||||||
takeSnapshot();
|
takeSnapshot();
|
||||||
|
|
||||||
// Extract the data from the drag event and parse it as a JSON object
|
// Extract the data from the drag event and parse it as a JSON object
|
||||||
let data: { type: string; node?: APIClassType } = JSON.parse(
|
const data: { type: string; node?: APIClassType } = JSON.parse(
|
||||||
event.dataTransfer.getData("nodedata")
|
event.dataTransfer.getData("nodedata")
|
||||||
);
|
);
|
||||||
|
|
||||||
// Calculate the position where the node should be created
|
const newId = getNodeId(data.type);
|
||||||
const position = reactFlowInstance!.screenToFlowPosition({
|
|
||||||
x: event.clientX,
|
|
||||||
y: event.clientY,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Generate a unique node ID
|
const newNode: NodeType = {
|
||||||
let { type } = data;
|
|
||||||
let newId = getNodeId(type);
|
|
||||||
let newNode: NodeType;
|
|
||||||
|
|
||||||
// Create a new node object
|
|
||||||
newNode = {
|
|
||||||
id: newId,
|
id: newId,
|
||||||
type: "genericNode",
|
type: "genericNode",
|
||||||
position,
|
position: {x: 0, y:0},
|
||||||
data: {
|
data: {
|
||||||
...data,
|
...data,
|
||||||
id: newId,
|
id: newId,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
paste({ nodes: [newNode], edges: [] }, {x: event.clientX, y: event.clientY});
|
||||||
|
|
||||||
setNodes((nds) => nds.concat(newNode));
|
|
||||||
} else if (event.dataTransfer.types.some((types) => types === "Files")) {
|
} else if (event.dataTransfer.types.some((types) => types === "Files")) {
|
||||||
takeSnapshot();
|
takeSnapshot();
|
||||||
if (event.dataTransfer.files.item(0)!.type === "application/json") {
|
if (event.dataTransfer.files.item(0)!.type === "application/json") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue