From 7b36b4315efa1f97fe03b4357ebb6ef7f4f26d38 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 10 Sep 2026 11:44:54 +0800 Subject: [PATCH] fix(preview): align header controls and artifact cards --- .../components/css/artifact-file-icon.less | 40 +++++++++++++ .../src/components/css/chat-markdown.less | 37 ++++++------ .../document-preview.fullscreen.test.mjs | 4 +- frontend/src/components/document-preview.vue | 59 ++++++++++++++----- frontend/src/utils/artifactFileIcon.ts | 16 +++++ .../src/utils/sandboxArtifactRefs.test.ts | 14 +++++ frontend/src/utils/sandboxArtifactRefs.ts | 13 +--- .../chat/components/ArtifactFileIcon.vue | 56 ++++-------------- .../chat/components/ChatArtifactsDrawer.vue | 7 +++ .../chat/components/ChatArtifactsPanel.vue | 7 +++ 10 files changed, 160 insertions(+), 93 deletions(-) create mode 100644 frontend/src/components/css/artifact-file-icon.less create mode 100644 frontend/src/utils/artifactFileIcon.ts diff --git a/frontend/src/components/css/artifact-file-icon.less b/frontend/src/components/css/artifact-file-icon.less new file mode 100644 index 00000000..55e64af6 --- /dev/null +++ b/frontend/src/components/css/artifact-file-icon.less @@ -0,0 +1,40 @@ +.artifact-file-icon-style() { + display: block; + flex-shrink: 0; + width: 32px; + height: 38px; + color: var(--td-text-color-secondary); + + &.kind-file-word { color: #5381c4; } + &.kind-file-excel { color: #419781; } + &.kind-file-powerpoint { color: #c18a4e; } + &.kind-file-pdf { color: #c56868; } + &.kind-image, + &.kind-video { color: #9273bd; } + &.kind-code, + &.kind-sound { color: #5d95ad; } + + .file-sheet { + fill: var(--td-bg-color-container); + stroke: currentColor; + stroke-opacity: 0.35; + stroke-width: 1.2; + } + + .file-fold, + .file-lines { + stroke: currentColor; + stroke-opacity: 0.35; + stroke-width: 1.2; + stroke-linecap: round; + stroke-linejoin: round; + } + + text { + fill: #fff; + font-family: ui-sans-serif, system-ui, sans-serif; + font-size: 7px; + font-weight: 650; + letter-spacing: 0.2px; + } +} diff --git a/frontend/src/components/css/chat-markdown.less b/frontend/src/components/css/chat-markdown.less index cdf0be79..c6165a45 100644 --- a/frontend/src/components/css/chat-markdown.less +++ b/frontend/src/components/css/chat-markdown.less @@ -1,4 +1,5 @@ @import './chat-hljs.less'; +@import './artifact-file-icon.less'; // Single source of truth for chat answer Markdown typography and block styles. // Used by botmsg, AgentStreamDisplay, embed chat, and the dev Markdown test page. @@ -644,25 +645,25 @@ :deep(.artifact-ref-card) { display: inline-flex; align-items: center; - gap: 10px; + gap: 12px; + width: 420px; max-width: min(420px, 100%); margin: 0.75em 0; - padding: 8px 14px 8px 10px; - border: 1px solid var(--td-component-stroke); - border-radius: 10px; - background: var(--td-bg-color-container); + box-sizing: border-box; + padding: 12px 8px; + border-radius: 8px; + background: transparent; cursor: pointer; vertical-align: middle; text-align: left; - transition: border-color 0.15s ease, background 0.15s ease; + transition: background 0.15s ease; &:hover { - border-color: var(--td-brand-color); background: var(--td-bg-color-container-hover); } &:focus-visible { - outline: 2px solid var(--td-brand-color); + outline: 2px solid var(--td-text-color-secondary); outline-offset: 2px; } } @@ -672,37 +673,34 @@ opacity: 0.7; &:hover { - border-color: var(--td-component-stroke); - background: var(--td-bg-color-container); + background: transparent; } } :deep(.artifact-ref-card__icon) { flex-shrink: 0; - width: 30px; - height: 30px; - border-radius: 8px; + width: 32px; + height: 38px; display: inline-flex; align-items: center; justify-content: center; - background: var(--td-bg-color-secondarycontainer); - color: var(--td-text-color-secondary); } - :deep(.artifact-ref-card__glyph) { - width: 17px; - height: 17px; + :deep(.artifact-file-icon-svg) { + .artifact-file-icon-style(); } :deep(.artifact-ref-card__text) { display: inline-flex; flex-direction: column; min-width: 0; + flex: 1; } :deep(.artifact-ref-card__name) { font-size: 13px; - font-weight: 600; + font-weight: 500; + letter-spacing: 0.01em; line-height: 1.35; color: var(--td-text-color-primary); overflow: hidden; @@ -711,6 +709,7 @@ } :deep(.artifact-ref-card__hint) { + margin-top: 2px; font-size: 12px; line-height: 1.3; color: var(--td-text-color-placeholder); diff --git a/frontend/src/components/document-preview.fullscreen.test.mjs b/frontend/src/components/document-preview.fullscreen.test.mjs index 98e8bbb5..f37c4e03 100644 --- a/frontend/src/components/document-preview.fullscreen.test.mjs +++ b/frontend/src/components/document-preview.fullscreen.test.mjs @@ -149,7 +149,9 @@ test('diagram zoom exits native fullscreen before opening its body-mounted viewe test('toolbar reserves layout space in normal and fullscreen modes and keeps exit visible on errors', async () => { const { descriptor } = parse(source) assert.match(descriptor.template.content, /v-if="isFullscreen \|\|/) - assert.match(descriptor.template.content, /\{\{ isFullscreen \? \$t\('preview.exitFullscreen'\)/) + assert.match(descriptor.template.content, /:aria-label="isFullscreen \? \$t\('preview.exitFullscreen'\)/) + assert.match(descriptor.template.content, //) + assert.doesNotMatch(descriptor.template.content, /\{\{ isFullscreen \? \$t\('preview.exitFullscreen'\)/) const result = await compileStyleAsync({ source: descriptor.styles[0].content, filename: 'document-preview.vue', id: 'preview', preprocessLang: 'less', }) diff --git a/frontend/src/components/document-preview.vue b/frontend/src/components/document-preview.vue index f5ccf0a4..7387f063 100644 --- a/frontend/src/components/document-preview.vue +++ b/frontend/src/components/document-preview.vue @@ -41,6 +41,8 @@ const props = defineProps<{ fileName: string; active: boolean; fillHeight?: boolean; + /** Place preview actions beside the host header's download button. */ + toolbarTarget?: HTMLElement | null; }>(); const loading = ref(false); @@ -479,23 +481,28 @@ onUnmounted(() => { +
@@ -88,6 +89,7 @@
() const { t } = useI18n() +const previewActions = ref(null) /** TDesign always follows @close with update:visible=false; swallow that when popping preview. */ let suppressDrawerClose = false @@ -453,6 +456,10 @@ onUnmounted(() => { } } +.artifact-preview-actions { + flex-shrink: 0; +} + .artifact-drawer-header-icon { flex-shrink: 0; width: 32px; diff --git a/frontend/src/views/chat/components/ChatArtifactsPanel.vue b/frontend/src/views/chat/components/ChatArtifactsPanel.vue index ae493864..48d9a481 100644 --- a/frontend/src/views/chat/components/ChatArtifactsPanel.vue +++ b/frontend/src/views/chat/components/ChatArtifactsPanel.vue @@ -30,10 +30,12 @@ +
(null) const listRef = ref(null) const previewItem = ref(null) const downloading = reactive>({}) @@ -327,6 +330,10 @@ async function handleDownload(item: SessionArtifactItem) { } } +.artifact-preview-actions { + flex-shrink: 0; +} + .artifact-panel-header-icon { width: 26px; height: 32px;