comfy-ts 2.11.0 → 2.13.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.
Files changed (122) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-qtFzOKpu.js → LogsSt-CUeo843w.js} +51 -7
  3. package/dist/LogsSt-CUeo843w.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +595 -73
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +286 -46
  8. package/dist/index.d.ts +286 -46
  9. package/dist/index.js +591 -74
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-BK7BA2dn.js → run-serve-DlRBv_Nk.js} +738 -58
  12. package/dist/run-serve-DlRBv_Nk.js.map +1 -0
  13. package/dist/{run-tui-CQyvMf0N.js → run-tui-B5uxm2_l.js} +43 -18
  14. package/dist/run-tui-B5uxm2_l.js.map +1 -0
  15. package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-E95iTF7E.js} +473 -60
  16. package/dist/schemaDrift-E95iTF7E.js.map +1 -0
  17. package/dist/serve-web.js +710 -174
  18. package/dist/{state--wrz0BQc.js → state-CUp2J1Zy.js} +126 -14
  19. package/dist/state-CUp2J1Zy.js.map +1 -0
  20. package/dist/web.d.ts +286 -46
  21. package/dist/web.js +591 -74
  22. package/dist/web.js.map +1 -1
  23. package/examples/comfy-cloud/sdk.d.ts +163 -163
  24. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  25. package/examples/rvion/10-anima-t2i.cflow.ts +252 -0
  26. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  27. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  28. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  29. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  30. package/extra/README.md +4 -0
  31. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  32. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  33. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  34. package/package.json +15 -7
  35. package/src/cli/draftMeta.ts +39 -0
  36. package/src/cli/serve/ServeApp.ts +305 -30
  37. package/src/cli/serve/applyVarPayload.ts +50 -22
  38. package/src/cli/serve/byteRange.ts +48 -0
  39. package/src/cli/serve/describeVar.ts +42 -6
  40. package/src/cli/serve/llmConfigShape.ts +51 -0
  41. package/src/cli/serve/llmConfigs.ts +52 -0
  42. package/src/cli/serve/run-serve.ts +12 -3
  43. package/src/cli/serve/tagList.ts +92 -0
  44. package/src/cli/serve/tagSource.ts +69 -0
  45. package/src/cli/serve/web/api.ts +72 -0
  46. package/src/cli/serve/web/components/App.tsx +485 -44
  47. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  48. package/src/cli/serve/web/components/Gallery.tsx +133 -31
  49. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  50. package/src/cli/serve/web/components/Icon.tsx +58 -2
  51. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  52. package/src/cli/serve/web/components/Omnibox.tsx +135 -0
  53. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  54. package/src/cli/serve/web/components/SideMenu.tsx +414 -0
  55. package/src/cli/serve/web/components/TooltipLayer.tsx +46 -0
  56. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  57. package/src/cli/serve/web/components/VarsForm.tsx +223 -351
  58. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  59. package/src/cli/serve/web/components/controls/LorasControl.tsx +646 -317
  60. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  61. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  62. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  63. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  64. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  65. package/src/cli/serve/web/components/modKey.ts +2 -0
  66. package/src/cli/serve/web/llm.ts +23 -12
  67. package/src/cli/serve/web/promptEditor/promptExtensions.ts +284 -0
  68. package/src/cli/serve/web/state/EnhancerSt.ts +431 -101
  69. package/src/cli/serve/web/state/FormSt.ts +214 -30
  70. package/src/cli/serve/web/state/OmniboxSt.ts +59 -0
  71. package/src/cli/serve/web/state/WebSt.ts +364 -80
  72. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  73. package/src/cli/serve/web/state/draftNames.ts +16 -0
  74. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  75. package/src/cli/serve/web/state/generateButton.ts +16 -0
  76. package/src/cli/serve/web/state/history.ts +54 -0
  77. package/src/cli/serve/web/state/host.ts +5 -2
  78. package/src/cli/serve/web/state/keptLines.ts +53 -0
  79. package/src/cli/serve/web/state/latentMode.ts +20 -0
  80. package/src/cli/serve/web/state/loraSort.ts +18 -0
  81. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  82. package/src/cli/serve/web/state/omnibox.ts +133 -0
  83. package/src/cli/serve/web/state/payload.ts +38 -58
  84. package/src/cli/serve/web/state/shortcuts.ts +103 -0
  85. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  86. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  87. package/src/cli/serve/web/state/varGroups.ts +24 -0
  88. package/src/cli/serve/web/styles.ts +653 -154
  89. package/src/cli/serve/webBundle.ts +54 -10
  90. package/src/cli/serve/workflowTags.ts +42 -0
  91. package/src/cli/serve/workspaceLabels.ts +23 -0
  92. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  93. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  94. package/src/cli/tui/state/DraftsSt.ts +28 -8
  95. package/src/cli/tui/state/EditorSt.ts +1 -1
  96. package/src/cli/tui/state/LorasSt.ts +1 -1
  97. package/src/cli/tui/state/PickerSt.ts +25 -7
  98. package/src/cli/tui/state/SettingsSt.ts +1 -1
  99. package/src/cli/tui/state/TuiSt.ts +10 -0
  100. package/src/coreExports.ts +21 -0
  101. package/src/host/ComfyHost.ts +17 -2
  102. package/src/host/ResilientWebsocket.ts +54 -4
  103. package/src/host/loraInfoCache.ts +6 -0
  104. package/src/runner/ComfyExecution.ts +60 -0
  105. package/src/runner/ComfyWorkflow.ts +4 -0
  106. package/src/runner/ComfyWsApi.ts +2 -0
  107. package/src/runner/MediaImage.ts +2 -2
  108. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  109. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  110. package/src/state.ts +5 -0
  111. package/src/utils/copyName.ts +12 -0
  112. package/src/vars/ComfyVars.ts +337 -67
  113. package/src/vars/DefinedWorkflow.ts +47 -20
  114. package/src/vars/lanes.ts +238 -0
  115. package/src/vars/loraEntry.ts +101 -0
  116. package/src/vars/promptSyntax.ts +382 -0
  117. package/dist/LogsSt-qtFzOKpu.js.map +0 -1
  118. package/dist/run-serve-BK7BA2dn.js.map +0 -1
  119. package/dist/run-tui-CQyvMf0N.js.map +0 -1
  120. package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
  121. package/dist/state--wrz0BQc.js.map +0 -1
  122. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -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,10 +8,19 @@ 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[]
