/** * 上下文显示组件 * 用于显示已选择的文件、文件夹、图片和文档 */ /** * 获取上下文显示区域的 HTML 内容 */ export function getContextDisplayContent(): string { return `
`; } /** * 获取上下文显示区域的样式 */ export function getContextDisplayStyles(): string { return ` /* 上下文显示区域 */ .context-display-area { margin-bottom: 8px; padding: 8px; background: rgba(128, 128, 128, 0.1); border-radius: 6px; border: 1px solid var(--vscode-input-border); } .context-items-container { display: flex; flex-wrap: wrap; gap: 8px; } /* 上下文项样式 */ .context-item { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--vscode-input-background); border: 1px solid var(--vscode-input-border); border-radius: 4px; font-size: 12px; color: var(--vscode-foreground); max-width: 300px; transition: all 0.2s ease; } .context-item.clickable { cursor: pointer; } .context-item.clickable:hover { background: var(--vscode-list-hoverBackground); } .context-item svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.8; } .context-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .context-item-remove { width: 14px; height: 14px; cursor: pointer; opacity: 0.6; transition: opacity 0.2s ease; flex-shrink: 0; } .context-item-remove:hover { opacity: 1; color: #f56c6c; } /* 图片预览样式 */ .context-item.image-item { position: relative; } .context-item-preview { width: 40px; height: 40px; object-fit: cover; border-radius: 3px; border: 1px solid var(--vscode-input-border); } `; } /** * 获取上下文显示区域的脚本 */ export function getContextDisplayScript(): string { return ` // 存储上下文项 let contextItems = []; // 获取文件图标 SVG function getFileIcon() { return ''; } // 获取文件夹图标 SVG function getFolderIcon() { return ''; } // 获取图片图标 SVG function getImageIcon() { return ''; } // 获取文档图标 SVG function getDocumentIcon() { return ''; } // 获取代码图标 SVG function getCodeIcon() { return ''; } // 获取删除图标 SVG function getRemoveIcon() { return ''; } // 提取文件名 function getFileName(path) { return path.split(/[\\\\/]/).pop(); } // 添加上下文项 function addContextItem(type, path, displayPath) { const exists = contextItems.some(item => item.type === type && item.path === path); if (exists) return; const id = Date.now() + Math.random(); contextItems.push({ id, type, path, displayPath: displayPath || '' }); renderContextItems(); } // 删除上下文项 function removeContextItem(id) { contextItems = contextItems.filter(item => item.id !== id); renderContextItems(); } // 渲染上下文项 function renderContextItems() { const container = document.getElementById('contextItemsContainer'); const displayArea = document.getElementById('contextDisplayArea'); if (!container || !displayArea) return; if (contextItems.length === 0) { displayArea.style.display = 'none'; return; } displayArea.style.display = 'block'; container.innerHTML = contextItems.map(item => { let icon = ''; switch(item.type) { case 'file': icon = getFileIcon(); break; case 'folder': icon = getFolderIcon(); break; case 'image': icon = getImageIcon(); break; case 'document': icon = getDocumentIcon(); break; case 'code': icon = getCodeIcon(); break; } const clickable = item.type !== 'folder' ? 'clickable' : ''; const onclick = item.type !== 'folder' ? \`onclick="window.handleContextItemClick(\${item.id})"\` : ''; return \`