fix usenodedata
This commit is contained in:
@@ -56,11 +56,11 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "^3.3.1",
|
||||
"@sveltejs/kit": "^2.11.1",
|
||||
"@sveltejs/kit": "^2.12.1",
|
||||
"@sveltejs/package": "^2.3.7",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.2",
|
||||
"@typescript-eslint/eslint-plugin": "^8.18.0",
|
||||
"@typescript-eslint/parser": "^8.18.0",
|
||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||
"@typescript-eslint/eslint-plugin": "^8.18.1",
|
||||
"@typescript-eslint/parser": "^8.18.1",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"cssnano": "^7.0.6",
|
||||
"dotenv": "^16.4.7",
|
||||
@@ -75,12 +75,12 @@
|
||||
"postcss-rename": "^0.6.1",
|
||||
"prettier": "^3.4.2",
|
||||
"prettier-plugin-svelte": "^3.3.2",
|
||||
"svelte": "^5.9.0",
|
||||
"svelte": "^5.14.4",
|
||||
"svelte-check": "^4.1.1",
|
||||
"svelte-eslint-parser": "^0.43.0",
|
||||
"svelte-preprocess": "^6.0.3",
|
||||
"tslib": "^2.8.1",
|
||||
"typescript": "^5.5.0"
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"svelte": "^5.0.0"
|
||||
|
||||
+14
-6
@@ -1,4 +1,3 @@
|
||||
import { derived, type Readable } from 'svelte/store';
|
||||
import { shallowNodeData } from '@xyflow/system';
|
||||
|
||||
import type { Node } from '$lib/types';
|
||||
@@ -13,18 +12,20 @@ import { useStore } from '$lib/store';
|
||||
*/
|
||||
export function useNodesData<NodeType extends Node = Node>(
|
||||
nodeId: string
|
||||
): Readable<Pick<NodeType, 'id' | 'data' | 'type'> | null>;
|
||||
): { current: Pick<NodeType, 'id' | 'data' | 'type'> | null };
|
||||
export function useNodesData<NodeType extends Node = Node>(
|
||||
nodeIds: string[]
|
||||
): Readable<Pick<NodeType, 'id' | 'data' | 'type'>[]>;
|
||||
): { current: Pick<NodeType, 'id' | 'data' | 'type'>[] };
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function useNodesData(nodeIds: any): any {
|
||||
const { nodes, nodeLookup } = useStore();
|
||||
const { nodes, nodeLookup } = $derived(useStore());
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let prevNodesData: any[] = [];
|
||||
let initialRun = true;
|
||||
|
||||
return derived([nodes, nodeLookup], ([, nodeLookup], set) => {
|
||||
const nodeData = $derived.by(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
nodes;
|
||||
const nextNodesData = [];
|
||||
const isArrayOfIds = Array.isArray(nodeIds);
|
||||
const _nodeIds = isArrayOfIds ? nodeIds : [nodeIds];
|
||||
@@ -42,8 +43,15 @@ export function useNodesData(nodeIds: any): any {
|
||||
|
||||
if (!shallowNodeData(nextNodesData, prevNodesData) || initialRun) {
|
||||
prevNodesData = nextNodesData;
|
||||
set(isArrayOfIds ? nextNodesData : (nextNodesData[0] ?? null));
|
||||
initialRun = false;
|
||||
}
|
||||
|
||||
return isArrayOfIds ? prevNodesData : (prevNodesData[0] ?? null);
|
||||
});
|
||||
|
||||
return {
|
||||
get current() {
|
||||
return nodeData;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export * from '$lib/hooks/useUpdateNodeInternals.svelte';
|
||||
export * from '$lib/hooks/useConnection.svelte';
|
||||
export * from '$lib/hooks/useNodesEdgesViewport.svelte';
|
||||
export * from '$lib/hooks/useHandleConnections.svelte';
|
||||
export * from '$lib/hooks/useNodesData';
|
||||
export * from '$lib/hooks/useNodesData.svelte';
|
||||
export * from '$lib/hooks/useInternalNode';
|
||||
export { useInitialized, useNodesInitialized } from '$lib/hooks/useInitialized';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user