dsh-plugin-zotero 0.6.1 → 0.6.5

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **把 Zotero 文献库映射进 DSH:用AI管理操作Zotero,读文献时让AI辅助你。**
4
4
 
5
- 本插件把 Zotero 的文库结构、元数据、PDF 全文、笔记与标注接入 DSH,将「检索文献 — 精读全文 — 摘录标注 — 与模型讨论 — 形成稿子」收进同一条工作流:右侧栏按分类与标签浏览文库,按标题 / 摘要筛选当前范围,双击条目即在 DSH 内打开独立阅读页,PDF 整页渲染、高亮原位叠加,同一篇文献的原文与译本附件可在页内切换;读到关键段落时可直接划词摘录,或引用该条标注、笔记乃至整篇文献,以引用胶囊写进当前会话草稿,模型随即基于原文接续完成综述、方法对比、数据提取与引文核对。
5
+ 本插件把 Zotero 的目录分类、条目元数据、PDF 全文、笔记与标注接入 DSH,将「检索文献 — 精读全文 — 摘录标注 — 与模型讨论 — 形成稿子」收进同一条工作流:右侧栏按分类与标签浏览文库,按标题 / 摘要筛选当前范围,双击条目即在 DSH 内打开独立阅读页,PDF 整页渲染、高亮原位叠加,同一篇文献的原文与译本附件可在页内切换;读到关键段落时可直接划词摘录,或引用该条标注、笔记乃至整篇文献,以引用胶囊写进当前会话草稿,模型随即基于原文接续完成综述、方法对比、数据提取与引文核对。
6
6
 
7
7
  模型侧同样具备完整的检索与整理能力:检索文库、精读 PDF、汇总高亮与笔记、按主题新建分类并归类,也可以把本地下载的论文导入 Zotero,读完外文文献后把译文作为附件回挂到对应条目。凡 Zotero 本地接口与集成 MCP 能提供的操作,均可由模型代劳。
8
8
 
@@ -24,7 +24,7 @@
24
24
  - **读文献**:双击条目就在 DSH 内开独立阅读页,PDF 整页渲染、高亮原位叠加,原文与译本附件随时切换;摘要、全文、笔记与标注都能在这里读完,写综述、做对比、提取数据都行,需要精确引用时会保留原文措辞。开启写权限后,正文里划选即选颜色落一条高亮或下划线(跨页自动按页拆条)、随手带一句评论,改色、改评论、改页码、加标签、高亮↔划线互转、删除都在同一处;笔记也能新建、编辑、删除。改动直接进 Zotero 库,不是插件里的副本。
25
25
  - **整理文库**:新建、重命名、移动、删除分类,批量把条目加入或移出分类。你说一句「把这几篇归到『待读』里」,它就照做。
26
26
  - **帮你入库**:把本地下载好的论文、PDF 交给 DSH 导入 Zotero;也可以让它读完外文文献后,把译文作为附件挂回条目。
27
- - **带进对话**:右侧面板单条目引用、列表多选批量引用、阅读页划词摘录与点高亮引用、单标签或多标签引用、整分类引用,一键写进当前会话草稿(不自动发送),你再接着说要求。条目、标签和整分类以「引用胶囊」的形式出现,草稿里一眼看清引了哪几篇,单独删掉某一条也不影响其他内容。
27
+ - **带进对话**:右侧面板单条目引用、列表多选批量引用、阅读页划词摘录与点高亮引用、单标签或多标签引用、整分类引用,一键写进当前会话草稿(不自动发送),你再接着说要求。全部都以「引用胶囊」的形式出现,草稿里一眼看清引了哪几篇 / 哪几段,单独删掉某一条也不影响其他内容;完整文本在发送那一刻才展开给模型。
28
28
  - **安全可控**:写能力默认全关 —— 「设置 → Zotero 插件」里的「Zotero 写权限」不开启,面板就是纯只读,模型也看不到任何写工具。开启后写操作优先走集成 MCP(在 Zotero 进程内执行,不触发本地 API 授权弹窗),标注与笔记这两类 MCP 覆盖不到的才走本地 API,需要一次性点「始终允许」授权;模型侧每一项工具都能单独开关。
29
29
 
30
30
  面板布局与 Zotero 本体一致:顶部状态栏显示连接状态并提供刷新;左侧是分类树,树下是可拖高、可折叠的标签面板;右侧列表显示当前范围(分类 / 全库 / 标签筛选后)的条目。分类树与条目列表之间的分隔条可拖动,宽度按本机记住。列表里单击条目选中、`Ctrl` / `Cmd` 点选多选,双击才在右侧栏顶层单开一个标签页看详情。阅读页就开在会话旁边的标签里,边读边摘、边问边改,不必在 Zotero 与 AI 两个窗口之间来回切换。
@@ -192,12 +192,12 @@ Zotero → **设置** → **高级** → 勾选「**允许此计算机上的其
192
192
  - **条目列表**:每行显示文献类型图标与作者 / 年份;读过的文献类型图标转为粉色、标题略淡,悬停补上类型名与最后阅读时间。单击选中、`Ctrl` / `Cmd` 点选多选,双击在右侧栏顶层开独立详情页,右键单行可直接插引用;头部搜索框针对当前范围(分类 / 全库 / 标签筛选后)按标题与摘要过滤,列表可分页「加载更多」,选中多条时右上角一次「引用 N」。
193
193
  - **标签面板**:树下方独立面板,可拖高 / 折叠;标签按 Zotero 的换行胶囊排布并跟随当前目录:选中分类时只列该分类自身条目里出现过的标签(不含子目录,自动标签弱化显示),选中文库根时列出全库标签;可按名称筛选、多选,并切换「全部(AND)/ 任一(OR)」。筛选作用于当前选择的范围,列表头部会显示已选标签胶囊与「清除筛选」;切换目录会自动清除已选标签,避免旧筛选作用到新范围。已选标签可从摘要行合并成一枚「标签组」胶囊引用。
