@dyyz1993/create-agent 2.0.1 → 2.1.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 +1 -1
- package/src/commands/create.ts +31 -31
- package/src/commands/workspace.ts +112 -105
- package/src/lib/copy.ts +117 -12
- package/templates/agent/.prettierignore +6 -0
- package/templates/agent/.prettierrc +9 -0
- package/templates/agent/commitlint.config.js +8 -0
- package/templates/agent/electron/main.js +46 -0
- package/templates/agent/electron/preload.js +5 -0
- package/templates/agent/electron-builder.json +40 -0
- package/templates/agent/eslint.config.mjs +2 -0
- package/templates/agent/package.json +75 -2
- package/templates/agent/src/mainview/App.tsx +29 -26
- package/templates/agent/src/mainview/components/chat/ChatPanel.tsx +88 -88
- package/templates/agent/src/mainview/components/file-preview/VirtualizedCodeView.tsx +105 -81
- package/templates/agent/src/mainview/components/search/SearchPanel.tsx +427 -378
- package/templates/agent/src/mainview/components/todo/TodoPanel.tsx +3 -3
- package/templates/agent/src/mainview/hooks/use-input-history.ts +70 -61
- package/templates/agent/src/mainview/lib/api-client.ts +1 -4
- package/templates/agent/src/mainview/main.tsx +4 -10
- package/templates/agent/src/mainview/stores/use-feed-store.ts +107 -107
- package/templates/agent/src/mainview/utils/drop-handler.ts +114 -115
- package/templates/agent/src/server-config.ts +1 -1
- package/templates/agent/src/server.ts +1 -2
- package/templates/agent/src/shared/handlers/chat.ts +5 -5
- package/templates/agent/src/shared/handlers/debug.ts +5 -1
- package/templates/agent/src/shared/handlers/git.ts +286 -243
- package/templates/agent/src/shared/http-routes.ts +1 -1
- package/templates/agent/src/shared/lib/bash-security.ts +43 -43
- package/templates/agent/tsconfig.ipc.json +5 -1
- package/templates/agent/tsconfig.json +3 -1
- package/templates/chat/package.json +3 -0
- package/templates/chat/src/mainview/hooks/use-input-history.ts +70 -61
- package/templates/chat/src/mainview/lib/api-client.ts +2 -5
- package/templates/chat/src/mainview/main.tsx +10 -7
- package/templates/chat/src/server-config.ts +1 -1
- package/templates/chat/src/server.ts +1 -2
- package/templates/chat/src/shared/handlers/chat.ts +5 -5
- package/templates/chat/src/shared/handlers/debug.ts +5 -1
- package/templates/chat/src/shared/http-routes.ts +1 -1
- package/templates/chat/tsconfig.ipc.json +5 -1
- package/templates/chat/tsconfig.json +12 -2
- package/templates/general/package.json +3 -0
- package/templates/general/src/mainview/components/file-preview/VirtualizedCodeView.tsx +101 -81
- package/templates/general/src/mainview/components/search/SearchPanel.tsx +429 -378
- package/templates/general/src/mainview/hooks/use-input-history.ts +70 -61
- package/templates/general/src/mainview/lib/api-client.ts +2 -5
- package/templates/general/src/mainview/main.tsx +10 -7
- package/templates/general/src/mainview/stores/use-feed-store.ts +107 -107
- package/templates/general/src/mainview/utils/drop-handler.ts +114 -115
- package/templates/general/src/server-config.ts +1 -1
- package/templates/general/src/server.ts +1 -2
- package/templates/general/src/shared/handlers/chat.ts +5 -5
- package/templates/general/src/shared/handlers/debug.ts +5 -1
- package/templates/general/src/shared/handlers/git.ts +286 -243
- package/templates/general/src/shared/http-routes.ts +1 -1
- package/templates/general/tsconfig.ipc.json +5 -1
- package/templates/general/tsconfig.json +12 -2
- package/templates/shared/components/ErrorBoundary.tsx +50 -49
- package/templates/shared/http-routes.ts +210 -190
|
@@ -2,6 +2,54 @@
|
|
|
2
2
|
"name": "pi-agent-app",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"description": "Coding agent template with Bash, Rules, and Todo management",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "xuyingzhou",
|
|
7
|
+
"email": "xuyingzhou@tuzhanai.com"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/dyyz1993/pi-agent-template",
|
|
10
|
+
"main": "electron/main.js",
|
|
11
|
+
"build": {
|
|
12
|
+
"appId": "com.piagent.app",
|
|
13
|
+
"productName": "Pi Agent",
|
|
14
|
+
"directories": {
|
|
15
|
+
"output": "dist-electron"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/**/*",
|
|
19
|
+
"electron/**/*",
|
|
20
|
+
"package.json"
|
|
21
|
+
],
|
|
22
|
+
"mac": {
|
|
23
|
+
"category": "public.app-category.developer-tools",
|
|
24
|
+
"target": [
|
|
25
|
+
{
|
|
26
|
+
"target": "dmg",
|
|
27
|
+
"arch": [
|
|
28
|
+
"x64",
|
|
29
|
+
"arm64"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"win": {
|
|
35
|
+
"target": [
|
|
36
|
+
{
|
|
37
|
+
"target": "nsis",
|
|
38
|
+
"arch": [
|
|
39
|
+
"x64"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
"linux": {
|
|
45
|
+
"maintainer": "xuyingzhou <xuyingzhou@tuzhanai.com>",
|
|
46
|
+
"target": [
|
|
47
|
+
"AppImage",
|
|
48
|
+
"deb"
|
|
49
|
+
],
|
|
50
|
+
"category": "Development"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
5
53
|
"scripts": {
|
|
6
54
|
"start": "vite build && electrobun dev",
|
|
7
55
|
"dev": "electrobun dev --watch",
|
|
@@ -12,8 +60,15 @@
|
|
|
12
60
|
"build:mac": "vite build && electrobun build --env=canary",
|
|
13
61
|
"build:win": "vite build && electrobun build --env=canary",
|
|
14
62
|
"build:linux": "vite build && electrobun build --env=canary",
|
|
63
|
+
"electron:dev": "vite build && electron .",
|
|
64
|
+
"electron:build": "vite build && electron-builder --mac --win --linux",
|
|
65
|
+
"electron:build:mac": "vite build && electron-builder --mac",
|
|
66
|
+
"electron:build:win": "vite build && electron-builder --win",
|
|
67
|
+
"electron:build:linux": "vite build && electron-builder --linux",
|
|
15
68
|
"lint": "eslint .",
|
|
16
69
|
"lint:fix": "eslint . --fix",
|
|
70
|
+
"format": "prettier --write .",
|
|
71
|
+
"format:check": "prettier --check .",
|
|
17
72
|
"test": "vitest run",
|
|
18
73
|
"test:watch": "vitest",
|
|
19
74
|
"test:coverage": "vitest run --coverage",
|
|
@@ -45,10 +100,11 @@
|
|
|
45
100
|
"@types/react": "^18.3.12",
|
|
46
101
|
"@types/react-dom": "^18.3.1",
|
|
47
102
|
"@types/ws": "^8.18.1",
|
|
48
|
-
"ws": "^8.18.0",
|
|
49
103
|
"@vitejs/plugin-react": "^4.3.4",
|
|
50
104
|
"autoprefixer": "^10.4.20",
|
|
51
105
|
"concurrently": "^9.1.0",
|
|
106
|
+
"electron": "^42.1.0",
|
|
107
|
+
"electron-builder": "^26.8.1",
|
|
52
108
|
"eslint": "^9.0.0",
|
|
53
109
|
"eslint-plugin-jsx-a11y": "^6.10.0",
|
|
54
110
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
@@ -61,6 +117,23 @@
|
|
|
61
117
|
"typescript": "^5.7.2",
|
|
62
118
|
"typescript-eslint": "^8.0.0",
|
|
63
119
|
"vite": "^6.0.3",
|
|
64
|
-
"vitest": "^4.1.5"
|
|
120
|
+
"vitest": "^4.1.5",
|
|
121
|
+
"ws": "^8.18.0",
|
|
122
|
+
"@commitlint/cli": "^19.8.1",
|
|
123
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
124
|
+
"prettier": "^3.5.3",
|
|
125
|
+
"lint-staged": "^15.5.2"
|
|
126
|
+
},
|
|
127
|
+
"lint-staged": {
|
|
128
|
+
"*.{ts,tsx}": [
|
|
129
|
+
"eslint --fix",
|
|
130
|
+
"prettier --write"
|
|
131
|
+
],
|
|
132
|
+
"*.{json,md,css,html}": [
|
|
133
|
+
"prettier --write"
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
"overrides": {
|
|
137
|
+
"minimatch": "^10.0.1"
|
|
65
138
|
}
|
|
66
139
|
}
|
|
@@ -1,41 +1,44 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
1
2
|
import { useState } from "react";
|
|
2
3
|
import { useConnectionStore } from "./stores/use-connection-store";
|
|
3
4
|
import { useBreakpointSync } from "./hooks/use-breakpoint";
|
|
4
5
|
import { useRpcInit } from "./hooks/use-rpc-init";
|
|
5
6
|
import { useSidebarResize } from "./hooks/use-sidebar-resize";
|
|
6
7
|
import { AppLayout, type CenterTab } from "./components/layout/AppLayout";
|
|
7
|
-
import { ErrorBoundary } from "./components/common/ErrorBoundary";
|
|
8
|
+
import { ErrorBoundary as _EB } from "./components/common/ErrorBoundary";
|
|
9
|
+
|
|
10
|
+
const ErrorBoundary = _EB as unknown as React.FC<{ children: ReactNode }>;
|
|
8
11
|
|
|
9
12
|
function App() {
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
const ready = useConnectionStore((s) => s.ready);
|
|
14
|
+
const [centerTab, setCenterTab] = useState<CenterTab>("chat");
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
useBreakpointSync();
|
|
17
|
+
useRpcInit();
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
const { sidebarWidth, handleResizeStart } = useSidebarResize();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (!ready) {
|
|
22
|
+
return (
|
|
23
|
+
<div className="h-screen bg-gray-900 flex items-center justify-center">
|
|
24
|
+
<div className="text-center">
|
|
25
|
+
<div className="inline-block w-8 h-8 border-2 border-indigo-400 border-t-transparent rounded-full animate-spin mb-4" />
|
|
26
|
+
<div className="text-gray-400 text-sm">Connecting to RPC server...</div>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
return (
|
|
33
|
+
<ErrorBoundary>
|
|
34
|
+
<AppLayout
|
|
35
|
+
centerTab={centerTab}
|
|
36
|
+
setCenterTab={setCenterTab}
|
|
37
|
+
sidebarWidth={sidebarWidth}
|
|
38
|
+
handleResizeStart={handleResizeStart}
|
|
39
|
+
/>
|
|
40
|
+
</ErrorBoundary>
|
|
41
|
+
);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
export default App;
|
|
@@ -6,97 +6,97 @@ import { useChatStore } from "../../stores/use-chat-store";
|
|
|
6
6
|
import { MessageBubble } from "./MessageBubble";
|
|
7
7
|
|
|
8
8
|
export function ChatPanel() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
const messages = useChatStore((s) => s.messages);
|
|
11
|
+
const inputText = useChatStore((s) => s.inputText);
|
|
12
|
+
const setInputText = useChatStore((s) => s.setInputText);
|
|
13
|
+
const sendMessage = useChatStore((s) => s.sendMessage);
|
|
14
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
15
|
+
const prevMessageCountRef = useRef(0);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const virtualizer = useVirtualizer({
|
|
18
|
+
count: messages.length,
|
|
19
|
+
getScrollElement: () => parentRef.current,
|
|
20
|
+
estimateSize: () => 80,
|
|
21
|
+
overscan: 5,
|
|
22
|
+
measureElement: (element) => element?.getBoundingClientRect().height ?? 80,
|
|
23
|
+
});
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (messages.length > prevMessageCountRef.current) {
|
|
27
|
+
virtualizer.scrollToIndex(messages.length - 1, { align: "end" });
|
|
28
|
+
}
|
|
29
|
+
prevMessageCountRef.current = messages.length;
|
|
30
|
+
}, [messages.length, virtualizer]);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
return (
|
|
33
|
+
<div className="flex-1 flex flex-col overflow-hidden relative">
|
|
34
|
+
<div className="px-4 py-2 bg-[var(--color-bg-secondary)] border-b border-[var(--color-border-primary)] flex items-center justify-between flex-shrink-0">
|
|
35
|
+
<h2 className="text-sm font-semibold flex items-center gap-1.5">
|
|
36
|
+
<MessageSquare className="w-4 h-4 text-[var(--color-text-accent)]" />
|
|
37
|
+
{t("chat.title")}
|
|
38
|
+
{messages.length > 0 && (
|
|
39
|
+
<span className="ml-1 px-2 py-0.5 bg-[var(--color-accent)]/30 text-[var(--color-text-accent)] rounded text-[10px]">
|
|
40
|
+
{messages.length}
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
</h2>
|
|
44
|
+
</div>
|
|
45
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
|
-
|
|
46
|
+
<div ref={parentRef} className="flex-1 overflow-y-auto">
|
|
47
|
+
{messages.length === 0 ? (
|
|
48
|
+
<div className="flex items-center justify-center h-full text-[var(--color-text-placeholder)] text-sm">
|
|
49
|
+
{t("chat.empty")}
|
|
50
|
+
</div>
|
|
51
|
+
) : (
|
|
52
|
+
<div
|
|
53
|
+
style={{
|
|
54
|
+
height: virtualizer.getTotalSize(),
|
|
55
|
+
width: "100%",
|
|
56
|
+
position: "relative",
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{virtualizer.getVirtualItems().map((virtualItem) => {
|
|
60
|
+
const msg = messages[virtualItem.index]!;
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
key={msg.id}
|
|
64
|
+
data-index={virtualItem.index}
|
|
65
|
+
ref={virtualizer.measureElement}
|
|
66
|
+
style={{
|
|
67
|
+
position: "absolute",
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
width: "100%",
|
|
71
|
+
transform: `translateY(${virtualItem.start}px)`,
|
|
72
|
+
padding: "6px 16px",
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<MessageBubble message={msg} />
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
})}
|
|
79
|
+
</div>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
<div className="px-4 py-3 bg-[var(--color-bg-secondary)] border-t border-[var(--color-border-primary)] flex gap-2 flex-shrink-0">
|
|
84
|
+
<input
|
|
85
|
+
type="text"
|
|
86
|
+
value={inputText}
|
|
87
|
+
onChange={(e) => setInputText(e.target.value)}
|
|
88
|
+
onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && sendMessage()}
|
|
89
|
+
placeholder={t("chat.placeholder")}
|
|
90
|
+
className="flex-1 px-3 py-2 text-sm bg-[var(--color-bg-tertiary)] rounded-lg text-[var(--color-text-primary)] border border-[var(--color-border-secondary)] focus:border-[var(--color-accent)] focus:outline-none"
|
|
91
|
+
/>
|
|
92
|
+
<button
|
|
93
|
+
onClick={sendMessage}
|
|
94
|
+
className="px-4 py-2 text-sm bg-[var(--color-accent)] hover:bg-[var(--color-accent-hover)] rounded-lg transition-colors flex items-center gap-1.5"
|
|
95
|
+
>
|
|
96
|
+
<Send className="w-4 h-4" />
|
|
97
|
+
{t("chat.send")}
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
102
|
}
|
|
@@ -4,96 +4,120 @@ import { Highlight, themes } from "prism-react-renderer";
|
|
|
4
4
|
import { getLanguage } from "../../utils/file-utils";
|
|
5
5
|
|
|
6
6
|
interface VirtualizedCodeViewProps {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
code: string;
|
|
8
|
+
filename: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** Lines longer than this skip syntax highlighting (plain text instead) */
|
|
12
12
|
const LONG_LINE_THRESHOLD = 5000;
|
|
13
13
|
|
|
14
14
|
export function VirtualizedCodeView({ code, filename }: VirtualizedCodeViewProps) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
16
|
+
const language = getLanguage(filename);
|
|
17
|
+
const lines = useMemo(() => code.split("\n"), [code]);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Detect minified files: avg line length > 500 chars
|
|
20
|
+
const avgLineLength = code.length / Math.max(lines.length, 1);
|
|
21
|
+
const usePlainText = !language || avgLineLength > 500;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const virtualizer = useVirtualizer({
|
|
24
|
+
count: lines.length,
|
|
25
|
+
getScrollElement: () => parentRef.current,
|
|
26
|
+
estimateSize: () => 20,
|
|
27
|
+
overscan: 20,
|
|
28
|
+
});
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
// --- Plain text path: no Prism tokenization ---
|
|
31
|
+
if (usePlainText) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
ref={parentRef}
|
|
35
|
+
className="flex-1 min-h-0 overflow-auto"
|
|
36
|
+
style={{ background: "#011627" }}
|
|
37
|
+
>
|
|
38
|
+
<div
|
|
39
|
+
style={{ height: `${virtualizer.getTotalSize()}px`, width: "100%", position: "relative" }}
|
|
40
|
+
>
|
|
41
|
+
{virtualizer.getVirtualItems().map((vr) => (
|
|
42
|
+
<div
|
|
43
|
+
key={vr.key}
|
|
44
|
+
style={{
|
|
45
|
+
position: "absolute",
|
|
46
|
+
top: 0,
|
|
47
|
+
left: 0,
|
|
48
|
+
width: "100%",
|
|
49
|
+
height: `${vr.size}px`,
|
|
50
|
+
transform: `translateY(${vr.start}px)`,
|
|
51
|
+
}}
|
|
52
|
+
className="flex text-xs leading-5 font-mono"
|
|
53
|
+
>
|
|
54
|
+
<span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
|
|
55
|
+
{vr.index + 1}
|
|
56
|
+
</span>
|
|
57
|
+
<span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">
|
|
58
|
+
{lines[vr.index]}
|
|
59
|
+
</span>
|
|
60
|
+
</div>
|
|
61
|
+
))}
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// --- Highlighted path: tokenize ONCE for the whole file, virtualize rendering ---
|
|
68
|
+
return (
|
|
69
|
+
<Highlight theme={themes.nightOwl} code={code} language={language}>
|
|
70
|
+
{({ tokens, getTokenProps }) => (
|
|
71
|
+
<div
|
|
72
|
+
ref={parentRef}
|
|
73
|
+
className="flex-1 min-h-0 overflow-auto"
|
|
74
|
+
style={{ background: "#011627" }}
|
|
75
|
+
>
|
|
76
|
+
<div
|
|
77
|
+
style={{
|
|
78
|
+
height: `${virtualizer.getTotalSize()}px`,
|
|
79
|
+
width: "100%",
|
|
80
|
+
position: "relative",
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
{virtualizer.getVirtualItems().map((vr) => {
|
|
84
|
+
const lineTokens = tokens[vr.index];
|
|
85
|
+
const lineText = lines[vr.index];
|
|
86
|
+
const isLongLine = (lineText?.length ?? 0) > LONG_LINE_THRESHOLD;
|
|
69
87
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
key={vr.key}
|
|
91
|
+
style={{
|
|
92
|
+
position: "absolute",
|
|
93
|
+
top: 0,
|
|
94
|
+
left: 0,
|
|
95
|
+
width: "100%",
|
|
96
|
+
height: `${vr.size}px`,
|
|
97
|
+
transform: `translateY(${vr.start}px)`,
|
|
98
|
+
}}
|
|
99
|
+
className="flex text-xs leading-5 font-mono"
|
|
100
|
+
>
|
|
101
|
+
<span className="inline-block w-10 text-right pr-4 text-gray-600 select-none shrink-0">
|
|
102
|
+
{vr.index + 1}
|
|
103
|
+
</span>
|
|
104
|
+
{isLongLine ? (
|
|
105
|
+
<span className="flex-1 text-[var(--color-text-secondary)] whitespace-pre">
|
|
106
|
+
{lineText}
|
|
107
|
+
</span>
|
|
108
|
+
) : (
|
|
109
|
+
<span className="flex-1">
|
|
110
|
+
{lineTokens!.map((token, key) => (
|
|
111
|
+
<span key={key} {...getTokenProps({ token })} />
|
|
112
|
+
))}
|
|
113
|
+
</span>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
})}
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
)}
|
|
121
|
+
</Highlight>
|
|
122
|
+
);
|
|
99
123
|
}
|