-
When working with a selected node (or multiple selected nodes with shift click), how does one address the selection to do things like delete them from the root svelvet node? I can think of a few different ways to do this, but wondering what the preferred/idiomatic approach would be. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Looking through the code, I devised this solution for others who also might be wondering: within a child component of import { getContext } from 'svelte';
import type { Graph } from 'svelvet';
const graph = getContext<graph>('graph'); With that in hand, the graph has a OK given that infrastructure knowledge. we can read from the store like so: import { get } from 'svelte/store';
const nodes = get(get(graph.groups).selected.nodes); Note that those nodes returned are yet another store see the I use this approach to get the node IDs: const nodeIds = Array.from(nodes).filter((node) => 'id' in node) as unknown as Node[]; Lastly, I can finally delete the nodes from the graph using That's how it's done. Or at least, that's how I did it. If there's a better solution, I'm all ears! |
Beta Was this translation helpful? Give feedback.
Looking through the code, I devised this solution for others who also might be wondering:
within a child component of
<Svelvet>
you can request the innerGraph
context like so:With that in hand, the graph has a
groups
property which is a writable store ofGroups
(definition here). Notice theGroupKey
(definition here) can be the literalselected
.OK given that infrastructure knowledge. we can read from the store like so:
Note that those nodes returned are yet another store see the
Group
…