// 聊天输入区事件绑定,逐步替代底部输入栏内联提交事件。 let chatComposerEventsBound = false; /** * 绑定聊天表单提交事件。 * 发送主流程仍由 Blade 主脚本的 sendMessage 维护,这里只统一 submit 入口。 * * @returns {void} */ export function bindChatComposerControls() { if (chatComposerEventsBound || typeof document === "undefined") { return; } chatComposerEventsBound = true; document.addEventListener("submit", (event) => { const form = event.target; if (!(form instanceof HTMLFormElement) || !form.matches("[data-chat-form]")) { return; } event.preventDefault(); if (typeof window.sendMessage === "function") { void window.sendMessage(event); } }); } /** * 设置聊天动作并把焦点带回输入框。 * 该入口兼容旧模板可能存在的 `setAction(...)` 调用,切换右侧标签仍交给 Blade 里的 switchTab 处理。 * * @param {string} action 动作名称 * @param {(tab:string) => void} switchTabHandler 右侧标签切换函数 * @returns {void} */ export function setChatComposerAction( action, switchTabHandler = typeof window !== "undefined" ? window.switchTab : null, ) { const actionSelect = document.getElementById("action"); const contentInput = document.getElementById("content"); if (actionSelect) { actionSelect.value = action; } // 右侧在线名单切换仍在 Blade 主脚本内,模块只通过兼容入口调用。 if (typeof switchTabHandler === "function") { switchTabHandler("users"); } if (contentInput) { contentInput.focus(); } }