comfy-ts 2.12.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.
- package/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
- package/dist/LogsSt-CUeo843w.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +123 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -16
- package/dist/index.d.ts +96 -16
- package/dist/index.js +123 -12
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BeAznay5.js → run-serve-DlRBv_Nk.js} +281 -19
- package/dist/run-serve-DlRBv_Nk.js.map +1 -0
- package/dist/{run-tui-BTGjvnKk.js → run-tui-B5uxm2_l.js} +4 -4
- package/dist/{run-tui-BTGjvnKk.js.map → run-tui-B5uxm2_l.js.map} +1 -1
- package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
- package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
- package/dist/serve-web.js +291 -129
- package/dist/{state-C7REnHan.js → state-CUp2J1Zy.js} +122 -14
- package/dist/state-CUp2J1Zy.js.map +1 -0
- package/dist/web.d.ts +96 -16
- package/dist/web.js +123 -12
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/sdk.d.ts +163 -163
- package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
- package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
- package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
- package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
- package/examples/rvion/stableAudio3Prompts.ts +19 -0
- package/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +157 -18
- package/src/cli/serve/byteRange.ts +48 -0
- package/src/cli/serve/run-serve.ts +12 -3
- package/src/cli/serve/web/api.ts +24 -0
- package/src/cli/serve/web/components/App.tsx +305 -156
- package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
- package/src/cli/serve/web/components/Gallery.tsx +44 -19
- package/src/cli/serve/web/components/Icon.tsx +40 -0
- package/src/cli/serve/web/components/Omnibox.tsx +70 -20
- package/src/cli/serve/web/components/SideMenu.tsx +414 -0
- package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
- package/src/cli/serve/web/components/VarsForm.tsx +70 -351
- package/src/cli/serve/web/components/controls/LorasControl.tsx +24 -22
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +6 -3
- package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
- package/src/cli/serve/web/state/FormSt.ts +22 -2
- package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
- package/src/cli/serve/web/state/WebSt.ts +172 -33
- package/src/cli/serve/web/state/draftNames.ts +16 -0
- package/src/cli/serve/web/state/draftTabs.ts +75 -0
- package/src/cli/serve/web/state/generateButton.ts +1 -1
- package/src/cli/serve/web/state/omnibox.ts +82 -18
- package/src/cli/serve/web/state/shortcuts.ts +56 -7
- package/src/cli/serve/web/styles.ts +242 -82
- package/src/cli/serve/workflowTags.ts +42 -0
- package/src/cli/serve/workspaceLabels.ts +23 -0
- package/src/cli/tui/state/DraftsSt.ts +10 -6
- package/src/coreExports.ts +1 -0
- package/src/host/ComfyHost.ts +17 -2
- package/src/host/ResilientWebsocket.ts +54 -4
- package/src/runner/ComfyExecution.ts +60 -0
- package/src/runner/ComfyWorkflow.ts +4 -0
- package/src/runner/ComfyWsApi.ts +2 -0
- package/src/runner/MediaImage.ts +2 -2
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
- package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
- package/src/utils/copyName.ts +12 -0
- package/src/vars/DefinedWorkflow.ts +7 -1
- package/dist/LogsSt-U1H0mP1m.js.map +0 -1
- package/dist/run-serve-BeAznay5.js.map +0 -1
- package/dist/state-C7REnHan.js.map +0 -1
|
@@ -52,6 +52,21 @@ export class VarSt {
|
|
|
52
52
|
this.uploadedUrl = url
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** the workflow's declared default, in the shape the controls hold */
|
|
56
|
+
get defaultValue(): unknown {
|
|
57
|
+
return normalizeInitial(this.desc, this.desc.default)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** by value: a size or a choice list is a fresh object every time */
|
|
61
|
+
get isAtDefault(): boolean {
|
|
62
|
+
return JSON.stringify(this.value) === JSON.stringify(this.defaultValue)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** back to what the workflow declares; an edit like any other (autosaved, revertable) */
|
|
66
|
+
resetToDefault(): void {
|
|
67
|
+
this.set(this.defaultValue)
|
|
68
|
+
}
|
|
69
|
+
|
|
55
70
|
revert(): void {
|
|
56
71
|
this.value = this.initial
|
|
57
72
|
this.dirty = false
|
|
@@ -76,7 +91,7 @@ export class FormSt {
|
|
|
76
91
|
private disposers: IReactionDisposer[] = []
|
|
77
92
|
/** saves are chained so two PUTs can never land out of order */
|
|
78
93
|
private saveChain: Promise<boolean> = Promise.resolve(true)
|
|
79
|
-
/** the values json the server last CONFIRMED — what is really on disk */
|
|
94
|
+
/** the values json the server last CONFIRMED — what is really on disk. Observable: `unsaved` reads it */
|
|
80
95
|
private lastSaved: string
|
|
81
96
|
/** the values json last HANDED to the chain, confirmed or still in flight. save() no-ops
|
|
82
97
|
* against this one, never against lastSaved: while a PUT is open the disk does not hold
|
|
@@ -120,7 +135,7 @@ export class FormSt {
|
|
|
120
135
|
host: false,
|
|
121
136
|
disposers: false,
|
|
122
137
|
saveChain: false,
|
|
123
|
-
lastSaved:
|
|
138
|
+
lastSaved: true,
|
|
124
139
|
lastQueued: false,
|
|
125
140
|
queueSeq: false,
|
|
126
141
|
onSettled: false,
|
|
@@ -348,6 +363,11 @@ export class FormSt {
|
|
|
348
363
|
found.source.set(updateLora(found.value, lora, withLora(loraSetting(found.value, lora), { mute })))
|
|
349
364
|
}
|
|
350
365
|
|
|
366
|
+
/** the values on screen are not on disk yet: inside the autosave debounce, or a PUT still open */
|
|
367
|
+
get unsaved(): boolean {
|
|
368
|
+
return JSON.stringify(this.valuesJSON()) !== this.lastSaved
|
|
369
|
+
}
|
|
370
|
+
|
|
351
371
|
get dirtyCount(): number {
|
|
352
372
|
return this.vars.filter((v) => v.dirty).length
|
|
353
373
|
}
|
|
@@ -25,7 +25,9 @@ export class OmniboxSt {
|
|
|
25
25
|
const ix =
|
|
26
26
|
current == null
|
|
27
27
|
? -1
|
|
28
|
-
: this.results.findIndex(
|
|
28
|
+
: this.results.findIndex(
|
|
29
|
+
(e) => e.kind === 'draft' && e.module === current.moduleKey && e.draft === current.draft,
|
|
30
|
+
)
|
|
29
31
|
this.cursor = Math.max(0, ix)
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -8,24 +8,29 @@ import {
|
|
|
8
8
|
fetchHosts,
|
|
9
9
|
fetchIndex,
|
|
10
10
|
fetchSettings,
|
|
11
|
+
fetchTabs,
|
|
11
12
|
pingHost,
|
|
12
13
|
postHostAction,
|
|
13
14
|
postLoraCivitai,
|
|
14
15
|
fetchHostDrift,
|
|
15
16
|
saveDraft,
|
|
16
17
|
saveSettings,
|
|
18
|
+
saveTabs,
|
|
17
19
|
setModuleHost,
|
|
18
20
|
type HostAction,
|
|
19
21
|
type HostsPayload,
|
|
20
22
|
type ModuleDescription,
|
|
23
|
+
type PathLabel,
|
|
21
24
|
type ServeSettings,
|
|
22
25
|
} from 'src/cli/serve/web/api.ts'
|
|
23
26
|
import { EnhancerSt } from 'src/cli/serve/web/state/EnhancerSt.ts'
|
|
24
27
|
import { OmniboxSt } from 'src/cli/serve/web/state/OmniboxSt.ts'
|
|
28
|
+
import { duplicateDraftName, freeDraftName } from 'src/cli/serve/web/state/draftNames.ts'
|
|
25
29
|
import { asLatentMode, type LatentMode } from 'src/cli/serve/web/state/latentMode.ts'
|
|
26
30
|
import { pushHistory, type HistoryEntry } from 'src/cli/serve/web/state/history.ts'
|
|
27
31
|
import { isPromptInput, promptLanesToText, type PromptInput } from 'src/vars/lanes.ts'
|
|
28
32
|
import { FORM_TIMING, FormSt, type FormTiming, type VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
33
|
+
import { closeTab, openTab, readTabs, renameTab, type DraftTab } from 'src/cli/serve/web/state/draftTabs.ts'
|
|
29
34
|
import { logWebError } from 'src/cli/serve/web/logWeb.ts'
|
|
30
35
|
import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
|
|
31
36
|
import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
|
|
@@ -59,13 +64,20 @@ export const DEFAULT_LAYOUT: ResultsLayout = 'side'
|
|
|
59
64
|
export const LAYOUTS: {
|
|
60
65
|
id: ResultsLayout
|
|
61
66
|
icon: 'panel-off' | 'panel-bottom' | 'panel-left' | 'panel-side' | 'panel-corner'
|
|
67
|
+
/** the word under the icon, where the results go */
|
|
68
|
+
label: string
|
|
62
69
|
title: string
|
|
63
70
|
}[] = [
|
|
64
|
-
{ id: 'off', icon: 'panel-off', title: 'no preview: the form only' },
|
|
65
|
-
{ id: 'bottom', icon: 'panel-bottom', title: 'results below the form' },
|
|
66
|
-
{ id: 'left', icon: 'panel-left', title: 'results left of the form' },
|
|
67
|
-
{ id: 'side', icon: 'panel-side', title: 'results right of the form' },
|
|
68
|
-
{
|
|
71
|
+
{ id: 'off', icon: 'panel-off', label: 'none', title: 'no preview: the form only' },
|
|
72
|
+
{ id: 'bottom', icon: 'panel-bottom', label: 'below', title: 'results below the form' },
|
|
73
|
+
{ id: 'left', icon: 'panel-left', label: 'left', title: 'results left of the form' },
|
|
74
|
+
{ id: 'side', icon: 'panel-side', label: 'right', title: 'results right of the form' },
|
|
75
|
+
{
|
|
76
|
+
id: 'pinned',
|
|
77
|
+
icon: 'panel-corner',
|
|
78
|
+
label: 'corner',
|
|
79
|
+
title: 'newest image in the bottom right corner, form scrolls under it',
|
|
80
|
+
},
|
|
69
81
|
]
|
|
70
82
|
|
|
71
83
|
function isLayout(raw: unknown): raw is ResultsLayout {
|
|
@@ -81,8 +93,12 @@ type StoredSelection = {
|
|
|
81
93
|
loraFill?: boolean
|
|
82
94
|
/** trigger words under the lora cards */
|
|
83
95
|
loraTriggers?: boolean
|
|
84
|
-
/** lora image size
|
|
96
|
+
/** the single lora image size, before the form and the popup got one each: seeds both */
|
|
85
97
|
loraScale?: number
|
|
98
|
+
/** lora image size factor in the form's lora rows */
|
|
99
|
+
loraFormScale?: number
|
|
100
|
+
/** lora image size factor in the lora popup */
|
|
101
|
+
loraPopupScale?: number
|
|
86
102
|
/** the label column width, px */
|
|
87
103
|
labelWidth?: number
|
|
88
104
|
loraSort?: string
|
|
@@ -96,8 +112,11 @@ type StoredSelection = {
|
|
|
96
112
|
/** results blurred until hovered */
|
|
97
113
|
blur?: boolean
|
|
98
114
|
/** fit = one per row at the panel's width, grid = the slider's size, wrapping */
|
|
115
|
+
/** the fit/grid pair before columns: read once to seed resultsColumns */
|
|
99
116
|
resultsView?: string
|
|
100
117
|
resultsSize?: number
|
|
118
|
+
/** how many results side by side in the preview, 1 = each as wide as the panel */
|
|
119
|
+
resultsColumns?: number
|
|
101
120
|
/** live previews opened to their full text, as `module/name` */
|
|
102
121
|
expandedPreviews?: string[]
|
|
103
122
|
logs?: boolean
|
|
@@ -123,12 +142,25 @@ export function clampLoraScale(raw: unknown): number {
|
|
|
123
142
|
return Math.min(2, Math.max(0.6, Math.round(n * 20) / 20))
|
|
124
143
|
}
|
|
125
144
|
|
|
126
|
-
|
|
145
|
+
/** the form and the popup each keep their own size: the popup is for browsing, so it is
|
|
146
|
+
* usually drawn bigger than the rows under a var */
|
|
147
|
+
export function readLoraScales(stored: StoredSelection): { form: number; popup: number } {
|
|
148
|
+
return {
|
|
149
|
+
form: clampLoraScale(stored.loraFormScale ?? stored.loraScale),
|
|
150
|
+
popup: clampLoraScale(stored.loraPopupScale ?? stored.loraScale),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** results side by side: one full width image at 1, a thumbnail wall at the top */
|
|
155
|
+
export function clampResultsColumns(raw: unknown): number {
|
|
156
|
+
const n = typeof raw === 'number' && Number.isFinite(raw) ? Math.round(raw) : 1
|
|
157
|
+
return Math.min(8, Math.max(1, n))
|
|
158
|
+
}
|
|
127
159
|
|
|
128
|
-
/** a
|
|
129
|
-
export function
|
|
130
|
-
|
|
131
|
-
return
|
|
160
|
+
/** a blob written before columns keeps its look: fit was one per row, grid about three */
|
|
161
|
+
export function readResultsColumns(stored: StoredSelection): number {
|
|
162
|
+
if (stored.resultsColumns != null) return clampResultsColumns(stored.resultsColumns)
|
|
163
|
+
return stored.resultsView === 'grid' ? 3 : 1
|
|
132
164
|
}
|
|
133
165
|
|
|
134
166
|
export const DEFAULT_LABEL_WIDTH = 120
|
|
@@ -165,6 +197,11 @@ export class WebSt {
|
|
|
165
197
|
bootError = ''
|
|
166
198
|
modules: ModuleDescription[] = []
|
|
167
199
|
loadErrors: Record<string, string> = {}
|
|
200
|
+
/** the menu's read-only cards: where `.comfy-ts/` lives, and the folder serve scanned */
|
|
201
|
+
workspace: PathLabel | null = null
|
|
202
|
+
root: PathLabel | null = null
|
|
203
|
+
/** the phone drawer (the menu column at 760px and below) */
|
|
204
|
+
menuOpen = false
|
|
168
205
|
form: FormSt | null = null
|
|
169
206
|
formLoading = false
|
|
170
207
|
formError: string | null = null
|
|
@@ -175,8 +212,10 @@ export class WebSt {
|
|
|
175
212
|
loraFill: boolean
|
|
176
213
|
/** trigger words under each lora card: off by default, the words are reference, not a control */
|
|
177
214
|
showLoraTriggers: boolean
|
|
178
|
-
/** how big
|
|
179
|
-
|
|
215
|
+
/** how big lora images are drawn in the form's rows, 1 = the base card size */
|
|
216
|
+
loraFormScale: number
|
|
217
|
+
/** how big lora images are drawn in the lora popup, 1 = the base card size */
|
|
218
|
+
loraPopupScale: number
|
|
180
219
|
loraSort: LoraSort
|
|
181
220
|
/** how many lora cards the popup draws. A cap exists because each card is an image
|
|
182
221
|
* request; how many is a MACHINE question (your box, your collection), so it is yours */
|
|
@@ -261,7 +300,9 @@ export class WebSt {
|
|
|
261
300
|
this.showLoraTitles = stored.loraTitles ?? true
|
|
262
301
|
this.loraFill = stored.loraFill ?? true
|
|
263
302
|
this.showLoraTriggers = stored.loraTriggers ?? false
|
|
264
|
-
|
|
303
|
+
const loraScales = readLoraScales(stored)
|
|
304
|
+
this.loraFormScale = loraScales.form
|
|
305
|
+
this.loraPopupScale = loraScales.popup
|
|
265
306
|
this.loraSort = asLoraSort(stored.loraSort)
|
|
266
307
|
// marked in the blob, so the bump happens once and a deliberate 60 sticks after it
|
|
267
308
|
this.loraCap = clampLoraCap(
|
|
@@ -269,8 +310,7 @@ export class WebSt {
|
|
|
269
310
|
)
|
|
270
311
|
this.latentMode = asLatentMode(stored.latent)
|
|
271
312
|
this.blurResults = stored.blur ?? false
|
|
272
|
-
this.
|
|
273
|
-
this.resultsSize = clampResultsSize(stored.resultsSize)
|
|
313
|
+
this.resultsColumns = readResultsColumns(stored)
|
|
274
314
|
this.expandedPreviews = Array.isArray(stored.expandedPreviews)
|
|
275
315
|
? stored.expandedPreviews.filter((x): x is string => typeof x === 'string')
|
|
276
316
|
: []
|
|
@@ -314,8 +354,13 @@ export class WebSt {
|
|
|
314
354
|
this.persist()
|
|
315
355
|
}
|
|
316
356
|
|
|
317
|
-
|
|
318
|
-
this.
|
|
357
|
+
setLoraFormScale(v: number): void {
|
|
358
|
+
this.loraFormScale = clampLoraScale(v)
|
|
359
|
+
this.persist()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
setLoraPopupScale(v: number): void {
|
|
363
|
+
this.loraPopupScale = clampLoraScale(v)
|
|
319
364
|
this.persist()
|
|
320
365
|
}
|
|
321
366
|
|
|
@@ -403,15 +448,15 @@ export class WebSt {
|
|
|
403
448
|
loraTitles: this.showLoraTitles,
|
|
404
449
|
loraFill: this.loraFill,
|
|
405
450
|
loraTriggers: this.showLoraTriggers,
|
|
406
|
-
|
|
451
|
+
loraFormScale: this.loraFormScale,
|
|
452
|
+
loraPopupScale: this.loraPopupScale,
|
|
407
453
|
loraSort: this.loraSort,
|
|
408
454
|
loraCap: this.loraCap,
|
|
409
455
|
loraCapMigrated: true,
|
|
410
456
|
layout: this.layout,
|
|
411
457
|
latent: this.latentMode,
|
|
412
458
|
blur: this.blurResults,
|
|
413
|
-
|
|
414
|
-
resultsSize: this.resultsSize,
|
|
459
|
+
resultsColumns: this.resultsColumns,
|
|
415
460
|
expandedPreviews: this.expandedPreviews,
|
|
416
461
|
logs: this.showLogs,
|
|
417
462
|
varOrder: this.varOrder,
|
|
@@ -424,6 +469,42 @@ export class WebSt {
|
|
|
424
469
|
}
|
|
425
470
|
}
|
|
426
471
|
|
|
472
|
+
/** the open drafts, left to right. The serve process keeps them (GET/PUT /tabs), never
|
|
473
|
+
* this browser: every window shows the same tabs */
|
|
474
|
+
tabs: readonly DraftTab[] = []
|
|
475
|
+
|
|
476
|
+
private async loadTabs(): Promise<void> {
|
|
477
|
+
try {
|
|
478
|
+
const reply = await fetchTabs()
|
|
479
|
+
const tabs = readTabs(
|
|
480
|
+
reply.tabs,
|
|
481
|
+
this.modules.map((m) => ({ module: m.module, drafts: m.drafts })),
|
|
482
|
+
)
|
|
483
|
+
runInAction(() => {
|
|
484
|
+
this.tabs = tabs
|
|
485
|
+
})
|
|
486
|
+
} catch (e) {
|
|
487
|
+
logWebError('the open tabs could not be read, starting with none', e)
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private setTabs(next: readonly DraftTab[]): void {
|
|
492
|
+
if (next === this.tabs) return
|
|
493
|
+
this.tabs = next
|
|
494
|
+
saveTabs(next).catch((e: unknown) => logWebError('the open tabs could not be saved', e))
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
get activeTab(): DraftTab | null {
|
|
498
|
+
return this.form == null ? null : { module: this.form.moduleKey, draft: this.form.draft }
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** × on a tab: closing the open one moves to its neighbour, the last tab stays */
|
|
502
|
+
closeTab(t: DraftTab): void {
|
|
503
|
+
const r = closeTab(this.tabs, t, this.activeTab)
|
|
504
|
+
this.setTabs(r.tabs)
|
|
505
|
+
if (r.next != null) void this.select(r.next)
|
|
506
|
+
}
|
|
507
|
+
|
|
427
508
|
moduleByKey(key: string): ModuleDescription | null {
|
|
428
509
|
return this.modules.find((m) => m.module === key) ?? null
|
|
429
510
|
}
|
|
@@ -434,6 +515,8 @@ export class WebSt {
|
|
|
434
515
|
runInAction(() => {
|
|
435
516
|
this.modules = index.workflows
|
|
436
517
|
this.loadErrors = index.loadErrors ?? {}
|
|
518
|
+
this.workspace = index.workspace ?? null
|
|
519
|
+
this.root = index.root ?? null
|
|
437
520
|
this.phase = 'ready'
|
|
438
521
|
})
|
|
439
522
|
void this.loadSettings()
|
|
@@ -452,6 +535,8 @@ export class WebSt {
|
|
|
452
535
|
this.postHost({ comfyTs: 'error', code: 'boot', message: 'no workflows are served' })
|
|
453
536
|
return
|
|
454
537
|
}
|
|
538
|
+
// before the first select, which adds its own tab to the list it read
|
|
539
|
+
await this.loadTabs()
|
|
455
540
|
await this.select(opening)
|
|
456
541
|
if (this.form == null) {
|
|
457
542
|
this.postHost({
|
|
@@ -482,6 +567,9 @@ export class WebSt {
|
|
|
482
567
|
|
|
483
568
|
/** `mirror: false` when a host request will answer with its own `state` right after */
|
|
484
569
|
select(p: { module: string; draft: string }, o: { mirror?: boolean } = {}): Promise<void> {
|
|
570
|
+
// the phone drawer is a way to a draft: arriving there closes it
|
|
571
|
+
this.menuOpen = false
|
|
572
|
+
this.renamingDraft = null
|
|
485
573
|
return this.trackSwitch(this.selectNow(p, o.mirror ?? true))
|
|
486
574
|
}
|
|
487
575
|
|
|
@@ -537,6 +625,7 @@ export class WebSt {
|
|
|
537
625
|
form.onSettled = (): void => this.mirrorState()
|
|
538
626
|
runInAction(() => {
|
|
539
627
|
this.form = form
|
|
628
|
+
this.setTabs(openTab(this.tabs, p))
|
|
540
629
|
this.persist()
|
|
541
630
|
this.syncUrl()
|
|
542
631
|
})
|
|
@@ -819,10 +908,8 @@ export class WebSt {
|
|
|
819
908
|
requestJump(kind: 'prompt' | 'loras'): void {
|
|
820
909
|
this.jump = { kind, seq: (this.jump?.seq ?? 0) + 1 }
|
|
821
910
|
}
|
|
822
|
-
/**
|
|
823
|
-
|
|
824
|
-
resultsView: 'fit' | 'grid' = 'fit'
|
|
825
|
-
resultsSize = DEFAULT_RESULTS_SIZE
|
|
911
|
+
/** results side by side in the preview, each column an equal share of its width */
|
|
912
|
+
resultsColumns = 1
|
|
826
913
|
/** live previews opened to their full text, as `module/name`; the rest show one line each */
|
|
827
914
|
expandedPreviews: string[] = []
|
|
828
915
|
private logsTimer: ReturnType<typeof setInterval> | null = null
|
|
@@ -839,13 +926,8 @@ export class WebSt {
|
|
|
839
926
|
this.persist()
|
|
840
927
|
}
|
|
841
928
|
|
|
842
|
-
|
|
843
|
-
this.
|
|
844
|
-
this.persist()
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
setResultsSize(px: number): void {
|
|
848
|
-
this.resultsSize = clampResultsSize(px)
|
|
929
|
+
setResultsColumns(n: number): void {
|
|
930
|
+
this.resultsColumns = clampResultsColumns(n)
|
|
849
931
|
this.persist()
|
|
850
932
|
}
|
|
851
933
|
|
|
@@ -854,6 +936,37 @@ export class WebSt {
|
|
|
854
936
|
this.persist()
|
|
855
937
|
}
|
|
856
938
|
|
|
939
|
+
setMenuOpen(open: boolean): void {
|
|
940
|
+
this.menuOpen = open
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/** the name being typed for the open draft, null when no rename is in progress. Here, not in
|
|
944
|
+
* the menu, because F2 starts it from any focus */
|
|
945
|
+
renamingDraft: string | null = null
|
|
946
|
+
|
|
947
|
+
/** F2 and the rename row. The phone drawer opens so the input is on screen; a folded desktop
|
|
948
|
+
* menu unfolds (App reacts to renamingDraft) */
|
|
949
|
+
startRename(): void {
|
|
950
|
+
if (this.form == null) return
|
|
951
|
+
this.renamingDraft = this.form.draft
|
|
952
|
+
this.menuOpen = true
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
setRenaming(v: string): void {
|
|
956
|
+
this.renamingDraft = v
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
stopRename(): void {
|
|
960
|
+
this.renamingDraft = null
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/** bumped by ⌘B and the ☰: the desktop menu Panel folds or unfolds on each bump */
|
|
964
|
+
menuFoldTick = 0
|
|
965
|
+
|
|
966
|
+
requestMenuFold(): void {
|
|
967
|
+
this.menuFoldTick++
|
|
968
|
+
}
|
|
969
|
+
|
|
857
970
|
toggleLogs(): void {
|
|
858
971
|
this.showLogs = !this.showLogs
|
|
859
972
|
this.persist()
|
|
@@ -1174,6 +1287,13 @@ export class WebSt {
|
|
|
1174
1287
|
this.modules = this.modules.map((m) =>
|
|
1175
1288
|
m.module === form.moduleKey ? { ...m, drafts: reply.drafts } : m,
|
|
1176
1289
|
)
|
|
1290
|
+
this.setTabs(
|
|
1291
|
+
renameTab(
|
|
1292
|
+
this.tabs,
|
|
1293
|
+
{ module: form.moduleKey, draft: from },
|
|
1294
|
+
{ module: form.moduleKey, draft: name },
|
|
1295
|
+
),
|
|
1296
|
+
)
|
|
1177
1297
|
}),
|
|
1178
1298
|
(e: unknown) =>
|
|
1179
1299
|
runInAction(() => {
|
|
@@ -1192,6 +1312,7 @@ export class WebSt {
|
|
|
1192
1312
|
}
|
|
1193
1313
|
|
|
1194
1314
|
private async deleteDraftNow(p: { module: string; draft: string }): Promise<void> {
|
|
1315
|
+
const neighbour = closeTab(this.tabs, p, this.activeTab).next
|
|
1195
1316
|
const form = this.form
|
|
1196
1317
|
if (form != null && form.moduleKey === p.module && form.draft === p.draft) {
|
|
1197
1318
|
form.dispose({ flush: false })
|
|
@@ -1203,9 +1324,12 @@ export class WebSt {
|
|
|
1203
1324
|
const reply = await deleteDraft(p)
|
|
1204
1325
|
runInAction(() => {
|
|
1205
1326
|
this.modules = this.modules.map((m) => (m.module === p.module ? { ...m, drafts: reply.drafts } : m))
|
|
1327
|
+
this.setTabs(this.tabs.filter((t) => t.module !== p.module || t.draft !== p.draft))
|
|
1206
1328
|
})
|
|
1329
|
+
// only when the open draft was the one deleted: its neighbour tab first, else the rule
|
|
1330
|
+
if (this.form != null) return
|
|
1207
1331
|
const fallback = reply.drafts.includes('default') ? 'default' : (reply.drafts[0] ?? 'default')
|
|
1208
|
-
await this.select({ module: p.module, draft: fallback })
|
|
1332
|
+
await this.select(neighbour ?? { module: p.module, draft: fallback })
|
|
1209
1333
|
} catch (e) {
|
|
1210
1334
|
runInAction(() => {
|
|
1211
1335
|
this.formError = e instanceof Error ? e.message : String(e)
|
|
@@ -1220,6 +1344,21 @@ export class WebSt {
|
|
|
1220
1344
|
await this.createDraft(rawName, form.valuesJSON())
|
|
1221
1345
|
}
|
|
1222
1346
|
|
|
1347
|
+
/** ⌘D and the duplicate row: a copy of what is on screen, auto-named, opened */
|
|
1348
|
+
duplicateCurrentDraft(): Promise<void> {
|
|
1349
|
+
const form = this.form
|
|
1350
|
+
if (form == null) return Promise.resolve()
|
|
1351
|
+
const drafts = this.moduleByKey(form.moduleKey)?.drafts ?? [form.draft]
|
|
1352
|
+
return this.duplicateDraft(duplicateDraftName(form.draft, drafts))
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/** the new draft row: the workflow's own values, auto-named, opened */
|
|
1356
|
+
newDraftFromDefaults(): Promise<void> {
|
|
1357
|
+
const form = this.form
|
|
1358
|
+
if (form == null) return Promise.resolve()
|
|
1359
|
+
return this.newDraft(freeDraftName(this.moduleByKey(form.moduleKey)?.drafts ?? []))
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1223
1362
|
/** a new draft from the workflow's OWN values (the ones in its code), not the open draft's */
|
|
1224
1363
|
async newDraft(rawName: string): Promise<void> {
|
|
1225
1364
|
const form = this.form
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// the names new and duplicate give a draft without asking: rename is one click away, a prompt on
|
|
2
|
+
// every copy is not. PURE, tests/serve-web-draft-names.test.ts
|
|
3
|
+
import { copyName } from 'src/utils/copyName.ts'
|
|
4
|
+
|
|
5
|
+
/** `new`, `new 2`, … the first name no draft of this workflow has */
|
|
6
|
+
export function freeDraftName(drafts: readonly string[]): string {
|
|
7
|
+
if (!drafts.includes('new')) return 'new'
|
|
8
|
+
let n = 2
|
|
9
|
+
while (drafts.includes(`new ${n}`)) n++
|
|
10
|
+
return `new ${n}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** `shot 007` → `shot 008`, `default` → `default-2`, never a name already taken */
|
|
14
|
+
export function duplicateDraftName(from: string, drafts: readonly string[]): string {
|
|
15
|
+
return copyName(from, drafts)
|
|
16
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// the open drafts as tabs: pure list operations and key reads, the store (WebSt) owns when they run
|
|
2
|
+
export type DraftTab = { module: string; draft: string }
|
|
3
|
+
|
|
4
|
+
/** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
|
|
5
|
+
* must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
|
|
6
|
+
export const SERVE_TABS_FILE = 'serve-tabs.json'
|
|
7
|
+
|
|
8
|
+
const same = (a: DraftTab, b: DraftTab): boolean => a.module === b.module && a.draft === b.draft
|
|
9
|
+
|
|
10
|
+
/** a draft you open gets a tab at the end; one already open keeps its place */
|
|
11
|
+
export function openTab(tabs: readonly DraftTab[], t: DraftTab): readonly DraftTab[] {
|
|
12
|
+
return tabs.some((x) => same(x, t)) ? tabs : [...tabs, { module: t.module, draft: t.draft }]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** `next` is where to go: the right neighbour of the closed OPEN tab, else its left one, null
|
|
16
|
+
* when the open tab stays. The last tab stays: a draft is always open */
|
|
17
|
+
export function closeTab(
|
|
18
|
+
tabs: readonly DraftTab[],
|
|
19
|
+
t: DraftTab,
|
|
20
|
+
active: DraftTab | null,
|
|
21
|
+
): { tabs: readonly DraftTab[]; next: DraftTab | null } {
|
|
22
|
+
const ix = tabs.findIndex((x) => same(x, t))
|
|
23
|
+
if (ix < 0 || tabs.length <= 1) return { tabs, next: null }
|
|
24
|
+
const rest = tabs.filter((_, i) => i !== ix)
|
|
25
|
+
if (active == null || !same(active, t)) return { tabs: rest, next: null }
|
|
26
|
+
return { tabs: rest, next: rest[Math.min(ix, rest.length - 1)] ?? null }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** the renamed draft keeps the tab's place, even when the switch already opened it at the end */
|
|
30
|
+
export function renameTab(tabs: readonly DraftTab[], from: DraftTab, to: DraftTab): readonly DraftTab[] {
|
|
31
|
+
const ix = tabs.findIndex((x) => same(x, from))
|
|
32
|
+
const rest = tabs.filter((x) => !same(x, to))
|
|
33
|
+
if (ix < 0) return openTab(rest, to)
|
|
34
|
+
return rest.map((x) => (same(x, from) ? { module: to.module, draft: to.draft } : x))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** ⌘1 to ⌘8 (ctrl elsewhere) the nth tab, ⌘9 the last one, as browsers do */
|
|
38
|
+
export function tabForKey(
|
|
39
|
+
tabs: readonly DraftTab[],
|
|
40
|
+
e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
|
|
41
|
+
): DraftTab | null {
|
|
42
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
43
|
+
if (!/^[1-9]$/.test(e.key)) return null
|
|
44
|
+
const n = Number(e.key)
|
|
45
|
+
return (n === 9 ? tabs[tabs.length - 1] : tabs[n - 1]) ?? null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** ⌘PageUp / ⌘PageDown (ctrl elsewhere): the previous or next tab, wrapping at the ends */
|
|
49
|
+
export function tabStepForKey(
|
|
50
|
+
tabs: readonly DraftTab[],
|
|
51
|
+
active: DraftTab | null,
|
|
52
|
+
e: { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean },
|
|
53
|
+
): DraftTab | null {
|
|
54
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
55
|
+
const dir = e.key === 'PageDown' ? 1 : e.key === 'PageUp' ? -1 : 0
|
|
56
|
+
if (dir === 0 || tabs.length < 2) return null
|
|
57
|
+
const ix = active == null ? -1 : tabs.findIndex((x) => same(x, active))
|
|
58
|
+
if (ix < 0) return (dir > 0 ? tabs[0] : tabs[tabs.length - 1]) ?? null
|
|
59
|
+
return tabs[(ix + dir + tabs.length) % tabs.length] ?? null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** a stored list, shape-checked, keeping only drafts that still exist */
|
|
63
|
+
export function readTabs(raw: unknown, modules: readonly { module: string; drafts: readonly string[] }[]): DraftTab[] {
|
|
64
|
+
if (!Array.isArray(raw)) return []
|
|
65
|
+
const out: DraftTab[] = []
|
|
66
|
+
for (const x of raw as unknown[]) {
|
|
67
|
+
if (x == null || typeof x !== 'object') continue
|
|
68
|
+
const o = x as { module?: unknown; draft?: unknown }
|
|
69
|
+
if (typeof o.module !== 'string' || typeof o.draft !== 'string') continue
|
|
70
|
+
const t = { module: o.module, draft: o.draft }
|
|
71
|
+
if (!modules.some((m) => m.module === t.module && m.drafts.includes(t.draft))) continue
|
|
72
|
+
if (!out.some((y) => same(y, t))) out.push(t)
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
@@ -9,7 +9,7 @@ export function generateButtonLook(p: { isRunning: boolean; percent: number | nu
|
|
|
9
9
|
running: boolean
|
|
10
10
|
} {
|
|
11
11
|
return {
|
|
12
|
-
label: '
|
|
12
|
+
label: 'Run',
|
|
13
13
|
fill: p.isRunning ? Math.max(0, Math.min(100, Math.round(p.percent ?? 0))) : null,
|
|
14
14
|
running: p.isRunning,
|
|
15
15
|
}
|