mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 14:54:12 +00:00
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>
142 lines
5.8 KiB
TypeScript
142 lines
5.8 KiB
TypeScript
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { registerProxyWidgets } from '@/core/graph/subgraph/proxyWidget'
|
|
import { promoteWidget } from '@/core/graph/subgraph/proxyWidgetUtils'
|
|
import { parseProxyWidgets } from '@/core/schemas/proxyWidget'
|
|
import { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { LGraphCanvas, SubgraphNode } from '@/lib/litegraph/src/litegraph'
|
|
|
|
import {
|
|
createTestSubgraph,
|
|
createTestSubgraphNode
|
|
} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers'
|
|
|
|
const canvasEl: Partial<HTMLCanvasElement> = { addEventListener() {} }
|
|
const canvas: Partial<LGraphCanvas> = { canvas: canvasEl as HTMLCanvasElement }
|
|
registerProxyWidgets(canvas as LGraphCanvas)
|
|
|
|
vi.mock('@/renderer/core/canvas/canvasStore', () => ({
|
|
useCanvasStore: () => ({})
|
|
}))
|
|
vi.mock('@/stores/domWidgetStore', () => ({
|
|
useDomWidgetStore: () => ({ widgetStates: new Map() })
|
|
}))
|
|
vi.mock('@/services/litegraphService', () => ({
|
|
useLitegraphService: () => ({ updatePreviews: () => ({}) })
|
|
}))
|
|
|
|
function setupSubgraph(
|
|
innerNodeCount: number = 0
|
|
): [SubgraphNode, LGraphNode[]] {
|
|
const subgraph = createTestSubgraph()
|
|
const subgraphNode = createTestSubgraphNode(subgraph)
|
|
subgraphNode._internalConfigureAfterSlots()
|
|
const graph = subgraphNode.graph
|
|
graph.add(subgraphNode)
|
|
const innerNodes = []
|
|
for (let i = 0; i < innerNodeCount; i++) {
|
|
const innerNode = new LGraphNode(`InnerNode${i}`)
|
|
subgraph.add(innerNode)
|
|
innerNodes.push(innerNode)
|
|
}
|
|
return [subgraphNode, innerNodes]
|
|
}
|
|
|
|
describe('Subgraph proxyWidgets', () => {
|
|
test('Can add simple widget', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'stringWidget', 'value', () => {})
|
|
subgraphNode.properties.proxyWidgets = [['1', 'stringWidget']]
|
|
expect(subgraphNode.widgets.length).toBe(1)
|
|
expect(subgraphNode.properties.proxyWidgets).toStrictEqual([
|
|
['1', 'stringWidget']
|
|
])
|
|
})
|
|
test('Can add multiple widgets with same name', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(2)
|
|
for (const innerNode of innerNodes)
|
|
innerNode.addWidget('text', 'stringWidget', 'value', () => {})
|
|
subgraphNode.properties.proxyWidgets = [
|
|
['1', 'stringWidget'],
|
|
['2', 'stringWidget']
|
|
]
|
|
expect(subgraphNode.widgets.length).toBe(2)
|
|
expect(subgraphNode.widgets[0].name).not.toEqual(
|
|
subgraphNode.widgets[1].name
|
|
)
|
|
})
|
|
test('Will serialize existing widgets', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'istringWidget', 'value', () => {})
|
|
subgraphNode.addWidget('text', 'stringWidget', 'value', () => {})
|
|
|
|
const proxyWidgets = parseProxyWidgets(subgraphNode.properties.proxyWidgets)
|
|
proxyWidgets.push(['1', 'istringWidget'])
|
|
subgraphNode.properties.proxyWidgets = proxyWidgets
|
|
|
|
expect(subgraphNode.widgets.length).toBe(2)
|
|
expect(subgraphNode.widgets[0].name).toBe('stringWidget')
|
|
subgraphNode.properties.proxyWidgets = [proxyWidgets[1], proxyWidgets[0]]
|
|
expect(subgraphNode.widgets[0].name).toBe('1: istringWidget')
|
|
})
|
|
test('Will mirror changes to value', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'stringWidget', 'value', () => {})
|
|
subgraphNode.properties.proxyWidgets = [['1', 'stringWidget']]
|
|
expect(subgraphNode.widgets.length).toBe(1)
|
|
expect(subgraphNode.widgets[0].value).toBe('value')
|
|
innerNodes[0].widgets![0].value = 'test'
|
|
expect(subgraphNode.widgets[0].value).toBe('test')
|
|
subgraphNode.widgets[0].value = 'test2'
|
|
expect(innerNodes[0].widgets![0].value).toBe('test2')
|
|
})
|
|
test('Will not modify position or sizing of existing widgets', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'stringWidget', 'value', () => {})
|
|
subgraphNode.properties.proxyWidgets = [['1', 'stringWidget']]
|
|
if (!innerNodes[0].widgets) throw new Error('node has no widgets')
|
|
innerNodes[0].widgets[0].y = 10
|
|
innerNodes[0].widgets[0].last_y = 11
|
|
innerNodes[0].widgets[0].computedHeight = 12
|
|
subgraphNode.widgets[0].y = 20
|
|
subgraphNode.widgets[0].last_y = 21
|
|
subgraphNode.widgets[0].computedHeight = 22
|
|
expect(innerNodes[0].widgets[0].y).toBe(10)
|
|
expect(innerNodes[0].widgets[0].last_y).toBe(11)
|
|
expect(innerNodes[0].widgets[0].computedHeight).toBe(12)
|
|
})
|
|
test('Can detach and re-attach widgets', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'stringWidget', 'value', () => {})
|
|
subgraphNode.properties.proxyWidgets = [['1', 'stringWidget']]
|
|
if (!innerNodes[0].widgets) throw new Error('node has no widgets')
|
|
expect(subgraphNode.widgets[0].value).toBe('value')
|
|
const poppedWidget = innerNodes[0].widgets.pop()
|
|
//simulate new draw frame
|
|
subgraphNode.widgets[0].computedHeight = 10
|
|
expect(subgraphNode.widgets[0].value).toBe(undefined)
|
|
innerNodes[0].widgets.push(poppedWidget!)
|
|
subgraphNode.widgets[0].computedHeight = 10
|
|
expect(subgraphNode.widgets[0].value).toBe('value')
|
|
})
|
|
test('Prevents duplicate promotion', () => {
|
|
const [subgraphNode, innerNodes] = setupSubgraph(1)
|
|
innerNodes[0].addWidget('text', 'stringWidget', 'value', () => {})
|
|
|
|
const widget = innerNodes[0].widgets![0]
|
|
|
|
// Promote once
|
|
promoteWidget(innerNodes[0], widget, [subgraphNode])
|
|
expect(subgraphNode.widgets.length).toBe(1)
|
|
expect(subgraphNode.properties.proxyWidgets).toHaveLength(1)
|
|
|
|
// Try to promote again - should not create duplicate
|
|
promoteWidget(innerNodes[0], widget, [subgraphNode])
|
|
expect(subgraphNode.widgets.length).toBe(1)
|
|
expect(subgraphNode.properties.proxyWidgets).toHaveLength(1)
|
|
expect(subgraphNode.properties.proxyWidgets).toStrictEqual([
|
|
['1', 'stringWidget']
|
|
])
|
|
})
|
|
})
|