194
194
  - **条目详情独立成页**:双击条目在右侧栏顶层新开一个标签页,同一条目再次双击只回到已有页;详情页可同时开多个,切换标签页时各自的展开状态与滚动位置都保留(正文常驻挂载)。
195
- - **文档优先版面**:详情页整页显示文献本体——PDF 走 PDF.js 渲染(顶部工具栏缩放、页码、当前页在 Zotero 中打开),没有 PDF 时回退到 API 全文文本。左侧固定的 30px 工具栏不遮挡正文。选中正文即浮出「摘录」按钮,点正文里的高亮则弹出标注卡片(类型、原文、评论,以及「引用」与「在 Zotero 中打开」)。
195
+ - **文档优先版面**:详情页整页显示文献本体——PDF 走 PDF.js 渲染(顶部工具栏缩放、页码、当前页在 Zotero 中打开),没有 PDF 时回退到 API 全文文本。左侧固定的 30px 工具栏不遮挡正文。选中正文即浮出划词工具条(复制 / 加入对话 / 新建标注),点正文里的高亮则弹出标注卡片(类型、原文、评论,以及「引用」与「在 Zotero 中打开」)。
196
196
  - **左上角信息面板**:点左上角 `i` 按钮弹出浮层,把文献信息 / 摘要 / 标注 / 笔记 / 附件 / 参考文献分块竖排,每块可单独折叠;点浮层外或按 `Esc` 关闭,点标注定位时自动关闭把焦点还给文档。
197
197
  - **文档目录**:`i` 左边的列表按钮展开 PDF 自带书签的大纲树,按层级缩进,点一条即跳到对应页(跳完自动收起);没有书签的 PDF 显示「这篇 PDF 没有目录」。Zotero 本地 API 与集成 MCP 都没有目录数据,这份大纲由插件从 PDF 文件里自己解析(上限 8 层 / 800 条)。
198
- - **笔记可读**:独立笔记(文库里的全局笔记)打开后正文直接占据文档区,跟普通条目一样阅读;子笔记在信息面板的「笔记」块里折叠呈现,正文保留 Zotero 的引用块、标注高亮、表格与外链图片。Host 侧已清洗脚本与事件属性,避免注入。「引用」把该条笔记转成纯文本写进会话草稿。
199
- - **标注可读**:PDF 上的高亮与划线原位叠加在页面上,点页内标注弹出卡片,可当场「引用」或跳回 Zotero 对应页;「标注」块按类型 / 颜色筛选,点条目可跨附件定位、滚动并闪烁,「引用」把该条标注写进会话草稿。
200
- - **多种插入方式**:单条目、列表多选批量、单标签、多标签(合并成一枚「标签组」胶囊,AND/OR 在插入那一刻定格)与整目录引用都以「引用胶囊」写进草稿——胶囊只显示标题,发送那一刻才展开成完整引用文本,模型拿到的内容与以前一致;全文划词摘录、单条标注、单条笔记仍按纯文本插入。所有方式都只写进会话草稿(不自动发送、不抢焦点),文本携带 `itemKey` / `collectionKey` / 标签名供模型接续操作。标签类引用始终按全库范围展开,不受你当时选中哪个分类影响。
198
+ - **笔记可读**:独立笔记(文库里的全局笔记)打开后正文直接占据文档区,跟普通条目一样阅读;子笔记在信息面板的「笔记」块里折叠呈现,正文保留 Zotero 的引用块、标注高亮、表格与外链图片。Host 侧已清洗脚本与事件属性,避免注入。「引用」把该条笔记作为一枚胶囊写进会话草稿,发送时展开成完整纯文本。
199
+ - **标注可读**:PDF 上的高亮与划线原位叠加在页面上,点页内标注弹出卡片,可当场「引用」或跳回 Zotero 对应页;「标注」块按类型 / 颜色筛选,点条目可跨附件定位、滚动并闪烁,「引用」把该条标注作为胶囊写进会话草稿。
200
+ - **多种插入方式**:单条目、列表多选批量、单标签、多标签(合并成一枚「标签组」胶囊,AND/OR 在插入那一刻定格)、整目录、全文划词摘录、单条标注与单条笔记**全部**以「引用胶囊」写进草稿——胶囊只显示短标签,发送那一刻才展开成完整引用文本,模型拿到的内容与以前一致。所有方式都只写进会话草稿(不自动发送、不抢焦点),文本携带 `itemKey` / `collectionKey` / 标签名供模型接续操作。标签类引用始终按全库范围展开,不受你当时选中哪个分类影响;摘录胶囊把 `itemKey`、标题与原文一起定格在胶囊里,重开 DSH 后仍可展开,发送时不依赖 Zotero 在线(单段上限 4000 字)。
201
201
  - **胶囊依赖本插件展开**:草稿里留着引用胶囊时禁用或卸载本插件,发送会失败并提示找不到引用来源,把胶囊删掉即可继续正常发送。
202
202
  - **分类只读**:不提供任何新建 / 改名 / 删除分类的按钮——整理分类是模型的活,人在面板里只管浏览与引用。
203
203
  - **标注与笔记可写(默认关)**:在「设置 → Zotero 插件」打开「Zotero 写权限」并授权后,阅读页划选即写高亮 / 下划线(Zotero 色板七色 + 评论一次点明),点页内高亮弹出的标注卡片可当场「添加评论 / 改评论」,「标注」块还支持改色、改页码、加标签、高亮↔划线、删除,「笔记」块支持新建 / 编辑 / 删除。所有写入都直接进 Zotero 本地库,插件不存副本;含 Zotero 引文或标注锚点的笔记只给删除、不给编辑,改正文会让锚点失联。删除是**硬删**,不进 Zotero 回收站,面板里要点两次才会真删。开关关着时上述入口一个都不出现。
