comfy-ts 2.10.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-DFxzQfDc.js → LogsSt-U1H0mP1m.js} +35 -5
- package/dist/LogsSt-U1H0mP1m.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +565 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -31
- package/dist/index.d.ts +210 -31
- package/dist/index.js +561 -63
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-_nrvJYyt.js → run-serve-BeAznay5.js} +549 -43
- package/dist/run-serve-BeAznay5.js.map +1 -0
- package/dist/{run-tui-Atvf9vb3.js → run-tui-BTGjvnKk.js} +75 -18
- package/dist/run-tui-BTGjvnKk.js.map +1 -0
- package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-Cg39vs53.js} +644 -60
- package/dist/schemaDrift-Cg39vs53.js.map +1 -0
- package/dist/serve-web.js +523 -133
- package/dist/{state-6RFDIQwJ.js → state-C7REnHan.js} +18 -3
- package/dist/{state-6RFDIQwJ.js.map → state-C7REnHan.js.map} +1 -1
- package/dist/web.d.ts +210 -31
- package/dist/web.js +561 -63
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -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 +17 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +242 -12
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/describeVar.ts +49 -6
- package/src/cli/serve/favicon.ts +3 -0
- 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 +60 -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 -177
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +708 -285
- 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 +281 -57
- 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 +57 -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 +472 -118
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/tui/components/Header.tsx +2 -0
- 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/HostSt.ts +34 -0
- 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/ComfyHost.ts +15 -0
- package/src/host/loraInfoCache.ts +70 -0
- package/src/host/loraManagerApi.ts +27 -0
- package/src/host/schemaDrift.ts +87 -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/DefinedWorkflow-BatWaZO1.js.map +0 -1
- package/dist/LogsSt-DFxzQfDc.js.map +0 -1
- package/dist/run-serve-_nrvJYyt.js.map +0 -1
- package/dist/run-tui-Atvf9vb3.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
// reaction is owned here). DRAFTS ARE LIVE (the TUI model): edits autosave
|
|
4
4
|
// through PUT /drafts, generate posts {} — the draft is the one source of truth
|
|
5
5
|
import { makeAutoObservable, observableRef, reaction, runInAction, type IReactionDisposer } from 'mobx'
|
|
6
|
-
import { saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
|
|
6
|
+
import { fetchPreviews, saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
|
|
7
7
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
8
8
|
import { normalizeInitial, payloadSnapshot } from 'src/cli/serve/web/state/payload.ts'
|
|
9
|
+
import {
|
|
10
|
+
flattenLoras,
|
|
11
|
+
isLorasInput,
|
|
12
|
+
loraSetting,
|
|
13
|
+
paletteLoras,
|
|
14
|
+
updateLora,
|
|
15
|
+
type LoraRecord,
|
|
16
|
+
type LorasInput,
|
|
17
|
+
} from 'src/vars/lanes.ts'
|
|
18
|
+
import { keywordParts, loraMuted, withLora } from 'src/vars/loraEntry.ts'
|
|
19
|
+
import { ENHANCE_KEY, readIntents } from 'src/cli/draftMeta.ts'
|
|
9
20
|
|
|
10
21
|
/** one var row: value in toJSON shape, replaced whole on every edit */
|
|
11
22
|
export class VarSt {
|
|
@@ -52,6 +63,10 @@ export class VarSt {
|
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
|
|
66
|
+
/** the debounces a form runs on: tests set them to a few ms rather than wait them out */
|
|
67
|
+
export type FormTiming = { autosaveMs: number; previewMs: number }
|
|
68
|
+
export const FORM_TIMING: FormTiming = { autosaveMs: 500, previewMs: 250 }
|
|
69
|
+
|
|
55
70
|
export class FormSt {
|
|
56
71
|
vars: VarSt[]
|
|
57
72
|
/** the module's host id — lora hover data routes are host-scoped */
|
|
@@ -72,34 +87,46 @@ export class FormSt {
|
|
|
72
87
|
/** called on the autosave debounce, right after the save is queued: the embedding host
|
|
73
88
|
* mirrors the form from it (WebSt), one call per settled burst of edits, never per key */
|
|
74
89
|
onSettled: (() => void) | null = null
|
|
90
|
+
/** the workflow's live previews for the values on screen, name → text */
|
|
91
|
+
previews: Record<string, string> = {}
|
|
92
|
+
previewError: string | null = null
|
|
93
|
+
private previewAbort: AbortController | null = null
|
|
75
94
|
|
|
76
95
|
constructor(
|
|
77
96
|
public readonly moduleKey: string,
|
|
78
97
|
public readonly draft: string,
|
|
79
98
|
mod: ModuleDescription,
|
|
80
99
|
values: Record<string, unknown>,
|
|
100
|
+
timing: FormTiming = FORM_TIMING,
|
|
81
101
|
) {
|
|
82
102
|
this.host = mod.host
|
|
83
103
|
this.vars = Object.entries(mod.vars).map(
|
|
84
104
|
([name, desc]) => new VarSt(name, desc, normalizeInitial(desc, values[name])),
|
|
85
105
|
)
|
|
106
|
+
this.intents = readIntents(values[ENHANCE_KEY])
|
|
86
107
|
// seeded from the RAW reply, not the normalized values: when normalizeInitial heals
|
|
87
108
|
// something (a stale lora key), the form is already out of sync with the file and the
|
|
88
109
|
// next save() must actually send, otherwise the server keeps building the stale record
|
|
89
|
-
this.lastSaved = JSON.stringify(
|
|
110
|
+
this.lastSaved = JSON.stringify(
|
|
111
|
+
withIntents(Object.fromEntries(this.vars.map((v) => [v.name, values[v.name]])), this.intents),
|
|
112
|
+
)
|
|
90
113
|
this.lastQueued = this.lastSaved
|
|
91
|
-
makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved' | 'lastQueued' | 'queueSeq'>(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
makeAutoObservable<FormSt, 'disposers' | 'saveChain' | 'lastSaved' | 'lastQueued' | 'queueSeq' | 'previewAbort'>(
|
|
115
|
+
this,
|
|
116
|
+
{
|
|
117
|
+
vars: false,
|
|
118
|
+
moduleKey: false,
|
|
119
|
+
draft: false,
|
|
120
|
+
host: false,
|
|
121
|
+
disposers: false,
|
|
122
|
+
saveChain: false,
|
|
123
|
+
lastSaved: false,
|
|
124
|
+
lastQueued: false,
|
|
125
|
+
queueSeq: false,
|
|
126
|
+
onSettled: false,
|
|
127
|
+
previewAbort: false,
|
|
128
|
+
},
|
|
129
|
+
)
|
|
103
130
|
// the persistence idiom: the values json is change-detector AND payload
|
|
104
131
|
this.disposers.push(
|
|
105
132
|
reaction(
|
|
@@ -108,9 +135,38 @@ export class FormSt {
|
|
|
108
135
|
void this.save()
|
|
109
136
|
this.onSettled?.()
|
|
110
137
|
},
|
|
111
|
-
{ delay:
|
|
138
|
+
{ delay: timing.autosaveMs },
|
|
112
139
|
),
|
|
113
140
|
)
|
|
141
|
+
// live previews: the same values json, asked sooner than the save (they are what you
|
|
142
|
+
// watch while typing), the older request cancelled so a slow reply never lands last
|
|
143
|
+
const previewNames = mod.previews ?? []
|
|
144
|
+
if (previewNames.length > 0)
|
|
145
|
+
this.disposers.push(
|
|
146
|
+
reaction(
|
|
147
|
+
() => JSON.stringify(this.varValues()),
|
|
148
|
+
() => void this.refreshPreviews(),
|
|
149
|
+
{ delay: timing.previewMs, fireImmediately: true },
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async refreshPreviews(): Promise<void> {
|
|
155
|
+
this.previewAbort?.abort()
|
|
156
|
+
const abort = new AbortController()
|
|
157
|
+
this.previewAbort = abort
|
|
158
|
+
try {
|
|
159
|
+
const reply = await fetchPreviews({ module: this.moduleKey, values: this.varValues(), signal: abort.signal })
|
|
160
|
+
runInAction(() => {
|
|
161
|
+
this.previews = reply.previews
|
|
162
|
+
this.previewError = null
|
|
163
|
+
})
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (abort.signal.aborted) return
|
|
166
|
+
runInAction(() => {
|
|
167
|
+
this.previewError = e instanceof Error ? e.message : String(e)
|
|
168
|
+
})
|
|
169
|
+
}
|
|
114
170
|
}
|
|
115
171
|
|
|
116
172
|
/** stop the autosave. `flush: false` is the DELETE path: flushing there would write the
|
|
@@ -118,6 +174,7 @@ export class FormSt {
|
|
|
118
174
|
dispose(p: { flush?: boolean } = {}): void {
|
|
119
175
|
for (const d of this.disposers) d()
|
|
120
176
|
this.disposers = []
|
|
177
|
+
this.previewAbort?.abort()
|
|
121
178
|
if (p.flush === false) return
|
|
122
179
|
// a draft switch inside the debounce window must not lose the edit. Compared against
|
|
123
180
|
// lastQueued, like save() itself: lastSaved lags behind an in-flight write, so a revert
|
|
@@ -153,7 +210,30 @@ export class FormSt {
|
|
|
153
210
|
)
|
|
154
211
|
}
|
|
155
212
|
|
|
213
|
+
/** the draft file's `$enhance`: the enhancer's input per prompt (src/cli/draftMeta.ts) */
|
|
214
|
+
intents: Record<string, string> = {}
|
|
215
|
+
|
|
216
|
+
intentFor(key: string): string | undefined {
|
|
217
|
+
return this.intents[key]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** '' clears it: the input then follows the prompt again */
|
|
221
|
+
setIntent(key: string, text: string): void {
|
|
222
|
+
const next = { ...this.intents }
|
|
223
|
+
if (text === '') delete next[key]
|
|
224
|
+
else next[key] = text
|
|
225
|
+
this.intents = next
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** what the draft FILE holds: the values, and the intents beside them. Saved together, so an
|
|
229
|
+
* intent is autosaved like any edit */
|
|
156
230
|
valuesJSON(): Record<string, unknown> {
|
|
231
|
+
return withIntents(this.varValues(), this.intents)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** the var values alone: what previews compute from and what an embedding page is told.
|
|
235
|
+
* An intent typed in the enhancer changes neither */
|
|
236
|
+
varValues(): Record<string, unknown> {
|
|
157
237
|
return Object.fromEntries(this.vars.map((v) => [v.name, v.value]))
|
|
158
238
|
}
|
|
159
239
|
|
|
@@ -167,27 +247,107 @@ export class FormSt {
|
|
|
167
247
|
* record's insertion order: walking the record showed the keywords in drag order while the
|
|
168
248
|
* prompt that ran used the enum order, so the preview and the run disagreed the moment you
|
|
169
249
|
* reordered a card. Computed here rather than fetched: it must follow every toggle live */
|
|
170
|
-
|
|
250
|
+
/** a var whose `activeWhen` does not hold right now: shown, but disabled. The reason is a
|
|
251
|
+
* sentence the label shows, null when the var is active */
|
|
252
|
+
inactiveReason(v: VarSt): string | null {
|
|
253
|
+
const when = v.desc.ui?.activeWhen
|
|
254
|
+
if (when == null) return null
|
|
255
|
+
for (const [name, allowed] of Object.entries(when)) {
|
|
256
|
+
const other = this.vars.find((x) => x.name === name)
|
|
257
|
+
const current = other?.value
|
|
258
|
+
if (!allowed.some((a) => a === current)) return `only used when ${name} is ${allowed.join(' or ')}`
|
|
259
|
+
}
|
|
260
|
+
return null
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** the loras var a prompt takes its keywords from, and the record the build reads from it
|
|
264
|
+
* (the plain record, or its active lanes merged) */
|
|
265
|
+
private keywordSource(promptVar: VarSt): { source: VarSt; value: LorasInput; record: LoraRecord } | null {
|
|
171
266
|
const sourceName = promptVar.desc.keywordsFrom
|
|
172
|
-
if (sourceName == null) return
|
|
267
|
+
if (sourceName == null) return null
|
|
173
268
|
const source = this.vars.find((v) => v.name === sourceName)
|
|
174
|
-
if (source == null) return
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
269
|
+
if (source == null) return null
|
|
270
|
+
const value = isLorasInput(source.value) ? source.value : {}
|
|
271
|
+
return { source, value, record: flattenLoras(value).record }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** one group per lora in the palette that has a keyword: its name, then the keyword split at
|
|
275
|
+
* the commas, each part on or off. A lora the build does not run (paused, or in a lane that
|
|
276
|
+
* is off) keeps its group, marked not running, so switching a lane never shifts the form */
|
|
277
|
+
loraKeywordGroups(
|
|
278
|
+
promptVar: VarSt,
|
|
279
|
+
): { lora: string; label: string; running: boolean; parts: { text: string; on: boolean }[] }[] {
|
|
280
|
+
const found = this.keywordSource(promptVar)
|
|
281
|
+
if (found == null) return []
|
|
282
|
+
const keywords = found.source.desc.optionKeywords ?? {}
|
|
283
|
+
const labels = found.source.desc.optionLabels ?? {}
|
|
284
|
+
const inPalette = new Map(paletteLoras(found.value).map((l) => [l.name, l]))
|
|
285
|
+
const out: { lora: string; label: string; running: boolean; parts: { text: string; on: boolean }[] }[] = []
|
|
286
|
+
for (const name of found.source.desc.options ?? []) {
|
|
287
|
+
const entry = inPalette.get(name)
|
|
288
|
+
if (entry == null) continue
|
|
289
|
+
const parts = keywordParts(keywords[name] ?? '')
|
|
290
|
+
if (parts.length === 0) continue
|
|
291
|
+
const muted = loraMuted(entry.setting)
|
|
292
|
+
out.push({
|
|
293
|
+
lora: name,
|
|
294
|
+
label: labels[name] ?? name,
|
|
295
|
+
running: entry.running,
|
|
296
|
+
parts: parts.map((text) => ({ text, on: !muted.includes(text) })),
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
return out
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** what the active loras will prepend, as sent: muted parts left out, deduped */
|
|
303
|
+
loraKeywordsFor(promptVar: VarSt): string[] {
|
|
180
304
|
const out: string[] = []
|
|
181
|
-
for (const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
305
|
+
for (const g of this.loraKeywordGroups(promptVar)) {
|
|
306
|
+
if (!g.running) continue
|
|
307
|
+
const kept = g.parts
|
|
308
|
+
.filter((w) => w.on)
|
|
309
|
+
.map((w) => w.text)
|
|
310
|
+
.join(', ')
|
|
311
|
+
if (kept !== '' && !out.includes(kept)) out.push(kept)
|
|
187
312
|
}
|
|
188
313
|
return out
|
|
189
314
|
}
|
|
190
315
|
|
|
316
|
+
/** every keyword part the build will add in front, with the lora it comes from (the editor
|
|
317
|
+
* flags a tag you typed that a lora already adds) */
|
|
318
|
+
injectedTagsFor(promptVar: VarSt): { tag: string; source: string }[] {
|
|
319
|
+
return this.loraKeywordGroups(promptVar)
|
|
320
|
+
.filter((g) => g.running)
|
|
321
|
+
.flatMap((g) => g.parts.filter((w) => w.on).map((w) => ({ tag: w.text, source: g.label })))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** the keyword parts of EVERY lora in the list, running or not: the editor completes them */
|
|
325
|
+
loraWordsFor(promptVar: VarSt): { word: string; source: string }[] {
|
|
326
|
+
const sourceName = promptVar.desc.keywordsFrom
|
|
327
|
+
const source = sourceName == null ? null : this.vars.find((v) => v.name === sourceName)
|
|
328
|
+
if (source == null) return []
|
|
329
|
+
const keywords = source.desc.optionKeywords ?? {}
|
|
330
|
+
const labels = source.desc.optionLabels ?? {}
|
|
331
|
+
return Object.entries(keywords).flatMap(([name, kw]) =>
|
|
332
|
+
keywordParts(kw).map((word) => ({ word, source: labels[name] ?? name })),
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** mute or unmute one part of a lora's keyword, stored on that lora in the draft */
|
|
337
|
+
toggleKeywordPart(promptVar: VarSt, lora: string, part: string): void {
|
|
338
|
+
const found = this.keywordSource(promptVar)
|
|
339
|
+
if (found == null) return
|
|
340
|
+
const muted = loraMuted(loraSetting(found.value, lora))
|
|
341
|
+
this.setKeywordMute(promptVar, lora, muted.includes(part) ? muted.filter((w) => w !== part) : [...muted, part])
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** the whole list of muted parts at once (the popover's all / none) */
|
|
345
|
+
setKeywordMute(promptVar: VarSt, lora: string, mute: readonly string[]): void {
|
|
346
|
+
const found = this.keywordSource(promptVar)
|
|
347
|
+
if (found == null) return
|
|
348
|
+
found.source.set(updateLora(found.value, lora, withLora(loraSetting(found.value, lora), { mute })))
|
|
349
|
+
}
|
|
350
|
+
|
|
191
351
|
get dirtyCount(): number {
|
|
192
352
|
return this.vars.filter((v) => v.dirty).length
|
|
193
353
|
}
|
|
@@ -234,3 +394,7 @@ export class FormSt {
|
|
|
234
394
|
for (const v of this.vars) v.revert()
|
|
235
395
|
}
|
|
236
396
|
}
|
|
397
|
+
|
|
398
|
+
function withIntents(values: Record<string, unknown>, intents: Record<string, string>): Record<string, unknown> {
|
|
399
|
+
return Object.keys(intents).length === 0 ? values : { ...values, [ENHANCE_KEY]: intents }
|
|
400
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// the ⌘K / ⌘J search over every workflow and draft. The list and the match are pure
|
|
2
|
+
// (omnibox.ts); this holds what is typed, which row is lit, and opens the pick
|
|
3
|
+
import { makeAutoObservable } from 'mobx'
|
|
4
|
+
import { omniboxEntries, searchOmnibox, type OmniboxEntry } from 'src/cli/serve/web/state/omnibox.ts'
|
|
5
|
+
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
6
|
+
|
|
7
|
+
export class OmniboxSt {
|
|
8
|
+
isOpen = false
|
|
9
|
+
query = ''
|
|
10
|
+
cursor = 0
|
|
11
|
+
|
|
12
|
+
constructor(private st: WebSt) {
|
|
13
|
+
makeAutoObservable<OmniboxSt, 'st'>(this, { st: false })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get results(): OmniboxEntry[] {
|
|
17
|
+
return searchOmnibox(omniboxEntries(this.st.modules), this.query)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
open(): void {
|
|
21
|
+
this.isOpen = true
|
|
22
|
+
this.query = ''
|
|
23
|
+
// the open draft is lit, so Enter right away is a no-op rather than a jump elsewhere
|
|
24
|
+
const current = this.st.form
|
|
25
|
+
const ix =
|
|
26
|
+
current == null
|
|
27
|
+
? -1
|
|
28
|
+
: this.results.findIndex((e) => e.module === current.moduleKey && e.draft === current.draft)
|
|
29
|
+
this.cursor = Math.max(0, ix)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
close(): void {
|
|
33
|
+
this.isOpen = false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toggle(): void {
|
|
37
|
+
if (this.isOpen) this.close()
|
|
38
|
+
else this.open()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setQuery(v: string): void {
|
|
42
|
+
this.query = v
|
|
43
|
+
this.cursor = 0
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
move(delta: number): void {
|
|
47
|
+
const n = this.results.length
|
|
48
|
+
if (n === 0) return
|
|
49
|
+
this.cursor = (this.cursor + delta + n) % n
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pick(entry: OmniboxEntry | undefined = this.results[this.cursor]): void {
|
|
53
|
+
if (entry == null) return
|
|
54
|
+
this.close()
|
|
55
|
+
void this.st.select({ module: entry.module, draft: entry.draft })
|
|
56
|
+
}
|
|
57
|
+
}
|