Line data Source code
1 : import { isEqual } from 'es-toolkit'
2 : import { effectScope, watch } from 'vue'
3 : import type { EffectScope } from 'vue'
4 :
5 : import { useChainCallback } from '@/composables/functional/useChainCallback'
6 : import { linkedConcatSlots } from '@/composables/videoConcat/linkedConcatSlots'
7 : import { translateOrder } from '@/composables/videoConcat/videoConcatOrder'
8 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
9 : import type { IVideoConcatWidget } from '@comfyorg/graph-model/widgets'
10 :
11 0 : export function syncConcatOrderWithLinks(
12 : node: LGraphNode,
13 : widget: IVideoConcatWidget,
14 : source: string
15 : ) {
16 0 : let scope: EffectScope | undefined
17 :
18 0 : function stop() {
19 0 : scope?.stop()
20 0 : scope = undefined
21 : }
22 :
23 0 : function start() {
24 0 : stop()
25 0 : scope = effectScope(true)
26 0 : scope.run(() => {
27 0 : watch(
28 : () => linkedConcatSlots(node, source),
29 : (current, previous) => {
30 0 : const order = widget.value.order ?? []
31 0 : const translated = translateOrder(order, previous, current)
32 0 : if (!isEqual(translated, order)) {
33 0 : widget.value = { ...widget.value, order: translated }
34 : }
35 : }
36 : )
37 : })
38 : }
39 :
40 0 : if (node.graph) start()
41 0 : node.onAdded = useChainCallback(node.onAdded, start)
42 0 : node.onRemoved = useChainCallback(node.onRemoved, stop)
43 : }
|