dsh-commit-journal 0.0.0-stage → 0.3.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/client.js ADDED
@@ -0,0 +1,3012 @@
1
+ /**
2
+ * Commit Journal browser UI: horizontal tabs, DSH dual-theme tokens.
3
+ * Account switching lives on the Accounts tab (no global top bar).
4
+ */
5
+ window.__ModuleLoader__.load({
6
+ id: 'dsh-commit-journal',
7
+ factory(require) {
8
+ const React = require('react')
9
+ const h = React.createElement
10
+ const { useCallback, useEffect, useMemo, useRef, useState } = React
11
+ let ReactDOM = null
12
+ try { ReactDOM = require('react-dom') } catch { ReactDOM = null }
13
+
14
+ let ui = null
15
+ try { ui = require('@deepseek-ai/dsh-client-ui-primitives') } catch { ui = null }
16
+ const UiButton = ui && ui.Button
17
+ const UiModal = ui && ui.Modal
18
+ const UiTag = ui && ui.Tag
19
+ const UiMenu = ui && ui.Menu
20
+ const UiToast = ui && ui.Toast
21
+ const IconPlus = ui && ui.IconPlusOutlineRegular
22
+ const IconRefresh = ui && ui.IconRefreshOutlineRegular
23
+ const IconEdit = ui && ui.IconEditOutlineRegular
24
+ const IconTrash = ui && ui.IconTrashOutlineRegular
25
+ const IconCheck = ui && ui.IconCheckOutlineRegular
26
+ const IconSearch = ui && ui.IconSearchOutlineRegular
27
+ const IconSave = ui && ui.IconSaveOutlineRegular
28
+ const IconClose = ui && ui.IconCloseOutlineRegular
29
+ const IconChevronLeft = ui && ui.IconChevronLeftOutlineRegular
30
+ const IconChevronRight = ui && ui.IconChevronRightOutlineRegular
31
+ const IconChevronDown = ui && ui.IconChevronDownOutlineRegular
32
+ const IconDownload = ui && ui.IconDownloadOutlineRegular
33
+ const IconGlobe = ui && ui.IconGlobeOutlineRegular
34
+ const IconLink = ui && (ui.IconRightUpOutlineRegular || ui.IconLinkOutlineRegular)
35
+ const UiSeg = ui && ui.SegmentedControl
36
+
37
+ const PANEL_ID = 'commit-journal'
38
+ const NS = 'commitJournal'
39
+ const API = 'http://127.0.0.1:39282'
40
+ const TABS = [
41
+ { id: 'accounts', zh: '账号', en: 'Accounts' },
42
+ { id: 'repos', zh: '仓库', en: 'Repos' },
43
+ { id: 'commits', zh: '提交', en: 'Commits' },
44
+ { id: 'activity', zh: '活跃', en: 'Activity' },
45
+ { id: 'logs', zh: '日志', en: 'Logs' },
46
+ { id: 'settings', zh: '设置', en: 'Settings' }
47
+ ]
48
+
49
+ const DICTIONARIES = {
50
+ en: {
51
+ panelLabel: 'Commit Journal',
52
+ accounts: 'Accounts',
53
+ repos: 'Repos',
54
+ commits: 'Commits',
55
+ activity: 'Activity',
56
+ logs: 'Logs',
57
+ settings: 'Settings',
58
+ emptyAccount: 'Add an account first.',
59
+ newAccount: 'New account',
60
+ save: 'Save',
61
+ cancel: 'Cancel',
62
+ edit: 'Edit',
63
+ remove: 'Delete',
64
+ test: 'Test',
65
+ testScan: 'Scan test',
66
+ activate: 'Switch to this',
67
+ currentAccount: 'Current account',
68
+ switchAccount: 'Switch account',
69
+ active: 'Active',
70
+ refresh: 'Refresh',
71
+ refreshScan: 'Rescan',
72
+ sync: 'Sync',
73
+ syncWatched: 'Sync watched',
74
+ syncWatchedLocal: 'Sync watched (local)',
75
+ saveWatch: 'Save watched',
76
+ query: 'Query',
77
+ clearCommits: 'Reset local commits',
78
+ clearLogs: 'Clear logs',
79
+ accountMode: 'Mode',
80
+ modeRemote: 'Remote pull',
81
+ modeLocal: 'Local scan (git)',
82
+ modeRemoteShort: 'Remote',
83
+ modeLocalShort: 'Local',
84
+ modeHintRemote: 'Pull commits via provider API with a personal access token.',
85
+ modeHintLocal: 'Scans git repos under the folders you list — no token needed.',
86
+ provider: 'Provider',
87
+ providerCodeup: 'Codeup (Yunxiao)',
88
+ providerGitlab: 'GitLab',
89
+ providerGithub: 'GitHub / GHE',
90
+ localRoots: 'Scan roots',
91
+ localRootsPh: 'One absolute path per line\ne.g. F:\\Personal\\projects',
92
+ localRootsHint: 'Recursively find .git under each root (depth ≤ 5).',
93
+ name: 'Display name',
94
+ namePh: 'e.g. Work account',
95
+ edition: 'Org type',
96
+ editionCentral: 'Central (public cloud)',
97
+ editionRegion: 'Region (dedicated / private)',
98
+ editionHintCentral: 'Uses codeup.aliyun.com — fill organization ID below.',
99
+ editionHintRegion: 'Fill your dedicated instance API Base URL below.',
100
+ org: 'Organization / API',
101
+ orgId: 'organizationId',
102
+ orgIdPh: 'Org ID from Yunxiao org admin → Basic info',
103
+ orgIdPhGithub: 'Org or user login (e.g. yu-bobo); empty = all token-visible repos',
104
+ orgIdPhGitlab: 'Optional group path/id; empty = membership projects',
105
+ orgIdLabelGithub: 'Org / user (optional)',
106
+ orgIdLabelGitlab: 'Group (optional)',
107
+ apiBase: 'API Base URL',
108
+ apiBasePh: 'e.g. https://xxx.devops.aliyuncs.com',
109
+ apiBasePhGithub: 'Leave empty for github.com; GHE e.g. https://github.example.com',
110
+ apiBasePhGitlab: 'Leave empty for gitlab.com; self-hosted e.g. https://gitlab.example.com',
111
+ apiBaseHintGithub: 'Empty → api.github.com; Enterprise Server host gets /api/v3 appended if missing.',
112
+ apiBaseHintGitlab: 'Empty → gitlab.com/api/v4; self-hosted host gets /api/v4 appended if missing.',
113
+ authors: 'Author filters',
114
+ authorsHint: 'Email or name, comma-separated; empty = no filter',
115
+ authorsPh: 'you@example.com, Alice',
116
+ token: 'Personal access token',
117
+ tokenPh: 'Yunxiao → Personal settings → Personal access token',
118
+ tokenPhGithub:
119
+ 'Avatar → Settings → Developer settings → Personal access tokens → Fine-grained or Tokens (classic)',
120
+ tokenPhGitlab: 'GitLab → Preferences → Access tokens (read_api / read_repository)',
121
+ tokenPhEdit: 'Leave blank to keep unchanged',
122
+ insecureSsl: 'Skip TLS certificate verification',
123
+ insecureSslHint:
124
+ 'Use for corporate HTTPS proxy or self-signed certs (e.g. GitHub fetch failed / UNABLE_TO_VERIFY_LEAF_SIGNATURE). Less safe.',
125
+ defaultBranch: 'Default sync branch',
126
+ defaultBranchPh: 'master / main / develop',
127
+ watched: 'Watched',
128
+ branch: 'Branch',
129
+ time: 'Time',
130
+ repo: 'Repo',
131
+ title: 'Message',
132
+ author: 'Author',
133
+ sha: 'SHA',
134
+ level: 'Level',
135
+ levelInfo: 'Info',
136
+ levelWarn: 'Warn',
137
+ levelError: 'Error',
138
+ message: 'Message',
139
+ syncInterval: 'Sync interval (min)',
140
+ lookback: 'Lookback days',
141
+ exportsPath: 'Exports folder',
142
+ exportsPathHint: 'Markdown dumps from sync / period reports. Empty = ~/.dsh-commit-journal/exports',
143
+ recentYear: 'Past year',
144
+ totalCommits: 'Commits',
145
+ activeDays: 'Active days',
146
+ longestStreak: 'Longest streak',
147
+ maxDay: 'Peak day',
148
+ noData: 'No data yet. Sync commits first.',
149
+ confirmDelete: 'Delete this account?',
150
+ confirmClearCommits: 'Clear local commits for this account?',
151
+ confirmClearLogs: 'Clear sync logs?',
152
+ keyword: 'Keyword',
153
+ from: 'From',
154
+ to: 'To',
155
+ allRepos: 'All repos',
156
+ openRepo: 'Open',
157
+ repoKeyword: 'Search repos',
158
+ pageOf: 'Page',
159
+ pageSizeLabel: '/ page',
160
+ totalItems: '{n} total',
161
+ syncOk: 'Synced: +{n} commits ({f} fetched)',
162
+ syncPartial: 'Synced +{n}, {e} repo error(s)',
163
+ refreshOk: 'Repos refreshed',
164
+ saveWatchOk: 'Watched repos saved',
165
+ testOk: 'Connection OK',
166
+ testScanOk: 'Scan OK ({n} repos)',
167
+ activateOk: 'Account activated',
168
+ saveOk: 'Saved',
169
+ clearOk: 'Cleared',
170
+ queryOk: 'Updated',
171
+ refreshScanOk: 'Rescanned roots',
172
+ currentStreak: 'Current streak',
173
+ avgPerDay: 'Avg / active day',
174
+ peakOn: 'Peak on',
175
+ weekdayDist: 'By weekday',
176
+ heatHint: 'Click a day with commits to open the side drawer.',
177
+ activityFootnote:
178
+ 'Only locally synced commits are counted, bucketed by local calendar day. The first sync only looks back the days in Settings; earlier years may look sparse. For fuller history, raise lookback under Settings → Sync, reset local commits, then sync again.',
179
+ dayEmpty: 'No commits on this day.',
180
+ less: 'Less',
181
+ more: 'More',
182
+ noteTotal: 'All commits in range',
183
+ noteActiveDays: 'At least one commit',
184
+ noteStreak: 'Consecutive days with commits',
185
+ notePeak: 'No record yet',
186
+ unitDay: 'd',
187
+ unitCommit: '',
188
+ heatSummary: '{w} weeks · {a} active days · {c} commits',
189
+ dayLoading: 'Loading…',
190
+ dayCommits: '{n} commits',
191
+ filterAll: 'All',
192
+ filterWatched: 'Watched',
193
+ filterUnwatched: 'Unwatched',
194
+ descAccounts:
195
+ 'Each account is remote (Codeup / GitLab / GitHub PAT) or local (scan roots). Switch the active account to change which data other tabs use.',
196
+ descRepos:
197
+ '“Sync watched” pulls all watched repos; each row can sync alone. With nothing watched, full sync covers every visible repo.',
198
+ descReposLocal:
199
+ 'Rescan discovers git repos under your roots. Watch the ones to index; sync runs git log into the local cache.',
200
+ descCommits: 'Browse locally synced commits; filter by repo, date range, and keyword.',
201
+ descActivity: 'Contribution heatmap for the selected range.',
202
+ descLogs: 'Sync log for the current account; error rows show which repo failed.',
203
+ descSettings:
204
+ 'Scheduled sync applies to every account (remote API or local rescan). Lookback days apply on first sync, after reset, and once after you raise the window; otherwise sync is incremental.',
205
+ syncSettingsTitle: 'Sync'
206
+ },
207
+ zh: {
208
+ panelLabel: '提交日志',
209
+ accounts: '账号',
210
+ repos: '仓库',
211
+ commits: '提交',
212
+ activity: '活跃',
213
+ logs: '日志',
214
+ settings: '设置',
215
+ emptyAccount: '请先添加账号。',
216
+ newAccount: '新建账号',
217
+ save: '保存',
218
+ cancel: '取消',
219
+ edit: '编辑',
220
+ remove: '删除',
221
+ test: '测试',
222
+ testScan: '扫描测试',
223
+ activate: '切换为当前',
224
+ currentAccount: '当前账号',
225
+ switchAccount: '切换账号',
226
+ active: '当前',
227
+ refresh: '刷新',
228
+ refreshScan: '重新扫描',
229
+ sync: '同步',
230
+ syncWatched: '同步关注',
231
+ syncWatchedLocal: '同步关注(本地)',
232
+ saveWatch: '保存关注',
233
+ query: '查询',
234
+ clearCommits: '重置本地提交',
235
+ clearLogs: '清除日志',
236
+ accountMode: '模式',
237
+ modeRemote: '远程拉取',
238
+ modeLocal: '本地扫描(git)',
239
+ modeRemoteShort: '远程',
240
+ modeLocalShort: '本地',
241
+ modeHintRemote: '使用对应平台的个人访问令牌,经 API 拉取提交。',
242
+ modeHintLocal: '扫描下方根目录中的本机 git 仓库,无需令牌。',
243
+ provider: '平台',
244
+ providerCodeup: 'Codeup(云效)',
245
+ providerGitlab: 'GitLab',
246
+ providerGithub: 'GitHub / 企业版',
247
+ localRoots: '扫描根目录',
248
+ localRootsPh: '每行一个绝对路径\n例如 F:\\Personal\\projects',
249
+ localRootsHint: '在各根目录下递归查找 .git(深度 ≤ 5)。',
250
+ name: '显示名称',
251
+ namePh: '例如:公司主账号',
252
+ edition: '组织类型',
253
+ editionCentral: '中心版(公共云)',
254
+ editionRegion: 'Region 版(专有云 / 独立实例)',
255
+ editionHintCentral: '走 codeup.aliyun.com,请在下方填写组织 ID。',
256
+ editionHintRegion: '请在下方填写专有云 / 独立实例的 API Base URL。',
257
+ org: '组织 / 接入点',
258
+ orgId: 'organizationId',
259
+ orgIdPh: '组织管理后台 → 基本信息里的组织 ID',
260
+ orgIdPhGithub: '组织或用户 login(如 yu-bobo);留空=令牌可见全部仓库',
261
+ orgIdPhGitlab: '可选 group 路径/ID;留空列出 membership 项目',
262
+ orgIdLabelGithub: '组织 / 用户(可选)',
263
+ orgIdLabelGitlab: 'Group(可选)',
264
+ apiBase: 'API Base URL',
265
+ apiBasePh: '实例访问域名,如 https://xxx.devops.aliyuncs.com',
266
+ apiBasePhGithub: 'github.com 可留空;GHE 如 https://github.example.com',
267
+ apiBasePhGitlab: 'gitlab.com 可留空;自建如 https://gitlab.example.com',
268
+ apiBaseHintGithub: '留空 → api.github.com;企业版主机缺 /api/v3 时会自动补。',
269
+ apiBaseHintGitlab: '留空 → gitlab.com/api/v4;自建主机缺 /api/v4 时会自动补。',
270
+ authors: '作者过滤',
271
+ authorsHint: '邮箱或姓名,逗号分隔;留空不过滤',
272
+ authorsPh: 'you@example.com, 张三',
273
+ token: '个人访问令牌',
274
+ tokenPh: '云效个人设置 → 个人访问令牌',
275
+ tokenPhGithub:
276
+ '头像 → Settings → Developer settings → Personal access tokens → Fine-grained 或 Tokens (classic)',
277
+ tokenPhGitlab: 'GitLab → Preferences → Access tokens(read_api / read_repository)',
278
+ tokenPhEdit: '留空则不修改',
279
+ insecureSsl: '跳过 TLS 证书校验',
280
+ insecureSslHint:
281
+ '公司代理 / HTTPS 解密 / 自签证书导致 fetch failed(如 UNABLE_TO_VERIFY_LEAF_SIGNATURE)时可勾选;安全性较低。',
282
+ defaultBranch: '默认同步分支',
283
+ defaultBranchPh: 'master / main / develop',
284
+ watched: '关注',
285
+ branch: '分支',
286
+ time: '时间',
287
+ repo: '仓库',
288
+ title: '说明',
289
+ author: '作者',
290
+ sha: 'SHA',
291
+ level: '级别',
292
+ levelInfo: '信息',
293
+ levelWarn: '警告',
294
+ levelError: '错误',
295
+ message: '内容',
296
+ syncInterval: '同步间隔(分钟)',
297
+ lookback: '回溯天数',
298
+ exportsPath: '导出目录',
299
+ exportsPathHint: '同步按日落盘与周期报告 Markdown 的目录;留空默认 ~/.dsh-commit-journal/exports',
300
+ recentYear: '近一年',
301
+ totalCommits: '提交总数',
302
+ activeDays: '活跃天数',
303
+ longestStreak: '最长连续',
304
+ maxDay: '单日最高',
305
+ noData: '暂无数据,请先同步提交。',
306
+ confirmDelete: '确定删除该账号?',
307
+ confirmClearCommits: '清除该账号本地提交记录?',
308
+ confirmClearLogs: '清除同步日志?',
309
+ keyword: '关键词',
310
+ from: '开始',
311
+ to: '结束',
312
+ allRepos: '全部仓库',
313
+ openRepo: '打开',
314
+ repoKeyword: '搜索仓库',
315
+ pageOf: '页',
316
+ pageSizeLabel: '条/页',
317
+ totalItems: '共 {n} 条',
318
+ syncOk: '同步完成:新增 {n} 条(拉取 {f})',
319
+ syncPartial: '同步部分完成:新增 {n},{e} 个仓库出错',
320
+ refreshOk: '仓库列表已刷新',
321
+ saveWatchOk: '关注列表已保存',
322
+ testOk: '连接测试通过',
323
+ testScanOk: '扫描通过(发现 {n} 个仓库)',
324
+ activateOk: '已切换为当前账号',
325
+ saveOk: '已保存',
326
+ clearOk: '已清除',
327
+ queryOk: '已更新',
328
+ refreshScanOk: '已按根目录重新扫描',
329
+ currentStreak: '当前连续',
330
+ avgPerDay: '活跃日均',
331
+ peakOn: '峰值日期',
332
+ weekdayDist: '星期分布',
333
+ heatHint: '点击有提交的日期,右侧抽屉查看当日明细。',
334
+ activityFootnote:
335
+ '仅统计本地已同步的提交,按本地时区自然日归档。首次同步只回溯设置中的天数,更早的历史年份可能偏少;需要更完整的历史可在「设置 → 同步」调大回溯天数后重置记录再同步。',
336
+ dayEmpty: '当天没有提交记录',
337
+ less: '少',
338
+ more: '多',
339
+ noteTotal: '所选区间内全部提交',
340
+ noteActiveDays: '至少有一次提交',
341
+ noteStreak: '连续每天都有提交',
342
+ notePeak: '暂无记录',
343
+ unitDay: '天',
344
+ unitCommit: '条',
345
+ heatSummary: '共 {w} 周 · 活跃 {a} 天 · 合计 {c} 条',
346
+ dayLoading: '加载中',
347
+ dayCommits: '{n} 条提交',
348
+ filterAll: '全部',
349
+ filterWatched: '已关注',
350
+ filterUnwatched: '未关注',
351
+ descAccounts:
352
+ '每个账号可选远程(Codeup / GitLab / GitHub PAT)或本地(扫描根目录)。切换当前账号后,其它页签使用该账号数据。',
353
+ descRepos:
354
+ '「同步关注」拉取全部关注仓;单行可单独同步。未关注任何仓库时全量同步会覆盖全部可见仓。',
355
+ descReposLocal:
356
+ '「重新扫描」按根目录发现本机 git 仓;勾选关注后同步会执行 git log 写入本地缓存。',
357
+ descCommits: '查询本地已同步的提交记录;可按仓库、日期与关键词筛选。',
358
+ descActivity: '近一年 / 指定年份的提交活跃度。',
359
+ descLogs: '当前账号同步记录;错误行可查看具体仓库失败原因。',
360
+ descSettings:
361
+ '定时同步对所有账号生效(远程拉 API 或本地重扫)。回溯天数用于首次同步、重置记录后,以及调大该值后的下一次同步(会按新窗口回填一次历史);其余时间按上次同步时间增量拉取。',
362
+ syncSettingsTitle: '同步'
363
+ }
364
+ }
365
+
366
+ const CSS = `
367
+ /* 与侧栏「新会话」同档(实测 #e5e5e5);挂 :root 以便 Modal/Toast portal 也能用 */
368
+ :root, .dsh-cj-root {
369
+ --dsh-cj-border: #e5e5e5;
370
+ --dsh-cj-border: color-mix(in srgb, var(--dsw-alias-label-primary, #000) 10%, transparent);
371
+ }
372
+ .dsh-cj-root {
373
+ --dsh-cj-heat-0: #ebedf0;
374
+ --dsh-cj-heat-1: #9be9a8;
375
+ --dsh-cj-heat-2: #40c463;
376
+ --dsh-cj-heat-3: #30a14e;
377
+ --dsh-cj-heat-4: #216e39;
378
+ position: relative;
379
+ box-sizing: border-box;
380
+ height: 100%;
381
+ display: flex;
382
+ flex-direction: column;
383
+ background: var(--dsw-alias-bg-base);
384
+ color: var(--dsw-alias-label-primary);
385
+ font-size: 13px;
386
+ line-height: 1.45;
387
+ overflow: hidden;
388
+ }
389
+ .dsh-cj-root[data-scheme="dark"],
390
+ :root[data-theme="dark"] .dsh-cj-root,
391
+ :root[data-color-scheme="dark"] .dsh-cj-root {
392
+ --dsh-cj-heat-0: #161b22;
393
+ --dsh-cj-heat-1: #0e4429;
394
+ --dsh-cj-heat-2: #006d32;
395
+ --dsh-cj-heat-3: #26a641;
396
+ --dsh-cj-heat-4: #39d353;
397
+ }
398
+ @media (prefers-color-scheme: dark) {
399
+ .dsh-cj-root:not([data-scheme="light"]) {
400
+ --dsh-cj-heat-0: #161b22;
401
+ --dsh-cj-heat-1: #0e4429;
402
+ --dsh-cj-heat-2: #006d32;
403
+ --dsh-cj-heat-3: #26a641;
404
+ --dsh-cj-heat-4: #39d353;
405
+ }
406
+ }
407
+ .dsh-cj-root *, .dsh-cj-root *::before, .dsh-cj-root *::after { box-sizing: border-box; }
408
+ .dsh-cj-tabs {
409
+ display: flex;
410
+ gap: 4px;
411
+ padding: calc(var(--dsh-frame-top-clearance, 0px) + 12px) 20px 0;
412
+ border-bottom: 1px solid var(--dsh-cj-border);
413
+ flex-shrink: 0;
414
+ }
415
+ .dsh-cj-tab {
416
+ appearance: none;
417
+ border: 0;
418
+ background: transparent;
419
+ color: var(--dsw-alias-label-secondary);
420
+ padding: 10px 14px;
421
+ margin-bottom: -1px;
422
+ border-bottom: 2px solid transparent;
423
+ cursor: pointer;
424
+ font-size: 13px;
425
+ border-radius: 8px 8px 0 0;
426
+ }
427
+ .dsh-cj-tab[data-active="1"] {
428
+ color: var(--dsw-alias-label-primary);
429
+ border-bottom-color: var(--dsw-alias-brand-primary);
430
+ font-weight: 600;
431
+ }
432
+ .dsh-cj-body {
433
+ flex: 1;
434
+ min-height: 0;
435
+ overflow: hidden;
436
+ padding: 16px 20px 16px;
437
+ display: flex;
438
+ flex-direction: column;
439
+ }
440
+ /* Table pages: fill remaining height; table scrolls; pager stays put */
441
+ .dsh-cj-page-fill {
442
+ flex: 1;
443
+ min-height: 0;
444
+ display: flex;
445
+ flex-direction: column;
446
+ overflow: hidden;
447
+ }
448
+ .dsh-cj-page-fill > .dsh-cj-page-head,
449
+ .dsh-cj-page-fill > .dsh-cj-row,
450
+ .dsh-cj-page-fill > .dsh-cj-pager,
451
+ .dsh-cj-page-fill > .dsh-cj-muted,
452
+ .dsh-cj-page-fill > .dsh-cj-error {
453
+ flex-shrink: 0;
454
+ }
455
+ /* Non-table pages keep a single scroll area */
456
+ .dsh-cj-page-scroll {
457
+ flex: 1;
458
+ min-height: 0;
459
+ overflow: auto;
460
+ }
461
+ .dsh-cj-row {
462
+ display: flex;
463
+ flex-wrap: wrap;
464
+ gap: 8px;
465
+ align-items: center;
466
+ margin-bottom: 12px;
467
+ }
468
+ .dsh-cj-row-end { justify-content: space-between; }
469
+ .dsh-cj-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
470
+ .dsh-cj-table .dsh-cj-actions {
471
+ flex-wrap: nowrap;
472
+ gap: 6px;
473
+ justify-content: flex-end;
474
+ }
475
+ .dsh-cj-td-actions {
476
+ white-space: nowrap;
477
+ width: 1%;
478
+ vertical-align: middle !important;
479
+ }
480
+ .dsh-cj-td-clip {
481
+ max-width: 140px;
482
+ overflow: hidden;
483
+ text-overflow: ellipsis;
484
+ white-space: nowrap;
485
+ }
486
+ .dsh-cj-btn-icon.dsh-cj-btn-sized,
487
+ .dsh-cj-btn.dsh-cj-btn-icon {
488
+ padding: 0 8px !important;
489
+ min-width: 32px;
490
+ justify-content: center !important;
491
+ }
492
+ /* Size only — do not override official Button primary/outline colors */
493
+ .dsh-cj-btn-sized {
494
+ box-sizing: border-box !important;
495
+ height: 32px !important;
496
+ min-height: 32px !important;
497
+ max-height: 32px !important;
498
+ padding: 0 12px !important;
499
+ font-size: 12px !important;
500
+ line-height: 18px !important;
501
+ display: inline-flex !important;
502
+ align-items: center !important;
503
+ white-space: nowrap;
504
+ vertical-align: middle;
505
+ }
506
+ .dsh-cj-btn {
507
+ appearance: none;
508
+ box-sizing: border-box;
509
+ height: 32px;
510
+ min-height: 32px;
511
+ padding: 0 12px;
512
+ margin: 0;
513
+ border: 1px solid var(--dsh-cj-border, #e5e5e5);
514
+ background: var(--dsw-alias-bg-layer-1);
515
+ color: var(--dsw-alias-label-primary);
516
+ border-radius: var(--dsw-radius-sm, 8px);
517
+ font-size: 12px;
518
+ line-height: 18px;
519
+ cursor: pointer;
520
+ display: inline-flex;
521
+ align-items: center;
522
+ justify-content: center;
523
+ gap: 4px;
524
+ white-space: nowrap;
525
+ vertical-align: middle;
526
+ }
527
+ .dsh-cj-btn:disabled { opacity: .45; cursor: not-allowed; }
528
+ .dsh-cj-btn[data-primary="1"] {
529
+ background: var(--dsw-alias-brand-primary);
530
+ border-color: transparent;
531
+ color: #fff;
532
+ }
533
+ .dsh-cj-btn[data-danger="1"] {
534
+ color: var(--dsw-alias-state-error-primary);
535
+ border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, transparent);
536
+ }
537
+ .dsh-cj-btn-danger {
538
+ color: var(--dsw-alias-state-error-primary) !important;
539
+ }
540
+ /* 控件描边与 --dsh-cj-border 同档;打到控件本身,不走官方 Input 偏浅的 l4 */
541
+ .dsh-cj-control,
542
+ .dsh-cj-input,
543
+ .dsh-cj-select,
544
+ .dsh-cj-select-trigger,
545
+ .dsh-cj-textarea {
546
+ box-sizing: border-box;
547
+ border: 1px solid var(--dsh-cj-border, #e5e5e5) !important;
548
+ border-radius: var(--dsw-radius-sm, 8px) !important;
549
+ background: var(--dsw-alias-bg-layer-1, #fff);
550
+ color: var(--dsw-alias-label-primary, #111);
551
+ }
552
+ .dsh-cj-control:focus-within,
553
+ .dsh-cj-input:focus,
554
+ .dsh-cj-select:focus,
555
+ .dsh-cj-select-trigger:focus,
556
+ .dsh-cj-select-trigger[aria-expanded="true"],
557
+ .dsh-cj-textarea:focus {
558
+ border-color: var(--dsw-alias-state-business-primary, var(--dsw-alias-brand-primary, #1677ff)) !important;
559
+ outline: none !important;
560
+ }
561
+ .dsh-cj-input, .dsh-cj-select {
562
+ height: 32px;
563
+ min-height: 32px;
564
+ padding: 0 10px;
565
+ font-size: 12px;
566
+ line-height: 18px;
567
+ min-width: 0;
568
+ vertical-align: middle;
569
+ }
570
+ .dsh-cj-input[type="date"] {
571
+ min-width: 140px;
572
+ color-scheme: inherit;
573
+ }
574
+ .dsh-cj-select-trigger {
575
+ display: inline-flex !important;
576
+ align-items: center;
577
+ justify-content: space-between;
578
+ gap: 8px;
579
+ width: auto;
580
+ max-width: 100%;
581
+ min-width: 0;
582
+ height: 32px !important;
583
+ min-height: 32px !important;
584
+ max-height: 32px !important;
585
+ padding: 0 10px !important;
586
+ font-size: 12px !important;
587
+ line-height: 18px !important;
588
+ font-weight: 400 !important;
589
+ }
590
+ .dsh-cj-select-anchor {
591
+ display: block;
592
+ width: 100%;
593
+ max-width: 100%;
594
+ min-width: 0;
595
+ }
596
+ .dsh-cj-select-anchor .dsh-cj-select-trigger,
597
+ .dsh-cj-field .dsh-cj-select-trigger {
598
+ width: 100% !important;
599
+ }
600
+ .dsh-cj-select-trigger .dsh-cj-select-label {
601
+ overflow: hidden;
602
+ text-overflow: ellipsis;
603
+ white-space: nowrap;
604
+ min-width: 0;
605
+ flex: 1;
606
+ text-align: left;
607
+ }
608
+ .dsh-cj-select-trigger .dsh-cj-select-caret {
609
+ flex-shrink: 0;
610
+ opacity: 0.7;
611
+ font-size: 11px;
612
+ line-height: 1;
613
+ }
614
+ .dsh-cj-select-menu {
615
+ position: fixed;
616
+ z-index: 60;
617
+ max-height: min(280px, 50vh);
618
+ overflow: auto;
619
+ padding: 4px;
620
+ border-radius: var(--dsw-radius-sm, 8px);
621
+ border: 1px solid var(--dsh-cj-border);
622
+ background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1));
623
+ box-shadow: var(--dsw-elevation-prominent, 0 8px 24px rgba(0,0,0,.18));
624
+ }
625
+ .dsh-cj-select-option {
626
+ appearance: none;
627
+ display: block;
628
+ width: 100%;
629
+ border: 0;
630
+ background: transparent;
631
+ color: var(--dsw-alias-label-primary);
632
+ text-align: left;
633
+ border-radius: 6px;
634
+ padding: 8px 10px;
635
+ font-size: 14px;
636
+ line-height: 22px;
637
+ cursor: pointer;
638
+ }
639
+ .dsh-cj-select-option:hover,
640
+ .dsh-cj-select-option[data-active="1"] {
641
+ background: var(--dsw-alias-bg-layer-1);
642
+ }
643
+ .dsh-cj-select-option[data-selected="1"] {
644
+ color: var(--dsw-alias-brand-primary);
645
+ font-weight: 600;
646
+ }
647
+ .dsh-cj-select-option:disabled {
648
+ opacity: 0.45;
649
+ cursor: not-allowed;
650
+ }
651
+ .dsh-cj-textarea {
652
+ display: block;
653
+ width: 100%;
654
+ max-width: 100%;
655
+ min-width: 0;
656
+ padding: 8px 10px;
657
+ margin: 0;
658
+ font-size: 12px;
659
+ line-height: 18px;
660
+ font-family: inherit;
661
+ min-height: 72px;
662
+ resize: vertical;
663
+ outline: none;
664
+ }
665
+ /* dimmed 太浅;用 secondary 并取消 Firefox 默认降低透明度 */
666
+ .dsh-cj-textarea::placeholder,
667
+ .dsh-cj-input::placeholder {
668
+ color: var(--dsw-alias-label-secondary, #737373);
669
+ opacity: 1;
670
+ }
671
+ /* Official Input wrapper also lands at 32px */
672
+ .dsh-cj-row > span {
673
+ vertical-align: middle;
674
+ }
675
+ .dsh-cj-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
676
+ .dsh-cj-account-form {
677
+ width: min(640px, calc(100vw - 48px));
678
+ max-width: 100%;
679
+ }
680
+ .dsh-cj-form-row {
681
+ display: grid;
682
+ grid-template-columns: 1fr 1fr;
683
+ gap: 0 12px;
684
+ align-items: start;
685
+ }
686
+ .dsh-cj-form-span {
687
+ grid-column: 1 / -1;
688
+ }
689
+ .dsh-cj-field-check {
690
+ margin-top: 2px;
691
+ }
692
+ .dsh-cj-field-check .dsh-cj-label {
693
+ display: flex;
694
+ align-items: center;
695
+ gap: 8px;
696
+ font-weight: 400;
697
+ cursor: pointer;
698
+ user-select: none;
699
+ }
700
+ @media (max-width: 560px) {
701
+ .dsh-cj-form-row { grid-template-columns: 1fr; }
702
+ .dsh-cj-account-form { width: 100%; }
703
+ }
704
+ /* 官方 Input 外层是 inline-flex + align-items:center;拉满宽度时不能改成 block,否则 placeholder 不垂直居中 */
705
+ .dsh-cj-field > span {
706
+ display: inline-flex;
707
+ align-items: center;
708
+ box-sizing: border-box;
709
+ width: 100%;
710
+ max-width: 100%;
711
+ min-width: 0;
712
+ }
713
+ .dsh-cj-field .dsh-cj-input {
714
+ box-sizing: border-box;
715
+ width: 100%;
716
+ max-width: 100%;
717
+ min-width: 0;
718
+ }
719
+ .dsh-cj-label { color: var(--dsw-alias-label-secondary); font-size: 12px; }
720
+ .dsh-cj-muted { color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 1.45; }
721
+ .dsh-cj-page-head { margin-bottom: 14px; }
722
+ .dsh-cj-page-title {
723
+ margin: 0 0 6px;
724
+ font-size: 16px;
725
+ font-weight: 650;
726
+ color: var(--dsw-alias-label-primary);
727
+ }
728
+ .dsh-cj-page-desc {
729
+ margin: 0;
730
+ color: var(--dsw-alias-label-secondary);
731
+ font-size: 12px;
732
+ line-height: 1.55;
733
+ }
734
+ .dsh-cj-footnote {
735
+ margin: 12px 0 0;
736
+ color: var(--dsw-alias-label-secondary);
737
+ font-size: 12px;
738
+ line-height: 1.55;
739
+ }
740
+ .dsh-cj-error { color: var(--dsw-alias-state-error-primary); font-size: 12px; margin: 0 0 10px; }
741
+ .dsh-cj-table-wrap {
742
+ flex: 1;
743
+ min-height: 0;
744
+ border: 1px solid var(--dsh-cj-border);
745
+ border-radius: 12px;
746
+ overflow: auto;
747
+ background: var(--dsw-alias-bg-layer-1);
748
+ }
749
+ .dsh-cj-page-scroll > .dsh-cj-table-wrap {
750
+ flex: initial;
751
+ min-height: auto;
752
+ max-height: none;
753
+ }
754
+ .dsh-cj-table { width: 100%; border-collapse: collapse; }
755
+ .dsh-cj-table th, .dsh-cj-table td {
756
+ padding: 10px 12px;
757
+ text-align: left;
758
+ border-bottom: 1px solid var(--dsh-cj-border);
759
+ vertical-align: top;
760
+ }
761
+ .dsh-cj-table th {
762
+ font-weight: 600;
763
+ color: var(--dsw-alias-label-secondary);
764
+ background: var(--dsw-alias-bg-layer-2);
765
+ position: sticky;
766
+ top: 0;
767
+ }
768
+ .dsh-cj-table tr:last-child td { border-bottom: 0; }
769
+ /* Fallback Tag tones (match official Tag.module.css) */
770
+ .dsh-cj-tag {
771
+ display: inline-flex;
772
+ align-items: center;
773
+ border-radius: 999px;
774
+ padding: 1px 8px;
775
+ font-size: 11px;
776
+ line-height: 17px;
777
+ font-weight: 500;
778
+ white-space: nowrap;
779
+ }
780
+ .dsh-cj-tag[data-tone="outline"] {
781
+ border: 0.5px solid var(--dsw-alias-border-l4, var(--dsh-cj-border));
782
+ color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
783
+ }
784
+ .dsh-cj-tag[data-tone="solid"] {
785
+ background: var(--dsw-alias-label-primary);
786
+ color: var(--dsw-alias-bg-layer-3, var(--dsw-alias-bg-layer-1));
787
+ }
788
+ .dsh-cj-tag[data-tone="neutral"] {
789
+ background: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-layer-2));
790
+ color: var(--dsw-alias-label-secondary);
791
+ }
792
+ .dsh-cj-tag[data-tone="success"] {
793
+ background: color-mix(in srgb, var(--dsw-alias-state-success-primary, #16a34a) 10%, transparent);
794
+ color: var(--dsw-alias-state-success-primary, #16a34a);
795
+ }
796
+ .dsh-cj-tag[data-tone="info"] {
797
+ background: color-mix(in srgb, var(--dsw-alias-state-business-primary, #2563eb) 10%, transparent);
798
+ color: var(--dsw-alias-state-business-primary, #2563eb);
799
+ }
800
+ .dsh-cj-tag[data-tone="warning"] {
801
+ background: color-mix(in srgb, var(--dsw-alias-state-warn-primary, #d97706) 12%, transparent);
802
+ color: var(--dsw-alias-state-warn-primary, #d97706);
803
+ }
804
+ .dsh-cj-tag[data-tone="danger"] {
805
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent);
806
+ color: var(--dsw-alias-state-error-primary);
807
+ }
808
+ /* Fallback modal: paint below native caption so top-right DSH controls stay usable */
809
+ .dsh-cj-modal-mask {
810
+ position: fixed;
811
+ inset: var(--dsh-frame-chrome-top, 0px) 0 0;
812
+ background: var(--dsw-alias-bg-mask-1, color-mix(in srgb, #000 40%, transparent));
813
+ display: flex; align-items: center; justify-content: center; z-index: 40;
814
+ padding: max(24px, var(--dsh-frame-overlay-top, 24px)) 24px;
815
+ }
816
+ .dsh-cj-modal {
817
+ width: min(480px, 100%);
818
+ background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1));
819
+ border: 1px solid var(--dsh-cj-border);
820
+ border-radius: var(--dsw-radius-panel, 14px);
821
+ padding: 16px;
822
+ max-height: 100%;
823
+ overflow: auto;
824
+ box-shadow: var(--dsw-elevation-prominent, none);
825
+ }
826
+ .dsh-cj-modal-wide {
827
+ width: min(680px, 100%);
828
+ }
829
+ .dsh-cj-modal h3 { margin: 0 0 12px; font-size: 15px; }
830
+ .dsh-cj-stats {
831
+ display: grid;
832
+ grid-template-columns: repeat(4, minmax(0, 1fr));
833
+ gap: 10px;
834
+ margin: 4px 0 16px;
835
+ }
836
+ .dsh-cj-stat {
837
+ position: relative;
838
+ overflow: hidden;
839
+ background: var(--dsw-alias-bg-layer-1);
840
+ border: 1px solid var(--dsh-cj-border);
841
+ border-radius: 12px;
842
+ padding: 12px 14px 13px;
843
+ }
844
+ .dsh-cj-stat .l {
845
+ position: relative;
846
+ z-index: 1;
847
+ color: var(--dsw-alias-label-secondary);
848
+ font-size: 12px;
849
+ letter-spacing: 0.04em;
850
+ }
851
+ .dsh-cj-stat .v {
852
+ position: relative;
853
+ z-index: 1;
854
+ margin-top: 4px;
855
+ font-size: 26px;
856
+ font-weight: 700;
857
+ line-height: 1.2;
858
+ color: var(--dsh-cj-heat-3);
859
+ font-variant-numeric: tabular-nums;
860
+ }
861
+ .dsh-cj-stat .v small {
862
+ margin-left: 4px;
863
+ font-size: 12px;
864
+ font-weight: 500;
865
+ color: var(--dsw-alias-label-secondary);
866
+ }
867
+ .dsh-cj-stat .n {
868
+ position: relative;
869
+ z-index: 1;
870
+ margin-top: 3px;
871
+ font-size: 12px;
872
+ color: var(--dsw-alias-label-secondary);
873
+ min-height: 16px;
874
+ }
875
+ .dsh-cj-heat {
876
+ background: var(--dsw-alias-bg-layer-1);
877
+ border: 1px solid var(--dsh-cj-border);
878
+ border-radius: 12px;
879
+ padding: 14px 16px 12px;
880
+ overflow-x: hidden;
881
+ container-type: inline-size;
882
+ }
883
+ .dsh-cj-heat-body {
884
+ --dsh-cj-cell: clamp(9px, calc((100cqw - 48px) / 53), 13px);
885
+ --dsh-cj-gap: 3px;
886
+ display: flex;
887
+ align-items: flex-start;
888
+ gap: 8px;
889
+ width: 100%;
890
+ }
891
+ .dsh-cj-heat-main { min-width: 0; }
892
+ .dsh-cj-months {
893
+ display: grid;
894
+ grid-auto-flow: column;
895
+ grid-auto-columns: calc(var(--dsh-cj-cell) + var(--dsh-cj-gap));
896
+ height: 16px;
897
+ margin-bottom: 4px;
898
+ color: var(--dsw-alias-label-secondary);
899
+ font-size: 11px;
900
+ line-height: 16px;
901
+ user-select: none;
902
+ }
903
+ .dsh-cj-months .dsh-cj-month {
904
+ white-space: nowrap;
905
+ }
906
+ .dsh-cj-weekdays {
907
+ display: grid;
908
+ grid-template-rows: repeat(7, var(--dsh-cj-cell));
909
+ gap: var(--dsh-cj-gap);
910
+ padding-top: 20px;
911
+ color: var(--dsw-alias-label-secondary);
912
+ font-size: 10px;
913
+ line-height: var(--dsh-cj-cell);
914
+ user-select: none;
915
+ width: 14px;
916
+ flex: none;
917
+ }
918
+ .dsh-cj-weekdays span {
919
+ height: var(--dsh-cj-cell);
920
+ display: flex;
921
+ align-items: center;
922
+ justify-content: flex-end;
923
+ }
924
+ .dsh-cj-grid {
925
+ display: grid;
926
+ grid-auto-flow: column;
927
+ grid-template-rows: repeat(7, var(--dsh-cj-cell));
928
+ grid-auto-columns: var(--dsh-cj-cell);
929
+ gap: var(--dsh-cj-gap);
930
+ }
931
+ .dsh-cj-cell {
932
+ width: var(--dsh-cj-cell);
933
+ height: var(--dsh-cj-cell);
934
+ border-radius: max(3px, calc(var(--dsh-cj-cell) * 0.2));
935
+ border: 0;
936
+ padding: 0;
937
+ background: var(--dsh-cj-heat-0);
938
+ }
939
+ .dsh-cj-cell.lv1 { background: var(--dsh-cj-heat-1); }
940
+ .dsh-cj-cell.lv2 { background: var(--dsh-cj-heat-2); }
941
+ .dsh-cj-cell.lv3 { background: var(--dsh-cj-heat-3); }
942
+ .dsh-cj-cell.lv4 { background: var(--dsh-cj-heat-4); }
943
+ .dsh-cj-cell.is-blank {
944
+ opacity: .45;
945
+ box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--dsh-cj-border) 80%, transparent);
946
+ }
947
+ .dsh-cj-cell.has-commits { cursor: pointer; }
948
+ .dsh-cj-cell.has-commits:hover {
949
+ transform: scale(1.2);
950
+ position: relative;
951
+ z-index: 2;
952
+ }
953
+ .dsh-cj-cell.is-today { outline: 1px solid var(--dsh-cj-heat-3); outline-offset: 1px; }
954
+ .dsh-cj-heat-foot {
955
+ display: flex;
956
+ align-items: center;
957
+ justify-content: space-between;
958
+ flex-wrap: wrap;
959
+ gap: 10px;
960
+ margin-top: 14px;
961
+ font-size: 12px;
962
+ color: var(--dsw-alias-label-secondary);
963
+ }
964
+ .dsh-cj-heat-legend {
965
+ display: flex; align-items: center; gap: 5px;
966
+ }
967
+ .dsh-cj-heat-legend .swatch {
968
+ width: 12px; height: 12px; border-radius: 3px; display: inline-block;
969
+ background: var(--dsh-cj-heat-0);
970
+ }
971
+ .dsh-cj-heat-legend .swatch.lv1 { background: var(--dsh-cj-heat-1); }
972
+ .dsh-cj-heat-legend .swatch.lv2 { background: var(--dsh-cj-heat-2); }
973
+ .dsh-cj-heat-legend .swatch.lv3 { background: var(--dsh-cj-heat-3); }
974
+ .dsh-cj-heat-legend .swatch.lv4 { background: var(--dsh-cj-heat-4); }
975
+ .dsh-cj-insights {
976
+ display: grid;
977
+ grid-template-columns: repeat(2, minmax(0, 1fr));
978
+ gap: 12px;
979
+ margin-top: 14px;
980
+ }
981
+ .dsh-cj-insight {
982
+ background: var(--dsw-alias-bg-layer-1);
983
+ border: 1px solid var(--dsh-cj-border);
984
+ border-radius: 12px;
985
+ padding: 12px 14px;
986
+ }
987
+ .dsh-cj-insight h4 {
988
+ margin: 0 0 10px;
989
+ font-size: 12px;
990
+ font-weight: 600;
991
+ color: var(--dsw-alias-label-secondary);
992
+ }
993
+ .dsh-cj-wd {
994
+ display: grid;
995
+ grid-template-columns: 18px 1fr 28px;
996
+ gap: 8px;
997
+ align-items: center;
998
+ margin-bottom: 6px;
999
+ font-size: 11px;
1000
+ color: var(--dsw-alias-label-secondary);
1001
+ }
1002
+ .dsh-cj-wd:last-child { margin-bottom: 0; }
1003
+ .dsh-cj-wd-bar {
1004
+ height: 6px;
1005
+ border-radius: 999px;
1006
+ background: color-mix(in srgb, var(--dsh-cj-border) 70%, transparent);
1007
+ overflow: hidden;
1008
+ }
1009
+ .dsh-cj-wd-bar > i {
1010
+ display: block;
1011
+ height: 100%;
1012
+ border-radius: 999px;
1013
+ background: var(--dsh-cj-heat-3);
1014
+ }
1015
+ .dsh-cj-meta-list {
1016
+ display: flex;
1017
+ flex-direction: column;
1018
+ gap: 8px;
1019
+ font-size: 12px;
1020
+ }
1021
+ .dsh-cj-meta-list div { display: flex; justify-content: space-between; gap: 12px; }
1022
+ .dsh-cj-meta-list strong { color: var(--dsw-alias-label-primary); font-weight: 600; }
1023
+ @media (max-width: 720px) {
1024
+ .dsh-cj-insights { grid-template-columns: 1fr; }
1025
+ }
1026
+ .dsh-cj-drawer {
1027
+ position: absolute;
1028
+ top: 0;
1029
+ right: 0;
1030
+ bottom: 0;
1031
+ z-index: 20;
1032
+ width: min(400px, 94%);
1033
+ display: flex;
1034
+ flex-direction: column;
1035
+ background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1));
1036
+ border-left: 1px solid var(--dsh-cj-border);
1037
+ box-shadow: var(--dsw-elevation-prominent, none);
1038
+ padding: 14px 16px 16px;
1039
+ }
1040
+ .dsh-cj-drawer-head {
1041
+ display: flex;
1042
+ align-items: center;
1043
+ justify-content: space-between;
1044
+ gap: 8px;
1045
+ margin-bottom: 12px;
1046
+ flex-shrink: 0;
1047
+ }
1048
+ .dsh-cj-drawer-body {
1049
+ flex: 1;
1050
+ min-height: 0;
1051
+ overflow: auto;
1052
+ }
1053
+ .dsh-cj-drawer-title {
1054
+ display: flex;
1055
+ flex-direction: column;
1056
+ gap: 2px;
1057
+ min-width: 0;
1058
+ }
1059
+ .dsh-cj-drawer-title strong { font-size: 15px; font-weight: 600; }
1060
+ .dsh-cj-drawer-title span {
1061
+ font-size: 12px;
1062
+ font-weight: 400;
1063
+ color: var(--dsw-alias-label-secondary);
1064
+ }
1065
+ .dsh-cj-commit {
1066
+ padding: 11px 13px 12px;
1067
+ margin-bottom: 10px;
1068
+ border-radius: 12px;
1069
+ border: 1px solid var(--dsh-cj-border);
1070
+ background: var(--dsw-alias-bg-layer-1);
1071
+ }
1072
+ .dsh-cj-commit:last-child { margin-bottom: 0; }
1073
+ .dsh-cj-commit-head {
1074
+ display: flex;
1075
+ align-items: center;
1076
+ justify-content: space-between;
1077
+ gap: 10px;
1078
+ font-size: 12px;
1079
+ color: var(--dsw-alias-label-secondary);
1080
+ }
1081
+ .dsh-cj-commit-repo {
1082
+ overflow: hidden;
1083
+ text-overflow: ellipsis;
1084
+ white-space: nowrap;
1085
+ }
1086
+ .dsh-cj-commit-title {
1087
+ margin-top: 5px;
1088
+ font-size: 13px;
1089
+ line-height: 1.55;
1090
+ word-break: break-word;
1091
+ }
1092
+ .dsh-cj-commit-meta {
1093
+ display: flex;
1094
+ align-items: center;
1095
+ gap: 8px;
1096
+ margin-top: 6px;
1097
+ font-size: 12px;
1098
+ color: var(--dsw-alias-label-secondary);
1099
+ }
1100
+ .dsh-cj-commit-sha {
1101
+ padding: 1px 6px;
1102
+ border-radius: 5px;
1103
+ border: 1px solid var(--dsh-cj-border);
1104
+ background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1));
1105
+ font-size: 11px;
1106
+ }
1107
+ .dsh-cj-pager {
1108
+ flex-shrink: 0;
1109
+ display: flex;
1110
+ justify-content: flex-end;
1111
+ gap: 6px;
1112
+ align-items: center;
1113
+ margin-top: 4px;
1114
+ padding: 12px 0 2px;
1115
+ border-top: 1px solid var(--dsh-cj-border);
1116
+ }
1117
+ .dsh-cj-pager-info {
1118
+ margin-right: auto;
1119
+ color: var(--dsw-alias-label-secondary);
1120
+ font-size: 12px;
1121
+ }
1122
+ .dsh-cj-pager-size {
1123
+ display: inline-flex;
1124
+ align-items: center;
1125
+ gap: 6px;
1126
+ color: var(--dsw-alias-label-secondary);
1127
+ font-size: 12px;
1128
+ }
1129
+ .dsh-cj-pager-size .dsh-cj-select-trigger {
1130
+ min-width: 72px;
1131
+ }
1132
+ .dsh-cj-link {
1133
+ color: var(--dsw-alias-brand-primary);
1134
+ text-decoration: none;
1135
+ }
1136
+ .dsh-cj-toast-fallback {
1137
+ position: fixed;
1138
+ top: 16px;
1139
+ left: 50%;
1140
+ transform: translateX(-50%);
1141
+ z-index: 10000;
1142
+ max-width: min(520px, calc(100vw - 24px));
1143
+ padding: 10px 14px;
1144
+ border-radius: 10px;
1145
+ font-size: 12px;
1146
+ line-height: 1.45;
1147
+ background: var(--dsw-alias-bg-layer-2, var(--dsw-alias-bg-layer-1));
1148
+ border: 1px solid var(--dsh-cj-border);
1149
+ color: var(--dsw-alias-label-primary);
1150
+ box-shadow: var(--dsw-elevation-prominent, 0 8px 24px rgba(0,0,0,.18));
1151
+ pointer-events: none;
1152
+ }
1153
+ .dsh-cj-toast-fallback[data-tone="success"] {
1154
+ background: color-mix(in srgb, var(--dsh-cj-heat-2) 18%, var(--dsw-alias-bg-layer-1));
1155
+ border-color: color-mix(in srgb, var(--dsh-cj-heat-3) 35%, var(--dsh-cj-border));
1156
+ }
1157
+ .dsh-cj-toast-fallback[data-tone="error"] {
1158
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, var(--dsw-alias-bg-layer-1));
1159
+ border-color: color-mix(in srgb, var(--dsw-alias-state-error-primary) 35%, var(--dsh-cj-border));
1160
+ color: var(--dsw-alias-state-error-primary);
1161
+ }
1162
+ .dsh-cj-seg {
1163
+ display: inline-flex;
1164
+ gap: 2px;
1165
+ padding: 2px;
1166
+ border-radius: 8px;
1167
+ background: var(--dsw-alias-bg-layer-2);
1168
+ border: 1px solid var(--dsh-cj-border);
1169
+ }
1170
+ .dsh-cj-seg button {
1171
+ appearance: none;
1172
+ border: 0;
1173
+ background: transparent;
1174
+ color: var(--dsw-alias-label-secondary);
1175
+ border-radius: 6px;
1176
+ padding: 5px 10px;
1177
+ font-size: 12px;
1178
+ cursor: pointer;
1179
+ }
1180
+ .dsh-cj-seg button[data-active="1"] {
1181
+ background: var(--dsw-alias-bg-layer-1);
1182
+ color: var(--dsw-alias-label-primary);
1183
+ font-weight: 600;
1184
+ box-shadow: var(--dsw-elevation-subtle, none);
1185
+ }
1186
+ @media (max-width: 720px) {
1187
+ .dsh-cj-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
1188
+ }
1189
+ `
1190
+
1191
+ // Strip Codeup 24-char org id prefix from path_with_namespace for UI labels
1192
+ function shortRepoLabel(path) {
1193
+ const raw = String(path || '').trim()
1194
+ if (!raw) return ''
1195
+ const parts = raw.split('/').filter(Boolean)
1196
+ if (parts.length <= 1) return raw
1197
+ if (/^[a-f0-9]{24}$/i.test(parts[0])) return parts.slice(1).join('/') || raw
1198
+ return raw
1199
+ }
1200
+
1201
+ function fillMsg(tpl, vars) {
1202
+ return String(tpl || '').replace(/\{(\w+)\}/g, (_, k) => String(vars[k] ?? ''))
1203
+ }
1204
+
1205
+ function syncToastText(t, result) {
1206
+ const inserted = result && result.inserted != null ? result.inserted : 0
1207
+ const fetched = result && result.fetched != null ? result.fetched : 0
1208
+ const errN = result && result.errors ? result.errors.length : 0
1209
+ if (errN) return fillMsg(t('syncPartial'), { n: inserted, e: errN })
1210
+ return fillMsg(t('syncOk'), { n: inserted, f: fetched })
1211
+ }
1212
+
1213
+ async function api(path, options) {
1214
+ const res = await fetch(API + path, {
1215
+ headers: { 'Content-Type': 'application/json', ...(options && options.headers) },
1216
+ ...options
1217
+ })
1218
+ const text = await res.text()
1219
+ let data = null
1220
+ try { data = text ? JSON.parse(text) : null } catch { data = { error: text } }
1221
+ if (!res.ok) throw new Error((data && data.error) || res.statusText || 'request failed')
1222
+ return data
1223
+ }
1224
+
1225
+ function PageHead({ desc }) {
1226
+ if (!desc) return null
1227
+ return h('div', { className: 'dsh-cj-page-head' },
1228
+ h('p', { className: 'dsh-cj-page-desc' }, desc)
1229
+ )
1230
+ }
1231
+
1232
+ const PAGE_SIZE_OPTIONS = [10, 20, 50, 100]
1233
+
1234
+ function StatusTag({ tone, children }) {
1235
+ if (UiTag) return h(UiTag, { tone: tone || 'outline' }, children)
1236
+ return h('span', { className: 'dsh-cj-tag', 'data-tone': tone || 'outline' }, children)
1237
+ }
1238
+
1239
+ /**
1240
+ * 自定义下拉:弹出层挂到 portal / fixed,避免原生 select 撑出 App 容器
1241
+ */
1242
+ function SelectField({
1243
+ value,
1244
+ options,
1245
+ onChange,
1246
+ disabled,
1247
+ style,
1248
+ className,
1249
+ placeholder,
1250
+ onOpen,
1251
+ 'aria-label': ariaLabel,
1252
+ title
1253
+ }) {
1254
+ const [open, setOpen] = useState(false)
1255
+ const anchorRef = useRef(null)
1256
+ const menuRef = useRef(null)
1257
+ const [menuStyle, setMenuStyle] = useState(null)
1258
+ const list = options || []
1259
+ const selected = list.find((o) => String(o.value) === String(value))
1260
+ const label = selected ? selected.label : (placeholder || '')
1261
+
1262
+ const close = useCallback(() => setOpen(false), [])
1263
+
1264
+ const openMenu = useCallback(() => {
1265
+ if (disabled) return
1266
+ setOpen(true)
1267
+ if (onOpen) onOpen()
1268
+ }, [disabled, onOpen])
1269
+
1270
+ const pick = useCallback((next) => {
1271
+ onChange(next)
1272
+ setOpen(false)
1273
+ }, [onChange])
1274
+
1275
+ useEffect(() => {
1276
+ if (!open || UiMenu) return undefined
1277
+ const place = () => {
1278
+ const el = anchorRef.current
1279
+ if (!el) return
1280
+ const root = el.closest('.dsh-cj-root') || document.body
1281
+ const a = el.getBoundingClientRect()
1282
+ const bound = root.getBoundingClientRect()
1283
+ const width = Math.max(a.width, 120)
1284
+ const maxH = Math.min(280, Math.max(120, bound.height - 16))
1285
+ let left = Math.min(Math.max(a.left, bound.left + 8), bound.right - width - 8)
1286
+ let top = a.bottom + 4
1287
+ if (top + Math.min(maxH, list.length * 32 + 12) > bound.bottom - 8) {
1288
+ top = Math.max(bound.top + 8, a.top - 4 - Math.min(maxH, list.length * 32 + 12))
1289
+ }
1290
+ setMenuStyle({
1291
+ left: Math.round(left) + 'px',
1292
+ top: Math.round(top) + 'px',
1293
+ width: Math.round(width) + 'px',
1294
+ maxHeight: Math.round(maxH) + 'px'
1295
+ })
1296
+ }
1297
+ place()
1298
+ const onDoc = (e) => {
1299
+ const t = e.target
1300
+ if (anchorRef.current && anchorRef.current.contains(t)) return
1301
+ if (menuRef.current && menuRef.current.contains(t)) return
1302
+ close()
1303
+ }
1304
+ const onKey = (e) => { if (e.key === 'Escape') close() }
1305
+ window.addEventListener('resize', place)
1306
+ window.addEventListener('scroll', place, true)
1307
+ document.addEventListener('mousedown', onDoc, true)
1308
+ document.addEventListener('keydown', onKey, true)
1309
+ return () => {
1310
+ window.removeEventListener('resize', place)
1311
+ window.removeEventListener('scroll', place, true)
1312
+ document.removeEventListener('mousedown', onDoc, true)
1313
+ document.removeEventListener('keydown', onKey, true)
1314
+ }
1315
+ }, [close, list.length, open])
1316
+
1317
+ const trigger = h('button', {
1318
+ ref: anchorRef,
1319
+ type: 'button',
1320
+ className: ['dsh-cj-btn', 'dsh-cj-btn-sized', 'dsh-cj-control', 'dsh-cj-select-trigger', className].filter(Boolean).join(' '),
1321
+ style,
1322
+ disabled: !!disabled,
1323
+ title: title || ariaLabel || undefined,
1324
+ 'aria-label': ariaLabel,
1325
+ 'aria-expanded': open ? 'true' : 'false',
1326
+ 'aria-haspopup': 'listbox',
1327
+ onClick: () => { if (open) close(); else openMenu() }
1328
+ },
1329
+ h('span', { className: 'dsh-cj-select-label' }, label || '—'),
1330
+ h('span', { className: 'dsh-cj-select-caret', 'aria-hidden': true },
1331
+ IconChevronDown ? h(IconChevronDown) : '▾'
1332
+ )
1333
+ )
1334
+
1335
+ if (UiMenu) {
1336
+ const emptyId = '__dsh_cj_empty__'
1337
+ const toId = (v) => (v == null || v === '' ? emptyId : String(v))
1338
+ const fromId = (id) => {
1339
+ if (id === emptyId) {
1340
+ const hit = list.find((o) => o.value == null || o.value === '')
1341
+ return hit ? hit.value : ''
1342
+ }
1343
+ const hit = list.find((o) => String(o.value) === id)
1344
+ return hit ? hit.value : id
1345
+ }
1346
+ return h(UiMenu, {
1347
+ open,
1348
+ onClose: close,
1349
+ portal: true,
1350
+ minWidthFromAnchor: true,
1351
+ selection: 'check',
1352
+ selectedId: toId(value),
1353
+ items: list.map((o) => ({
1354
+ id: toId(o.value),
1355
+ label: o.label,
1356
+ disabled: !!o.disabled
1357
+ })),
1358
+ onSelect: (id) => { pick(fromId(id)) },
1359
+ anchor: h('span', {
1360
+ ref: anchorRef,
1361
+ className: 'dsh-cj-select-anchor',
1362
+ style: style && style.width === '100%'
1363
+ ? { display: 'block', width: '100%', maxWidth: '100%' }
1364
+ : { display: 'inline-flex', maxWidth: '100%' },
1365
+ onClick: (e) => {
1366
+ if (disabled) return
1367
+ e.preventDefault()
1368
+ if (open) close()
1369
+ else openMenu()
1370
+ }
1371
+ },
1372
+ h('button', {
1373
+ type: 'button',
1374
+ className: ['dsh-cj-btn', 'dsh-cj-btn-sized', 'dsh-cj-control', 'dsh-cj-select-trigger', className].filter(Boolean).join(' '),
1375
+ style,
1376
+ disabled: !!disabled,
1377
+ title: title || ariaLabel || undefined,
1378
+ 'aria-label': ariaLabel,
1379
+ 'aria-expanded': open ? 'true' : 'false',
1380
+ 'aria-haspopup': 'listbox'
1381
+ },
1382
+ h('span', { className: 'dsh-cj-select-label' }, label || '—'),
1383
+ h('span', { className: 'dsh-cj-select-caret', 'aria-hidden': true },
1384
+ IconChevronDown ? h(IconChevronDown) : '▾'
1385
+ )
1386
+ )
1387
+ )
1388
+ })
1389
+ }
1390
+
1391
+ const menu = open && menuStyle
1392
+ ? h('div', {
1393
+ ref: menuRef,
1394
+ className: 'dsh-cj-select-menu',
1395
+ role: 'listbox',
1396
+ style: menuStyle
1397
+ },
1398
+ list.map((o) =>
1399
+ h('button', {
1400
+ key: String(o.value),
1401
+ type: 'button',
1402
+ role: 'option',
1403
+ className: 'dsh-cj-select-option',
1404
+ disabled: !!o.disabled,
1405
+ 'data-selected': String(o.value) === String(value) ? '1' : '0',
1406
+ 'aria-selected': String(o.value) === String(value),
1407
+ onClick: () => pick(o.value)
1408
+ }, o.label)
1409
+ )
1410
+ )
1411
+ : null
1412
+
1413
+ return h(React.Fragment, null,
1414
+ trigger,
1415
+ menu && ReactDOM && ReactDOM.createPortal
1416
+ ? ReactDOM.createPortal(menu, document.body)
1417
+ : menu
1418
+ )
1419
+ }
1420
+
1421
+ /**
1422
+ * 表格底部分页:总数、每页条数、左右翻页
1423
+ */
1424
+ function TablePager({ t, total, page, pageSize, busy, onPageChange, onPageSizeChange }) {
1425
+ const totalPages = Math.max(1, Math.ceil((total || 0) / pageSize))
1426
+ const safePage = Math.min(Math.max(1, page || 1), totalPages)
1427
+ return h('div', { className: 'dsh-cj-pager' },
1428
+ h('span', { className: 'dsh-cj-pager-info' },
1429
+ fillMsg(t('totalItems'), { n: total || 0 }) + ' · ' + safePage + ' / ' + totalPages
1430
+ ),
1431
+ h('label', { className: 'dsh-cj-pager-size' },
1432
+ h(SelectField, {
1433
+ value: pageSize,
1434
+ disabled: busy,
1435
+ 'aria-label': t('pageSizeLabel'),
1436
+ style: { minWidth: 72 },
1437
+ options: PAGE_SIZE_OPTIONS.map((n) => ({ value: n, label: String(n) })),
1438
+ onChange: (n) => onPageSizeChange(Number(n))
1439
+ }),
1440
+ h('span', null, t('pageSizeLabel'))
1441
+ ),
1442
+ h(Btn, {
1443
+ disabled: busy || safePage <= 1,
1444
+ icon: IconChevronLeft ? h(IconChevronLeft) : null,
1445
+ onClick: () => onPageChange(safePage - 1)
1446
+ }, IconChevronLeft ? null : '‹'),
1447
+ h(Btn, {
1448
+ disabled: busy || safePage >= totalPages,
1449
+ icon: IconChevronRight ? h(IconChevronRight) : null,
1450
+ onClick: () => onPageChange(safePage + 1)
1451
+ }, IconChevronRight ? null : '›')
1452
+ )
1453
+ }
1454
+
1455
+ function logLevelTag(t, level) {
1456
+ const key = String(level || '').toLowerCase()
1457
+ if (key === 'error') return h(StatusTag, { tone: 'danger' }, t('levelError'))
1458
+ if (key === 'warn' || key === 'warning') return h(StatusTag, { tone: 'warning' }, t('levelWarn'))
1459
+ return h(StatusTag, { tone: 'info' }, t('levelInfo'))
1460
+ }
1461
+
1462
+ function Btn(props) {
1463
+ const { primary, danger, icon, children, className, ...rest } = props
1464
+ if (UiButton) {
1465
+ return h(UiButton, {
1466
+ type: 'button',
1467
+ variant: primary ? 'primary' : 'outline',
1468
+ size: 'sm',
1469
+ icon: icon || undefined,
1470
+ className: ['dsh-cj-btn-sized', danger ? 'dsh-cj-btn-danger' : '', className].filter(Boolean).join(' ') || undefined,
1471
+ ...rest
1472
+ }, children)
1473
+ }
1474
+ return h('button', {
1475
+ type: 'button',
1476
+ className: ['dsh-cj-btn', className].filter(Boolean).join(' '),
1477
+ 'data-primary': primary ? '1' : undefined,
1478
+ 'data-danger': danger ? '1' : undefined,
1479
+ ...rest
1480
+ }, icon || null, children)
1481
+ }
1482
+
1483
+ function FieldInput(props) {
1484
+ const { className, ...rest } = props
1485
+ // 不用官方 Input:其默认 border-l4 比侧栏「新会话」浅,且内部样式会盖过 className
1486
+ const merged = ['dsh-cj-input', 'dsh-cj-control', className].filter(Boolean).join(' ')
1487
+ return h('input', { className: merged, ...rest })
1488
+ }
1489
+
1490
+ function editionLabel(t, edition) {
1491
+ return edition === 'region' ? t('editionRegion') : t('editionCentral')
1492
+ }
1493
+
1494
+ function accountModeLabel(t, mode) {
1495
+ return mode === 'local' ? t('modeLocalShort') : t('modeRemoteShort')
1496
+ }
1497
+
1498
+ function providerLabel(t, provider) {
1499
+ if (provider === 'gitlab') return t('providerGitlab')
1500
+ if (provider === 'github') return t('providerGithub')
1501
+ if (provider === 'local') return t('modeLocalShort')
1502
+ return t('providerCodeup')
1503
+ }
1504
+
1505
+ function accountOrgCell(a) {
1506
+ if (a.mode === 'local') {
1507
+ const roots = a.localRoots || []
1508
+ if (!roots.length) return '-'
1509
+ return roots.length === 1 ? roots[0] : roots[0] + ' (+' + (roots.length - 1) + ')'
1510
+ }
1511
+ return a.organizationId || a.apiBaseUrl || '-'
1512
+ }
1513
+
1514
+ function remoteProviderFields(form, setForm, t, mode) {
1515
+ const provider = form.provider || 'codeup'
1516
+ const tokenPh =
1517
+ mode === 'edit'
1518
+ ? t('tokenPhEdit')
1519
+ : provider === 'github'
1520
+ ? t('tokenPhGithub')
1521
+ : provider === 'gitlab'
1522
+ ? t('tokenPhGitlab')
1523
+ : t('tokenPh')
1524
+
1525
+ const providerField = h('div', { className: 'dsh-cj-field' },
1526
+ h('label', { className: 'dsh-cj-label' }, t('provider')),
1527
+ h(SelectField, {
1528
+ value: provider,
1529
+ style: { width: '100%' },
1530
+ 'aria-label': t('provider'),
1531
+ options: [
1532
+ { value: 'codeup', label: t('providerCodeup') },
1533
+ { value: 'gitlab', label: t('providerGitlab') },
1534
+ { value: 'github', label: t('providerGithub') }
1535
+ ],
1536
+ onChange: (v) => setForm({ ...form, provider: v })
1537
+ })
1538
+ )
1539
+
1540
+ const tokenRow = h(React.Fragment, null,
1541
+ h('div', { className: 'dsh-cj-field dsh-cj-form-span' },
1542
+ h('label', { className: 'dsh-cj-label' }, t('token')),
1543
+ h(FieldInput, {
1544
+ type: 'password',
1545
+ value: form.token,
1546
+ placeholder: tokenPh,
1547
+ title: tokenPh,
1548
+ onChange: (e) => setForm({ ...form, token: e.target.value })
1549
+ })
1550
+ ),
1551
+ h('div', { className: 'dsh-cj-field dsh-cj-field-check dsh-cj-form-span' },
1552
+ h('label', { className: 'dsh-cj-label', title: t('insecureSslHint') },
1553
+ h('input', {
1554
+ type: 'checkbox',
1555
+ checked: !!form.insecureSsl,
1556
+ onChange: (e) => setForm({ ...form, insecureSsl: e.target.checked })
1557
+ }),
1558
+ t('insecureSsl')
1559
+ )
1560
+ )
1561
+ )
1562
+
1563
+ if (provider === 'gitlab' || provider === 'github') {
1564
+ return h(React.Fragment, null,
1565
+ h('div', { className: 'dsh-cj-form-row' },
1566
+ providerField,
1567
+ h('div', { className: 'dsh-cj-field' },
1568
+ h('label', { className: 'dsh-cj-label' },
1569
+ provider === 'github' ? t('orgIdLabelGithub') : t('orgIdLabelGitlab')
1570
+ ),
1571
+ h(FieldInput, {
1572
+ value: form.organizationId,
1573
+ placeholder: provider === 'github' ? t('orgIdPhGithub') : t('orgIdPhGitlab'),
1574
+ title: provider === 'github' ? t('orgIdPhGithub') : t('orgIdPhGitlab'),
1575
+ onChange: (e) => setForm({ ...form, organizationId: e.target.value })
1576
+ })
1577
+ )
1578
+ ),
1579
+ h('div', { className: 'dsh-cj-form-row' },
1580
+ h('div', { className: 'dsh-cj-field dsh-cj-form-span' },
1581
+ h('label', { className: 'dsh-cj-label' }, t('apiBase')),
1582
+ h(FieldInput, {
1583
+ value: form.apiBaseUrl,
1584
+ placeholder: provider === 'github' ? t('apiBasePhGithub') : t('apiBasePhGitlab'),
1585
+ title: provider === 'github' ? t('apiBaseHintGithub') : t('apiBaseHintGitlab'),
1586
+ onChange: (e) => setForm({ ...form, apiBaseUrl: e.target.value })
1587
+ })
1588
+ )
1589
+ ),
1590
+ h('div', { className: 'dsh-cj-form-row' }, tokenRow)
1591
+ )
1592
+ }
1593
+
1594
+ return h(React.Fragment, null,
1595
+ h('div', { className: 'dsh-cj-form-row' },
1596
+ providerField,
1597
+ h('div', { className: 'dsh-cj-field' },
1598
+ h('label', { className: 'dsh-cj-label' }, t('edition')),
1599
+ h(SelectField, {
1600
+ value: form.edition,
1601
+ style: { width: '100%' },
1602
+ 'aria-label': t('edition'),
1603
+ options: [
1604
+ { value: 'central', label: t('editionCentral') },
1605
+ { value: 'region', label: t('editionRegion') }
1606
+ ],
1607
+ onChange: (v) => setForm({ ...form, edition: v })
1608
+ })
1609
+ )
1610
+ ),
1611
+ h('div', { className: 'dsh-cj-form-row' },
1612
+ form.edition === 'central'
1613
+ ? h('div', { className: 'dsh-cj-field dsh-cj-form-span' },
1614
+ h('label', { className: 'dsh-cj-label' }, t('orgId')),
1615
+ h(FieldInput, {
1616
+ value: form.organizationId,
1617
+ placeholder: t('orgIdPh'),
1618
+ title: t('editionHintCentral'),
1619
+ onChange: (e) => setForm({ ...form, organizationId: e.target.value })
1620
+ })
1621
+ )
1622
+ : h('div', { className: 'dsh-cj-field dsh-cj-form-span' },
1623
+ h('label', { className: 'dsh-cj-label' }, t('apiBase')),
1624
+ h(FieldInput, {
1625
+ value: form.apiBaseUrl,
1626
+ placeholder: t('apiBasePh'),
1627
+ title: t('editionHintRegion'),
1628
+ onChange: (e) => setForm({ ...form, apiBaseUrl: e.target.value })
1629
+ })
1630
+ )
1631
+ ),
1632
+ h('div', { className: 'dsh-cj-form-row' }, tokenRow)
1633
+ )
1634
+ }
1635
+
1636
+ function AccountModal({ open, title, form, setForm, busy, onClose, onSave, t, mode }) {
1637
+ const isLocal = form.accountMode === 'local'
1638
+ const body = h('div', { className: 'dsh-cj-account-form' },
1639
+ h('div', { className: 'dsh-cj-form-row' },
1640
+ h('div', { className: 'dsh-cj-field' },
1641
+ h('label', { className: 'dsh-cj-label' }, t('name')),
1642
+ h(FieldInput, {
1643
+ value: form.name,
1644
+ placeholder: t('namePh'),
1645
+ onChange: (e) => setForm({ ...form, name: e.target.value }),
1646
+ 'data-modal-autofocus': true
1647
+ })
1648
+ ),
1649
+ h('div', { className: 'dsh-cj-field' },
1650
+ h('label', { className: 'dsh-cj-label' }, t('accountMode')),
1651
+ h(SelectField, {
1652
+ value: form.accountMode || 'remote',
1653
+ style: { width: '100%' },
1654
+ 'aria-label': t('accountMode'),
1655
+ title: isLocal ? t('modeHintLocal') : t('modeHintRemote'),
1656
+ options: [
1657
+ { value: 'remote', label: t('modeRemote') },
1658
+ { value: 'local', label: t('modeLocal') }
1659
+ ],
1660
+ onChange: (v) => setForm({ ...form, accountMode: v })
1661
+ })
1662
+ )
1663
+ ),
1664
+ isLocal
1665
+ ? h('div', { className: 'dsh-cj-form-row' },
1666
+ h('div', { className: 'dsh-cj-field dsh-cj-form-span' },
1667
+ h('label', { className: 'dsh-cj-label' }, t('localRoots')),
1668
+ h('textarea', {
1669
+ className: 'dsh-cj-textarea',
1670
+ rows: 3,
1671
+ value: form.localRootsText || '',
1672
+ placeholder: t('localRootsPh'),
1673
+ title: t('localRootsHint'),
1674
+ onChange: (e) => setForm({ ...form, localRootsText: e.target.value })
1675
+ })
1676
+ )
1677
+ )
1678
+ : remoteProviderFields(form, setForm, t, mode),
1679
+ h('div', { className: 'dsh-cj-form-row' },
1680
+ h('div', { className: 'dsh-cj-field' },
1681
+ h('label', { className: 'dsh-cj-label' }, t('authors')),
1682
+ h(FieldInput, {
1683
+ value: form.authorFilters,
1684
+ placeholder: t('authorsPh'),
1685
+ title: t('authorsHint'),
1686
+ onChange: (e) => setForm({ ...form, authorFilters: e.target.value })
1687
+ })
1688
+ ),
1689
+ h('div', { className: 'dsh-cj-field' },
1690
+ h('label', { className: 'dsh-cj-label' }, t('defaultBranch')),
1691
+ h(FieldInput, {
1692
+ value: form.defaultBranch,
1693
+ placeholder: t('defaultBranchPh'),
1694
+ onChange: (e) => setForm({ ...form, defaultBranch: e.target.value })
1695
+ })
1696
+ )
1697
+ )
1698
+ )
1699
+
1700
+ const footer = h(React.Fragment, null,
1701
+ h(Btn, { icon: IconClose ? h(IconClose) : null, onClick: onClose }, t('cancel')),
1702
+ h(Btn, { primary: true, disabled: busy, icon: IconSave ? h(IconSave) : null, onClick: onSave }, t('save'))
1703
+ )
1704
+
1705
+ if (UiModal) {
1706
+ return h(UiModal, {
1707
+ open: !!open,
1708
+ onClose,
1709
+ title,
1710
+ closeLabel: t('cancel'),
1711
+ footer,
1712
+ backdropBlur: true,
1713
+ className: 'dsh-cj-modal-wide'
1714
+ }, body)
1715
+ }
1716
+
1717
+ if (!open) return null
1718
+ return h('div', { className: 'dsh-cj-modal-mask', onClick: onClose },
1719
+ h('div', { className: 'dsh-cj-modal dsh-cj-modal-wide', onClick: (e) => e.stopPropagation() },
1720
+ h('h3', null, title),
1721
+ body,
1722
+ h('div', { className: 'dsh-cj-actions' }, footer)
1723
+ )
1724
+ )
1725
+ }
1726
+
1727
+ function PanelIcon(props) {
1728
+ return h('svg', {
1729
+ width: 18, height: 18, viewBox: '0 0 16 16', fill: 'currentColor', 'aria-hidden': true, ...props
1730
+ },
1731
+ h('rect', { x: 1, y: 1, width: 3, height: 3, rx: 0.5, opacity: 0.35 }),
1732
+ h('rect', { x: 5, y: 1, width: 3, height: 3, rx: 0.5, opacity: 0.55 }),
1733
+ h('rect', { x: 9, y: 1, width: 3, height: 3, rx: 0.5, opacity: 0.75 }),
1734
+ h('rect', { x: 13, y: 1, width: 2, height: 3, rx: 0.5, opacity: 1 }),
1735
+ h('rect', { x: 1, y: 5, width: 3, height: 3, rx: 0.5, opacity: 0.55 }),
1736
+ h('rect', { x: 5, y: 5, width: 3, height: 3, rx: 0.5, opacity: 1 }),
1737
+ h('rect', { x: 9, y: 5, width: 3, height: 3, rx: 0.5, opacity: 0.35 }),
1738
+ h('rect', { x: 13, y: 5, width: 2, height: 3, rx: 0.5, opacity: 0.75 }),
1739
+ h('rect', { x: 1, y: 9, width: 3, height: 3, rx: 0.5, opacity: 0.75 }),
1740
+ h('rect', { x: 5, y: 9, width: 3, height: 3, rx: 0.5, opacity: 0.35 }),
1741
+ h('rect', { x: 9, y: 9, width: 3, height: 3, rx: 0.5, opacity: 1 }),
1742
+ h('rect', { x: 13, y: 9, width: 2, height: 3, rx: 0.5, opacity: 0.55 })
1743
+ )
1744
+ }
1745
+
1746
+ function emptyForm() {
1747
+ return {
1748
+ name: '',
1749
+ accountMode: 'local',
1750
+ provider: 'codeup',
1751
+ edition: 'central',
1752
+ organizationId: '',
1753
+ apiBaseUrl: '',
1754
+ insecureSsl: false,
1755
+ localRootsText: '',
1756
+ token: '',
1757
+ authorFilters: '',
1758
+ defaultBranch: 'master'
1759
+ }
1760
+ }
1761
+
1762
+ function AccountsPage({ t, accounts, activeId, onChanged, busy, setBusy, notify }) {
1763
+ const [modal, setModal] = useState(null)
1764
+ const [form, setForm] = useState(emptyForm())
1765
+
1766
+ const openNew = () => { setForm(emptyForm()); setModal('new') }
1767
+ const openEdit = (a) => {
1768
+ setForm({
1769
+ id: a.id,
1770
+ name: a.name || '',
1771
+ accountMode: a.mode === 'local' ? 'local' : 'remote',
1772
+ provider: a.mode === 'local' ? 'local' : (a.provider || 'codeup'),
1773
+ edition: a.edition || 'central',
1774
+ organizationId: a.organizationId || '',
1775
+ apiBaseUrl: a.apiBaseUrl || '',
1776
+ insecureSsl: !!a.insecureSsl,
1777
+ localRootsText: (a.localRoots || []).join('\n'),
1778
+ token: '',
1779
+ authorFilters: (a.authorFilters || []).join(', '),
1780
+ defaultBranch: a.defaultBranch || 'master'
1781
+ })
1782
+ setModal('edit')
1783
+ }
1784
+
1785
+ const switchAccount = async (id) => {
1786
+ if (!id || id === activeId) return
1787
+ setBusy(true)
1788
+ try {
1789
+ await api('/api/accounts/' + encodeURIComponent(id) + '/activate', { method: 'POST', body: '{}' })
1790
+ await onChanged()
1791
+ notify(t('activateOk'), 'success')
1792
+ } catch (e) { notify(e.message || String(e), 'error') }
1793
+ finally { setBusy(false) }
1794
+ }
1795
+
1796
+ const save = async () => {
1797
+ setBusy(true)
1798
+ try {
1799
+ const isLocal = form.accountMode === 'local'
1800
+ const provider = isLocal ? 'local' : (form.provider || 'codeup')
1801
+ const payload = {
1802
+ name: form.name,
1803
+ mode: isLocal ? 'local' : 'remote',
1804
+ provider,
1805
+ edition: !isLocal && provider === 'codeup' ? form.edition : undefined,
1806
+ organizationId: isLocal ? undefined : form.organizationId,
1807
+ apiBaseUrl: isLocal ? undefined : form.apiBaseUrl,
1808
+ insecureSsl: isLocal ? undefined : !!form.insecureSsl,
1809
+ localRoots: isLocal
1810
+ ? String(form.localRootsText || '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean)
1811
+ : undefined,
1812
+ token: isLocal ? undefined : (form.token || undefined),
1813
+ authorFilters: form.authorFilters.split(/[,,]/).map((s) => s.trim()).filter(Boolean),
1814
+ defaultBranch: form.defaultBranch,
1815
+ setActive: true,
1816
+ test: true
1817
+ }
1818
+ if (modal === 'edit') {
1819
+ await api('/api/accounts/' + encodeURIComponent(form.id), {
1820
+ method: 'PATCH',
1821
+ body: JSON.stringify(payload)
1822
+ })
1823
+ } else {
1824
+ await api('/api/accounts', { method: 'POST', body: JSON.stringify(payload) })
1825
+ }
1826
+ setModal(null)
1827
+ await onChanged()
1828
+ notify(t('saveOk'), 'success')
1829
+ } catch (e) { notify(e.message || String(e), 'error') }
1830
+ finally { setBusy(false) }
1831
+ }
1832
+
1833
+ return h('div', { className: 'dsh-cj-page-scroll' },
1834
+ h(PageHead, { desc: t('descAccounts') }),
1835
+ h('div', { className: 'dsh-cj-row dsh-cj-row-end' },
1836
+ accounts.length
1837
+ ? h('div', { className: 'dsh-cj-actions' },
1838
+ h('span', { className: 'dsh-cj-muted' }, t('currentAccount')),
1839
+ h(SelectField, {
1840
+ style: { minWidth: 180 },
1841
+ value: activeId || '',
1842
+ disabled: busy || accounts.length < 2,
1843
+ 'aria-label': t('switchAccount'),
1844
+ placeholder: t('switchAccount'),
1845
+ options: accounts.map((a) => ({
1846
+ value: a.id,
1847
+ label: (a.name || a.id) + ' · ' + accountModeLabel(t, a.mode)
1848
+ })),
1849
+ onChange: (id) => { void switchAccount(id) }
1850
+ })
1851
+ )
1852
+ : h('div', { className: 'dsh-cj-muted' }, t('emptyAccount')),
1853
+ h(Btn, { primary: true, icon: IconPlus ? h(IconPlus) : null, onClick: openNew }, t('newAccount'))
1854
+ ),
1855
+ h('div', { className: 'dsh-cj-table-wrap' },
1856
+ h('table', { className: 'dsh-cj-table' },
1857
+ h('thead', null, h('tr', null,
1858
+ h('th', null, t('name')),
1859
+ h('th', null, t('accountMode')),
1860
+ h('th', null, t('provider')),
1861
+ h('th', null, t('org')),
1862
+ h('th', null, t('authors')),
1863
+ h('th', null, '')
1864
+ )),
1865
+ h('tbody', null, accounts.map((a) =>
1866
+ h('tr', { key: a.id },
1867
+ h('td', null,
1868
+ a.name, ' ',
1869
+ a.active ? h(StatusTag, { tone: 'solid' }, t('active')) : null
1870
+ ),
1871
+ h('td', null, accountModeLabel(t, a.mode)),
1872
+ h('td', { className: 'dsh-cj-td-clip', title: a.mode === 'local' ? undefined : providerLabel(t, a.provider) },
1873
+ a.mode === 'local' ? '-' : providerLabel(t, a.provider)
1874
+ ),
1875
+ h('td', {
1876
+ className: 'dsh-cj-td-clip',
1877
+ title: a.mode === 'local' ? (a.localRoots || []).join('\n') : (a.organizationId || a.apiBaseUrl || '')
1878
+ }, accountOrgCell(a)),
1879
+ h('td', {
1880
+ className: 'dsh-cj-td-clip',
1881
+ title: (a.authorFilters || []).join(', ') || undefined
1882
+ }, (a.authorFilters || []).join(', ') || '-'),
1883
+ h('td', { className: 'dsh-cj-td-actions' },
1884
+ h('div', { className: 'dsh-cj-actions' },
1885
+ !a.active && h(Btn, {
1886
+ className: 'dsh-cj-btn-icon',
1887
+ disabled: busy,
1888
+ title: t('activate'),
1889
+ 'aria-label': t('activate'),
1890
+ icon: IconCheck ? h(IconCheck) : null,
1891
+ onClick: () => { void switchAccount(a.id) }
1892
+ }, IconCheck ? null : t('activate')),
1893
+ h(Btn, {
1894
+ className: 'dsh-cj-btn-icon',
1895
+ disabled: busy,
1896
+ title: a.mode === 'local' ? t('testScan') : t('test'),
1897
+ 'aria-label': a.mode === 'local' ? t('testScan') : t('test'),
1898
+ // 远程测连用地球;本地扫描用搜索,避免纯图标时语义混淆
1899
+ icon: a.mode === 'local'
1900
+ ? (IconSearch ? h(IconSearch) : null)
1901
+ : (IconGlobe ? h(IconGlobe) : null),
1902
+ onClick: async () => {
1903
+ setBusy(true)
1904
+ try {
1905
+ const res = await api(
1906
+ '/api/accounts/' + encodeURIComponent(a.id) + '/test',
1907
+ { method: 'POST', body: '{}' }
1908
+ )
1909
+ if (a.mode === 'local') {
1910
+ notify(fillMsg(t('testScanOk'), { n: res.repoCount || 0 }), 'success')
1911
+ } else {
1912
+ notify(t('testOk'), 'success')
1913
+ }
1914
+ } catch (e) { notify(e.message || String(e), 'error') }
1915
+ finally { setBusy(false) }
1916
+ }
1917
+ }, (a.mode === 'local' ? IconSearch : IconGlobe)
1918
+ ? null
1919
+ : (a.mode === 'local' ? t('testScan') : t('test'))),
1920
+ h(Btn, {
1921
+ className: 'dsh-cj-btn-icon',
1922
+ title: t('edit'),
1923
+ 'aria-label': t('edit'),
1924
+ icon: IconEdit ? h(IconEdit) : null,
1925
+ onClick: () => openEdit(a)
1926
+ }, IconEdit ? null : t('edit')),
1927
+ h(Btn, {
1928
+ className: 'dsh-cj-btn-icon',
1929
+ danger: true, disabled: busy,
1930
+ title: t('remove'),
1931
+ 'aria-label': t('remove'),
1932
+ icon: IconTrash ? h(IconTrash) : null,
1933
+ onClick: async () => {
1934
+ if (!confirm(t('confirmDelete'))) return
1935
+ setBusy(true)
1936
+ try {
1937
+ await api('/api/accounts/' + encodeURIComponent(a.id), { method: 'DELETE' })
1938
+ await onChanged()
1939
+ notify(t('clearOk'), 'success')
1940
+ } catch (e) { notify(e.message || String(e), 'error') }
1941
+ finally { setBusy(false) }
1942
+ }
1943
+ }, IconTrash ? null : t('remove'))
1944
+ )
1945
+ )
1946
+ )
1947
+ ))
1948
+ )
1949
+ ),
1950
+ h(AccountModal, {
1951
+ open: !!modal,
1952
+ mode: modal,
1953
+ title: modal === 'edit' ? t('edit') : t('newAccount'),
1954
+ form, setForm, busy, t,
1955
+ onClose: () => setModal(null),
1956
+ onSave: save
1957
+ })
1958
+ )
1959
+ }
1960
+
1961
+ function BranchSelect({ accountId, repo, value, onChange, notify, t }) {
1962
+ const [options, setOptions] = useState([])
1963
+ const [loading, setLoading] = useState(false)
1964
+ const loaded = React.useRef(false)
1965
+ const fallback = repo.defaultBranch || 'master'
1966
+
1967
+ const ensureLoaded = async () => {
1968
+ if (loaded.current || loading) return
1969
+ setLoading(true)
1970
+ try {
1971
+ const data = await api(
1972
+ '/api/repo-branches?accountId=' +
1973
+ encodeURIComponent(accountId) +
1974
+ '&repoId=' +
1975
+ encodeURIComponent(repo.id)
1976
+ )
1977
+ const names = (data.branches || []).map((b) => b.name).filter(Boolean)
1978
+ if (fallback && !names.includes(fallback)) names.unshift(fallback)
1979
+ setOptions(names)
1980
+ loaded.current = true
1981
+ } catch (e) {
1982
+ if (!options.length) setOptions(fallback ? [fallback] : [])
1983
+ notify(e.message || String(e), 'error')
1984
+ } finally { setLoading(false) }
1985
+ }
1986
+
1987
+ useEffect(() => {
1988
+ loaded.current = false
1989
+ setOptions(fallback ? [fallback] : [])
1990
+ }, [repo.id, fallback])
1991
+
1992
+ const current = value || fallback
1993
+ const list = options.includes(current) ? options : (current ? [current].concat(options) : options)
1994
+
1995
+ return h(SelectField, {
1996
+ style: { width: 160 },
1997
+ value: current,
1998
+ disabled: loading,
1999
+ title: loading ? '…' : t('branch'),
2000
+ 'aria-label': t('branch'),
2001
+ onOpen: () => { ensureLoaded().catch(() => {}) },
2002
+ options: list.map((name) => ({
2003
+ value: name,
2004
+ label: name === fallback ? (name + ' (' + t('defaultBranch') + ')') : name
2005
+ })),
2006
+ onChange: (v) => onChange(v === fallback ? '' : v)
2007
+ })
2008
+ }
2009
+
2010
+ function WatchFilter({ t, value, onChange }) {
2011
+ const options = [
2012
+ { value: 'watched', label: t('filterWatched') },
2013
+ { value: 'unwatched', label: t('filterUnwatched') },
2014
+ { value: 'all', label: t('filterAll') }
2015
+ ]
2016
+ if (UiSeg) {
2017
+ return h(UiSeg, {
2018
+ id: 'dsh-cj-watch-filter',
2019
+ label: t('watched'),
2020
+ value,
2021
+ options,
2022
+ onChange
2023
+ })
2024
+ }
2025
+ return h('div', { className: 'dsh-cj-seg', role: 'tablist' },
2026
+ options.map((o) =>
2027
+ h('button', {
2028
+ key: o.value,
2029
+ type: 'button',
2030
+ 'data-active': value === o.value ? '1' : '0',
2031
+ onClick: () => { if (value !== o.value) onChange(o.value) }
2032
+ }, o.label)
2033
+ )
2034
+ )
2035
+ }
2036
+
2037
+ function ReposPage({ t, accountId, accountMode, busy, setBusy, notify }) {
2038
+ const [repos, setRepos] = useState([])
2039
+ const [watched, setWatched] = useState([])
2040
+ const [branches, setBranches] = useState({})
2041
+ const [keyword, setKeyword] = useState('')
2042
+ const [watchFilter, setWatchFilter] = useState('watched')
2043
+ const [page, setPage] = useState(1)
2044
+ const [pageSize, setPageSize] = useState(10)
2045
+ const isLocal = accountMode === 'local'
2046
+
2047
+ const load = useCallback(async () => {
2048
+ if (!accountId) return
2049
+ const data = await api('/api/repos?accountId=' + encodeURIComponent(accountId))
2050
+ setRepos(data.repos || [])
2051
+ setWatched(data.watchedRepoIds || [])
2052
+ setBranches(data.repoBranches || {})
2053
+ }, [accountId])
2054
+
2055
+ useEffect(() => { load().catch((e) => notify(e.message || String(e), 'error')) }, [load, notify])
2056
+ useEffect(() => { setPage(1) }, [keyword, watchFilter, accountId, pageSize])
2057
+
2058
+ const allMode = watched.length === 0
2059
+ const isWatched = useCallback((id) => allMode || watched.includes(id), [allMode, watched])
2060
+
2061
+ const filtered = useMemo(() => {
2062
+ const q = keyword.trim().toLowerCase()
2063
+ return repos.filter((r) => {
2064
+ const watchedNow = isWatched(r.id)
2065
+ if (watchFilter === 'watched' && !watchedNow) return false
2066
+ if (watchFilter === 'unwatched' && watchedNow) return false
2067
+ if (!q) return true
2068
+ const label = shortRepoLabel(r.displayName || r.fullName || r.name).toLowerCase()
2069
+ return label.includes(q) || String(r.name || '').toLowerCase().includes(q)
2070
+ })
2071
+ }, [repos, keyword, watchFilter, isWatched])
2072
+
2073
+ const totalPages = Math.max(1, Math.ceil(filtered.length / pageSize))
2074
+ const safePage = Math.min(page, totalPages)
2075
+ const pageRepos = filtered.slice((safePage - 1) * pageSize, safePage * pageSize)
2076
+
2077
+ if (!accountId) {
2078
+ return h('div', { className: 'dsh-cj-page-fill' },
2079
+ h(PageHead, { desc: t('descRepos') }),
2080
+ h('p', { className: 'dsh-cj-muted' }, t('emptyAccount'))
2081
+ )
2082
+ }
2083
+
2084
+ return h('div', { className: 'dsh-cj-page-fill' },
2085
+ h(PageHead, { desc: isLocal ? t('descReposLocal') : t('descRepos') }),
2086
+ h('div', { className: 'dsh-cj-row' },
2087
+ h(WatchFilter, { t, value: watchFilter, onChange: setWatchFilter }),
2088
+ h(FieldInput, {
2089
+ style: { width: 180 },
2090
+ icon: IconSearch ? h(IconSearch) : undefined,
2091
+ placeholder: t('repoKeyword'),
2092
+ value: keyword,
2093
+ onChange: (e) => setKeyword(e.target.value)
2094
+ }),
2095
+ h('div', { className: 'dsh-cj-actions' },
2096
+ h(Btn, {
2097
+ disabled: busy,
2098
+ icon: IconRefresh ? h(IconRefresh) : null,
2099
+ onClick: async () => {
2100
+ setBusy(true)
2101
+ try {
2102
+ await api('/api/repos/refresh', { method: 'POST', body: JSON.stringify({ accountId }) })
2103
+ await load()
2104
+ notify(isLocal ? t('refreshScanOk') : t('refreshOk'), 'success')
2105
+ } catch (e) { notify(e.message || String(e), 'error') }
2106
+ finally { setBusy(false) }
2107
+ }
2108
+ }, isLocal ? t('refreshScan') : t('refresh')),
2109
+ h(Btn, {
2110
+ disabled: busy,
2111
+ icon: IconSave ? h(IconSave) : null,
2112
+ onClick: async () => {
2113
+ setBusy(true)
2114
+ try {
2115
+ await api('/api/repos/watch', {
2116
+ method: 'PUT',
2117
+ body: JSON.stringify({ accountId, watchedRepoIds: watched, repoBranches: branches })
2118
+ })
2119
+ await load()
2120
+ notify(t('saveWatchOk'), 'success')
2121
+ } catch (e) { notify(e.message || String(e), 'error') }
2122
+ finally { setBusy(false) }
2123
+ }
2124
+ }, t('saveWatch')),
2125
+ h(Btn, {
2126
+ primary: true, disabled: busy,
2127
+ icon: IconDownload ? h(IconDownload) : null,
2128
+ onClick: async () => {
2129
+ setBusy(true)
2130
+ try {
2131
+ const result = await api('/api/sync', { method: 'POST', body: JSON.stringify({ accountId }) })
2132
+ notify(syncToastText(t, result), (result.errors && result.errors.length) ? 'error' : 'success')
2133
+ } catch (e) { notify(e.message || String(e), 'error') }
2134
+ finally { setBusy(false) }
2135
+ }
2136
+ }, isLocal ? t('syncWatchedLocal') : t('syncWatched'))
2137
+ )
2138
+ ),
2139
+ h('div', { className: 'dsh-cj-table-wrap' },
2140
+ h('table', { className: 'dsh-cj-table' },
2141
+ h('thead', null, h('tr', null,
2142
+ h('th', null, t('watched')),
2143
+ h('th', null, t('repo')),
2144
+ h('th', null, t('branch')),
2145
+ h('th', null, '')
2146
+ )),
2147
+ h('tbody', null, pageRepos.map((r) => {
2148
+ const checked = isWatched(r.id)
2149
+ return h('tr', { key: r.id },
2150
+ h('td', null,
2151
+ h('input', {
2152
+ type: 'checkbox',
2153
+ checked,
2154
+ onChange: (e) => {
2155
+ if (allMode) {
2156
+ if (!e.target.checked) setWatched(repos.map((x) => x.id).filter((id) => id !== r.id))
2157
+ } else if (e.target.checked) setWatched(watched.concat([r.id]))
2158
+ else setWatched(watched.filter((id) => id !== r.id))
2159
+ }
2160
+ })
2161
+ ),
2162
+ h('td', null, shortRepoLabel(r.displayName || r.fullName || r.name)),
2163
+ h('td', null,
2164
+ h(BranchSelect, {
2165
+ accountId,
2166
+ repo: r,
2167
+ t,
2168
+ notify,
2169
+ value: branches[r.id] || '',
2170
+ onChange: (next) => {
2171
+ const nextMap = { ...branches }
2172
+ if (!next) delete nextMap[r.id]
2173
+ else nextMap[r.id] = next
2174
+ setBranches(nextMap)
2175
+ }
2176
+ })
2177
+ ),
2178
+ h('td', null,
2179
+ h('div', { className: 'dsh-cj-actions' },
2180
+ h(Btn, {
2181
+ disabled: busy,
2182
+ icon: IconDownload ? h(IconDownload) : null,
2183
+ onClick: async () => {
2184
+ setBusy(true)
2185
+ try {
2186
+ const result = await api('/api/sync', {
2187
+ method: 'POST',
2188
+ body: JSON.stringify({ accountId, repoIds: [r.id] })
2189
+ })
2190
+ notify(syncToastText(t, result), (result.errors && result.errors.length) ? 'error' : 'success')
2191
+ } catch (e) { notify(e.message || String(e), 'error') }
2192
+ finally { setBusy(false) }
2193
+ }
2194
+ }, t('sync')),
2195
+ r.webUrl
2196
+ ? h(Btn, {
2197
+ icon: IconLink ? h(IconLink) : null,
2198
+ onClick: () => {
2199
+ try { window.open(r.webUrl, '_blank', 'noopener,noreferrer') } catch { /* ignore */ }
2200
+ }
2201
+ }, t('openRepo'))
2202
+ : null
2203
+ )
2204
+ )
2205
+ )
2206
+ }))
2207
+ )
2208
+ ),
2209
+ h(TablePager, {
2210
+ t,
2211
+ total: filtered.length,
2212
+ page: safePage,
2213
+ pageSize,
2214
+ busy,
2215
+ onPageChange: setPage,
2216
+ onPageSizeChange: (size) => { setPageSize(size); setPage(1) }
2217
+ })
2218
+ )
2219
+ }
2220
+
2221
+ function CommitsPage({ t, accountId, busy, setBusy, notify }) {
2222
+ const [repos, setRepos] = useState([])
2223
+ const [items, setItems] = useState([])
2224
+ const [total, setTotal] = useState(0)
2225
+ const [repoId, setRepoId] = useState('')
2226
+ const [from, setFrom] = useState('')
2227
+ const [to, setTo] = useState('')
2228
+ const [keyword, setKeyword] = useState('')
2229
+ const [page, setPage] = useState(1)
2230
+ const [pageSize, setPageSize] = useState(10)
2231
+
2232
+ const load = useCallback(async (nextPage, nextSize) => {
2233
+ if (!accountId) return
2234
+ const size = nextSize || pageSize
2235
+ const p = nextPage || page
2236
+ const q = new URLSearchParams({
2237
+ accountId,
2238
+ limit: String(size),
2239
+ offset: String((p - 1) * size)
2240
+ })
2241
+ if (repoId) q.set('repoId', repoId)
2242
+ if (from) q.set('from', from + 'T00:00:00.000Z')
2243
+ if (to) q.set('to', to + 'T23:59:59.999Z')
2244
+ if (keyword.trim()) q.set('keyword', keyword.trim())
2245
+ const [commits, repoData] = await Promise.all([
2246
+ api('/api/commits?' + q.toString()),
2247
+ api('/api/repos?accountId=' + encodeURIComponent(accountId) + '&withCommitsOnly=1')
2248
+ ])
2249
+ setItems(commits.items || [])
2250
+ setTotal(commits.total || 0)
2251
+ setRepos(repoData.repos || [])
2252
+ setPage(p)
2253
+ if (nextSize) setPageSize(size)
2254
+ }, [accountId, from, keyword, page, pageSize, repoId, to])
2255
+
2256
+ useEffect(() => {
2257
+ if (!accountId) return
2258
+ load(1).catch((e) => notify(e.message || String(e), 'error'))
2259
+ }, [accountId]) // eslint-disable-line
2260
+
2261
+ if (!accountId) {
2262
+ return h('div', { className: 'dsh-cj-page-fill' },
2263
+ h(PageHead, { desc: t('descCommits') }),
2264
+ h('p', { className: 'dsh-cj-muted' }, t('emptyAccount'))
2265
+ )
2266
+ }
2267
+
2268
+ return h('div', { className: 'dsh-cj-page-fill' },
2269
+ h(PageHead, { desc: t('descCommits') }),
2270
+ h('div', { className: 'dsh-cj-row' },
2271
+ h(SelectField, {
2272
+ value: repoId,
2273
+ style: { minWidth: 180 },
2274
+ 'aria-label': t('repo'),
2275
+ options: [{ value: '', label: t('allRepos') }].concat(
2276
+ repos.map((r) => ({
2277
+ value: r.id,
2278
+ label: shortRepoLabel(r.displayName || r.fullName || r.name)
2279
+ }))
2280
+ ),
2281
+ onChange: setRepoId
2282
+ }),
2283
+ h(FieldInput, {
2284
+ type: 'date',
2285
+ style: { minWidth: 140 },
2286
+ value: from,
2287
+ onChange: (e) => setFrom(e.target.value),
2288
+ title: t('from'),
2289
+ 'aria-label': t('from')
2290
+ }),
2291
+ h(FieldInput, {
2292
+ type: 'date',
2293
+ style: { minWidth: 140 },
2294
+ value: to,
2295
+ onChange: (e) => setTo(e.target.value),
2296
+ title: t('to'),
2297
+ 'aria-label': t('to')
2298
+ }),
2299
+ h(FieldInput, {
2300
+ style: { minWidth: 160 },
2301
+ placeholder: t('keyword'),
2302
+ value: keyword,
2303
+ onChange: (e) => setKeyword(e.target.value),
2304
+ 'aria-label': t('keyword')
2305
+ }),
2306
+ h(Btn, {
2307
+ primary: true, disabled: busy,
2308
+ icon: IconSearch ? h(IconSearch) : null,
2309
+ onClick: () => {
2310
+ setBusy(true)
2311
+ load(1)
2312
+ .then(() => notify(t('queryOk'), 'success'))
2313
+ .catch((e) => notify(e.message || String(e), 'error'))
2314
+ .finally(() => setBusy(false))
2315
+ }
2316
+ }, t('query')),
2317
+ h(Btn, {
2318
+ danger: true, disabled: busy,
2319
+ icon: IconTrash ? h(IconTrash) : null,
2320
+ onClick: async () => {
2321
+ if (!confirm(t('confirmClearCommits'))) return
2322
+ setBusy(true)
2323
+ try {
2324
+ await api('/api/commits/clear', { method: 'POST', body: JSON.stringify({ accountId }) })
2325
+ await load(1)
2326
+ notify(t('clearOk'), 'success')
2327
+ } catch (e) { notify(e.message || String(e), 'error') }
2328
+ finally { setBusy(false) }
2329
+ }
2330
+ }, t('clearCommits'))
2331
+ ),
2332
+ h('div', { className: 'dsh-cj-table-wrap' },
2333
+ h('table', { className: 'dsh-cj-table' },
2334
+ h('thead', null, h('tr', null,
2335
+ h('th', null, t('time')), h('th', null, t('repo')), h('th', null, t('title')),
2336
+ h('th', null, t('author')), h('th', null, t('sha'))
2337
+ )),
2338
+ h('tbody', null, items.map((c) =>
2339
+ h('tr', { key: c.id },
2340
+ h('td', null, (c.committedAt || '').slice(0, 16).replace('T', ' ')),
2341
+ h('td', null, shortRepoLabel(c.repoName)),
2342
+ h('td', null, c.title),
2343
+ h('td', null, c.authorName),
2344
+ h('td', null,
2345
+ c.webUrl
2346
+ ? h('a', { className: 'dsh-cj-link', href: c.webUrl, target: '_blank', rel: 'noreferrer' }, c.shortId)
2347
+ : c.shortId
2348
+ )
2349
+ )
2350
+ ))
2351
+ )
2352
+ ),
2353
+ h(TablePager, {
2354
+ t,
2355
+ total,
2356
+ page,
2357
+ pageSize,
2358
+ busy,
2359
+ onPageChange: (p) => {
2360
+ setBusy(true)
2361
+ load(p).catch((e) => notify(e.message || String(e), 'error')).finally(() => setBusy(false))
2362
+ },
2363
+ onPageSizeChange: (size) => {
2364
+ setBusy(true)
2365
+ load(1, size).catch((e) => notify(e.message || String(e), 'error')).finally(() => setBusy(false))
2366
+ }
2367
+ })
2368
+ )
2369
+ }
2370
+
2371
+ function formatDayTitle(iso) {
2372
+ const d = new Date(iso + 'T12:00:00')
2373
+ if (Number.isNaN(d.getTime())) return iso
2374
+ const wd = ['日', '一', '二', '三', '四', '五', '六'][d.getDay()]
2375
+ return (d.getMonth() + 1) + ' 月 ' + d.getDate() + ' 日 周' + wd
2376
+ }
2377
+
2378
+ function ActivityPage({ t, accountId, notify }) {
2379
+ const [year, setYear] = useState(0)
2380
+ const [years, setYears] = useState([])
2381
+ const [data, setData] = useState(null)
2382
+ const [day, setDay] = useState(null)
2383
+ const [dayItems, setDayItems] = useState([])
2384
+ const [dayLoading, setDayLoading] = useState(false)
2385
+ const weekLabels = ['一', '二', '三', '四', '五', '六', '日']
2386
+ const dayReq = React.useRef(0)
2387
+
2388
+ useEffect(() => {
2389
+ setYear(0)
2390
+ setData(null)
2391
+ setYears([])
2392
+ setDay(null)
2393
+ setDayItems([])
2394
+ }, [accountId])
2395
+
2396
+ useEffect(() => {
2397
+ if (!accountId) return
2398
+ const q = new URLSearchParams({ accountId })
2399
+ if (year) q.set('year', String(year))
2400
+ api('/api/activity?' + q.toString())
2401
+ .then((d) => {
2402
+ setData(d)
2403
+ setYears(d.years || [])
2404
+ setDay(null)
2405
+ setDayItems([])
2406
+ })
2407
+ .catch((e) => notify(e.message || String(e), 'error'))
2408
+ }, [accountId, year, notify])
2409
+
2410
+ const openDay = async (date) => {
2411
+ const reqId = ++dayReq.current
2412
+ setDay(date)
2413
+ setDayItems([])
2414
+ setDayLoading(true)
2415
+ try {
2416
+ const r = await api('/api/activity/day?accountId=' + encodeURIComponent(accountId) + '&date=' + encodeURIComponent(date))
2417
+ if (dayReq.current === reqId) setDayItems(r.commits || [])
2418
+ } catch (e) {
2419
+ if (dayReq.current === reqId) {
2420
+ setDayItems([])
2421
+ notify(e.message || String(e), 'error')
2422
+ }
2423
+ } finally {
2424
+ if (dayReq.current === reqId) setDayLoading(false)
2425
+ }
2426
+ }
2427
+
2428
+ const heatmap = useMemo(() => {
2429
+ if (!data) return null
2430
+ const fromDay = new Date(data.from + 'T00:00:00')
2431
+ const toDay = new Date(data.to + 'T00:00:00')
2432
+ const mondayOffset = (fromDay.getDay() + 6) % 7
2433
+ const gridStart = new Date(fromDay); gridStart.setDate(fromDay.getDate() - mondayOffset)
2434
+ const endPad = (7 - ((toDay.getDay() + 6) % 7) - 1 + 7) % 7
2435
+ const gridEnd = new Date(toDay); gridEnd.setDate(toDay.getDate() + endPad)
2436
+ const totalDays = Math.round((gridEnd - gridStart) / 86400000) + 1
2437
+ const weeks = Math.ceil(totalDays / 7)
2438
+ const countByDay = new Map((data.days || []).map((d) => [d.date, d.count]))
2439
+ const step = Math.max(1, Math.ceil((data.stats.maxDayCount || 1) / 4))
2440
+ const now = new Date()
2441
+ const todayKey = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0')
2442
+ const cells = []
2443
+ const weekdayCounts = [0, 0, 0, 0, 0, 0, 0]
2444
+ for (let i = 0; i < weeks * 7; i++) {
2445
+ const d = new Date(gridStart); d.setDate(gridStart.getDate() + i)
2446
+ const key = d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
2447
+ const inRange = d >= fromDay && d <= toDay
2448
+ const count = inRange ? (countByDay.get(key) || 0) : 0
2449
+ const level = count <= 0 ? 0 : Math.min(4, Math.ceil(count / step))
2450
+ if (inRange && count > 0) weekdayCounts[(d.getDay() + 6) % 7] += count
2451
+ cells.push({ key, count, inRange, level, isToday: key === todayKey })
2452
+ }
2453
+ // Sparse month labels like the desktop reference (avoid crowding near the end)
2454
+ const monthLabels = []
2455
+ let lastLabelWeek = -4
2456
+ let prevMonth = -1
2457
+ for (let w = 0; w < weeks; w++) {
2458
+ const d = new Date(gridStart); d.setDate(gridStart.getDate() + w * 7)
2459
+ if (d < fromDay) continue
2460
+ if (d.getMonth() === prevMonth) continue
2461
+ prevMonth = d.getMonth()
2462
+ if (w - lastLabelWeek < 3 || w > weeks - 4) continue
2463
+ monthLabels.push({ column: w + 1, text: (d.getMonth() + 1) + '月' })
2464
+ lastLabelWeek = w
2465
+ }
2466
+ let currentStreak = 0
2467
+ for (let cur = new Date(Math.min(toDay.getTime(), Date.now())); cur >= fromDay; cur.setDate(cur.getDate() - 1)) {
2468
+ const key = cur.getFullYear() + '-' + String(cur.getMonth() + 1).padStart(2, '0') + '-' + String(cur.getDate()).padStart(2, '0')
2469
+ if ((countByDay.get(key) || 0) > 0) currentStreak++
2470
+ else break
2471
+ }
2472
+ const avg = data.stats.activeDays
2473
+ ? Math.round((data.stats.totalCommits / data.stats.activeDays) * 10) / 10
2474
+ : 0
2475
+ const wdMax = Math.max(1, ...weekdayCounts)
2476
+ return { weeks, cells, monthLabels, weekdayCounts, wdMax, currentStreak, avg }
2477
+ }, [data])
2478
+
2479
+ if (!accountId) {
2480
+ return h('div', { className: 'dsh-cj-page-scroll' },
2481
+ h(PageHead, { desc: t('descActivity') }),
2482
+ h('p', { className: 'dsh-cj-muted' }, t('emptyAccount'))
2483
+ )
2484
+ }
2485
+ if (!data) {
2486
+ return h('div', { className: 'dsh-cj-page-scroll' },
2487
+ h(PageHead, { desc: t('descActivity') }),
2488
+ h('p', { className: 'dsh-cj-muted' }, '…')
2489
+ )
2490
+ }
2491
+ if (!data.stats.totalCommits) {
2492
+ return h('div', { className: 'dsh-cj-page-scroll' },
2493
+ h(PageHead, { desc: t('descActivity') }),
2494
+ h('div', { className: 'dsh-cj-row dsh-cj-row-end' },
2495
+ h('span'),
2496
+ h(SelectField, {
2497
+ value: year,
2498
+ 'aria-label': t('recentYear'),
2499
+ options: [{ value: 0, label: t('recentYear') }].concat(
2500
+ years.map((y) => ({ value: y, label: y + ' 年' }))
2501
+ ),
2502
+ onChange: (v) => { setData(null); setYear(Number(v)) }
2503
+ })
2504
+ ),
2505
+ h('p', { className: 'dsh-cj-muted' }, t('noData')),
2506
+ h('p', { className: 'dsh-cj-footnote' }, t('activityFootnote'))
2507
+ )
2508
+ }
2509
+
2510
+ const stats = data.stats
2511
+
2512
+ return h('div', { className: 'dsh-cj-page-scroll' },
2513
+ // h(PageHead, {
2514
+ // desc: (year ? (year + ' 年提交活跃度') : t('descActivity')) + ' · ' + data.from + ' ~ ' + data.to
2515
+ // }),
2516
+ h('div', { className: 'dsh-cj-row dsh-cj-row-end' },
2517
+ h('span', { className: 'dsh-cj-muted' }, t('heatHint')),
2518
+ h(SelectField, {
2519
+ value: year,
2520
+ 'aria-label': t('recentYear'),
2521
+ options: [{ value: 0, label: t('recentYear') }].concat(
2522
+ years.map((y) => ({ value: y, label: y + ' 年' }))
2523
+ ),
2524
+ onChange: (v) => { setData(null); setYear(Number(v)) }
2525
+ })
2526
+ ),
2527
+ h('div', { className: 'dsh-cj-stats' },
2528
+ h('div', { className: 'dsh-cj-stat' },
2529
+ h('div', { className: 'l' }, t('totalCommits')),
2530
+ h('div', { className: 'v' }, stats.totalCommits),
2531
+ h('div', { className: 'n' }, t('noteTotal'))
2532
+ ),
2533
+ h('div', { className: 'dsh-cj-stat' },
2534
+ h('div', { className: 'l' }, t('activeDays')),
2535
+ h('div', { className: 'v' }, stats.activeDays, h('small', null, t('unitDay'))),
2536
+ h('div', { className: 'n' }, t('noteActiveDays'))
2537
+ ),
2538
+ h('div', { className: 'dsh-cj-stat' },
2539
+ h('div', { className: 'l' }, t('longestStreak')),
2540
+ h('div', { className: 'v' }, stats.longestStreak, h('small', null, t('unitDay'))),
2541
+ h('div', { className: 'n' }, t('noteStreak'))
2542
+ ),
2543
+ h('div', { className: 'dsh-cj-stat' },
2544
+ h('div', { className: 'l' }, t('maxDay')),
2545
+ h('div', { className: 'v' }, stats.maxDayCount, h('small', null, t('unitCommit'))),
2546
+ h('div', { className: 'n' }, stats.maxDayDate || t('notePeak'))
2547
+ )
2548
+ ),
2549
+ heatmap && h('div', { className: 'dsh-cj-heat' },
2550
+ h('div', { className: 'dsh-cj-heat-body' },
2551
+ h('div', { className: 'dsh-cj-weekdays', 'aria-hidden': true },
2552
+ weekLabels.map((x) => h('span', { key: x }, x))
2553
+ ),
2554
+ h('div', { className: 'dsh-cj-heat-main' },
2555
+ h('div', {
2556
+ className: 'dsh-cj-months',
2557
+ 'aria-hidden': true,
2558
+ style: { gridTemplateColumns: 'repeat(' + heatmap.weeks + ', calc(var(--dsh-cj-cell) + var(--dsh-cj-gap)))' }
2559
+ },
2560
+ heatmap.monthLabels.map((m) =>
2561
+ h('span', {
2562
+ key: m.column + '-' + m.text,
2563
+ className: 'dsh-cj-month',
2564
+ style: { gridColumn: m.column }
2565
+ }, m.text)
2566
+ )
2567
+ ),
2568
+ h('div', {
2569
+ className: 'dsh-cj-grid',
2570
+ role: 'group',
2571
+ 'aria-label': data.from + ' ~ ' + data.to
2572
+ },
2573
+ heatmap.cells.map((c) => {
2574
+ const clickable = c.inRange && c.count > 0
2575
+ const tip = c.inRange ? (c.key + ' · ' + c.count + ' ' + t('unitCommit')) : c.key
2576
+ return h('button', {
2577
+ key: c.key,
2578
+ type: 'button',
2579
+ className: [
2580
+ 'dsh-cj-cell',
2581
+ c.inRange ? 'lv' + c.level : 'is-blank',
2582
+ clickable ? 'has-commits' : '',
2583
+ c.isToday ? 'is-today' : '',
2584
+ day === c.key ? 'is-today' : ''
2585
+ ].filter(Boolean).join(' '),
2586
+ title: clickable ? tip + '(点击查看)' : tip,
2587
+ disabled: !clickable,
2588
+ onClick: () => openDay(c.key)
2589
+ })
2590
+ })
2591
+ )
2592
+ )
2593
+ ),
2594
+ h('div', { className: 'dsh-cj-heat-foot' },
2595
+ h('span', null, fillMsg(t('heatSummary'), {
2596
+ w: heatmap.weeks,
2597
+ a: stats.activeDays,
2598
+ c: stats.totalCommits
2599
+ })),
2600
+ h('span', { className: 'dsh-cj-heat-legend' },
2601
+ h('span', null, t('less')),
2602
+ [0, 1, 2, 3, 4].map((lv) =>
2603
+ h('span', { key: lv, className: 'swatch' + (lv ? ' lv' + lv : '') })
2604
+ ),
2605
+ h('span', null, t('more'))
2606
+ )
2607
+ )
2608
+ ),
2609
+ heatmap && h('div', { className: 'dsh-cj-insights' },
2610
+ h('div', { className: 'dsh-cj-insight' },
2611
+ h('h4', null, t('weekdayDist')),
2612
+ heatmap.weekdayCounts.map((n, i) =>
2613
+ h('div', { className: 'dsh-cj-wd', key: weekLabels[i] },
2614
+ h('span', null, weekLabels[i]),
2615
+ h('div', { className: 'dsh-cj-wd-bar' },
2616
+ h('i', { style: { width: Math.round((n / heatmap.wdMax) * 100) + '%' } })
2617
+ ),
2618
+ h('span', null, n)
2619
+ )
2620
+ )
2621
+ ),
2622
+ h('div', { className: 'dsh-cj-insight' },
2623
+ h('h4', null, t('activity')),
2624
+ h('div', { className: 'dsh-cj-meta-list' },
2625
+ h('div', null, h('span', null, t('currentStreak')), h('strong', null, heatmap.currentStreak)),
2626
+ h('div', null, h('span', null, t('avgPerDay')), h('strong', null, heatmap.avg)),
2627
+ h('div', null,
2628
+ h('span', null, t('peakOn')),
2629
+ h('strong', null, data.stats.maxDayDate || '—')
2630
+ ),
2631
+ h('div', null,
2632
+ h('span', null, t('maxDay')),
2633
+ h('strong', null, data.stats.maxDayCount)
2634
+ )
2635
+ )
2636
+ )
2637
+ ),
2638
+ h('p', { className: 'dsh-cj-footnote' }, t('activityFootnote')),
2639
+ day && h('aside', {
2640
+ className: 'dsh-cj-drawer',
2641
+ role: 'complementary',
2642
+ 'aria-label': day
2643
+ },
2644
+ h('div', { className: 'dsh-cj-drawer-head' },
2645
+ h('div', { className: 'dsh-cj-drawer-title' },
2646
+ h('strong', null, formatDayTitle(day)),
2647
+ h('span', null,
2648
+ day + ' · ' + (dayLoading ? t('dayLoading') : fillMsg(t('dayCommits'), { n: dayItems.length }))
2649
+ )
2650
+ ),
2651
+ h(Btn, {
2652
+ icon: IconClose ? h(IconClose) : null,
2653
+ onClick: () => setDay(null)
2654
+ }, IconClose ? null : '×')
2655
+ ),
2656
+ h('div', { className: 'dsh-cj-drawer-body' },
2657
+ dayLoading
2658
+ ? h('p', { className: 'dsh-cj-muted' }, '…')
2659
+ : (dayItems.length
2660
+ ? dayItems.map((c, i) =>
2661
+ h('div', { className: 'dsh-cj-commit', key: c.id || i },
2662
+ h('div', { className: 'dsh-cj-commit-head' },
2663
+ h('span', null, (c.time || '').slice(11, 16) || '—'),
2664
+ h('span', { className: 'dsh-cj-commit-repo', title: c.repo }, shortRepoLabel(c.repo))
2665
+ ),
2666
+ h('div', { className: 'dsh-cj-commit-title' }, c.title),
2667
+ h('div', { className: 'dsh-cj-commit-meta' },
2668
+ h('span', { className: 'dsh-cj-commit-sha' }, c.sha),
2669
+ h('span', null, c.authorName || ''),
2670
+ c.webUrl
2671
+ ? h(Btn, {
2672
+ icon: IconLink ? h(IconLink) : null,
2673
+ onClick: () => {
2674
+ try { window.open(c.webUrl, '_blank', 'noopener,noreferrer') } catch { /* ignore */ }
2675
+ }
2676
+ }, t('openRepo'))
2677
+ : null
2678
+ )
2679
+ )
2680
+ )
2681
+ : h('p', { className: 'dsh-cj-muted' }, t('dayEmpty')))
2682
+ )
2683
+ )
2684
+ )
2685
+ }
2686
+
2687
+ function LogsPage({ t, accountId, busy, setBusy, notify }) {
2688
+ const [items, setItems] = useState([])
2689
+ const [total, setTotal] = useState(0)
2690
+ const [page, setPage] = useState(1)
2691
+ const [pageSize, setPageSize] = useState(10)
2692
+
2693
+ const load = useCallback(async (nextPage, nextSize) => {
2694
+ if (!accountId) return
2695
+ const size = nextSize || pageSize
2696
+ const p = nextPage || page
2697
+ const q = new URLSearchParams({
2698
+ accountId,
2699
+ limit: String(size),
2700
+ offset: String((p - 1) * size)
2701
+ })
2702
+ const data = await api('/api/logs?' + q.toString())
2703
+ setItems(data.items || [])
2704
+ setTotal(data.total || 0)
2705
+ setPage(p)
2706
+ if (nextSize) setPageSize(size)
2707
+ }, [accountId, page, pageSize])
2708
+
2709
+ useEffect(() => {
2710
+ if (!accountId) return
2711
+ load(1).catch((e) => notify(e.message || String(e), 'error'))
2712
+ }, [accountId]) // eslint-disable-line
2713
+
2714
+ if (!accountId) {
2715
+ return h('div', { className: 'dsh-cj-page-fill' },
2716
+ h(PageHead, { desc: t('descLogs') }),
2717
+ h('p', { className: 'dsh-cj-muted' }, t('emptyAccount'))
2718
+ )
2719
+ }
2720
+
2721
+ return h('div', { className: 'dsh-cj-page-fill' },
2722
+ h(PageHead, { desc: t('descLogs') }),
2723
+ h('div', { className: 'dsh-cj-row' },
2724
+ h(Btn, {
2725
+ disabled: busy,
2726
+ icon: IconRefresh ? h(IconRefresh) : null,
2727
+ onClick: () => {
2728
+ setBusy(true)
2729
+ load(1)
2730
+ .then(() => notify(t('refreshOk'), 'success'))
2731
+ .catch((e) => notify(e.message || String(e), 'error'))
2732
+ .finally(() => setBusy(false))
2733
+ }
2734
+ }, t('refresh')),
2735
+ h(Btn, {
2736
+ danger: true, disabled: busy,
2737
+ icon: IconTrash ? h(IconTrash) : null,
2738
+ onClick: async () => {
2739
+ if (!confirm(t('confirmClearLogs'))) return
2740
+ setBusy(true)
2741
+ try {
2742
+ await api('/api/logs?accountId=' + encodeURIComponent(accountId), { method: 'DELETE' })
2743
+ await load(1)
2744
+ notify(t('clearOk'), 'success')
2745
+ } catch (e) { notify(e.message || String(e), 'error') }
2746
+ finally { setBusy(false) }
2747
+ }
2748
+ }, t('clearLogs'))
2749
+ ),
2750
+ h('div', { className: 'dsh-cj-table-wrap' },
2751
+ h('table', { className: 'dsh-cj-table' },
2752
+ h('thead', null, h('tr', null,
2753
+ h('th', null, t('level')), h('th', null, t('time')), h('th', null, t('message'))
2754
+ )),
2755
+ h('tbody', null, items.map((l) =>
2756
+ h('tr', { key: l.id },
2757
+ h('td', null, logLevelTag(t, l.level)),
2758
+ h('td', null, (l.at || '').replace('T', ' ').slice(0, 19)),
2759
+ h('td', null, l.message)
2760
+ )
2761
+ ))
2762
+ )
2763
+ ),
2764
+ h(TablePager, {
2765
+ t,
2766
+ total,
2767
+ page,
2768
+ pageSize,
2769
+ busy,
2770
+ onPageChange: (p) => {
2771
+ setBusy(true)
2772
+ load(p).catch((e) => notify(e.message || String(e), 'error')).finally(() => setBusy(false))
2773
+ },
2774
+ onPageSizeChange: (size) => {
2775
+ setBusy(true)
2776
+ load(1, size).catch((e) => notify(e.message || String(e), 'error')).finally(() => setBusy(false))
2777
+ }
2778
+ })
2779
+ )
2780
+ }
2781
+
2782
+ function SettingsPage({ t, busy, setBusy, notify }) {
2783
+ const [form, setForm] = useState({
2784
+ syncIntervalMinutes: 30,
2785
+ syncLookbackDays: 90,
2786
+ exportsPath: ''
2787
+ })
2788
+
2789
+ useEffect(() => {
2790
+ api('/api/settings').then((s) => setForm({
2791
+ syncIntervalMinutes: s.syncIntervalMinutes,
2792
+ syncLookbackDays: s.syncLookbackDays,
2793
+ exportsPath: s.exportsPath || ''
2794
+ })).catch((e) => notify(e.message || String(e), 'error'))
2795
+ }, [notify])
2796
+
2797
+ return h('div', { className: 'dsh-cj-page-scroll' },
2798
+ h(PageHead, { desc: t('descSettings') }),
2799
+ h('h3', {
2800
+ className: 'dsh-cj-page-title',
2801
+ style: { fontSize: 14, marginBottom: 10 }
2802
+ }, t('syncSettingsTitle')),
2803
+ h('div', { className: 'dsh-cj-field' },
2804
+ h('label', { className: 'dsh-cj-label' }, t('syncInterval')),
2805
+ h(FieldInput, {
2806
+ type: 'number', min: 5,
2807
+ value: form.syncIntervalMinutes,
2808
+ onChange: (e) => setForm({ ...form, syncIntervalMinutes: Number(e.target.value) })
2809
+ })
2810
+ ),
2811
+ h('div', { className: 'dsh-cj-field' },
2812
+ h('label', { className: 'dsh-cj-label' }, t('lookback')),
2813
+ h(FieldInput, {
2814
+ type: 'number', min: 1,
2815
+ value: form.syncLookbackDays,
2816
+ onChange: (e) => setForm({ ...form, syncLookbackDays: Number(e.target.value) })
2817
+ })
2818
+ ),
2819
+ h('div', { className: 'dsh-cj-field' },
2820
+ h('label', { className: 'dsh-cj-label' }, t('exportsPath')),
2821
+ h(FieldInput, {
2822
+ value: form.exportsPath,
2823
+ placeholder: '~/.dsh-commit-journal/exports',
2824
+ onChange: (e) => setForm({ ...form, exportsPath: e.target.value })
2825
+ }),
2826
+ h('div', { className: 'dsh-cj-muted' }, t('exportsPathHint'))
2827
+ ),
2828
+ h(Btn, {
2829
+ primary: true, disabled: busy,
2830
+ icon: IconSave ? h(IconSave) : null,
2831
+ onClick: async () => {
2832
+ setBusy(true)
2833
+ try {
2834
+ await api('/api/settings', { method: 'PUT', body: JSON.stringify(form) })
2835
+ notify(t('saveOk'), 'success')
2836
+ } catch (e) { notify(e.message || String(e), 'error') }
2837
+ finally { setBusy(false) }
2838
+ }
2839
+ }, t('save'))
2840
+ )
2841
+ }
2842
+
2843
+ function detectScheme() {
2844
+ const el = document.documentElement
2845
+ const attr = (el.getAttribute('data-theme') || el.getAttribute('data-color-scheme') || el.className || '').toLowerCase()
2846
+ if (attr.includes('dark')) return 'dark'
2847
+ if (attr.includes('light')) return 'light'
2848
+ const bg = getComputedStyle(el).getPropertyValue('--dsw-alias-bg-base').trim()
2849
+ const hex = bg.match(/#([0-9a-f]{6})/i)
2850
+ if (hex) {
2851
+ const n = parseInt(hex[1], 16)
2852
+ const r = (n >> 16) & 255, g = (n >> 8) & 255, b = n & 255
2853
+ return (r * 299 + g * 587 + b * 114) / 1000 < 128 ? 'dark' : 'light'
2854
+ }
2855
+ const rgb = bg.match(/rgba?\((\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i)
2856
+ if (rgb) {
2857
+ const r = Number(rgb[1]), g = Number(rgb[2]), b = Number(rgb[3])
2858
+ return (r * 299 + g * 587 + b * 114) / 1000 < 128 ? 'dark' : 'light'
2859
+ }
2860
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
2861
+ }
2862
+
2863
+ function App({ t }) {
2864
+ const [tab, setTab] = useState('accounts')
2865
+ const [accounts, setAccounts] = useState([])
2866
+ const [activeId, setActiveId] = useState(null)
2867
+ const [busy, setBusy] = useState(false)
2868
+ const [scheme, setScheme] = useState('light')
2869
+ const [toast, setToast] = useState(null)
2870
+ const toastSeq = React.useRef(0)
2871
+
2872
+ const notify = useCallback((text, tone) => {
2873
+ toastSeq.current += 1
2874
+ setToast({
2875
+ id: toastSeq.current,
2876
+ text: String(text || ''),
2877
+ tone: tone === 'success' ? 'success' : 'error',
2878
+ holdMs: tone === 'success' ? 3000 : 6000
2879
+ })
2880
+ }, [])
2881
+
2882
+ const clearToast = useCallback(() => setToast(null), [])
2883
+
2884
+ const refreshAccounts = useCallback(async () => {
2885
+ const data = await api('/api/accounts')
2886
+ setAccounts(data.accounts || [])
2887
+ setActiveId(data.activeAccountId || null)
2888
+ }, [])
2889
+
2890
+ useEffect(() => {
2891
+ refreshAccounts().catch((e) => notify(e.message || String(e), 'error'))
2892
+ }, [refreshAccounts, notify])
2893
+
2894
+ useEffect(() => {
2895
+ const sync = () => setScheme(detectScheme())
2896
+ sync()
2897
+ const mo = new MutationObserver(sync)
2898
+ mo.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-color-scheme', 'class'] })
2899
+ const mq = window.matchMedia('(prefers-color-scheme: dark)')
2900
+ if (mq.addEventListener) mq.addEventListener('change', sync)
2901
+ else if (mq.addListener) mq.addListener(sync)
2902
+ return () => {
2903
+ mo.disconnect()
2904
+ if (mq.removeEventListener) mq.removeEventListener('change', sync)
2905
+ else if (mq.removeListener) mq.removeListener(sync)
2906
+ }
2907
+ }, [])
2908
+
2909
+ // 无官方 Toast 时的兜底:固定顶栏 + 定时关闭
2910
+ useEffect(() => {
2911
+ if (!toast || UiToast) return undefined
2912
+ const timer = setTimeout(clearToast, toast.holdMs || 4000)
2913
+ return () => clearTimeout(timer)
2914
+ }, [toast, clearToast])
2915
+
2916
+ const activeAccount = accounts.find((a) => a.id === activeId) || null
2917
+ const activeMode = activeAccount && activeAccount.mode === 'local' ? 'local' : 'remote'
2918
+
2919
+ const toastNode = toast
2920
+ ? (UiToast
2921
+ ? h(UiToast, {
2922
+ key: toast.id,
2923
+ text: toast.text,
2924
+ tone: toast.tone === 'success' ? 'success' : undefined,
2925
+ holdMs: toast.holdMs,
2926
+ onDone: clearToast
2927
+ })
2928
+ : (ReactDOM && ReactDOM.createPortal
2929
+ ? ReactDOM.createPortal(
2930
+ h('div', {
2931
+ key: toast.id,
2932
+ className: 'dsh-cj-toast-fallback',
2933
+ 'data-tone': toast.tone,
2934
+ role: 'status'
2935
+ }, toast.text),
2936
+ document.body
2937
+ )
2938
+ : h('div', {
2939
+ key: toast.id,
2940
+ className: 'dsh-cj-toast-fallback',
2941
+ 'data-tone': toast.tone,
2942
+ role: 'status'
2943
+ }, toast.text)))
2944
+ : null
2945
+
2946
+ return h('div', { className: 'dsh-cj-root', 'data-scheme': scheme },
2947
+ h('style', null, CSS),
2948
+ toastNode,
2949
+ h('div', { className: 'dsh-cj-tabs', role: 'tablist' },
2950
+ TABS.map((item) =>
2951
+ h('button', {
2952
+ key: item.id,
2953
+ type: 'button',
2954
+ role: 'tab',
2955
+ className: 'dsh-cj-tab',
2956
+ 'data-active': tab === item.id ? '1' : '0',
2957
+ 'aria-selected': tab === item.id,
2958
+ onClick: () => setTab(item.id)
2959
+ }, t(item.id))
2960
+ )
2961
+ ),
2962
+ h('div', { className: 'dsh-cj-body' },
2963
+ tab === 'accounts' && h(AccountsPage, {
2964
+ t, accounts, activeId, busy, setBusy, notify,
2965
+ onChanged: refreshAccounts
2966
+ }),
2967
+ tab === 'repos' && h(ReposPage, {
2968
+ t, accountId: activeId, accountMode: activeMode, busy, setBusy, notify
2969
+ }),
2970
+ tab === 'commits' && h(CommitsPage, { t, accountId: activeId, busy, setBusy, notify }),
2971
+ tab === 'activity' && h(ActivityPage, { t, accountId: activeId, notify }),
2972
+ tab === 'logs' && h(LogsPage, { t, accountId: activeId, busy, setBusy, notify }),
2973
+ tab === 'settings' && h(SettingsPage, { t, busy, setBusy, notify })
2974
+ )
2975
+ )
2976
+ }
2977
+
2978
+ return {
2979
+ inject: ['slots', 'locale'],
2980
+ apply(ctx) {
2981
+ ctx.effect(() => ctx.locale.register(NS, DICTIONARIES), 'commit-journal: dictionaries')
2982
+ const translate = ctx.locale.bind(NS)
2983
+ // Tab labels come from TABS zh/en via locale keys if present; fallback zh in render
2984
+ const t = (key) => {
2985
+ try { return translate(key) } catch { return DICTIONARIES.zh[key] || key }
2986
+ }
2987
+
2988
+ ctx.slots.inject('sidebar.panellist', () =>
2989
+ ctx.slots.register(
2990
+ {
2991
+ name: 'sidebar.panellist',
2992
+ id: PANEL_ID,
2993
+ order: 25,
2994
+ label: () => translate('panelLabel'),
2995
+ locale: NS
2996
+ },
2997
+ PanelIcon
2998
+ )
2999
+ )
3000
+
3001
+ ctx.slots.inject('main', () =>
3002
+ ctx.slots.register(
3003
+ { name: 'main', key: PANEL_ID, locale: NS },
3004
+ function CommitJournalMain() {
3005
+ return h(App, { t })
3006
+ }
3007
+ )
3008
+ )
3009
+ }
3010
+ }
3011
+ }
3012
+ })