feat(svelte): add onlyRenderVisibleElements option

This commit is contained in:
moklick
2023-06-08 16:31:39 +02:00
parent 7e64969cd3
commit 0739528761
8 changed files with 33 additions and 5 deletions
@@ -0,0 +1,16 @@
import { derived } from 'svelte/store';
import { getNodesInside } from '@xyflow/system';
import type { Node } from '$lib/types';
import type { SvelteFlowStoreState } from './types';
export function getVisibleNodes(store: SvelteFlowStoreState) {
return derived(
[store.nodes, store.onlyRenderVisibleElements, store.width, store.height, store.transform],
([nodes, onlyRenderVisibleElements, width, height, transform]) => {
return onlyRenderVisibleElements
? getNodesInside<Node>(nodes, { x: 0, y: 0, width, height }, transform, true)
: nodes;
}
);
}