comfy-ts 2.7.0 → 2.8.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 (101) hide show
  1. package/README.md +20 -13
  2. package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
  3. package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
  4. package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
  5. package/dist/LogsSt-DFxzQfDc.js.map +1 -0
  6. package/dist/cli.js +7 -5
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +284 -35
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +125 -7
  11. package/dist/index.d.ts +125 -7
  12. package/dist/index.js +282 -37
  13. package/dist/index.js.map +1 -1
  14. package/dist/run-serve-_nrvJYyt.js +1948 -0
  15. package/dist/run-serve-_nrvJYyt.js.map +1 -0
  16. package/dist/{run-tui-JxlEbb_f.js → run-tui-BPw-SZYW.js} +106 -157
  17. package/dist/run-tui-BPw-SZYW.js.map +1 -0
  18. package/dist/serve-web.js +432 -72
  19. package/dist/{state-CaHeDL-0.js → state-B-boDz-Z.js} +180 -45
  20. package/dist/state-B-boDz-Z.js.map +1 -0
  21. package/dist/web.d.ts +109 -7
  22. package/dist/web.js +235 -36
  23. package/dist/web.js.map +1 -1
  24. package/examples/README.md +1 -0
  25. package/examples/comfy-cloud/sdk.d.ts +4066 -321
  26. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
  27. package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
  28. package/examples/web/tsconfig.json +3 -0
  29. package/extra/README.md +32 -0
  30. package/extra/comfyui-textgen-stream/README.md +35 -0
  31. package/extra/comfyui-textgen-stream/__init__.py +166 -0
  32. package/extra/scripts/fetch_text_encoder.py +137 -0
  33. package/package.json +6 -3
  34. package/src/cli/comfy-ts-cli.ts +3 -1
  35. package/src/cli/serve/ServeApp.ts +754 -40
  36. package/src/cli/serve/applyVarPayload.ts +10 -3
  37. package/src/cli/serve/describeVar.ts +47 -7
  38. package/src/cli/serve/managerOnlyLoras.ts +27 -0
  39. package/src/cli/serve/run-serve.ts +35 -38
  40. package/src/cli/serve/serveSettings.ts +86 -0
  41. package/src/cli/serve/startupPrint.ts +111 -0
  42. package/src/cli/serve/web/api.ts +97 -1
  43. package/src/cli/serve/web/components/App.tsx +61 -22
  44. package/src/cli/serve/web/components/Gallery.tsx +243 -30
  45. package/src/cli/serve/web/components/Icon.tsx +160 -0
  46. package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
  47. package/src/cli/serve/web/components/Sidebar.tsx +43 -19
  48. package/src/cli/serve/web/components/VarsForm.tsx +440 -91
  49. package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
  50. package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
  51. package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
  52. package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
  53. package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
  54. package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
  55. package/src/cli/serve/web/llm.ts +1 -1
  56. package/src/cli/serve/web/logWeb.ts +6 -0
  57. package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
  58. package/src/cli/serve/web/state/FormSt.ts +66 -17
  59. package/src/cli/serve/web/state/RunSt.ts +22 -1
  60. package/src/cli/serve/web/state/WebSt.ts +518 -14
  61. package/src/cli/serve/web/state/lightbox.ts +44 -0
  62. package/src/cli/serve/web/state/moduleTree.ts +52 -0
  63. package/src/cli/serve/web/state/payload.ts +44 -2
  64. package/src/cli/serve/web/state/urlSelection.ts +53 -0
  65. package/src/cli/serve/web/styles.ts +413 -57
  66. package/src/cli/serve/web/tsconfig.json +4 -0
  67. package/src/cli/tui/components/PickerOverlays.tsx +37 -0
  68. package/src/cli/tui/components/StatusBar.tsx +14 -1
  69. package/src/cli/tui/components/TuiApp.tsx +5 -2
  70. package/src/cli/tui/state/HostSt.ts +3 -2
  71. package/src/cli/tui/state/PickerSt.ts +48 -2
  72. package/src/cli/tui/state/TreeSt.ts +1 -1
  73. package/src/cli/tui/state/TuiSt.ts +2 -1
  74. package/src/coreExports.ts +8 -1
  75. package/src/graph/ComfyNode.ts +58 -1
  76. package/src/host/ComfyHost.ts +13 -2
  77. package/src/host/ComfyManager.ts +31 -13
  78. package/src/host/loraInfoCache.ts +35 -1
  79. package/src/host/loraManagerApi.ts +94 -0
  80. package/src/index.ts +2 -0
  81. package/src/promptEnhancers.ts +102 -0
  82. package/src/runner/ComfyExecution.ts +61 -6
  83. package/src/runner/ComfyWorkflow.ts +18 -4
  84. package/src/runner/ComfyWsApi.ts +3 -0
  85. package/src/runner/describePromptRejection.ts +34 -0
  86. package/src/sdk-generator/ComfySchema.ts +17 -4
  87. package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
  88. package/src/utils/ansi.ts +13 -0
  89. package/src/utils/matchesRegex.ts +13 -0
  90. package/src/utils/safeName.ts +29 -0
  91. package/src/utils/stringMap.ts +9 -0
  92. package/src/vars/ComfyVars.ts +61 -10
  93. package/src/vars/presets.ts +17 -0
  94. package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
  95. package/dist/DraftsSt-dizp3VcC.js.map +0 -1
  96. package/dist/run-serve-D1Tsuru9.js +0 -1162
  97. package/dist/run-serve-D1Tsuru9.js.map +0 -1
  98. package/dist/run-tui-JxlEbb_f.js.map +0 -1
  99. package/dist/state-CaHeDL-0.js.map +0 -1
  100. package/src/cli/serve/promptEnhancers.ts +0 -69
  101. package/src/cli/serve/safeName.ts +0 -12
