dsh-plugin-zotero 0.1.8 → 0.2.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 +4 -3
- package/client/client.js +680 -265
- package/lib/zotero/client.d.ts +2 -0
- package/lib/zotero/client.js +58 -5
- package/lib/zotero/types.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**装上它,DSH 就能直接操控你的 Zotero。**
|
|
4
4
|
|
|
5
|
-
打通之后,Zotero 不再是一个要你手动点开、一层层翻找的软件,而是 DSH 随手可用的资料库:你可以直接让 DSH 去检索文库、精读某篇 PDF
|
|
5
|
+
打通之后,Zotero 不再是一个要你手动点开、一层层翻找的软件,而是 DSH 随手可用的资料库:你可以直接让 DSH 去检索文库、精读某篇 PDF、汇总整理高亮标注与笔记、按主题新建分类并把文献归类;也可以把下载好的论文交给它导入,让它读完外文文献后把译文作为附件挂回对应条目。凡是 Zotero 本地接口和 MCP 插件能提供的操作,DSH 都可以替你做。
|
|
6
6
|
|
|
7
7
|
除了模型侧的能力,DSH 右侧栏还会多出一块「Zotero 文献库」面板:随时浏览自己的文库,把条目、摘录或整个分类一键带进对话。
|
|
8
8
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
- **读文献**:读摘要、PDF 全文、笔记与标注,写综述、做对比、提取数据都行;需要精确引用时会保留原文措辞。
|
|
21
21
|
- **整理文库**:新建、重命名、移动、删除分类,批量把条目加入或移出分类。你说一句「把这几篇归到『待读』里」,它就照做。
|
|
22
22
|
- **帮你入库**:把本地下载好的论文、PDF 交给 DSH 导入 Zotero;也可以让它读完外文文献后,把译文作为附件挂回条目。
|
|
23
|
-
-
|
|
23
|
+
- **带进对话**:右侧面板单条目引用、全文划词摘录或整分类引用,一键写进当前会话草稿(不自动发送),你再接着说要求。条目和整分类以「引用胶囊」的形式出现,草稿里一眼看清引了哪几篇,单独删掉某一条也不影响其他内容。
|
|
24
24
|
- **安全可控**:浏览面板严格只读;模型能用的每一项工具都能单独开关,想彻底只读就把写操作关掉;写操作优先走集成 MCP,它在 Zotero 进程内直接执行,不触发本地 API 的授权弹窗。
|
|
25
25
|
|
|
26
26
|
面板分三块:顶部状态栏显示连接状态并提供刷新;左侧分类树按分类浏览与搜索;右侧详情区展示正文与「参考文献 / 笔记 / 标注 / 附件」标签页。
|
|
@@ -80,7 +80,8 @@ curl http://127.0.0.1:23119/api/ # 期望输出:Zotero is running
|
|
|
80
80
|
- **摘要默认折叠**:标题行右侧的箭头按钮展开 / 收起摘要,默认把空间留给正文与全文。
|
|
81
81
|
- **笔记可读**:独立笔记(文库里的全局笔记)打开后正文直接占据上方正文区,跟普通条目一样阅读;条目下的子笔记仍进「笔记」tab,以折叠列表呈现(默认收起,点击标题展开),正文保留 Zotero 的引用块、标注高亮、表格与外链图片。Host 侧已清洗脚本与事件属性,避免注入。「引用」把该条笔记转成纯文本写进会话草稿。
|
|
82
82
|
- **标注可读**:PDF 上的高亮与划线汇总进「标注」tab(带颜色、页码、原文与评论,可按类型 / 颜色筛选);全文块里原位标出底色与下划线,点列表条目可滚动定位并闪烁,「引用」把该条标注写进会话草稿。
|
|
83
|
-
-
|
|
83
|
+
- **五种插入方式**:单条目引用与整目录引用以「引用胶囊」写进草稿——胶囊只显示标题,发送那一刻才展开成完整引用文本,模型拿到的内容与以前一致;全文划词摘录、单条标注、单条笔记仍按纯文本插入。所有方式都只写进会话草稿(不自动发送、不抢焦点),文本携带 `itemKey` / `collectionKey` 供模型接续操作。
|
|
84
|
+
- **胶囊依赖本插件展开**:草稿里留着引用胶囊时禁用或卸载本插件,发送会失败并提示找不到引用来源,把胶囊删掉即可继续正常发送。
|
|
84
85
|
- **面板严格只读**:不提供任何新建 / 改名 / 删除分类的按钮。
|
|
85
86
|
- **模型侧工具可逐个开关**:插件自持连接集成 MCP,把工具以 `mcp__zotero__*` 注册进 dsh,可在插件页按工具启用 / 禁用。
|
|
86
87
|
|
package/client/client.js
CHANGED
|
@@ -37,6 +37,48 @@ const dicts = {
|
|
|
37
37
|
"status.mcpOn": "模型工具可用",
|
|
38
38
|
"status.mcpOff": "模型工具不可用",
|
|
39
39
|
"status.loading": "加载中…",
|
|
40
|
+
"item.lastRead": "最后阅读:{date}",
|
|
41
|
+
"item.type": "类型:{type}",
|
|
42
|
+
"type.artwork": "艺术品",
|
|
43
|
+
"type.audioRecording": "录音",
|
|
44
|
+
"type.bill": "法案",
|
|
45
|
+
"type.blogPost": "博客帖文",
|
|
46
|
+
"type.book": "图书",
|
|
47
|
+
"type.bookSection": "图书章节",
|
|
48
|
+
"type.case": "司法案例",
|
|
49
|
+
"type.computerProgram": "软件",
|
|
50
|
+
"type.conferencePaper": "会议论文",
|
|
51
|
+
"type.dataset": "数据集",
|
|
52
|
+
"type.dictionaryEntry": "词条",
|
|
53
|
+
"type.document": "文档",
|
|
54
|
+
"type.email": "电子邮件",
|
|
55
|
+
"type.encyclopediaArticle": "百科条目",
|
|
56
|
+
"type.film": "电影",
|
|
57
|
+
"type.forumPost": "论坛帖文",
|
|
58
|
+
"type.hearing": "听证会",
|
|
59
|
+
"type.instantMessage": "即时消息",
|
|
60
|
+
"type.interview": "访谈",
|
|
61
|
+
"type.journalArticle": "期刊文章",
|
|
62
|
+
"type.letter": "信件",
|
|
63
|
+
"type.magazineArticle": "杂志文章",
|
|
64
|
+
"type.manuscript": "手稿",
|
|
65
|
+
"type.map": "地图",
|
|
66
|
+
"type.newspaperArticle": "报纸文章",
|
|
67
|
+
"type.note": "笔记",
|
|
68
|
+
"type.patent": "专利",
|
|
69
|
+
"type.podcast": "播客",
|
|
70
|
+
"type.preprint": "预印本",
|
|
71
|
+
"type.presentation": "演示文档",
|
|
72
|
+
"type.radioBroadcast": "电台广播",
|
|
73
|
+
"type.report": "报告",
|
|
74
|
+
"type.standard": "标准",
|
|
75
|
+
"type.statute": "法律",
|
|
76
|
+
"type.thesis": "学位论文",
|
|
77
|
+
"type.tvBroadcast": "电视广播",
|
|
78
|
+
"type.videoRecording": "视频",
|
|
79
|
+
"type.webpage": "网页",
|
|
80
|
+
"type.attachment": "附件",
|
|
81
|
+
"type.annotation": "标注",
|
|
40
82
|
"tree.library": "我的文库",
|
|
41
83
|
"tree.publications": "我的出版物",
|
|
42
84
|
"tree.unfiled": "未分类条目",
|
|
@@ -50,6 +92,7 @@ const dicts = {
|
|
|
50
92
|
"detail.metadata": "文献信息",
|
|
51
93
|
"detail.metadataExpand": "展开文献信息",
|
|
52
94
|
"detail.metadataCollapse": "收起文献信息",
|
|
95
|
+
"detail.type": "类型",
|
|
53
96
|
"detail.creators": "作者",
|
|
54
97
|
"detail.year": "年份",
|
|
55
98
|
"detail.source": "出处",
|
|
@@ -125,6 +168,7 @@ const dicts = {
|
|
|
125
168
|
"cmp.annotation.page": "页码:{value}",
|
|
126
169
|
"cmp.annotation.comment": "批注:{value}",
|
|
127
170
|
"cmp.annotation.key": "标注:{value}",
|
|
171
|
+
"cmp.annotation.pageTag": "(第 {value} 页)",
|
|
128
172
|
"cmp.note.header": "【Zotero 笔记|{title}|{key}】",
|
|
129
173
|
"cmp.note.truncated": "……(笔记正文已按长度截断)",
|
|
130
174
|
"cmp.note.date": "更新:{value}",
|
|
@@ -143,7 +187,11 @@ const dicts = {
|
|
|
143
187
|
"cmp.excerpt.quote": "“{value}”",
|
|
144
188
|
"cmp.collection.header": "【Zotero 目录|{name}|{key}】共 {n} 条",
|
|
145
189
|
"cmp.collection.line": "- {title}({meta})",
|
|
146
|
-
"cmp.collection.more": "……(仅列出前 {n} 条;完整清单可用 mcp__zotero__get_collection_items 获取)"
|
|
190
|
+
"cmp.collection.more": "……(仅列出前 {n} 条;完整清单可用 mcp__zotero__get_collection_items 获取)",
|
|
191
|
+
"cmp.missing.item": "【Zotero 条目|{key}】该条目已不在文库中,引用文本未能生成。",
|
|
192
|
+
"cmp.missing.collection": "【Zotero 目录|{key}】该目录已不存在,条目清单未能生成。",
|
|
193
|
+
"cmp.missing.note": "【Zotero 笔记|{key}】该笔记已不在文库中,引用文本未能生成。",
|
|
194
|
+
"cmp.missing.annotation": "【Zotero 标注|{key}】该标注已不在文库中,引用文本未能生成。"
|
|
147
195
|
},
|
|
148
196
|
en: {
|
|
149
197
|
"tab.title": "Zotero Library",
|
|
@@ -161,6 +209,48 @@ const dicts = {
|
|
|
161
209
|
"status.mcpOn": "Model tools available",
|
|
162
210
|
"status.mcpOff": "Model tools unavailable",
|
|
163
211
|
"status.loading": "Loading…",
|
|
212
|
+
"item.lastRead": "Last read: {date}",
|
|
213
|
+
"item.type": "Type: {type}",
|
|
214
|
+
"type.artwork": "Artwork",
|
|
215
|
+
"type.audioRecording": "Audio Recording",
|
|
216
|
+
"type.bill": "Bill",
|
|
217
|
+
"type.blogPost": "Blog Post",
|
|
218
|
+
"type.book": "Book",
|
|
219
|
+
"type.bookSection": "Book Section",
|
|
220
|
+
"type.case": "Case",
|
|
221
|
+
"type.computerProgram": "Computer Program",
|
|
222
|
+
"type.conferencePaper": "Conference Paper",
|
|
223
|
+
"type.dataset": "Dataset",
|
|
224
|
+
"type.dictionaryEntry": "Dictionary Entry",
|
|
225
|
+
"type.document": "Document",
|
|
226
|
+
"type.email": "Email",
|
|
227
|
+
"type.encyclopediaArticle": "Encyclopedia Article",
|
|
228
|
+
"type.film": "Film",
|
|
229
|
+
"type.forumPost": "Forum Post",
|
|
230
|
+
"type.hearing": "Hearing",
|
|
231
|
+
"type.instantMessage": "Instant Message",
|
|
232
|
+
"type.interview": "Interview",
|
|
233
|
+
"type.journalArticle": "Journal Article",
|
|
234
|
+
"type.letter": "Letter",
|
|
235
|
+
"type.magazineArticle": "Magazine Article",
|
|
236
|
+
"type.manuscript": "Manuscript",
|
|
237
|
+
"type.map": "Map",
|
|
238
|
+
"type.newspaperArticle": "Newspaper Article",
|
|
239
|
+
"type.note": "Note",
|
|
240
|
+
"type.patent": "Patent",
|
|
241
|
+
"type.podcast": "Podcast",
|
|
242
|
+
"type.preprint": "Preprint",
|
|
243
|
+
"type.presentation": "Presentation",
|
|
244
|
+
"type.radioBroadcast": "Radio Broadcast",
|
|
245
|
+
"type.report": "Report",
|
|
246
|
+
"type.standard": "Standard",
|
|
247
|
+
"type.statute": "Statute",
|
|
248
|
+
"type.thesis": "Thesis",
|
|
249
|
+
"type.tvBroadcast": "TV Broadcast",
|
|
250
|
+
"type.videoRecording": "Video Recording",
|
|
251
|
+
"type.webpage": "Webpage",
|
|
252
|
+
"type.attachment": "Attachment",
|
|
253
|
+
"type.annotation": "Annotation",
|
|
164
254
|
"tree.library": "My Library",
|
|
165
255
|
"tree.publications": "My Publications",
|
|
166
256
|
"tree.unfiled": "Unfiled Items",
|
|
@@ -174,6 +264,7 @@ const dicts = {
|
|
|
174
264
|
"detail.metadata": "Metadata",
|
|
175
265
|
"detail.metadataExpand": "Expand metadata",
|
|
176
266
|
"detail.metadataCollapse": "Collapse metadata",
|
|
267
|
+
"detail.type": "Type",
|
|
177
268
|
"detail.creators": "Creators",
|
|
178
269
|
"detail.year": "Year",
|
|
179
270
|
"detail.source": "Source",
|
|
@@ -249,6 +340,7 @@ const dicts = {
|
|
|
249
340
|
"cmp.annotation.page": "Page: {value}",
|
|
250
341
|
"cmp.annotation.comment": "Comment: {value}",
|
|
251
342
|
"cmp.annotation.key": "Annotation: {value}",
|
|
343
|
+
"cmp.annotation.pageTag": " (p. {value})",
|
|
252
344
|
"cmp.note.header": "[Zotero note | {title} | {key}]",
|
|
253
345
|
"cmp.note.truncated": "… (note body truncated by length)",
|
|
254
346
|
"cmp.note.date": "Updated: {value}",
|
|
@@ -267,7 +359,11 @@ const dicts = {
|
|
|
267
359
|
"cmp.excerpt.quote": "“{value}”",
|
|
268
360
|
"cmp.collection.header": "[Zotero collection | {name} | {key}] {n} items",
|
|
269
361
|
"cmp.collection.line": "- {title} ({meta})",
|
|
270
|
-
"cmp.collection.more": "… (first {n} only; use mcp__zotero__get_collection_items for the full list)"
|
|
362
|
+
"cmp.collection.more": "… (first {n} only; use mcp__zotero__get_collection_items for the full list)",
|
|
363
|
+
"cmp.missing.item": "[Zotero item | {key}] this item is no longer in the library; citation text unavailable.",
|
|
364
|
+
"cmp.missing.collection": "[Zotero collection | {key}] this collection no longer exists; item list unavailable.",
|
|
365
|
+
"cmp.missing.note": "[Zotero note | {key}] this note is no longer in the library; citation text unavailable.",
|
|
366
|
+
"cmp.missing.annotation": "[Zotero annotation | {key}] this annotation is no longer in the library; citation text unavailable."
|
|
271
367
|
}
|
|
272
368
|
};
|
|
273
369
|
//#endregion
|
|
@@ -288,10 +384,10 @@ function buildUrl(action, query = {}) {
|
|
|
288
384
|
const search = params.toString();
|
|
289
385
|
return `${BASE}/${action}${search === "" ? "" : `?${search}`}`;
|
|
290
386
|
}
|
|
291
|
-
async function get(action, query = {}) {
|
|
387
|
+
async function get(action, query = {}, signal) {
|
|
292
388
|
let res;
|
|
293
389
|
try {
|
|
294
|
-
res = await fetch(buildUrl(action, query));
|
|
390
|
+
res = await fetch(buildUrl(action, query), { signal });
|
|
295
391
|
} catch (error) {
|
|
296
392
|
throw new ApiFailure("network_error", `无法访问 Host 端点:${error instanceof Error ? error.message : String(error)}`);
|
|
297
393
|
}
|
|
@@ -303,17 +399,17 @@ async function get(action, query = {}) {
|
|
|
303
399
|
function fetchHealth() {
|
|
304
400
|
return get("health");
|
|
305
401
|
}
|
|
306
|
-
function fetchTree() {
|
|
307
|
-
return get("tree");
|
|
402
|
+
function fetchTree(signal) {
|
|
403
|
+
return get("tree", {}, signal);
|
|
308
404
|
}
|
|
309
|
-
function fetchItems(query = {}) {
|
|
310
|
-
return get("items", query);
|
|
405
|
+
function fetchItems(query = {}, signal) {
|
|
406
|
+
return get("items", query, signal);
|
|
311
407
|
}
|
|
312
|
-
function fetchItem(key, style = "apa") {
|
|
408
|
+
function fetchItem(key, style = "apa", signal) {
|
|
313
409
|
return get("item", {
|
|
314
410
|
key,
|
|
315
411
|
style
|
|
316
|
-
});
|
|
412
|
+
}, signal);
|
|
317
413
|
}
|
|
318
414
|
function fetchCollectionBib(key, style = "apa") {
|
|
319
415
|
return get("collection-bib", {
|
|
@@ -571,6 +667,344 @@ function resetPaneStore() {
|
|
|
571
667
|
for (const listener of listeners) listener();
|
|
572
668
|
}
|
|
573
669
|
//#endregion
|
|
670
|
+
//#region src/client/annotationComment.ts
|
|
671
|
+
/** 只有这些标签有意义;属性不会出现,仍容忍以防手改。 */
|
|
672
|
+
const TAG_SOURCE = "<\\/?(?:b|i|sub|sup|br|div)\\b[^>]*>";
|
|
673
|
+
function tagRegex() {
|
|
674
|
+
return new RegExp(TAG_SOURCE, "giu");
|
|
675
|
+
}
|
|
676
|
+
/** 评论 → 渲染 token;不平衡的闭合标签直接忽略。 */
|
|
677
|
+
function parseComment(comment) {
|
|
678
|
+
const tokens = [];
|
|
679
|
+
let bold = 0;
|
|
680
|
+
let italic = 0;
|
|
681
|
+
let sub = 0;
|
|
682
|
+
let sup = 0;
|
|
683
|
+
let last = 0;
|
|
684
|
+
const pushText = (text) => {
|
|
685
|
+
if (text === "") return;
|
|
686
|
+
tokens.push({
|
|
687
|
+
kind: "text",
|
|
688
|
+
text,
|
|
689
|
+
bold: bold > 0,
|
|
690
|
+
italic: italic > 0,
|
|
691
|
+
sub: sub > 0,
|
|
692
|
+
sup: sup > 0
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
for (const match of comment.matchAll(tagRegex())) {
|
|
696
|
+
const index = match.index ?? 0;
|
|
697
|
+
pushText(comment.slice(last, index));
|
|
698
|
+
last = index + match[0].length;
|
|
699
|
+
const tag = match[0].toLowerCase();
|
|
700
|
+
const closing = tag.startsWith("</");
|
|
701
|
+
const name = tag.replace(/[</>\s]/gu, "");
|
|
702
|
+
if (name === "br" || name === "div") {
|
|
703
|
+
if (!closing) tokens.push({
|
|
704
|
+
kind: "break",
|
|
705
|
+
text: "",
|
|
706
|
+
bold: false,
|
|
707
|
+
italic: false,
|
|
708
|
+
sub: false,
|
|
709
|
+
sup: false
|
|
710
|
+
});
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
const delta = closing ? -1 : 1;
|
|
714
|
+
if (name === "b") bold = Math.max(0, bold + delta);
|
|
715
|
+
else if (name === "i") italic = Math.max(0, italic + delta);
|
|
716
|
+
else if (name === "sub") sub = Math.max(0, sub + delta);
|
|
717
|
+
else if (name === "sup") sup = Math.max(0, sup + delta);
|
|
718
|
+
}
|
|
719
|
+
pushText(comment.slice(last));
|
|
720
|
+
while (tokens[0]?.kind === "break") tokens.shift();
|
|
721
|
+
while (tokens[tokens.length - 1]?.kind === "break") tokens.pop();
|
|
722
|
+
return tokens;
|
|
723
|
+
}
|
|
724
|
+
/** 去标签与换行,供插入草稿使用。 */
|
|
725
|
+
function commentPlain(comment) {
|
|
726
|
+
return comment.replace(tagRegex(), " ").replace(/\s+/gu, " ").trim();
|
|
727
|
+
}
|
|
728
|
+
/** 是否有可显示的内容(纯空白不算)。 */
|
|
729
|
+
function hasComment(comment) {
|
|
730
|
+
return commentPlain(comment) !== "";
|
|
731
|
+
}
|
|
732
|
+
function line(t, key, value) {
|
|
733
|
+
return tpl(t(key), { value });
|
|
734
|
+
}
|
|
735
|
+
/** 单条目的引用文本。 */
|
|
736
|
+
function itemText(t, detail) {
|
|
737
|
+
const lines = [tpl(t("cmp.item.header"), {
|
|
738
|
+
key: detail.key,
|
|
739
|
+
title: detail.title
|
|
740
|
+
})];
|
|
741
|
+
if (detail.creators.length > 0) lines.push(line(t, "cmp.item.creators", detail.creators.join("、")));
|
|
742
|
+
if (detail.year !== "") lines.push(line(t, "cmp.item.year", detail.year));
|
|
743
|
+
if (detail.publicationTitle !== "") lines.push(line(t, "cmp.item.source", detail.publicationTitle));
|
|
744
|
+
if (detail.doi !== "") lines.push(line(t, "cmp.item.doi", detail.doi));
|
|
745
|
+
if (detail.url !== "") lines.push(line(t, "cmp.item.url", detail.url));
|
|
746
|
+
if (detail.tags.length > 0) lines.push(line(t, "cmp.item.tags", detail.tags.join("、")));
|
|
747
|
+
if (detail.abstract !== "") lines.push(line(t, "cmp.item.abstract", detail.abstract));
|
|
748
|
+
return lines.join("\n");
|
|
749
|
+
}
|
|
750
|
+
/** 选中片段的摘录文本。 */
|
|
751
|
+
function excerptText(t, detail, quote) {
|
|
752
|
+
return `${tpl(t("cmp.excerpt.header"), {
|
|
753
|
+
title: detail.title,
|
|
754
|
+
key: detail.key
|
|
755
|
+
})}\n${tpl(t("cmp.excerpt.quote"), { value: quote })}`;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* PDF 抽取会在汉字之间插空格(`硫 化 氢`),展示与插入时去掉;
|
|
759
|
+
* 只处理汉字与汉字之间的空格,避免动到西文词距。
|
|
760
|
+
*/
|
|
761
|
+
function tidyAnnotation(text) {
|
|
762
|
+
return text.replace(/\s+/gu, " ").replace(/(?<=[\u3400-\u9fff])\s+(?=[\u3400-\u9fff])/gu, "").trim();
|
|
763
|
+
}
|
|
764
|
+
/** 一条标注的引用文本:原文 + 类型 + 页码 + 评论 + 标注 key。 */
|
|
765
|
+
function annotationText(t, detail, annotation) {
|
|
766
|
+
const comment = commentPlain(annotation.comment);
|
|
767
|
+
const quote = tidyAnnotation(annotation.text) || comment;
|
|
768
|
+
const type = annotation.type === "underline" ? t("annotation.type.underline") : t("annotation.type.highlight");
|
|
769
|
+
const lines = [excerptText(t, detail, quote), tpl(t("cmp.annotation.type"), { value: type })];
|
|
770
|
+
if (annotation.pageLabel !== "") lines.push(tpl(t("cmp.annotation.page"), { value: annotation.pageLabel }));
|
|
771
|
+
if (comment !== "" && quote !== comment) lines.push(tpl(t("cmp.annotation.comment"), { value: comment }));
|
|
772
|
+
lines.push(tpl(t("cmp.annotation.key"), { value: annotation.key }));
|
|
773
|
+
return lines.join("\n");
|
|
774
|
+
}
|
|
775
|
+
/** chip 标签里原文摘要的长度上限(字符,非字节)。 */
|
|
776
|
+
const CHIP_LABEL_LIMIT = 40;
|
|
777
|
+
/**
|
|
778
|
+
* 标注 chip 的标签:原文摘要 + 页码。
|
|
779
|
+
*
|
|
780
|
+
* 标注没有标题字段,最能代表它的就是高亮那段原文;纯评论型标注退到评论。
|
|
781
|
+
* 两者都空时返回空串,由 chip 构造处兜底成标注 key。
|
|
782
|
+
*/
|
|
783
|
+
function annotationChipLabel(t, annotation) {
|
|
784
|
+
const source = tidyAnnotation(annotation.text) || commentPlain(annotation.comment);
|
|
785
|
+
if (source === "") return "";
|
|
786
|
+
const chars = Array.from(source);
|
|
787
|
+
const summary = chars.length > CHIP_LABEL_LIMIT ? `${chars.slice(0, CHIP_LABEL_LIMIT).join("")}…` : source;
|
|
788
|
+
return annotation.pageLabel === "" ? summary : `${summary}${tpl(t("cmp.annotation.pageTag"), { value: annotation.pageLabel })}`;
|
|
789
|
+
}
|
|
790
|
+
/** 命名实体的最小集合(与 Host 清洗后的笔记 HTML 对齐)。 */
|
|
791
|
+
const NAMED_ENTITIES = {
|
|
792
|
+
nbsp: " ",
|
|
793
|
+
amp: String.fromCharCode(38),
|
|
794
|
+
lt: String.fromCharCode(60),
|
|
795
|
+
gt: String.fromCharCode(62),
|
|
796
|
+
quot: String.fromCharCode(34),
|
|
797
|
+
apos: String.fromCharCode(39)
|
|
798
|
+
};
|
|
799
|
+
/** 解码 HTML 实体;未识别的实体原样保留。 */
|
|
800
|
+
function decodeEntities(text) {
|
|
801
|
+
return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/giu, (match, body) => {
|
|
802
|
+
if (body.startsWith("#x") || body.startsWith("#X")) {
|
|
803
|
+
const code = Number.parseInt(body.slice(2), 16);
|
|
804
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
805
|
+
}
|
|
806
|
+
if (body.startsWith("#")) {
|
|
807
|
+
const code = Number.parseInt(body.slice(1), 10);
|
|
808
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
809
|
+
}
|
|
810
|
+
return NAMED_ENTITIES[body.toLowerCase()] ?? match;
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* 笔记 HTML → 纯文本:块级标签转换行、列表项加 `- `,剥标签后解码实体。
|
|
815
|
+
*
|
|
816
|
+
* 只保留段落与列表结构,图片等没有文本的可选内容自然消失。
|
|
817
|
+
*/
|
|
818
|
+
function noteHtmlToText(html) {
|
|
819
|
+
return decodeEntities(html.replace(/<br\s*\/?>/giu, "\n").replace(/<\/(?:p|div|h[1-6]|blockquote|li|tr|ul|ol|table|figure|figcaption|pre)>/giu, "\n").replace(/<li\b[^>]*>/giu, "- ").replace(/<[^>]*>/gu, "")).replace(/\u00a0/gu, " ").replace(/[ \t]+/gu, " ").replace(/ *\n */gu, "\n").replace(/(^|\n)- *\n/gu, "$1- ").replace(/\n{2,}(?=- )/gu, "\n").replace(/\n{3,}/gu, "\n\n").trim();
|
|
820
|
+
}
|
|
821
|
+
/** 单条笔记的引用文本:所属条目 + 正文纯文本 + 截断提示 + 更新日期 + 笔记 key。 */
|
|
822
|
+
function noteText(t, detail, note) {
|
|
823
|
+
const head = tpl(t("cmp.note.header"), {
|
|
824
|
+
title: detail.title,
|
|
825
|
+
key: detail.key
|
|
826
|
+
});
|
|
827
|
+
const body = noteHtmlToText(note.html);
|
|
828
|
+
const lines = [head];
|
|
829
|
+
if (body !== "") lines.push(body);
|
|
830
|
+
if (note.truncated) lines.push(t("cmp.note.truncated"));
|
|
831
|
+
const date = note.dateModified.slice(0, 10);
|
|
832
|
+
if (date !== "") lines.push(tpl(t("cmp.note.date"), { value: date }));
|
|
833
|
+
lines.push(tpl(t("cmp.note.key"), { value: note.key }));
|
|
834
|
+
return lines.join("\n");
|
|
835
|
+
}
|
|
836
|
+
/** 整目录的引用文本(标题清单 + 稳定标识)。 */
|
|
837
|
+
function collectionText(t, collection, items, total) {
|
|
838
|
+
const head = tpl(t("cmp.collection.header"), {
|
|
839
|
+
name: collection.name,
|
|
840
|
+
key: collection.key,
|
|
841
|
+
n: total
|
|
842
|
+
});
|
|
843
|
+
const preview = items.slice(0, 50);
|
|
844
|
+
const lines = preview.map((item) => {
|
|
845
|
+
const meta = [item.creators, item.year].filter((part) => part !== "").join(", ");
|
|
846
|
+
return tpl(t("cmp.collection.line"), {
|
|
847
|
+
title: item.title,
|
|
848
|
+
meta
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
if (total > preview.length) lines.push(tpl(t("cmp.collection.more"), { n: preview.length }));
|
|
852
|
+
return [head, ...lines].join("\n");
|
|
853
|
+
}
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/client/cite.ts
|
|
856
|
+
/** 文库里已经没有这个对象(与「连不上 Zotero」区分开)。 */
|
|
857
|
+
function isMissing(error) {
|
|
858
|
+
return error instanceof ApiFailure && error.code === "zotero_not_found";
|
|
859
|
+
}
|
|
860
|
+
async function itemCitation(t, key, signal) {
|
|
861
|
+
try {
|
|
862
|
+
return itemText(t, await fetchItem(key, "apa", signal));
|
|
863
|
+
} catch (error) {
|
|
864
|
+
if (isMissing(error)) return tpl(t("cmp.missing.item"), { key });
|
|
865
|
+
throw error;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
async function collectionCitation(t, key, signal) {
|
|
869
|
+
const collection = (await fetchTree(signal)).collections.find((node) => node.key === key);
|
|
870
|
+
if (collection === void 0) return tpl(t("cmp.missing.collection"), { key });
|
|
871
|
+
const data = await fetchItems({
|
|
872
|
+
scope: collection.scope,
|
|
873
|
+
collectionKey: collection.scope === void 0 ? collection.key : void 0,
|
|
874
|
+
limit: 50
|
|
875
|
+
}, signal);
|
|
876
|
+
return collectionText(t, collection, data.items, data.total);
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* 拆子条目 ref。
|
|
880
|
+
*
|
|
881
|
+
* 结构坏了(缺分隔符或某一段为空)说明这个 chip 不是本插件写的,抛出去让宿主
|
|
882
|
+
* 还原草稿;这与「对象已不在文库里」不同,后者只发一行标记。
|
|
883
|
+
*/
|
|
884
|
+
function parseChildRef(body) {
|
|
885
|
+
const at = body.indexOf("/");
|
|
886
|
+
const parentKey = at < 0 ? "" : body.slice(0, at);
|
|
887
|
+
const childKey = at < 0 ? "" : body.slice(at + 1);
|
|
888
|
+
if (parentKey === "" || childKey === "") throw new Error(`无法识别的 Zotero 子条目引用:${body}`);
|
|
889
|
+
return {
|
|
890
|
+
parentKey,
|
|
891
|
+
childKey
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* 笔记 / 标注的取数都落在父条目的详情上,代价与条目引用同量级:`fetchItem` 会带上
|
|
896
|
+
* 附件全文与标注分页。Host 侧取标注失败时返回空数组,所以「取不到」既可能是真被删
|
|
897
|
+
* 了,也可能是那次请求降级——两者都发一行标记,不值得为区分它阻断发送。
|
|
898
|
+
*/
|
|
899
|
+
async function noteCitation(t, body, signal) {
|
|
900
|
+
const { parentKey, childKey } = parseChildRef(body);
|
|
901
|
+
let detail;
|
|
902
|
+
try {
|
|
903
|
+
detail = await fetchItem(parentKey, "apa", signal);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
if (isMissing(error)) return tpl(t("cmp.missing.note"), { key: childKey });
|
|
906
|
+
throw error;
|
|
907
|
+
}
|
|
908
|
+
const note = detail.notes.find((child) => child.key === childKey);
|
|
909
|
+
if (note === void 0) return tpl(t("cmp.missing.note"), { key: childKey });
|
|
910
|
+
return noteText(t, detail, note);
|
|
911
|
+
}
|
|
912
|
+
/** 一条标注的引用;chip 的 label 是原文摘要,提交时重建为完整引用文本。 */
|
|
913
|
+
async function annotationCitation(t, body, signal) {
|
|
914
|
+
const { parentKey, childKey } = parseChildRef(body);
|
|
915
|
+
let detail;
|
|
916
|
+
try {
|
|
917
|
+
detail = await fetchItem(parentKey, "apa", signal);
|
|
918
|
+
} catch (error) {
|
|
919
|
+
if (isMissing(error)) return tpl(t("cmp.missing.annotation"), { key: childKey });
|
|
920
|
+
throw error;
|
|
921
|
+
}
|
|
922
|
+
const annotation = detail.annotations.find((child) => child.key === childKey);
|
|
923
|
+
if (annotation === void 0) return tpl(t("cmp.missing.annotation"), { key: childKey });
|
|
924
|
+
return annotationText(t, detail, annotation);
|
|
925
|
+
}
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region src/client/reference.ts
|
|
928
|
+
/**
|
|
929
|
+
* 写进 chip 的持久标识:一旦发布就不能改名,老草稿里的 chip 靠它找回 codec。
|
|
930
|
+
*/
|
|
931
|
+
const REF_SOURCE = "zotero";
|
|
932
|
+
const ITEM_PREFIX = "item:";
|
|
933
|
+
const COLLECTION_PREFIX = "col:";
|
|
934
|
+
const NOTE_PREFIX = "note:";
|
|
935
|
+
const ANNOTATION_PREFIX = "ann:";
|
|
936
|
+
/** 笔记 / 标注是子条目,单靠自身 key 取不到所属条目,ref 存「父 key/子 key」。 */
|
|
937
|
+
const REF_SEPARATOR = "/";
|
|
938
|
+
/** 按 ref 前缀分派到对应的引用文本构建。 */
|
|
939
|
+
function citationForRef(t, ref, signal) {
|
|
940
|
+
if (ref.startsWith(ITEM_PREFIX)) return itemCitation(t, ref.slice(5), signal);
|
|
941
|
+
if (ref.startsWith(COLLECTION_PREFIX)) return collectionCitation(t, ref.slice(4), signal);
|
|
942
|
+
if (ref.startsWith(NOTE_PREFIX)) return noteCitation(t, ref.slice(5), signal);
|
|
943
|
+
if (ref.startsWith(ANNOTATION_PREFIX)) return annotationCitation(t, ref.slice(4), signal);
|
|
944
|
+
return Promise.reject(/* @__PURE__ */ new Error(`无法识别的 Zotero 引用:${ref}`));
|
|
945
|
+
}
|
|
946
|
+
function createZoteroSource(t) {
|
|
947
|
+
return {
|
|
948
|
+
trigger: "@",
|
|
949
|
+
name: REF_SOURCE,
|
|
950
|
+
candidates: () => Promise.resolve([]),
|
|
951
|
+
onPick: () => void 0,
|
|
952
|
+
codec: {
|
|
953
|
+
clipboardText: (ref) => `@${ref}`,
|
|
954
|
+
serialize: (ref, signal) => citationForRef(t, ref, signal)
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
function reference(prefix, key, title, appearance) {
|
|
959
|
+
const ref = `${prefix}${key}`;
|
|
960
|
+
return {
|
|
961
|
+
source: REF_SOURCE,
|
|
962
|
+
ref,
|
|
963
|
+
label: title === "" ? key : title,
|
|
964
|
+
appearance,
|
|
965
|
+
clipboardText: `@${ref}`
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
/** 一条文献的 chip。 */
|
|
969
|
+
function itemReference(key, title) {
|
|
970
|
+
return reference(ITEM_PREFIX, key, title, "file");
|
|
971
|
+
}
|
|
972
|
+
/** 一个目录的 chip。 */
|
|
973
|
+
function collectionReference(key, name) {
|
|
974
|
+
return reference(COLLECTION_PREFIX, key, name, "folder");
|
|
975
|
+
}
|
|
976
|
+
/** 子条目的 ref 前缀:`note:<父 key>/` 形式,后半段由 {@link reference} 拼上子 key。 */
|
|
977
|
+
function childPrefix(prefix, parentKey) {
|
|
978
|
+
return `${prefix}${parentKey}${REF_SEPARATOR}`;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* 一条笔记的 chip。
|
|
982
|
+
*
|
|
983
|
+
* `parentKey` 必须是面板当前条目的 key——独立笔记时它就是笔记自身,
|
|
984
|
+
* codec 用 `fetchItem(parentKey)` 复现笔记列表,与面板取数路径一致才找得到。
|
|
985
|
+
*/
|
|
986
|
+
function noteReference(parentKey, noteKey, title) {
|
|
987
|
+
return reference(childPrefix(NOTE_PREFIX, parentKey), noteKey, title, "file");
|
|
988
|
+
}
|
|
989
|
+
/** 一条标注(高亮 / 划线)的 chip。 */
|
|
990
|
+
function annotationReference(parentKey, annotationKey, label) {
|
|
991
|
+
return reference(childPrefix(ANNOTATION_PREFIX, parentKey), annotationKey, label, "file");
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* 把 chip 插进该会话的输入框。
|
|
995
|
+
*
|
|
996
|
+
* `thisArg` 必须显式传会话 ctx:cordis 的事件表挂在根 ctx 上,不带过滤参数会把
|
|
997
|
+
* **所有**会话的监听器都跑一遍,第一个返回 true 的赢——多开几个会话就会插错地方。
|
|
998
|
+
*/
|
|
999
|
+
function insertChip(sessions, sessionId, reference, span) {
|
|
1000
|
+
const actx = sessionId === void 0 ? void 0 : sessions.scope(sessionId);
|
|
1001
|
+
if (!actx) return false;
|
|
1002
|
+
return actx.bail(actx, "slash/input-insert-reference", {
|
|
1003
|
+
reference,
|
|
1004
|
+
span
|
|
1005
|
+
}) === true;
|
|
1006
|
+
}
|
|
1007
|
+
//#endregion
|
|
574
1008
|
//#region src/client/ZoteroCard.tsx
|
|
575
1009
|
/**
|
|
576
1010
|
* 插件页配置卡(浏览器半)。
|
|
@@ -885,6 +1319,115 @@ function ZoteroCard(props) {
|
|
|
885
1319
|
});
|
|
886
1320
|
}
|
|
887
1321
|
//#endregion
|
|
1322
|
+
//#region src/client/itemType.tsx
|
|
1323
|
+
/** Zotero schema 的 itemType 键 → 图标家族。 */
|
|
1324
|
+
const FAMILY = {
|
|
1325
|
+
journalArticle: "document",
|
|
1326
|
+
magazineArticle: "document",
|
|
1327
|
+
newspaperArticle: "document",
|
|
1328
|
+
conferencePaper: "document",
|
|
1329
|
+
preprint: "document",
|
|
1330
|
+
manuscript: "document",
|
|
1331
|
+
encyclopediaArticle: "document",
|
|
1332
|
+
dictionaryEntry: "document",
|
|
1333
|
+
blogPost: "document",
|
|
1334
|
+
forumPost: "document",
|
|
1335
|
+
letter: "document",
|
|
1336
|
+
email: "document",
|
|
1337
|
+
instantMessage: "document",
|
|
1338
|
+
interview: "document",
|
|
1339
|
+
presentation: "document",
|
|
1340
|
+
document: "document",
|
|
1341
|
+
book: "book",
|
|
1342
|
+
bookSection: "book",
|
|
1343
|
+
thesis: "thesis",
|
|
1344
|
+
report: "report",
|
|
1345
|
+
webpage: "webpage",
|
|
1346
|
+
dataset: "dataset",
|
|
1347
|
+
computerProgram: "software",
|
|
1348
|
+
case: "legal",
|
|
1349
|
+
statute: "legal",
|
|
1350
|
+
bill: "legal",
|
|
1351
|
+
hearing: "legal",
|
|
1352
|
+
patent: "legal",
|
|
1353
|
+
standard: "legal",
|
|
1354
|
+
artwork: "media",
|
|
1355
|
+
audioRecording: "media",
|
|
1356
|
+
film: "media",
|
|
1357
|
+
map: "media",
|
|
1358
|
+
podcast: "media",
|
|
1359
|
+
radioBroadcast: "media",
|
|
1360
|
+
tvBroadcast: "media",
|
|
1361
|
+
videoRecording: "media",
|
|
1362
|
+
note: "note",
|
|
1363
|
+
attachment: "attachment"
|
|
1364
|
+
};
|
|
1365
|
+
/** 每个家族一条 path(16×16 viewBox,描边绘制)。 */
|
|
1366
|
+
const PATH = {
|
|
1367
|
+
document: "M4.5 2.5h5l3 3v8h-8z M9.5 2.5v3h3 M6.5 8h4.5 M6.5 10.5h4.5",
|
|
1368
|
+
book: "M8 4.3c-1.4-1-3-1.4-4.7-1.2v8.8c1.7-.2 3.3.2 4.7 1.2 1.4-1 3-1.4 4.7-1.2V3.1C11 2.9 9.4 3.3 8 4.3z M8 4.3v8.8",
|
|
1369
|
+
thesis: "M8 3.2 13.4 5.9 8 8.6 2.6 5.9z M4.6 7.1v3.1c0 1.3 1.5 2.3 3.4 2.3s3.4-1 3.4-2.3V7.1 M13.4 5.9v3.2",
|
|
1370
|
+
report: "M5 2.5h5l3 3v8H5z M10 2.5v3h3 M7 8h4 M7 10.5h4 M2.6 5.2v1 M2.6 8v1 M2.6 10.8v1",
|
|
1371
|
+
webpage: "M2.8 4h10.4v8H2.8z M2.8 6.3h10.4 M4.2 5.15h.5 M5.6 5.15h.5",
|
|
1372
|
+
dataset: "M3.5 4.2c0-.8 2-1.5 4.5-1.5s4.5.7 4.5 1.5-2 1.5-4.5 1.5S3.5 5 3.5 4.2z M3.5 4.2v7.6c0 .8 2 1.5 4.5 1.5s4.5-.7 4.5-1.5V4.2 M3.5 8c0 .8 2 1.5 4.5 1.5s4.5-.7 4.5-1.5",
|
|
1373
|
+
software: "M6.1 5.4 3.6 8l2.5 2.6 M9.9 5.4 12.4 8l-2.5 2.6 M8.8 4.4 7.2 11.6",
|
|
1374
|
+
legal: "M6.2 4.4 8.4 2.2 11.8 5.6 9.6 7.8z M7.6 6.9 3.8 10.7 M3 12.6h5",
|
|
1375
|
+
media: "M3 4.6h10v6.8H3z M6.9 6.4 9.6 8 6.9 9.6z",
|
|
1376
|
+
note: "M4.5 3h7v10h-7z M4.5 5.6h7 M6.6 7.9h3.3 M6.6 9.9h3.3",
|
|
1377
|
+
attachment: "M9.6 3.5 4.9 8.2a1.9 1.9 0 0 0 2.7 2.7l4.7-4.7a3 3 0 0 0-4.2-4.2L3.4 6.7a4.2 4.2 0 0 0 5.9 5.9l1.2-1.2"
|
|
1378
|
+
};
|
|
1379
|
+
/** 已读图标的粉色:不用主题蓝,蓝色容易被读成「未读消息」徽标。 */
|
|
1380
|
+
const READ_ICON_COLOR = "#e8798d";
|
|
1381
|
+
/** 条目类型图标;未知类型显示文档图标,已读条目整体转粉色。 */
|
|
1382
|
+
function ItemTypeIcon({ itemType, read = false }) {
|
|
1383
|
+
const family = FAMILY[itemType] ?? "document";
|
|
1384
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
1385
|
+
width: 14,
|
|
1386
|
+
height: 14,
|
|
1387
|
+
viewBox: "0 0 16 16",
|
|
1388
|
+
fill: "none",
|
|
1389
|
+
stroke: "currentColor",
|
|
1390
|
+
strokeWidth: 1.3,
|
|
1391
|
+
strokeLinejoin: "round",
|
|
1392
|
+
strokeLinecap: "round",
|
|
1393
|
+
style: {
|
|
1394
|
+
opacity: read ? .9 : .65,
|
|
1395
|
+
color: read ? READ_ICON_COLOR : void 0
|
|
1396
|
+
},
|
|
1397
|
+
"aria-hidden": true,
|
|
1398
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: PATH[family] })
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
/** 条目类型的本地化名称;未收录的类型回退为原始 schema 键。 */
|
|
1402
|
+
function itemTypeLabel(t, itemType) {
|
|
1403
|
+
if (itemType === "") return "";
|
|
1404
|
+
const key = `type.${itemType}`;
|
|
1405
|
+
const label = t(key);
|
|
1406
|
+
return label === "" || label === key ? itemType : label;
|
|
1407
|
+
}
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region src/client/readState.tsx
|
|
1410
|
+
/** 已读条目标题的淡化程度:留一点提示,又不至于看成禁用态。 */
|
|
1411
|
+
const READ_TITLE_OPACITY = .75;
|
|
1412
|
+
function isRead(item) {
|
|
1413
|
+
return item.lastRead !== null;
|
|
1414
|
+
}
|
|
1415
|
+
/** 已读条目的标题淡化;未读返回空对象,直接展开不影响原有样式。 */
|
|
1416
|
+
function readTitleStyle(read) {
|
|
1417
|
+
return read ? { opacity: READ_TITLE_OPACITY } : {};
|
|
1418
|
+
}
|
|
1419
|
+
/** 行内 hover 提示:类型、读过的补一行最后阅读时间。 */
|
|
1420
|
+
function itemTooltip(t, item) {
|
|
1421
|
+
const lines = [item.title];
|
|
1422
|
+
const type = itemTypeLabel(t, item.itemType);
|
|
1423
|
+
if (type !== "") lines.push(tpl(t("item.type"), { type }));
|
|
1424
|
+
if (item.lastRead !== null) {
|
|
1425
|
+
const date = (/* @__PURE__ */ new Date(item.lastRead * 1e3)).toLocaleDateString();
|
|
1426
|
+
lines.push(tpl(t("item.lastRead"), { date }));
|
|
1427
|
+
}
|
|
1428
|
+
return lines.join("\n");
|
|
1429
|
+
}
|
|
1430
|
+
//#endregion
|
|
888
1431
|
//#region src/client/CollectionTree.tsx
|
|
889
1432
|
/**
|
|
890
1433
|
* 左栏:文库分类树 + 条目叶子(Zotero 风格)。
|
|
@@ -938,7 +1481,6 @@ function glyph(path) {
|
|
|
938
1481
|
});
|
|
939
1482
|
}
|
|
940
1483
|
const FOLDER_ICON = "M2.5 12.5V4.5a1 1 0 0 1 1-1h3L8 5h4.5a1 1 0 0 1 1 1v6.5a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1z";
|
|
941
|
-
const ITEM_ICON = "M4.5 2.5h5L12 5v8.5H4.5zM9.5 2.5V5H12";
|
|
942
1484
|
const LIBRARY_ICON = "M2.5 3.5h5v9h-5zM8.5 3.5h5v9h-5z";
|
|
943
1485
|
/** 虚拟分类的图标 path(键与 {@link VIRTUAL_NODES.icon} 对应)。 */
|
|
944
1486
|
const VIRTUAL_ICON = {
|
|
@@ -1062,12 +1604,13 @@ function Chevron({ open, onToggle }) {
|
|
|
1062
1604
|
function ItemRow({ ctx, item, depth }) {
|
|
1063
1605
|
const [menuOpen, setMenuOpen] = (0, react.useState)(false);
|
|
1064
1606
|
const meta = [item.creators, item.year].filter((part) => part !== "").join(" · ");
|
|
1607
|
+
const read = isRead(item);
|
|
1065
1608
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
|
|
1066
1609
|
open: menuOpen,
|
|
1067
1610
|
onClose: () => setMenuOpen(false),
|
|
1068
1611
|
onSelect: (id) => {
|
|
1069
1612
|
setMenuOpen(false);
|
|
1070
|
-
if (id === "insert-item") ctx.onInsertItem(item
|
|
1613
|
+
if (id === "insert-item") ctx.onInsertItem(item);
|
|
1071
1614
|
},
|
|
1072
1615
|
align: "end",
|
|
1073
1616
|
portal: true,
|
|
@@ -1076,6 +1619,7 @@ function ItemRow({ ctx, item, depth }) {
|
|
|
1076
1619
|
label: ctx.t("action.insertItem")
|
|
1077
1620
|
}],
|
|
1078
1621
|
anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1622
|
+
title: itemTooltip(ctx.t, item),
|
|
1079
1623
|
onClick: () => ctx.onSelectItem(item.key),
|
|
1080
1624
|
onContextMenu: (event) => {
|
|
1081
1625
|
event.preventDefault();
|
|
@@ -1090,11 +1634,16 @@ function ItemRow({ ctx, item, depth }) {
|
|
|
1090
1634
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: iconBox }),
|
|
1091
1635
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1092
1636
|
style: iconBox,
|
|
1093
|
-
children:
|
|
1637
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemTypeIcon, {
|
|
1638
|
+
itemType: item.itemType,
|
|
1639
|
+
read
|
|
1640
|
+
})
|
|
1094
1641
|
}),
|
|
1095
1642
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1096
|
-
style:
|
|
1097
|
-
|
|
1643
|
+
style: {
|
|
1644
|
+
...titleStyle,
|
|
1645
|
+
...readTitleStyle(read)
|
|
1646
|
+
},
|
|
1098
1647
|
children: item.title
|
|
1099
1648
|
}),
|
|
1100
1649
|
meta !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
@@ -1323,180 +1872,6 @@ function CollectionTree(props) {
|
|
|
1323
1872
|
});
|
|
1324
1873
|
}
|
|
1325
1874
|
//#endregion
|
|
1326
|
-
//#region src/client/annotationComment.ts
|
|
1327
|
-
/** 只有这些标签有意义;属性不会出现,仍容忍以防手改。 */
|
|
1328
|
-
const TAG_SOURCE = "<\\/?(?:b|i|sub|sup|br|div)\\b[^>]*>";
|
|
1329
|
-
function tagRegex() {
|
|
1330
|
-
return new RegExp(TAG_SOURCE, "giu");
|
|
1331
|
-
}
|
|
1332
|
-
/** 评论 → 渲染 token;不平衡的闭合标签直接忽略。 */
|
|
1333
|
-
function parseComment(comment) {
|
|
1334
|
-
const tokens = [];
|
|
1335
|
-
let bold = 0;
|
|
1336
|
-
let italic = 0;
|
|
1337
|
-
let sub = 0;
|
|
1338
|
-
let sup = 0;
|
|
1339
|
-
let last = 0;
|
|
1340
|
-
const pushText = (text) => {
|
|
1341
|
-
if (text === "") return;
|
|
1342
|
-
tokens.push({
|
|
1343
|
-
kind: "text",
|
|
1344
|
-
text,
|
|
1345
|
-
bold: bold > 0,
|
|
1346
|
-
italic: italic > 0,
|
|
1347
|
-
sub: sub > 0,
|
|
1348
|
-
sup: sup > 0
|
|
1349
|
-
});
|
|
1350
|
-
};
|
|
1351
|
-
for (const match of comment.matchAll(tagRegex())) {
|
|
1352
|
-
const index = match.index ?? 0;
|
|
1353
|
-
pushText(comment.slice(last, index));
|
|
1354
|
-
last = index + match[0].length;
|
|
1355
|
-
const tag = match[0].toLowerCase();
|
|
1356
|
-
const closing = tag.startsWith("</");
|
|
1357
|
-
const name = tag.replace(/[</>\s]/gu, "");
|
|
1358
|
-
if (name === "br" || name === "div") {
|
|
1359
|
-
if (!closing) tokens.push({
|
|
1360
|
-
kind: "break",
|
|
1361
|
-
text: "",
|
|
1362
|
-
bold: false,
|
|
1363
|
-
italic: false,
|
|
1364
|
-
sub: false,
|
|
1365
|
-
sup: false
|
|
1366
|
-
});
|
|
1367
|
-
continue;
|
|
1368
|
-
}
|
|
1369
|
-
const delta = closing ? -1 : 1;
|
|
1370
|
-
if (name === "b") bold = Math.max(0, bold + delta);
|
|
1371
|
-
else if (name === "i") italic = Math.max(0, italic + delta);
|
|
1372
|
-
else if (name === "sub") sub = Math.max(0, sub + delta);
|
|
1373
|
-
else if (name === "sup") sup = Math.max(0, sup + delta);
|
|
1374
|
-
}
|
|
1375
|
-
pushText(comment.slice(last));
|
|
1376
|
-
while (tokens[0]?.kind === "break") tokens.shift();
|
|
1377
|
-
while (tokens[tokens.length - 1]?.kind === "break") tokens.pop();
|
|
1378
|
-
return tokens;
|
|
1379
|
-
}
|
|
1380
|
-
/** 去标签与换行,供插入草稿使用。 */
|
|
1381
|
-
function commentPlain(comment) {
|
|
1382
|
-
return comment.replace(tagRegex(), " ").replace(/\s+/gu, " ").trim();
|
|
1383
|
-
}
|
|
1384
|
-
/** 是否有可显示的内容(纯空白不算)。 */
|
|
1385
|
-
function hasComment(comment) {
|
|
1386
|
-
return commentPlain(comment) !== "";
|
|
1387
|
-
}
|
|
1388
|
-
//#endregion
|
|
1389
|
-
//#region src/client/compose.ts
|
|
1390
|
-
/** 整目录插入时最多列出多少条(完整清单交给模型的 MCP 工具)。 */
|
|
1391
|
-
const COLLECTION_PREVIEW_LIMIT$1 = 50;
|
|
1392
|
-
function line(t, key, value) {
|
|
1393
|
-
return tpl(t(key), { value });
|
|
1394
|
-
}
|
|
1395
|
-
/** 单条目的引用文本。 */
|
|
1396
|
-
function itemText(t, detail) {
|
|
1397
|
-
const lines = [tpl(t("cmp.item.header"), {
|
|
1398
|
-
key: detail.key,
|
|
1399
|
-
title: detail.title
|
|
1400
|
-
})];
|
|
1401
|
-
if (detail.creators.length > 0) lines.push(line(t, "cmp.item.creators", detail.creators.join("、")));
|
|
1402
|
-
if (detail.year !== "") lines.push(line(t, "cmp.item.year", detail.year));
|
|
1403
|
-
if (detail.publicationTitle !== "") lines.push(line(t, "cmp.item.source", detail.publicationTitle));
|
|
1404
|
-
if (detail.doi !== "") lines.push(line(t, "cmp.item.doi", detail.doi));
|
|
1405
|
-
if (detail.url !== "") lines.push(line(t, "cmp.item.url", detail.url));
|
|
1406
|
-
if (detail.tags.length > 0) lines.push(line(t, "cmp.item.tags", detail.tags.join("、")));
|
|
1407
|
-
if (detail.abstract !== "") lines.push(line(t, "cmp.item.abstract", detail.abstract));
|
|
1408
|
-
return lines.join("\n");
|
|
1409
|
-
}
|
|
1410
|
-
/** 选中片段的摘录文本。 */
|
|
1411
|
-
function excerptText(t, detail, quote) {
|
|
1412
|
-
return `${tpl(t("cmp.excerpt.header"), {
|
|
1413
|
-
title: detail.title,
|
|
1414
|
-
key: detail.key
|
|
1415
|
-
})}\n${tpl(t("cmp.excerpt.quote"), { value: quote })}`;
|
|
1416
|
-
}
|
|
1417
|
-
/**
|
|
1418
|
-
* PDF 抽取会在汉字之间插空格(`硫 化 氢`),展示与插入时去掉;
|
|
1419
|
-
* 只处理汉字与汉字之间的空格,避免动到西文词距。
|
|
1420
|
-
*/
|
|
1421
|
-
function tidyAnnotation(text) {
|
|
1422
|
-
return text.replace(/\s+/gu, " ").replace(/(?<=[\u3400-\u9fff])\s+(?=[\u3400-\u9fff])/gu, "").trim();
|
|
1423
|
-
}
|
|
1424
|
-
/** 一条标注的引用文本:原文 + 类型 + 页码 + 评论 + 标注 key。 */
|
|
1425
|
-
function annotationText(t, detail, annotation) {
|
|
1426
|
-
const comment = commentPlain(annotation.comment);
|
|
1427
|
-
const quote = tidyAnnotation(annotation.text) || comment;
|
|
1428
|
-
const type = annotation.type === "underline" ? t("annotation.type.underline") : t("annotation.type.highlight");
|
|
1429
|
-
const lines = [excerptText(t, detail, quote), tpl(t("cmp.annotation.type"), { value: type })];
|
|
1430
|
-
if (annotation.pageLabel !== "") lines.push(tpl(t("cmp.annotation.page"), { value: annotation.pageLabel }));
|
|
1431
|
-
if (comment !== "" && quote !== comment) lines.push(tpl(t("cmp.annotation.comment"), { value: comment }));
|
|
1432
|
-
lines.push(tpl(t("cmp.annotation.key"), { value: annotation.key }));
|
|
1433
|
-
return lines.join("\n");
|
|
1434
|
-
}
|
|
1435
|
-
/** 命名实体的最小集合(与 Host 清洗后的笔记 HTML 对齐)。 */
|
|
1436
|
-
const NAMED_ENTITIES = {
|
|
1437
|
-
nbsp: " ",
|
|
1438
|
-
amp: String.fromCharCode(38),
|
|
1439
|
-
lt: String.fromCharCode(60),
|
|
1440
|
-
gt: String.fromCharCode(62),
|
|
1441
|
-
quot: String.fromCharCode(34),
|
|
1442
|
-
apos: String.fromCharCode(39)
|
|
1443
|
-
};
|
|
1444
|
-
/** 解码 HTML 实体;未识别的实体原样保留。 */
|
|
1445
|
-
function decodeEntities(text) {
|
|
1446
|
-
return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/giu, (match, body) => {
|
|
1447
|
-
if (body.startsWith("#x") || body.startsWith("#X")) {
|
|
1448
|
-
const code = Number.parseInt(body.slice(2), 16);
|
|
1449
|
-
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
1450
|
-
}
|
|
1451
|
-
if (body.startsWith("#")) {
|
|
1452
|
-
const code = Number.parseInt(body.slice(1), 10);
|
|
1453
|
-
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
1454
|
-
}
|
|
1455
|
-
return NAMED_ENTITIES[body.toLowerCase()] ?? match;
|
|
1456
|
-
});
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* 笔记 HTML → 纯文本:块级标签转换行、列表项加 `- `,剥标签后解码实体。
|
|
1460
|
-
*
|
|
1461
|
-
* 只保留段落与列表结构,图片等没有文本的可选内容自然消失。
|
|
1462
|
-
*/
|
|
1463
|
-
function noteHtmlToText(html) {
|
|
1464
|
-
return decodeEntities(html.replace(/<br\s*\/?>/giu, "\n").replace(/<\/(?:p|div|h[1-6]|blockquote|li|tr|ul|ol|table|figure|figcaption|pre)>/giu, "\n").replace(/<li\b[^>]*>/giu, "- ").replace(/<[^>]*>/gu, "")).replace(/\u00a0/gu, " ").replace(/[ \t]+/gu, " ").replace(/ *\n */gu, "\n").replace(/(^|\n)- *\n/gu, "$1- ").replace(/\n{2,}(?=- )/gu, "\n").replace(/\n{3,}/gu, "\n\n").trim();
|
|
1465
|
-
}
|
|
1466
|
-
/** 单条笔记的引用文本:所属条目 + 正文纯文本 + 截断提示 + 更新日期 + 笔记 key。 */
|
|
1467
|
-
function noteText(t, detail, note) {
|
|
1468
|
-
const head = tpl(t("cmp.note.header"), {
|
|
1469
|
-
title: detail.title,
|
|
1470
|
-
key: detail.key
|
|
1471
|
-
});
|
|
1472
|
-
const body = noteHtmlToText(note.html);
|
|
1473
|
-
const lines = [head];
|
|
1474
|
-
if (body !== "") lines.push(body);
|
|
1475
|
-
if (note.truncated) lines.push(t("cmp.note.truncated"));
|
|
1476
|
-
const date = note.dateModified.slice(0, 10);
|
|
1477
|
-
if (date !== "") lines.push(tpl(t("cmp.note.date"), { value: date }));
|
|
1478
|
-
lines.push(tpl(t("cmp.note.key"), { value: note.key }));
|
|
1479
|
-
return lines.join("\n");
|
|
1480
|
-
}
|
|
1481
|
-
/** 整目录的引用文本(标题清单 + 稳定标识)。 */
|
|
1482
|
-
function collectionText(t, collection, items, total) {
|
|
1483
|
-
const head = tpl(t("cmp.collection.header"), {
|
|
1484
|
-
name: collection.name,
|
|
1485
|
-
key: collection.key,
|
|
1486
|
-
n: total
|
|
1487
|
-
});
|
|
1488
|
-
const preview = items.slice(0, COLLECTION_PREVIEW_LIMIT$1);
|
|
1489
|
-
const lines = preview.map((item) => {
|
|
1490
|
-
const meta = [item.creators, item.year].filter((part) => part !== "").join(", ");
|
|
1491
|
-
return tpl(t("cmp.collection.line"), {
|
|
1492
|
-
title: item.title,
|
|
1493
|
-
meta
|
|
1494
|
-
});
|
|
1495
|
-
});
|
|
1496
|
-
if (total > preview.length) lines.push(tpl(t("cmp.collection.more"), { n: preview.length }));
|
|
1497
|
-
return [head, ...lines].join("\n");
|
|
1498
|
-
}
|
|
1499
|
-
//#endregion
|
|
1500
1875
|
//#region src/client/inline.ts
|
|
1501
1876
|
/**
|
|
1502
1877
|
* 捕获草稿当前位置,再构建文本并插入。
|
|
@@ -2046,7 +2421,7 @@ function tabButtonStyle(selected) {
|
|
|
2046
2421
|
* 这里直接以 `dangerouslySetInnerHTML` 渲染。
|
|
2047
2422
|
*
|
|
2048
2423
|
* 每条笔记默认折叠成一行标题(正文首段摘要),点击标题展开正文;
|
|
2049
|
-
*
|
|
2424
|
+
* 行尾「引用」往会话输入框插一个笔记 chip,正文在提交那一刻才展开成文本。
|
|
2050
2425
|
*/
|
|
2051
2426
|
function NoteList({ t, notes, onInsert }) {
|
|
2052
2427
|
const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
|
|
@@ -2446,6 +2821,11 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
|
|
|
2446
2821
|
});
|
|
2447
2822
|
const hasBottom = tabs.length > 0;
|
|
2448
2823
|
const metaRows = [];
|
|
2824
|
+
const typeLabel = itemTypeLabel(t, detail.itemType);
|
|
2825
|
+
if (typeLabel !== "") metaRows.push({
|
|
2826
|
+
label: t("detail.type"),
|
|
2827
|
+
value: typeLabel
|
|
2828
|
+
});
|
|
2449
2829
|
if (detail.creators.length > 0) metaRows.push({
|
|
2450
2830
|
label: t("detail.creators"),
|
|
2451
2831
|
value: detail.creators.join("、")
|
|
@@ -2779,11 +3159,10 @@ const linkRowStyle = {
|
|
|
2779
3159
|
* 右侧栏面板容器:头部状态栏 + 左分类树 + 右详情。
|
|
2780
3160
|
*
|
|
2781
3161
|
* 两栏之间是可拖动的分隔条(宽度存 localStorage,跨会话/重启都记住)。
|
|
2782
|
-
* 数据与选择状态都在 {@link paneStore}
|
|
2783
|
-
*
|
|
3162
|
+
* 数据与选择状态都在 {@link paneStore} 的模块级单例里(跨会话共用同一块面板)。
|
|
3163
|
+
* 「添加到会话」走 ui-conversation 下发的会话级标准 prop:条目、整目录、笔记、
|
|
3164
|
+
* 标注都插引用 chip(见 reference.ts),只有摘录仍插纯文本。
|
|
2784
3165
|
*/
|
|
2785
|
-
/** 整目录插入时拉取的条目数(与 compose 的预览上限一致)。 */
|
|
2786
|
-
const COLLECTION_PREVIEW_LIMIT = 50;
|
|
2787
3166
|
/** 左栏宽度的存储键与取值范围。 */
|
|
2788
3167
|
const TREE_WIDTH_KEY = "dsh-plugin-zotero.treeWidth";
|
|
2789
3168
|
const TREE_WIDTH_DEFAULT = 260;
|
|
@@ -2819,7 +3198,7 @@ function StatusDot({ ok, label }) {
|
|
|
2819
3198
|
} }), label]
|
|
2820
3199
|
});
|
|
2821
3200
|
}
|
|
2822
|
-
function ZoteroPane({ t, inputActions }) {
|
|
3201
|
+
function ZoteroPane({ t, inputActions, sessions, sessionId }) {
|
|
2823
3202
|
const { health, libraryName, collections, treeError, treeLoading, query, results, selectedItemKey, selectedCollection, detail, detailLoading, detailError, collectionBib, nodeItems, nodeErrors, toast } = usePaneState();
|
|
2824
3203
|
(0, react.useEffect)(() => {
|
|
2825
3204
|
loadTree();
|
|
@@ -2860,16 +3239,24 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
2860
3239
|
else if (outcome === "no-editor") showToast(t("error.noEditor"));
|
|
2861
3240
|
else showToast(t("error.draftChanged"));
|
|
2862
3241
|
}, [t]);
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
3242
|
+
/**
|
|
3243
|
+
* 插一个引用 chip:草稿里只留 key,完整文本在提交那一刻由引用源的 codec 现取。
|
|
3244
|
+
*/
|
|
3245
|
+
const insertReference = (0, react.useCallback)((reference) => {
|
|
3246
|
+
if (!inputActions) {
|
|
3247
|
+
report("no-editor");
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3250
|
+
report(insertChip(sessions, sessionId, reference, inputActions.captureInsertion()) ? "inserted" : "draft-changed");
|
|
2867
3251
|
}, [
|
|
2868
|
-
detail,
|
|
2869
3252
|
inputActions,
|
|
2870
3253
|
report,
|
|
2871
|
-
|
|
3254
|
+
sessionId,
|
|
3255
|
+
sessions
|
|
2872
3256
|
]);
|
|
3257
|
+
const insertItem = (0, react.useCallback)((key, title) => {
|
|
3258
|
+
insertReference(itemReference(key, title));
|
|
3259
|
+
}, [insertReference]);
|
|
2873
3260
|
const insertExcerpt = (0, react.useCallback)(async (target, quote) => {
|
|
2874
3261
|
report(await insertBuilt(inputActions, () => excerptText(t, target, quote)));
|
|
2875
3262
|
}, [
|
|
@@ -2877,34 +3264,15 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
2877
3264
|
report,
|
|
2878
3265
|
t
|
|
2879
3266
|
]);
|
|
2880
|
-
const insertAnnotation = (0, react.useCallback)(
|
|
2881
|
-
|
|
2882
|
-
}, [
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
}, [
|
|
2890
|
-
inputActions,
|
|
2891
|
-
report,
|
|
2892
|
-
t
|
|
2893
|
-
]);
|
|
2894
|
-
const insertCollection = (0, react.useCallback)(async (collection) => {
|
|
2895
|
-
report(await insertBuilt(inputActions, async () => {
|
|
2896
|
-
const data = await fetchItems({
|
|
2897
|
-
scope: collection.scope,
|
|
2898
|
-
collectionKey: collection.scope === void 0 ? collection.key : void 0,
|
|
2899
|
-
limit: COLLECTION_PREVIEW_LIMIT
|
|
2900
|
-
});
|
|
2901
|
-
return collectionText(t, collection, data.items, data.total);
|
|
2902
|
-
}));
|
|
2903
|
-
}, [
|
|
2904
|
-
inputActions,
|
|
2905
|
-
report,
|
|
2906
|
-
t
|
|
2907
|
-
]);
|
|
3267
|
+
const insertAnnotation = (0, react.useCallback)((target, annotation) => {
|
|
3268
|
+
insertReference(annotationReference(target.key, annotation.key, annotationChipLabel(t, annotation)));
|
|
3269
|
+
}, [insertReference, t]);
|
|
3270
|
+
const insertNote = (0, react.useCallback)((target, note) => {
|
|
3271
|
+
insertReference(noteReference(target.key, note.key, note.title));
|
|
3272
|
+
}, [insertReference]);
|
|
3273
|
+
const insertCollection = (0, react.useCallback)((collection) => {
|
|
3274
|
+
insertReference(collectionReference(collection.key, collection.name));
|
|
3275
|
+
}, [insertReference]);
|
|
2908
3276
|
/** 分类详情里的条目列表:与左侧树共用同一份缓存(选中分类时树已按需拉取)。 */
|
|
2909
3277
|
const collectionItems = selectedCollection === null ? void 0 : nodeItems[selectedCollection.key];
|
|
2910
3278
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -2994,21 +3362,37 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
2994
3362
|
children: t("tree.empty")
|
|
2995
3363
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2996
3364
|
style: { padding: "8px 6px" },
|
|
2997
|
-
children: results.map((item) =>
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
children:
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3365
|
+
children: results.map((item) => {
|
|
3366
|
+
const read = isRead(item);
|
|
3367
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3368
|
+
title: itemTooltip(t, item),
|
|
3369
|
+
onClick: () => openItem(item.key),
|
|
3370
|
+
style: {
|
|
3371
|
+
...resultRowStyle,
|
|
3372
|
+
background: selectedItemKey === item.key ? "rgba(127,127,127,0.16)" : "transparent"
|
|
3373
|
+
},
|
|
3374
|
+
children: [
|
|
3375
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3376
|
+
style: itemIconStyle,
|
|
3377
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemTypeIcon, {
|
|
3378
|
+
itemType: item.itemType,
|
|
3379
|
+
read
|
|
3380
|
+
})
|
|
3381
|
+
}),
|
|
3382
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3383
|
+
style: {
|
|
3384
|
+
...resultTitleStyle,
|
|
3385
|
+
...readTitleStyle(read)
|
|
3386
|
+
},
|
|
3387
|
+
children: item.title
|
|
3388
|
+
}),
|
|
3389
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3390
|
+
style: resultMetaStyle,
|
|
3391
|
+
children: [item.creators, item.year].filter((p) => p !== "").join(" · ")
|
|
3392
|
+
})
|
|
3393
|
+
]
|
|
3394
|
+
}, item.key);
|
|
3395
|
+
})
|
|
3012
3396
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CollectionTree, {
|
|
3013
3397
|
t,
|
|
3014
3398
|
collections,
|
|
@@ -3016,8 +3400,8 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
3016
3400
|
selectedCollectionKey: selectedCollection?.key ?? null,
|
|
3017
3401
|
onSelectItem: openItem,
|
|
3018
3402
|
onSelectCollection: selectCollection,
|
|
3019
|
-
onInsertItem: (
|
|
3020
|
-
onInsertCollection:
|
|
3403
|
+
onInsertItem: (item) => insertItem(item.key, item.title),
|
|
3404
|
+
onInsertCollection: insertCollection
|
|
3021
3405
|
})
|
|
3022
3406
|
})]
|
|
3023
3407
|
}),
|
|
@@ -3073,10 +3457,10 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
3073
3457
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemDetail, {
|
|
3074
3458
|
t,
|
|
3075
3459
|
detail,
|
|
3076
|
-
onInsertItem: () =>
|
|
3460
|
+
onInsertItem: () => insertItem(detail.key, detail.title),
|
|
3077
3461
|
onInsertExcerpt: (quote) => void insertExcerpt(detail, quote),
|
|
3078
|
-
onInsertAnnotation: (annotation) =>
|
|
3079
|
-
onInsertNote: (note) =>
|
|
3462
|
+
onInsertAnnotation: (annotation) => insertAnnotation(detail, annotation),
|
|
3463
|
+
onInsertNote: (note) => insertNote(detail, note),
|
|
3080
3464
|
onOpenItem: openItem
|
|
3081
3465
|
}) : selectedCollection !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3082
3466
|
style: { padding: "12px 14px" },
|
|
@@ -3098,7 +3482,7 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
3098
3482
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
|
|
3099
3483
|
variant: "outline",
|
|
3100
3484
|
size: "sm",
|
|
3101
|
-
onClick: () =>
|
|
3485
|
+
onClick: () => insertCollection(selectedCollection),
|
|
3102
3486
|
children: t("action.insertCollection")
|
|
3103
3487
|
}),
|
|
3104
3488
|
selectedCollection.scope === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
@@ -3134,18 +3518,34 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
3134
3518
|
margin: "16px 0 6px"
|
|
3135
3519
|
},
|
|
3136
3520
|
children: t("detail.items")
|
|
3137
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: collectionItems.map((item) =>
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
children:
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3521
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: collectionItems.map((item) => {
|
|
3522
|
+
const read = isRead(item);
|
|
3523
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3524
|
+
title: itemTooltip(t, item),
|
|
3525
|
+
onClick: () => openItem(item.key),
|
|
3526
|
+
style: resultRowStyle,
|
|
3527
|
+
children: [
|
|
3528
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3529
|
+
style: itemIconStyle,
|
|
3530
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemTypeIcon, {
|
|
3531
|
+
itemType: item.itemType,
|
|
3532
|
+
read
|
|
3533
|
+
})
|
|
3534
|
+
}),
|
|
3535
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3536
|
+
style: {
|
|
3537
|
+
...resultTitleStyle,
|
|
3538
|
+
...readTitleStyle(read)
|
|
3539
|
+
},
|
|
3540
|
+
children: item.title
|
|
3541
|
+
}),
|
|
3542
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3543
|
+
style: resultMetaStyle,
|
|
3544
|
+
children: [item.creators, item.year].filter((part) => part !== "").join(" · ")
|
|
3545
|
+
})
|
|
3546
|
+
]
|
|
3547
|
+
}, item.key);
|
|
3548
|
+
}) })] })
|
|
3149
3549
|
]
|
|
3150
3550
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3151
3551
|
style: hintStyle,
|
|
@@ -3201,6 +3601,12 @@ const resultMetaStyle = {
|
|
|
3201
3601
|
opacity: .5,
|
|
3202
3602
|
fontSize: 11.5
|
|
3203
3603
|
};
|
|
3604
|
+
/** 列表行首的类型图标:基线对齐的行里改为垂直居中。 */
|
|
3605
|
+
const itemIconStyle = {
|
|
3606
|
+
display: "flex",
|
|
3607
|
+
alignSelf: "center",
|
|
3608
|
+
flexShrink: 0
|
|
3609
|
+
};
|
|
3204
3610
|
//#endregion
|
|
3205
3611
|
//#region src/client/index.ts
|
|
3206
3612
|
/**
|
|
@@ -3208,7 +3614,11 @@ const resultMetaStyle = {
|
|
|
3208
3614
|
*
|
|
3209
3615
|
* 在右侧栏注册一个「页」类型 tab(不给 patterns,走 guide 入口),并把面板
|
|
3210
3616
|
* 正文注册到 `sidebar.right.pane.tab` 席位。会话级标准 prop `inputActions`
|
|
3211
|
-
*
|
|
3617
|
+
* (ui-conversation 下发)与 `sessionId`(ui-session 下发)随槽位作用域透传给
|
|
3618
|
+
* 正文。
|
|
3619
|
+
*
|
|
3620
|
+
* 同时注册一个 Zotero 引用源(见 reference.ts):面板插的引用 chip 靠它的 codec
|
|
3621
|
+
* 在提交时展开成模型文本。它不进 `@` 菜单(候选恒空)。
|
|
3212
3622
|
*
|
|
3213
3623
|
* 注意:cordis 的对象式 inject 是「拦截 config」,不是 {required,optional},
|
|
3214
3624
|
* 因此这里用数组式 inject。
|
|
@@ -3220,7 +3630,9 @@ const inject = [
|
|
|
3220
3630
|
"slots",
|
|
3221
3631
|
"locale",
|
|
3222
3632
|
"sidebarRightTabs",
|
|
3223
|
-
"configForms"
|
|
3633
|
+
"configForms",
|
|
3634
|
+
"inputTriggers",
|
|
3635
|
+
"sessions"
|
|
3224
3636
|
];
|
|
3225
3637
|
function apply(ctx) {
|
|
3226
3638
|
ctx.effect(() => ctx.locale.register(NS, dicts), "dsh-plugin-zotero: dictionaries");
|
|
@@ -3236,9 +3648,12 @@ function apply(ctx) {
|
|
|
3236
3648
|
order: 10
|
|
3237
3649
|
}]
|
|
3238
3650
|
}), "dsh-plugin-zotero: sidebar tab");
|
|
3651
|
+
ctx.effect(() => ctx.inputTriggers.registerSource(createZoteroSource(t)), "dsh-plugin-zotero: reference codec");
|
|
3239
3652
|
const Body = (props) => (0, react.createElement)(ZoteroPane, {
|
|
3240
3653
|
t,
|
|
3241
|
-
|
|
3654
|
+
sessions: ctx.sessions,
|
|
3655
|
+
inputActions: props.inputActions,
|
|
3656
|
+
sessionId: props.sessionId
|
|
3242
3657
|
});
|
|
3243
3658
|
ctx.effect(() => ctx.slots.register({
|
|
3244
3659
|
name: "sidebar.right.pane.tab",
|
package/lib/zotero/client.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ interface RawItemData {
|
|
|
45
45
|
note?: string;
|
|
46
46
|
/** 标注所属附件,仅 `itemType === 'annotation'` 有。 */
|
|
47
47
|
parentItem?: string | false;
|
|
48
|
+
/** 附件最后阅读时间(Unix 秒);本地 API 在附件 JSON 里直接给出。 */
|
|
49
|
+
lastRead?: number;
|
|
48
50
|
annotationType?: string;
|
|
49
51
|
annotationText?: string;
|
|
50
52
|
annotationComment?: string;
|
package/lib/zotero/client.js
CHANGED
|
@@ -173,7 +173,7 @@ function toNote(raw) {
|
|
|
173
173
|
truncated,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
|
-
function toSummary(raw) {
|
|
176
|
+
function toSummary(raw, lastRead) {
|
|
177
177
|
const data = raw.data ?? {};
|
|
178
178
|
const itemType = data.itemType ?? '';
|
|
179
179
|
const hasAttachment = itemType === 'attachment'
|
|
@@ -193,8 +193,24 @@ function toSummary(raw) {
|
|
|
193
193
|
year: yearOf(raw.meta, data),
|
|
194
194
|
itemType,
|
|
195
195
|
hasAttachment,
|
|
196
|
+
lastRead,
|
|
196
197
|
};
|
|
197
198
|
}
|
|
199
|
+
/** 附件自己的 `lastRead` 就在它的 JSON 里,笔记没有,其余条目去问子附件。 */
|
|
200
|
+
function lastReadOf(raw) {
|
|
201
|
+
const data = raw.data ?? {};
|
|
202
|
+
if (data.itemType === 'attachment') {
|
|
203
|
+
const value = data.lastRead;
|
|
204
|
+
return Promise.resolve(typeof value === 'number' && value > 0 ? value : null);
|
|
205
|
+
}
|
|
206
|
+
if (data.itemType === 'note')
|
|
207
|
+
return Promise.resolve(null);
|
|
208
|
+
return itemLastRead(raw.key);
|
|
209
|
+
}
|
|
210
|
+
/** 列表归一化:已读状态并发取,单条失败按未读(不拖垮整页)。 */
|
|
211
|
+
async function toSummaries(raws) {
|
|
212
|
+
return Promise.all(raws.map(async (raw) => toSummary(raw, await lastReadOf(raw))));
|
|
213
|
+
}
|
|
198
214
|
/** 从库名 `library.name` 或条目数据里取文库名(缺省回退)。 */
|
|
199
215
|
function libraryNameOf(raw) {
|
|
200
216
|
const first = raw[0];
|
|
@@ -327,6 +343,42 @@ export async function listCollections() {
|
|
|
327
343
|
const UNFILED_SCAN_MAX = 1000;
|
|
328
344
|
/** 一页扫描条数(本地 API 上限 100)。 */
|
|
329
345
|
const PAGE_SIZE = 100;
|
|
346
|
+
// ---- 已读状态 ---------------------------------------------------------------
|
|
347
|
+
/** 已读状态缓存时长:`lastRead` 由 Zotero 阅读器写入,分钟级刷新足够。 */
|
|
348
|
+
const READ_STATE_TTL_MS = 60_000;
|
|
349
|
+
/** 单条已读状态缓存的上限;超了就整体丢弃(重新查一遍即可)。 */
|
|
350
|
+
const READ_STATE_CACHE_MAX = 5000;
|
|
351
|
+
const readStateCache = new Map();
|
|
352
|
+
/**
|
|
353
|
+
* 条目(父条目)的最晚阅读时间(Unix 秒),`null` 表示没读过。
|
|
354
|
+
*
|
|
355
|
+
* 已读状态只记在附件上,父条目要问它的子附件(原生 `getItemLastRead()` 同理)。
|
|
356
|
+
* 按条目查而不是扫全库:单条约 6ms,只查当前列表里的条目,大口库也不会卡。
|
|
357
|
+
* 取不到按未读处理——已读标志是附加信息,不能拖垮条目列表。
|
|
358
|
+
*/
|
|
359
|
+
async function itemLastRead(key) {
|
|
360
|
+
const cached = readStateCache.get(key);
|
|
361
|
+
if (cached !== undefined && Date.now() - cached.at < READ_STATE_TTL_MS)
|
|
362
|
+
return cached.lastRead;
|
|
363
|
+
try {
|
|
364
|
+
const { body } = await requestJson(`${libraryBase()}/items/${encode(key)}/children?itemType=attachment`);
|
|
365
|
+
let lastRead = null;
|
|
366
|
+
for (const child of Array.isArray(body) ? body : []) {
|
|
367
|
+
const value = child.data?.lastRead;
|
|
368
|
+
if (typeof value !== 'number' || value <= 0)
|
|
369
|
+
continue;
|
|
370
|
+
if (lastRead === null || value > lastRead)
|
|
371
|
+
lastRead = value;
|
|
372
|
+
}
|
|
373
|
+
if (readStateCache.size >= READ_STATE_CACHE_MAX)
|
|
374
|
+
readStateCache.clear();
|
|
375
|
+
readStateCache.set(key, { at: Date.now(), lastRead });
|
|
376
|
+
return lastRead;
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
330
382
|
/** 把 options 折成「顶层条目」端点基址 + 查询参数。 */
|
|
331
383
|
function itemListQuery(options) {
|
|
332
384
|
const base = options.scope === 'publications'
|
|
@@ -356,12 +408,13 @@ async function listUnfiled(offset, limit) {
|
|
|
356
408
|
break;
|
|
357
409
|
for (const raw of body) {
|
|
358
410
|
if ((raw.data?.collections ?? []).length === 0)
|
|
359
|
-
all.push(
|
|
411
|
+
all.push(raw);
|
|
360
412
|
}
|
|
361
413
|
if (body.length < PAGE_SIZE)
|
|
362
414
|
break;
|
|
363
415
|
}
|
|
364
|
-
|
|
416
|
+
const page = all.slice(offset, offset + limit);
|
|
417
|
+
return { total: all.length, items: await toSummaries(page) };
|
|
365
418
|
}
|
|
366
419
|
/** 顶层条目列表(按虚拟分类、真实分类、或全库,或关键字搜索)。 */
|
|
367
420
|
export async function listItems(options) {
|
|
@@ -369,8 +422,8 @@ export async function listItems(options) {
|
|
|
369
422
|
return listUnfiled(options.offset, options.limit);
|
|
370
423
|
const { base, params } = itemListQuery(options);
|
|
371
424
|
const { body, total } = await requestJson(`${base}?${params.toString()}`);
|
|
372
|
-
const
|
|
373
|
-
return { total: total ??
|
|
425
|
+
const raws = Array.isArray(body) ? body : [];
|
|
426
|
+
return { total: total ?? raws.length, items: await toSummaries(raws) };
|
|
374
427
|
}
|
|
375
428
|
/** 子条目(附件 / 笔记)。 */
|
|
376
429
|
export async function getItemChildren(key) {
|
package/lib/zotero/types.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export interface ZoteroItemSummary {
|
|
|
31
31
|
itemType: string;
|
|
32
32
|
/** 是否有可读附件(决定详情里能否取全文)。 */
|
|
33
33
|
hasAttachment: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 子附件里最晚的阅读时间(Unix **秒**),与 Zotero 原生 `getItemLastRead()` 一致;
|
|
36
|
+
* `null` 表示从未读过。Zotero 不记录读到第几页,只有这一个「读过没有」的信号。
|
|
37
|
+
*/
|
|
38
|
+
lastRead: number | null;
|
|
34
39
|
}
|
|
35
40
|
/** 条目下的一个附件。 */
|
|
36
41
|
export interface ZoteroAttachment {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-zotero",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Install this plugin and DSH can operate your Zotero for you: search the library, read PDF full text, summarize highlights and notes, organize collections by topic, import your downloaded papers, and attach a translated version back to an item. The right sidebar also gains a Zotero library panel that brings an item, an excerpt or a whole collection into the conversation with one click.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|