@ggboy123/dsh-paper-reader 1.8.3 → 1.10.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/README.md +9 -8
- package/dist/harness-translate.js +204 -0
- package/dist/host.js +165 -21
- package/dist/index.js +2 -1
- package/dist/library-manage.js +100 -1
- package/dist/translate-config.js +85 -12
- package/dist/translate.js +24 -16
- package/dist/translation-options.js +40 -0
- package/lib/client.js +652 -92
- package/package.json +1 -1
- package/reader/index.html +460 -130
- package/reader/vendor/PROVIDER_ICONS_LICENSE.txt +30 -0
- package/reader/vendor/anthropic.svg +1 -0
- package/reader/vendor/deepseek.svg +1 -0
- package/reader/vendor/gemini.svg +1 -0
- package/reader/vendor/kimi.svg +1 -0
- package/reader/vendor/openai.svg +1 -0
- package/reader/vendor/opencode.svg +1 -0
- package/reader/vendor/zhipu.svg +1 -0
- package/runtime/babeldoc-driver.py +4 -4
package/lib/client.js
CHANGED
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
* 阅读器是同源 iframe,但它的 <head> 首帧判定发生在网络请求之前 ⇒ 必须有一个**同步**可读的镜像。
|
|
34
34
|
* 配置的权威来源仍是服务端 /api/theme/config;这里只是镜像,写失败(隐私模式)不影响功能。
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
|
-
const
|
|
36
|
+
// classic script 会在更新 / 停用再启用时整文件重执行:顶层只放 function 声明,
|
|
37
|
+
// 禁止 const / let / class(旧版本的全局 lexical 也可能还在,var 同样会撞)。
|
|
38
38
|
function dprThemeMirror(cfg) {
|
|
39
39
|
if (!cfg || typeof cfg !== 'object') return null
|
|
40
40
|
const mode = ['follow', 'off', 'light', 'dark'].includes(cfg.pdfTheme) ? cfg.pdfTheme : 'follow'
|
|
@@ -45,8 +45,8 @@ function writeThemeMirror(cfg) {
|
|
|
45
45
|
const mir = dprThemeMirror(cfg)
|
|
46
46
|
if (!mir) return null
|
|
47
47
|
try {
|
|
48
|
-
localStorage.setItem(
|
|
49
|
-
localStorage.setItem(
|
|
48
|
+
localStorage.setItem('dpr.pdfTheme', mir.mode)
|
|
49
|
+
localStorage.setItem('dpr.pdfThemeCfg', JSON.stringify(mir))
|
|
50
50
|
} catch { /* 隐私模式:写不了镜像,阅读器仍可从服务端/宿主 postMessage 拿到 */ }
|
|
51
51
|
return mir
|
|
52
52
|
}
|
|
@@ -174,7 +174,7 @@ function dprClearRetryNeeded(err) {
|
|
|
174
174
|
* 反例:若塞进 `dpr.variant.<topic>/<name>`(按篇),改名搬家会搬它,而「全局」语义就破了。
|
|
175
175
|
* ③ 缺省 = 开:与改造前「分屏两列被 rAF 强行同步」的既有行为一致(老用户升级后观感不变)。
|
|
176
176
|
*/
|
|
177
|
-
|
|
177
|
+
function dprSyncScrollKey() { return 'dpr.syncScroll' }
|
|
178
178
|
/** 只认显式的 '0' 为关;缺失 / 脏值 / 隐私模式都算开(与 reader 的 readSyncPref 逐字同义)。 */
|
|
179
179
|
function dprSyncScrollFromRaw(raw) { return raw !== '0' }
|
|
180
180
|
function dprSyncScrollRaw(on) { return on ? '1' : '0' }
|
|
@@ -186,16 +186,17 @@ window.__ModuleLoader__.load({
|
|
|
186
186
|
factory: (require) => {
|
|
187
187
|
const React = require('react')
|
|
188
188
|
const { createPortal } = require('react-dom')
|
|
189
|
-
const { useState, useEffect, useCallback } = React
|
|
189
|
+
const { useState, useEffect, useCallback, useRef } = React
|
|
190
190
|
const h = React.createElement
|
|
191
191
|
|
|
192
192
|
const NS = 'dsh-paper-reader'
|
|
193
193
|
const zh = {
|
|
194
|
-
library: '文献库',
|
|
194
|
+
library: '文献库', refresh: '刷新',
|
|
195
195
|
empty: '文献库为空', hint: '新建专题或上传 PDF 开始', newTopic: '新建专题',
|
|
196
196
|
cancel: '取消', ok: '确定', defaultTopic: '默认专题', uploadBtn: '上传 PDF',
|
|
197
197
|
newTopicFail: '新建专题失败',
|
|
198
198
|
rename: '重命名', renameTopic: '重命名专题', renamePaper: '重命名论文',
|
|
199
|
+
renameInlineHint: 'Enter 保存,Esc 取消',
|
|
199
200
|
renameFail: '重命名失败', delFail: '删除失败',
|
|
200
201
|
upload: '上传 PDF 到此专题', newChat: '新建对话', session: '会话', pdfTab: '论文 PDF',
|
|
201
202
|
history: '历史对话',
|
|
@@ -206,8 +207,29 @@ window.__ModuleLoader__.load({
|
|
|
206
207
|
setRerankDesc: 'search_paper 检索的语义重排:关键词先捞候选,Jev 逐个判断「这段能否回答这个问题」再排序——大白话提问也能命中论文里的术语段落。不配则退回纯关键词排序。',
|
|
207
208
|
setEmbedTitle: '嵌入模型检索(可选)',
|
|
208
209
|
setEmbedDesc: 'search_paper 的语义召回:分块文本会发送到该 OpenAI 兼容 /embeddings 端点,用向量把「关键词一个字都没命中」的语义相近片段也捞进候选(与关键词结果融合,不替代)。留空即关闭,检索行为与现在完全一致。注意:分块文本(论文正文)会发往该端点。',
|
|
209
|
-
setTranslateTitle: '
|
|
210
|
-
setTranslateDesc: '
|
|
210
|
+
setTranslateTitle: '全文翻译模型',
|
|
211
|
+
setTranslateDesc: '生成中文版与划词翻译共用。默认跟随 Harness;专用配置只作用于翻译,不改变宿主模型设置。',
|
|
212
|
+
setTranslateFollow: '跟随 Harness', setTranslateCustom: '使用自定义模型', setTranslateDefault: '默认',
|
|
213
|
+
setTranslateFollowDesc: '与 Harness 当前模型保持一致', setTranslateCustomDesc: '翻译任务单独使用另一套配置',
|
|
214
|
+
setTranslateCurrentFollow: '当前跟随',
|
|
215
|
+
setTranslateFollowNote: 'Harness 切换模型后,下次翻译自动跟随;进行中的整篇翻译不变。',
|
|
216
|
+
setTranslateUnavailable: 'Harness 当前模型不可用,请先在 Harness 中完成模型设置。',
|
|
217
|
+
setTranslateProviders: '翻译服务商', setTranslateApplyKey: '申请 API Key',
|
|
218
|
+
setTranslateKeyAuto: '粘贴 Key 后自动验证并获取模型;选择模型后保存。',
|
|
219
|
+
setTranslateDiscovering: '正在验证 Key 并获取模型…', setTranslateModels: '选择翻译模型',
|
|
220
|
+
setTranslateRefresh: '刷新列表', setTranslateAdvanced: '高级设置:整篇 PDF 翻译参数',
|
|
221
|
+
setTranslateSplitTokens: '单段上下文上限(tokens)', setTranslateSplitHint: '超过后自动拆段;调小可减少单次上下文,调大可减少拆段次数。',
|
|
222
|
+
setTranslateMaxOutput: '单次输出上限(tokens)', setTranslateMaxOutputHint: '0 表示跟随端点默认,不传 max_tokens。',
|
|
223
|
+
setTranslateQps: '并发请求数(QPS)', setTranslateQpsHint: '过高容易触发端点限流;遇到 429 时可调低。',
|
|
224
|
+
setTranslateOptionsSave: '保存翻译参数', setTranslateOptionsSaved: '翻译参数已保存,下一篇 PDF 起生效',
|
|
225
|
+
setTranslateManualModel: '手动模型名', setTranslateUse: '使用', setTranslateUsing: '使用中',
|
|
226
|
+
setTranslateFollowSet: '已恢复为跟随 Harness,自定义配置已保留',
|
|
227
|
+
setTranslateScopeFollow: '跟随模式不保存或复制 Harness 的 Key,也不会改写 Harness 配置。',
|
|
228
|
+
setTranslateScopeCustom: '自定义配置仅用于翻译,不会写入或改变 Harness 的模型设置。',
|
|
229
|
+
setTranslateDelete: '删除此配置', setTranslateDeleteConfirm: '确认删除?', setTranslateDeleted: '已删除专用配置',
|
|
230
|
+
setTranslateEmpty: '填写 API Key 后,模型列表会自动出现在这里。',
|
|
231
|
+
setTranslateDiscovered: '已获取 {n} 个模型,请选择翻译模型', setTranslateSaved: '翻译模型已保存,仅影响翻译',
|
|
232
|
+
setTranslateConnected: '已连接', setTranslateSavedShort: '已保存', setTranslateSavedCount: '已保存 {n} 个', setTranslateNoModels: '暂无模型',
|
|
211
233
|
setBaseUrl: '端点 URL', setModel: '模型', setKey: 'API Key',
|
|
212
234
|
setSave: '测试并保存', setSaving: '测试连接中…', setClear: '清除自填配置',
|
|
213
235
|
setSaved: '已保存,立即生效', setCleared: '已清除,回落到部署方默认',
|
|
@@ -290,15 +312,20 @@ window.__ModuleLoader__.load({
|
|
|
290
312
|
setThemeStateLight: '浅色(不变深)',
|
|
291
313
|
// 嵌套子专题(方案 §B2):目录即层级;论文按文件夹整理
|
|
292
314
|
newSubTopic: '新建子专题', moveTopic: '移动到…', moveTopicTitle: '移动到(目标父专题路径,留空=顶层):',
|
|
315
|
+
movePaper: '移动到…', movePaperTitle: '移动论文', movePaperDestination: '目标专题',
|
|
316
|
+
movePaperHint: 'PDF、译文、笔记和学习记录一起移动;历史伴读会话不会删除,但会与新位置脱钩。',
|
|
317
|
+
moveDone: '已移动到「{topic}」', moveFail: '移动失败',
|
|
293
318
|
moveTopicHint: '整棵子树跟着移动;历史伴读会话不会删除,但会与树脱钩(确认框会给出数量)',
|
|
294
319
|
uploadHere: '上传 PDF 到此处',
|
|
320
|
+
topicActions: '专题操作', paperActions: '论文操作',
|
|
295
321
|
}
|
|
296
322
|
const en = {
|
|
297
|
-
library: 'Library',
|
|
323
|
+
library: 'Library', refresh: 'Refresh',
|
|
298
324
|
empty: 'Library is empty', hint: 'Create a topic or upload a PDF to start', newTopic: 'New topic',
|
|
299
325
|
cancel: 'Cancel', ok: 'OK', defaultTopic: 'Default', uploadBtn: 'Upload PDF',
|
|
300
326
|
newTopicFail: 'Failed to create topic',
|
|
301
327
|
rename: 'Rename', renameTopic: 'Rename topic', renamePaper: 'Rename paper',
|
|
328
|
+
renameInlineHint: 'Enter to save, Esc to cancel',
|
|
302
329
|
renameFail: 'Rename failed', delFail: 'Delete failed',
|
|
303
330
|
upload: 'Upload PDF into this topic', newChat: 'New chat', session: 'Session', pdfTab: 'Paper PDF',
|
|
304
331
|
history: 'Chat history',
|
|
@@ -309,8 +336,29 @@ window.__ModuleLoader__.load({
|
|
|
309
336
|
setRerankDesc: 'Semantic rerank for search_paper: keyword search shortlists candidates, Jev judges "can this passage answer the question" and reorders — plain-language questions hit terminology passages. Without it, plain keyword ranking is used.',
|
|
310
337
|
setEmbedTitle: 'Embedding search (optional)',
|
|
311
338
|
setEmbedDesc: 'Semantic recall for search_paper: chunk texts are sent to this OpenAI-compatible /embeddings endpoint so passages that share no keywords but are semantically close still enter the candidate set (fused with keyword hits, never replacing them). Leave empty to keep it off — search behaviour stays exactly as today. Note: chunk texts (paper body) are sent to this endpoint.',
|
|
312
|
-
setTranslateTitle: '
|
|
313
|
-
setTranslateDesc: '
|
|
339
|
+
setTranslateTitle: 'Translation model',
|
|
340
|
+
setTranslateDesc: 'Shared by generated Chinese PDFs and selection translation. Follow Harness by default, or override only translation without changing Harness settings.',
|
|
341
|
+
setTranslateFollow: 'Follow Harness', setTranslateCustom: 'Use a custom model', setTranslateDefault: 'Default',
|
|
342
|
+
setTranslateFollowDesc: 'Track the current Harness model', setTranslateCustomDesc: 'Use a separate endpoint only for translation',
|
|
343
|
+
setTranslateCurrentFollow: 'Currently following',
|
|
344
|
+
setTranslateFollowNote: 'New translations follow Harness model changes; an in-flight PDF keeps its original model.',
|
|
345
|
+
setTranslateUnavailable: 'The current Harness model is unavailable. Finish Harness model setup first.',
|
|
346
|
+
setTranslateProviders: 'Translation provider', setTranslateApplyKey: 'Get an API key',
|
|
347
|
+
setTranslateKeyAuto: 'Paste a key to validate and fetch models automatically; choose a model to save.',
|
|
348
|
+
setTranslateDiscovering: 'Validating key and fetching models…', setTranslateModels: 'Translation model',
|
|
349
|
+
setTranslateRefresh: 'Refresh', setTranslateAdvanced: 'Advanced: whole-PDF translation options',
|
|
350
|
+
setTranslateSplitTokens: 'Context per chunk (tokens)', setTranslateSplitHint: 'Longer chunks are split automatically. Lower this to reduce per-request context; raise it for fewer requests.',
|
|
351
|
+
setTranslateMaxOutput: 'Output cap per request (tokens)', setTranslateMaxOutputHint: '0 uses the provider default and omits max_tokens.',
|
|
352
|
+
setTranslateQps: 'Requests per second (QPS)', setTranslateQpsHint: 'High values can trigger rate limits. Lower this after HTTP 429 responses.',
|
|
353
|
+
setTranslateOptionsSave: 'Save translation options', setTranslateOptionsSaved: 'Translation options saved; applies to the next PDF task',
|
|
354
|
+
setTranslateManualModel: 'Manual model ID', setTranslateUse: 'Use', setTranslateUsing: 'In use',
|
|
355
|
+
setTranslateFollowSet: 'Translation now follows Harness; custom endpoints are kept',
|
|
356
|
+
setTranslateScopeFollow: 'Follow mode never copies Harness keys or changes Harness configuration.',
|
|
357
|
+
setTranslateScopeCustom: 'This endpoint is used only for translation and never changes Harness model settings.',
|
|
358
|
+
setTranslateDelete: 'Delete this endpoint', setTranslateDeleteConfirm: 'Confirm delete?', setTranslateDeleted: 'Custom endpoint deleted',
|
|
359
|
+
setTranslateEmpty: 'Enter an API key above and available models will appear here.',
|
|
360
|
+
setTranslateDiscovered: 'Found {n} models. Choose one for translation.', setTranslateSaved: 'Translation model saved; Harness is unchanged',
|
|
361
|
+
setTranslateConnected: 'Connected', setTranslateSavedShort: 'Saved', setTranslateSavedCount: '{n} saved', setTranslateNoModels: 'No models yet',
|
|
314
362
|
setBaseUrl: 'Endpoint URL', setModel: 'Model', setKey: 'API Key',
|
|
315
363
|
setSave: 'Test & save', setSaving: 'Testing…', setClear: 'Clear my config',
|
|
316
364
|
setSaved: 'Saved, effective immediately', setCleared: 'Cleared, falling back to deployment defaults',
|
|
@@ -383,8 +431,12 @@ window.__ModuleLoader__.load({
|
|
|
383
431
|
setThemeStateDark: 'dark applied',
|
|
384
432
|
setThemeStateLight: 'light (unchanged)',
|
|
385
433
|
newSubTopic: 'New subtopic', moveTopic: 'Move to...', moveTopicTitle: 'Move to (target parent topic path, empty = top level):',
|
|
434
|
+
movePaper: 'Move to...', movePaperTitle: 'Move paper', movePaperDestination: 'Destination topic',
|
|
435
|
+
movePaperHint: 'The PDF, translations, notes, and study progress move together. Past chats are kept but detach from the new location.',
|
|
436
|
+
moveDone: 'Moved to "{topic}"', moveFail: 'Move failed',
|
|
386
437
|
moveTopicHint: 'The whole subtree moves with it; past chats are kept but detach from the tree (the count is reported).',
|
|
387
438
|
uploadHere: 'Upload a PDF here',
|
|
439
|
+
topicActions: 'Topic actions', paperActions: 'Paper actions',
|
|
388
440
|
}
|
|
389
441
|
|
|
390
442
|
let t = (k) => k
|
|
@@ -413,7 +465,7 @@ window.__ModuleLoader__.load({
|
|
|
413
465
|
function pushThemeToReader() {
|
|
414
466
|
const payload = { type: 'dpr:theme' }
|
|
415
467
|
try {
|
|
416
|
-
const mir = JSON.parse(localStorage.getItem(
|
|
468
|
+
const mir = JSON.parse(localStorage.getItem('dpr.pdfThemeCfg') || 'null')
|
|
417
469
|
if (mir) { payload.mode = mir.mode; payload.strength = mir.strength; payload.chrome = mir.chrome; payload.curve = mir.curve }
|
|
418
470
|
} catch { /* 镜像损坏:仍然推宿主亮暗 */ }
|
|
419
471
|
const effective = payload.mode === 'dark' || (payload.mode !== 'off' && payload.mode !== 'light' && dprHostDark) ? 'dark' : 'light'
|
|
@@ -874,27 +926,169 @@ window.__ModuleLoader__.load({
|
|
|
874
926
|
|
|
875
927
|
/* ---------- 侧栏文献库树(接管 sidebar.workspaces) ---------- */
|
|
876
928
|
const S = {
|
|
877
|
-
root: { padding: '
|
|
878
|
-
head: { display: 'flex', alignItems: 'center', gap: '
|
|
879
|
-
|
|
929
|
+
root: { padding: '6px 0 14px', fontSize: '13px', color: 'var(--dsw-alias-label-primary, #24292f)' },
|
|
930
|
+
head: { display: 'flex', alignItems: 'center', gap: '3px', minHeight: '38px', padding: '4px 10px 7px 14px', fontSize: '12px', fontWeight: 600, color: 'var(--dsw-alias-label-secondary, #656d76)' },
|
|
931
|
+
headTitle: { display: 'flex', alignItems: 'center', gap: '7px', flex: 1, minWidth: 0 },
|
|
932
|
+
iconBtn: { width: '26px', height: '26px', flex: 'none', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer', border: 'none', borderRadius: '6px', background: 'none', color: 'inherit', padding: 0 },
|
|
880
933
|
// 页内弹窗(Electron 无 window.prompt)与空库入口按钮
|
|
881
934
|
// 主按钮固定蓝底白字:部分深色主题把 button-primary-fill/foreground 同时映射成白色(issue #20)。
|
|
882
935
|
btnPrimary: { fontSize: '13px', padding: '5px 14px', borderRadius: '6px', border: 'none', cursor: 'pointer', background: '#1f6feb', color: '#fff' },
|
|
883
936
|
btnGhost: { fontSize: '13px', padding: '5px 14px', borderRadius: '6px', cursor: 'pointer', background: 'none', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', color: 'var(--dsw-alias-label-secondary, #656d76)' },
|
|
884
|
-
linkBtn: { display: 'inline-flex', alignItems: 'center', gap: '
|
|
885
|
-
topicHead: { display: 'flex', alignItems: 'center', gap: '6px', padding: '5px
|
|
886
|
-
caret: {
|
|
887
|
-
items: { marginLeft: '
|
|
888
|
-
item: { display: 'flex', alignItems: 'center', gap: '
|
|
889
|
-
|
|
937
|
+
linkBtn: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', padding: '5px 10px', borderRadius: '6px', cursor: 'pointer', background: 'none', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', color: 'var(--dsw-alias-label-action-primary, #0969da)' },
|
|
938
|
+
topicHead: { position: 'relative', display: 'flex', alignItems: 'center', gap: '6px', minHeight: '32px', padding: '4px 5px 4px 7px', margin: '2px 7px 0', borderRadius: '7px', cursor: 'pointer', fontWeight: 550, userSelect: 'none', outline: 'none' },
|
|
939
|
+
caret: { width: '14px', height: '14px', flex: 'none', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: 'var(--dsw-alias-label-tertiary, #8c959f)', transition: 'transform .14s ease' },
|
|
940
|
+
items: { position: 'relative', marginLeft: '20px', paddingLeft: '4px', borderLeft: '1px solid var(--dsw-alias-border-l2, #e5e8eb)' },
|
|
941
|
+
item: { position: 'relative', display: 'flex', alignItems: 'center', gap: '7px', minHeight: '31px', padding: '4px 5px 4px 8px', margin: '1px 7px 0 3px', borderRadius: '7px', cursor: 'pointer', whiteSpace: 'nowrap', color: 'var(--dsw-alias-label-secondary, #656d76)', outline: 'none' },
|
|
942
|
+
rowLabel: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
943
|
+
count: { flex: 'none', minWidth: '18px', padding: '0 5px', borderRadius: '9px', background: 'var(--dsw-alias-bg-inset, rgba(127,127,127,.09))', color: 'var(--dsw-alias-label-tertiary, #8c959f)', fontSize: '10.5px', fontWeight: 500, lineHeight: '18px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
|
|
944
|
+
active: { background: 'var(--dsw-alias-bg-active, rgba(9,105,218,.12))', color: 'var(--dsw-alias-label-primary, #24292f)', fontWeight: 600 },
|
|
890
945
|
sessionItem: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)' },
|
|
891
|
-
empty: { padding: '
|
|
946
|
+
empty: { padding: '12px 14px', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)', lineHeight: 1.6 },
|
|
892
947
|
running: { color: 'var(--dsw-alias-state-success-primary, #1a7f37)', fontSize: '9px' },
|
|
893
948
|
// 收起态(rail):官方 rail 的控件是 36×36 圆形按钮、左对齐
|
|
894
949
|
rail: { display: 'flex', flexDirection: 'column', alignItems: 'flex-start' },
|
|
895
950
|
railBtn: { width: '36px', height: '36px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', border: 'none', background: 'none', borderRadius: '50%', color: 'var(--dsw-alias-label-primary, #24292f)', cursor: 'pointer', fontSize: '17px', padding: '0' },
|
|
896
951
|
}
|
|
897
952
|
|
|
953
|
+
// 同一套细线图标贯穿文献库;不再混用平台相关的彩色 emoji。
|
|
954
|
+
function LibraryIcon({ name, size = 16 }) {
|
|
955
|
+
const paths = {
|
|
956
|
+
chevron: [h('path', { key: 1, d: 'm6 9 6 6 6-6' })],
|
|
957
|
+
folder: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' })],
|
|
958
|
+
library: [h('path', { key: 1, d: 'M4 19.5A2.5 2.5 0 0 1 6.5 17H20V3H6.5A2.5 2.5 0 0 0 4 5.5Z' }), h('path', { key: 2, d: 'M4 5.5v14A2.5 2.5 0 0 0 6.5 22H20M9 7h7' })],
|
|
959
|
+
paper: [h('path', { key: 1, d: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8Z' }), h('path', { key: 2, d: 'M14 2v6h6M8 13h8M8 17h5' })],
|
|
960
|
+
upload: [h('path', { key: 1, d: 'M12 16V4m-5 5 5-5 5 5M5 20h14' })],
|
|
961
|
+
plus: [h('path', { key: 1, d: 'M12 5v14M5 12h14' })],
|
|
962
|
+
refresh: [h('path', { key: 1, d: 'M20 6v5h-5M4 18v-5h5' }), h('path', { key: 2, d: 'M18.5 9A7 7 0 0 0 6 6.5L4 11m2 4a7 7 0 0 0 12 2.5l2-4.5' })],
|
|
963
|
+
more: [h('circle', { key: 1, cx: 5, cy: 12, r: 1 }), h('circle', { key: 2, cx: 12, cy: 12, r: 1 }), h('circle', { key: 3, cx: 19, cy: 12, r: 1 })],
|
|
964
|
+
rename: [h('path', { key: 1, d: 'M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L8 18l-4 1 1-4Z' })],
|
|
965
|
+
move: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' }), h('path', { key: 2, d: 'M9 13h8m-3-3 3 3-3 3' })],
|
|
966
|
+
subtopic: [h('path', { key: 1, d: 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z' }), h('path', { key: 2, d: 'M12 10v6m-3-3h6' })],
|
|
967
|
+
trash: [h('path', { key: 1, d: 'M3 6h18M8 6V4h8v2m3 0-1 14H6L5 6m5 5v5m4-5v5' })],
|
|
968
|
+
}
|
|
969
|
+
return h('svg', {
|
|
970
|
+
width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
|
|
971
|
+
strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: 'false',
|
|
972
|
+
}, paths[name] || paths.paper)
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/* 行尾只留一个「更多」入口;菜单 portal 到 body,避免被侧栏滚动区裁掉。 */
|
|
976
|
+
function RowMenu({ label, items }) {
|
|
977
|
+
const [open, setOpen] = useState(false)
|
|
978
|
+
const [pos, setPos] = useState(null)
|
|
979
|
+
const anchor = React.useRef(null)
|
|
980
|
+
const menu = React.useRef(null)
|
|
981
|
+
const close = useCallback((focus = false) => {
|
|
982
|
+
setOpen(false)
|
|
983
|
+
if (focus) anchor.current?.focus()
|
|
984
|
+
}, [])
|
|
985
|
+
useEffect(() => {
|
|
986
|
+
if (!open) return
|
|
987
|
+
const rect = anchor.current?.getBoundingClientRect()
|
|
988
|
+
if (!rect) { setOpen(false); return }
|
|
989
|
+
const width = 168
|
|
990
|
+
const estimatedHeight = items.length * 34 + 10
|
|
991
|
+
setPos({
|
|
992
|
+
left: Math.max(8, Math.min(window.innerWidth - width - 8, rect.right - width)),
|
|
993
|
+
top: rect.bottom + estimatedHeight + 8 > window.innerHeight ? Math.max(8, rect.top - estimatedHeight - 4) : rect.bottom + 4,
|
|
994
|
+
})
|
|
995
|
+
const onPointer = (e) => {
|
|
996
|
+
if (!anchor.current?.contains(e.target) && !menu.current?.contains(e.target)) close()
|
|
997
|
+
}
|
|
998
|
+
const onKey = (e) => { if (e.key === 'Escape') { e.preventDefault(); close(true) } }
|
|
999
|
+
const onScroll = () => close()
|
|
1000
|
+
document.addEventListener('pointerdown', onPointer)
|
|
1001
|
+
document.addEventListener('keydown', onKey)
|
|
1002
|
+
window.addEventListener('resize', onScroll)
|
|
1003
|
+
window.addEventListener('scroll', onScroll, true)
|
|
1004
|
+
return () => {
|
|
1005
|
+
document.removeEventListener('pointerdown', onPointer)
|
|
1006
|
+
document.removeEventListener('keydown', onKey)
|
|
1007
|
+
window.removeEventListener('resize', onScroll)
|
|
1008
|
+
window.removeEventListener('scroll', onScroll, true)
|
|
1009
|
+
}
|
|
1010
|
+
}, [open, close, items.length])
|
|
1011
|
+
return h(React.Fragment, null,
|
|
1012
|
+
h('button', {
|
|
1013
|
+
ref: anchor, type: 'button', className: 'dpr-row-menu-trigger', style: S.iconBtn,
|
|
1014
|
+
title: label, 'aria-label': label, 'aria-haspopup': 'menu', 'aria-expanded': open,
|
|
1015
|
+
onClick: (e) => { e.stopPropagation(); setOpen((v) => !v) },
|
|
1016
|
+
}, h(LibraryIcon, { name: 'more', size: 17 })),
|
|
1017
|
+
open && pos && createPortal(h('div', {
|
|
1018
|
+
ref: menu, className: 'dpr-row-menu', role: 'menu', 'aria-label': label,
|
|
1019
|
+
style: { position: 'fixed', left: pos.left, top: pos.top },
|
|
1020
|
+
onClick: (e) => e.stopPropagation(),
|
|
1021
|
+
}, items.map((item, index) => h('button', {
|
|
1022
|
+
key: item.key, type: 'button', role: 'menuitem', 'data-dpr-act': item.key, autoFocus: index === 0,
|
|
1023
|
+
className: item.danger ? 'danger' : '',
|
|
1024
|
+
onClick: () => { close(true); item.onSelect() },
|
|
1025
|
+
}, h(LibraryIcon, { name: item.icon, size: 15 }), h('span', null, item.label)))), document.body))
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
/* 文件名原地重命名:Enter 保存,Esc / 失焦取消;不经过 Electron 不支持的 prompt。 */
|
|
1029
|
+
function InlineRename({ initial, label, onSave, onCancel }) {
|
|
1030
|
+
const [value, setValue] = useState(initial)
|
|
1031
|
+
const [busy, setBusy] = useState(false)
|
|
1032
|
+
const busyRef = React.useRef(false)
|
|
1033
|
+
const input = React.useRef(null)
|
|
1034
|
+
useEffect(() => { input.current?.focus(); input.current?.select() }, [])
|
|
1035
|
+
const submit = async () => {
|
|
1036
|
+
const name = value.trim()
|
|
1037
|
+
if (!name || name === initial || busyRef.current) { if (!busyRef.current) onCancel(); return }
|
|
1038
|
+
busyRef.current = true
|
|
1039
|
+
setBusy(true)
|
|
1040
|
+
const ok = await onSave(name)
|
|
1041
|
+
busyRef.current = false
|
|
1042
|
+
setBusy(false)
|
|
1043
|
+
if (!ok) input.current?.focus()
|
|
1044
|
+
}
|
|
1045
|
+
return h('input', {
|
|
1046
|
+
ref: input, value, type: 'text', disabled: busy, title: t('renameInlineHint'),
|
|
1047
|
+
'aria-label': label, 'data-dpr-rename': '',
|
|
1048
|
+
style: { flex: 1, minWidth: 0, width: '100%', boxSizing: 'border-box', padding: '2px 5px', border: '1px solid var(--dsw-alias-label-action-primary, #0969da)', borderRadius: '5px', background: 'var(--dsw-alias-bg-layer-1, #fff)', color: 'var(--dsw-alias-label-primary, #24292f)', font: 'inherit', fontSize: '12.5px', lineHeight: '20px', outline: 'none' },
|
|
1049
|
+
onChange: (e) => setValue(e.target.value),
|
|
1050
|
+
onClick: (e) => e.stopPropagation(),
|
|
1051
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
1052
|
+
onBlur: () => { if (!busyRef.current) onCancel() },
|
|
1053
|
+
onKeyDown: (e) => {
|
|
1054
|
+
e.stopPropagation()
|
|
1055
|
+
if (e.key === 'Enter') { e.preventDefault(); void submit() }
|
|
1056
|
+
else if (e.key === 'Escape') { e.preventDefault(); onCancel() }
|
|
1057
|
+
},
|
|
1058
|
+
})
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function MovePaperDialog({ topics, currentTopic, onConfirm, onCancel }) {
|
|
1062
|
+
const [destination, setDestination] = useState(currentTopic)
|
|
1063
|
+
const [busy, setBusy] = useState(false)
|
|
1064
|
+
const submit = async () => {
|
|
1065
|
+
setBusy(true)
|
|
1066
|
+
const ok = await onConfirm(destination)
|
|
1067
|
+
setBusy(false)
|
|
1068
|
+
if (ok) onCancel()
|
|
1069
|
+
}
|
|
1070
|
+
return h('div', {
|
|
1071
|
+
style: { position: 'fixed', inset: 0, zIndex: 99999, background: 'rgba(0,0,0,.35)', display: 'flex', alignItems: 'center', justifyContent: 'center', font: 'inherit' },
|
|
1072
|
+
onClick: onCancel,
|
|
1073
|
+
}, h('div', {
|
|
1074
|
+
role: 'dialog', 'aria-label': t('movePaperTitle'),
|
|
1075
|
+
style: { width: '340px', maxWidth: '90vw', padding: '18px', borderRadius: '12px', boxShadow: '0 12px 36px rgba(0,0,0,.28)', background: 'var(--dsw-alias-bg-layer-1, #fff)', color: 'var(--dsw-alias-label-primary, #24292f)' },
|
|
1076
|
+
onClick: (e) => e.stopPropagation(),
|
|
1077
|
+
},
|
|
1078
|
+
h('div', { style: { fontSize: '14px', fontWeight: 600, marginBottom: '14px' } }, t('movePaperTitle')),
|
|
1079
|
+
h('label', { style: { display: 'block', fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #656d76)', marginBottom: '6px' } }, t('movePaperDestination')),
|
|
1080
|
+
h('select', {
|
|
1081
|
+
value: destination, disabled: busy, autoFocus: true,
|
|
1082
|
+
style: { width: '100%', boxSizing: 'border-box', padding: '7px 9px', border: '1px solid var(--dsw-alias-border-l1, #d0d7de)', borderRadius: '7px', background: 'var(--dsw-alias-bg-layer-2, #f6f8fa)', color: 'inherit', font: 'inherit', fontSize: '13px' },
|
|
1083
|
+
onChange: (e) => setDestination(e.target.value),
|
|
1084
|
+
onKeyDown: (e) => { if (e.key === 'Escape') onCancel() },
|
|
1085
|
+
}, topics.map((topic) => h('option', { key: topic, value: topic }, topic))),
|
|
1086
|
+
h('div', { style: { marginTop: '10px', color: 'var(--dsw-alias-label-secondary, #656d76)', fontSize: '11.5px', lineHeight: 1.6 } }, t('movePaperHint')),
|
|
1087
|
+
h('div', { style: { display: 'flex', gap: '8px', justifyContent: 'flex-end', marginTop: '16px' } },
|
|
1088
|
+
h('button', { type: 'button', style: S.btnGhost, disabled: busy, onClick: onCancel }, t('cancel')),
|
|
1089
|
+
h('button', { type: 'button', style: { ...S.btnPrimary, ...(destination === currentTopic || busy ? { opacity: .5, cursor: 'default' } : {}) }, disabled: destination === currentTopic || busy, onClick: () => void submit() }, t('movePaper')))))
|
|
1090
|
+
}
|
|
1091
|
+
|
|
898
1092
|
/* ---------- 页内文本输入弹窗:Electron 渲染进程不实现 window.prompt
|
|
899
1093
|
(实测同版本 Electron 调用即抛 "prompt() is not supported",桌面端点「+」
|
|
900
1094
|
曾因此毫无反应),一律走 createPortal 挂 document.body,避免被侧栏 overflow 裁剪。 ---------- */
|
|
@@ -1138,6 +1332,7 @@ window.__ModuleLoader__.load({
|
|
|
1138
1332
|
// 子专题:目标父路径('' = 顶层);目录即层级 ⇒ 后端 mkdir recursive + 父目录必须存在
|
|
1139
1333
|
const [askSub, setAskSub] = useState(null) // { parent }
|
|
1140
1334
|
const [moving, setMoving] = useState(null) // { topic }
|
|
1335
|
+
const [movingPaper, setMovingPaper] = useState(null) // { topic, name }
|
|
1141
1336
|
const createSubTopic = useCallback(async (parent, name) => {
|
|
1142
1337
|
const path = parent ? `${parent}/${name}` : name
|
|
1143
1338
|
try {
|
|
@@ -1169,7 +1364,7 @@ window.__ModuleLoader__.load({
|
|
|
1169
1364
|
// 与删除一致:改名失败也可能带回 rollbackFailed(部分产物名字没能回滚)→ 必须给出恢复指引
|
|
1170
1365
|
const f = clearFailureText(err, t)
|
|
1171
1366
|
toast(t('renameFail') + ': ' + f.text + (f.recovery ? ' ' + f.recovery : ''), f.recovery ? 15000 : 6000)
|
|
1172
|
-
return
|
|
1367
|
+
return false
|
|
1173
1368
|
}
|
|
1174
1369
|
// 我们分支的加固实现会回 detachedSessions(会话 id 内嵌旧 topic/name → 改名后不再挂树上,
|
|
1175
1370
|
// 但会话本体不删除)。上游 UI 不提示这一点,用户会以为会话丢了——保留我们的提示。
|
|
@@ -1201,6 +1396,34 @@ window.__ModuleLoader__.load({
|
|
|
1201
1396
|
window.dispatchEvent(new CustomEvent('dpr:paper', { detail: { topic: newTopicName, name: newName } }))
|
|
1202
1397
|
}
|
|
1203
1398
|
refresh()
|
|
1399
|
+
return true
|
|
1400
|
+
}, [cur, refresh])
|
|
1401
|
+
|
|
1402
|
+
const doMovePaper = useCallback(async (topic, name, toTopic) => {
|
|
1403
|
+
try {
|
|
1404
|
+
const r = await api('/library/move-paper', {
|
|
1405
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
1406
|
+
body: JSON.stringify({ topic, name, toTopic }),
|
|
1407
|
+
})
|
|
1408
|
+
migrateLsKeys(topic, toTopic, name, name)
|
|
1409
|
+
setSessions((m) => { const c = { ...m }; delete c[`${topic}/${name}`]; return c })
|
|
1410
|
+
setClosed((c) => {
|
|
1411
|
+
const next = { ...c, [toTopic]: false }
|
|
1412
|
+
try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
|
|
1413
|
+
return next
|
|
1414
|
+
})
|
|
1415
|
+
if (cur && cur.topic === topic && cur.name === name) {
|
|
1416
|
+
setCur((c) => ({ ...c, topic: toTopic }))
|
|
1417
|
+
window.dispatchEvent(new CustomEvent('dpr:paper', { detail: { topic: toTopic, name } }))
|
|
1418
|
+
}
|
|
1419
|
+
toast(t('moveDone').replace('{topic}', toTopic) + (r.detachedSessions ? ' · ' + t('renameDetached').replace('{n}', String(r.detachedSessions)) : ''), r.detachedSessions ? 6000 : 3000)
|
|
1420
|
+
refresh()
|
|
1421
|
+
return true
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
const f = clearFailureText(err, t)
|
|
1424
|
+
toast(t('moveFail') + ': ' + f.text + (f.recovery ? ' ' + f.recovery : ''), f.recovery ? 15000 : 6000)
|
|
1425
|
+
return false
|
|
1426
|
+
}
|
|
1204
1427
|
}, [cur, refresh])
|
|
1205
1428
|
|
|
1206
1429
|
// 删除不走上游的「同一按钮点两次(3s arm)」:改用我们的「服务端删除计划 + 页内确认框」
|
|
@@ -1232,6 +1455,15 @@ window.__ModuleLoader__.load({
|
|
|
1232
1455
|
|
|
1233
1456
|
const topics = lib?.topics ?? []
|
|
1234
1457
|
const papers = lib?.papers ?? []
|
|
1458
|
+
const destinationTopics = []
|
|
1459
|
+
const collectDestinationTopics = (nodes) => {
|
|
1460
|
+
for (const node of nodes || []) {
|
|
1461
|
+
destinationTopics.push(node.path || node.name)
|
|
1462
|
+
collectDestinationTopics(node.children)
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
collectDestinationTopics(lib?.tree)
|
|
1466
|
+
if (destinationTopics.length === 0) destinationTopics.push(...topics)
|
|
1235
1467
|
|
|
1236
1468
|
// 头部「⬆」与空库按钮共用:定位目标专题,没有专题时先自动建「默认专题」
|
|
1237
1469
|
// (宿主端 mkdir recursive,重名无害)再弹文件选择——空库不再是无入口的死路。
|
|
@@ -1413,52 +1645,81 @@ window.__ModuleLoader__.load({
|
|
|
1413
1645
|
const childPapers = papersOf(path)
|
|
1414
1646
|
const children = node.children || []
|
|
1415
1647
|
const hasKids = children.length > 0 || childPapers.length > 0
|
|
1416
|
-
|
|
1648
|
+
const paperCount = dprTopicPaperCount(papers, path)
|
|
1649
|
+
const renamingThis = renaming?.kind === 'topic' && renaming.topic === path
|
|
1650
|
+
const toggle = () => {
|
|
1651
|
+
const next = { ...closed, [path]: !collapsed }
|
|
1652
|
+
setClosed(next)
|
|
1653
|
+
try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
|
|
1654
|
+
}
|
|
1655
|
+
const onRowKey = (e, action) => {
|
|
1656
|
+
if (e.target !== e.currentTarget) return
|
|
1657
|
+
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); action() }
|
|
1658
|
+
}
|
|
1659
|
+
return h('div', { key: path, 'data-dpr-node': '' },
|
|
1417
1660
|
h('div', {
|
|
1418
|
-
style:
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
setClosed(next)
|
|
1422
|
-
try { localStorage.setItem('dpr.treeClosed', JSON.stringify(next)) } catch {}
|
|
1423
|
-
},
|
|
1661
|
+
style: S.topicHead, className: 'dpr-topic-row', role: 'treeitem', tabIndex: 0,
|
|
1662
|
+
'aria-expanded': !collapsed, 'data-dpr-row': '', 'data-dpr-topic': path,
|
|
1663
|
+
onClick: toggle, onKeyDown: (e) => onRowKey(e, toggle),
|
|
1424
1664
|
},
|
|
1425
|
-
h('span', { style: { ...S.caret, transform: collapsed ? 'rotate(-90deg)' : 'none' } }, '
|
|
1426
|
-
h('span', {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1665
|
+
h('span', { style: { ...S.caret, visibility: hasKids ? 'visible' : 'hidden', transform: collapsed ? 'rotate(-90deg)' : 'none' } }, h(LibraryIcon, { name: 'chevron', size: 14 })),
|
|
1666
|
+
h('span', { className: 'dpr-topic-icon', 'aria-hidden': true }, h(LibraryIcon, { name: 'folder', size: 16 })),
|
|
1667
|
+
renamingThis
|
|
1668
|
+
? h(InlineRename, {
|
|
1669
|
+
initial: node.name || path.split('/').pop(), label: t('renameTopic'),
|
|
1670
|
+
onSave: async (name) => {
|
|
1671
|
+
const parent = path.includes('/') ? path.slice(0, path.lastIndexOf('/') + 1) : ''
|
|
1672
|
+
const ok = await doRename('topic', path, null, parent + name)
|
|
1673
|
+
if (ok) setRenaming(null)
|
|
1674
|
+
return ok
|
|
1675
|
+
},
|
|
1676
|
+
onCancel: () => setRenaming(null),
|
|
1677
|
+
})
|
|
1678
|
+
: h('span', { style: S.rowLabel, title: path }, node.name || path),
|
|
1679
|
+
!renamingThis && paperCount > 0 ? h('span', { style: S.count, title: `${paperCount} PDF` }, paperCount) : null,
|
|
1680
|
+
!renamingThis && h(RowMenu, {
|
|
1681
|
+
label: t('topicActions'), items: [
|
|
1682
|
+
{ key: 'upload', icon: 'upload', label: t('uploadHere'), onSelect: () => upload(path) },
|
|
1683
|
+
{ key: 'subtopic', icon: 'subtopic', label: t('newSubTopic'), onSelect: () => setAskSub({ parent: path }) },
|
|
1684
|
+
{ key: 'rename', icon: 'rename', label: t('rename'), onSelect: () => setRenaming({ kind: 'topic', topic: path }) },
|
|
1685
|
+
{ key: 'move', icon: 'move', label: t('moveTopic'), onSelect: () => setMoving({ topic: path }) },
|
|
1686
|
+
{ key: 'del', icon: 'trash', label: t('delTopic'), danger: true, onSelect: () => openDelete('topic', path, path) },
|
|
1687
|
+
],
|
|
1688
|
+
}),
|
|
1441
1689
|
),
|
|
1442
|
-
!collapsed && h('div', { style: S.items },
|
|
1690
|
+
!collapsed && h('div', { style: S.items, role: 'group' },
|
|
1443
1691
|
// 论文节点(叶子):路径 = 父专题路径 + 论文名
|
|
1444
1692
|
childPapers.map((p) => {
|
|
1445
1693
|
const isCurrentPaper = cur && cur.topic === p.topic && cur.name === p.name
|
|
1694
|
+
const renamingThisPaper = renaming?.kind === 'paper' && renaming.topic === p.topic && renaming.name === p.name
|
|
1446
1695
|
return h('div', {
|
|
1447
1696
|
key: path + '/' + p.name,
|
|
1448
|
-
style: { ...S.item, ...(
|
|
1697
|
+
style: { ...S.item, ...(isCurrentPaper ? S.active : {}) },
|
|
1698
|
+
className: isCurrentPaper ? 'dpr-paper-row dpr-active' : 'dpr-paper-row',
|
|
1699
|
+
role: 'treeitem', tabIndex: 0, 'aria-current': isCurrentPaper ? 'page' : undefined,
|
|
1449
1700
|
'data-dpr-row': '', 'data-dpr-paper': path + '/' + p.name,
|
|
1450
1701
|
title: p.pdfPath || p.name,
|
|
1451
|
-
onClick: () => enter(p.topic, p.name),
|
|
1452
|
-
},
|
|
1453
|
-
h('span', {
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1702
|
+
onClick: () => enter(p.topic, p.name), onKeyDown: (e) => onRowKey(e, () => enter(p.topic, p.name)),
|
|
1703
|
+
},
|
|
1704
|
+
h('span', { className: 'dpr-paper-icon', 'aria-hidden': true }, h(LibraryIcon, { name: 'paper', size: 15 })),
|
|
1705
|
+
renamingThisPaper
|
|
1706
|
+
? h(InlineRename, {
|
|
1707
|
+
initial: p.name, label: t('renamePaper'),
|
|
1708
|
+
onSave: async (name) => {
|
|
1709
|
+
const ok = await doRename('paper', p.topic, p.name, name)
|
|
1710
|
+
if (ok) setRenaming(null)
|
|
1711
|
+
return ok
|
|
1712
|
+
},
|
|
1713
|
+
onCancel: () => setRenaming(null),
|
|
1714
|
+
})
|
|
1715
|
+
: h('span', { style: S.rowLabel }, p.name),
|
|
1716
|
+
!renamingThisPaper && h(RowMenu, {
|
|
1717
|
+
label: t('paperActions'), items: [
|
|
1718
|
+
{ key: 'rename', icon: 'rename', label: t('rename'), onSelect: () => setRenaming({ kind: 'paper', topic: p.topic, name: p.name }) },
|
|
1719
|
+
{ key: 'move', icon: 'move', label: t('movePaper'), onSelect: () => setMovingPaper({ topic: p.topic, name: p.name }) },
|
|
1720
|
+
{ key: 'del', icon: 'trash', label: t('delPaper'), danger: true, onSelect: () => openDelete('paper', p.topic, p.name) },
|
|
1721
|
+
],
|
|
1722
|
+
}))
|
|
1462
1723
|
}),
|
|
1463
1724
|
// 子专题(递归)
|
|
1464
1725
|
children.map((c) => renderNode(c, depth + 1)),
|
|
@@ -1472,23 +1733,26 @@ window.__ModuleLoader__.load({
|
|
|
1472
1733
|
h('button', {
|
|
1473
1734
|
type: 'button', style: S.railBtn, 'data-dpr-rail': '', title: t('library'),
|
|
1474
1735
|
'aria-label': t('library'), onClick: () => expandSidebar && expandSidebar(),
|
|
1475
|
-
}, '
|
|
1736
|
+
}, h(LibraryIcon, { name: 'library', size: 19 })))
|
|
1476
1737
|
: h(React.Fragment, null,
|
|
1477
1738
|
h('div', { style: S.head },
|
|
1478
|
-
h('span', { style:
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
h('button', { style: S.iconBtn, title: '
|
|
1739
|
+
h('span', { style: S.headTitle },
|
|
1740
|
+
h('span', null, t('library')),
|
|
1741
|
+
papers.length > 0 ? h('span', { style: S.count }, papers.length) : null),
|
|
1742
|
+
h('button', { type: 'button', style: S.iconBtn, title: t('upload'), 'aria-label': t('upload'), onClick: () => uploadSmart() }, h(LibraryIcon, { name: 'upload', size: 15 })),
|
|
1743
|
+
h('button', { type: 'button', style: S.iconBtn, title: t('newTopic'), 'aria-label': t('newTopic'), onClick: newTopic }, h(LibraryIcon, { name: 'plus', size: 16 })),
|
|
1744
|
+
h('button', { type: 'button', style: S.iconBtn, title: t('refresh'), 'aria-label': t('refresh'), onClick: refresh }, h(LibraryIcon, { name: 'refresh', size: 15 })),
|
|
1482
1745
|
),
|
|
1483
1746
|
lib && topics.length === 0 && h('div', { style: S.empty },
|
|
1484
1747
|
`${t('empty')}:${t('hint')}`,
|
|
1485
|
-
h('div', { style: { display: 'flex', gap: '8px', margin: '
|
|
1486
|
-
h('button', { type: 'button', style: S.linkBtn, onClick: () => uploadSmart() },
|
|
1487
|
-
h('button', { type: 'button', style: S.linkBtn, onClick: newTopic },
|
|
1748
|
+
h('div', { style: { display: 'flex', gap: '8px', margin: '10px 0 2px' } },
|
|
1749
|
+
h('button', { type: 'button', style: S.linkBtn, onClick: () => uploadSmart() }, h(LibraryIcon, { name: 'upload', size: 14 }), t('uploadBtn')),
|
|
1750
|
+
h('button', { type: 'button', style: S.linkBtn, onClick: newTopic }, h(LibraryIcon, { name: 'plus', size: 14 }), t('newTopic')))),
|
|
1488
1751
|
// 递归渲染专题树(方案 §B2.3):专题节点可折叠,论文节点是叶子。
|
|
1489
1752
|
// 数据来自服务端 /api/library 的 `tree`(完整嵌套树);`papers` 里的 topic 是相对路径,
|
|
1490
1753
|
// 逐节点用 path 精确匹配(**不用前缀匹配** —— `A` 会误伤兄弟 `A/B`,R10 的教训)。
|
|
1491
|
-
(
|
|
1754
|
+
h('div', { role: 'tree', 'aria-label': t('library') },
|
|
1755
|
+
(lib?.tree ?? topics.map((topic) => ({ name: topic, path: topic, papers: [], children: [] }))).map((node) => renderNode(node, 0))),
|
|
1492
1756
|
)
|
|
1493
1757
|
|
|
1494
1758
|
return h('div', {
|
|
@@ -1532,18 +1796,12 @@ window.__ModuleLoader__.load({
|
|
|
1532
1796
|
onCancel: () => setMoving(null),
|
|
1533
1797
|
}),
|
|
1534
1798
|
document.body),
|
|
1535
|
-
//
|
|
1536
|
-
|
|
1537
|
-
h(
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
onConfirm: (name) => {
|
|
1542
|
-
const r = renaming
|
|
1543
|
-
setRenaming(null)
|
|
1544
|
-
doRename(r.kind, r.topic, r.name, name)
|
|
1545
|
-
},
|
|
1546
|
-
onCancel: () => setRenaming(null),
|
|
1799
|
+
// 论文移动:目标专题直接选,避免手输嵌套路径;重命名则在树行内联完成。
|
|
1800
|
+
movingPaper && createPortal(
|
|
1801
|
+
h(MovePaperDialog, {
|
|
1802
|
+
topics: destinationTopics, currentTopic: movingPaper.topic,
|
|
1803
|
+
onConfirm: (toTopic) => doMovePaper(movingPaper.topic, movingPaper.name, toTopic),
|
|
1804
|
+
onCancel: () => setMovingPaper(null),
|
|
1547
1805
|
}),
|
|
1548
1806
|
document.body),
|
|
1549
1807
|
// 删除:确认框必须列出服务端给的清单;专题删除还要输入专题名
|
|
@@ -1717,6 +1975,295 @@ window.__ModuleLoader__.load({
|
|
|
1717
1975
|
)
|
|
1718
1976
|
}
|
|
1719
1977
|
|
|
1978
|
+
/* ---------- 全文翻译模型:默认跟随 Harness,可选插件内专用覆盖 ----------
|
|
1979
|
+
跟随只在每次任务开始时读 agentDefaultModel,由服务端经 ctx.llm 调用;
|
|
1980
|
+
自定义端点仍写插件自己的 translate.json,两个方向都不调用 Harness saveSelection。 */
|
|
1981
|
+
const TRANSLATE_PROVIDERS = [
|
|
1982
|
+
{ id: 'deepseek', name: 'DeepSeek', mark: 'DS', icon: 'deepseek.svg', baseUrl: 'https://api.deepseek.com/v1', keyUrl: 'https://platform.deepseek.com/api_keys' },
|
|
1983
|
+
{ id: 'openai', name: 'OpenAI', mark: '◎', icon: 'openai.svg', mono: true, baseUrl: 'https://api.openai.com/v1', keyUrl: 'https://platform.openai.com/api-keys' },
|
|
1984
|
+
{ id: 'anthropic', name: 'Anthropic', mark: 'A', icon: 'anthropic.svg', baseUrl: 'https://api.anthropic.com/v1', keyUrl: 'https://console.anthropic.com/settings/keys' },
|
|
1985
|
+
{ id: 'gemini', name: 'Gemini', mark: '✦', icon: 'gemini.svg', baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai', keyUrl: 'https://aistudio.google.com/app/apikey' },
|
|
1986
|
+
{ id: 'zhipu', name: '智谱 GLM', mark: 'GL', icon: 'zhipu.svg', baseUrl: 'https://open.bigmodel.cn/api/coding/paas/v4', keyUrl: 'https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys' },
|
|
1987
|
+
{ id: 'custom', name: '自定义', mark: '+', baseUrl: '', keyUrl: '' },
|
|
1988
|
+
]
|
|
1989
|
+
function translateProviderFor(baseUrl) {
|
|
1990
|
+
const u = (baseUrl || '').toLowerCase()
|
|
1991
|
+
if (/deepseek/.test(u)) return 'deepseek'
|
|
1992
|
+
if (/openai\.com/.test(u)) return 'openai'
|
|
1993
|
+
if (/anthropic/.test(u)) return 'anthropic'
|
|
1994
|
+
if (/googleapis\.com/.test(u)) return 'gemini'
|
|
1995
|
+
if (/bigmodel|z\.ai/.test(u)) return 'zhipu'
|
|
1996
|
+
return 'custom'
|
|
1997
|
+
}
|
|
1998
|
+
function TranslateProviderIcon({ provider, size = 22 }) {
|
|
1999
|
+
if (!provider.icon) return provider.mark || '+'
|
|
2000
|
+
return h('img', {
|
|
2001
|
+
src: '/paper-reader/vendor/' + provider.icon, alt: '', 'aria-hidden': 'true',
|
|
2002
|
+
'data-dpr-provider-icon': provider.id,
|
|
2003
|
+
style: { width: size, height: size, objectFit: 'contain', display: 'block', background: '#fff', borderRadius: 4 },
|
|
2004
|
+
})
|
|
2005
|
+
}
|
|
2006
|
+
function TranslateSettingsCard() {
|
|
2007
|
+
const [cfg, setCfg] = useState(null)
|
|
2008
|
+
const [mode, setMode] = useState('follow')
|
|
2009
|
+
const [providerId, setProviderId] = useState('deepseek')
|
|
2010
|
+
const [draft, setDraft] = useState({ id: 'new', baseUrl: TRANSLATE_PROVIDERS[0].baseUrl, model: '', apiKey: '' })
|
|
2011
|
+
const [models, setModels] = useState([])
|
|
2012
|
+
const [options, setOptions] = useState({ splitTokens: 100000, maxOutputTokens: 32768, qps: 16 })
|
|
2013
|
+
const [manualModel, setManualModel] = useState(false)
|
|
2014
|
+
const [busy, setBusy] = useState('')
|
|
2015
|
+
const [msg, setMsg] = useState(null)
|
|
2016
|
+
const [deleteArmed, setDeleteArmed] = useState(false)
|
|
2017
|
+
const modelRequest = useRef(0)
|
|
2018
|
+
const provider = TRANSLATE_PROVIDERS.find((p) => p.id === providerId) || TRANSLATE_PROVIDERS[0]
|
|
2019
|
+
const endpoints = (cfg?.endpoints || []).filter((e) => e.source !== 'harness')
|
|
2020
|
+
const endpointProvider = (e) => TRANSLATE_PROVIDERS.some((p) => p.id === e?.provider) ? e.provider : translateProviderFor(e?.baseUrl)
|
|
2021
|
+
const load = useCallback(() => {
|
|
2022
|
+
modelRequest.current += 1
|
|
2023
|
+
return api('/translate/config').then((d) => {
|
|
2024
|
+
setCfg(d)
|
|
2025
|
+
setOptions(d.options || { splitTokens: 100000, maxOutputTokens: 32768, qps: 16 })
|
|
2026
|
+
setMode(d.mode === 'follow' ? 'follow' : 'custom')
|
|
2027
|
+
const saved = (d.endpoints || []).filter((e) => e.source !== 'harness')
|
|
2028
|
+
const active = saved.find((e) => e.id === d.activeId) || saved[0] || null
|
|
2029
|
+
if (active) {
|
|
2030
|
+
setProviderId(TRANSLATE_PROVIDERS.some((p) => p.id === active.provider) ? active.provider : translateProviderFor(active.baseUrl))
|
|
2031
|
+
setDraft({ id: active.id, baseUrl: active.baseUrl || '', model: active.model || '', apiKey: '' })
|
|
2032
|
+
setModels(active.model ? [active.model] : [])
|
|
2033
|
+
} else {
|
|
2034
|
+
setProviderId('deepseek')
|
|
2035
|
+
setDraft({ id: 'new', baseUrl: TRANSLATE_PROVIDERS[0].baseUrl, model: '', apiKey: '' })
|
|
2036
|
+
setModels([])
|
|
2037
|
+
}
|
|
2038
|
+
setMsg(null)
|
|
2039
|
+
setDeleteArmed(false)
|
|
2040
|
+
}).catch((e) => setMsg({ ok: false, text: String(e.message || e) }))
|
|
2041
|
+
}, [])
|
|
2042
|
+
useEffect(load, [load])
|
|
2043
|
+
|
|
2044
|
+
const chooseProvider = (id) => {
|
|
2045
|
+
modelRequest.current += 1
|
|
2046
|
+
setBusy('')
|
|
2047
|
+
setProviderId(id)
|
|
2048
|
+
const preset = TRANSLATE_PROVIDERS.find((p) => p.id === id) || TRANSLATE_PROVIDERS[0]
|
|
2049
|
+
const saved = endpoints.find((e) => e.source === 'file' && endpointProvider(e) === id)
|
|
2050
|
+
setDraft({
|
|
2051
|
+
id: saved?.id || 'new',
|
|
2052
|
+
baseUrl: saved?.baseUrl || preset.baseUrl,
|
|
2053
|
+
model: saved?.model || '',
|
|
2054
|
+
apiKey: '',
|
|
2055
|
+
})
|
|
2056
|
+
setModels(saved?.model ? [saved.model] : [])
|
|
2057
|
+
setManualModel(false)
|
|
2058
|
+
setMsg(null)
|
|
2059
|
+
setDeleteArmed(false)
|
|
2060
|
+
}
|
|
2061
|
+
const discover = async () => {
|
|
2062
|
+
if (busy === 'save' || busy === 'follow') return
|
|
2063
|
+
const seq = ++modelRequest.current
|
|
2064
|
+
setBusy('models'); setMsg(null)
|
|
2065
|
+
try {
|
|
2066
|
+
const d = await api('/translate/models', {
|
|
2067
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2068
|
+
body: JSON.stringify({ id: draft.id, baseUrl: draft.baseUrl.trim(), apiKey: draft.apiKey.trim() }),
|
|
2069
|
+
})
|
|
2070
|
+
if (seq !== modelRequest.current) return
|
|
2071
|
+
setModels(d.models || [])
|
|
2072
|
+
setManualModel(false)
|
|
2073
|
+
setDraft((old) => ({ ...old, model: d.models?.includes(old.model) ? old.model : (d.models?.[0] || old.model) }))
|
|
2074
|
+
setMsg({ ok: true, text: t('setTranslateDiscovered').replace('{n}', String(d.models?.length || 0)) })
|
|
2075
|
+
} catch (e) {
|
|
2076
|
+
if (seq === modelRequest.current) { setManualModel(true); setMsg({ ok: false, text: String(e.message || e) }) }
|
|
2077
|
+
} finally {
|
|
2078
|
+
if (seq === modelRequest.current) setBusy('')
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
// 输入停顿后自动获取;已有 Key 的端点不会仅因打开设置页就发请求。
|
|
2082
|
+
useEffect(() => {
|
|
2083
|
+
if (mode !== 'custom' || !draft.apiKey.trim()) return
|
|
2084
|
+
const timer = setTimeout(() => { void discover() }, 700)
|
|
2085
|
+
return () => clearTimeout(timer)
|
|
2086
|
+
}, [draft.apiKey, draft.baseUrl, providerId, mode])
|
|
2087
|
+
|
|
2088
|
+
const follow = async () => {
|
|
2089
|
+
if (mode === 'follow') return
|
|
2090
|
+
modelRequest.current += 1
|
|
2091
|
+
setBusy('follow'); setMsg(null)
|
|
2092
|
+
try {
|
|
2093
|
+
await api('/translate/config/selection', {
|
|
2094
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: 'harness' }),
|
|
2095
|
+
})
|
|
2096
|
+
await load()
|
|
2097
|
+
setMode('follow')
|
|
2098
|
+
toast(t('setTranslateFollowSet'))
|
|
2099
|
+
} catch (e) { setMsg({ ok: false, text: String(e.message || e) }) } finally { setBusy('') }
|
|
2100
|
+
}
|
|
2101
|
+
const saveModel = async (model) => {
|
|
2102
|
+
const name = (model || '').trim()
|
|
2103
|
+
if (!name) return
|
|
2104
|
+
modelRequest.current += 1
|
|
2105
|
+
setBusy('save'); setMsg(null)
|
|
2106
|
+
try {
|
|
2107
|
+
await api('/translate/config', {
|
|
2108
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
2109
|
+
body: JSON.stringify({
|
|
2110
|
+
id: draft.id, label: provider.name, provider: provider.id,
|
|
2111
|
+
baseUrl: draft.baseUrl.trim(), apiKey: draft.apiKey.trim(), model: name,
|
|
2112
|
+
}),
|
|
2113
|
+
})
|
|
2114
|
+
await load()
|
|
2115
|
+
setMode('custom')
|
|
2116
|
+
setMsg({ ok: true, text: t('setTranslateSaved') })
|
|
2117
|
+
toast(t('setTranslateSaved'))
|
|
2118
|
+
} catch (e) { setMsg({ ok: false, text: String(e.message || e) }) } finally { setBusy('') }
|
|
2119
|
+
}
|
|
2120
|
+
const saveOptions = async () => {
|
|
2121
|
+
setBusy('options'); setMsg(null)
|
|
2122
|
+
try {
|
|
2123
|
+
const d = await api('/translate/config/options', {
|
|
2124
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ splitTokens: Number(options.splitTokens), maxOutputTokens: Number(options.maxOutputTokens), qps: Number(options.qps) }),
|
|
2125
|
+
})
|
|
2126
|
+
setOptions(d.options)
|
|
2127
|
+
setMsg({ ok: true, text: t('setTranslateOptionsSaved') })
|
|
2128
|
+
toast(t('setTranslateOptionsSaved'))
|
|
2129
|
+
} catch (e) { setMsg({ ok: false, text: String(e.message || e) }) } finally { setBusy('') }
|
|
2130
|
+
}
|
|
2131
|
+
const remove = async () => {
|
|
2132
|
+
if (!draft.id || draft.id === 'new' || draft.id === 'profile') return
|
|
2133
|
+
if (!deleteArmed) { setDeleteArmed(true); return }
|
|
2134
|
+
setBusy('delete'); setMsg(null)
|
|
2135
|
+
try {
|
|
2136
|
+
await api('/translate/config?id=' + encodeURIComponent(draft.id), { method: 'DELETE' })
|
|
2137
|
+
await api('/translate/config/selection', {
|
|
2138
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id: 'harness' }),
|
|
2139
|
+
})
|
|
2140
|
+
await load()
|
|
2141
|
+
setMode('follow')
|
|
2142
|
+
toast(t('setTranslateDeleted'))
|
|
2143
|
+
} catch (e) { setMsg({ ok: false, text: String(e.message || e) }) } finally { setBusy(''); setDeleteArmed(false) }
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
const modeStyle = (selected) => ({
|
|
2147
|
+
flex: 1, minWidth: 0, display: 'flex', alignItems: 'flex-start', gap: 9, textAlign: 'left',
|
|
2148
|
+
padding: '12px', borderRadius: '9px', cursor: 'pointer',
|
|
2149
|
+
border: `1px solid ${selected ? 'var(--dsw-alias-button-primary-fill, #5269d8)' : 'var(--dsw-alias-border-l1, #d8dce4)'}`,
|
|
2150
|
+
background: selected ? 'var(--dsw-alias-button-primary-fill-alpha-10, #fafaff)' : 'var(--dsw-alias-bg-layer-1, #fff)',
|
|
2151
|
+
boxShadow: selected ? '0 0 0 1px var(--dsw-alias-button-primary-fill, #5269d8)' : 'none',
|
|
2152
|
+
})
|
|
2153
|
+
const radio = (selected) => h('span', { style: { width: '15px', height: '15px', marginTop: 2, flex: 'none', borderRadius: '50%', border: `1.5px solid ${selected ? 'var(--dsw-alias-button-primary-fill, #5269d8)' : '#b8bec9'}`, display: 'grid', placeItems: 'center' } },
|
|
2154
|
+
selected ? h('span', { style: { width: 7, height: 7, borderRadius: '50%', background: 'var(--dsw-alias-button-primary-fill, #5269d8)' } }) : null)
|
|
2155
|
+
const small = { fontSize: '11px', lineHeight: 1.55, color: 'var(--dsw-alias-label-secondary, #6d7480)' }
|
|
2156
|
+
const badge = { width: 29, height: 29, flex: 'none', display: 'grid', placeItems: 'center', borderRadius: 8, border: '1px solid var(--dsw-alias-border-l1, #e5e7ec)', color: 'var(--dsw-alias-label-secondary, #5269d8)', background: 'var(--dsw-alias-bg-layer-2, #fff)', fontSize: 10, fontWeight: 650 }
|
|
2157
|
+
const savedForProvider = endpoints.some((e) => e.source === 'file' && endpointProvider(e) === providerId)
|
|
2158
|
+
const savedCount = endpoints.filter((e) => e.source === 'file').length
|
|
2159
|
+
const optionField = (key, label, hint, min, max) => h('div', { style: { marginTop: 10 } },
|
|
2160
|
+
h('label', { style: { ...SET.label, margin: '0 0 4px' } }, label),
|
|
2161
|
+
h('input', {
|
|
2162
|
+
type: 'number', min, max, step: 1, value: options[key], 'data-dpr-translate-option': key,
|
|
2163
|
+
style: SET.input,
|
|
2164
|
+
onChange: (e) => setOptions({ ...options, [key]: e.target.value }),
|
|
2165
|
+
}),
|
|
2166
|
+
h('p', { style: { ...small, margin: '5px 0 0' } }, hint),
|
|
2167
|
+
)
|
|
2168
|
+
|
|
2169
|
+
return h('div', { style: { ...SET.card, padding: 0, overflow: 'hidden' }, 'data-dsh-plugin': 'dsh-paper-reader', 'data-dsh-part': 'settings-card', 'data-dpr-translate-settings': mode },
|
|
2170
|
+
h('div', { style: { padding: '16px 16px 14px', borderBottom: '1px solid var(--dsw-alias-border-l1, #e5e7ec)' } },
|
|
2171
|
+
h('h3', { style: SET.title }, t('setTranslateTitle')),
|
|
2172
|
+
h('p', { style: { ...SET.desc, margin: 0 } }, t('setTranslateDesc')),
|
|
2173
|
+
),
|
|
2174
|
+
h('div', { style: { display: 'flex', gap: 9, padding: '14px 16px' }, role: 'radiogroup', 'aria-label': t('setTranslateTitle') },
|
|
2175
|
+
h('button', { type: 'button', role: 'radio', 'aria-checked': mode === 'follow', 'data-dpr-translate-follow': '', style: modeStyle(mode === 'follow'), onClick: follow },
|
|
2176
|
+
radio(mode === 'follow'),
|
|
2177
|
+
h('span', null,
|
|
2178
|
+
h('span', { style: { display: 'block', fontSize: 12, fontWeight: 650 } }, t('setTranslateFollow'), ' ', h('span', { style: { ...small, color: 'var(--dsw-alias-button-primary-fill, #5269d8)' } }, t('setTranslateDefault'))),
|
|
2179
|
+
h('span', { style: { ...small, display: 'block', marginTop: 5 } }, t('setTranslateFollowDesc')),
|
|
2180
|
+
),
|
|
2181
|
+
),
|
|
2182
|
+
h('button', { type: 'button', role: 'radio', 'aria-checked': mode === 'custom', 'data-dpr-translate-custom': '', style: modeStyle(mode === 'custom'), onClick: () => { setMode('custom'); setMsg(null) } },
|
|
2183
|
+
radio(mode === 'custom'),
|
|
2184
|
+
h('span', null,
|
|
2185
|
+
h('span', { style: { display: 'block', fontSize: 12, fontWeight: 650 } }, t('setTranslateCustom')),
|
|
2186
|
+
h('span', { style: { ...small, display: 'block', marginTop: 5 } }, t('setTranslateCustomDesc')),
|
|
2187
|
+
),
|
|
2188
|
+
),
|
|
2189
|
+
),
|
|
2190
|
+
mode === 'follow' ? h('div', { style: { margin: '0 16px 16px', padding: 14, display: 'flex', alignItems: 'center', gap: 12, borderRadius: 9, border: '1px solid var(--dsw-alias-border-l1, #dce1f4)', background: 'var(--dsw-alias-button-primary-fill-alpha-10, #f0f2ff)' } },
|
|
2191
|
+
h('span', { style: { ...badge, width: 36, height: 36 } }, h(TranslateProviderIcon, { provider: TRANSLATE_PROVIDERS.find((p) => p.id === translateProviderFor(cfg?.harness?.providerName)) || TRANSLATE_PROVIDERS[5], size: 24 })),
|
|
2192
|
+
h('div', { style: { minWidth: 0 } },
|
|
2193
|
+
h('div', { style: small }, '● ', t('setTranslateCurrentFollow')),
|
|
2194
|
+
cfg?.harness ? h('div', { style: { marginTop: 4, fontSize: 13, fontWeight: 650, overflowWrap: 'anywhere' } }, cfg.harness.model, ' ', h('span', { style: { color: 'var(--dsw-alias-label-secondary, #6d7480)', fontWeight: 450 } }, '· ' + cfg.harness.providerName)) : h('div', { style: { ...SET.err, marginTop: 4 } }, t('setTranslateUnavailable')),
|
|
2195
|
+
h('div', { style: { ...small, marginTop: 5 } }, t('setTranslateFollowNote')),
|
|
2196
|
+
),
|
|
2197
|
+
) : h('div', null,
|
|
2198
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '0 16px 10px' } },
|
|
2199
|
+
h('strong', { style: { fontSize: 12 } }, t('setTranslateProviders')),
|
|
2200
|
+
h('span', { style: small }, t('setTranslateSavedCount').replace('{n}', String(savedCount))),
|
|
2201
|
+
),
|
|
2202
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 7, padding: '0 16px 14px' } },
|
|
2203
|
+
TRANSLATE_PROVIDERS.map((p) => {
|
|
2204
|
+
const selected = p.id === providerId
|
|
2205
|
+
const saved = endpoints.some((e) => e.source === 'file' && endpointProvider(e) === p.id)
|
|
2206
|
+
return h('button', { key: p.id, type: 'button', 'data-dpr-translate-provider': p.id, onClick: () => chooseProvider(p.id), style: { minWidth: 0, display: 'flex', alignItems: 'center', gap: 8, padding: 9, textAlign: 'left', cursor: 'pointer', borderRadius: 8, border: `1px solid ${selected ? 'var(--dsw-alias-button-primary-fill, #5269d8)' : 'var(--dsw-alias-border-l1, #e5e7ec)'}`, background: selected ? 'var(--dsw-alias-button-primary-fill-alpha-10, #fafaff)' : 'var(--dsw-alias-bg-layer-1, #fff)', boxShadow: selected ? '0 0 0 1px var(--dsw-alias-button-primary-fill, #5269d8)' : 'none' } },
|
|
2207
|
+
h('span', { style: badge }, h(TranslateProviderIcon, { provider: p, size: 22 })),
|
|
2208
|
+
h('span', { style: { minWidth: 0 } },
|
|
2209
|
+
h('span', { style: { display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 11, fontWeight: 600 } }, p.name),
|
|
2210
|
+
h('span', { style: { ...small, color: saved ? 'var(--dsw-alias-state-success-primary, #27845d)' : small.color } }, saved ? t('setTranslateSavedShort') : (p.id === 'custom' ? 'OpenAI API' : t('setOptional'))),
|
|
2211
|
+
),
|
|
2212
|
+
)
|
|
2213
|
+
}),
|
|
2214
|
+
),
|
|
2215
|
+
h('div', { style: { margin: '0 16px 16px', border: '1px solid var(--dsw-alias-border-l1, #e5e7ec)', borderRadius: 9, overflow: 'hidden' } },
|
|
2216
|
+
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '12px 12px 8px', gap: 10 } },
|
|
2217
|
+
h('strong', { style: { fontSize: 12 } }, provider.name, savedForProvider ? h('span', { style: { ...small, marginLeft: 7, color: 'var(--dsw-alias-state-success-primary, #27845d)' } }, '● ' + t('setTranslateSavedShort')) : null),
|
|
2218
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 9 } },
|
|
2219
|
+
provider.keyUrl ? h('a', { href: provider.keyUrl, target: '_blank', rel: 'noreferrer', style: { fontSize: 11, color: 'var(--dsw-alias-button-primary-fill, #5269d8)', textDecoration: 'none', whiteSpace: 'nowrap' } }, t('setTranslateApplyKey') + ' ↗') : null,
|
|
2220
|
+
draft.id !== 'new' && draft.id !== 'profile' ? h('button', { type: 'button', 'data-dpr-translate-delete': '', style: { ...SET.btnGhost, padding: '2px 5px', fontSize: 10, color: 'var(--dsw-alias-state-error-primary, #f85149)' }, disabled: busy === 'delete', onClick: remove }, deleteArmed ? t('setTranslateDeleteConfirm') : t('setTranslateDelete')) : null,
|
|
2221
|
+
),
|
|
2222
|
+
),
|
|
2223
|
+
h('div', { style: { padding: '0 12px 12px' } },
|
|
2224
|
+
h('label', { style: SET.label, htmlFor: 'dpr-translate-key' }, t('setKey')),
|
|
2225
|
+
h('input', { id: 'dpr-translate-key', 'data-dpr-translate-key': '', style: SET.input, type: 'password', autoComplete: 'off', disabled: busy === 'save', value: draft.apiKey, placeholder: savedForProvider ? t('setKeyKeep') + (endpoints.find((e) => e.id === draft.id)?.apiKeyHint || '') : 'sk-...', onChange: (e) => setDraft({ ...draft, apiKey: e.target.value }) }),
|
|
2226
|
+
h('p', { style: { ...small, margin: '6px 0 0', color: busy === 'models' ? 'var(--dsw-alias-button-primary-fill, #5269d8)' : small.color } }, busy === 'models' ? t('setTranslateDiscovering') : t('setTranslateKeyAuto')),
|
|
2227
|
+
provider.id === 'custom' ? h('div', null,
|
|
2228
|
+
h('label', { style: SET.label, htmlFor: 'dpr-translate-url' }, t('setBaseUrl')),
|
|
2229
|
+
h('input', { id: 'dpr-translate-url', 'data-dpr-translate-url': '', style: SET.input, type: 'text', value: draft.baseUrl, onChange: (e) => setDraft({ ...draft, baseUrl: e.target.value }) }),
|
|
2230
|
+
) : null,
|
|
2231
|
+
h('details', { style: { marginTop: 9 } },
|
|
2232
|
+
h('summary', { style: { ...small, cursor: 'pointer' } }, t('setTranslateAdvanced')),
|
|
2233
|
+
manualModel ? h('div', null,
|
|
2234
|
+
h('label', { style: SET.label, htmlFor: 'dpr-translate-manual-model' }, t('setTranslateManualModel')),
|
|
2235
|
+
h('div', { style: { display: 'flex', gap: 7 } },
|
|
2236
|
+
h('input', { id: 'dpr-translate-manual-model', 'data-dpr-translate-manual-model': '', style: { ...SET.input, flex: 1, minWidth: 0 }, type: 'text', value: draft.model, placeholder: 'deepseek-chat', onChange: (e) => setDraft({ ...draft, model: e.target.value }) }),
|
|
2237
|
+
h('button', { type: 'button', style: { ...SET.btnGhost, flex: 'none', whiteSpace: 'nowrap' }, disabled: busy === 'save' || !draft.model.trim(), onClick: () => saveModel(draft.model) }, busy === 'save' ? t('setSaving') : t('setTranslateUse')),
|
|
2238
|
+
),
|
|
2239
|
+
) : null,
|
|
2240
|
+
optionField('splitTokens', t('setTranslateSplitTokens'), t('setTranslateSplitHint'), 200, 128000),
|
|
2241
|
+
optionField('maxOutputTokens', t('setTranslateMaxOutput'), t('setTranslateMaxOutputHint'), 0, 32768),
|
|
2242
|
+
optionField('qps', t('setTranslateQps'), t('setTranslateQpsHint'), 1, 32),
|
|
2243
|
+
h('button', { type: 'button', 'data-dpr-translate-options-save': '', style: { ...SET.btnGhost, marginTop: 12 }, disabled: busy === 'options', onClick: saveOptions }, busy === 'options' ? t('setSaving') : t('setTranslateOptionsSave')),
|
|
2244
|
+
),
|
|
2245
|
+
),
|
|
2246
|
+
h('div', { style: { borderTop: '1px solid var(--dsw-alias-border-l1, #e5e7ec)', padding: 12 } },
|
|
2247
|
+
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 } },
|
|
2248
|
+
h('strong', { style: { fontSize: 12 } }, t('setTranslateModels'), ' ', h('span', { style: { ...small, fontWeight: 400 } }, models.length ? `(${models.length})` : '')),
|
|
2249
|
+
h('button', { type: 'button', 'data-dpr-translate-refresh': '', style: { ...SET.btnGhost, padding: '3px 7px', fontSize: 11 }, disabled: busy === 'models' || busy === 'save', onClick: discover }, t('setTranslateRefresh')),
|
|
2250
|
+
),
|
|
2251
|
+
models.length ? h('div', { style: { display: 'grid', gap: 6, maxHeight: 260, overflowY: 'auto' } }, models.map((model) => {
|
|
2252
|
+
const using = cfg?.activeId === draft.id && cfg?.source !== 'harness' && draft.model === model
|
|
2253
|
+
return h('button', { key: model, type: 'button', 'data-dpr-translate-model': model, disabled: busy === 'save', onClick: () => saveModel(model), style: { display: 'flex', alignItems: 'center', gap: 9, width: '100%', padding: 10, textAlign: 'left', cursor: 'pointer', borderRadius: 7, border: `1px solid ${using ? 'var(--dsw-alias-button-primary-fill, #aeb9ee)' : 'var(--dsw-alias-border-l1, #e5e7ec)'}`, background: using ? 'var(--dsw-alias-button-primary-fill-alpha-10, #fafaff)' : 'var(--dsw-alias-bg-layer-1, #fff)' } },
|
|
2254
|
+
radio(using),
|
|
2255
|
+
h('span', { style: { flex: 1, minWidth: 0, overflowWrap: 'anywhere', fontSize: 12, fontWeight: 600 } }, model),
|
|
2256
|
+
h('span', { style: { ...small, color: using ? 'var(--dsw-alias-button-primary-fill, #5269d8)' : small.color } }, using ? t('setTranslateUsing') : t('setTranslateUse')),
|
|
2257
|
+
)
|
|
2258
|
+
})) : h('div', { style: { ...small, padding: 14, textAlign: 'center', border: '1px dashed var(--dsw-alias-border-l1, #d8dce4)', borderRadius: 7 } }, t('setTranslateEmpty')),
|
|
2259
|
+
),
|
|
2260
|
+
),
|
|
2261
|
+
),
|
|
2262
|
+
h('div', { style: { padding: '0 16px 13px', textAlign: 'center', ...small } }, mode === 'follow' ? t('setTranslateScopeFollow') : t('setTranslateScopeCustom')),
|
|
2263
|
+
msg ? h('div', { style: { padding: '0 16px 13px', textAlign: 'center', ...(msg.ok ? SET.ok : SET.err) } }, msg.text) : null,
|
|
2264
|
+
)
|
|
2265
|
+
}
|
|
2266
|
+
|
|
1720
2267
|
/* ---------- 分屏同步滚动卡片(模式 B 的**全局**偏好)----------
|
|
1721
2268
|
本卡片与阅读器是**两个文档**(阅读器是同源 iframe ~ /paper-reader/),共享同一个 localStorage:
|
|
1722
2269
|
· 这里勾/取消 → 写 `dpr.syncScroll` → 阅读器收到 storage 事件 → 开关与滚动行为立即跟着变
|
|
@@ -1725,11 +2272,11 @@ window.__ModuleLoader__.load({
|
|
|
1725
2272
|
⇒ 两处入口互相同步,且都是**同一个键**(键名与 '1'/'0' 编码由文件顶层的纯函数定义,
|
|
1726
2273
|
与 reader/index.html 逐字一致)。默认开 = 缺省值(与改造前行为一致)。 */
|
|
1727
2274
|
function SyncScrollCard() {
|
|
1728
|
-
const readPref = () => { try { return dprSyncScrollFromRaw(localStorage.getItem(
|
|
2275
|
+
const readPref = () => { try { return dprSyncScrollFromRaw(localStorage.getItem(dprSyncScrollKey())) } catch { return true } }
|
|
1729
2276
|
const [on, setOn] = useState(readPref)
|
|
1730
2277
|
useEffect(() => {
|
|
1731
2278
|
const onStorage = (e) => {
|
|
1732
|
-
if (!e || e.key !==
|
|
2279
|
+
if (!e || e.key !== dprSyncScrollKey()) return
|
|
1733
2280
|
setOn(dprSyncScrollFromRaw(e.newValue)) // 另一处(阅读器/另一个窗口)改了 → 立即反映
|
|
1734
2281
|
}
|
|
1735
2282
|
window.addEventListener('storage', onStorage)
|
|
@@ -1737,7 +2284,7 @@ window.__ModuleLoader__.load({
|
|
|
1737
2284
|
}, [])
|
|
1738
2285
|
const apply = (v) => {
|
|
1739
2286
|
setOn(v)
|
|
1740
|
-
try { localStorage.setItem(
|
|
2287
|
+
try { localStorage.setItem(dprSyncScrollKey(), dprSyncScrollRaw(v)) } catch { /* 隐私模式写不了:阅读器里仍可单独改 */ }
|
|
1741
2288
|
}
|
|
1742
2289
|
return h('div', { style: SET.card, 'data-dsh-plugin': 'dsh-paper-reader', 'data-dsh-part': 'settings-card' },
|
|
1743
2290
|
h('h3', { style: SET.title }, t('setSyncScrollTitle')),
|
|
@@ -1830,10 +2377,7 @@ window.__ModuleLoader__.load({
|
|
|
1830
2377
|
baseUrlPlaceholder: 'https://api.openai.com/v1', modelPlaceholder: 'text-embedding-3-small', keyPlaceholder: 'sk-...',
|
|
1831
2378
|
batchSize: true,
|
|
1832
2379
|
}),
|
|
1833
|
-
h(
|
|
1834
|
-
path: '/translate/config', title: t('setTranslateTitle'), desc: t('setTranslateDesc'),
|
|
1835
|
-
baseUrlPlaceholder: 'https://api.deepseek.com/v1', modelPlaceholder: 'deepseek-chat', keyPlaceholder: 'sk-...',
|
|
1836
|
-
}),
|
|
2380
|
+
h(TranslateSettingsCard, null),
|
|
1837
2381
|
h(MineruCard, null),
|
|
1838
2382
|
h(ThemeCard, null),
|
|
1839
2383
|
h(SyncScrollCard, null),
|
|
@@ -1970,10 +2514,26 @@ window.__ModuleLoader__.load({
|
|
|
1970
2514
|
if (!document.getElementById('dpr-surface-css')) {
|
|
1971
2515
|
const styleEl = document.createElement('style')
|
|
1972
2516
|
styleEl.id = 'dpr-surface-css'
|
|
1973
|
-
styleEl.textContent =
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
2517
|
+
styleEl.textContent = [
|
|
2518
|
+
'[data-dpr-rail]:hover,[data-dpr-mode]:hover{background:var(--dsw-alias-interactive-bg-hover)!important}',
|
|
2519
|
+
'[data-dsh-plugin="dsh-paper-reader"] svg{display:block;flex:none}',
|
|
2520
|
+
'[data-dpr-row]{transition:background .12s ease,color .12s ease}',
|
|
2521
|
+
'[data-dpr-row]:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.09))!important}',
|
|
2522
|
+
'[data-dpr-row]:focus-visible{box-shadow:inset 0 0 0 2px var(--dsw-alias-label-action-primary,#0969da)}',
|
|
2523
|
+
'[data-dpr-row].dpr-active{background:var(--dsw-alias-bg-active,rgba(9,105,218,.12))!important}',
|
|
2524
|
+
'[data-dpr-row].dpr-active:before{content:"";position:absolute;left:0;top:7px;bottom:7px;width:2px;border-radius:2px;background:var(--dsw-alias-label-action-primary,#0969da)}',
|
|
2525
|
+
'.dpr-topic-icon{color:var(--dsw-alias-label-tertiary,#8c959f)}',
|
|
2526
|
+
'.dpr-paper-icon{color:var(--dsw-alias-label-tertiary,#8c959f)}',
|
|
2527
|
+
'.dpr-active .dpr-paper-icon,[data-dpr-row]:hover .dpr-topic-icon{color:currentColor}',
|
|
2528
|
+
'.dpr-row-menu-trigger{opacity:0!important;transition:opacity .12s,background .12s}',
|
|
2529
|
+
'[data-dpr-row]:hover .dpr-row-menu-trigger,[data-dpr-row]:focus-within .dpr-row-menu-trigger,.dpr-row-menu-trigger[aria-expanded="true"]{opacity:1!important}',
|
|
2530
|
+
'.dpr-row-menu-trigger:hover,.dpr-row-menu-trigger:focus-visible{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))!important;outline:none}',
|
|
2531
|
+
'.dpr-row-menu{z-index:100000;box-sizing:border-box;width:168px;padding:5px;border:1px solid var(--dsw-alias-border-l1,#d0d7de);border-radius:9px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 30px rgba(0,0,0,.18);color:var(--dsw-alias-label-primary,#24292f);font:13px -apple-system,"SF Pro","PingFang SC",sans-serif}',
|
|
2532
|
+
'.dpr-row-menu button{display:flex;align-items:center;gap:9px;width:100%;min-height:32px;padding:6px 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer}',
|
|
2533
|
+
'.dpr-row-menu button:hover,.dpr-row-menu button:focus-visible{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.09));outline:none}',
|
|
2534
|
+
'.dpr-row-menu button.danger{color:var(--dsw-alias-state-danger-primary,#cf222e)}',
|
|
2535
|
+
'@media(prefers-reduced-motion:reduce){[data-dpr-row],[data-dpr-row] span,.dpr-row-menu-trigger{transition:none!important}}',
|
|
2536
|
+
].join('')
|
|
1977
2537
|
document.head.appendChild(styleEl)
|
|
1978
2538
|
}
|
|
1979
2539
|
|