Line data Source code
1 : <template>
2 21 : <div class="space-y-4 text-sm text-muted-foreground">
3 : <SetNodeState
4 : v-if="isNodes(targetNodes)"
5 : :nodes="targetNodes"
6 : @changed="handleChanged"
7 : />
8 : <SetNodeColor :nodes="targetNodes" @changed="handleChanged" />
9 : <SetPinned :nodes="targetNodes" @changed="handleChanged" />
10 : </div>
11 : </template>
12 :
13 : <script setup lang="ts">
14 : import { shallowRef, watchEffect } from 'vue'
15 :
16 : import type { LGraphGroup, LGraphNode } from '@/lib/litegraph/src/litegraph'
17 : import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
18 : import { isLGraphGroup } from '@/utils/litegraphUtil'
19 :
20 : import SetNodeColor from './SetNodeColor.vue'
21 : import SetNodeState from './SetNodeState.vue'
22 : import SetPinned from './SetPinned.vue'
23 :
24 11 : const props = defineProps<{
25 : /**
26 : * - If the item is a Group, Node State cannot be set
27 : * as Groups do not have a 'mode' property.
28 : *
29 : * - The nodes array can contain either all Nodes or all Groups,
30 : * but it must not be a mix of both.
31 : */
32 : nodes?: LGraphNode[] | LGraphGroup[]
33 : }>()
34 :
35 11 : const targetNodes = shallowRef<LGraphNode[] | LGraphGroup[]>([])
36 11 : watchEffect(() => {
37 11 : if (props.nodes) {
38 11 : targetNodes.value = props.nodes
39 : } else {
40 0 : targetNodes.value = []
41 : }
42 : })
43 :
44 11 : const canvasStore = useCanvasStore()
45 :
46 21 : function isNodes(nodes: LGraphNode[] | LGraphGroup[]): nodes is LGraphNode[] {
47 21 : return !nodes.some((node) => isLGraphGroup(node))
48 : }
49 :
50 10 : function handleChanged() {
51 : /**
52 : * This is not a random comment—it's crucial.
53 : * Otherwise, the UI cannot update correctly.
54 : * There is a bug with triggerRef here, so we can't use triggerRef.
55 : * We'll work around it for now and later submit a Vue issue and pull request to fix it.
56 : */
57 10 : targetNodes.value = targetNodes.value.slice()
58 :
59 10 : canvasStore.canvas?.setDirty(true, true)
60 : }
61 : </script>
|