@@ -3,7 +3,7 @@
3
3
  // and a few without, never reopening the popup to add it back. Model/clip
4
4
  // strengths sit on the card too. The popup is the only place that lists ALL
5
5
  // loras: tap one there to add it to the palette, ✕ on a card removes it.
6
- // The PALETTE is derived, never read off the draft: loras that are ON, plus the
6
+ // the PALETTE is derived, never read off the draft: loras that are ON, plus the
7
7
  // ones paused in this session. Reading "every key in the record" was the bug —
8
8
  // LorasVar writes `false` for every lora ever unticked, so a real draft with 35
9
9
  // keys and 2 on showed all 35. A pause removes the key (and remembers the
@@ -11,21 +11,26 @@
11
11
  // toggles hide images/titles on every lora surface (NSFW screens, persisted on
12
12
  // WebSt); with both hidden the row collapses to a count. Names come from
13
13
  // descriptor optionLabels; the value keeps raw enum keys, replaced by copy
14
+ import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
15
+ import { logWebError } from 'src/cli/serve/web/logWeb.ts'
14
16
  import { observer, useLocalObservable } from 'mobx-react-lite'
15
- import { useEffect, type ReactNode } from 'react'
16
- import { fetchLoraInfo, loraPreviewSrc, type LoraInfo } from 'src/cli/serve/web/api.ts'
17
+ import { useEffect, useRef, type ReactNode } from 'react'
18
+ import { fetchLoraAbout, fetchLoraInfo, loraPreviewSrc, type LoraAbout, type LoraInfo } from 'src/cli/serve/web/api.ts'
17
19
  import type { LoraStrength } from 'src/vars/ComfyVars.ts'
18
20
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
19
21
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
20
22
  import {
21
23
  loraIsOn,
24
+ paletteOrder,
25
+ reorderLoras,
22
26
  loraStrengthPair,
23
27
  setLoraEnabled,
24
28
  setLoraStrength,
25
29
  type LoraStrengthPair,
26
30
  } from 'src/cli/serve/web/state/payload.ts'
27
31
 
28
- const CARD_CAP = 60
32
+ /** our own drag payload type: a foreign drag cannot forge it */
33
+ const CARD_DRAG_TYPE = 'application/x-comfy-lora'
29
34
 
30
35
  function asRecord(raw: unknown): Record<string, unknown> {
31
36
  if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) return raw as Record<string, unknown>
@@ -48,9 +53,21 @@ type LocalSt = {
48
53
  notePreviewFailed(name: string): void
49
54
  notePrevStrength(name: string, pair: LoraStrengthPair): void
50
55
  setPaused(name: string, paused: boolean): void
56
+ /** the lora whose details panel is open, null when none */
57
+ details: string | null
58
+ setDetails(name: string | null): void
59
+ /** model and clip shown APART, per lora. Absent = follow whether they already differ */
60
+ split: Map<string, boolean>
61
+ isSplit(name: string, whenUnset: boolean): boolean
62
+ setSplit(name: string, split: boolean): void
51
63
  }
52
64
 
