feat(core,composables): add useNodesInitialized composable

This commit is contained in:
braks
2024-02-03 19:39:49 +01:00
committed by Braks
parent eb78f77c72
commit f2165afe6f
3 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import { computed } from 'vue'
import { useVueFlow } from './useVueFlow'
export interface UseNodesInitializedOptions {
includeHiddenNodes?: boolean
}
export function useNodesInitialized(options: UseNodesInitializedOptions = { includeHiddenNodes: false }) {
const { nodes } = useVueFlow()
return computed(() => {
if (nodes.value.length === 0) {
return false
}
for (const node of nodes.value) {
if (options.includeHiddenNodes || !node.hidden) {
if (node?.handleBounds === undefined) {
return false
}
}
}
return true
})
}

View File

@@ -71,6 +71,7 @@ export { useNodeId } from './composables/useNodeId'
export { useConnection } from './composables/useConnection'
export { useHandleConnections } from './composables/useHandleConnections'
export { useNodesData } from './composables/useNodesData'
export { useNodesInitialized } from './composables/useNodesInitialized'
export { VueFlowError, ErrorCode, isErrorOfType } from './utils/errors'

View File

@@ -125,10 +125,16 @@ export function useGetters(state: State, nodeIds: ComputedRef<string[]>, edgeIds
...(getSelectedEdges.value ?? []),
])
/**
* @deprecated will be removed in next major version; use `useNodesInitialized` instead
*/
const getNodesInitialized: ComputedGetters['getNodesInitialized'] = computed(() =>
getNodes.value.filter((n) => n.initialized && n.handleBounds !== undefined),
)
/**
* @deprecated will be removed in next major version; use `useNodesInitialized` instead
*/
const areNodesInitialized: ComputedGetters['areNodesInitialized'] = computed(
() => getNodes.value.length > 0 && getNodesInitialized.value.length === getNodes.value.length,
)