dsh-plugin-zotero 0.9.1 → 0.9.3

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/client/client.js CHANGED
@@ -1129,7 +1129,6 @@ function fetchAttachmentInfo(key, signal) {
1129
1129
  function snapshotUrl(key) {
1130
1130
  return `/dsh-zotero/snapshot/${encodeURIComponent(key)}/`;
1131
1131
  }
1132
- /** 用系统 Zotero 打开条目或附件页。 */
1133
1132
  async function openInZotero(input) {
1134
1133
  await post("open-in-zotero", input);
1135
1134
  }
@@ -2238,8 +2237,26 @@ const KNOWN_SCOPES = [
2238
2237
  "trash",
2239
2238
  "recent"
2240
2239
  ];
2240
+ const VIRTUAL_COUNT_SCOPES = [
2241
+ "publications",
2242
+ "unfiled",
2243
+ "trash"
2244
+ ];
2245
+ /** scope 是否是树里要显示数量的特殊目录。 */
2246
+ function isVirtualCountScope(scope) {
2247
+ return scope === "publications" || scope === "unfiled" || scope === "trash";
2248
+ }
2241
2249
  /** 文库根节点的 id(只存在于客户端,不对应任何 Zotero 分类)。 */
2242
2250
  const TREE_ROOT_ID = "__library__";
2251
+ /**
2252
+ * 是否选中「最近阅读」。
2253
+ *
2254
+ * 这份名单来自本插件的阅读记录,Host 端本来就按最后打开时间倒序拼好;
2255
+ * 标题排序对它没有意义,标签面板在这里也搜不到东西,所以两处都要按它关掉。
2256
+ */
2257
+ function isRecentSelection(collection) {
2258
+ return collection !== null && collection.scope === "recent";
2259
+ }
2243
2260
  function readSort() {
2244
2261
  try {
2245
2262
  const value = window.localStorage.getItem(SORT_KEY);
@@ -2322,6 +2339,7 @@ function initialState() {
2322
2339
  expanded: /* @__PURE__ */ new Set([TREE_ROOT_ID, ...saved.expanded]),
2323
2340
  treeQuery: "",
2324
2341
  recentCount: 0,
2342
+ virtualCounts: {},
2325
2343
  selectedCollection: saved.selected === null ? null : {
2326
2344
  key: saved.selected.key,
2327
2345
  name: saved.selected.name,
@@ -2346,12 +2364,14 @@ function initialState() {
2346
2364
  toast: null
2347
2365
  };
2348
2366
  }
2349
- function errorMessage$4(error) {
2367
+ function errorMessage$5(error) {
2350
2368
  return error instanceof Error ? error.message : String(error);
2351
2369
  }
2352
2370
  let state = initialState();
2353
2371
  const listeners$1 = /* @__PURE__ */ new Set();
2354
2372
  let treeInflight = null;
2373
+ /** 特殊目录计数的请求序号:刷新后迟到的旧结果不能覆盖新数量。 */
2374
+ let virtualCountsSeq = 0;
2355
2375
  let tagsInflight = null;
2356
2376
  let searchTimer = null;
2357
2377
  let toastTimer = null;
@@ -2410,6 +2430,25 @@ function selectionQuery() {
2410
2430
  return { collectionKey: collection.key };
2411
2431
  }
2412
2432
  /**
2433
+ * 后台补「我的出版物 / 未分类条目 / 回收站」的数量。
2434
+ *
2435
+ * 复用条目列表接口,只取一条读总数;不阻塞分类树渲染。单项失败保留上一次
2436
+ * 成功的值(如果还没有则继续不显示),刷新时靠序号丢掉迟到的旧结果。
2437
+ */
2438
+ function loadVirtualCounts() {
2439
+ const seq = ++virtualCountsSeq;
2440
+ for (const scope of VIRTUAL_COUNT_SCOPES) fetchItems({
2441
+ scope,
2442
+ limit: 1
2443
+ }).then((data) => {
2444
+ if (seq !== virtualCountsSeq) return;
2445
+ patch({ virtualCounts: {
2446
+ ...state.virtualCounts,
2447
+ [scope]: data.total
2448
+ } });
2449
+ }).catch(() => {});
2450
+ }
2451
+ /**
2413
2452
  * 拉取状态与分类树。
2414
2453
  *
2415
2454
  * 成功后按 key 保留原选择(真实分类被删则回到文库根),再重拉条目列表;
@@ -2445,11 +2484,12 @@ function loadTree(force = false) {
2445
2484
  expanded,
2446
2485
  selectedCollection: selected
2447
2486
  });
2487
+ loadVirtualCounts();
2448
2488
  saveTreeState();
2449
2489
  reloadItems({ reset: true });
2450
2490
  loadTagUsage();
2451
2491
  } catch (error) {
2452
- patch({ treeError: errorMessage$4(error) });
2492
+ patch({ treeError: errorMessage$5(error) });
2453
2493
  } finally {
2454
2494
  patch({ treeLoading: false });
2455
2495
  treeInflight = null;
@@ -2525,7 +2565,7 @@ function loadTags(force = false) {
2525
2565
  tagsError: null
2526
2566
  });
2527
2567
  } catch (error) {
2528
- patch({ tagsError: errorMessage$4(error) });
2568
+ patch({ tagsError: errorMessage$5(error) });
2529
2569
  } finally {
2530
2570
  patch({ tagsLoading: false });
2531
2571
  tagsInflight = null;
@@ -2583,26 +2623,33 @@ function reloadItems(options) {
2583
2623
  selectedItemKeys: /* @__PURE__ */ new Set()
2584
2624
  });
2585
2625
  patch({ itemsLoading: true });
2586
- const tags = [...state.selectedTags];
2626
+ const recent = isRecentSelection(state.selectedCollection);
2627
+ const tags = recent ? [] : [...state.selectedTags];
2628
+ const query = state.query.trim();
2629
+ const selectedScope = state.selectedCollection?.scope;
2630
+ const countScope = !append && query === "" && tags.length === 0 && isVirtualCountScope(selectedScope) ? selectedScope : null;
2587
2631
  fetchItems({
2588
2632
  ...selectionQuery(),
2589
- q: state.query.trim(),
2633
+ q: query,
2590
2634
  tags: tags.length === 0 ? void 0 : tags,
2591
2635
  tagMode: tags.length === 0 ? void 0 : state.tagMode,
2592
- sort: state.sort === "none" ? void 0 : "title",
2593
- direction: state.sort === "none" ? void 0 : state.sort,
2636
+ sort: recent || state.sort === "none" ? void 0 : "title",
2637
+ direction: recent || state.sort === "none" ? void 0 : state.sort,
2594
2638
  limit: ITEMS_PAGE_SIZE,
2595
2639
  offset
2596
2640
  }, controller.signal).then((data) => {
2597
2641
  if (current !== itemsSeq) return;
2642
+ const virtualCounts = { ...state.virtualCounts };
2643
+ if (countScope !== null) virtualCounts[countScope] = data.total;
2598
2644
  patch({
2599
2645
  items: append ? [...state.items, ...data.items] : data.items,
2600
2646
  itemsTotal: data.total,
2601
- itemsError: null
2647
+ itemsError: null,
2648
+ virtualCounts
2602
2649
  });
2603
2650
  }).catch((error) => {
2604
2651
  if (current !== itemsSeq || controller.signal.aborted) return;
2605
- patch({ itemsError: errorMessage$4(error) });
2652
+ patch({ itemsError: errorMessage$5(error) });
2606
2653
  }).finally(() => {
2607
2654
  if (current !== itemsSeq) return;
2608
2655
  patch({ itemsLoading: false });
@@ -2623,6 +2670,7 @@ function loadMoreItems() {
2623
2670
  * 状态写进 localStorage:所有会话共用同一块面板,重启后也保持上次的选择。
2624
2671
  */
2625
2672
  function cycleItemSort() {
2673
+ if (isRecentSelection(state.selectedCollection)) return;
2626
2674
  const next = state.sort === "none" ? "asc" : state.sort === "asc" ? "desc" : "none";
2627
2675
  patch({ sort: next });
2628
2676
  try {
@@ -4230,7 +4278,7 @@ const EMPTY_DRAFT = {
4230
4278
  pageLabel: "",
4231
4279
  tags: ""
4232
4280
  };
4233
- function errorMessage$3(error) {
4281
+ function errorMessage$4(error) {
4234
4282
  return error instanceof Error ? error.message : String(error);
4235
4283
  }
4236
4284
  /**
@@ -4393,7 +4441,7 @@ function AnnotationList({ t, annotations, hasFulltext, truncated, filter, canWri
4393
4441
  onChanged();
4394
4442
  return true;
4395
4443
  } catch (error) {
4396
- setNotice(tpl(t("annotation.writeFailed"), { message: errorMessage$3(error) }));
4444
+ setNotice(tpl(t("annotation.writeFailed"), { message: errorMessage$4(error) }));
4397
4445
  return false;
4398
4446
  } finally {
4399
4447
  setBusy(false);
@@ -5787,7 +5835,7 @@ const highlightLabelStyle = {
5787
5835
  */
5788
5836
  /** 输入停止多久后自动写回。太短会把每次停顿都变成一次 PATCH。 */
5789
5837
  const SAVE_DELAY = 800;
5790
- function errorMessage$2(error) {
5838
+ function errorMessage$3(error) {
5791
5839
  return error instanceof Error ? error.message : String(error);
5792
5840
  }
5793
5841
  function NoteList({ t, notes, itemKey, canWrite, selfNote, composing, onComposingChange, onInsert, onChanged }) {
@@ -5833,7 +5881,7 @@ function NoteComposer({ t, itemKey, onCancel, onCreated }) {
5833
5881
  onCreated();
5834
5882
  onCancel();
5835
5883
  } catch (error) {
5836
- setNotice(tpl(t("note.writeFailed"), { message: errorMessage$2(error) }));
5884
+ setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
5837
5885
  } finally {
5838
5886
  setBusy(false);
5839
5887
  }
@@ -5914,7 +5962,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
5914
5962
  if (fresh.version > version.current) version.current = fresh.version;
5915
5963
  if (alive.current) setRaw(fresh.html);
5916
5964
  } catch (error) {
5917
- if (alive.current) setNotice(tpl(t("note.readFailed"), { message: errorMessage$2(error) }));
5965
+ if (alive.current) setNotice(tpl(t("note.readFailed"), { message: errorMessage$3(error) }));
5918
5966
  } finally {
5919
5967
  if (alive.current) setLoading(false);
5920
5968
  }
@@ -5976,7 +6024,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
5976
6024
  } catch (error) {
5977
6025
  if (alive.current) {
5978
6026
  setStatus("idle");
5979
- setNotice(tpl(t("note.writeFailed"), { message: errorMessage$2(error) }));
6027
+ setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
5980
6028
  }
5981
6029
  } finally {
5982
6030
  inflight.current = false;
@@ -6026,7 +6074,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
6026
6074
  showToast(t("note.deleted"));
6027
6075
  onChanged();
6028
6076
  } catch (error) {
6029
- if (alive.current) setNotice(tpl(t("note.writeFailed"), { message: errorMessage$2(error) }));
6077
+ if (alive.current) setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
6030
6078
  } finally {
6031
6079
  if (alive.current) setRemoving(false);
6032
6080
  }
@@ -39097,7 +39145,7 @@ const OUTLINE_SOURCE_LABEL = {
39097
39145
  text: "outline.source.text",
39098
39146
  webpage: "outline.source.text"
39099
39147
  };
39100
- function errorMessage$1(error) {
39148
+ function errorMessage$2(error) {
39101
39149
  return error instanceof Error ? error.message : String(error);
39102
39150
  }
39103
39151
  function attachmentSource(attachment) {
@@ -39292,7 +39340,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertTranslat
39292
39340
  kind: "attachment",
39293
39341
  page
39294
39342
  }).catch((error) => {
39295
- showToast(tpl(t("viewer.openFailed"), { message: errorMessage$1(error) }));
39343
+ showToast(tpl(t("viewer.openFailed"), { message: errorMessage$2(error) }));
39296
39344
  });
39297
39345
  }
39298
39346
  /**
@@ -39665,7 +39713,7 @@ function itemKeyFromAddress(address) {
39665
39713
  function parseItemKey(info) {
39666
39714
  return itemKeyFromAddress(info.tab.navigation?.address || info.tab.contentId || "");
39667
39715
  }
39668
- function errorMessage(error) {
39716
+ function errorMessage$1(error) {
39669
39717
  return error instanceof Error ? error.message : String(error);
39670
39718
  }
39671
39719
  const hintStyle$4 = {
@@ -39700,7 +39748,7 @@ function ZoteroItemPane(props) {
39700
39748
  setLoading(false);
39701
39749
  }).catch((err) => {
39702
39750
  if (current !== seq.current || signal.aborted) return;
39703
- setError(errorMessage(err));
39751
+ setError(errorMessage$1(err));
39704
39752
  setLoading(false);
39705
39753
  });
39706
39754
  }, [
@@ -39733,7 +39781,7 @@ function ZoteroItemPane(props) {
39733
39781
  if (source === "manual") showToast(t("detail.refreshed"));
39734
39782
  } catch (err) {
39735
39783
  if (current !== seq.current || signal.aborted) return;
39736
- showToast(tpl(t(source === "manual" ? "detail.refreshFailedManual" : "detail.refreshFailed"), { message: errorMessage(err) }));
39784
+ showToast(tpl(t(source === "manual" ? "detail.refreshFailedManual" : "detail.refreshFailed"), { message: errorMessage$1(err) }));
39737
39785
  }
39738
39786
  }, [
39739
39787
  itemKey,
@@ -39794,7 +39842,8 @@ function ZoteroItemPane(props) {
39794
39842
  *
39795
39843
  * - 行首三角箭头只管开合,且只在有子分类的行出现;点行体选中该范围。
39796
39844
  * - 缩进按层级一次性算出(`depth * INDENT`),不再逐层叠加 margin。
39797
- * - 真实分类行右侧显示条目数;右键 → 「添加整目录引用」。
39845
+ * - 真实分类与特殊目录(我的出版物 / 未分类条目 / 回收站)右侧显示条目数;
39846
+ * 右键真实分类 → 「添加整目录引用」。
39798
39847
  * - 「我的文库」根节点是可选中的全库范围;其下挂三个虚拟分类
39799
39848
  * (我的出版物 / 未分类条目 / 回收站),与 Zotero 左侧栏一致。
39800
39849
  * - 顶部筛选框只筛目录名(同 Zotero 左栏):命中分类保留、非命中的祖先作为
@@ -40060,8 +40109,11 @@ function virtualCollection(node, t) {
40060
40109
  function VirtualRows({ ctx, node, depth }) {
40061
40110
  const collection = virtualCollection(node, ctx.t);
40062
40111
  const selected = ctx.selectedCollectionKey === collection.key;
40063
- /** 只有「最近阅读」显示计数:其余虚拟分类的条目数要扫全库,代价不值得。 */
40064
- const count = node.scope === "recent" ? ctx.recentCount : void 0;
40112
+ /**
40113
+ * 最近阅读读插件自己的进度记录;其余三个特殊目录读后台补的 total。
40114
+ * 数量异步返回,没取到时保持不显示,不让数字把树撑变形。
40115
+ */
40116
+ const count = node.scope === "recent" ? ctx.recentCount : isVirtualCountScope(node.scope) ? ctx.virtualCounts[node.scope] : void 0;
40065
40117
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
40066
40118
  onClick: () => ctx.select(collection),
40067
40119
  style: {
@@ -40088,7 +40140,7 @@ function VirtualRows({ ctx, node, depth }) {
40088
40140
  });
40089
40141
  }
40090
40142
  function CollectionTree(props) {
40091
- const { t, libraryName, collections, treeQuery, selectedCollectionKey, recentCount, onSelectCollection, onInsertCollection } = props;
40143
+ const { t, libraryName, collections, treeQuery, selectedCollectionKey, recentCount, virtualCounts, onSelectCollection, onInsertCollection } = props;
40092
40144
  /** 展开集合在 store 里(默认展开根节点),重挂面板后原样恢复。 */
40093
40145
  const { expanded } = usePaneState();
40094
40146
  const filter = treeQuery.trim().toLowerCase();
@@ -40103,6 +40155,7 @@ function CollectionTree(props) {
40103
40155
  filter,
40104
40156
  selectedCollectionKey,
40105
40157
  recentCount,
40158
+ virtualCounts,
40106
40159
  toggle: toggleTreeNode,
40107
40160
  select: onSelectCollection,
40108
40161
  onInsertCollection
@@ -40311,6 +40364,9 @@ function SearchField({ value, placeholder, clearLabel, onChange }) {
40311
40364
  * 多选,右上角「引用 N」把选中的每条各插一个胶囊。右键单行仍能直接插该条引用。
40312
40365
  * 列表分页(加载更多),筛选后为空与本来为空分开提示。
40313
40366
  *
40367
+ * 标题排序按钮只在真实分类 / 虚拟分类下出现:「最近阅读」恒按最后打开时间倒序,
40368
+ * 那一栏不给排序入口(见 {@link isRecentSelection})。
40369
+ *
40314
40370
  * 行内排版是两行:第一行只放标题,第二行小字灰色放「类型 + 年份 + 作者」,
40315
40371
  * 行与行之间用一条浅色细线分隔。
40316
40372
  */
@@ -40412,6 +40468,7 @@ const itemMetaAttachStyle = {
40412
40468
  alignItems: "center",
40413
40469
  gap: 2,
40414
40470
  flex: "0 0 auto",
40471
+ marginLeft: "auto",
40415
40472
  opacity: .85
40416
40473
  };
40417
40474
  const itemMetaTextStyle = {
@@ -40713,6 +40770,8 @@ function ItemList(props) {
40713
40770
  const { t, libraryName, selectedCollection, query, items, itemsTotal, itemsLoading, itemsError, selectedTags, tagMode, sort, selectedItemKeys, onSearch, onRemoveTag, onRetry, onLoadMore, onCycleSort, onOpenItem, onSelectItem, onClearSelection, onInsertItem, onInsertItems, onInsertCollection } = props;
40714
40771
  const name = selectionName(t, libraryName, selectedCollection);
40715
40772
  const isRealCollection = selectedCollection !== null && selectedCollection.key !== "__library__" && selectedCollection.scope === void 0;
40773
+ /** 「最近阅读」恒按最后打开时间倒序:不给标题排序入口,省得点了没反应。 */
40774
+ const recent = isRecentSelection(selectedCollection);
40716
40775
  const tags = [...selectedTags];
40717
40776
  const filtered = tags.length > 0 || query.trim() !== "";
40718
40777
  /** 按列表顺序取选中项,插进草稿的 chip 顺序才与眼前一致。 */
@@ -40758,7 +40817,7 @@ function ItemList(props) {
40758
40817
  onClick: () => onInsertCollection(selectedCollection),
40759
40818
  children: t("action.insertItemShort")
40760
40819
  }) : null,
40761
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
40820
+ !recent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
40762
40821
  variant: "ghost",
40763
40822
  size: "sm",
40764
40823
  title: sortHint(t, sort),
@@ -41241,7 +41300,8 @@ const plainButtonStyle = {
41241
41300
  *
41242
41301
  * 与 Zotero 一致:左侧只有分类与标签,条目一律在右侧列表;列表行单击选中、
41243
41302
  * 双击才在本面板顶层开独立 tab(`onOpenItem`),详情不再占列表位置。
41244
- * 标签面板跟随当前目录:选中目录只列该目录自身的标签,切目录清空已选。
41303
+ * 标签面板跟随当前目录:选中目录只列该目录自身的标签,切目录清空已选;
41304
+ * 「最近阅读」下整块标签面板不渲染(只按最后打开时间列条目,不参与标签筛选)。
41245
41305
  *
41246
41306
  * 两栏之间是可拖动的分隔条(宽度存 localStorage,跨会话/重启都记住)。
41247
41307
  * 数据与选择状态都在 {@link paneStore} 的模块级单例里(跨会话共用同一块面板)。
@@ -41280,12 +41340,34 @@ function StatusDot({ ok, label }) {
41280
41340
  } }), label]
41281
41341
  });
41282
41342
  }
41343
+ function errorMessage(error) {
41344
+ return error instanceof Error ? error.message : String(error);
41345
+ }
41283
41346
  function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
41284
- const { health, libraryName, collections, treeError, treeLoading, selectedCollection, query, items, itemsTotal, itemsLoading, itemsError, tags, tagsLoading, tagsError, treeQuery, recentCount, tagQuery, selectedTags, tagMode, tagUsage, tagUsageLoading, sort, selectedItemKeys } = usePaneState();
41347
+ const { health, libraryName, collections, treeError, treeLoading, selectedCollection, query, items, itemsTotal, itemsLoading, itemsError, tags, tagsLoading, tagsError, treeQuery, recentCount, virtualCounts, tagQuery, selectedTags, tagMode, tagUsage, tagUsageLoading, sort, selectedItemKeys } = usePaneState();
41285
41348
  (0, react.useEffect)(() => {
41286
41349
  loadTree();
41287
41350
  }, []);
41351
+ /**
41352
+ * 「最近阅读」下不渲染标签面板:那份名单只来自本插件的阅读记录,
41353
+ * 标签过滤在里面筛不出东西,留着只会占掉分类树的高度。
41354
+ */
41355
+ const recent = isRecentSelection(selectedCollection);
41288
41356
  const insertion = useInsertion(t, sessions, sessionId, inputActions);
41357
+ /**
41358
+ * 跳回 Zotero 主窗口:真实分类带 key 跳到该分类(目录树 + 列表),
41359
+ * 文库根与「最近阅读」等虚拟分类没有 select URL,只唤起主窗口。
41360
+ */
41361
+ function openCurrentInZotero() {
41362
+ const collection = selectedCollection;
41363
+ const key = collection !== null && collection.key !== "__library__" && collection.scope === void 0 ? collection.key : null;
41364
+ openInZotero(key === null ? { kind: "library" } : {
41365
+ kind: "collection",
41366
+ key
41367
+ }).catch((error) => {
41368
+ showToast(tpl(t("viewer.openFailed"), { message: errorMessage(error) }));
41369
+ });
41370
+ }
41289
41371
  const [treeWidth, setTreeWidth] = (0, react.useState)(readTreeWidth);
41290
41372
  const [splitHover, setSplitHover] = (0, react.useState)(false);
41291
41373
  const bodyRef = (0, react.useRef)(null);
@@ -41352,6 +41434,18 @@ function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
41352
41434
  size: "sm",
41353
41435
  onClick: () => void loadTree(true),
41354
41436
  children: t("action.refresh")
41437
+ }),
41438
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
41439
+ variant: "ghost",
41440
+ size: "sm",
41441
+ onClick: openCurrentInZotero,
41442
+ title: t("viewer.openInZotero"),
41443
+ style: {
41444
+ display: "inline-flex",
41445
+ alignItems: "center",
41446
+ gap: 5
41447
+ },
41448
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenInZoteroIcon, { size: 12 }), t("viewer.openInZoteroShort")]
41355
41449
  })
