Files
ComfyUI_frontend/src/components/rightSidePanel/parameters/TabSubgraphInputs.vue
Rizumu Ayaka b1b2fd8a4f feat: right side panel favorites, no selection state, and more... (#7812)
Most of the features in this pull request are completed and can be
reviewed and merged.

## TODO

- [x] no selection panel
- [x] group selected panel
- [x] tabs 
  - [x] favorites tab
  - [x] global settings tab
  - [x] nodes tab
- [x] widget actions menu 
  - [x] [Bug]: style bugs
- [x] button zoom to the node on canvas.
- [x] rename widgets on widget actions
  - [ ] [Bug]: the canvas has not been updated after renaming. 
- [x] global settings
  - [ ] setting item: "show advanced parameters"
    - blocked by other things. skip for now.
  - [x] setting item: show toolbox on selection 
  - [x] setting item: nodes 2.0
  - [ ] setting item: "background color"
    - blocked by other things. skip for now.
  - [x] setting item: grid spacing
  - [x] setting item: snap nodes to grid
  - [x] setting item: link shape
  - [x] setting item: show connected links
  - [x] form style reuses the form style of node widgets
- [x] group node cases
  - [x] group node settings
  - [x] show all nodes in group
  - [x] show frame name on nodes when multiple selections are made
  - [x] group multiple selections
- [x] [Bug]: nodes without widgets cannot display the location and their
group
  - [x] [Bug]: labels layout
- [x] favorites
  - [x] the indicator on widgets
  - [x] favorite and unfavorite buttons on widgets
- [x] [Bug]: show node name in favorite widgets + improve labels layout
- [ ] [Bug]: After canceling the like, the like list will not be updated
immediately.
- [x] [Bug]: The favorite function does not work for the project on
Subgraph.
- [x] subgraph
- [x] add the node name from where this parameter comes from when node
is subgraph
  - [x] show and hide directly on Inputs
    - [x] some bugs need to be fixed.
- [x] advanced widgets 
  - [x] button: show advanced inputs
- Clicking button expands the "Advanced Inputs" section on the right
side panel, regardless of whether the panel is open or not
    - [x] [Bug]: style bugs
  - [x] advanced inputs section when node is subgraph
- [x] inputs tab rearranging
  - [x] favorited inputs rearranging
  - [x] subgraph inputs rearranging
- [ ] review and reconstruction to improve complexity and architecture

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-7812-feat-right-side-panel-favorites-no-selection-state-and-more-2da6d73d36508134b503d676f9b3d248)
by [Unito](https://www.unito.io)

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: bymyself <cbyrne@comfy.org>
2026-01-13 20:37:17 -07:00

245 lines
7.2 KiB
Vue

<script setup lang="ts">
import { useMounted, watchDebounced } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import {
computed,
customRef,
nextTick,
onBeforeUnmount,
onMounted,
ref,
shallowRef,
triggerRef,
useTemplateRef,
watch
} from 'vue'
import { useI18n } from 'vue-i18n'
import { isProxyWidget } from '@/core/graph/subgraph/proxyWidget'
import { parseProxyWidgets } from '@/core/schemas/proxyWidget'
import type { ProxyWidgetsProperty } from '@/core/schemas/proxyWidget'
import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import FormSearchInput from '@/renderer/extensions/vueNodes/widgets/components/form/FormSearchInput.vue'
import { DraggableList } from '@/scripts/ui/draggableList'
import { useRightSidePanelStore } from '@/stores/workspace/rightSidePanelStore'
import { searchWidgets } from '../shared'
import type { NodeWidgetsList } from '../shared'
import SectionWidgets from './SectionWidgets.vue'
const { node } = defineProps<{
node: SubgraphNode
}>()
const { t } = useI18n()
const canvasStore = useCanvasStore()
const rightSidePanelStore = useRightSidePanelStore()
const { focusedSection, searchQuery } = storeToRefs(rightSidePanelStore)
const advancedInputsCollapsed = ref(true)
const draggableList = ref<DraggableList | undefined>(undefined)
const sectionWidgetsRef = useTemplateRef('sectionWidgetsRef')
const advancedInputsSectionRef = useTemplateRef('advancedInputsSectionRef')
// Use customRef to track proxyWidgets changes
const proxyWidgets = customRef<ProxyWidgetsProperty>((track, trigger) => ({
get() {
track()
return parseProxyWidgets(node.properties.proxyWidgets)
},
set(value?: ProxyWidgetsProperty) {
trigger()
if (!value) return
// eslint-disable-next-line vue/no-mutating-props
node.properties.proxyWidgets = value
}
}))
watch(
focusedSection,
async (section) => {
if (section === 'advanced-inputs') {
advancedInputsCollapsed.value = false
rightSidePanelStore.clearFocusedSection()
await nextTick()
await new Promise((resolve) => setTimeout(resolve, 300))
const sectionComponent = advancedInputsSectionRef.value
const sectionElement = sectionComponent?.rootElement
if (sectionElement) {
sectionElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
}
},
{ immediate: true }
)
const widgetsList = computed((): NodeWidgetsList => {
const proxyWidgetsOrder = proxyWidgets.value
const { widgets = [] } = node
// Map proxyWidgets to actual proxy widgets in the correct order
const result: NodeWidgetsList = []
for (const [nodeId, widgetName] of proxyWidgetsOrder) {
// Find the proxy widget that matches this nodeId and widgetName
const widget = widgets.find((w) => {
// Check if this is a proxy widget with _overlay
if (isProxyWidget(w)) {
return (
String(w._overlay.nodeId) === nodeId &&
w._overlay.widgetName === widgetName
)
}
// For non-proxy widgets (like linked widgets), match by name
return w.name === widgetName
})
if (widget) {
result.push({ node, widget })
}
}
return result
})
const advancedInputsWidgets = computed((): NodeWidgetsList => {
const interiorNodes = node.subgraph.nodes
const proxyWidgetsValue = parseProxyWidgets(node.properties.proxyWidgets)
// Get all widgets from interior nodes
const allInteriorWidgets = interiorNodes.flatMap((interiorNode) => {
const { widgets = [] } = interiorNode
return widgets
.filter((w) => !w.computedDisabled)
.map((widget) => ({ node: interiorNode, widget }))
})
// Filter out widgets that are already promoted using tuple matching
return allInteriorWidgets.filter(({ node: interiorNode, widget }) => {
return !proxyWidgetsValue.some(
([nodeId, widgetName]) =>
interiorNode.id == nodeId && widget.name === widgetName
)
})
})
const parents = computed<SubgraphNode[]>(() => [node])
const searchedWidgetsList = shallowRef<NodeWidgetsList>(widgetsList.value)
const isSearching = ref(false)
async function searcher(query: string) {
isSearching.value = query.trim() !== ''
searchedWidgetsList.value = searchWidgets(widgetsList.value, query)
}
const isMounted = useMounted()
function setDraggableState() {
if (!isMounted.value) return
draggableList.value?.dispose()
const container = sectionWidgetsRef.value?.widgetsContainer
if (isSearching.value || !container?.children?.length) return
draggableList.value = new DraggableList(container, '.draggable-item')
draggableList.value.applyNewItemsOrder = function () {
const reorderedItems: HTMLElement[] = []
let oldPosition = -1
this.getAllItems().forEach((item, index) => {
if (item === this.draggableItem) {
oldPosition = index
return
}
if (!this.isItemToggled(item)) {
reorderedItems[index] = item
return
}
const newIndex = this.isItemAbove(item) ? index + 1 : index - 1
reorderedItems[newIndex] = item
})
if (oldPosition === -1) {
console.error('[TabSubgraphInputs] draggableItem not found in items')
return
}
for (let index = 0; index < this.getAllItems().length; index++) {
const item = reorderedItems[index]
if (typeof item === 'undefined') {
reorderedItems[index] = this.draggableItem as HTMLElement
}
}
const newPosition = reorderedItems.indexOf(
this.draggableItem as HTMLElement
)
// Update proxyWidgets order
const pw = proxyWidgets.value
const [w] = pw.splice(oldPosition, 1)
pw.splice(newPosition, 0, w)
proxyWidgets.value = pw
canvasStore.canvas?.setDirty(true, true)
triggerRef(proxyWidgets)
}
}
watchDebounced(searchedWidgetsList, () => setDraggableState(), {
debounce: 100
})
onMounted(() => setDraggableState())
onBeforeUnmount(() => draggableList.value?.dispose())
const label = computed(() => {
return searchedWidgetsList.value.length !== 0
? t('rightSidePanel.inputs')
: t('rightSidePanel.inputsNone')
})
</script>
<template>
<div class="px-4 pt-1 pb-4 flex gap-2 border-b border-interface-stroke">
<FormSearchInput
v-model="searchQuery"
:searcher
:update-key="widgetsList"
/>
</div>
<SectionWidgets
ref="sectionWidgetsRef"
:node
:label
:parents
:widgets="searchedWidgetsList"
:is-draggable="!isSearching"
:enable-empty-state="isSearching"
:tooltip="
isSearching || searchedWidgetsList.length
? ''
: t('rightSidePanel.inputsNoneTooltip')
"
class="border-b border-interface-stroke"
@update:collapse="nextTick(setDraggableState)"
>
<template #empty>
<div class="text-sm text-muted-foreground px-4 text-center pt-5 pb-15">
{{ t('rightSidePanel.noneSearchDesc') }}
</div>
</template>
</SectionWidgets>
<SectionWidgets
v-if="advancedInputsWidgets.length > 0"
ref="advancedInputsSectionRef"
v-model:collapse="advancedInputsCollapsed"
:label="t('rightSidePanel.advancedInputs')"
:parents="parents"
:widgets="advancedInputsWidgets"
show-node-name
class="border-b border-interface-stroke"
/>
</template>