[backport cloud/1.35] fix: right side panel visual indicators don't update for color picker… (#7608)

Backport of #7489 to `cloud/1.35`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7608-backport-cloud-1-35-fix-right-side-panel-visual-indicators-don-t-update-for-color-pick-2cd6d73d365081c4bb1fcf1b7f0d24fd)
by [Unito](https://www.unito.io)

Co-authored-by: Rizumu Ayaka <rizumu@ayaka.moe>
This commit is contained in:
Comfy Org PR Bot
2025-12-19 11:21:04 +09:00
committed by GitHub
parent b92b3f0c79
commit af1dc69582

View File

@@ -78,7 +78,7 @@
<script setup lang="ts"> <script setup lang="ts">
import ToggleSwitch from 'primevue/toggleswitch' import ToggleSwitch from 'primevue/toggleswitch'
import { computed } from 'vue' import { computed, shallowRef, triggerRef, watchEffect } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { LGraphCanvas, LiteGraph } from '@/lib/litegraph/src/litegraph' import { LGraphCanvas, LiteGraph } from '@/lib/litegraph/src/litegraph'
@@ -90,10 +90,23 @@ import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'
import { adjustColor } from '@/utils/colorUtil' import { adjustColor } from '@/utils/colorUtil'
import { cn } from '@/utils/tailwindUtil' import { cn } from '@/utils/tailwindUtil'
const { nodes = [] } = defineProps<{ const props = defineProps<{
nodes?: LGraphNode[] nodes?: LGraphNode[]
}>() }>()
/**
* This is not random writing. It is very important.
* Otherwise, the UI cannot be updated correctly.
*/
const targetNodes = shallowRef<LGraphNode[]>([])
watchEffect(() => {
if (props.nodes) {
targetNodes.value = props.nodes
} else {
targetNodes.value = []
}
})
const { t } = useI18n() const { t } = useI18n()
const canvasStore = useCanvasStore() const canvasStore = useCanvasStore()
@@ -103,24 +116,33 @@ const isLightTheme = computed(
) )
const nodeState = computed({ const nodeState = computed({
get(): LGraphNode['mode'] | null { get() {
if (!nodes.length) return null let mode: LGraphNode['mode'] | null = null
if (nodes.length === 1) { const nodes = targetNodes.value
return nodes[0].mode
} if (nodes.length === 0) return null
// For multiple nodes, if all nodes have the same mode, return that mode, otherwise return null // For multiple nodes, if all nodes have the same mode, return that mode, otherwise return null
const mode: LGraphNode['mode'] = nodes[0].mode if (nodes.length > 1) {
if (!nodes.every((node) => node.mode === mode)) { mode = nodes[0].mode
return null if (!nodes.every((node) => node.mode === mode)) {
mode = null
}
} else {
mode = nodes[0].mode
} }
return mode return mode
}, },
set(value: LGraphNode['mode']) { set(value: LGraphNode['mode']) {
nodes.forEach((node) => { targetNodes.value.forEach((node) => {
node.mode = value node.mode = value
}) })
/*
* This is not random writing. It is very important.
* Otherwise, the UI cannot be updated correctly.
*/
triggerRef(targetNodes)
canvasStore.canvas?.setDirty(true, true) canvasStore.canvas?.setDirty(true, true)
} }
}) })
@@ -128,10 +150,15 @@ const nodeState = computed({
// Pinned state // Pinned state
const isPinned = computed<boolean>({ const isPinned = computed<boolean>({
get() { get() {
return nodes.some((node) => node.pinned) return targetNodes.value.some((node) => node.pinned)
}, },
set(value) { set(value) {
nodes.forEach((node) => node.pin(value)) targetNodes.value.forEach((node) => node.pin(value))
/*
* This is not random writing. It is very important.
* Otherwise, the UI cannot be updated correctly.
*/
triggerRef(targetNodes)
canvasStore.canvas?.setDirty(true, true) canvasStore.canvas?.setDirty(true, true)
} }
}) })
@@ -175,8 +202,10 @@ const colorOptions: NodeColorOption[] = [
const nodeColor = computed<NodeColorOption['name'] | null>({ const nodeColor = computed<NodeColorOption['name'] | null>({
get() { get() {
if (nodes.length === 0) return null if (targetNodes.value.length === 0) return null
const theColorOptions = nodes.map((item) => item.getColorOption()) const theColorOptions = targetNodes.value.map((item) =>
item.getColorOption()
)
let colorOption: ColorOption | null | false = theColorOptions[0] let colorOption: ColorOption | null | false = theColorOptions[0]
if (!theColorOptions.every((option) => option === colorOption)) { if (!theColorOptions.every((option) => option === colorOption)) {
@@ -202,9 +231,14 @@ const nodeColor = computed<NodeColorOption['name'] | null>({
? null ? null
: LGraphCanvas.node_colors[colorName] : LGraphCanvas.node_colors[colorName]
for (const item of nodes) { for (const item of targetNodes.value) {
item.setColorOption(canvasColorOption) item.setColorOption(canvasColorOption)
} }
/*
* This is not random writing. It is very important.
* Otherwise, the UI cannot be updated correctly.
*/
triggerRef(targetNodes)
canvasStore.canvas?.setDirty(true, true) canvasStore.canvas?.setDirty(true, true)
} }
}) })