41356
41450
  ]
41357
41451
  }),
@@ -41406,11 +41500,12 @@ function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
41406
41500
  treeQuery,
41407
41501
  selectedCollectionKey: selectedCollection?.key ?? null,
41408
41502
  recentCount,
41503
+ virtualCounts,
41409
41504
  onSelectCollection: selectCollection,
41410
41505
  onInsertCollection: insertion.insertCollection
41411
41506
  })
41412
41507
  }),
41413
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagPanel, {
41508
+ !recent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TagPanel, {
41414
41509
  t,
41415
41510
  tags,
41416
41511
  tagsLoading,
@@ -365,16 +365,8 @@ async function handleAttachmentInfo(res, params) {
365
365
  };
366
366
  ok(res, data);
367
367
  }
368
- /** 用系统默认处理器打开 `zotero://` URL;参数数组传递,不经过 shell。 */
369
- function openExternal(url) {
370
- const command = process.platform === 'darwin'
371
- ? 'open'
372
- : process.platform === 'win32'
373
- ? 'rundll32'
374
- : 'xdg-open';
375
- const args = process.platform === 'win32'
376
- ? ['url.dll,FileProtocolHandler', url]
377
- : [url];
368
+ /** 分离进程启动外部命令;参数数组传递,不经过 shell。 */
369
+ function spawnDetached(command, args) {
378
370
  return new Promise((resolvePromise, reject) => {
379
371
  const child = spawn(command, args, { detached: true, stdio: 'ignore' });
380
372
  child.once('spawn', () => {
@@ -386,6 +378,29 @@ function openExternal(url) {
386
378
  });
387
379
  });
388
380
  }
381
+ /** 用系统默认处理器打开 `zotero://` URL。 */
382
+ function openExternal(url) {
383
+ const command = process.platform === 'darwin'
384
+ ? 'open'
385
+ : process.platform === 'win32'
386
+ ? 'rundll32'
387
+ : 'xdg-open';
388
+ const args = process.platform === 'win32'
389
+ ? ['url.dll,FileProtocolHandler', url]
390
+ : [url];
391
+ return spawnDetached(command, args);
392
+ }
393
+ /**
394
+ * 启动 / 激活 Zotero 主窗口:没有可定位的分类 key 时用(文库根、虚拟分类)。
395
+ * `zotero://select/library` 不是合法的 select URL,只能交给系统唤起应用。
396
+ */
397
+ function activateZotero() {
398
+ if (process.platform === 'darwin')
399
+ return spawnDetached('open', ['-a', 'Zotero']);
400
+ if (process.platform === 'win32')
401
+ return spawnDetached('cmd.exe', ['/c', 'start', '', 'zotero']);
402
+ return spawnDetached('zotero', []);
403
+ }
389
404
  /** 读取小请求体;超过上限直接拒绝,避免被大 body 拖住。 */
390
405
  async function readBody(req, limit) {
391
406
  const chunks = [];
@@ -402,9 +417,29 @@ async function readBody(req, limit) {
402
417
  async function handleOpenInZotero(req, res) {
403
418
  const record = await readJsonBody(req, 4096);
404
419
  const key = typeof record.key === 'string' ? record.key : '';
405
- const kind = record.kind === 'item' || record.kind === 'attachment' ? record.kind : null;
406
- if (!KEY_PATTERN.test(key) || kind === null) {
407
- fail(res, 400, 'bad_request', 'key 或 kind 不合法');
420
+ const kind = record.kind === 'item'
421
+ || record.kind === 'attachment'
422
+ || record.kind === 'collection'
423
+ || record.kind === 'library'
424
+ ? record.kind
425
+ : null;
426
+ if (kind === null) {
427
+ fail(res, 400, 'bad_request', 'kind 不合法');
428
+ return;
429
+ }
430
+ if (kind === 'library') {
431
+ await activateZotero();
432
+ ok(res, { opened: true });
433
+ return;
434
+ }
435
+ if (!KEY_PATTERN.test(key)) {
436
+ fail(res, 400, 'bad_request', 'key 格式不合法');
437
+ return;
438
+ }
439
+ if (kind === 'collection') {
440
+ // Zotero 主窗口选中该分类,右侧即为该分类的文献列表。
441
+ await openExternal(`zotero://select/library/collections/${key}`);
442
+ ok(res, { opened: true });
408
443
  return;
409
444
  }
410
445
  let url = `zotero://select/library/items/${key}`;
@@ -188,6 +188,8 @@ export interface ListTagUsageOptions {
188
188
  * 传多个 `collectionKeys` 时分目录扫描,并按条目 key 去重——同一篇条目可能
189
189
  * 同时挂在父分类与子分类里,不能重复计数。超过 `USAGE_SCAN_MAX` 条的大范围
190
190
  * 按前若干页截断,超大目录可能漏掉靠后的标签(本地 API 没有按分类列标签的端点)。
191
+ *
192
+ * 回收站走 `/items/trash/top`:不带 `/top` 会把子附件也扫进来,与列表口径不一致。
191
193
  */
192
194
  export declare function listTagUsage(options: ListTagUsageOptions): Promise<ZoteroTags>;
193
195
  export interface ListItemsOptions {
@@ -512,6 +512,8 @@ const USAGE_SCAN_MAX = 3000;
512
512
  * 传多个 `collectionKeys` 时分目录扫描,并按条目 key 去重——同一篇条目可能
513
513
  * 同时挂在父分类与子分类里,不能重复计数。超过 `USAGE_SCAN_MAX` 条的大范围
514
514
  * 按前若干页截断,超大目录可能漏掉靠后的标签(本地 API 没有按分类列标签的端点)。
515
+ *
516
+ * 回收站走 `/items/trash/top`:不带 `/top` 会把子附件也扫进来,与列表口径不一致。
515
517
  */
516
518
  export async function listTagUsage(options) {
517
519
  // 「最近阅读」没有可按分类扫描的端点,也没有必要:面板在选它时不请求标签用量。
@@ -523,7 +525,7 @@ export async function listTagUsage(options) {
523
525
  const bases = options.scope === 'publications'
524
526
  ? [`${libraryBase()}/publications/items`]
525
527
  : options.scope === 'trash'
526
- ? [`${libraryBase()}/items/trash`]
528
+ ? [`${libraryBase()}/items/trash/top`]
527
529
  : (options.collectionKeys ?? []).length > 0
528
530
  ? options.collectionKeys.map((key) => `${libraryBase()}/collections/${encode(key)}/items/top`)
529
531
  : [`${libraryBase()}/items/top`];
@@ -631,12 +633,18 @@ function appendItemSort(params, options) {
631
633
  params.set('sort', options.sort);
632
634
  params.set('direction', options.direction === 'desc' ? 'desc' : 'asc');
633
635
  }
634
- /** 范围内的顶层条目端点基址(条目列表与标签用量共用同一套范围规则)。 */
636
+ /**
637
+ * 范围内的顶层条目端点基址(条目列表与标签用量共用同一套范围规则)。
638
+ *
639
+ * 回收站必须用 `/items/trash/top`:Zotero 本地 API 的 `/items/trash` 会把
640
+ * 子附件一并列出,`Total-Results` 因此比客户端回收站的顶层条目数多(实测
641
+ * 126 = 94 顶层 + 32 子附件),列表里也会多出一批子附件行。
642
+ */
635
643
  function itemListBase(options) {
636
644
  return options.scope === 'publications'
637
645
  ? `${libraryBase()}/publications/items`
638
646
  : options.scope === 'trash'
639
- ? `${libraryBase()}/items/trash`
647
+ ? `${libraryBase()}/items/trash/top`
640
648
  : options.collectionKey
641
649
  ? `${libraryBase()}/collections/${encode(options.collectionKey)}/items/top`
642
650
  : `${libraryBase()}/items/top`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-zotero",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
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",