getNodes & getEdges can be called without specifying ids

This commit is contained in:
peterkogo
2024-01-22 16:38:00 +01:00
parent aee1b6b9f8
commit 08bb803ef2
+14 -4
View File
@@ -30,9 +30,9 @@ export function useSvelteFlow(): {
zoomIn: ZoomInOut; zoomIn: ZoomInOut;
zoomOut: ZoomInOut; zoomOut: ZoomInOut;
getNode: (id: string) => Node | undefined; getNode: (id: string) => Node | undefined;
getNodes: (ids: string[]) => (Node | undefined)[]; getNodes: (ids?: string[]) => (Node | undefined)[];
getEdge: (id: string) => Edge | undefined; getEdge: (id: string) => Edge | undefined;
getEdges: (ids: string[]) => (Edge | undefined)[]; getEdges: (ids?: string[]) => (Edge | undefined)[];
setZoom: (zoomLevel: number, options?: ViewportHelperFunctionOptions) => void; setZoom: (zoomLevel: number, options?: ViewportHelperFunctionOptions) => void;
getZoom: () => number; getZoom: () => number;
setCenter: (x: number, y: number, options?: SetCenterOptions) => void; setCenter: (x: number, y: number, options?: SetCenterOptions) => void;
@@ -128,9 +128,19 @@ export function useSvelteFlow(): {
zoomIn, zoomIn,
zoomOut, zoomOut,
getNode: (id) => get(nodeLookup).get(id), getNode: (id) => get(nodeLookup).get(id),
getNodes: (ids) => ids.map((id) => get(nodeLookup).get(id)), getNodes: (ids) => {
if (!ids) {
return get(nodes);
}
return ids.map((id) => get(nodeLookup).get(id));
},
getEdge: (id) => get(edgeLookup).get(id), getEdge: (id) => get(edgeLookup).get(id),
getEdges: (ids) => ids.map((id) => get(edgeLookup).get(id)), getEdges: (ids) => {
if (!ids) {
return get(edges);
}
return ids.map((id) => get(edgeLookup).get(id));
},
setZoom: (zoomLevel, options) => { setZoom: (zoomLevel, options) => {
get(panZoom)?.scaleTo(zoomLevel, { duration: options?.duration }); get(panZoom)?.scaleTo(zoomLevel, { duration: options?.duration });
}, },