Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

Improve Wiki reader layout and revision history UX.

wizardchen63b5f353c10b
diff --git a/frontend/src/i18n/embed.ts b/frontend/src/i18n/embed.ts
index dd9c1b881..e01c0c10e 100644
--- a/frontend/src/i18n/embed.ts
+++ b/frontend/src/i18n/embed.ts
@@ -486,6 +486,8 @@ const messages = {
"knowledgeEditor": {
"wikiBrowser": {
"viewInGraph": "在图谱中查看",
+ "editingBadge": "编辑中",
+ "pageActions": "页面操作",
"version": "v{ver}",
"filterSummary": "摘要",
"filterEntity": "实体",
@@ -980,6 +982,8 @@ const messages = {
"knowledgeEditor": {
"wikiBrowser": {
"viewInGraph": "View in Graph",
+ "editingBadge": "Editing",
+ "pageActions": "Page actions",
"version": "v{ver}",
"filterSummary": "Summaries",
"filterEntity": "Entities",
diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts
index 933312e86..472ff34dd 100755
--- a/frontend/src/i18n/locales/en-US.ts
+++ b/frontend/src/i18n/locales/en-US.ts
@@ -2194,12 +2194,30 @@ export default {
revisionDiff: 'Diff vs current',
revisionRaw: 'Raw content',
revisionDiffCaption: 'v{from} → v{to} (red = that version, green = current)',
+ revisionDiffIncremental: 'Version change',
+ revisionDiffCumulative: 'Vs current',
+ revisionDiffBasisLabel: 'Compare mode',
+ revisionViewModeLabel: 'View mode',
+ revisionLatestChangeHint: 'Changes from the previous version to current',
+ revisionIncrementalHint: 'Changes that produced v{ver}',
+ revisionInitialRange: 'Initial → v{ver}',
+ revisionInitialCreationHint: 'Initial content at creation',
+ revisionCumulativeHint: 'All changes from this version to current',
+ revisionDiffIncrementalCaption: 'v{from} → v{to} (adjacent versions; red = old, green = new)',
+ revisionDiffCumulativeCaption: 'v{from} → v{to} (cumulative changes to current)',
+ revisionFirstVersionHint: 'This is the first version — there is no previous version to compare.',
+ revisionDiffTitle: 'Title',
+ revisionDiffSummary: 'Summary',
+ revisionDiffContent: 'Body',
+ revisionDiffEmpty: 'No differences in title, summary, or body vs current',
revisionLoadFailed: 'Failed to load revision history',
revertBtn: 'Revert to this version',
revertConfirm: 'Revert to v{ver}? The current content is snapshotted first, so the revert itself can be undone.',
revertSuccess: 'Reverted to v{ver}',
revertFailed: 'Failed to revert',
viewInGraph: 'View in Graph',
+ editingBadge: 'Editing',
+ pageActions: 'Page actions',
tabDocuments: 'Documents',
tabGraph: 'Graph',
tabGraphTip: 'A graph of links between Wiki pages (page-link graph). This is NOT the same as the LLM-extracted entity-relationship Knowledge Graph configured under "KB Settings → Knowledge Graph".',
diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts
index fa2167d40..dc7dc689f 100755
--- a/frontend/src/i18n/locales/ko-KR.ts
+++ b/frontend/src/i18n/locales/ko-KR.ts
@@ -3562,12 +3562,30 @@ export default {
revisionDiff: '현재와 비교',
revisionRaw: '원문 보기',
revisionDiffCaption: 'v{from} → v{to} (빨강 = 해당 버전, 초록 = 현재)',
+ revisionDiffIncremental: '버전 변경',
+ revisionDiffCumulative: '현재와 비교',
+ revisionDiffBasisLabel: '비교 방식',
+ revisionViewModeLabel: '보기 방식',
+ revisionLatestChangeHint: '이전 버전에서 현재 버전으로의 변경',
+ revisionIncrementalHint: 'v{ver} 생성 시 변경 사항',
+ revisionInitialRange: '초기 → v{ver}',
+ revisionInitialCreationHint: '최초 생성 내용',
+ revisionCumulativeHint: '이 버전에서 현재까지의 누적 변경',
+ revisionDiffIncrementalCaption: 'v{from} → v{to} (인접 버전, 빨강=이전·초록=이후)',
+ revisionDiffCumulativeCaption: 'v{from} → v{to} (현재까지 누적 변경)',
+ revisionFirstVersionHint: '첫 번째 버전이라 이전 버전과 비교할 수 없습니다.',
+ revisionDiffTitle: '제목',
+ revisionDiffSummary: '요약',
+ revisionDiffContent: '본문',
+ revisionDiffEmpty: '제목, 요약, 본문에서 현재 버전과 차이가 없습니다',
revisionLoadFailed: '버전 기록을 불러오지 못했습니다',
revertBtn: '이 버전으로 롤백',
revertConfirm: 'v{ver}(으)로 롤백하시겠습니까? 현재 내용은 먼저 기록으로 저장됩니다.',
revertSuccess: 'v{ver}(으)로 롤백했습니다',
revertFailed: '롤백에 실패했습니다',
viewInGraph: '그래프에서 보기',
+ editingBadge: '편집 중',
+ pageActions: '페이지 작업',
tabDocuments: '문서',
tabGraph: '그래프',
tabGraphTip: 'Wiki 페이지 간의 링크 관계 그래프(페이지 링크 그래프)입니다. \'지식 베이스 설정 → 지식 그래프\'에서 구성하는 LLM 기반 엔티티-관계 지식 그래프와는 다른 개념입니다.',
diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts
index 85a7a43c5..9dbc48cda 100755
--- a/frontend/src/i18n/locales/ru-RU.ts
+++ b/frontend/src/i18n/locales/ru-RU.ts
@@ -3562,12 +3562,30 @@ export default {
revisionDiff: 'Сравнить с текущей',
revisionRaw: 'Исходный текст',
revisionDiffCaption: 'v{from} → v{to} (красный — та версия, зелёный — текущая)',
+ revisionDiffIncremental: 'Изменение версии',
+ revisionDiffCumulative: 'С текущей',
+ revisionDiffBasisLabel: 'Режим сравнения',
+ revisionViewModeLabel: 'Режим просмотра',
+ revisionLatestChangeHint: 'Изменения от предыдущей версии к текущей',
+ revisionIncrementalHint: 'Изменения, создавшие v{ver}',
+ revisionInitialRange: 'Начало → v{ver}',
+ revisionInitialCreationHint: 'Исходное содержимое при создании',
+ revisionCumulativeHint: 'Все изменения от этой версии до текущей',
+ revisionDiffIncrementalCaption: 'v{from} → v{to} (соседние версии; красный — старая, зелёный — новая)',
+ revisionDiffCumulativeCaption: 'v{from} → v{to} (накопленные изменения до текущей)',
+ revisionFirstVersionHint: 'Это первая версия — сравнивать не с чем.',
+ revisionDiffTitle: 'Заголовок',
+ revisionDiffSummary: 'Резюме',
+ revisionDiffContent: 'Содержимое',
+ revisionDiffEmpty: 'Нет различий в заголовке, резюме и содержимом с текущей версией',
revisionLoadFailed: 'Не удалось загрузить историю версий',
revertBtn: 'Откатить к этой версии',
revertConfirm: 'Откатить к v{ver}? Текущее содержимое сначала будет сохранено в историю.',
revertSuccess: 'Выполнен откат к v{ver}',
revertFailed: 'Не удалось выполнить откат',
viewInGraph: 'Открыть в графе',
+ editingBadge: 'Редактирование',
+ pageActions: 'Действия со страницей',
tabDocuments: 'Документы',
tabGraph: 'Граф',
tabGraphTip: 'Граф связей между Wiki-страницами (граф ссылок страниц). Это НЕ то же самое, что граф знаний на основе сущностей и отношений, настраиваемый в «Настройки БЗ → Граф знаний».',
diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts
index 883e2588e..cd9ea1507 100755
--- a/frontend/src/i18n/locales/zh-CN.ts
+++ b/frontend/src/i18n/locales/zh-CN.ts
@@ -3561,13 +3561,31 @@ export default {
revisionEmpty: '暂无历史版本,页面内容变化后会自动记录快照',
revisionDiff: '对比当前',
revisionRaw: '查看原文',
- revisionDiffCaption: 'v{from} → v{to}(红色为该版本内容,绿色为当前内容)',
+ revisionDiffCaption: 'v{from} → v{to}(红色为该版本,绿色为当前)',
+ revisionDiffIncremental: '版本变更',
+ revisionDiffCumulative: '对比当前',
+ revisionDiffBasisLabel: '对比方式',
+ revisionViewModeLabel: '查看方式',
+ revisionLatestChangeHint: '上一版到当前版的变更',
+ revisionIncrementalHint: '产生 v{ver} 的变更',
+ revisionInitialRange: '初始 → v{ver}',
+ revisionInitialCreationHint: '初始创建内容',
+ revisionCumulativeHint: '该版本到当前版的累计变更',
+ revisionDiffIncrementalCaption: 'v{from} → v{to}(相邻版本,红色为旧、绿色为新)',
+ revisionDiffCumulativeCaption: 'v{from} → v{to}(距当前的累计变更)',
+ revisionFirstVersionHint: '这是首个版本,没有上一版可对比。',
+ revisionDiffTitle: '标题',
+ revisionDiffSummary: '摘要',
+ revisionDiffContent: '正文',
+ revisionDiffEmpty: '此版本与当前在标题、摘要和正文上均无差异',
revisionLoadFailed: '加载版本历史失败',
revertBtn: '回滚到此版本',
revertConfirm: '确定回滚到 v{ver} 吗?当前内容会先保存为历史版本,回滚操作可再次撤销。',
revertSuccess: '已回滚到 v{ver}',
revertFailed: '回滚失败',
viewInGraph: '在图谱中查看',
+ editingBadge: '编辑中',
+ pageActions: '页面操作',
tabDocuments: '文档',
tabGraph: '图谱',
tabGraphTip: 'Wiki 页面之间的引用关系图(即页面链接图谱),与「知识库设置 → 知识图谱」中基于 LLM 抽取的实体-关系图谱不是同一个概念',
diff --git a/frontend/src/utils/wikiLineDiff.test.ts b/frontend/src/utils/wikiLineDiff.test.ts
index 82f8fae83..bbf70ec87 100644
--- a/frontend/src/utils/wikiLineDiff.test.ts
+++ b/frontend/src/utils/wikiLineDiff.test.ts
@@ -27,8 +27,7 @@ test('pure insertion and pure deletion', () => {
test('empty sides', () => {
assert.equal(diffWikiLines('', 'x\ny').filter((l) => l.type === 'add').length, 2)
assert.equal(diffWikiLines('x\ny', '').filter((l) => l.type === 'del').length, 2)
- // '' splits into one empty line on each side → one same row.
- assert.deepEqual(diffWikiLines('', ''), [{ type: 'same', text: '' }])
+ assert.deepEqual(diffWikiLines('', ''), [])
})
test('unchanged prefix/suffix stay in order around a block edit', () => {
diff --git a/frontend/src/utils/wikiLineDiff.ts b/frontend/src/utils/wikiLineDiff.ts
index a191e84fe..8bed15b10 100644
--- a/frontend/src/utils/wikiLineDiff.ts
+++ b/frontend/src/utils/wikiLineDiff.ts
@@ -18,8 +18,8 @@ const LCS_LINE_LIMIT = 1500
// detected first so typical wiki edits (one section changed) stay cheap even
// on long pages.
export function diffWikiLines(oldText: string, newText: string): WikiDiffLine[] {
- const oldLines = oldText.split('\n')
- const newLines = newText.split('\n')
+ const oldLines = oldText ? oldText.split('\n') : []
+ const newLines = newText ? newText.split('\n') : []
// Trim common prefix.
let start = 0
diff --git a/frontend/src/utils/wikiRevisionDiff.test.ts b/frontend/src/utils/wikiRevisionDiff.test.ts
new file mode 100644
index 000000000..23b9cfefc
--- /dev/null
+++ b/frontend/src/utils/wikiRevisionDiff.test.ts
@@ -0,0 +1,56 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+
+import { diffWikiRevision } from './wikiRevisionDiff.ts'
+
+test('title-only edits produce a title section', () => {
+ const sections = diffWikiRevision(
+ { title: 'Old', summary: 'same', content: 'body' },
+ { title: 'New', summary: 'same', content: 'body' },
+ )
+ assert.equal(sections.length, 1)
+ assert.equal(sections[0].field, 'title')
+ assert.ok(sections[0].lines.some((line) => line.type === 'del'))
+ assert.ok(sections[0].lines.some((line) => line.type === 'add'))
+})
+
+test('summary-only edits produce a summary section', () => {
+ const sections = diffWikiRevision(
+ { title: 'same', summary: 'old summary', content: 'body' },
+ { title: 'same', summary: 'new summary', content: 'body' },
+ )
+ assert.equal(sections.length, 1)
+ assert.equal(sections[0].field, 'summary')
+})
+
+test('content edits still produce a content section', () => {
+ const sections = diffWikiRevision(
+ { title: 'same', summary: 'same', content: 'old body' },
+ { title: 'same', summary: 'same', content: 'new body' },
+ )
+ assert.equal(sections.length, 1)
+ assert.equal(sections[0].field, 'content')
+})
+
+test('mixed field edits preserve section order', () => {
+ const sections = diffWikiRevision(
+ { title: 'A', summary: 's1', content: 'c1' },
+ { title: 'B', summary: 's2', content: 'c2' },
+ )
+ assert.deepEqual(
+ sections.map((section) => section.field),
+ ['title', 'summary', 'content'],
+ )
+})
+
+test('first version diffs from empty baseline', () => {
+ const sections = diffWikiRevision(
+ { title: '', summary: '', content: '' },
+ { title: 'Page', summary: 'Intro', content: 'Body' },
+ )
+ assert.deepEqual(
+ sections.map((section) => section.field),
+ ['title', 'summary', 'content'],
+ )
+ assert.ok(sections.every((section) => section.lines.every((line) => line.type === 'add')))
+})
diff --git a/frontend/src/utils/wikiRevisionDiff.ts b/frontend/src/utils/wikiRevisionDiff.ts
new file mode 100644
index 000000000..7fd726874
--- /dev/null
+++ b/frontend/src/utils/wikiRevisionDiff.ts
@@ -0,0 +1,43 @@
+import { diffWikiLines, type WikiDiffLine } from './wikiLineDiff'
+
+export type WikiRevisionDiffField = 'title' | 'summary' | 'content'
+
+export interface WikiRevisionDiffSection {
+ field: WikiRevisionDiffField
+ lines: WikiDiffLine[]
+}
+
+export interface WikiRevisionSnapshot {
+ title: string
+ summary: string
+ content: string
+}
+
+function hasChanges(lines: WikiDiffLine[]): boolean {
+ return lines.some((line) => line.type !== 'same')
+}
+
+/** Compare a stored revision against the current page across title, summary, and body. */
+export function diffWikiRevision(
+ oldSnap: WikiRevisionSnapshot,
+ newSnap: WikiRevisionSnapshot,
+): WikiRevisionDiffSection[] {
+ const sections: WikiRevisionDiffSection[] = []
+
+ const titleLines = diffWikiLines(oldSnap.title, newSnap.title)
+ if (hasChanges(titleLines)) {
+ sections.push({ field: 'title', lines: titleLines })
+ }
+
+ const summaryLines = diffWikiLines(oldSnap.summary, newSnap.summary)
+ if (hasChanges(summaryLines)) {
+ sections.push({ field: 'summary', lines: summaryLines })
+ }
+
+ const contentLines = diffWikiLines(oldSnap.content, newSnap.content)
+ if (hasChanges(contentLines)) {
+ sections.push({ field: 'content', lines: contentLines })
+ }
+
+ return sections
+}
diff --git a/frontend/src/views/knowledge/wiki/WikiBrowser.vue b/frontend/src/views/knowledge/wiki/WikiBrowser.vue
index 42d6158b5..5803c8aa2 100644
--- a/frontend/src/views/knowledge/wiki/WikiBrowser.vue
+++ b/frontend/src/views/knowledge/wiki/WikiBrowser.vue
@@ -396,140 +396,167 @@
<!-- Page header -->
<div class="wiki-reader-header">
<div class="wiki-reader-title-row">
- <h2 class="wiki-reader-title">
- <span class="wiki-reader-title-text">{{ selectedPage.title }}</span>
-
- <t-popup v-if="pageIssues.length > 0" v-model="showIssuesBox" placement="bottom-left" trigger="click"
- :overlayInnerStyle="{ padding: 0, boxShadow: 'var(--td-shadow-3)', borderRadius: '8px', width: '560px', maxWidth: '90vw' }">
- <span class="wiki-issue-trigger"
- :title="$t('knowledgeEditor.wikiBrowser.issueTitle', { count: pageIssues.length })">
- <t-icon name="error-circle-filled" style="color: var(--td-warning-color);" />
- </span>
-
- <template #content>
- <div class="wiki-issue-popup-content">
- <div class="wiki-issue-popup-header">
- <div class="wiki-issue-popup-title">
- <span>{{ $t('knowledgeEditor.wikiBrowser.issueFixSuggestions', { count: pageIssues.length })
- }}</span>
- </div>
- <t-button v-if="props.canEdit" size="small" theme="primary" variant="base"
- @click="triggerAutoFix">
- <template #icon><t-icon name="tools" /></template>
- {{ $t('knowledgeEditor.wikiBrowser.issueFixBtn') }}
- </t-button>
- </div>
- <div class="wiki-issue-popup-list">
- <div v-for="issue in pageIssues" :key="issue.id" class="wiki-issue-popup-item">
- <div class="wiki-issue-popup-main">
- <div class="wiki-issue-popup-tags">
- <t-tag v-if="issue.issue_type === 'mixed_entities'" theme="warning" variant="light"
- size="small">{{
- $t('knowledgeEditor.wikiBrowser.issueMixed') }}</t-tag>
- <t-tag v-else-if="issue.issue_type === 'contradictory_facts'" theme="danger"
- variant="light" size="small">{{
- $t('knowledgeEditor.wikiBrowser.issueConflict') }}</t-tag>
- <t-tag v-else-if="issue.issue_type === 'out_of_date'" theme="default" variant="light"
- size="small">{{
- $t('knowledgeEditor.wikiBrowser.issueOutdated') }}</t-tag>
- <t-tag v-else theme="primary" variant="light" size="small">{{
- $t('knowledgeEditor.wikiBrowser.issueAttention') }}</t-tag>
+ <div class="wiki-reader-title-block">
+ <h2 v-if="!editingPage" class="wiki-reader-title">
+ <span class="wiki-reader-title-text">{{ selectedPage.title }}</span>
+
+ <t-popup v-if="pageIssues.length > 0" v-model="showIssuesBox" placement="bottom-left"
+ trigger="click"
+ :overlayInnerStyle="{ padding: 0, boxShadow: 'var(--td-shadow-3)', borderRadius: '8px', width: '560px', maxWidth: '90vw' }">
+ <span class="wiki-issue-trigger"
+ :title="$t('knowledgeEditor.wikiBrowser.issueTitle', { count: pageIssues.length })">
+ <t-icon name="error-circle-filled" style="color: var(--td-warning-color);" />
+ </span>
+
+ <template #content>
+ <div class="wiki-issue-popup-content">
+ <div class="wiki-issue-popup-header">
+ <div class="wiki-issue-popup-title">
+ <span>{{ $t('knowledgeEditor.wikiBrowser.issueFixSuggestions', {
+ count:
+ pageIssues.length
+ })
+ }}</span>
</div>
- <div class="wiki-issue-popup-desc">
- {{ issue.description }}
- </div>
- <div class="wiki-issue-popup-meta">
- <span class="wiki-issue-popup-reporter">
- {{ issue.reported_by === 'wiki-researcher-agent' ?
- $t('knowledgeEditor.wikiBrowser.issueAiLinter') :
- $t('knowledgeEditor.wikiBrowser.issueReportedBy', { reporter: issue.reported_by }) }}
- </span>
- <div v-if="props.canEdit" class="wiki-issue-popup-actions">
- <span class="wiki-issue-popup-action" @click="triggerFixIssue(issue)"
- style="margin-right: 12px; font-weight: 500;">
- <t-icon name="tools" style="margin-right: 4px;" />{{
- $t('knowledgeEditor.wikiBrowser.issueFixSingle') }}
- </span>
- <span class="wiki-issue-popup-action" style="color: var(--td-text-color-placeholder);"
- @click="handleIssueIgnore(issue.id)">{{
- $t('knowledgeEditor.wikiBrowser.issueIgnore') }}</span>
+ <t-button v-if="props.canEdit" size="small" theme="primary" variant="base"
+ @click="triggerAutoFix">
+ <template #icon><t-icon name="tools" /></template>
+ {{ $t('knowledgeEditor.wikiBrowser.issueFixBtn') }}
+ </t-button>
+ </div>
+ <div class="wiki-issue-popup-list">
+ <div v-for="issue in pageIssues" :key="issue.id" class="wiki-issue-popup-item">
+ <div class="wiki-issue-popup-main">
+ <div class="wiki-issue-popup-tags">
+ <t-tag v-if="issue.issue_type === 'mixed_entities'" theme="warning" variant="light"
+ size="small">{{
+ $t('knowledgeEditor.wikiBrowser.issueMixed') }}</t-tag>
+ <t-tag v-else-if="issue.issue_type === 'contradictory_facts'" theme="danger"
+ variant="light" size="small">{{
+ $t('knowledgeEditor.wikiBrowser.issueConflict') }}</t-tag>
+ <t-tag v-else-if="issue.issue_type === 'out_of_date'" theme="default" variant="light"
+ size="small">{{
+ $t('knowledgeEditor.wikiBrowser.issueOutdated') }}</t-tag>
+ <t-tag v-else theme="primary" variant="light" size="small">{{
+ $t('knowledgeEditor.wikiBrowser.issueAttention') }}</t-tag>
+ </div>
+ <div class="wiki-issue-popup-desc">
+ {{ issue.description }}
+ </div>
+ <div class="wiki-issue-popup-meta">
+ <span class="wiki-issue-popup-reporter">
+ {{ issue.reported_by === 'wiki-researcher-agent' ?
+ $t('knowledgeEditor.wikiBrowser.issueAiLinter') :
+ $t('knowledgeEditor.wikiBrowser.issueReportedBy', {
+ reporter:
+ issue.reported_by
+ }) }}
+ </span>
+ <div v-if="props.canEdit" class="wiki-issue-popup-actions">
+ <span class="wiki-issue-popup-action" @click="triggerFixIssue(issue)"
+ style="margin-right: 12px; font-weight: 500;">
+ <t-icon name="tools" style="margin-right: 4px;" />{{
+ $t('knowledgeEditor.wikiBrowser.issueFixSingle') }}
+ </span>
+ <span class="wiki-issue-popup-action"
+ style="color: var(--td-text-color-placeholder);"
+ @click="handleIssueIgnore(issue.id)">{{
+ $t('knowledgeEditor.wikiBrowser.issueIgnore') }}</span>
+ </div>
+ </div>
</div>
</div>
</div>
</div>
- </div>
- </div>
- </template>
- </t-popup>
- </h2>
- <div class="wiki-reader-header-actions">
- <t-tooltip :content="$t('knowledgeEditor.wikiBrowser.historyBtn')" placement="top">
- <button type="button" class="wiki-reader-action-btn"
- :aria-label="$t('knowledgeEditor.wikiBrowser.historyBtn')" @click="openRevisionDrawer">
- <t-icon name="history" />
- </button>
- </t-tooltip>
- <t-tooltip v-if="props.canEdit && !editingPage"
- :content="$t('knowledgeEditor.wikiBrowser.editBtn')" placement="top">
- <button type="button" class="wiki-reader-action-btn"
- :aria-label="$t('knowledgeEditor.wikiBrowser.editBtn')" @click="startEditPage">
- <t-icon name="edit" />
- </button>
- </t-tooltip>
- <t-popconfirm v-if="props.canEdit" theme="danger"
- :content="$t('knowledgeEditor.wikiBrowser.deletePageConfirm', { title: selectedPage.title })"
- @confirm="confirmDeletePage">
- <t-tooltip :content="$t('knowledgeEditor.wikiBrowser.deletePageBtn')" placement="top">
- <button type="button" class="wiki-reader-action-btn wiki-reader-action-btn--danger"
- :aria-label="$t('knowledgeEditor.wikiBrowser.deletePageBtn')">
- <t-icon name="delete" />
- </button>
+ </template>
+ </t-popup>
+ </h2>
+ <t-input v-else v-model="editForm.title" class="wiki-edit-field wiki-edit-field--title"
+ :placeholder="$t('knowledgeEditor.wikiBrowser.editTitlePlaceholder')" />
+ <div class="wiki-reader-title-badges wiki-reader-title-badges--secondary">
+ <span v-if="editingPage" class="wiki-badge wiki-badge--editing">
+ {{ $t('knowledgeEditor.wikiBrowser.editingBadge') }}
+ </span>
+ <span class="wiki-badge wiki-badge--type">
+ <t-icon :name="getPageIcon(selectedPage)" />
+ {{ getTypeLabel(selectedPage.page_type) }}
+ </span>
+ <span class="wiki-badge wiki-badge--ver">
+ {{ $t('knowledgeEditor.wikiBrowser.version', { ver: selectedPage.version }) }}
+ </span>
+ <t-tooltip v-if="editSourceVisible(selectedPage.last_edit_source)"
+ :content="editSourceLabel(selectedPage.last_edit_source)">
+ <span class="wiki-badge wiki-badge--source">
+ <t-icon :name="editSourceIcon(selectedPage.last_edit_source)" />
+ {{ editSourceLabel(selectedPage.last_edit_source) }}
+ </span>
</t-tooltip>
- </t-popconfirm>
+ <span v-for="alias in (selectedPage.aliases || [])" :key="alias"
+ class="wiki-badge wiki-badge--alias"
+ :title="`${$t('knowledgeEditor.wikiBrowser.aliases')} ${alias}`">
+ <t-icon name="link" />
+ {{ alias }}
+ </span>
+ </div>
+ <p v-if="!editingPage && selectedPage.summary" class="wiki-reader-lead">{{ selectedPage.summary }}</p>
+ <t-textarea v-if="editingPage" v-model="editForm.summary"
+ class="wiki-edit-field wiki-edit-field--summary" :autosize="{ minRows: 2, maxRows: 4 }"
+ :placeholder="$t('knowledgeEditor.wikiBrowser.editSummaryPlaceholder')" />
+ </div>
+ <div class="wiki-reader-aside">
+ <div class="wiki-reader-actions" role="toolbar"
+ :aria-label="$t('knowledgeEditor.wikiBrowser.pageActions')">
+ <template v-if="editingPage">
+ <t-button theme="primary" size="small" :loading="savingPage" @click="savePageEdit()">
+ {{ $t('common.save') }}
+ </t-button>
+ <t-button variant="text" size="small" :disabled="savingPage" @click="cancelEditPage">
+ {{ $t('common.cancel') }}
+ </t-button>
+ </template>
+ <template v-else>
+ <t-tooltip v-if="props.canEdit" :content="$t('knowledgeEditor.wikiBrowser.editBtn')"
+ placement="top">
+ <button type="button" class="wiki-action-btn"
+ :aria-label="$t('knowledgeEditor.wikiBrowser.editBtn')" @click="startEditPage">
+ <t-icon name="edit" />
+ </button>
+ </t-tooltip>
+ <t-tooltip :content="$t('knowledgeEditor.wikiBrowser.historyBtn')" placement="top">
+ <button type="button" class="wiki-action-btn"
+ :aria-label="$t('knowledgeEditor.wikiBrowser.historyBtn')" @click="openRevisionDrawer">
+ <t-icon name="history" />
+ </button>
+ </t-tooltip>
+ <t-tooltip :content="$t('knowledgeEditor.wikiBrowser.viewInGraph')" placement="top">
+ <button type="button" class="wiki-action-btn"
+ :aria-label="$t('knowledgeEditor.wikiBrowser.viewInGraph')"
+ @click="emit('view-graph', selectedPage.slug)">
+ <t-icon name="chart-bubble" />
+ </button>
+ </t-tooltip>
+ <t-popconfirm v-if="props.canEdit" theme="danger"
+ :content="$t('knowledgeEditor.wikiBrowser.deletePageConfirm', { title: selectedPage.title })"
+ @confirm="confirmDeletePage">
+ <t-tooltip :content="$t('knowledgeEditor.wikiBrowser.deletePageBtn')" placement="top">
+ <button type="button" class="wiki-action-btn wiki-action-btn--danger"
+ :aria-label="$t('knowledgeEditor.wikiBrowser.deletePageBtn')">
+ <t-icon name="delete" />
+ </button>
+ </t-tooltip>
+ </t-popconfirm>
+ </template>
+ </div>
+ <div v-if="!editingPage" class="wiki-reader-aside-meta">
+ <span class="wiki-reader-aside-meta-item">
+ <t-icon name="time" size="14px" />
+ {{ formatDate(selectedPage.updated_at) }}
+ </span>
+ </div>
</div>
- </div>
- <div v-if="selectedPage.aliases && selectedPage.aliases.length" class="wiki-reader-aliases">
- <span class="wiki-alias-label">{{ $t('knowledgeEditor.wikiBrowser.aliases') }}:</span>
- <t-tag v-for="alias in selectedPage.aliases" :key="alias" size="small" variant="light"
- class="wiki-alias-tag">
- {{ alias }}
- </t-tag>
- </div>
- <div class="wiki-reader-meta">
- <t-tag size="small" :theme="getTypeTheme(selectedPage.page_type)" variant="light-outline">
- {{ getTypeLabel(selectedPage.page_type) }}
- </t-tag>
- <span class="wiki-reader-meta-text">{{ $t('knowledgeEditor.wikiBrowser.version', {
- ver:
- selectedPage.version
- })
- }}</span>
- <!-- Provenance of the current version; only surfaced when a
- human / agent / revert touched it — pipeline is the
- default and would just be noise. -->
- <t-tag v-if="editSourceVisible(selectedPage.last_edit_source)" size="small"
- :theme="editSourceTheme(selectedPage.last_edit_source)" variant="light">
- {{ editSourceLabel(selectedPage.last_edit_source) }}
- </t-tag>
- <span class="wiki-reader-meta-text">{{ formatDate(selectedPage.updated_at) }}</span>
- <t-link theme="primary" hover="color" class="wiki-reader-graph-link"
- @click="emit('view-graph', selectedPage.slug)">
- <template #prefixIcon><t-icon name="chart-bubble" /></template>
- {{ $t('knowledgeEditor.wikiBrowser.viewInGraph') }}
- </t-link>
</div>
</div>
- <!-- Backlinks (in_links) -->
- <div v-if="selectedPage.in_links?.length" class="wiki-reader-backlinks">
- <span class="wiki-backlink-label">
- <t-icon name="link" size="14px" />
- {{ $t('knowledgeEditor.wikiBrowser.linkedFrom') }}
- </span>
- <a v-for="link in selectedPage.in_links" :key="'in-' + link" href="#" class="wiki-backlink-tag"
- @click.prevent="navigateToSlug(link)">{{ slugDisplayName(link) }}</a>
- </div>
-
<!-- Content -->
<div v-if="!editingPage" ref="readerBodyRef" class="wiki-reader-body" v-html="renderedContent"
@click="handleContentClick">
@@ -539,12 +566,7 @@
the page version captured at edit start; the backend answers
409 when someone (or the pipeline) edited in between. -->
<div v-else class="wiki-page-editor">
- <t-input v-model="editForm.title" class="wiki-page-editor-title"
- :placeholder="$t('knowledgeEditor.wikiBrowser.editTitlePlaceholder')" />
- <t-textarea v-model="editForm.summary" class="wiki-page-editor-summary"
- :autosize="{ minRows: 2, maxRows: 4 }"
- :placeholder="$t('knowledgeEditor.wikiBrowser.editSummaryPlaceholder')" />
- <t-textarea v-model="editForm.content" class="wiki-page-editor-content"
+ <t-textarea v-model="editForm.content" class="wiki-edit-field wiki-edit-field--content"
:autosize="{ minRows: 16, maxRows: 40 }"
:placeholder="$t('knowledgeEditor.wikiBrowser.editContentPlaceholder')" />
<t-alert v-if="editConflictVersion !== null" theme="warning" class="wiki-page-editor-conflict"
@@ -560,25 +582,30 @@
</span>
</template>
</t-alert>
- <div class="wiki-page-editor-footer">
- <t-button theme="primary" :loading="savingPage" @click="savePageEdit()">
- {{ $t('common.save') }}
- </t-button>
- <t-button variant="outline" :disabled="savingPage" @click="cancelEditPage">
- {{ $t('common.cancel') }}
- </t-button>
- </div>
</div>
- <!-- Source refs -->
- <div v-if="parsedSourceRefs.length" class="wiki-reader-sources">
- <span class="wiki-link-label">{{ $t('knowledgeEditor.wikiBrowser.sources') }}</span>
- <a v-for="ref in parsedSourceRefs" :key="ref.id" href="#" class="wiki-source-ref"
- @click.prevent="emit('open-source-doc', ref.id)">
- <t-icon name="file" size="14px" />
- {{ ref.title }}
- </a>
- </div>
+ <!-- Page footer: backlinks + sources -->
+ <footer v-if="!editingPage && (selectedPage.in_links?.length || parsedSourceRefs.length)"
+ class="wiki-reader-footer">
+ <div v-if="selectedPage.in_links?.length" class="wiki-reader-footer-row">
+ <span class="wiki-reader-footer-label">{{ $t('knowledgeEditor.wikiBrowser.linkedFrom') }}</span>
+ <span class="wiki-reader-footer-value">
+ <a v-for="link in selectedPage.in_links" :key="'in-' + link" href="#"
+ class="wiki-content-link" @click.prevent="navigateToSlug(link)">
+ {{ slugDisplayName(link) }}
+ </a>
+ </span>
+ </div>
+ <div v-if="parsedSourceRefs.length" class="wiki-reader-footer-row">
+ <span class="wiki-reader-footer-label">{{ $t('knowledgeEditor.wikiBrowser.sources') }}</span>
+ <span class="wiki-reader-footer-value">
+ <a v-for="ref in parsedSourceRefs" :key="ref.id" href="#" class="wiki-content-link"
+ @click.prevent="emit('open-source-doc', ref.id)">
+ {{ ref.title }}
+ </a>
+ </span>
+ </div>
+ </footer>
</template>
<!-- System view: index overview rendered as markdown. Starts
@@ -1956,9 +1983,26 @@ function getPageIcon(page: WikiPage): string {
const renderedContent = computed(() => {
if (!selectedPage.value) return ''
- return renderMarkdown(selectedPage.value.content)
+ const body = stripDuplicateLeadingTitle(selectedPage.value.content || '', selectedPage.value.title)
+ return renderMarkdown(body)
})
+function stripDuplicateLeadingTitle(content: string, title: string): string {
+ if (!content || !title) return content
+ const lines = content.split('\n')
+ let i = 0
+ while (i < lines.length && lines[i].trim() === '') i++
+ if (i >= lines.length) return content
+ const headingMatch = lines[i].match(/^#\s+(.+?)\s*$/)
+ if (!headingMatch) return content
+ const heading = headingMatch[1].trim()
+ const pageTitle = title.trim()
+ if (heading !== pageTitle && heading.toLowerCase() !== pageTitle.toLowerCase()) return content
+ i++
+ while (i < lines.length && lines[i].trim() === '') i++
+ return lines.slice(i).join('\n')
+}
+
// Label shown next to the back arrow on page headers. Prefers the
// nearest page-history entry when available so the user sees where
// they'll land; falls back to the Index label when the current
@@ -3043,6 +3087,19 @@ function editSourceLabel(source?: string): string {
}
}
+function editSourceIcon(source?: string): string {
+ switch (source) {
+ case 'user':
+ return 'user'
+ case 'agent':
+ return 'tools'
+ case 'revert':
+ return 'rollback'
+ default:
+ return 'file-code'
+ }
+}
+
function editSourceTheme(source?: string): 'primary' | 'success' | 'warning' | 'default' {
switch (source) {
case 'user':
@@ -5367,7 +5424,85 @@ onUnmounted(() => {
}
.wiki-reader-header {
- margin-bottom: 12px;
+ margin-bottom: 24px;
+}
+
+.wiki-reader-lead {
+ margin: 10px 0 0;
+ font-size: 15px;
+ line-height: 1.65;
+ color: var(--td-text-color-secondary);
+}
+
+.wiki-reader-title-block {
+ flex: 1;
+ min-width: 0;
+}
+
+.wiki-reader-aside {
+ flex-shrink: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ gap: 8px;
+}
+
+.wiki-reader-aside-meta {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-end;
+ gap: 4px;
+ max-width: 220px;
+}
+
+.wiki-reader-aside-meta-item {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 12px;
+ line-height: 1.4;
+ color: var(--td-text-color-placeholder);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.wiki-badge {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ padding: 2px 8px;
+ border-radius: 4px;
+ font-size: 12px;
+ line-height: 1.4;
+ color: var(--td-text-color-secondary);
+ background: var(--td-bg-color-secondarycontainer);
+
+ .t-icon {
+ font-size: 13px;
+ flex-shrink: 0;
+ }
+}
+
+.wiki-badge--ver {
+ font-family: var(--td-font-family-mono, monospace);
+ font-variant-numeric: tabular-nums;
+}
+
+.wiki-badge--editing {
+ color: var(--td-warning-color);
+ background: var(--td-warning-color-1);
+}
+
+.wiki-badge--source {
+ cursor: default;
+}
+
+.wiki-badge--alias {
+ max-width: 240px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
}
.wiki-nav-bar {
@@ -5396,8 +5531,7 @@ onUnmounted(() => {
display: flex;
align-items: flex-start;
justify-content: space-between;
- gap: 12px;
- margin-bottom: 12px;
+ gap: 20px;
}
.wiki-reader-title {
@@ -5406,7 +5540,6 @@ onUnmounted(() => {
font-weight: 600;
line-height: 1.3;
color: var(--td-text-color-primary);
- flex: 1;
min-width: 0;
display: flex;
align-items: center;
@@ -5417,41 +5550,101 @@ onUnmounted(() => {
min-width: 0;
}
-.wiki-reader-header-actions {
+.wiki-reader-title-badges {
+ display: inline-flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 6px;
+ flex-shrink: 0;
+}
+
+.wiki-reader-title-badges--secondary {
+ margin-top: 8px;
+}
+
+.wiki-edit-field {
+ width: 100%;
+
+ :deep(.t-input),
+ :deep(.t-textarea) {
+ border-radius: 8px;
+ background: var(--td-bg-color-container);
+ transition: border-color 0.15s ease, box-shadow 0.15s ease;
+ }
+
+ :deep(.t-input:focus-within),
+ :deep(.t-textarea:focus-within) {
+ border-color: var(--td-brand-color);
+ box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
+ }
+}
+
+.wiki-edit-field--title {
+ width: 100%;
+
+ :deep(.t-input__inner) {
+ font-size: 22px;
+ font-weight: 600;
+ line-height: 1.35;
+ padding: 10px 12px;
+ height: auto;
+ min-height: 44px;
+ }
+}
+
+.wiki-edit-field--summary {
+ margin: 10px 0 0;
+
+ :deep(.t-textarea__inner) {
+ font-size: 14px;
+ line-height: 1.6;
+ padding: 10px 12px;
+ resize: vertical;
+ }
+}
+
+.wiki-edit-field--content {
+ :deep(.t-textarea__inner) {
+ font-family: var(--td-font-family-mono, monospace);
+ font-size: 14px;
+ line-height: 1.7;
+ padding: 12px 14px;
+ resize: vertical;
+ }
+}
+
+.wiki-reader-actions {
display: flex;
align-items: center;
- gap: 4px;
+ gap: 2px;
flex-shrink: 0;
- margin-top: 2px;
}
-.wiki-reader-action-btn {
+.wiki-action-btn {
width: 32px;
height: 32px;
padding: 0;
border: 0;
border-radius: 6px;
background: transparent;
- color: var(--td-text-color-secondary);
+ color: var(--td-text-color-placeholder);
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
cursor: pointer;
- transition: background-color 0.15s ease, color 0.15s ease;
+ transition: color 0.15s ease;
.t-icon {
font-size: 16px;
}
&:hover {
- color: var(--td-brand-color);
- background: var(--td-bg-color-container-hover);
+ color: var(--td-text-color-primary);
}
- &.wiki-reader-action-btn--danger:hover {
+ &.wiki-action-btn--danger:hover {
color: var(--td-error-color);
- background: var(--td-error-color-1);
}
}
@@ -5460,7 +5653,7 @@ onUnmounted(() => {
align-items: center;
flex-wrap: wrap;
gap: 6px 8px;
- margin: 0 0 10px;
+ margin: 0 0 8px;
font-size: 13px;
line-height: 1.4;
}
@@ -5479,8 +5672,9 @@ onUnmounted(() => {
.wiki-reader-meta {
display: flex;
align-items: center;
- gap: 12px;
+ gap: 10px;
flex-wrap: wrap;
+ min-width: 0;
}
.wiki-reader-meta-text {
@@ -5488,41 +5682,11 @@ onUnmounted(() => {
color: var(--td-text-color-placeholder);
}
-.wiki-reader-graph-link {
- margin-left: auto;
- font-size: 13px;
-}
-
.wiki-page-editor {
display: flex;
flex-direction: column;
gap: 12px;
- margin-top: 8px;
- padding: 16px;
- background: var(--td-bg-color-container);
- border: 1px solid var(--td-component-stroke);
- border-radius: 8px;
-
- .wiki-page-editor-title :deep(.t-input__inner) {
- font-size: 18px;
- font-weight: 600;
- background: transparent;
- }
-
- .wiki-page-editor-title :deep(.t-input) {
- background: transparent;
- }
-
- .wiki-page-editor-summary :deep(textarea) {
- font-size: 13px;
- line-height: 1.6;
- }
-
- .wiki-page-editor-content :deep(textarea) {
- font-family: var(--td-font-family-mono, monospace);
- font-size: 13px;
- line-height: 1.7;
- }
+ margin-top: 16px;
}
.wiki-page-editor-conflict {
@@ -5535,12 +5699,6 @@ onUnmounted(() => {
gap: 12px;
}
-.wiki-page-editor-footer {
- display: flex;
- gap: 8px;
- padding-top: 4px;
-}
-
.wiki-create-page-form {
display: flex;
flex-direction: column;
@@ -5783,69 +5941,48 @@ onUnmounted(() => {
}
}
-.wiki-reader-backlinks {
+.wiki-reader-footer {
+ margin-top: 32px;
+ padding-top: 18px;
+ border-top: 1px solid var(--td-component-stroke);
display: flex;
- align-items: center;
- flex-wrap: wrap;
- gap: 8px;
- padding-bottom: 16px;
- border-bottom: 1px solid var(--td-component-stroke);
- margin-bottom: 24px;
+ flex-direction: column;
+ gap: 10px;
}
-.wiki-backlink-label {
- display: inline-flex;
- align-items: center;
- gap: 4px;
+.wiki-reader-footer-row {
+ display: flex;
+ align-items: baseline;
+ gap: 16px;
font-size: 13px;
- color: var(--td-text-color-placeholder);
- font-weight: 500;
- flex-shrink: 0;
- margin-right: 4px;
+ line-height: 1.65;
}
-.wiki-backlink-tag {
- color: var(--td-text-color-secondary);
- text-decoration: none;
- font-size: 13px;
- padding: 2px 8px;
- background: var(--td-bg-color-secondarycontainer);
- border-radius: 4px;
- transition: all 0.15s;
-
- &:hover {
- color: var(--td-brand-color);
- background: var(--td-brand-color-light);
- }
+.wiki-reader-footer-label {
+ flex: 0 0 64px;
+ font-size: 12px;
+ color: var(--td-text-color-placeholder);
}
-.wiki-reader-sources {
- margin-top: 24px;
- padding-top: 16px;
- border-top: 1px solid var(--td-component-stroke);
+.wiki-reader-footer-value {
+ min-width: 0;
+ flex: 1;
display: flex;
- align-items: center;
flex-wrap: wrap;
- gap: 6px;
- font-size: 13px;
+ align-items: center;
+ gap: 8px 20px;
}
-.wiki-source-ref {
- display: inline-flex;
- align-items: center;
- gap: 4px;
- padding: 2px 10px;
- background: var(--td-bg-color-secondarycontainer);
- border-radius: 4px;
- color: var(--td-text-color-secondary);
- font-size: 12px;
+.wiki-reader-footer .wiki-content-link {
+ color: var(--td-brand-color);
text-decoration: none;
+ border-bottom: 1px dashed var(--td-brand-color);
cursor: pointer;
- transition: color 0.15s, background 0.15s;
+ font-weight: 500;
&:hover {
- color: var(--td-brand-color);
- background: var(--td-bg-color-container-hover);
+ border-bottom-style: solid;
+ text-decoration: none !important;
}
}
diff --git a/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue b/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue
index 15ad30f55..c5bc3908e 100644
--- a/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue
+++ b/frontend/src/views/knowledge/wiki/WikiRevisionDrawer.vue
@@ -1,7 +1,7 @@
<template>
- <t-drawer :visible="visible" size="760px" :footer="false" class="wiki-revision-drawer"
- :header="t('knowledgeEditor.wikiBrowser.historyTitle', { title: currentPage?.title || slug })"
- @update:visible="(v: boolean) => emit('update:visible', v)">
+ <SettingDrawer v-model:visible="drawerVisible" class="wiki-revision-drawer" :title="drawerTitle" icon="history"
+ width="760px" :min-width="560" :max-width="1280" storage-key="setting-drawer:width:wiki-revision-history"
+ hide-footer>
<div class="wiki-rev-layout">
<!-- Version list -->
<aside class="wiki-rev-list">
@@ -43,31 +43,25 @@
<!-- Detail pane -->
<div class="wiki-rev-detail">
- <template v-if="selectedVersion !== null && currentPage && selectedVersion === currentPage.version">
- <div class="wiki-rev-detail-hint">{{ t('knowledgeEditor.wikiBrowser.revisionCurrentHint') }}</div>
- </template>
-
- <template v-else-if="selectedRevision">
- <div class="wiki-rev-detail-toolbar">
- <div class="wiki-rev-detail-title">
- <span class="wiki-rev-detail-version">v{{ selectedRevision.version }}</span>
- <span class="wiki-rev-detail-name">{{ selectedRevision.title }}</span>
+ <template v-if="selectedVersion !== null && canShowDiff">
+ <div class="wiki-rev-detail-head">
+ <div class="wiki-rev-detail-context">
+ <div class="wiki-rev-detail-range">{{ versionRangeLabel }}</div>
+ <div v-if="contextHint" class="wiki-rev-detail-sub">{{ contextHint }}</div>
</div>
- <div class="wiki-rev-detail-actions">
- <div class="wiki-rev-mode-toggle" role="group">
- <button type="button" class="wiki-rev-mode-btn"
- :class="{ active: detailMode === 'diff' }" @click="detailMode = 'diff'">
- {{ t('knowledgeEditor.wikiBrowser.revisionDiff') }}
- </button>
- <button type="button" class="wiki-rev-mode-btn"
- :class="{ active: detailMode === 'raw' }" @click="detailMode = 'raw'">
- {{ t('knowledgeEditor.wikiBrowser.revisionRaw') }}
+ <div class="wiki-rev-detail-controls">
+ <div v-if="viewModeOptions.length > 1" class="wiki-rev-view-switch" role="tablist"
+ :aria-label="t('knowledgeEditor.wikiBrowser.revisionViewModeLabel')">
+ <button v-for="option in viewModeOptions" :key="option.value" type="button"
+ class="wiki-rev-view-switch-btn" role="tab" :aria-selected="viewMode === option.value"
+ :class="{ active: viewMode === option.value }" @click="viewMode = option.value">
+ {{ option.label }}
</button>
</div>
- <t-popconfirm v-if="canEdit"
+ <t-popconfirm v-if="canEdit && selectedRevision"
:content="t('knowledgeEditor.wikiBrowser.revertConfirm', { ver: selectedRevision.version })"
@confirm="doRevert">
- <t-button size="small" theme="warning" variant="outline" :loading="reverting">
+ <t-button size="small" variant="text" theme="warning" :loading="reverting">
<template #icon><t-icon name="rollback" /></template>
{{ t('knowledgeEditor.wikiBrowser.revertBtn') }}
</t-button>
@@ -75,36 +69,42 @@
</div>
</div>
- <div v-if="loadingDetail" class="wiki-rev-detail-loading">
+ <div v-if="loadingDetail || diffLoading" class="wiki-rev-detail-loading">
<t-loading size="small" />
<span>{{ t('knowledgeEditor.wikiBrowser.loading') }}</span>
</div>
- <!-- Diff vs current -->
- <div v-else-if="detailMode === 'diff'" class="wiki-rev-diff">
- <div class="wiki-rev-diff-caption">
- {{ t('knowledgeEditor.wikiBrowser.revisionDiffCaption', {
- from: selectedRevision.version, to: currentPage?.version ?? '?' }) }}
+ <div v-else-if="viewMode !== 'raw'" class="wiki-rev-diff">
+ <div v-if="diffSections.length === 0" class="wiki-rev-empty-diff">
+ {{ t('knowledgeEditor.wikiBrowser.revisionDiffEmpty') }}
</div>
- <pre class="wiki-rev-diff-body"><span v-for="(line, idx) in diffLines" :key="idx"
- :class="['wiki-rev-diff-line', `wiki-rev-diff-line--${line.type}`]">{{ diffPrefix(line.type) }}{{ line.text }}
+ <template v-for="section in diffSections" :key="section.field">
+ <div class="wiki-rev-diff-block">
+ <div class="wiki-rev-diff-block-label">{{ revisionDiffFieldLabel(section.field) }}</div>
+ <pre class="wiki-rev-diff-block-body"><span v-for="(line, idx) in section.lines"
+ :key="`${section.field}-${idx}`"
+ :class="['wiki-rev-diff-line', `wiki-rev-diff-line--${line.type}`]">{{ diffPrefix(line.type) }}{{ line.text }}
</span></pre>
+ </div>
+ </template>
</div>
- <!-- Raw content -->
- <pre v-else class="wiki-rev-raw">{{ detailContent }}</pre>
+ <div v-else-if="selectedRevision" class="wiki-rev-raw">
+ <pre class="wiki-rev-raw-body">{{ rawRevisionText }}</pre>
+ </div>
</template>
<div v-else class="wiki-rev-detail-hint">{{ t('knowledgeEditor.wikiBrowser.revisionSelectHint') }}</div>
</div>
</div>
- </t-drawer>
+ </SettingDrawer>
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { MessagePlugin } from 'tdesign-vue-next'
+import SettingDrawer from '@/components/settings/SettingDrawer.vue'
import {
listWikiRevisions,
getWikiRevision,
@@ -112,7 +112,16 @@ import {
type WikiPage,
type WikiPageRevision,
} from '@/api/wiki'
-import { diffWikiLines, type WikiDiffLine } from '@/utils/wikiLineDiff'
+import { diffWikiRevision, type WikiRevisionDiffField, type WikiRevisionSnapshot } from '@/utils/wikiRevisionDiff'
+
+type ViewMode = 'incremental' | 'cumulative' | 'raw'
+
+interface DiffPair {
+ fromVersion: number
+ toVersion: number
+ from: WikiRevisionSnapshot
+ to: WikiRevisionSnapshot
+}
const props = defineProps<{
visible: boolean
@@ -129,6 +138,15 @@ const emit = defineEmits<{
const { t } = useI18n()
+const drawerVisible = computed({
+ get: () => props.visible,
+ set: (val) => emit('update:visible', val),
+})
+
+const drawerTitle = computed(() =>
+ t('knowledgeEditor.wikiBrowser.historyTitle', { title: props.currentPage?.title || props.slug }),
+)
+
const PAGE_SIZE = 50
const revisions = ref<WikiPageRevision[]>([])
@@ -139,12 +157,93 @@ const selectedVersion = ref<number | null>(null)
const selectedRevision = ref<WikiPageRevision | null>(null)
const detailContent = ref('')
const loadingDetail = ref(false)
-const detailMode = ref<'diff' | 'raw'>('diff')
+const viewMode = ref<ViewMode>('incremental')
const reverting = ref(false)
+const diffLoading = ref(false)
+const diffPair = ref<DiffPair | null>(null)
+
+const snapshotCache = new Map<number, WikiRevisionSnapshot>()
+
+const currentVersion = computed(() => props.currentPage?.version ?? null)
+
+const isCurrentSelected = computed(() =>
+ currentVersion.value !== null && selectedVersion.value === currentVersion.value,
+)
+
+const canShowDiff = computed(() => {
+ if (selectedVersion.value === null || !props.currentPage) return false
+ if (viewMode.value === 'raw') return true
+ if (viewMode.value === 'cumulative') {
+ return !isCurrentSelected.value && selectedVersion.value! < currentVersion.value!
+ }
+ // incremental: v1 diffs from empty; later versions diff from the previous one
+ return selectedVersion.value! >= 1
+})
+
+const viewModeOptions = computed(() => {
+ if (isCurrentSelected.value) return []
+ const ver = selectedVersion.value!
+ const cur = currentVersion.value!
+ const options: Array<{ value: ViewMode; label: string }> = []
+ options.push({ value: 'incremental', label: t('knowledgeEditor.wikiBrowser.revisionDiffIncremental') })
+ if (ver < cur) {
+ options.push({ value: 'cumulative', label: t('knowledgeEditor.wikiBrowser.revisionDiffCumulative') })
+ }
+ options.push({ value: 'raw', label: t('knowledgeEditor.wikiBrowser.revisionRaw') })
+ return options
+})
+
+const versionRangeLabel = computed(() => {
+ if (viewMode.value === 'raw') {
+ return selectedRevision.value ? `v${selectedRevision.value.version}` : ''
+ }
+ if (!diffPair.value) return ''
+ if (diffPair.value.fromVersion < 1) {
+ return t('knowledgeEditor.wikiBrowser.revisionInitialRange', { ver: diffPair.value.toVersion })
+ }
+ return `v${diffPair.value.fromVersion} → v${diffPair.value.toVersion}`
+})
-const diffLines = computed<WikiDiffLine[]>(() => {
- if (!props.currentPage || !selectedRevision.value) return []
- return diffWikiLines(detailContent.value, props.currentPage.content || '')
+const contextHint = computed(() => {
+ if (viewMode.value === 'raw' && selectedRevision.value) {
+ return [
+ sourceLabel(selectedRevision.value.edit_source),
+ formatShortTime(selectedRevision.value.edited_at),
+ ].filter(Boolean).join(' · ')
+ }
+ if (viewMode.value === 'incremental') {
+ if ((isCurrentSelected.value && (currentVersion.value ?? 0) <= 1)
+ || selectedVersion.value === 1) {
+ return t('knowledgeEditor.wikiBrowser.revisionInitialCreationHint')
+ }
+ return isCurrentSelected.value
+ ? t('knowledgeEditor.wikiBrowser.revisionLatestChangeHint')
+ : t('knowledgeEditor.wikiBrowser.revisionIncrementalHint', { ver: selectedVersion.value ?? 0 })
+ }
+ if (viewMode.value === 'cumulative') {
+ return t('knowledgeEditor.wikiBrowser.revisionCumulativeHint')
+ }
+ return ''
+})
+
+const rawRevisionText = computed(() => {
+ if (!selectedRevision.value) return detailContent.value
+ const parts: string[] = []
+ if (selectedRevision.value.title) parts.push(selectedRevision.value.title)
+ if (selectedRevision.value.summary) {
+ if (parts.length) parts.push('')
+ parts.push(selectedRevision.value.summary)
+ }
+ if (detailContent.value) {
+ if (parts.length) parts.push('')
+ parts.push(detailContent.value)
+ }
+ return parts.join('\n')
+})
+
+const diffSections = computed(() => {
+ if (!diffPair.value || viewMode.value === 'raw') return []
+ return diffWikiRevision(diffPair.value.from, diffPair.value.to)
})
watch(
@@ -156,15 +255,119 @@ watch(
},
)
+watch(
+ () => viewModeOptions.value,
+ (options) => {
+ if (options.length === 0) return
+ if (!options.some((option) => option.value === viewMode.value)) {
+ viewMode.value = options[0].value
+ }
+ },
+)
+
+watch(
+ () => [selectedVersion.value, viewMode.value, props.currentPage?.version, props.currentPage?.content,
+ props.currentPage?.title, props.currentPage?.summary] as const,
+ () => {
+ if (props.visible && viewMode.value !== 'raw') {
+ void loadDiffPair()
+ }
+ },
+)
+
+function snapshotFromPage(page: WikiPage): WikiRevisionSnapshot {
+ return {
+ title: page.title || '',
+ summary: page.summary || '',
+ content: page.content || '',
+ }
+}
+
+function snapshotFromRevisionData(data: WikiPageRevision, content: string): WikiRevisionSnapshot {
+ return {
+ title: data.title || '',
+ summary: data.summary || '',
+ content,
+ }
+}
+
+async function loadVersionSnapshot(version: number): Promise<WikiRevisionSnapshot> {
+ if (!props.currentPage) {
+ return { title: '', summary: '', content: '' }
+ }
+ if (version === props.currentPage.version) {
+ return snapshotFromPage(props.currentPage)
+ }
+ const cached = snapshotCache.get(version)
+ if (cached) return cached
+ const res = await getWikiRevision(props.kbId, props.slug, version)
+ const data = (res as any).data || (res as any)
+ const snap = snapshotFromRevisionData(data, data.content || '')
+ snapshotCache.set(version, snap)
+ return snap
+}
+
+let diffRequestSeq = 0
+
+async function loadDiffPair() {
+ const seq = ++diffRequestSeq
+ if (!props.currentPage || selectedVersion.value === null || !canShowDiff.value) {
+ diffPair.value = null
+ diffLoading.value = false
+ return
+ }
+
+ const currentVer = props.currentPage.version
+ let fromVer = 0
+ let toVer = 0
+
+ if (viewMode.value === 'incremental') {
+ toVer = isCurrentSelected.value ? currentVer : selectedVersion.value!
+ fromVer = toVer - 1
+ } else {
+ fromVer = selectedVersion.value!
+ toVer = currentVer
+ }
+
+ if (fromVer < 0 || toVer < 1 || fromVer >= toVer) {
+ diffPair.value = null
+ diffLoading.value = false
+ return
+ }
+
+ diffLoading.value = true
+ try {
+ const from = fromVer < 1
+ ? { title: '', summary: '', content: '' }
+ : await loadVersionSnapshot(fromVer)
+ if (seq !== diffRequestSeq) return
+ const to = await loadVersionSnapshot(toVer)
+ if (seq !== diffRequestSeq) return
+ diffPair.value = { fromVersion: fromVer, toVersion: toVer, from, to }
+ } catch (e: any) {
+ if (seq !== diffRequestSeq) return
+ diffPair.value = null
+ MessagePlugin.error(e?.message || t('knowledgeEditor.wikiBrowser.revisionLoadFailed'))
+ } finally {
+ if (seq === diffRequestSeq) diffLoading.value = false
+ }
+}
+
function resetAndLoad() {
detailRequestSeq++
+ diffRequestSeq++
+ snapshotCache.clear()
revisions.value = []
total.value = 0
selectedVersion.value = props.currentPage?.version ?? null
selectedRevision.value = null
detailContent.value = ''
loadingDetail.value = false
+ diffPair.value = null
+ diffLoading.value = false
+ viewMode.value = 'incremental'
loadList(0)
+ void loadDiffPair()
}
async function loadList(offset: number) {
@@ -201,6 +404,7 @@ function selectCurrent() {
selectedRevision.value = null
detailContent.value = ''
loadingDetail.value = false
+ viewMode.value = 'incremental'
}
// Monotonic token guarding the detail fetch: clicking through the list fires
@@ -213,12 +417,15 @@ async function selectRevision(rev: WikiPageRevision) {
selectedVersion.value = rev.version
selectedRevision.value = rev
detailContent.value = ''
+ viewMode.value = 'incremental'
loadingDetail.value = true
try {
const res = await getWikiRevision(props.kbId, props.slug, rev.version)
if (seq !== detailRequestSeq) return
const data = (res as any).data || (res as any)
+ selectedRevision.value = { ...rev, ...data }
detailContent.value = data.content || ''
+ snapshotCache.set(rev.version, snapshotFromRevisionData(data, data.content || ''))
} catch (e: any) {
if (seq !== detailRequestSeq) return
MessagePlugin.error(e?.message || t('knowledgeEditor.wikiBrowser.revisionLoadFailed'))
@@ -245,10 +452,21 @@ async function doRevert() {
}
}
-function diffPrefix(type: WikiDiffLine['type']): string {
+function diffPrefix(type: 'same' | 'add' | 'del'): string {
return type === 'add' ? '+ ' : type === 'del' ? '- ' : ' '
}
+function revisionDiffFieldLabel(field: WikiRevisionDiffField): string {
+ switch (field) {
+ case 'title':
+ return t('knowledgeEditor.wikiBrowser.revisionDiffTitle')
+ case 'summary':
+ return t('knowledgeEditor.wikiBrowser.revisionDiffSummary')
+ default:
+ return t('knowledgeEditor.wikiBrowser.revisionDiffContent')
+ }
+}
+
function sourceLabel(source?: string): string {
switch (source) {
case 'user':
@@ -392,79 +610,75 @@ function formatShortTime(iso?: string): string {
display: flex;
flex-direction: column;
overflow: hidden;
- padding: 16px 20px;
+ padding: 14px 18px 18px;
}
-.wiki-rev-detail-toolbar {
+.wiki-rev-detail-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
- gap: 12px;
- margin-bottom: 12px;
- flex-wrap: wrap;
+ gap: 16px;
+ margin-bottom: 14px;
+ padding-bottom: 14px;
+ border-bottom: 1px solid var(--td-component-stroke);
}
-.wiki-rev-detail-title {
+.wiki-rev-detail-context {
min-width: 0;
- display: flex;
- align-items: baseline;
- gap: 8px;
+ flex: 1;
}
-.wiki-rev-detail-version {
- font-weight: 600;
+.wiki-rev-detail-range {
font-family: var(--td-font-family-mono, monospace);
- font-size: 13px;
- color: var(--td-text-color-secondary);
- flex-shrink: 0;
-}
-
-.wiki-rev-detail-name {
- font-weight: 600;
font-size: 15px;
+ font-weight: 600;
+ line-height: 1.4;
color: var(--td-text-color-primary);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
}
-.wiki-rev-detail-actions {
+.wiki-rev-detail-sub {
+ margin-top: 4px;
+ font-size: 12px;
+ line-height: 1.5;
+ color: var(--td-text-color-placeholder);
+}
+
+.wiki-rev-detail-controls {
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
-.wiki-rev-mode-toggle {
+.wiki-rev-view-switch {
display: inline-flex;
align-items: center;
gap: 2px;
padding: 2px;
- border-radius: 6px;
- background: var(--td-bg-color-container);
- border: 1px solid var(--td-component-stroke);
+ border-radius: 8px;
+ background: var(--td-bg-color-secondarycontainer);
}
-.wiki-rev-mode-btn {
- padding: 4px 10px;
+.wiki-rev-view-switch-btn {
+ padding: 5px 10px;
border: 0;
- border-radius: 4px;
+ border-radius: 6px;
background: transparent;
color: var(--td-text-color-secondary);
font-size: 12px;
line-height: 1.4;
+ white-space: nowrap;
cursor: pointer;
- transition: background 0.15s, color 0.15s;
+ transition: background 0.15s ease, color 0.15s ease;
}
-.wiki-rev-mode-btn:hover {
+.wiki-rev-view-switch-btn:hover {
color: var(--td-text-color-primary);
}
-.wiki-rev-mode-btn.active {
+.wiki-rev-view-switch-btn.active {
color: var(--td-brand-color);
background: var(--td-bg-color-container);
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
font-weight: 500;
}
@@ -493,26 +707,56 @@ function formatShortTime(iso?: string): string {
.wiki-rev-diff {
flex: 1;
min-height: 0;
+ overflow-y: auto;
display: flex;
flex-direction: column;
+ gap: 12px;
}
-.wiki-rev-diff-caption {
+.wiki-rev-empty-diff {
+ padding: 24px 0;
+ text-align: center;
+ font-size: 13px;
+ color: var(--td-text-color-placeholder);
+}
+
+.wiki-rev-diff-block {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.wiki-rev-diff-block-label {
font-size: 12px;
+ font-weight: 500;
color: var(--td-text-color-placeholder);
- margin-bottom: 8px;
}
-.wiki-rev-diff-body,
+.wiki-rev-diff-block-body {
+ overflow: auto;
+ margin: 0;
+ padding: 10px 12px;
+ background: var(--td-bg-color-secondarycontainer);
+ border-radius: 8px;
+ font-size: 12px;
+ line-height: 1.7;
+ font-family: var(--td-font-family-mono, monospace);
+ white-space: pre-wrap;
+ word-break: break-word;
+}
+
.wiki-rev-raw {
flex: 1;
+ min-height: 0;
overflow: auto;
+}
+
+.wiki-rev-raw-body {
margin: 0;
padding: 12px 14px;
- background: var(--td-bg-color-container);
- border: 1px solid var(--td-component-stroke);
+ background: var(--td-bg-color-secondarycontainer);
border-radius: 8px;
- font-size: 12px;
+ font-size: 13px;
line-height: 1.7;
font-family: var(--td-font-family-mono, monospace);
white-space: pre-wrap;
@@ -543,20 +787,24 @@ function formatShortTime(iso?: string): string {
height: 100%;
}
- .t-drawer__header {
- padding: 20px 24px;
- border-bottom: 1px solid var(--td-component-stroke);
- flex-shrink: 0;
+ .t-drawer__body {
+ flex: 1;
+ min-height: 0;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
}
- .t-drawer__body {
+ .setting-drawer__body {
flex: 1;
min-height: 0;
padding: 0;
+ gap: 0;
+ animation: none;
display: flex;
flex-direction: column;
overflow: hidden;
- background: var(--td-bg-color-container);
}
}
</style>