mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 19:21:54 +00:00
[TS] Improve various types / remove assertions (#4148)
This commit is contained in:
@@ -92,50 +92,26 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function bindExecutionEvents() {
|
function bindExecutionEvents() {
|
||||||
api.addEventListener(
|
api.addEventListener('execution_start', handleExecutionStart)
|
||||||
'execution_start',
|
api.addEventListener('execution_cached', handleExecutionCached)
|
||||||
handleExecutionStart as EventListener
|
api.addEventListener('executed', handleExecuted)
|
||||||
)
|
api.addEventListener('executing', handleExecuting)
|
||||||
api.addEventListener(
|
api.addEventListener('progress', handleProgress)
|
||||||
'execution_cached',
|
api.addEventListener('status', handleStatus)
|
||||||
handleExecutionCached as EventListener
|
api.addEventListener('execution_error', handleExecutionError)
|
||||||
)
|
|
||||||
api.addEventListener('executed', handleExecuted as EventListener)
|
|
||||||
api.addEventListener('executing', handleExecuting as EventListener)
|
|
||||||
api.addEventListener('progress', handleProgress as EventListener)
|
|
||||||
api.addEventListener('status', handleStatus as EventListener)
|
|
||||||
api.addEventListener(
|
|
||||||
'execution_error',
|
|
||||||
handleExecutionError as EventListener
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
api.addEventListener('progress_text', handleProgressText as EventListener)
|
api.addEventListener('progress_text', handleProgressText)
|
||||||
api.addEventListener(
|
api.addEventListener('display_component', handleDisplayComponent)
|
||||||
'display_component',
|
|
||||||
handleDisplayComponent as EventListener
|
|
||||||
)
|
|
||||||
|
|
||||||
function unbindExecutionEvents() {
|
function unbindExecutionEvents() {
|
||||||
api.removeEventListener(
|
api.removeEventListener('execution_start', handleExecutionStart)
|
||||||
'execution_start',
|
api.removeEventListener('execution_cached', handleExecutionCached)
|
||||||
handleExecutionStart as EventListener
|
api.removeEventListener('executed', handleExecuted)
|
||||||
)
|
api.removeEventListener('executing', handleExecuting)
|
||||||
api.removeEventListener(
|
api.removeEventListener('progress', handleProgress)
|
||||||
'execution_cached',
|
api.removeEventListener('status', handleStatus)
|
||||||
handleExecutionCached as EventListener
|
api.removeEventListener('execution_error', handleExecutionError)
|
||||||
)
|
api.removeEventListener('progress_text', handleProgressText)
|
||||||
api.removeEventListener('executed', handleExecuted as EventListener)
|
|
||||||
api.removeEventListener('executing', handleExecuting as EventListener)
|
|
||||||
api.removeEventListener('progress', handleProgress as EventListener)
|
|
||||||
api.removeEventListener('status', handleStatus as EventListener)
|
|
||||||
api.removeEventListener(
|
|
||||||
'execution_error',
|
|
||||||
handleExecutionError as EventListener
|
|
||||||
)
|
|
||||||
api.removeEventListener(
|
|
||||||
'progress_text',
|
|
||||||
handleProgressText as EventListener
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleExecutionStart(e: CustomEvent<ExecutionStartWsMessage>) {
|
function handleExecutionStart(e: CustomEvent<ExecutionStartWsMessage>) {
|
||||||
@@ -184,7 +160,7 @@ export const useExecutionStore = defineStore('execution', () => {
|
|||||||
clientId.value = api.clientId
|
clientId.value = api.clientId
|
||||||
|
|
||||||
// Once we've received the clientId we no longer need to listen
|
// Once we've received the clientId we no longer need to listen
|
||||||
api.removeEventListener('status', handleStatus as EventListener)
|
api.removeEventListener('status', handleStatus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import type { InjectionKey, ModelRef } from 'vue'
|
|||||||
|
|
||||||
export interface TreeNode extends PrimeVueTreeNode {
|
export interface TreeNode extends PrimeVueTreeNode {
|
||||||
label: string
|
label: string
|
||||||
children?: TreeNode[]
|
children?: this[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TreeExplorerNode<T = any> extends TreeNode {
|
export interface TreeExplorerNode<T = any> extends TreeNode {
|
||||||
data?: T
|
data?: T
|
||||||
children?: TreeExplorerNode<T>[]
|
children?: this[]
|
||||||
icon?: string
|
icon?: string
|
||||||
/**
|
/**
|
||||||
* Function to override what icon to use for the node.
|
* Function to override what icon to use for the node.
|
||||||
@@ -62,7 +62,7 @@ export interface TreeExplorerNode<T = any> extends TreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface RenderedTreeExplorerNode<T = any> extends TreeExplorerNode<T> {
|
export interface RenderedTreeExplorerNode<T = any> extends TreeExplorerNode<T> {
|
||||||
children?: RenderedTreeExplorerNode<T>[]
|
children?: this[]
|
||||||
icon: string
|
icon: string
|
||||||
type: 'folder' | 'node'
|
type: 'folder' | 'node'
|
||||||
/** Total number of leaves in the subtree */
|
/** Total number of leaves in the subtree */
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ const mergeNumericInputSpec = <T extends IntInputSpec | FloatInputSpec>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mergeCommonInputSpec(
|
return mergeCommonInputSpec(
|
||||||
[type, { ...options1, ...mergedOptions }] as unknown as T,
|
[type, { ...options1, ...mergedOptions }] as T,
|
||||||
[type, { ...options2, ...mergedOptions }] as unknown as T
|
[type, { ...options2, ...mergedOptions }] as T
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@ const mergeComboInputSpec = <T extends ComboInputSpec | ComboInputSpecV2>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return mergeCommonInputSpec(
|
return mergeCommonInputSpec(
|
||||||
['COMBO', { ...options1, options: intersection }] as unknown as T,
|
['COMBO', { ...options1, options: intersection }] as T,
|
||||||
['COMBO', { ...options2, options: intersection }] as unknown as T
|
['COMBO', { ...options2, options: intersection }] as T
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +107,7 @@ const mergeCommonInputSpec = <T extends InputSpec>(
|
|||||||
return value1 === value2 || (_.isNil(value1) && _.isNil(value2))
|
return value1 === value2 || (_.isNil(value1) && _.isNil(value2))
|
||||||
})
|
})
|
||||||
|
|
||||||
return mergeIsValid
|
return mergeIsValid ? ([type, { ...options1, ...options2 }] as T) : null
|
||||||
? ([type, { ...options1, ...options2 }] as unknown as T)
|
|
||||||
: null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ export const findNodeByKey = <T extends TreeNode>(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
for (const child of root.children) {
|
for (const child of root.children) {
|
||||||
const result = findNodeByKey(child as T, key)
|
const result = findNodeByKey(child, key)
|
||||||
if (result) {
|
if (result) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -130,11 +130,11 @@ export const findNodeByKey = <T extends TreeNode>(
|
|||||||
* @returns A deep clone of the node.
|
* @returns A deep clone of the node.
|
||||||
*/
|
*/
|
||||||
export function cloneTree<T extends TreeNode>(node: T): T {
|
export function cloneTree<T extends TreeNode>(node: T): T {
|
||||||
const clone: T = { ...node } as T
|
const clone = { ...node }
|
||||||
|
|
||||||
// Clone children recursively
|
// Clone children recursively
|
||||||
if (node.children && node.children.length > 0) {
|
if (node.children && node.children.length > 0) {
|
||||||
clone.children = node.children.map((child) => cloneTree(child as T))
|
clone.children = node.children.map((child) => cloneTree(child))
|
||||||
}
|
}
|
||||||
|
|
||||||
return clone
|
return clone
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ import dotenv from 'dotenv'
|
|||||||
import IconsResolver from 'unplugin-icons/resolver'
|
import IconsResolver from 'unplugin-icons/resolver'
|
||||||
import Icons from 'unplugin-icons/vite'
|
import Icons from 'unplugin-icons/vite'
|
||||||
import Components from 'unplugin-vue-components/vite'
|
import Components from 'unplugin-vue-components/vite'
|
||||||
import { defineConfig } from 'vite'
|
import { type UserConfig, defineConfig } from 'vite'
|
||||||
import { createHtmlPlugin } from 'vite-plugin-html'
|
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||||
import type { UserConfigExport } from 'vitest/config'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addElementVnodeExportPlugin,
|
addElementVnodeExportPlugin,
|
||||||
@@ -154,4 +153,4 @@ export default defineConfig({
|
|||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
exclude: ['@comfyorg/litegraph', '@comfyorg/comfyui-electron-types']
|
exclude: ['@comfyorg/litegraph', '@comfyorg/comfyui-electron-types']
|
||||||
}
|
}
|
||||||
}) as UserConfigExport
|
}) satisfies UserConfig as UserConfig
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Plugin, defineConfig } from 'vite'
|
import { Plugin, defineConfig } from 'vite'
|
||||||
import { mergeConfig } from 'vite'
|
import { mergeConfig } from 'vite'
|
||||||
import type { UserConfig } from 'vitest/config'
|
|
||||||
|
|
||||||
import baseConfig from './vite.config.mts'
|
import baseConfig from './vite.config.mts'
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ const mockElectronAPI: Plugin = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default mergeConfig(
|
export default mergeConfig(
|
||||||
baseConfig as unknown as UserConfig,
|
baseConfig,
|
||||||
defineConfig({
|
defineConfig({
|
||||||
plugins: [mockElectronAPI]
|
plugins: [mockElectronAPI]
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user