Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to restrict the node to single input #35

Closed
FrancisND opened this issue Aug 26, 2020 · 10 comments
Closed

How to restrict the node to single input #35

FrancisND opened this issue Aug 26, 2020 · 10 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@FrancisND
Copy link

FrancisND commented Aug 26, 2020

I really like your project and willing to use it but I have a question according to my requirement.
Is it possible to restrict the node to a single input ?

Also, Can we customize it?

@jerosoler jerosoler self-assigned this Aug 26, 2020
@jerosoler jerosoler added the help wanted Extra attention is needed label Aug 26, 2020
@jerosoler
Copy link
Owner

Hello @freesix

Thanks! ❤️

An input could be restricted with functions and events. Or you can modify the library.

For example:

editor.on("connectionCreated", function(info) {
  const nodeInfo = editor.getNodeFromId(info.input_id);
  if(nodeInfo.inputs[info.input_class].connections.length > 1) {
    const removeConnectionInfo = nodeInfo.inputs[info.input_class].connections[0];
    editor.removeSingleConnection(removeConnectionInfo.node, info.input_id, removeConnectionInfo.input, info.input_class);
  }
});

This example deletes the first connection and only keeps the last one.

@muratcim
Copy link

Thank you @jerosoler

How can we do the same for output. Output only to bind to an input

@jerosoler
Copy link
Owner

Hello @muratcim

Following the example above.

For example:

editor.on("connectionCreated", function(info) {
  const nodeInfo = editor.getNodeFromId(info.output_id);
  if(nodeInfo.outputs[info.output_class].connections.length > 1) {
    const removeConnectionInfo = nodeInfo.outputs[info.output_class].connections[0];
    editor.removeSingleConnection(info.output_id, removeConnectionInfo.node, info.output_class, removeConnectionInfo.output);
  }
});

@muratcim
Copy link

Thank you @jerosoler
it worked

Best Regards

@dotrungit91
Copy link

@jerosoler
I'm so glad I found this tutorial.
But there is a problem as follows:
I want to catch delete event and call api( when use delete on keyboard and right click to connection)

this.editor.on('connectionRemoved', (info) => { // call delete api })

But according to the instructions above,
every times restrict the node, it will automatically call the api.

@jerosoler
Copy link
Owner

It is only called if a connection is deleted.

@dotrungit91
Copy link

It is only called if a connection is deleted.

@jerosoler
yes sir, i just want to call the api when delete key is pressed or when right click. But when have more than one connection on input, it will automatically call the method removeSingleConnection.

@jerosoler
Copy link
Owner

You can create something like this.

let deleteConnectionAuto = false;

editor.on("connectionCreated", function(info) {
  const nodeInfo = editor.getNodeFromId(info.output_id);
  if(nodeInfo.outputs[info.output_class].connections.length > 1) {
    const removeConnectionInfo = nodeInfo.outputs[info.output_class].connections[0];
    deleteConnectionAuto = true;
    editor.removeSingleConnection(info.output_id, removeConnectionInfo.node, info.output_class, removeConnectionInfo.output);
  }
});

this.editor.on('connectionRemoved', (info) => { 
    if(!deleteConnectionAuto) {
        // call delete api
    } else {
        deleteConnectionAuto = false;
    }
})

@dotrungit91
Copy link

@jerosoler i loving you !!!!

@viniciusverasdossantos
Copy link

const nodeInfo = editor.getNodeFromId(info.output_id);
  if(nodeInfo.outputs[info.output_class].connections.length > 1) {
    const removeConnectionInfo = nodeInfo.outputs[info.output_class].connections[0];
    editor.removeSingleConnection(info.output_id, removeConnectionInfo.node, info.output_class, removeConnectionInfo.output);
  }

This code doesn't work for me. I'm using version .59
Is there another way?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants