dsh-github-repo-search 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +96 -2
- package/client.js +919 -0
- package/cordis.patch.yml +18 -0
- package/docs/DETAIL.md +3 -0
- package/docs/DETAIL.zh.md +3 -0
- package/docs/preview.svg +37 -0
- package/icon.svg +11 -0
- package/index.js +1141 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +56 -4
package/client.js
ADDED
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub 搜索结果面板(右侧栏)。
|
|
3
|
+
*
|
|
4
|
+
* 数据来源是 Host 侧的会话投影 `githubSearch`:`github_search_repos` /
|
|
5
|
+
* `github_repo` / `github_rate` 每次调用都会往 `tool/result` 的 meta 里带一份
|
|
6
|
+
* 结构化结果,Host 的投影单元把它折叠成 `{ queries, details, rate }`。
|
|
7
|
+
*
|
|
8
|
+
* 为什么在右侧栏:`sidebar.right.pane.tab` 是 session 作用域,标准 props 里带
|
|
9
|
+
* `useProjection`;而 root 作用域的 `main` 面板拿不到会话投影。
|
|
10
|
+
*
|
|
11
|
+
* 面板只读:不发起搜索(Web 端调用 Host 需要 Typert 生成的 Remote 命名空间,
|
|
12
|
+
* 第三方插件无法接入),也不写任何状态。搜索由对话驱动。
|
|
13
|
+
*
|
|
14
|
+
* 样式只用宿主真实存在的 `--dsw-alias-*` / `--dsw-radius-*` token,
|
|
15
|
+
* 因此明暗主题自动跟随;不要写死颜色。
|
|
16
|
+
*/
|
|
17
|
+
window.__ModuleLoader__.load({
|
|
18
|
+
id: 'dsh-github-repo-search',
|
|
19
|
+
factory(require) {
|
|
20
|
+
const React = require('react')
|
|
21
|
+
const h = React.createElement
|
|
22
|
+
const { useState, useCallback, useMemo } = React
|
|
23
|
+
|
|
24
|
+
const TAB_KIND = 'githubSearchPanel'
|
|
25
|
+
const TAB_ID = 'dsh-github-repo-search/panel'
|
|
26
|
+
|
|
27
|
+
/** 收藏与面板偏好存在浏览器本地:它们属于「我的使用习惯」,不进会话日志。 */
|
|
28
|
+
const STORE_KEY = 'dsh-github-repo-search.v1'
|
|
29
|
+
|
|
30
|
+
/** 读取本地偏好;storage 不可用或数据损坏时回落到默认值。 */
|
|
31
|
+
function readStore() {
|
|
32
|
+
const empty = { starred: [], tab: 'repos', sort: 'default', compare: [] }
|
|
33
|
+
if (typeof localStorage === 'undefined') return empty
|
|
34
|
+
try {
|
|
35
|
+
const raw = localStorage.getItem(STORE_KEY)
|
|
36
|
+
if (raw === null) return empty
|
|
37
|
+
const parsed = JSON.parse(raw)
|
|
38
|
+
if (parsed === null || typeof parsed !== 'object') return empty
|
|
39
|
+
return {
|
|
40
|
+
starred: Array.isArray(parsed.starred) ? parsed.starred.filter(x => x && typeof x.fullName === 'string') : [],
|
|
41
|
+
tab: typeof parsed.tab === 'string' ? parsed.tab : 'repos',
|
|
42
|
+
sort: typeof parsed.sort === 'string' ? parsed.sort : 'default',
|
|
43
|
+
compare: Array.isArray(parsed.compare) ? parsed.compare.filter(x => typeof x === 'string') : [],
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
return empty
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 写回本地偏好;失败不抛错(隐私模式等场景下静默降级为不持久化)。 */
|
|
51
|
+
function writeStore(next) {
|
|
52
|
+
if (typeof localStorage === 'undefined') return
|
|
53
|
+
try {
|
|
54
|
+
localStorage.setItem(STORE_KEY, JSON.stringify(next))
|
|
55
|
+
} catch {
|
|
56
|
+
// 存不进就算了,面板功能不受影响。
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 空状态里给的示例,覆盖三类检索,让人一眼知道能问什么。 */
|
|
61
|
+
const EXAMPLES = [
|
|
62
|
+
'搜一下 SVG 编辑器,按 star 排序',
|
|
63
|
+
'这个领域最近有什么活跃的项目',
|
|
64
|
+
'这个库里 useProjection 是怎么实现的',
|
|
65
|
+
'这个项目还有哪些没关的 bug',
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
/** 排序键:默认保持 GitHub 返回顺序。 */
|
|
69
|
+
const SORTS = [
|
|
70
|
+
{ id: 'default', label: '默认' },
|
|
71
|
+
{ id: 'stars', label: '星标' },
|
|
72
|
+
{ id: 'recent', label: '最近' },
|
|
73
|
+
{ id: 'name', label: '名称' },
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
/** 按当前排序返回新数组,不改动原数组。 */
|
|
77
|
+
function sortRepos(repos, sort) {
|
|
78
|
+
const copy = repos.slice()
|
|
79
|
+
if (sort === 'stars') copy.sort((a, b) => (b.stars || 0) - (a.stars || 0))
|
|
80
|
+
else if (sort === 'recent') copy.sort((a, b) => String(b.pushedAt ?? '').localeCompare(String(a.pushedAt ?? '')))
|
|
81
|
+
else if (sort === 'name') copy.sort((a, b) => String(a.fullName).localeCompare(String(b.fullName)))
|
|
82
|
+
return copy
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const css = {
|
|
86
|
+
root: {
|
|
87
|
+
display: 'flex',
|
|
88
|
+
flexDirection: 'column',
|
|
89
|
+
height: '100%',
|
|
90
|
+
minHeight: 0,
|
|
91
|
+
font: 'inherit',
|
|
92
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
93
|
+
background: 'var(--dsw-alias-bg-base)',
|
|
94
|
+
},
|
|
95
|
+
// ── 顶部工具条:配额与条目数 ──
|
|
96
|
+
toolbar: {
|
|
97
|
+
display: 'flex',
|
|
98
|
+
alignItems: 'center',
|
|
99
|
+
justifyContent: 'space-between',
|
|
100
|
+
gap: 8,
|
|
101
|
+
padding: '10px 14px 8px',
|
|
102
|
+
flex: 'none',
|
|
103
|
+
},
|
|
104
|
+
toolbarLeft: {
|
|
105
|
+
display: 'flex',
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
gap: 8,
|
|
108
|
+
minWidth: 0,
|
|
109
|
+
},
|
|
110
|
+
count: {
|
|
111
|
+
fontSize: 12,
|
|
112
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
113
|
+
whiteSpace: 'nowrap',
|
|
114
|
+
},
|
|
115
|
+
tabs: {
|
|
116
|
+
display: 'flex',
|
|
117
|
+
alignItems: 'center',
|
|
118
|
+
gap: 2,
|
|
119
|
+
padding: '0 12px 8px',
|
|
120
|
+
flex: 'none',
|
|
121
|
+
},
|
|
122
|
+
body: {
|
|
123
|
+
overflow: 'auto',
|
|
124
|
+
flex: 1,
|
|
125
|
+
minHeight: 0,
|
|
126
|
+
padding: '0 10px 20px',
|
|
127
|
+
},
|
|
128
|
+
sortRow: {
|
|
129
|
+
display: 'flex',
|
|
130
|
+
alignItems: 'center',
|
|
131
|
+
gap: 2,
|
|
132
|
+
padding: '0 12px 8px',
|
|
133
|
+
flex: 'none',
|
|
134
|
+
},
|
|
135
|
+
sortLabel: {
|
|
136
|
+
fontSize: 11,
|
|
137
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
138
|
+
marginRight: 4,
|
|
139
|
+
},
|
|
140
|
+
row: {
|
|
141
|
+
display: 'block',
|
|
142
|
+
boxSizing: 'border-box',
|
|
143
|
+
width: '100%',
|
|
144
|
+
padding: '8px 10px',
|
|
145
|
+
marginBottom: 6,
|
|
146
|
+
borderRadius: 'var(--dsw-radius-md)',
|
|
147
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
148
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
149
|
+
color: 'inherit',
|
|
150
|
+
cursor: 'pointer',
|
|
151
|
+
transition: 'background-color .12s ease',
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
// ── 空状态 ──
|
|
155
|
+
empty: {
|
|
156
|
+
display: 'flex',
|
|
157
|
+
flexDirection: 'column',
|
|
158
|
+
alignItems: 'center',
|
|
159
|
+
gap: 10,
|
|
160
|
+
padding: '48px 20px',
|
|
161
|
+
textAlign: 'center',
|
|
162
|
+
},
|
|
163
|
+
emptyIcon: { color: 'var(--dsw-alias-label-tertiary)', opacity: 0.55 },
|
|
164
|
+
emptyTitle: {
|
|
165
|
+
fontSize: 13,
|
|
166
|
+
fontWeight: 600,
|
|
167
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
168
|
+
},
|
|
169
|
+
examples: {
|
|
170
|
+
display: 'flex',
|
|
171
|
+
flexDirection: 'column',
|
|
172
|
+
gap: 6,
|
|
173
|
+
marginTop: 6,
|
|
174
|
+
width: '100%',
|
|
175
|
+
maxWidth: 280,
|
|
176
|
+
},
|
|
177
|
+
example: {
|
|
178
|
+
padding: '6px 10px',
|
|
179
|
+
borderRadius: 'var(--dsw-radius-md)',
|
|
180
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
181
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
182
|
+
fontSize: 11.5,
|
|
183
|
+
lineHeight: 1.5,
|
|
184
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
185
|
+
textAlign: 'left',
|
|
186
|
+
},
|
|
187
|
+
emptyHint: {
|
|
188
|
+
fontSize: 12,
|
|
189
|
+
lineHeight: 1.7,
|
|
190
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
191
|
+
maxWidth: 260,
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
// ── 查询分组 ──
|
|
195
|
+
group: { marginBottom: 18 },
|
|
196
|
+
groupHead: {
|
|
197
|
+
display: 'flex',
|
|
198
|
+
alignItems: 'baseline',
|
|
199
|
+
justifyContent: 'space-between',
|
|
200
|
+
gap: 8,
|
|
201
|
+
padding: '0 4px',
|
|
202
|
+
marginBottom: 8,
|
|
203
|
+
},
|
|
204
|
+
query: {
|
|
205
|
+
fontSize: 13,
|
|
206
|
+
fontWeight: 600,
|
|
207
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
208
|
+
overflow: 'hidden',
|
|
209
|
+
textOverflow: 'ellipsis',
|
|
210
|
+
whiteSpace: 'nowrap',
|
|
211
|
+
},
|
|
212
|
+
groupMeta: {
|
|
213
|
+
flex: 'none',
|
|
214
|
+
fontSize: 11,
|
|
215
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
216
|
+
whiteSpace: 'nowrap',
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
// ── 仓库卡片 ──
|
|
220
|
+
card: {
|
|
221
|
+
display: 'block',
|
|
222
|
+
width: '100%',
|
|
223
|
+
boxSizing: 'border-box',
|
|
224
|
+
textAlign: 'left',
|
|
225
|
+
padding: '10px 12px',
|
|
226
|
+
marginBottom: 8,
|
|
227
|
+
borderRadius: 'var(--dsw-radius-lg)',
|
|
228
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
229
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
230
|
+
color: 'inherit',
|
|
231
|
+
cursor: 'pointer',
|
|
232
|
+
font: 'inherit',
|
|
233
|
+
transition: 'background-color .12s ease, border-color .12s ease',
|
|
234
|
+
},
|
|
235
|
+
cardOpen: {
|
|
236
|
+
borderColor: 'var(--dsw-alias-border-l2)',
|
|
237
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
238
|
+
},
|
|
239
|
+
cardHead: {
|
|
240
|
+
display: 'flex',
|
|
241
|
+
alignItems: 'flex-start',
|
|
242
|
+
justifyContent: 'space-between',
|
|
243
|
+
gap: 8,
|
|
244
|
+
},
|
|
245
|
+
cardName: {
|
|
246
|
+
fontSize: 13,
|
|
247
|
+
fontWeight: 600,
|
|
248
|
+
lineHeight: 1.45,
|
|
249
|
+
wordBreak: 'break-word',
|
|
250
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
251
|
+
},
|
|
252
|
+
star: {
|
|
253
|
+
flex: 'none',
|
|
254
|
+
display: 'flex',
|
|
255
|
+
alignItems: 'center',
|
|
256
|
+
gap: 3,
|
|
257
|
+
fontSize: 12,
|
|
258
|
+
fontWeight: 600,
|
|
259
|
+
color: 'var(--dsw-alias-state-warn-primary)',
|
|
260
|
+
whiteSpace: 'nowrap',
|
|
261
|
+
},
|
|
262
|
+
chips: {
|
|
263
|
+
display: 'flex',
|
|
264
|
+
flexWrap: 'wrap',
|
|
265
|
+
gap: 5,
|
|
266
|
+
marginTop: 7,
|
|
267
|
+
},
|
|
268
|
+
chip: {
|
|
269
|
+
display: 'inline-flex',
|
|
270
|
+
alignItems: 'center',
|
|
271
|
+
fontSize: 11,
|
|
272
|
+
lineHeight: 1.5,
|
|
273
|
+
padding: '1px 7px',
|
|
274
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
275
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
276
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
277
|
+
whiteSpace: 'nowrap',
|
|
278
|
+
},
|
|
279
|
+
chipDim: {
|
|
280
|
+
display: 'inline-flex',
|
|
281
|
+
alignItems: 'center',
|
|
282
|
+
fontSize: 11,
|
|
283
|
+
lineHeight: 1.5,
|
|
284
|
+
padding: '1px 7px',
|
|
285
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
286
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
287
|
+
whiteSpace: 'nowrap',
|
|
288
|
+
},
|
|
289
|
+
desc: {
|
|
290
|
+
marginTop: 8,
|
|
291
|
+
fontSize: 12,
|
|
292
|
+
lineHeight: 1.6,
|
|
293
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
294
|
+
display: '-webkit-box',
|
|
295
|
+
WebkitLineClamp: 2,
|
|
296
|
+
WebkitBoxOrient: 'vertical',
|
|
297
|
+
overflow: 'hidden',
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
// ── 展开详情 ──
|
|
301
|
+
detailBox: {
|
|
302
|
+
margin: '0 0 8px',
|
|
303
|
+
padding: '9px 12px 11px',
|
|
304
|
+
borderRadius: '0 0 var(--dsw-radius-lg) var(--dsw-radius-lg)',
|
|
305
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
306
|
+
borderTop: 'none',
|
|
307
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
308
|
+
},
|
|
309
|
+
detailWrap: {
|
|
310
|
+
marginTop: 9,
|
|
311
|
+
paddingTop: 9,
|
|
312
|
+
borderTop: '1px solid var(--dsw-alias-border-l1)',
|
|
313
|
+
},
|
|
314
|
+
detailRow: {
|
|
315
|
+
display: 'flex',
|
|
316
|
+
gap: 8,
|
|
317
|
+
fontSize: 12,
|
|
318
|
+
lineHeight: 1.6,
|
|
319
|
+
marginBottom: 3,
|
|
320
|
+
},
|
|
321
|
+
detailLabel: {
|
|
322
|
+
flex: 'none',
|
|
323
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
324
|
+
minWidth: 54,
|
|
325
|
+
},
|
|
326
|
+
detailValue: {
|
|
327
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
328
|
+
wordBreak: 'break-word',
|
|
329
|
+
minWidth: 0,
|
|
330
|
+
},
|
|
331
|
+
link: {
|
|
332
|
+
color: 'var(--dsw-alias-brand-primary)',
|
|
333
|
+
textDecoration: 'none',
|
|
334
|
+
wordBreak: 'break-all',
|
|
335
|
+
},
|
|
336
|
+
readmeBox: {
|
|
337
|
+
marginTop: 8,
|
|
338
|
+
padding: '9px 10px',
|
|
339
|
+
borderRadius: 'var(--dsw-radius-md)',
|
|
340
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
341
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
342
|
+
maxHeight: 240,
|
|
343
|
+
overflow: 'auto',
|
|
344
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
|
|
345
|
+
fontSize: 11,
|
|
346
|
+
lineHeight: 1.65,
|
|
347
|
+
whiteSpace: 'pre-wrap',
|
|
348
|
+
wordBreak: 'break-word',
|
|
349
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
350
|
+
},
|
|
351
|
+
pendingHint: {
|
|
352
|
+
marginTop: 6,
|
|
353
|
+
fontSize: 11.5,
|
|
354
|
+
lineHeight: 1.6,
|
|
355
|
+
color: 'var(--dsw-alias-label-tertiary)',
|
|
356
|
+
},
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** 星标紧凑表示:1234 → 1.2k。 */
|
|
360
|
+
function compact(n) {
|
|
361
|
+
const value = Number(n) || 0
|
|
362
|
+
if (value < 1000) return String(value)
|
|
363
|
+
if (value < 10000) return `${(value / 1000).toFixed(1)}k`
|
|
364
|
+
return `${Math.round(value / 10000) * 10}k`
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** 星形图标。 */
|
|
368
|
+
function StarGlyph({ size }) {
|
|
369
|
+
const s = size ?? 11
|
|
370
|
+
return h('svg', {
|
|
371
|
+
width: s, height: s, viewBox: '0 0 16 16',
|
|
372
|
+
fill: 'currentColor', 'aria-hidden': true, style: { flex: 'none' },
|
|
373
|
+
}, h('path', { d: 'M8 1.2l2.06 4.18 4.61.67-3.34 3.25.79 4.6L8 11.73l-4.12 2.17.79-4.6L1.33 6.05l4.61-.67z' }))
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 复制按钮:点一下写入剪贴板并短暂显示「已复制」。
|
|
378
|
+
* 剪贴板不可用(非安全上下文等)时静默失败,不打断浏览。
|
|
379
|
+
*/
|
|
380
|
+
function CopyButton({ text, label }) {
|
|
381
|
+
const [done, setDone] = useState(false)
|
|
382
|
+
const onClick = useCallback((event) => {
|
|
383
|
+
event.stopPropagation()
|
|
384
|
+
const mark = () => {
|
|
385
|
+
setDone(true)
|
|
386
|
+
setTimeout(() => { setDone(false) }, 1200)
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
if (navigator?.clipboard?.writeText !== undefined) {
|
|
390
|
+
navigator.clipboard.writeText(text).then(mark, () => {})
|
|
391
|
+
}
|
|
392
|
+
} catch {
|
|
393
|
+
// 剪贴板不可用时不提示,避免噪音。
|
|
394
|
+
}
|
|
395
|
+
}, [text])
|
|
396
|
+
return h('button', {
|
|
397
|
+
type: 'button',
|
|
398
|
+
onClick,
|
|
399
|
+
style: {
|
|
400
|
+
padding: '1px 7px', border: '1px solid var(--dsw-alias-border-l1)',
|
|
401
|
+
borderRadius: 'var(--dsw-radius-xs)', background: 'transparent',
|
|
402
|
+
color: done ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
403
|
+
font: 'inherit', fontSize: 10.5, cursor: 'pointer',
|
|
404
|
+
},
|
|
405
|
+
}, done ? '已复制' : label)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** 一条仓库卡片:标题行带收藏与加入对比。 */
|
|
409
|
+
function RepoCard({ repo, detail, expanded, onToggle, starred, inCompare, onStar, onCompare }) {
|
|
410
|
+
const chips = []
|
|
411
|
+
if (repo.language !== null && repo.language !== undefined) chips.push({ text: repo.language, dim: false })
|
|
412
|
+
if (repo.license !== null && repo.license !== undefined) chips.push({ text: repo.license, dim: false })
|
|
413
|
+
if (repo.archived === true) chips.push({ text: '已归档', dim: true })
|
|
414
|
+
if (repo.pushedAt !== null && repo.pushedAt !== undefined) {
|
|
415
|
+
chips.push({ text: String(repo.pushedAt).slice(0, 10), dim: true })
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const actionStyle = (active) => ({
|
|
419
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
420
|
+
width: 20, height: 20, padding: 0, flex: 'none',
|
|
421
|
+
border: 'none', borderRadius: 'var(--dsw-radius-xs)',
|
|
422
|
+
background: active ? 'var(--dsw-alias-bg-layer-2)' : 'transparent',
|
|
423
|
+
color: active ? 'var(--dsw-alias-state-warn-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
424
|
+
cursor: 'pointer', opacity: active ? 1 : 0.5,
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
return h('div', null,
|
|
428
|
+
h('div', {
|
|
429
|
+
style: expanded === true ? { ...css.card, ...css.cardOpen } : css.card,
|
|
430
|
+
role: 'button',
|
|
431
|
+
tabIndex: 0,
|
|
432
|
+
'aria-expanded': expanded === true,
|
|
433
|
+
onClick: () => { onToggle() },
|
|
434
|
+
onKeyDown: (event) => {
|
|
435
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
436
|
+
event.preventDefault()
|
|
437
|
+
onToggle()
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
onMouseEnter: (event) => {
|
|
441
|
+
event.currentTarget.style.background = 'var(--dsw-alias-interactive-bg-hover)'
|
|
442
|
+
},
|
|
443
|
+
onMouseLeave: (event) => {
|
|
444
|
+
event.currentTarget.style.background = expanded === true
|
|
445
|
+
? 'var(--dsw-alias-bg-layer-2)'
|
|
446
|
+
: 'var(--dsw-alias-bg-layer-1)'
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
h('div', { style: css.cardHead },
|
|
450
|
+
h('div', { style: css.cardName }, repo.fullName),
|
|
451
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 4, flex: 'none' } },
|
|
452
|
+
h('span', { style: css.star }, h(StarGlyph, { size: 10 }), compact(repo.stars)),
|
|
453
|
+
h('button', {
|
|
454
|
+
type: 'button',
|
|
455
|
+
title: starred ? '取消收藏' : '收藏',
|
|
456
|
+
'aria-label': starred ? '取消收藏' : '收藏',
|
|
457
|
+
'aria-pressed': starred,
|
|
458
|
+
onClick: (event) => { event.stopPropagation(); onStar() },
|
|
459
|
+
style: actionStyle(starred),
|
|
460
|
+
}, h(StarGlyph, { size: 11 })),
|
|
461
|
+
h('button', {
|
|
462
|
+
type: 'button',
|
|
463
|
+
title: inCompare ? '移出对比' : '加入对比',
|
|
464
|
+
'aria-label': inCompare ? '移出对比' : '加入对比',
|
|
465
|
+
'aria-pressed': inCompare,
|
|
466
|
+
onClick: (event) => { event.stopPropagation(); onCompare() },
|
|
467
|
+
style: {
|
|
468
|
+
...actionStyle(inCompare),
|
|
469
|
+
color: inCompare ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
470
|
+
fontSize: 13, fontWeight: 700, lineHeight: 1,
|
|
471
|
+
},
|
|
472
|
+
}, inCompare ? '−' : '+'),
|
|
473
|
+
),
|
|
474
|
+
),
|
|
475
|
+
chips.length === 0
|
|
476
|
+
? null
|
|
477
|
+
: h('div', { style: css.chips }, ...chips.map((chip, index) =>
|
|
478
|
+
h('span', { key: index, style: chip.dim ? css.chipDim : css.chip }, chip.text))),
|
|
479
|
+
repo.description === null || repo.description === undefined
|
|
480
|
+
? null
|
|
481
|
+
: h('div', { style: css.desc }, repo.description),
|
|
482
|
+
),
|
|
483
|
+
|
|
484
|
+
expanded !== true
|
|
485
|
+
? null
|
|
486
|
+
: h('div', { style: css.detailBox },
|
|
487
|
+
h('div', { style: css.detailRow },
|
|
488
|
+
h('div', { style: css.detailLabel }, '仓库'),
|
|
489
|
+
h('div', { style: { ...css.detailValue, display: 'flex', flexDirection: 'column', gap: 4 } },
|
|
490
|
+
h('a', {
|
|
491
|
+
href: repo.url,
|
|
492
|
+
target: '_blank',
|
|
493
|
+
rel: 'noreferrer noopener',
|
|
494
|
+
style: css.link,
|
|
495
|
+
onClick: event => event.stopPropagation(),
|
|
496
|
+
}, repo.url),
|
|
497
|
+
h('div', { style: { display: 'flex', gap: 6 } },
|
|
498
|
+
h(CopyButton, { text: repo.fullName, label: '复制名称' }),
|
|
499
|
+
h(CopyButton, { text: `git clone ${repo.url}.git`, label: '复制 clone' })))),
|
|
500
|
+
detail === null || detail === undefined
|
|
501
|
+
? h('div', { style: css.pendingHint },
|
|
502
|
+
'还没有详情。让模型读一下这个仓库,这里会显示语言构成、最新 Release 和 README。')
|
|
503
|
+
: h('div', null,
|
|
504
|
+
detail.languages === null || detail.languages === undefined
|
|
505
|
+
? null
|
|
506
|
+
: h('div', { style: css.detailRow },
|
|
507
|
+
h('div', { style: css.detailLabel }, '语言'),
|
|
508
|
+
h('div', { style: css.detailValue }, detail.languages)),
|
|
509
|
+
detail.release === null || detail.release === undefined
|
|
510
|
+
? null
|
|
511
|
+
: h('div', { style: css.detailRow },
|
|
512
|
+
h('div', { style: css.detailLabel }, 'Release'),
|
|
513
|
+
h('div', { style: css.detailValue }, detail.release)),
|
|
514
|
+
detail.readme === null || detail.readme === undefined
|
|
515
|
+
? null
|
|
516
|
+
: h('div', { style: css.readmeBox }, detail.readme),
|
|
517
|
+
),
|
|
518
|
+
),
|
|
519
|
+
)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** 对比视图:把 2–3 个候选仓库并排比较,用来做选型决定。 */
|
|
523
|
+
function CompareView({ repos, onRemove, onClear }) {
|
|
524
|
+
if (repos.length === 0) {
|
|
525
|
+
return h('div', { style: css.empty },
|
|
526
|
+
h('div', { style: css.emptyTitle }, '对比区是空的'),
|
|
527
|
+
h('div', { style: css.emptyHint },
|
|
528
|
+
'在仓库卡片上点「+」,把 2–3 个候选放进来,这里会并排列出星标、语言、许可证、最近推送和简介。'),
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
const rows = [
|
|
532
|
+
{ label: '星标', value: r => compact(r.stars) },
|
|
533
|
+
{ label: '语言', value: r => r.language ?? '—' },
|
|
534
|
+
{ label: '许可证', value: r => r.license ?? '—' },
|
|
535
|
+
{ label: '最近推送', value: r => (r.pushedAt === null || r.pushedAt === undefined ? '—' : String(r.pushedAt).slice(0, 10)) },
|
|
536
|
+
{ label: 'Fork', value: r => compact(r.forks) },
|
|
537
|
+
{ label: '状态', value: r => (r.archived === true ? '已归档' : '活跃') },
|
|
538
|
+
]
|
|
539
|
+
return h('div', null,
|
|
540
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 4px', marginBottom: 8 } },
|
|
541
|
+
h('div', { style: { fontSize: 12, color: 'var(--dsw-alias-label-tertiary)' } }, `${repos.length} 个候选并排比较`),
|
|
542
|
+
h('button', {
|
|
543
|
+
type: 'button',
|
|
544
|
+
onClick: onClear,
|
|
545
|
+
style: {
|
|
546
|
+
border: 'none', background: 'transparent', cursor: 'pointer',
|
|
547
|
+
color: 'var(--dsw-alias-label-tertiary)', font: 'inherit', fontSize: 12,
|
|
548
|
+
textDecoration: 'underline', padding: 0,
|
|
549
|
+
},
|
|
550
|
+
}, '清空'),
|
|
551
|
+
),
|
|
552
|
+
h('div', { style: { display: 'flex', gap: 8, overflowX: 'auto', paddingBottom: 8 } },
|
|
553
|
+
...repos.map(repo => h('div', {
|
|
554
|
+
key: repo.fullName,
|
|
555
|
+
style: {
|
|
556
|
+
flex: '1 0 160px', minWidth: 160, boxSizing: 'border-box',
|
|
557
|
+
padding: '9px 10px', borderRadius: 'var(--dsw-radius-md)',
|
|
558
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
559
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
h('div', { style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 4 } },
|
|
563
|
+
h('div', { style: { fontSize: 12, fontWeight: 600, wordBreak: 'break-word', lineHeight: 1.4 } }, repo.fullName),
|
|
564
|
+
h('button', {
|
|
565
|
+
type: 'button', title: '移出对比',
|
|
566
|
+
onClick: () => { onRemove(repo.fullName) },
|
|
567
|
+
style: {
|
|
568
|
+
flex: 'none', width: 18, height: 18, padding: 0, border: 'none',
|
|
569
|
+
borderRadius: 'var(--dsw-radius-xs)', background: 'transparent',
|
|
570
|
+
color: 'var(--dsw-alias-label-tertiary)', cursor: 'pointer', fontSize: 13,
|
|
571
|
+
},
|
|
572
|
+
}, '×'),
|
|
573
|
+
),
|
|
574
|
+
...rows.map(row => h('div', { key: row.label, style: { display: 'flex', justifyContent: 'space-between', gap: 6, fontSize: 11, marginTop: 5 } },
|
|
575
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary)' } }, row.label),
|
|
576
|
+
h('span', { style: { color: 'var(--dsw-alias-label-secondary)', textAlign: 'right', wordBreak: 'break-word' } }, row.value(repo)),
|
|
577
|
+
)),
|
|
578
|
+
)),
|
|
579
|
+
),
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/** 面板主体。 */
|
|
584
|
+
function GitHubPanel(props) {
|
|
585
|
+
const state = props.useProjection('githubSearch')
|
|
586
|
+
const [openKey, setOpenKey] = useState(null)
|
|
587
|
+
const initial = useMemo(readStore, [])
|
|
588
|
+
const [starred, setStarred] = useState(initial.starred)
|
|
589
|
+
const [compare, setCompare] = useState(initial.compare)
|
|
590
|
+
const [tab, setTab] = useState(initial.tab)
|
|
591
|
+
const [sort, setSort] = useState(initial.sort)
|
|
592
|
+
|
|
593
|
+
// 任何偏好变化都写回本地,下次打开面板保持原样。
|
|
594
|
+
const persist = useCallback((patch) => {
|
|
595
|
+
writeStore({ ...readStore(), tab, sort, starred, compare, ...patch })
|
|
596
|
+
}, [tab, sort, starred, compare])
|
|
597
|
+
|
|
598
|
+
const selectTab = (next) => { setTab(next); persist({ tab: next }) }
|
|
599
|
+
const selectSort = (next) => { setSort(next); persist({ sort: next }) }
|
|
600
|
+
|
|
601
|
+
const queries = state !== null && state !== undefined && Array.isArray(state.queries) ? state.queries : []
|
|
602
|
+
const codeSearches = state !== null && state !== undefined && Array.isArray(state.codeSearches) ? state.codeSearches : []
|
|
603
|
+
const issueSearches = state !== null && state !== undefined && Array.isArray(state.issueSearches) ? state.issueSearches : []
|
|
604
|
+
const rate = state !== null && state !== undefined ? state.rate ?? null : null
|
|
605
|
+
|
|
606
|
+
const details = useMemo(() => {
|
|
607
|
+
const map = new Map()
|
|
608
|
+
const list = state !== null && state !== undefined && Array.isArray(state.details) ? state.details : []
|
|
609
|
+
for (const entry of list) map.set(entry.fullName, entry)
|
|
610
|
+
return map
|
|
611
|
+
}, [state])
|
|
612
|
+
|
|
613
|
+
// 收藏查找表,供卡片显示状态。
|
|
614
|
+
const starredSet = useMemo(() => new Set(starred.map(item => item.fullName)), [starred])
|
|
615
|
+
const compareSet = useMemo(() => new Set(compare), [compare])
|
|
616
|
+
|
|
617
|
+
const toggleStar = useCallback((repo) => {
|
|
618
|
+
setStarred((current) => {
|
|
619
|
+
const exists = current.some(item => item.fullName === repo.fullName)
|
|
620
|
+
const next = exists
|
|
621
|
+
? current.filter(item => item.fullName !== repo.fullName)
|
|
622
|
+
: [{ ...repo, starredAt: Date.now() }, ...current].slice(0, 50)
|
|
623
|
+
persist({ starred: next })
|
|
624
|
+
return next
|
|
625
|
+
})
|
|
626
|
+
}, [persist])
|
|
627
|
+
|
|
628
|
+
const toggleCompare = useCallback((fullName) => {
|
|
629
|
+
setCompare((current) => {
|
|
630
|
+
if (current.includes(fullName)) {
|
|
631
|
+
const next = current.filter(name => name !== fullName)
|
|
632
|
+
persist({ compare: next })
|
|
633
|
+
return next
|
|
634
|
+
}
|
|
635
|
+
// 对比最多三个:再多就失去「并排看」的意义。
|
|
636
|
+
const next = [...current, fullName].slice(-3)
|
|
637
|
+
persist({ compare: next })
|
|
638
|
+
return next
|
|
639
|
+
})
|
|
640
|
+
}, [persist])
|
|
641
|
+
|
|
642
|
+
const allRepos = useMemo(() => {
|
|
643
|
+
const map = new Map()
|
|
644
|
+
for (const group of queries) {
|
|
645
|
+
for (const repo of Array.isArray(group.repos) ? group.repos : []) {
|
|
646
|
+
if (!map.has(repo.fullName)) map.set(repo.fullName, repo)
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
for (const repo of starred) if (!map.has(repo.fullName)) map.set(repo.fullName, repo)
|
|
650
|
+
return map
|
|
651
|
+
}, [queries, starred])
|
|
652
|
+
|
|
653
|
+
const compareRepos = useMemo(
|
|
654
|
+
() => compare.map(name => allRepos.get(name)).filter(Boolean),
|
|
655
|
+
[compare, allRepos],
|
|
656
|
+
)
|
|
657
|
+
|
|
658
|
+
const repoCount = queries.reduce((n, g) => n + (Array.isArray(g.repos) ? g.repos.length : 0), 0)
|
|
659
|
+
const codeCount = codeSearches.reduce((n, g) => n + (Array.isArray(g.hits) ? g.hits.length : 0), 0)
|
|
660
|
+
const issueCount = issueSearches.reduce((n, g) => n + (Array.isArray(g.issues) ? g.issues.length : 0), 0)
|
|
661
|
+
const nothing = repoCount + codeCount + issueCount === 0 && starred.length === 0
|
|
662
|
+
|
|
663
|
+
const tabEmpty = (title, hint) => h('div', { style: css.empty },
|
|
664
|
+
h('div', { style: css.emptyTitle }, title),
|
|
665
|
+
h('div', { style: css.emptyHint }, hint),
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
/** 渲染一组仓库卡片。 */
|
|
669
|
+
const renderRepoGroup = (group, gi, keyPrefix) => {
|
|
670
|
+
const rows = sortRepos(Array.isArray(group.repos) ? group.repos : [], sort)
|
|
671
|
+
return h('div', { key: `${keyPrefix}:${group.query}:${gi}`, style: css.group },
|
|
672
|
+
h(GroupHead, {
|
|
673
|
+
query: group.query,
|
|
674
|
+
meta: `${group.total} 个${group.page > 1 ? ` · 第 ${group.page} 页` : ''} · 显示 ${rows.length}`,
|
|
675
|
+
}),
|
|
676
|
+
rows.map((repo, ri) => {
|
|
677
|
+
const key = `${keyPrefix}:${gi}:${repo.fullName}:${ri}`
|
|
678
|
+
return h(RepoCard, {
|
|
679
|
+
key, repo,
|
|
680
|
+
detail: details.get(repo.fullName) ?? null,
|
|
681
|
+
expanded: openKey === key,
|
|
682
|
+
onToggle: () => { setOpenKey(current => (current === key ? null : key)) },
|
|
683
|
+
starred: starredSet.has(repo.fullName),
|
|
684
|
+
inCompare: compareSet.has(repo.fullName),
|
|
685
|
+
onStar: () => { toggleStar(repo) },
|
|
686
|
+
onCompare: () => { toggleCompare(repo.fullName) },
|
|
687
|
+
})
|
|
688
|
+
}),
|
|
689
|
+
)
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
let content
|
|
693
|
+
if (tab === 'starred') {
|
|
694
|
+
content = starred.length === 0
|
|
695
|
+
? tabEmpty('还没有收藏', '在仓库卡片上点星形按钮收藏,收藏会跨会话保留。')
|
|
696
|
+
: h('div', { style: css.group },
|
|
697
|
+
h(GroupHead, { query: '我的收藏', meta: `${starred.length} 个` }),
|
|
698
|
+
sortRepos(starred, sort).map((repo, ri) => {
|
|
699
|
+
const key = `starred:${repo.fullName}:${ri}`
|
|
700
|
+
return h(RepoCard, {
|
|
701
|
+
key, repo,
|
|
702
|
+
detail: details.get(repo.fullName) ?? null,
|
|
703
|
+
expanded: openKey === key,
|
|
704
|
+
onToggle: () => { setOpenKey(current => (current === key ? null : key)) },
|
|
705
|
+
starred: true,
|
|
706
|
+
inCompare: compareSet.has(repo.fullName),
|
|
707
|
+
onStar: () => { toggleStar(repo) },
|
|
708
|
+
onCompare: () => { toggleCompare(repo.fullName) },
|
|
709
|
+
})
|
|
710
|
+
}),
|
|
711
|
+
)
|
|
712
|
+
} else if (tab === 'compare') {
|
|
713
|
+
content = h(CompareView, {
|
|
714
|
+
repos: compareRepos,
|
|
715
|
+
onRemove: (name) => { toggleCompare(name) },
|
|
716
|
+
onClear: () => { setCompare([]); persist({ compare: [] }) },
|
|
717
|
+
})
|
|
718
|
+
} else if (nothing) {
|
|
719
|
+
content = h('div', { style: css.empty },
|
|
720
|
+
h('svg', {
|
|
721
|
+
width: 36, height: 36, viewBox: '0 0 36 36', fill: 'none',
|
|
722
|
+
stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round',
|
|
723
|
+
'aria-hidden': true, style: css.emptyIcon,
|
|
724
|
+
},
|
|
725
|
+
h('circle', { cx: 15.2, cy: 15.2, r: 8.2 }),
|
|
726
|
+
h('path', { d: 'M21.4 21.4 28 28' }),
|
|
727
|
+
h('path', { d: 'M11.4 12.6h7.6M11.4 15.8h7.6M11.4 19h4.8' })),
|
|
728
|
+
h('div', { style: css.emptyTitle }, '这个会话还没有检索过 GitHub'),
|
|
729
|
+
h('div', { style: css.emptyHint }, '直接跟模型说,下面几种说法都能触发检索:'),
|
|
730
|
+
h('div', { style: css.examples },
|
|
731
|
+
...EXAMPLES.map(example => h('div', { key: example, style: css.example }, example)),
|
|
732
|
+
),
|
|
733
|
+
)
|
|
734
|
+
} else if (tab === 'repos') {
|
|
735
|
+
content = queries.length === 0
|
|
736
|
+
? tabEmpty('还没有仓库检索结果', '试试「搜一下 xx 相关的仓库」。')
|
|
737
|
+
: queries.map((group, gi) => renderRepoGroup(group, gi, 'repo'))
|
|
738
|
+
} else if (tab === 'code') {
|
|
739
|
+
content = codeSearches.length === 0
|
|
740
|
+
? tabEmpty('还没有代码检索结果', '代码搜索要更窄的条件,例如「在某个仓库里搜 useProjection」。')
|
|
741
|
+
: codeSearches.map((group, gi) => {
|
|
742
|
+
const rows = Array.isArray(group.hits) ? group.hits : []
|
|
743
|
+
return h('div', { key: `${group.query}:${gi}`, style: css.group },
|
|
744
|
+
h(GroupHead, {
|
|
745
|
+
query: group.query,
|
|
746
|
+
meta: `${group.total} 个${group.page > 1 ? ` · 第 ${group.page} 页` : ''} · 显示 ${rows.length}`,
|
|
747
|
+
}),
|
|
748
|
+
rows.map((hit, ri) => h(CodeRow, { key: `${gi}:${hit.url}:${ri}`, hit })),
|
|
749
|
+
)
|
|
750
|
+
})
|
|
751
|
+
} else {
|
|
752
|
+
content = issueSearches.length === 0
|
|
753
|
+
? tabEmpty('还没有议题检索结果', '可以问「这个项目有哪些未关闭的 bug」。')
|
|
754
|
+
: issueSearches.map((group, gi) => {
|
|
755
|
+
const rows = Array.isArray(group.issues) ? group.issues : []
|
|
756
|
+
return h('div', { key: `${group.query}:${gi}`, style: css.group },
|
|
757
|
+
h(GroupHead, {
|
|
758
|
+
query: group.query,
|
|
759
|
+
meta: `${group.total} 个${group.page > 1 ? ` · 第 ${group.page} 页` : ''} · 显示 ${rows.length}`,
|
|
760
|
+
}),
|
|
761
|
+
rows.map((issue, ri) => h(IssueRow, { key: `${gi}:${issue.url}:${ri}`, issue })),
|
|
762
|
+
)
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const showSort = tab === 'repos' || tab === 'starred'
|
|
767
|
+
|
|
768
|
+
return h('div', { style: css.root },
|
|
769
|
+
h('div', { style: css.toolbar },
|
|
770
|
+
h('div', { style: css.toolbarLeft },
|
|
771
|
+
h('div', { style: { fontSize: 13, fontWeight: 600 } }, 'GitHub'),
|
|
772
|
+
),
|
|
773
|
+
rate === null || rate === undefined
|
|
774
|
+
? null
|
|
775
|
+
: h('div', {
|
|
776
|
+
style: css.count,
|
|
777
|
+
title: `search ${rate.searchRemaining}/${rate.searchLimit} · core ${rate.coreRemaining}/${rate.coreLimit}`,
|
|
778
|
+
}, `配额 ${rate.searchRemaining}/${rate.searchLimit}`),
|
|
779
|
+
),
|
|
780
|
+
h('div', { style: css.tabs },
|
|
781
|
+
h(TabButton, { active: tab === 'repos', label: '仓库', count: repoCount, onClick: () => { selectTab('repos') } }),
|
|
782
|
+
h(TabButton, { active: tab === 'code', label: '代码', count: codeCount, onClick: () => { selectTab('code') } }),
|
|
783
|
+
h(TabButton, { active: tab === 'issues', label: '议题', count: issueCount, onClick: () => { selectTab('issues') } }),
|
|
784
|
+
h(TabButton, { active: tab === 'starred', label: '收藏', count: starred.length, onClick: () => { selectTab('starred') } }),
|
|
785
|
+
h(TabButton, { active: tab === 'compare', label: '对比', count: compare.length, onClick: () => { selectTab('compare') } }),
|
|
786
|
+
),
|
|
787
|
+
showSort
|
|
788
|
+
? h('div', { style: css.sortRow },
|
|
789
|
+
h('span', { style: css.sortLabel }, '排序'),
|
|
790
|
+
...SORTS.map(option => h('button', {
|
|
791
|
+
key: option.id,
|
|
792
|
+
type: 'button',
|
|
793
|
+
onClick: () => { selectSort(option.id) },
|
|
794
|
+
style: {
|
|
795
|
+
padding: '2px 7px', border: 'none',
|
|
796
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
797
|
+
background: sort === option.id ? 'var(--dsw-alias-bg-layer-2)' : 'transparent',
|
|
798
|
+
color: sort === option.id ? 'var(--dsw-alias-label-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
799
|
+
font: 'inherit', fontSize: 11, cursor: 'pointer',
|
|
800
|
+
},
|
|
801
|
+
}, option.label)),
|
|
802
|
+
)
|
|
803
|
+
: null,
|
|
804
|
+
h('div', { style: css.body }, content),
|
|
805
|
+
)
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/** 放大镜图标,供两个入口按钮复用。 */
|
|
809
|
+
function SearchGlyph({ size }) {
|
|
810
|
+
const s = typeof size === 'number' ? size : 16
|
|
811
|
+
return h('svg', {
|
|
812
|
+
width: s, height: s, viewBox: '0 0 36 36', fill: 'none',
|
|
813
|
+
stroke: 'currentColor', strokeWidth: 2.6, strokeLinecap: 'round',
|
|
814
|
+
'aria-hidden': true, style: { flex: 'none', display: 'block' },
|
|
815
|
+
},
|
|
816
|
+
h('circle', { cx: 15.2, cy: 15.2, r: 8.2 }),
|
|
817
|
+
h('path', { d: 'M21.4 21.4 28 28' }),
|
|
818
|
+
h('path', { d: 'M11.4 12.6h7.6M11.4 15.8h7.6M11.4 19h4.8' }))
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/** 会话头部按钮。 */
|
|
822
|
+
function HeaderButton({ openGithubPanel }) {
|
|
823
|
+
return h('button', {
|
|
824
|
+
type: 'button',
|
|
825
|
+
title: 'GitHub 搜索结果',
|
|
826
|
+
'aria-label': 'GitHub 搜索结果',
|
|
827
|
+
onClick: () => { openGithubPanel() },
|
|
828
|
+
style: {
|
|
829
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
830
|
+
width: 28, height: 28, padding: 0,
|
|
831
|
+
border: 'none', borderRadius: 'var(--dsw-radius-sm)',
|
|
832
|
+
background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
|
|
833
|
+
cursor: 'pointer',
|
|
834
|
+
},
|
|
835
|
+
onMouseEnter: (event) => {
|
|
836
|
+
event.currentTarget.style.background = 'var(--dsw-alias-interactive-bg-hover)'
|
|
837
|
+
event.currentTarget.style.color = 'var(--dsw-alias-label-primary)'
|
|
838
|
+
},
|
|
839
|
+
onMouseLeave: (event) => {
|
|
840
|
+
event.currentTarget.style.background = 'transparent'
|
|
841
|
+
event.currentTarget.style.color = 'var(--dsw-alias-label-secondary)'
|
|
842
|
+
},
|
|
843
|
+
}, h(SearchGlyph, { size: 16 }))
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** 左侧栏底部入口。 */
|
|
847
|
+
function SidebarAction({ openGithubPanel }) {
|
|
848
|
+
return h('button', {
|
|
849
|
+
type: 'button',
|
|
850
|
+
title: 'GitHub 搜索结果',
|
|
851
|
+
'aria-label': 'GitHub 搜索结果',
|
|
852
|
+
onClick: () => { openGithubPanel() },
|
|
853
|
+
style: {
|
|
854
|
+
display: 'flex', alignItems: 'center', gap: 9,
|
|
855
|
+
width: '100%', padding: '6px 8px',
|
|
856
|
+
border: 'none', borderRadius: 'var(--dsw-radius-sm)',
|
|
857
|
+
background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
|
|
858
|
+
cursor: 'pointer', font: 'inherit', fontSize: 13, textAlign: 'left',
|
|
859
|
+
},
|
|
860
|
+
onMouseEnter: (event) => {
|
|
861
|
+
event.currentTarget.style.background = 'var(--dsw-alias-interactive-bg-hover)'
|
|
862
|
+
event.currentTarget.style.color = 'var(--dsw-alias-label-primary)'
|
|
863
|
+
},
|
|
864
|
+
onMouseLeave: (event) => {
|
|
865
|
+
event.currentTarget.style.background = 'transparent'
|
|
866
|
+
event.currentTarget.style.color = 'var(--dsw-alias-label-secondary)'
|
|
867
|
+
},
|
|
868
|
+
},
|
|
869
|
+
h(SearchGlyph, { size: 16 }),
|
|
870
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, 'GitHub 搜索结果'),
|
|
871
|
+
)
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
return {
|
|
875
|
+
inject: ['slots', 'sidebarRightTabs', 'sidebarRight'],
|
|
876
|
+
apply(ctx) {
|
|
877
|
+
const openPanel = () => {
|
|
878
|
+
try {
|
|
879
|
+
ctx.sidebarRight.openTab(TAB_KIND)
|
|
880
|
+
} catch (error) {
|
|
881
|
+
console.warn('[github-repo-search] openTab failed:', error)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// 面板类型:右侧栏按 kind 打开。
|
|
886
|
+
ctx.effect(
|
|
887
|
+
() => ctx.sidebarRightTabs.register({
|
|
888
|
+
id: TAB_ID,
|
|
889
|
+
kind: TAB_KIND,
|
|
890
|
+
priority: 'extension',
|
|
891
|
+
title: () => 'GitHub 搜索结果',
|
|
892
|
+
}),
|
|
893
|
+
'github-repo-search: right sidebar tab type',
|
|
894
|
+
)
|
|
895
|
+
|
|
896
|
+
ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({
|
|
897
|
+
name: 'sidebar.right.pane.tab',
|
|
898
|
+
key: TAB_ID,
|
|
899
|
+
}, GitHubPanel))
|
|
900
|
+
|
|
901
|
+
ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
902
|
+
name: 'conversation.session.header.utilities',
|
|
903
|
+
id: TAB_ID,
|
|
904
|
+
order: -4,
|
|
905
|
+
label: () => 'GitHub 搜索结果',
|
|
906
|
+
inject: () => ({ openGithubPanel: openPanel }),
|
|
907
|
+
}, HeaderButton))
|
|
908
|
+
|
|
909
|
+
ctx.slots.inject('sidebar.footer.action', () => ctx.slots.register({
|
|
910
|
+
name: 'sidebar.footer.action',
|
|
911
|
+
id: TAB_ID,
|
|
912
|
+
order: 20,
|
|
913
|
+
label: () => 'GitHub 搜索结果',
|
|
914
|
+
inject: () => ({ openGithubPanel: openPanel }),
|
|
915
|
+
}, SidebarAction))
|
|
916
|
+
},
|
|
917
|
+
}
|
|
918
|
+
},
|
|
919
|
+
})
|