53
- export const LorasControl = observer(function LorasControl(p: { v: VarSt; host: string; st: WebSt }) {
65
+ export const LorasControl = observer(function LorasControl(p: {
66
+ v: VarSt
67
+ host: string
68
+ st: WebSt
69
+ hostUrl: string | null
70
+ }) {
54
71
  const local = useLocalObservable<LocalSt>(() => ({
55
72
  open: false,
56
73
  filter: '',
@@ -77,18 +94,46 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
77
94
  if (paused) this.paused.add(name)
78
95
  else this.paused.delete(name)
79
96
  },
97
+ details: null,
98
+ setDetails(name: string | null) {
99
+ this.details = name
100
+ },
101
+ split: new Map(),
102
+ isSplit(name: string, whenUnset: boolean) {
103
+ return this.split.get(name) ?? whenUnset
104
+ },
105
+ setSplit(name: string, split: boolean) {
106
+ this.split.set(name, split)
107
+ },
80
108
  }))
81
109
  const record = asRecord(p.v.value)
82
110
  const options = p.v.desc.options ?? []
83
111
  const labels = p.v.desc.optionLabels ?? {}
84
112
  const label = (name: string): string => labels[name] ?? name
85
113
  // the PALETTE is what the row shows: the loras that are ON, plus the ones paused in this
86
- // session. It is NOT "every key in the record" — LorasVar writes `false` for every lora
87
- // ever unticked, so that reading put the whole catalog in the row (his repro: a draft
114
+ // session. It is NOT "every key in the record", LorasVar writes `false` for every lora
115
+ // ever unticked, so that reading put the whole catalog in the row (a real draft
88
116
  // with 35 keys and 2 on). A paused lora leaves the record entirely and lives here instead
89
117
  const isOn = (name: string): boolean => loraIsOn(record[name])
90
118
  const isInPalette = (name: string): boolean => isOn(name) || local.paused.has(name)
91
- const selectedNames = options.filter(isInPalette)
119
+ // NEWEST FIRST: the record keeps insertion order, so the lora you just added is the last
120
+ // key, reversed, it lands where you are looking instead of at the end of the row
121
+ const selectedNames = paletteOrder({ record, options, paused: local.paused })
122
+ /** known to the lora manager, absent from ComfyUI's own enum. it is offered rather than
123
+ * hidden, but ComfyUI validates a prompt against the enum it has CACHED, so picking one
124
+ * fails at send time until that host rescans its models */
125
+ const managerOnly = new Set(p.v.desc.managerOnlyOptions ?? [])
126
+ const MANAGER_ONLY_TIP =
127
+ 'on disk and known to the lora manager, but ComfyUI has not scanned it: it refuses the prompt. only restarting ComfyUI makes it re-read the folder'
128
+ const warnBadge = (name: string): ReactNode =>
129
+ managerOnly.has(name) ? (
130
+ <span className="lora-warn" data-tip={MANAGER_ONLY_TIP}>
131
+ <Icon name="warn" size={0.9} />
132
+ </span>
133
+ ) : null
134
+ /** manager-only loras actually IN the palette: those are the ones a run will send, and the
135
+ * ones ComfyUI has no entry for until it rescans its models */
136
+ const managerOnlyInUse = selectedNames.filter((n) => managerOnly.has(n))
92
137
  const showImages = p.st.showLoraImages
93
138
  const showTitles = p.st.showLoraTitles
94
139
 
@@ -114,31 +159,39 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
114
159
  p.v.set(setLoraStrength(record, name, pair))
115
160
  }
116
161
 
117
- /** model/clip inputs. A PAUSED lora still edits its strengths — they are what comes back */
162
+ /** ONE slider by default, labelled `m+c`: model and clip are the same number in almost every
163
+ * lora, and two sliders for one decision is noise. Clicking the label splits them, and a lora
164
+ * whose values already differ opens split, its setting is someone's work, not a default */
118
165
  const strengthInputs = (name: string): ReactNode => {
119
166
  const pair = isOn(name) ? loraStrengthPair(record[name]) : (local.prevStrength.get(name) ?? { model: 1, clip: 1 })
120
- return (
121
- <>
122
- <span className="st-label">m</span>
123
- <input
124
- type="number"
125
- step={0.05}
126
- value={pair.model}
127
- onChange={(e) => {
128
- const n = parseFloat(e.target.value)
129
- if (Number.isFinite(n)) setStrength(name, { model: n, clip: pair.clip })
130
- }}
131
- />
132
- <span className="st-label">c</span>
167
+ const split = local.isSplit(name, pair.model !== pair.clip)
168
+ const write = (which: 'model' | 'clip' | 'both', raw: number): void => {
169
+ if (!Number.isFinite(raw)) return
170
+ const n = Math.round(raw * 100) / 100
171
+ if (which === 'both') return setStrength(name, { model: n, clip: n })
172
+ setStrength(name, which === 'model' ? { model: n, clip: pair.clip } : { model: pair.model, clip: n })
173
+ }
174
+ const line = (which: 'model' | 'clip' | 'both', value: number, text: string, tip: string): ReactNode => (
175
+ <div className="st-line">
176
+ <button type="button" className="st-label" data-tip={tip} onClick={() => local.setSplit(name, !split)}>
177
+ {text}
178
+ </button>
133
179
  <input
134
- type="number"
180
+ type="range"
181
+ min={-1}
182
+ max={2}
135
183
  step={0.05}
136
- value={pair.clip}
137
- onChange={(e) => {
138
- const n = parseFloat(e.target.value)
139
- if (Number.isFinite(n)) setStrength(name, { model: pair.model, clip: n })
140
- }}
184
+ value={value}
185
+ onChange={(e) => write(which, parseFloat(e.target.value))}
141
186
  />
187
+ <input type="number" step={0.05} value={value} onChange={(e) => write(which, parseFloat(e.target.value))} />
188
+ </div>
189
+ )
190
+ if (!split) return line('both', pair.model, 'm+c', 'model and clip together — click to set them apart')
191
+ return (
192
+ <>
193
+ {line('model', pair.model, 'm', 'model strength — click to tie them back together')}
194
+ {line('clip', pair.clip, 'c', 'clip strength — click to tie them back together')}
142
195
  </>
143
196
  )
144
197
  }
@@ -172,7 +225,48 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
172
225
  const matchesFilter = (name: string): boolean =>
173
226
  name.toLowerCase().includes(needle) || label(name).toLowerCase().includes(needle)
174
227
  const matches = options.filter(matchesFilter)
175
- const cards = matches.filter((o) => !isInPalette(o)).slice(0, CARD_CAP)
228
+ const cardCap = p.st.loraCap
229
+ const cards = matches.filter((o) => !isInPalette(o)).slice(0, cardCap)
230
+ /** the enum value IS a path (`krea2\styles\x.safetensors`, separators vary by host and by
231
+ * where the name came from), so the folder is everything before the last separator */
232
+ const folderOf = (name: string): string => {
233
+ const parts = name.split(/[\\/]+/)
234
+ return parts.length <= 1 ? '' : parts.slice(0, -1).join('/')
235
+ }
236
+ const groupedCards = (() => {
237
+ const byFolder = new Map<string, string[]>()
238
+ for (const name of cards) {
239
+ const folder = folderOf(name)
240
+ const list = byFolder.get(folder)
241
+ if (list == null) byFolder.set(folder, [name])
242
+ else list.push(name)
243
+ }
244
+ return [...byFolder.entries()]
245
+ .map(([folder, names]) => ({ folder, names }))
246
+ .sort((a, b) => a.folder.localeCompare(b.folder))
247
+ })()
248
+
249
+ // opening the popup puts you IN the filter with the previous needle SELECTED, so typing
250
+ // replaces it instead of appending to it (the field keeps its text between opens)
251
+ const filterRef = useRef<HTMLInputElement>(null)
252
+ useEffect(() => {
253
+ if (!open) return
254
+ const input = filterRef.current
255
+ if (input == null) return
256
+ input.focus()
257
+ input.select()
258
+ }, [open])
259
+
260
+ /** enter takes the FIRST card, the one the eye lands on. The popup stays open with the
261
+ * needle reselected, so adding three loras is type-enter-type-enter, and the new entry
262
+ * is visible at once in the palette section above */
263
+ const addFirstMatch = (): void => {
264
+ const first = cards[0]
265
+ if (first == null) return
266
+ // the SAME call the card's own click makes, so enter and a tap cannot drift apart
267
+ setEntry(first, [1, 1])
268
+ filterRef.current?.select()
269
+ }
176
270
 
177
271
  const thumb = (name: string): ReactNode => {
178
272
  if (!showImages) return null
@@ -181,7 +275,7 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
181
275
  ) : (
182
276
  <img
183
277
  key={name}
184
- className="lora-thumb"
278
+ className={p.st.loraFill ? 'lora-thumb fill' : 'lora-thumb'}
185
279
  loading="lazy"
186
280
  src={loraPreviewSrc({ host: p.host, name })}
187
281
  alt={label(name)}
@@ -195,85 +289,224 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
195
289
  <button
196
290
  type="button"
197
291
  className={showImages ? 'mode sel' : 'mode'}
198
- title={showImages ? 'hide lora images' : 'show lora images'}
292
+ data-tip={showImages ? 'hide lora images' : 'show lora images'}
199
293
  onClick={() => p.st.toggleLoraImages()}
200
294
  >
201
- 🖼
295
+ <Icon name="image" />
202
296
  </button>
203
297
  <button
204
298
  type="button"
205
299
  className={showTitles ? 'mode sel' : 'mode'}
206
- title={showTitles ? 'hide lora titles' : 'show lora titles'}
300
+ data-tip={showTitles ? 'hide lora titles' : 'show lora titles'}
207
301
  onClick={() => p.st.toggleLoraTitles()}
208
302
  >
209
- 🏷
303
+ <Icon name="tag" />
210
304
  </button>
305
+ {/* cover vs contain: a style lora's art crops beautifully and a character sheet does
306
+ not, so which one is right is per collection, not something to decide here */}
307
+ {showImages ? (
308
+ <button
309
+ type="button"
310
+ className={p.st.loraFill ? 'mode sel' : 'mode'}
311
+ data-tip={p.st.loraFill ? 'fit the whole preview inside the card' : 'fill the card with the preview'}
312
+ onClick={() => p.st.toggleLoraFill()}
313
+ >
314
+ <Icon name={p.st.loraFill ? 'shrink' : 'expand'} />
315
+ </button>
316
+ ) : null}
211
317
  </>
212
318
  )
213
319
 
214
320
  return (
215
321
  <div>
322
+ {/* the controls sit ABOVE the palette, left aligned: after a row of cards they read as
323
+ an afterthought, and a centred trio of buttons has nothing to align with */}
324
+ <div className="lora-actions">
325
+ <button type="button" className="field-height" onClick={() => local.setOpen(true)}>
326
+ <Icon name="plus" /> {selectedNames.length === 0 ? `add loras (${options.length})` : 'add'}
327
+ </button>
328
+ <span className="btn-group field-height">{visibilityToggles}</span>
329
+ {/* the host's OWN lora manager: where you tag, rename and re-scan them. Same host
330
+ the runs go to, so the page you open is the one that owns these files */}
331
+ <button
332
+ type="button"
333
+ className="field-height"
334
+ disabled={p.st.loraSyncing}
335
+ data-tip="re-download the lora metadata from the lora manager on this host (names, trigger words, previews)"
336
+ onClick={() => void p.st.refreshLoras()}
337
+ >
338
+ <Icon name="refresh" /> {p.st.loraSyncing ? 'syncing…' : 'sync'}
339
+ </button>
340
+ {managerOnlyInUse.length > 0 ? (
341
+ <button
342
+ type="button"
343
+ className="field-height warn-action"
344
+ disabled={p.st.hostWatch === 'down'}
345
+ data-tip={`${managerOnlyInUse.length} lora(s) here are on disk but ComfyUI has not scanned them, so it refuses the prompt. Only a RESTART makes it re-read its models folder: refetching the schema just re-reads the same list. then hit refresh here and the var widens in place`}
346
+ onClick={() => void p.st.hostAction('restart')}
347
+ >
348
+ <Icon name="power" /> restart ComfyUI
349
+ </button>
350
+ ) : null}
351
+ {p.hostUrl == null ? null : (
352
+ <a
353
+ className="button-link field-height"
354
+ href={`${p.hostUrl}/loras`}
355
+ target="_blank"
356
+ rel="noreferrer"
357
+ data-tip="open the lora manager of this host in a new tab"
358
+ >
359
+ <Icon name="external" /> manager
360
+ </a>
361
+ )}
362
+ {selectedNames.length > 0 ? (
363
+ <span className="hint">
364
+ {selectedNames.length} in the palette · {selectedNames.filter(isOn).length} on
365
+ </span>
366
+ ) : null}
367
+ {/* the workflow's own narrowing, said out loud: a picker that shows 200 loras when
368
+ the var asked for krea2 ones is not explainable */}
369
+ {p.v.desc.optionsFilter == null ? null : (
370
+ <span
371
+ className="hint"
372
+ data-tip="this workflow declared v.loras(<regex>) — only matching loras are offered"
373
+ >
374
+ filter {p.v.desc.optionsFilter}
375
+ </span>
376
+ )}
377
+ </div>
216
378
  <div className="row-inline">
217
379
  {!showImages && !showTitles ? (
218
380
  <span className="hint">
219
381
  {selectedNames.length} lora{selectedNames.length === 1 ? '' : 's'} in the palette
220
382
  </span>
221
383
  ) : (
222
- selectedNames.map((name) => (
384
+ selectedNames.map((name, ix) => (
223
385
  <span
224
386
  key={name}
225
387
  className={`${showImages ? 'lora-chip card' : 'lora-chip'}${isOn(name) ? '' : ' off'}`}
388
+ draggable
389
+ onMouseDown={(e) => {
390
+ // the WHOLE card drags, so the browser hands it the pointer before any
391
+ // control below sees it, and a slider drag would only reorder the card.
392
+ // disarm for this gesture when it starts on an input: recomputed on every
393
+ // mousedown, so there is no armed/disarmed state to leak
394
+ const from = e.target as HTMLElement
395
+ // buttons too (✕, the m+c label): a press that drifts a pixel would
396
+ // otherwise start a reorder instead of firing the click
397
+ e.currentTarget.draggable = from.closest('input, label, button, select, a') == null
398
+ }}
399
+ // re-arm once the gesture is over, so the grab cursor comes back the
400
+ // moment you leave the slider
401
+ onMouseUp={(e) => {
402
+ e.currentTarget.draggable = true
403
+ }}
404
+ onDragStart={(e) => {
405
+ e.dataTransfer.effectAllowed = 'move'
406
+ // the index travels in the drag itself: no drag state to leak or reset
407
+ e.dataTransfer.setData(CARD_DRAG_TYPE, String(ix))
408
+ }}
409
+ // only OUR drag: a desktop file or a var row carries no index, and
410
+ // Number('') is 0, so a foreign drop would reorder from slot 0
411
+ onDragOver={(e) => {
412
+ if (e.dataTransfer.types.includes(CARD_DRAG_TYPE)) e.preventDefault()
413
+ }}
414
+ onDrop={(e) => {
415
+ const raw = e.dataTransfer.getData(CARD_DRAG_TYPE)
416
+ if (raw === '') return
417
+ e.preventDefault()
418
+ const from = Number(raw)
419
+ if (Number.isInteger(from) && from !== ix)
420
+ p.v.set(reorderLoras({ record, displayed: selectedNames, from, to: ix }))
421
+ }}
226
422
  >
227
- {/* THE palette gesture: the card itself pauses and resumes, so trying a
228
- few images with a lora and a few without never opens the popup */}
229
- <button
230
- type="button"
231
- className="lora-toggle"
232
- title={isOn(name) ? `${name}\nclick to pause` : `${name}\npaused — click to resume`}
233
- onClick={() => toggleOn(name, !isOn(name))}
234
- >
235
- {thumb(name)}
236
- {showTitles ? <span className="chip-title">{label(name)}</span> : null}
237
- <span className="chip-state">{isOn(name) ? '● on' : '⏸ paused'}</span>
238
- </button>
239
- <span className="chip-controls">
240
- {strengthInputs(name)}
423
+ {/* the ✕ is a child of the PICTURE's own box, never of the card: its
424
+ containing block is then this wrapper whatever else is positioned
425
+ around it, so it cannot take a row of flow nor escape the card */}
426
+ <span className="chip-media">
427
+ {/* the CARD opens what this lora is; only the switch turns it on and off,
428
+ so reading about a lora can never change what the graph runs */}
241
429
  <button
242
430
  type="button"
243
- title="remove from the palette (the popup adds it back)"
431
+ className="lora-toggle"
432
+ data-tip={`${name}\nclick for its details`}
433
+ onClick={() => local.setDetails(name)}
434
+ >
435
+ {thumb(name)}
436
+ </button>
437
+ <button
438
+ type="button"
439
+ className="chip-remove"
440
+ data-tip="remove from the palette (the popup adds it back)"
244
441
  onClick={() => setEntry(name, null)}
245
442
  >
246
- ✕
443
+ <Icon name="close" size={1.05} />
247
444
  </button>
248
445
  </span>
446
+ {/* the switch sits WITH the title: state and name read as one line */}
447
+ <span className="chip-head">
448
+ <label className="switch" data-tip={isOn(name) ? 'pause this lora' : 'resume this lora'}>
449
+ <input
450
+ type="checkbox"
451
+ checked={isOn(name)}
452
+ onChange={(e) => toggleOn(name, e.target.checked)}
453
+ />
454
+ <span className="track" />
455
+ </label>
456
+ {showTitles ? (
457
+ <button
458
+ type="button"
459
+ className="chip-title as-text"
460
+ data-tip={`${name}\nclick for its details`}
461
+ onClick={() => local.setDetails(name)}
462
+ >
463
+ {label(name)}
464
+ </button>
465
+ ) : null}
466
+ {warnBadge(name)}
467
+ </span>
468
+ <span className="chip-controls">{strengthInputs(name)}</span>
249
469
  </span>
250
470
  ))
251
471
  )}
252
- <button type="button" onClick={() => local.setOpen(true)}>
253
- {selectedNames.length === 0 ? `add loras… (${options.length})` : '+ add…'}
254
- </button>
255
- {visibilityToggles}
256
472
  </div>
257
473
 
474
+ {local.details == null ? null : (
475
+ <LoraDetails
476
+ name={local.details}
477
+ host={p.host}
478
+ hostUrl={p.hostUrl}
479
+ label={label(local.details)}
480
+ showImage={showImages}
481
+ keyword={(p.v.desc.optionKeywords ?? {})[local.details] ?? null}
482
+ managerOnly={managerOnly.has(local.details)}
483
+ onClose={() => local.setDetails(null)}
484
+ />
485
+ )}
258
486
  {local.open ? (
259
487
  <div className="modal-overlay" onClick={() => local.setOpen(false)}>
260
488
  <div className="modal" onClick={(e) => e.stopPropagation()}>
261
489
  <div className="modal-head">
262
490
  <input
491
+ ref={filterRef}
263
492
  type="text"
264
- autoFocus
265
- placeholder={`filter ${options.length} loras`}
493
+ placeholder={`search ${options.length} loras${p.v.desc.optionsFilter == null ? '' : ` matching ${p.v.desc.optionsFilter}`} — enter adds the first`}
266
494
  value={local.filter}
267
495
  onChange={(e) => local.setFilter(e.target.value)}
496
+ onKeyDown={(e) => {
497
+ if (e.key !== 'Enter') return
498
+ e.preventDefault()
499
+ addFirstMatch()
500
+ }}
268
501
  />
269
502
  {visibilityToggles}
270
- <button type="button" title="close (esc)" onClick={() => local.setOpen(false)}>
271
- ✕
503
+ <button type="button" data-tip="close (esc)" onClick={() => local.setOpen(false)}>
504
+ <Icon name="close" />
272
505
  </button>
273
506
  </div>
274
507
  <div className="modal-body">
275
508
  {selectedNames.length > 0 ? (
276
- <div className="lora-active-section">
509
+ <div>
277
510
  <div className="section-title">your palette ({selectedNames.length})</div>
278
511
  {selectedNames.filter(matchesFilter).map((name) => {
279
512
  const info = local.info.get(name)
@@ -281,7 +514,7 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
281
514
  <div key={name} className={isOn(name) ? 'lora-active-row' : 'lora-active-row off'}>
282
515
  {thumb(name)}
283
516
  <div className="lora-active-text">
284
- <div className="lora-label" title={name}>
517
+ <div className="lora-label" data-tip={name}>
285
518
  {showTitles ? label(name) : '···'}
286
519
  </div>
287
520
  {typeof info === 'object' && info.triggerWords.length > 0 ? (
@@ -293,16 +526,17 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
293
526
  <input
294
527
  type="checkbox"
295
528
  checked={isOn(name)}
296
- title={isOn(name) ? 'pause (stays in the palette)' : 'resume'}
529
+ data-tip={isOn(name) ? 'pause (stays in the palette)' : 'resume'}
297
530
  onChange={(e) => toggleOn(name, e.target.checked)}
298
531
  />
299
532
  {strengthInputs(name)}
300
533
  <button
301
534
  type="button"
302
- title="remove from the list"
535
+ className="chip-remove"
536
+ data-tip="remove from the list"
303
537
  onClick={() => setEntry(name, null)}
304
538
  >
305
- ✕
539
+ <Icon name="close" size={0.9} />
306
540
  </button>
307
541
  </div>
308
542
  )
@@ -310,24 +544,48 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
310
544
  </div>
311
545
  ) : null}
312
546
  <div className="section-title">all loras — tap to add to the palette</div>
313
- <div className="lora-grid">
314
- {cards.map((name) => (
315
- <button
316
- key={name}
317
- type="button"
318
- className="lora-card"
319
- title={name}
320
- onClick={() => setEntry(name, [1, 1])}
321
- >
322
- {thumb(name)}
323
- <div className="lora-label">{showTitles ? label(name) : name.slice(0, 2) + '···'}</div>
324
- </button>
325
- ))}
326
- </div>
327
- {matches.length - selectedNames.filter(matchesFilter).length > CARD_CAP ? (
547
+ {groupedCards.map((group) => (
548
+ <div key={group.folder}>
549
+ <div className="section-title">
550
+ {group.folder === '' ? 'loose (no folder)' : `${group.folder}/`} · {group.names.length}
551
+ </div>
552
+ <div className="lora-grid">
553
+ {group.names.map((name) => (
554
+ <button
555
+ key={name}
556
+ type="button"
557
+ className="lora-card"
558
+ data-tip={name}
559
+ onClick={() => setEntry(name, [1, 1])}
560
+ >
561
+ {thumb(name)}
562
+ <div className="lora-label">
563
+ {showTitles ? label(name) : name.slice(0, 2) + '···'}
564
+ {warnBadge(name)}
565
+ </div>
566
+ </button>
567
+ ))}
568
+ </div>
569
+ </div>
570
+ ))}
571
+ {matches.length - selectedNames.filter(matchesFilter).length > cardCap ? (
328
572
  <div className="loras-more">
329
- … {matches.length - selectedNames.filter(matchesFilter).length - CARD_CAP} more — refine the
330
- filter
573
+ … {matches.length - selectedNames.filter(matchesFilter).length - cardCap} more — refine the
574
+ filter, or draw
575
+ <input
576
+ type="number"
577
+ min={1}
578
+ max={2000}
579
+ value={cardCap}
580
+ data-tip="how many cards this popup draws — each one is an image request, so the right number depends on your collection and your box. Kept in this browser"
581
+ // an empty box is mid-edit, not a request for the default: without
582
+ // this, clearing the field snapped the value to 200 as you typed
583
+ onChange={(e) => {
584
+ const n = parseInt(e.target.value, 10)
585
+ if (Number.isFinite(n)) p.st.setLoraCap(n)
586
+ }}
587
+ />
588
+ at once
331
589
  </div>
332
590
  ) : null}
333
591
  {matches.length === 0 ? <div className="loras-more">no lora matches '{local.filter}'</div> : null}
@@ -338,3 +596,162 @@ export const LorasControl = observer(function LorasControl(p: { v: VarSt; host:
338
596
  </div>
339
597
  )
340
598
  })
599
+
600
+ /** what a lora IS, from the lora-manager mirror: clicking a card opens this instead of
601
+ * silently toggling the graph. Everything shown comes from the mirror, so an unsynced lora
602
+ * says so rather than rendering an empty sheet */
603
+ const LoraDetails = observer(function LoraDetails(p: {
604
+ name: string
605
+ host: string
606
+ hostUrl: string | null
607
+ label: string
608
+ showImage: boolean
609
+ keyword: string | null
610
+ managerOnly: boolean
611
+ onClose(): void
612
+ }) {
613
+ const local = useLocalObservable<{
614
+ info: LoraInfo | 'loading' | 'error'
615
+ about: LoraAbout | null
616
+ aboutError: string | null
617
+ set(v: LoraInfo | 'loading' | 'error'): void
618
+ setAbout(v: LoraAbout | null): void
619
+ setAboutError(msg: string): void
620
+ }>(() => ({
621
+ info: 'loading',
622
+ about: null,
623
+ aboutError: null,
624
+ set(v) {
625
+ this.info = v
626
+ },
627
+ setAbout(v) {
628
+ this.about = v
629
+ this.aboutError = null
630
+ },
631
+ setAboutError(msg: string) {
632
+ this.about = null
633
+ this.aboutError = msg
634
+ },
635
+ }))
636
+ const { name, host } = p
637
+ useEffect(() => {
638
+ // the panel is ONE instance reused across loras, and /lora-about is a live host round
639
+ // trip: without this guard, opening A then B within A's latency painted A's description
640
+ // and example images under B's title
641
+ let current = true
642
+ local.set('loading')
643
+ local.setAbout(null)
644
+ fetchLoraInfo({ host, name })
645
+ .then((i) => {
646
+ if (current) local.set(i)
647
+ })
648
+ .catch((e: unknown) => {
649
+ if (current) local.set('error')
650
+ logWebError(`lora info for ${name}`, e)
651
+ })
652
+ // the LIVE half (civitai description + example images) arrives second: the mirror data
653
+ // must not wait on a host round trip to render
654
+ fetchLoraAbout({ host, name })
655
+ .then((a) => {
656
+ if (current) local.setAbout(a)
657
+ })
658
+ .catch((e: unknown) => {
659
+ // an empty sheet reads as "this lora has nothing to say", which is a different
660
+ // fact from "the extension did not answer"
661
+ if (current) local.setAboutError(e instanceof Error ? e.message : String(e))
662
+ logWebError(`lora details for ${name}`, e)
663
+ })
664
+ return () => {
665
+ current = false
666
+ }
667
+ }, [host, name, local])
668
+ useEffect(() => {
669
+ const onKey = (e: KeyboardEvent): void => {
670
+ if (e.key === 'Escape') p.onClose()
671
+ }
672
+ window.addEventListener('keydown', onKey)
673
+ return () => window.removeEventListener('keydown', onKey)
674
+ }, [p])
675
+ const info = local.info
676
+ const row = (k: string, v: ReactNode): ReactNode =>
677
+ v == null || v === '' ? null : (
678
+ <div className="detail-row">
679
+ <span className="detail-key">{k}</span>
680
+ <span className="detail-val">{v}</span>
681
+ </div>
682
+ )
683
+ return (
684
+ <div className="modal-overlay" onClick={() => p.onClose()}>
685
+ <div className="modal" onClick={(e) => e.stopPropagation()}>
686
+ <div className="modal-head">
687
+ <b style={{ flex: 1 }}>{p.label}</b>
688
+ <button type="button" data-tip="close (esc)" onClick={() => p.onClose()}>
689
+ <Icon name="close" />
690
+ </button>
691
+ </div>
692
+ <div className="modal-body">
693
+ {info === 'loading' ? <div className="hint">reading the mirror…</div> : null}
694
+ {info === 'error' ? <div className="error">🔴 could not read this lora's metadata</div> : null}
695
+ {typeof info === 'object' ? (
696
+ <div className="lora-details">
697
+ {p.showImage ? (
698
+ <img className="detail-thumb" src={loraPreviewSrc({ host, name })} alt={p.label} />
699
+ ) : null}
700
+ <div className="detail-list">
701
+ {info.known === false ? (
702
+ <div className="hint">
703
+ not in the lora manager mirror — run sync, or this file is unknown to it
704
+ </div>
705
+ ) : null}
706
+ {p.managerOnly ? <div className="hint">⚠ only the lora manager lists it, not comfy</div> : null}
707
+ {row('file', name)}
708
+ {row('base model', info.baseModel)}
709
+ {row('folder', info.folder)}
710
+ {row('trigger words', info.triggerWords.join(', '))}
711
+ {row('prompt keyword', p.keyword)}
712
+ {row('tags', (info.tags ?? []).join(', '))}
713
+ {row('notes', info.notes)}
714
+ {row('size', info.fileSize == null ? null : `${(info.fileSize / 1e9).toFixed(2)} GB`)}
715
+ {row('path', info.filePath)}
716
+ {local.about?.description == null ? null : (
717
+ <div className="detail-desc">{local.about.description}</div>
718
+ )}
719
+ {row(
720
+ 'civitai',
721
+ info.civitaiUrl == null ? null : (
722
+ <a href={info.civitaiUrl} target="_blank" rel="noreferrer">
723
+ {info.civitaiVersion ?? 'model page'} ↗
724
+ </a>
725
+ ),
726
+ )}
727
+ {local.about != null && local.about.examples.length > 0 ? (
728
+ <div>
729
+ <div className="section-title">examples ({local.about.examples.length})</div>
730
+ <div className="detail-examples">
731
+ {local.about.examples.slice(0, 8).map((src) => (
732
+ <img key={src} src={src} alt="" loading="lazy" />
733
+ ))}
734
+ </div>
735
+ </div>
736
+ ) : null}
737
+ {local.about?.examplesReason == null ? null : (
738
+ <div className="hint">no example images: {local.about.examplesReason}</div>
739
+ )}
740
+ {/* an empty sheet reads as "this lora has nothing to say"; that the
741
+ extension never answered is a different fact and must be said */}
742
+ {local.aboutError == null ? null : (
743
+ <div className="error">🔴 the lora manager did not answer: {local.aboutError}</div>
744
+ )}
745
+ {p.hostUrl == null ? null : (
746
+ <a className="button-link" href={`${p.hostUrl}/loras`} target="_blank" rel="noreferrer">
747
+ <Icon name="external" /> open in the lora manager
748
+ </a>
749
+ )}
750
+ </div>
751
+ </div>
752
+ ) : null}
753
+ </div>
754
+ </div>
755
+ </div>
756
+ )
757
+ })