Skip to content

Commit 68ba907

Browse files
committed
feat(core,composables): add type and id to useNodesData
1 parent 5336209 commit 68ba907

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

packages/core/src/composables/useNodesData.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { ComputedRef, MaybeRefOrGetter } from 'vue'
22
import { computed, toValue } from 'vue'
33
import type { GraphNode, Node } from '../types'
4+
import { warn } from '../utils'
45
import { useVueFlow } from './useVueFlow'
56

6-
type NodeData<NodeType extends Node = GraphNode> = NonNullable<NodeType['data']>
7+
type NodeData<NodeType extends Node = GraphNode> = NonNullable<NodeType['data']> & { id: string; type: NodeType['type'] }
78

89
/**
910
* Composable for receiving data of one or multiple nodes
@@ -31,23 +32,30 @@ export function useNodesData(_nodeIds: any): any {
3132
const nodeIds = toValue(_nodeIds)
3233

3334
if (!Array.isArray(nodeIds)) {
34-
return findNode(nodeIds)?.data || null
35+
const node = findNode(nodeIds)
36+
37+
return node?.data ?? null
3538
}
3639

3740
const data = []
3841

3942
for (const nodeId of nodeIds) {
40-
const nodeData = findNode(nodeId)?.data
41-
42-
if (nodeData) {
43-
data.push(nodeData)
43+
const node = findNode(nodeId)
44+
45+
if (node) {
46+
data.push({
47+
id: node.id,
48+
type: node.type,
49+
data: node.data,
50+
})
4451
}
4552
}
4653

4754
return data
4855
},
4956
set() {
50-
console.warn('You are trying to set node data via useNodesData. This is not supported.')
57+
// noop
58+
warn('You are trying to set node data via useNodesData. This is not supported.')
5159
},
5260
})
5361
}

0 commit comments

Comments
 (0)