feat(core,composables): add useNodesInitialized composable
This commit is contained in:
26
packages/core/src/composables/useNodesInitialized.ts
Normal file
26
packages/core/src/composables/useNodesInitialized.ts
Normal 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
|
||||
})
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user