13
+ /** search tags: what the graph outputs (image, audio, video, text), llm, edit, then free tags */
14
+ tags?: string[]
10
15
  }
11
16
 
17
+ export type PathLabel = { path: string; label: string }
18
+
12
19
  export type IndexPayload = {
13
20
  workflows: ModuleDescription[]
21
+ /** where `.comfy-ts/` lives, and the folder serve scanned */
22
+ workspace?: PathLabel
23
+ root?: PathLabel
14
24
  loadErrors?: Record<string, string>
15
25
  }
16
26
 
@@ -19,6 +29,9 @@ export type GeneratedImage = { filename: string; url: string | null; absPath: st
19
29
  /** a STRING output (PreviewAny). An llm graph produces these and no images at all */
20
30
  export type GeneratedText = { nodeKey: string | null; text: string }
21
31
 
32
+ /** an audio file (SaveAudio*, PreviewAudio): the panel plays it in an <audio> player */
33
+ export type GeneratedAudio = { filename: string; mime: string; url: string | null; absPath: string | null }
34
+
22
35
  export type GenerateOk = {
23
36
  ok: true
24
37
  module: string
@@ -28,6 +41,7 @@ export type GenerateOk = {
28
41
  seeds: Record<string, number>
29
42
  images: GeneratedImage[]
30
43
  texts?: GeneratedText[]
44
+ audios?: GeneratedAudio[]
31
45
  }
32
46
 
33
47
  async function jsonFetch<T>(url: string, init?: RequestInit): Promise<T> {
@@ -57,6 +71,20 @@ export function postGenerate(p: {
57
71
  })
58
72
  }
59
73
 
74
+ /** the workflow's previews for these values: nothing runs, nothing is written */
75
+ export function fetchPreviews(p: {
76
+ module: string
77
+ values: Record<string, unknown>
78
+ signal?: AbortSignal
79
+ }): Promise<{ previews: Record<string, string> }> {
80
+ return jsonFetch(`/preview/${encodeURIComponent(p.module)}`, {
81
+ method: 'POST',
82
+ headers: { 'content-type': 'application/json' },
83
+ body: JSON.stringify(p.values),
84
+ signal: p.signal,
85
+ })
86
+ }
87
+
60
88
  export function saveDraft(
61
89
  p: { module: string; draft: string; values: Record<string, unknown> },
62
90
  opts: { keepalive?: boolean } = {},
@@ -70,6 +98,19 @@ export function saveDraft(
70
98
  })
71
99
  }
72
100
 
101
+ /** the open draft tabs: the serve process keeps them, so every window shows the same ones */
102
+ export function fetchTabs(): Promise<{ tabs: unknown }> {
103
+ return jsonFetch('/tabs')
104
+ }
105
+
106
+ export function saveTabs(tabs: readonly { module: string; draft: string }[]): Promise<{ tabs: unknown }> {
107
+ return jsonFetch('/tabs', {
108
+ method: 'PUT',
109
+ headers: { 'content-type': 'application/json' },
110
+ body: JSON.stringify({ tabs }),
111
+ })
112
+ }
113
+
73
114
  export function deleteDraft(p: { module: string; draft: string }): Promise<{ ok: true; drafts: string[] }> {
74
115
  return jsonFetch(`/drafts/${encodeURIComponent(p.module)}/${encodeURIComponent(p.draft)}`, { method: 'DELETE' })
75
116
  }
@@ -224,6 +265,23 @@ export function deletePromptEnhancer(p: { name: string }): Promise<{ ok: true; e
224
265
  return jsonFetch(`/prompt-enhancers/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
225
266
  }
226
267
 
268
+ /** the enhancer's LLM configs, files under `.comfy-ts/llm-configs/` (server-owned) */
269
+ export function fetchLlmConfigs(): Promise<{ configs: LlmConfigEntry[] }> {
270
+ return jsonFetch('/llm-configs')
271
+ }
272
+
273
+ export function saveLlmConfig(p: LlmConfigEntry): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
274
+ return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, {
275
+ method: 'PUT',
276
+ headers: { 'content-type': 'application/json' },
277
+ body: JSON.stringify(p.config),
278
+ })
279
+ }
280
+
281
+ export function deleteLlmConfig(p: { name: string }): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
282
+ return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
283
+ }
284
+
227
285
  export async function uploadFile(p: { file: File }): Promise<{ path: string; url: string | null }> {
228
286
  const bytes = new Uint8Array(await p.file.arrayBuffer())
229
287
  let bin = ''
@@ -234,3 +292,17 @@ export async function uploadFile(p: { file: File }): Promise<{ path: string; url
234
292
  body: JSON.stringify({ name: p.file.name, dataBase64: btoa(bin) }),
235
293
  })
236
294
  }
295
+
296
+ export type TagHit = { name: string; category: number | null; count: number; alias?: string }
297
+
298
+ /** completion hits from the tag list a prompt var declares; a missing list throws its reason */
299
+ export function fetchTags(p: {
300
+ module: string
301
+ varName: string
302
+ q: string
303
+ limit?: number
304
+ signal?: AbortSignal
305
+ }): Promise<{ hits: TagHit[] }> {
306
+ const q = new URLSearchParams({ q: p.q, limit: String(p.limit ?? 20) })
307
+ return jsonFetch(`/tags/${encodeURIComponent(p.module)}/${encodeURIComponent(p.varName)}?${q}`, { signal: p.signal })
308
+ }
@@ -1,11 +1,20 @@
1
- // layout root: sidebar drawer + form column + results column (right on wide
2
- // screens, below on narrow ones). NO title bar: the workflow head box opens the
3
- // sidebar, so a permanent bar would only spend vertical space naming the app
1
+ // layout root: the menu column (SideMenu.tsx), then the form and results columns placed by
2
+ // the preview panel's own buttons. At 760px and below the menu is a drawer behind ☰
4
3
  import { observer } from 'mobx-react-lite'
5
- import { useEffect } from 'react'
4
+ import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from 'react'
5
+ import { Group, Panel, Separator, useDefaultLayout, usePanelRef } from 'react-resizable-panels'
6
+ import { MenuCards, MenuHead, MenuRail } from 'src/cli/serve/web/components/SideMenu.tsx'
6
7
  import { Gallery } from 'src/cli/serve/web/components/Gallery.tsx'
7
- import { Sidebar } from 'src/cli/serve/web/components/Sidebar.tsx'
8
+ import { Icon, type IconName } from 'src/cli/serve/web/components/Icon.tsx'
9
+ import { LATENT_MODES, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
10
+ import { Omnibox, useOmniboxShortcut } from 'src/cli/serve/web/components/Omnibox.tsx'
11
+ import { TooltipLayer } from 'src/cli/serve/web/components/TooltipLayer.tsx'
12
+ import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
13
+ import { SHORTCUT_KEYS, shortcutOf } from 'src/cli/serve/web/state/shortcuts.ts'
14
+ import { reaction } from 'mobx'
15
+ import { collapsedPreview } from 'src/cli/serve/web/state/stableSlots.ts'
8
16
  import { GenerateButton, VarsForm } from 'src/cli/serve/web/components/VarsForm.tsx'
17
+ import { DraftTabs, useTabShortcuts } from 'src/cli/serve/web/components/DraftTabs.tsx'
9
18
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
10
19
 
11
20
  /** ⌘A / ctrl+A selects the field you are in. The browser does this on its own until something
@@ -34,8 +43,381 @@ function useSelectAllInFields(): void {
34
43
  }, [])
35
44
  }
36
45
 
46
+ /** the preview panel's own controls, on top of it: where it sits, what shows while it runs */
47
+ /** the workflow's live previews (defineWorkflow({ previews })): text computed from the values
48
+ * on screen, refreshed as you edit. Compact by default, the name inline and every line cut to
49
+ * one; a click opens the full text, remembered. A `- ` line is the negative, as in a prompt */
50
+ /** the console opens at its last line, and follows new ones while you are at the bottom, so a
51
+ * run's progress stays in view. Scrolled up to read, it stays where you put it */
52
+ function ConsoleLines(p: { text: string }): ReactNode {
53
+ const ref = useRef<HTMLPreElement>(null)
54
+ // measured on scroll, before the next lines land: after they land it is always false
55
+ const atBottom = useRef(true)
56
+ useLayoutEffect(() => {
57
+ const el = ref.current
58
+ if (el != null && atBottom.current) el.scrollTop = el.scrollHeight
59
+ }, [p.text])
60
+ return (
61
+ <pre
62
+ ref={ref}
63
+ onScroll={(e) => {
64
+ const el = e.currentTarget
65
+ atBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 8
66
+ }}
67
+ >
68
+ {p.text}
69
+ </pre>
70
+ )
71
+ }
72
+
73
+ /** the whole preview text, negative lines included, as the prompt box takes it back. The
74
+ * clipboard needs a secure context: localhost is one, LAN http is not, and the button says so */
75
+ function PreviewCopy(p: { text: string }): ReactNode {
76
+ const [copied, setCopied] = useState(false)
77
+ const canCopy = typeof navigator !== 'undefined' && navigator.clipboard != null
78
+ useEffect(() => {
79
+ if (!copied) return
80
+ const t = setTimeout(() => setCopied(false), 1500)
81
+ return () => clearTimeout(t)
82
+ }, [copied])
83
+ return (
84
+ <button
85
+ type="button"
86
+ className="live-preview-copy"
87
+ disabled={!canCopy}
88
+ data-tip={canCopy ? (copied ? 'copied' : 'copy the full prompt') : 'copy needs localhost or https'}
89
+ onClick={() => {
90
+ navigator.clipboard.writeText(p.text).then(
91
+ () => setCopied(true),
92
+ (e: unknown) => console.error('[comfy-ts] 🔴 copy failed:', e),
93
+ )
94
+ }}
95
+ >
96
+ <Icon name={copied ? 'check' : 'copy'} />
97
+ </button>
98
+ )
99
+ }
100
+
101
+ const LivePreviews = observer(function LivePreviews(p: { st: WebSt }) {
102
+ const form = p.st.form
103
+ const names = form == null ? [] : (p.st.moduleByKey(form.moduleKey)?.previews ?? [])
104
+ if (form == null || names.length === 0) return null
105
+ return (
106
+ <div className="live-previews">
107
+ {names.map((name) => {
108
+ const key = `${form.moduleKey}/${name}`
109
+ const expanded = p.st.expandedPreviews.includes(key)
110
+ const text = form.previews[name] ?? '…'
111
+ const lines = text.split('\n').filter((l) => l.trim() !== '')
112
+ // collapsed = exactly two lines whatever the prompt holds, so typing never moves the
113
+ // gallery; the full text is one click away
114
+ const short = collapsedPreview(text)
115
+ return (
116
+ <div key={name} className="live-preview-row">
117
+ <button
118
+ type="button"
119
+ className={expanded ? 'live-preview expanded' : 'live-preview'}
120
+ data-tip={expanded ? 'click to show one line each' : 'click for the full text'}
121
+ onClick={() => p.st.togglePreviewExpanded(key)}
122
+ >
123
+ <span className="live-preview-name">
124
+ {name}
125
+ {form.previewError == null ? null : (
126
+ <span className="live-preview-error" data-tip={`preview failed: ${form.previewError}`}>
127
+ 🔴
128
+ </span>
129
+ )}
130
+ </span>
131
+ <span className="live-preview-lines">
132
+ {!expanded ? (
133
+ <>
134
+ <span className="live-preview-line">{short.positive}</span>
135
+ <span className="live-preview-line negative">
136
+ {short.negative === '' ? '' : `− ${short.negative}`}
137
+ </span>
138
+ </>
139
+ ) : null}
140
+ {expanded &&
141
+ lines.map((line, ix) =>
142
+ line.startsWith('- ') ? (
143
+ // index keys: a preview's lines have no identity of their own
144
+ <span key={ix} className="live-preview-line negative">
145
+ − {line.slice(2)}
146
+ </span>
147
+ ) : (
148
+ <span key={ix} className="live-preview-line">
149
+ {line}
150
+ </span>
151
+ ),
152
+ )}
153
+ </span>
154
+ </button>
155
+ <PreviewCopy text={text} />
156
+ </div>
157
+ )
158
+ })}
159
+ </div>
160
+ )
161
+ })
162
+
163
+ const LATENT_ICON: Record<LatentMode, IconName> = { full: 'image', corner: 'panel-corner', off: 'panel-off' }
164
+
165
+ const ResultsHead = observer(function ResultsHead(p: { st: WebSt }) {
166
+ return (
167
+ <div className="results-head">
168
+ {/* a caption over each group: unlabelled icon strips read as one. Placement is page
169
+ layout, so it lives in the menu column */}
170
+ <div className="head-group-labeled">
171
+ <span className="group-caption">while running</span>
172
+ <span className="row-inline head-row">
173
+ <span className="btn-group">
174
+ {LATENT_MODES.map((m) => (
175
+ <button
176
+ key={m.mode}
177
+ type="button"
178
+ className={p.st.latentMode === m.mode ? 'sel' : ''}
179
+ data-tip={m.tip}
180
+ onClick={() => p.st.setLatentMode(m.mode)}
181
+ >
182
+ <Icon name={LATENT_ICON[m.mode]} />
183
+ </button>
184
+ ))}
185
+ </span>
186
+ </span>
187
+ </div>
188
+ <label className="cols-field" data-tip="results side by side: 1 is one image as wide as this panel">
189
+ <Icon name="grid" />
190
+ <input
191
+ type="number"
192
+ min={1}
193
+ max={8}
194
+ step={1}
195
+ value={p.st.resultsColumns}
196
+ onChange={(e) => {
197
+ const n = Number(e.target.value)
198
+ if (e.target.value !== '' && Number.isFinite(n)) p.st.setResultsColumns(n)
199
+ }}
200
+ />
201
+ cols
202
+ </label>
203
+ <span className="btn-group">
204
+ <button
205
+ type="button"
206
+ className={p.st.blurResults ? 'sel' : ''}
207
+ data-tip={
208
+ p.st.blurResults
209
+ ? 'blurred until you hover: click for always clear'
210
+ : 'always clear: click to blur until you hover'
211
+ }
212
+ onClick={() => p.st.toggleBlur()}
213
+ >
214
+ <Icon name={p.st.blurResults ? 'eye-off' : 'eye'} /> blur
215
+ <span className="kbd-hint">
216
+ {MOD_KEY}
217
+ {SHORTCUT_KEYS['toggle-blur']}
218
+ </span>
219
+ </button>
220
+ </span>
221
+ </div>
222
+ )
223
+ })
224
+
225
+ /** below this width two side by side panels leave the form unusable, so a side placement
226
+ * stacks: the chosen mode adapting, the button stays lit */
227
+ const SPLIT_MIN_WIDTH = 760
228
+
229
+ function useNarrow(): boolean {
230
+ const query = `(max-width: ${SPLIT_MIN_WIDTH}px)`
231
+ const [narrow, setNarrow] = useState(() => window.matchMedia(query).matches)
232
+ useEffect(() => {
233
+ const mq = window.matchMedia(query)
234
+ const on = (): void => setNarrow(mq.matches)
235
+ mq.addEventListener('change', on)
236
+ return () => mq.removeEventListener('change', on)
237
+ }, [query])
238
+ return narrow
239
+ }
240
+
241
+ /** the sizes you drag are kept in this browser; a blocked storage just forgets them */
242
+ const splitStorage = {
243
+ getItem: (key: string): string | null => {
244
+ try {
245
+ return localStorage.getItem(key)
246
+ } catch {
247
+ return null
248
+ }
249
+ },
250
+ setItem: (key: string, value: string): void => {
251
+ try {
252
+ localStorage.setItem(key, value)
253
+ } catch {
254
+ // storage full or blocked: the split just is not remembered
255
+ }
256
+ },
257
+ }
258
+
259
+ const SplitWork = observer(function SplitWork(p: { st: WebSt; left: boolean; form: ReactNode; results: ReactNode }) {
260
+ // one remembered layout per side: dragging the left split does not move the right one
261
+ const id = p.left ? 'comfy-ts-split-left' : 'comfy-ts-split-right'
262
+ const saved = useDefaultLayout({ id, storage: splitStorage })
263
+ const formPanel = (
264
+ <Panel id="form" minSize="30%" className="split-panel split-form">
265
+ {p.form}
266
+ </Panel>
267
+ )
268
+ const resultsPanel = (
269
+ <Panel id="results" defaultSize="34%" minSize="16%" className="split-panel split-results">
270
+ {p.results}
271
+ </Panel>
272
+ )
273
+ return (
274
+ <Group
275
+ key={id}
276
+ id={id}
277
+ orientation="horizontal"
278
+ // NOT the layout-side / layout-left classes: those style the stacked page, and one of
279
+ // their rules (align-items: flex-start) kept the panels from stretching to the window,
280
+ // so they grew with the form and the window cut it off, with nothing to scroll
281
+ className={`work split split-${p.left ? 'left' : 'right'}`}
282
+ defaultLayout={saved.defaultLayout}
283
+ onLayoutChanged={saved.onLayoutChanged}
284
+ >
285
+ {p.left ? resultsPanel : formPanel}
286
+ <Separator className="split-handle" />
287
+ {p.left ? formPanel : resultsPanel}
288
+ </Group>
289
+ )
290
+ })
291
+
292
+ /** px: the rail is one icon wide, and a column dragged below MENU_MIN snaps to it */
293
+ const MENU_RAIL = 48
294
+ const MENU_MIN = 180
295
+
296
+ /** the menu as a resizable left Panel: its size and its collapsed state are kept in this
297
+ * browser, like the form and results split */
298
+ const MenuLayout = observer(function MenuLayout(p: { st: WebSt; main: ReactNode }) {
299
+ const saved = useDefaultLayout({ id: 'comfy-ts-menu', storage: splitStorage })
300
+ const menuRef = usePanelRef()
301
+ const [collapsed, setCollapsed] = useState(false)
302
+ // a rename (F2) types into the menu: a folded menu opens so the input is on screen
303
+ useEffect(
304
+ () =>
305
+ reaction(
306
+ () => p.st.renamingDraft != null,
307
+ (renaming) => {
308
+ const panel = menuRef.current
309
+ if (renaming && panel != null && panel.isCollapsed()) panel.expand()
310
+ },
311
+ ),
312
+ [p.st, menuRef],
313
+ )
314
+ // ⌘B and ☰ bump the tick; folding is the Panel's own state, so it is remembered with its size
315
+ useEffect(
316
+ () =>
317
+ reaction(
318
+ () => p.st.menuFoldTick,
319
+ () => {
320
+ const panel = menuRef.current
321
+ if (panel == null) return
322
+ if (panel.isCollapsed()) panel.expand()
323
+ else panel.collapse()
324
+ },
325
+ ),
326
+ [p.st, menuRef],
327
+ )
328
+ return (
329
+ <Group
330
+ id="comfy-ts-menu"
331
+ orientation="horizontal"
332
+ className="menu-layout"
333
+ defaultLayout={saved.defaultLayout}
334
+ onLayoutChanged={saved.onLayoutChanged}
335
+ >
336
+ <Panel
337
+ id="menu"
338
+ panelRef={menuRef}
339
+ defaultSize={220}
340
+ minSize={MENU_MIN}
341
+ maxSize={420}
342
+ collapsible
343
+ collapsedSize={MENU_RAIL}
344
+ groupResizeBehavior="preserve-pixel-size"
345
+ onResize={(size) => setCollapsed(size.inPixels < MENU_MIN - 1)}
346
+ className="menu-panel"
347
+ >
348
+ {collapsed ? (
349
+ <MenuRail st={p.st} onExpand={() => menuRef.current?.expand()} />
350
+ ) : (
351
+ <div className="menu-col">
352
+ <MenuHead
353
+ tip={`fold the menu to icons (${MOD_KEY}B), it stays folded in this browser`}
354
+ keyHint={`${MOD_KEY}${SHORTCUT_KEYS['toggle-menu']}`}
355
+ onBurger={() => menuRef.current?.collapse()}
356
+ />
357
+ <MenuCards st={p.st} />
358
+ </div>
359
+ )}
360
+ </Panel>
361
+ <Separator className="split-handle" />
362
+ <Panel id="main" minSize="40%" className="menu-main">
363
+ {p.main}
364
+ </Panel>
365
+ </Group>
366
+ )
367
+ })
368
+
369
+ /** phones: a slim bar naming where you are, the whole menu one tap away */
370
+ const MobileBar = observer(function MobileBar(p: { st: WebSt }) {
371
+ const form = p.st.form
372
+ return (
373
+ <div className="mobile-bar">
374
+ <button type="button" className="head-icon" aria-label="menu" onClick={() => p.st.setMenuOpen(true)}>
375
+ <Icon name="menu" />
376
+ </button>
377
+ <button type="button" className="mobile-where" onClick={() => p.st.omnibox.open()}>
378
+ <span className="menu-value mobile-workflow">{form?.moduleKey ?? 'no workflow'}</span>
379
+ {form == null ? null : <span className="mobile-draft"> · {form.draft}</span>}
380
+ </button>
381
+ </div>
382
+ )
383
+ })
384
+
385
+ const MenuDrawer = observer(function MenuDrawer(p: { st: WebSt }) {
386
+ if (!p.st.menuOpen) return null
387
+ return (
388
+ <div className="drawer-overlay" onClick={() => p.st.setMenuOpen(false)}>
389
+ <div className="drawer" onClick={(e) => e.stopPropagation()}>
390
+ <MenuHead
391
+ tip="close the menu"
392
+ keyHint={`${MOD_KEY}${SHORTCUT_KEYS['toggle-menu']}`}
393
+ onBurger={() => p.st.setMenuOpen(false)}
394
+ />
395
+ <MenuCards st={p.st} />
396
+ </div>
397
+ </div>
398
+ )
399
+ })
400
+
401
+ /** ⌘B (ctrl elsewhere) folds the menu column, or opens and closes the drawer on a phone */
402
+ function useMenuShortcut(st: WebSt, narrow: boolean): void {
403
+ useEffect(() => {
404
+ const onKey = (e: KeyboardEvent): void => {
405
+ if (shortcutOf(e) !== 'toggle-menu') return
406
+ e.preventDefault()
407
+ if (narrow) st.setMenuOpen(!st.menuOpen)
408
+ else st.requestMenuFold()
409
+ }
410
+ window.addEventListener('keydown', onKey)
411
+ return () => window.removeEventListener('keydown', onKey)
412
+ }, [st, narrow])
413
+ }
414
+
37
415
  export const App = observer(function App(p: { st: WebSt }) {
416
+ const narrow = useNarrow()
417
+ useMenuShortcut(p.st, narrow)
418
+ useTabShortcuts(p.st)
38
419
  useSelectAllInFields()
420
+ useOmniboxShortcut(p.st)
39
421
  if (p.st.phase === 'loading') return <div className="center">loading…</div>
40
422
  if (p.st.phase === 'error')
41
423
  return (
@@ -43,50 +425,109 @@ export const App = observer(function App(p: { st: WebSt }) {
43
425
  <div className="error">🔴 {p.st.bootError}</div>
44
426
  </div>
45
427
  )
428
+ const layout = p.st.layout
429
+ const formCol = (
430
+ <div className="form-col">
431
+ <VarsForm st={p.st} />
432
+ {/* the ComfyUI console, only while asked for (it polls) */}
433
+ {p.st.showLogs ? (
434
+ <div className="logs">
435
+ <div className="logs-head">
436
+ {/* the host the lines actually come from (pullLogs uses hostFor),
437
+ not the module's declared default */}
438
+ <span>console · {p.st.hostFor(p.st.form?.moduleKey ?? '') || 'host'}</span>
439
+ <button type="button" className="link" onClick={() => p.st.toggleLogs()}>
440
+ hide
441
+ </button>
442
+ </div>
443
+ {p.st.logsError != null ? <div className="error">🔴 {p.st.logsError}</div> : null}
444
+ <ConsoleLines text={p.st.logLines.join('\n')} />
445
+ </div>
446
+ ) : null}
447
+ </div>
448
+ )
449
+ const resultsCol = (
450
+ <div className="results-col">
451
+ <ResultsHead st={p.st} />
452
+ {p.st.generateInResults ? (
453
+ <div className="results-run">
454
+ <GenerateButton st={p.st} />
455
+ {/* one line, always reserved: an error arriving never pushes the gallery down */}
456
+ <span className="run-error" data-tip={p.st.run.error ?? undefined}>
457
+ {p.st.run.error == null ? '' : `🔴 ${p.st.run.error}`}
458
+ </span>
459
+ </div>
460
+ ) : null}
461
+ <LivePreviews st={p.st} />
462
+ <Gallery st={p.st} compact={layout === 'pinned'} />
463
+ </div>
464
+ )
465
+ const notices = (
466
+ <>
467
+ {p.st.formError != null ? <div className="center error">🔴 {p.st.formError}</div> : null}
468
+ {p.st.formLoading && p.st.form == null ? <div className="center">loading draft…</div> : null}
469
+ {p.st.modules.length === 0 ? <div className="center">no workflow modules loaded</div> : null}
470
+ </>
471
+ )
472
+ // left / right on a screen wide enough: two FULL-HEIGHT panels, each scrolling on its own,
473
+ // split by a handle you drag. Everything else is one scrolling page
474
+ const split = (layout === 'side' || layout === 'left') && !narrow
475
+ const body = split ? (
476
+ <SplitWork
477
+ st={p.st}
478
+ left={layout === 'left'}
479
+ form={
480
+ <>
481
+ {notices}
482
+ {formCol}
483
+ </>
484
+ }
485
+ results={resultsCol}
486
+ />
487
+ ) : (
488
+ <div className="main">
489
+ {notices}
490
+ {/* the layout buttons drive ONE class, and it is the whole truth: the selected
491
+ button always names where the panel is */}
492
+ <div className={`work layout-${layout}`}>
493
+ {formCol}
494
+ {layout === 'off' ? (
495
+ // the panel took its buttons with it: this is the way back
496
+ <button
497
+ type="button"
498
+ className="show-preview"
499
+ data-tip="show the preview panel again"
500
+ onClick={() => p.st.showPreview()}
501
+ >
502
+ <Icon name="panel-side" /> preview
503
+ </button>
504
+ ) : (
505
+ resultsCol
506
+ )}
507
+ </div>
508
+ </div>
509
+ )
46
510
  return (
47
511
  <div className="app">
512
+ {narrow ? <MobileBar st={p.st} /> : null}
48
513
  <div className="cols">
49
- {p.st.sidebarOpen ? <div className="backdrop" onClick={() => p.st.toggleSidebar()} /> : null}
50
- {p.st.sidebarOpen ? <Sidebar st={p.st} /> : null}
51
- <div className="main">
52
- {p.st.formError != null ? <div className="center error">🔴 {p.st.formError}</div> : null}
53
- {p.st.formLoading && p.st.form == null ? <div className="center">loading draft…</div> : null}
54
- {p.st.modules.length === 0 ? <div className="center">no workflow modules loaded</div> : null}
55
- {/* the layout buttons drive ONE class, and it is the whole truth: the selected
56
- button always names where the panel is */}
57
- <div className={`work layout-${p.st.layout}`}>
58
- <div className="form-col">
59
- <VarsForm st={p.st} />
60
- {/* the ComfyUI console, only while asked for (it polls) */}
61
- {p.st.showLogs ? (
62
- <div className="logs">
63
- <div className="logs-head">
64
- {/* the host the lines actually come from (pullLogs uses hostFor),
65
- not the module's declared default */}
66
- <span>console · {p.st.hostFor(p.st.form?.moduleKey ?? '') || 'host'}</span>
67
- <button type="button" className="link" onClick={() => p.st.toggleLogs()}>
68
- hide
69
- </button>
70
- </div>
71
- {p.st.logsError != null ? <div className="error">🔴 {p.st.logsError}</div> : null}
72
- <pre>{p.st.logLines.join('\n')}</pre>
73
- </div>
74
- ) : null}
75
- </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'} />
514
+ {narrow ? (
515
+ body
516
+ ) : (
517
+ <MenuLayout
518
+ st={p.st}
519
+ main={
520
+ <div className="tabs-col">
521
+ <DraftTabs st={p.st} />
522
+ <div className="tabs-body">{body}</div>
85
523
  </div>
86
- )}
87
- </div>
88
- </div>
524
+ }
525
+ />
526
+ )}
89
527
  </div>
528
+ {narrow ? <MenuDrawer st={p.st} /> : null}
529
+ <Omnibox st={p.st} />
530
+ <TooltipLayer />
90
531
  </div>
91
532
  )
92
533
  })