@@ -4,6 +4,7 @@ import { defineStore } from 'pinia'
44import { Type , Transform , plainToClass } from 'class-transformer'
55import { ComfyWidgetConstructor } from '@/scripts/widgets'
66import { TreeNode } from 'primevue/treenode'
7+ import { buildTree } from '@/utils/treeUtil'
78
89export class BaseInputSpec < T = any > {
910 name : string
@@ -262,34 +263,11 @@ export const useNodeDefStore = defineStore('nodeDef', {
262263 nodeSearchService ( state ) {
263264 return new NodeSearchService ( Object . values ( state . nodeDefsByName ) )
264265 } ,
265- nodeTree ( state ) : TreeNode {
266- const root : TreeNode = {
267- key : 'root' ,
268- label : 'Nodes' ,
269- leaf : false ,
270- children : [ ]
271- }
272- for ( const nodeDef of Object . values ( state . nodeDefsByName ) ) {
273- const path = nodeDef . category . split ( '/' )
274- let current = root
275- let key = 'root'
276- for ( const part of path ) {
277- key += `/${ part } `
278- let next = current . children . find ( ( child ) => child . label === part )
279- if ( ! next ) {
280- next = { key, label : part , children : [ ] , leaf : false }
281- current . children . push ( next )
282- }
283- current = next
284- }
285- current . children . push ( {
286- label : nodeDef . display_name ,
287- data : nodeDef ,
288- key : `${ key } /${ nodeDef . name } ` ,
289- leaf : true
290- } )
291- }
292- return root
266+ nodeTree ( ) : TreeNode {
267+ return buildTree ( this . nodeDefs , ( nodeDef : ComfyNodeDefImpl ) => [
268+ ...nodeDef . category . split ( '/' ) ,
269+ nodeDef . display_name
270+ ] )
293271 } ,
294272 sortedNodeTree ( ) : TreeNode {
295273 return sortedTree ( this . nodeTree )
0 commit comments