// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails import "@hotwired/turbo-rails" import "controllers" // Custom Turbo Stream action to reset forms without replacing DOM // This preserves Stimulus controllers and their state (e.g., STT WebSocket connections) Turbo.StreamActions.reset_form = function () { const targetId = this.getAttribute("target"); const form = document.getElementById(targetId)?.querySelector("form") || document.getElementById(targetId); if (form && form.tagName === "FORM") { form.reset(); // Focus the first input and dispatch input event to update Stimulus controller state const input = form.querySelector("input[type='text'], textarea"); if (input) { // Dispatch input event so STT controller updates its internal state input.dispatchEvent(new Event("input", { bubbles: true })); input.focus(); } } };