@vetta-org/theme-ui 0.1.2 → 0.2.0
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/activity/ActivityPanelFrame.tsx +1 -1
- package/src/activity/CodePreview.tsx +15 -1
- package/src/activity/MarkdownPreviewView.test.tsx +53 -0
- package/src/activity/MarkdownPreviewView.tsx +86 -10
- package/src/chat/ContextRingView.test.tsx +81 -0
- package/src/chat/ContextRingView.tsx +78 -62
- package/src/chat/HeaderActionBarView.tsx +122 -47
- 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/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/markdown/FileLinkBadge.tsx +77 -0
- package/src/markdown/MarkdownContent.tsx +12 -5
- package/src/markdown/MarkdownImage.tsx +6 -16
- package/src/markdown/MermaidBlock.tsx +50 -11
- package/src/markdown/image-actions.ts +29 -0
- package/src/markdown/index.ts +1 -0
- 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 +6 -0
- package/src/overlays/CommandMenuRow.tsx +43 -12
- package/src/overlays/CommandMenuView.tsx +96 -11
- package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
- package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
- package/src/overlays/ReleaseNoteMarkdown.test.tsx +24 -0
- package/src/overlays/ReleaseNoteMarkdown.tsx +26 -0
- package/src/overlays/SplashPanel.tsx +4 -4
- package/src/overlays/SplashParts.tsx +6 -2
- package/src/overlays/UpdateRestartDialogView.tsx +65 -0
- package/src/overlays/assets/diagnostics-banner.webp +0 -0
- package/src/overlays/command-menu-types.ts +13 -1
- package/src/overlays/index.ts +12 -0
- package/src/plugin-ui/index.ts +2 -0
- package/src/project/DefaultConversationSectionView.tsx +13 -22
- package/src/project/DefaultSessionRowView.tsx +8 -0
- package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
- package/src/settings/GeneralSettingsView.tsx +2 -5
- package/src/settings/LauncherSettingsView.test.tsx +95 -0
- package/src/settings/LauncherSettingsView.tsx +273 -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/assets/space-editor-illustration.webp +0 -0
- package/src/settings/index.ts +18 -39
- package/src/shared/SegmentedControl.test.tsx +68 -0
- package/src/shared/SegmentedControl.tsx +10 -2
- package/src/shared/TabBar.tsx +2 -2
- package/src/shared/VettaKbd.tsx +20 -1
- package/src/shared/index.ts +2 -1
- package/src/shared/platform.ts +9 -0
- package/src/sidebar/AddProjectMenuTriggerView.tsx +11 -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 +2 -0
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vetta-org/theme-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -822,6 +822,10 @@
|
|
|
822
822
|
"types": "./src/sidebar/SidebarFilterSelectView.tsx",
|
|
823
823
|
"import": "./src/sidebar/SidebarFilterSelectView.tsx"
|
|
824
824
|
},
|
|
825
|
+
"./sidebar/SidebarSectionActionButton": {
|
|
826
|
+
"types": "./src/sidebar/SidebarSectionActionButton.tsx",
|
|
827
|
+
"import": "./src/sidebar/SidebarSectionActionButton.tsx"
|
|
828
|
+
},
|
|
825
829
|
"./sidebar/SidebarTopBar": {
|
|
826
830
|
"types": "./src/sidebar/SidebarTopBar.tsx",
|
|
827
831
|
"import": "./src/sidebar/SidebarTopBar.tsx"
|
|
@@ -859,8 +863,8 @@
|
|
|
859
863
|
"@lezer/highlight": "1.2.3",
|
|
860
864
|
"@lobehub/icons-static-svg": "1.95.0",
|
|
861
865
|
"@tanstack/react-virtual": "^3.14.26",
|
|
862
|
-
"@vetta-org/theme-sdk": "^0.
|
|
863
|
-
"@vetta-org/ui": "^0.1.
|
|
866
|
+
"@vetta-org/theme-sdk": "^0.2.0",
|
|
867
|
+
"@vetta-org/ui": "^0.1.2",
|
|
864
868
|
"codemirror": "^6.0.2",
|
|
865
869
|
"katex": "^0.18.7",
|
|
866
870
|
"mdast-util-from-markdown": "^2.0.3",
|
|
@@ -872,23 +876,18 @@
|
|
|
872
876
|
},
|
|
873
877
|
"peerDependencies": {
|
|
874
878
|
"@xyflow/react": "^12.0.0",
|
|
875
|
-
"canvas-confetti": "^1.9.0",
|
|
876
879
|
"motion": "^12.0.0",
|
|
877
880
|
"react": "^19.0.0",
|
|
878
881
|
"react-dom": "^19.0.0",
|
|
879
882
|
"react-markdown": "^10.0.0",
|
|
880
883
|
"react-virtuoso": "^4.0.0",
|
|
881
884
|
"remark-gfm": "^4.0.0",
|
|
882
|
-
"shiki": ">=3.0.0"
|
|
883
|
-
"three": "^0.185.0"
|
|
885
|
+
"shiki": ">=3.0.0"
|
|
884
886
|
},
|
|
885
887
|
"peerDependenciesMeta": {
|
|
886
888
|
"@xyflow/react": {
|
|
887
889
|
"optional": true
|
|
888
890
|
},
|
|
889
|
-
"canvas-confetti": {
|
|
890
|
-
"optional": true
|
|
891
|
-
},
|
|
892
891
|
"react-markdown": {
|
|
893
892
|
"optional": true
|
|
894
893
|
},
|
|
@@ -900,24 +899,17 @@
|
|
|
900
899
|
},
|
|
901
900
|
"shiki": {
|
|
902
901
|
"optional": true
|
|
903
|
-
},
|
|
904
|
-
"three": {
|
|
905
|
-
"optional": true
|
|
906
902
|
}
|
|
907
903
|
},
|
|
908
904
|
"devDependencies": {
|
|
909
|
-
"@types/canvas-confetti": "^1.9.0",
|
|
910
905
|
"@types/react": "^19.1.1",
|
|
911
906
|
"@types/react-dom": "^19.1.1",
|
|
912
|
-
"@types/three": "^0.185.0",
|
|
913
907
|
"@xyflow/react": "^12.10.2",
|
|
914
|
-
"canvas-confetti": "^1.9.4",
|
|
915
908
|
"motion": "^12.23.12",
|
|
916
909
|
"react-markdown": "^10.1.0",
|
|
917
910
|
"react-virtuoso": "^4.18.14",
|
|
918
911
|
"remark-gfm": "^4.0.1",
|
|
919
912
|
"shiki": "^4.0.2",
|
|
920
|
-
"three": "^0.185.0",
|
|
921
913
|
"typescript": "^5.9.2"
|
|
922
914
|
}
|
|
923
915
|
}
|
|
@@ -17,7 +17,7 @@ export function ActivityPanelFrame({
|
|
|
17
17
|
<div
|
|
18
18
|
className={cn(
|
|
19
19
|
// 只留左上圆角,以及左边、上边的描边;右边和底边贴内容区,不再画线和圆角。
|
|
20
|
-
"relative z-10 flex min-h-0 flex-1 flex-col overflow-visible rounded-tl-xl border-l border-t border-border bg-muted",
|
|
20
|
+
"relative z-10 flex min-h-0 flex-1 flex-col overflow-visible rounded-tl-xl border-l border-t border-border bg-card dark:bg-muted",
|
|
21
21
|
className,
|
|
22
22
|
)}
|
|
23
23
|
data-theme-surface-root="activity.panel"
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { useEffect, useState, type JSX } from "react";
|
|
2
2
|
import { codeToHtml } from "shiki";
|
|
3
|
+
import { ReadonlyCodeView } from "../file-preview/ReadonlyCodeView";
|
|
3
4
|
import { getTextEditorLanguageId } from "../file-preview/text-editor-language";
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Shiki tokenizes the whole source on the renderer thread (about 1.4 ms per KB) and the
|
|
8
|
+
* result is one unvirtualized DOM tree; past this size the preview switches to CodeMirror.
|
|
9
|
+
*/
|
|
10
|
+
export const CODE_PREVIEW_HIGHLIGHT_LIMIT = 100_000;
|
|
11
|
+
|
|
5
12
|
export interface CodePreviewProps {
|
|
6
13
|
content: string;
|
|
7
14
|
extension: string;
|
|
8
15
|
theme: "light" | "dark";
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
export function CodePreview(
|
|
18
|
+
export function CodePreview(props: CodePreviewProps): JSX.Element {
|
|
19
|
+
if (props.content.length > CODE_PREVIEW_HIGHLIGHT_LIMIT) {
|
|
20
|
+
return <ReadonlyCodeView content={props.content} extension={props.extension} />;
|
|
21
|
+
}
|
|
22
|
+
return <HighlightedCodePreview {...props} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function HighlightedCodePreview({ content, extension, theme }: CodePreviewProps): JSX.Element {
|
|
12
26
|
const [html, setHtml] = useState<string | null>(null);
|
|
13
27
|
|
|
14
28
|
useEffect(() => {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act, type ReactNode } from "react";
|
|
4
|
+
import { createRoot, type Root } from "react-dom/client";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { MarkdownPreviewView } from "./MarkdownPreviewView";
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
9
|
+
|
|
10
|
+
const mounted: Root[] = [];
|
|
11
|
+
|
|
12
|
+
function render(node: ReactNode): { container: HTMLDivElement } {
|
|
13
|
+
const container = document.createElement("div");
|
|
14
|
+
document.body.append(container);
|
|
15
|
+
const root = createRoot(container);
|
|
16
|
+
mounted.push(root);
|
|
17
|
+
act(() => root.render(node));
|
|
18
|
+
return { container };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const section = (index: number) => `## Section ${index}\n\n${"word ".repeat(600)}\n`;
|
|
22
|
+
|
|
23
|
+
describe("MarkdownPreviewView", () => {
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
for (const root of mounted.splice(0)) act(() => root.unmount());
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("renders a large document section by section without losing content", async () => {
|
|
30
|
+
vi.useFakeTimers();
|
|
31
|
+
const content = Array.from({ length: 40 }, (_, index) => section(index)).join("\n");
|
|
32
|
+
const { container } = render(<MarkdownPreviewView content={content} theme="light" onOpenExternal={() => {}} />);
|
|
33
|
+
|
|
34
|
+
const firstPass = container.querySelectorAll("h2").length;
|
|
35
|
+
expect(firstPass).toBeGreaterThan(0);
|
|
36
|
+
expect(firstPass).toBeLessThan(40);
|
|
37
|
+
|
|
38
|
+
// Each section schedules the next one after it commits.
|
|
39
|
+
for (let step = 0; step < 40; step++) {
|
|
40
|
+
await act(async () => {
|
|
41
|
+
await vi.runOnlyPendingTimersAsync();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
expect(container.querySelectorAll("h2")).toHaveLength(40);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("renders a small document in one pass", () => {
|
|
48
|
+
const { container } = render(
|
|
49
|
+
<MarkdownPreviewView content={"# Title\n\nbody"} theme="light" onOpenExternal={() => {}} />,
|
|
50
|
+
);
|
|
51
|
+
expect(container.querySelector("h1")?.textContent).toBe("Title");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -3,9 +3,9 @@ import { cn } from "@vetta-org/ui";
|
|
|
3
3
|
import { MarkdownHostProvider } from "../markdown/host";
|
|
4
4
|
import type { MarkdownHost } from "../markdown/host";
|
|
5
5
|
import { MarkdownImage } from "../markdown/MarkdownImage";
|
|
6
|
-
import { memo, useMemo, type JSX, type MouseEvent } from "react";
|
|
6
|
+
import { Fragment, memo, useEffect, useMemo, useState, type JSX, type MouseEvent } from "react";
|
|
7
7
|
import ReactMarkdown from "react-markdown";
|
|
8
|
-
import type { Components } from "react-markdown";
|
|
8
|
+
import type { Components, Options as ReactMarkdownOptions } from "react-markdown";
|
|
9
9
|
import remarkGfm from "remark-gfm";
|
|
10
10
|
import {
|
|
11
11
|
MarkdownTable,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "../shared/MarkdownTable";
|
|
18
18
|
import { useMarkdownDefinition } from "../markdown/definition";
|
|
19
19
|
import { BuiltinCodeBlock, Formula } from "../markdown/builtin-renderers";
|
|
20
|
+
import { splitMarkdownForProgressiveRender } from "../markdown/progressive-chunks";
|
|
20
21
|
import { richRemarkPlugins } from "../markdown/rich-syntax";
|
|
21
22
|
import { SvgPreview } from "../markdown/SvgPreview";
|
|
22
23
|
import { WebsiteIcon } from "../markdown/WebsiteIcon";
|
|
@@ -198,17 +199,92 @@ export const MarkdownPreviewView = memo(function MarkdownPreviewView({
|
|
|
198
199
|
};
|
|
199
200
|
}, [theme, onOpenExternal, definition, labels]);
|
|
200
201
|
|
|
202
|
+
const remarkPlugins = useMemo(
|
|
203
|
+
() => [...MARKDOWN_REMARK_PLUGINS, ...(definition.remarkPlugins ?? [])],
|
|
204
|
+
[definition.remarkPlugins],
|
|
205
|
+
);
|
|
206
|
+
const chunks = useMemo(() => splitMarkdownForProgressiveRender(body), [body]);
|
|
207
|
+
const mountedChunks = useProgressiveChunkCount(chunks.length);
|
|
208
|
+
const progressive = chunks.length > 1;
|
|
209
|
+
|
|
201
210
|
return (
|
|
202
211
|
<MarkdownHostProvider host={host}><div className={cn("markdown-body break-words p-4", className)}>
|
|
203
212
|
{parsed && parsed.entries.length > 0 && <Frontmatter entries={parsed.entries} />}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
213
|
+
{chunks.slice(0, mountedChunks).map((chunk, index) => {
|
|
214
|
+
const rendered = (
|
|
215
|
+
<MarkdownChunk
|
|
216
|
+
markdown={chunk}
|
|
217
|
+
remarkPlugins={remarkPlugins}
|
|
218
|
+
rehypePlugins={definition.rehypePlugins}
|
|
219
|
+
components={components}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
return progressive ? (
|
|
223
|
+
// Off-screen sections skip layout and paint; "auto" remembers each measured height.
|
|
224
|
+
<div key={index} style={PROGRESSIVE_CHUNK_STYLE}>
|
|
225
|
+
{rendered}
|
|
226
|
+
</div>
|
|
227
|
+
) : (
|
|
228
|
+
<Fragment key={index}>{rendered}</Fragment>
|
|
229
|
+
);
|
|
230
|
+
})}
|
|
212
231
|
</div></MarkdownHostProvider>
|
|
213
232
|
);
|
|
214
233
|
});
|
|
234
|
+
|
|
235
|
+
const PROGRESSIVE_CHUNK_STYLE = { contentVisibility: "auto", containIntrinsicSize: "auto 800px" } as const;
|
|
236
|
+
/** Sections rendered in the first frame; enough to fill the pane. */
|
|
237
|
+
const INITIAL_CHUNKS = 2;
|
|
238
|
+
|
|
239
|
+
const MarkdownChunk = memo(function MarkdownChunk({
|
|
240
|
+
markdown,
|
|
241
|
+
remarkPlugins,
|
|
242
|
+
rehypePlugins,
|
|
243
|
+
components,
|
|
244
|
+
}: {
|
|
245
|
+
markdown: string;
|
|
246
|
+
remarkPlugins: ReactMarkdownOptions["remarkPlugins"];
|
|
247
|
+
rehypePlugins: ReactMarkdownOptions["rehypePlugins"];
|
|
248
|
+
components: Components;
|
|
249
|
+
}): JSX.Element {
|
|
250
|
+
return (
|
|
251
|
+
<ReactMarkdown
|
|
252
|
+
urlTransform={chatUrlTransform}
|
|
253
|
+
remarkPlugins={remarkPlugins}
|
|
254
|
+
rehypePlugins={rehypePlugins}
|
|
255
|
+
components={components}
|
|
256
|
+
>
|
|
257
|
+
{markdown}
|
|
258
|
+
</ReactMarkdown>
|
|
259
|
+
);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Parsing and rendering a large document in one task blocks the window for seconds. The
|
|
264
|
+
* first sections render at once and the rest are added one per idle period, so the preview
|
|
265
|
+
* appears immediately and input stays responsive while it fills in.
|
|
266
|
+
*/
|
|
267
|
+
function useProgressiveChunkCount(total: number): number {
|
|
268
|
+
const [count, setCount] = useState(() => Math.min(total, INITIAL_CHUNKS));
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
if (count >= total) return;
|
|
271
|
+
const handle = scheduleIdle(() => setCount((current) => Math.min(total, current + 1)));
|
|
272
|
+
return () => cancelIdle(handle);
|
|
273
|
+
}, [count, total]);
|
|
274
|
+
return Math.min(count, total);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function scheduleIdle(callback: () => void): number {
|
|
278
|
+
if (typeof window !== "undefined" && typeof window.requestIdleCallback === "function") {
|
|
279
|
+
return window.requestIdleCallback(callback, { timeout: 200 });
|
|
280
|
+
}
|
|
281
|
+
return setTimeout(callback, 16) as unknown as number;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function cancelIdle(handle: number): void {
|
|
285
|
+
if (typeof window !== "undefined" && typeof window.cancelIdleCallback === "function") {
|
|
286
|
+
window.cancelIdleCallback(handle);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
clearTimeout(handle);
|
|
290
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act, createElement, type ReactElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { ContextRingView } from "./ContextRingView";
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
9
|
+
|
|
10
|
+
// Radix 的定位靠 floating-ui 的 autoUpdate,jsdom 没有 ResizeObserver。
|
|
11
|
+
if (typeof globalThis.ResizeObserver === "undefined") {
|
|
12
|
+
class NoopResizeObserver implements ResizeObserver {
|
|
13
|
+
observe(): void {}
|
|
14
|
+
unobserve(): void {}
|
|
15
|
+
disconnect(): void {}
|
|
16
|
+
}
|
|
17
|
+
Object.assign(globalThis, { ResizeObserver: NoopResizeObserver });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 同一批 jsdom 版本也没有 PointerEvent,而 Radix 靠它区分鼠标与触摸。
|
|
21
|
+
if (typeof globalThis.PointerEvent === "undefined") {
|
|
22
|
+
class MousePointerEvent extends MouseEvent {
|
|
23
|
+
readonly pointerType: string;
|
|
24
|
+
constructor(type: string, init: MouseEventInit & { pointerType?: string } = {}) {
|
|
25
|
+
super(type, init);
|
|
26
|
+
this.pointerType = init.pointerType ?? "mouse";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Object.assign(globalThis, { PointerEvent: MousePointerEvent });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const TOOLTIP = "上下文已使用 234k tokens(22.4%,1.0M 窗口)";
|
|
33
|
+
|
|
34
|
+
describe("ContextRingView tooltip", () => {
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
vi.useFakeTimers();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.useRealTimers();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("悬停提示挂在 body 上,不留在输入栏那一列里被裁掉、被活动面板盖住", async () => {
|
|
44
|
+
const container = document.createElement("div");
|
|
45
|
+
document.body.append(container);
|
|
46
|
+
const root = createRoot(container);
|
|
47
|
+
await act(async () => root.render(view()));
|
|
48
|
+
|
|
49
|
+
const trigger = container.firstElementChild;
|
|
50
|
+
if (!(trigger instanceof HTMLElement)) throw new Error("missing ring trigger");
|
|
51
|
+
await act(async () => {
|
|
52
|
+
trigger.dispatchEvent(pointerEvent("pointerenter", false));
|
|
53
|
+
trigger.dispatchEvent(pointerEvent("pointermove", true));
|
|
54
|
+
vi.advanceTimersByTime(300);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const tip = document.querySelector('[role="tooltip"]');
|
|
58
|
+
expect(tip?.textContent).toBe(TOOLTIP);
|
|
59
|
+
// 关键断言:提示不是触发器的后代。留在原地的话父级的 overflow-clip 会裁掉它,
|
|
60
|
+
// isolate 又把它关在自己的层里,压不过右边的活动面板。
|
|
61
|
+
expect(container.contains(tip as Node)).toBe(false);
|
|
62
|
+
expect(document.body.contains(tip as Node)).toBe(true);
|
|
63
|
+
|
|
64
|
+
await act(async () => root.unmount());
|
|
65
|
+
container.remove();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function view(): ReactElement {
|
|
70
|
+
return createElement(ContextRingView, {
|
|
71
|
+
percent: 22.4,
|
|
72
|
+
offset: 10,
|
|
73
|
+
color: "currentColor",
|
|
74
|
+
isCompacting: false,
|
|
75
|
+
tooltip: TOOLTIP,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function pointerEvent(type: string, bubbles: boolean): PointerEvent {
|
|
80
|
+
return new PointerEvent(type, { bubbles, pointerType: "mouse", clientX: 0, clientY: 0 });
|
|
81
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
|
2
|
+
import type { JSX } from "react";
|
|
3
3
|
|
|
4
4
|
const SIZE = 16;
|
|
5
5
|
const STROKE = 3;
|
|
@@ -7,6 +7,18 @@ const RADIUS = (SIZE - STROKE) / 2;
|
|
|
7
7
|
const CIRCUMFERENCE = 2 * Math.PI * RADIUS;
|
|
8
8
|
const SPIN_ARC = CIRCUMFERENCE * 0.25;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 空着那段(轨道)的颜色与浓度。
|
|
12
|
+
*
|
|
13
|
+
* 不用 --secondary:它在多数主题里与输入栏底色只差几级(深色约 1.0~1.1:1),再乘 50%
|
|
14
|
+
* 铺上去等于没画,用户看不出圈里还剩多少。--muted-foreground 是各主题都保证与表面拉得
|
|
15
|
+
* 开的文字级灰,取 35% 后深浅两套配色与全部内置主题都稳定落在 1.6~2.0:1——是一道看得
|
|
16
|
+
* 见的槽,又压不过 --primary 画的进度弧。透明度留在属性上而不是写进 color-mix,是为了
|
|
17
|
+
* 让半透明输入栏、插件浮层下面透出的东西都照常参与合成。
|
|
18
|
+
*/
|
|
19
|
+
const TRACK_STROKE = "var(--muted-foreground, #888)";
|
|
20
|
+
const TRACK_OPACITY = 0.35;
|
|
21
|
+
|
|
10
22
|
export interface ContextRingViewProps {
|
|
11
23
|
/** Progress 0–100; ignored while compacting. */
|
|
12
24
|
percent: number;
|
|
@@ -19,6 +31,13 @@ export interface ContextRingViewProps {
|
|
|
19
31
|
className?: string;
|
|
20
32
|
}
|
|
21
33
|
|
|
34
|
+
/**
|
|
35
|
+
* 提示走 Radix Portal 挂到 body,不在圈内做绝对定位。
|
|
36
|
+
*
|
|
37
|
+
* 输入栏所在的列带 `isolate` 与 `overflow-clip`(见 DefaultChatView 的 layout 注释),
|
|
38
|
+
* 圈内绝对定位的元素既会被那圈裁掉、也压不过右邻的活动面板,靠提 z-index 救不回来;
|
|
39
|
+
* 挂出文档流后两端都不成立。只对齐到圈的右缘(align end),长文案往左伸,不去挤面板。
|
|
40
|
+
*/
|
|
22
41
|
export function ContextRingView({
|
|
23
42
|
percent: _percent,
|
|
24
43
|
offset,
|
|
@@ -27,73 +46,70 @@ export function ContextRingView({
|
|
|
27
46
|
tooltip,
|
|
28
47
|
className,
|
|
29
48
|
}: ContextRingViewProps): JSX.Element {
|
|
30
|
-
const [hovered, setHovered] = useState(false);
|
|
31
|
-
|
|
32
49
|
return (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
className="absolute bottom-full left-1/2 -translate-x-1/2 mb-2 whitespace-nowrap rounded-md px-2 py-1 text-[11px] text-foreground pointer-events-none"
|
|
50
|
+
<TooltipPrimitive.Provider delayDuration={200}>
|
|
51
|
+
<TooltipPrimitive.Root>
|
|
52
|
+
<TooltipPrimitive.Trigger asChild>
|
|
53
|
+
<div className={`relative flex items-center cursor-default${className ? ` ${className}` : ""}`}>
|
|
54
|
+
<svg
|
|
55
|
+
width={SIZE}
|
|
56
|
+
height={SIZE}
|
|
57
|
+
className={isCompacting ? "" : "rotate-[-90deg]"}
|
|
58
|
+
style={isCompacting ? { animation: "context-ring-spin 1s linear infinite" } : undefined}
|
|
59
|
+
>
|
|
60
|
+
<circle
|
|
61
|
+
cx={SIZE / 2}
|
|
62
|
+
cy={SIZE / 2}
|
|
63
|
+
r={RADIUS}
|
|
64
|
+
fill="none"
|
|
65
|
+
stroke={TRACK_STROKE}
|
|
66
|
+
strokeWidth={STROKE}
|
|
67
|
+
opacity={TRACK_OPACITY}
|
|
68
|
+
/>
|
|
69
|
+
{isCompacting ? (
|
|
70
|
+
<circle
|
|
71
|
+
cx={SIZE / 2}
|
|
72
|
+
cy={SIZE / 2}
|
|
73
|
+
r={RADIUS}
|
|
74
|
+
fill="none"
|
|
75
|
+
stroke="#f59e0b"
|
|
76
|
+
strokeWidth={STROKE}
|
|
77
|
+
strokeDasharray={`${SPIN_ARC} ${CIRCUMFERENCE - SPIN_ARC}`}
|
|
78
|
+
strokeLinecap="round"
|
|
79
|
+
/>
|
|
80
|
+
) : (
|
|
81
|
+
<circle
|
|
82
|
+
cx={SIZE / 2}
|
|
83
|
+
cy={SIZE / 2}
|
|
84
|
+
r={RADIUS}
|
|
85
|
+
fill="none"
|
|
86
|
+
stroke={color}
|
|
87
|
+
strokeWidth={STROKE}
|
|
88
|
+
strokeDasharray={CIRCUMFERENCE}
|
|
89
|
+
strokeDashoffset={offset}
|
|
90
|
+
strokeLinecap="round"
|
|
91
|
+
style={{ transition: "stroke-dashoffset 0.4s ease, stroke 0.3s ease" }}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
</svg>
|
|
95
|
+
</div>
|
|
96
|
+
</TooltipPrimitive.Trigger>
|
|
97
|
+
<TooltipPrimitive.Portal>
|
|
98
|
+
<TooltipPrimitive.Content
|
|
99
|
+
side="top"
|
|
100
|
+
align="end"
|
|
101
|
+
sideOffset={8}
|
|
102
|
+
className="pointer-events-none z-50 whitespace-nowrap rounded-md px-2 py-1 text-[11px] text-foreground"
|
|
87
103
|
style={{
|
|
88
104
|
background: "var(--secondary, #2a2a2a)",
|
|
89
105
|
boxShadow: "0 2px 8px rgba(0,0,0,0.3)",
|
|
90
106
|
}}
|
|
91
107
|
>
|
|
92
108
|
{tooltip}
|
|
93
|
-
</
|
|
94
|
-
|
|
95
|
-
</
|
|
96
|
-
</
|
|
109
|
+
</TooltipPrimitive.Content>
|
|
110
|
+
</TooltipPrimitive.Portal>
|
|
111
|
+
</TooltipPrimitive.Root>
|
|
112
|
+
</TooltipPrimitive.Provider>
|
|
97
113
|
);
|
|
98
114
|
}
|
|
99
115
|
|