Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ onBeforeUnmount(() => fullscreen.unbind())
<MkIcon name="icon_close_outlined" size="18" />
</el-button>
</template>
<!-- 占位:嵌入脚本在 iframe 外层右上角叠加放大/还原与关闭按钮,空出这两个按钮的位置,避免遮挡下载与全屏 -->
<template v-else>
<el-button text tabindex="-1" class="invisible pointer-events-none ml-0!">
<MkIcon name="icon_magnify_outlined" size="18" />
</el-button>
<el-button text tabindex="-1" class="invisible pointer-events-none ml-0!">
<MkIcon name="icon_close_outlined" size="18" />
</el-button>
</template>
</div>
</div>
<!-- 预览区域:按文件地址重建预览组件,切换文件时旧文件的加载与绘制随组件卸载取消 -->

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my review of the added code:

Issues / Irregularities

  1. pointer-events-none with invisible is redundant and semantically confusing. invisible (visibility: hidden) already prevents pointer events, so combining both plus pointer-events-none adds noise without benefit.

  2. pointer-events-none is not a standard Tailwind utility in all setups. Tailwind uses pointer-events-none, but if this project's config deviates, it silently does nothing. Verify it exists in your Tailwind/utility-CSS build.

  3. ml-0! (important modifier) looks suspicious. In Tailwind v3 the important modifier is !ml-0; the trailing ! syntax is Tailwind v4. Mixing conventions here suggests either a misconfiguration or an accidental typo — confirm which Tailwind version this repo targets. This is the most likely bug because if the syntax is wrong, the class won't be applied at all.

  4. Non-breaking space (&nbsp;) inside the button instead of self-closing tag. Either use <el-button ... /> (if Element Plus supports it) or place the icon directly without stray whitespace to keep markup clean.

  5. tabindex="-1" is good for removing from tab order, but these are placeholder buttons — using actual <el-button> elements rather than styled <span>/<div> placeholders creates empty focusable/interactive elements that could confuse assistive technology even with aria-hidden absent. Consider adding aria-hidden="true".

  6. Hardcoded duplication. The two placeholder buttons duplicate size/class strings. If the layout ignores these frequently, extract into a small local component (<PlaceholderBtn :icon="...">) to reduce drift between the real and placeholder buttons.

  7. Comment is verbose/Chinese while the rest of the file appears English-commented (line 83 area). Consistency suggestion only.

Optimization Suggestions

  • Add aria-hidden="true" to both placeholder buttons.
  • Simplify classes to just invisible ml-0 (drop pointer-events-none unless you actually need to keep the element clickable-but-transparent for layout).
  • Replace ml-0! with the correct important syntax for your Tailwind version, or remove the important flag entirely if not needed.
  • Document why the placeholders must mirror the real buttons' size — otherwise future refactors may break alignment silently.
  • Consider rendering the placeholders only when the iframe branch (embedded script) is actually active rather than as a blanket v-else, to avoid dead DOM in normal previews.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, useTemplateRef, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useViewType } from '@/conversation-panel/view/index'
import { useRightSidebarStore } from '../../index'
import { createFullscreenToggle, createPdfRenderer } from './index'
import { downloadByURL } from '@/utils/common'

defineOptions({ name: 'DocumentPreview' })

