@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vetta-org/theme-ui",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import { StorageCleanListView } from "./StorageCleanListView";
|
|
7
|
+
|
|
8
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
9
|
+
|
|
10
|
+
it("展示理由与恢复方式,点击整行切换勾选,占用中的条目不能勾选", () => {
|
|
11
|
+
const toggled: unknown[] = [];
|
|
12
|
+
const item = { path: "workspace/a", size: "1 GB", reason: "Idle", restore: "npm ci", checked: true, disabled: false };
|
|
13
|
+
const container = document.createElement("div");
|
|
14
|
+
document.body.append(container);
|
|
15
|
+
const root = createRoot(container);
|
|
16
|
+
act(() =>
|
|
17
|
+
root.render(
|
|
18
|
+
<StorageCleanListView
|
|
19
|
+
items={[
|
|
20
|
+
{ ...item, id: "a", title: "Dependencies" },
|
|
21
|
+
{ ...item, id: "b", title: "Busy", checked: false, disabled: true },
|
|
22
|
+
]}
|
|
23
|
+
summary="1 selected"
|
|
24
|
+
onToggle={(id, checked) => toggled.push([id, checked])}
|
|
25
|
+
/>,
|
|
26
|
+
),
|
|
27
|
+
);
|
|
28
|
+
const [first, second] = [...container.querySelectorAll("label")];
|
|
29
|
+
expect(first?.textContent).toContain("Idle");
|
|
30
|
+
expect(first?.textContent).toContain("npm ci");
|
|
31
|
+
act(() => first?.click());
|
|
32
|
+
act(() => second?.click());
|
|
33
|
+
expect(toggled).toEqual([["a", false]]);
|
|
34
|
+
act(() => root.unmount());
|
|
35
|
+
container.remove();
|
|
36
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import { cn } from "./cn";
|
|
3
|
+
|
|
4
|
+
export interface StorageCleanListItemView {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly title: string;
|
|
7
|
+
readonly path: string;
|
|
8
|
+
readonly size: string;
|
|
9
|
+
readonly reason: string;
|
|
10
|
+
/** 清理之后怎么恢复,由宿主给出。 */
|
|
11
|
+
readonly restore: string;
|
|
12
|
+
readonly checked: boolean;
|
|
13
|
+
readonly disabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StorageCleanListViewProps {
|
|
17
|
+
readonly items: readonly StorageCleanListItemView[];
|
|
18
|
+
readonly summary: string;
|
|
19
|
+
readonly onToggle: (id: string, checked: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function StorageCleanListView({ items, summary, onToggle }: StorageCleanListViewProps): JSX.Element {
|
|
23
|
+
return (
|
|
24
|
+
<div className="space-y-2">
|
|
25
|
+
<ul className="max-h-[320px] overflow-y-auto rounded-lg border border-border/50 bg-background/50">
|
|
26
|
+
{items.map((item, index) => (
|
|
27
|
+
<li key={item.id} className={cn(index > 0 && "border-t border-border/40")}>
|
|
28
|
+
<label className={cn("flex items-start gap-3 p-3", item.disabled ? "opacity-50" : "cursor-pointer")}>
|
|
29
|
+
<input
|
|
30
|
+
type="checkbox"
|
|
31
|
+
className="mt-0.5 h-3.5 w-3.5 shrink-0 accent-primary"
|
|
32
|
+
checked={item.checked}
|
|
33
|
+
disabled={item.disabled}
|
|
34
|
+
onChange={(event) => onToggle(item.id, event.target.checked)}
|
|
35
|
+
/>
|
|
36
|
+
<span className="min-w-0 flex-1">
|
|
37
|
+
<span className="flex justify-between gap-3 text-[12px] font-medium text-foreground">
|
|
38
|
+
<span>{item.title}</span>
|
|
39
|
+
<span className="shrink-0 tabular-nums">{item.size}</span>
|
|
40
|
+
</span>
|
|
41
|
+
<span className="mt-0.5 block break-all font-mono text-[10px] text-muted-foreground">{item.path}</span>
|
|
42
|
+
<span className="mt-1 block text-[11px] text-foreground">{item.reason}</span>
|
|
43
|
+
<span className="mt-0.5 block text-[11px] text-muted-foreground">{item.restore}</span>
|
|
44
|
+
</span>
|
|
45
|
+
</label>
|
|
46
|
+
</li>
|
|
47
|
+
))}
|
|
48
|
+
</ul>
|
|
49
|
+
<p className="text-[11px] text-muted-foreground">{summary}</p>
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -79,6 +79,8 @@ export type {
|
|
|
79
79
|
export { SchedulerEditApprovalDrawerView } from "./SchedulerEditApprovalDrawerView";
|
|
80
80
|
export type { SchedulerUpdateApprovalViewProps } from "./SchedulerUpdateApprovalView";
|
|
81
81
|
export { SchedulerUpdateApprovalView } from "./SchedulerUpdateApprovalView";
|
|
82
|
+
export type { StorageCleanListItemView, StorageCleanListViewProps } from "./StorageCleanListView";
|
|
83
|
+
export { StorageCleanListView } from "./StorageCleanListView";
|
|
82
84
|
export type { ThemeChangeApprovalViewProps } from "./ThemeChangeApprovalView";
|
|
83
85
|
export { ThemeChangeApprovalView } from "./ThemeChangeApprovalView";
|
|
84
86
|
export type { WebhookDeleteApprovalViewProps } from "./WebhookDeleteApprovalView";
|
|
@@ -21,6 +21,7 @@ interface ActivityPanelContextValue {
|
|
|
21
21
|
readonly resize: (delta: number) => void;
|
|
22
22
|
readonly resizeEnd: () => void;
|
|
23
23
|
readonly resizeStart: () => void;
|
|
24
|
+
readonly resizeReset?: () => void;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const ActivityPanelContext = createContext<ActivityPanelContextValue | null>(null);
|
|
@@ -37,6 +38,8 @@ export interface ActivityPanelRootProps {
|
|
|
37
38
|
/** Reports the absolute live width while the local shell follows the pointer. */
|
|
38
39
|
readonly onResize?: (width: number) => void;
|
|
39
40
|
readonly onResizeEnd?: (width: number) => void;
|
|
41
|
+
/** 双击分隔条:宿主把宽度恢复成默认值。 */
|
|
42
|
+
readonly onResizeReset?: () => void;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/** Owns controlled panel state and resize behavior. Layout remains explicit children. */
|
|
@@ -51,6 +54,7 @@ export function ActivityPanelRoot({
|
|
|
51
54
|
onResizeStart,
|
|
52
55
|
onResize,
|
|
53
56
|
onResizeEnd,
|
|
57
|
+
onResizeReset,
|
|
54
58
|
}: ActivityPanelRootProps): JSX.Element {
|
|
55
59
|
const liveWidthRef = useRef(width);
|
|
56
60
|
const [liveWidth, setLiveWidth] = useState(width);
|
|
@@ -94,6 +98,7 @@ export function ActivityPanelRoot({
|
|
|
94
98
|
isResizing: locallyResizing || isResizing,
|
|
95
99
|
resize,
|
|
96
100
|
resizeEnd,
|
|
101
|
+
resizeReset: onResizeReset,
|
|
97
102
|
resizeStart,
|
|
98
103
|
}}
|
|
99
104
|
>
|
|
@@ -194,7 +199,7 @@ export const ActivityPanelBody = forwardRef<HTMLDivElement, ActivityPanelBodyPro
|
|
|
194
199
|
);
|
|
195
200
|
|
|
196
201
|
export function ActivityPanelResizeHandle(): JSX.Element | null {
|
|
197
|
-
const { isOpen, resize, resizeEnd, resizeStart } = useActivityPanelContext("ResizeHandle");
|
|
202
|
+
const { isOpen, resize, resizeEnd, resizeReset, resizeStart } = useActivityPanelContext("ResizeHandle");
|
|
198
203
|
if (!isOpen) return null;
|
|
199
204
|
return (
|
|
200
205
|
<ResizeHandle
|
|
@@ -202,6 +207,7 @@ export function ActivityPanelResizeHandle(): JSX.Element | null {
|
|
|
202
207
|
onResizeStart={resizeStart}
|
|
203
208
|
onResize={resize}
|
|
204
209
|
onResizeEnd={resizeEnd}
|
|
210
|
+
onReset={resizeReset}
|
|
205
211
|
/>
|
|
206
212
|
);
|
|
207
213
|
}
|
|
@@ -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"
|
|
@@ -19,6 +19,9 @@ export interface BackgroundTaskViewItem {
|
|
|
19
19
|
statusLabel: string;
|
|
20
20
|
statusClassName: string;
|
|
21
21
|
durationLabel: string;
|
|
22
|
+
/** Replaces the default `bash` badge, e.g. for processes a command left running. */
|
|
23
|
+
badgeLabel?: string;
|
|
24
|
+
badgeTitle?: string;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
/** Subagent child row (explorer / future types) — same tab, different card. */
|
|
@@ -126,9 +129,18 @@ function WorkCardHeader({
|
|
|
126
129
|
);
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
function KindBadge({
|
|
132
|
+
function KindBadge({
|
|
133
|
+
tone,
|
|
134
|
+
title,
|
|
135
|
+
children,
|
|
136
|
+
}: {
|
|
137
|
+
tone: "neutral" | "primary";
|
|
138
|
+
title?: string;
|
|
139
|
+
children: ReactNode;
|
|
140
|
+
}): JSX.Element {
|
|
130
141
|
return (
|
|
131
142
|
<span
|
|
143
|
+
title={title}
|
|
132
144
|
className={`shrink-0 rounded-md px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${
|
|
133
145
|
tone === "primary" ? "bg-primary/10 text-primary" : "bg-muted text-muted-foreground"
|
|
134
146
|
}`}
|
|
@@ -203,7 +215,11 @@ function BashTaskCard({
|
|
|
203
215
|
statusClassName={task.statusClassName}
|
|
204
216
|
statusLabel={task.statusLabel}
|
|
205
217
|
durationLabel={task.durationLabel}
|
|
206
|
-
badge={
|
|
218
|
+
badge={
|
|
219
|
+
<KindBadge tone="neutral" title={task.badgeTitle}>
|
|
220
|
+
{task.badgeLabel ?? "bash"}
|
|
221
|
+
</KindBadge>
|
|
222
|
+
}
|
|
207
223
|
identity={
|
|
208
224
|
<span className="block truncate font-mono text-[10px] text-muted-foreground/70" title={task.id}>
|
|
209
225
|
{task.id}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Button, ButtonGroup, ButtonGroupItem } from "@vetta-org/ui";
|
|
2
|
-
import type { FormEvent, JSX, Ref } from "react";
|
|
2
|
+
import type { FormEvent, JSX, Ref, ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
export interface BrowserPanelLabels {
|
|
5
5
|
noSession: string;
|
|
@@ -16,6 +16,8 @@ export interface BrowserPanelLabels {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface BrowserPanelViewProps {
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
captureAction?: { label: string; disabled: boolean; onClick: () => void };
|
|
19
21
|
/** Null when the host has no bound workspace — show empty state. */
|
|
20
22
|
workspaceId: string | null;
|
|
21
23
|
labels: BrowserPanelLabels;
|
|
@@ -46,6 +48,8 @@ function toolbarIcon(icon: string): JSX.Element {
|
|
|
46
48
|
* Session-scoped built-in browser shell. Host owns webview event wiring via ref.
|
|
47
49
|
*/
|
|
48
50
|
export function BrowserPanelView({
|
|
51
|
+
children,
|
|
52
|
+
captureAction,
|
|
49
53
|
workspaceId,
|
|
50
54
|
labels,
|
|
51
55
|
address,
|
|
@@ -120,6 +124,15 @@ export function BrowserPanelView({
|
|
|
120
124
|
/>
|
|
121
125
|
</form>
|
|
122
126
|
<ButtonGroup blur={false} className="shrink-0">
|
|
127
|
+
{captureAction && (
|
|
128
|
+
<ButtonGroupItem
|
|
129
|
+
icon={toolbarIcon("icon-[mdi--camera-outline]")}
|
|
130
|
+
title={captureAction.label}
|
|
131
|
+
aria-label={captureAction.label}
|
|
132
|
+
disabled={captureAction.disabled}
|
|
133
|
+
onClick={captureAction.onClick}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
123
136
|
<ButtonGroupItem
|
|
124
137
|
icon={toolbarIcon("icon-[mdi--open-in-new]")}
|
|
125
138
|
title={labels.openExternal}
|
|
@@ -141,6 +154,7 @@ export function BrowserPanelView({
|
|
|
141
154
|
allowpopups={true}
|
|
142
155
|
className="h-full w-full"
|
|
143
156
|
/>
|
|
157
|
+
{children}
|
|
144
158
|
{!hasPage && (
|
|
145
159
|
<div className="absolute inset-0 flex flex-col items-center justify-center gap-2 bg-muted p-6 text-center">
|
|
146
160
|
<span className="icon-[mdi--web] h-8 w-8 text-muted-foreground/30" />
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import type { PointerEvent, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
interface Rect {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
interface BrowserSelectionViewProps {
|
|
11
|
+
mode: "element" | "region";
|
|
12
|
+
viewport: { width: number; height: number };
|
|
13
|
+
rect: Rect | null;
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
label: string;
|
|
16
|
+
onInspect: (x: number, y: number, lock: boolean) => void;
|
|
17
|
+
onRegionChange: (rect: Rect) => void;
|
|
18
|
+
onScroll: (x: number, y: number, point: { x: number; y: number }) => void;
|
|
19
|
+
/** Floats above the page while selecting; a sibling of the surface so its clicks never start a selection. */
|
|
20
|
+
toolbar?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Host overlay intercepts pointer input; selecting never clicks the guest page. */
|
|
24
|
+
export function BrowserSelectionView({
|
|
25
|
+
mode,
|
|
26
|
+
viewport,
|
|
27
|
+
rect,
|
|
28
|
+
disabled,
|
|
29
|
+
label,
|
|
30
|
+
onInspect,
|
|
31
|
+
onRegionChange,
|
|
32
|
+
onScroll,
|
|
33
|
+
toolbar,
|
|
34
|
+
}: BrowserSelectionViewProps) {
|
|
35
|
+
const surface = useRef<HTMLDivElement>(null);
|
|
36
|
+
const drag = useRef<{
|
|
37
|
+
x: number;
|
|
38
|
+
y: number;
|
|
39
|
+
clientX: number;
|
|
40
|
+
clientY: number;
|
|
41
|
+
rect: Rect | null;
|
|
42
|
+
action: string;
|
|
43
|
+
pending: boolean;
|
|
44
|
+
} | null>(null);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const node = surface.current;
|
|
47
|
+
if (!node) return;
|
|
48
|
+
const wheel = (event: WheelEvent) => {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
if (!disabled && !drag.current && mode === "element") {
|
|
51
|
+
const bounds = node.getBoundingClientRect();
|
|
52
|
+
onScroll(event.deltaX, event.deltaY, {
|
|
53
|
+
x: ((event.clientX - bounds.left) * viewport.width) / (bounds.width || 1),
|
|
54
|
+
y: ((event.clientY - bounds.top) * viewport.height) / (bounds.height || 1),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
node.addEventListener("wheel", wheel, { passive: false });
|
|
59
|
+
return () => node.removeEventListener("wheel", wheel);
|
|
60
|
+
}, [mode, disabled, onScroll, viewport.width, viewport.height]);
|
|
61
|
+
const point = (event: PointerEvent) => {
|
|
62
|
+
const bounds = surface.current?.getBoundingClientRect();
|
|
63
|
+
return {
|
|
64
|
+
x: Math.max(
|
|
65
|
+
0,
|
|
66
|
+
Math.min(viewport.width, ((event.clientX - (bounds?.left ?? 0)) * viewport.width) / (bounds?.width || 1)),
|
|
67
|
+
),
|
|
68
|
+
y: Math.max(
|
|
69
|
+
0,
|
|
70
|
+
Math.min(viewport.height, ((event.clientY - (bounds?.top ?? 0)) * viewport.height) / (bounds?.height || 1)),
|
|
71
|
+
),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const move = (event: PointerEvent) => {
|
|
75
|
+
if (disabled) return;
|
|
76
|
+
const current = point(event),
|
|
77
|
+
start = drag.current;
|
|
78
|
+
if (!start && mode === "element") {
|
|
79
|
+
void onInspect(current.x, current.y, false);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!start) return;
|
|
83
|
+
if (start.pending) {
|
|
84
|
+
if (Math.hypot(event.clientX - start.clientX, event.clientY - start.clientY) < 4) return;
|
|
85
|
+
start.pending = false;
|
|
86
|
+
}
|
|
87
|
+
if (start.action === "move" && start.rect) {
|
|
88
|
+
onRegionChange({
|
|
89
|
+
...start.rect,
|
|
90
|
+
x: Math.max(0, Math.min(viewport.width - start.rect.width, start.rect.x + current.x - start.x)),
|
|
91
|
+
y: Math.max(0, Math.min(viewport.height - start.rect.height, start.rect.y + current.y - start.y)),
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let anchorX = start.x,
|
|
96
|
+
anchorY = start.y;
|
|
97
|
+
if (start.rect && start.action !== "new") {
|
|
98
|
+
anchorX = start.action.includes("w") ? start.rect.x + start.rect.width : start.rect.x;
|
|
99
|
+
anchorY = start.action.includes("n") ? start.rect.y + start.rect.height : start.rect.y;
|
|
100
|
+
}
|
|
101
|
+
onRegionChange({
|
|
102
|
+
x: Math.min(anchorX, current.x),
|
|
103
|
+
y: Math.min(anchorY, current.y),
|
|
104
|
+
width: Math.abs(current.x - anchorX),
|
|
105
|
+
height: Math.abs(current.y - anchorY),
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<div
|
|
111
|
+
ref={surface}
|
|
112
|
+
role="application"
|
|
113
|
+
aria-label={label}
|
|
114
|
+
tabIndex={0}
|
|
115
|
+
className="absolute inset-0 z-10 cursor-crosshair touch-none select-none"
|
|
116
|
+
onPointerDown={(event) => {
|
|
117
|
+
if (disabled || event.button !== 0) return;
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
const current = point(event);
|
|
120
|
+
const action =
|
|
121
|
+
mode === "region" && event.target instanceof HTMLElement
|
|
122
|
+
? (event.target.dataset.captureAction ?? "new")
|
|
123
|
+
: "new";
|
|
124
|
+
drag.current = {
|
|
125
|
+
...current,
|
|
126
|
+
clientX: event.clientX,
|
|
127
|
+
clientY: event.clientY,
|
|
128
|
+
rect,
|
|
129
|
+
action,
|
|
130
|
+
pending: mode === "element",
|
|
131
|
+
};
|
|
132
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
133
|
+
}}
|
|
134
|
+
onPointerMove={move}
|
|
135
|
+
onPointerUp={(event) => {
|
|
136
|
+
if (drag.current) move(event);
|
|
137
|
+
if (!disabled && drag.current?.pending) {
|
|
138
|
+
const current = point(event);
|
|
139
|
+
void onInspect(current.x, current.y, true);
|
|
140
|
+
}
|
|
141
|
+
drag.current = null;
|
|
142
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId))
|
|
143
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
144
|
+
}}
|
|
145
|
+
onPointerCancel={() => {
|
|
146
|
+
drag.current = null;
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{rect ? (
|
|
150
|
+
<svg
|
|
151
|
+
aria-hidden="true"
|
|
152
|
+
className="pointer-events-none absolute inset-0 h-full w-full fill-background/60"
|
|
153
|
+
viewBox={`0 0 ${viewport.width} ${viewport.height}`}
|
|
154
|
+
preserveAspectRatio="none"
|
|
155
|
+
>
|
|
156
|
+
<path
|
|
157
|
+
fillRule="evenodd"
|
|
158
|
+
d={`M0 0H${viewport.width}V${viewport.height}H0Z M${rect.x} ${rect.y}h${rect.width}v${rect.height}h${-rect.width}Z`}
|
|
159
|
+
/>
|
|
160
|
+
</svg>
|
|
161
|
+
) : null}
|
|
162
|
+
{rect ? (
|
|
163
|
+
<div
|
|
164
|
+
data-capture-action="move"
|
|
165
|
+
className={`absolute border-3 border-browser-selection ${mode === "region" ? "cursor-move" : "cursor-crosshair"}`}
|
|
166
|
+
style={{
|
|
167
|
+
left: `${(rect.x / viewport.width) * 100}%`,
|
|
168
|
+
top: `${(rect.y / viewport.height) * 100}%`,
|
|
169
|
+
width: `${(rect.width / viewport.width) * 100}%`,
|
|
170
|
+
height: `${(rect.height / viewport.height) * 100}%`,
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{mode === "region"
|
|
174
|
+
? ["nw", "ne", "sw", "se"].map((corner) => (
|
|
175
|
+
<span
|
|
176
|
+
key={corner}
|
|
177
|
+
data-capture-action={corner}
|
|
178
|
+
className="absolute h-3 w-3 rounded-full border border-browser-selection bg-background"
|
|
179
|
+
style={{
|
|
180
|
+
left: corner.includes("w") ? -6 : undefined,
|
|
181
|
+
right: corner.includes("e") ? -6 : undefined,
|
|
182
|
+
top: corner.includes("n") ? -6 : undefined,
|
|
183
|
+
bottom: corner.includes("s") ? -6 : undefined,
|
|
184
|
+
cursor: `${corner}-resize`,
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
))
|
|
188
|
+
: null}
|
|
189
|
+
</div>
|
|
190
|
+
) : null}
|
|
191
|
+
</div>
|
|
192
|
+
{toolbar ? (
|
|
193
|
+
<div className="pointer-events-none absolute inset-x-0 bottom-3 z-20 flex justify-center px-3">
|
|
194
|
+
<div className="pointer-events-auto max-w-full">{toolbar}</div>
|
|
195
|
+
</div>
|
|
196
|
+
) : null}
|
|
197
|
+
</>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
@@ -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
|
+
});
|