@keyou007/agent-bot 0.1.27-alpha.1 → 0.1.27-alpha.2
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/CHANGELOG.md +24 -0
- package/README.md +54 -4
- package/README.zh.md +54 -4
- package/SECURITY.md +14 -0
- package/assets/workspace-sessions.js +648 -0
- package/assets/workspace.css +160 -0
- package/assets/workspace.js +1795 -0
- package/config.example.yaml +3 -2
- package/dist/codex/CodexEventMapper.js +35 -0
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +50 -4
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/codex/TraeTaskNotification.js +44 -0
- package/dist/codex/TraeTaskNotification.js.map +1 -0
- package/dist/config/SettingsStore.js +1 -1
- package/dist/config/SettingsStore.js.map +1 -1
- package/dist/config/loadConfig.js +3 -2
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/config/paths.js +3 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/feishu/CardRenderer.js +54 -10
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +2 -2
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +103 -16
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +61 -17
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +1 -1
- package/dist/local-files/GitDiffPreview.js +11 -7
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LocalFileViewerServer.js +273 -25
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownFileLinks.js +5 -4
- package/dist/local-files/MarkdownFileLinks.js.map +1 -1
- package/dist/local-files/TurnPreviewPage.js +32 -10
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WebPageTitle.js +85 -0
- package/dist/local-files/WebPageTitle.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +553 -0
- package/dist/local-files/WorkspaceFiles.js.map +1 -0
- package/dist/local-files/WorkspaceOrigin.js +38 -0
- package/dist/local-files/WorkspaceOrigin.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +19 -0
- package/dist/local-files/WorkspacePage.js.map +1 -0
- package/dist/local-files/WorkspaceSessions.js +689 -0
- package/dist/local-files/WorkspaceSessions.js.map +1 -0
- package/dist/presentation/TurnStateReducer.js +74 -13
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/presentation/turnActivity.js +41 -0
- package/dist/presentation/turnActivity.js.map +1 -0
- package/dist/presentation/turnStatus.js +11 -0
- package/dist/presentation/turnStatus.js.map +1 -1
- package/dist/presentation/visibleTurnActivities.js +4 -2
- package/dist/presentation/visibleTurnActivities.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +150 -14
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/state/InboundMessageStore.js +54 -0
- package/dist/state/InboundMessageStore.js.map +1 -0
- package/dist/state/StateStore.js +71 -1
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +4 -2
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/migrations.js +20 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +1 -0
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/supervision/SafeRestartScheduler.js +33 -16
- package/dist/supervision/SafeRestartScheduler.js.map +1 -1
- package/dist/terminal/TerminalLinks.js +32 -0
- package/dist/terminal/TerminalLinks.js.map +1 -1
- package/dist/terminal/TerminalPage.js +44 -24
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/terminal/TerminalServer.js +103 -39
- package/dist/terminal/TerminalServer.js.map +1 -1
- package/docs/technical-reference.md +1 -1
- package/docs/technical-reference.zh.md +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +3 -1
- package/src/codex/CodexEventMapper.ts +39 -1
- package/src/codex/CodexRuntime.ts +54 -4
- package/src/codex/TraeTaskNotification.ts +49 -0
- package/src/config/SettingsStore.ts +1 -1
- package/src/config/loadConfig.ts +3 -2
- package/src/config/paths.ts +4 -0
- package/src/feishu/CardRenderer.ts +45 -11
- package/src/feishu/FeishuMessageClient.ts +2 -2
- package/src/feishu/FeishuTurnPresenter.ts +110 -20
- package/src/index.ts +62 -17
- package/src/local-files/DiagramPreview.ts +1 -1
- package/src/local-files/GitDiffPreview.ts +10 -7
- package/src/local-files/LocalFileViewerServer.ts +243 -25
- package/src/local-files/MarkdownFileLinks.ts +5 -3
- package/src/local-files/TurnPreviewPage.ts +35 -9
- package/src/local-files/WebPageTitle.ts +59 -0
- package/src/local-files/WorkspaceFiles.ts +468 -0
- package/src/local-files/WorkspaceOrigin.ts +31 -0
- package/src/local-files/WorkspacePage.ts +21 -0
- package/src/local-files/WorkspaceSessions.ts +587 -0
- package/src/presentation/TurnStateReducer.ts +76 -14
- package/src/presentation/turnActivity.ts +43 -0
- package/src/presentation/turnStatus.ts +14 -0
- package/src/presentation/turnViewTypes.ts +10 -1
- package/src/presentation/visibleTurnActivities.ts +4 -2
- package/src/proxy/ProxySessionController.ts +149 -13
- package/src/runtime/types.ts +17 -0
- package/src/state/InboundMessageStore.ts +72 -0
- package/src/state/StateStore.ts +80 -1
- package/src/state/TurnPreviewJournal.ts +4 -2
- package/src/state/migrations.ts +20 -0
- package/src/supervision/SafeRestartNotifier.ts +1 -0
- package/src/supervision/SafeRestartScheduler.ts +42 -18
- package/src/terminal/TerminalLinks.ts +26 -0
- package/src/terminal/TerminalPage.ts +44 -24
- package/src/terminal/TerminalServer.ts +98 -36
|
@@ -0,0 +1,1795 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const apiBase = document.body.dataset.workspaceUrl;
|
|
3
|
+
const project = document.body.dataset.project;
|
|
4
|
+
const root = document.body.dataset.root || '';
|
|
5
|
+
const appBase = document.body.dataset.workspaceApp;
|
|
6
|
+
const historyScope = appBase ? new URL(appBase,window.location.href).href : apiBase;
|
|
7
|
+
const isWindowsRoot = base => /^[a-z]:/iu.test(base) || base.startsWith(String.fromCharCode(92));
|
|
8
|
+
const projectPath = (value, base = root) => isWindowsRoot(base) ? value?.replaceAll('\\','/').toLowerCase() : value;
|
|
9
|
+
const stored = key => { try { return JSON.parse(window.localStorage?.getItem(key) || 'null'); } catch { return null; } };
|
|
10
|
+
const chatAnchor = value => value?.bottom === true ? {bottom:true} :
|
|
11
|
+
typeof value?.turn === 'string' && value.turn.length <= 200 && Number.isSafeInteger(value.offset) && Math.abs(value.offset) < 10_000_000
|
|
12
|
+
? {turn:value.turn,offset:value.offset} : undefined;
|
|
13
|
+
const put = (key,value) => { try { window.localStorage?.setItem(key,JSON.stringify(value)); } catch {} };
|
|
14
|
+
const choice = (value, values, fallback) => {
|
|
15
|
+
if (value === undefined || value === null) return fallback;
|
|
16
|
+
if (!values.includes(value)) throw new Error('页面状态中的选项无效。'); return value;
|
|
17
|
+
};
|
|
18
|
+
const offset = value => {
|
|
19
|
+
if (value === undefined) return 0;
|
|
20
|
+
if (!Number.isFinite(value) || value < 0) throw new Error('页面状态中的位置无效。'); return value;
|
|
21
|
+
};
|
|
22
|
+
const relativePath = (value, empty = false) => {
|
|
23
|
+
if (typeof value !== 'string' || (!empty && !value) || value.includes('\0') || /^[\\/]|^[a-z]:/iu.test(value) || value.split(/[\\/]/u).includes('..')) throw new Error('页面状态中的路径无效。'); return value;
|
|
24
|
+
};
|
|
25
|
+
const tabKinds = ['file','diff','new','web','terminal'];
|
|
26
|
+
const webAddress = value => {
|
|
27
|
+
const url = new URL(value);
|
|
28
|
+
if (!['http:','https:'].includes(url.protocol) || url.username || url.password || url.origin === window.location.origin || value.length > 4096) throw new Error('仅支持不含账号密码的外部 HTTP / HTTPS 网址。');
|
|
29
|
+
return url.toString();
|
|
30
|
+
};
|
|
31
|
+
const addressTarget = value => {
|
|
32
|
+
if (/^https?:/iu.test(value)) return webAddress(value);
|
|
33
|
+
if (!value.startsWith('//') && /^file:|^[a-z]:[\\/]|^[\\/]/iu.test(value)) throw new Error('未找到对应的项目文件,请输入 HTTP / HTTPS 网址。');
|
|
34
|
+
const authority = value.replace(/^\/\//u,'').split(/[/?#]/u)[0], host = authority.replace(/:[0-9]+$/u,'');
|
|
35
|
+
const local = /^localhost$|[.]localhost$|^\[[a-f0-9:]+\]$|^[0-9]+(?:[.][0-9]+){3}$/iu.test(host);
|
|
36
|
+
return webAddress((local?'http://':'https://')+value.replace(/^\/\//u,''));
|
|
37
|
+
};
|
|
38
|
+
const fileAddress = (value, root) => {
|
|
39
|
+
const windowsRoot = isWindowsRoot(root);
|
|
40
|
+
if (/^https?:|^\/\//iu.test(value) || /^[^\s/\\:@]+:[0-9]+(?:[/?#]|$)|^\[[a-f0-9:]+\](?::[0-9]+)?(?:[/?#]|$)/iu.test(value)) return;
|
|
41
|
+
if (/^[a-z][a-z0-9+.-]*:/iu.test(value) && !/^file:|^[a-z]:[\\/]/iu.test(value)) throw new Error('仅支持项目文件或 HTTP / HTTPS 网址。');
|
|
42
|
+
const hashIndex = value.indexOf('#'), hash = hashIndex < 0?undefined:value.slice(hashIndex);
|
|
43
|
+
let path = hashIndex < 0?value:value.slice(0,hashIndex);
|
|
44
|
+
if (/^file:/iu.test(path)) { const url = new URL(path); if (url.host && url.host !== 'localhost') throw new Error('仅支持项目内的本地文件。'); path = decodeURIComponent(url.pathname).replace(/^\/([a-z]:)/iu,'$1'); }
|
|
45
|
+
path = path.replaceAll('\\','/'); const base = root.replaceAll('\\','/').replace(/\/$/u,'');
|
|
46
|
+
if (/^[a-z]:|^\//iu.test(path)) {
|
|
47
|
+
if (!projectPath(path,root).startsWith(projectPath(base,root)+'/')) throw new Error('文件必须位于当前项目目录内。'); path = path.slice(base.length+1);
|
|
48
|
+
}
|
|
49
|
+
relativePath(path,true); if (windowsRoot && /[<>:"|?*]/u.test(path)) return; const trailing = path.endsWith('/'); path = path.split('/').filter(part => part && part !== '.').join('/'); if (trailing && path) path += '/';
|
|
50
|
+
return {path,hash,literal:hash && !/^file:/iu.test(value) && (!windowsRoot || !/[<>:"|?*]/u.test(path+hash))?path+hash:undefined};
|
|
51
|
+
};
|
|
52
|
+
const tabPath = (value, kind) => {
|
|
53
|
+
if (kind === 'web') return webAddress(value);
|
|
54
|
+
if (kind === 'new' || kind === 'terminal') { if (typeof value !== 'string' || !/^[a-f0-9]{16}$/u.test(value)) throw new Error('标签标识无效。'); return value; }
|
|
55
|
+
return relativePath(value);
|
|
56
|
+
};
|
|
57
|
+
const instanceId = () => Array.from(crypto.getRandomValues(new Uint8Array(8)),n => n.toString(16).padStart(2,'0')).join('');
|
|
58
|
+
const tabId = value => { if (typeof value !== 'string' || !/^[a-f0-9]{16}$/u.test(value)) throw new Error('标签标识无效。'); return value; };
|
|
59
|
+
const readTreeState = input => {
|
|
60
|
+
const trees = {};
|
|
61
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('本地目录状态无效。');
|
|
62
|
+
for (const mode of ['files','changes']) {
|
|
63
|
+
const value = input[mode]; if (value === undefined) continue;
|
|
64
|
+
if (!value || !Array.isArray(value.expanded ?? []) || !Array.isArray(value.pages ?? []) || !Array.isArray(value.filterCollapsed ?? [])) throw new Error('本地目录状态无效。');
|
|
65
|
+
const pages = (value.pages ?? []).map(item => {
|
|
66
|
+
if (!Array.isArray(item) || item.length !== 2 || !Number.isSafeInteger(item[1]) || item[1] < 1) throw new Error('本地目录页数无效。'); return [relativePath(item[0],true),item[1]];
|
|
67
|
+
});
|
|
68
|
+
if (value.query !== undefined && (typeof value.query !== 'string' || value.query.length > 160)) throw new Error('本地过滤状态无效。');
|
|
69
|
+
trees[mode] = {expanded:(value.expanded || []).map(item => relativePath(item)),pages,scrollTop:offset(value.scrollTop),query:value.query || '',filterScrollTop:offset(value.filterScrollTop),filterCollapsed:(value.filterCollapsed || []).map(item => relativePath(item))};
|
|
70
|
+
}
|
|
71
|
+
return trees;
|
|
72
|
+
};
|
|
73
|
+
const readUrlState = (href = window.location.href, resolveId) => {
|
|
74
|
+
const url = new URL(href), params = url.searchParams;
|
|
75
|
+
const entry = params.get('entry'), kind = choice(params.get('kind'),tabKinds,'file'), mode = choice(params.get('mode'),['all','staged','unstaged'],'all');
|
|
76
|
+
const route = {pane:choice(params.get('pane'),['tasks','chat','files'],'files'),listMode:choice(params.get('list'),['files','changes'],'files'),view:choice(params.get('view'),['list','content'],entry?'content':'list'),tab:entry?{id:params.has('tab')?tabId(params.get('tab')):undefined,path:tabPath(entry,kind),kind,mode,original:params.has('original')?relativePath(params.get('original')):undefined}:null};
|
|
77
|
+
let extra = {v:1}; const encoded = url.hash.startsWith('#workspace=');
|
|
78
|
+
if (encoded) {
|
|
79
|
+
extra = JSON.parse(decodeURIComponent(url.hash.slice(11)));
|
|
80
|
+
if (!extra || typeof extra !== 'object' || Array.isArray(extra) || extra.v !== 1) throw new Error('链接中的页面状态格式无效。');
|
|
81
|
+
}
|
|
82
|
+
const tabs = [];
|
|
83
|
+
if (extra.tabs !== undefined) {
|
|
84
|
+
if (!Array.isArray(extra.tabs)) throw new Error('链接中的文件标签无效。');
|
|
85
|
+
for (const value of extra.tabs) {
|
|
86
|
+
if (!value || typeof value !== 'object') throw new Error('链接中的文件标签无效。');
|
|
87
|
+
const kind = choice(value.kind,tabKinds,'file');
|
|
88
|
+
const path = tabPath(value.path,kind);
|
|
89
|
+
const tab = {id:value.id===undefined?resolveId?.(kind,path) || instanceId():tabId(value.id),path,kind,mode:choice(value.mode,['all','staged','unstaged'],'all'),original:value.original===undefined?undefined:relativePath(value.original),scrollTop:offset(value.scrollTop),scrollLeft:offset(value.scrollLeft),hash:undefined,requestedHash:undefined};
|
|
90
|
+
for (const key of ['hash','requestedHash']) if (value[key] !== undefined) { if (typeof value[key] !== 'string' || !value[key].startsWith('#')) throw new Error('链接中的文件锚点无效。'); tab[key] = value[key]; }
|
|
91
|
+
tabs.push(tab);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (route.tab) {
|
|
95
|
+
let active = tabs.find(tab => route.tab.id?tab.id===route.tab.id:tab.path === route.tab.path && tab.kind === route.tab.kind);
|
|
96
|
+
if (!active) { active = {...route.tab,id:route.tab.id || resolveId?.(kind,route.tab.path) || instanceId(),scrollTop:0,scrollLeft:0}; tabs.push(active); }
|
|
97
|
+
Object.assign(active,{path:route.tab.path,kind:route.tab.kind,mode:route.tab.mode,original:route.tab.original}); route.tab.id = active.id;
|
|
98
|
+
if (!encoded && url.hash) active.hash = active.requestedHash = url.hash;
|
|
99
|
+
route.tab.hash = active.hash;
|
|
100
|
+
}
|
|
101
|
+
const trees = {};
|
|
102
|
+
for (const list of ['files','changes']) {
|
|
103
|
+
const query = extra.trees?.[list]?.query;
|
|
104
|
+
if (query !== undefined && (typeof query !== 'string' || query.length > 160)) throw new Error('文件过滤条件无效。');
|
|
105
|
+
trees[list] = {query:query || ''};
|
|
106
|
+
}
|
|
107
|
+
const scroll = {};
|
|
108
|
+
for (const name of ['tasks','chat','composer','tabs']) if (extra.scroll?.[name] !== undefined) {
|
|
109
|
+
const value = extra.scroll[name]; if (!Array.isArray(value) || value.length !== 2) throw new Error('链接中的滚动状态无效。'); scroll[name] = value.map(offset);
|
|
110
|
+
}
|
|
111
|
+
const layout = {};
|
|
112
|
+
for (const key of ['sidebar','chat','explorer']) if (extra.layout?.[key] !== undefined) { const value = offset(extra.layout[key]); if (value > 4000) throw new Error('面板宽度无效。'); layout[key] = value; }
|
|
113
|
+
for (const key of ['sidebarCollapsed','filesCollapsed','explorerCollapsed']) if (extra.layout?.[key] !== undefined) { if (typeof extra.layout[key] !== 'boolean') throw new Error('面板折叠状态无效。'); layout[key] = extra.layout[key]; }
|
|
114
|
+
const recentTabs = extra.recentTabs ?? [], keys = new Map(tabs.flatMap(tab => [[tab.id,tab.id],[tab.kind+':'+tab.path,tab.id]]));
|
|
115
|
+
if (new Set(tabs.map(tab => tab.id)).size !== tabs.length) throw new Error('链接中的标签标识重复。');
|
|
116
|
+
if (!Array.isArray(recentTabs) || recentTabs.some(key => typeof key !== 'string' || !keys.has(key))) throw new Error('链接中的标签浏览顺序无效。');
|
|
117
|
+
return {route,tabs,trees,scroll,layout,recentTabs:[...new Set(recentTabs.map(key => keys.get(key)))]};
|
|
118
|
+
};
|
|
119
|
+
const element = (tag, text, className) => {
|
|
120
|
+
const node = document.createElement(tag);
|
|
121
|
+
if (text !== undefined) node.textContent = text;
|
|
122
|
+
if (className) node.className = className;
|
|
123
|
+
return node;
|
|
124
|
+
};
|
|
125
|
+
const icons = {
|
|
126
|
+
tasks: '<path d="m3 6 2 2 4-4M12 6h9M3 13h3M12 13h9M3 20h3M12 20h9"/>',
|
|
127
|
+
chat: '<path d="M21 11a8 8 0 0 1-8 8H8l-5 3V11a8 8 0 0 1 8-8h2a8 8 0 0 1 8 8Z"/>',
|
|
128
|
+
folder: '<path d="M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"/>',
|
|
129
|
+
tree: '<rect x="3" y="2" width="6" height="5" rx="1"/><path d="M6 7v13h6M6 12h6"/><rect x="12" y="9" width="9" height="6" rx="1"/><rect x="12" y="17" width="9" height="6" rx="1"/>',
|
|
130
|
+
file: '<path d="M14 2H5a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V9Z M14 2v7h7M8 13h8M8 17h8"/>',
|
|
131
|
+
openFile: '<path d="M9 11v9a1 1 0 0 0 1 1h11a1 1 0 0 0 1-1V9l-6-6h-2M16 3v6h6"/><path d="M3 10V6a2 2 0 0 1 2-2h7m-3-3 3 3-3 3"/>',
|
|
132
|
+
diff: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M7 8h6M10 5v6M11 16h6"/>',
|
|
133
|
+
refresh: '<path d="M20 7a8 8 0 1 0 1 9M20 2v5h-5"/>',
|
|
134
|
+
back: '<path d="m14 5-7 7 7 7"/>',
|
|
135
|
+
forward: '<path d="m10 5 7 7-7 7"/>',
|
|
136
|
+
up: '<path d="M12 20V4m-6 6 6-6 6 6"/>',
|
|
137
|
+
down: '<path d="M12 4v16m-6-6 6 6 6-6"/>',
|
|
138
|
+
close: '<path d="m6 6 12 12M6 18 18 6"/>',
|
|
139
|
+
download: '<path d="M12 3v12m-5-5 5 5 5-5M4 16v5h16v-5"/>',
|
|
140
|
+
send: '<path d="m22 2-7 20-4-9-9-4Z M22 2 11 13"/>',
|
|
141
|
+
lock: '<rect x="5" y="10" width="14" height="11" rx="2"/><path d="M8 10V6a4 4 0 0 1 8 0v4M12 14v3"/>',
|
|
142
|
+
branch: '<circle cx="6" cy="4" r="2"/><circle cx="6" cy="20" r="2"/><circle cx="18" cy="6" r="2"/><path d="M6 6v12M18 8a10 10 0 0 1-12 9"/>',
|
|
143
|
+
plus: '<path d="M12 4v16M4 12h16"/>',
|
|
144
|
+
new: '<rect x="3" y="3" width="18" height="18" rx="2.5"/><path d="M3 8h18M7 5.5h.01M10 5.5h.01"/>',
|
|
145
|
+
sidebar: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/>',
|
|
146
|
+
explorer: '<rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/>',
|
|
147
|
+
web: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3a17 17 0 0 1 0 18 17 17 0 0 1 0-18Z"/>',
|
|
148
|
+
terminal: '<rect x="2" y="3" width="20" height="18" rx="2"/><path d="m6 8 4 4-4 4M13 16h5"/>',
|
|
149
|
+
external: '<path d="M14 3h7v7M21 3 10 14M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-5"/>',
|
|
150
|
+
locate: '<circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/><path d="M12 2v4M12 18v4M2 12h4M18 12h4"/>',
|
|
151
|
+
'file-javascript': '<g stroke="none"><g transform="matrix(0.5 0 0 0.5 3 -16)"><g><path fill="currentColor" stroke="none" d="M 12.65625 59.96094 Q 12.65625 64.94141 10.1953125 67.70508 Q 7.734375 70.46875 3.6328125 70.46875 Q 1.7187501 70.46875 0.48828125 70.01953 L 0.48828125 65.64453 Q 1.6015626 66.40625 3.359375 66.40625 Q 8.0078125 66.40625 8.0078125 59.21875 L 8.0078125 41.992188 L 12.65625 41.992188 L 12.65625 59.96094 Z M 18.027344 68.88672 L 18.027344 64.10156 Q 18.671875 64.6875 19.560547 65.15625 Q 20.449219 65.625 21.445313 65.947266 Q 22.441406 66.26953 23.437498 66.44531 Q 24.433596 66.62109 25.27344 66.62109 Q 28.203125 66.62109 29.638672 65.64453 Q 31.074219 64.66797 31.074219 62.812496 Q 31.074219 61.816406 30.595705 61.083984 Q 30.117188 60.351566 29.257813 59.746094 Q 28.398438 59.140625 27.236328 58.58398 Q 26.074219 58.027348 24.746094 57.421875 Q 23.320313 56.660156 22.089844 55.878906 Q 20.859375 55.097656 19.951172 54.15039 Q 19.042969 53.203125 18.52539 52.01172 Q 18.007813 50.820313 18.007813 49.21875 Q 18.007813 47.246094 18.896484 45.791016 Q 19.785156 44.335938 21.240234 43.38867 Q 22.69531 42.441406 24.550781 41.98242 Q 26.406248 41.523438 28.339842 41.523438 Q 32.734375 41.523438 34.746094 42.51953 L 34.746094 47.109375 Q 32.36328 45.39062 28.613281 45.39062 Q 27.578125 45.39062 26.552734 45.585934 Q 25.527344 45.781246 24.716797 46.230465 Q 23.90625 46.679684 23.398438 47.382816 Q 22.890623 48.085938 22.890623 49.08203 Q 22.890623 50.01953 23.28125 50.703125 Q 23.671875 51.386723 24.423828 51.953125 Q 25.175783 52.51953 26.259766 53.05664 Q 27.34375 53.59375 28.769531 54.218754 Q 30.234375 54.98047 31.533201 55.820313 Q 32.83203 56.660156 33.81836 57.67578 Q 34.804688 58.691406 35.38086 59.931644 Q 35.95703 61.171875 35.95703 62.753906 Q 35.95703 64.88281 35.097656 66.34766 Q 34.23828 67.8125 32.783203 68.73047 Q 31.328125 69.64844 29.433596 70.05859 Q 27.539063 70.46875 25.429688 70.46875 Q 24.72656 70.46875 23.701172 70.36133 Q 22.675781 70.25391 21.601563 70.04883 Q 20.527344 69.84375 19.570313 69.55078 Q 18.613281 69.25781 18.027344 68.88672 Z" /></g></g></g>',
|
|
152
|
+
'file-typescript': '<g stroke="none"><g transform="matrix(0.46511627906976744 0 0 0.46511627906976744 2 -14.046511627906975)"><g><path fill="currentColor" stroke="none" d="M 21.425781 45.9375 L 13.378907 45.9375 L 13.378907 70 L 8.730469 70 L 8.730469 45.9375 L 0.70312494 45.9375 L 0.70312494 41.992188 L 21.425781 41.992188 L 21.425781 45.9375 Z M 24.238283 68.88672 L 24.238283 64.10156 Q 24.882813 64.6875 25.771484 65.15625 Q 26.660158 65.625 27.65625 65.947266 Q 28.652344 66.26953 29.648438 66.44531 Q 30.644531 66.62109 31.484375 66.62109 Q 34.414063 66.62109 35.84961 65.64453 Q 37.285156 64.66797 37.285156 62.812496 Q 37.285156 61.816406 36.80664 61.083984 Q 36.328125 60.351566 35.46875 59.746094 Q 34.609375 59.140625 33.447266 58.58398 Q 32.285156 58.027348 30.957031 57.421875 Q 29.531252 56.660156 28.300781 55.878906 Q 27.070313 55.097656 26.16211 54.15039 Q 25.253906 53.203125 24.736328 52.01172 Q 24.21875 50.820313 24.21875 49.21875 Q 24.21875 47.246094 25.107422 45.791016 Q 25.996094 44.335938 27.451172 43.38867 Q 28.90625 42.441406 30.761717 41.98242 Q 32.617188 41.523438 34.55078 41.523438 Q 38.945313 41.523438 40.95703 42.51953 L 40.95703 47.109375 Q 38.57422 45.39062 34.82422 45.39062 Q 33.789063 45.39062 32.76367 45.585934 Q 31.738281 45.781246 30.927734 46.230465 Q 30.117188 46.679684 29.609375 47.382816 Q 29.101563 48.085938 29.101563 49.08203 Q 29.101563 50.01953 29.492188 50.703125 Q 29.882813 51.386723 30.634766 51.953125 Q 31.386719 52.51953 32.470703 53.05664 Q 33.554688 53.59375 34.98047 54.218754 Q 36.445313 54.98047 37.74414 55.820313 Q 39.04297 56.660156 40.029297 57.67578 Q 41.015625 58.691406 41.591797 59.931644 Q 42.16797 61.171875 42.16797 62.753906 Q 42.16797 64.88281 41.308594 66.34766 Q 40.44922 67.8125 38.99414 68.73047 Q 37.539063 69.64844 35.64453 70.05859 Q 33.75 70.46875 31.640625 70.46875 Q 30.9375 70.46875 29.91211 70.36133 Q 28.88672 70.25391 27.8125 70.04883 Q 26.738281 69.84375 25.78125 69.55078 Q 24.824217 69.25781 24.238283 68.88672 Z" /></g></g></g>',
|
|
153
|
+
'file-cpp': '<g stroke="none"><g transform="matrix(0.5333333333333333 0 0 0.5333333333333333 1.8000000000000007 -17.866666666666667)"><g><path fill="currentColor" stroke="none" d="M 22.988281 68.828125 Q 19.824219 70.46875 15.1171875 70.46875 Q 9.0234375 70.46875 5.3515625 66.62109 Q 1.6796875 62.773438 1.6796875 56.523438 Q 1.6796875 49.804688 5.8105464 45.664063 Q 9.941406 41.523438 16.25 41.523438 Q 20.3125 41.523438 22.988281 42.67578 L 22.988281 47.285156 Q 20.15625 45.60547 16.738281 45.60547 Q 12.187499 45.60547 9.365234 48.515625 Q 6.5429688 51.42578 6.5429688 56.289066 Q 6.5429688 60.91797 9.1796875 63.66211 Q 11.816405 66.40625 16.113281 66.40625 Q 20.078125 66.40625 22.988281 64.53125 L 22.988281 68.828125 Z" /></g></g><path d="M16.3 10.2v4.2m-1.45-2.1h2.9M21.3 10.2v4.2m-1.45-2.1h2.9" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
154
|
+
'file-cpp-header': '<g stroke="none"><g transform="matrix(0.5172413793103449 0 0 0.5172413793103449 2.249999999999999 -16.70689655172414)"><g><path fill="currentColor" stroke="none" d="M 25.957031 70 L 21.289063 70 L 21.289063 57.851563 L 8.105469 57.851563 L 8.105469 70 L 3.4570313 70 L 3.4570313 41.992188 L 8.105469 41.992188 L 8.105469 53.769535 L 21.289063 53.769535 L 21.289063 41.992188 L 25.957031 41.992188 L 25.957031 70 Z" /></g></g><path d="M19 8h3M19 12h3" fill="none" stroke="currentColor" stroke-width="1.45" stroke-linecap="round" stroke-linejoin="round" opacity="0.7" /></g>',
|
|
155
|
+
'file-python': '<g stroke="none"><path fill="currentColor" fill-rule="evenodd" d="M11.85 2.25c-3.33 0-4.83 1.02-4.83 3.15v1.48h5.18v1.14H5.31C2.86 8.02 1.9 9.73 1.9 12.87c0 3.02 1.08 4.65 3.38 4.65h1.33v-2.65c0-2.49 1.71-4.02 4.23-4.02h3.31c2.28 0 3.67-1.14 3.67-3.41V5.47c0-2.15-1.81-3.22-5.97-3.22Z M10.28 4.76a.86.86 0 1 1-1.72 0 .86.86 0 0 1 1.72 0Z"/><path fill="var(--file-icon-secondary,#f2be3a)" fill-rule="evenodd" transform="rotate(180 12 12)" d="M11.85 2.25c-3.33 0-4.83 1.02-4.83 3.15v1.48h5.18v1.14H5.31C2.86 8.02 1.9 9.73 1.9 12.87c0 3.02 1.08 4.65 3.38 4.65h1.33v-2.65c0-2.49 1.71-4.02 4.23-4.02h3.31c2.28 0 3.67-1.14 3.67-3.41V5.47c0-2.15-1.81-3.22-5.97-3.22Z M10.28 4.76a.86.86 0 1 1-1.72 0 .86.86 0 0 1 1.72 0Z"/></g>',
|
|
156
|
+
'file-go': '<g stroke="none"><g transform="matrix(0.32142857142857145 0 0 0.32142857142857145 4.678571428571429 -6.000000000000001)"><g><path fill="currentColor" stroke="none" d="M 25.3125 68.08594 Q 20.9375 70.46875 15.566406 70.46875 Q 9.355469 70.46875 5.5078125 66.60156 Q 1.6601564 62.73438 1.6601564 56.367188 Q 1.6601564 49.86328 5.8691406 45.69336 Q 10.078125 41.523438 16.5625 41.523438 Q 21.230469 41.523438 24.414063 42.890625 L 24.414063 47.67578 Q 21.191406 45.527344 16.738281 45.527344 Q 12.265626 45.527344 9.404297 48.476566 Q 6.5429688 51.42578 6.5429688 56.11328 Q 6.5429688 60.937496 9.003906 63.70117 Q 11.464844 66.46484 15.683595 66.46484 Q 18.574219 66.46484 20.683594 65.35156 L 20.683594 58.691406 L 14.785156 58.691406 L 14.785156 54.785156 L 25.3125 54.785156 L 25.3125 68.08594 Z M 42.890625 70.46875 Q 36.835938 70.46875 33.19336 66.54297 Q 29.550781 62.617184 29.550781 56.328125 Q 29.550781 49.570313 33.26172 45.546875 Q 36.972656 41.523438 43.339844 41.523438 Q 49.23828 41.523438 52.841793 45.429688 Q 56.445313 49.335938 56.445313 55.644535 Q 56.445313 62.5 52.753906 66.484375 Q 49.062504 70.46875 42.890625 70.46875 Z M 43.10547 45.60547 Q 39.257813 45.60547 36.845703 48.476566 Q 34.433594 51.347656 34.433594 56.035152 Q 34.433594 60.703125 36.777344 63.554688 Q 39.121094 66.40625 42.910156 66.40625 Q 46.933598 66.40625 49.257816 63.691406 Q 51.582027 60.976563 51.582027 56.093754 Q 51.582027 51.07422 49.32617 48.339844 Q 47.07031 45.60547 43.10547 45.60547 Z" /></g></g><path d="M1.5 8h2M.5 12h2M1.5 16h2" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
157
|
+
'file-rust': '<g stroke="none"><path fill="currentColor" fill-rule="evenodd" d="M20.18 9.34L21.88 9.90L21.88 14.10L20.18 14.66L19.66 15.90L20.47 17.50L17.50 20.47L15.90 19.66L14.66 20.18L14.10 21.88L9.90 21.88L9.34 20.18L8.10 19.66L6.50 20.47L3.53 17.50L4.34 15.90L3.82 14.66L2.12 14.10L2.12 9.90L3.82 9.34L4.34 8.10L3.53 6.50L6.50 3.53L8.10 4.34L9.34 3.82L9.90 2.12L14.10 2.12L14.66 3.82L15.90 4.34L17.50 3.53L20.47 6.50L19.66 8.10Z M18.8 12a6.8 6.8 0 1 0-13.6 0a6.8 6.8 0 1 0 13.6 0Z" /><g transform="matrix(0.3793103448275862 0 0 0.3793103448275862 6.5 -9.051724137931034)"><g><path fill="currentColor" stroke="none" d="M 25.097656 70 L 19.667969 70 L 15.1953125 62.5 Q 14.589843 61.464844 14.013672 60.73242 Q 13.4375 60 12.841797 59.53125 Q 12.246094 59.062504 11.542969 58.847656 Q 10.839844 58.632813 9.9609375 58.632813 L 8.0859375 58.632813 L 8.0859375 70 L 3.4570313 70 L 3.4570313 41.992188 L 12.675781 41.992188 Q 14.6484375 41.992188 16.308594 42.460938 Q 17.96875 42.929688 19.199219 43.87695 Q 20.429688 44.82422 21.123047 46.240234 Q 21.816406 47.65625 21.816406 49.55078 Q 21.816406 51.035156 21.376953 52.27539 Q 20.9375 53.51563 20.126953 54.48242 Q 19.316406 55.449223 18.173828 56.132813 Q 17.03125 56.816406 15.605468 57.187504 L 15.605468 57.26562 Q 16.367188 57.695313 16.933594 58.21289 Q 17.5 58.73047 18.007813 59.277344 Q 18.515625 59.82422 19.013672 60.517574 Q 19.511719 61.210938 20.117188 62.128906 L 25.097656 70 Z M 8.0859375 45.76172 L 8.0859375 54.863285 L 11.953125 54.863285 Q 13.027344 54.863285 13.935547 54.53125 Q 14.84375 54.19922 15.507813 53.574223 Q 16.171875 52.94922 16.542969 52.05078 Q 16.914063 51.152344 16.914063 50.03906 Q 16.914063 48.027348 15.644531 46.89453 Q 14.375 45.76172 11.992187 45.76172 L 8.0859375 45.76172 Z" /></g></g></g>',
|
|
158
|
+
'file-markdown': '<g stroke="none"><g transform="matrix(0.41935483870967744 0 0 0.41935483870967744 0.24193548387096775 -11.2741935483871)"><g><path fill="currentColor" stroke="none" d="M 33.535156 70 L 28.925781 70 L 28.925781 51.875 Q 28.925781 49.648434 29.199219 46.425777 L 29.121094 46.425777 Q 28.691408 48.26172 28.359375 49.062504 L 20 70 L 16.796875 70 L 8.417969 49.21875 Q 8.066406 48.30078 7.6757813 46.425777 L 7.5976563 46.425777 Q 7.7539067 48.10547 7.7539067 51.914063 L 7.7539067 70 L 3.4570313 70 L 3.4570313 41.992188 L 10 41.992188 L 17.363281 60.64453 Q 18.203125 62.79297 18.457031 63.847656 L 18.554688 63.847656 Q 19.277344 61.64063 19.726563 60.566406 L 27.226563 41.992188 L 33.535156 41.992188 L 33.535156 70 Z" /></g></g><path d="M19.4 5v14m-2.8-2.8 2.8 2.8 2.8-2.8" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
159
|
+
'file-json': '<g stroke="none"><path d="M8.5 3H7.4C6 3 5.2 4 5.2 5.4v3.3c0 1.8-1.1 3.3-3.2 3.3 2.1 0 3.2 1.5 3.2 3.3v3.3C5.2 20 6 21 7.4 21h1.1M15.5 3h1.1c1.4 0 2.2 1 2.2 2.4v3.3c0 1.8 1.1 3.3 3.2 3.3-2.1 0-3.2 1.5-3.2 3.3v3.3c0 1.4-.8 2.4-2.2 2.4h-1.1" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /><circle cx="12" cy="9" r=".8" fill="currentColor" /><circle cx="12" cy="15" r=".8" fill="currentColor" /></g>',
|
|
160
|
+
'file-html': '<g stroke="none"><path d="M4 3h16l-1.5 17L12 22l-6.5-2L4 3Z" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round"/><path d="M7.5 7h8.9l-.2 2H9.8l.15 2.1h6.1l-.55 6.2L12 18.4l-3.7-1.05-.25-2.65h2.1l.12 1.08 1.74.48 1.7-.5 .2-2.6H8.25L7.5 7Z" fill="currentColor"/></g>',
|
|
161
|
+
'file-style': '<g stroke="none"><g transform="matrix(0.6296296296296297 0 0 0.6296296296296297 4.759259259259259 -22.314814814814817)"><g><path fill="currentColor" stroke="none" d="M 22.851564 49.511723 L 22.246094 52.246094 L 17.8125 52.246094 L 16.679688 57.63672 L 21.523438 57.63672 L 20.839844 60.371094 L 16.113281 60.371094 L 14.511719 67.59766 L 11.40625 67.59766 L 12.96875 60.371094 L 8.2421875 60.371094 L 6.71875 67.59766 L 3.6132813 67.59766 L 5.1367188 60.371094 L 0.6640625 60.371094 L 1.2109375 57.63672 L 5.7421875 57.63672 L 6.8164063 52.246094 L 2.0507813 52.246094 L 2.6171875 49.511723 L 7.382813 49.511723 L 8.9453125 41.992188 L 12.089843 41.992188 L 10.546875 49.511723 L 15.2734375 49.511723 L 16.875 41.992188 L 19.960938 41.992188 L 18.398438 49.511723 L 22.851564 49.511723 Z M 14.7265625 52.246094 L 9.9609375 52.246094 L 8.7890625 57.63672 L 13.574218 57.63672 L 14.7265625 52.246094 Z" /></g></g></g>',
|
|
162
|
+
'file-config': '<g stroke="none"><path d="M3 6h3.4m3.2 0H21M3 12h11.4m3.2 0H21M3 18h5.4m3.2 0H21" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /><path d="M6.4 4h3.2v4h-3.2Z" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" /><path d="M14.4 10h3.2v4h-3.2Z" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" /><path d="M8.4 16h3.2v4h-3.2Z" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" /></g>',
|
|
163
|
+
'file-shell': '<g stroke="none"><path d="M12.2 6.6c-1.2-1.1-2.8-1.4-4.1-1-1.7.5-2.4 2-1.5 3.2.8 1 2.3 1.4 3.7 1.9 1.8.6 3 1.3 2.8 3-.3 1.9-2.6 2.7-4.5 2.1-1-.3-1.8-.7-2.4-1.4M9.8 3.5v15.5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/><path d="M15.8 18h5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></g>',
|
|
164
|
+
'file-image': '<g stroke="none"><rect x="2.7" y="4.5" width="18.6" height="15.5" rx="1.4" fill="none" stroke="currentColor" stroke-width="1.5" /><circle cx="8" cy="9.5" r="1.4" fill="currentColor" /><path d="m4 18 5-5 4 4 3-5 4 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
165
|
+
'file-pdf': '<g stroke="none"><path d="M7.5 17.5c2-3.7 3.8-8.7 4-12 .1-3.3-2.2-3.6-2.4-1.2-.4 5.2 4.5 10 8.8 11.1 4.1 1 5-.8 2.5-1.4-4.2-1.1-11.7.7-15.9 3.3-3.8 2.4-3.8 4.3-1.7 3.9 1.3-.3 2.8-2 4.7-5.7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
166
|
+
'file-archive': '<g stroke="none"><path d="M9 3.5h6V8H9ZM12 8v13M9 11h3m0 3h3M9 17h3m0 3h3" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
167
|
+
'file-database': '<g stroke="none"><ellipse cx="12" cy="5" rx="8" ry="3" fill="none" stroke="currentColor" stroke-width="1.5" /><path d="M4 5v13c0 4 16 4 16 0V5M4 11c0 4 16 4 16 0" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
168
|
+
'file-git': '<g stroke="none"><path d="M7 6v12m0-10 8.4 6.4" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round" opacity="1" /><circle cx="7" cy="4" r="2" fill="none" stroke="currentColor" stroke-width="1.5" /><circle cx="7" cy="20" r="2" fill="none" stroke="currentColor" stroke-width="1.5" /><circle cx="17" cy="16" r="2" fill="none" stroke="currentColor" stroke-width="1.5" /></g>',
|
|
169
|
+
'file-package': '<g stroke="none"><path d="m12 2.5 8.5 4.7v9.6L12 21.5l-8.5-4.7V7.2L12 2.5m-8.5 4.7 8.5 4.7 8.5-4.7M12 11.9v9.6m-4.2-16.7 8.5 4.7v4.6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
170
|
+
'file-docker': '<g stroke="none"><path fill="currentColor" fill-rule="evenodd" d="M2 12.5h15.7c1-2.1 3-2.9 4.7-2.1-.2 2.2-1.8 3.9-3.6 4.2-1.4 4.8-6 6.3-10.4 5.8-3.3-.4-5.9-2.6-6.4-7.9Zm14.5 1.2a.7.7 0 1 0 0 1.4.7.7 0 0 0 0-1.4Z" /><rect x="5.2" y="8.7" width="2.4" height="2.4" rx=".25" fill="currentColor" /><rect x="8.3" y="8.7" width="2.4" height="2.4" rx=".25" fill="currentColor" /><rect x="11.4" y="8.7" width="2.4" height="2.4" rx=".25" fill="currentColor" /><rect x="14.5" y="8.7" width="2.4" height="2.4" rx=".25" fill="currentColor" /><rect x="8.3" y="5.5" width="2.4" height="2.4" rx=".25" fill="currentColor" /><rect x="11.4" y="5.5" width="2.4" height="2.4" rx=".25" fill="currentColor" /></g>',
|
|
171
|
+
'file-code': '<g stroke="none"><path d="m8 6-6 6 6 6m8-12 6 6-6 6m-2-15-4 18" fill="none" stroke="currentColor" stroke-width="1.65" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
172
|
+
'file-file': '<g stroke="none"><path d="M14.5 2.5H6A1.5 1.5 0 0 0 4.5 4v16A1.5 1.5 0 0 0 6 21.5h12A1.5 1.5 0 0 0 19.5 20V7.5l-5-5v5h5M8 12h8M8 16h6" fill="none" stroke="currentColor" stroke-width="1.45" stroke-linecap="round" stroke-linejoin="round" opacity="1" /></g>',
|
|
173
|
+
'file-cmake': '<g stroke="none"><path d="M11.65 2.7 2.3 21.1 10.05 17.15Z" fill="currentColor"/><path d="m12.75 2.7 9 18.4-7.4-5.35Z" fill="var(--file-icon-secondary,#e36357)"/><path d="m11.5 11.6-3.2 7.1 11.75 2.5-6.35-5.6Z" fill="var(--file-icon-tertiary,#53b783)"/></g>',
|
|
174
|
+
'file-make': '<g stroke="none"><g transform="rotate(-38 12 12)"><path d="M4.7 4.3h9.8l4.8 2.2-2.1 2.5-3.7-.7H9.6L7.5 9H4.7V4.3Z" fill="currentColor"/><rect x="9.5" y="8" width="3.5" height="13" rx=".8" fill="currentColor"/><path d="M10.5 16.8h1.5" fill="none" stroke="var(--file-icon-secondary,#f7d999)" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round"/></g></g>',
|
|
175
|
+
'file-gn': '<g stroke="none"><g transform="translate(0 -1.5)"><path d="M11.1 8.4v9.2c0 2.9-1.6 4.1-4.3 4.1-1.5 0-2.6-.4-3.4-1.1M11.1 11.7a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0M15 7.9v10.2M15 11.1c0-2 1.3-3.4 3.4-3.4 2.2 0 3.4 1.5 3.4 3.5v6.9" fill="none" stroke="currentColor" stroke-width="2.05" stroke-linecap="round" stroke-linejoin="round"/></g></g>',
|
|
176
|
+
'file-ninja': '<g stroke="none"><path fill="currentColor" fill-rule="evenodd" d="M12 2.5l2.1 6.25 7.4 3.25-6.25 2.1L12 21.5l-2.1-6.25L2.5 12l6.25-2.1L12 2.5Z M13.7 12a1.7 1.7 0 1 1-3.4 0 1.7 1.7 0 0 1 3.4 0Z"/></g>',
|
|
177
|
+
'file-bazel': '<g stroke="none"><path d="m12 2.8 9.2 4.85L12 12.5 2.8 7.65Z" fill="currentColor"/><path d="m12 2.8 9.2 4.85L12 12.5Z" fill="var(--file-icon-secondary,#31a776)"/><path d="m2.8 11.3 9.2 4.85 9.2-4.85v4.2L12 20.35 2.8 15.5Z" fill="var(--file-icon-secondary,#31a776)"/><path d="m2.8 11.3 9.2 4.85v4.2L2.8 15.5Z" fill="currentColor"/></g>',
|
|
178
|
+
'file-license': '<g stroke="none"><path d="M12 4v16M7 21h10M4.5 7.2h15" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/><circle cx="12" cy="3.6" r="1.5" fill="currentColor"/><path d="m5 7.2-3 6.7m3-6.7 3 6.7m11-6.7-3 6.7m3-6.7 3 6.7" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linecap="round" stroke-linejoin="round"/><path d="M1.7 13.7h6.6a3.3 3.3 0 0 1-6.6 0Zm14 0h6.6a3.3 3.3 0 0 1-6.6 0Z" fill="currentColor"/></g>',
|
|
179
|
+
'file-agents': '<g stroke="none"><path d="M12 3.4v3.1M3.7 11.2H2v4.5h1.7m16.6-4.5H22v4.5h-1.7" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round"/><circle cx="12" cy="2.9" r="1.25" fill="currentColor"/><rect x="4.2" y="6.6" width="15.6" height="13.2" rx="3.2" fill="none" stroke="currentColor" stroke-width="1.65"/><rect x="7.5" y="10.4" width="2.3" height="3.2" rx="1.05" fill="currentColor"/><rect x="14.2" y="10.4" width="2.3" height="3.2" rx="1.05" fill="currentColor"/><path d="M9.2 16.7h5.6" fill="none" stroke="currentColor" stroke-width="1.45" stroke-linecap="round" stroke-linejoin="round"/></g>',
|
|
180
|
+
'file-readme': '<g stroke="none"><path d="M12 6.3C9.7 4.6 6.6 4.3 3.1 5v14.4c3.5-.7 6.6-.4 8.9 1.3 2.3-1.7 5.4-2 8.9-1.3V5c-3.5-.7-6.6-.4-8.9 1.3Zm0 0v14.4M6.1 9.1l3 .5m5.8 0 3-.5M6.1 12.6l3 .5m5.8 0 3-.5" fill="none" stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round"/></g>',
|
|
181
|
+
};
|
|
182
|
+
const icon = name => {
|
|
183
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg','svg');
|
|
184
|
+
svg.setAttribute('viewBox','0 0 24 24'); svg.setAttribute('fill','none'); svg.setAttribute('stroke','currentColor');
|
|
185
|
+
svg.setAttribute('stroke-width','1.7'); svg.setAttribute('stroke-linecap','round'); svg.setAttribute('stroke-linejoin','round');
|
|
186
|
+
svg.setAttribute('aria-hidden','true'); svg.setAttribute('focusable','false'); svg.setAttribute('class','workspace-icon');
|
|
187
|
+
svg.innerHTML = icons[name]; return svg;
|
|
188
|
+
};
|
|
189
|
+
const iconControl = (tag, name, label, className = '') => {
|
|
190
|
+
const node = element(tag,undefined,'icon-control '+className); node.append(icon(name));
|
|
191
|
+
node.title = label; node.setAttribute('aria-label',label); return node;
|
|
192
|
+
};
|
|
193
|
+
const fileIcon = path => {
|
|
194
|
+
const name = path.replaceAll('\\','/').split('/').pop().toLowerCase(), extension = name.split('.').pop();
|
|
195
|
+
const names = {dockerfile:'docker','docker-compose.yml':'docker','compose.yaml':'docker','.gitignore':'git','.gitattributes':'git','.gitmodules':'git','package.json':'package','package-lock.json':'package','npm-shrinkwrap.json':'package','yarn.lock':'package','pnpm-lock.yaml':'package','cargo.toml':'package','go.mod':'package','cmakelists.txt':'cmake',makefile:'make',gnumakefile:'make','makefile.am':'make','makefile.in':'make','.gn':'gn',build:'bazel','build.bazel':'bazel',workspace:'bazel','workspace.bazel':'bazel','module.bazel':'bazel','agents.md':'agents'};
|
|
196
|
+
const extensions = {ts:'typescript',tsx:'typescript',mts:'typescript',cts:'typescript',js:'javascript',jsx:'javascript',mjs:'javascript',cjs:'javascript',py:'python',pyi:'python',pyw:'python',go:'go',rs:'rust',md:'markdown',markdown:'markdown',mdx:'markdown',mdown:'markdown',mkd:'markdown',mkdn:'markdown',json:'json',jsonc:'json',json5:'json',css:'style',scss:'style',sass:'style',less:'style',html:'html',htm:'html',vue:'html',svelte:'html',svg:'image',png:'image',jpg:'image',jpeg:'image',gif:'image',webp:'image',ico:'image',bmp:'image',pdf:'pdf',zip:'archive',tar:'archive',gz:'archive','7z':'archive',rar:'archive',sh:'shell',bash:'shell',zsh:'shell',ps1:'shell',bat:'shell',cmd:'shell',sql:'database',csv:'database',db:'database',sqlite:'database',yaml:'config',yml:'config',toml:'config',ini:'config',conf:'config',env:'config',xml:'config',cmake:'cmake',mk:'make',mak:'make',gn:'gn',gni:'gn',ninja:'ninja',bazel:'bazel',bzl:'bazel',c:'cpp',cc:'cpp',cpp:'cpp',cxx:'cpp','c++':'cpp',ixx:'cpp',cppm:'cpp',h:'cpp-header',hh:'cpp-header',hpp:'cpp-header',hxx:'cpp-header','h++':'cpp-header',inl:'cpp-header',inc:'cpp-header',cs:'code',java:'code',kt:'code',swift:'code',rb:'code',php:'code'};
|
|
197
|
+
const special = /^readme(?:[.-]|$)/.test(name)?'readme':/^(?:licen[cs]e|copying)(?:[.-]|$)/.test(name)?'license':undefined;
|
|
198
|
+
const type = Object.hasOwn(names,name)?names[name]:special ?? (Object.hasOwn(extensions,extension)?extensions[extension]:'file'), svg = icon('file-'+type);
|
|
199
|
+
svg.setAttribute('stroke','none'); svg.setAttribute('stroke-linecap','butt'); svg.setAttribute('stroke-linejoin','miter');
|
|
200
|
+
svg.classList.add('file-icon'); svg.dataset.type = type; return svg;
|
|
201
|
+
};
|
|
202
|
+
const gitStatus = item => {
|
|
203
|
+
const index = item.index || ' ', worktree = item.worktree || ' '; if (index === ' ' && worktree === ' ') return;
|
|
204
|
+
const names = {M:'修改',A:'新增',D:'删除',R:'重命名',C:'复制',T:'类型变化'};
|
|
205
|
+
const labels = item.conflict ? ['冲突'] : item.untracked ? ['未跟踪'] : [index !== ' ' ? '已暂存 · '+(names[index] || index) : '',worktree !== ' ' ? '未暂存 · '+(names[worktree] || worktree) : ''].filter(Boolean);
|
|
206
|
+
const status = element('span',item.conflict?'!':item.untracked?'U':index === 'D' || worktree === 'D'?'D':index !== ' '?index:worktree,'change-status');
|
|
207
|
+
status.title = labels.join(' / '); status.setAttribute('aria-hidden','true'); status.dataset.kind = item.conflict?'conflict':item.untracked?'untracked':index === 'D' || worktree === 'D'?'deleted':'changed'; return status;
|
|
208
|
+
};
|
|
209
|
+
const lineStats = item => {
|
|
210
|
+
const stats = element('span',undefined,'tree-line-stats');
|
|
211
|
+
if (Number.isSafeInteger(item.additions) && Number.isSafeInteger(item.deletions)) {
|
|
212
|
+
stats.append(element('span','+'+item.additions,'line-additions'),element('span','−'+item.deletions,'line-deletions'));
|
|
213
|
+
stats.title = (item.directory?'目录累计':'')+'增加 '+item.additions+' 行,删除 '+item.deletions+' 行'+(item.lineStatsIncomplete?'(部分文件无可用行数,仅累计已统计文本文件)':'');
|
|
214
|
+
} else { stats.textContent = '—'; stats.title = '无可用文本行数统计(二进制、超过 2 MiB、读取超时或失败)。'; }
|
|
215
|
+
stats.setAttribute('aria-hidden','true'); return stats;
|
|
216
|
+
};
|
|
217
|
+
const directoryGitStatus = (summary,item) => {
|
|
218
|
+
if (item.ignored) { summary.classList.add('is-git-ignored'); summary.setAttribute('aria-label',item.name+',Git 已忽略'); }
|
|
219
|
+
if (!item.changes) return;
|
|
220
|
+
const count = element('span',String(item.changes),'directory-git-status count-badge'), label = '目录内 '+item.changes+' 个文件有 Git 变更', stats = lineStats(item), metadata = element('span',undefined,'tree-git-meta');
|
|
221
|
+
count.title = label; count.setAttribute('aria-hidden','true'); metadata.append(stats,count); summary.append(metadata); summary.setAttribute('aria-label',item.name+(item.ignored?',Git 已忽略':'')+','+label+','+stats.title);
|
|
222
|
+
};
|
|
223
|
+
class WorkspaceScrollbars {
|
|
224
|
+
constructor(host) {
|
|
225
|
+
this.host = host; this.hovered = new Set(); this.recent = new Map(); this.entries = new Map(); this.targets = new WeakMap();
|
|
226
|
+
this.layer = element('div',undefined,'workspace-scrollbars'); this.layer.setAttribute('aria-hidden','true'); host.append(this.layer);
|
|
227
|
+
this.layer.addEventListener('pointerdown',this.startDrag); this.layer.addEventListener('pointermove',this.moveDrag);
|
|
228
|
+
this.layer.addEventListener('pointerup',this.endDrag); this.layer.addEventListener('pointercancel',this.endDrag); this.layer.addEventListener('lostpointercapture',this.endDrag);
|
|
229
|
+
this.layer.addEventListener('wheel',this.wheel,{passive:false});
|
|
230
|
+
host.addEventListener('pointerover',this.pointer); host.addEventListener('pointerout',this.pointer);
|
|
231
|
+
host.addEventListener('scroll',this.scrolled,true); host.addEventListener('load',this.queue,true); window.addEventListener('resize',this.queue);
|
|
232
|
+
this.observer = new window.MutationObserver(records => { if (records.some(record => !this.layer.contains(record.target))) this.queue(); });
|
|
233
|
+
this.observer.observe(host,{subtree:true,childList:true,attributes:true,attributeFilter:['class','hidden','open','style','data-pane','data-view','data-file-tab','data-special-tab']});
|
|
234
|
+
}
|
|
235
|
+
pointer = event => {
|
|
236
|
+
if (event.pointerType === 'touch') return;
|
|
237
|
+
this.hovered.clear();
|
|
238
|
+
let node = event.type === 'pointerout' ? event.relatedTarget : event.target;
|
|
239
|
+
node = this.targets.get(node?.closest?.('.scrollbar-track'))?.node ?? node;
|
|
240
|
+
while (node?.nodeType === 1 && this.host.contains(node)) { this.hovered.add(node); node = node.parentElement; }
|
|
241
|
+
this.queue();
|
|
242
|
+
};
|
|
243
|
+
geometry(node,axis,axes) {
|
|
244
|
+
const horizontal = axis === 'x', size = horizontal ? node.clientWidth : node.clientHeight, content = horizontal ? node.scrollWidth : node.scrollHeight;
|
|
245
|
+
const length = Math.max(0,size-4-(axes[horizontal?'vertical':'horizontal']?12:0));
|
|
246
|
+
const thumb = Math.min(length,Math.max(24,size*size/content)), travel = length-thumb, max = content-size;
|
|
247
|
+
const ratio = Math.max(0,Math.min(1,(horizontal?node.scrollLeft:node.scrollTop)/max));
|
|
248
|
+
return {length,thumb,travel,max,position:ratio*travel};
|
|
249
|
+
}
|
|
250
|
+
startDrag = event => {
|
|
251
|
+
if (event.button !== 0 || this.dragging) return;
|
|
252
|
+
const track = event.target.closest('.scrollbar-track'), target = this.targets.get(track); if (!target) return;
|
|
253
|
+
const {node,axis} = target, axes = this.axes(node), bounds = axes && this.bounds(node); if (!bounds) return;
|
|
254
|
+
const geometry = this.geometry(node,axis,axes); if (geometry.travel <= 0) return;
|
|
255
|
+
const coordinate = axis === 'x'?event.clientX:event.clientY, start = bounds.port[axis === 'x'?'left':'top']+2, position = coordinate-start;
|
|
256
|
+
const onThumb = position >= geometry.position && position <= geometry.position+geometry.thumb;
|
|
257
|
+
this.dragging = {node,axis,track,pointerId:event.pointerId,grab:onThumb?position-geometry.position:geometry.thumb/2};
|
|
258
|
+
track.setPointerCapture(event.pointerId); track.classList.add('is-dragging'); this.host.classList.add('is-scrollbar-dragging');
|
|
259
|
+
event.preventDefault(); if (!onThumb) this.moveDrag(event); this.queue();
|
|
260
|
+
};
|
|
261
|
+
moveDrag = event => {
|
|
262
|
+
const drag = this.dragging; if (!drag || event.pointerId !== drag.pointerId) return;
|
|
263
|
+
const {node,axis,grab} = drag, axes = this.axes(node), bounds = axes && this.bounds(node);
|
|
264
|
+
if (!bounds || !axes[axis === 'x'?'horizontal':'vertical']) { this.endDrag(); return; }
|
|
265
|
+
const geometry = this.geometry(node,axis,axes); if (geometry.travel <= 0) { this.endDrag(); return; }
|
|
266
|
+
const coordinate = axis === 'x'?event.clientX:event.clientY, start = bounds.port[axis === 'x'?'left':'top']+2;
|
|
267
|
+
node[axis === 'x'?'scrollLeft':'scrollTop'] = Math.max(0,Math.min(1,(coordinate-start-grab)/geometry.travel))*geometry.max;
|
|
268
|
+
event.preventDefault(); this.queue();
|
|
269
|
+
};
|
|
270
|
+
endDrag = event => {
|
|
271
|
+
const drag = this.dragging; if (!drag || event && event.pointerId !== drag.pointerId) return;
|
|
272
|
+
this.dragging = undefined; drag.track.classList.remove('is-dragging'); this.host.classList.remove('is-scrollbar-dragging');
|
|
273
|
+
if (drag.track.hasPointerCapture(drag.pointerId)) drag.track.releasePointerCapture(drag.pointerId);
|
|
274
|
+
this.recent.set(drag.node,Date.now()+900); this.queue();
|
|
275
|
+
};
|
|
276
|
+
wheel = event => {
|
|
277
|
+
const target = this.targets.get(event.target.closest('.scrollbar-track')); if (!target || event.ctrlKey) return;
|
|
278
|
+
let x = event.deltaX, y = event.deltaY;
|
|
279
|
+
if (target.node.classList.contains('file-tabs') && Math.abs(y) > Math.abs(x) || event.shiftKey && x === 0) { x = y; y = 0; }
|
|
280
|
+
let moved = false;
|
|
281
|
+
for (const [axis,delta] of [['x',x],['y',y]]) {
|
|
282
|
+
if (!delta) continue;
|
|
283
|
+
const horizontal = axis === 'x', property = horizontal?'scrollLeft':'scrollTop';
|
|
284
|
+
for (let node = target.node; node && this.host.contains(node); node = node.parentElement) {
|
|
285
|
+
const axes = this.axes(node); if (!axes?.[horizontal?'horizontal':'vertical']) continue;
|
|
286
|
+
const size = horizontal?node.clientWidth:node.clientHeight, maximum = (horizontal?node.scrollWidth:node.scrollHeight)-size;
|
|
287
|
+
const before = node[property], scale = event.deltaMode === 1?16:event.deltaMode === 2?size:1;
|
|
288
|
+
node[property] = Math.max(0,Math.min(maximum,before+delta*scale)); if (node[property] === before) continue;
|
|
289
|
+
moved = true; this.recent.set(node,Date.now()+900); break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (moved) { event.preventDefault(); this.queue(); }
|
|
293
|
+
};
|
|
294
|
+
scrolled = event => {
|
|
295
|
+
if (this.axes(event.target)) this.recent.set(event.target,Date.now()+900);
|
|
296
|
+
this.queue();
|
|
297
|
+
};
|
|
298
|
+
queue = () => {
|
|
299
|
+
if (!this.host.isConnected || this.frame !== undefined) return;
|
|
300
|
+
this.frame = window.requestAnimationFrame(() => { this.frame = undefined; this.render(); });
|
|
301
|
+
};
|
|
302
|
+
axes(node) {
|
|
303
|
+
if (!this.host.contains(node) || !(node.clientWidth > 0 && node.clientHeight > 0)) return;
|
|
304
|
+
const x = node.scrollWidth > node.clientWidth+1, y = node.scrollHeight > node.clientHeight+1; if (!x && !y) return;
|
|
305
|
+
const style = window.getComputedStyle(node), horizontal = x && ['auto','scroll'].includes(style.overflowX), vertical = y && ['auto','scroll'].includes(style.overflowY);
|
|
306
|
+
if (horizontal || vertical) return {horizontal,vertical};
|
|
307
|
+
}
|
|
308
|
+
bounds(node) {
|
|
309
|
+
const rect = node.getBoundingClientRect(), left = rect.left+node.clientLeft, top = rect.top+node.clientTop;
|
|
310
|
+
const port = {left,top,right:left+node.clientWidth,bottom:top+node.clientHeight};
|
|
311
|
+
const clip = {left:Math.max(left,0),top:Math.max(top,0),right:Math.min(port.right,window.innerWidth),bottom:Math.min(port.bottom,window.innerHeight)};
|
|
312
|
+
for (let parent = node.parentElement; parent; parent = parent.parentElement) {
|
|
313
|
+
const style = window.getComputedStyle(parent); if (style.overflowX === 'visible' && style.overflowY === 'visible') continue;
|
|
314
|
+
const box = parent.getBoundingClientRect();
|
|
315
|
+
if (style.overflowX !== 'visible') { clip.left = Math.max(clip.left,box.left+parent.clientLeft); clip.right = Math.min(clip.right,box.left+parent.clientLeft+parent.clientWidth); }
|
|
316
|
+
if (style.overflowY !== 'visible') { clip.top = Math.max(clip.top,box.top+parent.clientTop); clip.bottom = Math.min(clip.bottom,box.top+parent.clientTop+parent.clientHeight); }
|
|
317
|
+
}
|
|
318
|
+
if (clip.right > clip.left && clip.bottom > clip.top) return {port,clip};
|
|
319
|
+
}
|
|
320
|
+
render() {
|
|
321
|
+
const now = Date.now(); clearTimeout(this.timer);
|
|
322
|
+
for (const [node,until] of this.recent) if (until <= now || !this.host.contains(node)) this.recent.delete(node);
|
|
323
|
+
for (const node of this.hovered) if (!this.host.contains(node)) this.hovered.delete(node);
|
|
324
|
+
const visible = new Set();
|
|
325
|
+
for (const node of new Set([...this.hovered,...this.recent.keys(),...(this.dragging?[this.dragging.node]:[])])) {
|
|
326
|
+
const axes = this.axes(node), bounds = axes && this.bounds(node);
|
|
327
|
+
if (this.dragging?.node === node && (!bounds || !axes[this.dragging.axis === 'x'?'horizontal':'vertical'])) this.endDrag();
|
|
328
|
+
if (!bounds) continue;
|
|
329
|
+
const {port,clip} = bounds; let entry = this.entries.get(node);
|
|
330
|
+
if (!entry) {
|
|
331
|
+
const box = element('div',undefined,'workspace-scrollbar'), x = element('span',undefined,'scrollbar-x'), y = element('span',undefined,'scrollbar-y');
|
|
332
|
+
const trackX = element('div',undefined,'scrollbar-track scrollbar-track-x'), trackY = element('div',undefined,'scrollbar-track scrollbar-track-y');
|
|
333
|
+
box.dataset.region = node.classList.contains('file-tabs') ? 'tabs' : node.classList.contains('content-body') ? 'content' : node.classList.contains('file-navigation') ? 'tree' : 'other';
|
|
334
|
+
box.append(trackX,trackY,x,y); this.layer.append(box); entry = {box,x,y,trackX,trackY}; this.entries.set(node,entry);
|
|
335
|
+
this.targets.set(trackX,{node,axis:'x'}); this.targets.set(trackY,{node,axis:'y'});
|
|
336
|
+
}
|
|
337
|
+
visible.add(node);
|
|
338
|
+
Object.assign(entry.box.style,{left:clip.left+'px',top:clip.top+'px',width:clip.right-clip.left+'px',height:clip.bottom-clip.top+'px'});
|
|
339
|
+
entry.x.hidden = entry.trackX.hidden = !axes.horizontal; entry.y.hidden = entry.trackY.hidden = !axes.vertical;
|
|
340
|
+
if (axes.horizontal) {
|
|
341
|
+
const geometry = this.geometry(node,'x',axes), tabs = entry.box.dataset.region === 'tabs', top = tabs ? port.top+1 : port.bottom-5;
|
|
342
|
+
Object.assign(entry.x.style,{left:port.left-clip.left+2+geometry.position+'px',top:top-clip.top+'px',width:geometry.thumb+'px'});
|
|
343
|
+
Object.assign(entry.trackX.style,{left:port.left-clip.left+2+'px',top:(tabs?port.top:port.bottom-12)-clip.top+'px',width:geometry.length+'px',height:(tabs?6:12)+'px'});
|
|
344
|
+
}
|
|
345
|
+
if (axes.vertical) {
|
|
346
|
+
const geometry = this.geometry(node,'y',axes);
|
|
347
|
+
Object.assign(entry.y.style,{left:port.right-clip.left-5+'px',top:port.top-clip.top+2+geometry.position+'px',height:geometry.thumb+'px'});
|
|
348
|
+
Object.assign(entry.trackY.style,{left:port.right-clip.left-12+'px',top:port.top-clip.top+2+'px',width:'12px',height:geometry.length+'px'});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (const [node,entry] of this.entries) if (!visible.has(node)) { entry.box.remove(); this.entries.delete(node); }
|
|
352
|
+
if (this.recent.size) this.timer = setTimeout(this.queue,Math.max(1,Math.min(...this.recent.values())-Date.now()));
|
|
353
|
+
}
|
|
354
|
+
disconnect() {
|
|
355
|
+
this.endDrag();
|
|
356
|
+
this.observer.disconnect(); clearTimeout(this.timer); if (this.frame !== undefined) window.cancelAnimationFrame(this.frame);
|
|
357
|
+
this.layer.removeEventListener('pointerdown',this.startDrag); this.layer.removeEventListener('pointermove',this.moveDrag);
|
|
358
|
+
this.layer.removeEventListener('pointerup',this.endDrag); this.layer.removeEventListener('pointercancel',this.endDrag); this.layer.removeEventListener('lostpointercapture',this.endDrag);
|
|
359
|
+
this.layer.removeEventListener('wheel',this.wheel);
|
|
360
|
+
this.host.removeEventListener('pointerover',this.pointer); this.host.removeEventListener('pointerout',this.pointer);
|
|
361
|
+
this.host.removeEventListener('scroll',this.scrolled,true); this.host.removeEventListener('load',this.queue,true); window.removeEventListener('resize',this.queue);
|
|
362
|
+
this.hovered.clear(); this.recent.clear(); this.entries.clear();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
class WorkspaceTaskList extends HTMLElement {
|
|
366
|
+
connectedCallback() {
|
|
367
|
+
this.replaceChildren(element('h2','项目任务','pane-heading'),element('div',project,'workspace-project'),element('div','任务列表将在后续接入。当前页面只浏览这个项目,不创建或切换任务。','workspace-placeholder'));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
class WorkspaceChat extends HTMLElement {
|
|
371
|
+
connectedCallback() {
|
|
372
|
+
const body = element('div',undefined,'chat-body');
|
|
373
|
+
body.append(element('div','Agent 聊天将在后续接入,不会启动 Agent。文件浏览保持只读,终端须单独点击并认证。','workspace-placeholder'));
|
|
374
|
+
const composer = element('div',undefined,'chat-composer'), input = element('textarea'), send = iconControl('button','send','发送(聊天尚未接入)');
|
|
375
|
+
input.disabled = send.disabled = true;
|
|
376
|
+
input.placeholder = '聊天能力尚未接入'; input.setAttribute('aria-label','聊天输入(尚未接入)');
|
|
377
|
+
composer.append(input,send);
|
|
378
|
+
this.replaceChildren(element('h2','聊天','pane-heading'),body,composer);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
class WorkspaceFiles extends HTMLElement {
|
|
382
|
+
connectedCallback() {
|
|
383
|
+
this.dataset.noProject = String(!this.fileApi);
|
|
384
|
+
this.controllers = new Set(); this.tabs = new Map(); this.views = new Map(); this.activeKey = undefined; this.recentTabs = [];
|
|
385
|
+
this.renderedKey = undefined;
|
|
386
|
+
this.dataset.view = 'list'; this.listScrollTop = 0;
|
|
387
|
+
this.generation = 0; this.navigationGeneration = 0; this.navigationSequence = 0; this.listMode = 'files';
|
|
388
|
+
this.innerHTML = '<div class="file-tabs" role="tablist" aria-label="已打开文件"></div><div class="content-toolbar" hidden></div><div class="file-layout"><section class="file-main"><div class="content-body" role="region" aria-label="文件内容" tabindex="0"><div class="content-empty">从右侧文件树选择文件,或在改动列表中查看 Git 变更。</div></div></section><aside class="file-explorer" aria-label="文件浏览"><div class="file-toolbar"><div class="file-list-switch" role="group" aria-label="文件浏览方式"><button data-list="files" aria-pressed="true">文件</button><button data-list="changes" aria-pressed="false">未提交</button></div><button class="refresh" title="刷新列表和当前文件">刷新</button></div><nav class="file-navigation" aria-label="项目文件"></nav></aside></div>';
|
|
389
|
+
this.navigation = this.querySelector('.file-navigation'); this.tabBar = this.querySelector('.file-tabs');
|
|
390
|
+
const strip = element('div',undefined,'file-tab-strip'); this.tabBar.before(strip); strip.append(this.tabBar);
|
|
391
|
+
const actions = element('div',undefined,'tab-actions'), add = iconControl('button','plus','新标签','new-tab');
|
|
392
|
+
add.onclick = () => this.openNew(); actions.append(add); strip.append(actions);
|
|
393
|
+
this.explorerToggle = iconControl('button','explorer','折叠文件列表','toggle-explorer');
|
|
394
|
+
this.explorerToggle.onclick = () => { this.saveScroll(); this.closest('agentbot-workspace').togglePanel('explorer'); this.restoreScroll(); };
|
|
395
|
+
const mobileAdd = iconControl('button','plus','新标签','mobile-new-tab'); mobileAdd.onclick = () => this.openNew(); this.querySelector('.file-toolbar').append(mobileAdd);
|
|
396
|
+
this.frameLayer = element('div',undefined,'workspace-frame-layer'); this.frameLayer.hidden = true; this.querySelector('.file-main').append(this.frameLayer);
|
|
397
|
+
this.querySelector('.file-explorer').before(this.closest('agentbot-workspace').separator('explorer','调整文件列表宽度'));
|
|
398
|
+
const searchBox = element('div',undefined,'file-search'), search = element('input'); search.type = 'search'; search.placeholder = '过滤文件 / 路径'; search.maxLength = 160; search.setAttribute('aria-label','过滤文件');
|
|
399
|
+
searchBox.append(search); this.querySelector('.file-toolbar').after(searchBox); this.search = search;
|
|
400
|
+
search.addEventListener('input',() => this.setFilter(search.value));
|
|
401
|
+
this.tabBar.addEventListener('wheel',event => {
|
|
402
|
+
if (event.ctrlKey || Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
403
|
+
const left = this.tabBar.scrollLeft, scale = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? this.tabBar.clientWidth : 1;
|
|
404
|
+
this.scrollTabs(left+event.deltaY*scale);
|
|
405
|
+
if (this.tabBar.scrollLeft !== left) event.preventDefault();
|
|
406
|
+
},{passive:false});
|
|
407
|
+
this.tabBar.addEventListener('scroll',() => this.rememberTabsScroll());
|
|
408
|
+
this.tabResize = new ResizeObserver(() => this.resizeTabs()); this.tabResize.observe(this.tabBar);
|
|
409
|
+
this.toolbar = this.querySelector('.content-toolbar'); this.content = this.querySelector('.content-body');
|
|
410
|
+
this.navigationBack = iconControl('button','back','后退','navigation-back mobile-back'); this.navigationBack.onclick = () => this.closest('agentbot-workspace').goBack();
|
|
411
|
+
this.navigationForward = iconControl('button','forward','前进','navigation-forward'); this.navigationForward.onclick = () => this.closest('agentbot-workspace').traverseHistory(1);
|
|
412
|
+
this.content.addEventListener('scroll',() => this.updateDiffNavigation());
|
|
413
|
+
this.diffResize = () => this.updateDiffNavigation(); window.addEventListener('resize',this.diffResize);
|
|
414
|
+
this.content.onclick = event => {
|
|
415
|
+
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
416
|
+
const link = event.target.closest('a'); if (!link) return;
|
|
417
|
+
if (link.dataset.workspaceEntry !== undefined) { event.preventDefault(); this.openFile(link.dataset.workspaceEntry,'file',undefined,new URL(link.href).hash); }
|
|
418
|
+
else if (link.getAttribute('href')?.startsWith('#')) {
|
|
419
|
+
event.preventDefault(); this.navigate(() => { const tab = this.tabs.get(this.activeKey); tab.hash = tab.requestedHash = link.getAttribute('href'); this.restoreHash(tab); });
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
this.navigationViews = new Map([['files',{node:this.navigation,scrollTop:0,pending:0,ready:false,expanded:new Set(),pages:new Map(),restorePages:new Map(),observers:new Set()}]]);
|
|
423
|
+
this.addEventListener('click',this.keepTreeRow,true);
|
|
424
|
+
this.addEventListener('mousedown',this.startTreeToggle,true);
|
|
425
|
+
this.addEventListener('keydown',this.clearTreePointerFocus,true);
|
|
426
|
+
this.addEventListener('scroll',this.trimTreeScroll,true);
|
|
427
|
+
const filesButton = this.querySelector('[data-list=files]'), changesButton = this.querySelector('[data-list=changes]');
|
|
428
|
+
filesButton.replaceChildren(icon('tree')); filesButton.classList.add('icon-control'); filesButton.title = '项目文件'; filesButton.setAttribute('aria-label','项目文件');
|
|
429
|
+
const count = element('span',undefined,'count-badge'); count.hidden = true; count.setAttribute('aria-hidden','true');
|
|
430
|
+
changesButton.replaceChildren(icon('diff'),count); changesButton.classList.add('icon-control'); changesButton.title = '未提交改动'; changesButton.setAttribute('aria-label','未提交改动');
|
|
431
|
+
const refresh = this.querySelector('.refresh'); refresh.replaceChildren(icon('refresh')); refresh.classList.add('icon-control'); refresh.setAttribute('aria-label',refresh.title);
|
|
432
|
+
this.locateButton = iconControl('button','locate','在列表中定位当前文件','locate-current-file'); refresh.before(this.locateButton); this.locateButton.onclick = () => this.revealCurrentFile();
|
|
433
|
+
this.revealMessage = element('div',undefined,'reveal-message'); this.revealMessage.hidden = true; this.revealMessage.setAttribute('role','status'); this.navigation.before(this.revealMessage);
|
|
434
|
+
for (const button of this.querySelectorAll('[data-list]')) {
|
|
435
|
+
button.onclick = () => this.selectList(button.dataset.list);
|
|
436
|
+
}
|
|
437
|
+
this.querySelector('.refresh').onclick = () => {
|
|
438
|
+
this.saveScroll(); this.loadNavigation(this.listMode,true); const tab = this.tabs.get(this.activeKey); if (tab) this.loadTab(tab,true);
|
|
439
|
+
};
|
|
440
|
+
this.renderTabs();
|
|
441
|
+
if (!this.fileApi) this.content.replaceChildren(element('div','此任务没有可浏览的项目目录。','content-empty'));
|
|
442
|
+
}
|
|
443
|
+
disconnectedCallback() {
|
|
444
|
+
this.removeEventListener('click',this.keepTreeRow,true);
|
|
445
|
+
this.removeEventListener('mousedown',this.startTreeToggle,true);
|
|
446
|
+
this.removeEventListener('keydown',this.clearTreePointerFocus,true);
|
|
447
|
+
this.removeEventListener('scroll',this.trimTreeScroll,true);
|
|
448
|
+
this.disposeAddressPicker(); window.removeEventListener('resize',this.diffResize);
|
|
449
|
+
this.tabResize.disconnect();
|
|
450
|
+
for (const controller of this.controllers) controller.abort();
|
|
451
|
+
this.controllers.clear();
|
|
452
|
+
for (const view of this.navigationViews.values()) for (const observer of view.observers) observer.disconnect();
|
|
453
|
+
this.tabs.clear(); this.views.clear();
|
|
454
|
+
clearTimeout(this.searchTimer); this.searchController?.abort();
|
|
455
|
+
}
|
|
456
|
+
navigate(action, replace = false) {
|
|
457
|
+
const app = this.closest('agentbot-workspace');
|
|
458
|
+
if (app?.filesPanel === this) app.navigate(action,replace);
|
|
459
|
+
}
|
|
460
|
+
queuePersist() { const app = this.closest('agentbot-workspace'); if (app?.filesPanel === this) app.queuePersist(); }
|
|
461
|
+
pathKey(value) { return projectPath(value,this.projectRoot); }
|
|
462
|
+
startTreeToggle = event => {
|
|
463
|
+
if (event.button !== 0) return;
|
|
464
|
+
const summary = event.target.closest('summary'); if (!summary || !this.navigation.contains(summary)) return;
|
|
465
|
+
this.clearTreePointerFocus(); summary.classList.add('is-pointer-focused');
|
|
466
|
+
summary.focus({preventScroll:true}); event.preventDefault();
|
|
467
|
+
};
|
|
468
|
+
clearTreePointerFocus = event => {
|
|
469
|
+
if (event && !['Tab','Enter',' ','ArrowUp','ArrowDown','ArrowLeft','ArrowRight','Home','End'].includes(event.key)) return;
|
|
470
|
+
for (const summary of this.navigation.querySelectorAll('summary.is-pointer-focused')) summary.classList.remove('is-pointer-focused');
|
|
471
|
+
};
|
|
472
|
+
keepTreeRow = event => {
|
|
473
|
+
const summary = event.target.closest('summary'); if (!summary || !this.navigation.contains(summary)) return;
|
|
474
|
+
this.reserveTreeScroll(this.navigation.scrollTop);
|
|
475
|
+
};
|
|
476
|
+
trimTreeScroll = event => { if (event.target === this.navigation) this.reserveTreeScroll(this.navigation.scrollTop); };
|
|
477
|
+
reserveTreeScroll(top) {
|
|
478
|
+
const navigation = this.navigation; if (!navigation.clientHeight) return;
|
|
479
|
+
const tree = navigation.querySelector(':scope > .navigation-tree');
|
|
480
|
+
if (tree) tree.style.minHeight = top > 0 ? 'calc(100% + '+top+'px)' : '';
|
|
481
|
+
}
|
|
482
|
+
navigationView(mode) {
|
|
483
|
+
let view = this.navigationViews.get(mode);
|
|
484
|
+
if (!view) { view = {node:this.navigation.cloneNode(false),scrollTop:0,pending:0,ready:false,expanded:new Set(),pages:new Map(),restorePages:new Map(),observers:new Set()}; this.navigationViews.set(mode,view); }
|
|
485
|
+
return view;
|
|
486
|
+
}
|
|
487
|
+
restoreTrees(trees) {
|
|
488
|
+
for (const mode of ['files','changes']) {
|
|
489
|
+
const saved = trees[mode], view = this.navigationViews.get(mode) || (saved ? this.navigationView(mode) : undefined); if (!view) continue;
|
|
490
|
+
const expanded = new Set(saved?.expanded || []);
|
|
491
|
+
const changed = [...view.expanded].some(path => !expanded.has(path)) || [...expanded].some(path => !view.expanded.has(path));
|
|
492
|
+
const pages = new Map(saved?.pages || []), needsPages = [...pages].some(([entry,count]) => count > (view.pages.get(entry) || 0));
|
|
493
|
+
view.expanded = expanded; view.restorePages = pages; view.scrollTop = saved?.scrollTop || 0;
|
|
494
|
+
view.filterScrollTop = saved?.filterScrollTop || 0; view.filterCollapsed = new Set(saved?.filterCollapsed || []);
|
|
495
|
+
for (const details of view.node.querySelectorAll('details[data-directory]')) details.open = expanded.has(details.dataset.directory);
|
|
496
|
+
for (const details of view.filterNode?.querySelectorAll('details[data-filter-directory]') || []) details.open = !view.filterCollapsed.has(details.dataset.filterDirectory);
|
|
497
|
+
if (view.ready && (changed || needsPages)) this.loadNavigation(mode);
|
|
498
|
+
if ((view.query || '') !== (saved?.query || '')) { view.query = saved?.query || ''; if (view.query && !view.filterNode) view.filterNode = view.node.cloneNode(false); }
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
selectList(mode) {
|
|
502
|
+
this.navigate(() => {
|
|
503
|
+
if (mode === this.listMode) {
|
|
504
|
+
const view = this.navigationView(mode), node = view.query?view.filterNode:view.node;
|
|
505
|
+
if (this.navigation !== node) { this.navigation.replaceWith(node); this.navigation = node; }
|
|
506
|
+
this.search.value = view.query || ''; if (view.query && view.filterQuery !== view.query) this.filterNavigation(mode);
|
|
507
|
+
if (this.fileApi && !view.ready && !view.pending) this.loadNavigation(mode);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
this.saveScroll(); const previous = this.navigationViews.get(this.listMode);
|
|
511
|
+
previous.scrollTop = this.listScrollTop;
|
|
512
|
+
const view = this.navigationView(mode);
|
|
513
|
+
const node = view.query ? view.filterNode : view.node;
|
|
514
|
+
this.navigation.replaceWith(node); this.navigation = node; this.listMode = mode; this.search.value = view.query || '';
|
|
515
|
+
if (view.query && view.filterQuery !== view.query) this.filterNavigation(mode);
|
|
516
|
+
this.navigationGeneration = view.generation; this.listScrollTop = view.query ? view.filterScrollTop || 0 : view.scrollTop; this.dataset.view = 'list';
|
|
517
|
+
for (const button of this.querySelectorAll('[data-list]')) button.setAttribute('aria-pressed',String(button.dataset.list === mode));
|
|
518
|
+
if (this.fileApi && !view.ready && !view.pending) this.loadNavigation(); this.restoreScroll(); this.syncFrames();
|
|
519
|
+
this.updateCurrentFile();
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
async request(api, params = {}, controller = new AbortController()) {
|
|
523
|
+
if (!this.fileApi) throw new Error('此任务没有可浏览的项目目录。');
|
|
524
|
+
const url = new URL(this.fileApi); url.searchParams.set('api',api);
|
|
525
|
+
for (const [key,value] of Object.entries(params)) if (value !== undefined) url.searchParams.set(key,String(value));
|
|
526
|
+
this.controllers.add(controller);
|
|
527
|
+
const timer = setTimeout(() => controller.abort(),15000);
|
|
528
|
+
try {
|
|
529
|
+
const response = await fetch(url,{signal:controller.signal,credentials:api === 'terminal'?'same-origin':'omit',cache:'no-store'});
|
|
530
|
+
let data;
|
|
531
|
+
try { data = await response.json(); }
|
|
532
|
+
catch { throw new Error('服务器返回无效 JSON(HTTP '+response.status+')'); }
|
|
533
|
+
if (!response.ok) throw Object.assign(new Error(data.error || '读取失败(HTTP '+response.status+')'),{status:response.status});
|
|
534
|
+
return data;
|
|
535
|
+
} catch (error) {
|
|
536
|
+
if (error.name === 'AbortError') throw new Error('读取超时,请重试。');
|
|
537
|
+
if (error.name === 'TypeError') throw new Error('网络不可用:'+error.message);
|
|
538
|
+
throw error;
|
|
539
|
+
} finally { clearTimeout(timer); this.controllers.delete(controller); }
|
|
540
|
+
}
|
|
541
|
+
notice(container, text, retry) {
|
|
542
|
+
const message = element('div',text,'navigation-message'+(retry?' error':'')); container.replaceChildren(message);
|
|
543
|
+
if (retry) { const button = iconControl('button','refresh','重试'); button.onclick = retry; container.append(button); }
|
|
544
|
+
}
|
|
545
|
+
async updateChangesCount() {
|
|
546
|
+
const generation = this.navigationGeneration;
|
|
547
|
+
try {
|
|
548
|
+
const data = await this.request('changes',{prefetch:1});
|
|
549
|
+
if (!this.isConnected || generation !== this.navigationGeneration) return;
|
|
550
|
+
const view = this.navigationView('changes'); if (!view.ready && !view.pending && Array.isArray(data.preloaded)) { view.rootData = data; this.cacheMetadata(view,data); }
|
|
551
|
+
this.applyChangesMetadata(data);
|
|
552
|
+
} catch (error) {
|
|
553
|
+
if (this.isConnected && generation === this.navigationGeneration) this.showChangesCountError(error);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
showChangesCountError(error) {
|
|
557
|
+
const button = this.querySelector('[data-list=changes]');
|
|
558
|
+
const count = button.querySelector('.count-badge'); count.textContent = '!'; count.hidden = false;
|
|
559
|
+
button.title = '读取未提交改动失败:'+error.message; button.setAttribute('aria-label',button.title);
|
|
560
|
+
}
|
|
561
|
+
applyChangesMetadata(data) {
|
|
562
|
+
const button = this.querySelector('[data-list=changes]'), count = button.querySelector('.count-badge');
|
|
563
|
+
count.textContent = String(data.totalChanges); count.hidden = data.totalChanges === 0;
|
|
564
|
+
button.title = '未提交改动,'+data.totalChanges+' 个'+(data.notice?' · '+data.notice:''); button.setAttribute('aria-label',button.title);
|
|
565
|
+
this.dispatchEvent(new CustomEvent('workspace-status',{bubbles:true,detail:{label:data.branch || data.notice || '只读工作台',repository:data.repository === true}}));
|
|
566
|
+
}
|
|
567
|
+
cacheMetadata(view, data) {
|
|
568
|
+
if (!Array.isArray(data.preloaded)) return;
|
|
569
|
+
view.preloaded = data.preloaded; view.directoryCache = new Map([['',[]]]);
|
|
570
|
+
for (const item of data.preloaded) {
|
|
571
|
+
const parent = item.path.includes('/')?item.path.slice(0,item.path.lastIndexOf('/')):'';
|
|
572
|
+
if (!view.directoryCache.has(parent)) view.directoryCache.set(parent,[]); view.directoryCache.get(parent).push(item);
|
|
573
|
+
if (item.directory && !view.directoryCache.has(item.path)) view.directoryCache.set(item.path,[]);
|
|
574
|
+
}
|
|
575
|
+
for (const [entry,items] of view.directoryCache) view.directoryCache.set(entry,{...data,preloaded:undefined,entries:items.sort((a,b) => Number(b.directory)-Number(a.directory) || a.name.localeCompare(b.name,undefined,{numeric:true})),total:items.length,page:0,totalPages:1});
|
|
576
|
+
}
|
|
577
|
+
createFileButton(item, mode) {
|
|
578
|
+
const changed = mode === 'changes', button = element('button',undefined,changed?'change-file':'tree-file');
|
|
579
|
+
button.dataset.filePath = item.path;
|
|
580
|
+
button.append(fileIcon(item.path),element('span',item.name,changed?'change-name':undefined));
|
|
581
|
+
const title = item.originalPath ? item.originalPath+' → '+item.path : item.path;
|
|
582
|
+
button.title = item.error || title; button.disabled = item.blocked;
|
|
583
|
+
if (item.ignored) { button.classList.add('is-git-ignored'); button.setAttribute('aria-label',title+' · Git 已忽略'); }
|
|
584
|
+
const status = gitStatus(item);
|
|
585
|
+
if (status) {
|
|
586
|
+
const stats = lineStats(item), metadata = element('span',undefined,'tree-git-meta');
|
|
587
|
+
metadata.append(stats,status); button.setAttribute('aria-label',title+' · '+status.title+' · '+stats.title); button.append(metadata);
|
|
588
|
+
}
|
|
589
|
+
button.onclick = event => {
|
|
590
|
+
const selection = window.getSelection();
|
|
591
|
+
if (event.detail > 0 && selection && !selection.isCollapsed && selection.containsNode(button,true)) return;
|
|
592
|
+
this.openFile(item.path,changed?'diff':'file',item.originalPath);
|
|
593
|
+
}; return button;
|
|
594
|
+
}
|
|
595
|
+
updateCurrentFile() {
|
|
596
|
+
const tab = this.tabs.get(this.activeKey), path = tab && ['file','diff'].includes(tab.kind) ? tab.path : undefined, currentPath = this.pathKey(path);
|
|
597
|
+
this.locateButton.disabled = !path || this.revealing;
|
|
598
|
+
for (const view of this.navigationViews.values()) for (const node of [view.node,view.filterNode]) if (node) {
|
|
599
|
+
for (const button of node.querySelectorAll('[data-file-path]')) {
|
|
600
|
+
const active = this.pathKey(button.dataset.filePath) === currentPath; button.classList.toggle('is-current-file',active);
|
|
601
|
+
if (active) button.setAttribute('aria-current','true'); else button.removeAttribute('aria-current');
|
|
602
|
+
}
|
|
603
|
+
for (const details of node.querySelectorAll('details[data-directory],details[data-filter-directory]')) {
|
|
604
|
+
const directory = this.pathKey(details.dataset.directory ?? details.dataset.filterDirectory);
|
|
605
|
+
details.classList.toggle('is-current-path',Boolean(currentPath?.startsWith(directory+'/')));
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
async revealCurrentFile(keepView = false) {
|
|
610
|
+
const tab = this.tabs.get(this.activeKey); if (this.revealing || !tab || !['file','diff'].includes(tab.kind)) return;
|
|
611
|
+
const mode = keepView?this.listMode:tab.kind === 'diff' ? 'changes' : 'files';
|
|
612
|
+
if (keepView && this.navigationView(mode).query) { this.pendingFilterTarget = {key:tab.key,mode,path:tab.path,query:this.navigationView(mode).query}; this.revealFilteredFile(); return; }
|
|
613
|
+
this.revealing = true; this.revealMessage.hidden = true; this.locateButton.setAttribute('aria-busy','true'); this.updateCurrentFile();
|
|
614
|
+
if (!keepView) this.navigate(() => {
|
|
615
|
+
this.saveScroll(); this.selectList(mode);
|
|
616
|
+
if (this.navigationView(mode).query) { this.search.value = ''; this.setFilter(''); }
|
|
617
|
+
this.dataset.view = 'list';
|
|
618
|
+
const app = this.closest('agentbot-workspace'); app.selectPane('files'); if (app.layout.explorerCollapsed) { app.layout.explorerCollapsed = false; app.applyLayout(); }
|
|
619
|
+
});
|
|
620
|
+
const view = this.navigationView(mode), generation = view.generation;
|
|
621
|
+
const current = () => this.isConnected && this.activeKey === tab.key && this.listMode === mode && (keepView || this.dataset.view === 'list' && this.closest('agentbot-workspace').dataset.pane === 'files') && this.navigation === view.node && generation === view.generation && !view.query;
|
|
622
|
+
const find = async (container, path) => {
|
|
623
|
+
let loaded;
|
|
624
|
+
while (current()) {
|
|
625
|
+
if (loaded !== container.loading) { const pending = container.loading; await pending; loaded = pending; continue; }
|
|
626
|
+
const item = [...container.children].find(node => this.pathKey(node.dataset.directory) === this.pathKey(path) || this.pathKey(node.dataset.filePath) === this.pathKey(path));
|
|
627
|
+
if (item) return item;
|
|
628
|
+
const continuation = [...container.children].find(node => node.classList.contains('navigation-continuation'));
|
|
629
|
+
if (!continuation) throw new Error(container.querySelector('.navigation-message.error')?.textContent || '当前文件不在'+(mode === 'changes'?'未提交改动':'文件')+'列表中,可能已移动、删除或状态已变化。');
|
|
630
|
+
await continuation.loadNext();
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
try {
|
|
634
|
+
await view.loading;
|
|
635
|
+
if (!current()) return;
|
|
636
|
+
let container = view.node.firstElementChild; const parts = this.pathKey(tab.path).split('/');
|
|
637
|
+
for (let index = 1; index < parts.length; index++) {
|
|
638
|
+
const path = parts.slice(0,index).join('/'), directory = await find(container,path); if (!directory || !current()) return;
|
|
639
|
+
if (!directory.dataset.directory) throw new Error('父目录不是可访问目录:'+directory.title);
|
|
640
|
+
if (directory.firstElementChild.getAttribute('aria-disabled') === 'true') throw new Error(directory.textContent);
|
|
641
|
+
view.expanded.add(directory.dataset.directory); directory.open = true; await directory.loadChildren(); if (!current() || !directory.open) return; container = directory.lastElementChild;
|
|
642
|
+
}
|
|
643
|
+
const target = await find(container,tab.path); if (!target || !current()) return;
|
|
644
|
+
for (let parent = target.closest('details'); parent; parent = parent.parentElement.closest('details')) if (!parent.open) return;
|
|
645
|
+
if (!target.dataset.filePath) throw new Error('当前路径已变成目录,无法定位原文件。');
|
|
646
|
+
if (target.disabled) throw new Error(target.title);
|
|
647
|
+
this.updateCurrentFile();
|
|
648
|
+
this.pendingTreeTarget = {key:tab.key,mode,node:target}; this.centerTreeTarget();
|
|
649
|
+
if (!keepView) target.focus({preventScroll:true}); this.saveScroll(); this.queuePersist();
|
|
650
|
+
} catch (error) {
|
|
651
|
+
if (current()) { this.revealMessage.hidden = false; this.notice(this.revealMessage,'定位失败:'+error.message,() => { this.loadNavigation(mode,true).then(() => this.revealCurrentFile(keepView)); }); }
|
|
652
|
+
} finally {
|
|
653
|
+
this.revealing = false;
|
|
654
|
+
if (this.isConnected) { this.locateButton.removeAttribute('aria-busy'); this.updateCurrentFile(); }
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
centerTreeTarget() {
|
|
658
|
+
const target = this.pendingTreeTarget; if (!target) return;
|
|
659
|
+
if (target.key !== this.activeKey || target.mode !== this.listMode || !this.navigation.contains(target.node)) { this.pendingTreeTarget = undefined; return; }
|
|
660
|
+
if (this.navigation.clientHeight <= 0) return;
|
|
661
|
+
for (let parent = target.node.closest('details'); parent; parent = parent.parentElement.closest('details')) if (!parent.open) { this.pendingTreeTarget = undefined; return; }
|
|
662
|
+
const row = target.node.getBoundingClientRect(), viewport = this.navigation.getBoundingClientRect();
|
|
663
|
+
this.navigation.scrollTop = Math.max(0,this.navigation.scrollTop+row.top-viewport.top-(this.navigation.clientHeight-row.height)/2); this.pendingTreeTarget = undefined; this.saveScroll();
|
|
664
|
+
}
|
|
665
|
+
revealFilteredFile() {
|
|
666
|
+
const target = this.pendingFilterTarget; if (!target) return;
|
|
667
|
+
const view = this.navigationView(target.mode);
|
|
668
|
+
if (target.key !== this.activeKey || target.mode !== this.listMode || target.query !== view.query) { this.pendingFilterTarget = undefined; return; }
|
|
669
|
+
if (view.filterQuery !== target.query || this.navigation !== view.filterNode) return;
|
|
670
|
+
this.pendingFilterTarget = undefined;
|
|
671
|
+
const node = [...view.filterNode.querySelectorAll('[data-file-path]')].find(node => this.pathKey(node.dataset.filePath) === this.pathKey(target.path)); if (!node) return;
|
|
672
|
+
for (let parent = node.closest('details'); parent; parent = parent.parentElement.closest('details')) { parent.open = true; view.filterCollapsed?.delete(parent.dataset.filterDirectory); }
|
|
673
|
+
this.pendingTreeTarget = {key:target.key,mode:target.mode,node}; this.centerTreeTarget(); this.queuePersist();
|
|
674
|
+
}
|
|
675
|
+
setFilter(query) {
|
|
676
|
+
const view = this.navigationView(this.listMode); if (!view.query) this.saveScroll();
|
|
677
|
+
if (view.query !== query.trim()) { view.filterScrollTop = 0; view.filterCollapsed = new Set(); }
|
|
678
|
+
view.query = query.trim(); this.searchController?.abort(); this.searchSequence = (this.searchSequence || 0)+1; clearTimeout(this.searchTimer);
|
|
679
|
+
if (!view.query) { this.navigation.replaceWith(view.node); this.navigation = view.node; this.navigation.scrollTop = view.scrollTop; this.listScrollTop = view.scrollTop; }
|
|
680
|
+
else {
|
|
681
|
+
if (!view.filterNode) view.filterNode = view.node.cloneNode(false);
|
|
682
|
+
if (this.navigation !== view.filterNode) { this.navigation.replaceWith(view.filterNode); this.navigation = view.filterNode; }
|
|
683
|
+
this.notice(view.filterNode,'正在过滤…'); view.filterNode.scrollTop = this.listScrollTop = 0;
|
|
684
|
+
this.searchTimer = setTimeout(() => this.filterNavigation(this.listMode),180);
|
|
685
|
+
}
|
|
686
|
+
this.queuePersist();
|
|
687
|
+
}
|
|
688
|
+
async filterNavigation(mode) {
|
|
689
|
+
const view = this.navigationView(mode), query = view.query; if (!query) return;
|
|
690
|
+
if (!view.filterNode) view.filterNode = view.node.cloneNode(false);
|
|
691
|
+
if (mode !== this.listMode) return;
|
|
692
|
+
const sequence = this.searchSequence = (this.searchSequence || 0)+1;
|
|
693
|
+
if (mode === this.listMode && this.navigation !== view.filterNode) { this.navigation.replaceWith(view.filterNode); this.navigation = view.filterNode; }
|
|
694
|
+
const node = view.filterNode; this.notice(node,'正在过滤…');
|
|
695
|
+
this.searchController?.abort(); const controller = this.searchController = new AbortController();
|
|
696
|
+
try {
|
|
697
|
+
const normalized = query.replaceAll('\\','/').toLowerCase();
|
|
698
|
+
const data = view.preloaded ? {entries:view.preloaded.filter(item => item.path.toLowerCase().includes(normalized)),truncated:false,gitError:view.gitError} : await this.request(mode === 'changes'?'changes':'tree',{query},controller);
|
|
699
|
+
if (!this.isConnected || sequence !== this.searchSequence || query !== view.query) return;
|
|
700
|
+
view.filterQuery = query;
|
|
701
|
+
const flat = new Map(), ignored = new Set((data.ignoredPaths || view.preloaded?.filter(item => item.directory && item.ignored).map(item => item.path) || []).map(value => this.pathKey(value)));
|
|
702
|
+
const directoryChanges = new Map((data.directoryChanges || view.preloaded?.filter(item => item.directory) || []).map(item => [this.pathKey(item.path),item]));
|
|
703
|
+
for (const item of data.entries) {
|
|
704
|
+
flat.set(item.path,item);
|
|
705
|
+
for (let path = item.path.includes('/')?item.path.slice(0,item.path.lastIndexOf('/')):''; path; path = path.includes('/')?path.slice(0,path.lastIndexOf('/')):'') {
|
|
706
|
+
if (!flat.has(path)) flat.set(path,{...directoryChanges.get(this.pathKey(path)),path,name:path.split('/').pop(),directory:true,ignored:ignored.has(this.pathKey(path))});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const list = element('div',undefined,'navigation-tree'); node.replaceChildren(list); const folders = new Map([['',list]]);
|
|
710
|
+
const entries = [...flat.values()].sort((a,b) => a.path.split('/').length-b.path.split('/').length || Number(b.directory)-Number(a.directory) || a.path.localeCompare(b.path,undefined,{numeric:true}));
|
|
711
|
+
for (const item of entries) {
|
|
712
|
+
const parent = folders.get(item.path.includes('/')?item.path.slice(0,item.path.lastIndexOf('/')):'');
|
|
713
|
+
if (item.directory) {
|
|
714
|
+
const details = element('details'), summary = element('summary'), children = element('div'); summary.append(element('span',item.name)); summary.title = item.path;
|
|
715
|
+
directoryGitStatus(summary,item);
|
|
716
|
+
details.dataset.filterDirectory = item.path;
|
|
717
|
+
details.open = !view.filterCollapsed?.has(item.path); details.append(summary,children); parent.append(details); folders.set(item.path,children);
|
|
718
|
+
details.addEventListener('toggle',() => { if (query !== view.query || !node.contains(details)) return; view.filterCollapsed ??= new Set(); if (details.open) view.filterCollapsed.delete(item.path); else view.filterCollapsed.add(item.path); this.queuePersist(); });
|
|
719
|
+
}
|
|
720
|
+
else parent.append(this.createFileButton(item,mode));
|
|
721
|
+
}
|
|
722
|
+
if (!entries.length) list.append(element('div',data.notice || '没有匹配的文件。','navigation-message'));
|
|
723
|
+
if (data.gitError) list.append(element('div','读取 Git 状态失败:'+data.gitError,'navigation-message error'));
|
|
724
|
+
if (data.truncated) list.append(element('div','结果未完整加载(最多扫描 20000 条 / 1 秒,返回 300 个匹配)。请用目录前缀缩小范围,例如 src/名称。','navigation-message'));
|
|
725
|
+
if (mode === this.listMode) this.search.value = view.query;
|
|
726
|
+
this.reserveTreeScroll(view.filterScrollTop || 0);
|
|
727
|
+
node.scrollTop = view.filterScrollTop || 0; this.listScrollTop = view.filterScrollTop || 0;
|
|
728
|
+
this.updateCurrentFile();
|
|
729
|
+
this.revealFilteredFile();
|
|
730
|
+
} catch (error) {
|
|
731
|
+
if (this.isConnected && sequence === this.searchSequence && query === view.query) this.notice(node,'过滤失败:'+error.message,() => this.filterNavigation(mode));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
async loadNavigation(mode = this.listMode, refresh = false) {
|
|
735
|
+
const generation = ++this.navigationSequence, view = this.navigationView(mode);
|
|
736
|
+
if (mode === this.listMode) this.navigationGeneration = generation;
|
|
737
|
+
for (const details of view.node.querySelectorAll('details[data-directory]')) {
|
|
738
|
+
if (details.open) view.expanded.add(details.dataset.directory); else view.expanded.delete(details.dataset.directory);
|
|
739
|
+
}
|
|
740
|
+
for (const observer of view.observers) observer.disconnect(); view.observers.clear();
|
|
741
|
+
if (!view.restorePages.size) view.restorePages = new Map(view.pages); view.pages.clear();
|
|
742
|
+
view.generation = generation; view.ready = false;
|
|
743
|
+
if (refresh) view.preloaded = view.directoryCache = view.rootData = undefined;
|
|
744
|
+
view.node.setAttribute('aria-label',mode === 'changes'?'未提交改动目录树':'项目文件');
|
|
745
|
+
const list = element('div',undefined,'navigation-tree'); view.node.replaceChildren(list);
|
|
746
|
+
view.loading = this.loadDirectory(list,'',0,generation,mode); await view.loading;
|
|
747
|
+
if (generation === view.generation) {
|
|
748
|
+
view.ready = true;
|
|
749
|
+
if (view.query) this.filterNavigation(mode);
|
|
750
|
+
if (this.navigation === view.node) { this.listScrollTop = view.scrollTop; this.restoreScroll(); }
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
expandSingleDirectory(container) {
|
|
754
|
+
let parent = container.closest('details');
|
|
755
|
+
while (parent) { if (!parent.open) return; parent = parent.parentElement.closest('details'); }
|
|
756
|
+
return container.expandSingle?.();
|
|
757
|
+
}
|
|
758
|
+
loadDirectory(container, entry, page, generation, mode, expandChain = false) {
|
|
759
|
+
const pending = this.readDirectory(container,entry,page,generation,mode,expandChain); container.loading = pending; return pending;
|
|
760
|
+
}
|
|
761
|
+
async readDirectory(container, entry, page, generation, mode, expandChain = false) {
|
|
762
|
+
const view = this.navigationViews.get(mode), rootPage = !entry && page === 0; view.pending++;
|
|
763
|
+
const loading = element('div','正在读取…','navigation-message'); loading.setAttribute('role','status'); container.append(loading);
|
|
764
|
+
try {
|
|
765
|
+
let data = view.directoryCache?.get(entry) || (rootPage ? view.rootData : undefined);
|
|
766
|
+
if (!data) data = await this.request(mode === 'changes'?'changes':'tree',{entry,page,prefetch:rootPage?1:undefined});
|
|
767
|
+
if (!this.isConnected || generation !== view.generation) return;
|
|
768
|
+
if (data.preloaded) { this.cacheMetadata(view,data); data = view.directoryCache.get(entry); }
|
|
769
|
+
if (data.page !== page) throw new Error('目录内容发生变化,请刷新后重试。');
|
|
770
|
+
loading.remove();
|
|
771
|
+
view.gitError = data.gitError; if (data.gitError && page === 0) container.append(element('div','读取 Git 信息失败:'+data.gitError,'navigation-message error'));
|
|
772
|
+
if (mode === 'changes') this.applyChangesMetadata(data);
|
|
773
|
+
if (!data.total) container.append(element('div',data.notice || (mode === 'changes'?'没有尚未提交的改动。':'空目录'),'navigation-message'));
|
|
774
|
+
const expandedLoads = [];
|
|
775
|
+
for (const item of data.entries) {
|
|
776
|
+
if (item.directory) {
|
|
777
|
+
const details = element('details'), summary = element('summary'); summary.append(element('span',item.name)); summary.title = item.path;
|
|
778
|
+
details.dataset.directory = item.path;
|
|
779
|
+
directoryGitStatus(summary,item);
|
|
780
|
+
const children = element('div'); details.append(summary,children); let loaded = false;
|
|
781
|
+
const expandChildren = chain => {
|
|
782
|
+
if (generation !== view.generation) return;
|
|
783
|
+
if (!loaded && !item.blocked) { loaded = true; return this.loadDirectory(children,item.path,0,generation,mode,chain); }
|
|
784
|
+
if (chain) return this.expandSingleDirectory(children);
|
|
785
|
+
};
|
|
786
|
+
details.loadChildren = () => expandChildren(false) || children.loading;
|
|
787
|
+
if (page === 0 && data.total === 1 && data.entries.length === 1 && !item.blocked) {
|
|
788
|
+
container.expandSingle = () => {
|
|
789
|
+
if (generation !== view.generation) return;
|
|
790
|
+
details.open = true; view.expanded.add(item.path); return expandChildren(true);
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
if (item.blocked) { summary.setAttribute('aria-disabled','true'); this.notice(children,item.error); }
|
|
794
|
+
details.addEventListener('toggle',() => {
|
|
795
|
+
if (generation !== view.generation) return;
|
|
796
|
+
const changed = view.expanded.has(item.path) !== details.open;
|
|
797
|
+
if (details.open) view.expanded.add(item.path); else view.expanded.delete(item.path);
|
|
798
|
+
if (details.open) expandChildren(changed);
|
|
799
|
+
const app = this.closest('agentbot-workspace');
|
|
800
|
+
if (changed && app?.filesPanel === this && !app.restoring) app.persistHistory(); else this.queuePersist();
|
|
801
|
+
});
|
|
802
|
+
container.append(details);
|
|
803
|
+
if (view.expanded.has(item.path)) {
|
|
804
|
+
details.open = true;
|
|
805
|
+
if (!item.blocked) expandedLoads.push(expandChildren(expandChain));
|
|
806
|
+
}
|
|
807
|
+
} else container.append(this.createFileButton(item,mode));
|
|
808
|
+
}
|
|
809
|
+
view.pages.set(entry,data.page+1);
|
|
810
|
+
if (data.page+1<data.totalPages && data.page+1<(view.restorePages.get(entry) || 1)) {
|
|
811
|
+
expandedLoads.push(this.loadDirectory(container,entry,data.page+1,generation,mode));
|
|
812
|
+
} else if (data.page+1<data.totalPages) {
|
|
813
|
+
view.restorePages.delete(entry);
|
|
814
|
+
const continuation = element('div',Math.min((data.page+1)*100,data.total)+'/'+data.total+' · 向下滚动加载','navigation-message navigation-continuation');
|
|
815
|
+
continuation.setAttribute('role','status'); container.append(continuation);
|
|
816
|
+
const observer = new IntersectionObserver(entries => {
|
|
817
|
+
if (!entries.some(item => item.isIntersecting) || !this.isConnected || !continuation.isConnected || generation !== view.generation || this.navigation !== view.node || view.node.clientHeight <= 0) return;
|
|
818
|
+
let parent = continuation.parentElement.closest('details');
|
|
819
|
+
while (parent) { if (!parent.open) return; parent = parent.parentElement.closest('details'); }
|
|
820
|
+
continuation.loadNext();
|
|
821
|
+
},{root:view.node,rootMargin:'120px 0px'});
|
|
822
|
+
continuation.loadNext = () => {
|
|
823
|
+
if (continuation.loading) return continuation.loading;
|
|
824
|
+
if (!continuation.isConnected || generation !== view.generation) return;
|
|
825
|
+
observer.disconnect(); view.observers.delete(observer); continuation.remove();
|
|
826
|
+
return continuation.loading = this.loadDirectory(container,entry,data.page+1,generation,mode);
|
|
827
|
+
};
|
|
828
|
+
view.observers.add(observer); observer.observe(continuation);
|
|
829
|
+
} else view.restorePages.delete(entry);
|
|
830
|
+
if (expandChain) expandedLoads.push(this.expandSingleDirectory(container));
|
|
831
|
+
await Promise.all(expandedLoads);
|
|
832
|
+
this.updateCurrentFile();
|
|
833
|
+
this.queuePersist();
|
|
834
|
+
} catch (error) {
|
|
835
|
+
if (this.isConnected && generation === view.generation) {
|
|
836
|
+
if (mode === 'changes' && rootPage) this.showChangesCountError(error);
|
|
837
|
+
loading.remove(); const failure = element('div'); container.append(failure);
|
|
838
|
+
this.notice(failure,(mode === 'changes'?'读取未提交改动失败:':'')+error.message,() => { failure.remove(); this.loadDirectory(container,entry,page,generation,mode,expandChain); });
|
|
839
|
+
}
|
|
840
|
+
} finally { view.pending--; }
|
|
841
|
+
}
|
|
842
|
+
activateTab(key) {
|
|
843
|
+
this.activeKey = key; this.recentTabs = this.recentTabs.filter(current => current !== key && this.tabs.has(current));
|
|
844
|
+
if (key) this.recentTabs.push(key);
|
|
845
|
+
}
|
|
846
|
+
tabView(key, path, kind, original) {
|
|
847
|
+
let views = this.views.get(key); if (!views) { views = new Map(); this.views.set(key,views); }
|
|
848
|
+
const viewKey = kind+':'+path; let tab = views.get(viewKey);
|
|
849
|
+
if (!tab) { tab = {key,path,kind,original,mode:'all',scrollTop:0,scrollLeft:0}; views.set(viewKey,tab); }
|
|
850
|
+
return tab;
|
|
851
|
+
}
|
|
852
|
+
showTab(tab) {
|
|
853
|
+
if (this.tabs.get(tab.key) !== tab) this.renderedKey = undefined;
|
|
854
|
+
this.tabs.set(tab.key,tab); this.activateTab(tab.key); this.dataset.view = 'content';
|
|
855
|
+
this.renderTabs(); this.restoreScroll(); this.loadTab(tab);
|
|
856
|
+
}
|
|
857
|
+
closeViews(key) { for (const tab of this.views.get(key)?.values() || []) { tab.titleController?.abort(); tab.frame?.remove(); tab.frame = tab.preview = undefined; } this.views.delete(key); }
|
|
858
|
+
openFile(path, kind, original, hash, replaceKey) {
|
|
859
|
+
this.navigate(() => {
|
|
860
|
+
this.saveScroll(); this.dataset.view = 'content';
|
|
861
|
+
let tab = [...this.tabs.values()].find(tab => this.pathKey(tab.path) === this.pathKey(path) && tab.kind === kind);
|
|
862
|
+
if (tab && ['file','diff'].includes(kind)) { if (original !== undefined) tab.original = original; if (hash) tab.hash = tab.requestedHash = hash; this.showTab(tab); this.revealActiveTab(); return; }
|
|
863
|
+
const replace = replaceKey === this.activeKey && this.tabs.get(replaceKey)?.kind === 'new';
|
|
864
|
+
if (!tab || replace) {
|
|
865
|
+
tab ??= this.tabView(replace?replaceKey:kind==='new'?path:instanceId(),path,kind,original);
|
|
866
|
+
const key = tab.key;
|
|
867
|
+
const tabs = new Map();
|
|
868
|
+
for (const [currentKey,current] of this.tabs) {
|
|
869
|
+
if (replace && currentKey === key && key !== replaceKey) continue;
|
|
870
|
+
if (!replace || currentKey !== replaceKey) tabs.set(currentKey,current);
|
|
871
|
+
if (currentKey === (replace?replaceKey:this.activeKey)) tabs.set(key,tab);
|
|
872
|
+
}
|
|
873
|
+
if (!tabs.has(key)) tabs.set(key,tab);
|
|
874
|
+
if (replace && key !== replaceKey) this.closeViews(replaceKey);
|
|
875
|
+
if (this.tabs.get(key) && this.tabs.get(key) !== tab) this.renderedKey = undefined;
|
|
876
|
+
this.tabs = tabs; this.revealTabKey = key;
|
|
877
|
+
}
|
|
878
|
+
if (hash) tab.hash = tab.requestedHash = hash;
|
|
879
|
+
if (kind === 'terminal' && replace) tab.startTerminal = true;
|
|
880
|
+
this.showTab(tab);
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
openNew() { this.openFile(instanceId(),'new'); }
|
|
884
|
+
navigateAddress(path, kind, tabKey, hash) {
|
|
885
|
+
this.navigate(() => {
|
|
886
|
+
const current = this.tabs.get(tabKey);
|
|
887
|
+
if (kind === 'file') {
|
|
888
|
+
const existing = [...this.tabs.values()].find(tab => tab.kind === 'file' && this.pathKey(tab.path) === this.pathKey(path));
|
|
889
|
+
if (existing) { current.draft = existing.draft = undefined; this.openFile(path,kind,undefined,hash); return; }
|
|
890
|
+
}
|
|
891
|
+
this.saveScroll(); const tab = this.tabView(tabKey,path,kind); current.draft = tab.draft = undefined;
|
|
892
|
+
if (kind === 'file') tab.hash = tab.requestedHash = hash;
|
|
893
|
+
this.showTab(tab);
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
async openAddress(value, source, tabKey, selectedPath) {
|
|
897
|
+
const current = this.tabs.get(tabKey), picker = this.addressPicker; if (!current || tabKey !== this.activeKey || !picker) return;
|
|
898
|
+
picker.lookupController?.abort(); const submission = picker.submission = (picker.submission || 0)+1;
|
|
899
|
+
const pane = this.closest('agentbot-workspace').dataset.pane, view = this.dataset.view;
|
|
900
|
+
const active = () => this.addressPicker === picker && picker.submission === submission && picker.input.isConnected && picker.input.value === value && this.activeKey === tabKey && this.tabs.get(tabKey) === current && this.dataset.view === view && this.closest('agentbot-workspace').dataset.pane === pane;
|
|
901
|
+
this.hideAddressSuggestions(picker);
|
|
902
|
+
try {
|
|
903
|
+
const input = value.trim(); if (!input) throw new Error('请输入项目文件路径或 HTTP / HTTPS 网址。');
|
|
904
|
+
|
|
905
|
+
if (input.startsWith('#')) {
|
|
906
|
+
if (['file','diff'].includes(current.kind)) { this.navigate(() => { current.draft = undefined; current.hash = current.requestedHash = input; this.restoreHash(current); }); return; }
|
|
907
|
+
if (current.kind === 'web') { this.navigateAddress(webAddress(new URL(input,current.path).toString()),'web',tabKey); return; }
|
|
908
|
+
}
|
|
909
|
+
const target = fileAddress(input,this.projectRoot);
|
|
910
|
+
if (selectedPath !== undefined) { this.navigateAddress(selectedPath,'file',tabKey,this.pathKey(target?.path) === this.pathKey(selectedPath)?target?.hash:undefined); return; }
|
|
911
|
+
if (target) {
|
|
912
|
+
picker.lookupController = new AbortController(); picker.input.setAttribute('aria-busy','true');
|
|
913
|
+
let entry = target.path; if (target.literal) try { entry = relativePath(target.literal); } catch {}
|
|
914
|
+
let data = await this.request('address',{entry},picker.lookupController), hash = entry === target.path?target.hash:undefined;
|
|
915
|
+
if (!active()) return;
|
|
916
|
+
if (data.exact === undefined && entry !== target.path) {
|
|
917
|
+
data = await this.request('address',{entry:target.path},picker.lookupController); hash = target.hash;
|
|
918
|
+
if (!active()) return;
|
|
919
|
+
}
|
|
920
|
+
if (data.exact !== undefined) { this.navigateAddress(data.exact,'file',tabKey,hash); return; }
|
|
921
|
+
}
|
|
922
|
+
if (active()) this.navigateAddress(addressTarget(input),'web',tabKey);
|
|
923
|
+
} catch (error) { if (active()) { source.textContent = error.message; source.hidden = false; source.classList.add('workspace-address-error'); } }
|
|
924
|
+
finally { if (this.addressPicker === picker && picker.submission === submission) picker.input.removeAttribute('aria-busy'); }
|
|
925
|
+
}
|
|
926
|
+
hideAddressSuggestions(picker = this.addressPicker) {
|
|
927
|
+
if (!picker) return;
|
|
928
|
+
picker.sequence++; clearTimeout(picker.timer); picker.controller?.abort(); picker.items = []; picker.index = -1;
|
|
929
|
+
picker.list.hidden = true; picker.input.setAttribute('aria-expanded','false'); picker.input.removeAttribute('aria-activedescendant'); picker.input.removeAttribute('aria-busy');
|
|
930
|
+
}
|
|
931
|
+
setAddressPickerVisible(visible) {
|
|
932
|
+
const picker = this.addressPicker; if (!picker) return;
|
|
933
|
+
if (visible) document.addEventListener('pointerdown',picker.outside,true);
|
|
934
|
+
else {
|
|
935
|
+
this.hideAddressSuggestions(picker); picker.submission = (picker.submission || 0)+1; picker.lookupController?.abort();
|
|
936
|
+
document.removeEventListener('pointerdown',picker.outside,true);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
disposeAddressPicker() { this.setAddressPickerVisible(false); this.addressPicker = undefined; }
|
|
940
|
+
selectAddressOption(picker, index) {
|
|
941
|
+
picker.index = index;
|
|
942
|
+
const options = [...picker.list.querySelectorAll('[role=option]')];
|
|
943
|
+
for (const [position,option] of options.entries()) option.setAttribute('aria-selected',String(position === index));
|
|
944
|
+
if (options[index]) { picker.input.setAttribute('aria-activedescendant',options[index].id); options[index].scrollIntoView({block:'nearest'}); }
|
|
945
|
+
else picker.input.removeAttribute('aria-activedescendant');
|
|
946
|
+
}
|
|
947
|
+
async suggestAddress(picker, direction) {
|
|
948
|
+
this.hideAddressSuggestions(picker); const value = picker.input.value, input = value.trim();
|
|
949
|
+
let target; try { target = input && !input.startsWith('#') ? fileAddress(input,this.projectRoot) : undefined; } catch { return; }
|
|
950
|
+
const query = (target?.literal || target?.path)?.replaceAll('\\','/'); if (!query) return; try { relativePath(query); } catch { return; }
|
|
951
|
+
const sequence = picker.sequence, active = () => this.addressPicker === picker && sequence === picker.sequence && picker.input.isConnected && picker.input.value === value;
|
|
952
|
+
picker.value = value;
|
|
953
|
+
const show = (items, message, error = false) => {
|
|
954
|
+
if (!active()) return;
|
|
955
|
+
picker.items = items; picker.list.replaceChildren(); picker.list.hidden = false; picker.input.setAttribute('aria-expanded','true'); picker.input.removeAttribute('aria-busy');
|
|
956
|
+
for (const [index,item] of items.entries()) {
|
|
957
|
+
const option = element('button',undefined,'address-option'); option.type = 'button'; option.tabIndex = -1; option.id = picker.list.id+'-'+index;
|
|
958
|
+
option.setAttribute('role','option'); option.setAttribute('aria-selected','false'); option.title = item.path; option.append(fileIcon(item.path),element('span',item.path));
|
|
959
|
+
option.onpointerdown = event => { if (event.button === 0) event.preventDefault(); };
|
|
960
|
+
option.onclick = () => { if (active() && option.isConnected && !picker.list.hidden) this.openAddress(value,picker.hint,picker.key,item.path); };
|
|
961
|
+
picker.list.append(option);
|
|
962
|
+
}
|
|
963
|
+
if (message) { const status = element('div',message,'address-options-status'+(error?' error':'')); status.setAttribute('role','status'); picker.list.append(status); }
|
|
964
|
+
if (direction && items.length) this.selectAddressOption(picker,direction > 0?0:items.length-1);
|
|
965
|
+
};
|
|
966
|
+
if (query.length > 160) { show([],'路径较长,请输入完整路径后按回车。'); return; }
|
|
967
|
+
const preloaded = this.navigationViews.get('files')?.preloaded;
|
|
968
|
+
if (preloaded) {
|
|
969
|
+
const matches = preloaded.filter(item => !item.directory && !item.blocked && item.path.toLowerCase().includes(query.toLowerCase())).sort((a,b) => a.path.localeCompare(b.path,undefined,{numeric:true}));
|
|
970
|
+
show(matches.slice(0,20),matches.length > 20?'还有更多匹配,请继续输入路径。':matches.length?'':'没有匹配的文件;按回车打开输入地址。'); return;
|
|
971
|
+
}
|
|
972
|
+
show([],'正在匹配项目文件…'); picker.input.setAttribute('aria-busy','true');
|
|
973
|
+
picker.timer = setTimeout(async () => {
|
|
974
|
+
if (!active()) return;
|
|
975
|
+
picker.controller = new AbortController();
|
|
976
|
+
try {
|
|
977
|
+
const data = await this.request('address',{entry:query,query},picker.controller);
|
|
978
|
+
if (!active()) return;
|
|
979
|
+
show(data.entries,data.truncated?'匹配结果未完整显示,请继续输入路径。':data.entries.length?'':'没有匹配的文件;按回车打开输入地址。');
|
|
980
|
+
} catch (error) { if (active()) show([],'读取匹配文件失败:'+error.message,true); }
|
|
981
|
+
},180);
|
|
982
|
+
}
|
|
983
|
+
tabTitle(tab) { return tab.kind === 'new'?'新标签':tab.kind === 'terminal'?'Terminal':tab.kind === 'web'?tab.pageTitle || tab.path:tab.path.split('/').pop(); }
|
|
984
|
+
async loadWebTitle(tab, refresh = false) {
|
|
985
|
+
if (tab.titleRead && !refresh) return;
|
|
986
|
+
tab.titleRead = true; tab.titleController?.abort(); const controller = tab.titleController = new AbortController();
|
|
987
|
+
const current = () => this.isConnected && !controller.signal.aborted && tab.titleController === controller && this.views.get(tab.key)?.get('web:'+tab.path) === tab;
|
|
988
|
+
try {
|
|
989
|
+
const data = await this.request('web-title',{entry:tab.path},controller);
|
|
990
|
+
if (!current()) return;
|
|
991
|
+
tab.pageTitle = typeof data.title === 'string' ? data.title.replace(/\s+/gu,' ').trim().slice(0,200) || undefined : undefined;
|
|
992
|
+
} catch { if (!current()) return; tab.pageTitle = undefined; }
|
|
993
|
+
if (tab.frame) tab.frame.title = this.tabTitle(tab);
|
|
994
|
+
if (this.tabs.get(tab.key) === tab) this.renderTabs();
|
|
995
|
+
}
|
|
996
|
+
syncFrames() {
|
|
997
|
+
const current = this.tabs.get(this.activeKey), framed = Boolean(current?.frame);
|
|
998
|
+
this.dataset.fileTab = String(Boolean(current && ['file','diff'].includes(current.kind)));
|
|
999
|
+
if (this.dataset.fileTab === 'false') this.explorerToggle.remove();
|
|
1000
|
+
this.dataset.specialTab = String(Boolean(current && ['new','web','terminal'].includes(current.kind)));
|
|
1001
|
+
this.frameLayer.hidden = !framed; this.content.hidden = framed;
|
|
1002
|
+
for (const views of this.views.values()) for (const tab of views.values()) if (tab.frame) {
|
|
1003
|
+
tab.frame.hidden = tab.frame !== current?.frame;
|
|
1004
|
+
if (tab.kind === 'terminal') {
|
|
1005
|
+
const visible = !tab.frame.hidden && tab.frame.clientHeight > 0;
|
|
1006
|
+
const start = visible && tab.frameReady && tab.startTerminal === true;
|
|
1007
|
+
tab.frame.contentWindow?.postMessage({type:'agentbot-workspace-visibility',visible,start},window.location.origin);
|
|
1008
|
+
if (start) tab.startTerminal = false;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
renderAddress(tab, hint) {
|
|
1013
|
+
this.disposeAddressPicker();
|
|
1014
|
+
const address = element('div',undefined,'workspace-address'), field = element('div',undefined,'workspace-address-field'), input = element('input'), list = element('div',undefined,'address-options');
|
|
1015
|
+
list.id = 'workspace-address-options-'+instanceId(); list.setAttribute('role','listbox'); list.setAttribute('aria-label','匹配的项目文件'); list.hidden = true;
|
|
1016
|
+
input.placeholder = '文件路径或 https://…'; input.setAttribute('aria-label','文件路径或网页地址'); input.maxLength = 4096; input.autocomplete = 'off'; input.spellcheck = false;
|
|
1017
|
+
input.setAttribute('role','combobox'); input.setAttribute('aria-autocomplete','list'); input.setAttribute('aria-controls',list.id); input.setAttribute('aria-expanded','false');
|
|
1018
|
+
this.addressInput = input; this.updateAddress();
|
|
1019
|
+
const picker = this.addressPicker = {input,list,field,hint,key:tab.key,sequence:0,items:[],index:-1};
|
|
1020
|
+
const active = () => input.isConnected && this.addressPicker === picker && this.activeKey === tab.key;
|
|
1021
|
+
picker.outside = event => { if (!field.contains(event.target)) this.hideAddressSuggestions(picker); }; if (!this.hidden) this.setAddressPickerVisible(true);
|
|
1022
|
+
const changed = event => { if (!active()) return; picker.lookupController?.abort(); picker.submission = (picker.submission || 0)+1; this.tabs.get(tab.key).draft = input.value; this.hideAddressSuggestions(picker); if (!picker.composing && !event?.isComposing) this.suggestAddress(picker); };
|
|
1023
|
+
input.oninput = changed; input.addEventListener('compositionstart',() => { picker.composing = true; changed(); }); input.addEventListener('compositionend',event => { picker.composing = false; changed(event); }); input.onfocus = () => { if (active() && !picker.composing) this.suggestAddress(picker); };
|
|
1024
|
+
input.onblur = event => { if (!field.contains(event.relatedTarget)) this.hideAddressSuggestions(picker); };
|
|
1025
|
+
input.onkeydown = event => {
|
|
1026
|
+
if (!active() || picker.composing || event.isComposing) return;
|
|
1027
|
+
if (event.key === 'Escape') { event.preventDefault(); picker.lookupController?.abort(); picker.submission = (picker.submission || 0)+1; this.hideAddressSuggestions(picker); }
|
|
1028
|
+
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
1029
|
+
event.preventDefault(); const direction = event.key === 'ArrowDown'?1:-1;
|
|
1030
|
+
if (list.hidden || !picker.items.length) this.suggestAddress(picker,direction);
|
|
1031
|
+
else this.selectAddressOption(picker,picker.index < 0 ? direction > 0?0:picker.items.length-1 : (picker.index+direction+picker.items.length)%picker.items.length);
|
|
1032
|
+
} else if (event.key === 'Enter') {
|
|
1033
|
+
event.preventDefault(); const item = !list.hidden && picker.value === input.value ? picker.items[picker.index] : undefined;
|
|
1034
|
+
this.openAddress(input.value,hint,tab.key,item?.path);
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
field.append(input,list); address.append(this.navigationBack,this.navigationForward,field); this.toolbar.append(address); return input;
|
|
1038
|
+
}
|
|
1039
|
+
updateAddress() { const tab = this.tabs.get(this.activeKey); if (this.addressInput && tab) this.addressInput.value = tab.draft ?? (['file','diff'].includes(tab.kind)?tab.path+(tab.hash || ''):tab.kind==='web'?tab.path:''); }
|
|
1040
|
+
async loadSpecialTab(tab, forceRefresh, generation, controller) {
|
|
1041
|
+
this.toolbar.hidden = false; this.toolbar.replaceChildren();
|
|
1042
|
+
const hint = element('p',tab.kind === 'web'?'网页仍可能受网站嵌入策略、第三方 Cookie 或混合内容限制,可在新窗口打开。':'输入项目内文件路径或 HTTP / HTTPS 网址。','launch-hint'), input = this.renderAddress(tab,hint);
|
|
1043
|
+
const actions = element('div',undefined,'workspace-view-actions'); this.toolbar.append(actions);
|
|
1044
|
+
const list = iconControl('button','tree','返回文件列表','mobile-list'); list.onclick = () => this.showList(); actions.append(list);
|
|
1045
|
+
if (tab.kind === 'new') {
|
|
1046
|
+
if (!tab.launch) {
|
|
1047
|
+
const launch = element('div',undefined,'workspace-launchpad'), actions = element('div',undefined,'launch-actions');
|
|
1048
|
+
for (const [kind,label] of [['file','打开文件'],['web','打开网页'],['terminal','打开 Terminal']]) {
|
|
1049
|
+
const button = element('button'); button.append(icon(kind),element('span',label)); button.dataset.launch = kind;
|
|
1050
|
+
actions.append(button);
|
|
1051
|
+
}
|
|
1052
|
+
launch.append(element('h2','新标签'),actions); tab.launch = launch;
|
|
1053
|
+
}
|
|
1054
|
+
for (const button of tab.launch.querySelectorAll('[data-launch]')) button.onclick = () => { if (button.dataset.launch === 'terminal') this.openFile(tab.path,'terminal',undefined,undefined,tab.key); else { input.placeholder = button.dataset.launch === 'file'?'项目内完整文件路径':'网址(自动补齐协议)'; input.focus(); this.suggestAddress(this.addressPicker); } };
|
|
1055
|
+
tab.launch.querySelector('.launch-hint')?.remove(); tab.launch.append(hint); this.content.replaceChildren(tab.launch); this.renderedKey = tab.key; this.syncFrames(); return;
|
|
1056
|
+
}
|
|
1057
|
+
const refresh = iconControl('button','refresh','刷新视图'); refresh.onclick = () => this.loadTab(tab,true); actions.append(refresh);
|
|
1058
|
+
try {
|
|
1059
|
+
if (!tab.frame) {
|
|
1060
|
+
this.content.replaceChildren(element('div','正在打开…','content-empty')); this.syncFrames();
|
|
1061
|
+
if (tab.kind === 'terminal') await this.closest('agentbot-workspace').sessions?.sessionCheck;
|
|
1062
|
+
if (controller.signal.aborted) return;
|
|
1063
|
+
const url = tab.kind === 'terminal' ? new URL((await this.request('terminal',{instance:tab.path},controller)).url) : new URL(webAddress(tab.path));
|
|
1064
|
+
if (!this.isConnected || generation !== this.generation || !this.tabs.has(tab.key)) return;
|
|
1065
|
+
if (tab.kind === 'terminal') {
|
|
1066
|
+
const terminalBase = new URL(this.fileApi).pathname.split('/workspace/')[0]+'/terminal/';
|
|
1067
|
+
if (url.origin !== window.location.origin || url.username || url.password || !url.pathname.startsWith(terminalBase) || !/^[A-Za-z0-9_-]{8}$/u.test(url.pathname.slice(terminalBase.length)) || url.search || url.hash) throw new Error('终端服务返回了无效地址。');
|
|
1068
|
+
}
|
|
1069
|
+
const frame = element('iframe',undefined,'workspace-frame'); frame.title = this.tabTitle(tab); frame.referrerPolicy = tab.kind === 'web'?'strict-origin-when-cross-origin':'no-referrer';
|
|
1070
|
+
if (tab.kind === 'web') {
|
|
1071
|
+
frame.setAttribute('sandbox','allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-downloads allow-modals allow-pointer-lock allow-orientation-lock allow-presentation allow-storage-access-by-user-activation');
|
|
1072
|
+
frame.setAttribute('allow','autoplay; fullscreen; encrypted-media; picture-in-picture; clipboard-write; storage-access');
|
|
1073
|
+
}
|
|
1074
|
+
frame.addEventListener('load',() => { tab.frameReady = true; this.syncFrames(); });
|
|
1075
|
+
frame.src = url.toString(); tab.frame = frame; this.frameLayer.append(frame);
|
|
1076
|
+
} else if (forceRefresh) tab.frame.src = tab.frame.src;
|
|
1077
|
+
if (tab.kind === 'web') this.loadWebTitle(tab,forceRefresh);
|
|
1078
|
+
const external = iconControl('a','external','新窗口打开'); external.href = tab.path; if (tab.kind === 'terminal') external.href = tab.frame.src; external.target = '_blank'; external.rel = 'noopener noreferrer'; actions.append(external);
|
|
1079
|
+
if (tab.kind === 'web') { const label = element('span','无法内嵌时在新窗口打开','frame-hint'); label.title = hint.textContent; actions.append(label); }
|
|
1080
|
+
this.renderedKey = tab.key; this.syncFrames(); this.queuePersist();
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
if (!this.isConnected || generation !== this.generation) return;
|
|
1083
|
+
const app = this.closest('agentbot-workspace');
|
|
1084
|
+
const retry = () => this.loadTab(tab,true);
|
|
1085
|
+
this.notice(this.content,'打开'+(tab.kind === 'terminal'?'终端':'网页')+'失败:'+error.message,retry);
|
|
1086
|
+
if (tab.kind === 'terminal' && error.status === 401 && app.sessions && !app.sessions.csrf) {
|
|
1087
|
+
const login = element('button','登录工作台');
|
|
1088
|
+
login.onclick = () => app.sessions.showLogin(() => {
|
|
1089
|
+
if (app.filesPanel !== this || app.dataset.pane !== 'tasks' || this.dataset.view !== 'content' || this.tabs.get(this.activeKey) !== tab) return;
|
|
1090
|
+
app.navigate(() => app.selectPane('files')); void retry();
|
|
1091
|
+
});
|
|
1092
|
+
this.content.append(login);
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
saveScroll() {
|
|
1097
|
+
const previous = this.tabs.get(this.activeKey);
|
|
1098
|
+
if (previous && this.renderedKey === this.activeKey && this.content.clientHeight > 0) { previous.scrollTop = this.content.scrollTop; previous.scrollLeft = this.content.scrollLeft; }
|
|
1099
|
+
const view = this.navigationViews.get(this.listMode);
|
|
1100
|
+
if (view.ready && this.navigation.clientHeight > 0) {
|
|
1101
|
+
if (view.query) this.listScrollTop = view.filterScrollTop = this.navigation.scrollTop;
|
|
1102
|
+
else this.listScrollTop = view.scrollTop = this.navigation.scrollTop;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
restoreScroll() {
|
|
1106
|
+
const current = this.tabs.get(this.activeKey);
|
|
1107
|
+
if (current && this.content.clientHeight > 0) { this.content.scrollTop = current.scrollTop; this.content.scrollLeft = current.scrollLeft; }
|
|
1108
|
+
if (this.navigation.clientHeight > 0) { this.reserveTreeScroll(this.listScrollTop); this.navigation.scrollTop = this.listScrollTop; }
|
|
1109
|
+
if (current && this.renderedKey === this.activeKey) this.restoreHash(current);
|
|
1110
|
+
this.centerTreeTarget();
|
|
1111
|
+
this.updateDiffNavigation();
|
|
1112
|
+
}
|
|
1113
|
+
restoreHash(tab) {
|
|
1114
|
+
this.updateAddress();
|
|
1115
|
+
for (const node of this.content.querySelectorAll('.workspace-anchor')) node.classList.remove('workspace-anchor');
|
|
1116
|
+
if (!tab.hash) return;
|
|
1117
|
+
let id; try { id = decodeURIComponent(tab.hash.slice(1)); } catch { return; }
|
|
1118
|
+
const target = document.getElementById(id);
|
|
1119
|
+
if (target && this.content.contains(target)) {
|
|
1120
|
+
target.classList.add('workspace-anchor');
|
|
1121
|
+
if (tab.requestedHash && this.content.clientHeight > 0) {
|
|
1122
|
+
if (tab.kind === 'diff' && this.diffBlocks.includes(target)) this.content.scrollTop = this.diffBlockScrollTop(target);
|
|
1123
|
+
else target.scrollIntoView({block:'start'});
|
|
1124
|
+
this.saveScroll();
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (this.content.clientHeight > 0) tab.requestedHash = undefined;
|
|
1128
|
+
}
|
|
1129
|
+
showList() {
|
|
1130
|
+
this.navigate(() => { this.saveScroll(); this.dataset.view = 'list'; this.restoreScroll(); this.syncFrames(); });
|
|
1131
|
+
}
|
|
1132
|
+
diffBlockScrollTop(block) {
|
|
1133
|
+
let end = block;
|
|
1134
|
+
while (end.nextElementSibling?.matches('.diff-addition,.diff-deletion')) end = end.nextElementSibling;
|
|
1135
|
+
const center = (block.getBoundingClientRect().top+end.getBoundingClientRect().bottom)/2;
|
|
1136
|
+
const top = this.content.scrollTop+center-this.content.getBoundingClientRect().top-this.content.clientHeight/2;
|
|
1137
|
+
return Math.min(Math.max(0,top),Math.max(0,this.content.scrollHeight-this.content.clientHeight));
|
|
1138
|
+
}
|
|
1139
|
+
updateDiffNavigation() {
|
|
1140
|
+
if (!this.diffControls || this.content.clientHeight === 0) return;
|
|
1141
|
+
const tab = this.tabs.get(this.activeKey), blocks = this.renderedKey === this.activeKey ? this.diffBlocks : [];
|
|
1142
|
+
if (!blocks.length) { this.diffControls.previous.disabled = this.diffControls.next.disabled = true; return {blocks,previous:-1,next:-1}; }
|
|
1143
|
+
const top = this.content.scrollTop, positions = blocks.map(block => this.diffBlockScrollTop(block));
|
|
1144
|
+
let previous = -1, next = -1;
|
|
1145
|
+
for (let index = 0; index < positions.length; index++) {
|
|
1146
|
+
if (positions[index] < top-1) previous = index;
|
|
1147
|
+
if (next < 0 && positions[index] > top+1) next = index;
|
|
1148
|
+
}
|
|
1149
|
+
const selected = blocks.findIndex(block => '#'+block.id === tab?.hash);
|
|
1150
|
+
if (selected >= 0 && Math.abs(top-positions[selected]) <= 1) { previous = selected-1; next = selected+1 < blocks.length ? selected+1 : -1; }
|
|
1151
|
+
this.diffControls.previous.disabled = previous < 0; this.diffControls.next.disabled = next < 0;
|
|
1152
|
+
return {blocks,previous,next};
|
|
1153
|
+
}
|
|
1154
|
+
jumpDiff(direction) {
|
|
1155
|
+
const state = this.updateDiffNavigation(), target = state?.blocks[state[direction]]; if (!target) return;
|
|
1156
|
+
this.navigate(() => {
|
|
1157
|
+
const tab = this.tabs.get(this.activeKey), left = this.content.scrollLeft;
|
|
1158
|
+
tab.hash = tab.requestedHash = '#'+target.id; this.restoreHash(tab); this.content.scrollLeft = left;
|
|
1159
|
+
this.saveScroll(); this.updateDiffNavigation();
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
restoreView(route, position) {
|
|
1163
|
+
this.selectList(route.listMode); this.dataset.view = route.view;
|
|
1164
|
+
if (position) this.listScrollTop = position.listScrollTop;
|
|
1165
|
+
if (route.tab) {
|
|
1166
|
+
const key = route.tab.id, tab = this.tabs.get(key);
|
|
1167
|
+
const retained = this.activeKey === key && tab?.mode === route.tab.mode && this.renderedKey === key;
|
|
1168
|
+
if (tab.mode !== route.tab.mode) this.renderedKey = undefined;
|
|
1169
|
+
tab.mode = route.tab.mode; tab.hash = route.tab.hash; if (position) { tab.scrollTop = position.scrollTop; tab.scrollLeft = position.scrollLeft; }
|
|
1170
|
+
this.activateTab(key);
|
|
1171
|
+
this.renderTabs();
|
|
1172
|
+
this.restoreScroll(); if (!retained) this.loadTab(tab);
|
|
1173
|
+
} else {
|
|
1174
|
+
this.tabController?.abort(); this.generation++; this.activeKey = this.renderedKey = undefined;
|
|
1175
|
+
this.toolbar.hidden = true; this.syncFrames(); this.content.replaceChildren(element('div',this.fileApi?'选择一个文件或改动。':'此任务没有可浏览的项目目录。','content-empty')); this.renderTabs(); this.restoreScroll();
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
renderTabs() {
|
|
1179
|
+
const left = this.rememberTabsScroll(), rows = new Map([...this.tabBar.querySelectorAll('.file-tab')].map(row => [row.dataset.key,row]));
|
|
1180
|
+
this.tabBar.querySelector('.file-tabs-placeholder')?.remove();
|
|
1181
|
+
for (const [key,row] of rows) if (!this.tabs.has(key)) row.remove();
|
|
1182
|
+
let activeRow, addedActive = this.revealTabKey === this.activeKey, index = 0;
|
|
1183
|
+
this.revealTabKey = undefined;
|
|
1184
|
+
for (const tab of this.tabs.values()) {
|
|
1185
|
+
let row = rows.get(tab.key);
|
|
1186
|
+
if (!row) {
|
|
1187
|
+
row = element('div',undefined,'file-tab'); row.dataset.key = tab.key;
|
|
1188
|
+
const select = element('button'), close = iconControl('button','close','关闭 '+this.tabTitle(tab)+(tab.kind === 'diff'?' 改动':''),'close-tab');
|
|
1189
|
+
select.setAttribute('role','tab'); row.append(select,close);
|
|
1190
|
+
if (tab.key === this.activeKey) addedActive = true;
|
|
1191
|
+
}
|
|
1192
|
+
const select = row.querySelector('[role=tab]'), close = row.querySelector('.close-tab');
|
|
1193
|
+
if (select.title !== tab.path || row.dataset.kind !== tab.kind) {
|
|
1194
|
+
select.replaceChildren(['file','diff'].includes(tab.kind)?fileIcon(tab.path):icon(tab.kind),element('span',this.tabTitle(tab),'tab-name'));
|
|
1195
|
+
if (tab.kind === 'diff') { const badge = element('span','±','tab-diff-badge'); badge.setAttribute('aria-hidden','true'); select.append(badge); }
|
|
1196
|
+
select.title = tab.path; row.dataset.kind = tab.kind;
|
|
1197
|
+
}
|
|
1198
|
+
const name = select.querySelector('.tab-name'), title = this.tabTitle(tab); if (name.textContent !== title) name.textContent = title;
|
|
1199
|
+
select.setAttribute('aria-label',(tab.kind === 'diff'?'查看改动 ':tab.kind === 'web'?'查看网页 ':tab.kind === 'terminal'?'查看终端 ':tab.kind === 'new'?'':'查看文件 ')+(tab.kind === 'new'?'新标签':tab.kind === 'web' && tab.pageTitle?tab.pageTitle+' · '+tab.path:tab.path));
|
|
1200
|
+
const label = '关闭 '+this.tabTitle(tab)+(tab.kind === 'diff'?' 改动':''); close.title = label; close.setAttribute('aria-label',label);
|
|
1201
|
+
select.onclick = () => this.navigate(() => { this.saveScroll(); this.showTab(this.tabs.get(tab.key)); });
|
|
1202
|
+
close.onclick = () => this.navigate(() => {
|
|
1203
|
+
const keys = [...this.tabs.keys()], index = keys.indexOf(tab.key);
|
|
1204
|
+
this.saveScroll(); this.tabs.delete(tab.key); this.closeViews(tab.key);
|
|
1205
|
+
this.recentTabs = this.recentTabs.filter(key => this.tabs.has(key));
|
|
1206
|
+
if (this.activeKey === tab.key) {
|
|
1207
|
+
this.tabController?.abort();
|
|
1208
|
+
this.activateTab(this.recentTabs.at(-1) || keys[index-1] || keys[index+1]); const next = this.tabs.get(this.activeKey);
|
|
1209
|
+
if (next) { this.restoreScroll(); this.loadTab(next); }
|
|
1210
|
+
else { this.generation++; this.renderedKey = undefined; this.toolbar.hidden = true; this.syncFrames(); this.content.replaceChildren(element('div','选择一个文件或改动。','content-empty')); this.showList(); }
|
|
1211
|
+
}
|
|
1212
|
+
this.renderTabs();
|
|
1213
|
+
},true);
|
|
1214
|
+
if (this.tabBar.children[index] !== row) this.tabBar.insertBefore(row,this.tabBar.children[index] || null);
|
|
1215
|
+
index++;
|
|
1216
|
+
row.classList.toggle('is-active',tab.key === this.activeKey);
|
|
1217
|
+
row.querySelector('[role=tab]').setAttribute('aria-selected',String(tab.key === this.activeKey));
|
|
1218
|
+
if (tab.key === this.activeKey) activeRow = row;
|
|
1219
|
+
}
|
|
1220
|
+
if (!this.tabs.size) this.tabBar.append(element('span','文件预览','file-tabs-placeholder'));
|
|
1221
|
+
this.syncFrames();
|
|
1222
|
+
this.updateCurrentFile();
|
|
1223
|
+
this.scrollTabs(left);
|
|
1224
|
+
if (activeRow && this.tabBar.clientWidth > 0) {
|
|
1225
|
+
const bar = this.tabBar.getBoundingClientRect(), row = activeRow.getBoundingClientRect();
|
|
1226
|
+
if (addedActive || row.right <= bar.left || row.left >= bar.right) {
|
|
1227
|
+
this.revealActiveTab();
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
revealActiveTab() {
|
|
1232
|
+
const row = this.tabBar.querySelector('.file-tab.is-active'); if (!row || this.tabBar.clientWidth <= 0) return;
|
|
1233
|
+
const bar = this.tabBar.getBoundingClientRect(), bounds = row.getBoundingClientRect();
|
|
1234
|
+
if (bounds.left < bar.left) this.scrollTabs(this.tabBar.scrollLeft+bounds.left-bar.left);
|
|
1235
|
+
else if (bounds.right > bar.right) this.scrollTabs(this.tabBar.scrollLeft+bounds.right-bar.right);
|
|
1236
|
+
}
|
|
1237
|
+
rememberTabsScroll() {
|
|
1238
|
+
const width = this.tabBar.clientWidth;
|
|
1239
|
+
if (this.tabWidth === undefined || width > 0 && width === this.tabWidth) this.tabScrollLeft = Math.max(0,this.tabBar.scrollLeft || 0);
|
|
1240
|
+
return this.tabScrollLeft || 0;
|
|
1241
|
+
}
|
|
1242
|
+
scrollTabs(left) {
|
|
1243
|
+
const width = this.tabBar.clientWidth;
|
|
1244
|
+
this.tabScrollLeft = Math.max(0,left);
|
|
1245
|
+
if (width > 0) this.tabScrollLeft = Math.min(this.tabScrollLeft,Math.max(0,this.tabBar.scrollWidth-width));
|
|
1246
|
+
this.tabWidth = width; this.tabBar.scrollLeft = this.tabScrollLeft;
|
|
1247
|
+
}
|
|
1248
|
+
resizeTabs() { this.scrollTabs(this.rememberTabsScroll()); }
|
|
1249
|
+
async loadTab(tab, forceRefresh = false) {
|
|
1250
|
+
if (!forceRefresh && this.loadingTab?.key === tab.key && this.loadingTab.path === tab.path && this.loadingTab.kind === tab.kind && this.loadingTab.mode === tab.mode && this.loadingTab.original === tab.original && !this.tabController.signal.aborted) return;
|
|
1251
|
+
const generation = ++this.generation;
|
|
1252
|
+
this.tabController?.abort(); const controller = new AbortController(); this.tabController = controller;
|
|
1253
|
+
this.syncFrames();
|
|
1254
|
+
if (['new','web','terminal'].includes(tab.kind)) { this.loadingTab = undefined; this.diffBlocks = []; this.diffControls = undefined; await this.loadSpecialTab(tab,forceRefresh,generation,controller); return; }
|
|
1255
|
+
const cached = !forceRefresh && tab.preview?.mode === tab.mode && tab.preview.original === tab.original ? tab.preview : undefined;
|
|
1256
|
+
const focusFirstDiff = tab.kind === 'diff' && !tab.preview && !tab.hash && tab.scrollTop === 0;
|
|
1257
|
+
this.loadingTab = cached ? undefined : {key:tab.key,path:tab.path,kind:tab.kind,mode:tab.mode,original:tab.original};
|
|
1258
|
+
this.diffBlocks = []; this.diffControls = undefined;
|
|
1259
|
+
if (!cached) tab.preview = undefined;
|
|
1260
|
+
this.toolbar.hidden = false; this.toolbar.replaceChildren();
|
|
1261
|
+
const hint = element('p',undefined,'launch-hint'); hint.hidden = true; this.renderAddress(tab,hint); this.toolbar.append(hint);
|
|
1262
|
+
const actions = element('div',undefined,'workspace-view-actions'); this.toolbar.append(actions);
|
|
1263
|
+
const refresh = iconControl('button','refresh','刷新当前文件','content-refresh');
|
|
1264
|
+
const list = iconControl('button','tree',this.listMode === 'changes'?'返回改动列表':'返回文件列表','mobile-list');
|
|
1265
|
+
list.onclick = () => this.showList();
|
|
1266
|
+
refresh.onclick = () => { this.saveScroll(); this.loadTab(tab,true); };
|
|
1267
|
+
actions.append(list);
|
|
1268
|
+
if (tab.kind === 'diff') {
|
|
1269
|
+
const previous = iconControl('button','up','上一处改动','diff-previous'), next = iconControl('button','down','下一处改动','diff-next');
|
|
1270
|
+
previous.disabled = next.disabled = true; previous.onclick = () => this.jumpDiff('previous'); next.onclick = () => this.jumpDiff('next');
|
|
1271
|
+
this.diffControls = {previous,next}; actions.append(previous,next);
|
|
1272
|
+
const select = element('select'); select.setAttribute('aria-label','Diff 范围');
|
|
1273
|
+
select.title = 'Diff 范围:全部、已暂存、未暂存';
|
|
1274
|
+
for (const [value,label] of [['all','全部'],['staged','已暂存'],['unstaged','未暂存']]) {
|
|
1275
|
+
const option = element('option',label); option.value = value; option.selected = value === tab.mode; select.append(option);
|
|
1276
|
+
}
|
|
1277
|
+
select.onchange = () => this.navigate(() => { this.saveScroll(); tab.mode = select.value; tab.scrollTop = tab.scrollLeft = 0; this.renderedKey = undefined; this.loadTab(tab,true); });
|
|
1278
|
+
actions.append(select);
|
|
1279
|
+
}
|
|
1280
|
+
actions.append(this.explorerToggle,refresh);
|
|
1281
|
+
const retained = this.renderedKey === tab.key;
|
|
1282
|
+
if (!retained && !cached) { this.renderedKey = undefined; this.content.replaceChildren(element('div','正在读取…','content-empty')); }
|
|
1283
|
+
try {
|
|
1284
|
+
const data = cached || await this.request(tab.kind,{entry:tab.path,mode:tab.mode,original:tab.original},controller);
|
|
1285
|
+
if (!this.isConnected || generation !== this.generation || !this.tabs.has(tab.key)) return;
|
|
1286
|
+
const visible = retained && this.content.clientHeight > 0;
|
|
1287
|
+
const top = visible ? this.content.scrollTop : tab.scrollTop, left = visible ? this.content.scrollLeft : tab.scrollLeft;
|
|
1288
|
+
if (cached) { if (!retained) this.content.replaceChildren(...cached.nodes); }
|
|
1289
|
+
else {
|
|
1290
|
+
this.content.innerHTML = data.html;
|
|
1291
|
+
tab.preview = {mode:tab.mode,original:tab.original,nodes:[...this.content.childNodes],canViewFile:data.canViewFile,rawUrl:data.rawUrl,change:data.change,gitError:data.gitError};
|
|
1292
|
+
}
|
|
1293
|
+
this.renderedKey = tab.key;
|
|
1294
|
+
if (tab.kind === 'diff') this.diffBlocks = [...this.content.querySelectorAll('.git-diff .diff-addition,.git-diff .diff-deletion')].filter(block => !block.previousElementSibling?.matches('.diff-addition,.diff-deletion'));
|
|
1295
|
+
this.content.scrollTop = top; this.content.scrollLeft = left;
|
|
1296
|
+
if (focusFirstDiff && this.diffBlocks.length) tab.hash = tab.requestedHash = '#'+this.diffBlocks[0].id;
|
|
1297
|
+
window.agentBotDiagrams?.scan();
|
|
1298
|
+
this.restoreHash(tab); this.updateDiffNavigation(); this.queuePersist();
|
|
1299
|
+
if (tab.kind === 'diff') {
|
|
1300
|
+
const file = iconControl('button','openFile','查看文件内容','file-content'); file.disabled = !data.canViewFile;
|
|
1301
|
+
file.onclick = () => this.openFile(tab.path,'file'); refresh.before(file);
|
|
1302
|
+
} else if (data.rawUrl) {
|
|
1303
|
+
const download = iconControl('a','download','下载'), url = new URL(data.rawUrl); url.searchParams.set('download','1');
|
|
1304
|
+
download.href = url; download.target = '_blank'; download.rel = 'noopener noreferrer'; refresh.before(download);
|
|
1305
|
+
}
|
|
1306
|
+
if (tab.kind === 'file' && data.change) { const changes = iconControl('button','diff','查看文件变更','file-changes'); changes.onclick = () => this.openFile(data.change.path,'diff',data.change.originalPath); refresh.before(changes); }
|
|
1307
|
+
if (data.gitError) { hint.textContent = '读取 Git 状态失败:'+data.gitError; hint.hidden = false; }
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
if (this.isConnected && generation === this.generation) {
|
|
1310
|
+
this.renderedKey = undefined;
|
|
1311
|
+
this.updateDiffNavigation();
|
|
1312
|
+
this.notice(this.content,'读取'+(tab.kind === 'diff'?' Diff':'文件')+'失败:'+error.message,() => this.loadTab(tab,true));
|
|
1313
|
+
}
|
|
1314
|
+
} finally { if (generation === this.generation) this.loadingTab = undefined; }
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
class AgentBotWorkspace extends HTMLElement {
|
|
1318
|
+
connectedCallback() {
|
|
1319
|
+
this.positions = new Map(); this.historyRoutes = new Map(); this.paneScrollPositions = new Map(); this.navigating = this.restoring = false;
|
|
1320
|
+
this.taskPanels = new Map(); this.guestPanel = undefined;
|
|
1321
|
+
const initialHref = window.location.href, initialTask = appBase ? this.taskFromUrl(initialHref) : undefined;
|
|
1322
|
+
this.guestUrl = root ? apiBase : historyScope;
|
|
1323
|
+
const state = window.history.state; this.historyIndex = state?.workspace === historyScope ? state.index : 0;
|
|
1324
|
+
this.historyMaximum = state?.workspace === historyScope ? state.maximum ?? state.index : 0;
|
|
1325
|
+
this.historyMaximumKnown = state?.workspace !== historyScope || state.maximum !== undefined;
|
|
1326
|
+
this.historyGuard = Boolean(state?.workspace === historyScope && state.guarded);
|
|
1327
|
+
this.dataset.pane = 'files';
|
|
1328
|
+
this.innerHTML = '<header class="workspace-header"><div class="workspace-title"></div><small class="workspace-status">只读工作台</small><nav class="workspace-nav" aria-label="工作台区域"><button data-pane="tasks">任务</button><button data-pane="chat">聊天</button><button data-pane="files" aria-pressed="true">文件</button></nav></header><main class="workspace-layout"><workspace-task-list></workspace-task-list><workspace-chat></workspace-chat></main>';
|
|
1329
|
+
this.layout = appBase ? this.globalLayout() : {};
|
|
1330
|
+
this.querySelector('workspace-chat').before(this.separator('sidebar','调整任务侧栏宽度'));
|
|
1331
|
+
this.querySelector('.workspace-layout').append(this.separator('chat','调整聊天区域宽度'));
|
|
1332
|
+
// The signed entry authorizes this project's files, not the task's conversation.
|
|
1333
|
+
const files = root && initialTask ? this.createFilesPanel(initialTask,apiBase,root) : this.getGuestPanel();
|
|
1334
|
+
this.showFilesPanel(files);
|
|
1335
|
+
const collapse = iconControl('button','sidebar','折叠任务侧栏','toggle-sidebar'); collapse.onclick = () => this.togglePanel('sidebar'); this.querySelector('.workspace-header').prepend(collapse);
|
|
1336
|
+
const collapseFiles = iconControl('button','explorer','折叠文件工作区','toggle-files'); collapseFiles.onclick = () => this.togglePanel('files'); this.querySelector('.workspace-header').append(collapseFiles);
|
|
1337
|
+
this.layoutResize = () => this.applyLayout(); window.addEventListener('resize',this.layoutResize);
|
|
1338
|
+
this.scrollbars = new WorkspaceScrollbars(this);
|
|
1339
|
+
this.querySelector('.workspace-title').textContent = project+' · Workspace'; this.querySelector('.workspace-title').title = root;
|
|
1340
|
+
const status = this.querySelector('.workspace-status'); status.replaceChildren(icon('lock'),element('span','只读')); status.title = '只读工作台';
|
|
1341
|
+
for (const button of this.querySelectorAll('[data-pane]')) {
|
|
1342
|
+
const pane = button.dataset.pane, label = {tasks:'任务',chat:'聊天',files:'文件与改动列表'}[pane];
|
|
1343
|
+
button.replaceChildren(icon(pane === 'files'?'folder':pane)); button.classList.add('icon-control'); button.title = label; button.setAttribute('aria-label',label);
|
|
1344
|
+
button.onclick = () => this.navigate(() => {
|
|
1345
|
+
if (pane === 'files' && this.dataset.pane === pane) this.filesPanel.showList();
|
|
1346
|
+
else this.selectPane(pane);
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
this.addEventListener('workspace-status',this.statusChanged);
|
|
1350
|
+
window.addEventListener('popstate',this.historyChanged); window.addEventListener('pagehide',this.persistHistory);
|
|
1351
|
+
window.addEventListener('beforeunload',this.persistHistory);
|
|
1352
|
+
if (appBase) this.sessions = new window.AgentBotSessionWorkspace(this,appBase);
|
|
1353
|
+
// Reload may snapshot its URL before beforeunload saves the final reading position.
|
|
1354
|
+
const reload = state?.workspace === historyScope && window.performance?.getEntriesByType('navigation')[0]?.type === 'reload';
|
|
1355
|
+
if (root || !initialTask) this.restoreFilesPanel(reload?state.position:undefined,reload?state.url:undefined);
|
|
1356
|
+
else {
|
|
1357
|
+
const params = new URL(initialHref).searchParams;
|
|
1358
|
+
const rememberedPane = state?.workspace === historyScope && state.route?.task === initialTask ? state.route.pane : undefined;
|
|
1359
|
+
const pane = params.get('pane') || rememberedPane;
|
|
1360
|
+
this.selectPane(['tasks','chat','files'].includes(pane) ? pane : params.has('list') || params.has('entry') ? 'files' : 'chat');
|
|
1361
|
+
this.applyLayout();
|
|
1362
|
+
}
|
|
1363
|
+
this.addEventListener('scroll',this.queuePersist,true);
|
|
1364
|
+
if (appBase && !root && !initialTask) this.selectPane('tasks');
|
|
1365
|
+
window.addEventListener('hashchange',this.urlChanged);
|
|
1366
|
+
if (state?.workspace === historyScope && state.boundary) { this.syncedUrl = window.location.href; this.stepHistory(1,false,true); return; }
|
|
1367
|
+
if (state?.workspace !== historyScope && files.tabs.get(files.activeKey)?.kind === 'web') {
|
|
1368
|
+
this.historyGuard = true; const initial = this.historyState();
|
|
1369
|
+
window.history.replaceState({...initial,index:-1,boundary:true},'',initial.url); window.history.pushState(initial,'',initial.url);
|
|
1370
|
+
}
|
|
1371
|
+
this.persistHistory();
|
|
1372
|
+
if (!this.savedTreeModes.has(files.listMode)) files.revealCurrentFile(true);
|
|
1373
|
+
}
|
|
1374
|
+
disconnectedCallback() {
|
|
1375
|
+
this.removeEventListener('workspace-status',this.statusChanged);
|
|
1376
|
+
this.sessions?.dispose();
|
|
1377
|
+
this.scrollbars.disconnect();
|
|
1378
|
+
this.finishHistoryTraversal();
|
|
1379
|
+
window.removeEventListener('resize',this.layoutResize); this.endDrag?.();
|
|
1380
|
+
this.removeEventListener('scroll',this.queuePersist,true); window.removeEventListener('hashchange',this.urlChanged); clearTimeout(this.persistTimer);
|
|
1381
|
+
window.removeEventListener('popstate',this.historyChanged); window.removeEventListener('pagehide',this.persistHistory); window.removeEventListener('beforeunload',this.persistHistory);
|
|
1382
|
+
}
|
|
1383
|
+
selectPane(pane) {
|
|
1384
|
+
if (pane === this.dataset.pane) return;
|
|
1385
|
+
const files = this.filesPanel, scrollers = this.paneScrollers();
|
|
1386
|
+
files.saveScroll();
|
|
1387
|
+
if (!this.restoring) for (const node of scrollers) if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
1388
|
+
this.dataset.pane = pane;
|
|
1389
|
+
files.syncFrames();
|
|
1390
|
+
for (const button of this.querySelectorAll('[data-pane]')) button.setAttribute('aria-pressed',String(button.dataset.pane === pane));
|
|
1391
|
+
files.restoreScroll();
|
|
1392
|
+
for (const node of scrollers) {
|
|
1393
|
+
const position = this.paneScrollPositions.get(node);
|
|
1394
|
+
if (position && node.clientHeight > 0) { node.scrollTop = position.top; if (node === files.tabBar) files.scrollTabs(position.left); else node.scrollLeft = position.left; }
|
|
1395
|
+
}
|
|
1396
|
+
files.resizeTabs(); this.sessions?.restorePosition();
|
|
1397
|
+
}
|
|
1398
|
+
globalLayout() { const saved = stored('agentbot-workspace-layout') || {}; return {
|
|
1399
|
+
...(typeof saved.sidebar === 'number' ? {sidebar:saved.sidebar} : {}),
|
|
1400
|
+
...(typeof saved.sidebarCollapsed === 'boolean' ? {sidebarCollapsed:saved.sidebarCollapsed} : {}),
|
|
1401
|
+
}; }
|
|
1402
|
+
initTreeStorage(projectRoot, taskId) {
|
|
1403
|
+
this.treeStorageKey = taskId ? 'agentbot-workspace-task-tree:'+taskId+':'+projectPath(projectRoot,projectRoot) : 'agentbot-workspace-tree:'+projectPath(projectRoot);
|
|
1404
|
+
this.treeStates = {};
|
|
1405
|
+
try { const saved = stored(this.treeStorageKey); if (saved?.v === 1) this.treeStates = readTreeState(saved.trees); } catch {}
|
|
1406
|
+
this.savedTreeModes = new Set(Object.keys(this.treeStates));
|
|
1407
|
+
}
|
|
1408
|
+
taskFromUrl(href) {
|
|
1409
|
+
const id = new URL(href).searchParams.get('task'); return id && id.length <= 200 && !/[\x00-\x1f\x7f]/u.test(id) ? id : undefined;
|
|
1410
|
+
}
|
|
1411
|
+
chatPositionFromUrl(href) {
|
|
1412
|
+
try { return chatAnchor(JSON.parse(new URL(href).searchParams.get('chat') || 'null')); } catch {}
|
|
1413
|
+
}
|
|
1414
|
+
savedSessionChat(id) { return chatAnchor(stored('agentbot-workspace-task:'+id)?.chat); }
|
|
1415
|
+
rightLayout() { const {sidebar,sidebarCollapsed,...right} = this.layout; return right; }
|
|
1416
|
+
createFilesPanel(taskId, fileApi, projectRoot) {
|
|
1417
|
+
const files = document.createElement('workspace-files');
|
|
1418
|
+
files.taskId = taskId; files.fileApi = fileApi;
|
|
1419
|
+
files.projectRoot = taskId && fileApi ? new URL(fileApi).searchParams.get('path') || projectRoot : projectRoot;
|
|
1420
|
+
files.hidden = true;
|
|
1421
|
+
if (taskId) { files.dataset.taskPanel = 'true'; this.taskPanels.set(taskId,files); }
|
|
1422
|
+
this.querySelector('.workspace-layout').append(files);
|
|
1423
|
+
return files;
|
|
1424
|
+
}
|
|
1425
|
+
getGuestPanel() { return this.guestPanel ??= this.createFilesPanel(undefined,root ? apiBase : '',root); }
|
|
1426
|
+
removeFilesPanel(files) { this.paneScrollPositions.delete(files.tabBar); files.remove(); }
|
|
1427
|
+
showFilesPanel(files) {
|
|
1428
|
+
const previous = this.filesPanel;
|
|
1429
|
+
if (previous === files) return;
|
|
1430
|
+
if (previous?.isConnected) {
|
|
1431
|
+
previous.saveScroll(); previous.panelLayout = this.rightLayout();
|
|
1432
|
+
previous.hidden = true; previous.setAddressPickerVisible(false); previous.syncFrames();
|
|
1433
|
+
}
|
|
1434
|
+
this.filesPanel = files;
|
|
1435
|
+
this.initTreeStorage(files.projectRoot,files.taskId);
|
|
1436
|
+
if (files.panelLayout) this.layout = {...this.globalLayout(),...files.panelLayout};
|
|
1437
|
+
files.hidden = false; files.setAddressPickerVisible(true);
|
|
1438
|
+
this.statusChanged({target:files,detail:files.lastStatus || {label:'只读',repository:false}});
|
|
1439
|
+
}
|
|
1440
|
+
restoreFilesPanel(position, href, pane) {
|
|
1441
|
+
const files = this.filesPanel;
|
|
1442
|
+
this.restoreUrl(false,position,href,false,pane);
|
|
1443
|
+
if (files.fileApi && files.listMode !== 'changes') void files.updateChangesCount();
|
|
1444
|
+
}
|
|
1445
|
+
activateTaskPanel(task, nav, render) {
|
|
1446
|
+
const apply = () => {
|
|
1447
|
+
const previous = this.filesPanel, fileApi = task.workspace || '';
|
|
1448
|
+
let files = this.taskPanels.get(task.id);
|
|
1449
|
+
if (files?.fileApi !== fileApi) {
|
|
1450
|
+
if (files) this.removeFilesPanel(files);
|
|
1451
|
+
files = this.createFilesPanel(task.id,fileApi,task.project.root || '');
|
|
1452
|
+
}
|
|
1453
|
+
this.taskId = task.id;
|
|
1454
|
+
this.dataset.hasTask = 'true';
|
|
1455
|
+
this.paneScrollPositions.delete(this.querySelector('.chat-body'));
|
|
1456
|
+
this.paneScrollPositions.delete(this.querySelector('workspace-chat textarea'));
|
|
1457
|
+
const pane = nav.history ? nav.pane || this.dataset.pane : nav.initial ? this.dataset.pane : 'chat';
|
|
1458
|
+
this.showFilesPanel(files);
|
|
1459
|
+
if (previous !== files && !files.panelLayout) {
|
|
1460
|
+
const saved = stored('agentbot-workspace-task:'+task.id), currentHref = window.location.href;
|
|
1461
|
+
let href = nav.initial && this.taskFromUrl(currentHref) === task.id ? currentHref : nav.href;
|
|
1462
|
+
if (!href && typeof saved?.href === 'string' && saved.root === files.projectRoot) href = saved.href;
|
|
1463
|
+
if (href) {
|
|
1464
|
+
try {
|
|
1465
|
+
const url = new URL(href,window.location.href);
|
|
1466
|
+
if (url.origin !== window.location.origin || (url.pathname !== new URL(historyScope).pathname && url.pathname !== new URL(fileApi).pathname)) href = undefined;
|
|
1467
|
+
} catch { href = undefined; }
|
|
1468
|
+
}
|
|
1469
|
+
const list = nav.initial && previous.listMode === 'changes' ? 'changes' : undefined;
|
|
1470
|
+
this.restoreFilesPanel(nav.position,href || this.taskRouteUrl(task.id,list),pane);
|
|
1471
|
+
if (!this.savedTreeModes.has(files.listMode)) void files.revealCurrentFile(true);
|
|
1472
|
+
} else if (!nav.initial && (!nav.history || !this.restoreUrl(true,nav.position,nav.href,false,pane))) this.selectPane(pane);
|
|
1473
|
+
this.querySelector('.workspace-title').textContent = task.project.name+' · Workspace';
|
|
1474
|
+
this.querySelector('.workspace-title').title = task.project.root || '无项目';
|
|
1475
|
+
if (previous !== files) this.applyLayout();
|
|
1476
|
+
render();
|
|
1477
|
+
};
|
|
1478
|
+
if (nav.history) {
|
|
1479
|
+
apply(); this.taskHistoryPending = false; this.historyIndex = nav.index; this.finishHistoryTraversal(); this.persistHistory();
|
|
1480
|
+
} else {
|
|
1481
|
+
this.taskHistoryPending = false;
|
|
1482
|
+
this.navigate(apply,Boolean(nav.initial));
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
taskRouteUrl(task, list) {
|
|
1486
|
+
const url = new URL(historyScope); url.searchParams.set('task',task); if (list) url.searchParams.set('list',list); return url.href;
|
|
1487
|
+
}
|
|
1488
|
+
releaseSessionPanels(href) {
|
|
1489
|
+
// A history visit to the guest route keeps background panels. Losing the login destroys them.
|
|
1490
|
+
if (!href) {
|
|
1491
|
+
if (this.taskId) this.persistHistory();
|
|
1492
|
+
for (const panel of this.taskPanels.values()) this.removeFilesPanel(panel);
|
|
1493
|
+
this.taskPanels.clear();
|
|
1494
|
+
if (this.guestPanel) this.removeFilesPanel(this.guestPanel);
|
|
1495
|
+
this.guestPanel = undefined;
|
|
1496
|
+
}
|
|
1497
|
+
this.taskId = undefined; this.dataset.hasTask = 'false'; this.taskHistoryPending = false;
|
|
1498
|
+
const guest = this.getGuestPanel(), returning = this.filesPanel !== guest;
|
|
1499
|
+
this.showFilesPanel(guest);
|
|
1500
|
+
if (href) this.restoreFilesPanel(undefined,href,root ? 'files' : 'tasks');
|
|
1501
|
+
else if (returning && !guest.panelLayout) this.restoreFilesPanel(undefined,this.guestUrl,this.dataset.pane);
|
|
1502
|
+
this.applyLayout();
|
|
1503
|
+
this.querySelector('.workspace-title').textContent = project+' · Workspace'; this.querySelector('.workspace-title').title = root;
|
|
1504
|
+
}
|
|
1505
|
+
updateSessionStatus(connected,label) {
|
|
1506
|
+
this.sessionConnection = label; this.dataset.liveConnection = String(connected);
|
|
1507
|
+
this.statusChanged({target:this.filesPanel,detail:this.filesPanel.lastStatus || {label:'只读',repository:false}});
|
|
1508
|
+
}
|
|
1509
|
+
openChatFile(entry,kind,hash) {
|
|
1510
|
+
if (!this.taskId || !this.filesPanel.fileApi) return;
|
|
1511
|
+
this.navigate(() => {
|
|
1512
|
+
this.selectPane('files');
|
|
1513
|
+
if (this.layout.filesCollapsed) { this.layout.filesCollapsed = false; this.applyLayout(); }
|
|
1514
|
+
this.filesPanel.openFile(entry,kind,undefined,hash);
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
paneScrollers() { return [...this.querySelectorAll('workspace-task-list,.chat-body,workspace-chat textarea'),this.filesPanel.tabBar]; }
|
|
1518
|
+
route() {
|
|
1519
|
+
const files = this.filesPanel, tab = files.tabs.get(files.activeKey);
|
|
1520
|
+
return {task:files.taskId,pane:this.dataset.pane,listMode:files.listMode,view:files.dataset.view,tab:tab?{id:tab.key,path:tab.path,kind:tab.kind,original:tab.original,mode:tab.mode,hash:tab.hash}:null};
|
|
1521
|
+
}
|
|
1522
|
+
separator(panel, label) {
|
|
1523
|
+
const node = element('div',undefined,'workspace-separator'); node.dataset.panel = panel; node.tabIndex = 0;
|
|
1524
|
+
node.setAttribute('role','separator'); node.setAttribute('aria-orientation','vertical'); node.setAttribute('aria-label',label);
|
|
1525
|
+
const change = delta => {
|
|
1526
|
+
const current = panel === 'explorer' ? this.filesPanel.querySelector('.file-explorer').getBoundingClientRect().width : this.querySelector(panel === 'sidebar'?'workspace-task-list':'workspace-chat').getBoundingClientRect().width;
|
|
1527
|
+
this.layout[panel] = current + (panel === 'explorer'?-delta:delta); this.applyLayout(); this.queuePersist();
|
|
1528
|
+
};
|
|
1529
|
+
node.onkeydown = event => { if (['ArrowLeft','ArrowRight'].includes(event.key)) { event.preventDefault(); change(event.key === 'ArrowRight'?16:-16); } };
|
|
1530
|
+
node.onpointerdown = event => {
|
|
1531
|
+
if (event.button !== 0) return;
|
|
1532
|
+
event.preventDefault(); this.endDrag?.(); node.setPointerCapture(event.pointerId);
|
|
1533
|
+
let x = event.clientX; this.classList.add('is-resizing'); node.classList.add('is-dragging');
|
|
1534
|
+
const move = next => { if (next.pointerId !== event.pointerId) return; const delta = next.clientX-x; x = next.clientX; change(delta); };
|
|
1535
|
+
const end = next => { if (next && next.pointerId !== event.pointerId) return; this.classList.remove('is-resizing'); node.classList.remove('is-dragging'); window.removeEventListener('pointermove',move); window.removeEventListener('pointerup',end); window.removeEventListener('pointercancel',end); this.endDrag = undefined; if (this.isConnected) this.persistHistory(); };
|
|
1536
|
+
this.endDrag = end; window.addEventListener('pointermove',move); window.addEventListener('pointerup',end); window.addEventListener('pointercancel',end);
|
|
1537
|
+
};
|
|
1538
|
+
return node;
|
|
1539
|
+
}
|
|
1540
|
+
togglePanel(panel) {
|
|
1541
|
+
const files = this.filesPanel, scrollers = this.paneScrollers();
|
|
1542
|
+
files.saveScroll();
|
|
1543
|
+
for (const node of scrollers) if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
1544
|
+
this.layout[panel+'Collapsed'] = !this.layout[panel+'Collapsed']; this.applyLayout(); files.restoreScroll();
|
|
1545
|
+
for (const node of scrollers) {
|
|
1546
|
+
const position = this.paneScrollPositions.get(node);
|
|
1547
|
+
if (position && node.clientHeight > 0) { node.scrollTop = position.top; if (node === files.tabBar) files.scrollTabs(position.left); else node.scrollLeft = position.left; }
|
|
1548
|
+
}
|
|
1549
|
+
this.persistHistory();
|
|
1550
|
+
}
|
|
1551
|
+
applyLayout() {
|
|
1552
|
+
const files = this.filesPanel; if (!files) return;
|
|
1553
|
+
files.rememberTabsScroll();
|
|
1554
|
+
const clamp = (value,min,max) => Math.max(min,Math.min(value,max));
|
|
1555
|
+
const width = this.querySelector('.workspace-layout').clientWidth || window.innerWidth;
|
|
1556
|
+
const sidebar = this.layout.sidebarCollapsed ? 0 : clamp(this.layout.sidebar ?? width*.16,140,Math.min(400,Math.max(140,width-600)));
|
|
1557
|
+
const chat = clamp(this.layout.chat ?? (width-sidebar)*.4,200,Math.max(200,width-sidebar-402));
|
|
1558
|
+
this.style.setProperty('--sidebar-size',sidebar+'px'); this.style.setProperty('--chat-size',chat+'px');
|
|
1559
|
+
this.dataset.sidebarCollapsed = String(Boolean(this.layout.sidebarCollapsed)); this.dataset.filesCollapsed = String(Boolean(this.layout.filesCollapsed)); files.dataset.explorerCollapsed = String(Boolean(this.layout.explorerCollapsed));
|
|
1560
|
+
const available = files.clientWidth || Math.max(400,width-sidebar-chat-2), explorer = clamp(this.layout.explorer ?? available*.32,120,Math.max(120,Math.min(600,available-161)));
|
|
1561
|
+
files.style.setProperty('--explorer-size',explorer+'px');
|
|
1562
|
+
for (const [panel,size,min,max] of [['sidebar',sidebar,140,400],['chat',chat,200,Math.max(200,width-sidebar-402)],['explorer',explorer,120,Math.max(120,available-161)]]) {
|
|
1563
|
+
const splitter = (panel === 'explorer' ? files : this).querySelector('.workspace-separator[data-panel='+panel+']'); splitter.setAttribute('aria-valuenow',String(Math.round(size))); splitter.setAttribute('aria-valuemin',String(min)); splitter.setAttribute('aria-valuemax',String(Math.round(max)));
|
|
1564
|
+
if (this.layout[panel] !== undefined && (panel === 'explorer'?window.innerWidth>650:window.innerWidth>950) && !this.layout[panel+'Collapsed']) this.layout[panel] = size;
|
|
1565
|
+
}
|
|
1566
|
+
for (const panel of ['sidebar','files','explorer']) {
|
|
1567
|
+
const button = panel === 'explorer' ? files.explorerToggle : this.querySelector(panel === 'files'?'.toggle-files':'.toggle-sidebar'), collapsed = Boolean(this.layout[panel+'Collapsed']);
|
|
1568
|
+
button.title = (collapsed?'展开':'折叠')+{sidebar:'任务侧栏',files:'文件工作区',explorer:'文件列表'}[panel]; button.setAttribute('aria-label',button.title); button.setAttribute('aria-pressed',String(!collapsed));
|
|
1569
|
+
}
|
|
1570
|
+
files.syncFrames();
|
|
1571
|
+
files.resizeTabs();
|
|
1572
|
+
}
|
|
1573
|
+
rememberPosition() {
|
|
1574
|
+
const files = this.filesPanel; files.saveScroll(); const tab = files.tabs.get(files.activeKey);
|
|
1575
|
+
const position = {listScrollTop:files.listScrollTop,scrollTop:tab?.scrollTop || 0,scrollLeft:tab?.scrollLeft || 0,chat:this.taskId ? this.sessions?.position() : undefined};
|
|
1576
|
+
this.positions.set(this.historyIndex,position); return position;
|
|
1577
|
+
}
|
|
1578
|
+
historyState() { return {workspace:historyScope,index:this.historyIndex,maximum:this.historyMaximumKnown?this.historyMaximum:undefined,guarded:this.historyGuard,route:this.route(),position:this.rememberPosition(),url:this.stateUrl()}; }
|
|
1579
|
+
persistTrees() {
|
|
1580
|
+
const files = this.filesPanel;
|
|
1581
|
+
for (const [mode,view] of files.navigationViews) {
|
|
1582
|
+
if (!view.ready && !view.expanded.size) continue;
|
|
1583
|
+
const pages = new Map(view.pages);
|
|
1584
|
+
for (const [entry,count] of view.restorePages) pages.set(entry,Math.max(count,pages.get(entry) || 0));
|
|
1585
|
+
this.treeStates[mode] = {expanded:[...view.expanded].sort(),pages:[...pages].filter(([,count]) => count > 1),scrollTop:view.scrollTop || 0,query:view.query || '',filterScrollTop:view.filterScrollTop || 0,filterCollapsed:[...(view.filterCollapsed || [])]};
|
|
1586
|
+
}
|
|
1587
|
+
if (Object.keys(this.treeStates).length) try { window.localStorage?.setItem(this.treeStorageKey,JSON.stringify({v:1,trees:this.treeStates})); } catch {}
|
|
1588
|
+
}
|
|
1589
|
+
stateUrl() {
|
|
1590
|
+
const files = this.filesPanel, route = this.route(), href = window.location.href;
|
|
1591
|
+
// A task URL without a signed file panel must wait for the authorized task response.
|
|
1592
|
+
if (!route.task && appBase && this.taskFromUrl(href)) return href;
|
|
1593
|
+
const url = new URL(this.taskId ? historyScope : this.guestUrl), extra = {v:1}; files.saveScroll();
|
|
1594
|
+
if (route.task) {
|
|
1595
|
+
url.searchParams.set('task',route.task);
|
|
1596
|
+
const chat = this.taskId ? this.sessions?.position() : this.chatPositionFromUrl(href);
|
|
1597
|
+
if (chat && !chat.bottom) url.searchParams.set('chat',JSON.stringify(chat));
|
|
1598
|
+
}
|
|
1599
|
+
if (!this.taskId && route.pane !== 'files') url.searchParams.set('pane',route.pane);
|
|
1600
|
+
if (route.listMode !== 'files') url.searchParams.set('list',route.listMode);
|
|
1601
|
+
if (route.tab) {
|
|
1602
|
+
url.searchParams.set('entry',route.tab.path);
|
|
1603
|
+
url.searchParams.set('tab',route.tab.id);
|
|
1604
|
+
if (route.tab.kind !== 'file') url.searchParams.set('kind',route.tab.kind);
|
|
1605
|
+
if (route.tab.mode !== 'all') url.searchParams.set('mode',route.tab.mode);
|
|
1606
|
+
if (route.tab.original) url.searchParams.set('original',route.tab.original);
|
|
1607
|
+
if (route.view !== 'content') url.searchParams.set('view',route.view);
|
|
1608
|
+
} else if (route.view !== 'list') url.searchParams.set('view',route.view);
|
|
1609
|
+
const tabs = [...files.tabs.values()].map(tab => {
|
|
1610
|
+
const value = {id:tab.key,path:tab.path};
|
|
1611
|
+
if (tab.kind !== 'file') value.kind = tab.kind;
|
|
1612
|
+
if (tab.mode !== 'all') value.mode = tab.mode;
|
|
1613
|
+
if (tab.original) value.original = tab.original;
|
|
1614
|
+
if (tab.scrollTop > 0) value.scrollTop = tab.scrollTop;
|
|
1615
|
+
if (tab.scrollLeft > 0) value.scrollLeft = tab.scrollLeft;
|
|
1616
|
+
if (tab.hash) value.hash = tab.hash;
|
|
1617
|
+
if (tab.requestedHash) value.requestedHash = tab.requestedHash;
|
|
1618
|
+
return value;
|
|
1619
|
+
});
|
|
1620
|
+
if (tabs.length !== (route.tab?1:0) || tabs.some(tab => tab.scrollTop || tab.scrollLeft || tab.hash || tab.requestedHash)) extra.tabs = tabs;
|
|
1621
|
+
if (files.recentTabs.length > 1) extra.recentTabs = files.recentTabs;
|
|
1622
|
+
const trees = {};
|
|
1623
|
+
for (const [mode,view] of files.navigationViews) {
|
|
1624
|
+
if (view.query) trees[mode] = {query:view.query};
|
|
1625
|
+
}
|
|
1626
|
+
if (Object.keys(trees).length) extra.trees = trees;
|
|
1627
|
+
const scroll = {};
|
|
1628
|
+
for (const [name,selector] of [['tasks','workspace-task-list'],['chat','.chat-body'],['composer','workspace-chat textarea'],['tabs','.file-tabs']]) {
|
|
1629
|
+
const node = name === 'tabs' ? files.tabBar : this.querySelector(selector); if (!node) continue;
|
|
1630
|
+
if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
1631
|
+
const position = this.paneScrollPositions.get(node); if ((!this.taskId || name === 'tabs') && position && (position.top || position.left)) scroll[name] = [position.top,position.left];
|
|
1632
|
+
}
|
|
1633
|
+
if (Object.keys(scroll).length) extra.scroll = scroll;
|
|
1634
|
+
const {sidebar,sidebarCollapsed,...rightLayout} = this.layout;
|
|
1635
|
+
if (appBase) put('agentbot-workspace-layout',{sidebar,sidebarCollapsed});
|
|
1636
|
+
const layout = this.taskId ? rightLayout : this.layout;
|
|
1637
|
+
if (Object.keys(layout).length) extra.layout = layout;
|
|
1638
|
+
if (Object.keys(extra).length > 1) url.hash = 'workspace='+encodeURIComponent(JSON.stringify(extra));
|
|
1639
|
+
return url.toString();
|
|
1640
|
+
}
|
|
1641
|
+
queuePersist = () => {
|
|
1642
|
+
if (this.restoring || this.navigating || this.taskHistoryPending) return;
|
|
1643
|
+
clearTimeout(this.persistTimer); this.persistTimer = setTimeout(() => { if (this.isConnected) this.persistHistory(); },200);
|
|
1644
|
+
};
|
|
1645
|
+
persistHistory = event => {
|
|
1646
|
+
if (this.historyTraversal?.skipping || this.taskHistoryPending) return;
|
|
1647
|
+
if (event && window.history.state?.workspace !== historyScope) return;
|
|
1648
|
+
clearTimeout(this.persistTimer); const state = this.historyState(), url = state.url;
|
|
1649
|
+
this.persistTrees();
|
|
1650
|
+
if (this.taskId) put('agentbot-workspace-task:'+this.taskId,{root:this.filesPanel.projectRoot,href:url,chat:state.position.chat});
|
|
1651
|
+
if (window.history.state?.workspace !== historyScope || window.history.state.url !== url || window.history.state.index !== this.historyIndex) window.history.replaceState(state,'',url);
|
|
1652
|
+
this.syncedUrl = url; this.historyRoutes.set(this.historyIndex,state.route); this.updateNavigation();
|
|
1653
|
+
};
|
|
1654
|
+
navigate(action, replace = false) {
|
|
1655
|
+
if (this.navigating || this.restoring) { action(); return; }
|
|
1656
|
+
this.finishHistoryTraversal();
|
|
1657
|
+
const before = JSON.stringify(this.route()); this.persistHistory();
|
|
1658
|
+
this.navigating = true; try { action(); } finally { this.navigating = false; }
|
|
1659
|
+
const changed = before !== JSON.stringify(this.route());
|
|
1660
|
+
if (changed && !replace) {
|
|
1661
|
+
this.historyIndex++; this.historyMaximum = this.historyIndex; this.historyMaximumKnown = true;
|
|
1662
|
+
for (const index of this.historyRoutes.keys()) if (index >= this.historyIndex) this.historyRoutes.delete(index);
|
|
1663
|
+
const state = this.historyState(), url = state.url; window.history.pushState(state,'',url); this.syncedUrl = url;
|
|
1664
|
+
this.historyRoutes.set(this.historyIndex,state.route); this.updateNavigation();
|
|
1665
|
+
}
|
|
1666
|
+
else this.persistHistory();
|
|
1667
|
+
}
|
|
1668
|
+
updateNavigation() {
|
|
1669
|
+
const files = this.filesPanel, current = files.tabs.get(files.activeKey), task = files.taskId;
|
|
1670
|
+
const available = direction => {
|
|
1671
|
+
if (!current) return false;
|
|
1672
|
+
if (direction < 0 && this.historyIndex === 0) return current.kind === 'web' && this.historyGuard;
|
|
1673
|
+
// Cross-origin frames do not expose their own Back/Forward boundaries.
|
|
1674
|
+
if (current.kind === 'web' || direction > 0 && !this.historyMaximumKnown) return true;
|
|
1675
|
+
const count = direction < 0 ? this.historyIndex : this.historyMaximum-this.historyIndex;
|
|
1676
|
+
let known = 0;
|
|
1677
|
+
for (const [index,route] of this.historyRoutes) if (direction < 0 ? index >= 0 && index < this.historyIndex : index > this.historyIndex && index <= this.historyMaximum) {
|
|
1678
|
+
known++;
|
|
1679
|
+
if (route.task === task && (task || route.pane === 'files') && route.view === 'content' && route.tab && files.tabs.has(route.tab.id)) return true;
|
|
1680
|
+
}
|
|
1681
|
+
return known < count;
|
|
1682
|
+
};
|
|
1683
|
+
files.navigationBack.disabled = !available(-1); files.navigationForward.disabled = !available(1);
|
|
1684
|
+
}
|
|
1685
|
+
goBack() { this.traverseHistory(-1); }
|
|
1686
|
+
traverseHistory(direction) {
|
|
1687
|
+
const files = this.filesPanel, current = files.tabs.get(files.activeKey);
|
|
1688
|
+
this.updateNavigation(); if (!current || (direction < 0 ? files.navigationBack : files.navigationForward).disabled) return;
|
|
1689
|
+
files.revealActiveTab(); this.persistHistory();
|
|
1690
|
+
if (direction < 0 && this.historyIndex === 0 && (!this.historyGuard || current?.kind !== 'web')) return;
|
|
1691
|
+
this.stepHistory(direction,true,false);
|
|
1692
|
+
}
|
|
1693
|
+
finishHistoryTraversal() { clearTimeout(this.historyTimer); this.historyTraversal = undefined; this.updateNavigation(); }
|
|
1694
|
+
stepHistory(direction, local, skipping) {
|
|
1695
|
+
clearTimeout(this.historyTimer); const index = window.history.state?.index, traversal = this.historyTraversal = {direction,local,skipping};
|
|
1696
|
+
this.updateNavigation();
|
|
1697
|
+
// Native history has no completion event for a no-op or child-only traversal.
|
|
1698
|
+
this.historyTimer = setTimeout(() => {
|
|
1699
|
+
if (this.historyTraversal !== traversal) return;
|
|
1700
|
+
if (skipping && window.history.state?.workspace === historyScope && window.history.state.index === index) this.stepHistory(-direction,local,true);
|
|
1701
|
+
else this.finishHistoryTraversal();
|
|
1702
|
+
},250);
|
|
1703
|
+
window.history.go(direction);
|
|
1704
|
+
}
|
|
1705
|
+
restoreUrl(merge, position, href, local = false, pane) {
|
|
1706
|
+
this.restoring = true;
|
|
1707
|
+
try {
|
|
1708
|
+
const files = this.filesPanel;
|
|
1709
|
+
const resolveId = (kind,path) => {
|
|
1710
|
+
const view = kind+':'+path;
|
|
1711
|
+
if (files.views.get(files.activeKey)?.has(view)) return files.activeKey;
|
|
1712
|
+
for (const [key,views] of files.views) if (files.tabs.has(key) && views.has(view)) return key;
|
|
1713
|
+
};
|
|
1714
|
+
let saved;
|
|
1715
|
+
try { saved = readUrlState(href,merge?resolveId:undefined); }
|
|
1716
|
+
catch (error) {
|
|
1717
|
+
const notice = element('div','无法还原链接中的页面状态:'+error.message+' 已返回文件列表。','workspace-notice'); notice.setAttribute('role','status'); this.querySelector('.workspace-layout').before(notice);
|
|
1718
|
+
saved = {route:{pane:'files',listMode:'files',view:'list',tab:null},tabs:[],trees:{},scroll:{}};
|
|
1719
|
+
}
|
|
1720
|
+
if (pane) saved.route.pane = pane;
|
|
1721
|
+
if (local && files.taskId) saved.route.pane = 'files';
|
|
1722
|
+
saved.route.task = files.taskId;
|
|
1723
|
+
if (!files.fileApi) saved = {...saved,route:{...saved.route,listMode:'files',view:'list',tab:null},tabs:[],recentTabs:[],trees:{}};
|
|
1724
|
+
const activeKey = saved.route.tab?.id;
|
|
1725
|
+
if (merge) this.historyRoutes.set(window.history.state.index,{...saved.route});
|
|
1726
|
+
if (merge && (saved.route.tab && !files.tabs.has(activeKey) || local && (!saved.route.tab || saved.route.pane !== 'files' || saved.route.view !== 'content'))) return false;
|
|
1727
|
+
if (merge) {
|
|
1728
|
+
const tab = saved.tabs.find(tab => tab.id === activeKey), previous = files.tabs.get(activeKey);
|
|
1729
|
+
if (tab) {
|
|
1730
|
+
if (files.activeKey === activeKey && (previous.path !== tab.path || previous.kind !== tab.kind || previous.mode !== tab.mode || previous.original !== tab.original)) files.renderedKey = undefined;
|
|
1731
|
+
files.tabs.set(activeKey,Object.assign(files.tabView(activeKey,tab.path,tab.kind,tab.original),tab));
|
|
1732
|
+
}
|
|
1733
|
+
if (local) saved.route.listMode = files.listMode;
|
|
1734
|
+
} else {
|
|
1735
|
+
this.layout = {...(appBase ? this.globalLayout() : {}),...saved.layout}; this.applyLayout();
|
|
1736
|
+
files.tabs = new Map(saved.tabs.map(tab => [tab.id,Object.assign(files.tabView(tab.id,tab.path,tab.kind,tab.original),tab)])); files.recentTabs = saved.recentTabs || [];
|
|
1737
|
+
const trees = {};
|
|
1738
|
+
for (const mode of ['files','changes']) {
|
|
1739
|
+
const value = this.treeStates[mode] || {}, query = saved.trees[mode]?.query || '';
|
|
1740
|
+
trees[mode] = {...value,query,...(query !== (value.query || '')?{filterCollapsed:[],filterScrollTop:0}:{})};
|
|
1741
|
+
}
|
|
1742
|
+
files.restoreTrees(trees); const view = files.navigationView(files.listMode); files.listScrollTop = (view.query?view.filterScrollTop:view.scrollTop) || 0;
|
|
1743
|
+
}
|
|
1744
|
+
if (merge) for (const node of this.paneScrollers()) if (node.clientHeight > 0) this.paneScrollPositions.set(node,{top:Math.max(0,node.scrollTop || 0),left:Math.max(0,node.scrollLeft || 0)});
|
|
1745
|
+
this.selectPane(saved.route.pane);
|
|
1746
|
+
const tree = files.navigationView(saved.route.listMode);
|
|
1747
|
+
const active = files.tabs.get(activeKey), target = {...(position || {listScrollTop:(tree?.query?tree.filterScrollTop:tree?.scrollTop) || 0,scrollTop:active?.scrollTop || 0,scrollLeft:active?.scrollLeft || 0})};
|
|
1748
|
+
if (merge) { const view = files.navigationView(saved.route.listMode); target.listScrollTop = (view.query?view.filterScrollTop:view.scrollTop) || 0; }
|
|
1749
|
+
files.restoreView(saved.route,target);
|
|
1750
|
+
if (!merge) for (const [name,selector] of [['tasks','workspace-task-list'],['chat','.chat-body'],['composer','workspace-chat textarea'],['tabs','.file-tabs']]) {
|
|
1751
|
+
const node = name === 'tabs' ? files.tabBar : this.querySelector(selector), values = saved.scroll[name];
|
|
1752
|
+
if (node && values) { this.paneScrollPositions.set(node,{top:values[0],left:values[1]}); if (node === files.tabBar) files.scrollTabs(values[1]); if (node.clientHeight > 0) { node.scrollTop = values[0]; if (node !== files.tabBar) node.scrollLeft = values[1]; } }
|
|
1753
|
+
}
|
|
1754
|
+
if (merge) files.revealActiveTab();
|
|
1755
|
+
return true;
|
|
1756
|
+
}
|
|
1757
|
+
finally { this.restoring = false; }
|
|
1758
|
+
}
|
|
1759
|
+
historyChanged = event => {
|
|
1760
|
+
if (event.state?.workspace !== historyScope) { this.finishHistoryTraversal(); return; }
|
|
1761
|
+
const traversal = this.historyTraversal, direction = traversal?.direction || Math.sign(event.state.index-this.historyIndex) || -1, local = Boolean(traversal?.local);
|
|
1762
|
+
if (event.state.boundary) { this.stepHistory(local?-direction:direction,local,true); return; }
|
|
1763
|
+
if (event.state.index === this.historyIndex && window.location.href === this.syncedUrl) { this.finishHistoryTraversal(); this.filesPanel.revealActiveTab(); this.persistHistory(); return; }
|
|
1764
|
+
const sameIndex = event.state.index === this.historyIndex; this.rememberPosition();
|
|
1765
|
+
clearTimeout(this.persistTimer); this.taskHistoryPending = false;
|
|
1766
|
+
const targetTask = appBase ? this.taskFromUrl(window.location.href) : undefined;
|
|
1767
|
+
if (appBase && this.sessions?.selecting && this.sessions.target !== targetTask && !local) this.sessions.cancelSelection();
|
|
1768
|
+
const position = sameIndex ? undefined : this.positions.get(event.state.index) || event.state.position;
|
|
1769
|
+
const panelTask = this.filesPanel.taskId, pane = panelTask ? event.state.route?.pane : undefined;
|
|
1770
|
+
if (appBase && !local && targetTask !== panelTask && this.sessions?.csrf) {
|
|
1771
|
+
const href = window.location.href, index = event.state.index;
|
|
1772
|
+
if (targetTask) { this.taskHistoryPending = true; void this.sessions.choose(targetTask,{history:true,href,index,position,pane:event.state.route?.pane}); }
|
|
1773
|
+
else { this.sessions.clearTask(); this.releaseSessionPanels(href); this.historyIndex = index; this.finishHistoryTraversal(); this.persistHistory(); }
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
if ((!local || targetTask === panelTask) && this.restoreUrl(true,position,undefined,local,pane)) {
|
|
1777
|
+
if (!local && this.taskId && targetTask === this.taskId) this.sessions?.restoreHistoryPosition(position?.chat || this.chatPositionFromUrl(window.location.href) || {bottom:true});
|
|
1778
|
+
this.historyIndex = event.state.index; this.finishHistoryTraversal(); this.persistHistory();
|
|
1779
|
+
} else if (local && (direction < 0 && event.state.index <= 0 || direction > 0 && this.historyMaximumKnown && event.state.index >= this.historyMaximum)) this.stepHistory(-direction,local,true);
|
|
1780
|
+
else this.stepHistory(direction,local,true);
|
|
1781
|
+
};
|
|
1782
|
+
urlChanged = () => { if (window.location.href !== this.syncedUrl && window.history.state?.workspace === historyScope) this.historyChanged({state:window.history.state}); };
|
|
1783
|
+
statusChanged = event => {
|
|
1784
|
+
event.target.lastStatus = event.detail;
|
|
1785
|
+
if (event.target !== this.filesPanel) return;
|
|
1786
|
+
const status = this.querySelector('.workspace-status'), label = this.sessionConnection || event.detail.label;
|
|
1787
|
+
status.replaceChildren(icon(event.detail.repository?'branch':'lock'),element('span',label));
|
|
1788
|
+
status.title = this.sessionConnection && event.detail.repository ? label+' · '+event.detail.label : label;
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
customElements.define('workspace-task-list',WorkspaceTaskList);
|
|
1792
|
+
customElements.define('workspace-chat',WorkspaceChat);
|
|
1793
|
+
customElements.define('workspace-files',WorkspaceFiles);
|
|
1794
|
+
customElements.define('agentbot-workspace',AgentBotWorkspace);
|
|
1795
|
+
})();
|