17 lines
588 B
TypeScript
17 lines
588 B
TypeScript
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;
|
|
}
|
|
);
|
|
}
|