move handleEdgeSelection into store, fix hooks

This commit is contained in:
peterkogo
2024-12-18 16:20:37 +01:00
parent 988a0cb7d7
commit 19e233af2d
10 changed files with 66 additions and 63 deletions
@@ -0,0 +1,25 @@
import { useStore } from '$lib/store';
import type { InternalNode } from '$lib/types';
/**
* Hook to get an internal node by id.
*
* @public
* @param id - the node id
* @returns a readable with an internal node or undefined
*/
export function useInternalNode(id: string): { current: InternalNode | undefined } {
const { nodeLookup, nodes } = $derived(useStore());
const node = $derived.by(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
nodes;
return nodeLookup.get(id);
});
return {
get current() {
return node;
}
};
}