mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 14:30:41 +00:00
## Summary - Adds subgraph title button to Vue node headers (matching LiteGraph behavior) - Fixes Vue node lifecycle issues during subgraph navigation and tab switching - Extracts reusable `useSubgraphNavigation` composable with callback-based API - Adds comprehensive tests for subgraph functionality - Ensures proper graph context restoration during tab switches https://github.com/user-attachments/assets/fd4ff16a-4071-4da6-903f-b2be8dd6e672 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5572-feat-Add-Vue-node-subgraph-title-button-with-lifecycle-management-26f6d73d365081bfbd9cfd7d2775e1ef) by [Unito](https://www.unito.io) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DrJKL <DrJKL@users.noreply.github.com>
181 lines
4.8 KiB
Vue
181 lines
4.8 KiB
Vue
<template>
|
|
<div v-if="renderError" class="node-error p-4 text-red-500 text-sm">
|
|
{{ $t('Node Header Error') }}
|
|
</div>
|
|
<div
|
|
v-else
|
|
class="lg-node-header flex items-center justify-between p-4 rounded-t-2xl cursor-move w-full"
|
|
:data-testid="`node-header-${nodeData?.id || ''}`"
|
|
@dblclick="handleDoubleClick"
|
|
>
|
|
<!-- Collapse/Expand Button -->
|
|
<button
|
|
v-show="!readonly"
|
|
class="bg-transparent border-transparent flex items-center"
|
|
data-testid="node-collapse-button"
|
|
@click.stop="handleCollapse"
|
|
@dblclick.stop
|
|
>
|
|
<i
|
|
:class="collapsed ? 'pi pi-chevron-right' : 'pi pi-chevron-down'"
|
|
class="text-xs leading-none relative top-px text-stone-200 dark-theme:text-slate-300"
|
|
></i>
|
|
</button>
|
|
|
|
<!-- Node Title -->
|
|
<div
|
|
v-tooltip.top="tooltipConfig"
|
|
class="text-sm font-bold truncate flex-1"
|
|
data-testid="node-title"
|
|
>
|
|
<EditableText
|
|
:model-value="displayTitle"
|
|
:is-editing="isEditing"
|
|
:input-attrs="{ 'data-testid': 'node-title-input' }"
|
|
@edit="handleTitleEdit"
|
|
@cancel="handleTitleCancel"
|
|
/>
|
|
</div>
|
|
|
|
<!-- Title Buttons -->
|
|
<div v-if="!readonly" class="flex items-center">
|
|
<IconButton
|
|
v-if="isSubgraphNode"
|
|
size="sm"
|
|
type="transparent"
|
|
class="text-stone-200 dark-theme:text-slate-300"
|
|
data-testid="subgraph-enter-button"
|
|
title="Enter Subgraph"
|
|
@click.stop="handleEnterSubgraph"
|
|
@dblclick.stop
|
|
>
|
|
<i class="pi pi-external-link"></i>
|
|
</IconButton>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { type Ref, computed, inject, onErrorCaptured, ref, watch } from 'vue'
|
|
|
|
import IconButton from '@/components/button/IconButton.vue'
|
|
import EditableText from '@/components/common/EditableText.vue'
|
|
import type { VueNodeData } from '@/composables/graph/useGraphNodeManager'
|
|
import { useErrorHandling } from '@/composables/useErrorHandling'
|
|
import { useNodeTooltips } from '@/renderer/extensions/vueNodes/composables/useNodeTooltips'
|
|
import type { LODLevel } from '@/renderer/extensions/vueNodes/lod/useLOD'
|
|
import { app } from '@/scripts/app'
|
|
import {
|
|
getLocatorIdFromNodeData,
|
|
getNodeByLocatorId
|
|
} from '@/utils/graphTraversalUtil'
|
|
|
|
interface NodeHeaderProps {
|
|
nodeData?: VueNodeData
|
|
readonly?: boolean
|
|
lodLevel?: LODLevel
|
|
collapsed?: boolean
|
|
}
|
|
|
|
const { nodeData, readonly, collapsed } = defineProps<NodeHeaderProps>()
|
|
|
|
const emit = defineEmits<{
|
|
collapse: []
|
|
'update:title': [newTitle: string]
|
|
'enter-subgraph': []
|
|
}>()
|
|
|
|
// Error boundary implementation
|
|
const renderError = ref<string | null>(null)
|
|
const { toastErrorHandler } = useErrorHandling()
|
|
|
|
onErrorCaptured((error) => {
|
|
renderError.value = error.message
|
|
toastErrorHandler(error)
|
|
return false
|
|
})
|
|
|
|
// Editing state
|
|
const isEditing = ref(false)
|
|
|
|
const tooltipContainer =
|
|
inject<Ref<HTMLElement | undefined>>('tooltipContainer')
|
|
const { getNodeDescription, createTooltipConfig } = useNodeTooltips(
|
|
nodeData?.type || '',
|
|
tooltipContainer
|
|
)
|
|
|
|
const tooltipConfig = computed(() => {
|
|
if (readonly || isEditing.value) {
|
|
return { value: '', disabled: true }
|
|
}
|
|
const description = getNodeDescription.value
|
|
return createTooltipConfig(description)
|
|
})
|
|
|
|
const resolveTitle = (info: VueNodeData | undefined) => {
|
|
const title = (info?.title ?? '').trim()
|
|
if (title.length > 0) return title
|
|
const type = (info?.type ?? '').trim()
|
|
return type.length > 0 ? type : 'Untitled'
|
|
}
|
|
|
|
// Local state for title to provide immediate feedback
|
|
const displayTitle = ref(resolveTitle(nodeData))
|
|
|
|
// Watch for external changes to the node title or type
|
|
watch(
|
|
() => [nodeData?.title, nodeData?.type] as const,
|
|
() => {
|
|
const next = resolveTitle(nodeData)
|
|
if (next !== displayTitle.value) {
|
|
displayTitle.value = next
|
|
}
|
|
}
|
|
)
|
|
|
|
// Subgraph detection
|
|
const isSubgraphNode = computed(() => {
|
|
if (!nodeData?.id) return false
|
|
|
|
// Get the underlying LiteGraph node
|
|
const graph = app.graph?.rootGraph || app.graph
|
|
if (!graph) return false
|
|
|
|
const locatorId = getLocatorIdFromNodeData(nodeData)
|
|
|
|
const litegraphNode = getNodeByLocatorId(graph, locatorId)
|
|
|
|
// Use the official type guard method
|
|
return litegraphNode?.isSubgraphNode() ?? false
|
|
})
|
|
|
|
// Event handlers
|
|
const handleCollapse = () => {
|
|
emit('collapse')
|
|
}
|
|
|
|
const handleDoubleClick = () => {
|
|
if (!readonly) {
|
|
isEditing.value = true
|
|
}
|
|
}
|
|
|
|
const handleTitleEdit = (newTitle: string) => {
|
|
isEditing.value = false
|
|
const trimmedTitle = newTitle.trim()
|
|
if (trimmedTitle && trimmedTitle !== displayTitle.value) {
|
|
// Emit for litegraph sync
|
|
emit('update:title', trimmedTitle)
|
|
}
|
|
}
|
|
|
|
const handleTitleCancel = () => {
|
|
isEditing.value = false
|
|
}
|
|
|
|
const handleEnterSubgraph = () => {
|
|
emit('enter-subgraph')
|
|
}
|
|
</script>
|