const { t } = useI18n({ useScope: 'global' })
const viewType = useViewType()
const { knowledgeSource, closeRightSide } = useRightSidebarStore()
const { previewDocument, closePreview } = knowledgeSource
const { loading, error, render, destroy } = createPdfRenderer()
Expand Down Expand Up @@ -63,11 +65,23 @@ onBeforeUnmount(() => {
<MkIcon name="icon_window-new_outlined" size="18" />
</el-button>
</MkTooltip>
<el-divider direction="vertical" class="mx-1!" />
<!-- 关闭文档预览 -->
<el-button text @click="closeRightSide()">
<MkIcon name="icon_close_outlined" size="18" />
</el-button>
<!-- 嵌入模式下由返回按钮回到知识来源,不显示关闭 -->
<template v-if="viewType !== 'EMBED'">
<el-divider direction="vertical" class="mx-1!" />
<!-- 关闭文档预览 -->
<el-button text @click="closeRightSide()">
<MkIcon name="icon_close_outlined" size="18" />
</el-button>
</template>
<!-- 占位:嵌入脚本在 iframe 外层右上角叠加放大/还原与关闭按钮,空出这两个按钮的位置,避免遮挡下载与全屏 -->
<template v-else>
<el-button text tabindex="-1" class="invisible pointer-events-none ml-0!">
<MkIcon name="icon_magnify_outlined" size="18" />
</el-button>
<el-button text tabindex="-1" class="invisible pointer-events-none ml-0!">
<MkIcon name="icon_close_outlined" size="18" />
</el-button>
</template>
</div>
</div>
<div ref="viewerRef" class="document-preview-viewer relative min-h-0 flex-1 overflow-auto bg-white">

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff

Potential issues

  1. Placeholder hack is fragile & non-semantic
    Using two invisible / pointer-events-none buttons purely as layout spacers to reserve width for overlay buttons injected by an external embed script is brittle:

    • The external script's button sizes/styles are not guaranteed to match icon_magnify_outlined / icon_close_outlined at size="18".
    • el-button carries default padding/border/margins; even with ml-0!, spacing may drift across themes or Element Plus versions.
    • tabindex="-1" is redundant on a disabled/non-focusable element but doesn't prevent screen readers from announcing it — use aria-hidden="true" as well (or better, a plain <span>/<div> with explicit width).
  2. Magic string 'EMBED'
    Comparing viewType !== 'EMBED' against a raw literal couples this component to the enum's serialized value. Prefer importing the enum/const (e.g. ViewType.EMBED) so renaming or refactoring in @/conversation-panel/view/index fails loudly instead of silently breaking.

  3. useViewType() semantics unverified
    Confirm it returns a reactive value (ref/computed). If it returns a plain value captured once, the v-if won't update on view-type changes. Also check whether it requires being called inside a component setup with proper injection context (it's fine here, but worth confirming it doesn't rely on a provider that DocumentPreview might be rendered outside of).

  4. Reactivity via destructuring
    Existing line const { knowledgeSource, closeRightSide } = useRightSidebarStore() loses reactivity for store state if knowledgeSource is itself a ref/reactive property accessed by value; not introduced by this diff, but flag alongside the new viewType usage since both affect template reactivity.

  5. Behavior gap: no way to close in EMBED mode from this component
    Hiding the close button means the only exit is the overlay-provided one. If the embed script fails to load/inject, users are trapped. Consider keeping a fallback (e.g., render the close button if overlay isn't detected) or documenting the contract.

  6. Comment duplication / accuracy
    The new comments are helpful but assume the overlay positions buttons at the top-right of the iframe's outer frame. Verify this holds in all embed containers and locales (RTL) — in RTL the reserved order should be mirrored.

Optimization suggestions

  • Replace the spacer buttons with <span class="w-9 shrink-0" aria-hidden="true" /> (or exact computed widths), removing icon import/cost and semantic noise.
  • Extract the visibility condition into a named computed, e.g. const canCloseFromPanel = computed(() => viewType.value !== ViewType.EMBED), improving readability and testability.
  • Add a unit/e2e test asserting the close button is absent in EMBED and present otherwise.
  • Consider CSS custom property / shared constant for the reserved width so the embed script and this component stay in sync (single source of truth).
  • If useViewType is cheap, fine; if it triggers subscriptions, ensure it's cleaned up (onMounted/onBeforeUnmount already exist for other resources — verify none leak).

Minor

  • ml-0! relies on Tailwind important modifier plus Element Plus specificity; prefer a scoped class in the <style> block for robustness.
  • No irregular syntax in the diff itself; the template/script structure is valid.

Expand Down
Loading