comfy-ts 2.11.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-U1H0mP1m.js} +35 -5
- package/dist/LogsSt-U1H0mP1m.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +473 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -31
- package/dist/index.d.ts +191 -31
- package/dist/index.js +469 -63
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-BeAznay5.js} +461 -43
- package/dist/run-serve-BeAznay5.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-BTGjvnKk.js} +43 -18
- package/dist/run-tui-BTGjvnKk.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-Cg39vs53.js} +470 -60
- package/dist/schemaDrift-Cg39vs53.js.map +1 -0
- package/dist/serve-web.js +508 -134
- package/dist/{state--wrz0BQc.js → state-C7REnHan.js} +7 -3
- package/dist/{state--wrz0BQc.js.map → state-C7REnHan.js.map} +1 -1
- package/dist/web.d.ts +191 -31
- package/dist/web.js +469 -63
- package/dist/web.js.map +1 -1
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
- package/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +148 -12
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +48 -0
- package/src/cli/serve/web/components/App.tsx +336 -44
- package/src/cli/serve/web/components/Gallery.tsx +105 -28
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +18 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +85 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +341 -188
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +644 -317
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
- package/src/cli/serve/web/state/FormSt.ts +193 -29
- package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
- package/src/cli/serve/web/state/WebSt.ts +219 -74
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/generateButton.ts +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +69 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +54 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +457 -118
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +18 -2
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +20 -0
- package/src/host/loraInfoCache.ts +6 -0
- package/src/state.ts +5 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +40 -19
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// a booru tag list in memory: parsed once per source, searched per keystroke. PURE (text in, hits
|
|
2
|
+
// out). Formats: the a1111 tagcomplete csv `name,category,count,"alias,alias"`, or one tag per line
|
|
3
|
+
|
|
4
|
+
export type TagEntry = { name: string; category: number | null; count: number; aliases: string[] }
|
|
5
|
+
export type TagHit = { name: string; category: number | null; count: number; alias?: string }
|
|
6
|
+
|
|
7
|
+
/** one csv line, double-quoted fields with `""` escapes */
|
|
8
|
+
function csvFields(line: string): string[] {
|
|
9
|
+
const out: string[] = []
|
|
10
|
+
let cur = ''
|
|
11
|
+
let quoted = false
|
|
12
|
+
for (let i = 0; i < line.length; i++) {
|
|
13
|
+
const ch = line[i]
|
|
14
|
+
if (quoted) {
|
|
15
|
+
if (ch === '"' && line[i + 1] === '"') {
|
|
16
|
+
cur += '"'
|
|
17
|
+
i++
|
|
18
|
+
} else if (ch === '"') quoted = false
|
|
19
|
+
else cur += ch
|
|
20
|
+
} else if (ch === '"') quoted = true
|
|
21
|
+
else if (ch === ',') {
|
|
22
|
+
out.push(cur)
|
|
23
|
+
cur = ''
|
|
24
|
+
} else cur += ch
|
|
25
|
+
}
|
|
26
|
+
out.push(cur)
|
|
27
|
+
return out
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const intOrNull = (s: string | undefined): number | null => (s != null && /^\d+$/.test(s.trim()) ? Number(s) : null)
|
|
31
|
+
|
|
32
|
+
export function parseTagList(text: string): TagEntry[] {
|
|
33
|
+
const out: TagEntry[] = []
|
|
34
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
35
|
+
const line = raw.trim()
|
|
36
|
+
if (line === '' || line.startsWith('#')) continue
|
|
37
|
+
const f = csvFields(line)
|
|
38
|
+
const name = (f[0] ?? '').trim()
|
|
39
|
+
if (name === '') continue
|
|
40
|
+
// `name,count` (two columns) is a counted plain list; three and more is the tagcomplete shape
|
|
41
|
+
const twoCols = f.length === 2
|
|
42
|
+
out.push({
|
|
43
|
+
name,
|
|
44
|
+
category: twoCols ? null : intOrNull(f[1]),
|
|
45
|
+
count: (twoCols ? intOrNull(f[1]) : intOrNull(f[2])) ?? 0,
|
|
46
|
+
aliases: (f[3] ?? '')
|
|
47
|
+
.split(',')
|
|
48
|
+
.map((a) => a.trim())
|
|
49
|
+
.filter((a) => a !== ''),
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** the searchable form: lowercase, spaces as underscores (the lists write `long_hair`) */
|
|
56
|
+
const key = (s: string): string => s.trim().toLowerCase().replace(/\s+/g, '_')
|
|
57
|
+
|
|
58
|
+
export class TagList {
|
|
59
|
+
private rows: { e: TagEntry; name: string; aliases: string[] }[]
|
|
60
|
+
constructor(public readonly entries: TagEntry[]) {
|
|
61
|
+
this.rows = entries.map((e) => ({ e, name: key(e.name), aliases: e.aliases.map(key) }))
|
|
62
|
+
this.rows.sort((a, b) => b.e.count - a.e.count)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static parse(text: string): TagList {
|
|
66
|
+
return new TagList(parseTagList(text))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** prefix of the name first, then prefix of an alias (answered with the name it points to),
|
|
70
|
+
* then a word inside the name (`hair` finds `long_hair`), each by post count */
|
|
71
|
+
search(query: string, limit = 20): TagHit[] {
|
|
72
|
+
const q = key(query)
|
|
73
|
+
if (q === '') return []
|
|
74
|
+
const hits: TagHit[] = []
|
|
75
|
+
const seen = new Set<string>()
|
|
76
|
+
const take = (e: TagEntry, alias?: string): boolean => {
|
|
77
|
+
if (seen.has(e.name)) return false
|
|
78
|
+
seen.add(e.name)
|
|
79
|
+
hits.push(alias == null ? { name: e.name, category: e.category, count: e.count } : { ...pick(e), alias })
|
|
80
|
+
return hits.length >= limit
|
|
81
|
+
}
|
|
82
|
+
for (const r of this.rows) if (r.name.startsWith(q) && take(r.e)) return hits
|
|
83
|
+
for (const r of this.rows) {
|
|
84
|
+
const a = r.aliases.find((x) => x.startsWith(q))
|
|
85
|
+
if (a != null && take(r.e, a)) return hits
|
|
86
|
+
}
|
|
87
|
+
for (const r of this.rows) if (r.name.includes(`_${q}`) && take(r.e)) return hits
|
|
88
|
+
return hits
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const pick = (e: TagEntry): TagHit => ({ name: e.name, category: e.category, count: e.count })
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// where a prompt's tag list comes from: `v.prompt(…, { tags })` names a url, serve reads it once and
|
|
2
|
+
// keeps it in memory. The list never ships with the code: a remote one is fetched on first use and
|
|
3
|
+
// kept under the cache dir, a local one is re-read when its file changes
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { homedir } from 'node:os'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { dirname, isAbsolute, join, resolve } from 'pathe'
|
|
8
|
+
import { TagList } from 'src/cli/serve/tagList.ts'
|
|
9
|
+
import { sha1HexOfString } from 'src/utils/sha1.ts'
|
|
10
|
+
|
|
11
|
+
export type TagSourceRef = { kind: 'file'; path: string } | { kind: 'http'; url: string }
|
|
12
|
+
|
|
13
|
+
/** http(s) stays a url; `file://`, `~/`, absolute and relative (to the workflow file) become a path */
|
|
14
|
+
export function resolveTagSource(url: string, moduleFile: string): TagSourceRef {
|
|
15
|
+
if (/^https?:\/\//i.test(url)) return { kind: 'http', url }
|
|
16
|
+
if (url.startsWith('file://')) return { kind: 'file', path: fileURLToPath(url) }
|
|
17
|
+
if (url === '~' || url.startsWith('~/')) return { kind: 'file', path: join(homedir(), url.slice(1)) }
|
|
18
|
+
if (isAbsolute(url)) return { kind: 'file', path: url }
|
|
19
|
+
return { kind: 'file', path: resolve(dirname(moduleFile), url) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class TagSources {
|
|
23
|
+
private files = new Map<string, { mtimeMs: number; list: TagList }>()
|
|
24
|
+
private remote = new Map<string, Promise<TagList>>()
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private p: {
|
|
28
|
+
/** where remote lists are kept between runs */
|
|
29
|
+
cacheDir: () => string
|
|
30
|
+
/** a capped download: a tag list url pointing at something huge must not exhaust serve */
|
|
31
|
+
fetchText: (url: string) => Promise<string>
|
|
32
|
+
},
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
async load(ref: TagSourceRef): Promise<TagList> {
|
|
36
|
+
if (ref.kind === 'file') return this.loadFile(ref.path)
|
|
37
|
+
const hit = this.remote.get(ref.url)
|
|
38
|
+
if (hit != null) return hit
|
|
39
|
+
const pending = this.loadRemote(ref.url)
|
|
40
|
+
this.remote.set(ref.url, pending)
|
|
41
|
+
// a failure is not remembered: the next keystroke retries (the network may be back)
|
|
42
|
+
pending.catch(() => this.remote.delete(ref.url))
|
|
43
|
+
return pending
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private loadFile(path: string): TagList {
|
|
47
|
+
if (!existsSync(path)) throw new Error(`tag list not found: ${path}`)
|
|
48
|
+
const mtimeMs = statSync(path).mtimeMs
|
|
49
|
+
const cached = this.files.get(path)
|
|
50
|
+
if (cached != null && cached.mtimeMs === mtimeMs) return cached.list
|
|
51
|
+
const list = TagList.parse(readFileSync(path, 'utf8'))
|
|
52
|
+
if (list.entries.length === 0) throw new Error(`tag list is empty: ${path}`)
|
|
53
|
+
this.files.set(path, { mtimeMs, list })
|
|
54
|
+
return list
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private async loadRemote(url: string): Promise<TagList> {
|
|
58
|
+
const file = join(this.p.cacheDir(), `${sha1HexOfString(url)}.txt`)
|
|
59
|
+
if (existsSync(file)) return TagList.parse(readFileSync(file, 'utf8'))
|
|
60
|
+
console.log(`[serve] fetching tag list ${url}`)
|
|
61
|
+
const text = await this.p.fetchText(url)
|
|
62
|
+
const list = TagList.parse(text)
|
|
63
|
+
if (list.entries.length === 0) throw new Error(`tag list is empty: ${url}`)
|
|
64
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
65
|
+
writeFileSync(file, text)
|
|
66
|
+
console.log(`[serve] tag list ${url}: ${list.entries.length} tags, kept in ${file}`)
|
|
67
|
+
return list
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/cli/serve/web/api.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// typed fetch layer over the serve json api — the ONLY web-ui module that talks http
|
|
2
|
+
import type { LlmConfigEntry } from 'src/cli/serve/llmConfigShape.ts'
|
|
2
3
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
3
4
|
|
|
4
5
|
export type ModuleDescription = {
|
|
@@ -7,6 +8,8 @@ export type ModuleDescription = {
|
|
|
7
8
|
host: string
|
|
8
9
|
drafts: string[]
|
|
9
10
|
vars: Record<string, VarDescriptor>
|
|
11
|
+
/** names of the workflow's live previews (POST /preview/<module>) */
|
|
12
|
+
previews?: string[]
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export type IndexPayload = {
|
|
@@ -57,6 +60,20 @@ export function postGenerate(p: {
|
|
|
57
60
|
})
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
/** the workflow's previews for these values: nothing runs, nothing is written */
|
|
64
|
+
export function fetchPreviews(p: {
|
|
65
|
+
module: string
|
|
66
|
+
values: Record<string, unknown>
|
|
67
|
+
signal?: AbortSignal
|
|
68
|
+
}): Promise<{ previews: Record<string, string> }> {
|
|
69
|
+
return jsonFetch(`/preview/${encodeURIComponent(p.module)}`, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'content-type': 'application/json' },
|
|
72
|
+
body: JSON.stringify(p.values),
|
|
73
|
+
signal: p.signal,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
export function saveDraft(
|
|
61
78
|
p: { module: string; draft: string; values: Record<string, unknown> },
|
|
62
79
|
opts: { keepalive?: boolean } = {},
|
|
@@ -224,6 +241,23 @@ export function deletePromptEnhancer(p: { name: string }): Promise<{ ok: true; e
|
|
|
224
241
|
return jsonFetch(`/prompt-enhancers/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
|
|
225
242
|
}
|
|
226
243
|
|
|
244
|
+
/** the enhancer's LLM configs, files under `.comfy-ts/llm-configs/` (server-owned) */
|
|
245
|
+
export function fetchLlmConfigs(): Promise<{ configs: LlmConfigEntry[] }> {
|
|
246
|
+
return jsonFetch('/llm-configs')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function saveLlmConfig(p: LlmConfigEntry): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
|
|
250
|
+
return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, {
|
|
251
|
+
method: 'PUT',
|
|
252
|
+
headers: { 'content-type': 'application/json' },
|
|
253
|
+
body: JSON.stringify(p.config),
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function deleteLlmConfig(p: { name: string }): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
|
|
258
|
+
return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
|
|
259
|
+
}
|
|
260
|
+
|
|
227
261
|
export async function uploadFile(p: { file: File }): Promise<{ path: string; url: string | null }> {
|
|
228
262
|
const bytes = new Uint8Array(await p.file.arrayBuffer())
|
|
229
263
|
let bin = ''
|
|
@@ -234,3 +268,17 @@ export async function uploadFile(p: { file: File }): Promise<{ path: string; url
|
|
|
234
268
|
body: JSON.stringify({ name: p.file.name, dataBase64: btoa(bin) }),
|
|
235
269
|
})
|
|
236
270
|
}
|
|
271
|
+
|
|
272
|
+
export type TagHit = { name: string; category: number | null; count: number; alias?: string }
|
|
273
|
+
|
|
274
|
+
/** completion hits from the tag list a prompt var declares; a missing list throws its reason */
|
|
275
|
+
export function fetchTags(p: {
|
|
276
|
+
module: string
|
|
277
|
+
varName: string
|
|
278
|
+
q: string
|
|
279
|
+
limit?: number
|
|
280
|
+
signal?: AbortSignal
|
|
281
|
+
}): Promise<{ hits: TagHit[] }> {
|
|
282
|
+
const q = new URLSearchParams({ q: p.q, limit: String(p.limit ?? 20) })
|
|
283
|
+
return jsonFetch(`/tags/${encodeURIComponent(p.module)}/${encodeURIComponent(p.varName)}?${q}`, { signal: p.signal })
|
|
284
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
// layout root:
|
|
2
|
-
//
|
|
3
|
-
// sidebar, so a permanent bar would only spend vertical space naming the app
|
|
1
|
+
// layout root: form column + results column, placed by the preview panel's own buttons.
|
|
2
|
+
// NO title bar and no menu: ⌘K / ⌘J or the workflow head box opens the omnibox
|
|
4
3
|
import { observer } from 'mobx-react-lite'
|
|
5
|
-
import { useEffect } from 'react'
|
|
4
|
+
import { useEffect, useState, type ReactNode } from 'react'
|
|
5
|
+
import { Group, Panel, Separator, useDefaultLayout } from 'react-resizable-panels'
|
|
6
6
|
import { Gallery } from 'src/cli/serve/web/components/Gallery.tsx'
|
|
7
|
-
import {
|
|
7
|
+
import { Icon, type IconName } from 'src/cli/serve/web/components/Icon.tsx'
|
|
8
|
+
import { LATENT_MODES, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
|
|
9
|
+
import { Omnibox, useOmniboxShortcut } from 'src/cli/serve/web/components/Omnibox.tsx'
|
|
10
|
+
import { TooltipLayer } from 'src/cli/serve/web/components/TooltipLayer.tsx'
|
|
11
|
+
import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
|
|
12
|
+
import { collapsedPreview } from 'src/cli/serve/web/state/stableSlots.ts'
|
|
8
13
|
import { GenerateButton, VarsForm } from 'src/cli/serve/web/components/VarsForm.tsx'
|
|
9
|
-
import type
|
|
14
|
+
import { LAYOUTS, type WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
10
15
|
|
|
11
16
|
/** ⌘A / ctrl+A selects the field you are in. The browser does this on its own until something
|
|
12
17
|
* on the page consumes the event, and this panel has several window-level key handlers plus a
|
|
@@ -34,8 +39,251 @@ function useSelectAllInFields(): void {
|
|
|
34
39
|
}, [])
|
|
35
40
|
}
|
|
36
41
|
|
|
42
|
+
/** the preview panel's own controls, on top of it: where it sits, what shows while it runs */
|
|
43
|
+
/** the workflow's live previews (defineWorkflow({ previews })): text computed from the values
|
|
44
|
+
* on screen, refreshed as you edit. Compact by default, the name inline and every line cut to
|
|
45
|
+
* one; a click opens the full text, remembered. A `- ` line is the negative, as in a prompt */
|
|
46
|
+
const LivePreviews = observer(function LivePreviews(p: { st: WebSt }) {
|
|
47
|
+
const form = p.st.form
|
|
48
|
+
const names = form == null ? [] : (p.st.moduleByKey(form.moduleKey)?.previews ?? [])
|
|
49
|
+
if (form == null || names.length === 0) return null
|
|
50
|
+
return (
|
|
51
|
+
<div className="live-previews">
|
|
52
|
+
{names.map((name) => {
|
|
53
|
+
const key = `${form.moduleKey}/${name}`
|
|
54
|
+
const expanded = p.st.expandedPreviews.includes(key)
|
|
55
|
+
const text = form.previews[name] ?? '…'
|
|
56
|
+
const lines = text.split('\n').filter((l) => l.trim() !== '')
|
|
57
|
+
// collapsed = exactly two lines whatever the prompt holds, so typing never moves the
|
|
58
|
+
// gallery; the full text is one click away
|
|
59
|
+
const short = collapsedPreview(text)
|
|
60
|
+
return (
|
|
61
|
+
<button
|
|
62
|
+
key={name}
|
|
63
|
+
type="button"
|
|
64
|
+
className={expanded ? 'live-preview expanded' : 'live-preview'}
|
|
65
|
+
data-tip={expanded ? 'click to show one line each' : 'click for the full text'}
|
|
66
|
+
onClick={() => p.st.togglePreviewExpanded(key)}
|
|
67
|
+
>
|
|
68
|
+
<span className="live-preview-name">
|
|
69
|
+
{name}
|
|
70
|
+
{form.previewError == null ? null : (
|
|
71
|
+
<span className="live-preview-error" data-tip={`preview failed: ${form.previewError}`}>
|
|
72
|
+
🔴
|
|
73
|
+
</span>
|
|
74
|
+
)}
|
|
75
|
+
</span>
|
|
76
|
+
<span className="live-preview-lines">
|
|
77
|
+
{!expanded ? (
|
|
78
|
+
<>
|
|
79
|
+
<span className="live-preview-line">{short.positive}</span>
|
|
80
|
+
<span className="live-preview-line negative">
|
|
81
|
+
{short.negative === '' ? '' : `− ${short.negative}`}
|
|
82
|
+
</span>
|
|
83
|
+
</>
|
|
84
|
+
) : null}
|
|
85
|
+
{expanded &&
|
|
86
|
+
lines.map((line, ix) =>
|
|
87
|
+
line.startsWith('- ') ? (
|
|
88
|
+
// index keys: a preview's lines have no identity of their own
|
|
89
|
+
<span key={ix} className="live-preview-line negative">
|
|
90
|
+
− {line.slice(2)}
|
|
91
|
+
</span>
|
|
92
|
+
) : (
|
|
93
|
+
<span key={ix} className="live-preview-line">
|
|
94
|
+
{line}
|
|
95
|
+
</span>
|
|
96
|
+
),
|
|
97
|
+
)}
|
|
98
|
+
</span>
|
|
99
|
+
</button>
|
|
100
|
+
)
|
|
101
|
+
})}
|
|
102
|
+
</div>
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const LATENT_ICON: Record<LatentMode, IconName> = { full: 'image', corner: 'panel-corner', off: 'panel-off' }
|
|
107
|
+
|
|
108
|
+
const ResultsHead = observer(function ResultsHead(p: { st: WebSt }) {
|
|
109
|
+
return (
|
|
110
|
+
<div className="results-head">
|
|
111
|
+
{/* a caption over each group: three unlabelled icon strips read as one */}
|
|
112
|
+
<div className="head-group-labeled">
|
|
113
|
+
<span className="group-caption">preview</span>
|
|
114
|
+
<span className="btn-group">
|
|
115
|
+
{LAYOUTS.map((l) => (
|
|
116
|
+
<button
|
|
117
|
+
key={l.id}
|
|
118
|
+
type="button"
|
|
119
|
+
className={p.st.layout === l.id ? 'sel' : ''}
|
|
120
|
+
data-tip={l.title}
|
|
121
|
+
onClick={() => p.st.setLayout(l.id)}
|
|
122
|
+
>
|
|
123
|
+
<Icon name={l.icon} />
|
|
124
|
+
</button>
|
|
125
|
+
))}
|
|
126
|
+
</span>
|
|
127
|
+
</div>
|
|
128
|
+
<div className="head-group-labeled">
|
|
129
|
+
<span className="group-caption">while running</span>
|
|
130
|
+
<span className="row-inline head-row">
|
|
131
|
+
<span className="btn-group">
|
|
132
|
+
{LATENT_MODES.map((m) => (
|
|
133
|
+
<button
|
|
134
|
+
key={m.mode}
|
|
135
|
+
type="button"
|
|
136
|
+
className={p.st.latentMode === m.mode ? 'sel' : ''}
|
|
137
|
+
data-tip={m.tip}
|
|
138
|
+
onClick={() => p.st.setLatentMode(m.mode)}
|
|
139
|
+
>
|
|
140
|
+
<Icon name={LATENT_ICON[m.mode]} />
|
|
141
|
+
</button>
|
|
142
|
+
))}
|
|
143
|
+
</span>
|
|
144
|
+
<span className="btn-group">
|
|
145
|
+
<button
|
|
146
|
+
type="button"
|
|
147
|
+
className={p.st.showLogs ? 'sel' : ''}
|
|
148
|
+
data-tip={p.st.showLogs ? 'hide the ComfyUI console' : 'show the ComfyUI console'}
|
|
149
|
+
onClick={() => p.st.toggleLogs()}
|
|
150
|
+
>
|
|
151
|
+
<Icon name="terminal" />
|
|
152
|
+
</button>
|
|
153
|
+
</span>
|
|
154
|
+
</span>
|
|
155
|
+
</div>
|
|
156
|
+
<div className="head-group-labeled">
|
|
157
|
+
<span className="group-caption">results</span>
|
|
158
|
+
<span className="row-inline results-view">
|
|
159
|
+
<span className="btn-group">
|
|
160
|
+
<button
|
|
161
|
+
type="button"
|
|
162
|
+
className={p.st.resultsView === 'fit' ? 'sel' : ''}
|
|
163
|
+
data-tip="fit: one image per row, as wide as this panel"
|
|
164
|
+
onClick={() => p.st.setResultsView('fit')}
|
|
165
|
+
>
|
|
166
|
+
<Icon name="rows" />
|
|
167
|
+
</button>
|
|
168
|
+
<button
|
|
169
|
+
type="button"
|
|
170
|
+
className={p.st.resultsView === 'grid' ? 'sel' : ''}
|
|
171
|
+
data-tip="grid: images at the size you set, as many per row as fit"
|
|
172
|
+
onClick={() => p.st.setResultsView('grid')}
|
|
173
|
+
>
|
|
174
|
+
<Icon name="grid" />
|
|
175
|
+
</button>
|
|
176
|
+
</span>
|
|
177
|
+
{/* always here, greyed out in fit: appearing with grid moved the groups beside it */}
|
|
178
|
+
<input
|
|
179
|
+
type="range"
|
|
180
|
+
className="setting-range"
|
|
181
|
+
min={120}
|
|
182
|
+
max={640}
|
|
183
|
+
step={20}
|
|
184
|
+
disabled={p.st.resultsView !== 'grid'}
|
|
185
|
+
value={p.st.resultsSize}
|
|
186
|
+
data-tip={
|
|
187
|
+
p.st.resultsView === 'grid' ? `image size ${p.st.resultsSize}px` : 'image size, for the grid view'
|
|
188
|
+
}
|
|
189
|
+
onChange={(e) => p.st.setResultsSize(Number(e.target.value))}
|
|
190
|
+
/>
|
|
191
|
+
</span>
|
|
192
|
+
</div>
|
|
193
|
+
<div className="head-group-labeled">
|
|
194
|
+
<span className="group-caption">
|
|
195
|
+
blur <span className="kbd-hint">{MOD_KEY}B</span>
|
|
196
|
+
</span>
|
|
197
|
+
<span className="btn-group">
|
|
198
|
+
<button
|
|
199
|
+
type="button"
|
|
200
|
+
className={p.st.blurResults ? 'sel' : ''}
|
|
201
|
+
data-tip={
|
|
202
|
+
p.st.blurResults
|
|
203
|
+
? `blurred until you hover: click (or ${MOD_KEY}B) for always clear`
|
|
204
|
+
: `always clear: click (or ${MOD_KEY}B) to blur until you hover`
|
|
205
|
+
}
|
|
206
|
+
onClick={() => p.st.toggleBlur()}
|
|
207
|
+
>
|
|
208
|
+
<Icon name={p.st.blurResults ? 'eye-off' : 'eye'} />
|
|
209
|
+
</button>
|
|
210
|
+
</span>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
/** below this width two side by side panels leave the form unusable, so a side placement
|
|
217
|
+
* stacks: the chosen mode adapting, the button stays lit */
|
|
218
|
+
const SPLIT_MIN_WIDTH = 760
|
|
219
|
+
|
|
220
|
+
function useNarrow(): boolean {
|
|
221
|
+
const query = `(max-width: ${SPLIT_MIN_WIDTH}px)`
|
|
222
|
+
const [narrow, setNarrow] = useState(() => window.matchMedia(query).matches)
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
const mq = window.matchMedia(query)
|
|
225
|
+
const on = (): void => setNarrow(mq.matches)
|
|
226
|
+
mq.addEventListener('change', on)
|
|
227
|
+
return () => mq.removeEventListener('change', on)
|
|
228
|
+
}, [query])
|
|
229
|
+
return narrow
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** the sizes you drag are kept in this browser; a blocked storage just forgets them */
|
|
233
|
+
const splitStorage = {
|
|
234
|
+
getItem: (key: string): string | null => {
|
|
235
|
+
try {
|
|
236
|
+
return localStorage.getItem(key)
|
|
237
|
+
} catch {
|
|
238
|
+
return null
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
setItem: (key: string, value: string): void => {
|
|
242
|
+
try {
|
|
243
|
+
localStorage.setItem(key, value)
|
|
244
|
+
} catch {
|
|
245
|
+
// storage full or blocked: the split just is not remembered
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const SplitWork = observer(function SplitWork(p: { st: WebSt; left: boolean; form: ReactNode; results: ReactNode }) {
|
|
251
|
+
// one remembered layout per side: dragging the left split does not move the right one
|
|
252
|
+
const id = p.left ? 'comfy-ts-split-left' : 'comfy-ts-split-right'
|
|
253
|
+
const saved = useDefaultLayout({ id, storage: splitStorage })
|
|
254
|
+
const formPanel = (
|
|
255
|
+
<Panel id="form" minSize="30%" className="split-panel split-form">
|
|
256
|
+
{p.form}
|
|
257
|
+
</Panel>
|
|
258
|
+
)
|
|
259
|
+
const resultsPanel = (
|
|
260
|
+
<Panel id="results" defaultSize="34%" minSize="16%" className="split-panel split-results">
|
|
261
|
+
{p.results}
|
|
262
|
+
</Panel>
|
|
263
|
+
)
|
|
264
|
+
return (
|
|
265
|
+
<Group
|
|
266
|
+
key={id}
|
|
267
|
+
id={id}
|
|
268
|
+
orientation="horizontal"
|
|
269
|
+
// NOT the layout-side / layout-left classes: those style the stacked page, and one of
|
|
270
|
+
// their rules (align-items: flex-start) kept the panels from stretching to the window,
|
|
271
|
+
// so they grew with the form and the window cut it off, with nothing to scroll
|
|
272
|
+
className={`work split split-${p.left ? 'left' : 'right'}`}
|
|
273
|
+
defaultLayout={saved.defaultLayout}
|
|
274
|
+
onLayoutChanged={saved.onLayoutChanged}
|
|
275
|
+
>
|
|
276
|
+
{p.left ? resultsPanel : formPanel}
|
|
277
|
+
<Separator className="split-handle" />
|
|
278
|
+
{p.left ? formPanel : resultsPanel}
|
|
279
|
+
</Group>
|
|
280
|
+
)
|
|
281
|
+
})
|
|
282
|
+
|
|
37
283
|
export const App = observer(function App(p: { st: WebSt }) {
|
|
284
|
+
const narrow = useNarrow()
|
|
38
285
|
useSelectAllInFields()
|
|
286
|
+
useOmniboxShortcut(p.st)
|
|
39
287
|
if (p.st.phase === 'loading') return <div className="center">loading…</div>
|
|
40
288
|
if (p.st.phase === 'error')
|
|
41
289
|
return (
|
|
@@ -43,50 +291,94 @@ export const App = observer(function App(p: { st: WebSt }) {
|
|
|
43
291
|
<div className="error">🔴 {p.st.bootError}</div>
|
|
44
292
|
</div>
|
|
45
293
|
)
|
|
294
|
+
const layout = p.st.layout
|
|
295
|
+
const formCol = (
|
|
296
|
+
<div className="form-col">
|
|
297
|
+
<VarsForm st={p.st} />
|
|
298
|
+
{/* the ComfyUI console, only while asked for (it polls) */}
|
|
299
|
+
{p.st.showLogs ? (
|
|
300
|
+
<div className="logs">
|
|
301
|
+
<div className="logs-head">
|
|
302
|
+
{/* the host the lines actually come from (pullLogs uses hostFor),
|
|
303
|
+
not the module's declared default */}
|
|
304
|
+
<span>console · {p.st.hostFor(p.st.form?.moduleKey ?? '') || 'host'}</span>
|
|
305
|
+
<button type="button" className="link" onClick={() => p.st.toggleLogs()}>
|
|
306
|
+
hide
|
|
307
|
+
</button>
|
|
308
|
+
</div>
|
|
309
|
+
{p.st.logsError != null ? <div className="error">🔴 {p.st.logsError}</div> : null}
|
|
310
|
+
<pre>{p.st.logLines.join('\n')}</pre>
|
|
311
|
+
</div>
|
|
312
|
+
) : null}
|
|
313
|
+
</div>
|
|
314
|
+
)
|
|
315
|
+
const resultsCol = (
|
|
316
|
+
<div className="results-col">
|
|
317
|
+
<ResultsHead st={p.st} />
|
|
318
|
+
{p.st.generateInResults ? (
|
|
319
|
+
<div className="results-run">
|
|
320
|
+
<GenerateButton st={p.st} />
|
|
321
|
+
{/* one line, always reserved: an error arriving never pushes the gallery down */}
|
|
322
|
+
<span className="run-error" data-tip={p.st.run.error ?? undefined}>
|
|
323
|
+
{p.st.run.error == null ? '' : `🔴 ${p.st.run.error}`}
|
|
324
|
+
</span>
|
|
325
|
+
</div>
|
|
326
|
+
) : null}
|
|
327
|
+
<LivePreviews st={p.st} />
|
|
328
|
+
<Gallery st={p.st} compact={layout === 'pinned'} />
|
|
329
|
+
</div>
|
|
330
|
+
)
|
|
331
|
+
const notices = (
|
|
332
|
+
<>
|
|
333
|
+
{p.st.formError != null ? <div className="center error">🔴 {p.st.formError}</div> : null}
|
|
334
|
+
{p.st.formLoading && p.st.form == null ? <div className="center">loading draft…</div> : null}
|
|
335
|
+
{p.st.modules.length === 0 ? <div className="center">no workflow modules loaded</div> : null}
|
|
336
|
+
</>
|
|
337
|
+
)
|
|
338
|
+
// left / right on a screen wide enough: two FULL-HEIGHT panels, each scrolling on its own,
|
|
339
|
+
// split by a handle you drag. Everything else is one scrolling page
|
|
340
|
+
const split = (layout === 'side' || layout === 'left') && !narrow
|
|
46
341
|
return (
|
|
47
342
|
<div className="app">
|
|
48
343
|
<div className="cols">
|
|
49
|
-
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
344
|
+
{split ? (
|
|
345
|
+
<SplitWork
|
|
346
|
+
st={p.st}
|
|
347
|
+
left={layout === 'left'}
|
|
348
|
+
form={
|
|
349
|
+
<>
|
|
350
|
+
{notices}
|
|
351
|
+
{formCol}
|
|
352
|
+
</>
|
|
353
|
+
}
|
|
354
|
+
results={resultsCol}
|
|
355
|
+
/>
|
|
356
|
+
) : (
|
|
357
|
+
<div className="main">
|
|
358
|
+
{notices}
|
|
359
|
+
{/* the layout buttons drive ONE class, and it is the whole truth: the selected
|
|
360
|
+
button always names where the panel is */}
|
|
361
|
+
<div className={`work layout-${layout}`}>
|
|
362
|
+
{formCol}
|
|
363
|
+
{layout === 'off' ? (
|
|
364
|
+
// the panel took its buttons with it: this is the way back
|
|
365
|
+
<button
|
|
366
|
+
type="button"
|
|
367
|
+
className="show-preview"
|
|
368
|
+
data-tip="show the preview panel again"
|
|
369
|
+
onClick={() => p.st.showPreview()}
|
|
370
|
+
>
|
|
371
|
+
<Icon name="panel-side" /> preview
|
|
372
|
+
</button>
|
|
373
|
+
) : (
|
|
374
|
+
resultsCol
|
|
375
|
+
)}
|
|
75
376
|
</div>
|
|
76
|
-
{p.st.layout === 'off' ? null : (
|
|
77
|
-
<div className="results-col">
|
|
78
|
-
{p.st.generateInResults ? (
|
|
79
|
-
<div className="results-run">
|
|
80
|
-
<GenerateButton st={p.st} />
|
|
81
|
-
{p.st.run.error != null ? <span className="error">🔴 {p.st.run.error}</span> : null}
|
|
82
|
-
</div>
|
|
83
|
-
) : null}
|
|
84
|
-
<Gallery st={p.st} compact={p.st.layout === 'pinned'} />
|
|
85
|
-
</div>
|
|
86
|
-
)}
|
|
87
377
|
</div>
|
|
88
|
-
|
|
378
|
+
)}
|
|
89
379
|
</div>
|
|
380
|
+
<Omnibox st={p.st} />
|
|
381
|
+
<TooltipLayer />
|
|
90
382
|
</div>
|
|
91
383
|
)
|
|
92
384
|
})
|