@vetta-org/theme-ui 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -16
- package/src/action-approval/StorageCleanListView.test.tsx +36 -0
- package/src/action-approval/StorageCleanListView.tsx +52 -0
- package/src/action-approval/index.ts +2 -0
- package/src/activity/ActivityPanel.tsx +7 -1
- package/src/activity/ActivityPanelFrame.tsx +1 -1
- package/src/activity/BackgroundTasksTabPanelView.tsx +18 -2
- package/src/activity/BrowserPanelView.tsx +15 -1
- package/src/activity/BrowserSelectionView.tsx +199 -0
- package/src/activity/CodePreview.tsx +15 -1
- package/src/activity/MarkdownPreviewView.test.tsx +53 -0
- package/src/activity/MarkdownPreviewView.tsx +86 -10
- package/src/activity/index.ts +1 -0
- package/src/chat/ContextRingView.test.tsx +81 -0
- package/src/chat/ContextRingView.tsx +78 -62
- package/src/chat/EditDiffView.tsx +4 -4
- package/src/chat/HeaderActionBarView.tsx +135 -48
- package/src/chat/HeaderActionOverflowMenu.tsx +11 -20
- package/src/chat/MessageFeedLayoutView.tsx +6 -5
- package/src/chat/MessageInputView.tsx +5 -1
- package/src/chat/index.ts +2 -1
- package/src/chat/message-feed-fade.css +80 -0
- package/src/chat/message-feed-fade.test.tsx +75 -0
- package/src/chat/streaming-reveal.test.ts +1 -74
- package/src/chat/streaming-reveal.ts +0 -3
- package/src/file-preview/FilePreviewDialogView.tsx +2 -1
- package/src/file-preview/ReadonlyCodeView.tsx +46 -0
- package/src/file-preview/syntax-tokens.css +1 -1
- package/src/image-assets.d.ts +4 -0
- package/src/layout/ResizeHandle.tsx +4 -1
- package/src/layout/resize-handle-reset.test.tsx +50 -0
- package/src/markdown/FileLinkBadge.tsx +77 -0
- package/src/markdown/MarkdownContent.tsx +61 -31
- package/src/markdown/MarkdownImage.tsx +6 -16
- package/src/markdown/MermaidBlock.tsx +50 -11
- package/src/markdown/UrlLinkBadge.tsx +84 -0
- package/src/markdown/image-actions.ts +29 -0
- package/src/markdown/index.ts +2 -0
- package/src/markdown/nodes.ts +6 -1
- package/src/markdown/preview-policy.test.ts +31 -0
- package/src/markdown/preview-policy.ts +33 -0
- package/src/markdown/progressive-chunks.test.ts +43 -0
- package/src/markdown/progressive-chunks.ts +58 -0
- package/src/markdown/rich-labels.ts +9 -0
- package/src/markdown/streaming-fade.test.ts +83 -0
- package/src/markdown/streaming-fade.tsx +141 -0
- package/src/markdown/streaming-reveal.ts +0 -67
- package/src/markdown/streaming.ts +64 -131
- package/src/overlays/CommandMenuRow.tsx +47 -26
- package/src/overlays/CommandMenuView.tsx +107 -15
- package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
- package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
- package/src/overlays/ReleaseNoteImage.test.tsx +105 -0
- package/src/overlays/ReleaseNoteMarkdown.test.tsx +49 -0
- package/src/overlays/ReleaseNoteMarkdown.tsx +120 -7
- package/src/overlays/SplashPanel.tsx +4 -4
- package/src/overlays/SplashParts.tsx +6 -2
- package/src/overlays/UpdateCheckerView.tsx +17 -15
- package/src/overlays/UpdateRestartDialogView.tsx +76 -2
- package/src/overlays/assets/diagnostics-banner.webp +0 -0
- package/src/overlays/command-menu-types.ts +15 -1
- package/src/overlays/index.ts +13 -0
- package/src/plugin-ui/index.ts +4 -0
- package/src/project/DefaultConversationSectionView.tsx +17 -22
- package/src/project/DefaultSessionRowView.tsx +8 -0
- package/src/project/ManageSessionsSplashView.tsx +0 -2
- package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
- package/src/settings/GeneralSettingsView.tsx +21 -5
- package/src/settings/LauncherSettingsView.test.tsx +95 -0
- package/src/settings/LauncherSettingsView.tsx +272 -0
- package/src/settings/PetActionGalleryView.test.tsx +163 -0
- package/src/settings/PetActionGalleryView.tsx +216 -0
- package/src/settings/PetSettingsView.test.tsx +117 -0
- package/src/settings/PetSettingsView.tsx +86 -22
- package/src/settings/PresetProviderRowView.tsx +37 -98
- package/src/settings/ShortcutsSettingsView.tsx +0 -4
- package/src/settings/SpaceEditorDialogView.tsx +94 -56
- package/src/settings/SpacesSettingsView.tsx +53 -8
- package/src/settings/StorageBar.tsx +70 -0
- package/src/settings/StorageExplorer.tsx +488 -0
- package/src/settings/StorageReadout.tsx +64 -0
- package/src/settings/StorageSettingsView.test.tsx +181 -0
- package/src/settings/StorageSettingsView.tsx +458 -0
- package/src/settings/assets/space-editor-illustration.webp +0 -0
- package/src/settings/index.ts +28 -39
- package/src/settings/storage-treemap-layout.test.ts +32 -0
- package/src/settings/storage-treemap-layout.ts +55 -0
- package/src/shared/SegmentedControl.test.tsx +68 -0
- package/src/shared/SegmentedControl.tsx +18 -11
- package/src/shared/StageDialogContent.test.tsx +61 -0
- package/src/shared/StageDialogContent.tsx +80 -0
- package/src/shared/TabBar.tsx +2 -2
- package/src/shared/VettaKbd.tsx +20 -1
- package/src/shared/index.ts +4 -1
- package/src/shared/platform.ts +9 -0
- package/src/sidebar/AddProjectMenuTriggerView.tsx +13 -12
- package/src/sidebar/SettingsMenuTriggerView.tsx +2 -1
- package/src/sidebar/SidebarSectionActionButton.test.tsx +91 -0
- package/src/sidebar/SidebarSectionActionButton.tsx +52 -0
- package/src/styles.css +7 -0
- package/src/markdown/streaming.test.ts +0 -57
- package/src/settings/AchievementNavigationButtonView.tsx +0 -90
- package/src/settings/AchievementPromotionDialogView.tsx +0 -91
- package/src/settings/AchievementSettingsView.tsx +0 -43
- package/src/settings/PetBubbleStylePreviewView.tsx +0 -44
- package/src/settings/QuickPanelSettingsSectionView.tsx +0 -64
- package/src/settings/achievements/AchievementCurtains.tsx +0 -50
- package/src/settings/achievements/AchievementPromotionBadge3D.tsx +0 -350
- package/src/settings/achievements/AchievementPromotionConfetti.tsx +0 -71
- package/src/settings/achievements/AchievementTitle.tsx +0 -52
- package/src/settings/achievements/index.ts +0 -13
|
@@ -1,78 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
HOLD_MAX_MS,
|
|
4
|
-
holdBackUnclosedInline,
|
|
5
|
-
nextPhraseEnd,
|
|
6
|
-
planReveal,
|
|
7
|
-
snapToTokenBoundary,
|
|
8
|
-
splitStreamingSegments,
|
|
9
|
-
} from "./streaming-reveal";
|
|
10
|
-
|
|
11
|
-
describe("nextPhraseEnd", () => {
|
|
12
|
-
test("ends a phrase after latin punctuation followed by whitespace", () => {
|
|
13
|
-
expect(nextPhraseEnd("Hello there, world", 0, false)).toBe("Hello there,".length);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("keeps trailing latin punctuation pending until the next character arrives", () => {
|
|
17
|
-
expect(nextPhraseEnd("Hello there,", 0, false)).toBeNull();
|
|
18
|
-
expect(nextPhraseEnd("Hello there,", 0, true)).toBe("Hello there,".length);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("does not break inside numbers or dotted words", () => {
|
|
22
|
-
expect(nextPhraseEnd("pi is 3.14 and more", 0, false)).toBeNull();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("ends a phrase after CJK punctuation including closing quotes", () => {
|
|
26
|
-
expect(nextPhraseEnd("他说:“秋天到了。”然后走了", 0, false)).toBe("他说:".length);
|
|
27
|
-
expect(nextPhraseEnd("他说:“秋天到了。”然后走了", 3, false)).toBe("他说:“秋天到了。”".length);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("ends a phrase at a newline", () => {
|
|
31
|
-
expect(nextPhraseEnd("const a = 1\nconst b", 0, false)).toBe("const a = 1\n".length);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("treats an unfinished tail as pending unless final", () => {
|
|
35
|
-
expect(nextPhraseEnd("still typing", 0, false)).toBeNull();
|
|
36
|
-
expect(nextPhraseEnd("still typing", 0, true)).toBe("still typing".length);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("caps long unpunctuated runs, preferring whitespace", () => {
|
|
40
|
-
const latin = "word ".repeat(30);
|
|
41
|
-
const end = nextPhraseEnd(latin, 0, false);
|
|
42
|
-
expect(end).not.toBeNull();
|
|
43
|
-
expect(end).toBeLessThanOrEqual(48);
|
|
44
|
-
expect(latin[end as number]).toBe(" ");
|
|
45
|
-
|
|
46
|
-
const cjk = "秋".repeat(100);
|
|
47
|
-
expect(nextPhraseEnd(cjk, 0, false)).toBe(48);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("does not split a surrogate pair when capping", () => {
|
|
51
|
-
const text = `${"秋".repeat(47)}😀tail`;
|
|
52
|
-
expect(nextPhraseEnd(text, 0, false)).toBe(49);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("splitStreamingSegments", () => {
|
|
57
|
-
test("round-trips the source text", () => {
|
|
58
|
-
const text = "Hello, world! 你好世界,这是流式输出。\n indented 3.14 and more";
|
|
59
|
-
expect(splitStreamingSegments(text).join("")).toBe(text);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("splits into phrases with leading whitespace attached", () => {
|
|
63
|
-
expect(splitStreamingSegments("As twilight falls, the city wakes. Lights flicker")).toEqual([
|
|
64
|
-
"As twilight falls,",
|
|
65
|
-
" the city wakes.",
|
|
66
|
-
" Lights flicker",
|
|
67
|
-
]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("keeps earlier segments stable as text grows by whole phrases", () => {
|
|
71
|
-
const before = splitStreamingSegments("秋天来了,天气凉了,");
|
|
72
|
-
const after = splitStreamingSegments("秋天来了,天气凉了,树叶黄了。");
|
|
73
|
-
expect(after.slice(0, before.length)).toEqual(before);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
2
|
+
import { HOLD_MAX_MS, holdBackUnclosedInline, planReveal, snapToTokenBoundary } from "./streaming-reveal";
|
|
76
3
|
|
|
77
4
|
describe("snapToTokenBoundary", () => {
|
|
78
5
|
test("never splits a latin word or a number", () => {
|
|
@@ -3,11 +3,8 @@ export {
|
|
|
3
3
|
DEFAULT_RATE_PER_MS,
|
|
4
4
|
HOLD_MAX_MS,
|
|
5
5
|
holdBackUnclosedInline,
|
|
6
|
-
nextPhraseEnd,
|
|
7
6
|
planReveal,
|
|
8
7
|
REVEAL_TICK_MS,
|
|
9
|
-
STREAMING_SETTLE_MS,
|
|
10
8
|
STREAMING_STALL_FLUSH_MS,
|
|
11
9
|
snapToTokenBoundary,
|
|
12
|
-
splitStreamingSegments,
|
|
13
10
|
} from "../markdown/streaming-reveal";
|
|
@@ -64,7 +64,8 @@ export function FilePreviewDialogView({
|
|
|
64
64
|
{context && item && (
|
|
65
65
|
<motion.div
|
|
66
66
|
// no-drag:盖住下层页面顶部的 -webkit-app-region: drag,否则那块区域的点击会被系统拖窗口接管,浮层按钮点不了
|
|
67
|
-
|
|
67
|
+
// z-[110]:灯箱总是用户主动打开的,要盖过 z-[100] 的模态弹窗(如版本介绍里点配图),仍低于右键菜单 z-[120]
|
|
68
|
+
className="no-drag fixed inset-0 z-[110] bg-background/95"
|
|
68
69
|
initial={{ opacity: 0 }}
|
|
69
70
|
animate={{ opacity: 1 }}
|
|
70
71
|
exit={{ opacity: 0 }}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { EditorState } from "@codemirror/state";
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import { basicSetup } from "codemirror";
|
|
4
|
+
import { useEffect, useRef, type JSX } from "react";
|
|
5
|
+
import { textCodeEditorTheme } from "./text-code-editor-theme";
|
|
6
|
+
import { getTextEditorLanguageExtension, normalizeFileExtension } from "./text-editor-language";
|
|
7
|
+
|
|
8
|
+
const fillPane = EditorView.theme({ "&": { height: "100%" } });
|
|
9
|
+
|
|
10
|
+
export interface ReadonlyCodeViewProps {
|
|
11
|
+
content: string;
|
|
12
|
+
extension: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read-only CodeMirror for sources too large to highlight whole. It lays out and
|
|
17
|
+
* highlights only the visible lines, so opening a multi-megabyte file stays responsive.
|
|
18
|
+
*/
|
|
19
|
+
export function ReadonlyCodeView({ content, extension }: ReadonlyCodeViewProps): JSX.Element {
|
|
20
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
21
|
+
const languageKey = normalizeFileExtension(extension);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
const host = hostRef.current;
|
|
25
|
+
if (!host) return;
|
|
26
|
+
const view = new EditorView({
|
|
27
|
+
state: EditorState.create({
|
|
28
|
+
doc: content,
|
|
29
|
+
extensions: [
|
|
30
|
+
basicSetup,
|
|
31
|
+
EditorState.readOnly.of(true),
|
|
32
|
+
EditorView.editable.of(false),
|
|
33
|
+
getTextEditorLanguageExtension(languageKey),
|
|
34
|
+
textCodeEditorTheme,
|
|
35
|
+
// Fill the preview pane and scroll inside the editor, so long lines get their
|
|
36
|
+
// own horizontal scrollbar instead of one at the bottom of the whole file.
|
|
37
|
+
fillPane,
|
|
38
|
+
],
|
|
39
|
+
}),
|
|
40
|
+
parent: host,
|
|
41
|
+
});
|
|
42
|
+
return () => view.destroy();
|
|
43
|
+
}, [content, languageKey]);
|
|
44
|
+
|
|
45
|
+
return <div ref={hostRef} className="h-full min-h-0 w-full bg-background" />;
|
|
46
|
+
}
|
|
@@ -11,6 +11,8 @@ export interface ResizeHandleProps {
|
|
|
11
11
|
onResizeStart?: () => void;
|
|
12
12
|
onResize: (delta: number) => void;
|
|
13
13
|
onResizeEnd?: () => void;
|
|
14
|
+
/** 双击把手(常见约定:恢复默认尺寸)。 */
|
|
15
|
+
onReset?: () => void;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export interface ResizeHandleAxis {
|
|
@@ -58,7 +60,7 @@ export function resizeHandleDelta(side: ResizeHandleSide, pointerDelta: number):
|
|
|
58
60
|
return side === "right" || side === "bottom" ? pointerDelta : -pointerDelta;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
export function ResizeHandle({ side, onResizeStart, onResize, onResizeEnd }: ResizeHandleProps): JSX.Element {
|
|
63
|
+
export function ResizeHandle({ side, onResizeStart, onResize, onResizeEnd, onReset }: ResizeHandleProps): JSX.Element {
|
|
62
64
|
const startRef = useRef(0);
|
|
63
65
|
const axis = resolveResizeHandleAxis(side);
|
|
64
66
|
|
|
@@ -125,6 +127,7 @@ export function ResizeHandle({ side, onResizeStart, onResize, onResizeEnd }: Res
|
|
|
125
127
|
<div
|
|
126
128
|
data-resize-handle={side}
|
|
127
129
|
onPointerDown={onPointerDown}
|
|
130
|
+
onDoubleClick={onReset}
|
|
128
131
|
className={`group absolute z-30 ${axis.cursorClass} ${axis.track} ${axis.edge}`}
|
|
129
132
|
>
|
|
130
133
|
<div
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, createElement, useState } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { ResizeHandle } from "./ResizeHandle";
|
|
6
|
+
|
|
7
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
|
|
9
|
+
const DEFAULT_WIDTH = 360;
|
|
10
|
+
const USER_WIDTH = 520;
|
|
11
|
+
|
|
12
|
+
// 和宿主一样:拖动累加宽度,双击回到默认宽度;把面板当前宽度与是否在拖动渲染出来。
|
|
13
|
+
function Panel() {
|
|
14
|
+
const [width, setWidth] = useState(USER_WIDTH);
|
|
15
|
+
const [dragging, setDragging] = useState(false);
|
|
16
|
+
return createElement(
|
|
17
|
+
"section",
|
|
18
|
+
{ "data-width": width, "data-dragging": dragging },
|
|
19
|
+
createElement(ResizeHandle, {
|
|
20
|
+
side: "left",
|
|
21
|
+
onResizeStart: () => setDragging(true),
|
|
22
|
+
onResize: (delta: number) => setWidth((current) => current + delta),
|
|
23
|
+
onResizeEnd: () => setDragging(false),
|
|
24
|
+
onReset: () => setWidth(DEFAULT_WIDTH),
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 双击把手是「恢复默认尺寸」的常见约定;宿主据此把活动面板回到当前标签卡的默认宽度。
|
|
30
|
+
it("双击把手触发 onReset,不当作一次拖动", () => {
|
|
31
|
+
const host = document.createElement("div");
|
|
32
|
+
document.body.append(host);
|
|
33
|
+
const root = createRoot(host);
|
|
34
|
+
act(() => root.render(createElement(Panel)));
|
|
35
|
+
|
|
36
|
+
const panel = host.querySelector<HTMLElement>("section");
|
|
37
|
+
const handle = host.querySelector<HTMLElement>("[data-resize-handle]");
|
|
38
|
+
expect(panel?.dataset.width).toBe(String(USER_WIDTH));
|
|
39
|
+
act(() => {
|
|
40
|
+
handle?.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 面板正好落在默认宽度:没有叠加任何拖动位移,也没有进入拖动态(不挂拖动遮罩、不锁选区)。
|
|
44
|
+
expect(panel?.dataset.width).toBe(String(DEFAULT_WIDTH));
|
|
45
|
+
expect(panel?.dataset.dragging).toBe("false");
|
|
46
|
+
expect(document.body.children).toHaveLength(1);
|
|
47
|
+
expect(document.body.style.userSelect).toBe("");
|
|
48
|
+
act(() => root.unmount());
|
|
49
|
+
host.remove();
|
|
50
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { JSX, MouseEvent, ReactNode } from "react";
|
|
3
|
+
import { ContextMenuView } from "../shared/ContextMenuView";
|
|
4
|
+
import type { ContextMenuNode } from "../shared/ContextMenuView";
|
|
5
|
+
|
|
6
|
+
export interface FileLinkMenuLabels {
|
|
7
|
+
open: string;
|
|
8
|
+
/** 平台相关:macOS「在访达中显示」,Windows「在资源管理器中显示」。 */
|
|
9
|
+
reveal: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface FileLinkBadgeProps {
|
|
13
|
+
path: string;
|
|
14
|
+
className: string;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
menuLabels?: FileLinkMenuLabels;
|
|
17
|
+
onOpen: (path: string) => void;
|
|
18
|
+
/** 宿主能在本机文件管理器里定位该文件时才传;不传则右键保持浏览器默认行为。 */
|
|
19
|
+
onReveal?: (path: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 消息里的文件徽标:左键在应用内预览,右键菜单可在系统文件管理器中定位。 */
|
|
23
|
+
export function FileLinkBadge({
|
|
24
|
+
path,
|
|
25
|
+
className,
|
|
26
|
+
children,
|
|
27
|
+
menuLabels,
|
|
28
|
+
onOpen,
|
|
29
|
+
onReveal,
|
|
30
|
+
}: FileLinkBadgeProps): JSX.Element {
|
|
31
|
+
const [menu, setMenu] = useState<{ x: number; y: number } | null>(null);
|
|
32
|
+
const canReveal = onReveal !== undefined && menuLabels !== undefined;
|
|
33
|
+
|
|
34
|
+
const handleContextMenu = (event: MouseEvent<HTMLButtonElement>): void => {
|
|
35
|
+
if (!canReveal) return;
|
|
36
|
+
// 有选中文字时让会话的「复制 / 加入输入框」菜单接手。
|
|
37
|
+
const selection = window.getSelection();
|
|
38
|
+
if (selection && !selection.isCollapsed) return;
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
setMenu({ x: event.clientX, y: event.clientY });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const items: ContextMenuNode[] = canReveal
|
|
45
|
+
? [
|
|
46
|
+
{
|
|
47
|
+
kind: "item",
|
|
48
|
+
id: "open",
|
|
49
|
+
label: menuLabels.open,
|
|
50
|
+
iconClassName: "icon-[solar--eye-linear]",
|
|
51
|
+
onSelect: () => onOpen(path),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
kind: "item",
|
|
55
|
+
id: "reveal",
|
|
56
|
+
label: menuLabels.reveal,
|
|
57
|
+
iconClassName: "icon-[solar--folder-open-linear]",
|
|
58
|
+
onSelect: () => onReveal(path),
|
|
59
|
+
},
|
|
60
|
+
]
|
|
61
|
+
: [];
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
title={path}
|
|
68
|
+
className={className}
|
|
69
|
+
onClick={() => onOpen(path)}
|
|
70
|
+
onContextMenu={handleContextMenu}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</button>
|
|
74
|
+
{menu ? <ContextMenuView items={items} x={menu.x} y={menu.y} onClose={() => setMenu(null)} /> : null}
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -22,10 +22,18 @@ import {
|
|
|
22
22
|
} from "../shared/MarkdownTable";
|
|
23
23
|
import { SkillTypeIcon } from "../skills/skill-icon";
|
|
24
24
|
import { InlineTokenChip } from "./InlineTokenChip";
|
|
25
|
+
import { FileLinkBadge } from "./FileLinkBadge";
|
|
26
|
+
import { type OpenUrlHandler, UrlLinkBadge } from "./UrlLinkBadge";
|
|
25
27
|
import { WebsiteIcon } from "./WebsiteIcon";
|
|
26
28
|
import { useRenderSnapshot } from "./use-render-snapshot";
|
|
27
29
|
import { chatUrlTransform, classifyMarkdownLink, normalizeLocalFileLinksInMarkdown } from "./markdown-link";
|
|
28
|
-
import { useStreamingDisplayText
|
|
30
|
+
import { useStreamingDisplayText } from "./streaming";
|
|
31
|
+
import {
|
|
32
|
+
rehypeStreamingFade,
|
|
33
|
+
STREAMING_FADE_TAG,
|
|
34
|
+
StreamingFadeSpan,
|
|
35
|
+
type StreamingReveal,
|
|
36
|
+
} from "./streaming-fade";
|
|
29
37
|
import {
|
|
30
38
|
INLINE_TOKEN_TAG,
|
|
31
39
|
rehypeInlineTokens,
|
|
@@ -60,7 +68,10 @@ export interface MarkdownContentProps {
|
|
|
60
68
|
labels: MarkdownLabels;
|
|
61
69
|
getFileIconClass: (fileName: string) => string;
|
|
62
70
|
onOpenFile: (path: string) => void;
|
|
63
|
-
|
|
71
|
+
/** 在系统文件管理器中定位文件;传入后文件徽标右键出现「在访达中显示」。 */
|
|
72
|
+
onRevealFile?: (path: string) => void;
|
|
73
|
+
/** `alternate` 为 true 时改用非默认的打开方式(右键第二项、⌘/Ctrl+点击)。 */
|
|
74
|
+
onOpenUrl: OpenUrlHandler;
|
|
64
75
|
/** 传入即启用行内 token 渲染;仅用户消息需要,助手 markdown 不受影响。 */
|
|
65
76
|
inlineTokens?: InlineTokenSupport;
|
|
66
77
|
}
|
|
@@ -75,12 +86,14 @@ function basename(path: string): string {
|
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
interface MarkdownDocumentProps {
|
|
78
|
-
animateChunks: boolean;
|
|
79
89
|
components: Components;
|
|
80
90
|
definition: MarkdownDefinition;
|
|
81
91
|
inlineTokens?: InlineTokenSupport;
|
|
82
92
|
live: boolean;
|
|
83
93
|
text: string;
|
|
94
|
+
/** 流式尾块里仍在淡入的放出区间,与本文档在整段显示文本中的起始下标。 */
|
|
95
|
+
reveals?: readonly StreamingReveal[];
|
|
96
|
+
revealOffset?: number;
|
|
84
97
|
}
|
|
85
98
|
|
|
86
99
|
/**
|
|
@@ -88,21 +101,24 @@ interface MarkdownDocumentProps {
|
|
|
88
101
|
* 已提交块不会跟着整篇重跑 remark;流式结束后分块结构保持不变,已提交块不会重挂。
|
|
89
102
|
*/
|
|
90
103
|
const MarkdownDocument = memo(function MarkdownDocument({
|
|
91
|
-
animateChunks,
|
|
92
104
|
components,
|
|
93
105
|
definition,
|
|
94
106
|
inlineTokens,
|
|
95
107
|
live,
|
|
96
108
|
text,
|
|
109
|
+
reveals,
|
|
110
|
+
revealOffset = 0,
|
|
97
111
|
}: MarkdownDocumentProps): JSX.Element {
|
|
98
112
|
const hasStructuredAnnotations = inlineTokens?.annotations !== undefined;
|
|
113
|
+
const markdownSource = useMemo(() => normalizeLocalFileLinksInMarkdown(text), [text]);
|
|
114
|
+
// 改写过本地文件链接的源码与显示文本坐标对不上,这时不淡入,免得包错位置。
|
|
115
|
+
const fadeReveals = reveals && reveals.length > 0 && markdownSource === text ? reveals : undefined;
|
|
99
116
|
const rehypePlugins = useMemo(() => {
|
|
100
117
|
const plugins: NonNullable<Options["rehypePlugins"]> = [...(definition.rehypePlugins ?? [])];
|
|
101
|
-
if (
|
|
118
|
+
if (fadeReveals) plugins.push(rehypeStreamingFade(fadeReveals, revealOffset));
|
|
102
119
|
if (inlineTokens && !hasStructuredAnnotations) plugins.push(() => rehypeInlineTokens(inlineTokens.parse));
|
|
103
120
|
return plugins.length > 0 ? plugins : undefined;
|
|
104
|
-
}, [
|
|
105
|
-
const markdownSource = useMemo(() => normalizeLocalFileLinksInMarkdown(text), [text]);
|
|
121
|
+
}, [fadeReveals, revealOffset, hasStructuredAnnotations, inlineTokens, definition]);
|
|
106
122
|
const normalizedAnnotations = useMemo(
|
|
107
123
|
() =>
|
|
108
124
|
inlineTokens?.annotations
|
|
@@ -143,8 +159,8 @@ const MarkdownDocument = memo(function MarkdownDocument({
|
|
|
143
159
|
* Memo'd markdown renderer for chat text blocks. Host injects file/url handlers and theme.
|
|
144
160
|
*
|
|
145
161
|
* `components` 映射的函数引用必须在 streaming 期间保持稳定:React 把 components.p 等
|
|
146
|
-
* 当成元素类型;引用一变就会整树 remount
|
|
147
|
-
*
|
|
162
|
+
* 当成元素类型;引用一变就会整树 remount,已有文本整段重挂,表现为 text block 高频闪烁。
|
|
163
|
+
* labels / 回调通过 ref 读取,不进 deps。
|
|
148
164
|
*/
|
|
149
165
|
export const MarkdownContent = memo(function MarkdownContent({
|
|
150
166
|
text,
|
|
@@ -154,6 +170,7 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
154
170
|
labels,
|
|
155
171
|
getFileIconClass,
|
|
156
172
|
onOpenFile,
|
|
173
|
+
onRevealFile,
|
|
157
174
|
onOpenUrl,
|
|
158
175
|
inlineTokens,
|
|
159
176
|
definition: definitionOverride,
|
|
@@ -163,9 +180,7 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
163
180
|
const definition = definitionOverride ?? inheritedDefinition;
|
|
164
181
|
const definitionRef = useRef(definition);
|
|
165
182
|
definitionRef.current = definition;
|
|
166
|
-
const { displayText,
|
|
167
|
-
const chunkedRef = useRef(false);
|
|
168
|
-
if (animateChunks) chunkedRef.current = true;
|
|
183
|
+
const { text: displayText, reveals } = useStreamingDisplayText(text, isStreamingTail);
|
|
169
184
|
const frozenBlocksRef = useRef(false);
|
|
170
185
|
if (isStreamingTail && !inlineTokens) frozenBlocksRef.current = true;
|
|
171
186
|
const splitDocuments = frozenBlocksRef.current && !inlineTokens;
|
|
@@ -185,11 +200,13 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
185
200
|
const labelsRef = useRef(labels);
|
|
186
201
|
const getFileIconClassRef = useRef(getFileIconClass);
|
|
187
202
|
const onOpenFileRef = useRef(onOpenFile);
|
|
203
|
+
const onRevealFileRef = useRef(onRevealFile);
|
|
188
204
|
const onOpenUrlRef = useRef(onOpenUrl);
|
|
189
205
|
const inlineTokensRef = useRef(inlineTokens);
|
|
190
206
|
labelsRef.current = labels;
|
|
191
207
|
getFileIconClassRef.current = getFileIconClass;
|
|
192
208
|
onOpenFileRef.current = onOpenFile;
|
|
209
|
+
onRevealFileRef.current = onRevealFile;
|
|
193
210
|
onOpenUrlRef.current = onOpenUrl;
|
|
194
211
|
inlineTokensRef.current = inlineTokens;
|
|
195
212
|
|
|
@@ -253,34 +270,48 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
253
270
|
const label =
|
|
254
271
|
typeof children === "string" && ABSOLUTE_PATH_LABEL.test(children.trim()) ? basename(children.trim()) : children;
|
|
255
272
|
return (
|
|
256
|
-
<
|
|
257
|
-
|
|
258
|
-
title={kind.path}
|
|
273
|
+
<FileLinkBadge
|
|
274
|
+
path={kind.path}
|
|
259
275
|
className={cn(LINK_BADGE_CLASS, "cursor-pointer")}
|
|
260
|
-
|
|
276
|
+
menuLabels={labelsRef.current.fileLink}
|
|
277
|
+
onOpen={(path) => onOpenFileRef.current(path)}
|
|
278
|
+
onReveal={onRevealFileRef.current ? (path) => onRevealFileRef.current?.(path) : undefined}
|
|
261
279
|
>
|
|
262
280
|
<span className={cn(getFileIconClassRef.current(fileName), "h-3.5 w-3.5 shrink-0")} />
|
|
263
281
|
<span className="truncate">{label}</span>
|
|
264
|
-
</
|
|
282
|
+
</FileLinkBadge>
|
|
265
283
|
);
|
|
266
284
|
}
|
|
267
285
|
if (kind.type === "url") {
|
|
268
286
|
return (
|
|
269
|
-
<
|
|
270
|
-
|
|
271
|
-
title={kind.url}
|
|
287
|
+
<UrlLinkBadge
|
|
288
|
+
url={kind.url}
|
|
272
289
|
className={LINK_BADGE_CLASS}
|
|
290
|
+
menuLabels={labelsRef.current.urlLink}
|
|
291
|
+
onOpen={(...args) => onOpenUrlRef.current(...args)}
|
|
292
|
+
>
|
|
293
|
+
<WebsiteIcon href={kind.url} />
|
|
294
|
+
<span className="truncate">{children}</span>
|
|
295
|
+
</UrlLinkBadge>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
// 邮件地址交给宿主(系统邮件客户端),不进内置浏览器。
|
|
299
|
+
if (/^mailto:/i.test(kind.href)) {
|
|
300
|
+
return (
|
|
301
|
+
<a
|
|
302
|
+
href={kind.href}
|
|
303
|
+
title={kind.href}
|
|
304
|
+
className="text-chart-2 underline decoration-chart-2/30"
|
|
273
305
|
onClick={(e) => {
|
|
274
306
|
e.preventDefault();
|
|
275
|
-
onOpenUrlRef.current(kind.
|
|
307
|
+
onOpenUrlRef.current(kind.href);
|
|
276
308
|
}}
|
|
277
309
|
>
|
|
278
|
-
|
|
279
|
-
<span className="truncate">{children}</span>
|
|
310
|
+
{children}
|
|
280
311
|
</a>
|
|
281
312
|
);
|
|
282
313
|
}
|
|
283
|
-
//
|
|
314
|
+
// fragment / unknown: never target=_blank — that opens the OS browser
|
|
284
315
|
// for misclassified local paths. Keep visible but non-navigating.
|
|
285
316
|
return (
|
|
286
317
|
<span className="text-chart-2 underline decoration-chart-2/30" title={kind.href || undefined}>
|
|
@@ -289,6 +320,7 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
289
320
|
);
|
|
290
321
|
},
|
|
291
322
|
strong: ({ children }) => <strong className="font-semibold text-foreground">{children}</strong>,
|
|
323
|
+
[STREAMING_FADE_TAG]: StreamingFadeSpan,
|
|
292
324
|
"vetta-svg": ({ node }: { node?: HastElement }) => {
|
|
293
325
|
const source = node?.properties?.source;
|
|
294
326
|
const rich = labelsRef.current.rich ?? defaultRichContentLabels;
|
|
@@ -370,10 +402,7 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
370
402
|
[theme],
|
|
371
403
|
);
|
|
372
404
|
|
|
373
|
-
//
|
|
374
|
-
// 表现为回复结尾「卡一下」。「最新短语略暗」只挂在包裹类上,撤掉包裹类就恢复全亮,DOM 不动。
|
|
375
|
-
// 切块一旦启用就保持到实例卸载:流式结束时 `animateChunks` 要等 settle 才关,若此刻把
|
|
376
|
-
// 已冻结块并回单一文档,已上屏的节点会整段重挂并再包成 `.streaming-chunk` 重放淡入。
|
|
405
|
+
// 切块一旦启用就保持到实例卸载:流式结束时若把已冻结块并回单一文档,已上屏的节点会整段重挂。
|
|
377
406
|
// 稳定块只按已闭合的顶层围栏切分,分块与整篇渲染结果一致,因此结束后不需要再合并。
|
|
378
407
|
const split = useMemo(
|
|
379
408
|
() => renderText === displayText ? candidateSplit : splitDocuments ? splitStableMarkdownBlocks(renderText) : null,
|
|
@@ -384,11 +413,10 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
384
413
|
const showTail = !split || tail.length > 0 || committed.length === 0;
|
|
385
414
|
|
|
386
415
|
return (
|
|
387
|
-
<MarkdownHostProvider host={host}><div className={cn("markdown-body break-words",
|
|
416
|
+
<MarkdownHostProvider host={host}><div className={cn("markdown-body break-words", className)}>
|
|
388
417
|
{committed.map((block, index) => (
|
|
389
418
|
<MarkdownDocument
|
|
390
419
|
key={`committed-${index}`}
|
|
391
|
-
animateChunks={false}
|
|
392
420
|
components={components}
|
|
393
421
|
definition={definition}
|
|
394
422
|
live={false}
|
|
@@ -398,12 +426,14 @@ export const MarkdownContent = memo(function MarkdownContent({
|
|
|
398
426
|
{showTail ? (
|
|
399
427
|
<MarkdownDocument
|
|
400
428
|
key="tail"
|
|
401
|
-
animateChunks={chunkedRef.current}
|
|
402
429
|
components={components}
|
|
403
430
|
definition={definition}
|
|
404
431
|
inlineTokens={inlineTokens}
|
|
405
432
|
live={isStreamingTail}
|
|
406
433
|
text={tail}
|
|
434
|
+
// 长尾块降频解析时不淡入:放出记录每次都变,会绕过降频逐次重解析。
|
|
435
|
+
reveals={renderInterval === 0 ? reveals : undefined}
|
|
436
|
+
revealOffset={renderText.length - tail.length}
|
|
407
437
|
/>
|
|
408
438
|
) : null}
|
|
409
439
|
</div></MarkdownHostProvider>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Button } from "@vetta-org/ui/button";
|
|
2
|
-
import { memo, useEffect,
|
|
2
|
+
import { memo, useEffect, useState } from "react";
|
|
3
3
|
import { useMarkdownHost } from "./host";
|
|
4
|
+
import { useImageActions } from "./image-actions";
|
|
4
5
|
import type { MarkdownLabels } from "./rich-labels";
|
|
5
6
|
import { defaultRichContentLabels } from "./rich-labels";
|
|
6
7
|
import { useRichVisibility } from "./use-rich-visibility";
|
|
@@ -12,9 +13,8 @@ export const MarkdownImage = memo(function MarkdownImage({ src = "", alt = "", t
|
|
|
12
13
|
const [attempt, setAttempt] = useState(0);
|
|
13
14
|
const [result, setResult] = useState<{ source: string; url: string }>();
|
|
14
15
|
const [failed, setFailed] = useState(false);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
useEffect(() => () => { generation.current++; }, [src]);
|
|
16
|
+
const url = result?.source === src ? result.url : undefined;
|
|
17
|
+
const { action, setAction, run, busy } = useImageActions(host, url, src);
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
if (!active || !src) return;
|
|
20
20
|
let cancelled = false;
|
|
@@ -24,16 +24,6 @@ export const MarkdownImage = memo(function MarkdownImage({ src = "", alt = "", t
|
|
|
24
24
|
void request.then((url) => { if (!cancelled) setResult({ source: src, url }); }, () => { if (!cancelled) setFailed(true); });
|
|
25
25
|
return () => { cancelled = true; };
|
|
26
26
|
}, [active, host, src, attempt]);
|
|
27
|
-
const url = result?.source === src ? result.url : undefined;
|
|
28
|
-
const run = async (kind: "copy" | "save") => {
|
|
29
|
-
if (!host || !url) return;
|
|
30
|
-
const current = generation.current;
|
|
31
|
-
setAction(kind);
|
|
32
|
-
try {
|
|
33
|
-
await (kind === "copy" ? host.copyImage(url) : host.saveImage(url));
|
|
34
|
-
if (current === generation.current) setAction(kind === "copy" ? "copied" : null);
|
|
35
|
-
} catch { if (current === generation.current) setAction("failed"); }
|
|
36
|
-
};
|
|
37
27
|
return <span ref={ref} className="my-2 inline-flex max-w-full flex-col gap-1 align-top">
|
|
38
28
|
{failed ? <span role="status">{rich.imageFailed ?? rich.failed} {alt}</span> : url ? (
|
|
39
29
|
<img key={`${url}:${attempt}`} src={url} alt={alt} title={title} loading="lazy" decoding="async" referrerPolicy="no-referrer" className="max-h-96 max-w-full rounded object-contain" onError={() => setFailed(true)} />
|
|
@@ -42,8 +32,8 @@ export const MarkdownImage = memo(function MarkdownImage({ src = "", alt = "", t
|
|
|
42
32
|
{failed && <Button variant="ghost" size="sm" onClick={(event) => { event.preventDefault(); event.stopPropagation(); setFailed(false); setAttempt((value) => value + 1); }}>{rich.retry ?? "Retry"}</Button>}
|
|
43
33
|
{host && url && !failed && <>
|
|
44
34
|
<Button variant="ghost" size="sm" onClick={(event) => { event.preventDefault(); event.stopPropagation(); host.openImage(url, alt); }}>{rich.enlarge ?? "Enlarge"}</Button>
|
|
45
|
-
<Button variant="ghost" size="sm" disabled={
|
|
46
|
-
<Button variant="ghost" size="sm" disabled={
|
|
35
|
+
<Button variant="ghost" size="sm" disabled={busy} onClick={(event) => { event.preventDefault(); event.stopPropagation(); void run("copy"); }}>{action === "copied" ? labels.copied : labels.copy}</Button>
|
|
36
|
+
<Button variant="ghost" size="sm" disabled={busy} onClick={(event) => { event.preventDefault(); event.stopPropagation(); void run("save"); }}>{rich.save ?? "Save"}</Button>
|
|
47
37
|
</>}
|
|
48
38
|
</span>
|
|
49
39
|
{action === "failed" && <span role="status">{rich.actionFailed ?? rich.failed}</span>}
|