|
1 | 1 | <script lang="ts"> |
2 | | - import { createEventDispatcher } from 'svelte'; |
| 2 | + import { createEventDispatcher, onDestroy } from 'svelte'; |
3 | 3 | import Button from './Button.svelte'; |
4 | 4 |
|
5 | 5 | export let promptBlendingConfig: any = null; |
|
27 | 27 | // UI state |
28 | 28 | let activeTab: 'prompts' | 'seeds' = 'prompts'; |
29 | 29 |
|
| 30 | + // Debounce timers |
| 31 | + let promptDebounceTimer: number | null = null; |
| 32 | + let seedDebounceTimer: number | null = null; |
| 33 | + const DEBOUNCE_DELAY = 300; // milliseconds |
| 34 | +
|
| 35 | + // Cleanup timers on component destroy |
| 36 | + onDestroy(() => { |
| 37 | + if (promptDebounceTimer !== null) { |
| 38 | + clearTimeout(promptDebounceTimer); |
| 39 | + } |
| 40 | + if (seedDebounceTimer !== null) { |
| 41 | + clearTimeout(seedDebounceTimer); |
| 42 | + } |
| 43 | + }); |
| 44 | +
|
30 | 45 | // Helper functions for config hashing |
31 | 46 | function getPromptConfigHash(config: any, current: string): string { |
32 | 47 | return JSON.stringify(config) + '|' + current; |
|
146 | 161 |
|
147 | 162 | function updatePromptText(index: number, value: string) { |
148 | 163 | promptList[index][0] = value; |
149 | | - promptList = [...promptList]; |
150 | | - updatePromptBlendingWithoutRefresh(); |
| 164 | + hasPendingPromptChanges = true; |
| 165 | + |
| 166 | + // Clear existing timer |
| 167 | + if (promptDebounceTimer !== null) { |
| 168 | + clearTimeout(promptDebounceTimer); |
| 169 | + } |
| 170 | + |
| 171 | + // Set new debounced timer |
| 172 | + promptDebounceTimer = setTimeout(() => { |
| 173 | + updatePromptBlendingWithoutRefresh(); |
| 174 | + promptDebounceTimer = null; |
| 175 | + }, DEBOUNCE_DELAY) as unknown as number; |
151 | 176 | } |
152 | 177 |
|
153 | 178 | function updatePromptWeight(index: number, value: number) { |
|
225 | 250 |
|
226 | 251 | function updateSeedValue(index: number, value: number) { |
227 | 252 | seedList[index][0] = value; |
228 | | - seedList = [...seedList]; |
229 | | - updateSeedBlendingWithoutRefresh(); |
| 253 | + hasPendingSeedChanges = true; |
| 254 | + |
| 255 | + // Clear existing timer |
| 256 | + if (seedDebounceTimer !== null) { |
| 257 | + clearTimeout(seedDebounceTimer); |
| 258 | + } |
| 259 | + |
| 260 | + // Set new debounced timer |
| 261 | + seedDebounceTimer = setTimeout(() => { |
| 262 | + updateSeedBlendingWithoutRefresh(); |
| 263 | + seedDebounceTimer = null; |
| 264 | + }, DEBOUNCE_DELAY) as unknown as number; |
230 | 265 | } |
231 | 266 |
|
232 | 267 | function updateSeedWeight(index: number, value: number) { |
|
370 | 405 |
|
371 | 406 | <textarea |
372 | 407 | bind:value={promptList[index][0]} |
373 | | - on:input={() => updatePromptText(index, promptList[index][0])} |
| 408 | + on:input={(e) => updatePromptText(index, e.currentTarget.value)} |
374 | 409 | placeholder="Enter prompt..." |
375 | 410 | rows="2" |
376 | 411 | class="w-full p-2 border rounded resize-none dark:bg-gray-600 dark:border-gray-500" |
|
463 | 498 | <input |
464 | 499 | type="number" |
465 | 500 | bind:value={seedList[index][0]} |
466 | | - on:input={() => updateSeedValue(index, seedList[index][0])} |
| 501 | + on:input={(e) => updateSeedValue(index, Number(e.currentTarget.value))} |
467 | 502 | min="1" |
468 | 503 | max="999999" |
469 | 504 | class="flex-1 p-2 border rounded dark:bg-gray-600 dark:border-gray-500" |
|
0 commit comments