From 7fa6f028fcea9e08720db1f565ec4911ea0e7aa6 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Sun, 20 Sep 2026 16:16:28 +0800 Subject: [PATCH] feat(chat): rework the saved-answer Markdown editor (#3467) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(chat): make the saved-answer Markdown editor usable Saving a chat answer to a knowledge base dropped the raw answer — citation tags and all — into a 760px drawer with a single column and a preview toggle. Every `` had to be deleted by hand, and the title arrived hard-cut with an ellipsis. - strip `` tags from the seeded draft and list the cited documents once at the bottom; keep `` citations as real Markdown links - cut a long question on a clause boundary instead of at 40 chars + "..." - compact title + knowledge-base row, full-height editor (no more calc(100vh - 360px)), and an edit / split / preview switch that starts on split whenever the drawer is wide enough for two panes - opt-in maximize toggle on SettingDrawer for full-width editing - native textarea in place of t-textarea, with Cmd/Ctrl+B/I/K/S/Enter, list continuation on Enter and Tab indenting - confirm before discarding unsaved changes; show a character/line count * style(chat): stop painting the Markdown editor green Brand green was doing decorative work in the editor: a 4px green rule and an 8% green wash on every blockquote in the preview, a green pill for the active view, green toolbar hovers, and a green halo around the whole editor while it had focus. Together they read as noise. Green now means action only — the publish button, links, keyboard focus rings. Blockquotes match the chat renderer's own neutral treatment (2px --td-component-stroke, no fill), the view switch uses a raised neutral pill, and toolbar hover/active use the container tokens. * refactor(chat): fold the editor toolbar from 16 buttons to 10 Sixteen same-sized icons gave equal weight to "bold" and "insert horizontal rule", and at the default drawer width the row already ran out of space (the overflow scrollbar is hidden, so the last icons simply vanished). Headings collapse into one labelled "标题" menu and the block inserts (quote, code block, table, image, rule) into "插入"; the actions people reach for mid-sentence — bold/italic/strike/inline code, the three list kinds, link — stay one click away. The cropped shortcut line in the status bar becomes a keyboard button whose tooltip lists every binding, including Cmd+Enter to publish, which was undocumented. * refactor(chat): collapse the editor into four bands The drawer stacked seven horizontal strips — header, subtitle, a labelled title row, a labelled knowledge-base row, toolbar, canvas, status bar — each with its own rule or tint, and none of them shared a left edge. The document now has a head (a borderless title that reads as a title, with "存入 <知识库>" as a sentence under it), one editor card, and a footer. The header subtitle, the two field labels and the status strip are gone: word/line counts moved next to the draft tag in the footer and the shortcut sheet to the toolbar's right end. Title, destination and the editor card all start on the same left edge. * refactor(chat): move the destination onto the title row "存入" was a verb invented for this one screen, and the row it sat on cost the head a whole line. The destination is now the folder icon this product already uses for a knowledge base in the @-mention list, followed by the select, parked at the right end of the title row — so the head is one line whose two ends line up with the editor card below it. The narrow layout that stacks them again is now driven by the editor's ResizeObserver instead of a `@container` query: the scoped-style pipeline drops `@container` blocks (none of them reach the page), so the previous rules — stacking and, worse, the toolbar wrap that keeps the last buttons from silently overflowing — never actually applied. * style(chat): let the destination select reach the right edge The select's box sat flush with the editor card, but a 132px min-width held it open past its content, so the folder icon, the name and the caret stopped 43px short — the block read as floating rather than aligned. It now shrinks to its content (up to 260px, then truncates), leaving only the control's own 5px of inner padding, and stays right-aligned when the narrow layout stacks it under the title. * style(chat): keep the narrow toolbar on one row A narrow drawer wrapped the toolbar into two rows and left the view switch hanging beside the second one, and the head split into two rows as well. The view switch now drops its three text labels on narrow (the tooltips already carry them), which buys back enough room for the whole toolbar — all ten controls — to stay on one row down to the 600px minimum width. The head keeps title and destination on one line too, now that the destination shrank to its content. * style(chat): shrink the editor drawer's header The header was sized for a title plus a subtitle; with the subtitle gone it kept 65px for one 15px line — a 32px badge inside 14px of padding, propped up by TDesign's 56px min-height. Down to 47px: 26px badge, 9px padding, min-height released. Scoped to this drawer, so the other SettingDrawer consumers keep their proportions. * chore(chat): drop leftovers from the editor rework - the per-button `btn-` class on toolbar buttons: nothing styled or queried it - `INDENT` was exported but only ever used inside markdownEditing - a comment still pointed at the status bar that no longer exists --- .../components/manual-knowledge-editor.vue | 1073 ++++++++++++----- .../src/components/settings/SettingDrawer.vue | 75 +- frontend/src/i18n/locales/en-US.ts | 26 +- frontend/src/i18n/locales/ja-JP.ts | 26 +- frontend/src/i18n/locales/ko-KR.ts | 26 +- frontend/src/i18n/locales/ru-RU.ts | 26 +- frontend/src/i18n/locales/zh-CN.ts | 26 +- frontend/src/utils/chatMessageShared.ts | 16 +- frontend/src/utils/citationMarkdown.ts | 47 + .../src/utils/manualKnowledgeDraft.test.ts | 67 + frontend/src/utils/manualKnowledgeDraft.ts | 56 + frontend/src/utils/markdownEditing.test.ts | 49 + frontend/src/utils/markdownEditing.ts | 115 ++ 13 files changed, 1260 insertions(+), 368 deletions(-) create mode 100644 frontend/src/utils/manualKnowledgeDraft.test.ts create mode 100644 frontend/src/utils/manualKnowledgeDraft.ts create mode 100644 frontend/src/utils/markdownEditing.test.ts create mode 100644 frontend/src/utils/markdownEditing.ts diff --git a/frontend/src/components/manual-knowledge-editor.vue b/frontend/src/components/manual-knowledge-editor.vue index 45500914..432f0a09 100644 --- a/frontend/src/components/manual-knowledge-editor.vue +++ b/frontend/src/components/manual-knowledge-editor.vue @@ -2,7 +2,7 @@ import { ref, reactive, computed, watch, nextTick, onBeforeUnmount } from 'vue' import SettingDrawer from '@/components/settings/SettingDrawer.vue' import { marked } from 'marked' -import { MessagePlugin } from 'tdesign-vue-next' +import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next' import { useUIStore } from '@/stores/ui' import { listKnowledgeBases, @@ -15,6 +15,7 @@ import { useUploadConfirmStore } from '@/stores/uploadConfirm' import { useOrganizationStore } from '@/stores/organization' import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess' import { sanitizeHTML, safeMarkdownToHTML, hydrateProtectedFileImages } from '@/utils/security' +import { continueListOnEnter, countContent, indentOnTab } from '@/utils/markdownEditing' import { useI18n } from 'vue-i18n' interface KnowledgeBaseOption { @@ -85,72 +86,85 @@ const kbLoading = ref(false) const contentLoading = ref(false) const saving = ref(false) const savingAction = ref('draft') -const activeTab = ref<'edit' | 'preview'>('edit') const lastUpdatedAt = ref('') -const textareaComponent = ref(null) -const textareaElement = ref(null) -const selectionRange = reactive({ start: 0, end: 0 }) -const selectionEvents = ['select', 'keyup', 'click', 'mouseup', 'input'] +// ---------- view mode ---------- +type ViewMode = 'edit' | 'split' | 'preview' +const VIEW_MODE_STORAGE_KEY = 'manual-editor:view-mode' +/** Below this the two panes would each be too narrow to write or read in. */ +const SPLIT_MIN_WIDTH = 820 -const resolveTextareaElement = (): HTMLTextAreaElement | null => { - const component = textareaComponent.value as any - if (!component) return null - if (component.textareaRef) { - return component.textareaRef as HTMLTextAreaElement +const readStoredViewMode = (): ViewMode => { + try { + const stored = window.localStorage.getItem(VIEW_MODE_STORAGE_KEY) + if (stored === 'edit' || stored === 'split' || stored === 'preview') return stored + } catch { + // localStorage can throw in private mode / quota errors. } - if (component.$el) { - const el = component.$el.querySelector('textarea') - if (el) { - return el as HTMLTextAreaElement - } - } - return null + return 'split' } -const handleTextareaSelectionEvent = () => { - const textarea = textareaElement.value ?? resolveTextareaElement() - if (!textarea) { - return +const viewMode = ref(readStoredViewMode()) +const editorAreaRef = ref(null) +const editorAreaWidth = ref(SPLIT_MIN_WIDTH) +const canSplit = computed(() => editorAreaWidth.value >= SPLIT_MIN_WIDTH) +/** + * Narrow-layout switch, driven from the same measurement rather than a + * `@container` query: this project's scoped-style pipeline drops `@container` + * blocks, so those rules never reach the page. + */ +const NARROW_WIDTH = 620 +const isNarrow = computed(() => editorAreaWidth.value > 0 && editorAreaWidth.value < NARROW_WIDTH) +/** Split silently falls back to edit-only while the drawer is too narrow for it. */ +const activeView = computed(() => + viewMode.value === 'split' && !canSplit.value ? 'edit' : viewMode.value, +) +const showEditor = computed(() => activeView.value !== 'preview') +const showPreview = computed(() => activeView.value !== 'edit') + +const setViewMode = (mode: ViewMode) => { + if (mode === 'split' && !canSplit.value) return + viewMode.value = mode + try { + window.localStorage.setItem(VIEW_MODE_STORAGE_KEY, mode) + } catch { + // Ignore: remembering the layout is a convenience, not a requirement. } +} + +let editorAreaObserver: ResizeObserver | null = null + +watch(editorAreaRef, (el) => { + editorAreaObserver?.disconnect() + editorAreaObserver = null + if (!el) return + // Measure straight away: waiting for the observer's first callback would + // paint a split editor for a frame before collapsing it on a narrow drawer. + editorAreaWidth.value = el.clientWidth + if (typeof ResizeObserver === 'undefined') return + editorAreaObserver = new ResizeObserver((entries) => { + editorAreaWidth.value = entries[0]?.contentRect.width ?? 0 + }) + editorAreaObserver.observe(el) +}) + +// ---------- textarea selection ---------- +const textareaEl = ref(null) +const selectionRange = reactive({ start: 0, end: 0 }) + +const syncSelection = () => { + const textarea = textareaEl.value + if (!textarea) return selectionRange.start = textarea.selectionStart ?? 0 selectionRange.end = textarea.selectionEnd ?? 0 } -const detachTextareaListeners = () => { - if (!textareaElement.value) { - return - } - selectionEvents.forEach((eventName) => { - textareaElement.value?.removeEventListener(eventName, handleTextareaSelectionEvent) - }) - textareaElement.value = null -} - -const attachTextareaListeners = () => { - nextTick(() => { - const textarea = resolveTextareaElement() - if (!textarea) { - return - } - if (textareaElement.value === textarea) { - return - } - detachTextareaListeners() - textareaElement.value = textarea - selectionEvents.forEach((eventName) => { - textarea.addEventListener(eventName, handleTextareaSelectionEvent) - }) - handleTextareaSelectionEvent() - }) -} - const setSelectionRange = (start: number, end: number) => { selectionRange.start = start selectionRange.end = end nextTick(() => { - const textarea = resolveTextareaElement() - if (!textarea || activeTab.value !== 'edit') { + const textarea = textareaEl.value + if (!textarea || !showEditor.value) { return } // Initialization can finish while the drawer is still sliding in. A plain @@ -340,77 +354,220 @@ type ToolbarButton = { action: ToolbarAction icon: string } +/** + * A group of related actions behind one labelled trigger. Headings and the + * block inserts are one-per-document choices, so they cost more toolbar room + * than they earn as separate icons. + */ +type ToolbarMenu = { + key: string + label: string + options: Array<{ content: string; value: string }> + actions: Record +} type ToolbarGroup = { key: string buttons: ToolbarButton[] + menu?: ToolbarMenu } -const toolbarGroups = computed(() => [ - { - key: 'format', - buttons: [ - { key: 'bold', icon: 'textformat-bold', tooltip: t('manualEditor.toolbar.bold'), action: () => wrapSelection('**', '**', t('manualEditor.placeholders.bold')) }, - { key: 'italic', icon: 'textformat-italic', tooltip: t('manualEditor.toolbar.italic'), action: () => wrapSelection('*', '*', t('manualEditor.placeholders.italic')) }, - { key: 'strike', icon: 'textformat-strikethrough', tooltip: t('manualEditor.toolbar.strike'), action: () => wrapSelection('~~', '~~', t('manualEditor.placeholders.strike')) }, - { key: 'inline-code', icon: 'code', tooltip: t('manualEditor.toolbar.inlineCode'), action: () => wrapSelection('`', '`', t('manualEditor.placeholders.inlineCode')) }, - ], - }, - { +const toolbarGroups = computed(() => { + const headingMenu: ToolbarMenu = { key: 'heading', - buttons: [ - { key: 'h1', icon: 'numbers-1', tooltip: t('manualEditor.toolbar.heading1'), action: () => applyHeading(1) }, - { key: 'h2', icon: 'numbers-2', tooltip: t('manualEditor.toolbar.heading2'), action: () => applyHeading(2) }, - { key: 'h3', icon: 'numbers-3', tooltip: t('manualEditor.toolbar.heading3'), action: () => applyHeading(3) }, + label: t('manualEditor.toolbar.headingGroup'), + options: [ + { content: t('manualEditor.toolbar.heading1'), value: 'h1' }, + { content: t('manualEditor.toolbar.heading2'), value: 'h2' }, + { content: t('manualEditor.toolbar.heading3'), value: 'h3' }, ], - }, - { - key: 'list', - buttons: [ - { key: 'ul', icon: 'view-list', tooltip: t('manualEditor.toolbar.bulletList'), action: applyBulletList }, - { key: 'ol', icon: 'list-numbered', tooltip: t('manualEditor.toolbar.orderedList'), action: applyOrderedList }, - { key: 'task', icon: 'check-rectangle', tooltip: t('manualEditor.toolbar.taskList'), action: applyTaskList }, - { key: 'quote', icon: 'quote', tooltip: t('manualEditor.toolbar.blockquote'), action: applyBlockquote }, - ], - }, - { + actions: { + h1: () => applyHeading(1), + h2: () => applyHeading(2), + h3: () => applyHeading(3), + }, + } + + const insertMenu: ToolbarMenu = { key: 'insert', - buttons: [ - { key: 'codeblock', icon: 'code-1', tooltip: t('manualEditor.toolbar.codeBlock'), action: insertCodeBlock }, - { key: 'link', icon: 'link', tooltip: t('manualEditor.toolbar.link'), action: insertLink }, - { key: 'image', icon: 'image', tooltip: t('manualEditor.toolbar.image'), action: insertImage }, - { key: 'table', icon: 'table', tooltip: t('manualEditor.toolbar.table'), action: insertTable }, - { key: 'hr', icon: 'component-divider-horizontal', tooltip: t('manualEditor.toolbar.horizontalRule'), action: insertHorizontalRule }, + label: t('manualEditor.toolbar.insertGroup'), + options: [ + { content: t('manualEditor.toolbar.blockquote'), value: 'quote' }, + { content: t('manualEditor.toolbar.codeBlock'), value: 'codeblock' }, + { content: t('manualEditor.toolbar.table'), value: 'table' }, + { content: t('manualEditor.toolbar.image'), value: 'image' }, + { content: t('manualEditor.toolbar.horizontalRule'), value: 'hr' }, ], - }, -]) + actions: { + quote: applyBlockquote, + codeblock: insertCodeBlock, + table: insertTable, + image: insertImage, + hr: insertHorizontalRule, + }, + } + + return [ + { + key: 'format', + buttons: [ + { key: 'bold', icon: 'textformat-bold', tooltip: t('manualEditor.toolbar.bold'), action: () => wrapSelection('**', '**', t('manualEditor.placeholders.bold')) }, + { key: 'italic', icon: 'textformat-italic', tooltip: t('manualEditor.toolbar.italic'), action: () => wrapSelection('*', '*', t('manualEditor.placeholders.italic')) }, + { key: 'strike', icon: 'textformat-strikethrough', tooltip: t('manualEditor.toolbar.strike'), action: () => wrapSelection('~~', '~~', t('manualEditor.placeholders.strike')) }, + { key: 'inline-code', icon: 'code', tooltip: t('manualEditor.toolbar.inlineCode'), action: () => wrapSelection('`', '`', t('manualEditor.placeholders.inlineCode')) }, + ], + }, + { key: 'heading', buttons: [], menu: headingMenu }, + { + key: 'list', + buttons: [ + { key: 'ul', icon: 'view-list', tooltip: t('manualEditor.toolbar.bulletList'), action: applyBulletList }, + { key: 'ol', icon: 'list-numbered', tooltip: t('manualEditor.toolbar.orderedList'), action: applyOrderedList }, + { key: 'task', icon: 'check-rectangle', tooltip: t('manualEditor.toolbar.taskList'), action: applyTaskList }, + ], + }, + { + key: 'insert', + buttons: [ + { key: 'link', icon: 'link', tooltip: t('manualEditor.toolbar.link'), action: insertLink }, + ], + menu: insertMenu, + }, + ] +}) + +/** TDesign hands the clicked item's `value` (or the item itself in older builds). */ +const handleToolbarMenuSelect = (menu: ToolbarMenu, selected: unknown) => { + const key = + selected && typeof selected === 'object' + ? String((selected as { value?: unknown }).value ?? '') + : String(selected ?? '') + const action = menu.actions[key] + if (action) handleToolbarAction(action) +} const previewRoot = ref(null) -const isPreviewMode = computed(() => activeTab.value === 'preview') -const viewToggleIcon = computed(() => (isPreviewMode.value ? 'edit-1' : 'browse')) -const viewToggleLabel = computed(() => - isPreviewMode.value ? t('manualEditor.view.editLabel') : t('manualEditor.view.previewLabel'), -) + +const viewOptions = computed(() => [ + { value: 'edit' as ViewMode, icon: 'edit-1', label: t('manualEditor.view.edit'), disabled: false, tooltip: t('manualEditor.view.edit') }, + { + value: 'split' as ViewMode, + icon: 'column-layout', + label: t('manualEditor.view.split'), + disabled: !canSplit.value, + tooltip: canSplit.value ? t('manualEditor.view.split') : t('manualEditor.view.splitUnavailable'), + }, + { value: 'preview' as ViewMode, icon: 'browse', label: t('manualEditor.view.preview'), disabled: false, tooltip: t('manualEditor.view.preview') }, +]) const handleToolbarAction = (action: ToolbarAction) => { if (saving.value) { return } - if (activeTab.value !== 'edit') { - activeTab.value = 'edit' - nextTick(() => { - attachTextareaListeners() - action() - }) + // Formatting acts on the textarea, so bring it back into view first. + if (!showEditor.value) { + setViewMode(canSplit.value ? 'split' : 'edit') + nextTick(action) } else { - attachTextareaListeners() action() } } -const toggleEditorView = () => { - activeTab.value = isPreviewMode.value ? 'edit' : 'preview' +// ---------- keyboard ---------- +const isApplePlatform = + typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent) +const modifierLabel = computed(() => (isApplePlatform ? '⌘' : 'Ctrl+')) + +const SHORTCUT_ACTIONS: Record void> = { + b: () => wrapSelection('**', '**', t('manualEditor.placeholders.bold')), + i: () => wrapSelection('*', '*', t('manualEditor.placeholders.italic')), + k: insertLink, } +const applyPatch = (patch: { value: string; start: number; end: number }) => { + form.content = patch.value + setSelectionRange(patch.start, patch.end) +} + +/** Read the live caret off the event target — it is ahead of our cached range. */ +const readEditorState = (event: KeyboardEvent) => { + const textarea = event.currentTarget instanceof HTMLTextAreaElement ? event.currentTarget : null + return { + value: form.content ?? '', + start: textarea?.selectionStart ?? selectionRange.start, + end: textarea?.selectionEnd ?? selectionRange.end, + } +} + +/** + * Shortcuts an author expects from any Markdown editor, plus list/indent + * behaviour a bare
-
+
- + +
@@ -913,8 +1125,11 @@ onBeforeUnmount(() => { /* 复用模型管理同款 SettingDrawer:分组 section / header 图标 / footer 按钮 / 拖拽调宽。 这里只负责本编辑器特有的内容样式。内容内联渲染(无 teleport),scoped 生效。 */ .manual-editor { + flex: 1; + min-height: 0; display: flex; flex-direction: column; + gap: 14px; } .manual-editor-footer-meta { @@ -923,6 +1138,18 @@ onBeforeUnmount(() => { align-items: center; gap: 8px; color: var(--td-text-color-placeholder); + + /* 状态标签保持整行,窄抽屉里让后面的时间先省略 */ + :deep(.t-tag) { + flex-shrink: 0; + white-space: nowrap; + } +} + +.manual-editor-footer-count { + font-size: var(--app-text-sm); + color: var(--td-text-color-placeholder); + white-space: nowrap; } .manual-editor-footer-actions { @@ -940,7 +1167,8 @@ onBeforeUnmount(() => { border-color: transparent; background: var(--td-bg-color-secondarycontainer); color: var(--td-text-color-secondary); - transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease; + transition: background var(--app-motion-base) ease, border-color var(--app-motion-base) ease, + color var(--app-motion-base) ease; &:hover { border-color: var(--td-component-stroke); @@ -949,53 +1177,135 @@ onBeforeUnmount(() => { } } -.form-item { +/* ---------- 文档头:标题 + 存入位置 ---------- */ +.doc-head { + flex-shrink: 0; display: flex; - flex-direction: column; - gap: 6px; + align-items: center; + gap: 12px; } -.form-label { - font-size: var(--app-text-md); - font-weight: 500; - color: var(--td-text-color-primary); +/* 标题按“文档标题”排版,不做成表单控件;hover/聚焦才显出输入框的边界 */ +:deep(.doc-title) { + flex: 1 1 auto; + min-width: 0; + padding: 0; + background: transparent; + /* 负外边距抵掉内边距:文字和下方编辑卡左对齐,hover 底色仍有呼吸空间 */ + margin: 0 -8px; - &.required::after { - content: '*'; - margin-left: 4px; - color: var(--td-error-color); + .t-input { + padding: 4px 8px; + border-radius: var(--app-radius-sm); + background: transparent; + transition: background var(--app-motion-fast) ease; + } + + .t-input__inner { + font-size: var(--app-text-xl); + font-weight: 600; + line-height: 1.4; + color: var(--td-text-color-primary); + } + + &:hover .t-input { + background: var(--td-bg-color-container-hover); + } + + .t-input.t-is-focused { + background: var(--td-bg-color-container-hover); } } -.form-desc { - margin: 2px 0 0; +.doc-meta { + flex: 0 0 auto; + display: flex; + align-items: center; + gap: 4px; font-size: var(--app-text-sm); color: var(--td-text-color-placeholder); } -.kb-row { - display: flex; - align-items: center; - gap: 12px; +.doc-meta__icon { + flex-shrink: 0; + font-size: var(--app-text-md); +} - :deep(.t-select) { - flex: 1; - min-width: 0; +:deep(.doc-meta__kb) { + /* TDesign 的 select 根节点是块级;这里让它收到内容宽度, + 否则框比文字宽,箭头够不到右边缘,看着就是没对齐 */ + flex: 0 1 auto; + width: auto; + min-width: 0; + max-width: 260px; + + .t-input { + border-color: transparent; + background: transparent; + padding-left: 4px; + padding-right: 4px; + } + + .t-input__inner { + color: var(--td-text-color-secondary); + } + + &:hover .t-input { + border-color: var(--td-component-border); + background: var(--td-bg-color-container); } } -.status-row { - display: flex; - align-items: center; - gap: 6px; - flex-shrink: 0; +.doc-meta__time { + overflow: hidden; + text-overflow: ellipsis; white-space: nowrap; } -/* 内容分组:让编辑区占满,无需依赖父级 flex 链路,直接用视口高度,稳健 */ -.editor-section { +.kb-empty { + padding: 20px; + text-align: center; + color: var(--td-text-color-placeholder); +} + +/* 窄抽屉:与其让工具栏折行(视图切换会悬在第二行),不如把视图切换收成图标, + 一行仍然装得下。文字含义由 tooltip 兜底。 */ +.manual-editor--narrow { + .view-switch__btn { + padding: 0 6px; + } + + .view-switch__label { + display: none; + } + + /* 极窄时的兜底:真放不下才换行,而不是把按钮藏进隐藏的滚动条里 */ + .editor-toolbar { + flex-wrap: wrap; + } + + .editor-toolbar__format { + flex-wrap: wrap; + overflow-x: visible; + } +} + +/* ---------- 编辑区 ---------- */ +.editor-area { flex: 1; - min-height: 0; + /* 视口很矮时不再继续压缩,改由抽屉主体滚动 */ + min-height: 260px; + display: flex; + flex-direction: column; + border: 1px solid var(--td-component-stroke); + border-radius: var(--app-radius-md); + overflow: hidden; + background: var(--td-bg-color-container); + transition: border-color var(--app-motion-base) ease, box-shadow var(--app-motion-base) ease; + + &:focus-within { + border-color: var(--td-component-border); + } } .editor-toolbar { @@ -1028,43 +1338,84 @@ onBeforeUnmount(() => { flex-shrink: 0; display: flex; align-items: center; + gap: 6px; padding-left: 8px; border-left: 1px solid var(--td-component-stroke); } -.toggle-view-btn { - min-width: 92px; - height: 30px; - padding: 0 10px; +/* 编辑 / 分屏 / 预览:一组分段控件,当前视图一眼可见 */ +.view-switch { + display: flex; + align-items: center; + gap: 2px; + padding: 2px; + border-radius: var(--app-radius-sm); + background: var(--td-bg-color-component-disabled); border: 1px solid var(--td-component-stroke); - border-radius: 7px; - background: var(--td-bg-color-container); +} + +.view-switch__btn { + display: flex; + align-items: center; + gap: 4px; + height: 24px; + padding: 0 8px; + border: none; + border-radius: var(--app-radius-xs); + background: transparent; color: var(--td-text-color-secondary); + font-size: var(--app-text-sm); font-weight: 500; - box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); - transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease; + white-space: nowrap; + cursor: pointer; + transition: background var(--app-motion-fast) ease, color var(--app-motion-fast) ease; + + &:hover:not(.is-disabled) { + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); + } + + &.is-active { + background: var(--td-bg-color-container); + color: var(--td-text-color-primary); + box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); + } + + &.is-disabled { + color: var(--td-text-color-disabled); + cursor: not-allowed; + } + + &:focus-visible { + outline: none; + box-shadow: 0 0 0 2px color-mix(in srgb, var(--td-brand-color) 25%, transparent); + } +} + +/* 快捷键速查:和视图切换同处工具栏右端,省掉一整条状态栏 */ +.toolbar-shortcuts { + display: flex; + align-items: center; + justify-content: center; + width: 26px; + height: 26px; + padding: 0; + border: none; + border-radius: var(--app-radius-sm); + background: transparent; + color: var(--td-text-color-placeholder); + font-size: var(--app-text-md); + cursor: help; + transition: background var(--app-motion-fast) ease, color var(--app-motion-fast) ease; &:hover { - border-color: color-mix(in srgb, var(--td-brand-color) 45%, transparent); - background: color-mix(in srgb, var(--td-brand-color) 6%, transparent); - color: var(--td-brand-color); - box-shadow: 0 2px 6px color-mix(in srgb, var(--td-brand-color) 10%, transparent); + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-secondary); } - &.is-preview { - border-color: color-mix(in srgb, var(--td-brand-color) 50%, transparent); - background: color-mix(in srgb, var(--td-brand-color) 10%, transparent); - color: var(--td-brand-color); - } - - &:active { - transform: translateY(1px); - box-shadow: none; - } - - :deep(.t-button__icon) { - margin-right: 5px; - font-size: var(--app-text-lg); + &:focus-visible { + outline: none; + box-shadow: 0 0 0 2px color-mix(in srgb, var(--td-brand-color) 25%, transparent); } } @@ -1074,6 +1425,38 @@ onBeforeUnmount(() => { gap: 2px; } +.toolbar-menu-btn { + display: flex; + align-items: center; + gap: 2px; + height: 28px; + padding: 0 6px 0 8px; + border: none; + border-radius: var(--app-radius-sm); + background: transparent; + color: var(--td-text-color-secondary); + font-size: var(--app-text-sm); + font-weight: 500; + white-space: nowrap; + cursor: pointer; + transition: background var(--app-motion-base) ease, color var(--app-motion-base) ease; + + &:hover { + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); + } + + &:focus-visible { + outline: none; + box-shadow: 0 0 0 2px color-mix(in srgb, var(--td-brand-color) 25%, transparent); + } +} + +.toolbar-menu-btn__caret { + font-size: var(--app-text-sm); + opacity: 0.7; +} + .toolbar-divider { width: 1px; height: 18px; @@ -1090,11 +1473,11 @@ onBeforeUnmount(() => { border: none; background: transparent; cursor: pointer; - transition: all var(--app-motion-base) ease; + transition: background var(--app-motion-base) ease, color var(--app-motion-base) ease; display: flex; align-items: center; justify-content: center; - + .t-icon { color: var(--td-text-color-secondary); font-size: var(--app-text-xl); @@ -1104,20 +1487,11 @@ onBeforeUnmount(() => { } .toolbar-btn:hover { - background: color-mix(in srgb, var(--td-brand-color) 8%, transparent); - color: var(--td-brand-color); - - .t-icon { - color: var(--td-brand-color); - } -} + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); -.toolbar-btn.active { - background: color-mix(in srgb, var(--td-brand-color) 12%, transparent); - color: var(--td-brand-color); - .t-icon { - color: var(--td-brand-color); + color: var(--td-text-color-primary); } } @@ -1127,31 +1501,20 @@ onBeforeUnmount(() => { } .toolbar-btn:active { - background: color-mix(in srgb, var(--td-brand-color) 15%, transparent); + background: var(--td-bg-color-container-active); transform: translateY(0.5px); } -.editor-area { - /* 抽屉为整屏高,减去 header/footer/基本信息分组的大致高度, - 让编辑区占据剩余空间且不必撑满父级 flex 链路。 */ - height: calc(100vh - 360px); - min-height: 280px; +.editor-body { + flex: 1; + min-height: 0; display: flex; - flex-direction: column; - border: 1px solid var(--td-component-stroke); - border-radius: var(--app-radius-md); - overflow: hidden; - background: var(--td-bg-color-container); - transition: border-color var(--app-motion-base) ease, box-shadow var(--app-motion-base) ease; - - &:focus-within { - border-color: var(--td-brand-color); - box-shadow: 0 0 0 2px color-mix(in srgb, var(--td-brand-color) 10%, transparent); - } + align-items: stretch; } .editor-pane { flex: 1; + min-width: 0; min-height: 0; display: flex; flex-direction: column; @@ -1159,33 +1522,37 @@ onBeforeUnmount(() => { background: var(--td-bg-color-container); } -:deep(.editor-textarea) { - flex: 1; - min-height: 0; - display: flex; - flex-direction: column; - height: 100%; +/* 分屏时两栏之间给一道分隔线,预览栏底色略沉,区分“源码 / 成稿” */ +.editor-area--split { + .editor-pane--preview { + border-left: 1px solid var(--td-component-stroke); + background: var(--td-bg-color-secondarycontainer); + } - .t-textarea__inner { - flex: 1; - height: 100% !important; - resize: none; - border: none; - border-radius: 0; - padding: 14px 16px; - font-family: var(--app-font-family-mono); - font-size: var(--app-text-base); - line-height: 1.7; - background: var(--td-bg-color-container); - - &:focus { - box-shadow: none; - } + .preview-container { + background: var(--td-bg-color-secondarycontainer); } } -.editor-pane--preview { +.editor-textarea { + flex: 1; + min-height: 0; + width: 100%; + padding: 14px 16px; + border: none; + outline: none; + resize: none; + box-sizing: border-box; + font-family: var(--app-font-family-mono); + font-size: var(--app-text-base); + line-height: 1.7; + color: var(--td-text-color-primary); background: var(--td-bg-color-container); + tab-size: 2; + + &::placeholder { + color: var(--td-text-color-placeholder); + } } .preview-container { @@ -1220,17 +1587,21 @@ onBeforeUnmount(() => { overflow: auto; } + /* 与 chat-markdown.less 的引用块一致:中性描边、无底色 */ :deep(blockquote) { - border-left: 4px solid var(--td-brand-color); - padding-left: 12px; + border-left: 2px solid var(--td-component-stroke); + padding: 6px 0 6px 14px; color: var(--td-text-color-secondary); - margin: 16px 0; - background: color-mix(in srgb, var(--td-brand-color) 8%, transparent); + margin: 12px 0; } :deep(a) { color: var(--td-brand-color); } + + :deep(img) { + max-width: 100%; + } } .loading-wrapper, @@ -1247,3 +1618,69 @@ onBeforeUnmount(() => { color: var(--td-text-color-placeholder); } + + + diff --git a/frontend/src/components/settings/SettingDrawer.vue b/frontend/src/components/settings/SettingDrawer.vue index a6c02b32..11b30e47 100644 --- a/frontend/src/components/settings/SettingDrawer.vue +++ b/frontend/src/components/settings/SettingDrawer.vue @@ -1,6 +1,6 @@