Line data Source code
1 : import { onScopeDispose } from 'vue'
2 :
3 : import {
4 : clearRevealedLinks,
5 : setRevealedLinks
6 : } from '@/lib/litegraph/src/canvas/linkRevealState'
7 : import type { LinkRevealKind } from '@/lib/litegraph/src/canvas/linkRevealState'
8 : import { app } from '@/scripts/app'
9 : import { useLinkPresentationStore } from '@/stores/linkPresentationStore'
10 : import { useLinkStore } from '@/stores/linkStore'
11 : import { graphScopeOf } from '@comfyorg/graph-model/graphScopeId'
12 : import type { NodeId } from '@comfyorg/graph-model/nodeId'
13 :
14 : interface SlotLinkRevealOptions {
15 : nodeId?: NodeId
16 : index: number
17 : type: 'input' | 'output'
18 : kind?: LinkRevealKind
19 : }
20 :
21 71390 : export function useSlotLinkReveal(options: SlotLinkRevealOptions) {
22 71390 : const owner = {}
23 :
24 224 : function revealLinks(): void {
25 224 : const graph = app.canvas.graph
26 224 : if (!graph || options.nodeId === undefined) return
27 :
28 224 : const scope = graphScopeOf(graph)
29 224 : const linkStore = useLinkStore()
30 224 : const presentationStore = useLinkPresentationStore()
31 : const links =
32 : options.type === 'output'
33 : ? [
34 : ...linkStore.getOutputSlotLinks(
35 : scope,
36 : options.nodeId,
37 : options.index
38 : )
39 : ]
40 : : [linkStore.getInputSlotLink(scope, options.nodeId, options.index)]
41 224 : const linkIds = links.flatMap((link) =>
42 : link && presentationStore.getPresentation(scope, link.id)?.hidden
43 : ? [link.id]
44 : : []
45 : )
46 224 : if (setRevealedLinks(scope.rootGraphId, linkIds, owner, options.kind)) {
47 8 : app.canvas.setDirty(false, true)
48 : }
49 : }
50 :
51 47570 : function unrevealLinks(): void {
52 47570 : if (clearRevealedLinks(owner)) app.canvas.setDirty(false, true)
53 : }
54 :
55 71390 : onScopeDispose(unrevealLinks)
56 :
57 71390 : return { revealLinks, unrevealLinks }
58 : }
|