open-source-labs / Svelvet

🎛 A Svelte library for building dynamic, infinitely customizable node-based user interfaces and flowcharts
https://svelvet.io
2.5k stars 161 forks source link

Event for when node is selected? #454

Open DanielSidhion opened 11 months ago

DanielSidhion commented 11 months ago

I want to run some code whenever a node gets selected or deselected. I know that Node provides a selected prop through a let: directive, but due to how Svelte's let: directives work, there isn't an easy way of running some code whenever that value changes. Currently, my workaround hack is to have the following code:

<script>
  function nodeSelected(value) {
    // Do something here.
  }
</script>

<Node let:selected ...>
  {@const _ = nodeSelected(selected)}
</Node>

Node has nodeClicked and nodeReleased events, but they're not 100% the same as selected. For example, if someone selects a node by dragging a selection box around it, none of those events get fired, but the node still gets selected.

Is there a way a node can get an event when it gets selected or deselected? I'm willing to contribute a PR, but I'm asking here before spending time to code this.