@@ -272,7 +272,7 @@ src/ # 插件源码(主包,ESM / NodeNext / strict)
272
272
  ├── AnnotationList.tsx / NoteList.tsx # 标注与笔记列表
273
273
  ├── Toast.tsx # 插入结果等轻提示
274
274
  ├── reference.ts / cite.ts # 引用胶囊的 ref 编码与提交时的文本展开
275
- ├── useInsertion.ts / inline.ts # 往会话草稿插入胶囊或纯文本
275
+ ├── useInsertion.ts / inline.ts # 往会话草稿插入引用胶囊
276
276
  ├── styles.ts # 强调色等共用样式常量
277
277
  ├── paneStore.ts # 跨会话共享的面板状态
278
278
  ├── compose.ts # 插入文本模板
package/client/client.js CHANGED
@@ -384,6 +384,10 @@ const dicts = {
384
384
  "itemTab.invalid": "该标签页的条目地址无效",
385
385
  "detail.loadFailed": "条目加载失败:{message}",
386
386
  "detail.refreshFailed": "内容已写入 Zotero,但详情没刷新成功:{message}",
387
+ "detail.refreshHint": "重新读取整条文献与页面上的高亮标注:元数据、摘要、笔记、附件、参考文献一起更新",
388
+ "detail.refreshing": "正在刷新…",
389
+ "detail.refreshed": "已刷新",
390
+ "detail.refreshFailedManual": "刷新失败:{message}",
387
391
  "detail.metadata": "文献信息",
388
392
  "detail.metadataExpand": "展开文献信息",
389
393
  "detail.metadataCollapse": "收起文献信息",
@@ -436,6 +440,7 @@ const dicts = {
436
440
  "error.partialInsert": "输入框草稿已变化,只插入 {n} 条;请避免在插入期间编辑草稿",
437
441
  "error.empty": "没有可插入的内容",
438
442
  "error.tooManyTags": "一次最多加入 {n} 个标签",
443
+ "error.excerptTooLong": "摘录过长(上限 {n} 字),请缩小选区或改用条目引用",
439
444
  "toast.inserted": "已添加到会话草稿",
440
445
  "toast.insertedItems": "已把 {n} 条加入会话草稿",
441
446
  "toast.copied": "已复制",
@@ -600,6 +605,7 @@ const dicts = {
600
605
  "cmp.item.url": "链接:{value}",
601
606
  "cmp.excerpt.header": "【Zotero 摘录|{title}|{key}】",
602
607
  "cmp.excerpt.quote": "“{value}”",
608
+ "cmp.excerpt.chipLabel": "摘录:{value}",
603
609
  "cmp.collection.header": "【Zotero 目录|{name}|{key}】共 {n} 条",
604
610
  "cmp.collection.line": "- {title}({meta})",
605
611
  "cmp.collection.more": "……(仅列出前 {n} 条;完整清单可用 mcp__zotero__get_collection_items 获取)",
@@ -718,6 +724,10 @@ const dicts = {
718
724
  "itemTab.invalid": "This tab has an invalid item address",
719
725
  "detail.loadFailed": "Failed to load the item: {message}",
720
726
  "detail.refreshFailed": "The change is in Zotero, but the details did not refresh: {message}",
727
+ "detail.refreshHint": "Reload the whole item and the highlights on the page: metadata, abstract, notes, attachments and bibliography",
728
+ "detail.refreshing": "Refreshing…",
729
+ "detail.refreshed": "Refreshed",
730
+ "detail.refreshFailedManual": "Failed to refresh: {message}",
721
731
  "detail.metadata": "Metadata",
722
732
  "detail.metadataExpand": "Expand metadata",
723
733
  "detail.metadataCollapse": "Collapse metadata",
@@ -770,6 +780,7 @@ const dicts = {
770
780
  "error.partialInsert": "The draft changed; only {n} were inserted. Avoid editing while inserting.",
771
781
  "error.empty": "Nothing to insert",
772
782
  "error.tooManyTags": "Add at most {n} tags at once",
783
+ "error.excerptTooLong": "This excerpt is too long (limit {n} characters). Select less text or cite the whole item instead.",
773
784
  "toast.inserted": "Added to the conversation draft",
774
785
  "toast.insertedItems": "Added {n} to the conversation draft",
775
786
  "toast.copied": "Copied",
@@ -934,6 +945,7 @@ const dicts = {
934
945
  "cmp.item.url": "URL: {value}",
935
946
  "cmp.excerpt.header": "[Zotero excerpt | {title} | {key}]",
936
947
  "cmp.excerpt.quote": "“{value}”",
948
+ "cmp.excerpt.chipLabel": "Excerpt: {value}",
937
949
  "cmp.collection.header": "[Zotero collection | {name} | {key}] {n} items",
938
950
  "cmp.collection.line": "- {title} ({meta})",
939
951
  "cmp.collection.more": "… (first {n} only; use mcp__zotero__get_collection_items for the full list)",
@@ -1591,7 +1603,12 @@ function itemText(t, detail) {
1591
1603
  if (detail.url !== "") lines.push(line(t, "cmp.item.url", detail.url));
1592
1604
  return lines.join("\n");
1593
1605
  }
1594
- /** 选中片段的摘录文本。 */
1606
+ /**
1607
+ * 选中片段的摘录文本。
1608
+ *
1609
+ * 只需要 key 与标题:提交时 codec 从摘录 chip 的 ref 里取回这两段,不再重新
1610
+ * 请求 Zotero,所以参数放宽到 {@link ZoteroItemDetail} 的最小子集。
1611
+ */
1595
1612
  function excerptText(t, detail, quote) {
1596
1613
  return `${tpl(t("cmp.excerpt.header"), {
1597
1614
  title: detail.title,
@@ -1599,6 +1616,17 @@ function excerptText(t, detail, quote) {
1599
1616
  })}\n${tpl(t("cmp.excerpt.quote"), { value: quote })}`;
1600
1617
  }
1601
1618
  /**
1619
+ * 摘录 chip 的标签:只放原文开头,胶囊自己会省略过长部分。
1620
+ *
1621
+ * PDF 抽取会在汉字之间插空格,标签里顺手清掉(展开给模型的原文不动)。
1622
+ */
1623
+ function excerptChipLabel(t, quote) {
1624
+ const source = tidyAnnotation(quote);
1625
+ const chars = Array.from(source);
1626
+ const summary = chars.length > CHIP_LABEL_LIMIT ? `${chars.slice(0, CHIP_LABEL_LIMIT).join("")}…` : source;
1627
+ return tpl(t("cmp.excerpt.chipLabel"), { value: summary });
1628
+ }
1629
+ /**
1602
1630
  * PDF 抽取会在汉字之间插空格(`硫 化 氢`),展示与插入时去掉;
1603
1631
  * 只处理汉字与汉字之间的空格,避免动到西文词距。
1604
1632
  */
@@ -1825,14 +1853,35 @@ async function annotationCitation(t, body, signal) {
1825
1853
  if (annotation === void 0) return tpl(t("cmp.missing.annotation"), { key: childKey });
1826
1854
  return annotationText(t, detail, annotation);
1827
1855
  }
1828
- /** 解码标签名;ref 结构坏了直接抛出(不是「对象已删除」)。 */
1829
- function decodeTagName(encoded) {
1856
+ /**
1857
+ * 一段划选摘录的引用。
1858
+ *
1859
+ * 与按 key 现取的引用不同,摘录没有「文库里被删掉」这回事:itemKey、标题、
1860
+ * 原文都在 ref 里定格,所以这里不请求 Host,也不需要 AbortSignal。
1861
+ * 结构坏了(不是三段 / 某段解码失败)说明这个 chip 不是本插件写的,抛出去让
1862
+ * 宿主还原草稿,别把一截乱码发给模型。
1863
+ */
1864
+ async function excerptCitation(t, body) {
1865
+ const parts = body.split(":");
1866
+ const [rawKey, rawTitle, rawQuote] = parts;
1867
+ if (parts.length !== 3 || rawKey === void 0 || rawTitle === void 0 || rawQuote === void 0) throw new Error(`无法识别的 Zotero 摘录引用:${body}`);
1868
+ return excerptText(t, {
1869
+ key: decodeRefPart("摘录", rawKey),
1870
+ title: decodeRefPart("摘录", rawTitle)
1871
+ }, decodeRefPart("摘录", rawQuote));
1872
+ }
1873
+ /** 解码 ref 里的一段;坏转义会抛 URIError,换成带来源的可辨认错误。 */
1874
+ function decodeRefPart(kind, encoded) {
1830
1875
  try {
1831
1876
  return decodeURIComponent(encoded);
1832
1877
  } catch {
1833
- throw new Error(`无法识别的 Zotero 标签引用:${encoded}`);
1878
+ throw new Error(`无法识别的 Zotero ${kind}引用:${encoded}`);
1834
1879
  }
1835
1880
  }
1881
+ /** 解码标签名;ref 结构坏了直接抛出(不是「对象已删除」)。 */
1882
+ function decodeTagName(encoded) {
1883
+ return decodeRefPart("标签", encoded);
1884
+ }
1836
1885
  /**
1837
1886
  * 单个标签的引用(全库范围)。
1838
1887
  *
@@ -1888,10 +1937,25 @@ const ITEM_PREFIX = "item:";
1888
1937
  const COLLECTION_PREFIX = "col:";
1889
1938
  const NOTE_PREFIX = "note:";
1890
1939
  const ANNOTATION_PREFIX = "ann:";
1940
+ /**
1941
+ * 划选摘录:`exc:<编码后的 itemKey>:<编码后的标题>:<编码后的原文>`。
1942
+ *
1943
+ * 与按 key 现取的引用不同,摘录是插入那一刻定格的文本,文库里根本没有对应对象,
1944
+ * 所以三段数据全部自包含在 ref 里:草稿跨重启恢复后照样能展开,也不依赖 Zotero 在线。
1945
+ * `encodeURIComponent` 把 `:` 与所有空白都编码掉,用 `:` 分段不会歧义。
1946
+ */
1947
+ const EXCERPT_PREFIX = "exc:";
1891
1948
  /** 单个标签:`tag:<编码后的标签名>`。 */
1892
1949
  const TAG_PREFIX = "tag:";
1893
1950
  /** 标签组:`tags:<all|any>:<编码后的标签名>,…`。 */
1894
1951
  const TAG_SET_PREFIX = "tags:";
1952
+ /**
1953
+ * 单段摘录的字符上限。
1954
+ *
1955
+ * ref 与 chip 的 clipboardText 都会带着编码后的原文存进会话草稿,划选整页时
1956
+ * 不做限制会把草稿撑到几十万字符。超限时提示缩小选区,不静默截断原文。
1957
+ */
1958
+ const MAX_EXCERPT_CHARS = 4e3;
1895
1959
  /** 笔记 / 标注是子条目,单靠自身 key 取不到所属条目,ref 存「父 key/子 key」。 */
1896
1960
  const REF_SEPARATOR = "/";
1897
1961
  /** 按 ref 前缀分派到对应的引用文本构建。 */
@@ -1900,6 +1964,7 @@ function citationForRef(t, ref, signal) {
1900
1964
  if (ref.startsWith(COLLECTION_PREFIX)) return collectionCitation(t, ref.slice(4), signal);
1901
1965
  if (ref.startsWith(NOTE_PREFIX)) return noteCitation(t, ref.slice(5), signal);
1902
1966
  if (ref.startsWith(ANNOTATION_PREFIX)) return annotationCitation(t, ref.slice(4), signal);
1967
+ if (ref.startsWith(EXCERPT_PREFIX)) return excerptCitation(t, ref.slice(4));
1903
1968
  if (ref.startsWith(TAG_SET_PREFIX)) return tagSetCitation(t, ref.slice(5), signal);
1904
1969
  if (ref.startsWith(TAG_PREFIX)) return tagCitation(t, ref.slice(4), signal);
1905
1970
  return Promise.reject(/* @__PURE__ */ new Error(`无法识别的 Zotero 引用:${ref}`));
@@ -1952,6 +2017,26 @@ function annotationReference(parentKey, annotationKey, label) {
1952
2017
  return reference(childPrefix(ANNOTATION_PREFIX, parentKey), annotationKey, label, "file");
1953
2018
  }
1954
2019
  /**
2020
+ * 一段划选摘录的 chip。
2021
+ *
2022
+ * 原文原样编码进 ref,提交时由 {@link excerptCitation} 解码后重建完整引文;
2023
+ * `label` 只是胶囊上显示的短摘要,与展开文本无关。
2024
+ */
2025
+ function excerptReference(key, title, quote, label) {
2026
+ const ref = `${EXCERPT_PREFIX}${[
2027
+ key,
2028
+ title,
2029
+ quote
2030
+ ].map((part) => encodeURIComponent(part)).join(":")}`;
2031
+ return {
2032
+ source: REF_SOURCE,
2033
+ ref,
2034
+ label,
2035
+ appearance: "file",
2036
+ clipboardText: `@${ref}`
2037
+ };
2038
+ }
2039
+ /**
1955
2040
  * 单个标签的 chip。
1956
2041
  *
1957
2042
  * 标签名可能含空格,`clipboardText` 必须无空格,所以先 `encodeURIComponent`。
@@ -2132,6 +2217,14 @@ const THEME_CSS = `
2132
2217
  text-overflow: ellipsis;
2133
2218
  white-space: nowrap;
2134
2219
  }
2220
+ /* 页面级刷新按钮进行中:只转图标,宽度由工具条定死。SVG 默认绕左上角转,center 必须显式写。 */
2221
+ .dsh-zp-refresh-spin {
2222
+ transform-origin: center;
2223
+ animation: dsh-zp-refresh-rotate 900ms linear infinite;
2224
+ }
2225
+ @keyframes dsh-zp-refresh-rotate {
2226
+ to { transform: rotate(360deg); }
2227
+ }
2135
2228
  `.trim();
2136
2229
  const THEME_STYLE_ID = "dsh-plugin-zotero-theme";
2137
2230
  /** 幂等:插件重载 / 多会话只留一份 <style>。 */
@@ -4378,6 +4471,9 @@ const noticeStyle$2 = {
4378
4471
  *
4379
4472
  * 各区块的开合全局记一份(见 {@link useInfoSections}):用户按自己的习惯折过
4380
4473
  * 一次之后,换文献、关浮层、重启都保持原样,不用每篇重新折。
4474
+ *
4475
+ * 刷新整份详情的按钮在**阅读器工具条**(页面级,见 `DocumentView`),不放在这里:
4476
+ * 它同时影响页面上的标注,浮层收着的时候也应该能点。
4381
4477
  */
4382
4478
  function Block({ label, hint, open, onToggle, action, children }) {
4383
4479
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
@@ -5006,6 +5102,29 @@ const emptyStyle$1 = {
5006
5102
  opacity: .72
5007
5103
  };
5008
5104
  //#endregion
5105
+ //#region src/client/viewer/OpenInZoteroIcon.tsx
5106
+ /** 默认 12px,与 11.5px 字号的工具条 / 卡片小按钮相称。 */
5107
+ function OpenInZoteroIcon({ size = 12 }) {
5108
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
5109
+ width: size,
5110
+ height: size,
5111
+ viewBox: "0 0 16 16",
5112
+ fill: "none",
5113
+ stroke: "currentColor",
5114
+ strokeWidth: "1.4",
5115
+ strokeLinecap: "round",
5116
+ strokeLinejoin: "round",
5117
+ "aria-hidden": "true",
5118
+ focusable: "false",
5119
+ style: { flexShrink: 0 },
5120
+ children: [
5121
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M9.5 2.5h4v4" }),
5122
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M13.5 2.5 7.5 8.5" }),
5123
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 9.5v3a1 1 0 0 1-1 1H3.5a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h3" })
5124
+ ]
5125
+ });
5126
+ }
5127
+ //#endregion
5009
5128
  //#region node_modules/.pnpm/pdfjs-dist@6.3.289/node_modules/pdfjs-dist/build/pdf.mjs
5010
5129
  const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
5011
5130
  const BBOX_INIT = [
@@ -28610,11 +28729,11 @@ function AnnotationCard({ t, annotation, style, cardRef, canEdit, onClose, onIns
28610
28729
  style: smallButtonStyle$1,
28611
28730
  children: t("action.insertItemShort")
28612
28731
  }),
28613
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
28732
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
28614
28733
  type: "button",
28615
28734
  onClick: onOpenInZotero,
28616
- style: smallButtonStyle$1,
28617
- children: t("viewer.openInZoteroShort")
28735
+ style: zoteroButtonStyle$1,
28736
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenInZoteroIcon, {}), t("viewer.openInZoteroShort")]
28618
28737
  }),
28619
28738
  canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
28620
28739
  type: "button",
@@ -28748,6 +28867,13 @@ const smallButtonStyle$1 = {
28748
28867
  cursor: "pointer",
28749
28868
  whiteSpace: "nowrap"
28750
28869
  };
28870
+ /** 只有跳 Zotero 这个按钮带图标:单独补 flex 对齐,不动卡片里其它纯文字按钮。 */
28871
+ const zoteroButtonStyle$1 = {
28872
+ ...smallButtonStyle$1,
28873
+ display: "inline-flex",
28874
+ alignItems: "center",
28875
+ gap: 4
28876
+ };
28751
28877
  /** 删除的二次确认态:只换描边与文字色,不铺红底(深色主题下红底会糊成一块)。 */
28752
28878
  const dangerStyle = {
28753
28879
  borderColor: "rgba(217,83,79,0.7)",
@@ -30866,11 +30992,11 @@ function PdfViewer(props) {
30866
30992
  style: smallButtonStyle,
30867
30993
  children: t("action.retry")
30868
30994
  }),
30869
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30995
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
30870
30996
  type: "button",
30871
30997
  onClick: () => onOpenInZotero(1),
30872
- style: smallButtonStyle,
30873
- children: t("viewer.openInZotero")
30998
+ style: zoteroButtonStyle,
30999
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenInZoteroIcon, {}), t("viewer.openInZotero")]
30874
31000
  }),
30875
31001
  error.fix !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
30876
31002
  type: "button",
@@ -30933,6 +31059,13 @@ const smallButtonStyle = {
30933
31059
  cursor: "pointer",
30934
31060
  whiteSpace: "nowrap"
30935
31061
  };
31062
+ /** 只有跳 Zotero 这个按钮带图标:单独补 flex 对齐,不动旁边的「重试 / 打开系统设置」。 */
31063
+ const zoteroButtonStyle = {
31064
+ ...smallButtonStyle,
31065
+ display: "inline-flex",
31066
+ alignItems: "center",
31067
+ gap: 4
31068
+ };
30936
31069
  //#endregion
30937
31070
  //#region src/client/viewer/snapshotProtocol.ts
30938
31071
  /**
@@ -31950,7 +32083,31 @@ function ZoomIcon({ kind }) {
31950
32083
  })
31951
32084
  });
31952
32085
  }
31953
- function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertAnnotation, onOpenInZotero, onChanged, onOutlineChange }) {
32086
+ /**
32087
+ * 页面级刷新按钮的循环箭头。
32088
+ *
32089
+ * 进行中靠全局 `.dsh-zp-refresh-spin` 转起来;文字换成「正在刷新…」只是给个明确反馈,
32090
+ * 防重复点击靠的是 `disabled` 与 `ZoteroItemPane` 里的请求序号。
32091
+ */
32092
+ function RefreshIcon({ spinning }) {
32093
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
32094
+ className: spinning ? "dsh-zp-refresh-spin" : void 0,
32095
+ width: "12",
32096
+ height: "12",
32097
+ viewBox: "0 0 16 16",
32098
+ "aria-hidden": "true",
32099
+ focusable: "false",
32100
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("g", {
32101
+ fill: "none",
32102
+ stroke: "currentColor",
32103
+ strokeWidth: "1.5",
32104
+ strokeLinecap: "round",
32105
+ strokeLinejoin: "round",
32106
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M13 8a5 5 0 1 1-1.5-3.55" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M13.2 3.1v3.2H10" })]
32107
+ })
32108
+ });
32109
+ }
32110
+ function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onInsertExcerpt, onInsertAnnotation, onOpenInZotero, onChanged, refreshing, onRefresh, onOutlineChange }) {
31954
32111
  const renderer = pickRenderer(source, detail);
31955
32112
  const Renderer = renderer.Component;
31956
32113
  const [page, setPage] = (0, react.useState)({
@@ -32010,15 +32167,28 @@ function DocumentView({ t, detail, source, annotations, viewerRef, onReady, onIn
32010
32167
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ZoomIcon, { kind: "in" })
32011
32168
  })]
32012
32169
  })] }),
32013
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
32170
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
32171
+ type: "button",
32172
+ className: SOFT_BUTTON_CLASS,
32173
+ onClick: onRefresh,
32174
+ disabled: refreshing,
32175
+ "aria-label": refreshing ? t("detail.refreshing") : t("action.refresh"),
32176
+ title: refreshing ? t("detail.refreshing") : t("detail.refreshHint"),
32177
+ style: refreshing ? {
32178
+ ...refreshButtonStyle,
32179
+ cursor: "default"
32180
+ } : refreshButtonStyle,
32181
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RefreshIcon, { spinning: refreshing }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: refreshing ? t("detail.refreshing") : t("action.refresh") })]
32182
+ }),
32183
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
32014
32184
  type: "button",
32015
32185
  onClick: () => onOpenInZotero(page.current),
32016
32186
  style: {
32017
32187
  ...toolButtonStyle,
32018
- marginLeft: GROUP_GAP
32188
+ marginLeft: 4
32019
32189
  },
32020
32190
  title: t("viewer.openInZotero"),
32021
- children: t("viewer.openInZoteroShort")
32191
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenInZoteroIcon, {}), t("viewer.openInZoteroShort")]
32022
32192
  })
32023
32193
  ]
32024
32194
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
@@ -32136,6 +32306,7 @@ const toolButtonStyle = {
32136
32306
  display: "inline-flex",
32137
32307
  alignItems: "center",
32138
32308
  justifyContent: "center",
32309
+ gap: 4,
32139
32310
  height: 22,
32140
32311
  minWidth: 22,
32141
32312
  padding: "0 5px",
@@ -32145,6 +32316,29 @@ const toolButtonStyle = {
32145
32316
  cursor: "pointer",
32146
32317
  whiteSpace: "nowrap"
32147
32318
  };
32319
+ /**
32320
+ * 页面级刷新:紧挨 `Zotero` 按钮左边(中间隔 4,与缩放组之间隔 GROUP_GAP)。
32321
+ *
32322
+ * 宽度按较长文案「正在刷新…」定死:换成进行中文案时按钮不变宽,工具条里的
32323
+ * 页码与标题不会被推得左右跳。文字居中,常态「刷新」两边留白即可。
32324
+ */
32325
+ const refreshButtonStyle = {
32326
+ ...SOFT_BUTTON_STYLE,
32327
+ flexShrink: 0,
32328
+ display: "inline-flex",
32329
+ alignItems: "center",
32330
+ justifyContent: "center",
32331
+ gap: 4,
32332
+ width: 106,
32333
+ height: 22,
32334
+ padding: "0 5px",
32335
+ marginLeft: GROUP_GAP,
32336
+ fontSize: 11.5,
32337
+ lineHeight: 1,
32338
+ borderRadius: 5,
32339
+ cursor: "pointer",
32340
+ whiteSpace: "nowrap"
32341
+ };
32148
32342
  //#endregion
32149
32343
  //#region src/client/ItemDetail.tsx
32150
32344
  /**
@@ -32183,7 +32377,7 @@ function attachmentSource(attachment) {
32183
32377
  source.url = isHtml(source) ? snapshotUrl(attachment.key) : fileUrl(attachment.key);
32184
32378
  return source;
32185
32379
  }
32186
- function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotation, onInsertNote, onChanged }) {
32380
+ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotation, onInsertNote, onChanged, onRefresh }) {
32187
32381
  const [infoOpen, setInfoOpen] = (0, react.useState)(false);
32188
32382
  const [outlineOpen, setOutlineOpen] = (0, react.useState)(false);
32189
32383
  const [outline, setOutline] = (0, react.useState)({
@@ -32195,6 +32389,8 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
32195
32389
  type: "all",
32196
32390
  color: null
32197
32391
  });
32392
+ /** 页面级刷新的进行中状态:工具条按钮在 `DocumentView`,动作来源在 `ZoteroItemPane`。 */
32393
+ const [refreshing, setRefreshing] = (0, react.useState)(false);
32198
32394
  const [stateKey, setStateKey] = (0, react.useState)(detail.key);
32199
32395
  const viewerRef = (0, react.useRef)(null);
32200
32396
  const pendingLocate = (0, react.useRef)(null);
@@ -32208,6 +32404,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
32208
32404
  });
32209
32405
  setInfoOpen(false);
32210
32406
  setOutlineOpen(false);
32407
+ setRefreshing(false);
32211
32408
  pendingLocate.current = null;
32212
32409
  }
32213
32410
  (0, react.useEffect)(() => () => {
@@ -32228,6 +32425,21 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
32228
32425
  } : null;
32229
32426
  /** 收起信息浮层;`InfoPanel` 内部再用 `useDismiss` 接管「点浮层外 / Esc」。 */
32230
32427
  const closeInfo = (0, react.useCallback)(() => setInfoOpen(false), []);
32428
+ /**
32429
+ * 页面级刷新:状态放这一层,工具条按钮与整份详情共用同一份。
32430
+ *
32431
+ * `ZoteroItemPane` 的刷新已经吞掉错误(只出 toast),这里只负责「进行中」,
32432
+ * 按钮在此期间禁用并显示「正在刷新…」,避免连点叠出一串请求。
32433
+ */
32434
+ async function handleRefresh() {
32435
+ if (refreshing) return;
32436
+ setRefreshing(true);
32437
+ try {
32438
+ await onRefresh();
32439
+ } finally {
32440
+ setRefreshing(false);
32441
+ }
32442
+ }
32231
32443
  const documentKey = `${detail.key}:${source?.attachmentKey ?? "self"}`;
32232
32444
  /** 归属对不上的目录一律当「还没读到」,绝不用上一条文献的书签跳页。 */
32233
32445
  const outlineItems = outline.documentKey === documentKey ? outline.items : null;
@@ -32313,6 +32525,8 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertAnnotati
32313
32525
  onInsertAnnotation,
32314
32526
  onOpenInZotero: openInZoteroAt,
32315
32527
  onChanged,
32528
+ refreshing,
32529
+ onRefresh: () => void handleRefresh(),
32316
32530
  onOutlineChange: handleOutlineChange
32317
32531
  }),
32318
32532
  outlineAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OutlinePanel, {
@@ -32380,26 +32594,13 @@ function Toast() {
32380
32594
  });
32381
32595
  }
32382
32596
  //#endregion
32383
- //#region src/client/inline.ts
32384
- /**
32385
- * 捕获草稿当前位置,再构建文本并插入。
32386
- *
32387
- * @param actions 面板从 props 拿到的 `inputActions`(缺失表示不在会话上下文)
32388
- * @param build 文本构建器;在捕获之后才执行,允许异步取数据
32389
- */
32390
- async function insertBuilt(actions, build) {
32391
- if (!actions) return "no-editor";
32392
- const span = actions.captureInsertion();
32393
- const text = await build();
32394
- return actions.insertText(text, span) ? "inserted" : "draft-changed";
32395
- }
32396
- //#endregion
32397
32597
  //#region src/client/useInsertion.ts
32398
32598
  /**
32399
32599
  * 「添加到会话」的共享动作集。
32400
32600
  *
32401
- * 主面板与条目 tab 都挂一份,行为必须一致:引用类插 chip(提交时由 codec 展开),
32402
- * 摘录插纯文本,结果统一走 toast。`inputActions` 缺失表示当前面板不在会话上下文。
32601
+ * 主面板与条目 tab 都挂一份,行为必须一致:所有引用(包括划选摘录)都插 chip,
32602
+ * 输入框里只有胶囊,完整文本在提交时由 codec 展开;结果统一走 toast。
32603
+ * `inputActions` 缺失表示当前面板不在会话上下文。
32403
32604
  */
32404
32605
  function useInsertion(t, sessions, sessionId, inputActions) {
32405
32606
  const report = (0, react.useCallback)((outcome) => {
@@ -32460,13 +32661,17 @@ function useInsertion(t, sessions, sessionId, inputActions) {
32460
32661
  report,
32461
32662
  insertReference,
32462
32663
  insertItem,
32463
- insertExcerpt: (0, react.useCallback)(async (target, quote) => {
32464
- report(await insertBuilt(inputActions, () => excerptText(t, target, quote)));
32465
- }, [
32466
- inputActions,
32467
- report,
32468
- t
32469
- ]),
32664
+ insertExcerpt: (0, react.useCallback)((target, quote) => {
32665
+ if (quote.trim() === "") {
32666
+ showToast(t("error.empty"));
32667
+ return;
32668
+ }
32669
+ if (Array.from(quote).length > 4e3) {
32670
+ showToast(tpl(t("error.excerptTooLong"), { n: MAX_EXCERPT_CHARS }));
32671
+ return;
32672
+ }
32673
+ insertReference(excerptReference(target.key, target.title, quote, excerptChipLabel(t, quote)));
32674
+ }, [insertReference, t]),
32470
32675
  insertAnnotation: (0, react.useCallback)((target, annotation) => {
32471
32676
  insertReference(annotationReference(target.key, annotation.key, annotationChipLabel(t, annotation)));
32472
32677
  }, [insertReference, t]),
@@ -32572,23 +32777,32 @@ function ZoteroItemPane(props) {
32572
32777
  signal
32573
32778
  ]);
32574
32779
  /**
32575
- * 静默重取当前详情(写操作之后走这条)。
32780
+ * 静默重取整份详情:面板内写操作之后、以及信息栏右上角的刷新按钮都走这条。
32781
+ *
32782
+ * 外部改动(模型通过 MCP 写笔记、在 Zotero 客户端里改元数据)没有推送通道,
32783
+ * 前端只能重取;`ItemDetail` 与渲染器的 key 都不变,所以滚动位置、浮层开合、
32784
+ * 选中的附件一律保留,只是把 detail 换成最新的一份。
32576
32785
  *
32577
32786
  * 不复用 `retry` 那条路径:它会把整棵树换成「加载中」,信息面板随之收起——刚存完
32578
32787
  * 一条笔记就眼看它填的内容消失,比慢半拍更让人以为是写丢了。
32579
32788
  * 失败也只提示,不清空已有详情:写已经落库,这次没刷到而已。
32789
+ *
32790
+ * 返回 Promise 让刷新按钮能显示「进行中」;`source` 只用于区分失败提示的口径
32791
+ * (写后刷新要安慰一句「已写入」,手动刷新并没有写入这回事)。
32580
32792
  */
32581
- const refresh = (0, react.useCallback)(() => {
32793
+ const refresh = (0, react.useCallback)(async (source = "write") => {
32582
32794
  if (itemKey === null) return;
32583
32795
  const current = ++seq.current;
32584
- fetchItem(itemKey, "apa", signal).then((data) => {
32796
+ try {
32797
+ const data = await fetchItem(itemKey, "apa", signal);
32585
32798
  if (current !== seq.current) return;
32586
32799
  rememberItemTitle(data.key, data.title);
32587
32800
  setDetail(data);
32588
- }).catch((err) => {
32801
+ if (source === "manual") showToast(t("detail.refreshed"));
32802
+ } catch (err) {
32589
32803
  if (current !== seq.current || signal.aborted) return;
32590
- showToast(tpl(t("detail.refreshFailed"), { message: errorMessage(err) }));
32591
- });
32804
+ showToast(tpl(t(source === "manual" ? "detail.refreshFailedManual" : "detail.refreshFailed"), { message: errorMessage(err) }));
32805
+ }
32592
32806
  }, [
32593
32807
  itemKey,
32594
32808
  signal,
@@ -32631,10 +32845,11 @@ function ZoteroItemPane(props) {
32631
32845
  t,
32632
32846
  detail,
32633
32847
  onInsertItem: () => insertItem(detail.key, detail.title),
32634
- onInsertExcerpt: (quote) => void insertExcerpt(detail, quote),
32848
+ onInsertExcerpt: (quote) => insertExcerpt(detail, quote),
32635
32849
  onInsertAnnotation: (annotation) => insertAnnotation(detail, annotation),
32636
32850
  onInsertNote: (note) => insertNote(detail, note),
32637
- onChanged: refresh
32851
+ onChanged: () => void refresh(),
32852
+ onRefresh: () => refresh("manual")
32638
32853
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Toast, {})]
32639
32854
  });
32640
32855
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-zotero",
3
- "version": "0.6.1",
3
+ "version": "0.6.5",
4
4
  "description": "Map your Zotero library into DSH: let AI operate Zotero for you and help you read papers. Browse collections and tags in the sidebar, read PDFs with highlights in place, and cite excerpts, annotations, notes or whole items into the chat. The model works from the source text for reviews, comparisons and data extraction, and can also search and organize the library, import papers and attach translations back to items; first use needs the Zotero MCP plugin and the local API enabled.",
5
5
  "keywords": [
6
6
  "dsh",