class InterfaceConfig extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.idlContent = ''; this.filePath = ''; this.isEdited = false; } connectedCallback() { this.render(); this.addEventListeners(); // 加载IDL文件列表到下拉框 this.loadIdlFileList(); } addEventListeners() { // 新建文件按钮 this.shadowRoot.getElementById('new-file').addEventListener('click', () => this.handleNewFile()); // 文件选择下拉框 this.shadowRoot.getElementById('file-select-dropdown').addEventListener('change', (e) => { if (e.target.value) { this.handleFileChange(e.target.value); } }); // 保存按钮 this.shadowRoot.getElementById('save-button').addEventListener('click', () => this.saveFile()); // 另存为按钮 this.shadowRoot.getElementById('save-as-button').addEventListener('click', () => this.saveFileAs()); // 文本编辑器内容变化时更新可视化编辑器和编辑状态 this.shadowRoot.getElementById('idl-editor').addEventListener('input', () => { this.idlContent = this.shadowRoot.getElementById('idl-editor').value; this.updateVisualEditor(); this.setEditedState(true); }); } async selectFile() { try { // 获取IDL文件列表 const response = await fetch('/api/idl/list'); if (!response.ok) { const error = await response.json(); throw new Error(error.error || '获取文件列表失败'); } const data = await response.json(); // 显示文件选择对话框 if (!data.files || data.files.length === 0) { this.showConfirmDialog('文件列表', '没有可用的IDL文件', null); return; } // 创建文件选择对话框 const fileSelector = document.createElement('div'); fileSelector.className = 'method-dialog'; const fileListHtml = data.files.map(file => `