Shorten node source package name by remove ComfyUI prefix/suffix (#883)
* Shorten node source package name by remove ComfyUI prefix/suffix * Update test expectations [skip ci] --------- Co-authored-by: github-actions <github-actions@github.com>
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 45 KiB |
@@ -1,29 +0,0 @@
|
|||||||
<template>
|
|
||||||
<Chip :class="nodeSource.className">
|
|
||||||
{{ nodeSource.displayText }}
|
|
||||||
</Chip>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { getNodeSource } from '@/types/nodeSource'
|
|
||||||
import Chip from 'primevue/chip'
|
|
||||||
import { computed } from 'vue'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
python_module: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const nodeSource = computed(() => getNodeSource(props.python_module))
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.comfy-core,
|
|
||||||
.comfy-custom-nodes,
|
|
||||||
.comfy-unknown {
|
|
||||||
font-size: small;
|
|
||||||
font-weight: lighter;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -38,17 +38,20 @@
|
|||||||
:value="formatNumberWithSuffix(nodeFrequency, { roundToInt: true })"
|
:value="formatNumberWithSuffix(nodeFrequency, { roundToInt: true })"
|
||||||
severity="secondary"
|
severity="secondary"
|
||||||
/>
|
/>
|
||||||
<NodeSourceChip
|
<Chip
|
||||||
v-if="nodeDef.python_module !== undefined"
|
v-if="nodeDef.nodeSource.type !== NodeSourceType.Unknown"
|
||||||
:python_module="nodeDef.python_module"
|
class="text-sm font-light"
|
||||||
/>
|
>
|
||||||
|
{{ nodeDef.nodeSource.displayText }}
|
||||||
|
</Chip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Tag from 'primevue/tag'
|
import Tag from 'primevue/tag'
|
||||||
import NodeSourceChip from '@/components/node/NodeSourceChip.vue'
|
import Chip from 'primevue/chip'
|
||||||
|
import { NodeSourceType } from '@/types/nodeSource'
|
||||||
import { ComfyNodeDefImpl, useNodeFrequencyStore } from '@/stores/nodeDefStore'
|
import { ComfyNodeDefImpl, useNodeFrequencyStore } from '@/stores/nodeDefStore'
|
||||||
import { highlightQuery } from '@/utils/formatUtil'
|
import { highlightQuery } from '@/utils/formatUtil'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
|||||||
@@ -4,23 +4,23 @@ import type { ComfyLGraphNode } from '@/types/comfyLGraphNode'
|
|||||||
import { LGraphBadge } from '@comfyorg/litegraph'
|
import { LGraphBadge } from '@comfyorg/litegraph'
|
||||||
import { useSettingStore } from '@/stores/settingStore'
|
import { useSettingStore } from '@/stores/settingStore'
|
||||||
import { computed, ComputedRef, watch } from 'vue'
|
import { computed, ComputedRef, watch } from 'vue'
|
||||||
import {
|
import { NodeBadgeMode, NodeSource, NodeSourceType } from '@/types/nodeSource'
|
||||||
getNodeSource as getNodeSourceFromPythonModule,
|
|
||||||
NodeBadgeMode
|
|
||||||
} from '@/types/nodeSource'
|
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { getColorPalette, defaultColorPalette } from './colorPalette'
|
import { getColorPalette, defaultColorPalette } from './colorPalette'
|
||||||
import { BadgePosition } from '@comfyorg/litegraph'
|
import { BadgePosition } from '@comfyorg/litegraph'
|
||||||
import type { Palette } from '@/types/colorPalette'
|
import type { Palette } from '@/types/colorPalette'
|
||||||
|
import type { ComfyNodeDef } from '@/types/apiTypes'
|
||||||
|
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||||
|
|
||||||
function getNodeSource(node: ComfyLGraphNode) {
|
function getNodeSource(node: ComfyLGraphNode): NodeSource | null {
|
||||||
const pythonModule = (node.constructor as typeof ComfyLGraphNode).nodeData
|
const nodeDef = (node.constructor as typeof ComfyLGraphNode)
|
||||||
?.python_module
|
.nodeData as ComfyNodeDef
|
||||||
return pythonModule ? getNodeSourceFromPythonModule(pythonModule) : null
|
const nodeDefStore = useNodeDefStore()
|
||||||
|
return nodeDefStore.nodeDefsByName[nodeDef.name]?.nodeSource ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCoreNode(node: ComfyLGraphNode) {
|
function isCoreNode(node: ComfyLGraphNode) {
|
||||||
return getNodeSource(node)?.type === 'core'
|
return getNodeSource(node)?.type === NodeSourceType.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
function badgeTextVisible(
|
function badgeTextVisible(
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
import { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||||
import { getNodeSource } from '@/types/nodeSource'
|
|
||||||
import Fuse, { IFuseOptions, FuseSearchOptions } from 'fuse.js'
|
import Fuse, { IFuseOptions, FuseSearchOptions } from 'fuse.js'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
@@ -202,7 +201,7 @@ export class NodeSourceFilter extends NodeFilter<string> {
|
|||||||
public readonly longInvokeSequence = 'source'
|
public readonly longInvokeSequence = 'source'
|
||||||
|
|
||||||
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
public override getNodeOptions(node: ComfyNodeDefImpl): string[] {
|
||||||
return [getNodeSource(node.python_module).displayText]
|
return [node.nodeSource.displayText]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { TreeNode } from 'primevue/treenode'
|
|||||||
import { buildTree } from '@/utils/treeUtil'
|
import { buildTree } from '@/utils/treeUtil'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { type NodeSource, getNodeSource } from '@/types/nodeSource'
|
||||||
|
|
||||||
export class BaseInputSpec<T = any> {
|
export class BaseInputSpec<T = any> {
|
||||||
name: string
|
name: string
|
||||||
@@ -194,6 +195,12 @@ export class ComfyNodeDefImpl {
|
|||||||
@Transform(({ obj }) => ComfyNodeDefImpl.transformOutputSpec(obj))
|
@Transform(({ obj }) => ComfyNodeDefImpl.transformOutputSpec(obj))
|
||||||
output: ComfyOutputsSpec
|
output: ComfyOutputsSpec
|
||||||
|
|
||||||
|
@Transform(({ obj }) => getNodeSource(obj.python_module), {
|
||||||
|
toClassOnly: true
|
||||||
|
})
|
||||||
|
@Expose()
|
||||||
|
nodeSource: NodeSource
|
||||||
|
|
||||||
private static transformOutputSpec(obj: any): ComfyOutputsSpec {
|
private static transformOutputSpec(obj: any): ComfyOutputsSpec {
|
||||||
const { output, output_is_list, output_name, output_tooltips } = obj
|
const { output, output_is_list, output_name, output_tooltips } = obj
|
||||||
const result = output.map((type: string | any[], index: number) => {
|
const result = output.map((type: string | any[], index: number) => {
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
export type NodeSourceType = 'core' | 'custom_nodes'
|
export enum NodeSourceType {
|
||||||
|
Core = 'core',
|
||||||
|
CustomNodes = 'custom_nodes',
|
||||||
|
Unknown = 'unknown'
|
||||||
|
}
|
||||||
|
|
||||||
export type NodeSource = {
|
export type NodeSource = {
|
||||||
type: NodeSourceType
|
type: NodeSourceType
|
||||||
className: string
|
className: string
|
||||||
@@ -6,24 +11,41 @@ export type NodeSource = {
|
|||||||
badgeText: string
|
badgeText: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getNodeSource = (python_module: string): NodeSource => {
|
const UNKNOWN_NODE_SOURCE: NodeSource = {
|
||||||
|
type: NodeSourceType.Unknown,
|
||||||
|
className: 'comfy-unknown',
|
||||||
|
displayText: 'Unknown',
|
||||||
|
badgeText: '?'
|
||||||
|
}
|
||||||
|
|
||||||
|
const shortenNodeName = (name: string) => {
|
||||||
|
return name
|
||||||
|
.replace(/^(ComfyUI-|ComfyUI_|Comfy-|Comfy_)/, '')
|
||||||
|
.replace(/(-ComfyUI|_ComfyUI|-Comfy|_Comfy)$/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getNodeSource = (python_module?: string): NodeSource => {
|
||||||
|
if (!python_module) {
|
||||||
|
return UNKNOWN_NODE_SOURCE
|
||||||
|
}
|
||||||
const modules = python_module.split('.')
|
const modules = python_module.split('.')
|
||||||
if (['nodes', 'comfy_extras'].includes(modules[0])) {
|
if (['nodes', 'comfy_extras'].includes(modules[0])) {
|
||||||
return {
|
return {
|
||||||
type: 'core',
|
type: NodeSourceType.Core,
|
||||||
className: 'comfy-core',
|
className: 'comfy-core',
|
||||||
displayText: 'Comfy Core',
|
displayText: 'Comfy Core',
|
||||||
badgeText: '🦊'
|
badgeText: '🦊'
|
||||||
}
|
}
|
||||||
} else if (modules[0] === 'custom_nodes') {
|
} else if (modules[0] === 'custom_nodes') {
|
||||||
|
const displayName = shortenNodeName(modules[1])
|
||||||
return {
|
return {
|
||||||
type: 'custom_nodes',
|
type: NodeSourceType.CustomNodes,
|
||||||
className: 'comfy-custom-nodes',
|
className: 'comfy-custom-nodes',
|
||||||
displayText: modules[1],
|
displayText: displayName,
|
||||||
badgeText: modules[1]
|
badgeText: displayName
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unknown node source: ${python_module}`)
|
return UNKNOWN_NODE_SOURCE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||