From 68ba9075e93a5ae766dc64b68eeaa121e9b77b14 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:48:16 +0100 Subject: [PATCH] feat(core,composables): add type and id to `useNodesData` --- packages/core/src/composables/useNodesData.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core/src/composables/useNodesData.ts b/packages/core/src/composables/useNodesData.ts index d3dc6002..2c0a8a41 100644 --- a/packages/core/src/composables/useNodesData.ts +++ b/packages/core/src/composables/useNodesData.ts @@ -1,9 +1,10 @@ import type { ComputedRef, MaybeRefOrGetter } from 'vue' import { computed, toValue } from 'vue' import type { GraphNode, Node } from '../types' +import { warn } from '../utils' import { useVueFlow } from './useVueFlow' -type NodeData = NonNullable +type NodeData = NonNullable & { id: string; type: NodeType['type'] } /** * Composable for receiving data of one or multiple nodes @@ -31,23 +32,30 @@ export function useNodesData(_nodeIds: any): any { const nodeIds = toValue(_nodeIds) if (!Array.isArray(nodeIds)) { - return findNode(nodeIds)?.data || null + const node = findNode(nodeIds) + + return node?.data ?? null } const data = [] for (const nodeId of nodeIds) { - const nodeData = findNode(nodeId)?.data + const node = findNode(nodeId) - if (nodeData) { - data.push(nodeData) + if (node) { + data.push({ + id: node.id, + type: node.type, + data: node.data, + }) } } return data }, set() { - console.warn('You are trying to set node data via useNodesData. This is not supported.') + // noop + warn('You are trying to set node data via useNodesData. This is not supported.') }, }) }