7878
7979<script setup lang="ts">
8080import ToggleSwitch from ' primevue/toggleswitch'
81- import { computed , shallowRef , triggerRef , watchEffect } from ' vue'
81+ import { computed } from ' vue'
8282import { useI18n } from ' vue-i18n'
8383
8484import { LGraphCanvas , LiteGraph } from ' @/lib/litegraph/src/litegraph'
@@ -90,8 +90,7 @@ import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
9090import { adjustColor } from ' @/utils/colorUtil'
9191import { cn } from ' @/utils/tailwindUtil'
9292
93- const props = defineProps <{
94- node? : LGraphNode
93+ const { nodes = [] } = defineProps <{
9594 nodes? : LGraphNode []
9695}>()
9796
@@ -103,48 +102,35 @@ const isLightTheme = computed(
103102 () => colorPaletteStore .completedActivePalette .light_theme
104103)
105104
106- const targetNodes = shallowRef <LGraphNode []>([])
107- watchEffect (() => {
108- if (props .node ) {
109- targetNodes .value = [props .node ]
110- } else {
111- targetNodes .value = props .nodes || []
112- }
113- })
114-
115105const nodeState = computed ({
116- get() {
117- let mode: LGraphNode [' mode' ] | null = null
118-
106+ get(): LGraphNode [' mode' ] | null {
119107 // For multiple nodes, if all nodes have the same mode, return that mode, otherwise return null
120- if (targetNodes . value . length > 1 ) {
121- mode = targetNodes . value [0 ].mode
122- if ( ! targetNodes . value . every (( node ) => node . mode === mode )) {
123- mode = null
124- }
125- } else {
126- mode = targetNodes . value [ 0 ]. mode
108+ if (nodes . length == 1 ) {
109+ return nodes [0 ].mode
110+ }
111+
112+ const mode : LGraphNode [ ' mode ' ] = nodes [ 0 ]. mode
113+ if ( ! nodes . every (( node ) => node . mode === mode )) {
114+ return null
127115 }
128116
129117 return mode
130118 },
131119 set(value : LGraphNode [' mode' ]) {
132- targetNodes . value .forEach ((node ) => {
120+ nodes .forEach ((node ) => {
133121 node .mode = value
134122 })
135- triggerRef (targetNodes )
136123 canvasStore .canvas ?.setDirty (true , true )
137124 }
138125})
139126
140127// Pinned state
141128const isPinned = computed <boolean >({
142129 get() {
143- return targetNodes . value .some ((node ) => node .pinned )
130+ return nodes .some ((node ) => node .pinned )
144131 },
145132 set(value ) {
146- targetNodes .value .forEach ((node ) => node .pin (value ))
147- triggerRef (targetNodes )
133+ nodes .forEach ((node ) => node .pin (value ))
148134 canvasStore .canvas ?.setDirty (true , true )
149135 }
150136})
@@ -188,10 +174,8 @@ const colorOptions: NodeColorOption[] = [
188174
189175const nodeColor = computed <NodeColorOption [' name' ] | null >({
190176 get() {
191- if (targetNodes .value .length === 0 ) return null
192- const theColorOptions = targetNodes .value .map ((item ) =>
193- item .getColorOption ()
194- )
177+ if (nodes .length === 0 ) return null
178+ const theColorOptions = nodes .map ((item ) => item .getColorOption ())
195179
196180 let colorOption: ColorOption | null | false = theColorOptions [0 ]
197181 if (! theColorOptions .every ((option ) => option === colorOption )) {
@@ -217,10 +201,9 @@ const nodeColor = computed<NodeColorOption['name'] | null>({
217201 ? null
218202 : LGraphCanvas .node_colors [colorName ]
219203
220- for (const item of targetNodes . value ) {
204+ for (const item of nodes ) {
221205 item .setColorOption (canvasColorOption )
222206 }
223- triggerRef (targetNodes )
224207 canvasStore .canvas ?.setDirty (true , true )
225208 }
226209})
0 commit comments