mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 06:47:33 +00:00
[Refactor] Remove abstract inheritance of node search filter (#1774)
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
>
|
||||
<template #container>
|
||||
<NodeSearchBox
|
||||
:filters="nodeFilters as FilterAndValue[]"
|
||||
:filters="nodeFilters"
|
||||
@add-filter="addFilter"
|
||||
@remove-filter="removeFilter"
|
||||
@add-node="addNode"
|
||||
|
||||
@@ -10,8 +10,8 @@ interface ExtraSearchOptions {
|
||||
}
|
||||
|
||||
export class FuseSearch<T> {
|
||||
private fuse: Fuse<T>
|
||||
private readonly keys: string[]
|
||||
public readonly fuse: Fuse<T>
|
||||
public readonly keys: string[]
|
||||
public readonly data: T[]
|
||||
public readonly advancedScoring: boolean
|
||||
|
||||
@@ -130,21 +130,30 @@ export class FuseSearch<T> {
|
||||
|
||||
export type FilterAndValue<T = string> = [NodeFilter<T>, T]
|
||||
|
||||
export abstract class NodeFilter<FilterOptionT = string> {
|
||||
public abstract readonly id: string
|
||||
public abstract readonly name: string
|
||||
public abstract readonly invokeSequence: string
|
||||
public abstract readonly longInvokeSequence: string
|
||||
export class NodeFilter<FilterOptionT = string> {
|
||||
public readonly fuseSearch: FuseSearch<FilterOptionT>
|
||||
|
||||
constructor(
|
||||
public readonly id: string,
|
||||
public readonly name: string,
|
||||
public readonly invokeSequence: string,
|
||||
public readonly longInvokeSequence: string,
|
||||
public readonly nodeOptions:
|
||||
| FilterOptionT[]
|
||||
| ((node: ComfyNodeDefImpl) => FilterOptionT[]),
|
||||
nodeDefs: ComfyNodeDefImpl[],
|
||||
options?: IFuseOptions<FilterOptionT>
|
||||
) {
|
||||
this.fuseSearch = new FuseSearch(this.getAllNodeOptions(nodeDefs), options)
|
||||
}
|
||||
|
||||
private getAllNodeOptions(nodeDefs: ComfyNodeDefImpl[]): FilterOptionT[] {
|
||||
public getNodeOptions(node: ComfyNodeDefImpl): FilterOptionT[] {
|
||||
return this.nodeOptions instanceof Function
|
||||
? this.nodeOptions(node)
|
||||
: this.nodeOptions
|
||||
}
|
||||
|
||||
public getAllNodeOptions(nodeDefs: ComfyNodeDefImpl[]): FilterOptionT[] {
|
||||
return [
|
||||
...new Set(
|
||||
nodeDefs.reduce((acc, nodeDef) => {
|
||||
@@ -154,8 +163,6 @@ export abstract class NodeFilter<FilterOptionT = string> {
|
||||
]
|
||||
}
|
||||
|
||||
public abstract getNodeOptions(node: ComfyNodeDefImpl): FilterOptionT[]
|
||||
|
||||
public matches(
|
||||
node: ComfyNodeDefImpl,
|
||||
value: FilterOptionT,
|
||||
@@ -173,50 +180,6 @@ export abstract class NodeFilter<FilterOptionT = string> {
|
||||
}
|
||||
}
|
||||
|
||||
export class InputTypeFilter extends NodeFilter<string> {
|
||||
public readonly id: string = 'input'
|
||||
public readonly name = 'Input Type'
|
||||
public readonly invokeSequence = 'i'
|
||||
public readonly longInvokeSequence = 'input'
|
||||
|
||||
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
||||
return node.input.all.map((input) => input.type)
|
||||
}
|
||||
}
|
||||
|
||||
export class OutputTypeFilter extends NodeFilter<string> {
|
||||
public readonly id: string = 'output'
|
||||
public readonly name = 'Output Type'
|
||||
public readonly invokeSequence = 'o'
|
||||
public readonly longInvokeSequence = 'output'
|
||||
|
||||
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
||||
return node.output.all.map((output) => output.type)
|
||||
}
|
||||
}
|
||||
|
||||
export class NodeSourceFilter extends NodeFilter<string> {
|
||||
public readonly id: string = 'source'
|
||||
public readonly name = 'Source'
|
||||
public readonly invokeSequence = 's'
|
||||
public readonly longInvokeSequence = 'source'
|
||||
|
||||
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
||||
return [node.nodeSource.displayText]
|
||||
}
|
||||
}
|
||||
|
||||
export class NodeCategoryFilter extends NodeFilter<string> {
|
||||
public readonly id: string = 'category'
|
||||
public readonly name = 'Category'
|
||||
public readonly invokeSequence = 'c'
|
||||
public readonly longInvokeSequence = 'category'
|
||||
|
||||
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
||||
return [node.category]
|
||||
}
|
||||
}
|
||||
|
||||
export class NodeSearchService {
|
||||
public readonly nodeFuseSearch: FuseSearch<ComfyNodeDefImpl>
|
||||
public readonly nodeFilters: NodeFilter<string>[]
|
||||
@@ -241,15 +204,52 @@ export class NodeSearchService {
|
||||
shouldSort: true
|
||||
}
|
||||
|
||||
this.nodeFilters = [
|
||||
new InputTypeFilter(data, filterSearchOptions),
|
||||
new OutputTypeFilter(data, filterSearchOptions),
|
||||
new NodeCategoryFilter(data, filterSearchOptions)
|
||||
]
|
||||
const inputTypeFilter = new NodeFilter<string>(
|
||||
/* id */ 'input',
|
||||
/* name */ 'Input Type',
|
||||
/* invokeSequence */ 'i',
|
||||
/* longInvokeSequence */ 'input',
|
||||
(node) => node.input.all.map((input) => input.type),
|
||||
data,
|
||||
filterSearchOptions
|
||||
)
|
||||
|
||||
if (data[0].python_module !== undefined) {
|
||||
this.nodeFilters.push(new NodeSourceFilter(data, filterSearchOptions))
|
||||
}
|
||||
const outputTypeFilter = new NodeFilter<string>(
|
||||
/* id */ 'output',
|
||||
/* name */ 'Output Type',
|
||||
/* invokeSequence */ 'o',
|
||||
/* longInvokeSequence */ 'output',
|
||||
(node) => node.output.all.map((output) => output.type),
|
||||
data,
|
||||
filterSearchOptions
|
||||
)
|
||||
|
||||
const nodeCategoryFilter = new NodeFilter<string>(
|
||||
/* id */ 'category',
|
||||
/* name */ 'Category',
|
||||
/* invokeSequence */ 'c',
|
||||
/* longInvokeSequence */ 'category',
|
||||
(node) => [node.category],
|
||||
data,
|
||||
filterSearchOptions
|
||||
)
|
||||
|
||||
const nodeSourceFilter = new NodeFilter<string>(
|
||||
/* id */ 'source',
|
||||
/* name */ 'Source',
|
||||
/* invokeSequence */ 's',
|
||||
/* longInvokeSequence */ 'source',
|
||||
(node) => [node.nodeSource.displayText],
|
||||
data,
|
||||
filterSearchOptions
|
||||
)
|
||||
|
||||
this.nodeFilters = [
|
||||
inputTypeFilter,
|
||||
outputTypeFilter,
|
||||
nodeCategoryFilter,
|
||||
nodeSourceFilter
|
||||
]
|
||||
}
|
||||
|
||||
public endsWithFilterStartSequence(query: string): boolean {
|
||||
|
||||
Reference in New Issue
Block a user