refactor(lora-provider): extract mode change logic to shared TypeScript module

- Extract common mode change logic from lora_randomizer.js and lora_stacker.js
  into new mode-change-handler.ts TypeScript module
- Add LORA_PROVIDER_NODE_TYPES constant to centralize LoRA provider node types
- Update getActiveLorasFromNode in utils.js to support Lora Cycler's
  cycler_config widget (single current_lora_filename)
- Update getConnectedInputStackers and updateDownstreamLoaders to use
  isLoraProviderNode helper instead of hardcoded class checks
- Register mode change handlers in main.ts for all LoRA provider nodes
  (Lora Stacker, Lora Randomizer, Lora Cycler)
- Add value change callback to Lora Cycler widget to trigger
  updateDownstreamLoaders when current_lora_filename changes
- Remove duplicate mode change logic from lora_stacker.js
- Delete lora_randomizer.js (logic now centralized)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Will Miao
2026-01-22 20:46:09 +08:00
parent 6832469889
commit 932d85617c
7 changed files with 320 additions and 85 deletions

View File

@@ -31,34 +31,6 @@ app.registerExtension({
let isUpdating = false;
let isSyncingInput = false;
// Mechanism 3: Property descriptor to listen for mode changes
const self = this;
let _mode = this.mode;
Object.defineProperty(this, 'mode', {
get() {
return _mode;
},
set(value) {
const oldValue = _mode;
_mode = value;
// Trigger mode change handler
if (self.onModeChange) {
self.onModeChange(value, oldValue);
}
}
});
// Define the mode change handler
this.onModeChange = function(newMode, oldMode) {
// Update connected trigger word toggle nodes and downstream loader trigger word toggle nodes
// when mode changes, similar to when loras change
const isNodeActive = newMode === 0 || newMode === 3; // Active when mode is Always (0) or On Trigger (3)
const activeLoraNames = isNodeActive ? getActiveLorasFromNode(self) : new Set();
updateConnectedTriggerWords(self, activeLoraNames);
updateDownstreamLoaders(self);
};
const inputWidget = this.widgets[0];
inputWidget.options.getMaxHeight = () => 100;
this.inputWidget = inputWidget;