dsh-plugin-zotero 0.1.9 → 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 +1 -1
- package/client/client.js +314 -52
- package/package.json +7 -6
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
|
|
package/client/client.js
CHANGED
|
@@ -38,6 +38,47 @@ const dicts = {
|
|
|
38
38
|
"status.mcpOff": "模型工具不可用",
|
|
39
39
|
"status.loading": "加载中…",
|
|
40
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": "标注",
|
|
41
82
|
"tree.library": "我的文库",
|
|
42
83
|
"tree.publications": "我的出版物",
|
|
43
84
|
"tree.unfiled": "未分类条目",
|
|
@@ -51,6 +92,7 @@ const dicts = {
|
|
|
51
92
|
"detail.metadata": "文献信息",
|
|
52
93
|
"detail.metadataExpand": "展开文献信息",
|
|
53
94
|
"detail.metadataCollapse": "收起文献信息",
|
|
95
|
+
"detail.type": "类型",
|
|
54
96
|
"detail.creators": "作者",
|
|
55
97
|
"detail.year": "年份",
|
|
56
98
|
"detail.source": "出处",
|
|
@@ -126,6 +168,7 @@ const dicts = {
|
|
|
126
168
|
"cmp.annotation.page": "页码:{value}",
|
|
127
169
|
"cmp.annotation.comment": "批注:{value}",
|
|
128
170
|
"cmp.annotation.key": "标注:{value}",
|
|
171
|
+
"cmp.annotation.pageTag": "(第 {value} 页)",
|
|
129
172
|
"cmp.note.header": "【Zotero 笔记|{title}|{key}】",
|
|
130
173
|
"cmp.note.truncated": "……(笔记正文已按长度截断)",
|
|
131
174
|
"cmp.note.date": "更新:{value}",
|
|
@@ -146,7 +189,9 @@ const dicts = {
|
|
|
146
189
|
"cmp.collection.line": "- {title}({meta})",
|
|
147
190
|
"cmp.collection.more": "……(仅列出前 {n} 条;完整清单可用 mcp__zotero__get_collection_items 获取)",
|
|
148
191
|
"cmp.missing.item": "【Zotero 条目|{key}】该条目已不在文库中,引用文本未能生成。",
|
|
149
|
-
"cmp.missing.collection": "【Zotero 目录|{key}】该目录已不存在,条目清单未能生成。"
|
|
192
|
+
"cmp.missing.collection": "【Zotero 目录|{key}】该目录已不存在,条目清单未能生成。",
|
|
193
|
+
"cmp.missing.note": "【Zotero 笔记|{key}】该笔记已不在文库中,引用文本未能生成。",
|
|
194
|
+
"cmp.missing.annotation": "【Zotero 标注|{key}】该标注已不在文库中,引用文本未能生成。"
|
|
150
195
|
},
|
|
151
196
|
en: {
|
|
152
197
|
"tab.title": "Zotero Library",
|
|
@@ -165,6 +210,47 @@ const dicts = {
|
|
|
165
210
|
"status.mcpOff": "Model tools unavailable",
|
|
166
211
|
"status.loading": "Loading…",
|
|
167
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",
|
|
168
254
|
"tree.library": "My Library",
|
|
169
255
|
"tree.publications": "My Publications",
|
|
170
256
|
"tree.unfiled": "Unfiled Items",
|
|
@@ -178,6 +264,7 @@ const dicts = {
|
|
|
178
264
|
"detail.metadata": "Metadata",
|
|
179
265
|
"detail.metadataExpand": "Expand metadata",
|
|
180
266
|
"detail.metadataCollapse": "Collapse metadata",
|
|
267
|
+
"detail.type": "Type",
|
|
181
268
|
"detail.creators": "Creators",
|
|
182
269
|
"detail.year": "Year",
|
|
183
270
|
"detail.source": "Source",
|
|
@@ -253,6 +340,7 @@ const dicts = {
|
|
|
253
340
|
"cmp.annotation.page": "Page: {value}",
|
|
254
341
|
"cmp.annotation.comment": "Comment: {value}",
|
|
255
342
|
"cmp.annotation.key": "Annotation: {value}",
|
|
343
|
+
"cmp.annotation.pageTag": " (p. {value})",
|
|
256
344
|
"cmp.note.header": "[Zotero note | {title} | {key}]",
|
|
257
345
|
"cmp.note.truncated": "… (note body truncated by length)",
|
|
258
346
|
"cmp.note.date": "Updated: {value}",
|
|
@@ -273,7 +361,9 @@ const dicts = {
|
|
|
273
361
|
"cmp.collection.line": "- {title} ({meta})",
|
|
274
362
|
"cmp.collection.more": "… (first {n} only; use mcp__zotero__get_collection_items for the full list)",
|
|
275
363
|
"cmp.missing.item": "[Zotero item | {key}] this item is no longer in the library; citation text unavailable.",
|
|
276
|
-
"cmp.missing.collection": "[Zotero collection | {key}] this collection no longer exists; item list 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."
|
|
277
367
|
}
|
|
278
368
|
};
|
|
279
369
|
//#endregion
|
|
@@ -682,6 +772,21 @@ function annotationText(t, detail, annotation) {
|
|
|
682
772
|
lines.push(tpl(t("cmp.annotation.key"), { value: annotation.key }));
|
|
683
773
|
return lines.join("\n");
|
|
684
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
|
+
}
|
|
685
790
|
/** 命名实体的最小集合(与 Host 清洗后的笔记 HTML 对齐)。 */
|
|
686
791
|
const NAMED_ENTITIES = {
|
|
687
792
|
nbsp: " ",
|
|
@@ -770,6 +875,54 @@ async function collectionCitation(t, key, signal) {
|
|
|
770
875
|
}, signal);
|
|
771
876
|
return collectionText(t, collection, data.items, data.total);
|
|
772
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
|
+
}
|
|
773
926
|
//#endregion
|
|
774
927
|
//#region src/client/reference.ts
|
|
775
928
|
/**
|
|
@@ -778,10 +931,16 @@ async function collectionCitation(t, key, signal) {
|
|
|
778
931
|
const REF_SOURCE = "zotero";
|
|
779
932
|
const ITEM_PREFIX = "item:";
|
|
780
933
|
const COLLECTION_PREFIX = "col:";
|
|
934
|
+
const NOTE_PREFIX = "note:";
|
|
935
|
+
const ANNOTATION_PREFIX = "ann:";
|
|
936
|
+
/** 笔记 / 标注是子条目,单靠自身 key 取不到所属条目,ref 存「父 key/子 key」。 */
|
|
937
|
+
const REF_SEPARATOR = "/";
|
|
781
938
|
/** 按 ref 前缀分派到对应的引用文本构建。 */
|
|
782
939
|
function citationForRef(t, ref, signal) {
|
|
783
940
|
if (ref.startsWith(ITEM_PREFIX)) return itemCitation(t, ref.slice(5), signal);
|
|
784
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);
|
|
785
944
|
return Promise.reject(/* @__PURE__ */ new Error(`无法识别的 Zotero 引用:${ref}`));
|
|
786
945
|
}
|
|
787
946
|
function createZoteroSource(t) {
|
|
@@ -814,6 +973,23 @@ function itemReference(key, title) {
|
|
|
814
973
|
function collectionReference(key, name) {
|
|
815
974
|
return reference(COLLECTION_PREFIX, key, name, "folder");
|
|
816
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
|
+
}
|
|
817
993
|
/**
|
|
818
994
|
* 把 chip 插进该会话的输入框。
|
|
819
995
|
*
|
|
@@ -1143,43 +1319,113 @@ function ZoteroCard(props) {
|
|
|
1143
1319
|
});
|
|
1144
1320
|
}
|
|
1145
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
|
|
1146
1409
|
//#region src/client/readState.tsx
|
|
1147
|
-
/**
|
|
1148
|
-
* 已读圆点颜色:柔和的粉色。
|
|
1149
|
-
*
|
|
1150
|
-
* 不用主题蓝:蓝点在列表里很像「未读消息」徽标,粉色更接近 Zotero Style 的
|
|
1151
|
-
* 阅读进度条配色,读起来是「标记」而不是「待办」。
|
|
1152
|
-
*/
|
|
1153
|
-
const READ_DOT_COLOR = "#e8798d";
|
|
1154
1410
|
/** 已读条目标题的淡化程度:留一点提示,又不至于看成禁用态。 */
|
|
1155
1411
|
const READ_TITLE_OPACITY = .75;
|
|
1156
1412
|
function isRead(item) {
|
|
1157
1413
|
return item.lastRead !== null;
|
|
1158
1414
|
}
|
|
1159
|
-
/** 圆点槽位:未读时透明但仍占宽,避免已读/未读行的标题起点错位。 */
|
|
1160
|
-
function ReadDot({ read }) {
|
|
1161
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1162
|
-
"aria-hidden": true,
|
|
1163
|
-
style: {
|
|
1164
|
-
width: 4,
|
|
1165
|
-
height: 4,
|
|
1166
|
-
borderRadius: "50%",
|
|
1167
|
-
flexShrink: 0,
|
|
1168
|
-
alignSelf: "center",
|
|
1169
|
-
background: read ? READ_DOT_COLOR : "transparent",
|
|
1170
|
-
opacity: read ? .9 : 0
|
|
1171
|
-
}
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
1415
|
/** 已读条目的标题淡化;未读返回空对象,直接展开不影响原有样式。 */
|
|
1175
1416
|
function readTitleStyle(read) {
|
|
1176
1417
|
return read ? { opacity: READ_TITLE_OPACITY } : {};
|
|
1177
1418
|
}
|
|
1178
|
-
/** 行内 hover
|
|
1419
|
+
/** 行内 hover 提示:类型、读过的补一行最后阅读时间。 */
|
|
1179
1420
|
function itemTooltip(t, item) {
|
|
1180
|
-
|
|
1181
|
-
const
|
|
1182
|
-
|
|
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");
|
|
1183
1429
|
}
|
|
1184
1430
|
//#endregion
|
|
1185
1431
|
//#region src/client/CollectionTree.tsx
|
|
@@ -1235,7 +1481,6 @@ function glyph(path) {
|
|
|
1235
1481
|
});
|
|
1236
1482
|
}
|
|
1237
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";
|
|
1238
|
-
const ITEM_ICON = "M4.5 2.5h5L12 5v8.5H4.5zM9.5 2.5V5H12";
|
|
1239
1484
|
const LIBRARY_ICON = "M2.5 3.5h5v9h-5zM8.5 3.5h5v9h-5z";
|
|
1240
1485
|
/** 虚拟分类的图标 path(键与 {@link VIRTUAL_NODES.icon} 对应)。 */
|
|
1241
1486
|
const VIRTUAL_ICON = {
|
|
@@ -1389,9 +1634,11 @@ function ItemRow({ ctx, item, depth }) {
|
|
|
1389
1634
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: iconBox }),
|
|
1390
1635
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1391
1636
|
style: iconBox,
|
|
1392
|
-
children:
|
|
1637
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ItemTypeIcon, {
|
|
1638
|
+
itemType: item.itemType,
|
|
1639
|
+
read
|
|
1640
|
+
})
|
|
1393
1641
|
}),
|
|
1394
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ReadDot, { read }),
|
|
1395
1642
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1396
1643
|
style: {
|
|
1397
1644
|
...titleStyle,
|
|
@@ -2174,7 +2421,7 @@ function tabButtonStyle(selected) {
|
|
|
2174
2421
|
* 这里直接以 `dangerouslySetInnerHTML` 渲染。
|
|
2175
2422
|
*
|
|
2176
2423
|
* 每条笔记默认折叠成一行标题(正文首段摘要),点击标题展开正文;
|
|
2177
|
-
*
|
|
2424
|
+
* 行尾「引用」往会话输入框插一个笔记 chip,正文在提交那一刻才展开成文本。
|
|
2178
2425
|
*/
|
|
2179
2426
|
function NoteList({ t, notes, onInsert }) {
|
|
2180
2427
|
const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
|
|
@@ -2574,6 +2821,11 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
|
|
|
2574
2821
|
});
|
|
2575
2822
|
const hasBottom = tabs.length > 0;
|
|
2576
2823
|
const metaRows = [];
|
|
2824
|
+
const typeLabel = itemTypeLabel(t, detail.itemType);
|
|
2825
|
+
if (typeLabel !== "") metaRows.push({
|
|
2826
|
+
label: t("detail.type"),
|
|
2827
|
+
value: typeLabel
|
|
2828
|
+
});
|
|
2577
2829
|
if (detail.creators.length > 0) metaRows.push({
|
|
2578
2830
|
label: t("detail.creators"),
|
|
2579
2831
|
value: detail.creators.join("、")
|
|
@@ -2908,8 +3160,8 @@ const linkRowStyle = {
|
|
|
2908
3160
|
*
|
|
2909
3161
|
* 两栏之间是可拖动的分隔条(宽度存 localStorage,跨会话/重启都记住)。
|
|
2910
3162
|
* 数据与选择状态都在 {@link paneStore} 的模块级单例里(跨会话共用同一块面板)。
|
|
2911
|
-
* 「添加到会话」走 ui-conversation 下发的会话级标准 prop
|
|
2912
|
-
* chip(见 reference.ts
|
|
3163
|
+
* 「添加到会话」走 ui-conversation 下发的会话级标准 prop:条目、整目录、笔记、
|
|
3164
|
+
* 标注都插引用 chip(见 reference.ts),只有摘录仍插纯文本。
|
|
2913
3165
|
*/
|
|
2914
3166
|
/** 左栏宽度的存储键与取值范围。 */
|
|
2915
3167
|
const TREE_WIDTH_KEY = "dsh-plugin-zotero.treeWidth";
|
|
@@ -3012,20 +3264,12 @@ function ZoteroPane({ t, inputActions, sessions, sessionId }) {
|
|
|
3012
3264
|
report,
|
|
3013
3265
|
t
|
|
3014
3266
|
]);
|
|
3015
|
-
const insertAnnotation = (0, react.useCallback)(
|
|
3016
|
-
|
|
3017
|
-
}, [
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
]);
|
|
3022
|
-
const insertNote = (0, react.useCallback)(async (target, note) => {
|
|
3023
|
-
report(await insertBuilt(inputActions, () => noteText(t, target, note)));
|
|
3024
|
-
}, [
|
|
3025
|
-
inputActions,
|
|
3026
|
-
report,
|
|
3027
|
-
t
|
|
3028
|
-
]);
|
|
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]);
|
|
3029
3273
|
const insertCollection = (0, react.useCallback)((collection) => {
|
|
3030
3274
|
insertReference(collectionReference(collection.key, collection.name));
|
|
3031
3275
|
}, [insertReference]);
|
|
@@ -3128,7 +3372,13 @@ function ZoteroPane({ t, inputActions, sessions, sessionId }) {
|
|
|
3128
3372
|
background: selectedItemKey === item.key ? "rgba(127,127,127,0.16)" : "transparent"
|
|
3129
3373
|
},
|
|
3130
3374
|
children: [
|
|
3131
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
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
|
+
}),
|
|
3132
3382
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3133
3383
|
style: {
|
|
3134
3384
|
...resultTitleStyle,
|
|
@@ -3209,8 +3459,8 @@ function ZoteroPane({ t, inputActions, sessions, sessionId }) {
|
|
|
3209
3459
|
detail,
|
|
3210
3460
|
onInsertItem: () => insertItem(detail.key, detail.title),
|
|
3211
3461
|
onInsertExcerpt: (quote) => void insertExcerpt(detail, quote),
|
|
3212
|
-
onInsertAnnotation: (annotation) =>
|
|
3213
|
-
onInsertNote: (note) =>
|
|
3462
|
+
onInsertAnnotation: (annotation) => insertAnnotation(detail, annotation),
|
|
3463
|
+
onInsertNote: (note) => insertNote(detail, note),
|
|
3214
3464
|
onOpenItem: openItem
|
|
3215
3465
|
}) : selectedCollection !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
3216
3466
|
style: { padding: "12px 14px" },
|
|
@@ -3275,7 +3525,13 @@ function ZoteroPane({ t, inputActions, sessions, sessionId }) {
|
|
|
3275
3525
|
onClick: () => openItem(item.key),
|
|
3276
3526
|
style: resultRowStyle,
|
|
3277
3527
|
children: [
|
|
3278
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
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
|
+
}),
|
|
3279
3535
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
3280
3536
|
style: {
|
|
3281
3537
|
...resultTitleStyle,
|
|
@@ -3345,6 +3601,12 @@ const resultMetaStyle = {
|
|
|
3345
3601
|
opacity: .5,
|
|
3346
3602
|
fontSize: 11.5
|
|
3347
3603
|
};
|
|
3604
|
+
/** 列表行首的类型图标:基线对齐的行里改为垂直居中。 */
|
|
3605
|
+
const itemIconStyle = {
|
|
3606
|
+
display: "flex",
|
|
3607
|
+
alignSelf: "center",
|
|
3608
|
+
flexShrink: 0
|
|
3609
|
+
};
|
|
3348
3610
|
//#endregion
|
|
3349
3611
|
//#region src/client/index.ts
|
|
3350
3612
|
/**
|
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",
|
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
"engines": {
|
|
36
36
|
"dsh": ">=0.2.1-rc.3 <0.3.0-0"
|
|
37
37
|
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"build:client": "tsdown",
|
|
41
|
+
"typecheck:client": "tsc -p tsconfig.client.json --noEmit",
|
|
42
|
+
"prepack": "pnpm build && pnpm build:client"
|
|
43
|
+
},
|
|
38
44
|
"peerDependencies": {
|
|
39
45
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
40
46
|
"@deepseek-ai/schemastery": "^3.18.5"
|
|
@@ -64,10 +70,5 @@
|
|
|
64
70
|
],
|
|
65
71
|
"platform": "web"
|
|
66
72
|
}
|
|
67
|
-
},
|
|
68
|
-
"scripts": {
|
|
69
|
-
"build": "tsc -p tsconfig.json",
|
|
70
|
-
"build:client": "tsdown",
|
|
71
|
-
"typecheck:client": "tsc -p tsconfig.client.json --noEmit"
|
|
72
73
|
}
|
|
73
74
|
}
|