mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 06:44:32 +00:00
Road to No Explicit Any Part 7: Scripts and Dialog Cleanup (#8092)
## Summary Continues the TypeScript strict typing improvements by removing `any` types from core scripts and dialog components. ### Changes **api.ts (6 instances)** - Define `V1RawPrompt` and `CloudRawPrompt` tuple types for queue prompt formats - Export `QueueIndex`, `PromptInputs`, `ExtraData`, `OutputsToExecute` from apiSchema - Type `#postItem` body, `storeUserData` data, and `getCustomNodesI18n` return **groupNodeManage.ts (all @ts-expect-error removed)** - Add `GroupNodeConfigEntry` interface to LGraph.ts - Extend `GroupNodeWorkflowData` with `title`, `widgets_values`, and typed `config` - Type all class properties with definite assignment assertions - Type all method parameters and event handlers - Fix save button callback with proper generic types for node ordering **changeTracker.ts (4 instances)** - Type `nodeOutputs` as `Record<string, ExecutedWsMessage['output']>` - Type prompt callback with `CanvasPointerEvent` and proper value types **asyncDialog.ts and dialog.ts** - Make `ComfyAsyncDialog` generic with `DialogAction<T>` type - Type `ComfyDialog` constructor and show method parameters - Update `ManageGroupDialog.show` signature to match base class ## Test plan - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes - [x] Sourcegraph checks for external usage --- Related: Continues from #8083 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8092-Road-to-No-Explicit-Any-Part-7-Scripts-and-Dialog-Cleanup-2ea6d73d365081fbb890e73646a6ad16) by [Unito](https://www.unito.io)
This commit is contained in:
committed by
GitHub
parent
d5f17f7d9f
commit
7ef4ea6f25
@@ -1,28 +1,28 @@
|
||||
import { $el } from '../../ui'
|
||||
import { ComfyDialog } from '../dialog'
|
||||
|
||||
export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
#resolve: (value: any) => void
|
||||
type DialogAction<T> = string | { value?: T; text: string }
|
||||
|
||||
constructor(actions?: Array<string | { value?: any; text: string }>) {
|
||||
export class ComfyAsyncDialog<
|
||||
T = string | null
|
||||
> extends ComfyDialog<HTMLDialogElement> {
|
||||
#resolve: (value: T | null) => void = () => {}
|
||||
|
||||
constructor(actions?: Array<DialogAction<T>>) {
|
||||
super(
|
||||
'dialog.comfy-dialog.comfyui-dialog',
|
||||
// @ts-expect-error fixme ts strict error
|
||||
actions?.map((opt) => {
|
||||
if (typeof opt === 'string') {
|
||||
opt = { text: opt }
|
||||
}
|
||||
const action = typeof opt === 'string' ? { text: opt } : opt
|
||||
return $el('button.comfyui-button', {
|
||||
type: 'button',
|
||||
textContent: opt.text,
|
||||
onclick: () => this.close(opt.value ?? opt.text)
|
||||
})
|
||||
textContent: action.text,
|
||||
onclick: () => this.close((action.value ?? action.text) as T)
|
||||
}) as HTMLButtonElement
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
override show(html: string | HTMLElement | HTMLElement[]) {
|
||||
override show(html: string | HTMLElement | HTMLElement[]): Promise<T | null> {
|
||||
this.element.addEventListener('close', () => {
|
||||
this.close()
|
||||
})
|
||||
@@ -34,7 +34,7 @@ export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
|
||||
})
|
||||
}
|
||||
|
||||
showModal(html: string | HTMLElement | HTMLElement[]) {
|
||||
showModal(html: string | HTMLElement | HTMLElement[]): Promise<T | null> {
|
||||
this.element.addEventListener('close', () => {
|
||||
this.close()
|
||||
})
|
||||
@@ -47,22 +47,22 @@ export class ComfyAsyncDialog extends ComfyDialog<HTMLDialogElement> {
|
||||
})
|
||||
}
|
||||
|
||||
override close(result = null) {
|
||||
override close(result: T | null = null) {
|
||||
this.#resolve(result)
|
||||
this.element.close()
|
||||
super.close()
|
||||
}
|
||||
|
||||
static async prompt({
|
||||
static async prompt<U = string>({
|
||||
title = null,
|
||||
message,
|
||||
actions
|
||||
}: {
|
||||
title: string | null
|
||||
message: string
|
||||
actions: Array<string | { value?: any; text: string }>
|
||||
}) {
|
||||
const dialog = new ComfyAsyncDialog(actions)
|
||||
actions: Array<DialogAction<U>>
|
||||
}): Promise<U | null> {
|
||||
const dialog = new ComfyAsyncDialog<U>(actions)
|
||||
const content = [$el('span', message)]
|
||||
if (title) {
|
||||
content.unshift($el('h3', title))
|
||||
|
||||
@@ -4,11 +4,10 @@ export class ComfyDialog<
|
||||
T extends HTMLElement = HTMLElement
|
||||
> extends EventTarget {
|
||||
element: T
|
||||
// @ts-expect-error fixme ts strict error
|
||||
textElement: HTMLElement
|
||||
textElement!: HTMLElement
|
||||
#buttons: HTMLButtonElement[] | null
|
||||
|
||||
constructor(type = 'div', buttons = null) {
|
||||
constructor(type = 'div', buttons: HTMLButtonElement[] | null = null) {
|
||||
super()
|
||||
this.#buttons = buttons
|
||||
this.element = $el(type + '.comfy-modal', { parent: document.body }, [
|
||||
@@ -35,8 +34,7 @@ export class ComfyDialog<
|
||||
this.element.style.display = 'none'
|
||||
}
|
||||
|
||||
// @ts-expect-error fixme ts strict error
|
||||
show(html) {
|
||||
show(html: string | HTMLElement | HTMLElement[]): void {
|
||||
if (typeof html === 'string') {
|
||||
this.textElement.innerHTML = html
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user