dsh-git-assistant 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/LICENSE +21 -0
- package/README.md +133 -2
- package/cordis.patch.yml +4 -0
- package/icon.svg +7 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +82 -4
- package/src/client.js +4407 -0
- package/src/index.js +1854 -0
package/src/client.js
ADDED
|
@@ -0,0 +1,4407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-git-assistant — browser half.
|
|
3
|
+
*
|
|
4
|
+
* One panel, two seats:
|
|
5
|
+
* - conversation.view → a tab next to 对话 / 轨迹 / 上下文 in a Session;
|
|
6
|
+
* - sidebar.panellist + main → a global entry in the left rail that opens the same panel.
|
|
7
|
+
*
|
|
8
|
+
* v0.2.0: source control (staged / changes / untracked), file browser, unified & split diff with a
|
|
9
|
+
* light syntax highlighter, stage / unstage / discard / commit / amend / branch switch + create.
|
|
10
|
+
*/
|
|
11
|
+
window.__ModuleLoader__.load({
|
|
12
|
+
id: 'dsh-git-assistant',
|
|
13
|
+
factory: (require) => {
|
|
14
|
+
const React = require('react')
|
|
15
|
+
const h = React.createElement
|
|
16
|
+
const { memo, useCallback, useEffect, useMemo, useRef, useState } = React
|
|
17
|
+
|
|
18
|
+
const NS = 'dshGitAssistant'
|
|
19
|
+
const ID = 'dsh-git-assistant'
|
|
20
|
+
const STORAGE_REPOSITORY = 'dsh-git-assistant:repository'
|
|
21
|
+
const POLL_MS = 5000
|
|
22
|
+
const SHARED_STATE = new Map()
|
|
23
|
+
const SHARED_LISTENERS = new Set()
|
|
24
|
+
|
|
25
|
+
function useSharedState(key, initial) {
|
|
26
|
+
const [value, setValue] = useState(() => {
|
|
27
|
+
if (SHARED_STATE.has(key)) return SHARED_STATE.get(key)
|
|
28
|
+
const next = typeof initial === 'function' ? initial() : initial
|
|
29
|
+
SHARED_STATE.set(key, next)
|
|
30
|
+
return next
|
|
31
|
+
})
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const listener = () => setValue(SHARED_STATE.get(key))
|
|
34
|
+
SHARED_LISTENERS.add(listener)
|
|
35
|
+
return () => { SHARED_LISTENERS.delete(listener) }
|
|
36
|
+
}, [key])
|
|
37
|
+
const set = useCallback(next => {
|
|
38
|
+
const computed = typeof next === 'function' ? next(SHARED_STATE.get(key)) : next
|
|
39
|
+
SHARED_STATE.set(key, computed)
|
|
40
|
+
for (const listener of SHARED_LISTENERS) listener()
|
|
41
|
+
}, [key])
|
|
42
|
+
return [value, set]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const statusBus = new Map()
|
|
46
|
+
let statusLoop = null
|
|
47
|
+
|
|
48
|
+
function statusEntryOf(path) {
|
|
49
|
+
let entry = statusBus.get(path)
|
|
50
|
+
if (!entry) {
|
|
51
|
+
entry = { path, listeners: new Set(), state: { phase: 'idle', data: null, error: null }, inFlight: null, queued: false, failures: 0, lastFetch: 0 }
|
|
52
|
+
statusBus.set(path, entry)
|
|
53
|
+
}
|
|
54
|
+
return entry
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function notifyStatus(entry) {
|
|
58
|
+
for (const listener of entry.listeners) listener(entry.state)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function loadStatusEntry(entry) {
|
|
62
|
+
if (entry.inFlight) { entry.queued = true; return entry.inFlight }
|
|
63
|
+
entry.lastFetch = Date.now()
|
|
64
|
+
entry.inFlight = api('/status', { path: entry.path })
|
|
65
|
+
.then(data => {
|
|
66
|
+
entry.failures = 0
|
|
67
|
+
entry.state = { phase: 'ready', data, error: null }
|
|
68
|
+
})
|
|
69
|
+
.catch(error => {
|
|
70
|
+
entry.failures = Math.min(entry.failures + 1, 4)
|
|
71
|
+
entry.state = { phase: 'error', data: entry.state.data, error: String(error?.message ?? error) }
|
|
72
|
+
})
|
|
73
|
+
.finally(() => {
|
|
74
|
+
entry.inFlight = null
|
|
75
|
+
notifyStatus(entry)
|
|
76
|
+
if (entry.queued) { entry.queued = false; loadStatusEntry(entry) }
|
|
77
|
+
})
|
|
78
|
+
return entry.inFlight
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function ensureStatusLoop() {
|
|
82
|
+
if (statusLoop) return
|
|
83
|
+
statusLoop = setInterval(() => {
|
|
84
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
85
|
+
const now = Date.now()
|
|
86
|
+
for (const entry of statusBus.values()) {
|
|
87
|
+
if (entry.listeners.size === 0) continue
|
|
88
|
+
const backoff = entry.failures > 0 ? Math.min(60000, POLL_MS * 2 ** entry.failures) : POLL_MS
|
|
89
|
+
if (now - entry.lastFetch >= backoff) loadStatusEntry(entry)
|
|
90
|
+
}
|
|
91
|
+
}, POLL_MS)
|
|
92
|
+
statusLoop.unref?.()
|
|
93
|
+
const wake = () => {
|
|
94
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
95
|
+
for (const entry of statusBus.values()) if (entry.listeners.size > 0) loadStatusEntry(entry)
|
|
96
|
+
}
|
|
97
|
+
if (typeof document !== 'undefined') document.addEventListener('visibilitychange', wake)
|
|
98
|
+
if (typeof window !== 'undefined') window.addEventListener('focus', wake)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function subscribeStatus(path, listener) {
|
|
102
|
+
const entry = statusEntryOf(path)
|
|
103
|
+
entry.listeners.add(listener)
|
|
104
|
+
listener(entry.state)
|
|
105
|
+
ensureStatusLoop()
|
|
106
|
+
if (entry.listeners.size === 1) loadStatusEntry(entry)
|
|
107
|
+
return () => { entry.listeners.delete(listener) }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function refreshStatusPath(path) {
|
|
111
|
+
const entry = path ? statusBus.get(path) : undefined
|
|
112
|
+
return entry ? loadStatusEntry(entry) : Promise.resolve()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Subscribe to host-side Git change events for one checkout; the browser reconnects automatically. */
|
|
116
|
+
function useRepoEvents(path, onChange) {
|
|
117
|
+
const handlerRef = useRef(onChange)
|
|
118
|
+
handlerRef.current = onChange
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!path || typeof EventSource === 'undefined') return undefined
|
|
121
|
+
const source = new EventSource(`${window.location.origin}/git-assistant/api/events?path=${encodeURIComponent(path)}`)
|
|
122
|
+
let timer = null
|
|
123
|
+
const listener = () => {
|
|
124
|
+
if (timer) return
|
|
125
|
+
timer = setTimeout(() => { timer = null; handlerRef.current?.() }, 700)
|
|
126
|
+
}
|
|
127
|
+
source.addEventListener('change', listener)
|
|
128
|
+
return () => {
|
|
129
|
+
if (timer) clearTimeout(timer)
|
|
130
|
+
source.removeEventListener('change', listener)
|
|
131
|
+
source.close()
|
|
132
|
+
}
|
|
133
|
+
}, [path])
|
|
134
|
+
}
|
|
135
|
+
const MAX_DIFF_LINES = 6000
|
|
136
|
+
const MAX_PREVIEW_LINES = 5000
|
|
137
|
+
|
|
138
|
+
const DICT = {
|
|
139
|
+
zh: {
|
|
140
|
+
label: 'Git', title: 'Git 工作台',
|
|
141
|
+
changesTab: '更改', filesTab: '文件', issuesTab: '议题',
|
|
142
|
+
issueDetailEmpty: '选择右侧的议题查看详情', issueNoIssues: '没有匹配的议题',
|
|
143
|
+
issuesOpen: '打开', issuesClosed: '关闭', issuesAll: '全部',
|
|
144
|
+
issueOpenInGitHub: '在 GitHub 打开', issueParent: '父议题', issueChildren: '子议题',
|
|
145
|
+
issueSearchPlaceholder: '搜索议题…', issueComments: '评论', issueUpdated: '更新', issueNoComments: '暂无评论', loadMore: '加载更多',
|
|
146
|
+
staged: '已暂存的更改', unstaged: '更改', untracked: '未跟踪',
|
|
147
|
+
noRepos: '没有找到 Git 仓库', noReposHint: '在 DSH 里添加一个 Git 仓库目录作为工作区后,这里会列出来。',
|
|
148
|
+
loading: '读取中…', refresh: '刷新', pickRepo: '选择仓库',
|
|
149
|
+
emptyDiff: '选择文件查看改动', emptyDiffHint: '点击左侧变更文件查看差异;也可以切到「文件」浏览仓库。',
|
|
150
|
+
noDiff: '该文件没有可显示的差异', binary: '二进制文件,暂不展示内容',
|
|
151
|
+
truncateNotice: '内容较大,已截断显示', readOnly: '只读预览',
|
|
152
|
+
commitPlaceholder: '提交信息(Ctrl/⌘ + Enter 提交)', commit: '提交', amend: '修补上次提交',
|
|
153
|
+
commitAmend: '提交(修改)', commitPush: '提交并推送', commitSync: '提交并同步',
|
|
154
|
+
committedPushed: '已提交并推送', committedSynced: '已提交并同步',
|
|
155
|
+
commitEmpty: '先写提交信息', committing: '提交中…',
|
|
156
|
+
stageAll: '全部暂存', unstageAll: '全部取消暂存', stage: '暂存', unstage: '取消暂存', discard: '丢弃',
|
|
157
|
+
discardTitle: '丢弃更改?', discardTracked: '将丢弃 {file} 的工作区改动,无法撤销。',
|
|
158
|
+
discardUntracked: '将删除未跟踪文件 {file},无法撤销。', discardAllTitle: '丢弃全部更改?',
|
|
159
|
+
discardAllMessage: '将丢弃 {count} 个文件的更改(含未跟踪文件),无法撤销。',
|
|
160
|
+
cancel: '取消', confirm: '确认',
|
|
161
|
+
switched: '已切换到 {branch}', created: '已创建分支 {branch}', stagedDone: '已暂存 {count} 个文件',
|
|
162
|
+
unstagedDone: '已取消暂存 {count} 个文件', committed: '已提交', branchPlaceholder: '新分支名…', createBranch: '新建分支',
|
|
163
|
+
switchConfirmTitle: '切换分支?', switchConfirm: '当前有未提交的更改,切换后会带到 {branch}。继续?',
|
|
164
|
+
filterPlaceholder: '筛选文件…', filesLoading: '读取文件列表…', noFiles: '没有文件',
|
|
165
|
+
copyPath: '复制文件路径', copyFolderPath: '复制文件夹路径', copyImage: '复制图片',
|
|
166
|
+
downloadFile: '下载', saveAs: '另存为…', revealInFinder: '在 Finder 中显示', openDefaultApp: '用默认应用打开',
|
|
167
|
+
copiedPath: '已复制路径', imageCopied: '图片已复制', actionFailed: '操作失败',
|
|
168
|
+
filesTruncated: '文件过多,仅显示前 {count} 个',
|
|
169
|
+
conflicts: '冲突', ahead: '待推送', behind: '待拉取', detached: '游离 HEAD',
|
|
170
|
+
loadError: '读取失败', omitted: '另有 {count} 个未跟踪文件未列出',
|
|
171
|
+
unified: '统一', split: '并排', viewLabel: '视图',
|
|
172
|
+
worktree: '工作树', mainWorktree: '主工作树',
|
|
173
|
+
noBranch: '无分支',
|
|
174
|
+
viewAll: '查看全部更改',
|
|
175
|
+
discardAll: '放弃全部更改',
|
|
176
|
+
allChanges: '全部更改',
|
|
177
|
+
allStaged: '全部已暂存',
|
|
178
|
+
allDiffLoading: '正在读取全部差异…',
|
|
179
|
+
allDiffLimited: '仅显示前 {count} 个文件',
|
|
180
|
+
resize: '拖动调整宽度',
|
|
181
|
+
worktrees: '工作树',
|
|
182
|
+
cleanTree: '工作区干净,没有更改',
|
|
183
|
+
syncChanges: '同步更改',
|
|
184
|
+
graphTitle: '图形',
|
|
185
|
+
graphLoading: '读取提交历史…',
|
|
186
|
+
graphEmpty: '没有提交记录',
|
|
187
|
+
syncing: '同步中…',
|
|
188
|
+
detached: '游离 HEAD',
|
|
189
|
+
pickChat: '选择聊天',
|
|
190
|
+
newChat: '新建边聊',
|
|
191
|
+
chatEmpty: '还没有消息',
|
|
192
|
+
send: '发送',
|
|
193
|
+
chatCollapse: '收起聊天',
|
|
194
|
+
chatExpand: '展开聊天',
|
|
195
|
+
chatHeader: '边聊',
|
|
196
|
+
rightbarHint: '在右侧栏中打开 Git 工作台;展开宽度可看完整 diff。',
|
|
197
|
+
quoteAction: '引用文本',
|
|
198
|
+
quoted: '已引用到对话输入框',
|
|
199
|
+
quoteCopied: '已复制选中文本,可粘贴到对话',
|
|
200
|
+
branches: '分支',
|
|
201
|
+
changes: '更改',
|
|
202
|
+
graphOptions: '图形选项',
|
|
203
|
+
commitScope: '提交范围',
|
|
204
|
+
currentBranch: '当前分支',
|
|
205
|
+
allRefs: '所有引用(含远端/标签)',
|
|
206
|
+
fileDisplayMode: '提交文件展示方式',
|
|
207
|
+
viewTree: '树形展示',
|
|
208
|
+
viewList: '列表展示',
|
|
209
|
+
statsFiles: '{count} 个文件',
|
|
210
|
+
unknownAuthor: '未知作者',
|
|
211
|
+
cardRenderFailed: '卡片渲染失败:{error}',
|
|
212
|
+
panelRenderFailed: 'Git 面板渲染失败:{error}', retry: '重试',
|
|
213
|
+
moreCommitActions: '更多提交方式',
|
|
214
|
+
moreLines: '已显示 {shown} / {total} 行,继续滚动加载',
|
|
215
|
+
selectCommit: '选择提交', unpushedCommits: '未推送的提交', noUnpushedCommits: '当前分支没有未推送的提交',
|
|
216
|
+
wrapLines: '换行', collapseAllFiles: '全部折叠', expandAllFiles: '全部展开', workspaceChanges: '工作区更改', commitChanges: '本次提交的更改',
|
|
217
|
+
diffHunkCollapsed: '这个 hunk 有 {count} 行,点击展开',
|
|
218
|
+
unchangedLines: '{count} 行未变更,点击展开',
|
|
219
|
+
dirtyCount: '{count} 个文件有改动',
|
|
220
|
+
moreFileActions: '更多操作', fileHistory: '文件历史', fileHistoryEmpty: '这个文件还没有提交记录',
|
|
221
|
+
stashPush: '暂存到 stash', stashPop: '恢复到工作区', stashList: 'stash 列表', stashEmpty: '没有 stash',
|
|
222
|
+
stashPushed: '已暂存到 stash', stashPopped: '已恢复 stash', stashChip: '查看 stash',
|
|
223
|
+
stashChipCount: '查看 stash 记录({count} 条)',
|
|
224
|
+
commentPlaceholder: '写下评论,Ctrl/⌘ + Enter 发送', commentSend: '发送评论', commentSending: '发送中…',
|
|
225
|
+
commentEmpty: '评论不能为空', commentDone: '评论已发送',
|
|
226
|
+
closeIssue: '关闭议题', reopenIssue: '重新打开', issueClosedOk: '议题已关闭', issueReopenedOk: '议题已重新打开',
|
|
227
|
+
issueStateOpen: '开启', issueStateClosed: '已关闭',
|
|
228
|
+
branchInWorktree: '占用:{name}',
|
|
229
|
+
branchInWorktreeHint: '该分支已在「{name}」工作树中检出;同一个分支不能同时在两个工作树里检出',
|
|
230
|
+
switchBranchHere: '切换此工作树的分支', worktreeBranches: '工作树分支',
|
|
231
|
+
switchedWorktree: '已把「{worktree}」切到 {branch}',
|
|
232
|
+
},
|
|
233
|
+
en: {
|
|
234
|
+
label: 'Git', title: 'Git Workbench',
|
|
235
|
+
changesTab: 'Changes', filesTab: 'Files', issuesTab: 'Issues',
|
|
236
|
+
issueDetailEmpty: 'Select an issue on the right', issueNoIssues: 'No matching issues',
|
|
237
|
+
issuesOpen: 'Open', issuesClosed: 'Closed', issuesAll: 'All',
|
|
238
|
+
issueOpenInGitHub: 'Open in GitHub', issueParent: 'Parent', issueChildren: 'Children',
|
|
239
|
+
issueSearchPlaceholder: 'Search issues…', issueComments: 'comments', issueUpdated: 'updated', issueNoComments: 'No comments yet', loadMore: 'Load more',
|
|
240
|
+
staged: 'Staged changes', unstaged: 'Changes', untracked: 'Untracked',
|
|
241
|
+
noRepos: 'No Git repository found', noReposHint: 'Add the directory of a Git repository as a DSH workspace and it appears here.',
|
|
242
|
+
loading: 'Loading…', refresh: 'Refresh', pickRepo: 'Pick repository',
|
|
243
|
+
emptyDiff: 'Select a file to see its diff', emptyDiffHint: 'Click a changed file on the left, or switch to Files to browse the repository.',
|
|
244
|
+
noDiff: 'This file has no diff to show', binary: 'Binary file; content is not rendered',
|
|
245
|
+
truncateNotice: 'Content truncated', readOnly: 'Read-only preview',
|
|
246
|
+
commitPlaceholder: 'Commit message (Ctrl/⌘ + Enter to commit)', commit: 'Commit', amend: 'Amend last commit',
|
|
247
|
+
commitAmend: 'Commit (amend)', commitPush: 'Commit & push', commitSync: 'Commit & sync',
|
|
248
|
+
committedPushed: 'Committed and pushed', committedSynced: 'Committed and synced',
|
|
249
|
+
commitEmpty: 'Write a commit message first', committing: 'Committing…',
|
|
250
|
+
stageAll: 'Stage all', unstageAll: 'Unstage all', stage: 'Stage', unstage: 'Unstage', discard: 'Discard',
|
|
251
|
+
discardTitle: 'Discard changes?', discardTracked: 'Working-tree changes in {file} will be lost. This cannot be undone.',
|
|
252
|
+
discardUntracked: 'Untracked file {file} will be deleted. This cannot be undone.', discardAllTitle: 'Discard all changes?',
|
|
253
|
+
discardAllMessage: 'Changes in {count} files (including untracked) will be lost. This cannot be undone.',
|
|
254
|
+
cancel: 'Cancel', confirm: 'Confirm',
|
|
255
|
+
switched: 'Switched to {branch}', created: 'Created branch {branch}', stagedDone: 'Staged {count} files',
|
|
256
|
+
unstagedDone: 'Unstaged {count} files', committed: 'Committed', branchPlaceholder: 'New branch name…', createBranch: 'Create branch',
|
|
257
|
+
switchConfirmTitle: 'Switch branch?', switchConfirm: 'There are uncommitted changes; they will follow you to {branch}. Continue?',
|
|
258
|
+
filterPlaceholder: 'Filter files…', filesLoading: 'Loading files…', noFiles: 'No files',
|
|
259
|
+
copyPath: 'Copy file path', copyFolderPath: 'Copy folder path', copyImage: 'Copy image',
|
|
260
|
+
downloadFile: 'Download', saveAs: 'Save as…', revealInFinder: 'Reveal in Finder', openDefaultApp: 'Open with default app',
|
|
261
|
+
copiedPath: 'Path copied', imageCopied: 'Image copied', actionFailed: 'Action failed',
|
|
262
|
+
filesTruncated: 'Too many files; showing the first {count}',
|
|
263
|
+
conflicts: 'conflicts', ahead: 'to push', behind: 'to pull', detached: 'Detached HEAD',
|
|
264
|
+
loadError: 'Failed to load', omitted: '{count} more untracked files not listed',
|
|
265
|
+
unified: 'Unified', split: 'Split', viewLabel: 'View',
|
|
266
|
+
worktree: 'worktree', mainWorktree: 'main worktree',
|
|
267
|
+
noBranch: 'no branch',
|
|
268
|
+
viewAll: 'View all changes',
|
|
269
|
+
discardAll: 'Discard all changes',
|
|
270
|
+
allChanges: 'All changes',
|
|
271
|
+
allStaged: 'All staged changes',
|
|
272
|
+
allDiffLoading: 'Loading all diffs…',
|
|
273
|
+
allDiffLimited: 'Showing the first {count} files',
|
|
274
|
+
resize: 'Drag to resize',
|
|
275
|
+
worktrees: 'Worktrees',
|
|
276
|
+
cleanTree: 'Working tree clean',
|
|
277
|
+
syncChanges: 'Sync changes',
|
|
278
|
+
graphTitle: 'Graph',
|
|
279
|
+
graphLoading: 'Loading history…',
|
|
280
|
+
graphEmpty: 'No commits',
|
|
281
|
+
syncing: 'Syncing…',
|
|
282
|
+
detached: 'Detached HEAD',
|
|
283
|
+
pickChat: 'Pick chat',
|
|
284
|
+
newChat: 'New side chat',
|
|
285
|
+
chatEmpty: 'No messages yet',
|
|
286
|
+
send: 'Send',
|
|
287
|
+
chatCollapse: 'Collapse chat',
|
|
288
|
+
chatExpand: 'Expand chat',
|
|
289
|
+
chatHeader: 'Side chat',
|
|
290
|
+
rightbarHint: 'Open the Git workbench in the right sidebar; widen it for the full diff.',
|
|
291
|
+
quoteAction: 'Quote',
|
|
292
|
+
quoted: 'Quoted into the chat composer',
|
|
293
|
+
quoteCopied: 'Selection copied — paste it into the chat',
|
|
294
|
+
branches: 'Branches',
|
|
295
|
+
changes: 'Changes',
|
|
296
|
+
graphOptions: 'Graph options',
|
|
297
|
+
commitScope: 'Commit scope',
|
|
298
|
+
currentBranch: 'Current branch',
|
|
299
|
+
allRefs: 'All refs (remote + tags)',
|
|
300
|
+
fileDisplayMode: 'Commit file display',
|
|
301
|
+
viewTree: 'Tree view',
|
|
302
|
+
viewList: 'List view',
|
|
303
|
+
statsFiles: '{count} files',
|
|
304
|
+
unknownAuthor: 'Unknown author',
|
|
305
|
+
cardRenderFailed: 'Card render failed: {error}',
|
|
306
|
+
panelRenderFailed: 'Git panel failed to render: {error}', retry: 'Retry',
|
|
307
|
+
moreCommitActions: 'More commit actions',
|
|
308
|
+
moreLines: 'Showing {shown} / {total} lines — scroll to load more',
|
|
309
|
+
selectCommit: 'Select commit', unpushedCommits: 'Unpushed commits', noUnpushedCommits: 'No unpushed commits on this branch',
|
|
310
|
+
wrapLines: 'Wrap lines', collapseAllFiles: 'Collapse all', expandAllFiles: 'Expand all', workspaceChanges: 'Working tree changes', commitChanges: 'Changes in this commit',
|
|
311
|
+
diffHunkCollapsed: 'This hunk has {count} lines — click to expand',
|
|
312
|
+
unchangedLines: '{count} unchanged lines — click to expand',
|
|
313
|
+
dirtyCount: '{count} changed files',
|
|
314
|
+
moreFileActions: 'More actions', fileHistory: 'File history', fileHistoryEmpty: 'No commits touch this file yet',
|
|
315
|
+
stashPush: 'Stash changes', stashPop: 'Pop stash', stashList: 'Stashes', stashEmpty: 'No stash entries',
|
|
316
|
+
stashPushed: 'Changes stashed', stashPopped: 'Stash restored', stashChip: 'View stashes',
|
|
317
|
+
stashChipCount: 'View stash entries ({count})',
|
|
318
|
+
commentPlaceholder: 'Write a comment (Ctrl/⌘ + Enter to send)', commentSend: 'Comment', commentSending: 'Sending…',
|
|
319
|
+
commentEmpty: 'Comment is empty', commentDone: 'Comment posted',
|
|
320
|
+
closeIssue: 'Close issue', reopenIssue: 'Reopen', issueClosedOk: 'Issue closed', issueReopenedOk: 'Issue reopened',
|
|
321
|
+
issueStateOpen: 'Open', issueStateClosed: 'Closed',
|
|
322
|
+
branchInWorktree: 'held by {name}',
|
|
323
|
+
branchInWorktreeHint: 'This branch is already checked out in the "{name}" worktree; git allows it in only one worktree at a time',
|
|
324
|
+
switchBranchHere: 'Switch this worktree branch', worktreeBranches: 'Worktree branches',
|
|
325
|
+
switchedWorktree: 'Switched "{worktree}" to {branch}',
|
|
326
|
+
},
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Surface vocabulary for the workbench: one canvas, one elevated card layer, one inset "well"
|
|
331
|
+
* for anything you type into, plus a single filled primary action. Everything resolves through
|
|
332
|
+
* DSH theme tokens so light and dark stay honest; the literal fallbacks only cover a missing token.
|
|
333
|
+
*/
|
|
334
|
+
const T = {
|
|
335
|
+
text: 'var(--dsw-alias-label-primary, inherit)',
|
|
336
|
+
ink2: 'var(--dsw-alias-label-secondary, color-mix(in srgb, currentColor 68%, transparent))',
|
|
337
|
+
muted: 'var(--dsw-alias-label-tertiary, color-mix(in srgb, currentColor 54%, transparent))',
|
|
338
|
+
subtle: 'var(--dsw-alias-label-caption, color-mix(in srgb, currentColor 40%, transparent))',
|
|
339
|
+
inverse: 'var(--dsw-alias-label-primary-inverted, #fff)',
|
|
340
|
+
primary: 'var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary, #4d6bfe))',
|
|
341
|
+
primaryHover: 'var(--dsw-alias-button-primary-hover, var(--dsw-alias-brand-primary, #4d6bfe))',
|
|
342
|
+
primaryDim: 'var(--dsw-alias-button-primary-dimmed, color-mix(in srgb, currentColor 9%, transparent))',
|
|
343
|
+
primaryText: 'var(--dsw-alias-label-primary-inverted, #fff)',
|
|
344
|
+
accent: 'var(--dsw-alias-link, var(--dsw-alias-brand-primary, #4d6bfe))',
|
|
345
|
+
border: 'var(--dsw-alias-border-l2, color-mix(in srgb, currentColor 15%, transparent))',
|
|
346
|
+
borderSoft: 'var(--dsw-alias-border-l1, color-mix(in srgb, currentColor 9%, transparent))',
|
|
347
|
+
lineStrong: 'var(--dsw-alias-border-l4, color-mix(in srgb, currentColor 26%, transparent))',
|
|
348
|
+
hover: 'var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 7%, transparent))',
|
|
349
|
+
selected: 'var(--dsw-alias-interactive-bg-active, color-mix(in srgb, currentColor 11%, transparent))',
|
|
350
|
+
// Surfaces: canvas (page) → surface (card) → surfaceAlt (card header strip) → well (inputs).
|
|
351
|
+
canvas: 'var(--dsw-alias-bg-module-platform, #f5f6f7)',
|
|
352
|
+
surface: 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
353
|
+
surfaceAlt: 'var(--dsw-alias-card-fill, #fafafa)',
|
|
354
|
+
surfaceHover: 'var(--dsw-alias-card-fill-hover, #f5f5f5)',
|
|
355
|
+
well: 'var(--dsw-specific-selector, #f5f6f7)',
|
|
356
|
+
chip: 'var(--dsw-alias-bg-skeleton, rgba(0,0,0,.045))',
|
|
357
|
+
edge: 'var(--dsw-elevation-soft, 0 0 0 .5px rgba(0,0,0,.16), 0 4px 16px rgba(0,0,0,.03), 0 0 24px rgba(0,0,0,.03))',
|
|
358
|
+
edgeStrong: 'var(--dsw-elevation-panel, 0 0 0 .5px rgba(0,0,0,.16), 0 3px 8px rgba(0,0,0,.03), 0 0 16px rgba(0,0,0,.02))',
|
|
359
|
+
ring: 'var(--dsw-elevation-stroke, 0 0 0 .5px rgba(0,0,0,.16))',
|
|
360
|
+
card: 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
361
|
+
glass: 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
362
|
+
menu: 'var(--dsw-alias-bg-overlay, var(--dsw-alias-bg-layer-1, Canvas))',
|
|
363
|
+
layer: 'var(--dsw-specific-selector, color-mix(in srgb, currentColor 4%, transparent))',
|
|
364
|
+
layer2: 'var(--dsw-alias-bg-layer-2, color-mix(in srgb, currentColor 6%, transparent))',
|
|
365
|
+
success: 'var(--dsw-alias-state-success-primary, #22c55e)',
|
|
366
|
+
error: 'var(--dsw-alias-state-error-primary, #ec1313)',
|
|
367
|
+
warn: 'var(--dsw-alias-state-warn-label, #dd8629)',
|
|
368
|
+
brand: 'var(--dsw-alias-state-business-primary, #4176e6)',
|
|
369
|
+
mono: 'var(--dsw-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)',
|
|
370
|
+
sans: 'var(--dsw-font-family, inherit)',
|
|
371
|
+
serif: '"Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Iowan Old Style", Palatino, Georgia, serif',
|
|
372
|
+
shadowSoft: 'var(--dsw-elevation-soft, 0 1px 2px rgba(0,0,0,.06), 0 10px 30px rgba(0,0,0,.07))',
|
|
373
|
+
shadowProminent: 'var(--dsw-elevation-prominent, 0 18px 48px rgba(0,0,0,.22))',
|
|
374
|
+
ease: 'cubic-bezier(.2,.8,.2,1)',
|
|
375
|
+
rSm: 8, rMd: 12, rLg: 16, rXl: 20, pill: 999,
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** Wrapping a tinted fill around a semantic colour keeps status chips readable in both themes. */
|
|
379
|
+
function tint(color, strength = 12) {
|
|
380
|
+
return `color-mix(in srgb, ${color} ${strength}%, transparent)`
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const ADD_BG = 'color-mix(in srgb, var(--dsw-alias-state-success-primary, #22c55e) 12%, transparent)'
|
|
384
|
+
const DEL_BG = 'color-mix(in srgb, var(--dsw-alias-state-error-primary, #ec1313) 12%, transparent)'
|
|
385
|
+
const STATUS_COLOR = { M: T.warn, A: T.success, U: T.success, D: T.error, R: T.brand, C: T.error, '?': T.success }
|
|
386
|
+
/** A status letter as a tinted chip: readable at 10px without colouring the whole file name. */
|
|
387
|
+
function StatusChip({ status, size = 16 }) {
|
|
388
|
+
if (!status) return h('span', { style: { width: size, flex: `0 0 ${size}px` } })
|
|
389
|
+
const color = STATUS_COLOR[status] ?? T.muted
|
|
390
|
+
return h('span', {
|
|
391
|
+
style: {
|
|
392
|
+
width: size, height: size, flex: `0 0 ${size}px`, display: 'inline-flex', alignItems: 'center',
|
|
393
|
+
justifyContent: 'center', borderRadius: 5, fontSize: 9.5, fontWeight: 700, letterSpacing: 0,
|
|
394
|
+
color, background: tint(color, 14),
|
|
395
|
+
},
|
|
396
|
+
}, status)
|
|
397
|
+
}
|
|
398
|
+
const MONO = T.mono
|
|
399
|
+
|
|
400
|
+
function basename(path) {
|
|
401
|
+
if (typeof path !== 'string' || path.length === 0) return '—'
|
|
402
|
+
const parts = path.replace(/\/+$/, '').split('/')
|
|
403
|
+
return parts[parts.length - 1] || path
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function splitPath(path) {
|
|
407
|
+
const index = path.lastIndexOf('/')
|
|
408
|
+
return index < 0 ? { dir: '', name: path } : { dir: path.slice(0, index + 1), name: path.slice(index + 1) }
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function api(path, params) {
|
|
412
|
+
const url = new URL(`/git-assistant/api${path}`, window.location.origin)
|
|
413
|
+
for (const [key, value] of Object.entries(params ?? {})) {
|
|
414
|
+
if (value !== undefined && value !== null && value !== '') url.searchParams.set(key, String(value))
|
|
415
|
+
}
|
|
416
|
+
const response = await fetch(url, { headers: { accept: 'application/json' } })
|
|
417
|
+
const body = await response.json().catch(() => undefined)
|
|
418
|
+
if (!response.ok) throw apiError(body, response.status)
|
|
419
|
+
return body
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Preserve structured error fields so the UI can translate instead of echoing git's fatal text. */
|
|
423
|
+
function apiError(body, status) {
|
|
424
|
+
const error = new Error(body?.error ?? `HTTP ${status}`)
|
|
425
|
+
if (body?.code) error.code = body.code
|
|
426
|
+
if (body?.worktree) error.worktree = body.worktree
|
|
427
|
+
return error
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
async function apiPost(path, body) {
|
|
431
|
+
const response = await fetch(new URL(`/git-assistant/api${path}`, window.location.origin), {
|
|
432
|
+
method: 'POST',
|
|
433
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
434
|
+
body: JSON.stringify(body ?? {}),
|
|
435
|
+
})
|
|
436
|
+
const payload = await response.json().catch(() => undefined)
|
|
437
|
+
if (!response.ok) throw apiError(payload, response.status)
|
|
438
|
+
return payload
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const DRAG_TYPE = 'application/x-dsh-git-assistant-file'
|
|
442
|
+
let dragPayload = null
|
|
443
|
+
|
|
444
|
+
/** Locate DSH's composer card inside the conversation area for this Session. */
|
|
445
|
+
function composerCardFor(target, sessionId) {
|
|
446
|
+
if (!(target instanceof Element)) return null
|
|
447
|
+
const conversation = target.closest('[data-conversation-content]')
|
|
448
|
+
if (!conversation || conversation.dataset.conversationSession !== sessionId) return null
|
|
449
|
+
const card = conversation.querySelector('[data-composer-card]')
|
|
450
|
+
return card && card.querySelector('[data-composer-input][contenteditable="true"]') ? card : null
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function readStoredRepository() {
|
|
454
|
+
try { return window.localStorage.getItem(STORAGE_REPOSITORY) ?? '' } catch { return '' }
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/* ── syntax highlighting (lightweight, line based) ──────────────── */
|
|
458
|
+
|
|
459
|
+
const LANG_BY_EXT = {
|
|
460
|
+
js: 'js', mjs: 'js', cjs: 'js', jsx: 'js', ts: 'ts', tsx: 'ts', mts: 'ts', cts: 'ts',
|
|
461
|
+
json: 'json', py: 'py', rs: 'rs', go: 'go', sh: 'sh', bash: 'sh', zsh: 'sh', fish: 'sh',
|
|
462
|
+
css: 'css', scss: 'css', less: 'css', html: 'html', htm: 'html', xml: 'html', svg: 'html',
|
|
463
|
+
vue: 'html', svelte: 'html', md: 'md', markdown: 'md', yml: 'yaml', yaml: 'yaml',
|
|
464
|
+
toml: 'toml', sql: 'sql', java: 'java', kt: 'java', c: 'c', h: 'c', cpp: 'c', cc: 'c',
|
|
465
|
+
hpp: 'c', cs: 'js', rb: 'sh', php: 'js', lua: 'sh', ini: 'toml', conf: 'sh', env: 'sh',
|
|
466
|
+
txt: undefined, lock: undefined,
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const KEYWORDS = {
|
|
470
|
+
js: 'const let var function return if else for while do break continue class extends new this super import from export default async await try catch finally throw typeof instanceof in of delete void yield static get set null true false undefined NaN',
|
|
471
|
+
ts: 'const let var function return if else for while do break continue class extends new this super import from export default async await try catch finally throw typeof instanceof keyof infer as satisfies interface type enum namespace declare readonly public private protected abstract implements null true false undefined never unknown any string number boolean',
|
|
472
|
+
json: 'true false null',
|
|
473
|
+
py: 'def class return if elif else for while break continue import from as pass raise try except finally with lambda None True False and or not in is global nonlocal yield async await self',
|
|
474
|
+
rs: 'fn let mut const struct enum impl trait pub use mod match if else for while loop return break continue async await move where self Self Some None Ok Err true false',
|
|
475
|
+
go: 'func package import var const type struct interface map chan go defer if else for range return switch case default break continue select nil true false string int int64 float64 bool byte rune error',
|
|
476
|
+
sh: 'if then else elif fi for while do done case esac function return export local readonly source echo printf cd test set unset true false',
|
|
477
|
+
css: 'important media import supports keyframes from to and not only',
|
|
478
|
+
html: 'DOCTYPE html head body div span script style link meta title class id href src',
|
|
479
|
+
yaml: 'true false null yes no on off',
|
|
480
|
+
toml: 'true false',
|
|
481
|
+
sql: 'select from where insert into update delete create table drop alter index join left right inner outer on group by order limit offset values set and or not null true false',
|
|
482
|
+
java: 'public private protected class interface extends implements import package static final new return if else for while do break continue try catch finally throw throws void int long double float boolean char byte short String true false null this super abstract synchronized volatile transient native',
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const KEYWORD_SETS = new Map()
|
|
486
|
+
for (const [language, words] of Object.entries(KEYWORDS)) KEYWORD_SETS.set(language, new Set(words.split(' ')))
|
|
487
|
+
|
|
488
|
+
const COMMENT_PREFIX = { js: '//', ts: '//', json: null, py: '#', rs: '//', go: '//', sh: '#', css: null, html: null, yaml: '#', toml: '#', sql: '--', java: '//', c: '//' }
|
|
489
|
+
|
|
490
|
+
function escapeRegExp(text) { return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') }
|
|
491
|
+
|
|
492
|
+
function languageOf(path) {
|
|
493
|
+
const dot = path.lastIndexOf('.')
|
|
494
|
+
if (dot < 0) return undefined
|
|
495
|
+
return LANG_BY_EXT[path.slice(dot + 1).toLowerCase()]
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const tokenCache = new Map()
|
|
499
|
+
|
|
500
|
+
/** Tokenize one line into [{ text, kind }] where kind ∈ keyword|string|comment|number|plain. */
|
|
501
|
+
function tokenize(text, language) {
|
|
502
|
+
const keywords = KEYWORDS[language]
|
|
503
|
+
if (!keywords) return [{ text, kind: 'plain' }]
|
|
504
|
+
const cacheKey = `${language}\u0000${text}`
|
|
505
|
+
const cached = tokenCache.get(cacheKey)
|
|
506
|
+
if (cached) return cached
|
|
507
|
+
const comment = COMMENT_PREFIX[language]
|
|
508
|
+
let commentPart = ''
|
|
509
|
+
if (comment) commentPart = `${escapeRegExp(comment)}.*$|`
|
|
510
|
+
const pattern = new RegExp(
|
|
511
|
+
`(${commentPart}'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\`[^\`\\\\]*(?:\\\\.[^\`\\\\]*)*\`)` +
|
|
512
|
+
`|(\\b\\d[\\d_]*(?:\\.\\d+)?(?:[eE][+-]?\\d+)?\\b)|([A-Za-z_$][\\w$]*)`, 'g')
|
|
513
|
+
const tokens = []
|
|
514
|
+
let last = 0
|
|
515
|
+
let match
|
|
516
|
+
while ((match = pattern.exec(text)) !== null) {
|
|
517
|
+
if (match.index > last) tokens.push({ text: text.slice(last, match.index), kind: 'plain' })
|
|
518
|
+
if (match[1] !== undefined) tokens.push({ text: match[1], kind: comment && match[1].startsWith(comment) ? 'comment' : 'string' })
|
|
519
|
+
else if (match[2] !== undefined) tokens.push({ text: match[2], kind: 'number' })
|
|
520
|
+
else if (match[3] !== undefined) {
|
|
521
|
+
const word = match[3]
|
|
522
|
+
tokens.push({ text: word, kind: KEYWORD_SETS.get(language)?.has(word) ? 'keyword' : /^(true|false|null|nil|None|True|False)$/.test(word) ? 'literal' : 'plain' })
|
|
523
|
+
}
|
|
524
|
+
last = pattern.lastIndex
|
|
525
|
+
}
|
|
526
|
+
if (last < text.length) tokens.push({ text: text.slice(last), kind: 'plain' })
|
|
527
|
+
if (tokens.length === 0) tokens.push({ text, kind: 'plain' })
|
|
528
|
+
if (tokenCache.size > 20000) tokenCache.clear()
|
|
529
|
+
tokenCache.set(cacheKey, tokens)
|
|
530
|
+
return tokens
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/* Syntax colors follow GitHub Primer (github-dark / github-light); icon set follows Material Icon Theme (MIT). */
|
|
534
|
+
const GITHUB_SYNTAX = {
|
|
535
|
+
dark: { keyword: '#ff7b72', string: '#a5d6ff', number: '#79c0ff', literal: '#79c0ff', comment: '#8b949e' },
|
|
536
|
+
light: { keyword: '#cf222e', string: '#0a3069', number: '#0550ae', literal: '#0550ae', comment: '#6e7781' },
|
|
537
|
+
}
|
|
538
|
+
let codePalette = GITHUB_SYNTAX.dark
|
|
539
|
+
const paletteListeners = new Set()
|
|
540
|
+
function isDarkUi() {
|
|
541
|
+
try {
|
|
542
|
+
if (typeof document === 'undefined' || !document.body || typeof getComputedStyle !== 'function') throw new Error('no dom')
|
|
543
|
+
const background = getComputedStyle(document.body).backgroundColor
|
|
544
|
+
const match = background.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/)
|
|
545
|
+
if (match) {
|
|
546
|
+
const red = Number(match[1])
|
|
547
|
+
const green = Number(match[2])
|
|
548
|
+
const blue = Number(match[3])
|
|
549
|
+
if (red + green + blue > 0) return 0.2126 * red + 0.7152 * green + 0.0722 * blue < 128
|
|
550
|
+
}
|
|
551
|
+
} catch { /* fall through */ }
|
|
552
|
+
try { return window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ?? true } catch { return true }
|
|
553
|
+
}
|
|
554
|
+
function refreshCodePalette() {
|
|
555
|
+
const next = isDarkUi() ? GITHUB_SYNTAX.dark : GITHUB_SYNTAX.light
|
|
556
|
+
if (next === codePalette) return
|
|
557
|
+
codePalette = next
|
|
558
|
+
for (const listener of paletteListeners) listener()
|
|
559
|
+
}
|
|
560
|
+
if (typeof window !== 'undefined' && typeof MutationObserver !== 'undefined' && typeof document !== 'undefined') {
|
|
561
|
+
try {
|
|
562
|
+
const observer = new MutationObserver(() => refreshCodePalette())
|
|
563
|
+
for (const target of [document.documentElement, document.body]) {
|
|
564
|
+
if (target) observer.observe(target, { attributes: true, attributeFilter: ['class', 'data-theme', 'style'] })
|
|
565
|
+
}
|
|
566
|
+
} catch { /* ignore */ }
|
|
567
|
+
}
|
|
568
|
+
function useCodePalette() {
|
|
569
|
+
const [, force] = useState(0)
|
|
570
|
+
useEffect(() => {
|
|
571
|
+
const listener = () => force(value => value + 1)
|
|
572
|
+
paletteListeners.add(listener)
|
|
573
|
+
refreshCodePalette()
|
|
574
|
+
return () => paletteListeners.delete(listener)
|
|
575
|
+
}, [])
|
|
576
|
+
return codePalette
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function tokenStyle(kind, baseColor) {
|
|
580
|
+
if (kind === 'comment') return { color: codePalette.comment, opacity: 0.9 }
|
|
581
|
+
if (kind === 'string') return { color: codePalette.string }
|
|
582
|
+
if (kind === 'number') return { color: codePalette.number }
|
|
583
|
+
if (kind === 'literal') return { color: codePalette.literal }
|
|
584
|
+
if (kind === 'keyword') return { color: codePalette.keyword }
|
|
585
|
+
return { color: baseColor }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function CodeText({ text, language, baseColor, highlight }) {
|
|
589
|
+
if (!highlight || !language) return h('span', { style: { color: baseColor } }, text)
|
|
590
|
+
const tokens = tokenize(text, language)
|
|
591
|
+
if (tokens.length === 1) return h('span', { style: { color: baseColor } }, text)
|
|
592
|
+
return h('span', {}, tokens.map((token, index) => h('span', { key: index, style: tokenStyle(token.kind, baseColor) }, token.text)))
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/* ── diff row building ──────────────────────────────────────────── */
|
|
596
|
+
|
|
597
|
+
function hunkLabel(hunk) {
|
|
598
|
+
const match = /^(@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@)/.exec(hunk.header ?? '')
|
|
599
|
+
return match ? match[1] : (hunk.header ?? '')
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function hunkCounts(hunk) {
|
|
603
|
+
let oldCount = 0
|
|
604
|
+
let newCount = 0
|
|
605
|
+
for (const line of hunk.lines ?? []) {
|
|
606
|
+
if (line.kind === 'del') oldCount += 1
|
|
607
|
+
else if (line.kind === 'add') newCount += 1
|
|
608
|
+
else { oldCount += 1; newCount += 1 }
|
|
609
|
+
}
|
|
610
|
+
return { oldCount, newCount }
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function gapRowBetween(previous, next, index) {
|
|
614
|
+
if (!previous) return null
|
|
615
|
+
const counts = hunkCounts(previous)
|
|
616
|
+
const previousOldEnd = (previous.oldStart ?? 0) + counts.oldCount - 1
|
|
617
|
+
const previousNewEnd = (previous.newStart ?? 0) + counts.newCount - 1
|
|
618
|
+
const nextStart = next.newStart ?? 0
|
|
619
|
+
const count = nextStart - previousNewEnd - 1
|
|
620
|
+
if (count <= 0) return null
|
|
621
|
+
return { kind: 'gap', key: `g:${index}`, count, newStart: previousNewEnd + 1, delta: previousOldEnd - previousNewEnd }
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function unifiedRows(hunks, language, highlight) {
|
|
625
|
+
const rows = []
|
|
626
|
+
let budget = MAX_DIFF_LINES
|
|
627
|
+
hunks.forEach((hunk, hunkIndex) => {
|
|
628
|
+
if (budget <= 0) return
|
|
629
|
+
const gap = gapRowBetween(hunks[hunkIndex - 1], hunk, hunkIndex)
|
|
630
|
+
if (gap) rows.push(gap)
|
|
631
|
+
let oldNumber = hunk.oldStart
|
|
632
|
+
let newNumber = hunk.newStart
|
|
633
|
+
hunk.lines.forEach((line, lineIndex) => {
|
|
634
|
+
if (budget <= 0) return
|
|
635
|
+
budget -= 1
|
|
636
|
+
const isAdd = line.kind === 'add'
|
|
637
|
+
const isDel = line.kind === 'del'
|
|
638
|
+
rows.push({
|
|
639
|
+
kind: 'line', key: `l:${hunkIndex}:${lineIndex}`, hunkIndex,
|
|
640
|
+
oldNumber: isAdd ? '' : String(oldNumber++),
|
|
641
|
+
newNumber: isDel ? '' : String(newNumber++),
|
|
642
|
+
sign: isAdd ? '+' : isDel ? '−' : ' ',
|
|
643
|
+
kindOfLine: line.kind,
|
|
644
|
+
text: line.text,
|
|
645
|
+
language, highlight,
|
|
646
|
+
})
|
|
647
|
+
})
|
|
648
|
+
})
|
|
649
|
+
if (budget <= 0) rows.push({ kind: 'notice', key: 'budget' })
|
|
650
|
+
return rows
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function splitRows(hunks, language, highlight) {
|
|
654
|
+
const rows = []
|
|
655
|
+
let budget = MAX_DIFF_LINES
|
|
656
|
+
hunks.forEach((hunk, hunkIndex) => {
|
|
657
|
+
if (budget <= 0) return
|
|
658
|
+
const gap = gapRowBetween(hunks[hunkIndex - 1], hunk, hunkIndex)
|
|
659
|
+
if (gap) rows.push(gap)
|
|
660
|
+
let oldNumber = hunk.oldStart
|
|
661
|
+
let newNumber = hunk.newStart
|
|
662
|
+
let index = 0
|
|
663
|
+
const lines = hunk.lines
|
|
664
|
+
while (index < lines.length && budget > 0) {
|
|
665
|
+
const line = lines[index]
|
|
666
|
+
if (line.kind === 'ctx') {
|
|
667
|
+
budget -= 1
|
|
668
|
+
rows.push({ kind: 'pair', key: `p:${hunkIndex}:${index}`, hunkIndex, left: { number: String(oldNumber++), text: line.text, kind: 'ctx' }, right: { number: String(newNumber++), text: line.text, kind: 'ctx' }, language, highlight })
|
|
669
|
+
index += 1
|
|
670
|
+
continue
|
|
671
|
+
}
|
|
672
|
+
const dels = []
|
|
673
|
+
const adds = []
|
|
674
|
+
while (index < lines.length && lines[index].kind === 'del') { dels.push(lines[index]); index += 1 }
|
|
675
|
+
while (index < lines.length && lines[index].kind === 'add') { adds.push(lines[index]); index += 1 }
|
|
676
|
+
const count = Math.max(dels.length, adds.length)
|
|
677
|
+
for (let offset = 0; offset < count && budget > 0; offset += 1) {
|
|
678
|
+
budget -= 1
|
|
679
|
+
const left = dels[offset]
|
|
680
|
+
const right = adds[offset]
|
|
681
|
+
rows.push({
|
|
682
|
+
kind: 'pair', key: `p:${hunkIndex}:${index}:${offset}`, hunkIndex,
|
|
683
|
+
left: left ? { number: String(oldNumber++), text: left.text, kind: 'del' } : undefined,
|
|
684
|
+
right: right ? { number: String(newNumber++), text: right.text, kind: 'add' } : undefined,
|
|
685
|
+
language, highlight,
|
|
686
|
+
})
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
})
|
|
690
|
+
if (budget <= 0) rows.push({ kind: 'notice', key: 'budget' })
|
|
691
|
+
return rows
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/* ── data hooks ─────────────────────────────────────────────────── */
|
|
695
|
+
|
|
696
|
+
function useRepositories() {
|
|
697
|
+
const [state, setState] = useState({ phase: 'loading', items: [], error: null })
|
|
698
|
+
const [version, setVersion] = useState(0)
|
|
699
|
+
useEffect(() => {
|
|
700
|
+
let live = true
|
|
701
|
+
setState(previous => ({ ...previous, phase: previous.items.length > 0 ? 'ready' : 'loading' }))
|
|
702
|
+
api('/repositories')
|
|
703
|
+
.then(data => {
|
|
704
|
+
if (!live) return
|
|
705
|
+
setState({ phase: 'ready', items: Array.isArray(data?.repositories) ? data.repositories : [], error: null })
|
|
706
|
+
})
|
|
707
|
+
.catch(error => { if (live) setState({ phase: 'error', items: [], error: String(error?.message ?? error) }) })
|
|
708
|
+
return () => { live = false }
|
|
709
|
+
}, [version])
|
|
710
|
+
return [state, () => setVersion(value => value + 1)]
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function useStatus(repository, dataVersion) {
|
|
714
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
715
|
+
const path = repository?.path
|
|
716
|
+
useEffect(() => {
|
|
717
|
+
if (!path) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
718
|
+
return subscribeStatus(path, setState)
|
|
719
|
+
}, [path])
|
|
720
|
+
useEffect(() => {
|
|
721
|
+
if (path && dataVersion > 0) refreshStatusPath(path)
|
|
722
|
+
}, [path, dataVersion])
|
|
723
|
+
return [state, () => refreshStatusPath(path)]
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function useBranches(repository, dataVersion) {
|
|
727
|
+
const [state, setState] = useState({ phase: 'idle', items: [] })
|
|
728
|
+
const path = repository?.path
|
|
729
|
+
useEffect(() => {
|
|
730
|
+
if (!path) { setState({ phase: 'idle', items: [] }); return undefined }
|
|
731
|
+
let live = true
|
|
732
|
+
setState(previous => ({ ...previous, phase: 'loading' }))
|
|
733
|
+
api('/branches', { path })
|
|
734
|
+
.then(data => { if (live) setState({ phase: 'ready', items: Array.isArray(data?.branches) ? data.branches : [] }) })
|
|
735
|
+
.catch(() => { if (live) setState({ phase: 'error', items: [] }) })
|
|
736
|
+
return () => { live = false }
|
|
737
|
+
}, [path, dataVersion])
|
|
738
|
+
return state
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function useFiles(repository, dataVersion, enabled) {
|
|
742
|
+
const [state, setState] = useState({ phase: 'idle', files: [], total: 0, truncated: false })
|
|
743
|
+
const path = repository?.path
|
|
744
|
+
useEffect(() => {
|
|
745
|
+
if (!path) { setState({ phase: 'idle', files: [], total: 0, truncated: false }); return undefined }
|
|
746
|
+
if (!enabled) return undefined
|
|
747
|
+
let live = true
|
|
748
|
+
setState(previous => ({ ...previous, phase: previous.files.length > 0 ? 'refreshing' : 'loading' }))
|
|
749
|
+
api('/files', { path })
|
|
750
|
+
.then(data => {
|
|
751
|
+
if (!live) return
|
|
752
|
+
setState({ phase: 'ready', files: Array.isArray(data?.files) ? data.files : [], total: data?.total ?? 0, truncated: Boolean(data?.truncated) })
|
|
753
|
+
})
|
|
754
|
+
.catch(() => { if (live) setState({ phase: 'error', files: [], total: 0, truncated: false }) })
|
|
755
|
+
return () => { live = false }
|
|
756
|
+
}, [path, dataVersion, enabled])
|
|
757
|
+
return state
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function useDiff(repository, selection, dataVersion) {
|
|
761
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
762
|
+
const [version, setVersion] = useState(0)
|
|
763
|
+
const path = repository?.path
|
|
764
|
+
const active = selection?.kind === 'diff' || selection?.kind === 'commit-diff'
|
|
765
|
+
useEffect(() => {
|
|
766
|
+
if (!path || !active) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
767
|
+
let live = true
|
|
768
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
769
|
+
const request = selection?.kind === 'commit-diff'
|
|
770
|
+
? api('/commit-diff', { path, hash: selection.hash, file: selection.path })
|
|
771
|
+
: api('/diff', { path, file: selection.path, staged: selection.staged ? '1' : '0' })
|
|
772
|
+
request
|
|
773
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
774
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
775
|
+
return () => { live = false }
|
|
776
|
+
}, [path, active, selection?.path, selection?.staged, selection?.hash, version, dataVersion])
|
|
777
|
+
return [state, () => setVersion(value => value + 1)]
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function useFilePreview(repository, selection) {
|
|
781
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
782
|
+
const path = repository?.path
|
|
783
|
+
const active = selection?.kind === 'file'
|
|
784
|
+
useEffect(() => {
|
|
785
|
+
if (!path || !active) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
786
|
+
let live = true
|
|
787
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
788
|
+
api('/file', { path, file: selection.path })
|
|
789
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
790
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
791
|
+
return () => { live = false }
|
|
792
|
+
}, [path, active, selection?.path])
|
|
793
|
+
return state
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/** Fetch one diff per changed file for the "all changes" view (bounded). */
|
|
797
|
+
function useAllDiffs(repository, selection, statusData, dataVersion) {
|
|
798
|
+
const [state, setState] = useState({ phase: 'idle', entries: [], error: null })
|
|
799
|
+
const [version, setVersion] = useState(0)
|
|
800
|
+
const active = selection?.kind === 'all'
|
|
801
|
+
const scopes = active
|
|
802
|
+
? (selection.staged ? (statusData?.staged ?? []) : [...(statusData?.unstaged ?? []), ...(statusData?.untracked ?? [])])
|
|
803
|
+
: []
|
|
804
|
+
const signature = scopes.map(entry => entry.path).join('\n')
|
|
805
|
+
useEffect(() => {
|
|
806
|
+
if (!repository?.path || !active || scopes.length === 0) { setState({ phase: 'idle', entries: [], error: null }); return undefined }
|
|
807
|
+
let live = true
|
|
808
|
+
setState({ phase: 'loading', entries: [], error: null })
|
|
809
|
+
const limited = scopes.slice(0, 30).map(entry => entry.path)
|
|
810
|
+
Promise.all(limited.map(file => api('/diff', { path: repository.path, file, staged: selection.staged ? '1' : '0' })
|
|
811
|
+
.then(data => ({ file, entry: data?.files?.[0] }))
|
|
812
|
+
.catch(error => ({ file, error: String(error?.message ?? error) }))))
|
|
813
|
+
.then(entries => { if (live) setState({ phase: 'ready', entries, error: null }) })
|
|
814
|
+
.catch(error => { if (live) setState({ phase: 'error', entries: [], error: String(error?.message ?? error) }) })
|
|
815
|
+
return () => { live = false }
|
|
816
|
+
}, [repository?.path, active, selection?.staged, signature, version, dataVersion])
|
|
817
|
+
return [state, () => setVersion(value => value + 1)]
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function useWorktrees(repository, dataVersion) {
|
|
821
|
+
const [state, setState] = useState({ phase: 'idle', items: [] })
|
|
822
|
+
const [version, setVersion] = useState(0)
|
|
823
|
+
const path = repository?.path
|
|
824
|
+
const previousPathRef = useRef(path)
|
|
825
|
+
useEffect(() => {
|
|
826
|
+
if (!path) { previousPathRef.current = path; setState({ phase: 'idle', items: [] }); return undefined }
|
|
827
|
+
let live = true
|
|
828
|
+
if (previousPathRef.current !== path) {
|
|
829
|
+
previousPathRef.current = path
|
|
830
|
+
setState({ phase: 'loading', items: [] })
|
|
831
|
+
} else {
|
|
832
|
+
setState(previous => ({ ...previous, phase: 'loading' }))
|
|
833
|
+
}
|
|
834
|
+
api('/worktrees', { path })
|
|
835
|
+
.then(data => { if (live) setState({ phase: 'ready', items: Array.isArray(data?.worktrees) ? data.worktrees : [] }) })
|
|
836
|
+
.catch(() => { if (live) setState({ phase: 'error', items: [] }) })
|
|
837
|
+
return () => { live = false }
|
|
838
|
+
}, [path, version, dataVersion])
|
|
839
|
+
return [state, () => setVersion(value => value + 1)]
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function useStatusAt(path, enabled) {
|
|
843
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
844
|
+
useEffect(() => {
|
|
845
|
+
if (!path || !enabled) return undefined
|
|
846
|
+
return subscribeStatus(path, setState)
|
|
847
|
+
}, [path, enabled])
|
|
848
|
+
return [state, () => refreshStatusPath(path)]
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/** One worktree is one complete operable area: header, commit box, staged/changed lists. */
|
|
852
|
+
function copyToClipboard(text) {
|
|
853
|
+
try {
|
|
854
|
+
if (typeof navigator === 'undefined' || !navigator.clipboard || typeof navigator.clipboard.writeText !== 'function') {
|
|
855
|
+
return Promise.reject(new Error('clipboard unavailable'))
|
|
856
|
+
}
|
|
857
|
+
return navigator.clipboard.writeText(text)
|
|
858
|
+
} catch (error) {
|
|
859
|
+
return Promise.reject(error)
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** Small fixed-position menu anchored at viewport coordinates; escapes card overflow clipping. */
|
|
864
|
+
function FloatingMenu({ at, width = 250, onClose, children }) {
|
|
865
|
+
const ref = useRef(null)
|
|
866
|
+
useEffect(() => {
|
|
867
|
+
const close = event => { if (ref.current && !ref.current.contains(event.target)) onClose?.() }
|
|
868
|
+
const timer = setTimeout(() => document.addEventListener('pointerdown', close, true))
|
|
869
|
+
return () => { clearTimeout(timer); document.removeEventListener('pointerdown', close, true) }
|
|
870
|
+
}, [])
|
|
871
|
+
const left = Math.max(8, Math.min(at.x, (window.innerWidth || 1280) - width - 8))
|
|
872
|
+
const top = Math.min(at.y, Math.max(8, (window.innerHeight || 800) - 260))
|
|
873
|
+
return h('div', {
|
|
874
|
+
ref,
|
|
875
|
+
style: {
|
|
876
|
+
position: 'fixed', left, top, zIndex: 120, width, padding: 5, maxHeight: 320, overflowY: 'auto',
|
|
877
|
+
background: T.menu, border: `0.5px solid ${T.border}`, borderRadius: T.rMd,
|
|
878
|
+
boxShadow: T.shadowProminent, backdropFilter: 'blur(24px) saturate(170%)',
|
|
879
|
+
},
|
|
880
|
+
}, children)
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function MenuItem({ icon, label, onClick, danger }) {
|
|
884
|
+
return h('button', {
|
|
885
|
+
type: 'button', onClick,
|
|
886
|
+
style: {
|
|
887
|
+
appearance: 'none', border: 'none', background: 'transparent', color: danger ? T.error : T.ink2,
|
|
888
|
+
cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 8, width: '100%', textAlign: 'left',
|
|
889
|
+
padding: '6px 9px', borderRadius: T.rSm, font: 'inherit', fontSize: 12,
|
|
890
|
+
},
|
|
891
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover; event.currentTarget.style.color = danger ? T.error : T.text },
|
|
892
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent'; event.currentTarget.style.color = danger ? T.error : T.ink2 },
|
|
893
|
+
}, icon ? h('span', { style: { display: 'inline-flex', opacity: 0.7, flex: '0 0 auto' } }, icon) : null, label)
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** One worktree is one complete operable area: header, commit box, stash, staged/changed lists. */
|
|
897
|
+
function WorktreeCard({ t, item, defaultOpen, onOpen, onNotify, selectedPath, onChanged, onSelect, onDiscardAll, onFileHistory, onDialog, visible = true }) {
|
|
898
|
+
const [open, setOpen] = useState(defaultOpen)
|
|
899
|
+
const [status, refreshStatus] = useStatusAt(item.path, open && visible)
|
|
900
|
+
const [busy, setBusy] = useState(false)
|
|
901
|
+
const [pendingStage, setPendingStage] = useState(() => new Map())
|
|
902
|
+
const [expandedDirs, setExpandedDirs] = useState(() => new Set())
|
|
903
|
+
const [collapsedSections, setCollapsedSections] = useState(() => new Set())
|
|
904
|
+
const [hoveredKey, setHoveredKey] = useState(undefined)
|
|
905
|
+
const [stashes, setStashes] = useState({ phase: 'idle', items: [] })
|
|
906
|
+
const [stashMenu, setStashMenu] = useState(null)
|
|
907
|
+
const [branchMenu, setBranchMenu] = useState(null)
|
|
908
|
+
const [rowMenu, setRowMenu] = useState(null)
|
|
909
|
+
const messageRef = useRef(null)
|
|
910
|
+
const data = status.data
|
|
911
|
+
const behind = status.data?.behind ?? item.behind ?? 0
|
|
912
|
+
const needsSync = behind > 0
|
|
913
|
+
const displayName = item.name ?? item.path.replace(/\/+$/, '').split('/').pop()
|
|
914
|
+
const branchLabel = item.branch ?? t('detached')
|
|
915
|
+
let stagedFiles = data?.staged ?? []
|
|
916
|
+
let changeFiles = [...(data?.unstaged ?? []), ...(data?.untracked ?? [])]
|
|
917
|
+
if (pendingStage.size > 0) {
|
|
918
|
+
const stagedMap = new Map(stagedFiles.map(file => [file.path, file]))
|
|
919
|
+
const changeMap = new Map(changeFiles.map(file => [file.path, file]))
|
|
920
|
+
for (const [path, operation] of pendingStage) {
|
|
921
|
+
if (operation === 'stage') {
|
|
922
|
+
const file = changeMap.get(path)
|
|
923
|
+
if (file) { changeMap.delete(path); stagedMap.set(path, file) }
|
|
924
|
+
} else {
|
|
925
|
+
const file = stagedMap.get(path)
|
|
926
|
+
if (file) { stagedMap.delete(path); changeMap.set(path, file) }
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
stagedFiles = [...stagedMap.values()]
|
|
930
|
+
changeFiles = [...changeMap.values()]
|
|
931
|
+
}
|
|
932
|
+
const stagedTree = useMemo(() => fileRows(stagedFiles.map(file => ({ ...file, __staged: true }))), [data, pendingStage])
|
|
933
|
+
const changeTree = useMemo(() => fileRows(changeFiles), [data, pendingStage])
|
|
934
|
+
const dirty = stagedFiles.length + changeFiles.length > 0
|
|
935
|
+
const stagedStatus = useMemo(() => new Map(stagedFiles.map(file => [file.path, file.status])), [data, pendingStage])
|
|
936
|
+
const changeStatus = useMemo(() => new Map(changeFiles.map(file => [file.path, file.status])), [data, pendingStage])
|
|
937
|
+
const loadStashes = useCallback(() => {
|
|
938
|
+
let live = true
|
|
939
|
+
api('/stashes', { path: item.path })
|
|
940
|
+
.then(result => { if (live) setStashes({ phase: 'ready', items: Array.isArray(result?.stashes) ? result.stashes : [] }) })
|
|
941
|
+
.catch(error => { if (live) setStashes({ phase: 'error', items: [], error: String(error?.message ?? error) }) })
|
|
942
|
+
return () => { live = false }
|
|
943
|
+
}, [item.path])
|
|
944
|
+
useEffect(() => { if (open && visible) return loadStashes(); return undefined }, [open, visible, loadStashes])
|
|
945
|
+
const toggleSection = name => setCollapsedSections(previous => {
|
|
946
|
+
const next = new Set(previous)
|
|
947
|
+
if (next.has(name)) next.delete(name)
|
|
948
|
+
else next.add(name)
|
|
949
|
+
return next
|
|
950
|
+
})
|
|
951
|
+
const toggleDir = path => setExpandedDirs(previous => {
|
|
952
|
+
const next = new Set(previous)
|
|
953
|
+
if (next.has(path)) next.delete(path)
|
|
954
|
+
else next.add(path)
|
|
955
|
+
return next
|
|
956
|
+
})
|
|
957
|
+
const errorText = error => error?.code === 'branch-in-worktree'
|
|
958
|
+
? t('branchInWorktreeHint', { name: basename(error.worktree ?? '') })
|
|
959
|
+
: String(error?.message ?? error)
|
|
960
|
+
const runAction = async (work) => {
|
|
961
|
+
setBusy(true)
|
|
962
|
+
try { await work() } catch (error) { onNotify?.(errorText(error), 'error') }
|
|
963
|
+
finally { setBusy(false); refreshStatus() }
|
|
964
|
+
}
|
|
965
|
+
const optimisticStage = (files, staged) => {
|
|
966
|
+
const paths = files.map(file => file.path).filter(Boolean)
|
|
967
|
+
if (paths.length === 0) return
|
|
968
|
+
const operation = staged ? 'unstage' : 'stage'
|
|
969
|
+
setPendingStage(previous => {
|
|
970
|
+
const next = new Map(previous)
|
|
971
|
+
for (const path of paths) next.set(path, operation)
|
|
972
|
+
return next
|
|
973
|
+
})
|
|
974
|
+
setBusy(true)
|
|
975
|
+
apiPost(staged ? '/unstage' : '/stage', { path: item.path, files: paths })
|
|
976
|
+
.then(() => refreshStatus())
|
|
977
|
+
.then(() => new Promise(resolve => setTimeout(resolve, 120)))
|
|
978
|
+
.catch(error => onNotify?.(String(error?.message ?? error), 'error'))
|
|
979
|
+
.finally(() => {
|
|
980
|
+
setBusy(false)
|
|
981
|
+
setPendingStage(previous => {
|
|
982
|
+
const next = new Map(previous)
|
|
983
|
+
for (const path of paths) next.delete(path)
|
|
984
|
+
return next
|
|
985
|
+
})
|
|
986
|
+
})
|
|
987
|
+
}
|
|
988
|
+
const sync = () => runAction(async () => {
|
|
989
|
+
await apiPost('/sync', { path: item.path })
|
|
990
|
+
onChanged?.()
|
|
991
|
+
onNotify?.(t('syncChanges'))
|
|
992
|
+
})
|
|
993
|
+
const commit = () => {
|
|
994
|
+
const message = messageRef.current?.value ?? ''
|
|
995
|
+
if (!message.trim()) { onNotify?.(t('commitEmpty'), 'error'); return }
|
|
996
|
+
runAction(async () => {
|
|
997
|
+
await apiPost('/commit', { path: item.path, message, action: 'commit' })
|
|
998
|
+
if (messageRef.current) messageRef.current.value = ''
|
|
999
|
+
onNotify?.(t('committed'))
|
|
1000
|
+
})
|
|
1001
|
+
}
|
|
1002
|
+
const openBranchMenu = async event => {
|
|
1003
|
+
event.stopPropagation()
|
|
1004
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1005
|
+
const at = { x: rect.left, y: rect.bottom + 4 }
|
|
1006
|
+
setBranchMenu({ ...at, phase: 'loading', items: [] })
|
|
1007
|
+
try {
|
|
1008
|
+
const data = await api('/branches', { path: item.path })
|
|
1009
|
+
setBranchMenu({ ...at, phase: 'ready', items: Array.isArray(data?.branches) ? data.branches : [] })
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
setBranchMenu({ ...at, phase: 'error', error: String(error?.message ?? error), items: [] })
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
const requestSwitchHere = branchName => {
|
|
1015
|
+
setBranchMenu(null)
|
|
1016
|
+
if (branchName === branchLabel) return
|
|
1017
|
+
const go = () => runAction(async () => {
|
|
1018
|
+
await apiPost('/switch', { path: item.path, branch: branchName })
|
|
1019
|
+
onChanged?.()
|
|
1020
|
+
onNotify?.(t('switchedWorktree', { worktree: displayName, branch: branchName }))
|
|
1021
|
+
})
|
|
1022
|
+
if (dirty) {
|
|
1023
|
+
onDialog?.({
|
|
1024
|
+
title: t('switchConfirmTitle'),
|
|
1025
|
+
message: t('switchConfirm', { branch: branchName }),
|
|
1026
|
+
confirmLabel: t('confirm'), cancelLabel: t('cancel'), danger: false,
|
|
1027
|
+
onConfirm: go,
|
|
1028
|
+
})
|
|
1029
|
+
} else go()
|
|
1030
|
+
}
|
|
1031
|
+
const branchMenuElement = branchMenu
|
|
1032
|
+
? h(FloatingMenu, { key: 'branch-menu', at: branchMenu, width: 300, onClose: () => setBranchMenu(null) },
|
|
1033
|
+
h('div', { style: { padding: '6px 9px 3px', fontSize: 10.5, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', color: T.muted } }, t('worktreeBranches')),
|
|
1034
|
+
branchMenu.phase === 'loading'
|
|
1035
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11.5, color: T.muted } }, t('loading'))
|
|
1036
|
+
: branchMenu.phase === 'error'
|
|
1037
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11.5, color: T.error } }, branchMenu.error)
|
|
1038
|
+
: branchMenu.items.map(branch => {
|
|
1039
|
+
const blocked = Boolean(branch.worktree)
|
|
1040
|
+
return h('button', {
|
|
1041
|
+
key: branch.name, type: 'button',
|
|
1042
|
+
onClick: () => {
|
|
1043
|
+
if (blocked) {
|
|
1044
|
+
setBranchMenu(null)
|
|
1045
|
+
onNotify?.(t('branchInWorktreeHint', { name: branch.worktreeName ?? basename(branch.worktree) }), 'info')
|
|
1046
|
+
return
|
|
1047
|
+
}
|
|
1048
|
+
requestSwitchHere(branch.name)
|
|
1049
|
+
},
|
|
1050
|
+
title: blocked ? t('branchInWorktreeHint', { name: branch.worktreeName ?? basename(branch.worktree) }) : branch.name,
|
|
1051
|
+
style: {
|
|
1052
|
+
appearance: 'none', border: 'none', background: branch.current ? T.selected : 'transparent',
|
|
1053
|
+
color: 'inherit', font: 'inherit', cursor: blocked ? 'default' : 'pointer',
|
|
1054
|
+
display: 'flex', alignItems: 'center', gap: 7, width: '100%', textAlign: 'left',
|
|
1055
|
+
padding: '6px 9px', borderRadius: T.rSm, opacity: blocked ? 0.8 : 1,
|
|
1056
|
+
},
|
|
1057
|
+
onMouseEnter: event => { if (!branch.current) event.currentTarget.style.background = blocked ? T.chip : T.hover },
|
|
1058
|
+
onMouseLeave: event => { if (!branch.current) event.currentTarget.style.background = 'transparent' },
|
|
1059
|
+
},
|
|
1060
|
+
h('span', { style: { width: 12, fontSize: 11, opacity: branch.current ? 0.85 : 0.25 } }, '✓'),
|
|
1061
|
+
h('span', { style: { fontFamily: MONO, fontSize: 11.5, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, branch.name),
|
|
1062
|
+
h('span', { style: { flex: 1 } }),
|
|
1063
|
+
blocked
|
|
1064
|
+
? h('span', {
|
|
1065
|
+
style: { fontSize: 9.5, whiteSpace: 'nowrap', color: T.muted, background: T.chip, borderRadius: T.pill, padding: '1px 7px', maxWidth: 150, overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
1066
|
+
}, t('branchInWorktree', { name: branch.worktreeName ?? basename(branch.worktree) }))
|
|
1067
|
+
: null)
|
|
1068
|
+
}))
|
|
1069
|
+
: null
|
|
1070
|
+
const stashPushChanges = () => runAction(async () => {
|
|
1071
|
+
await apiPost('/stash-push', { path: item.path })
|
|
1072
|
+
loadStashes()
|
|
1073
|
+
onChanged?.()
|
|
1074
|
+
onNotify?.(t('stashPushed'))
|
|
1075
|
+
})
|
|
1076
|
+
const stashPopAt = index => runAction(async () => {
|
|
1077
|
+
const result = await apiPost('/stash-pop', { path: item.path, index })
|
|
1078
|
+
setStashes({ phase: 'ready', items: Array.isArray(result?.stashes) ? result.stashes : [] })
|
|
1079
|
+
setStashMenu(null)
|
|
1080
|
+
onChanged?.()
|
|
1081
|
+
onNotify?.(t('stashPopped'))
|
|
1082
|
+
})
|
|
1083
|
+
const copyPathOf = file => {
|
|
1084
|
+
copyToClipboard(file.path)
|
|
1085
|
+
.then(() => onNotify?.(t('copiedPath')))
|
|
1086
|
+
.catch(() => onNotify?.(t('actionFailed'), 'error'))
|
|
1087
|
+
}
|
|
1088
|
+
const fileCommand = (route, file) => apiPost(route, { path: item.path, file: file.path })
|
|
1089
|
+
.catch(error => onNotify?.(String(error?.message ?? error), 'error'))
|
|
1090
|
+
const openRowMenu = (file, staged, event) => {
|
|
1091
|
+
event.stopPropagation()
|
|
1092
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1093
|
+
setRowMenu({ x: rect.left, y: rect.bottom + 4, file, staged })
|
|
1094
|
+
}
|
|
1095
|
+
const rowMenuItems = rowMenu ? [
|
|
1096
|
+
h(MenuItem, { key: 'copy', icon: h(IconCopy), label: t('copyPath'), onClick: () => { copyPathOf(rowMenu.file); setRowMenu(null) } }),
|
|
1097
|
+
h(MenuItem, { key: 'reveal', icon: h(IconFolder), label: t('revealInFinder'), onClick: () => { fileCommand('/reveal', rowMenu.file); setRowMenu(null) } }),
|
|
1098
|
+
h(MenuItem, { key: 'open', icon: h(IconExternal), label: t('openDefaultApp'), onClick: () => { fileCommand('/open', rowMenu.file); setRowMenu(null) } }),
|
|
1099
|
+
h(MenuItem, { key: 'history', icon: h(IconHistory), label: t('fileHistory'), onClick: () => { onFileHistory?.(rowMenu.file, item.path); setRowMenu(null) } }),
|
|
1100
|
+
] : null
|
|
1101
|
+
const rowMenuElement = rowMenu
|
|
1102
|
+
? h(FloatingMenu, { key: 'row-menu', at: rowMenu, width: 230, onClose: () => setRowMenu(null) }, rowMenuItems)
|
|
1103
|
+
: null
|
|
1104
|
+
const stashMenuElement = stashMenu
|
|
1105
|
+
? h(FloatingMenu, { key: 'stash-menu', at: stashMenu, width: 320, onClose: () => setStashMenu(null) },
|
|
1106
|
+
h('div', { style: { padding: '6px 9px 3px', fontSize: 10.5, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', color: T.muted } }, t('stashList')),
|
|
1107
|
+
stashes.phase === 'loading'
|
|
1108
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11.5, color: T.muted } }, t('loading'))
|
|
1109
|
+
: stashes.phase === 'error'
|
|
1110
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11.5, color: T.error } }, stashes.error)
|
|
1111
|
+
: stashes.items.length === 0
|
|
1112
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11.5, color: T.subtle } }, t('stashEmpty'))
|
|
1113
|
+
: stashes.items.map(entry => h('div', {
|
|
1114
|
+
key: entry.selector,
|
|
1115
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, padding: '5px 6px', borderRadius: T.rSm },
|
|
1116
|
+
},
|
|
1117
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.subtle, flex: '0 0 auto' } }, `@{${entry.index}}`),
|
|
1118
|
+
h('span', { style: { flex: 1, minWidth: 0, fontSize: 11.5, color: T.ink2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }, title: entry.subject }, entry.subject || '—'),
|
|
1119
|
+
entry.time ? h('span', { style: { fontSize: 10, color: T.subtle, flex: '0 0 auto' } }, formatRelativeTime(entry.time)) : null,
|
|
1120
|
+
h(IconAction, { label: t('stashPop'), disabled: busy, onClick: () => stashPopAt(entry.index) }, h(IconUndo)))))
|
|
1121
|
+
: null
|
|
1122
|
+
const sectionHeader = (label, count, expanded, onToggle, actions) => h('div', {
|
|
1123
|
+
onClick: onToggle,
|
|
1124
|
+
style: {
|
|
1125
|
+
display: 'flex', alignItems: 'center', gap: 6, minHeight: 26, marginTop: 2, padding: '0 2px',
|
|
1126
|
+
cursor: 'pointer', userSelect: 'none',
|
|
1127
|
+
},
|
|
1128
|
+
},
|
|
1129
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 4, color: T.ink2 } },
|
|
1130
|
+
h(Chevron, { open: expanded, size: 8 }),
|
|
1131
|
+
h('span', { style: { fontSize: 10.5, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase' } }, label)),
|
|
1132
|
+
h('span', {
|
|
1133
|
+
style: {
|
|
1134
|
+
fontFamily: MONO, fontSize: 9.5, fontWeight: 600, color: T.muted,
|
|
1135
|
+
background: T.chip, borderRadius: T.pill, padding: '0 6px', lineHeight: '15px',
|
|
1136
|
+
},
|
|
1137
|
+
}, String(count)),
|
|
1138
|
+
h('span', { style: { flex: 1 } }),
|
|
1139
|
+
h('span', { onClick: event => event.stopPropagation(), style: { display: 'inline-flex', alignItems: 'center', gap: 1 } }, actions))
|
|
1140
|
+
const composer = dirty || needsSync ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
1141
|
+
h('textarea', {
|
|
1142
|
+
ref: messageRef, rows: 2, placeholder: `${t('commitPlaceholder')} · ${branchLabel}`,
|
|
1143
|
+
onFocus: event => { event.currentTarget.style.borderColor = T.accent; event.currentTarget.style.boxShadow = `0 0 0 3px ${tint(T.accent, 18)}` },
|
|
1144
|
+
onBlur: event => { event.currentTarget.style.borderColor = T.borderSoft; event.currentTarget.style.boxShadow = 'none' },
|
|
1145
|
+
onKeyDown: event => { if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) { event.preventDefault(); commit() } },
|
|
1146
|
+
style: {
|
|
1147
|
+
width: '100%', boxSizing: 'border-box', resize: 'vertical', background: T.well, color: 'inherit',
|
|
1148
|
+
border: `1px solid ${T.borderSoft}`, borderRadius: 9, padding: '7px 9px', fontSize: 12.5,
|
|
1149
|
+
fontFamily: 'inherit', outline: 'none', lineHeight: '18px', minHeight: 54,
|
|
1150
|
+
transition: `border-color .15s ${T.ease}, box-shadow .15s ${T.ease}`,
|
|
1151
|
+
},
|
|
1152
|
+
}),
|
|
1153
|
+
h('button', {
|
|
1154
|
+
type: 'button', onClick: needsSync ? sync : commit, disabled: busy || (!needsSync && !dirty),
|
|
1155
|
+
/* Sync is just as much a primary action as commit while the branch is behind: same filled
|
|
1156
|
+
treatment, different verb, so the eye always finds one solid button per card. */
|
|
1157
|
+
onMouseEnter: event => { if (!event.currentTarget.disabled) event.currentTarget.style.background = T.primaryHover },
|
|
1158
|
+
onMouseLeave: event => { event.currentTarget.style.background = T.primary },
|
|
1159
|
+
style: {
|
|
1160
|
+
appearance: 'none', border: '1px solid transparent',
|
|
1161
|
+
borderRadius: 9, height: 30, width: '100%', fontSize: 12, fontWeight: 600,
|
|
1162
|
+
font: 'inherit',
|
|
1163
|
+
background: T.primary,
|
|
1164
|
+
color: T.primaryText,
|
|
1165
|
+
boxShadow: '0 1px 2px rgba(0,0,0,.14)',
|
|
1166
|
+
cursor: busy ? 'default' : 'pointer', opacity: busy ? 0.55 : 1,
|
|
1167
|
+
transition: `background .15s ${T.ease}, opacity .15s ${T.ease}`,
|
|
1168
|
+
},
|
|
1169
|
+
}, busy ? (needsSync ? t('syncing') : t('committing')) : needsSync ? `⟳ ${t('syncChanges')} ${behind}↓` : `✓ ${t('commit')}`))
|
|
1170
|
+
: null
|
|
1171
|
+
const cleanState = !dirty && !needsSync && status.phase === 'ready' ? h('div', {
|
|
1172
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, padding: '6px 2px 2px' },
|
|
1173
|
+
},
|
|
1174
|
+
h('span', {
|
|
1175
|
+
style: {
|
|
1176
|
+
width: 18, height: 18, flex: '0 0 18px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
1177
|
+
borderRadius: '50%', background: tint(T.success, 14), color: T.success,
|
|
1178
|
+
},
|
|
1179
|
+
}, h('svg', { width: 11, height: 11, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 3, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M5 13l4 4L19 7' }))),
|
|
1180
|
+
h('span', { style: { fontSize: 12, color: T.ink2 } }, t('cleanTree')))
|
|
1181
|
+
: null
|
|
1182
|
+
const syncWhenClean = !dirty && needsSync ? h('button', {
|
|
1183
|
+
type: 'button', onClick: sync, disabled: busy,
|
|
1184
|
+
onMouseEnter: event => { if (!event.currentTarget.disabled) event.currentTarget.style.background = T.primaryHover },
|
|
1185
|
+
onMouseLeave: event => { event.currentTarget.style.background = T.primary },
|
|
1186
|
+
style: {
|
|
1187
|
+
appearance: 'none', border: '1px solid transparent', borderRadius: 8, height: 28, padding: '0 12px',
|
|
1188
|
+
fontSize: 11.5, fontWeight: 600, font: 'inherit', background: T.primary, color: T.primaryText,
|
|
1189
|
+
cursor: busy ? 'default' : 'pointer', opacity: busy ? 0.55 : 1, whiteSpace: 'nowrap',
|
|
1190
|
+
},
|
|
1191
|
+
}, busy ? t('syncing') : `⟳ ${t('syncChanges')} ${behind}↓`) : null
|
|
1192
|
+
return [h('div', {
|
|
1193
|
+
key: 'card',
|
|
1194
|
+
'data-worktree-path': item.path,
|
|
1195
|
+
style: {
|
|
1196
|
+
marginBottom: 8, borderRadius: T.rMd, background: T.surface, boxShadow: T.edge, overflow: 'hidden',
|
|
1197
|
+
},
|
|
1198
|
+
},
|
|
1199
|
+
h('div', {
|
|
1200
|
+
onClick: () => { setOpen(value => !value); onSelect?.(item.path) },
|
|
1201
|
+
style: {
|
|
1202
|
+
display: 'flex', alignItems: 'center', gap: 7, minHeight: 36, padding: '0 12px', cursor: 'pointer',
|
|
1203
|
+
background: open ? T.surfaceAlt : T.surface,
|
|
1204
|
+
borderBottom: open ? `1px solid ${T.borderSoft}` : 'none',
|
|
1205
|
+
transition: `background .15s ${T.ease}`,
|
|
1206
|
+
},
|
|
1207
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.surfaceAlt },
|
|
1208
|
+
onMouseLeave: event => { event.currentTarget.style.background = open ? T.surfaceAlt : T.surface },
|
|
1209
|
+
},
|
|
1210
|
+
h(Chevron, { open, size: 9 }),
|
|
1211
|
+
h('span', { title: item.path, style: { fontSize: 12.5, fontWeight: 600, color: T.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 72, flex: '0 1 auto' } }, displayName),
|
|
1212
|
+
branchLabel !== displayName ? h('span', {
|
|
1213
|
+
title: branchLabel,
|
|
1214
|
+
style: {
|
|
1215
|
+
fontFamily: MONO, fontSize: 10.5, color: T.ink2, background: T.chip, borderRadius: 5,
|
|
1216
|
+
padding: '1px 6px', whiteSpace: 'nowrap', maxWidth: 104, flex: '0 2 auto', overflow: 'hidden', textOverflow: 'ellipsis',
|
|
1217
|
+
},
|
|
1218
|
+
}, branchLabel) : null,
|
|
1219
|
+
item.isMain ? h('span', {
|
|
1220
|
+
style: {
|
|
1221
|
+
fontSize: 9.5, fontWeight: 500, color: T.muted, border: `1px solid ${T.border}`, borderRadius: T.pill,
|
|
1222
|
+
padding: '0 7px', lineHeight: '15px', whiteSpace: 'nowrap', flex: '0 0 auto',
|
|
1223
|
+
},
|
|
1224
|
+
}, t('mainWorktree')) : null,
|
|
1225
|
+
h('span', { style: { flex: 1 } }),
|
|
1226
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.muted, whiteSpace: 'nowrap' } }, `${item.behind > 0 ? `↓${item.behind}` : ''}${item.ahead > 0 ? ` ↑${item.ahead}` : ''}`),
|
|
1227
|
+
h(IconAction, { label: t('switchBranchHere'), onClick: openBranchMenu }, h(IconBranch)),
|
|
1228
|
+
stashes.items.length > 0 ? h('button', {
|
|
1229
|
+
type: 'button',
|
|
1230
|
+
'aria-label': t('stashChipCount', { count: stashes.items.length }),
|
|
1231
|
+
onClick: event => {
|
|
1232
|
+
event.stopPropagation()
|
|
1233
|
+
const rect = event.currentTarget.getBoundingClientRect()
|
|
1234
|
+
setStashMenu({ x: rect.left, y: rect.bottom + 4 })
|
|
1235
|
+
},
|
|
1236
|
+
onMouseEnter: event => {
|
|
1237
|
+
event.currentTarget.style.background = T.surfaceHover
|
|
1238
|
+
event.currentTarget.style.borderColor = T.border
|
|
1239
|
+
showTooltip(t('stashChipCount', { count: stashes.items.length }), event.currentTarget)
|
|
1240
|
+
},
|
|
1241
|
+
onMouseLeave: event => {
|
|
1242
|
+
event.currentTarget.style.background = T.surface
|
|
1243
|
+
hideTooltip()
|
|
1244
|
+
},
|
|
1245
|
+
style: {
|
|
1246
|
+
appearance: 'none', border: `1px solid ${T.border}`, background: T.surface, color: T.ink2,
|
|
1247
|
+
display: 'inline-flex', alignItems: 'center', gap: 3, height: 20, padding: '0 7px', borderRadius: T.pill,
|
|
1248
|
+
cursor: 'pointer', fontSize: 10, fontFamily: MONO,
|
|
1249
|
+
transition: `background .15s ${T.ease}`,
|
|
1250
|
+
},
|
|
1251
|
+
}, h(IconStash), String(stashes.items.length)) : null,
|
|
1252
|
+
h(IconAction, { label: t('refresh'), onClick: event => { event.stopPropagation(); refreshStatus(); loadStashes() } }, h(RefreshIcon, {}))),
|
|
1253
|
+
open ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, padding: '10px 12px 12px' } },
|
|
1254
|
+
composer,
|
|
1255
|
+
cleanState,
|
|
1256
|
+
!dirty && needsSync ? h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
1257
|
+
h('span', { style: { flex: 1, fontSize: 12, color: T.ink2 } }, t('cleanTree')),
|
|
1258
|
+
syncWhenClean) : null,
|
|
1259
|
+
stagedFiles.length > 0 ? h('div', { style: { borderTop: `1px solid ${T.borderSoft}`, paddingTop: 4 } },
|
|
1260
|
+
sectionHeader(t('staged'), stagedFiles.length, !collapsedSections.has('staged'), () => toggleSection('staged'),
|
|
1261
|
+
h(IconAction, { label: t('unstageAll'), disabled: busy, onClick: () => optimisticStage(stagedFiles, true) }, h(IconMinus))),
|
|
1262
|
+
!collapsedSections.has('staged')
|
|
1263
|
+
? h(TreeRows, {
|
|
1264
|
+
node: stagedTree, depth: 0, expandedDirs, onToggleDir: toggleDir,
|
|
1265
|
+
onOpen: file => onOpen(file, item.path),
|
|
1266
|
+
selectedKey: selectedPath ? `s:${selectedPath}` : undefined,
|
|
1267
|
+
actionsFor: file => h('span', { style: { display: 'inline-flex', gap: 1 } },
|
|
1268
|
+
h(IconAction, {
|
|
1269
|
+
label: t('unstage'), disabled: busy,
|
|
1270
|
+
onClick: event => { event.stopPropagation(); optimisticStage([file], true) },
|
|
1271
|
+
}, h(IconMinus)),
|
|
1272
|
+
h(IconAction, { label: t('moreFileActions'), onClick: event => openRowMenu(file, true, event) }, h(IconMore))),
|
|
1273
|
+
statusByPath: stagedStatus, showStatus: true,
|
|
1274
|
+
hoveredKey, onHoverKey: setHoveredKey,
|
|
1275
|
+
})
|
|
1276
|
+
: null) : null,
|
|
1277
|
+
changeFiles.length > 0 ? h('div', { style: { borderTop: `1px solid ${T.borderSoft}`, paddingTop: 4 } },
|
|
1278
|
+
sectionHeader(t('changes'), changeFiles.length, !collapsedSections.has('changes'), () => toggleSection('changes'),
|
|
1279
|
+
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 1 } },
|
|
1280
|
+
h(IconAction, {
|
|
1281
|
+
label: t('discardAll'), danger: true, disabled: busy || changeFiles.length === 0,
|
|
1282
|
+
onClick: () => onDiscardAll?.(changeFiles.map(file => file.path)),
|
|
1283
|
+
}, h(IconUndo)),
|
|
1284
|
+
h(IconAction, { label: t('stashPush'), disabled: busy, onClick: () => stashPushChanges() }, h(IconStash)),
|
|
1285
|
+
h(IconAction, { label: t('stageAll'), disabled: busy || changeFiles.length === 0, onClick: () => optimisticStage(changeFiles, false) }, h(IconPlus)))),
|
|
1286
|
+
!collapsedSections.has('changes')
|
|
1287
|
+
? h(TreeRows, {
|
|
1288
|
+
node: changeTree, depth: 0, expandedDirs, onToggleDir: toggleDir,
|
|
1289
|
+
onOpen: file => onOpen(file, item.path),
|
|
1290
|
+
selectedKey: selectedPath ? `f:${selectedPath}` : undefined,
|
|
1291
|
+
actionsFor: file => h('span', { style: { display: 'inline-flex', gap: 1 } },
|
|
1292
|
+
h(IconAction, {
|
|
1293
|
+
label: t('discard'), danger: true, disabled: busy,
|
|
1294
|
+
onClick: event => { event.stopPropagation(); runAction(() => apiPost('/discard', { path: item.path, files: [file.path] })) },
|
|
1295
|
+
}, h(IconUndo)),
|
|
1296
|
+
h(IconAction, {
|
|
1297
|
+
label: t('stage'), disabled: busy,
|
|
1298
|
+
onClick: event => { event.stopPropagation(); optimisticStage([file], false) },
|
|
1299
|
+
}, h(IconPlus)),
|
|
1300
|
+
h(IconAction, { label: t('moreFileActions'), onClick: event => openRowMenu(file, false, event) }, h(IconMore))),
|
|
1301
|
+
statusByPath: changeStatus, showStatus: true,
|
|
1302
|
+
hoveredKey, onHoverKey: setHoveredKey,
|
|
1303
|
+
})
|
|
1304
|
+
: null) : null,
|
|
1305
|
+
status.phase === 'loading' ? h('div', { style: { fontSize: 11.5, color: T.muted, padding: '2px 0' } }, t('loading')) : null,
|
|
1306
|
+
status.phase === 'error' ? h('div', { style: { fontSize: 11.5, color: T.error, padding: '2px 0' } }, status.error) : null) : null),
|
|
1307
|
+
rowMenuElement, stashMenuElement, branchMenuElement]
|
|
1308
|
+
}
|
|
1309
|
+
/** Multi-file diff for one commit: file cards with collapse, wrap and per-file diff. */
|
|
1310
|
+
function CommitFileDiff({ context, entry, view, wrap, t }) {
|
|
1311
|
+
const state = useCommitFileDiff(context, entry.path)
|
|
1312
|
+
if (state.phase === 'loading') return h('div', { style: { padding: '8px 14px', color: T.muted, fontSize: 11.5 } }, t('loading'))
|
|
1313
|
+
if (state.phase === 'error') return h('div', { style: { padding: '8px 14px', color: T.error, fontSize: 11.5 } }, state.error)
|
|
1314
|
+
return h(DiffLines, { file: state.data?.files ?? [], view, t, wrap, embedded: true, context })
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function CommitFilesView({ state, view, wrap, t, collapseMode, context }) {
|
|
1318
|
+
const [collapsed, setCollapsed] = useState(() => new Set())
|
|
1319
|
+
const files = state.data?.files ?? []
|
|
1320
|
+
useEffect(() => {
|
|
1321
|
+
if (!files.length) return
|
|
1322
|
+
setCollapsed(new Set(files
|
|
1323
|
+
.filter(file => (file.additions ?? 0) + (file.deletions ?? 0) > 3000)
|
|
1324
|
+
.map(file => file.path)))
|
|
1325
|
+
}, [state.data])
|
|
1326
|
+
useEffect(() => {
|
|
1327
|
+
if (!files.length) return
|
|
1328
|
+
setCollapsed(collapseMode ? new Set(files.map(file => file.path)) : new Set())
|
|
1329
|
+
}, [collapseMode])
|
|
1330
|
+
if (state.phase === 'loading') return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('loading'))
|
|
1331
|
+
if (state.phase === 'error') return h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, state.error)
|
|
1332
|
+
if (files.length === 0) return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('noDiff'))
|
|
1333
|
+
return h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', paddingBottom: 16 } },
|
|
1334
|
+
files.map(entry => {
|
|
1335
|
+
const isCollapsed = collapsed.has(entry.path)
|
|
1336
|
+
const additions = entry.additions ?? 0
|
|
1337
|
+
const deletions = entry.deletions ?? 0
|
|
1338
|
+
return h('div', { key: entry.path, style: { borderBottom: `0.5px solid ${T.borderSoft}` } },
|
|
1339
|
+
h('div', {
|
|
1340
|
+
onClick: () => setCollapsed(previous => {
|
|
1341
|
+
const next = new Set(previous)
|
|
1342
|
+
if (next.has(entry.path)) next.delete(entry.path)
|
|
1343
|
+
else next.add(entry.path)
|
|
1344
|
+
return next
|
|
1345
|
+
}),
|
|
1346
|
+
style: {
|
|
1347
|
+
display: 'flex', alignItems: 'center', gap: 6, padding: '6px 12px', cursor: 'pointer',
|
|
1348
|
+
position: 'sticky', top: 0, zIndex: 2, background: T.menu,
|
|
1349
|
+
borderBottom: isCollapsed ? 'none' : `0.5px solid ${T.borderSoft}`,
|
|
1350
|
+
},
|
|
1351
|
+
},
|
|
1352
|
+
h(Chevron, { open: !isCollapsed, size: 8 }),
|
|
1353
|
+
h(FileGlyph, { name: entry.path.split('/').pop() ?? entry.path, kind: 'file' }),
|
|
1354
|
+
h('span', {
|
|
1355
|
+
title: entry.path,
|
|
1356
|
+
style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontFamily: MONO, fontSize: 11.5, color: T.ink2 },
|
|
1357
|
+
}, entry.path),
|
|
1358
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.success } }, `+${additions}`),
|
|
1359
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.error } }, `−${deletions}`),
|
|
1360
|
+
h(StatusChip, { status: entry.status ?? 'M', size: 15 })),
|
|
1361
|
+
isCollapsed
|
|
1362
|
+
? null
|
|
1363
|
+
: h('div', { style: { padding: '2px 0 6px' } },
|
|
1364
|
+
h(CommitFileDiff, { context, entry, view, wrap, t })))
|
|
1365
|
+
}))
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
const MD_INLINE_CODE = { fontFamily: MONO, fontSize: '0.92em', padding: '0 4px', borderRadius: 4, background: T.hover }
|
|
1369
|
+
const MD_PRE = { margin: '6px 0', padding: '8px 10px', borderRadius: T.rSm, background: T.hover, overflowX: 'auto', fontFamily: MONO, fontSize: 11, lineHeight: '17px' }
|
|
1370
|
+
|
|
1371
|
+
function markdownInline(text, keyPrefix) {
|
|
1372
|
+
const tokens = String(text ?? '').split(/(`[^`\n]+`|\*\*[^*\n]+\*\*|__[^_\n]+__|~~[^~\n]+~~|\*[^*\n]+\*|_[^_\n]+_|!\[[^\]]*\]\([^)\s]+\)|\[[^\]]+\]\([^)\s]+\))/g)
|
|
1373
|
+
return tokens.filter(Boolean).map((token, index) => {
|
|
1374
|
+
const key = `${keyPrefix}:${index}`
|
|
1375
|
+
if (/^`[^`]+`$/.test(token)) return h('code', { key, style: MD_INLINE_CODE }, token.slice(1, -1))
|
|
1376
|
+
if (/^\*\*[^*]+\*\*$/.test(token) || /^__[^_]+__$/.test(token)) return h('strong', { key }, token.slice(2, -2))
|
|
1377
|
+
if (/^~~[^~]+~~$/.test(token)) return h('del', { key }, token.slice(2, -2))
|
|
1378
|
+
if (/^\*[^*]+\*$/.test(token) || /^_[^_]+_$/.test(token)) return h('em', { key }, token.slice(1, -1))
|
|
1379
|
+
const image = /^!\[([^\]]*)\]\(([^)\s]+)\)$/.exec(token)
|
|
1380
|
+
if (image) return h('img', { key, src: image[2], alt: image[1], style: { maxWidth: '100%', borderRadius: 6, display: 'block', margin: '4px 0' } })
|
|
1381
|
+
const link = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(token)
|
|
1382
|
+
if (link) return h('a', { key, href: link[2], target: '_blank', rel: 'noreferrer', style: { color: T.accent } }, link[1])
|
|
1383
|
+
return token
|
|
1384
|
+
})
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
function markdownCells(line) {
|
|
1388
|
+
return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(cell => cell.trim())
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function markdownBlocks(text) {
|
|
1392
|
+
const lines = String(text ?? '').replace(/\r\n/g, '\n').split('\n')
|
|
1393
|
+
const blocks = []
|
|
1394
|
+
let index = 0
|
|
1395
|
+
let key = 0
|
|
1396
|
+
while (index < lines.length) {
|
|
1397
|
+
const line = lines[index]
|
|
1398
|
+
if (!line.trim()) { index += 1; continue }
|
|
1399
|
+
if (/^```/.test(line)) {
|
|
1400
|
+
index += 1
|
|
1401
|
+
const code = []
|
|
1402
|
+
while (index < lines.length && !/^```/.test(lines[index])) code.push(lines[index++])
|
|
1403
|
+
index += 1
|
|
1404
|
+
blocks.push(h('pre', { key: key++, style: MD_PRE }, h('code', { style: { fontFamily: MONO } }, code.join('\n'))))
|
|
1405
|
+
continue
|
|
1406
|
+
}
|
|
1407
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(line)
|
|
1408
|
+
if (heading) {
|
|
1409
|
+
const level = heading[1].length
|
|
1410
|
+
blocks.push(h('div', {
|
|
1411
|
+
key: key++,
|
|
1412
|
+
style: { fontSize: Math.max(13, 20 - (level - 1) * 2), fontWeight: 600, lineHeight: '1.4', margin: '10px 0 4px', color: T.text },
|
|
1413
|
+
}, markdownInline(heading[2], `h${key}`)))
|
|
1414
|
+
index += 1
|
|
1415
|
+
continue
|
|
1416
|
+
}
|
|
1417
|
+
if (/^\s*(---+|___+|\*\*\*+)\s*$/.test(line)) {
|
|
1418
|
+
blocks.push(h('hr', { key: key++, style: { border: 'none', borderTop: `0.5px solid ${T.borderSoft}`, margin: '10px 0' } }))
|
|
1419
|
+
index += 1
|
|
1420
|
+
continue
|
|
1421
|
+
}
|
|
1422
|
+
if (/^\s*>\s?/.test(line)) {
|
|
1423
|
+
const quoted = []
|
|
1424
|
+
while (index < lines.length && /^\s*>\s?/.test(lines[index])) quoted.push(lines[index++].replace(/^\s*>\s?/, ''))
|
|
1425
|
+
blocks.push(h('blockquote', { key: key++, style: { margin: '6px 0', padding: '2px 10px', borderLeft: `2px solid ${T.border}`, color: T.ink2 } }, markdownBlocks(quoted.join('\n'))))
|
|
1426
|
+
continue
|
|
1427
|
+
}
|
|
1428
|
+
if (/^\s*([-*+]|\d+\.)\s+/.test(line)) {
|
|
1429
|
+
const ordered = /^\s*\d+\./.test(line)
|
|
1430
|
+
const items = []
|
|
1431
|
+
while (index < lines.length && /^\s*([-*+]|\d+\.)\s+/.test(lines[index])) {
|
|
1432
|
+
const match = /^\s*(?:[-*+]|\d+\.)\s+(.*)$/.exec(lines[index])
|
|
1433
|
+
items.push(match ? match[1] : '')
|
|
1434
|
+
index += 1
|
|
1435
|
+
}
|
|
1436
|
+
blocks.push(h(ordered ? 'ol' : 'ul', { key: key++, style: { margin: '4px 0', paddingLeft: 20 } },
|
|
1437
|
+
items.map((item, itemIndex) => h('li', { key: itemIndex, style: { margin: '1px 0' } }, markdownInline(item, `li${key}:${itemIndex}`)))))
|
|
1438
|
+
continue
|
|
1439
|
+
}
|
|
1440
|
+
if (/\|/.test(line) && index + 1 < lines.length && /^\s*\|?[\s:|-]+\|?\s*$/.test(lines[index + 1])) {
|
|
1441
|
+
const header = markdownCells(line)
|
|
1442
|
+
const rows = []
|
|
1443
|
+
index += 2
|
|
1444
|
+
while (index < lines.length && /\|/.test(lines[index]) && lines[index].trim()) rows.push(markdownCells(lines[index++]))
|
|
1445
|
+
const headRow = h('tr', null, header.map((cell, cellIndex) => h('th', {
|
|
1446
|
+
key: cellIndex,
|
|
1447
|
+
style: { textAlign: 'left', padding: '3px 8px', border: `0.5px solid ${T.borderSoft}`, background: T.hover, fontWeight: 600, whiteSpace: 'nowrap' },
|
|
1448
|
+
}, markdownInline(cell, `th${key}:${cellIndex}`))))
|
|
1449
|
+
const bodyRows = rows.map((cells, rowIndex) => h('tr', { key: rowIndex },
|
|
1450
|
+
cells.map((cell, cellIndex) => h('td', {
|
|
1451
|
+
key: cellIndex,
|
|
1452
|
+
style: { padding: '3px 8px', border: `0.5px solid ${T.borderSoft}`, verticalAlign: 'top' },
|
|
1453
|
+
}, markdownInline(cell, `td${key}:${rowIndex}:${cellIndex}`)))))
|
|
1454
|
+
blocks.push(h('div', { key: key++, style: { overflowX: 'auto', margin: '6px 0' } },
|
|
1455
|
+
h('table', { style: { borderCollapse: 'collapse', fontSize: 11.5, width: '100%' } },
|
|
1456
|
+
h('thead', null, headRow),
|
|
1457
|
+
h('tbody', null, bodyRows))))
|
|
1458
|
+
continue
|
|
1459
|
+
}
|
|
1460
|
+
const paragraph = [line]
|
|
1461
|
+
index += 1
|
|
1462
|
+
while (index < lines.length && lines[index].trim() && !/^(#{1,6})\s|^```|^\s*>|^\s*([-*+]|\d+\.)\s|^\s*(---+)|\|/.test(lines[index])) {
|
|
1463
|
+
paragraph.push(lines[index++])
|
|
1464
|
+
}
|
|
1465
|
+
blocks.push(h('p', { key: key++, style: { margin: '4px 0', lineHeight: '1.65' } },
|
|
1466
|
+
paragraph.map((part, partIndex) => h('span', { key: partIndex }, markdownInline(part, `p${key}:${partIndex}`), partIndex < paragraph.length - 1 ? h('br') : null))))
|
|
1467
|
+
}
|
|
1468
|
+
return blocks
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function MarkdownBody({ text }) {
|
|
1472
|
+
return h('div', { style: { fontSize: 12.5, lineHeight: '1.6', color: T.ink2, wordBreak: 'break-word' } }, markdownBlocks(text))
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
function issueStateColor(value) {
|
|
1476
|
+
return value === 'open' ? T.success : '#a371f7'
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
/**
|
|
1480
|
+
* GitHub label chips: a light tint of the label hue for the fill, and that hue pulled toward the
|
|
1481
|
+
* theme's primary text for the label itself — so pale labels (#a2eeef) stay readable on white.
|
|
1482
|
+
*/
|
|
1483
|
+
function labelChipStyle(color) {
|
|
1484
|
+
const hex = String(color ?? '').replace(/^#/, '')
|
|
1485
|
+
const base = /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : 'currentColor'
|
|
1486
|
+
return {
|
|
1487
|
+
background: `color-mix(in srgb, ${base} 15%, transparent)`,
|
|
1488
|
+
color: `color-mix(in srgb, ${base} 52%, var(--dsw-alias-label-primary, #0f1115))`,
|
|
1489
|
+
border: `1px solid color-mix(in srgb, ${base} 26%, transparent)`,
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function IssueCard({ t, issue, selected, onClick }) {
|
|
1494
|
+
const stateColor = issueStateColor(issue.state)
|
|
1495
|
+
return h('div', {
|
|
1496
|
+
role: 'button', tabIndex: 0,
|
|
1497
|
+
onClick,
|
|
1498
|
+
onKeyDown: event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onClick() } },
|
|
1499
|
+
style: {
|
|
1500
|
+
display: 'flex', flexDirection: 'column', gap: 7, padding: '10px 11px', minHeight: 104,
|
|
1501
|
+
borderRadius: 10, cursor: 'pointer', position: 'relative',
|
|
1502
|
+
background: selected ? tint(T.accent, 7) : T.surface,
|
|
1503
|
+
boxShadow: selected ? `inset 0 0 0 1.5px ${T.accent}, 0 2px 8px rgba(0,0,0,.05)` : T.ring,
|
|
1504
|
+
transition: `box-shadow .15s ${T.ease}, background .15s ${T.ease}`,
|
|
1505
|
+
},
|
|
1506
|
+
onMouseEnter: event => { if (!selected) event.currentTarget.style.boxShadow = `${T.ring}, 0 2px 10px rgba(0,0,0,.07)` },
|
|
1507
|
+
onMouseLeave: event => { if (!selected) event.currentTarget.style.boxShadow = T.ring },
|
|
1508
|
+
},
|
|
1509
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
1510
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.muted } }, `#${issue.number}`),
|
|
1511
|
+
h('span', { style: { width: 7, height: 7, borderRadius: '50%', background: stateColor } }),
|
|
1512
|
+
h('span', { style: { fontSize: 10, color: T.muted, textTransform: 'capitalize' } }, issue.state),
|
|
1513
|
+
h('span', { style: { flex: 1 } }),
|
|
1514
|
+
issue.comments > 0 ? h('span', { style: { fontSize: 10, color: T.subtle } }, `💬 ${issue.comments}`) : null,
|
|
1515
|
+
h('span', { style: { fontSize: 10, color: T.subtle, whiteSpace: 'nowrap' } }, issue.updatedAt ? formatRelativeTime(Math.floor(new Date(issue.updatedAt).getTime() / 1000)) : '')),
|
|
1516
|
+
h('div', {
|
|
1517
|
+
style: {
|
|
1518
|
+
fontSize: 12.5, fontWeight: 500, lineHeight: '18px', color: T.text,
|
|
1519
|
+
display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical', overflow: 'hidden',
|
|
1520
|
+
},
|
|
1521
|
+
}, issue.title),
|
|
1522
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 4, flexWrap: 'wrap' } },
|
|
1523
|
+
...(issue.labels ?? []).slice(0, 3).map(label => h('span', {
|
|
1524
|
+
key: label.name,
|
|
1525
|
+
style: { fontSize: 9.5, padding: '0 6px', lineHeight: '16px', borderRadius: T.pill, whiteSpace: 'nowrap', ...labelChipStyle(label.color) },
|
|
1526
|
+
}, label.name)),
|
|
1527
|
+
(issue.labels?.length ?? 0) > 3 ? h('span', { style: { fontSize: 9.5, color: T.subtle } }, `+${issue.labels.length - 3}`) : null),
|
|
1528
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 'auto' } },
|
|
1529
|
+
issue.parent
|
|
1530
|
+
? h('span', { style: { fontSize: 9.5, color: T.subtle, border: `0.5px solid ${T.border}`, borderRadius: T.pill, padding: '0 6px', whiteSpace: 'nowrap' } }, `↑ #${issue.parent.number}`)
|
|
1531
|
+
: null,
|
|
1532
|
+
(issue.children?.length ?? 0) > 0
|
|
1533
|
+
? h('span', { style: { fontSize: 9.5, color: T.subtle, border: `0.5px solid ${T.border}`, borderRadius: T.pill, padding: '0 6px', whiteSpace: 'nowrap' } }, `⌄ ${issue.children.length} ${t('issueChildren')}`)
|
|
1534
|
+
: null,
|
|
1535
|
+
h('span', { style: { flex: 1 } })))
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
function IssueDetailPane({ t, state, onNavigate, onClose, comments, onCommentPost, onToggleState }) {
|
|
1539
|
+
const composerRef = useRef(null)
|
|
1540
|
+
const [sending, setSending] = useState(false)
|
|
1541
|
+
const [toggling, setToggling] = useState(false)
|
|
1542
|
+
const postComment = () => {
|
|
1543
|
+
if (sending) return
|
|
1544
|
+
const body = composerRef.current?.value ?? ''
|
|
1545
|
+
if (!body.trim()) return
|
|
1546
|
+
setSending(true)
|
|
1547
|
+
Promise.resolve(onCommentPost?.(body.trim()))
|
|
1548
|
+
.then(() => { if (composerRef.current) composerRef.current.value = '' })
|
|
1549
|
+
.catch(() => { /* the parent already surfaced the failure */ })
|
|
1550
|
+
.finally(() => setSending(false))
|
|
1551
|
+
}
|
|
1552
|
+
const toggleState = () => {
|
|
1553
|
+
if (toggling) return
|
|
1554
|
+
const issue = state?.data?.issue
|
|
1555
|
+
if (!issue) return
|
|
1556
|
+
setToggling(true)
|
|
1557
|
+
Promise.resolve(onToggleState?.(issue.state === 'closed' ? 'open' : 'closed'))
|
|
1558
|
+
.catch(() => { /* the parent already surfaced the failure */ })
|
|
1559
|
+
.finally(() => setToggling(false))
|
|
1560
|
+
}
|
|
1561
|
+
if (!state || state.phase === 'idle') {
|
|
1562
|
+
return h('div', { style: { flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 10, padding: 24, color: T.muted, textAlign: 'center' } },
|
|
1563
|
+
h('div', {
|
|
1564
|
+
style: {
|
|
1565
|
+
width: 44, height: 44, borderRadius: 14, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
1566
|
+
background: T.surfaceAlt, boxShadow: T.ring, color: T.muted,
|
|
1567
|
+
},
|
|
1568
|
+
}, h('svg', { width: 22, height: 22, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round', strokeLinejoin: 'round' },
|
|
1569
|
+
h('circle', { cx: 12, cy: 12, r: 9 }), h('path', { d: 'M12 8v5' }), h('circle', { cx: 12, cy: 16.5, r: 0.6, fill: 'currentColor' }))),
|
|
1570
|
+
h('div', { style: { fontSize: 12.5, color: T.ink2 } }, t('issueDetailEmpty')))
|
|
1571
|
+
}
|
|
1572
|
+
if (state.phase === 'loading') return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('loading'))
|
|
1573
|
+
if (state.phase === 'error') return h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, state.error)
|
|
1574
|
+
const issue = state.data?.issue
|
|
1575
|
+
if (!issue) return null
|
|
1576
|
+
const commentItems = comments?.data?.comments ?? []
|
|
1577
|
+
return h('div', { style: { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' } },
|
|
1578
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, padding: '0 12px', minHeight: 36, background: T.surfaceAlt, borderBottom: `1px solid ${T.borderSoft}`, flex: '0 0 auto' } },
|
|
1579
|
+
h('span', { style: { fontFamily: MONO, fontSize: 11, fontWeight: 600, color: T.ink2 } }, `#${issue.number}`),
|
|
1580
|
+
h('span', { style: { fontSize: 10, fontWeight: 600, padding: '0 8px', lineHeight: '16px', borderRadius: T.pill, whiteSpace: 'nowrap', color: issueStateColor(issue.state), background: tint(issueStateColor(issue.state), 12) } },
|
|
1581
|
+
issue.state === 'closed' ? t('issueStateClosed') : t('issueStateOpen')),
|
|
1582
|
+
h('span', { style: { flex: 1 } }),
|
|
1583
|
+
onToggleState ? h(SmallButton, {
|
|
1584
|
+
label: toggling ? t('loading') : issue.state === 'closed' ? t('reopenIssue') : t('closeIssue'),
|
|
1585
|
+
onClick: toggleState, disabled: toggling,
|
|
1586
|
+
}) : null,
|
|
1587
|
+
issue.url ? h('a', {
|
|
1588
|
+
href: issue.url, target: '_blank', rel: 'noreferrer',
|
|
1589
|
+
style: { fontSize: 10.5, color: T.accent, textDecoration: 'none' },
|
|
1590
|
+
}, t('issueOpenInGitHub')) : null,
|
|
1591
|
+
h('button', {
|
|
1592
|
+
type: 'button', onClick: onClose, title: '×',
|
|
1593
|
+
style: { appearance: 'none', border: 'none', background: 'transparent', color: T.muted, cursor: 'pointer', fontSize: 15, padding: '0 4px' },
|
|
1594
|
+
}, '×')),
|
|
1595
|
+
h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '12px 12px 14px', display: 'flex', flexDirection: 'column', gap: 10 } },
|
|
1596
|
+
h('div', { style: { fontSize: 15, lineHeight: '22px', fontWeight: 600, color: T.text } }, issue.title),
|
|
1597
|
+
h('div', { style: { display: 'flex', gap: 4, flexWrap: 'wrap' } },
|
|
1598
|
+
...(issue.labels ?? []).map(label => h('span', {
|
|
1599
|
+
key: label.name,
|
|
1600
|
+
style: { fontSize: 10, padding: '0 7px', lineHeight: '17px', borderRadius: T.pill, whiteSpace: 'nowrap', ...labelChipStyle(label.color) },
|
|
1601
|
+
}, label.name))),
|
|
1602
|
+
h('div', { style: { display: 'flex', gap: 12, fontSize: 11, color: T.subtle, flexWrap: 'wrap' } },
|
|
1603
|
+
h('span', null, `${issue.comments ?? 0} ${t('issueComments')}`),
|
|
1604
|
+
issue.updatedAt ? h('span', null, `${t('issueUpdated')} ${formatRelativeTime(Math.floor(new Date(issue.updatedAt).getTime() / 1000))}`) : null,
|
|
1605
|
+
issue.author ? h('span', null, `@${issue.author}`) : null),
|
|
1606
|
+
(issue.parent || (issue.children?.length ?? 0) > 0)
|
|
1607
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 4, padding: '8px 10px', borderRadius: 9, background: T.well, boxShadow: `inset 0 0 0 1px ${T.borderSoft}` } },
|
|
1608
|
+
h('div', { style: { fontSize: 10, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', color: T.muted } }, t('issueRelations')),
|
|
1609
|
+
issue.parent
|
|
1610
|
+
? h('button', {
|
|
1611
|
+
type: 'button', onClick: () => onNavigate?.(issue.parent.number),
|
|
1612
|
+
style: { appearance: 'none', border: 'none', background: 'transparent', color: T.accent, cursor: 'pointer', textAlign: 'left', padding: 0, fontSize: 11 },
|
|
1613
|
+
}, `${t('issueParent')}: #${issue.parent.number} ${issue.parent.title ?? ''}`)
|
|
1614
|
+
: null,
|
|
1615
|
+
...(issue.children ?? []).map(child => h('button', {
|
|
1616
|
+
key: child.number, type: 'button', onClick: () => onNavigate?.(child.number),
|
|
1617
|
+
style: { appearance: 'none', border: 'none', background: 'transparent', color: T.accent, cursor: 'pointer', textAlign: 'left', padding: 0, fontSize: 11 },
|
|
1618
|
+
}, `${t('issueChildren')}: #${child.number} ${child.title ?? ''}`)))
|
|
1619
|
+
: null,
|
|
1620
|
+
issue.body
|
|
1621
|
+
? h('div', { style: { borderTop: `0.5px solid ${T.borderSoft}`, paddingTop: 10 } }, h(MarkdownBody, { text: issue.body }))
|
|
1622
|
+
: null,
|
|
1623
|
+
h('div', { style: { borderTop: `1px solid ${T.borderSoft}`, paddingTop: 12, display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
1624
|
+
h('div', { style: { fontSize: 10.5, fontWeight: 700, color: T.muted, letterSpacing: '0.08em', textTransform: 'uppercase' } }, `${issue.comments ?? 0} ${t('issueComments')}`),
|
|
1625
|
+
comments?.phase === 'loading'
|
|
1626
|
+
? h('div', { style: { fontSize: 11, color: T.muted } }, t('loading'))
|
|
1627
|
+
: comments?.phase === 'error'
|
|
1628
|
+
? h('div', { style: { fontSize: 11, color: T.error } }, comments.error)
|
|
1629
|
+
: commentItems.length === 0
|
|
1630
|
+
? h('div', { style: { fontSize: 11, color: T.subtle } }, t('issueNoComments'))
|
|
1631
|
+
: commentItems.map(comment => h('div', {
|
|
1632
|
+
key: comment.id,
|
|
1633
|
+
style: {
|
|
1634
|
+
boxShadow: T.ring, borderRadius: 9, padding: '9px 11px', background: T.surface,
|
|
1635
|
+
display: 'flex', flexDirection: 'column', gap: 6,
|
|
1636
|
+
},
|
|
1637
|
+
},
|
|
1638
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 7, fontSize: 11, color: T.muted } },
|
|
1639
|
+
h('span', {
|
|
1640
|
+
title: comment.author,
|
|
1641
|
+
style: {
|
|
1642
|
+
width: 20, height: 20, borderRadius: '50%', flex: '0 0 auto', display: 'inline-flex',
|
|
1643
|
+
alignItems: 'center', justifyContent: 'center', fontSize: 10, fontWeight: 700,
|
|
1644
|
+
background: tint(T.brand, 20), color: T.brand,
|
|
1645
|
+
},
|
|
1646
|
+
}, (comment.author || '?').slice(0, 1).toUpperCase()),
|
|
1647
|
+
h('span', { style: { fontWeight: 600, color: T.text } }, comment.author ? `@${comment.author}` : ''),
|
|
1648
|
+
comment.createdAt ? h('span', { style: { color: T.subtle } }, formatRelativeTime(Math.floor(new Date(comment.createdAt).getTime() / 1000))) : null),
|
|
1649
|
+
h(MarkdownBody, { text: comment.body }))),
|
|
1650
|
+
onCommentPost ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 7, padding: 9, borderRadius: 10, background: T.well, boxShadow: `inset 0 0 0 1px ${T.borderSoft}` } },
|
|
1651
|
+
h('textarea', {
|
|
1652
|
+
ref: composerRef, rows: 2, placeholder: t('commentPlaceholder'),
|
|
1653
|
+
onFocus: event => { event.currentTarget.parentElement.style.boxShadow = `inset 0 0 0 1px ${T.accent}, 0 0 0 3px ${tint(T.accent, 14)}` },
|
|
1654
|
+
onBlur: event => { event.currentTarget.parentElement.style.boxShadow = `inset 0 0 0 1px ${T.borderSoft}` },
|
|
1655
|
+
style: {
|
|
1656
|
+
width: '100%', boxSizing: 'border-box', resize: 'vertical', background: 'transparent', color: 'inherit',
|
|
1657
|
+
border: 'none', outline: 'none', fontSize: 12.5, fontFamily: 'inherit', lineHeight: '18px', padding: 0,
|
|
1658
|
+
minHeight: 40,
|
|
1659
|
+
},
|
|
1660
|
+
onKeyDown: event => { if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) { event.preventDefault(); postComment() } },
|
|
1661
|
+
}),
|
|
1662
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
1663
|
+
h('span', { style: { flex: 1, fontSize: 10, color: T.subtle } }, '⌘/Ctrl + Enter'),
|
|
1664
|
+
h('button', {
|
|
1665
|
+
type: 'button', onClick: postComment, disabled: sending,
|
|
1666
|
+
onMouseEnter: event => { if (!event.currentTarget.disabled) event.currentTarget.style.background = T.primaryHover },
|
|
1667
|
+
onMouseLeave: event => { event.currentTarget.style.background = T.primary },
|
|
1668
|
+
style: {
|
|
1669
|
+
appearance: 'none', border: '1px solid transparent', borderRadius: 7, height: 26, padding: '0 12px',
|
|
1670
|
+
fontSize: 11.5, fontWeight: 600, font: 'inherit', background: T.primary, color: T.primaryText,
|
|
1671
|
+
cursor: sending ? 'default' : 'pointer', opacity: sending ? 0.55 : 1,
|
|
1672
|
+
},
|
|
1673
|
+
}, sending ? t('commentSending') : t('commentSend')))) : null)))
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
function IssuesPane({ t, state, selectedNumber, onSelect, search, onSearch, stateFilter, onStateFilter, onRefresh, onLoadMore }) {
|
|
1677
|
+
const issues = state.issues ?? []
|
|
1678
|
+
const stateOptions = [['open', t('issuesOpen')], ['closed', t('issuesClosed')], ['all', t('issuesAll')]]
|
|
1679
|
+
return h('div', { style: { flex: 1, minWidth: 0, minHeight: 0, display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
1680
|
+
h('div', {
|
|
1681
|
+
style: {
|
|
1682
|
+
flex: '0 0 auto', display: 'flex', alignItems: 'center', gap: 6, minHeight: 40, padding: '0 8px',
|
|
1683
|
+
minWidth: 0, borderRadius: T.rMd, background: T.surface, boxShadow: T.edge,
|
|
1684
|
+
},
|
|
1685
|
+
},
|
|
1686
|
+
h('input', {
|
|
1687
|
+
value: search, placeholder: t('issueSearchPlaceholder'),
|
|
1688
|
+
onChange: event => onSearch(event.target.value),
|
|
1689
|
+
style: {
|
|
1690
|
+
flex: 1, minWidth: 80, height: 28, borderRadius: T.rSm, padding: '0 10px', fontSize: 12, color: 'inherit',
|
|
1691
|
+
background: T.well,
|
|
1692
|
+
border: `1px solid ${T.borderSoft}`, outline: 'none',
|
|
1693
|
+
},
|
|
1694
|
+
}),
|
|
1695
|
+
h('span', { style: { display: 'inline-flex', padding: 2, borderRadius: T.pill, background: T.hover, border: `0.5px solid ${T.borderSoft}` } },
|
|
1696
|
+
stateOptions.map(([value, label]) => h('button', {
|
|
1697
|
+
key: value, type: 'button', onClick: () => onStateFilter(value),
|
|
1698
|
+
style: {
|
|
1699
|
+
appearance: 'none', border: 'none', cursor: 'pointer', font: 'inherit', fontSize: 10.5,
|
|
1700
|
+
height: 22, padding: '0 10px', borderRadius: T.pill,
|
|
1701
|
+
background: stateFilter === value ? T.card : 'transparent',
|
|
1702
|
+
color: stateFilter === value ? T.text : T.muted,
|
|
1703
|
+
},
|
|
1704
|
+
}, label))),
|
|
1705
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.subtle } }, state.phase === 'ready' ? String(issues.length) : ''),
|
|
1706
|
+
h(IconButton, { label: t('refresh'), onClick: onRefresh }, h(RefreshIcon, {}))),
|
|
1707
|
+
h('div', {
|
|
1708
|
+
style: {
|
|
1709
|
+
flex: 1, minHeight: 0, overflowY: 'auto', borderRadius: T.rMd,
|
|
1710
|
+
background: T.surface, boxShadow: T.edge, padding: 10,
|
|
1711
|
+
},
|
|
1712
|
+
},
|
|
1713
|
+
state.phase === 'loading' && issues.length === 0
|
|
1714
|
+
? h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('loading'))
|
|
1715
|
+
: state.phase === 'error'
|
|
1716
|
+
? h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, state.error)
|
|
1717
|
+
: issues.length === 0
|
|
1718
|
+
? h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('issueNoIssues'))
|
|
1719
|
+
: h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))', gap: 8, alignContent: 'start' } },
|
|
1720
|
+
issues.map(issue => h(IssueCard, {
|
|
1721
|
+
key: issue.number, t, issue,
|
|
1722
|
+
selected: selectedNumber === issue.number,
|
|
1723
|
+
onClick: () => onSelect(selectedNumber === issue.number ? undefined : issue.number),
|
|
1724
|
+
})),
|
|
1725
|
+
(state.total ?? issues.length) > issues.length
|
|
1726
|
+
? h('div', { style: { gridColumn: '1 / -1', display: 'flex', justifyContent: 'center', padding: '4px 0 2px' } },
|
|
1727
|
+
h('button', {
|
|
1728
|
+
type: 'button', onClick: onLoadMore,
|
|
1729
|
+
style: {
|
|
1730
|
+
appearance: 'none', border: `0.5px solid ${T.border}`, borderRadius: T.pill,
|
|
1731
|
+
background: T.hover, color: T.ink2, fontSize: 11, padding: '4px 14px', cursor: 'pointer',
|
|
1732
|
+
},
|
|
1733
|
+
}, `${t('loadMore')} (${issues.length}/${state.total})`))
|
|
1734
|
+
: null)))
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
const LANE_COLORS = ['#60a5fa', '#fbbf24', '#34d399', '#f472b6', '#fb923c', '#38bdf8', '#a78bfa', '#f87171']
|
|
1738
|
+
const LANE_WIDTH = 14
|
|
1739
|
+
const ROW_HEIGHT = 22
|
|
1740
|
+
const laneX = column => column * LANE_WIDTH + LANE_WIDTH / 2
|
|
1741
|
+
const laneColor = column => LANE_COLORS[column % LANE_COLORS.length]
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* Lane assignment over topo-ordered commits, in a renderer-friendly shape: every row knows which lanes pass
|
|
1745
|
+
* straight through, which lanes join into its node, and which lanes start from the node for extra parents.
|
|
1746
|
+
*/
|
|
1747
|
+
function computeGraphLanes(commits) {
|
|
1748
|
+
const later = new Set()
|
|
1749
|
+
for (const row of commits) for (const parent of row.parents) later.add(parent)
|
|
1750
|
+
let colorCursor = 0
|
|
1751
|
+
const nextColor = () => colorCursor++ % LANE_COLORS.length
|
|
1752
|
+
let lanes = []
|
|
1753
|
+
const rows = []
|
|
1754
|
+
let maxLaneCount = 1
|
|
1755
|
+
for (const row of commits) {
|
|
1756
|
+
let nodeIndex = lanes.findIndex(lane => lane.hash === row.oid)
|
|
1757
|
+
const wasAwaited = nodeIndex !== -1
|
|
1758
|
+
if (!wasAwaited) {
|
|
1759
|
+
lanes.push({ hash: row.oid, color: nextColor() })
|
|
1760
|
+
nodeIndex = lanes.length - 1
|
|
1761
|
+
}
|
|
1762
|
+
const oldLanes = lanes.slice()
|
|
1763
|
+
const oldNodeIndex = nodeIndex
|
|
1764
|
+
const nodeColor = oldLanes[oldNodeIndex].color
|
|
1765
|
+
const joins = []
|
|
1766
|
+
const working = []
|
|
1767
|
+
for (let index = 0; index < oldLanes.length; index += 1) {
|
|
1768
|
+
if (index === oldNodeIndex) continue
|
|
1769
|
+
if (oldLanes[index].hash === row.oid) { joins.push(index); continue }
|
|
1770
|
+
working.push({ hash: oldLanes[index].hash, color: oldLanes[index].color, oldIndex: index })
|
|
1771
|
+
}
|
|
1772
|
+
const nodeSlot = oldNodeIndex - joins.filter(index => index < oldNodeIndex).length
|
|
1773
|
+
const parents = row.parents.filter(parent => later.has(parent))
|
|
1774
|
+
const first = parents[0]
|
|
1775
|
+
const rest = parents.slice(1)
|
|
1776
|
+
let newNodeIndex = -1
|
|
1777
|
+
if (first) {
|
|
1778
|
+
newNodeIndex = Math.min(nodeSlot, working.length)
|
|
1779
|
+
working.splice(newNodeIndex, 0, { hash: first, color: nodeColor, oldIndex: -1 })
|
|
1780
|
+
}
|
|
1781
|
+
const starts = []
|
|
1782
|
+
let insertAt = newNodeIndex === -1 ? nodeSlot : newNodeIndex + 1
|
|
1783
|
+
for (const parent of rest) {
|
|
1784
|
+
const existing = working.findIndex(entry => entry.hash === parent)
|
|
1785
|
+
if (existing !== -1) { starts.push(existing); continue }
|
|
1786
|
+
working.splice(insertAt, 0, { hash: parent, color: nextColor(), oldIndex: -2 })
|
|
1787
|
+
starts.push(insertAt)
|
|
1788
|
+
insertAt += 1
|
|
1789
|
+
}
|
|
1790
|
+
const survivorMap = new Map()
|
|
1791
|
+
for (let index = 0; index < working.length; index += 1) {
|
|
1792
|
+
if (working[index].oldIndex >= 0) survivorMap.set(working[index].oldIndex, index)
|
|
1793
|
+
}
|
|
1794
|
+
const newLanes = working.map(entry => ({ hash: entry.hash, color: entry.color }))
|
|
1795
|
+
const laneCount = Math.max(oldLanes.length, newLanes.length, oldNodeIndex + 1, newNodeIndex + 1, ...starts.map(index => index + 1), 1)
|
|
1796
|
+
maxLaneCount = Math.max(maxLaneCount, laneCount)
|
|
1797
|
+
rows.push({
|
|
1798
|
+
oid: row.oid, oldLanes, newLanes, oldNodeIndex, newNodeIndex, wasAwaited, joins, starts, survivorMap,
|
|
1799
|
+
nodeColor, hasFirstParent: Boolean(first), laneCount,
|
|
1800
|
+
})
|
|
1801
|
+
lanes = newLanes
|
|
1802
|
+
}
|
|
1803
|
+
return { rows, maxLaneCount }
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
/** SVG shapes for one row of the commit graph, at a given lane spacing. */
|
|
1807
|
+
function graphRowShapes(row, spacing) {
|
|
1808
|
+
const shapes = []
|
|
1809
|
+
const laneX = column => column * spacing + spacing / 2
|
|
1810
|
+
const stroke = { fill: 'none', strokeWidth: 1.8, strokeLinecap: 'round' }
|
|
1811
|
+
const mid = ROW_HEIGHT / 2
|
|
1812
|
+
const nodeX = laneX(row.newNodeIndex === -1 ? row.oldNodeIndex : row.newNodeIndex)
|
|
1813
|
+
for (const [oldIndex, newIndex] of row.survivorMap) {
|
|
1814
|
+
const color = LANE_COLORS[row.oldLanes[oldIndex].color]
|
|
1815
|
+
const x1 = laneX(oldIndex)
|
|
1816
|
+
const x2 = laneX(newIndex)
|
|
1817
|
+
if (oldIndex === newIndex) {
|
|
1818
|
+
shapes.push(h('line', { key: `p${oldIndex}`, x1, y1: 0, x2, y2: ROW_HEIGHT, stroke: color, ...stroke }))
|
|
1819
|
+
} else {
|
|
1820
|
+
shapes.push(h('path', {
|
|
1821
|
+
key: `p${oldIndex}`, d: `M ${x1} 0 C ${x1} ${mid} ${x2} ${mid} ${x2} ${ROW_HEIGHT}`,
|
|
1822
|
+
stroke: color, ...stroke,
|
|
1823
|
+
}))
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
for (const join of row.joins) {
|
|
1827
|
+
const color = LANE_COLORS[row.oldLanes[join].color]
|
|
1828
|
+
const x = laneX(join)
|
|
1829
|
+
shapes.push(h('path', {
|
|
1830
|
+
key: `j${join}`, d: `M ${x} 0 C ${x} ${mid} ${nodeX} 0 ${nodeX} ${mid}`,
|
|
1831
|
+
stroke: color, ...stroke,
|
|
1832
|
+
}))
|
|
1833
|
+
}
|
|
1834
|
+
const nodeColor = LANE_COLORS[row.nodeColor]
|
|
1835
|
+
if (row.wasAwaited) {
|
|
1836
|
+
const topX = laneX(row.oldNodeIndex)
|
|
1837
|
+
if (topX === nodeX) shapes.push(h('line', { key: 'nt', x1: nodeX, y1: 0, x2: nodeX, y2: mid, stroke: nodeColor, ...stroke }))
|
|
1838
|
+
else shapes.push(h('path', { key: 'nt', d: `M ${topX} 0 C ${topX} ${mid} ${nodeX} ${mid} ${nodeX} ${mid}`, stroke: nodeColor, ...stroke }))
|
|
1839
|
+
}
|
|
1840
|
+
if (row.hasFirstParent && row.newNodeIndex !== -1) {
|
|
1841
|
+
const firstColor = LANE_COLORS[row.newLanes[row.newNodeIndex]?.color ?? row.nodeColor]
|
|
1842
|
+
shapes.push(h('line', { key: 'nb', x1: nodeX, y1: mid, x2: nodeX, y2: ROW_HEIGHT, stroke: firstColor, ...stroke }))
|
|
1843
|
+
}
|
|
1844
|
+
for (const start of row.starts) {
|
|
1845
|
+
const color = LANE_COLORS[row.newLanes[start]?.color ?? 0]
|
|
1846
|
+
shapes.push(h('path', {
|
|
1847
|
+
key: `s${start}`,
|
|
1848
|
+
d: `M ${nodeX} ${mid} C ${nodeX} ${ROW_HEIGHT} ${laneX(start)} ${mid} ${laneX(start)} ${ROW_HEIGHT}`,
|
|
1849
|
+
stroke: color, ...stroke,
|
|
1850
|
+
}))
|
|
1851
|
+
}
|
|
1852
|
+
shapes.push(h('circle', { key: 'node', cx: nodeX, cy: mid, r: 3.4, fill: nodeColor, stroke: 'var(--dsw-alias-bg-layer-2, #111)', strokeWidth: 1.2 }))
|
|
1853
|
+
return shapes
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
/** Collapsible commit-graph drawer docked at the bottom of the workbench column. */
|
|
1857
|
+
function GraphPanel({ t, repository, width, onOpenDiff }) {
|
|
1858
|
+
const [expanded, setExpanded] = useState(false)
|
|
1859
|
+
const [height, setHeight] = useState(472)
|
|
1860
|
+
const [state, setState] = useState({ phase: 'idle', commits: [], hasMore: true })
|
|
1861
|
+
const [loadingMore, setLoadingMore] = useState(false)
|
|
1862
|
+
const [scope, setScope] = useState(() => { try { return window.localStorage.getItem('dsh-git-assistant:graph-scope') ?? 'branch' } catch { return 'branch' } })
|
|
1863
|
+
const chooseScope = value => { setScope(value); try { window.localStorage.setItem('dsh-git-assistant:graph-scope', value) } catch { /* ignore */ } }
|
|
1864
|
+
const [version, setVersion] = useState(0)
|
|
1865
|
+
const [expandedHash, setExpandedHash] = useState(undefined)
|
|
1866
|
+
const [details, setDetails] = useState({})
|
|
1867
|
+
const [hover, setHover] = useState(undefined)
|
|
1868
|
+
const hoverTimer = useRef(null)
|
|
1869
|
+
const frameRef = useRef(null)
|
|
1870
|
+
const loadCommit = hash => {
|
|
1871
|
+
if (!path) return
|
|
1872
|
+
setDetails(previous => previous[hash] ? previous : { ...previous, [hash]: { phase: 'loading' } })
|
|
1873
|
+
api('/commit', { path, hash })
|
|
1874
|
+
.then(data => setDetails(previous => ({ ...previous, [hash]: { phase: 'ready', data } })))
|
|
1875
|
+
.catch(error => setDetails(previous => ({ ...previous, [hash]: { phase: 'error', error: String(error?.message ?? error) } })))
|
|
1876
|
+
}
|
|
1877
|
+
const detailsOf = hash => details[hash]
|
|
1878
|
+
const [treeDirs, setTreeDirs] = useState({})
|
|
1879
|
+
const [fileView, setFileView] = useState(() => { try { return window.localStorage.getItem('dsh-git-assistant:graph-file-view') ?? 'tree' } catch { return 'tree' } })
|
|
1880
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
1881
|
+
const menuRef = useRef(null)
|
|
1882
|
+
const chooseFileView = view => {
|
|
1883
|
+
setFileView(view)
|
|
1884
|
+
setMenuOpen(false)
|
|
1885
|
+
try { window.localStorage.setItem('dsh-git-assistant:graph-file-view', view) } catch { /* ignore */ }
|
|
1886
|
+
}
|
|
1887
|
+
const toggleTreeDir = (hash, path) => setTreeDirs(previous => {
|
|
1888
|
+
const current = new Set(previous[hash] ?? [])
|
|
1889
|
+
if (current.has(path)) current.delete(path)
|
|
1890
|
+
else current.add(path)
|
|
1891
|
+
return { ...previous, [hash]: current }
|
|
1892
|
+
})
|
|
1893
|
+
const path = repository?.path
|
|
1894
|
+
useEffect(() => {
|
|
1895
|
+
if (!menuOpen) return undefined
|
|
1896
|
+
const close = event => { if (menuRef.current && !menuRef.current.contains(event.target)) setMenuOpen(false) }
|
|
1897
|
+
document.addEventListener('pointerdown', close)
|
|
1898
|
+
return () => document.removeEventListener('pointerdown', close)
|
|
1899
|
+
}, [menuOpen])
|
|
1900
|
+
const PAGE_SIZE = 100
|
|
1901
|
+
const loadPage = useCallback(async (skip, replace) => {
|
|
1902
|
+
if (!path) return
|
|
1903
|
+
setLoadingMore(true)
|
|
1904
|
+
if (replace) setState({ phase: 'loading', commits: [], hasMore: true })
|
|
1905
|
+
try {
|
|
1906
|
+
const data = await api('/graph', { path, limit: PAGE_SIZE, skip, scope })
|
|
1907
|
+
const rows = Array.isArray(data?.commits) ? data.commits : []
|
|
1908
|
+
setState(previous => {
|
|
1909
|
+
const base = replace ? [] : previous.commits
|
|
1910
|
+
const seen = new Set(base.map(commit => commit.oid))
|
|
1911
|
+
const merged = base.concat(rows.filter(commit => !seen.has(commit.oid)))
|
|
1912
|
+
return { phase: 'ready', commits: merged, hasMore: Boolean(data?.hasMore) && rows.length > 0, error: null }
|
|
1913
|
+
})
|
|
1914
|
+
} catch (error) {
|
|
1915
|
+
setState(previous => ({ ...previous, phase: 'error', commits: replace ? [] : previous.commits, error: String(error?.message ?? error) }))
|
|
1916
|
+
} finally { setLoadingMore(false) }
|
|
1917
|
+
}, [path, scope])
|
|
1918
|
+
useEffect(() => { if (expanded && path) loadPage(0, true) }, [expanded, path, version, scope, loadPage])
|
|
1919
|
+
const loadMore = () => {
|
|
1920
|
+
if (loadingMore || state.phase !== 'ready' || !state.hasMore) return
|
|
1921
|
+
loadPage(state.commits.length, false)
|
|
1922
|
+
}
|
|
1923
|
+
const graph = useMemo(() => computeGraphLanes(state.commits), [state.commits])
|
|
1924
|
+
const laneSpacing = Math.max(5, Math.min(LANE_WIDTH, Math.floor((width * 0.6) / Math.max(1, graph.maxLaneCount))))
|
|
1925
|
+
const startDrag = event => {
|
|
1926
|
+
event.preventDefault()
|
|
1927
|
+
const startY = event.clientY
|
|
1928
|
+
const startHeight = height
|
|
1929
|
+
const move = moveEvent => setHeight(Math.min(620, Math.max(140, startHeight + (startY - moveEvent.clientY))))
|
|
1930
|
+
const stop = () => {
|
|
1931
|
+
document.removeEventListener('pointermove', move)
|
|
1932
|
+
document.removeEventListener('pointerup', stop)
|
|
1933
|
+
document.body.style.cursor = ''
|
|
1934
|
+
document.body.style.userSelect = ''
|
|
1935
|
+
}
|
|
1936
|
+
document.body.style.cursor = 'row-resize'
|
|
1937
|
+
document.body.style.userSelect = 'none'
|
|
1938
|
+
document.addEventListener('pointermove', move)
|
|
1939
|
+
document.addEventListener('pointerup', stop)
|
|
1940
|
+
}
|
|
1941
|
+
const frameStyle = {
|
|
1942
|
+
position: 'absolute', left: 20, bottom: 18, width: Math.max(140, width - 16), zIndex: 40,
|
|
1943
|
+
borderRadius: T.rMd, background: T.surface, boxShadow: T.edgeStrong, overflow: 'hidden',
|
|
1944
|
+
display: 'flex', flexDirection: 'column',
|
|
1945
|
+
height: expanded ? height : 30,
|
|
1946
|
+
transition: 'height .18s ' + T.ease,
|
|
1947
|
+
}
|
|
1948
|
+
const header = h('div', {
|
|
1949
|
+
onClick: () => setExpanded(value => !value),
|
|
1950
|
+
style: { display: 'flex', alignItems: 'center', gap: 7, minHeight: 30, padding: '0 10px', cursor: 'pointer', flex: '0 0 auto', borderBottom: expanded ? `1px solid ${T.borderSoft}` : 'none' },
|
|
1951
|
+
},
|
|
1952
|
+
h(Chevron, { open: expanded, size: 9 }),
|
|
1953
|
+
h('span', { style: { fontSize: 11.5, fontWeight: 600, color: T.ink2 } }, t('graphTitle')),
|
|
1954
|
+
h('span', { style: { flex: 1 } }),
|
|
1955
|
+
expanded ? h(IconAction, { label: t('refresh'), onClick: event => { event.stopPropagation(); setVersion(value => value + 1) } }, h(RefreshIcon, {})) : null,
|
|
1956
|
+
expanded ? h('div', {
|
|
1957
|
+
ref: menuRef, style: { position: 'relative', display: 'inline-flex' },
|
|
1958
|
+
onClick: event => event.stopPropagation(),
|
|
1959
|
+
},
|
|
1960
|
+
h('button', {
|
|
1961
|
+
type: 'button', title: t('graphOptions'), onClick: event => { event.stopPropagation(); setMenuOpen(open => !open) },
|
|
1962
|
+
style: {
|
|
1963
|
+
appearance: 'none', border: 'none', background: menuOpen ? T.hover : 'transparent', color: T.muted,
|
|
1964
|
+
width: 22, height: 22, borderRadius: T.rSm, cursor: 'pointer', fontSize: 14, lineHeight: '18px', padding: 0,
|
|
1965
|
+
},
|
|
1966
|
+
}, '⋯'),
|
|
1967
|
+
menuOpen ? h('div', {
|
|
1968
|
+
style: {
|
|
1969
|
+
position: 'absolute', top: '100%', right: 0, marginTop: 4, zIndex: 80, width: 170,
|
|
1970
|
+
background: T.menu, border: `0.5px solid ${T.border}`, borderRadius: T.rMd, padding: 4,
|
|
1971
|
+
boxShadow: T.shadowProminent, backdropFilter: 'blur(24px) saturate(160%)',
|
|
1972
|
+
},
|
|
1973
|
+
},
|
|
1974
|
+
h('div', { style: { padding: '4px 8px 3px', fontSize: 10, color: T.subtle } }, t('commitScope')),
|
|
1975
|
+
...[['branch', t('currentBranch')], ['all', t('allRefs')]].map(([value, label]) => h('button', {
|
|
1976
|
+
key: `scope-${value}`, type: 'button', onClick: () => chooseScope(value),
|
|
1977
|
+
style: {
|
|
1978
|
+
appearance: 'none', border: 'none', width: '100%', textAlign: 'left', cursor: 'pointer',
|
|
1979
|
+
background: 'transparent', color: 'inherit', padding: '5px 8px', borderRadius: T.rSm, fontSize: 12,
|
|
1980
|
+
display: 'flex', alignItems: 'center', gap: 6,
|
|
1981
|
+
},
|
|
1982
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
1983
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
1984
|
+
},
|
|
1985
|
+
h('span', { style: { width: 12, color: T.success } }, scope === value ? '✓' : ''),
|
|
1986
|
+
h('span', null, label))),
|
|
1987
|
+
h('div', { style: { height: 1, background: T.borderSoft, margin: '4px 6px' } }),
|
|
1988
|
+
h('div', { style: { padding: '4px 8px 3px', fontSize: 10, color: T.subtle } }, t('fileDisplayMode')),
|
|
1989
|
+
...[['tree', t('viewTree')], ['list', t('viewList')]].map(([value, label]) => h('button', {
|
|
1990
|
+
key: value, type: 'button', onClick: () => chooseFileView(value),
|
|
1991
|
+
style: {
|
|
1992
|
+
appearance: 'none', border: 'none', width: '100%', textAlign: 'left', cursor: 'pointer',
|
|
1993
|
+
background: 'transparent', color: 'inherit', padding: '5px 8px', borderRadius: T.rSm, fontSize: 12,
|
|
1994
|
+
display: 'flex', alignItems: 'center', gap: 6,
|
|
1995
|
+
},
|
|
1996
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
1997
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
1998
|
+
},
|
|
1999
|
+
h('span', { style: { width: 12, color: T.success } }, fileView === value ? '✓' : ''),
|
|
2000
|
+
h('span', null, label)))) : null) : null)
|
|
2001
|
+
if (!expanded) return h('div', { style: frameStyle }, header)
|
|
2002
|
+
const body = state.phase === 'loading'
|
|
2003
|
+
? h('div', { style: { padding: '8px 12px', fontSize: 11, color: T.muted } }, t('graphLoading'))
|
|
2004
|
+
: state.phase === 'error'
|
|
2005
|
+
? h('div', { style: { padding: '8px 12px', fontSize: 11, color: T.error } }, state.error)
|
|
2006
|
+
: state.commits.length === 0
|
|
2007
|
+
? h('div', { style: { padding: '8px 12px', fontSize: 11, color: T.muted } }, t('graphEmpty'))
|
|
2008
|
+
: [
|
|
2009
|
+
...state.commits.flatMap((commit, index) => {
|
|
2010
|
+
const row = graph.rows[index]
|
|
2011
|
+
const detail = detailsOf(commit.oid)
|
|
2012
|
+
const isOpen = expandedHash === commit.oid
|
|
2013
|
+
const rowWidth = Math.max(1, row ? row.laneCount : 1) * laneSpacing
|
|
2014
|
+
const rowEl = h('div', {
|
|
2015
|
+
key: commit.oid,
|
|
2016
|
+
onClick: () => {
|
|
2017
|
+
setExpandedHash(previous => previous === commit.oid ? undefined : commit.oid)
|
|
2018
|
+
if (!isOpen) loadCommit(commit.oid)
|
|
2019
|
+
},
|
|
2020
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, height: ROW_HEIGHT, padding: '0 10px', fontSize: 11.5, cursor: 'pointer', background: isOpen ? T.selected : 'transparent' },
|
|
2021
|
+
onMouseEnter: event => {
|
|
2022
|
+
event.currentTarget.style.background = isOpen ? T.selected : T.hover
|
|
2023
|
+
const target = event.currentTarget
|
|
2024
|
+
clearTimeout(hoverTimer.current)
|
|
2025
|
+
hoverTimer.current = setTimeout(() => {
|
|
2026
|
+
const box = frameRef.current?.getBoundingClientRect()
|
|
2027
|
+
if (!box || !target.isConnected) return
|
|
2028
|
+
const rect = target.getBoundingClientRect()
|
|
2029
|
+
setHover({ hash: commit.oid, commit, top: rect.bottom - box.top + 4 })
|
|
2030
|
+
}, 350)
|
|
2031
|
+
},
|
|
2032
|
+
onMouseLeave: event => { event.currentTarget.style.background = isOpen ? T.selected : 'transparent'; clearTimeout(hoverTimer.current); setHover(undefined) },
|
|
2033
|
+
},
|
|
2034
|
+
h('svg', {
|
|
2035
|
+
width: rowWidth, height: ROW_HEIGHT, viewBox: `0 0 ${rowWidth} ${ROW_HEIGHT}`,
|
|
2036
|
+
style: { flex: '0 0 auto', overflow: 'visible' },
|
|
2037
|
+
}, row ? graphRowShapes(row, laneSpacing) : null),
|
|
2038
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: T.ink2 } }, commit.subject || commit.oid.slice(0, 7)),
|
|
2039
|
+
h('span', { style: { fontFamily: MONO, fontSize: 9.5, color: T.subtle } }, commit.oid.slice(0, 7)))
|
|
2040
|
+
|
|
2041
|
+
const filesBlock = isOpen
|
|
2042
|
+
? (() => {
|
|
2043
|
+
const continuing = row
|
|
2044
|
+
? row.newLanes.map((lane, index) => (lane?.hash ? { index, color: lane.color } : null)).filter(Boolean)
|
|
2045
|
+
: []
|
|
2046
|
+
const ready = detail?.phase === 'ready'
|
|
2047
|
+
const fileList = ready ? detail.data.files : []
|
|
2048
|
+
const tree = ready ? fileRows(fileList.map(file => ({ path: file.path, status: file.status }))) : null
|
|
2049
|
+
const statusMap = new Map(fileList.map(file => [file.path, file.status]))
|
|
2050
|
+
return h('div', {
|
|
2051
|
+
key: `${commit.oid}:files`,
|
|
2052
|
+
style: { display: 'flex', alignItems: 'stretch', padding: '2px 10px 8px 10px', background: 'color-mix(in srgb, var(--dsw-alias-bg-layer-1, currentColor) 26%, transparent)' },
|
|
2053
|
+
},
|
|
2054
|
+
h('div', { style: { position: 'relative', flex: '0 0 auto', width: rowWidth } },
|
|
2055
|
+
...continuing.map(lane => h('span', {
|
|
2056
|
+
key: `lane-${lane.index}`,
|
|
2057
|
+
style: {
|
|
2058
|
+
position: 'absolute', top: 0, bottom: 0, left: lane.index * laneSpacing + laneSpacing / 2 - 1, width: 2,
|
|
2059
|
+
background: laneColor(lane.color), borderRadius: 1,
|
|
2060
|
+
},
|
|
2061
|
+
}))),
|
|
2062
|
+
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 2, paddingLeft: 2 } },
|
|
2063
|
+
h('div', { style: { fontSize: 10.5, color: T.muted, padding: '2px 0 3px' } },
|
|
2064
|
+
ready ? t('statsFiles', { count: detail.data.stats.files }) : t('loading'),
|
|
2065
|
+
ready ? h('span', { style: { color: T.success, marginLeft: 6 } }, `+${detail.data.stats.additions}`) : null,
|
|
2066
|
+
ready ? h('span', { style: { color: T.error, marginLeft: 6 } }, `−${detail.data.stats.deletions}`) : null),
|
|
2067
|
+
detail?.phase === 'error'
|
|
2068
|
+
? h('div', { style: { fontSize: 10.5, color: T.error } }, detail.error)
|
|
2069
|
+
: ready
|
|
2070
|
+
? (fileView === 'tree'
|
|
2071
|
+
? h(TreeRows, {
|
|
2072
|
+
node: tree, depth: 0,
|
|
2073
|
+
expandedDirs: treeDirs[commit.oid] ?? new Set(),
|
|
2074
|
+
onToggleDir: path => toggleTreeDir(commit.oid, path),
|
|
2075
|
+
onOpen: file => onOpenDiff?.(commit.oid, file.path),
|
|
2076
|
+
selectedKey: undefined, actionsFor: null,
|
|
2077
|
+
statusByPath: statusMap, showStatus: true,
|
|
2078
|
+
hoveredKey: undefined, onHoverKey: () => {},
|
|
2079
|
+
})
|
|
2080
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 1 } },
|
|
2081
|
+
...fileList.map(file => h('div', {
|
|
2082
|
+
key: file.path,
|
|
2083
|
+
onClick: event => { event.stopPropagation(); onOpenDiff?.(commit.oid, file.path) },
|
|
2084
|
+
title: file.path,
|
|
2085
|
+
style: { display: 'flex', alignItems: 'center', gap: 6, minHeight: 20, padding: '0 6px', borderRadius: T.rSm, cursor: 'pointer', fontSize: 11.5 },
|
|
2086
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
2087
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
2088
|
+
},
|
|
2089
|
+
h(StatusChip, { status: file.status ?? 'M', size: 14 }),
|
|
2090
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: T.ink2 } }, file.path),
|
|
2091
|
+
h('span', { style: { fontFamily: MONO, fontSize: 9.5, color: T.success } }, `+${file.additions}`),
|
|
2092
|
+
h('span', { style: { fontFamily: MONO, fontSize: 9.5, color: T.error } }, `−${file.deletions}`)))))
|
|
2093
|
+
: null))
|
|
2094
|
+
})()
|
|
2095
|
+
: null
|
|
2096
|
+
return [rowEl, filesBlock]
|
|
2097
|
+
}),
|
|
2098
|
+
loadingMore
|
|
2099
|
+
? h('div', { key: 'graph-more', style: { padding: '6px 12px', fontSize: 10.5, color: T.muted } }, t('graphLoading'))
|
|
2100
|
+
: null,
|
|
2101
|
+
]
|
|
2102
|
+
const hoverDetail = hover ? detailsOf(hover.hash) : undefined
|
|
2103
|
+
const hoverCard = hover
|
|
2104
|
+
? h('div', {
|
|
2105
|
+
style: {
|
|
2106
|
+
position: 'absolute', left: 12, top: hover.top, zIndex: 60, width: Math.min(420, width - 24),
|
|
2107
|
+
maxHeight: 240, overflowY: 'auto', pointerEvents: 'none',
|
|
2108
|
+
background: T.menu, border: `0.5px solid ${T.border}`, borderRadius: T.rMd,
|
|
2109
|
+
boxShadow: T.shadowProminent, backdropFilter: 'blur(24px) saturate(160%)', padding: '10px 12px',
|
|
2110
|
+
},
|
|
2111
|
+
},
|
|
2112
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
2113
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: T.muted, flexWrap: 'wrap' } },
|
|
2114
|
+
h('span', null, hover.commit.author || t('unknownAuthor')),
|
|
2115
|
+
h('span', null, '·'),
|
|
2116
|
+
h('span', null, new Date(hover.commit.time * 1000).toLocaleString()),
|
|
2117
|
+
h('span', { style: { flex: 1 } }),
|
|
2118
|
+
h('span', { style: { fontFamily: MONO, color: T.subtle } }, hover.hash.slice(0, 7))),
|
|
2119
|
+
h('div', { style: { fontSize: 12, fontWeight: 600, color: T.ink2, whiteSpace: 'pre-wrap' } }, hover.commit.subject || hover.commit.oid.slice(0, 7)),
|
|
2120
|
+
hover.commit.body
|
|
2121
|
+
? h('div', { style: { fontSize: 11.5, color: T.muted, whiteSpace: 'pre-wrap', maxHeight: 110, overflow: 'hidden' } }, hover.commit.body)
|
|
2122
|
+
: null,
|
|
2123
|
+
(hover.commit.refs ?? []).length > 0
|
|
2124
|
+
? h('div', { style: { display: 'flex', gap: 4, flexWrap: 'wrap' } },
|
|
2125
|
+
...hover.commit.refs.map(ref => h('span', {
|
|
2126
|
+
key: ref,
|
|
2127
|
+
style: { fontSize: 9.5, fontFamily: MONO, color: '#a78bfa', background: 'color-mix(in srgb, #a78bfa 16%, transparent)', padding: '0 6px', borderRadius: 999, whiteSpace: 'nowrap' },
|
|
2128
|
+
}, ref)))
|
|
2129
|
+
: null,
|
|
2130
|
+
hover.commit.stats
|
|
2131
|
+
? h('div', { style: { fontSize: 11, color: T.muted } },
|
|
2132
|
+
t('statsFiles', { count: hover.commit.stats.files }),
|
|
2133
|
+
h('span', { style: { color: T.success, marginLeft: 6 } }, `+${hover.commit.stats.additions}`),
|
|
2134
|
+
h('span', { style: { color: T.error, marginLeft: 6 } }, `−${hover.commit.stats.deletions}`))
|
|
2135
|
+
: null))
|
|
2136
|
+
: null
|
|
2137
|
+
return h('div', { ref: frameRef, style: frameStyle },
|
|
2138
|
+
h('div', { onPointerDown: startDrag, style: { flex: '0 0 auto', height: 6, cursor: 'row-resize', display: 'flex', justifyContent: 'center', alignItems: 'center' } },
|
|
2139
|
+
h('span', { style: { width: 34, height: 2, borderRadius: 2, background: T.borderSoft } })),
|
|
2140
|
+
header,
|
|
2141
|
+
h('div', {
|
|
2142
|
+
onScroll: event => {
|
|
2143
|
+
const element = event.currentTarget
|
|
2144
|
+
if (element.scrollHeight - element.scrollTop - element.clientHeight < 160) loadMore()
|
|
2145
|
+
},
|
|
2146
|
+
style: { flex: 1, minHeight: 0, overflowY: 'auto', paddingBottom: 6 },
|
|
2147
|
+
}, body),
|
|
2148
|
+
hoverCard)
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
/** Isolates one card's render failure so the panel never goes blank. */
|
|
2152
|
+
class CardBoundary extends React.Component {
|
|
2153
|
+
constructor(props) { super(props); this.state = { error: null } }
|
|
2154
|
+
static getDerivedStateFromError(error) { return { error } }
|
|
2155
|
+
render() {
|
|
2156
|
+
if (this.state.error) {
|
|
2157
|
+
return h('div', { style: { margin: '6px 8px', padding: '6px 10px', fontSize: 10.5, color: T.error, border: `0.5px solid ${T.border}`, borderRadius: T.rSm } },
|
|
2158
|
+
t('cardRenderFailed', { error: String(this.state.error?.message ?? this.state.error) }))
|
|
2159
|
+
}
|
|
2160
|
+
return this.props.children
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
class PanelBoundary extends React.Component {
|
|
2165
|
+
constructor(props) { super(props); this.state = { error: null } }
|
|
2166
|
+
static getDerivedStateFromError(error) { return { error } }
|
|
2167
|
+
render() {
|
|
2168
|
+
if (this.state.error) {
|
|
2169
|
+
const t = this.props.t ?? (key => key)
|
|
2170
|
+
return h('div', {
|
|
2171
|
+
style: {
|
|
2172
|
+
flex: 1, minHeight: 200, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
|
|
2173
|
+
gap: 10, padding: 24, textAlign: 'center', color: T.muted, fontSize: 12,
|
|
2174
|
+
},
|
|
2175
|
+
},
|
|
2176
|
+
h('div', { style: { fontSize: 13, color: T.error, maxWidth: 480, lineHeight: '20px' } },
|
|
2177
|
+
t('panelRenderFailed', { error: String(this.state.error?.message ?? this.state.error) })),
|
|
2178
|
+
h('button', {
|
|
2179
|
+
type: 'button',
|
|
2180
|
+
onClick: () => this.setState({ error: null }),
|
|
2181
|
+
style: {
|
|
2182
|
+
appearance: 'none', border: `0.5px solid ${T.border}`, borderRadius: T.pill,
|
|
2183
|
+
padding: '4px 14px', fontSize: 11.5, cursor: 'pointer', background: T.hover, color: T.ink2,
|
|
2184
|
+
},
|
|
2185
|
+
}, t('retry')))
|
|
2186
|
+
}
|
|
2187
|
+
return this.props.children
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
const IMAGE_PATH_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'avif', 'svg'])
|
|
2192
|
+
function isImagePath(path) {
|
|
2193
|
+
const extension = String(path).split('.').pop()?.toLowerCase()
|
|
2194
|
+
return IMAGE_PATH_EXTENSIONS.has(extension)
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
/** Right-click menu rendered in a body-level layer (no ancestor clipping / fixed containing blocks). */
|
|
2198
|
+
function openFileContextMenu({ x, y, items }) {
|
|
2199
|
+
const menu = document.createElement('div')
|
|
2200
|
+
menu.setAttribute('role', 'menu')
|
|
2201
|
+
// DSH 0.2.2-rc.2: macOS desktop only excludes interactive controls inside declared window regions.
|
|
2202
|
+
menu.setAttribute('data-window-drag-exclude', '')
|
|
2203
|
+
menu.style.cssText = [
|
|
2204
|
+
'position:fixed', 'z-index:9999', 'min-width:190px', 'max-width:280px', 'padding:4px',
|
|
2205
|
+
'border-radius:10px', 'background:var(--dsw-alias-bg-layer-2, #1b1b20)',
|
|
2206
|
+
'border:0.5px solid var(--dsw-alias-border-l2, rgba(255,255,255,.14))',
|
|
2207
|
+
'box-shadow:0 18px 48px rgba(0,0,0,.35)', 'backdrop-filter:blur(24px) saturate(160%)',
|
|
2208
|
+
'font-size:12px', 'color:var(--dsw-alias-label-primary, #e6e6ea)',
|
|
2209
|
+
'font-family:var(--dsw-font-family, -apple-system, sans-serif)', 'line-height:1.5',
|
|
2210
|
+
].join(';')
|
|
2211
|
+
menu.style.left = `${x}px`
|
|
2212
|
+
menu.style.top = `${y}px`
|
|
2213
|
+
const close = () => {
|
|
2214
|
+
document.removeEventListener('pointerdown', onPointer, true)
|
|
2215
|
+
document.removeEventListener('keydown', onKeydown)
|
|
2216
|
+
window.removeEventListener('scroll', close, true)
|
|
2217
|
+
window.removeEventListener('resize', close)
|
|
2218
|
+
menu.remove()
|
|
2219
|
+
}
|
|
2220
|
+
const onPointer = event => { if (!menu.contains(event.target)) close() }
|
|
2221
|
+
const onKeydown = event => { if (event.key === 'Escape') close() }
|
|
2222
|
+
for (const entry of items) {
|
|
2223
|
+
if (entry.separator) {
|
|
2224
|
+
const line = document.createElement('div')
|
|
2225
|
+
line.style.cssText = 'height:1px;margin:4px 6px;background:var(--dsw-alias-border-l2, rgba(255,255,255,.12))'
|
|
2226
|
+
menu.appendChild(line)
|
|
2227
|
+
continue
|
|
2228
|
+
}
|
|
2229
|
+
const button = document.createElement('button')
|
|
2230
|
+
button.type = 'button'
|
|
2231
|
+
button.textContent = entry.label
|
|
2232
|
+
button.style.cssText = [
|
|
2233
|
+
'appearance:none', 'border:none', 'background:transparent', 'color:inherit', 'width:100%',
|
|
2234
|
+
'text-align:left', 'cursor:pointer', 'padding:6px 10px', 'border-radius:6px', 'font:inherit',
|
|
2235
|
+
].join(';')
|
|
2236
|
+
button.addEventListener('mouseenter', () => { button.style.background = 'var(--dsw-alias-interactive-bg-hover, rgba(255,255,255,.08))' })
|
|
2237
|
+
button.addEventListener('mouseleave', () => { button.style.background = 'transparent' })
|
|
2238
|
+
button.addEventListener('click', () => { close(); try { entry.onClick() } catch { /* ignore */ } })
|
|
2239
|
+
menu.appendChild(button)
|
|
2240
|
+
}
|
|
2241
|
+
document.body.appendChild(menu)
|
|
2242
|
+
const bounds = menu.getBoundingClientRect()
|
|
2243
|
+
menu.style.left = `${Math.max(8, Math.min(x, window.innerWidth - bounds.width - 8))}px`
|
|
2244
|
+
menu.style.top = `${Math.max(8, Math.min(y, window.innerHeight - bounds.height - 8))}px`
|
|
2245
|
+
document.addEventListener('pointerdown', onPointer, true)
|
|
2246
|
+
document.addEventListener('keydown', onKeydown)
|
|
2247
|
+
window.addEventListener('scroll', close, true)
|
|
2248
|
+
window.addEventListener('resize', close)
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
/** One worktree's file browser, mirroring the changes cards. */
|
|
2252
|
+
/* Icons: Material Icon Theme (MIT, https://github.com/material-extensions/vscode-material-icon-theme) */
|
|
2253
|
+
const FILE_ICONS = {
|
|
2254
|
+
"audio": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ef5350\" d=\"M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2m6 10h-4v8a4 4 0 1 1-4-4 3.96 3.96 0 0 1 2 .555V8h6Z\"/></svg>",
|
|
2255
|
+
"console": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#ff7043\" d=\"M2 2a1 1 0 0 0-1 1v10c0 .554.446 1 1 1h12c.554 0 1-.446 1-1V3a1 1 0 0 0-1-1zm0 3h12v8H2zm1 2 2 2-2 2 1 1 3-3-3-3zm5 3.5V12h5v-1.5z\"/></svg>",
|
|
2256
|
+
"csharp": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M30 14v-2h-2V8h-2v4h-2V8h-2v4h-2v2h2v2h-2v2h2v4h2v-4h2v4h2v-4h2v-2h-2v-2Zm-4 2h-2v-2h2Zm-12.437 6A5.57 5.57 0 0 1 8 16.437v-2.873A5.57 5.57 0 0 1 13.563 8H18V2h-4.437A11.563 11.563 0 0 0 2 13.563v2.873A11.564 11.564 0 0 0 13.563 28H18v-6Z\"/></svg>",
|
|
2257
|
+
"css": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#7e57c2\" d=\"M20 18h-2v-2h-2v2c0 .193 0 .703 1.254 1.033A3.345 3.345 0 0 1 20 22h2v2h2v-2c0-.388-.562-.851-1.254-1.034C20.356 20.34 20 18.84 20 18m-3.254 2.966C14.356 20.34 14 18.84 14 18h-2v-2h-2v8h2v-2h4v2h2v-2c0-.388-.562-.851-1.254-1.034\"/><path fill=\"#7e57c2\" d=\"M24 4H4v20a4 4 0 0 0 4 4h16.16A3.84 3.84 0 0 0 28 24.16V8a4 4 0 0 0-4-4m2 14h-2v-2h-2v2c0 .193 0 .703 1.254 1.033A3.345 3.345 0 0 1 26 22v2a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2 2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2 2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2 2 2 0 0 1 2-2h2a2 2 0 0 1 2 2 2 2 0 0 1 2-2h2a2 2 0 0 1 2 2Z\"/></svg>",
|
|
2258
|
+
"database": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ffca28\" d=\"M16 24c-5.525 0-10-.9-10-2v4c0 1.1 4.475 2 10 2s10-.9 10-2v-4c0 1.1-4.475 2-10 2m0-8c-5.525 0-10-.9-10-2v4c0 1.1 4.475 2 10 2s10-.9 10-2v-4c0 1.1-4.475 2-10 2m0-12C10.477 4 6 4.895 6 6v4c0 1.1 4.475 2 10 2s10-.9 10-2V6c0-1.105-4.477-2-10-2\"/></svg>",
|
|
2259
|
+
"docker": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M21.81 10.25c-.06-.04-.56-.43-1.64-.43-.28 0-.56.03-.84.08-.21-1.4-1.38-2.11-1.43-2.14l-.29-.17-.18.27c-.24.36-.43.77-.51 1.19-.2.8-.08 1.56.33 2.21-.49.28-1.29.35-1.46.35H2.62c-.34 0-.62.28-.62.63 0 1.15.18 2.3.58 3.38.45 1.19 1.13 2.07 2 2.61.98.6 2.59.94 4.42.94.79 0 1.61-.07 2.42-.22 1.12-.2 2.2-.59 3.19-1.16A8.3 8.3 0 0 0 16.78 16c1.05-1.17 1.67-2.5 2.12-3.65h.19c1.14 0 1.85-.46 2.24-.85.26-.24.45-.53.59-.87l.08-.24zm-17.96.99h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H3.85c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.43 0h1.76c.08 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16H6.28c-.09 0-.16.07-.16.16v1.58c.01.09.07.16.16.16m2.47 0h1.75c.1 0 .17-.07.17-.16V9.5c0-.08-.06-.16-.17-.16H8.75c-.08 0-.15.07-.15.16v1.58c0 .09.06.16.15.16m2.44 0h1.77c.08 0 .15-.07.15-.16V9.5c0-.08-.06-.16-.15-.16h-1.77c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16M6.28 9h1.76c.08 0 .16-.09.16-.18V7.25c0-.09-.07-.16-.16-.16H6.28c-.09 0-.16.06-.16.16v1.57c.01.09.07.18.16.18m2.47 0h1.75c.1 0 .17-.09.17-.18V7.25c0-.09-.06-.16-.17-.16H8.75c-.08 0-.15.06-.15.16v1.57c0 .09.06.18.15.18m2.44 0h1.77c.08 0 .15-.09.15-.18V7.25c0-.09-.07-.16-.15-.16h-1.77c-.08 0-.15.06-.15.16v1.57c0 .09.07.18.15.18m0-2.28h1.77c.08 0 .15-.07.15-.16V5c0-.1-.07-.17-.15-.17h-1.77c-.08 0-.15.06-.15.17v1.56c0 .08.07.16.15.16m2.46 4.52h1.76c.09 0 .16-.07.16-.16V9.5c0-.08-.07-.16-.16-.16h-1.76c-.08 0-.15.07-.15.16v1.58c0 .09.07.16.15.16\"/></svg>",
|
|
2260
|
+
"document": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M0 0h24v24H0z\"/><path fill=\"#42a5f5\" d=\"M8 16h8v2H8zm0-4h8v2H8zm6-10H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8zm4 18H6V4h7v5h5z\"/></svg>",
|
|
2261
|
+
"file": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path d=\"m8.668 6h3.6641l-3.6641-3.668v3.668m-4.668-4.668h5.332l4 4v8c0 0.73828-0.59375 1.3359-1.332 1.3359h-8c-0.73828 0-1.332-0.59766-1.332-1.3359v-10.664c0-0.74219 0.59375-1.3359 1.332-1.3359m3.332 1.3359h-3.332v10.664h8v-6h-4.668z\" fill=\"#90a4ae\" /></svg>",
|
|
2262
|
+
"folder": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path d=\"m6.922 3.768-.644-.536A1 1 0 0 0 5.638 3H2a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1H7.562a1 1 0 0 1-.64-.232\" fill=\"#90a4ae\" /></svg>",
|
|
2263
|
+
"folder-open": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path d=\"M14.483 6H4.721a1 1 0 0 0-.949.684L2 12V5h12a1 1 0 0 0-1-1H7.562a1 1 0 0 1-.64-.232l-.644-.536A1 1 0 0 0 5.638 3H2a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h11l2.403-5.606A1 1 0 0 0 14.483 6\" fill=\"#90a4ae\" /></svg>",
|
|
2264
|
+
"git": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#e64a19\" d=\"M13.172 2.828 11.78 4.22l1.91 1.91 2 2A2.986 2.986 0 0 1 20 10.81a3.25 3.25 0 0 1-.31 1.31l2.06 2a2.68 2.68 0 0 1 3.37.57 2.86 2.86 0 0 1 .88 2.117 3.02 3.02 0 0 1-.856 2.109A2.9 2.9 0 0 1 23 19.81a2.93 2.93 0 0 1-2.13-.87 2.694 2.694 0 0 1-.56-3.38l-2-2.06a3 3 0 0 1-.31.12V20a3 3 0 0 1 1.44 1.09 2.92 2.92 0 0 1 .56 1.72 2.88 2.88 0 0 1-.878 2.128 2.98 2.98 0 0 1-2.048.871 2.981 2.981 0 0 1-2.514-4.719A3 3 0 0 1 16 20v-6.38a2.96 2.96 0 0 1-1.44-1.09 2.9 2.9 0 0 1-.56-1.72 2.9 2.9 0 0 1 .31-1.31l-3.9-3.9-7.579 7.572a4 4 0 0 0-.001 5.658l10.342 10.342a4 4 0 0 0 5.656 0l10.344-10.344a4 4 0 0 0 0-5.656L18.828 2.828a4 4 0 0 0-5.656 0\"/></svg>",
|
|
2265
|
+
"go": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#00acc1\" d=\"M2 12h4v2H2zm-2 4h6v2H0zm4 4h2v2H4zm16.954-5H14v3h3.239a4.42 4.42 0 0 1-3.531 2 2.65 2.65 0 0 1-2.053-.858 2.86 2.86 0 0 1-.628-2.28A4.515 4.515 0 0 1 15.292 13a2.73 2.73 0 0 1 1.749.584l2.962-1.185A5.6 5.6 0 0 0 15.292 10a7.526 7.526 0 0 0-7.243 6.5 5.614 5.614 0 0 0 5.659 6.5 7.526 7.526 0 0 0 7.243-6.5 6.4 6.4 0 0 0 .003-1.5\"/><path fill=\"#00acc1\" d=\"M26.292 10a7.526 7.526 0 0 0-7.243 6.5 5.614 5.614 0 0 0 5.659 6.5 7.526 7.526 0 0 0 7.243-6.5 5.614 5.614 0 0 0-5.659-6.5m2.681 6.137A4.515 4.515 0 0 1 24.708 20a2.65 2.65 0 0 1-2.053-.858 2.86 2.86 0 0 1-.628-2.28A4.515 4.515 0 0 1 26.292 13a2.65 2.65 0 0 1 2.053.858 2.86 2.86 0 0 1 .628 2.28Z\"/></svg>",
|
|
2266
|
+
"graphql": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ec407a\" d=\"M6 20h20v2H6z\"/><circle cx=\"7\" cy=\"21\" r=\"3\" fill=\"#ec407a\"/><circle cx=\"16\" cy=\"27\" r=\"3\" fill=\"#ec407a\"/><circle cx=\"25\" cy=\"21\" r=\"3\" fill=\"#ec407a\"/><path fill=\"#ec407a\" d=\"M6 10h20v2H6z\"/><circle cx=\"7\" cy=\"11\" r=\"3\" fill=\"#ec407a\"/><circle cx=\"16\" cy=\"5\" r=\"3\" fill=\"#ec407a\"/><circle cx=\"25\" cy=\"11\" r=\"3\" fill=\"#ec407a\"/><path fill=\"#ec407a\" d=\"M6 12h2v10H6zm18-2h2v12h-2z\"/><path fill=\"#ec407a\" d=\"m5.014 19.41 11.674 6.866L15.674 28 4 21.134z\"/><path fill=\"#ec407a\" d=\"M26.688 21.724 15.014 28.59 14 26.866 25.674 20zM5.124 10.382l11.415-7.29 1.077 1.686L6.2 12.068z\"/><path fill=\"#ec407a\" d=\"m25.798 12.067-11.415-7.29 1.077-1.685 11.415 7.29zM6.2 19.932l11.416 7.29-1.077 1.686-11.415-7.29z\"/><path fill=\"#ec407a\" d=\"m26.875 21.619-11.415 7.29-1.077-1.687 11.415-7.289zM5.877 22.6 16.04 3.686l1.762.946L7.638 23.546z\"/><path fill=\"#ec407a\" d=\"M24.361 23.545 14.197 4.633l1.761-.947 10.165 18.913z\"/></svg>",
|
|
2267
|
+
"hex": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#26a69a\" d=\"M4 8v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2m4 14V10h4v12Zm11.999-6L18 18.001 21 21l-3 3.001L19.999 26l3.003-3 3 2.999L28 24l-3-2.999 3-3L26.001 16l-3 3z\"/></svg>",
|
|
2268
|
+
"html": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#e65100\" d=\"m4 4 2 22 10 2 10-2 2-22Zm19.72 7H11.28l.29 3h11.86l-.802 9.335L15.99 25l-6.635-1.646L8.93 19h3.02l.19 2 3.86.77 3.84-.77.29-4H8.84L8 8h16Z\"/></svg>",
|
|
2269
|
+
"image": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#26a69a\" d=\"M8.5 6h4l-4-4zM3.875 1H9.5l4 4v8.6c0 .773-.616 1.4-1.375 1.4h-8.25c-.76 0-1.375-.627-1.375-1.4V2.4c0-.777.612-1.4 1.375-1.4M4 13.6h8V8l-2.625 2.8L8 9.4zm1.25-7.7c-.76 0-1.375.627-1.375 1.4s.616 1.4 1.375 1.4c.76 0 1.375-.627 1.375-1.4S6.009 5.9 5.25 5.9\"/></svg>",
|
|
2270
|
+
"java": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#f44336\" d=\"M4 26h24v2H4zM28 4H7a1 1 0 0 0-1 1v13a4 4 0 0 0 4 4h10a4 4 0 0 0 4-4v-4h4a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2m0 8h-4V6h4Z\"/></svg>",
|
|
2271
|
+
"javascript": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#ffca28\" d=\"M2 2v12h12V2zm6 6h1v4a1.003 1.003 0 0 1-1 1H7a1.003 1.003 0 0 1-1-1v-1h1v1h1zm3 0h2v1h-2v1h1a1.003 1.003 0 0 1 1 1v1a1.003 1.003 0 0 1-1 1h-2v-1h2v-1h-1a1.003 1.003 0 0 1-1-1V9a1.003 1.003 0 0 1 1-1\"/></svg>",
|
|
2272
|
+
"json": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 -960 960 960\" width=\"14\" height=\"14\"><path fill=\"#f9a825\" d=\"M560-160v-80h120q17 0 28.5-11.5T720-280v-80q0-38 22-69t58-44v-14q-36-13-58-44t-22-69v-80q0-17-11.5-28.5T680-720H560v-80h120q50 0 85 35t35 85v80q0 17 11.5 28.5T840-560h40v160h-40q-17 0-28.5 11.5T800-360v80q0 50-35 85t-85 35zm-280 0q-50 0-85-35t-35-85v-80q0-17-11.5-28.5T120-400H80v-160h40q17 0 28.5-11.5T160-600v-80q0-50 35-85t85-35h120v80H280q-17 0-28.5 11.5T240-680v80q0 38-22 69t-58 44v14q36 13 58 44t22 69v80q0 17 11.5 28.5T280-240h120v80z\"/></svg>",
|
|
2273
|
+
"kotlin": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><defs><linearGradient id=\"a\" x1=\"1.725\" x2=\"22.185\" y1=\"22.67\" y2=\"1.982\" gradientTransform=\"translate(1.306 1.129)scale(.89324)\" gradientUnits=\"userSpaceOnUse\"><stop offset=\"0\" stop-color=\"#7c4dff\"/><stop offset=\".5\" stop-color=\"#d500f9\"/><stop offset=\"1\" stop-color=\"#ef5350\"/></linearGradient></defs><path fill=\"url(#a)\" d=\"M2.975 2.976v18.048h18.05v-.03l-4.478-4.511-4.48-4.515 4.48-4.515 4.443-4.477z\"/></svg>",
|
|
2274
|
+
"less": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#0277bd\" d=\"M8 3a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2H3v2h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h2v-2H8v-5a2 2 0 0 0-2-2 2 2 0 0 0 2-2V5h2V3m6 0a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1v2h-1a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-2v-2h2v-5a2 2 0 0 1 2-2 2 2 0 0 1-2-2V5h-2V3z\"/></svg>",
|
|
2275
|
+
"license": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#ff5722\" d=\"M8 1a5.5 5.5 0 0 0-4 9.26V15l4-1.5 4 1.5v-4.74A5.49 5.49 0 0 0 8 1m0 1.5a4 4 0 1 1 0 8 4 4 0 0 1 0-8m0 2a2 2 0 1 0 0 4 2 2 0 0 0 0-4\"/></svg>",
|
|
2276
|
+
"lock": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ffd54f\" d=\"M25 12h-3V8a6 6 0 0 0-12 0v4H7a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1V13a1 1 0 0 0-1-1M14 8a2 2 0 0 1 4 0v4h-4Zm2 17a4 4 0 1 1 4-4 4 4 0 0 1-4 4\"/></svg>",
|
|
2277
|
+
"log": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M0 0h24v24H0z\"/><path fill=\"#afb42b\" d=\"M19 5v9h-5v5H5V5zm0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h10l6-6V5c0-1.1-.9-2-2-2m-7 11H7v-2h5zm5-4H7V8h10z\"/></svg>",
|
|
2278
|
+
"makefile": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ef5350\" d=\"m29.5 24.02-1.6-.92a4.4 4.4 0 0 0 .09-.9A1.3 1.3 0 0 0 28 22a5.6 5.6 0 0 0-.1-1.1l1.6-.92a.493.493 0 0 0 .18-.68l-1.5-2.6a.45.45 0 0 0-.18-.18V6.01a2.006 2.006 0 0 0-2-2H4a2.006 2.006 0 0 0-2 2V22a2.006 2.006 0 0 0 2 2h10.53l-.03.02a.493.493 0 0 0-.18.68l1.5 2.6a.493.493 0 0 0 .68.18l1.6-.92a5.9 5.9 0 0 0 1.9 1.09v1.85a.495.495 0 0 0 .5.5h3a.495.495 0 0 0 .5-.5v-1.85a5.9 5.9 0 0 0 1.9-1.09l1.6.92a.493.493 0 0 0 .68-.18l1.5-2.6a.493.493 0 0 0-.18-.68M24 22.01a1.99 1.99 0 0 1-.88 1.65l-.18.11a2.04 2.04 0 0 1-1.88 0l-.18-.11a1.99 1.99 0 0 1-.88-1.65V22a2 2 0 0 1 .88-1.66l.18-.11a2.04 2.04 0 0 1 1.88 0l.18.11A2 2 0 0 1 24 22Zm2-4.63-.1.06a5.9 5.9 0 0 0-1.9-1.09V14.5a.495.495 0 0 0-.5-.5h-3a.495.495 0 0 0-.5.5v1.85a5.9 5.9 0 0 0-1.9 1.09l-1.6-.92a.493.493 0 0 0-.68.18l-1.5 2.6a.493.493 0 0 0 .18.68l1.6.92A5.6 5.6 0 0 0 16 22v.01L4 22V10.01h22Z\"/></svg>",
|
|
2279
|
+
"markdown": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#42a5f5\" d=\"m14 10-4 3.5L6 10H4v12h4v-6l2 2 2-2v6h4V10zm12 6v-6h-4v6h-4l6 8 6-8z\"/></svg>",
|
|
2280
|
+
"nodejs": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#8bc34a\" d=\"M16 20.003v2h4a2 2 0 0 0 2-2v-2a2 2 0 0 0-2-2h-2v-2h4v-2h-4a2 2 0 0 0-2 2v2a2 2 0 0 0 2 2h2v2Z\"/><path fill=\"#8bc34a\" d=\"m16 3.003-12 7v14l4 2h6v-13.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v11.5H8l-2-1.034V11.15l10-5.833 10 5.833v11.703l-10 5.833-1.745-1.022L13 29.253l3 1.75 12-7v-14Z\"/></svg>",
|
|
2281
|
+
"npm": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#e53935\" d=\"M4 4v24h24V4Zm20 20h-4V12h-4v12H8V8h16Z\"/></svg>",
|
|
2282
|
+
"pdf": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#ef5350\" d=\"M13 9h5.5L13 3.5zM6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m4.93 10.44c.41.9.93 1.64 1.53 2.15l.41.32c-.87.16-2.07.44-3.34.93l-.11.04.5-1.04c.45-.87.78-1.66 1.01-2.4m6.48 3.81c.18-.18.27-.41.28-.66.03-.2-.02-.39-.12-.55-.29-.47-1.04-.69-2.28-.69l-1.29.07-.87-.58c-.63-.52-1.2-1.43-1.6-2.56l.04-.14c.33-1.33.64-2.94-.02-3.6a.85.85 0 0 0-.61-.24h-.24c-.37 0-.7.39-.79.77-.37 1.33-.15 2.06.22 3.27v.01c-.25.88-.57 1.9-1.08 2.93l-.96 1.8-.89.49c-1.2.75-1.77 1.59-1.88 2.12-.04.19-.02.36.05.54l.03.05.48.31.44.11c.81 0 1.73-.95 2.97-3.07l.18-.07c1.03-.33 2.31-.56 4.03-.75 1.03.51 2.24.74 3 .74.44 0 .74-.11.91-.3m-.41-.71.09.11c-.01.1-.04.11-.09.13h-.04l-.19.02c-.46 0-1.17-.19-1.9-.51.09-.1.13-.1.23-.1 1.4 0 1.8.25 1.9.35M7.83 17c-.65 1.19-1.24 1.85-1.69 2 .05-.38.5-1.04 1.21-1.69zm3.02-6.91c-.23-.9-.24-1.63-.07-2.05l.07-.12.15.05c.17.24.19.56.09 1.1l-.03.16-.16.82z\"/></svg>",
|
|
2283
|
+
"php": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#1e88e5\" d=\"M12 18.08c-6.63 0-12-2.72-12-6.08s5.37-6.08 12-6.08S24 8.64 24 12s-5.37 6.08-12 6.08m-5.19-7.95c.54 0 .91.1 1.09.31.18.2.22.56.13 1.03-.1.53-.29.87-.58 1.09q-.42.33-1.29.33h-.87l.53-2.76zm-3.5 5.55h1.44l.34-1.75h1.23c.54 0 .98-.06 1.33-.17.35-.12.67-.31.96-.58.24-.22.43-.46.58-.73.15-.26.26-.56.31-.88.16-.78.05-1.39-.33-1.82-.39-.44-.99-.65-1.82-.65H4.59zm7.25-8.33-1.28 6.58h1.42l.74-3.77h1.14c.36 0 .6.06.71.18s.13.34.07.66l-.57 2.93h1.45l.59-3.07c.13-.62.03-1.07-.27-1.36-.3-.27-.85-.4-1.65-.4h-1.27L12 7.35zM18 10.13c.55 0 .91.1 1.09.31.18.2.22.56.13 1.03-.1.53-.29.87-.57 1.09-.29.22-.72.33-1.3.33h-.85l.5-2.76zm-3.5 5.55h1.44l.34-1.75h1.22c.55 0 1-.06 1.35-.17.35-.12.65-.31.95-.58.24-.22.44-.46.58-.73.15-.26.26-.56.32-.88.15-.78.04-1.39-.34-1.82-.36-.44-.99-.65-1.82-.65h-2.75z\"/></svg>",
|
|
2284
|
+
"pnpm": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#e0e0e0\" d=\"M2 22h8v8H2zm10 0h8v8h-8zm10 0h8v8h-8zM12 12h8v8h-8z\"/><path fill=\"#ffb300\" d=\"M2 2h8v8H2zm10 0h8v8h-8zm10 0h8v8h-8zm0 10h8v8h-8z\"/></svg>",
|
|
2285
|
+
"prettier": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#f44336\" d=\"M2 8h4v1H2zm0 6h4v1H2zm9-10h3v1h-3zM2 2h3v1H2z\"/><path fill=\"#f9a825\" d=\"M9 2h3v1H9zm1 4h4v1h-4zm-5 6h1v1H5zm-3-2h6v1H2z\"/><path fill=\"#26a69a\" d=\"M2 12h3v1H2zm7-4h5v1H9zM2 4h4v1H2zm3-2h4v1H5z\"/><path fill=\"#ba68c8\" d=\"M2 6h3v1H2zm7-2h2v1H9zm-1 6h4v1H8z\"/></svg>",
|
|
2286
|
+
"python": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M9.86 2A2.86 2.86 0 0 0 7 4.86v1.68h4.29c.39 0 .71.57.71.96H4.86A2.86 2.86 0 0 0 2 10.36v3.781a2.86 2.86 0 0 0 2.86 2.86h1.18v-2.68a2.85 2.85 0 0 1 2.85-2.86h5.25c1.58 0 2.86-1.271 2.86-2.851V4.86A2.86 2.86 0 0 0 14.14 2zm-.72 1.61c.4 0 .72.12.72.71s-.32.891-.72.891c-.39 0-.71-.3-.71-.89s.32-.711.71-.711\"/><path fill=\"#fdd835\" d=\"M17.959 7v2.68a2.85 2.85 0 0 1-2.85 2.859H9.86A2.85 2.85 0 0 0 7 15.389v3.75a2.86 2.86 0 0 0 2.86 2.86h4.28A2.86 2.86 0 0 0 17 19.14v-1.68h-4.291c-.39 0-.709-.57-.709-.96h7.14A2.86 2.86 0 0 0 22 13.64V9.86A2.86 2.86 0 0 0 19.14 7zM8.32 11.513l-.004.004.038-.004zm6.54 7.276c.39 0 .71.3.71.89a.71.71 0 0 1-.71.71c-.4 0-.72-.12-.72-.71s.32-.89.72-.89\"/></svg>",
|
|
2287
|
+
"react": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#00bcd4\" d=\"M16 12c7.444 0 12 2.59 12 4s-4.556 4-12 4-12-2.59-12-4 4.556-4 12-4m0-2c-7.732 0-14 2.686-14 6s6.268 6 14 6 14-2.686 14-6-6.268-6-14-6\"/><path fill=\"#00bcd4\" d=\"M16 14a2 2 0 1 0 2 2 2 2 0 0 0-2-2\"/><path fill=\"#00bcd4\" d=\"M10.458 5.507c2.017 0 5.937 3.177 9.006 8.493 3.722 6.447 3.757 11.687 2.536 12.392a.9.9 0 0 1-.457.1c-2.017 0-5.938-3.176-9.007-8.492C8.814 11.553 8.779 6.313 10 5.608a.9.9 0 0 1 .458-.1m-.001-2A2.87 2.87 0 0 0 9 3.875C6.13 5.532 6.938 12.304 10.804 19c3.284 5.69 7.72 9.493 10.74 9.493A2.87 2.87 0 0 0 23 28.124c2.87-1.656 2.062-8.428-1.804-15.124-3.284-5.69-7.72-9.493-10.74-9.493Z\"/><path fill=\"#00bcd4\" d=\"M21.543 5.507a.9.9 0 0 1 .457.1c1.221.706 1.186 5.946-2.536 12.393-3.07 5.316-6.99 8.493-9.007 8.493a.9.9 0 0 1-.457-.1C8.779 25.686 8.814 20.446 12.536 14c3.07-5.316 6.99-8.493 9.007-8.493m0-2c-3.02 0-7.455 3.804-10.74 9.493C6.939 19.696 6.13 26.468 9 28.124a2.87 2.87 0 0 0 1.457.369c3.02 0 7.455-3.804 10.74-9.493C25.061 12.304 25.87 5.532 23 3.876a2.87 2.87 0 0 0-1.457-.369\"/></svg>",
|
|
2288
|
+
"react_ts": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M16 12c7.444 0 12 2.59 12 4s-4.556 4-12 4-12-2.59-12-4 4.556-4 12-4m0-2c-7.732 0-14 2.686-14 6s6.268 6 14 6 14-2.686 14-6-6.268-6-14-6\"/><path fill=\"#0288d1\" d=\"M16 14a2 2 0 1 0 2 2 2 2 0 0 0-2-2\"/><path fill=\"#0288d1\" d=\"M10.458 5.507c2.017 0 5.937 3.177 9.006 8.493 3.722 6.447 3.757 11.687 2.536 12.392a.9.9 0 0 1-.457.1c-2.017 0-5.938-3.176-9.007-8.492C8.814 11.553 8.779 6.313 10 5.608a.9.9 0 0 1 .458-.1m-.001-2A2.87 2.87 0 0 0 9 3.875C6.13 5.532 6.938 12.304 10.804 19c3.284 5.69 7.72 9.493 10.74 9.493A2.87 2.87 0 0 0 23 28.124c2.87-1.656 2.062-8.428-1.804-15.124-3.284-5.69-7.72-9.493-10.74-9.493Z\"/><path fill=\"#0288d1\" d=\"M21.543 5.507a.9.9 0 0 1 .457.1c1.221.706 1.186 5.946-2.536 12.393-3.07 5.316-6.99 8.493-9.007 8.493a.9.9 0 0 1-.457-.1C8.779 25.686 8.814 20.446 12.536 14c3.07-5.316 6.99-8.493 9.007-8.493m0-2c-3.02 0-7.455 3.804-10.74 9.493C6.939 19.696 6.13 26.468 9 28.124a2.87 2.87 0 0 0 1.457.369c3.02 0 7.455-3.804 10.74-9.493C25.061 12.304 25.87 5.532 23 3.876a2.87 2.87 0 0 0-1.457-.369\"/></svg>",
|
|
2289
|
+
"readme": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path d=\"M0 0h24v24H0z\"/><path fill=\"#42a5f5\" d=\"M8 1C4.136 1 1 4.136 1 8s3.136 7 7 7 7-3.136 7-7-3.136-7-7-7m1 11H7V7.5h2zm0-6H7V4h2z\"/></svg>",
|
|
2290
|
+
"ruby": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#f44336\" d=\"M18.041 3.177c2.24.382 2.879 1.919 2.843 3.527V6.67l-1.013 13.266-13.132.897h.008c-1.093-.044-3.518-.151-3.634-3.545l1.217-2.222 2.462 5.74 2.097-6.77-.045.009.018-.018 6.85 2.186L13.945 9.3l6.53-.409-5.144-4.212 2.71-1.51v.009M3.113 17.252v.017zM6.916 6.874c2.63-2.622 6.033-4.168 7.34-2.844 1.297 1.306-.072 4.523-2.702 7.135-2.666 2.613-6.015 4.248-7.322 2.933-1.306-1.324.036-4.612 2.675-7.224z\"/></svg>",
|
|
2291
|
+
"rust": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ff7043\" d=\"m30 12-4-2V6h-4l-2-4-4 2-4-2-2 4H6v4l-4 2 2 4-2 4 4 2v4h4l2 4 4-2 4 2 2-4h4v-4l4-2-2-4ZM6 16a9.9 9.9 0 0 1 .842-4H10v8H6.842A9.9 9.9 0 0 1 6 16m10 10a9.98 9.98 0 0 1-7.978-4H16v-2h-2v-2h4c.819.819.297 2.308 1.179 3.37a1.89 1.89 0 0 0 1.46.63h3.34A9.98 9.98 0 0 1 16 26m-2-12v-2h4a1 1 0 0 1 0 2Zm11.158 6H24a2.006 2.006 0 0 1-2-2 2 2 0 0 0-2-2 3 3 0 0 0 3-3q0-.08-.004-.161A3.115 3.115 0 0 0 19.83 10H8.022a9.986 9.986 0 0 1 17.136 10\"/></svg>",
|
|
2292
|
+
"sass": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ec407a\" d=\"M27.837 5.673a4.33 4.33 0 0 0-2.293-2.701c-2.362-1.261-6.11-1.298-9.548-.092a26.3 26.3 0 0 0-8.76 4.966c-2.752 2.542-3.438 4.925-3.189 6.194.523 2.668 3.274 4.539 5.485 6.042.418.284.822.559 1.175.816-1.429.76-4.261 2.444-5.088 4.248a3.88 3.88 0 0 0-.118 3.332A2.37 2.37 0 0 0 6.869 29.8a5.6 5.6 0 0 0 1.49.2 6.35 6.35 0 0 0 5.19-2.856 6.74 6.74 0 0 0 .864-5.382 7.3 7.3 0 0 1 2.044-.03 3.92 3.92 0 0 1 2.816 1.311 1.82 1.82 0 0 1 .423 1.262 1.55 1.55 0 0 1-.772 1.05c-.234.14-.586.355-.504.803.036.194.198.633.894.512a2.93 2.93 0 0 0 2.145-2.651 4 4 0 0 0-1.197-2.904 5.94 5.94 0 0 0-4.396-1.626 10.6 10.6 0 0 0-2.672.304 20 20 0 0 0-2.203-1.846c-1.712-1.3-3.33-2.529-3.235-4.26.125-2.263 2.468-4.532 6.964-6.744 4.016-1.976 7.254-2.037 8.944-1.438a2 2 0 0 1 1.204.883 2.77 2.77 0 0 1-.36 2.47 9.71 9.71 0 0 1-7.425 4.304 3.86 3.86 0 0 1-3.238-.757c-.278-.302-.593-.645-1.074-.383q-.565.31-.225 1.189a3.9 3.9 0 0 0 2.407 1.92 11.7 11.7 0 0 0 7.128-.671c3.527-1.35 6.681-5.202 5.756-8.787M11.895 24.475a4 4 0 0 1-.192.468 4.5 4.5 0 0 1-.753 1.081 2.83 2.83 0 0 1-2.533 1.107c-.056-.032-.078-.146-.085-.193a3.28 3.28 0 0 1 1.076-2.284 11.3 11.3 0 0 1 2.644-1.933 3.85 3.85 0 0 1-.157 1.754\"/></svg>",
|
|
2293
|
+
"settings": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path d=\"M0 0h24v24H0z\"/><path fill=\"#42a5f5\" d=\"M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46a.5.5 0 0 0-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65A.49.49 0 0 0 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1a.6.6 0 0 0-.18-.03c-.17 0-.34.09-.43.25l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46a.5.5 0 0 0 .61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1q.09.03.18.03c.17 0 .34-.09.43-.25l2-3.46c.12-.22.07-.49-.12-.64zm-1.98-1.71c.04.31.05.52.05.73s-.02.43-.05.73l-.14 1.13.89.7 1.08.84-.7 1.21-1.27-.51-1.04-.42-.9.68c-.43.32-.84.56-1.25.73l-1.06.43-.16 1.13-.2 1.35h-1.4l-.19-1.35-.16-1.13-1.06-.43c-.43-.18-.83-.41-1.23-.71l-.91-.7-1.06.43-1.27.51-.7-1.21 1.08-.84.89-.7-.14-1.13c-.03-.31-.05-.54-.05-.74s.02-.43.05-.73l.14-1.13-.89-.7-1.08-.84.7-1.21 1.27.51 1.04.42.9-.68c.43-.32.84-.56 1.25-.73l1.06-.43.16-1.13.2-1.35h1.39l.19 1.35.16 1.13 1.06.43c.43.18.83.41 1.23.71l.91.7 1.06-.43 1.27-.51.7 1.21-1.07.85-.89.7zM12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4m0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2\"/></svg>",
|
|
2294
|
+
"svelte": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 300 300\" width=\"14\" height=\"14\"><path fill=\"#ff5722\" d=\"M175.94 24.328c-13.037.252-26.009 3.872-37.471 11.174L79.912 72.818a67.13 67.13 0 0 0-30.355 44.906 70.8 70.8 0 0 0 6.959 45.445 67.2 67.2 0 0 0-10.035 25.102 71.54 71.54 0 0 0 12.236 54.156c23.351 33.41 69.468 43.311 102.81 22.07l58.559-37.158a67.36 67.36 0 0 0 30.355-44.906 70.77 70.77 0 0 0-6.982-45.422 67.65 67.65 0 0 0 10.059-25.102 71.63 71.63 0 0 0-12.236-54.156v-.18c-15.324-21.925-40.453-33.727-65.342-33.246zm5.137 28.68a46.5 46.5 0 0 1 36.09 19.969 42.98 42.98 0 0 1 7.365 32.557 45 45 0 0 1-1.393 5.455l-1.123 3.37-2.986-2.247a75.9 75.9 0 0 0-22.902-11.45l-2.244-.651.201-2.246a13.16 13.16 0 0 0-2.379-8.711 13.99 13.99 0 0 0-14.953-5.412 12.8 12.8 0 0 0-3.594 1.572l-58.578 37.25a12.24 12.24 0 0 0-5.502 8.15 13.1 13.1 0 0 0 2.246 9.834 14.03 14.03 0 0 0 14.93 5.569 13.5 13.5 0 0 0 3.594-1.573l22.453-14.234a41.8 41.8 0 0 1 11.898-5.232 46.48 46.48 0 0 1 49.914 18.502 43.02 43.02 0 0 1 7.363 32.557 40.42 40.42 0 0 1-18.254 27.078l-58.58 37.316a43 43 0 0 1-11.898 5.23A46.545 46.545 0 0 1 82.81 227.14a42.98 42.98 0 0 1-7.341-32.557 38 38 0 0 1 1.39-5.41l1.102-3.37 3.008 2.246a75.9 75.9 0 0 0 22.836 11.361l2.244.65-.201 2.247a13.25 13.25 0 0 0 2.447 8.644 14.03 14.03 0 0 0 15.043 5.569 13.1 13.1 0 0 0 3.592-1.573l58.467-37.316a12.17 12.17 0 0 0 5.502-8.173 12.96 12.96 0 0 0-2.246-9.811 14.03 14.03 0 0 0-15.043-5.568 12.8 12.8 0 0 0-3.592 1.57l-22.453 14.258a42.9 42.9 0 0 1-11.877 5.209 46.52 46.52 0 0 1-49.846-18.5 43.02 43.02 0 0 1-7.297-32.557A40.42 40.42 0 0 1 96.798 96.98l58.646-37.316a42.8 42.8 0 0 1 11.811-5.21 46.5 46.5 0 0 1 13.822-1.444z\"/></svg>",
|
|
2295
|
+
"svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ffb300\" d=\"M29.168 14.03a2.7 2.7 0 0 0-1.968-.83 2.51 2.51 0 0 0-1.929.8h-4.443l3.078-3.078a2.835 2.835 0 0 0 2.857-2.842 2.6 2.6 0 0 0-.831-1.969 2.82 2.82 0 0 0-2.014-.788 2.67 2.67 0 0 0-1.968.788 2.36 2.36 0 0 0-.812 1.922L18 11.17V6.726a2.51 2.51 0 0 0 .8-1.929 2.7 2.7 0 0 0-.832-1.968 2.745 2.745 0 0 0-3.936 0 2.7 2.7 0 0 0-.832 1.968 2.51 2.51 0 0 0 .8 1.93v4.443l-3.138-3.138a2.36 2.36 0 0 0-.812-1.922 2.66 2.66 0 0 0-1.968-.788 2.83 2.83 0 0 0-2.014.788 2.6 2.6 0 0 0-.831 1.969 2.74 2.74 0 0 0 .831 2.013 2.8 2.8 0 0 0 2.026.829l3.078 3.078H6.729a2.51 2.51 0 0 0-1.929-.8 2.7 2.7 0 0 0-1.968.831 2.745 2.745 0 0 0 0 3.937 2.7 2.7 0 0 0 1.968.832 2.51 2.51 0 0 0 1.929-.8h4.443l-3.078 3.077a2.835 2.835 0 0 0-2.857 2.842 2.6 2.6 0 0 0 .831 1.969 2.82 2.82 0 0 0 2.014.788 2.67 2.67 0 0 0 1.968-.788 2.36 2.36 0 0 0 .812-1.922L14 20.827v4.444a2.51 2.51 0 0 0-.8 1.929 2.784 2.784 0 0 0 4.768 1.968A2.7 2.7 0 0 0 18.8 27.2a2.51 2.51 0 0 0-.8-1.929v-4.444l3.138 3.138a2.36 2.36 0 0 0 .812 1.922 2.66 2.66 0 0 0 1.968.788 2.83 2.83 0 0 0 2.014-.788 2.6 2.6 0 0 0 .831-1.969 2.74 2.74 0 0 0-.831-2.013 2.8 2.8 0 0 0-2.026-.829L20.828 18h4.443a2.51 2.51 0 0 0 1.93.8 2.784 2.784 0 0 0 1.967-4.769Z\"/></svg>",
|
|
2296
|
+
"swift": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#ff6e40\" d=\"M17.087 19.721c-2.36 1.36-5.59 1.5-8.86.1a13.8 13.8 0 0 1-6.23-5.32c.67.55 1.46 1 2.3 1.4 3.37 1.57 6.73 1.46 9.1 0-3.37-2.59-6.24-5.96-8.37-8.71-.45-.45-.78-1.01-1.12-1.51 8.28 6.05 7.92 7.59 2.41-1.01 4.89 4.94 9.43 7.74 9.43 7.74.16.09.25.16.36.22.1-.25.19-.51.26-.78.79-2.85-.11-6.12-2.08-8.81 4.55 2.75 7.25 7.91 6.12 12.24-.03.11-.06.22-.05.39 2.24 2.83 1.64 5.78 1.35 5.22-1.21-2.39-3.48-1.65-4.62-1.17\"/></svg>",
|
|
2297
|
+
"table": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#8bc34a\" d=\"M6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m7 1.5V9h5.5zm4 7.5h-4v2h1l-2 1.67L10 13h1v-2H7v2h1l3 2.5L8 18H7v2h4v-2h-1l2-1.67L14 18h-1v2h4v-2h-1l-3-2.5 3-2.5h1z\"/></svg>",
|
|
2298
|
+
"toml": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#cfd8dc\" d=\"M4 6V4h8v2H9v7H7V6z\"/><path fill=\"#ef5350\" d=\"M4 1v1H2v12h2v1H1V1zm8 0v1h2v12h-2v1h3V1z\"/></svg>",
|
|
2299
|
+
"tsconfig": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#757575\" d=\"M15 2H6a2.006 2.006 0 0 0-2 2v22a2.006 2.006 0 0 0 2 2h6v-4H6v-2h6v-2H6v-2h6v-2H6v-2h6v-2h2V4l8 8h2v-1Z\" data-mit-no-recolor=\"true\"/><path fill=\"#0288d1\" d=\"M12 12v18h18V12Zm8 6h-2v8h-2v-8h-2v-2h6Zm8 0h-4v2h2a2.006 2.006 0 0 1 2 2v2a2.006 2.006 0 0 1-2 2h-4v-2h4v-2h-2a2.006 2.006 0 0 1-2-2v-2a2.006 2.006 0 0 1 2-2h4Z\"/></svg>",
|
|
2300
|
+
"tune": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#fbc02d\" d=\"M12 10h10v2H12z\"/><path fill=\"#fbc02d\" d=\"M16 4h2v8h-2zm4 18h10v2H20zm4 2h2v4h-2zm0-20h2v14h-2zM2 18h10v2H2z\"/><path fill=\"#fbc02d\" d=\"M6 18h2v10H6zM6 4h2v10H6zm10 12h2v12h-2z\"/></svg>",
|
|
2301
|
+
"typescript": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M2 2v12h12V2zm4 6h3v1H8v4H7V9H6zm5 0h2v1h-2v1h1a1.003 1.003 0 0 1 1 1v1a1.003 1.003 0 0 1-1 1h-2v-1h2v-1h-1a1.003 1.003 0 0 1-1-1V9a1.003 1.003 0 0 1 1-1\"/></svg>",
|
|
2302
|
+
"video": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#ff9800\" d=\"m24 6 2 6h-4l-2-6h-3l2 6h-4l-2-6h-3l2 6H8L6 6H5a3 3 0 0 0-3 3v14a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V6Z\"/></svg>",
|
|
2303
|
+
"vite": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#a0f\" d=\"M29.313 12h-6.664a1.427 1.427 0 0 1-1.1-2.24l4.398-6.676A.703.703 0 0 0 25.397 2H8.428a.62.62 0 0 0-.55.289l-5.77 8.627A.703.703 0 0 0 2.658 12h8.175a1.427 1.427 0 0 1 1.099 2.24l-4.48 6.676A.702.702 0 0 0 8 22l6.695.002A1.34 1.34 0 0 1 16 23.375v5.934a.652.652 0 0 0 1.168.433l12.694-16.586a.725.725 0 0 0-.55-1.156\"/></svg>",
|
|
2304
|
+
"vue": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#41b883\" d=\"M1.791 3.851 12 21.471 22.209 3.936V3.85H18.24l-6.18 10.616L5.906 3.851z\"/><path fill=\"#35495e\" d=\"m5.907 3.851 6.152 10.617L18.24 3.851h-3.723L12.084 8.03 9.66 3.85z\"/></svg>",
|
|
2305
|
+
"webassembly": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#7c4dff\" d=\"M22 18h4v4h-4z\"/><path fill=\"#7c4dff\" d=\"M20 2a4 4 0 0 1-8 0H2v28h28V2Zm-2 24h-2v2h-4v-2h-2v2H6v-2H4V16h2v10h4V16h2v10h4V16h2Zm10 2h-2v-4h-4v4h-2V18h2v-2h4v2h2Z\"/></svg>",
|
|
2306
|
+
"xml": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#8bc34a\" d=\"M13 9h5.5L13 3.5zM6 2h8l6 6v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4c0-1.11.89-2 2-2m.12 13.5 3.74 3.74 1.42-1.41-2.33-2.33 2.33-2.33-1.42-1.41zm11.16 0-3.74-3.74-1.42 1.41 2.33 2.33-2.33 2.33 1.42 1.41z\"/></svg>",
|
|
2307
|
+
"yaml": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#ff5252\" d=\"M13 9h5.5L13 3.5zM6 2h8l6 6v12c0 1.1-.9 2-2 2H6c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2m12 16v-2H9v2zm-4-4v-2H6v2z\"/></svg>",
|
|
2308
|
+
"yarn": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" width=\"14\" height=\"14\"><path fill=\"#0288d1\" d=\"M27.575 23.967a9.9 9.9 0 0 0-3.751 1.726 22.6 22.6 0 0 1-5.537 2.504 1.55 1.55 0 0 1-.931.52 59 59 0 0 1-6.11.548c-1.102.008-1.777-.282-1.965-.735a1.49 1.49 0 0 1 .82-1.965 3.6 3.6 0 0 1-.486-.359c-.163-.162-.334-.487-.385-.367-.213.52-.324 1.794-.897 2.366-.786.795-2.273.53-3.153.069-.965-.513.069-1.718.069-1.718a.69.69 0 0 1-.94-.324 4.6 4.6 0 0 1-.632-2.794 5.2 5.2 0 0 1 1.674-2.76 8.84 8.84 0 0 1 .624-4.17 9.9 9.9 0 0 1 3-3.469S7.136 11.015 7.82 9.177c.444-1.196.623-1.187.769-1.239a3.44 3.44 0 0 0 1.375-.811 4.99 4.99 0 0 1 4.178-1.607s1.094-3.357 2.12-2.7a17.4 17.4 0 0 1 1.452 2.735s1.213-.71 1.35-.445a10.74 10.74 0 0 1 .495 5.81 13.3 13.3 0 0 1-2.46 5.127c-.129.214 1.47.889 2.477 3.683.932 2.554.103 4.699.248 4.938.026.043.034.06.034.06s1.068.085 3.213-1.24a8.05 8.05 0 0 1 4.05-1.52 1.026 1.026 0 0 1 .453 2Z\"/></svg>",
|
|
2309
|
+
"zip": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"14\" height=\"14\"><path fill=\"#afb42b\" d=\"M14 17h-2v-2h-2v-2h2v2h2m0-6h-2v2h2v2h-2v-2h-2V9h2V7h-2V5h2v2h2m5-4H5c-1.11 0-2 .89-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2\"/></svg>",
|
|
2310
|
+
}
|
|
2311
|
+
const FILE_EXTENSION_ICONS = {
|
|
2312
|
+
"md": "markdown",
|
|
2313
|
+
"markdown": "markdown",
|
|
2314
|
+
"json": "json",
|
|
2315
|
+
"jsonc": "json",
|
|
2316
|
+
"js": "javascript",
|
|
2317
|
+
"mjs": "javascript",
|
|
2318
|
+
"cjs": "javascript",
|
|
2319
|
+
"jsx": "react",
|
|
2320
|
+
"ts": "typescript",
|
|
2321
|
+
"mts": "typescript",
|
|
2322
|
+
"cts": "typescript",
|
|
2323
|
+
"tsx": "react_ts",
|
|
2324
|
+
"css": "css",
|
|
2325
|
+
"scss": "sass",
|
|
2326
|
+
"sass": "sass",
|
|
2327
|
+
"less": "less",
|
|
2328
|
+
"html": "html",
|
|
2329
|
+
"htm": "html",
|
|
2330
|
+
"vue": "vue",
|
|
2331
|
+
"svelte": "svelte",
|
|
2332
|
+
"py": "python",
|
|
2333
|
+
"go": "go",
|
|
2334
|
+
"rs": "rust",
|
|
2335
|
+
"java": "java",
|
|
2336
|
+
"kt": "kotlin",
|
|
2337
|
+
"rb": "ruby",
|
|
2338
|
+
"php": "php",
|
|
2339
|
+
"cs": "csharp",
|
|
2340
|
+
"swift": "swift",
|
|
2341
|
+
"sh": "console",
|
|
2342
|
+
"bash": "console",
|
|
2343
|
+
"zsh": "console",
|
|
2344
|
+
"fish": "console",
|
|
2345
|
+
"yml": "yaml",
|
|
2346
|
+
"yaml": "yaml",
|
|
2347
|
+
"toml": "toml",
|
|
2348
|
+
"ini": "settings",
|
|
2349
|
+
"conf": "settings",
|
|
2350
|
+
"xml": "xml",
|
|
2351
|
+
"sql": "database",
|
|
2352
|
+
"graphql": "graphql",
|
|
2353
|
+
"gql": "graphql",
|
|
2354
|
+
"csv": "table",
|
|
2355
|
+
"txt": "document",
|
|
2356
|
+
"log": "log",
|
|
2357
|
+
"lock": "lock",
|
|
2358
|
+
"pdf": "pdf",
|
|
2359
|
+
"png": "image",
|
|
2360
|
+
"jpg": "image",
|
|
2361
|
+
"jpeg": "image",
|
|
2362
|
+
"gif": "image",
|
|
2363
|
+
"webp": "image",
|
|
2364
|
+
"bmp": "image",
|
|
2365
|
+
"ico": "image",
|
|
2366
|
+
"avif": "image",
|
|
2367
|
+
"svg": "svg",
|
|
2368
|
+
"mp3": "audio",
|
|
2369
|
+
"wav": "audio",
|
|
2370
|
+
"ogg": "video",
|
|
2371
|
+
"flac": "audio",
|
|
2372
|
+
"m4a": "audio",
|
|
2373
|
+
"mp4": "video",
|
|
2374
|
+
"webm": "video",
|
|
2375
|
+
"mov": "video",
|
|
2376
|
+
"m4v": "video",
|
|
2377
|
+
"ogv": "video",
|
|
2378
|
+
"zip": "zip",
|
|
2379
|
+
"tar": "zip",
|
|
2380
|
+
"gz": "zip",
|
|
2381
|
+
"tgz": "zip",
|
|
2382
|
+
"bz2": "zip",
|
|
2383
|
+
"xz": "zip",
|
|
2384
|
+
"7z": "zip",
|
|
2385
|
+
"rar": "zip",
|
|
2386
|
+
"db": "database",
|
|
2387
|
+
"sqlite": "database",
|
|
2388
|
+
"wasm": "webassembly",
|
|
2389
|
+
"bin": "hex",
|
|
2390
|
+
"env": "tune",
|
|
2391
|
+
}
|
|
2392
|
+
const FILE_NAME_ICONS = {
|
|
2393
|
+
".gitignore": "git",
|
|
2394
|
+
".gitattributes": "git",
|
|
2395
|
+
".gitmodules": "git",
|
|
2396
|
+
"dockerfile": "docker",
|
|
2397
|
+
"makefile": "makefile",
|
|
2398
|
+
"license": "license",
|
|
2399
|
+
"readme.md": "readme",
|
|
2400
|
+
"package.json": "nodejs",
|
|
2401
|
+
"pnpm-lock.yaml": "pnpm",
|
|
2402
|
+
"yarn.lock": "yarn",
|
|
2403
|
+
".npmrc": "npm",
|
|
2404
|
+
".prettierrc": "prettier",
|
|
2405
|
+
"tsconfig.json": "tsconfig",
|
|
2406
|
+
"vite.config.ts": "vite",
|
|
2407
|
+
}
|
|
2408
|
+
const FOLDER_ICON = "folder"
|
|
2409
|
+
const FOLDER_OPEN_ICON = "folder-open"
|
|
2410
|
+
|
|
2411
|
+
function FileGlyph({ name, kind, expanded }) {
|
|
2412
|
+
const baseName = String(name ?? '').toLowerCase()
|
|
2413
|
+
const extension = baseName.includes('.') ? baseName.slice(baseName.lastIndexOf('.') + 1) : ''
|
|
2414
|
+
const icon = kind === 'dir'
|
|
2415
|
+
? (expanded ? FOLDER_OPEN_ICON : FOLDER_ICON)
|
|
2416
|
+
: (FILE_NAME_ICONS[baseName] ?? FILE_EXTENSION_ICONS[extension] ?? 'file')
|
|
2417
|
+
const markup = FILE_ICONS[icon] ?? FILE_ICONS.file
|
|
2418
|
+
return h('span', {
|
|
2419
|
+
style: { width: 14, height: 14, flex: '0 0 auto', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' },
|
|
2420
|
+
dangerouslySetInnerHTML: { __html: markup },
|
|
2421
|
+
})
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
/** One worktree's file browser: lazy filesystem tree (all files, icons, statuses). */
|
|
2425
|
+
function WorktreeFilesCard({ t, item, defaultOpen, onOpen, selectedPath, onSelect, onNotify, visible = true }) {
|
|
2426
|
+
const [open, setOpen] = useState(defaultOpen)
|
|
2427
|
+
const [expandedDirs, setExpandedDirs] = useState(() => new Set())
|
|
2428
|
+
const [dirs, setDirs] = useState({})
|
|
2429
|
+
const [version, setVersion] = useState(0)
|
|
2430
|
+
const [status, refreshStatus] = useStatusAt(item.path, open && visible)
|
|
2431
|
+
const statusByPath = useMemo(() => {
|
|
2432
|
+
const map = new Map()
|
|
2433
|
+
for (const file of [...(status.data?.staged ?? []), ...(status.data?.unstaged ?? []), ...(status.data?.untracked ?? [])]) {
|
|
2434
|
+
if (file?.path) map.set(file.path, file.status)
|
|
2435
|
+
}
|
|
2436
|
+
return map
|
|
2437
|
+
}, [status.data])
|
|
2438
|
+
const dirStatusByPath = useMemo(() => aggregateDirStatus(statusByPath), [statusByPath])
|
|
2439
|
+
const loadDir = useCallback(async dir => {
|
|
2440
|
+
setDirs(previous => ({ ...previous, [dir]: { phase: 'loading', entries: previous[dir]?.entries ?? [] } }))
|
|
2441
|
+
try {
|
|
2442
|
+
const data = await api('/fs/list', { path: item.path, dir })
|
|
2443
|
+
setDirs(previous => ({ ...previous, [dir]: { phase: 'ready', entries: Array.isArray(data?.entries) ? data.entries : [], truncated: Boolean(data?.truncated) } }))
|
|
2444
|
+
} catch (error) {
|
|
2445
|
+
setDirs(previous => ({ ...previous, [dir]: { phase: 'error', entries: [], error: String(error?.message ?? error) } }))
|
|
2446
|
+
}
|
|
2447
|
+
}, [item.path])
|
|
2448
|
+
useEffect(() => { if (open && visible) loadDir('') }, [open, visible, loadDir, version])
|
|
2449
|
+
const refreshFiles = () => { setVersion(value => value + 1); refreshStatus() }
|
|
2450
|
+
const toggleDir = path => setExpandedDirs(previous => {
|
|
2451
|
+
const next = new Set(previous)
|
|
2452
|
+
if (next.has(path)) { next.delete(path); return next }
|
|
2453
|
+
next.add(path)
|
|
2454
|
+
if (!dirs[path] || dirs[path].phase === 'error') loadDir(path)
|
|
2455
|
+
return next
|
|
2456
|
+
})
|
|
2457
|
+
const rows = useMemo(() => {
|
|
2458
|
+
const rows = []
|
|
2459
|
+
const walk = (dirPath, depth) => {
|
|
2460
|
+
const node = dirs[dirPath]
|
|
2461
|
+
if (!node) return
|
|
2462
|
+
if (node.phase === 'loading' && node.entries.length === 0) {
|
|
2463
|
+
rows.push(h('div', { key: `${dirPath}:loading`, style: { fontSize: 10.5, color: T.muted, padding: `3px 8px 3px ${10 + depth * 13}px` } }, t('filesLoading')))
|
|
2464
|
+
return
|
|
2465
|
+
}
|
|
2466
|
+
if (node.phase === 'error') {
|
|
2467
|
+
rows.push(h('div', { key: `${dirPath}:error`, style: { fontSize: 10.5, color: T.error, padding: `3px 8px 3px ${10 + depth * 13}px` } }, node.error))
|
|
2468
|
+
return
|
|
2469
|
+
}
|
|
2470
|
+
for (const entry of node.entries) {
|
|
2471
|
+
const isDir = entry.kind === 'dir'
|
|
2472
|
+
const statusLetter = isDir ? dirStatusByPath.get(entry.path) : statusByPath.get(entry.path)
|
|
2473
|
+
const expanded = isDir && expandedDirs.has(entry.path)
|
|
2474
|
+
const selected = !isDir && selectedPath === entry.path
|
|
2475
|
+
rows.push(h('div', {
|
|
2476
|
+
key: entry.path,
|
|
2477
|
+
title: entry.path,
|
|
2478
|
+
onClick: () => { if (isDir) toggleDir(entry.path); else onOpen({ path: entry.path }, item.path) },
|
|
2479
|
+
style: {
|
|
2480
|
+
display: 'flex', alignItems: 'center', gap: 5, minHeight: 21, margin: '0 4px',
|
|
2481
|
+
padding: `1px 6px 1px ${8 + depth * 13}px`, borderRadius: T.rSm, cursor: 'pointer',
|
|
2482
|
+
background: selected ? T.selected : 'transparent',
|
|
2483
|
+
color: T.ink2,
|
|
2484
|
+
fontSize: 12,
|
|
2485
|
+
},
|
|
2486
|
+
onMouseEnter: event => { if (!selected) event.currentTarget.style.background = T.hover },
|
|
2487
|
+
onMouseLeave: event => { if (!selected) event.currentTarget.style.background = 'transparent' },
|
|
2488
|
+
onContextMenu: event => { event.preventDefault(); event.stopPropagation(); openFileContextMenu({ x: event.clientX, y: event.clientY, items: menuItems(entry, isDir) }) },
|
|
2489
|
+
},
|
|
2490
|
+
isDir ? h(Chevron, { open: expanded, size: 8 }) : h('span', { style: { width: 8, flex: '0 0 8px' } }),
|
|
2491
|
+
h(FileGlyph, { name: entry.name, kind: entry.kind, expanded }),
|
|
2492
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, entry.name),
|
|
2493
|
+
statusLetter ? h(StatusChip, { status: statusLetter, size: 15 }) : null))
|
|
2494
|
+
if (isDir && expanded) walk(entry.path, depth + 1)
|
|
2495
|
+
}
|
|
2496
|
+
if (node.truncated) rows.push(h('div', { key: `${dirPath}:truncated`, style: { fontSize: 10, color: T.subtle, padding: `2px 8px 2px ${10 + depth * 13}px` } }, '…'))
|
|
2497
|
+
}
|
|
2498
|
+
walk('', 0)
|
|
2499
|
+
return rows
|
|
2500
|
+
}, [dirs, expandedDirs, selectedPath, statusByPath, dirStatusByPath, item.path])
|
|
2501
|
+
const menuItems = (entry, isDir) => {
|
|
2502
|
+
const root = item.path.replace(/\/$/, '')
|
|
2503
|
+
const absolute = `${root}/${entry.path}`
|
|
2504
|
+
const rawUrl = `/git-assistant/api/raw?path=${encodeURIComponent(item.path)}&file=${encodeURIComponent(entry.path)}`
|
|
2505
|
+
const notify = (message, kind) => onNotify?.(message, kind)
|
|
2506
|
+
const copy = async (text, done) => {
|
|
2507
|
+
try { await navigator.clipboard.writeText(text); notify(done) } catch { notify(t('actionFailed'), 'error') }
|
|
2508
|
+
}
|
|
2509
|
+
const copyImage = async () => {
|
|
2510
|
+
try {
|
|
2511
|
+
const response = await fetch(rawUrl)
|
|
2512
|
+
const blob = await response.blob()
|
|
2513
|
+
await navigator.clipboard.write([new ClipboardItem({ [blob.type || 'image/png']: blob })])
|
|
2514
|
+
notify(t('imageCopied'))
|
|
2515
|
+
} catch { notify(t('actionFailed'), 'error') }
|
|
2516
|
+
}
|
|
2517
|
+
const download = () => {
|
|
2518
|
+
const link = document.createElement('a')
|
|
2519
|
+
link.href = `${rawUrl}&download=1`
|
|
2520
|
+
link.download = entry.name
|
|
2521
|
+
document.body.appendChild(link)
|
|
2522
|
+
link.click()
|
|
2523
|
+
link.remove()
|
|
2524
|
+
}
|
|
2525
|
+
const saveAs = async () => {
|
|
2526
|
+
try {
|
|
2527
|
+
const response = await fetch(rawUrl)
|
|
2528
|
+
const blob = await response.blob()
|
|
2529
|
+
if (window.showSaveFilePicker) {
|
|
2530
|
+
const handle = await window.showSaveFilePicker({ suggestedName: entry.name })
|
|
2531
|
+
const writable = await handle.createWritable()
|
|
2532
|
+
await writable.write(blob)
|
|
2533
|
+
await writable.close()
|
|
2534
|
+
} else download()
|
|
2535
|
+
} catch (error) { if (error?.name !== 'AbortError') notify(t('actionFailed'), 'error') }
|
|
2536
|
+
}
|
|
2537
|
+
const call = endpoint => apiPost(endpoint, { path: item.path, file: entry.path }).catch(() => notify(t('actionFailed'), 'error'))
|
|
2538
|
+
if (isDir) {
|
|
2539
|
+
return [
|
|
2540
|
+
{ label: t('copyFolderPath'), onClick: () => copy(absolute, t('copiedPath')) },
|
|
2541
|
+
{ separator: true },
|
|
2542
|
+
{ label: t('revealInFinder'), onClick: () => call('/reveal') },
|
|
2543
|
+
]
|
|
2544
|
+
}
|
|
2545
|
+
const items = [{ label: t('copyPath'), onClick: () => copy(absolute, t('copiedPath')) }]
|
|
2546
|
+
if (isImagePath(entry.path)) items.push({ label: t('copyImage'), onClick: copyImage })
|
|
2547
|
+
items.push(
|
|
2548
|
+
{ label: t('downloadFile'), onClick: download },
|
|
2549
|
+
{ label: t('saveAs'), onClick: saveAs },
|
|
2550
|
+
{ separator: true },
|
|
2551
|
+
{ label: t('revealInFinder'), onClick: () => call('/reveal') },
|
|
2552
|
+
{ label: t('openDefaultApp'), onClick: () => call('/open') },
|
|
2553
|
+
)
|
|
2554
|
+
return items
|
|
2555
|
+
}
|
|
2556
|
+
return h(CardBoundary, null,
|
|
2557
|
+
h('div', {
|
|
2558
|
+
style: { marginBottom: 8, flex: open ? '1 0 auto' : '0 0 auto', minHeight: open ? 0 : undefined, display: 'flex', flexDirection: 'column', borderRadius: T.rMd, background: T.surface, boxShadow: T.edge, overflow: 'hidden' },
|
|
2559
|
+
},
|
|
2560
|
+
h('div', {
|
|
2561
|
+
onClick: () => { setOpen(value => !value); onSelect?.(item.path) },
|
|
2562
|
+
style: {
|
|
2563
|
+
display: 'flex', alignItems: 'center', gap: 7, minHeight: 36, padding: '0 12px', cursor: 'pointer',
|
|
2564
|
+
background: open ? T.surfaceAlt : T.surface,
|
|
2565
|
+
borderBottom: open ? `1px solid ${T.borderSoft}` : 'none',
|
|
2566
|
+
},
|
|
2567
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.surfaceAlt },
|
|
2568
|
+
onMouseLeave: event => { event.currentTarget.style.background = open ? T.surfaceAlt : T.surface },
|
|
2569
|
+
},
|
|
2570
|
+
h(Chevron, { open, size: 9 }),
|
|
2571
|
+
h('span', { title: item.path, style: { fontSize: 12.5, fontWeight: 600, color: T.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 72, flex: '0 1 auto' } }, item.name ?? item.path.split('/').pop()),
|
|
2572
|
+
item.branch ? h('span', {
|
|
2573
|
+
style: { fontFamily: MONO, fontSize: 10.5, color: T.ink2, background: T.chip, borderRadius: 5, padding: '1px 6px', whiteSpace: 'nowrap', maxWidth: 104, flex: '0 2 auto', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
2574
|
+
}, item.branch) : null,
|
|
2575
|
+
h('span', { style: { flex: 1 } }),
|
|
2576
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.muted, whiteSpace: 'nowrap' } }, `${item.behind > 0 ? `↓${item.behind}` : ''}${item.ahead > 0 ? ` ↑${item.ahead}` : ''}`),
|
|
2577
|
+
h(IconAction, { label: t('refresh'), onClick: event => { event.stopPropagation(); refreshFiles() } }, h(RefreshIcon, {}))),
|
|
2578
|
+
open ? h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '6px 4px 8px' } }, rows) : null))
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
function formatRelativeTime(epochSeconds) {
|
|
2582
|
+
const now = Math.floor(Date.now() / 1000)
|
|
2583
|
+
const diff = Math.max(0, now - epochSeconds)
|
|
2584
|
+
let locale
|
|
2585
|
+
try { locale = document?.documentElement?.lang || undefined } catch { locale = undefined }
|
|
2586
|
+
let rtf
|
|
2587
|
+
try { rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }) } catch { rtf = undefined }
|
|
2588
|
+
if (!rtf) return new Date(epochSeconds * 1000).toLocaleDateString()
|
|
2589
|
+
if (diff < 60) return rtf.format(-diff, 'second')
|
|
2590
|
+
if (diff < 3600) return rtf.format(-Math.round(diff / 60), 'minute')
|
|
2591
|
+
if (diff < 86400) return rtf.format(-Math.round(diff / 3600), 'hour')
|
|
2592
|
+
if (diff < 86400 * 30) return rtf.format(-Math.round(diff / 86400), 'day')
|
|
2593
|
+
return new Date(epochSeconds * 1000).toLocaleDateString()
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
/** Unpushed commits for the current worktree (local commits not reachable from any remote). */
|
|
2597
|
+
function useLocalCommits(repository, enabled) {
|
|
2598
|
+
const [state, setState] = useState({ phase: 'idle', commits: [], error: null })
|
|
2599
|
+
const [version, setVersion] = useState(0)
|
|
2600
|
+
const path = repository?.path
|
|
2601
|
+
useEffect(() => {
|
|
2602
|
+
if (!path || !enabled) { setState({ phase: 'idle', commits: [], error: null }); return undefined }
|
|
2603
|
+
let live = true
|
|
2604
|
+
setState(previous => ({ ...previous, phase: 'loading' }))
|
|
2605
|
+
api('/local-commits', { path, limit: 80 })
|
|
2606
|
+
.then(data => { if (live) setState({ phase: 'ready', commits: Array.isArray(data?.commits) ? data.commits : [], error: null }) })
|
|
2607
|
+
.catch(error => { if (live) setState({ phase: 'error', commits: [], error: String(error?.message ?? error) }) })
|
|
2608
|
+
return () => { live = false }
|
|
2609
|
+
}, [path, enabled, version])
|
|
2610
|
+
return [state, () => setVersion(value => value + 1)]
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
/** Full parsed patch of one commit, for the multi-file commit view. */
|
|
2614
|
+
function useCommitPatch(repository, selection) {
|
|
2615
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
2616
|
+
const [version, setVersion] = useState(0)
|
|
2617
|
+
const active = selection?.kind === 'commit-files'
|
|
2618
|
+
const path = selection?.repoPath ?? repository?.path
|
|
2619
|
+
useEffect(() => {
|
|
2620
|
+
if (!path || !active) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
2621
|
+
let live = true
|
|
2622
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
2623
|
+
api('/commit', { path, hash: selection.hash })
|
|
2624
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
2625
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
2626
|
+
return () => { live = false }
|
|
2627
|
+
}, [path, active, selection?.hash, version])
|
|
2628
|
+
return [state, () => setVersion(value => value + 1)]
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
function useCommitFileDiff(context, file) {
|
|
2632
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
2633
|
+
const path = context?.repoPath
|
|
2634
|
+
const hash = context?.hash
|
|
2635
|
+
useEffect(() => {
|
|
2636
|
+
if (!path || !hash || !file) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
2637
|
+
let live = true
|
|
2638
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
2639
|
+
api('/commit-diff', { path, hash, file })
|
|
2640
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
2641
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
2642
|
+
return () => { live = false }
|
|
2643
|
+
}, [path, hash, file])
|
|
2644
|
+
return state
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
function useIssues(repository, enabled, stateFilter, query, limit, version) {
|
|
2648
|
+
const [state, setState] = useState({ phase: 'idle', issues: [], repo: null, total: 0, error: null })
|
|
2649
|
+
const path = repository?.path
|
|
2650
|
+
useEffect(() => {
|
|
2651
|
+
if (!path || !enabled) { setState(previous => ({ ...previous, phase: 'idle' })); return undefined }
|
|
2652
|
+
let live = true
|
|
2653
|
+
setState(previous => ({ ...previous, phase: previous.issues.length ? 'ready' : 'loading', error: null }))
|
|
2654
|
+
api('/issues', { path, state: stateFilter, search: query, limit, refresh: version > 0 ? '1' : '' })
|
|
2655
|
+
.then(data => { if (live) setState({ phase: 'ready', issues: Array.isArray(data?.issues) ? data.issues : [], repo: data?.repo ?? null, total: Number(data?.total) || (Array.isArray(data?.issues) ? data.issues.length : 0), error: null }) })
|
|
2656
|
+
.catch(error => { if (live) setState(previous => ({ ...previous, phase: 'error', error: String(error?.message ?? error) })) })
|
|
2657
|
+
return () => { live = false }
|
|
2658
|
+
}, [path, enabled, stateFilter, query, limit, version])
|
|
2659
|
+
return state
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
function useIssueDetail(repository, number, version = 0) {
|
|
2663
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
2664
|
+
const path = repository?.path
|
|
2665
|
+
useEffect(() => {
|
|
2666
|
+
if (!path || !number) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
2667
|
+
let live = true
|
|
2668
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
2669
|
+
api('/issue', { path, number, refresh: version > 0 ? '1' : '' })
|
|
2670
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
2671
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
2672
|
+
return () => { live = false }
|
|
2673
|
+
}, [path, number, version])
|
|
2674
|
+
return state
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
function useIssueComments(repository, number, version = 0) {
|
|
2678
|
+
const [state, setState] = useState({ phase: 'idle', data: null, error: null })
|
|
2679
|
+
const path = repository?.path
|
|
2680
|
+
useEffect(() => {
|
|
2681
|
+
if (!path || !number) { setState({ phase: 'idle', data: null, error: null }); return undefined }
|
|
2682
|
+
let live = true
|
|
2683
|
+
setState({ phase: 'loading', data: null, error: null })
|
|
2684
|
+
api('/issue-comments', { path, number, refresh: version > 0 ? '1' : '' })
|
|
2685
|
+
.then(data => { if (live) setState({ phase: 'ready', data, error: null }) })
|
|
2686
|
+
.catch(error => { if (live) setState({ phase: 'error', data: null, error: String(error?.message ?? error) }) })
|
|
2687
|
+
return () => { live = false }
|
|
2688
|
+
}, [path, number, version])
|
|
2689
|
+
return state
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
/* ── primitives ─────────────────────────────────────────────────── */
|
|
2693
|
+
|
|
2694
|
+
function Chevron({ open, size = 10 }) {
|
|
2695
|
+
return h('svg', {
|
|
2696
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
2697
|
+
strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
|
|
2698
|
+
style: { transform: open ? 'rotate(90deg)' : 'none', transition: 'transform 100ms ease', opacity: 0.66, flex: '0 0 auto' },
|
|
2699
|
+
}, h('path', { d: 'M9 5l7 7-7 7' }))
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
function GitIcon({ size = 16 }) {
|
|
2703
|
+
return h('svg', {
|
|
2704
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
2705
|
+
strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
|
|
2706
|
+
},
|
|
2707
|
+
h('circle', { cx: 6, cy: 5.5, r: 2.2 }),
|
|
2708
|
+
h('circle', { cx: 6, cy: 18.5, r: 2.2 }),
|
|
2709
|
+
h('circle', { cx: 18, cy: 8.5, r: 2.2 }),
|
|
2710
|
+
h('path', { d: 'M6 7.7v8.6' }),
|
|
2711
|
+
h('path', { d: 'M18 10.7c0 3-3.2 3.6-6.4 4.2-2.4.5-3.6 1.2-3.6 1.6' }))
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
function RefreshIcon({ size = 13 }) {
|
|
2715
|
+
return h('svg', {
|
|
2716
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
2717
|
+
strokeWidth: 1.9, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
|
|
2718
|
+
}, h('path', { d: 'M20 11a8 8 0 1 0-2.3 5.7' }), h('path', { d: 'M20 5v6h-6' }))
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
function IconButton({ label, onClick, children, disabled }) {
|
|
2722
|
+
return h('button', {
|
|
2723
|
+
type: 'button', title: label, 'aria-label': label, onClick, disabled,
|
|
2724
|
+
style: {
|
|
2725
|
+
appearance: 'none', border: 'none', background: 'transparent', color: T.ink2,
|
|
2726
|
+
cursor: disabled ? 'default' : 'pointer', display: 'inline-flex', alignItems: 'center',
|
|
2727
|
+
justifyContent: 'center', width: 30, height: 30, borderRadius: T.rMd, opacity: disabled ? 0.3 : 1, padding: 0,
|
|
2728
|
+
transition: `background .15s ${T.ease}, color .15s ${T.ease}`,
|
|
2729
|
+
},
|
|
2730
|
+
onMouseEnter: event => { if (!disabled) { event.currentTarget.style.background = T.hover; event.currentTarget.style.color = T.text; showTooltip(label, event.currentTarget) } },
|
|
2731
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent'; event.currentTarget.style.color = T.ink2; hideTooltip() },
|
|
2732
|
+
}, children)
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
let tooltipElement = null
|
|
2736
|
+
function hideTooltip() {
|
|
2737
|
+
if (tooltipElement) { tooltipElement.remove(); tooltipElement = null }
|
|
2738
|
+
}
|
|
2739
|
+
function showTooltip(text, target) {
|
|
2740
|
+
hideTooltip()
|
|
2741
|
+
if (!text || typeof document === 'undefined' || !target) return
|
|
2742
|
+
const element = document.createElement('div')
|
|
2743
|
+
element.textContent = text
|
|
2744
|
+
element.setAttribute('role', 'tooltip')
|
|
2745
|
+
element.style.cssText = [
|
|
2746
|
+
'position:fixed', 'z-index:10000', 'pointer-events:none', 'padding:4px 8px', 'border-radius:6px',
|
|
2747
|
+
'font-size:11px', 'line-height:1.4', 'max-width:280px', 'white-space:nowrap',
|
|
2748
|
+
'background:var(--dsw-alias-bg-layer-2, #1b1b20)', 'color:var(--dsw-alias-label-primary, #e6e6ea)',
|
|
2749
|
+
'border:0.5px solid var(--dsw-alias-border-l2, rgba(255,255,255,.14))',
|
|
2750
|
+
'box-shadow:0 6px 24px rgba(0,0,0,.3)',
|
|
2751
|
+
'font-family:var(--dsw-font-family, -apple-system, sans-serif)',
|
|
2752
|
+
].join(';')
|
|
2753
|
+
document.body.appendChild(element)
|
|
2754
|
+
const rect = target.getBoundingClientRect()
|
|
2755
|
+
const width = element.offsetWidth || 0
|
|
2756
|
+
const height = element.offsetHeight || 0
|
|
2757
|
+
const left = Math.max(4, Math.min(rect.left + rect.width / 2 - width / 2, (window.innerWidth || 1200) - width - 4))
|
|
2758
|
+
let top = rect.bottom + 6
|
|
2759
|
+
if (top + height > (window.innerHeight || 800) - 4) top = rect.top - height - 6
|
|
2760
|
+
element.style.left = `${left}px`
|
|
2761
|
+
element.style.top = `${Math.max(4, top)}px`
|
|
2762
|
+
tooltipElement = element
|
|
2763
|
+
}
|
|
2764
|
+
if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
|
|
2765
|
+
document.addEventListener('pointerdown', () => hideTooltip(), true)
|
|
2766
|
+
}
|
|
2767
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener === 'function') {
|
|
2768
|
+
window.addEventListener('scroll', () => hideTooltip(), true)
|
|
2769
|
+
window.addEventListener('blur', () => hideTooltip())
|
|
2770
|
+
}
|
|
2771
|
+
|
|
2772
|
+
function IconAction({ label, onClick, disabled, danger, children }) {
|
|
2773
|
+
return h('button', {
|
|
2774
|
+
type: 'button', title: label, 'aria-label': label, onClick, disabled,
|
|
2775
|
+
style: {
|
|
2776
|
+
appearance: 'none', border: 'none', background: 'transparent', color: danger ? T.muted : T.ink2,
|
|
2777
|
+
cursor: disabled ? 'default' : 'pointer', display: 'inline-flex', alignItems: 'center',
|
|
2778
|
+
justifyContent: 'center', width: 22, height: 22, borderRadius: 6, padding: 0,
|
|
2779
|
+
opacity: disabled ? 0.3 : 1, transition: `background .15s ${T.ease}, color .15s ${T.ease}`,
|
|
2780
|
+
},
|
|
2781
|
+
onMouseEnter: event => { if (!disabled) { event.currentTarget.style.background = T.hover; event.currentTarget.style.color = danger ? T.error : T.text; showTooltip(label, event.currentTarget) } },
|
|
2782
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent'; event.currentTarget.style.color = danger ? T.error : T.muted; hideTooltip() },
|
|
2783
|
+
}, children)
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
const IconPlus = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }, h('path', { d: 'M12 5v14M5 12h14' }))
|
|
2787
|
+
const IconUndo = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.9, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M9 14L4 9l5-5' }), h('path', { d: 'M4 9h9a6 6 0 1 1 0 12H8' }))
|
|
2788
|
+
const IconDiff = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('rect', { x: 3, y: 4, width: 18, height: 16, rx: 2 }), h('path', { d: 'M12 4v16M7 8h2M7 12h2M15 8h2M15 12h2M15 16h2' }))
|
|
2789
|
+
const IconMinus = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' }, h('path', { d: 'M5 12h14' }))
|
|
2790
|
+
const IconStash = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M4 8l2-4h12l2 4' }), h('path', { d: 'M4 8v11a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V8' }), h('path', { d: 'M12 8v6' }), h('path', { d: 'M9.5 11.5L12 14l2.5-2.5' }))
|
|
2791
|
+
const IconCopy = () => h('svg', { width: 12.5, height: 12.5, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('rect', { x: 9, y: 9, width: 11, height: 12, rx: 2 }), h('path', { d: 'M5 15H4a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1' }))
|
|
2792
|
+
const IconFolder = () => h('svg', { width: 12.5, height: 12.5, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M3 7a1 1 0 0 1 1-1h5l2 2.5h8a1 1 0 0 1 1 1V18a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7z' }))
|
|
2793
|
+
const IconBranch = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('circle', { cx: 6, cy: 5, r: 2 }), h('circle', { cx: 6, cy: 19, r: 2 }), h('circle', { cx: 18, cy: 7, r: 2 }), h('path', { d: 'M6 7v10' }), h('path', { d: 'M18 9v1.5a4 4 0 0 1-4 4H9' }))
|
|
2794
|
+
const IconExternal = () => h('svg', { width: 12.5, height: 12.5, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M14 4h6v6' }), h('path', { d: 'M20 4L11 13' }), h('path', { d: 'M20 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h5' }))
|
|
2795
|
+
const IconHistory = () => h('svg', { width: 12.5, height: 12.5, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' }, h('path', { d: 'M3.5 12a8.5 8.5 0 1 0 2.5-6' }), h('path', { d: 'M3 4v4h4' }), h('path', { d: 'M12 8v4.5l3 2' }))
|
|
2796
|
+
const IconMore = () => h('svg', { width: 13, height: 13, viewBox: '0 0 24 24', fill: 'currentColor', stroke: 'none' }, h('circle', { cx: 5, cy: 12, r: 1.7 }), h('circle', { cx: 12, cy: 12, r: 1.7 }), h('circle', { cx: 19, cy: 12, r: 1.7 }))
|
|
2797
|
+
|
|
2798
|
+
/** Secondary action: a real raised control (surface + hairline ring), never a ghost outline. */
|
|
2799
|
+
function SmallButton({ label, onClick, disabled, title }) {
|
|
2800
|
+
return h('button', {
|
|
2801
|
+
type: 'button', title: title ?? label, onClick, disabled,
|
|
2802
|
+
style: {
|
|
2803
|
+
appearance: 'none', border: '1px solid transparent', background: T.surface, color: T.text,
|
|
2804
|
+
cursor: disabled ? 'default' : 'pointer', fontSize: 11.5, fontWeight: 500, lineHeight: '18px',
|
|
2805
|
+
height: 26, padding: '0 11px', borderRadius: 8, opacity: disabled ? 0.4 : 1, whiteSpace: 'nowrap',
|
|
2806
|
+
boxShadow: T.ring, transition: `background .15s ${T.ease}`,
|
|
2807
|
+
},
|
|
2808
|
+
onMouseEnter: event => { if (!disabled) event.currentTarget.style.background = T.surfaceHover },
|
|
2809
|
+
onMouseLeave: event => { event.currentTarget.style.background = T.surface },
|
|
2810
|
+
}, label)
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
function Section({ title, count, collapsed, onToggle, actions, children }) {
|
|
2814
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', paddingTop: 2 } },
|
|
2815
|
+
h('div', {
|
|
2816
|
+
style: {
|
|
2817
|
+
display: 'flex', alignItems: 'center', gap: 4, padding: '10px 10px 4px 14px',
|
|
2818
|
+
fontSize: 10.5, fontWeight: 600, letterSpacing: '0.08em', textTransform: 'uppercase', color: T.muted,
|
|
2819
|
+
},
|
|
2820
|
+
},
|
|
2821
|
+
h('button', {
|
|
2822
|
+
type: 'button', onClick: onToggle,
|
|
2823
|
+
style: {
|
|
2824
|
+
appearance: 'none', border: 'none', background: 'transparent', color: 'inherit', cursor: 'pointer',
|
|
2825
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, padding: 0, font: 'inherit',
|
|
2826
|
+
fontSize: 10.5, fontWeight: 600, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'inherit',
|
|
2827
|
+
},
|
|
2828
|
+
},
|
|
2829
|
+
h(Chevron, { open: !collapsed }),
|
|
2830
|
+
h('span', { style: { color: T.muted } }, title)),
|
|
2831
|
+
h('span', { style: { flex: 1 } }),
|
|
2832
|
+
actions,
|
|
2833
|
+
h('span', { style: { color: T.subtle, fontWeight: 500, minWidth: 18, textAlign: 'right' } }, String(count))),
|
|
2834
|
+
collapsed ? null : children)
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
function fileRows(files) {
|
|
2838
|
+
const root = { children: new Map(), files: [] }
|
|
2839
|
+
for (const file of files) {
|
|
2840
|
+
const parts = file.path.split('/')
|
|
2841
|
+
let node = root
|
|
2842
|
+
for (let index = 0; index < parts.length - 1; index += 1) {
|
|
2843
|
+
const name = parts[index]
|
|
2844
|
+
let child = node.children.get(name)
|
|
2845
|
+
if (!child) {
|
|
2846
|
+
child = { name, path: parts.slice(0, index + 1).join('/'), children: new Map(), files: [] }
|
|
2847
|
+
node.children.set(name, child)
|
|
2848
|
+
}
|
|
2849
|
+
node = child
|
|
2850
|
+
}
|
|
2851
|
+
node.files.push({ ...file, name: parts[parts.length - 1] })
|
|
2852
|
+
}
|
|
2853
|
+
return root
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
/* ── tree components ────────────────────────────────────────────── */
|
|
2857
|
+
|
|
2858
|
+
/** Highest-priority change status per directory, derived from changed file paths. */
|
|
2859
|
+
function aggregateDirStatus(statusByPath) {
|
|
2860
|
+
const priority = { U: 5, A: 5, D: 4, R: 3, M: 2 }
|
|
2861
|
+
const result = new Map()
|
|
2862
|
+
if (!statusByPath || statusByPath.size === 0) return result
|
|
2863
|
+
for (const [path, status] of statusByPath) {
|
|
2864
|
+
if (!status) continue
|
|
2865
|
+
const parts = String(path).split('/')
|
|
2866
|
+
parts.pop()
|
|
2867
|
+
let current = ''
|
|
2868
|
+
for (const part of parts) {
|
|
2869
|
+
current = current ? `${current}/${part}` : part
|
|
2870
|
+
const previous = result.get(current)
|
|
2871
|
+
if (!previous || (priority[status] ?? 0) > (priority[previous] ?? 0)) result.set(current, status)
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
return result
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
function TreeRows({ node, depth, expandedDirs, onToggleDir, onOpen, selectedKey, actionsFor, statusByPath, showStatus, hoveredKey, onHoverKey, pickedKeys, onDragStartRow, dirStatusByPath }) {
|
|
2878
|
+
const rows = []
|
|
2879
|
+
const directories = [...node.children.values()].sort((a, b) => a.name.localeCompare(b.name))
|
|
2880
|
+
for (const directory of directories) {
|
|
2881
|
+
const expanded = expandedDirs.has(directory.path)
|
|
2882
|
+
const dirStatus = dirStatusByPath?.get(directory.path)
|
|
2883
|
+
rows.push(h('div', {
|
|
2884
|
+
key: `dir:${directory.path}`,
|
|
2885
|
+
style: {
|
|
2886
|
+
display: 'flex', alignItems: 'center', gap: 5, minHeight: 24, margin: '0 4px',
|
|
2887
|
+
padding: `1px 7px 1px ${7 + depth * 13}px`, cursor: 'pointer', userSelect: 'none',
|
|
2888
|
+
borderRadius: 6, color: T.ink2, transition: `background .12s ${T.ease}`,
|
|
2889
|
+
},
|
|
2890
|
+
onClick: () => onToggleDir(directory.path),
|
|
2891
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
2892
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
2893
|
+
},
|
|
2894
|
+
h(Chevron, { open: expanded, size: 9 }),
|
|
2895
|
+
h(FileGlyph, { name: directory.name, kind: 'dir', expanded }),
|
|
2896
|
+
h('span', { style: { fontSize: 12, fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, directory.name),
|
|
2897
|
+
h('span', { style: { flex: 1 } }),
|
|
2898
|
+
dirStatus ? h(StatusChip, { status: dirStatus, size: 15 }) : null))
|
|
2899
|
+
if (expanded) {
|
|
2900
|
+
rows.push(h(TreeRows, {
|
|
2901
|
+
key: `children:${directory.path}`, node: directory, depth: depth + 1, expandedDirs, onToggleDir,
|
|
2902
|
+
onOpen, selectedKey, actionsFor, statusByPath, showStatus, hoveredKey, onHoverKey, pickedKeys, onDragStartRow, dirStatusByPath,
|
|
2903
|
+
}))
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
const files = [...node.files].sort((a, b) => a.name.localeCompare(b.name))
|
|
2907
|
+
for (const file of files) {
|
|
2908
|
+
const key = file.__staged !== undefined ? `${file.__staged ? 's' : 'w'}:${file.path}` : `f:${file.path}`
|
|
2909
|
+
const active = selectedKey === key || Boolean(pickedKeys?.has(key))
|
|
2910
|
+
const status = showStatus ? statusByPath.get(file.path) : file.status
|
|
2911
|
+
const hovered = hoveredKey === key
|
|
2912
|
+
rows.push(h('div', {
|
|
2913
|
+
key: `file:${key}`,
|
|
2914
|
+
title: `${file.oldPath ? `${file.path} ← ${file.oldPath}` : file.path}${status ? ` · ${status}` : ''}`,
|
|
2915
|
+
draggable: true,
|
|
2916
|
+
onDragStart: event => { if (onDragStartRow) onDragStartRow(file, event) },
|
|
2917
|
+
onClick: event => onOpen(file, event),
|
|
2918
|
+
style: {
|
|
2919
|
+
display: 'flex', alignItems: 'center', gap: 6, minHeight: 25, margin: '0 4px',
|
|
2920
|
+
padding: `1px 7px 1px ${7 + depth * 13 + 12}px`,
|
|
2921
|
+
cursor: 'pointer', background: active ? T.selected : 'transparent', minWidth: 0,
|
|
2922
|
+
borderRadius: 6, transition: `background .12s ${T.ease}`,
|
|
2923
|
+
},
|
|
2924
|
+
onMouseEnter: event => { if (!active) event.currentTarget.style.background = T.hover; onHoverKey?.(key) },
|
|
2925
|
+
onMouseLeave: event => { if (!active) event.currentTarget.style.background = 'transparent'; if (hoveredKey === key) onHoverKey?.(undefined) },
|
|
2926
|
+
},
|
|
2927
|
+
h(FileGlyph, { name: file.name, kind: 'file' }),
|
|
2928
|
+
h('span', {
|
|
2929
|
+
style: {
|
|
2930
|
+
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0, fontSize: 12.5,
|
|
2931
|
+
fontWeight: active ? 500 : 400, color: T.text,
|
|
2932
|
+
},
|
|
2933
|
+
}, file.name),
|
|
2934
|
+
h('span', { style: { flex: 1 } }),
|
|
2935
|
+
(hovered || active) && actionsFor
|
|
2936
|
+
? h('span', { style: { display: 'inline-flex', gap: 1, alignItems: 'center', flex: '0 0 auto' } }, actionsFor(file))
|
|
2937
|
+
: null,
|
|
2938
|
+
h(StatusChip, { status, size: 15 })))
|
|
2939
|
+
}
|
|
2940
|
+
return rows
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
/* ── diff / preview components ──────────────────────────────────── */
|
|
2944
|
+
|
|
2945
|
+
const DIFF_RENDER_STEP = 600
|
|
2946
|
+
|
|
2947
|
+
function DiffLines({ file, view, t, wrap = false, embedded = false, context }) {
|
|
2948
|
+
const files = Array.isArray(file) ? file : [file]
|
|
2949
|
+
const entry = files[0]
|
|
2950
|
+
const [visibleCount, setVisibleCount] = useState(DIFF_RENDER_STEP)
|
|
2951
|
+
const [expandedHunks, setExpandedHunks] = useState(() => new Set())
|
|
2952
|
+
const [expandedGaps, setExpandedGaps] = useState(() => new Map())
|
|
2953
|
+
const scrollRef = useRef(null)
|
|
2954
|
+
const resetKey = `${entry?.path ?? ''}|${entry?.additions ?? 0}|${entry?.deletions ?? 0}|${entry?.hunks?.length ?? 0}|${view}`
|
|
2955
|
+
useEffect(() => {
|
|
2956
|
+
setVisibleCount(DIFF_RENDER_STEP)
|
|
2957
|
+
setExpandedHunks(new Set())
|
|
2958
|
+
setExpandedGaps(new Map())
|
|
2959
|
+
if (scrollRef.current) scrollRef.current.scrollTop = 0
|
|
2960
|
+
}, [resetKey])
|
|
2961
|
+
if (!entry) return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('noDiff'))
|
|
2962
|
+
if (entry.binary) return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('binary'))
|
|
2963
|
+
if (entry.hunks.length === 0) return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('noDiff'))
|
|
2964
|
+
const language = languageOf(entry.path ?? '')
|
|
2965
|
+
const highlight = entry.hunks.reduce((total, hunk) => total + hunk.lines.length, 0) <= 1500
|
|
2966
|
+
const rows = view === 'split' ? splitRows(entry.hunks, language, highlight) : unifiedRows(entry.hunks, language, highlight)
|
|
2967
|
+
const bigHunks = new Set()
|
|
2968
|
+
entry.hunks.forEach((hunk, index) => { if ((hunk.lines?.length ?? 0) > 1000) bigHunks.add(index) })
|
|
2969
|
+
const displayRows = []
|
|
2970
|
+
const collapsedShown = new Set()
|
|
2971
|
+
for (const row of rows) {
|
|
2972
|
+
if (row.hunkIndex !== undefined && bigHunks.has(row.hunkIndex) && !expandedHunks.has(row.hunkIndex)) {
|
|
2973
|
+
if (!collapsedShown.has(row.hunkIndex)) {
|
|
2974
|
+
collapsedShown.add(row.hunkIndex)
|
|
2975
|
+
displayRows.push({ kind: 'collapsed-hunk', key: `c:${row.hunkIndex}`, hunkIndex: row.hunkIndex, count: entry.hunks[row.hunkIndex].lines.length })
|
|
2976
|
+
}
|
|
2977
|
+
continue
|
|
2978
|
+
}
|
|
2979
|
+
displayRows.push(row)
|
|
2980
|
+
}
|
|
2981
|
+
const effectiveWrap = view === 'split' ? true : wrap
|
|
2982
|
+
const visibleRows = embedded || visibleCount >= displayRows.length ? displayRows : displayRows.slice(0, visibleCount)
|
|
2983
|
+
const loadGap = async gap => {
|
|
2984
|
+
if (!context?.repoPath || expandedGaps.get(gap.key) === 'loading') return
|
|
2985
|
+
setExpandedGaps(previous => new Map(previous).set(gap.key, 'loading'))
|
|
2986
|
+
try {
|
|
2987
|
+
const data = await api('/lines', {
|
|
2988
|
+
path: context.repoPath, file: entry.path,
|
|
2989
|
+
start: gap.newStart, end: gap.newStart + gap.count - 1,
|
|
2990
|
+
staged: context.staged ? '1' : '0', hash: context.hash ?? '',
|
|
2991
|
+
})
|
|
2992
|
+
setExpandedGaps(previous => new Map(previous).set(gap.key, Array.isArray(data?.lines) ? data.lines : []))
|
|
2993
|
+
} catch {
|
|
2994
|
+
setExpandedGaps(previous => new Map(previous).set(gap.key, []))
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
const renderRow = row => {
|
|
2998
|
+
if (row.kind === 'gap') {
|
|
2999
|
+
const loaded = expandedGaps.get(row.key)
|
|
3000
|
+
if (Array.isArray(loaded)) {
|
|
3001
|
+
return loaded.map((text, index) => {
|
|
3002
|
+
const newNumber = row.newStart + index
|
|
3003
|
+
const oldNumber = newNumber - (row.delta ?? 0)
|
|
3004
|
+
if (view === 'split') {
|
|
3005
|
+
return h('div', {
|
|
3006
|
+
key: `${row.key}:${index}`,
|
|
3007
|
+
style: { display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', minHeight: 20, borderBottom: `0.5px solid ${T.borderSoft}` },
|
|
3008
|
+
},
|
|
3009
|
+
h(DiffHalf, { line: { number: String(oldNumber), text, kind: 'ctx' }, side: 'left', language, highlight, wrap: effectiveWrap }),
|
|
3010
|
+
h(DiffHalf, { line: { number: String(newNumber), text, kind: 'ctx' }, side: 'right', language, highlight, wrap: effectiveWrap }))
|
|
3011
|
+
}
|
|
3012
|
+
return h('div', {
|
|
3013
|
+
key: `${row.key}:${index}`,
|
|
3014
|
+
style: { display: 'grid', gridTemplateColumns: '46px 46px 16px minmax(max-content, 1fr)', minHeight: 19, alignItems: 'start' },
|
|
3015
|
+
},
|
|
3016
|
+
h('span', { style: numberStyle }, String(oldNumber)),
|
|
3017
|
+
h('span', { style: numberStyle }, String(newNumber)),
|
|
3018
|
+
h('span', { style: { ...numberStyle, textAlign: 'center', color: T.muted } }, ' '),
|
|
3019
|
+
h('span', {
|
|
3020
|
+
style: {
|
|
3021
|
+
fontFamily: MONO, fontSize: 11.5, lineHeight: '19px', whiteSpace: wrap ? 'pre-wrap' : 'pre',
|
|
3022
|
+
overflowWrap: wrap ? 'anywhere' : undefined, paddingRight: 18, color: 'inherit',
|
|
3023
|
+
},
|
|
3024
|
+
}, h(CodeText, { text, language, highlight, baseColor: 'inherit' })))
|
|
3025
|
+
})
|
|
3026
|
+
}
|
|
3027
|
+
const loading = loaded === 'loading'
|
|
3028
|
+
return h('button', {
|
|
3029
|
+
key: row.key, type: 'button', disabled: loading || !context?.repoPath,
|
|
3030
|
+
onClick: () => loadGap(row),
|
|
3031
|
+
style: {
|
|
3032
|
+
display: 'block', width: '100%', textAlign: 'left', appearance: 'none', border: 'none',
|
|
3033
|
+
background: T.hover, color: T.muted, padding: '3px 16px', fontSize: 11, fontFamily: MONO,
|
|
3034
|
+
cursor: loading ? 'default' : 'pointer', opacity: context?.repoPath ? 1 : 0.5,
|
|
3035
|
+
},
|
|
3036
|
+
}, loading ? t('loading') : t('unchangedLines', { count: row.count }))
|
|
3037
|
+
}
|
|
3038
|
+
if (row.kind === 'hunk') return h('div', { key: row.key, style: hunkHeaderStyle }, row.label)
|
|
3039
|
+
if (row.kind === 'notice') return h('div', { key: row.key, style: { padding: '8px 16px', color: T.muted, fontSize: 11.5 } }, t('truncateNotice'))
|
|
3040
|
+
if (row.kind === 'collapsed-hunk') {
|
|
3041
|
+
return h('button', {
|
|
3042
|
+
key: row.key, type: 'button',
|
|
3043
|
+
onClick: () => setExpandedHunks(previous => { const next = new Set(previous); next.add(row.hunkIndex); return next }),
|
|
3044
|
+
style: {
|
|
3045
|
+
display: 'block', width: '100%', textAlign: 'left', appearance: 'none', border: 'none', cursor: 'pointer',
|
|
3046
|
+
background: T.hover, color: T.muted, padding: '8px 16px', fontSize: 11.5, font: 'inherit',
|
|
3047
|
+
},
|
|
3048
|
+
}, t('diffHunkCollapsed', { count: row.count }))
|
|
3049
|
+
}
|
|
3050
|
+
if (view === 'split') {
|
|
3051
|
+
return h('div', {
|
|
3052
|
+
key: row.key,
|
|
3053
|
+
style: { display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', minHeight: 20, borderBottom: `0.5px solid ${T.borderSoft}` },
|
|
3054
|
+
},
|
|
3055
|
+
h(DiffHalf, { line: row.left, side: 'left', language, highlight, wrap: effectiveWrap }),
|
|
3056
|
+
h(DiffHalf, { line: row.right, side: 'right', language, highlight, wrap: effectiveWrap }))
|
|
3057
|
+
}
|
|
3058
|
+
const isAdd = row.kindOfLine === 'add'
|
|
3059
|
+
const isDel = row.kindOfLine === 'del'
|
|
3060
|
+
return h('div', {
|
|
3061
|
+
key: row.key,
|
|
3062
|
+
style: {
|
|
3063
|
+
display: 'grid', gridTemplateColumns: '46px 46px 16px minmax(max-content, 1fr)',
|
|
3064
|
+
background: isAdd ? ADD_BG : isDel ? DEL_BG : 'transparent', minHeight: 19, alignItems: 'start',
|
|
3065
|
+
},
|
|
3066
|
+
},
|
|
3067
|
+
h('span', { style: numberStyle }, row.oldNumber),
|
|
3068
|
+
h('span', { style: numberStyle }, row.newNumber),
|
|
3069
|
+
h('span', {
|
|
3070
|
+
style: { ...numberStyle, textAlign: 'center', opacity: 1, color: isAdd ? T.success : isDel ? T.error : T.muted },
|
|
3071
|
+
}, row.sign),
|
|
3072
|
+
h('span', {
|
|
3073
|
+
style: {
|
|
3074
|
+
fontFamily: MONO, fontSize: 11.5, lineHeight: '19px', whiteSpace: wrap ? 'pre-wrap' : 'pre',
|
|
3075
|
+
overflowWrap: wrap ? 'anywhere' : undefined, paddingRight: 18,
|
|
3076
|
+
color: isAdd ? T.success : isDel ? T.error : 'inherit', opacity: isDel ? 0.9 : 1,
|
|
3077
|
+
},
|
|
3078
|
+
}, h(CodeText, { text: row.text, language, highlight, baseColor: isAdd ? T.success : isDel ? T.error : 'inherit' })))
|
|
3079
|
+
}
|
|
3080
|
+
return h('div', {
|
|
3081
|
+
ref: scrollRef,
|
|
3082
|
+
onScroll: embedded ? undefined : event => {
|
|
3083
|
+
const element = event.currentTarget
|
|
3084
|
+
if (visibleCount < displayRows.length && element.scrollHeight - element.scrollTop - element.clientHeight < 800) {
|
|
3085
|
+
setVisibleCount(count => Math.min(displayRows.length, count + DIFF_RENDER_STEP))
|
|
3086
|
+
}
|
|
3087
|
+
},
|
|
3088
|
+
style: embedded ? { paddingBottom: 8 } : { overflow: 'auto', flex: 1, minHeight: 0, paddingBottom: 24 },
|
|
3089
|
+
},
|
|
3090
|
+
visibleRows.map(renderRow),
|
|
3091
|
+
!embedded && visibleCount < displayRows.length
|
|
3092
|
+
? h('div', { style: { padding: '8px 16px', fontSize: 11.5, color: T.muted } }, t('moreLines', { shown: visibleCount, total: displayRows.length }))
|
|
3093
|
+
: null)
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
function DiffHalf({ line, side, language, highlight, wrap = false }) {
|
|
3097
|
+
const isAdd = line?.kind === 'add'
|
|
3098
|
+
const isDel = line?.kind === 'del'
|
|
3099
|
+
return h('div', {
|
|
3100
|
+
style: {
|
|
3101
|
+
display: 'grid', gridTemplateColumns: '38px 13px minmax(0, 1fr)', minWidth: 0,
|
|
3102
|
+
background: isAdd ? ADD_BG : isDel ? DEL_BG : 'transparent',
|
|
3103
|
+
borderLeft: side === 'right' ? `1px solid ${T.borderSoft}` : 'none',
|
|
3104
|
+
},
|
|
3105
|
+
},
|
|
3106
|
+
h('span', { style: { ...numberStyle, paddingRight: 6 } }, line?.number ?? ''),
|
|
3107
|
+
h('span', {
|
|
3108
|
+
style: { ...numberStyle, textAlign: 'center', opacity: 1, color: isAdd ? T.success : isDel ? T.error : T.muted },
|
|
3109
|
+
}, line ? (isAdd ? '+' : isDel ? '−' : ' ') : ''),
|
|
3110
|
+
h('span', {
|
|
3111
|
+
style: {
|
|
3112
|
+
fontFamily: MONO, fontSize: 11.5, lineHeight: '19px', whiteSpace: wrap ? 'pre-wrap' : 'pre',
|
|
3113
|
+
overflowWrap: wrap ? 'anywhere' : undefined, paddingRight: 14,
|
|
3114
|
+
color: isAdd ? T.success : isDel ? T.error : 'inherit', opacity: isDel ? 0.9 : 1, minWidth: 0,
|
|
3115
|
+
display: 'block',
|
|
3116
|
+
},
|
|
3117
|
+
}, line ? h(CodeText, { text: line.text, language, highlight, baseColor: isAdd ? T.success : isDel ? T.error : 'inherit' }) : ''))
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
const numberStyle = {
|
|
3121
|
+
fontFamily: MONO, fontSize: 10.5, lineHeight: '20px', textAlign: 'right', paddingRight: 9,
|
|
3122
|
+
color: T.subtle, opacity: 0.72, userSelect: 'none', whiteSpace: 'nowrap',
|
|
3123
|
+
}
|
|
3124
|
+
const hunkHeaderStyle = {
|
|
3125
|
+
fontFamily: MONO, fontSize: 11, lineHeight: '26px', padding: '0 14px', color: T.muted,
|
|
3126
|
+
background: T.hover, borderTop: `0.5px solid ${T.borderSoft}`, borderBottom: `0.5px solid ${T.borderSoft}`,
|
|
3127
|
+
whiteSpace: 'pre', overflow: 'hidden', textOverflow: 'ellipsis',
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
/**
|
|
3131
|
+
* Text preview with incremental rendering, mirroring DiffLines: the first PREVIEW_RENDER_STEP
|
|
3132
|
+
* lines commit immediately (a click therefore shows content at once, even for a 5000-line
|
|
3133
|
+
* file), and further chunks mount as the scroller nears the bottom. The body is memoized so
|
|
3134
|
+
* status polling and hover elsewhere cannot rebuild thousands of rows.
|
|
3135
|
+
*/
|
|
3136
|
+
const PREVIEW_RENDER_STEP = 400
|
|
3137
|
+
const PreviewBody = memo(function PreviewBody({ content, path, truncated, t }) {
|
|
3138
|
+
const [visibleCount, setVisibleCount] = useState(PREVIEW_RENDER_STEP)
|
|
3139
|
+
const language = languageOf(path)
|
|
3140
|
+
const lines = useMemo(() => (content ?? '').split('\n').slice(0, MAX_PREVIEW_LINES), [content])
|
|
3141
|
+
useEffect(() => { setVisibleCount(PREVIEW_RENDER_STEP) }, [content, path])
|
|
3142
|
+
const highlight = lines.length <= 3000
|
|
3143
|
+
const visible = visibleCount >= lines.length ? lines : lines.slice(0, visibleCount)
|
|
3144
|
+
return h('div', {
|
|
3145
|
+
onScroll: event => {
|
|
3146
|
+
const element = event.currentTarget
|
|
3147
|
+
if (visibleCount < lines.length && element.scrollHeight - element.scrollTop - element.clientHeight < 600) {
|
|
3148
|
+
setVisibleCount(count => Math.min(lines.length, count + PREVIEW_RENDER_STEP))
|
|
3149
|
+
}
|
|
3150
|
+
},
|
|
3151
|
+
style: { overflow: 'auto', flex: 1, minHeight: 0, paddingBottom: 24 },
|
|
3152
|
+
},
|
|
3153
|
+
visible.map((line, index) => h('div', {
|
|
3154
|
+
key: index,
|
|
3155
|
+
style: { display: 'grid', gridTemplateColumns: '46px minmax(max-content, 1fr)', minHeight: 19 },
|
|
3156
|
+
},
|
|
3157
|
+
h('span', { style: { ...numberStyle, opacity: 0.4 } }, String(index + 1)),
|
|
3158
|
+
h('span', {
|
|
3159
|
+
style: { fontFamily: MONO, fontSize: 11.5, lineHeight: '19px', whiteSpace: 'pre', paddingRight: 18 },
|
|
3160
|
+
}, h(CodeText, { text: line, language, highlight, baseColor: 'inherit' })))),
|
|
3161
|
+
visibleCount < lines.length
|
|
3162
|
+
? h('div', { style: { padding: '8px 16px', fontSize: 11.5, color: T.muted } }, t('moreLines', { shown: visibleCount, total: lines.length }))
|
|
3163
|
+
: null,
|
|
3164
|
+
truncated ? h('div', { style: { padding: '8px 16px', color: T.muted, fontSize: 11.5 } }, t('truncateNotice')) : null)
|
|
3165
|
+
})
|
|
3166
|
+
|
|
3167
|
+
function FilePreview({ state, selection, t }) {
|
|
3168
|
+
if (state.phase === 'loading') return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('loading'))
|
|
3169
|
+
if (state.phase === 'error') return h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, state.error)
|
|
3170
|
+
const data = state.data
|
|
3171
|
+
if (!data) return null
|
|
3172
|
+
const extension = selection.path.slice(selection.path.lastIndexOf('.') + 1).toLowerCase()
|
|
3173
|
+
const rawUrl = `/git-assistant/api/raw?path=${encodeURIComponent(data.repoPath ?? '')}&file=${encodeURIComponent(selection.path)}`
|
|
3174
|
+
const image = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif'].includes(extension)
|
|
3175
|
+
const audio = ['mp3', 'wav', 'ogg', 'm4a', 'aac', 'flac'].includes(extension)
|
|
3176
|
+
const video = ['mp4', 'webm', 'mov', 'm4v', 'ogv'].includes(extension)
|
|
3177
|
+
if (image) {
|
|
3178
|
+
return h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20, overflow: 'auto' } },
|
|
3179
|
+
h('img', { src: rawUrl, alt: selection.path, style: { maxWidth: '100%', maxHeight: '100%', objectFit: 'contain' } }))
|
|
3180
|
+
}
|
|
3181
|
+
if (audio) {
|
|
3182
|
+
return h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 20 } },
|
|
3183
|
+
h('audio', { controls: true, src: rawUrl, style: { width: '80%' } }))
|
|
3184
|
+
}
|
|
3185
|
+
if (video) {
|
|
3186
|
+
return h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 16, overflow: 'auto' } },
|
|
3187
|
+
h('video', { controls: true, src: rawUrl, style: { maxWidth: '100%', maxHeight: '100%' } }))
|
|
3188
|
+
}
|
|
3189
|
+
if (extension === 'pdf') {
|
|
3190
|
+
return h('div', { style: { flex: 1, minHeight: 0, display: 'flex' } },
|
|
3191
|
+
h('iframe', { src: rawUrl, title: selection.path, style: { flex: 1, width: '100%', height: '100%', border: 'none', background: '#fff' } }))
|
|
3192
|
+
}
|
|
3193
|
+
if (data.binary) {
|
|
3194
|
+
return h('div', { style: { flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column', gap: 6, color: T.muted, fontSize: 12.5, padding: 18 } },
|
|
3195
|
+
h('div', null, t('binary')),
|
|
3196
|
+
h('div', { style: { fontFamily: MONO, fontSize: 11, color: T.subtle } }, `${selection.path} · ${typeof data.size === 'number' ? `${(data.size / 1024).toFixed(1)} KB` : ''}`))
|
|
3197
|
+
}
|
|
3198
|
+
if (data.binary === false && typeof data.content === 'string') {
|
|
3199
|
+
return h(PreviewBody, { content: data.content, path: selection.path, truncated: Boolean(data.truncated), t })
|
|
3200
|
+
}
|
|
3201
|
+
return null
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
function AllDiff({ state, view, t, context }) {
|
|
3205
|
+
if (state.phase === 'loading') return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('allDiffLoading'))
|
|
3206
|
+
if (state.phase === 'error') return h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, state.error)
|
|
3207
|
+
if (state.entries.length === 0) return h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('noDiff'))
|
|
3208
|
+
return h('div', { style: { overflow: 'auto', flex: 1, minHeight: 0, paddingBottom: 12 } },
|
|
3209
|
+
state.entries.map(item => h('div', { key: item.file },
|
|
3210
|
+
h('div', {
|
|
3211
|
+
style: {
|
|
3212
|
+
display: 'flex', alignItems: 'center', gap: 8, padding: '8px 14px',
|
|
3213
|
+
borderBottom: `0.5px solid ${T.borderSoft}`, background: T.hover,
|
|
3214
|
+
position: 'sticky', top: 0, zIndex: 1,
|
|
3215
|
+
},
|
|
3216
|
+
},
|
|
3217
|
+
h('span', { style: { fontFamily: MONO, fontSize: 11.5, color: T.ink2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, item.file),
|
|
3218
|
+
h('span', { style: { flex: 1 } }),
|
|
3219
|
+
item.entry
|
|
3220
|
+
? h('span', { style: { display: 'inline-flex', gap: 6, fontFamily: MONO, fontSize: 10.5, whiteSpace: 'nowrap' } },
|
|
3221
|
+
h('span', { style: { color: T.success } }, `+${item.entry.additions ?? 0}`),
|
|
3222
|
+
h('span', { style: { color: T.error } }, `−${item.entry.deletions ?? 0}`))
|
|
3223
|
+
: null),
|
|
3224
|
+
item.error
|
|
3225
|
+
? h('div', { style: { padding: '6px 14px', color: T.error, fontSize: 11.5 } }, item.error)
|
|
3226
|
+
: item.entry && item.entry.binary
|
|
3227
|
+
? h('div', { style: { padding: '6px 14px', color: T.muted, fontSize: 11.5 } }, t('binary'))
|
|
3228
|
+
: item.entry && item.entry.hunks.length > 0
|
|
3229
|
+
? h(DiffLines, { file: [item.entry], view, t, context })
|
|
3230
|
+
: h('div', { style: { padding: '6px 14px', color: T.muted, fontSize: 11.5 } }, t('noDiff')))))
|
|
3231
|
+
}
|
|
3232
|
+
|
|
3233
|
+
/* ── dialogs / toast ────────────────────────────────────────────── */
|
|
3234
|
+
|
|
3235
|
+
function Dialog({ dialog, onClose }) {
|
|
3236
|
+
if (!dialog) return null
|
|
3237
|
+
return h('div', {
|
|
3238
|
+
style: {
|
|
3239
|
+
position: 'fixed', inset: 0, zIndex: 100, background: 'color-mix(in srgb, #000 32%, transparent)',
|
|
3240
|
+
backdropFilter: 'blur(6px)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24,
|
|
3241
|
+
},
|
|
3242
|
+
onPointerDown: event => { if (event.target === event.currentTarget) onClose() },
|
|
3243
|
+
},
|
|
3244
|
+
h('div', {
|
|
3245
|
+
style: {
|
|
3246
|
+
width: 420, maxWidth: '100%', background: T.menu, border: `0.5px solid ${T.border}`,
|
|
3247
|
+
borderRadius: T.rXl, padding: 20, boxShadow: T.shadowProminent,
|
|
3248
|
+
backdropFilter: 'blur(28px) saturate(170%)', display: 'flex', flexDirection: 'column', gap: 12,
|
|
3249
|
+
},
|
|
3250
|
+
},
|
|
3251
|
+
h('div', { style: { fontSize: 14, fontWeight: 600, letterSpacing: '0.01em' } }, dialog.title),
|
|
3252
|
+
h('div', { style: { fontSize: 12.5, color: T.ink2, lineHeight: '20px' } }, dialog.message),
|
|
3253
|
+
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8, marginTop: 4 } },
|
|
3254
|
+
h('button', {
|
|
3255
|
+
type: 'button', onClick: onClose,
|
|
3256
|
+
style: {
|
|
3257
|
+
appearance: 'none', border: `0.5px solid ${T.lineStrong}`, background: 'transparent', color: T.ink2,
|
|
3258
|
+
height: 30, padding: '0 16px', borderRadius: T.pill, fontSize: 12, cursor: 'pointer',
|
|
3259
|
+
},
|
|
3260
|
+
}, dialog.cancelLabel),
|
|
3261
|
+
h('button', {
|
|
3262
|
+
type: 'button',
|
|
3263
|
+
onClick: () => { const run = dialog.onConfirm; onClose(); run() },
|
|
3264
|
+
style: {
|
|
3265
|
+
appearance: 'none', border: 'none', background: dialog.danger ? T.error : T.primary,
|
|
3266
|
+
color: T.inverse, height: 30, padding: '0 16px', borderRadius: T.pill, fontSize: 12,
|
|
3267
|
+
cursor: 'pointer', boxShadow: T.shadowSoft,
|
|
3268
|
+
},
|
|
3269
|
+
}, dialog.confirmLabel))))
|
|
3270
|
+
}
|
|
3271
|
+
|
|
3272
|
+
/** File-history overlay: commits touching one file, click to open that commit's diff. */
|
|
3273
|
+
function FileHistoryDialog({ history, t, onClose, onOpenCommit }) {
|
|
3274
|
+
const [state, setState] = useState({ phase: 'loading', commits: [], error: null })
|
|
3275
|
+
const path = history?.path
|
|
3276
|
+
const file = history?.file
|
|
3277
|
+
useEffect(() => {
|
|
3278
|
+
if (!path || !file) return undefined
|
|
3279
|
+
let live = true
|
|
3280
|
+
setState({ phase: 'loading', commits: [], error: null })
|
|
3281
|
+
api('/file-log', { path, file, limit: 40 })
|
|
3282
|
+
.then(data => { if (live) setState({ phase: 'ready', commits: Array.isArray(data?.commits) ? data.commits : [], error: null }) })
|
|
3283
|
+
.catch(error => { if (live) setState({ phase: 'error', commits: [], error: String(error?.message ?? error) }) })
|
|
3284
|
+
return () => { live = false }
|
|
3285
|
+
}, [path, file])
|
|
3286
|
+
if (!history) return null
|
|
3287
|
+
return h('div', {
|
|
3288
|
+
style: {
|
|
3289
|
+
position: 'fixed', inset: 0, zIndex: 100, background: 'color-mix(in srgb, #000 32%, transparent)',
|
|
3290
|
+
backdropFilter: 'blur(6px)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 24,
|
|
3291
|
+
},
|
|
3292
|
+
onPointerDown: event => { if (event.target === event.currentTarget) onClose() },
|
|
3293
|
+
},
|
|
3294
|
+
h('div', {
|
|
3295
|
+
style: {
|
|
3296
|
+
width: 460, maxWidth: '100%', maxHeight: '80vh', background: T.menu, border: `0.5px solid ${T.border}`,
|
|
3297
|
+
borderRadius: T.rXl, padding: 18, boxShadow: T.shadowProminent,
|
|
3298
|
+
backdropFilter: 'blur(28px) saturate(170%)', display: 'flex', flexDirection: 'column', gap: 10,
|
|
3299
|
+
},
|
|
3300
|
+
},
|
|
3301
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
3302
|
+
h('span', { style: { display: 'inline-flex', opacity: 0.65 } }, h(IconHistory)),
|
|
3303
|
+
h('span', { style: { fontSize: 13, fontWeight: 600 } }, t('fileHistory')),
|
|
3304
|
+
h('span', { style: { flex: 1 } }),
|
|
3305
|
+
h('button', {
|
|
3306
|
+
type: 'button', onClick: onClose,
|
|
3307
|
+
style: { appearance: 'none', border: 'none', background: 'transparent', color: T.muted, cursor: 'pointer', fontSize: 14, padding: '0 4px' },
|
|
3308
|
+
}, '×')),
|
|
3309
|
+
h('div', { style: { fontSize: 11.5, fontFamily: MONO, color: T.ink2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', paddingBottom: 4, borderBottom: `0.5px solid ${T.borderSoft}` } }, file),
|
|
3310
|
+
h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', display: 'flex', flexDirection: 'column', gap: 2 } },
|
|
3311
|
+
state.phase === 'loading' ? h('div', { style: { padding: '10px 2px', fontSize: 12, color: T.muted } }, t('loading'))
|
|
3312
|
+
: state.phase === 'error' ? h('div', { style: { padding: '10px 2px', fontSize: 12, color: T.error } }, state.error)
|
|
3313
|
+
: state.commits.length === 0 ? h('div', { style: { padding: '10px 2px', fontSize: 12, color: T.subtle } }, t('fileHistoryEmpty'))
|
|
3314
|
+
: state.commits.map(commit => h('button', {
|
|
3315
|
+
key: commit.oid, type: 'button',
|
|
3316
|
+
onClick: () => { onOpenCommit?.(commit); onClose?.() },
|
|
3317
|
+
style: {
|
|
3318
|
+
appearance: 'none', border: 'none', background: 'transparent', color: 'inherit', cursor: 'pointer',
|
|
3319
|
+
display: 'flex', alignItems: 'center', gap: 8, textAlign: 'left', padding: '6px 8px',
|
|
3320
|
+
borderRadius: T.rSm, font: 'inherit',
|
|
3321
|
+
},
|
|
3322
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
3323
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
3324
|
+
},
|
|
3325
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10.5, color: T.accent, flex: '0 0 auto' } }, commit.oid.slice(0, 7)),
|
|
3326
|
+
h('span', { style: { flex: 1, minWidth: 0, fontSize: 12, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, commit.subject || '(no message)'),
|
|
3327
|
+
commit.time ? h('span', { style: { fontSize: 10.5, color: T.subtle, flex: '0 0 auto' } }, formatRelativeTime(commit.time)) : null)))))
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
function Toast({ toast }) {
|
|
3331
|
+
if (!toast) return null
|
|
3332
|
+
return h('div', {
|
|
3333
|
+
style: {
|
|
3334
|
+
position: 'absolute', left: '50%', bottom: 20, transform: 'translateX(-50%)', zIndex: 60,
|
|
3335
|
+
background: T.menu, border: `0.5px solid ${T.border}`, borderRadius: T.pill, padding: '8px 18px',
|
|
3336
|
+
fontSize: 12, boxShadow: T.shadowProminent, backdropFilter: 'blur(20px) saturate(160%)',
|
|
3337
|
+
maxWidth: '80%', color: toast.kind === 'error' ? T.error : T.text,
|
|
3338
|
+
},
|
|
3339
|
+
}, toast.text)
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
|
|
3343
|
+
/**
|
|
3344
|
+
* One small stylesheet for things inline styles cannot express: placeholder tone, textarea
|
|
3345
|
+
* caret, and thin scrollbars that suit the card surfaces. Mounted once per panel tree.
|
|
3346
|
+
*/
|
|
3347
|
+
const SURFACE_STYLE_ID = 'dsh-git-assistant-surface'
|
|
3348
|
+
function ensureSurfaceStyle() {
|
|
3349
|
+
if (typeof document === 'undefined') return undefined
|
|
3350
|
+
if (document.getElementById(SURFACE_STYLE_ID)) return undefined
|
|
3351
|
+
const style = document.createElement('style')
|
|
3352
|
+
style.id = SURFACE_STYLE_ID
|
|
3353
|
+
style.textContent = `
|
|
3354
|
+
.ga-panel textarea::placeholder,
|
|
3355
|
+
.ga-panel input::placeholder { color: var(--dsw-alias-label-caption, #adb2b8); opacity: 1; }
|
|
3356
|
+
.ga-panel textarea, .ga-panel input { caret-color: var(--dsw-alias-link, #4176e6); }
|
|
3357
|
+
.ga-panel ::-webkit-scrollbar { width: 9px; height: 9px; }
|
|
3358
|
+
.ga-panel ::-webkit-scrollbar-thumb {
|
|
3359
|
+
background: var(--dsw-alias-scrollbar-bg-l1, #e5e5e5); border-radius: 6px;
|
|
3360
|
+
border: 2px solid transparent; background-clip: padding-box;
|
|
3361
|
+
}
|
|
3362
|
+
.ga-panel ::-webkit-scrollbar-thumb:hover { background: var(--dsw-alias-scrollbar-hover-l1, #d4d4d4); background-clip: padding-box; }
|
|
3363
|
+
.ga-panel ::-webkit-scrollbar-track { background: transparent; }
|
|
3364
|
+
`
|
|
3365
|
+
document.head.appendChild(style)
|
|
3366
|
+
return () => { try { style.remove() } catch { /* gone */ } }
|
|
3367
|
+
}
|
|
3368
|
+
|
|
3369
|
+
/* ── main panel ─────────────────────────────────────────────────── */
|
|
3370
|
+
|
|
3371
|
+
function Panel({ t, ctx, sessionId, renderFactorySlot, inputActions }) {
|
|
3372
|
+
useCodePalette()
|
|
3373
|
+
const [repositories, refreshRepositories] = useRepositories()
|
|
3374
|
+
const [storedId, setStoredId] = useSharedState('repositoryId', readStoredRepository)
|
|
3375
|
+
const [dataVersion, setDataVersion] = useState(0)
|
|
3376
|
+
const bump = useCallback(() => setDataVersion(value => value + 1), [])
|
|
3377
|
+
const [mode, setMode] = useSharedState('mode', 'changes')
|
|
3378
|
+
const [selection, setSelection] = useSharedState('selection', null)
|
|
3379
|
+
const [view, setView] = useSharedState('view', 'unified')
|
|
3380
|
+
const [commitMessage, setCommitMessage] = useState('')
|
|
3381
|
+
const [amend, setAmend] = useState(false)
|
|
3382
|
+
const [commitMenu, setCommitMenu] = useState(false)
|
|
3383
|
+
const commitMenuRef = useRef(null)
|
|
3384
|
+
const commitRef = useRef(null)
|
|
3385
|
+
const [busy, setBusy] = useState(false)
|
|
3386
|
+
const [dialog, setDialog] = useState(null)
|
|
3387
|
+
const [toast, setToast] = useState(null)
|
|
3388
|
+
const [collapsedSections, setCollapsedSections] = useState(() => new Set())
|
|
3389
|
+
const [expandedDirs, setExpandedDirs] = useState(() => new Set())
|
|
3390
|
+
const [leftWidth, setLeftWidth] = useState(() => { try { const stored = Number(window.localStorage.getItem('dsh-git-assistant:left-width')); return Number.isFinite(stored) && stored >= 240 && stored <= 560 ? stored : 318 } catch { return 318 } })
|
|
3391
|
+
const bodyRef = useRef(null)
|
|
3392
|
+
const [bodyWidth, setBodyWidth] = useState(0)
|
|
3393
|
+
useEffect(() => {
|
|
3394
|
+
const element = bodyRef.current
|
|
3395
|
+
if (!element || typeof ResizeObserver === 'undefined') return undefined
|
|
3396
|
+
const observer = new ResizeObserver(entries => {
|
|
3397
|
+
for (const entry of entries) setBodyWidth(Math.round(entry.contentRect.width))
|
|
3398
|
+
})
|
|
3399
|
+
observer.observe(element)
|
|
3400
|
+
return () => observer.disconnect()
|
|
3401
|
+
}, [])
|
|
3402
|
+
const [hoveredKey, setHoveredKey] = useState(undefined)
|
|
3403
|
+
const [picked, setPicked] = useState(() => new Set())
|
|
3404
|
+
const [graphPath, setGraphPath] = useState(undefined)
|
|
3405
|
+
const [wrap, setWrap] = useState(false)
|
|
3406
|
+
const [commitPickerOpen, setCommitPickerOpen] = useState(false)
|
|
3407
|
+
const commitPickerRef = useRef(null)
|
|
3408
|
+
const [allFilesCollapsed, setAllFilesCollapsed] = useState(false)
|
|
3409
|
+
const [issuesState, setIssuesState] = useSharedState('issuesState', 'open')
|
|
3410
|
+
const [issuesSearch, setIssuesSearch] = useSharedState('issuesSearch', '')
|
|
3411
|
+
const [issuesQuery, setIssuesQuery] = useState('')
|
|
3412
|
+
const [issueNumber, setIssueNumber] = useSharedState('issueNumber', undefined)
|
|
3413
|
+
const [issuesVersion, setIssuesVersion] = useState(0)
|
|
3414
|
+
const [issuesLimit, setIssuesLimit] = useState(60)
|
|
3415
|
+
const [issuesWidth, setIssuesWidth] = useState(480)
|
|
3416
|
+
const [quoteText, setQuoteText] = useState(undefined)
|
|
3417
|
+
const [quoteAnchor, setQuoteAnchor] = useState(undefined)
|
|
3418
|
+
const rightCardRef = useRef(null)
|
|
3419
|
+
const dragFilesRef = useRef(new Map())
|
|
3420
|
+
const [filesFilter, setFilesFilter] = useState('')
|
|
3421
|
+
const [menuOpen, setMenuOpen] = useState(false)
|
|
3422
|
+
const [branchMenuOpen, setBranchMenuOpen] = useState(false)
|
|
3423
|
+
const [newBranch, setNewBranch] = useState('')
|
|
3424
|
+
const menuRef = useRef(null)
|
|
3425
|
+
const branchRef = useRef(null)
|
|
3426
|
+
|
|
3427
|
+
const sessionCwd = useMemo(() => {
|
|
3428
|
+
if (!ctx || !sessionId) return undefined
|
|
3429
|
+
try {
|
|
3430
|
+
const list = ctx.sessions?.list?.getSnapshot?.()
|
|
3431
|
+
const row = list?.byId?.[sessionId]
|
|
3432
|
+
return typeof row?.cwd === 'string' ? row.cwd : undefined
|
|
3433
|
+
} catch { return undefined }
|
|
3434
|
+
}, [ctx, sessionId])
|
|
3435
|
+
|
|
3436
|
+
const preferredId = useMemo(() => {
|
|
3437
|
+
const items = repositories.items
|
|
3438
|
+
if (items.length === 0) return undefined
|
|
3439
|
+
if (storedId && items.some(item => item.id === storedId)) return storedId
|
|
3440
|
+
if (sessionCwd) {
|
|
3441
|
+
const match = items.find(item => item.path === sessionCwd || sessionCwd.startsWith(item.path + '/'))
|
|
3442
|
+
if (match) return match.id
|
|
3443
|
+
}
|
|
3444
|
+
return items[0].id
|
|
3445
|
+
}, [repositories.items, storedId, sessionCwd])
|
|
3446
|
+
const active = useMemo(() => repositories.items.find(item => item.id === preferredId), [repositories.items, preferredId])
|
|
3447
|
+
useRepoEvents(active?.path, useCallback(() => {
|
|
3448
|
+
if (active?.path) refreshStatusPath(active.path)
|
|
3449
|
+
bump()
|
|
3450
|
+
}, [active?.path, bump]))
|
|
3451
|
+
const repositoryChoices = useMemo(() => {
|
|
3452
|
+
const unique = new Map()
|
|
3453
|
+
for (const repository of repositories.items) {
|
|
3454
|
+
const current = unique.get(repository.repoName)
|
|
3455
|
+
if (!current || repository.isMain) unique.set(repository.repoName, repository)
|
|
3456
|
+
}
|
|
3457
|
+
return [...unique.values()]
|
|
3458
|
+
}, [repositories.items])
|
|
3459
|
+
|
|
3460
|
+
const [status, refreshStatus] = useStatus(active, dataVersion)
|
|
3461
|
+
const branches = useBranches(active, dataVersion)
|
|
3462
|
+
const files = useFiles(active, dataVersion, mode === 'files')
|
|
3463
|
+
const [diff, refreshDiff] = useDiff(selection?.repoPath ? { path: selection.repoPath } : active, selection, dataVersion)
|
|
3464
|
+
const preview = useFilePreview(selection?.repoPath ? { path: selection.repoPath } : active, selection)
|
|
3465
|
+
const [allDiff, refreshAllDiff] = useAllDiffs(active, selection, status.data, dataVersion)
|
|
3466
|
+
const [worktrees, refreshWorktrees] = useWorktrees(active, dataVersion)
|
|
3467
|
+
const [localCommits, refreshLocalCommits] = useLocalCommits(active, commitPickerOpen)
|
|
3468
|
+
const [commitPatch, refreshCommitPatch] = useCommitPatch(active, selection)
|
|
3469
|
+
const issues = useIssues(active, mode === 'issues', issuesState, issuesQuery, issuesLimit, issuesVersion)
|
|
3470
|
+
const [issueNonce, bumpIssueNonce] = useState(0)
|
|
3471
|
+
const issueDetail = useIssueDetail(active, issueNumber, issueNonce)
|
|
3472
|
+
const issueComments = useIssueComments(active, issueNumber, issueNonce)
|
|
3473
|
+
const [fileHistory, setFileHistory] = useState(null)
|
|
3474
|
+
useEffect(() => {
|
|
3475
|
+
if (!issues.stale) return undefined
|
|
3476
|
+
const timer = setTimeout(() => setIssuesVersion(value => value + 1), 1200)
|
|
3477
|
+
return () => clearTimeout(timer)
|
|
3478
|
+
}, [issues.stale, issues.issues.length])
|
|
3479
|
+
useEffect(() => {
|
|
3480
|
+
if (mode !== 'issues' || !active?.path) return undefined
|
|
3481
|
+
let live = true
|
|
3482
|
+
const touch = () => { if (live) api('/issues/touch', { path: active.path }).catch(() => {}) }
|
|
3483
|
+
touch()
|
|
3484
|
+
const timer = setInterval(touch, 60000)
|
|
3485
|
+
return () => { live = false; clearInterval(timer) }
|
|
3486
|
+
}, [mode, active?.path])
|
|
3487
|
+
|
|
3488
|
+
useEffect(() => {
|
|
3489
|
+
if (!commitPickerOpen) return undefined
|
|
3490
|
+
const close = event => { if (commitPickerRef.current && !commitPickerRef.current.contains(event.target)) setCommitPickerOpen(false) }
|
|
3491
|
+
document.addEventListener('pointerdown', close)
|
|
3492
|
+
return () => document.removeEventListener('pointerdown', close)
|
|
3493
|
+
}, [commitPickerOpen])
|
|
3494
|
+
useEffect(() => {
|
|
3495
|
+
if (!selection || selection.kind !== 'commit-files') return
|
|
3496
|
+
setWrap(false)
|
|
3497
|
+
setAllFilesCollapsed(false)
|
|
3498
|
+
}, [selection?.hash])
|
|
3499
|
+
useEffect(() => {
|
|
3500
|
+
const timer = setTimeout(() => setIssuesQuery(issuesSearch.trim()), 350)
|
|
3501
|
+
return () => clearTimeout(timer)
|
|
3502
|
+
}, [issuesSearch])
|
|
3503
|
+
useEffect(() => { setIssuesLimit(60) }, [issuesState, issuesQuery, active?.path])
|
|
3504
|
+
useEffect(() => {
|
|
3505
|
+
if (!commitMenu) return undefined
|
|
3506
|
+
const close = event => { if (commitMenuRef.current && !commitMenuRef.current.contains(event.target)) setCommitMenu(false) }
|
|
3507
|
+
document.addEventListener('pointerdown', close)
|
|
3508
|
+
return () => document.removeEventListener('pointerdown', close)
|
|
3509
|
+
}, [commitMenu])
|
|
3510
|
+
useEffect(() => {
|
|
3511
|
+
if (!active) return
|
|
3512
|
+
try { window.localStorage.setItem(STORAGE_REPOSITORY, active.id) } catch { /* ignore */ }
|
|
3513
|
+
}, [active?.id])
|
|
3514
|
+
useEffect(() => { setSelection(null); setFilesFilter(''); setBranchMenuOpen(false) }, [active?.id])
|
|
3515
|
+
useEffect(() => { try { window.localStorage.setItem('dsh-git-assistant:left-width', String(leftWidth)) } catch { /* ignore */ } }, [leftWidth])
|
|
3516
|
+
useEffect(() => {
|
|
3517
|
+
if (!menuOpen && !branchMenuOpen) return undefined
|
|
3518
|
+
const close = event => {
|
|
3519
|
+
if (menuOpen && menuRef.current && !menuRef.current.contains(event.target)) setMenuOpen(false)
|
|
3520
|
+
if (branchMenuOpen && branchRef.current && !branchRef.current.contains(event.target)) setBranchMenuOpen(false)
|
|
3521
|
+
}
|
|
3522
|
+
document.addEventListener('pointerdown', close)
|
|
3523
|
+
return () => document.removeEventListener('pointerdown', close)
|
|
3524
|
+
}, [menuOpen, branchMenuOpen])
|
|
3525
|
+
useEffect(() => {
|
|
3526
|
+
if (!toast) return undefined
|
|
3527
|
+
const timer = setTimeout(() => setToast(null), 3600)
|
|
3528
|
+
return () => clearTimeout(timer)
|
|
3529
|
+
}, [toast])
|
|
3530
|
+
|
|
3531
|
+
const notify = useCallback((text, kind = 'info') => setToast({ text, kind }), [])
|
|
3532
|
+
/** Point at the card holding a branch: scroll it in and flash an outline for a moment. */
|
|
3533
|
+
const flashWorktree = useCallback(path => {
|
|
3534
|
+
if (!path || typeof document === 'undefined') return
|
|
3535
|
+
const node = document.querySelector(`[data-worktree-path="${String(path).replace(/"/g, '\\"')}"]`)
|
|
3536
|
+
if (!node) return
|
|
3537
|
+
if (typeof node.scrollIntoView === 'function') node.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
|
3538
|
+
node.style.outline = `2px solid ${T.accent}`
|
|
3539
|
+
node.style.outlineOffset = '2px'
|
|
3540
|
+
setTimeout(() => { node.style.outline = ''; node.style.outlineOffset = '' }, 1600)
|
|
3541
|
+
}, [])
|
|
3542
|
+
useEffect(() => ensureSurfaceStyle(), [])
|
|
3543
|
+
const postIssueComment = useCallback(async body => {
|
|
3544
|
+
if (!active?.path || !issueNumber) throw new Error('no issue selected')
|
|
3545
|
+
try {
|
|
3546
|
+
await apiPost('/issue-comment', { path: active.path, number: issueNumber, body })
|
|
3547
|
+
notify(t('commentDone'))
|
|
3548
|
+
} catch (error) {
|
|
3549
|
+
notify(String(error?.message ?? error), 'error')
|
|
3550
|
+
throw error
|
|
3551
|
+
}
|
|
3552
|
+
bumpIssueNonce(value => value + 1)
|
|
3553
|
+
setIssuesVersion(value => value + 1)
|
|
3554
|
+
}, [active?.path, issueNumber, notify, t])
|
|
3555
|
+
const toggleIssueState = useCallback(async state => {
|
|
3556
|
+
if (!active?.path || !issueNumber) throw new Error('no issue selected')
|
|
3557
|
+
try {
|
|
3558
|
+
await apiPost('/issue-state', { path: active.path, number: issueNumber, state })
|
|
3559
|
+
notify(state === 'closed' ? t('issueClosedOk') : t('issueReopenedOk'))
|
|
3560
|
+
} catch (error) {
|
|
3561
|
+
notify(String(error?.message ?? error), 'error')
|
|
3562
|
+
throw error
|
|
3563
|
+
}
|
|
3564
|
+
bumpIssueNonce(value => value + 1)
|
|
3565
|
+
setIssuesVersion(value => value + 1)
|
|
3566
|
+
}, [active?.path, issueNumber, notify, t])
|
|
3567
|
+
|
|
3568
|
+
const stagedFiles = useMemo(() => (status.data?.staged ?? []).map(entry => ({ ...entry, __staged: true })), [status.data])
|
|
3569
|
+
const changeFiles = useMemo(() => [
|
|
3570
|
+
...(status.data?.unstaged ?? []).map(entry => ({ ...entry, __staged: false })),
|
|
3571
|
+
...(status.data?.untracked ?? []).map(entry => ({ ...entry, __staged: false })),
|
|
3572
|
+
], [status.data])
|
|
3573
|
+
const statusByPath = useMemo(() => {
|
|
3574
|
+
const map = new Map()
|
|
3575
|
+
for (const entry of status.data?.staged ?? []) map.set(entry.path, entry.status)
|
|
3576
|
+
for (const entry of status.data?.unstaged ?? []) if (!map.has(entry.path)) map.set(entry.path, entry.status)
|
|
3577
|
+
for (const entry of status.data?.untracked ?? []) if (!map.has(entry.path)) map.set(entry.path, entry.status)
|
|
3578
|
+
return map
|
|
3579
|
+
}, [status.data])
|
|
3580
|
+
|
|
3581
|
+
const selectedKey = useMemo(() => {
|
|
3582
|
+
if (!selection) return undefined
|
|
3583
|
+
if (selection.kind === 'diff') return `${selection.staged ? 's' : 'w'}:${selection.path}`
|
|
3584
|
+
return `f:${selection.path}`
|
|
3585
|
+
}, [selection])
|
|
3586
|
+
|
|
3587
|
+
const run = useCallback(async (action, successText) => {
|
|
3588
|
+
setBusy(true)
|
|
3589
|
+
try {
|
|
3590
|
+
await action()
|
|
3591
|
+
if (successText) notify(successText, 'ok')
|
|
3592
|
+
bump()
|
|
3593
|
+
} catch (error) {
|
|
3594
|
+
notify(error?.code === 'branch-in-worktree'
|
|
3595
|
+
? t('branchInWorktreeHint', { name: basename(error.worktree ?? '') })
|
|
3596
|
+
: String(error?.message ?? error), 'error')
|
|
3597
|
+
} finally {
|
|
3598
|
+
setBusy(false)
|
|
3599
|
+
}
|
|
3600
|
+
}, [bump, notify])
|
|
3601
|
+
|
|
3602
|
+
const stagePaths = useCallback(paths => run(
|
|
3603
|
+
() => apiPost('/stage', { path: active.path, files: paths }),
|
|
3604
|
+
t('stagedDone', { count: paths.length })), [active?.path, run, t])
|
|
3605
|
+
const unstagePaths = useCallback(paths => run(
|
|
3606
|
+
() => apiPost('/unstage', { path: active.path, files: paths }),
|
|
3607
|
+
t('unstagedDone', { count: paths.length })), [active?.path, run, t])
|
|
3608
|
+
|
|
3609
|
+
const discardPaths = useCallback(paths => {
|
|
3610
|
+
const tracked = paths.filter(path => {
|
|
3611
|
+
const entry = changeFiles.find(file => file.path === path || (file.path === path && file.__staged === false))
|
|
3612
|
+
return entry?.status !== 'U'
|
|
3613
|
+
})
|
|
3614
|
+
const untracked = paths.filter(path => !tracked.includes(path))
|
|
3615
|
+
const message = paths.length === 1
|
|
3616
|
+
? (tracked.length > 0 ? t('discardTracked', { file: paths[0] }) : t('discardUntracked', { file: paths[0] }))
|
|
3617
|
+
: t('discardAllMessage', { count: paths.length })
|
|
3618
|
+
setDialog({
|
|
3619
|
+
title: paths.length === 1 ? t('discardTitle') : t('discardAllTitle'),
|
|
3620
|
+
message,
|
|
3621
|
+
confirmLabel: t('discard'),
|
|
3622
|
+
cancelLabel: t('cancel'),
|
|
3623
|
+
danger: true,
|
|
3624
|
+
onConfirm: () => run(() => apiPost('/discard', { path: active.path, files: paths })),
|
|
3625
|
+
})
|
|
3626
|
+
}, [changeFiles, run, t])
|
|
3627
|
+
|
|
3628
|
+
const graphRepository = graphPath ? { path: graphPath } : active
|
|
3629
|
+
const graphDrawer = mode === 'changes'
|
|
3630
|
+
? h(GraphPanel, {
|
|
3631
|
+
t, repository: graphRepository, width: leftWidth,
|
|
3632
|
+
onOpenDiff: (hash, path) => {
|
|
3633
|
+
if (!graphRepository?.path) return
|
|
3634
|
+
setSelection({ kind: 'commit-diff', repoPath: graphRepository.path, hash, path })
|
|
3635
|
+
},
|
|
3636
|
+
})
|
|
3637
|
+
: null
|
|
3638
|
+
const worktreeFilesCards = h('div', { style: { flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', overflowY: 'auto', padding: '10px 10px 12px' } },
|
|
3639
|
+
worktrees.items.map(item => h(WorktreeFilesCard, {
|
|
3640
|
+
key: item.path, t, item, defaultOpen: item.path === active?.path || Boolean(item.isMain), visible: mode === 'files',
|
|
3641
|
+
selectedPath: selection?.kind === 'file' ? selection.path : undefined,
|
|
3642
|
+
onSelect: path => setGraphPath(path),
|
|
3643
|
+
onNotify: notify,
|
|
3644
|
+
onOpen: (file, repoPath) => { setGraphPath(repoPath); setSelection({ kind: 'file', path: file.path, repoPath }) },
|
|
3645
|
+
})))
|
|
3646
|
+
const worktreeCards = h('div', { style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '10px 10px 44px' } },
|
|
3647
|
+
worktrees.items.map(item => h(WorktreeCard, {
|
|
3648
|
+
key: item.path, t, item, defaultOpen: item.path === active?.path || Boolean(item.isMain), visible: mode === 'changes',
|
|
3649
|
+
selectedPath: selection?.kind === 'diff' ? selection.path : undefined,
|
|
3650
|
+
onNotify: notify,
|
|
3651
|
+
onChanged: () => { refreshWorktrees(); bump() },
|
|
3652
|
+
onDiscardAll: paths => discardPaths(paths),
|
|
3653
|
+
onSelect: path => setGraphPath(path),
|
|
3654
|
+
onOpen: (file, repoPath) => { setGraphPath(repoPath); setSelection({ kind: 'diff', path: file.path, staged: Boolean(file.__staged), repoPath }) },
|
|
3655
|
+
onFileHistory: (file, repoPath) => setFileHistory({ path: repoPath, file: file.path, phase: 'loading', commits: [], error: null }),
|
|
3656
|
+
onDialog: setDialog,
|
|
3657
|
+
})))
|
|
3658
|
+
const openAll = useCallback(staged => { setSelection({ kind: 'all', staged: Boolean(staged) }) }, [])
|
|
3659
|
+
const discardAll = useCallback(() => discardPaths(changeFiles.map(file => file.path)), [discardPaths, changeFiles])
|
|
3660
|
+
|
|
3661
|
+
const commit = useCallback((action = 'commit') => {
|
|
3662
|
+
if (busy) return
|
|
3663
|
+
const message = commitRef.current?.value ?? commitMessage
|
|
3664
|
+
if (!message.trim() && action !== 'amend') { notify(t('commitEmpty'), 'error'); return }
|
|
3665
|
+
setCommitMenu(false)
|
|
3666
|
+
run(async () => {
|
|
3667
|
+
await apiPost('/commit', { path: active.path, message, action })
|
|
3668
|
+
if (commitRef.current) commitRef.current.value = ''
|
|
3669
|
+
setCommitMessage('')
|
|
3670
|
+
setAmend(false)
|
|
3671
|
+
if (selection?.kind === 'diff') refreshDiff()
|
|
3672
|
+
}, t(action === 'push' ? 'committedPushed' : action === 'sync' ? 'committedSynced' : 'committed'))
|
|
3673
|
+
}, [busy, commitMessage, active?.path, run, t, selection, refreshDiff])
|
|
3674
|
+
|
|
3675
|
+
const switchBranch = useCallback(branch => {
|
|
3676
|
+
setBranchMenuOpen(false)
|
|
3677
|
+
const dirty = (status.data?.staged?.length ?? 0) + (status.data?.unstaged?.length ?? 0) + (status.data?.untracked?.length ?? 0) > 0
|
|
3678
|
+
const go = () => run(async () => { await apiPost('/switch', { path: active.path, branch }) }, t('switched', { branch }))
|
|
3679
|
+
if (dirty) {
|
|
3680
|
+
setDialog({
|
|
3681
|
+
title: t('switchConfirmTitle'),
|
|
3682
|
+
message: t('switchConfirm', { branch }),
|
|
3683
|
+
confirmLabel: t('confirm'), cancelLabel: t('cancel'), danger: false,
|
|
3684
|
+
onConfirm: go,
|
|
3685
|
+
})
|
|
3686
|
+
} else go()
|
|
3687
|
+
}, [active?.path, run, status.data, t])
|
|
3688
|
+
|
|
3689
|
+
const createBranch = useCallback(() => {
|
|
3690
|
+
const name = newBranch.trim()
|
|
3691
|
+
if (!name) return
|
|
3692
|
+
setBranchMenuOpen(false)
|
|
3693
|
+
setNewBranch('')
|
|
3694
|
+
run(async () => { await apiPost('/branch/create', { path: active.path, name }); }, t('created', { branch: name }))
|
|
3695
|
+
}, [active?.path, newBranch, run, t])
|
|
3696
|
+
|
|
3697
|
+
const toggleSection = key => {
|
|
3698
|
+
setCollapsedSections(previous => {
|
|
3699
|
+
const next = new Set(previous)
|
|
3700
|
+
if (next.has(key)) next.delete(key)
|
|
3701
|
+
else next.add(key)
|
|
3702
|
+
return next
|
|
3703
|
+
})
|
|
3704
|
+
}
|
|
3705
|
+
const toggleDir = path => {
|
|
3706
|
+
setExpandedDirs(previous => {
|
|
3707
|
+
const next = new Set(previous)
|
|
3708
|
+
if (next.has(path)) next.delete(path)
|
|
3709
|
+
else next.add(path)
|
|
3710
|
+
return next
|
|
3711
|
+
})
|
|
3712
|
+
}
|
|
3713
|
+
const quoteSelected = useCallback(() => {
|
|
3714
|
+
const text = quoteText
|
|
3715
|
+
if (!text) return
|
|
3716
|
+
setQuoteAnchor(undefined)
|
|
3717
|
+
let inserted = false
|
|
3718
|
+
try { inserted = Boolean(inputActions && typeof inputActions.insertQuote === 'function' && inputActions.insertQuote(text)) } catch { inserted = false }
|
|
3719
|
+
if (inserted) notify(t('quoted'))
|
|
3720
|
+
else { try { navigator.clipboard?.writeText(text) } catch { /* ignore */ } ; notify(t('quoteCopied')) }
|
|
3721
|
+
setQuoteText(undefined)
|
|
3722
|
+
}, [quoteText, inputActions, notify, t])
|
|
3723
|
+
const captureQuote = () => {
|
|
3724
|
+
try {
|
|
3725
|
+
const selection = window.getSelection?.()
|
|
3726
|
+
const value = selection?.toString().trim()
|
|
3727
|
+
if (!value || value.length < 2 || !selection || selection.rangeCount === 0) {
|
|
3728
|
+
setQuoteText(undefined); setQuoteAnchor(undefined); return
|
|
3729
|
+
}
|
|
3730
|
+
const range = selection.getRangeAt(0)
|
|
3731
|
+
const box = rightCardRef.current?.getBoundingClientRect()
|
|
3732
|
+
const rect = range.getBoundingClientRect()
|
|
3733
|
+
setQuoteText(value.slice(0, 6000))
|
|
3734
|
+
if (box && rect.width + rect.height > 0) {
|
|
3735
|
+
setQuoteAnchor({
|
|
3736
|
+
x: Math.min(Math.max(rect.left - box.left + rect.width / 2, 60), box.width - 60),
|
|
3737
|
+
y: Math.max(rect.top - box.top, 34),
|
|
3738
|
+
})
|
|
3739
|
+
} else setQuoteAnchor(undefined)
|
|
3740
|
+
} catch { /* ignore */ }
|
|
3741
|
+
}
|
|
3742
|
+
useEffect(() => {
|
|
3743
|
+
if (!active?.path) { dragFilesRef.current.clear(); return undefined }
|
|
3744
|
+
let live = true
|
|
3745
|
+
for (const key of picked) {
|
|
3746
|
+
const file = key.slice(2)
|
|
3747
|
+
if (dragFilesRef.current.has(file)) continue
|
|
3748
|
+
fetch(new URL(`/git-assistant/api/raw?path=${encodeURIComponent(active.path)}&file=${encodeURIComponent(file)}`, window.location.origin))
|
|
3749
|
+
.then(response => response.ok ? response.blob() : undefined)
|
|
3750
|
+
.then(blob => { if (live && blob && blob.size <= 3_000_000) dragFilesRef.current.set(file, blob) })
|
|
3751
|
+
.catch(() => { /* ignore */ })
|
|
3752
|
+
}
|
|
3753
|
+
return () => { live = false }
|
|
3754
|
+
}, [picked, active?.path])
|
|
3755
|
+
const startDrag = (file, event) => {
|
|
3756
|
+
const keys = picked.has(keyOf(file)) && picked.size > 0 ? [...picked] : [keyOf(file)]
|
|
3757
|
+
const paths = keys.map(key => key.slice(2))
|
|
3758
|
+
const token = (globalThis.crypto?.randomUUID?.() ?? String(Date.now()))
|
|
3759
|
+
dragPayload = { token, paths }
|
|
3760
|
+
event.dataTransfer.effectAllowed = 'copy'
|
|
3761
|
+
event.dataTransfer.setData(DRAG_TYPE, token)
|
|
3762
|
+
event.dataTransfer.setData('text/plain', `@${file.path}`)
|
|
3763
|
+
}
|
|
3764
|
+
useEffect(() => {
|
|
3765
|
+
if (!sessionId) return undefined
|
|
3766
|
+
const onOver = event => {
|
|
3767
|
+
if (!event.dataTransfer?.types?.includes(DRAG_TYPE)) return
|
|
3768
|
+
const card = composerCardFor(event.target, sessionId)
|
|
3769
|
+
if (!card) return
|
|
3770
|
+
event.preventDefault()
|
|
3771
|
+
event.dataTransfer.dropEffect = 'copy'
|
|
3772
|
+
}
|
|
3773
|
+
const onDrop = async event => {
|
|
3774
|
+
const token = event.dataTransfer?.getData(DRAG_TYPE)
|
|
3775
|
+
if (!token || !dragPayload || dragPayload.token !== token) return
|
|
3776
|
+
const card = composerCardFor(event.target, sessionId)
|
|
3777
|
+
if (!card) return
|
|
3778
|
+
event.preventDefault()
|
|
3779
|
+
event.stopPropagation()
|
|
3780
|
+
const payload = dragPayload
|
|
3781
|
+
dragPayload = null
|
|
3782
|
+
const files = []
|
|
3783
|
+
for (const path of payload.paths.slice(0, 20)) {
|
|
3784
|
+
try {
|
|
3785
|
+
const url = new URL('/git-assistant/api/raw', window.location.origin)
|
|
3786
|
+
url.searchParams.set('path', active?.path ?? '')
|
|
3787
|
+
url.searchParams.set('file', path)
|
|
3788
|
+
const response = await fetch(url)
|
|
3789
|
+
if (!response.ok) continue
|
|
3790
|
+
const blob = await response.blob()
|
|
3791
|
+
if (blob.size > 4_000_000) continue
|
|
3792
|
+
files.push(new File([blob], path.split('/').pop() || path, { type: blob.type || 'application/octet-stream' }))
|
|
3793
|
+
} catch { /* ignore */ }
|
|
3794
|
+
}
|
|
3795
|
+
if (files.length === 0 || !card.isConnected) return
|
|
3796
|
+
const data = new DataTransfer()
|
|
3797
|
+
for (const file of files) data.items.add(file)
|
|
3798
|
+
card.dispatchEvent(new DragEvent('drop', { bubbles: true, cancelable: true, dataTransfer: data }))
|
|
3799
|
+
}
|
|
3800
|
+
const onEnd = () => { dragPayload = null }
|
|
3801
|
+
document.addEventListener('dragover', onOver, true)
|
|
3802
|
+
document.addEventListener('drop', onDrop, true)
|
|
3803
|
+
document.addEventListener('dragend', onEnd, true)
|
|
3804
|
+
return () => {
|
|
3805
|
+
document.removeEventListener('dragover', onOver, true)
|
|
3806
|
+
document.removeEventListener('drop', onDrop, true)
|
|
3807
|
+
document.removeEventListener('dragend', onEnd, true)
|
|
3808
|
+
}
|
|
3809
|
+
}, [sessionId, active?.path])
|
|
3810
|
+
const effectiveLeftWidth = mode === 'issues' ? issuesWidth : leftWidth
|
|
3811
|
+
/**
|
|
3812
|
+
* The right-hand pane must keep enough room for its toolbar (commit picker, wrap, collapse,
|
|
3813
|
+
* view switch) to stay on one line, so the splitter's upper bound follows the measured body
|
|
3814
|
+
* width instead of a fixed 560/760. A narrow host (right sidebar, split conversation view)
|
|
3815
|
+
* therefore simply cannot squeeze the viewer into an unusable sliver.
|
|
3816
|
+
*/
|
|
3817
|
+
const RIGHT_PANE_MIN = mode === 'issues' ? 300 : 340
|
|
3818
|
+
const LEFT_PANE_MAX = mode === 'issues' ? 760 : 560
|
|
3819
|
+
const leftPaneMax = bodyWidth > 0
|
|
3820
|
+
? Math.max(240, Math.min(LEFT_PANE_MAX, bodyWidth - 14 - RIGHT_PANE_MIN))
|
|
3821
|
+
: LEFT_PANE_MAX
|
|
3822
|
+
useEffect(() => {
|
|
3823
|
+
if (bodyWidth <= 0) return
|
|
3824
|
+
if (leftWidth > leftPaneMax) setLeftWidth(leftPaneMax)
|
|
3825
|
+
if (issuesWidth > leftPaneMax) setIssuesWidth(leftPaneMax)
|
|
3826
|
+
}, [bodyWidth, leftPaneMax, leftWidth, issuesWidth])
|
|
3827
|
+
const startResize = useCallback(event => {
|
|
3828
|
+
event.preventDefault()
|
|
3829
|
+
const startX = event.clientX
|
|
3830
|
+
const startWidth = mode === 'issues' ? issuesWidth : leftWidth
|
|
3831
|
+
const applyWidth = mode === 'issues' ? setIssuesWidth : setLeftWidth
|
|
3832
|
+
const maxWidth = leftPaneMax
|
|
3833
|
+
const move = moveEvent => applyWidth(Math.min(maxWidth, Math.max(240, startWidth + moveEvent.clientX - startX)))
|
|
3834
|
+
const stop = () => {
|
|
3835
|
+
document.removeEventListener('pointermove', move)
|
|
3836
|
+
document.removeEventListener('pointerup', stop)
|
|
3837
|
+
document.body.style.cursor = ''
|
|
3838
|
+
document.body.style.userSelect = ''
|
|
3839
|
+
}
|
|
3840
|
+
document.body.style.cursor = 'col-resize'
|
|
3841
|
+
document.body.style.userSelect = 'none'
|
|
3842
|
+
document.addEventListener('pointermove', move)
|
|
3843
|
+
document.addEventListener('pointerup', stop)
|
|
3844
|
+
}, [leftWidth, issuesWidth, mode, leftPaneMax])
|
|
3845
|
+
|
|
3846
|
+
const keyOf = file => file.__staged === undefined ? `f:${file.path}` : `${file.__staged ? 's' : 'w'}:${file.path}`
|
|
3847
|
+
const openDiff = (file, event) => {
|
|
3848
|
+
const key = keyOf(file)
|
|
3849
|
+
setMode('changes')
|
|
3850
|
+
setSelection({ kind: 'diff', path: file.path, staged: Boolean(file.__staged) })
|
|
3851
|
+
setPicked(previous => {
|
|
3852
|
+
const next = new Set(previous)
|
|
3853
|
+
if (event && (event.metaKey || event.ctrlKey || event.shiftKey)) {
|
|
3854
|
+
if (next.has(key)) next.delete(key)
|
|
3855
|
+
else next.add(key)
|
|
3856
|
+
} else {
|
|
3857
|
+
next.clear(); next.add(key)
|
|
3858
|
+
}
|
|
3859
|
+
return next
|
|
3860
|
+
})
|
|
3861
|
+
}
|
|
3862
|
+
const pickedPathsFor = file => {
|
|
3863
|
+
const key = keyOf(file)
|
|
3864
|
+
if (picked.has(key) && picked.size > 1) return [...picked].map(value => value.slice(2))
|
|
3865
|
+
return [file.path]
|
|
3866
|
+
}
|
|
3867
|
+
const scopedPaths = (allPaths) => {
|
|
3868
|
+
if (picked.size === 0) return allPaths
|
|
3869
|
+
const wanted = new Set([...picked].map(value => value.slice(2)))
|
|
3870
|
+
const filtered = allPaths.filter(path => wanted.has(path))
|
|
3871
|
+
return filtered.length > 0 ? filtered : allPaths
|
|
3872
|
+
}
|
|
3873
|
+
const openFile = (file, event) => {
|
|
3874
|
+
setSelection({ kind: 'file', path: file.path })
|
|
3875
|
+
const key = keyOf(file)
|
|
3876
|
+
setPicked(previous => {
|
|
3877
|
+
const next = new Set(previous)
|
|
3878
|
+
if (event && (event.metaKey || event.ctrlKey || event.shiftKey)) {
|
|
3879
|
+
if (next.has(key)) next.delete(key)
|
|
3880
|
+
else next.add(key)
|
|
3881
|
+
} else {
|
|
3882
|
+
next.clear(); next.add(key)
|
|
3883
|
+
}
|
|
3884
|
+
return next
|
|
3885
|
+
})
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
const filteredFiles = useMemo(() => {
|
|
3889
|
+
const query = filesFilter.trim().toLowerCase()
|
|
3890
|
+
if (!query) return files.files
|
|
3891
|
+
return files.files.filter(path => path.toLowerCase().includes(query)).slice(0, 400)
|
|
3892
|
+
}, [files.files, filesFilter])
|
|
3893
|
+
|
|
3894
|
+
const changeTree = useMemo(() => fileRows([
|
|
3895
|
+
...stagedFiles.map(file => ({ ...file })),
|
|
3896
|
+
]), [stagedFiles])
|
|
3897
|
+
const workingTree = useMemo(() => fileRows(changeFiles), [changeFiles])
|
|
3898
|
+
const repositoryFilesTree = useMemo(() => fileRows(filteredFiles.map(path => ({ path, status: statusByPath.get(path) }))), [filteredFiles, statusByPath])
|
|
3899
|
+
|
|
3900
|
+
const changesCount = stagedFiles.length + changeFiles.length
|
|
3901
|
+
const dirty = changesCount > 0
|
|
3902
|
+
const ahead = status.data?.ahead ?? 0
|
|
3903
|
+
const behind = status.data?.behind ?? 0
|
|
3904
|
+
|
|
3905
|
+
return h('div', {
|
|
3906
|
+
className: 'ga-panel',
|
|
3907
|
+
style: {
|
|
3908
|
+
display: 'flex', flexDirection: 'column', height: '100%', minHeight: 0, color: T.text,
|
|
3909
|
+
fontSize: 13, lineHeight: 1.5, position: 'relative', overflow: 'hidden', fontFamily: T.sans,
|
|
3910
|
+
letterSpacing: '0.002em', background: T.canvas,
|
|
3911
|
+
},
|
|
3912
|
+
},
|
|
3913
|
+
// ── title bar ──────────────────────────────────────────
|
|
3914
|
+
h('div', {
|
|
3915
|
+
style: {
|
|
3916
|
+
display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: 8, rowGap: 6, minHeight: 46,
|
|
3917
|
+
padding: '6px 12px', margin: '10px 12px 0', borderRadius: T.rMd, background: T.surface,
|
|
3918
|
+
boxShadow: T.edge, flex: '0 0 auto', position: 'relative', zIndex: 60, minWidth: 0,
|
|
3919
|
+
},
|
|
3920
|
+
},
|
|
3921
|
+
h('span', { style: { display: 'inline-flex', color: T.ink2 } }, h(GitIcon, { size: 15 })),
|
|
3922
|
+
h('span', { style: { fontSize: 14, lineHeight: '20px', fontWeight: 600, letterSpacing: '0.005em', whiteSpace: 'nowrap' } }, t('title')),
|
|
3923
|
+
h('span', { 'aria-hidden': true, style: { color: T.subtle } }, '·'),
|
|
3924
|
+
h('div', { ref: menuRef, style: { position: 'relative', minWidth: 0 } },
|
|
3925
|
+
h('button', {
|
|
3926
|
+
type: 'button', onClick: () => setMenuOpen(open => !open), disabled: repositories.items.length === 0,
|
|
3927
|
+
title: active?.path ?? t('pickRepo'),
|
|
3928
|
+
style: {
|
|
3929
|
+
appearance: 'none', border: `0.5px solid ${menuOpen ? T.border : 'transparent'}`,
|
|
3930
|
+
background: menuOpen ? T.hover : 'transparent', color: 'inherit', font: 'inherit',
|
|
3931
|
+
display: 'inline-flex', alignItems: 'center', gap: 7, padding: '5px 10px', borderRadius: T.rMd,
|
|
3932
|
+
cursor: repositories.items.length === 0 ? 'default' : 'pointer', maxWidth: 440, minWidth: 0,
|
|
3933
|
+
transition: `background .18s ${T.ease}, border-color .18s ${T.ease}`,
|
|
3934
|
+
},
|
|
3935
|
+
},
|
|
3936
|
+
h('span', { style: { fontSize: 12.5, fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
3937
|
+
active ? active.repoName : t('noRepos')),
|
|
3938
|
+
h(Chevron, { open: menuOpen, size: 9 })),
|
|
3939
|
+
menuOpen ? h('div', {
|
|
3940
|
+
style: {
|
|
3941
|
+
position: 'absolute', top: '100%', left: 0, marginTop: 8, zIndex: 40, width: 320,
|
|
3942
|
+
maxHeight: 460, overflowY: 'auto', background: T.menu, border: `0.5px solid ${T.border}`,
|
|
3943
|
+
borderRadius: T.rLg, padding: 6, boxShadow: T.shadowProminent,
|
|
3944
|
+
backdropFilter: 'blur(28px) saturate(170%)',
|
|
3945
|
+
},
|
|
3946
|
+
}, ...repositoryChoices.map(repository => h('button', {
|
|
3947
|
+
key: repository.repoName, type: 'button',
|
|
3948
|
+
onClick: () => { setStoredId(repository.id); setMenuOpen(false) },
|
|
3949
|
+
style: {
|
|
3950
|
+
appearance: 'none', border: 'none', width: '100%', textAlign: 'left', cursor: 'pointer',
|
|
3951
|
+
display: 'flex', alignItems: 'center', gap: 7, padding: '7px 10px', borderRadius: T.rSm,
|
|
3952
|
+
font: 'inherit', color: 'inherit',
|
|
3953
|
+
background: repository.repoName === active?.repoName ? T.selected : 'transparent',
|
|
3954
|
+
},
|
|
3955
|
+
onMouseEnter: event => { if (repository.repoName !== active?.repoName) event.currentTarget.style.background = T.hover },
|
|
3956
|
+
onMouseLeave: event => { if (repository.repoName !== active?.repoName) event.currentTarget.style.background = 'transparent' },
|
|
3957
|
+
},
|
|
3958
|
+
h('span', {
|
|
3959
|
+
title: repository.path,
|
|
3960
|
+
style: { flex: 1, minWidth: 0, fontSize: 12.5, fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
3961
|
+
}, repository.repoName),
|
|
3962
|
+
repository.repoName === active?.repoName
|
|
3963
|
+
? h('span', { style: { fontSize: 11, color: T.accent } }, '✓')
|
|
3964
|
+
: null))) : null),
|
|
3965
|
+
|
|
3966
|
+
// branch chip + menu
|
|
3967
|
+
active ? h('div', { ref: branchRef, style: { position: 'relative', minWidth: 0 } },
|
|
3968
|
+
h('button', {
|
|
3969
|
+
type: 'button', onClick: () => setBranchMenuOpen(open => !open), title: t('branches'),
|
|
3970
|
+
style: {
|
|
3971
|
+
appearance: 'none', border: `1px solid ${branchMenuOpen ? T.border : T.borderSoft}`,
|
|
3972
|
+
background: branchMenuOpen ? T.surfaceHover : T.chip,
|
|
3973
|
+
color: T.ink2, font: 'inherit',
|
|
3974
|
+
display: 'inline-flex', alignItems: 'center', gap: 6, padding: '3px 10px', borderRadius: T.pill,
|
|
3975
|
+
cursor: 'pointer', maxWidth: 260, minWidth: 0, transition: `background .18s ${T.ease}`,
|
|
3976
|
+
},
|
|
3977
|
+
},
|
|
3978
|
+
h('span', { style: { fontFamily: MONO, fontSize: 11.5, opacity: 0.7, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
3979
|
+
active.branch ?? t('detached')),
|
|
3980
|
+
h(Chevron, { open: branchMenuOpen, size: 8 })),
|
|
3981
|
+
branchMenuOpen ? h('div', {
|
|
3982
|
+
style: {
|
|
3983
|
+
position: 'absolute', top: '100%', left: 0, marginTop: 8, zIndex: 40, width: 360,
|
|
3984
|
+
maxHeight: 380, overflowY: 'auto', background: T.menu, border: `0.5px solid ${T.border}`,
|
|
3985
|
+
borderRadius: T.rLg, padding: 6, boxShadow: T.shadowProminent,
|
|
3986
|
+
backdropFilter: 'blur(28px) saturate(170%)',
|
|
3987
|
+
},
|
|
3988
|
+
},
|
|
3989
|
+
...branches.items.map(branch => {
|
|
3990
|
+
// The host reports a holder worktree for every branch checked out elsewhere; such a
|
|
3991
|
+
// row can only point at that worktree, never run `git switch` here.
|
|
3992
|
+
const blocked = Boolean(branch.worktree)
|
|
3993
|
+
return h('button', {
|
|
3994
|
+
key: branch.name, type: 'button',
|
|
3995
|
+
onClick: () => {
|
|
3996
|
+
if (blocked) {
|
|
3997
|
+
setBranchMenuOpen(false)
|
|
3998
|
+
notify(t('branchInWorktreeHint', { name: branch.worktreeName ?? basename(branch.worktree) }), 'info')
|
|
3999
|
+
flashWorktree(branch.worktree)
|
|
4000
|
+
return
|
|
4001
|
+
}
|
|
4002
|
+
switchBranch(branch.name)
|
|
4003
|
+
},
|
|
4004
|
+
title: blocked ? t('branchInWorktreeHint', { name: branch.worktreeName ?? basename(branch.worktree) }) : branch.name,
|
|
4005
|
+
style: {
|
|
4006
|
+
appearance: 'none', border: 'none', width: '100%', textAlign: 'left', cursor: blocked ? 'default' : 'pointer',
|
|
4007
|
+
display: 'flex', alignItems: 'center', gap: 7, padding: '6px 10px', borderRadius: T.rSm,
|
|
4008
|
+
font: 'inherit', color: 'inherit', background: branch.current ? T.selected : 'transparent',
|
|
4009
|
+
opacity: blocked ? 0.8 : 1,
|
|
4010
|
+
},
|
|
4011
|
+
onMouseEnter: event => { if (!branch.current) event.currentTarget.style.background = blocked ? T.chip : T.hover },
|
|
4012
|
+
onMouseLeave: event => { if (!branch.current) event.currentTarget.style.background = 'transparent' },
|
|
4013
|
+
},
|
|
4014
|
+
h('span', { style: { width: 12, fontSize: 11, opacity: branch.current ? 0.85 : 0.25 } }, '✓'),
|
|
4015
|
+
h('span', { style: { fontSize: 12, fontFamily: MONO, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 } }, branch.name),
|
|
4016
|
+
h('span', { style: { flex: 1 } }),
|
|
4017
|
+
blocked
|
|
4018
|
+
? h('span', {
|
|
4019
|
+
style: {
|
|
4020
|
+
display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 9.5, whiteSpace: 'nowrap',
|
|
4021
|
+
color: T.muted, background: T.chip, borderRadius: T.pill, padding: '1px 7px', flex: '0 0 auto',
|
|
4022
|
+
maxWidth: 150, overflow: 'hidden', textOverflow: 'ellipsis',
|
|
4023
|
+
},
|
|
4024
|
+
}, t('branchInWorktree', { name: branch.worktreeName ?? basename(branch.worktree) }))
|
|
4025
|
+
: branch.upstream ? h('span', { style: { fontSize: 9.5, opacity: 0.35, fontFamily: MONO } }, branch.upstream) : null)
|
|
4026
|
+
}),
|
|
4027
|
+
h('div', { style: { display: 'flex', gap: 6, padding: '6px 8px 3px', borderTop: `1px solid ${T.borderSoft}`, marginTop: 4 } },
|
|
4028
|
+
h('input', {
|
|
4029
|
+
value: newBranch, placeholder: t('branchPlaceholder'),
|
|
4030
|
+
onChange: event => setNewBranch(event.target.value),
|
|
4031
|
+
onKeyDown: event => { if (event.key === 'Enter') createBranch() },
|
|
4032
|
+
style: {
|
|
4033
|
+
flex: 1, minWidth: 0, background: T.layer, color: 'inherit', border: `1px solid ${T.border}`,
|
|
4034
|
+
borderRadius: 5, padding: '3px 7px', fontSize: 11.5, fontFamily: MONO, outline: 'none',
|
|
4035
|
+
},
|
|
4036
|
+
}),
|
|
4037
|
+
h(SmallButton, { label: t('createBranch'), onClick: createBranch, disabled: !newBranch.trim() }))) : null)
|
|
4038
|
+
: null,
|
|
4039
|
+
|
|
4040
|
+
h('span', { style: { flex: 1 } }),
|
|
4041
|
+
ahead > 0 || behind > 0 || status.data?.conflicted?.length
|
|
4042
|
+
? h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 7, fontSize: 11, fontFamily: MONO, opacity: 0.6, whiteSpace: 'nowrap' } },
|
|
4043
|
+
ahead > 0 ? h('span', { title: t('ahead') }, `↑${ahead}`) : null,
|
|
4044
|
+
behind > 0 ? h('span', { title: t('behind') }, `↓${behind}`) : null,
|
|
4045
|
+
status.data?.conflicted?.length ? h('span', { style: { color: T.error, fontFamily: 'inherit' } }, t('conflicts')) : null)
|
|
4046
|
+
: null,
|
|
4047
|
+
),
|
|
4048
|
+
|
|
4049
|
+
// ── body ────────────────────────────────────────────────
|
|
4050
|
+
h('div', { ref: bodyRef, style: { display: 'flex', flex: 1, minHeight: 0, gap: 8, padding: '8px 12px 12px', minWidth: 0, position: 'relative' } },
|
|
4051
|
+
// left column
|
|
4052
|
+
h('div', {
|
|
4053
|
+
style: {
|
|
4054
|
+
width: effectiveLeftWidth, flex: `0 0 ${effectiveLeftWidth}px`, minWidth: 240, borderRadius: T.rMd, background: T.surface,
|
|
4055
|
+
boxShadow: T.edge,
|
|
4056
|
+
display: 'flex', flexDirection: 'column', minHeight: 0, overflow: 'hidden',
|
|
4057
|
+
},
|
|
4058
|
+
},
|
|
4059
|
+
// mode tabs
|
|
4060
|
+
h('div', { style: { padding: '10px 10px 4px', borderBottom: `1px solid ${T.borderSoft}` } },
|
|
4061
|
+
h('div', {
|
|
4062
|
+
style: {
|
|
4063
|
+
display: 'flex', gap: 2, padding: 3, borderRadius: 10,
|
|
4064
|
+
background: T.chip, border: `1px solid ${T.borderSoft}`,
|
|
4065
|
+
},
|
|
4066
|
+
},
|
|
4067
|
+
['changes', 'files', 'issues'].map(value => h('button', {
|
|
4068
|
+
key: value, type: 'button', onClick: () => setMode(value),
|
|
4069
|
+
style: {
|
|
4070
|
+
appearance: 'none', border: 'none', cursor: 'pointer', font: 'inherit', flex: 1,
|
|
4071
|
+
fontSize: 12, fontWeight: mode === value ? 600 : 500,
|
|
4072
|
+
height: 26, padding: '0 10px', borderRadius: 7,
|
|
4073
|
+
background: mode === value ? T.surface : 'transparent',
|
|
4074
|
+
color: mode === value ? T.text : T.ink2,
|
|
4075
|
+
boxShadow: mode === value ? `${T.ring}, 0 1px 2px rgba(0,0,0,.05)` : 'none',
|
|
4076
|
+
transition: `background .18s ${T.ease}, color .18s ${T.ease}`,
|
|
4077
|
+
},
|
|
4078
|
+
onMouseEnter: event => { if (mode !== value) event.currentTarget.style.color = T.text },
|
|
4079
|
+
onMouseLeave: event => { if (mode !== value) event.currentTarget.style.color = T.ink2 },
|
|
4080
|
+
}, value === 'changes' ? t('changesTab') : value === 'files' ? t('filesTab') : t('issuesTab'))))),
|
|
4081
|
+
|
|
4082
|
+
h('div', { style: { display: mode === 'changes' ? 'flex' : 'none', flexDirection: 'column', flex: 1, minHeight: 0 } }, worktreeCards),
|
|
4083
|
+
h('div', { style: { display: mode === 'files' ? 'flex' : 'none', flexDirection: 'column', flex: 1, minHeight: 0 } }, worktreeFilesCards),
|
|
4084
|
+
h('div', { style: { display: mode === 'issues' ? 'flex' : 'none', flexDirection: 'column', flex: 1, minHeight: 0 } },
|
|
4085
|
+
h(IssueDetailPane, {
|
|
4086
|
+
t, state: issueDetail, comments: issueComments,
|
|
4087
|
+
onNavigate: setIssueNumber,
|
|
4088
|
+
onClose: () => setIssueNumber(undefined),
|
|
4089
|
+
onCommentPost: postIssueComment,
|
|
4090
|
+
onToggleState: toggleIssueState,
|
|
4091
|
+
})),
|
|
4092
|
+
),
|
|
4093
|
+
|
|
4094
|
+
// commit graph drawer docked over the workbench column
|
|
4095
|
+
graphDrawer,
|
|
4096
|
+
|
|
4097
|
+
// resize handle between the two cards
|
|
4098
|
+
h('div', {
|
|
4099
|
+
role: 'separator', 'aria-orientation': 'vertical', title: t('resize'), onPointerDown: startResize,
|
|
4100
|
+
style: { flex: '0 0 6px', alignSelf: 'stretch', cursor: 'col-resize', borderRadius: 3, transition: `background .15s ${T.ease}` },
|
|
4101
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.borderSoft },
|
|
4102
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
4103
|
+
}),
|
|
4104
|
+
|
|
4105
|
+
// right column: document card or issues board
|
|
4106
|
+
mode === 'issues' ? h(IssuesPane, {
|
|
4107
|
+
t, state: issues, selectedNumber: issueNumber,
|
|
4108
|
+
onSelect: setIssueNumber, search: issuesSearch, onSearch: setIssuesSearch,
|
|
4109
|
+
stateFilter: issuesState, onStateFilter: setIssuesState,
|
|
4110
|
+
onRefresh: () => setIssuesVersion(value => value + 1),
|
|
4111
|
+
onLoadMore: () => setIssuesLimit(value => value + 60),
|
|
4112
|
+
}) : h('div', {
|
|
4113
|
+
style: { flex: 1, minWidth: 0, minHeight: 0, display: 'flex', flexDirection: 'column', gap: 6 },
|
|
4114
|
+
},
|
|
4115
|
+
h('div', {
|
|
4116
|
+
style: {
|
|
4117
|
+
flex: '0 0 auto', display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: 6, rowGap: 6,
|
|
4118
|
+
minHeight: 40, padding: '6px 8px', minWidth: 0, borderRadius: T.rMd, background: T.surface,
|
|
4119
|
+
boxShadow: T.edge, position: 'relative', zIndex: 30,
|
|
4120
|
+
},
|
|
4121
|
+
},
|
|
4122
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, flex: '1 1 auto' } },
|
|
4123
|
+
h('div', { ref: commitPickerRef, style: { position: 'relative', minWidth: 0, flex: '0 1 auto' } },
|
|
4124
|
+
h('button', {
|
|
4125
|
+
type: 'button', title: t('selectCommit'),
|
|
4126
|
+
onClick: () => { setCommitPickerOpen(open => !open); if (!commitPickerOpen) refreshLocalCommits() },
|
|
4127
|
+
style: {
|
|
4128
|
+
appearance: 'none', border: '1px solid transparent', boxShadow: T.ring,
|
|
4129
|
+
background: commitPickerOpen ? T.chip : T.surface, color: T.ink2, height: 26,
|
|
4130
|
+
padding: '0 10px', borderRadius: 7, fontSize: 11.5, cursor: 'pointer', whiteSpace: 'nowrap',
|
|
4131
|
+
display: 'inline-flex', alignItems: 'center', gap: 5, minWidth: 0, maxWidth: 320,
|
|
4132
|
+
},
|
|
4133
|
+
},
|
|
4134
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
4135
|
+
selection?.kind === 'commit-files'
|
|
4136
|
+
? (selection.subject || selection.hash.slice(0, 7))
|
|
4137
|
+
: t('selectCommit')),
|
|
4138
|
+
h(Chevron, { open: commitPickerOpen, size: 8 })),
|
|
4139
|
+
commitPickerOpen ? h('div', {
|
|
4140
|
+
style: {
|
|
4141
|
+
position: 'absolute', top: '100%', left: 0, marginTop: 6, zIndex: 80, width: 380,
|
|
4142
|
+
maxHeight: 360, overflowY: 'auto', background: T.menu, border: `0.5px solid ${T.border}`,
|
|
4143
|
+
borderRadius: T.rMd, padding: 4, boxShadow: T.shadowProminent,
|
|
4144
|
+
backdropFilter: 'blur(24px) saturate(160%)',
|
|
4145
|
+
},
|
|
4146
|
+
},
|
|
4147
|
+
h('button', {
|
|
4148
|
+
type: 'button', onClick: () => { setSelection(null); setCommitPickerOpen(false) },
|
|
4149
|
+
style: { display: 'flex', alignItems: 'center', width: '100%', textAlign: 'left', background: 'transparent', border: 'none', cursor: 'pointer', color: 'inherit', padding: '5px 8px', borderRadius: T.rSm, fontSize: 11.5, gap: 6 },
|
|
4150
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
4151
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
4152
|
+
}, t('workspaceChanges')),
|
|
4153
|
+
h('div', { style: { padding: '4px 8px 3px', fontSize: 10, color: T.subtle } }, t('unpushedCommits')),
|
|
4154
|
+
localCommits.phase === 'loading'
|
|
4155
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11, color: T.muted } }, t('loading'))
|
|
4156
|
+
: localCommits.commits.length === 0
|
|
4157
|
+
? h('div', { style: { padding: '6px 10px', fontSize: 11, color: T.muted } }, t('noUnpushedCommits'))
|
|
4158
|
+
: localCommits.commits.map(commit => h('button', {
|
|
4159
|
+
key: commit.oid, type: 'button',
|
|
4160
|
+
onClick: () => {
|
|
4161
|
+
setSelection({ kind: 'commit-files', repoPath: active?.path, hash: commit.oid, subject: commit.subject })
|
|
4162
|
+
setCommitPickerOpen(false)
|
|
4163
|
+
},
|
|
4164
|
+
style: { display: 'flex', alignItems: 'center', gap: 8, width: '100%', textAlign: 'left', background: 'transparent', border: 'none', cursor: 'pointer', color: 'inherit', padding: '5px 8px', borderRadius: T.rSm, fontSize: 11.5 },
|
|
4165
|
+
onMouseEnter: event => { event.currentTarget.style.background = T.hover },
|
|
4166
|
+
onMouseLeave: event => { event.currentTarget.style.background = 'transparent' },
|
|
4167
|
+
},
|
|
4168
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, commit.subject || '(no message)'),
|
|
4169
|
+
h('span', { style: { fontFamily: MONO, fontSize: 10, color: T.subtle, whiteSpace: 'nowrap' } }, formatRelativeTime(commit.time)))))
|
|
4170
|
+
: null),
|
|
4171
|
+
selection?.kind === 'commit-files'
|
|
4172
|
+
? h('span', {
|
|
4173
|
+
style: {
|
|
4174
|
+
fontFamily: MONO, fontSize: 10.5, color: T.muted, whiteSpace: 'nowrap',
|
|
4175
|
+
border: `0.5px solid ${T.border}`, borderRadius: T.pill, padding: '1px 8px',
|
|
4176
|
+
},
|
|
4177
|
+
}, selection.hash.slice(0, 7))
|
|
4178
|
+
: null,
|
|
4179
|
+
selection?.kind === 'commit-files' && commitPatch.data?.stats
|
|
4180
|
+
? h('span', { style: { display: 'inline-flex', gap: 7, fontFamily: MONO, fontSize: 10.5, whiteSpace: 'nowrap' } },
|
|
4181
|
+
h('span', { style: { color: T.success } }, `+${commitPatch.data.stats.additions}`),
|
|
4182
|
+
h('span', { style: { color: T.error } }, `−${commitPatch.data.stats.deletions}`))
|
|
4183
|
+
: null,
|
|
4184
|
+
),
|
|
4185
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto', marginLeft: 'auto' } },
|
|
4186
|
+
h('button', {
|
|
4187
|
+
type: 'button', onClick: () => setWrap(value => !value), title: t('wrapLines'),
|
|
4188
|
+
style: {
|
|
4189
|
+
appearance: 'none', border: '1px solid transparent', whiteSpace: 'nowrap', cursor: 'pointer', height: 26, padding: '0 10px',
|
|
4190
|
+
borderRadius: 7, fontSize: 11.5, fontWeight: 500, font: 'inherit',
|
|
4191
|
+
color: wrap ? T.text : T.ink2, background: wrap ? T.chip : T.surface, boxShadow: wrap ? 'none' : T.ring,
|
|
4192
|
+
},
|
|
4193
|
+
}, t('wrapLines')),
|
|
4194
|
+
h('button', {
|
|
4195
|
+
type: 'button', onClick: () => setAllFilesCollapsed(value => !value),
|
|
4196
|
+
disabled: selection?.kind !== 'commit-files', title: allFilesCollapsed ? t('expandAllFiles') : t('collapseAllFiles'),
|
|
4197
|
+
style: {
|
|
4198
|
+
appearance: 'none', border: '1px solid transparent', whiteSpace: 'nowrap', cursor: selection?.kind === 'commit-files' ? 'pointer' : 'default',
|
|
4199
|
+
height: 26, padding: '0 10px', borderRadius: 7, fontSize: 11.5, fontWeight: 500, font: 'inherit',
|
|
4200
|
+
color: T.ink2, background: allFilesCollapsed ? T.chip : T.surface,
|
|
4201
|
+
boxShadow: allFilesCollapsed ? 'none' : T.ring,
|
|
4202
|
+
opacity: selection?.kind === 'commit-files' ? 1 : 0.4,
|
|
4203
|
+
},
|
|
4204
|
+
}, allFilesCollapsed ? t('expandAllFiles') : t('collapseAllFiles')),
|
|
4205
|
+
h('span', { style: { display: 'inline-flex', padding: 2, borderRadius: 8, background: T.chip, boxShadow: `inset 0 0 0 1px ${T.borderSoft}` } },
|
|
4206
|
+
['unified', 'split'].map(value => h('button', {
|
|
4207
|
+
key: value, type: 'button', onClick: () => setView(value),
|
|
4208
|
+
style: {
|
|
4209
|
+
appearance: 'none', border: 'none', cursor: 'pointer', font: 'inherit', fontSize: 11, fontWeight: view === value ? 600 : 500, whiteSpace: 'nowrap',
|
|
4210
|
+
height: 22, padding: '0 10px', borderRadius: 6,
|
|
4211
|
+
background: view === value ? T.surface : 'transparent',
|
|
4212
|
+
color: view === value ? T.text : T.ink2,
|
|
4213
|
+
boxShadow: view === value ? T.ring : 'none',
|
|
4214
|
+
transition: `background .18s ${T.ease}, color .18s ${T.ease}`,
|
|
4215
|
+
},
|
|
4216
|
+
}, t(value)))),
|
|
4217
|
+
)),
|
|
4218
|
+
|
|
4219
|
+
h('div', {
|
|
4220
|
+
style: {
|
|
4221
|
+
flex: 1, minWidth: 0, minHeight: 0, display: 'flex', flexDirection: 'column', position: 'relative',
|
|
4222
|
+
borderRadius: T.rMd, background: T.surface, boxShadow: T.edge, overflow: 'hidden',
|
|
4223
|
+
},
|
|
4224
|
+
onMouseUp: captureQuote,
|
|
4225
|
+
ref: rightCardRef,
|
|
4226
|
+
},
|
|
4227
|
+
quoteText ? h('button', {
|
|
4228
|
+
type: 'button', onClick: quoteSelected,
|
|
4229
|
+
style: {
|
|
4230
|
+
position: 'absolute', zIndex: 20, height: 26, padding: '0 11px',
|
|
4231
|
+
left: quoteAnchor ? quoteAnchor.x : 24, top: quoteAnchor ? Math.max(quoteAnchor.y - 34, 6) : 10,
|
|
4232
|
+
transform: quoteAnchor ? 'translateX(-50%)' : 'none',
|
|
4233
|
+
borderRadius: T.pill, border: `0.5px solid ${T.border}`, background: T.menu,
|
|
4234
|
+
color: T.ink2, fontSize: 11.5, cursor: 'pointer', boxShadow: T.shadowProminent,
|
|
4235
|
+
backdropFilter: 'blur(16px)',
|
|
4236
|
+
},
|
|
4237
|
+
}, t('quoteAction')) : null,
|
|
4238
|
+
selection && selection.kind !== 'commit-files' ? h('div', {
|
|
4239
|
+
style: {
|
|
4240
|
+
display: 'flex', alignItems: 'center', gap: 8, minHeight: 46, padding: '0 14px',
|
|
4241
|
+
borderBottom: `0.5px solid ${T.borderSoft}`, flex: '0 0 auto', minWidth: 0,
|
|
4242
|
+
},
|
|
4243
|
+
},
|
|
4244
|
+
(() => {
|
|
4245
|
+
if (selection.kind === 'all') {
|
|
4246
|
+
const count = selection.staged ? stagedFiles.length : changeFiles.length
|
|
4247
|
+
return h('span', { style: { fontSize: 12, fontWeight: 500, whiteSpace: 'nowrap' } },
|
|
4248
|
+
selection.staged ? t('allStaged') : t('allChanges'),
|
|
4249
|
+
h('span', { style: { marginLeft: 7, fontFamily: MONO, fontSize: 10.5, color: T.muted } }, String(count)))
|
|
4250
|
+
}
|
|
4251
|
+
if (selection.kind === 'commit-files') {
|
|
4252
|
+
const subject = commitPatch.data?.commit?.subject ?? selection.subject ?? ''
|
|
4253
|
+
return h('span', { style: { fontSize: 12, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 0 }, title: subject },
|
|
4254
|
+
h('span', { style: { fontWeight: 500 } }, subject))
|
|
4255
|
+
}
|
|
4256
|
+
const parts = splitPath(selection.path)
|
|
4257
|
+
return h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 5, fontSize: 12, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', minWidth: 0 }, title: selection.path },
|
|
4258
|
+
h(FileGlyph, { name: parts.name, kind: 'file' }),
|
|
4259
|
+
h('span', { style: { opacity: 0.45 } }, parts.dir),
|
|
4260
|
+
h('span', { style: { fontWeight: 500 } }, parts.name))
|
|
4261
|
+
})(),
|
|
4262
|
+
selection.kind !== 'file'
|
|
4263
|
+
? h('span', { style: { fontSize: 10.5, color: T.muted, border: `0.5px solid ${T.border}`, borderRadius: T.pill, padding: '1px 8px', whiteSpace: 'nowrap', fontFamily: selection.kind === 'commit-diff' || selection.kind === 'commit-files' ? MONO : undefined } },
|
|
4264
|
+
selection.kind === 'commit-diff' || selection.kind === 'commit-files' ? selection.hash.slice(0, 7) : selection.staged ? t('staged') : t('changes'))
|
|
4265
|
+
: h('span', { style: { fontSize: 10.5, opacity: 0.5, border: `1px solid ${T.border}`, borderRadius: 4, padding: '1px 5px', whiteSpace: 'nowrap' } },
|
|
4266
|
+
t('readOnly')),
|
|
4267
|
+
h('span', { style: { flex: 1 } }),
|
|
4268
|
+
selection.kind === 'diff' || selection.kind === 'commit-diff'
|
|
4269
|
+
? h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 1, flex: '0 0 auto' } },
|
|
4270
|
+
h(IconAction, {
|
|
4271
|
+
label: t('copyPath'),
|
|
4272
|
+
onClick: () => {
|
|
4273
|
+
copyToClipboard(selection.path)
|
|
4274
|
+
.then(() => notify(t('copiedPath')))
|
|
4275
|
+
.catch(() => notify(t('actionFailed'), 'error'))
|
|
4276
|
+
},
|
|
4277
|
+
}, h(IconCopy)),
|
|
4278
|
+
h(IconAction, { label: t('revealInFinder'), onClick: () => { apiPost('/reveal', { path: selection.repoPath ?? active?.path, file: selection.path }).catch(() => {}) } }, h(IconFolder)),
|
|
4279
|
+
h(IconAction, { label: t('openDefaultApp'), onClick: () => { apiPost('/open', { path: selection.repoPath ?? active?.path, file: selection.path }).catch(() => {}) } }, h(IconExternal)),
|
|
4280
|
+
h(IconAction, {
|
|
4281
|
+
label: t('fileHistory'),
|
|
4282
|
+
onClick: () => setFileHistory({ path: selection.repoPath ?? active?.path, file: selection.path }),
|
|
4283
|
+
}, h(IconHistory)))
|
|
4284
|
+
: null,
|
|
4285
|
+
selection.kind !== 'file'
|
|
4286
|
+
? h('span', { style: { display: 'inline-flex', gap: 7, fontSize: 11, fontFamily: MONO, whiteSpace: 'nowrap' } },
|
|
4287
|
+
(() => {
|
|
4288
|
+
if (selection.kind === 'diff' || selection.kind === 'commit-diff') {
|
|
4289
|
+
const file = diff.data?.files?.[0]
|
|
4290
|
+
return file ? [h('span', { key: 'a', style: { color: T.success } }, `+${file.additions ?? 0}`), h('span', { key: 'd', style: { color: T.error } }, `−${file.deletions ?? 0}`)] : null
|
|
4291
|
+
}
|
|
4292
|
+
if (selection.kind === 'commit-files') {
|
|
4293
|
+
const stats = commitPatch.data?.stats
|
|
4294
|
+
return [h('span', { key: 'a', style: { color: T.success } }, `+${stats?.additions ?? 0}`), h('span', { key: 'd', style: { color: T.error } }, `−${stats?.deletions ?? 0}`)]
|
|
4295
|
+
}
|
|
4296
|
+
const totals = allDiff.entries.reduce((sum, item) => ({ add: sum.add + (item.entry?.additions ?? 0), del: sum.del + (item.entry?.deletions ?? 0) }), { add: 0, del: 0 })
|
|
4297
|
+
return [h('span', { key: 'a', style: { color: T.success } }, `+${totals.add}`), h('span', { key: 'd', style: { color: T.error } }, `−${totals.del}`)]
|
|
4298
|
+
})())
|
|
4299
|
+
: null,
|
|
4300
|
+
)
|
|
4301
|
+
: null,
|
|
4302
|
+
|
|
4303
|
+
selection
|
|
4304
|
+
? selection.kind === 'diff' || selection.kind === 'commit-diff'
|
|
4305
|
+
? diff.phase === 'loading'
|
|
4306
|
+
? h('div', { style: { padding: 18, color: T.muted, fontSize: 12.5 } }, t('loading'))
|
|
4307
|
+
: diff.phase === 'error'
|
|
4308
|
+
? h('div', { style: { padding: 18, color: T.error, fontSize: 12.5 } }, diff.error)
|
|
4309
|
+
: h(DiffLines, {
|
|
4310
|
+
file: diff.data?.files ?? [], view, t, wrap,
|
|
4311
|
+
context: {
|
|
4312
|
+
repoPath: selection.repoPath ?? active?.path,
|
|
4313
|
+
staged: Boolean(selection.staged),
|
|
4314
|
+
hash: selection.kind === 'commit-diff' ? selection.hash : undefined,
|
|
4315
|
+
},
|
|
4316
|
+
})
|
|
4317
|
+
: selection.kind === 'all'
|
|
4318
|
+
? h(AllDiff, { state: allDiff, view, t, context: { repoPath: selection.repoPath ?? active?.path, staged: Boolean(selection.staged) } })
|
|
4319
|
+
: selection.kind === 'commit-files'
|
|
4320
|
+
? h(CommitFilesView, { state: commitPatch, view, wrap, t, collapseMode: allFilesCollapsed, context: { repoPath: selection.repoPath ?? active?.path, hash: selection.hash } })
|
|
4321
|
+
: h(FilePreview, { state: { ...preview, data: preview.data ? { ...preview.data, repoPath: selection.repoPath ?? active?.path } : null }, selection, t })
|
|
4322
|
+
: h('div', {
|
|
4323
|
+
style: { flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 12, padding: 28, textAlign: 'center' },
|
|
4324
|
+
},
|
|
4325
|
+
h('div', {
|
|
4326
|
+
style: {
|
|
4327
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', width: 56, height: 56,
|
|
4328
|
+
borderRadius: 16, background: T.surfaceAlt, boxShadow: T.ring, color: T.muted,
|
|
4329
|
+
},
|
|
4330
|
+
},
|
|
4331
|
+
h('svg', { width: 28, height: 28, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' },
|
|
4332
|
+
h('path', { d: 'M6 3h12a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1z' }),
|
|
4333
|
+
h('path', { d: 'M9 8h6M9 12h6M9 16h4' }))),
|
|
4334
|
+
h('div', { style: { fontSize: 15, lineHeight: '22px', fontWeight: 600, color: T.text } }, t('emptyDiff')),
|
|
4335
|
+
h('div', { style: { fontSize: 12, color: T.muted, maxWidth: 320, lineHeight: '20px' } }, t('emptyDiffHint')))))),
|
|
4336
|
+
|
|
4337
|
+
h(Dialog, { dialog, onClose: () => setDialog(null) }),
|
|
4338
|
+
h(FileHistoryDialog, {
|
|
4339
|
+
history: fileHistory, t,
|
|
4340
|
+
onClose: () => setFileHistory(null),
|
|
4341
|
+
onOpenCommit: commit => {
|
|
4342
|
+
if (!fileHistory?.path) return
|
|
4343
|
+
setGraphPath(fileHistory.path)
|
|
4344
|
+
setMode('changes')
|
|
4345
|
+
setSelection({ kind: 'commit-diff', repoPath: fileHistory.path, hash: commit.oid, path: fileHistory.file })
|
|
4346
|
+
},
|
|
4347
|
+
}),
|
|
4348
|
+
h(Toast, { toast }))
|
|
4349
|
+
}
|
|
4350
|
+
|
|
4351
|
+
/**
|
|
4352
|
+
* Conversation-seat wrapper: while this Git view is the active conversation view, the resident composer is
|
|
4353
|
+
* replaced with nothing through the public 'conversation.composer' chain slot; switching back to Chat
|
|
4354
|
+
* disposes the takeover and the default composer returns.
|
|
4355
|
+
*/
|
|
4356
|
+
function ConversationGitView({ t, ctx, sessionId, renderFactorySlot, inputActions }) {
|
|
4357
|
+
useEffect(() => {
|
|
4358
|
+
if (!sessionId || !ctx?.slots?.register) return undefined
|
|
4359
|
+
let dispose
|
|
4360
|
+
try {
|
|
4361
|
+
dispose = ctx.slots.register({
|
|
4362
|
+
name: 'conversation.composer',
|
|
4363
|
+
select: owner => (owner && owner.sessionId === sessionId ? { hidden: true } : null),
|
|
4364
|
+
}, () => null)
|
|
4365
|
+
} catch {
|
|
4366
|
+
return undefined
|
|
4367
|
+
}
|
|
4368
|
+
return () => { try { dispose?.() } catch { /* already gone */ } }
|
|
4369
|
+
}, [ctx, sessionId])
|
|
4370
|
+
return h(PanelBoundary, { t }, h(Panel, { t, ctx, sessionId, renderFactorySlot, inputActions }))
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4373
|
+
/* ── registration ───────────────────────────────────────────────── */
|
|
4374
|
+
|
|
4375
|
+
const inject = ['slots', 'locale', 'sessions']
|
|
4376
|
+
|
|
4377
|
+
function apply(ctx) {
|
|
4378
|
+
ctx.effect(() => ctx.locale.register(NS, { zh: DICT.zh, en: DICT.en }), 'dsh-git-assistant: dictionaries')
|
|
4379
|
+
const t = ctx.locale.bind(NS)
|
|
4380
|
+
|
|
4381
|
+
ctx.slots.inject('main', () => ctx.slots.register(
|
|
4382
|
+
{ name: 'main', key: ID, locale: NS },
|
|
4383
|
+
props => h(PanelBoundary, { t: props?.t ?? t }, h(Panel, { t: props?.t ?? t, ctx, renderFactorySlot: props?.renderFactorySlot, inputActions: props?.inputActions }))))
|
|
4384
|
+
ctx.slots.inject('sidebar.panellist', () => ctx.slots.register(
|
|
4385
|
+
{ name: 'sidebar.panellist', id: ID, order: 24, label: () => t('label'), locale: NS },
|
|
4386
|
+
props => h(GitIcon, { size: props?.size })))
|
|
4387
|
+
ctx.slots.inject('conversation.view', () => ctx.slots.register(
|
|
4388
|
+
{ name: 'conversation.view', id: ID, order: 24, locale: NS, label: () => t('label') },
|
|
4389
|
+
props => h(ConversationGitView, { t: props?.t ?? t, ctx, sessionId: props?.sessionId, renderFactorySlot: props?.renderFactorySlot, inputActions: props?.inputActions })))
|
|
4390
|
+
// Right-sidebar seat: same workbench as a per-session right column.
|
|
4391
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register(
|
|
4392
|
+
{ name: 'sidebar.right.pane.tab', key: ID, locale: NS },
|
|
4393
|
+
props => h(PanelBoundary, { t: props?.t ?? t }, h(Panel, { t: props?.t ?? t, ctx, sessionId: props?.sessionId, renderFactorySlot: props?.renderFactorySlot, inputActions: props?.inputActions }))))
|
|
4394
|
+
const tabs = typeof ctx.get === 'function' ? ctx.get('sidebarRightTabs') : ctx.sidebarRightTabs
|
|
4395
|
+
if (tabs && typeof tabs.register === 'function') {
|
|
4396
|
+
ctx.effect(() => tabs.register({
|
|
4397
|
+
id: ID,
|
|
4398
|
+
kind: ID,
|
|
4399
|
+
title: () => t('label'),
|
|
4400
|
+
guide: [{ id: ID, order: 40, title: () => t('label'), description: () => t('rightbarHint') }],
|
|
4401
|
+
}), 'dsh-git-assistant: right sidebar tab type')
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
|
|
4405
|
+
return { inject, apply, __internals: { tokenize, languageOf, unifiedRows, splitRows, DiffLines, TreeRows, FilePreview, DICT, computeGraphLanes } }
|
|
4406
|
+
},
|
|
4407
|
+
})
|