Files
EasyFlow/easyflow-ui-admin/packages/tinyflow-ui/src/components/utils/useGetNodesFromSource.svelte.ts
陈子默 7e7c236c2a fix: 修复管理端前端 lint 与构建问题
- 收敛 easyflow-ui-admin 的 lint、格式和类型问题

- 修正 demo 页面与管理端前端构建失败点

- 验证 pnpm lint 与 pnpm build 均已通过
2026-04-05 21:39:13 +08:00

32 lines
975 B
TypeScript

import { store } from '#store/stores.svelte';
import type { Edge, Node } from '@xyflow/svelte';
export const useGetNodesFromSource = () => {
const getEdgesBySource = (target: string, edges: Edge[]) => {
return edges.filter(
// 排除循环节点的子节点,否则在多层循环嵌套时不正确
(edge) => edge.source === target && edge.sourceHandle !== 'loop_handle',
);
};
const getNodesFromSource = (sourceNodeId: string) => {
const edges = store.getEdges();
const result: Node[] = [];
let edgesFromSource = getEdgesBySource(sourceNodeId, edges);
while (edgesFromSource.length > 0) {
const newEdgesFromSource: Edge[] = [];
edgesFromSource.forEach((edge) => {
result.push(store.getNode(edge.target)!);
newEdgesFromSource.push(...getEdgesBySource(edge.target, edges));
});
edgesFromSource = newEdgesFromSource;
}
return result;
};
return {
getNodesFromSource,
};
};