dsh-gallery 1.5.0 → 1.6.4

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.js CHANGED
@@ -1046,6 +1046,11 @@ async function encodeMaskPngBytes(imageData, width, height) {
1046
1046
  groupInput: '素材 {n}',
1047
1047
  groupIntermediate: '过程稿 {n}',
1048
1048
  groupUnknown: '未归类 {n}',
1049
+ // v1.6.4:跨对话共用 —— 同一个文件被多个对话引用(不合并、不去重,只标归属)
1050
+ groupShared: '共用 {n}',
1051
+ groupSharedTip: '这 {n} 张是同一个文件,{who} 也在用。在任一对话里删除或隐藏,两边会一起生效;同名但不同路径的两份文件互不影响。',
1052
+ sharedWithSome: '其他对话',
1053
+ sharedWithMany: '{first} 等 {n} 个对话',
1049
1054
  groupTruncated: '仅显示最近 {shown} 个,共 {total} 个',
1050
1055
  groupShowMore: '再显示 {step} 张 · 已显示 {shown} / 共 {total}',
1051
1056
  groupHistoryTitle: '历史资产',
@@ -1124,9 +1129,9 @@ async function encodeMaskPngBytes(imageData, width, height) {
1124
1129
  ctxCopy: '写进输入框',
1125
1130
  ctxDelete: '删除文件',
1126
1131
  ctxDeleteSelected: '删除选中的 {n} 个文件',
1127
- ctxDeleteManyTitle: '确认删除 {n} 个文件?此操作不可恢复',
1132
+ ctxDeleteManyTitle: '把 {n} 个文件移到回收区?可撤销',
1128
1133
  ctxDeleteManySummary: '共 {n} 个文件',
1129
- ctxDeletePartial: '已删除 {n} 个,{fail} 个失败',
1134
+ ctxDeletePartial: '已移到回收区 {n} 个,{fail} 个失败',
1130
1135
  batchDeleteSelected: '删除所选',
1131
1136
  batchDeleteHint: '删除选中的全部文件(会二次确认,不可恢复)',
1132
1137
  // 2026-11-25 按标签圈选:把某一类下的文件一次选中,再交给批量动作
@@ -1140,8 +1145,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
1140
1145
  batchInvertHint: '选中当前列表里还没选中的文件',
1141
1146
  ctxCopyFileSelected: '复制选中的 {n} 个文件',
1142
1147
  labelEditSelected: '改这 {n} 张的标签',
1143
- ctxDeleteConfirm: '确认删除?此操作不可恢复',
1144
- ctxDeleteYes: '确认删除',
1148
+ ctxDeleteConfirm: '移到回收区?可撤销(Ctrl+Z)',
1149
+ ctxDeleteYes: '移到回收区',
1145
1150
  ctxDeleteNo: '取消',
1146
1151
  // 批注删除按钮的 title 与卡片删除共用 t('delete')
1147
1152
  delete: '删除',
@@ -1290,6 +1295,9 @@ async function encodeMaskPngBytes(imageData, width, height) {
1290
1295
  thumbFailed: '无法加载',
1291
1296
  dims: '{w} × {h}',
1292
1297
  dimsUnknown: '尺寸未知',
1298
+ // v1.6.3:同一视图里的同名文件(不是重复,是两份不同目录的真文件)
1299
+ sameNameIn: '同名 {n} 份 · {dir}',
1300
+ rootDir: '根目录',
1293
1301
  close: '关闭',
1294
1302
  prev: '上一张',
1295
1303
  next: '下一张',
@@ -1315,9 +1323,52 @@ async function encodeMaskPngBytes(imageData, width, height) {
1315
1323
  // v1.5.0 导出交付清单:CSV 进 Excel、JSON 给下一轮,落在 ~/.dsh/gallery-exports/
1316
1324
  batchExportManifest: '导出清单',
1317
1325
  batchExportHint: '把选中的这批导出成交付清单(CSV 给 Excel 看、JSON 给下一轮读),存到 ~/.dsh/gallery-exports/;同名不覆盖',
1318
- exportOk: '已导出 {n} 条清单:{path}',
1326
+ exportOk: '已导出 {n} 条:{name}',
1319
1327
  exportEmpty: '这批没有可导出的文件(可能还没打分类)',
1320
1328
  exportFailed: '导出清单失败:{message}',
1329
+ // v1.6.0:清单落盘后给三个便捷出口(打开文件夹 / 复制路径 / 写进输入框)
1330
+ exportOpenDir: '打开文件夹',
1331
+ exportCopyPath: '复制路径',
1332
+ exportToComposer: '写进输入框',
1333
+ // v1.6.2:导出记录(常驻,事后照样能再引用一次)
1334
+ exportHistoryEntry: '导出记录',
1335
+ exportHistoryOpen: '导出记录',
1336
+ exportHistoryTitle: '导出记录',
1337
+ exportHistoryHint: '以前导出的交付清单都在这;点「写进输入框」就能把这批清单再递给助手',
1338
+ exportHistoryEmpty: '还没有导出过清单',
1339
+ exportHistoryLoading: '读取中…',
1340
+ exportHistoryFailed: '读不到导出记录:{message}',
1341
+ exportHistorySource: '来源',
1342
+ exportHistoryCount: '{n} 条',
1343
+ exportHistoryMissing: '文件已不在(可能被移走或删了)',
1344
+ exportHistoryRefresh: '刷新',
1345
+ exportHistoryLegacy: '早期导出',
1346
+ exportHistoryGlobal: '全局资产',
1347
+ exportHistoryUnknownSource: '未记录来源',
1348
+ exportPathCopied: '清单路径已复制到剪贴板',
1349
+ exportPathCopyFailed: '复制路径失败,请手动选中提示里的路径',
1350
+ exportOpenFailed: '打不开导出文件夹:{message}',
1351
+ exportDraftReady: '清单路径已写进输入框(只写不发)',
1352
+ exportDraftInClipboard: '写不进输入框,路径已放剪贴板',
1353
+ // v1.6.0 撤销(Ctrl+Z):删除移到回收区、隐藏取消隐藏,两类都能撤
1354
+ undoAction: '撤销 (Ctrl+Z)',
1355
+ undoNothing: '没有可撤销的操作',
1356
+ whereGlobal: '全局资产',
1357
+ whereSession: '当前对话',
1358
+ // v1.6.2:撤销提示要能看出「是哪个对话、哪一类」——
1359
+ // 老板切了几个对话后,只写「当前对话」等于没说。
1360
+ whereSessionNamed: '对话「{name}」',
1361
+ kindImage: '图片',
1362
+ kindFile: '文件',
1363
+ kindMedia: '音视频',
1364
+ undoOtherScope: '这里没有可撤销的操作;最近一批在「{where}」的{kind}里,切过去再按 Ctrl+Z',
1365
+ undoDeleteOk: '已移到回收区:{n} 个文件(按 Ctrl+Z 可撤回)',
1366
+ undoHideOk: '已隐藏 {n} 个文件(按 Ctrl+Z 可撤回)',
1367
+ undoDeleteDone: '已撤销:{n} 个文件回到原位({where} · {kind})',
1368
+ undoDeletePartial: '撤销完成 {n} 个;{fail} 个失败、{conflict} 个原位已有同名文件(未覆盖)',
1369
+ undoDeleteNone: '没能撤回来:这批可能已过保留期被清理',
1370
+ undoHideDone: '已撤销隐藏:{n} 个文件回到列表({where} · {kind})',
1371
+ undoFailed: '撤销失败:{message}',
1321
1372
  copyOk: '已复制 {n} 个文件到剪贴板;切到目标对话后右键「粘贴」或按 Ctrl+V',
1322
1373
  copyOkInternal: '已复制 {n} 个文件(系统剪贴板不可用,仅插件内粘贴有效)',
1323
1374
  copyFailed: '复制失败:{message}',
@@ -1516,6 +1567,11 @@ async function encodeMaskPngBytes(imageData, width, height) {
1516
1567
  groupInput: 'Source {n}',
1517
1568
  groupIntermediate: 'WIP {n}',
1518
1569
  groupUnknown: 'Unclassified {n}',
1570
+ // v1.6.4: assets referenced by more than one chat (kept in both, labelled)
1571
+ groupShared: 'Shared {n}',
1572
+ groupSharedTip: '{n} of these are the same file(s) {who} also uses. Deleting or hiding in one place affects both; same-name files in different folders stay independent.',
1573
+ sharedWithSome: 'other chats',
1574
+ sharedWithMany: '{first} and {n} chats',
1519
1575
  groupTruncated: 'Showing latest {shown} of {total}',
1520
1576
  groupShowMore: 'Show {step} more · {shown} of {total}',
1521
1577
  groupHistoryTitle: 'Older assets',
@@ -1593,9 +1649,9 @@ async function encodeMaskPngBytes(imageData, width, height) {
1593
1649
  ctxCopy: 'Write into chat input',
1594
1650
  ctxDelete: 'Delete file',
1595
1651
  ctxDeleteSelected: 'Delete {n} selected files',
1596
- ctxDeleteManyTitle: 'Delete {n} files permanently? This cannot be undone',
1652
+ ctxDeleteManyTitle: 'Move {n} files to Trash? This can be undone',
1597
1653
  ctxDeleteManySummary: '{n} files',
1598
- ctxDeletePartial: 'Deleted {n}, {fail} failed',
1654
+ ctxDeletePartial: 'Moved {n} to Trash, {fail} failed',
1599
1655
  batchDeleteSelected: 'Delete selected',
1600
1656
  batchDeleteHint: 'Delete every selected file (asks for confirmation, cannot be undone)',
1601
1657
  legendPick: 'Pick',
@@ -1608,8 +1664,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
1608
1664
  batchInvertHint: 'Select the files in the current list that are not selected yet',
1609
1665
  ctxCopyFileSelected: 'Copy {n} selected files',
1610
1666
  labelEditSelected: 'Re-label these {n} files',
1611
- ctxDeleteConfirm: 'Delete permanently? This cannot be undone',
1612
- ctxDeleteYes: 'Delete',
1667
+ ctxDeleteConfirm: 'Move to Trash? You can undo with Ctrl+Z',
1668
+ ctxDeleteYes: 'Move to Trash',
1613
1669
  ctxDeleteNo: 'Cancel',
1614
1670
  delete: 'Delete',
1615
1671
  ctxHiddenDone: 'Hidden. Restore it in settings later.',
@@ -1753,6 +1809,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
1753
1809
  thumbFailed: 'Cannot load',
1754
1810
  dims: '{w} × {h}',
1755
1811
  dimsUnknown: 'Size unknown',
1812
+ sameNameIn: '{n} with the same name · {dir}',
1813
+ rootDir: 'root folder',
1756
1814
  close: 'Close',
1757
1815
  prev: 'Previous',
1758
1816
  next: 'Next',
@@ -1777,9 +1835,47 @@ async function encodeMaskPngBytes(imageData, width, height) {
1777
1835
  batchCopyHint: 'Write the selected files to the system clipboard; paste them in another chat or Explorer',
1778
1836
  batchExportManifest: 'Export list',
1779
1837
  batchExportHint: 'Export the selection as a delivery list (CSV for Excel, JSON for the next round) into ~/.dsh/gallery-exports/; existing files are never overwritten',
1780
- exportOk: 'Exported {n} items: {path}',
1838
+ exportOk: 'Exported {n} items: {name}',
1781
1839
  exportEmpty: 'Nothing exportable in this batch (maybe no category yet)',
1782
1840
  exportFailed: 'Export failed: {message}',
1841
+ exportOpenDir: 'Open folder',
1842
+ exportCopyPath: 'Copy path',
1843
+ exportToComposer: 'Write to input',
1844
+ exportHistoryEntry: 'Export history',
1845
+ exportHistoryOpen: 'Export history',
1846
+ exportHistoryTitle: 'Export history',
1847
+ exportHistoryHint: 'Every delivery list you exported is listed here; "Write to input" hands the path to the assistant again',
1848
+ exportHistoryEmpty: 'No lists exported yet',
1849
+ exportHistoryLoading: 'Loading…',
1850
+ exportHistoryFailed: 'Could not read the export history: {message}',
1851
+ exportHistorySource: 'Source',
1852
+ exportHistoryCount: '{n} items',
1853
+ exportHistoryMissing: 'File is gone (moved or deleted)',
1854
+ exportHistoryRefresh: 'Refresh',
1855
+ exportHistoryLegacy: 'Earlier export',
1856
+ exportHistoryGlobal: 'All assets',
1857
+ exportHistoryUnknownSource: 'Source not recorded',
1858
+ exportPathCopied: 'List path copied to clipboard',
1859
+ exportPathCopyFailed: 'Copy failed — select the path in the notice manually',
1860
+ exportOpenFailed: 'Could not open the export folder: {message}',
1861
+ exportDraftReady: 'List path written to the input box (written, not sent)',
1862
+ exportDraftInClipboard: 'Could not write to the input box; path is on the clipboard',
1863
+ undoAction: 'Undo (Ctrl+Z)',
1864
+ undoNothing: 'Nothing to undo',
1865
+ whereGlobal: 'All assets',
1866
+ whereSession: 'This chat',
1867
+ whereSessionNamed: 'chat "{name}"',
1868
+ kindImage: 'images',
1869
+ kindFile: 'files',
1870
+ kindMedia: 'media',
1871
+ undoOtherScope: 'Nothing to undo here; the latest batch was in {kind} of "{where}" — switch there and press Ctrl+Z',
1872
+ undoDeleteOk: 'Moved {n} file(s) to Trash (press Ctrl+Z to undo)',
1873
+ undoHideOk: 'Hidden {n} file(s) (press Ctrl+Z to undo)',
1874
+ undoDeleteDone: 'Undone: {n} file(s) restored ({where} · {kind})',
1875
+ undoDeletePartial: 'Restored {n}; {fail} failed, {conflict} already exist at the original path (not overwritten)',
1876
+ undoDeleteNone: 'Nothing could be restored — this batch may have passed its retention window',
1877
+ undoHideDone: 'Undone: {n} file(s) shown again ({where} · {kind})',
1878
+ undoFailed: 'Undo failed: {message}',
1783
1879
  copyOk: 'Copied {n} file(s) to the clipboard; right-click "Paste" or press Ctrl+V in the target chat',
1784
1880
  copyOkInternal: 'Copied {n} file(s) (system clipboard unavailable; in-plugin paste only)',
1785
1881
  copyFailed: 'Copy failed: {message}',
@@ -2703,6 +2799,23 @@ async function encodeMaskPngBytes(imageData, width, height) {
2703
2799
  white-space: nowrap;
2704
2800
  }
2705
2801
  .dg-groupChips { display: inline-flex; gap: 5px; flex: 0 0 auto; }
2802
+ /**
2803
+ * v1.6.4:组头「共用 N」—— 同一个文件同时被别的对话引用。
2804
+ * 虚线框 + 琥珀色,刻意与分类 chips(绿/橙/灰实心)区分:它不是分类,是归属提示。
2805
+ */
2806
+ .dg-groupShared {
2807
+ flex: 0 0 auto;
2808
+ margin-left: 2px;
2809
+ padding: 1px 6px;
2810
+ border-radius: 9px;
2811
+ border: 1px dashed rgba(208, 139, 22, 0.55);
2812
+ font-size: 10px;
2813
+ font-weight: 600;
2814
+ line-height: 1.6;
2815
+ color: #D08B16;
2816
+ white-space: nowrap;
2817
+ cursor: help;
2818
+ }
2706
2819
  .dg-chip {
2707
2820
  padding: 1px 7px;
2708
2821
  border-radius: 9px;
@@ -2760,6 +2873,15 @@ async function encodeMaskPngBytes(imageData, width, height) {
2760
2873
  .dg-meta { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
2761
2874
  .dg-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2762
2875
  .dg-dim { font-size: 11px; color: var(--dsw-alias-label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2876
+ /* v1.6.3:同一视图里出现同名文件时的「同名 N 份 · 所在目录」提示。
2877
+ 老板 11-25 截图:一组里并排两张「老人手部_GPT25_0.png」,看着像重复,
2878
+ 实际一个是「漫剧手册分析/」、一个是他自己拷的「GPT25备用/」。
2879
+ 只在重名时出现,其余卡片视觉零变化;颜色用琥珀色以示「这不是重复」。 */
2880
+ .dg-dir {
2881
+ font-size: 10px; line-height: 1.2;
2882
+ color: #d08b16;
2883
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
2884
+ }
2763
2885
  .dg-more {
2764
2886
  margin: 12px 0 4px;
2765
2887
  padding: 8px 10px;
@@ -3821,6 +3943,59 @@ async function encodeMaskPngBytes(imageData, width, height) {
3821
3943
  }
3822
3944
  .dg-pasteOk { border-color: rgba(94,214,150,0.6); }
3823
3945
  .dg-pasteFail { border-color: rgba(255,107,107,0.6); color: #ffd2d2; }
3946
+ /* v1.6.0 带按钮的提示(导出清单 / 撤销):有按钮就必须能点,所以这一档放开 pointer-events。 */
3947
+ /* v1.6.2 修「一字一行」:原来这条是 flex 横排,长路径 + word-break:break-all 被压到 1 字符宽,
3948
+ 整条提示竖成一根柱子(老板截图)。改成上下两段:文字占一行(超长省略),按钮在下面一行。 */
3949
+ .dg-pasteNoticeAction {
3950
+ pointer-events: auto; display: flex; flex-direction: column; align-items: stretch; gap: 8px;
3951
+ max-width: 92%; word-break: normal;
3952
+ }
3953
+ .dg-pasteText { flex: 0 0 auto; min-width: 0; word-break: break-word; }
3954
+ .dg-pasteBtns { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; justify-content: center; }
3955
+ .dg-pasteBtn {
3956
+ font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
3957
+ padding: 3px 9px; border-radius: 5px; color: #e8eaed;
3958
+ background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.22);
3959
+ }
3960
+ .dg-pasteBtn:hover { background: rgba(255,255,255,0.18); }
3961
+ .dg-pasteBtn:active { background: rgba(255,255,255,0.26); }
3962
+
3963
+ /* ===== 导出记录面板(v1.6.2) =====
3964
+ 复用设置面板的遮罩与卡片骨架(.dg-settingsLayer / .dg-settings),
3965
+ 这里只把它加宽一点,并把「文件名 / 来源时间条数 / 两个按钮」压成一行。 */
3966
+ .dg-exportPanel { max-width: 560px; }
3967
+ .dg-exportHint {
3968
+ padding: 8px 12px 0; font-size: 11px; line-height: 1.5; opacity: .78;
3969
+ }
3970
+ .dg-exportList {
3971
+ padding: 8px 12px; display: flex; flex-direction: column; gap: 6px;
3972
+ overflow: auto; flex: 1 1 auto; min-height: 0;
3973
+ }
3974
+ .dg-exportRow {
3975
+ display: flex; align-items: center; gap: 8px; padding: 7px 8px;
3976
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px;
3977
+ background: var(--dsw-alias-bg-layer-2);
3978
+ }
3979
+ .dg-exportMain { flex: 1 1 auto; min-width: 0; }
3980
+ .dg-exportName {
3981
+ font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
3982
+ }
3983
+ .dg-exportMeta {
3984
+ font-size: 11px; opacity: .72; margin-top: 2px;
3985
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
3986
+ }
3987
+ .dg-exportMetaGone { color: #ff9b9b; opacity: 1; }
3988
+ .dg-exportActs { display: flex; gap: 6px; flex: 0 0 auto; }
3989
+ .dg-exportEmpty { padding: 20px 4px; text-align: center; font-size: 12px; opacity: .7; }
3990
+ .dg-exportFail { color: #ff9b9b; opacity: 1; }
3991
+ .dg-exportFoot {
3992
+ display: flex; align-items: center; gap: 8px; padding: 8px 12px;
3993
+ border-top: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-2);
3994
+ }
3995
+ .dg-exportDir {
3996
+ flex: 1 1 auto; min-width: 0; font-size: 11px; opacity: .7;
3997
+ white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
3998
+ }
3824
3999
 
3825
4000
  /* v1.0.2 图片裁剪层:绿框 + 八向手柄 + 像素级取色放大镜(照老板给的参考图对齐)
3826
4001
  坐标系说明:裁剪框/放大镜都用 getBoundingClientRect 的**视口坐标**定位,
@@ -6420,8 +6595,128 @@ ${absPath}
6420
6595
  ])
6421
6596
  }
6422
6597
 
6598
+ /**
6599
+ * 同名文件判定(v1.6.3)。
6600
+ *
6601
+ * 老板 11-25 截图:一个对话组里并排两张 `老人手部_GPT25_0.png`,看着就像重复展示。
6602
+ * 实测是两份**真文件**:`漫剧手册分析/` 一份、`退订漫剧/图卡/GPT25备用/` 一份
6603
+ * (后者是他自己拷的备用件),尺寸相同、时间不同。
6604
+ * 卡片原先只显示文件名,两份并排自然分不出 → 这里给「同名 N 份」标出所在目录。
6605
+ *
6606
+ * 只统计**同一视图**内(同组 / 扁平列表)的同名,跨组不参与(跨组共用另有角标语义)。
6607
+ */
6608
+ function countNamesOf(list) {
6609
+ const counts = new Map()
6610
+ for (const it of Array.isArray(list) ? list : []) {
6611
+ const n = it?.name ?? String(it?.relPath ?? '').split('/').pop()
6612
+ if (n === undefined || n === null || n === '') continue
6613
+ counts.set(n, (counts.get(n) ?? 0) + 1)
6614
+ }
6615
+ return counts
6616
+ }
6617
+
6618
+ /**
6619
+ * 跨对话共用索引(v1.6.4)。
6620
+ *
6621
+ * 老板 11-25 定的口径:两个对话引用同一张图是**事实**(两边的日志都精确引用过),
6622
+ * 既不合并、也不去重 —— 但要把「归属」标出来,让人一眼看出这不是重复数据,
6623
+ * 而是同一个文件同时属于两个对话。
6624
+ *
6625
+ * 顺带把删除/隐藏的边界讲清(这是老板拍板的前提):
6626
+ * · 同名但不同路径的两份真文件 → 各自独立,删一份不动另一份;
6627
+ * · 同一路径的共用件 → 本来就是同一个文件,删/隐必然两处一起生效。
6628
+ *
6629
+ * 按 `data` 引用缓存:面板每帧都会问一次,全库几千条重算会拖慢滚轮与拖动。
6630
+ */
6631
+ const SHARE_INDEX_CACHE = new WeakMap()
6632
+
6633
+ function shareIndexOf(data) {
6634
+ const none = { byRel: new Map(), countByGroup: new WeakMap() }
6635
+ if (data === null || typeof data !== 'object') return none
6636
+ const cached = SHARE_INDEX_CACHE.get(data)
6637
+ if (cached !== undefined) return cached
6638
+
6639
+ const groups = Array.isArray(data.groups) ? data.groups : []
6640
+ const byRel = new Map()
6641
+ for (const g of groups) {
6642
+ // 「历史资产」池不是真的对话归属,算进来会把一大堆图误标成共用
6643
+ if (g?.isHistory === true) continue
6644
+ const title = String(g?.title ?? '')
6645
+ for (const f of Array.isArray(g?.files) ? g.files : []) {
6646
+ const rel = String(f?.relPath ?? '')
6647
+ if (rel === '') continue
6648
+ const owners = byRel.get(rel)
6649
+ if (owners === undefined) byRel.set(rel, [title])
6650
+ else if (!owners.includes(title)) owners.push(title)
6651
+ }
6652
+ }
6653
+
6654
+ const countByGroup = new WeakMap()
6655
+ for (const g of groups) {
6656
+ if (g?.isHistory === true) continue
6657
+ let n = 0
6658
+ for (const f of Array.isArray(g?.files) ? g.files : []) {
6659
+ const owners = byRel.get(String(f?.relPath ?? ''))
6660
+ if (Array.isArray(owners) && owners.length > 1) n += 1
6661
+ }
6662
+ if (n > 0) countByGroup.set(g, n)
6663
+ }
6664
+
6665
+ const built = { byRel, countByGroup }
6666
+ SHARE_INDEX_CACHE.set(data, built)
6667
+ return built
6668
+ }
6669
+
6670
+ /** 兜底:后端没给 `sharedPeers` 时,按已加载的组内条目现算共用对象。 */
6671
+ function sharedPeersOf(group, shareInfo) {
6672
+ const selfTitle = String(group?.title ?? '')
6673
+ const out = []
6674
+ for (const f of Array.isArray(group?.files) ? group.files : []) {
6675
+ const owners = shareInfo.byRel.get(String(f?.relPath ?? ''))
6676
+ if (!Array.isArray(owners)) continue
6677
+ for (const title of owners) {
6678
+ if (title !== selfTitle && !out.includes(title)) out.push(title)
6679
+ }
6680
+ }
6681
+ return out
6682
+ }
6683
+
6684
+ /**
6685
+ * 组头「共用 N」的悬停说明。
6686
+ *
6687
+ * 共用对象可能一大串(实测有 85 张图牵扯 27 个对话),全塞进组头会撑爆,
6688
+ * 所以明细放悬停里,最多点 3 个名字,其余折成「等 N 个对话」。
6689
+ * 末尾必须把删除/隐藏的边界讲明 —— 这是老板拍板时问的那一句。
6690
+ */
6691
+ function sharedTipOf(t, n, peers) {
6692
+ const names = (Array.isArray(peers) ? peers : [])
6693
+ .map((s) => String(s ?? '').trim())
6694
+ .filter((s) => s !== '')
6695
+ let who
6696
+ if (names.length === 0) {
6697
+ who = t('sharedWithSome')
6698
+ } else if (names.length <= 3) {
6699
+ who = names.map((s) => `「${s}」`).join('、')
6700
+ } else {
6701
+ who = format(t('sharedWithMany'), {
6702
+ n: names.length,
6703
+ first: names.slice(0, 3).map((s) => `「${s}」`).join('、'),
6704
+ })
6705
+ }
6706
+ return format(t('groupSharedTip'), { n, who })
6707
+ }
6708
+
6709
+ /** 相对路径的所在目录(取尾两段,足够区分同名文件;根目录返回空串)。 */
6710
+ function dirLabelOf(relPath) {
6711
+ const rel = String(relPath ?? '').replace(/\\/g, '/')
6712
+ const cut = rel.lastIndexOf('/')
6713
+ if (cut < 0) return ''
6714
+ const segs = rel.slice(0, cut).split('/').filter((s) => s !== '')
6715
+ return segs.slice(-2).join('/')
6716
+ }
6717
+
6423
6718
  /** 单张缩略图卡片:独立加载、独立失败,互不影响。 */
6424
- function Card({ item, t, onOpen, limiter, onContextMenu, onDoubleClick }) {
6719
+ function Card({ item, t, onOpen, limiter, onContextMenu, onDoubleClick, nameCounts }) {
6425
6720
  const [state, setState] = React.useState({ status: 'pending' })
6426
6721
  const [node, setNode] = React.useState(null)
6427
6722
  // v0.17.0:单击延迟计时器(双击时取消,避免「闪一下大图」)
@@ -6507,6 +6802,12 @@ ${absPath}
6507
6802
  ? format(t('dims'), { w: item.width, h: item.height })
6508
6803
  : t('dimsUnknown')
6509
6804
 
6805
+ // v1.6.3:同名文件 → 显示「同名 N 份 · 所在目录」,让两份真文件一眼可分
6806
+ const sameCount = nameCounts instanceof Map
6807
+ ? (nameCounts.get(item.name) ?? 0)
6808
+ : 0
6809
+ const dirLabel = sameCount > 1 ? dirLabelOf(item.relPath) : ''
6810
+
6510
6811
  return h('button', {
6511
6812
  type: 'button',
6512
6813
  ref: setNode,
@@ -6567,6 +6868,16 @@ ${absPath}
6567
6868
  : t('loading')),
6568
6869
  ),
6569
6870
  h('div', { className: 'dg-meta', key: 'meta' }, [
6871
+ // v1.6.3:同名提醒放在文件名上方,只在重名时出现;目录用琥珀色,
6872
+ // 与「分类角标」的绿/橙/灰错开,避免被误读成又一个分类。
6873
+ sameCount > 1
6874
+ ? h('span', {
6875
+ className: 'dg-dir',
6876
+ key: 'dir',
6877
+ title: `${item.relPath}`,
6878
+ 'data-gallery-same-name': String(sameCount),
6879
+ }, format(t('sameNameIn'), { n: sameCount, dir: dirLabel === '' ? t('rootDir') : dirLabel }))
6880
+ : null,
6570
6881
  h('span', { className: 'dg-name', key: 'name' }, item.name),
6571
6882
  h('span', { className: 'dg-dim', key: 'dim' }, dims),
6572
6883
  h('span', { className: 'dg-dim', key: 'time' }, formatTime(item.mtime)),
@@ -9634,6 +9945,12 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
9634
9945
  const [page, setPage] = React.useState(1)
9635
9946
  // 设置面板开关(改产出根目录)
9636
9947
  const [settingsOpen, setSettingsOpen] = React.useState(false)
9948
+ /**
9949
+ * 导出记录面板(v1.6.2)。
9950
+ * 老板的原话:导出完只有一条几秒就消失的提示,事后想再用这批清单,
9951
+ * 只能自己去 `~\.dsh\gallery-exports\` 里翻,而且多次导出的文件混在一起认不出。
9952
+ * 这里常驻一个入口,列历史清单(来源 / 时间 / 条数),点一下就「写进输入框」。 */
9953
+ const [exportHistoryOpen, setExportHistoryOpen] = React.useState(false)
9637
9954
  // 全局分组:哪些组是展开的(键是 sessionId 或 '__history__')
9638
9955
  const [openGroups, setOpenGroups] = React.useState(new Set())
9639
9956
  // 每组额外取回来的明细(首次只有 60 张,点「再显示」再追加 60 张)。
@@ -10451,9 +10768,82 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10451
10768
  })
10452
10769
  }, [])
10453
10770
 
10771
+ /**
10772
+ * 粘贴/操作提示(成功/失败)。
10773
+ *
10774
+ * v1.6.0:支持带按钮 —— 导出清单后要能「打开文件夹 / 复制路径 / 写进输入框」,
10775
+ * 删除或隐藏后要能点「撤销」。带按钮时停留 6 秒(默认 3 秒),且允许鼠标点。
10776
+ *
10777
+ * 声明位置刻意早于 doHide / doDelete:useCallback 的依赖数组在**渲染时立即求值**,
10778
+ * 引用后面声明的 const 会直接 TDZ 白屏(v0.16.0 踩过)。
10779
+ */
10780
+ const [pasteNotice, setPasteNotice] = React.useState(null)
10781
+ const showPasteNotice = React.useCallback((kindOf, text, actions) => {
10782
+ setPasteNotice({
10783
+ kind: kindOf,
10784
+ text,
10785
+ actions: Array.isArray(actions) && actions.length > 0 ? actions : null,
10786
+ })
10787
+ }, [])
10788
+
10789
+ /**
10790
+ * 撤销栈(Ctrl+Z):只记「还能撤的动作」,最多 10 步,先进后出。
10791
+ *
10792
+ * 用 ref 而不是 state:撤销是「按下快捷键那一刻取最新值」,
10793
+ * 不需要触发重渲染,也不该因为加一条记录就整面板重画。
10794
+ */
10795
+ const undoStackRef = React.useRef([])
10796
+ // 提示条上的「撤销」按钮点下去要走同一个执行器;执行器在下面才声明,
10797
+ // 所以这里留一个 ref 由 effect 回填(别在提示按钮里直接引用后面声明的 const)。
10798
+ const undoRef = React.useRef(null)
10799
+ /**
10800
+ * 撤销「作用域」键:全局资产 / 某个对话 / 各类画廊(图片、文件、音视频)各算一个。
10801
+ *
10802
+ * 2026-11-25(老板报):原来撤销就是一个先进后出的栈,按删除倒序撤,
10803
+ * 跟「现在在看哪个对话」完全无关 —— 在 A 对话里点 Ctrl+Z,可能把 B 对话
10804
+ * 刚删的东西搬回来,看着莫名其妙。现在每批操作记下它发生在哪个视图,
10805
+ * Ctrl+Z 只撤**当前视图**里的那一批;当前视图没有就直说「最近一批在 XX 里」。
10806
+ */
10807
+ const viewKeyOf = React.useCallback(
10808
+ () => `${kind}|${scope}|${scope === 'session' ? String(sessionId ?? '') : ''}`,
10809
+ [kind, scope, sessionId],
10810
+ )
10811
+ /**
10812
+ * 当前对话标题(v1.6.2)。
10813
+ * 老板的原话:撤销提示只写「当前对话」,看不出是哪一段 —— 切了几个对话之后
10814
+ * 根本不知道自己刚撤的是哪一批。这里从 scan 结果的 groups 里取 isCurrent 那组的
10815
+ * title(会话视图只有一个组,取不到 isCurrent 就退到第一个)。
10816
+ */
10817
+ const currentSessionTitleOf = React.useCallback(() => {
10818
+ const groups = Array.isArray(view?.data?.groups) ? view.data.groups : []
10819
+ const hit = groups.find((g) => g?.isCurrent === true) ?? (scope === 'session' ? groups[0] : undefined)
10820
+ return String(hit?.title ?? '').trim()
10821
+ }, [view, scope])
10822
+ const whereOf = React.useCallback(() => {
10823
+ if (scope !== 'session') return t('whereGlobal')
10824
+ const title = currentSessionTitleOf()
10825
+ return title === '' ? t('whereSession') : format(t('whereSessionNamed'), { name: title })
10826
+ }, [scope, t, currentSessionTitleOf])
10827
+ const kindLabelOf = React.useCallback(
10828
+ () => (kind === 'file' ? t('kindFile') : kind === 'media' ? t('kindMedia') : t('kindImage')),
10829
+ [kind, t],
10830
+ )
10831
+ const pushUndo = React.useCallback((entry) => {
10832
+ const stack = undoStackRef.current
10833
+ stack.push({
10834
+ ...entry,
10835
+ at: Date.now(),
10836
+ view: viewKeyOf(),
10837
+ where: whereOf(),
10838
+ kindLabel: kindLabelOf(),
10839
+ })
10840
+ while (stack.length > 20) stack.shift()
10841
+ }, [viewKeyOf, whereOf, kindLabelOf])
10842
+
10454
10843
  /**
10455
10844
  * 隐藏条目(只从列表移除,不动文件)。
10456
10845
  * 2026-11-25:接受单个条目或 relPath 数组;批量隐藏一次写完。
10846
+ * v1.6.0:隐藏可撤销(写进撤销栈 + 提示条带「撤销」按钮)。
10457
10847
  */
10458
10848
  const doHide = React.useCallback(async (target) => {
10459
10849
  const rels = (Array.isArray(target) ? target : [target?.relPath ?? ''])
@@ -10465,11 +10855,16 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10465
10855
  if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
10466
10856
  setSelected(new Set())
10467
10857
  setBatchMode(false)
10858
+ pushUndo({ kind: 'hide', rels })
10859
+ showPasteNotice('ok', format(t('undoHideOk'), { n: rels.length }), [
10860
+ { label: t('undoAction'), onClick: () => { void undoRef.current?.() } },
10861
+ ])
10468
10862
  await load(undefined, kind, scope, page).then((data) => setView({ status: 'ready', data })).catch(() => {})
10469
10863
  } catch (error) {
10470
10864
  console.error('dsh-gallery: 隐藏失败', error)
10865
+ showPasteNotice('fail', t('ctxHideFailed'))
10471
10866
  }
10472
- }, [load, kind, scope, page, t])
10867
+ }, [load, kind, scope, page, t, showPasteNotice, pushUndo])
10473
10868
 
10474
10869
  /** 在资源管理器里定位。 */
10475
10870
  const doReveal = React.useCallback(async (item) => {
@@ -10481,11 +10876,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10481
10876
  }
10482
10877
  }, [t])
10483
10878
 
10484
- /** 粘贴/操作提示(成功/失败),3 秒自动消失。 */
10485
- const [pasteNotice, setPasteNotice] = React.useState(null)
10486
- const showPasteNotice = React.useCallback((kindOf, text) => {
10487
- setPasteNotice({ kind: kindOf, text })
10488
- }, [])
10879
+ /** 粘贴/操作提示(成功/失败)的声明已提前到 doHide 之前(带按钮 + 撤销栈)。 */
10489
10880
 
10490
10881
  /**
10491
10882
  * 执行删除(需二次确认)。
@@ -10502,10 +10893,20 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10502
10893
  try {
10503
10894
  const payload = await callHost('delete', { paths: rels, confirm: true })
10504
10895
  if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
10896
+ const deletedCount = Array.isArray(payload?.deletedPaths) ? payload.deletedPaths.length : 0
10897
+ const undoToken = String(payload?.undoToken ?? '')
10505
10898
  const failed = (Array.isArray(payload?.failed) ? payload.failed.length : 0)
10506
10899
  + (Array.isArray(payload?.notFound) ? payload.notFound.length : 0)
10900
+ const undoActions = undoToken === ''
10901
+ ? null
10902
+ : [{ label: t('undoAction'), onClick: () => { void undoRef.current?.() } }]
10903
+ if (deletedCount > 0 && undoToken !== '') {
10904
+ pushUndo({ kind: 'delete', token: undoToken, count: deletedCount })
10905
+ }
10507
10906
  if (failed > 0) {
10508
- showPasteNotice('fail', format(t('ctxDeletePartial'), { n: rels.length - failed, fail: failed }))
10907
+ showPasteNotice('fail', format(t('ctxDeletePartial'), { n: deletedCount, fail: failed }), undoActions)
10908
+ } else if (deletedCount > 0) {
10909
+ showPasteNotice('ok', format(t('undoDeleteOk'), { n: deletedCount }), undoActions)
10509
10910
  }
10510
10911
  setDeleteTarget(null)
10511
10912
  setSelected(new Set())
@@ -10517,7 +10918,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10517
10918
  setDeleteTarget(null)
10518
10919
  showPasteNotice('fail', t('ctxDeleteFailed'))
10519
10920
  }
10520
- }, [deleteTarget, load, kind, scope, page, t, showPasteNotice])
10921
+ }, [deleteTarget, load, kind, scope, page, t, showPasteNotice, pushUndo])
10521
10922
 
10522
10923
  const refresh = React.useCallback(async () => {
10523
10924
  setRefreshing(true)
@@ -10534,7 +10935,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10534
10935
  // ---- v0.16.0 粘贴:剪贴板图片/文件作为「素材」落当前对话 ----
10535
10936
  React.useEffect(() => {
10536
10937
  if (pasteNotice === null) return undefined
10537
- const timer = setTimeout(() => setPasteNotice(null), 3000)
10938
+ // 带按钮的提示多留一会儿,够手点;纯文字提示 3 秒就够。
10939
+ const timer = setTimeout(() => setPasteNotice(null), pasteNotice.actions === null ? 3000 : 6000)
10538
10940
  return () => clearTimeout(timer)
10539
10941
  }, [pasteNotice])
10540
10942
 
@@ -10807,6 +11209,33 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10807
11209
  }
10808
11210
  }, [callHost, t, showPasteNotice])
10809
11211
 
11212
+ /**
11213
+ * 导出记录(v1.6.2)。
11214
+ *
11215
+ * 老板要的是「事后还能用」:一次导出只弹几秒提示,等于只有当场能引用;
11216
+ * 多次导出后文件名又认不出谁是谁。这里把 host 侧的登记读回来,
11217
+ * 列成一张常驻的表 —— 每条都能重新「写进输入框」,新开对话也能直接接上。
11218
+ */
11219
+ const [exportHistory, setExportHistory] = React.useState({ status: 'idle', items: [], dir: '' })
11220
+ const loadExportHistory = React.useCallback(async () => {
11221
+ setExportHistory((prev) => ({ ...prev, status: 'loading' }))
11222
+ try {
11223
+ const payload = await callHost('exportList', {})
11224
+ if (payload?.ok !== true) throw new Error(payload?.error?.message ?? 'exportList failed')
11225
+ setExportHistory({
11226
+ status: 'ready',
11227
+ dir: String(payload?.dir ?? ''),
11228
+ items: Array.isArray(payload?.items) ? payload.items : [],
11229
+ })
11230
+ } catch (error) {
11231
+ setExportHistory({ status: 'failed', dir: '', items: [], message: String(error?.message ?? error) })
11232
+ }
11233
+ }, [callHost])
11234
+ const openExportHistory = React.useCallback(() => {
11235
+ setExportHistoryOpen(true)
11236
+ void loadExportHistory()
11237
+ }, [loadExportHistory])
11238
+
10810
11239
  /**
10811
11240
  * 导出交付清单(v1.5.0)。
10812
11241
  *
@@ -10820,21 +11249,78 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10820
11249
  .map((p) => String(p ?? '')).filter((p) => p !== ''))]
10821
11250
  if (paths.length === 0) return false
10822
11251
  try {
11252
+ // v1.6.2:把「这批是哪儿导的」一起交给 host ——
11253
+ // 文件名因此变成 `交付清单_<来源>_<时间>_<分类>_<N>张.csv`,导出记录里也有来源。
11254
+ const sourceLabel = scope === 'session'
11255
+ ? (currentSessionTitleOf() || t('whereSession'))
11256
+ : t('whereGlobal')
10823
11257
  const payload = await callHost('exportManifest', {
10824
11258
  relPaths: paths,
10825
11259
  format: 'both',
10826
11260
  includeNotes: true,
11261
+ sourceLabel,
11262
+ sessionTitle: scope === 'session' ? currentSessionTitleOf() : '',
10827
11263
  })
10828
11264
  if (payload?.ok !== true) throw new Error(payload?.error?.message ?? 'exportManifest failed')
10829
11265
  const files = Array.isArray(payload.files) ? payload.files : []
10830
- const head = files.length > 0 ? String(files[0].path ?? '') : String(payload.dir ?? '')
10831
- showPasteNotice('ok', format(t('exportOk'), { n: payload.count ?? paths.length, path: head }))
11266
+ // 主路径给 CSV(Excel 直接能开);JSON 落在同名 .json,路径只差扩展名。
11267
+ const csvFile = files.find((f) => String(f?.path ?? '').toLowerCase().endsWith('.csv')) ?? files[0]
11268
+ const head = String(csvFile?.path ?? '') || String(payload.dir ?? '')
11269
+ const count = Number(payload.count) || paths.length
11270
+ // v1.6.2:提示里只报文件名。以前整条绝对路径塞进去,窄面板下被压成一字一行。
11271
+ const baseName = String(payload?.base ?? '')
11272
+ const fileName = baseName !== ''
11273
+ ? `${baseName}.csv`
11274
+ : (String(csvFile?.path ?? '').split(/[\\/]/).pop() ?? '')
11275
+ /**
11276
+ * v1.6.0:落盘地址不再只躺着给人看,三个按钮各管一件事 ——
11277
+ * · 打开文件夹:系统文件管理器打开导出目录(Host 只认这一个目录,不收任意路径);
11278
+ * · 复制路径:粘到别处 / 发给别人;
11279
+ * · 写进输入框:把路径递给助手,下一轮直接读这份清单。
11280
+ * v1.6.2:再加「导出记录」—— 提示几秒就消失,得留个能翻旧账的入口。
11281
+ */
11282
+ showPasteNotice('ok', format(t('exportOk'), { n: count, name: fileName }), [
11283
+ {
11284
+ label: t('exportHistoryOpen'),
11285
+ onClick: () => { openExportHistory() },
11286
+ },
11287
+ {
11288
+ label: t('exportOpenDir'),
11289
+ onClick: () => {
11290
+ void callHost('openExportDir', {}).then((r) => {
11291
+ if (r?.ok === false) throw new Error(r?.error?.message ?? t('exportOpenFailed'))
11292
+ }).catch((error) => {
11293
+ showPasteNotice('fail', format(t('exportOpenFailed'), { message: String(error?.message ?? error) }))
11294
+ })
11295
+ },
11296
+ },
11297
+ {
11298
+ label: t('exportCopyPath'),
11299
+ onClick: () => {
11300
+ void copyText(head).then((ok) => {
11301
+ showPasteNotice(ok ? 'ok' : 'fail', ok ? t('exportPathCopied') : t('exportPathCopyFailed'))
11302
+ })
11303
+ },
11304
+ },
11305
+ {
11306
+ label: t('exportToComposer'),
11307
+ onClick: () => {
11308
+ void writeDraftToComposer(`交付清单(${count} 条):${head}`, sessionId).then((result) => {
11309
+ if (result?.ok === true) showPasteNotice('ok', t('exportDraftReady'))
11310
+ else { void copyText(head); showPasteNotice('fail', t('exportDraftInClipboard')) }
11311
+ }).catch(() => {
11312
+ void copyText(head)
11313
+ showPasteNotice('fail', t('exportDraftInClipboard'))
11314
+ })
11315
+ },
11316
+ },
11317
+ ])
10832
11318
  return true
10833
11319
  } catch (error) {
10834
11320
  showPasteNotice('fail', format(t('exportFailed'), { message: String(error?.message ?? error) }))
10835
11321
  return false
10836
11322
  }
10837
- }, [callHost, t, showPasteNotice])
11323
+ }, [callHost, t, showPasteNotice, sessionId, scope, currentSessionTitleOf, openExportHistory])
10838
11324
 
10839
11325
  React.useEffect(() => {
10840
11326
  let alive = true
@@ -10902,14 +11388,30 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10902
11388
  if (!canPartial) { void refresh(); return }
10903
11389
 
10904
11390
  // 逐个组重取明细
11391
+ //
11392
+ // 🔴 2026-11-25 修(老板实测「全局里其他对话资产显示不全」):
11393
+ // 旧调用只传了 { kind, scope, sessionId, page },**没传 groupKey**,
11394
+ // 服务端按 groupKey 找不到组,直接回 { ok:true, files:[] };
11395
+ // 前端拿到空数组后把整组 files 覆盖成空 —— 那一组就只剩几条纹丝不动的旧卡。
11396
+ // 同时 limit 被 clamp 到 60,大组重取也会被截断。
11397
+ // 现在:带 groupKey、要全量;空返回但声称有内容时不信它,整表重来。
10905
11398
  const fresh = new Map()
10906
11399
  let needFull = false
10907
11400
  for (const c of changed) {
10908
11401
  const sid = String(c?.sessionId ?? '')
10909
11402
  if (sid === '') { needFull = true; break }
10910
11403
  try {
10911
- const p = await callHost('groupMore', { kind, scope, sessionId: sid, page: 1 })
11404
+ const p = await callHost('groupMore', {
11405
+ kind,
11406
+ scope: 'global',
11407
+ sessionId: sid,
11408
+ groupKey: sid,
11409
+ offset: 0,
11410
+ limit: 5000,
11411
+ })
10912
11412
  if (p?.ok === false) { needFull = true; break }
11413
+ const got = Array.isArray(p?.files) ? p.files : []
11414
+ if (got.length === 0 && Number(p?.total) > 0) { needFull = true; break }
10913
11415
  fresh.set(sid, p)
10914
11416
  } catch { needFull = true; break }
10915
11417
  }
@@ -10928,10 +11430,20 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10928
11430
  const files = Array.isArray(p?.files) ? p.files
10929
11431
  : (Array.isArray(p?.items) ? p.items : null)
10930
11432
  if (files === null) { sawUnknownGroup = true; continue }
11433
+ // 原本有内容却回空:不信它,整表重来。少画几张顶多刷新一下,
11434
+ // 把整组抹掉才是真事故(老板报过「其他对话资产显示不全」)。
11435
+ if (files.length === 0 && Number(nextGroups[idx].fileCount) > 0) {
11436
+ sawUnknownGroup = true
11437
+ continue
11438
+ }
10931
11439
  nextGroups[idx] = {
10932
11440
  ...nextGroups[idx],
10933
11441
  files,
10934
- fileCount: typeof p.fileCount === 'number' ? p.fileCount : nextGroups[idx].fileCount,
11442
+ // groupMore 回的是 total 而不是 fileCount,这里两个都认:
11443
+ // 只认 fileCount 会一直沿用旧值,「再显示」按钮的判据就飘了。
11444
+ fileCount: typeof p.fileCount === 'number'
11445
+ ? p.fileCount
11446
+ : (Number(p.total) || files.length),
10935
11447
  returnedCount: files.length,
10936
11448
  counts: p.counts ?? nextGroups[idx].counts,
10937
11449
  latestMtime: p.latestMtime ?? nextGroups[idx].latestMtime,
@@ -10965,6 +11477,92 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
10965
11477
  if (typeof fn === 'function') fn()
10966
11478
  }, [])
10967
11479
 
11480
+ /**
11481
+ * 撤销最近一步(Ctrl+Z 与提示条上的「撤销」按钮共用这一条路)。
11482
+ *
11483
+ * 只认两类动作:删除(把这一批从回收区搬回原位)、隐藏(取消隐藏)。
11484
+ * 每撤一步就弹掉栈里一条;栈空时明确说一句「没有可撤销的操作」,
11485
+ * 不静默无反应 —— 否则人会以为快捷键没生效。
11486
+ */
11487
+ const runUndo = React.useCallback(async () => {
11488
+ const stack = undoStackRef.current
11489
+ const key = viewKeyOf()
11490
+ // 只撤「当前视图」里的那一批;跨视图不撤,避免把人别处删的东西搬回来
11491
+ let idx = -1
11492
+ for (let i = stack.length - 1; i >= 0; i -= 1) {
11493
+ if (stack[i].view === key) { idx = i; break }
11494
+ }
11495
+ if (idx < 0) {
11496
+ const last = stack[stack.length - 1]
11497
+ if (last === undefined) {
11498
+ showPasteNotice('fail', t('undoNothing'))
11499
+ } else {
11500
+ showPasteNotice('fail', format(t('undoOtherScope'), {
11501
+ where: String(last.where ?? ''), kind: String(last.kindLabel ?? ''),
11502
+ }))
11503
+ }
11504
+ return
11505
+ }
11506
+ const [entry] = stack.splice(idx, 1)
11507
+ try {
11508
+ if (entry.kind === 'delete') {
11509
+ const payload = await callHost('undoDelete', { token: entry.token })
11510
+ if (payload?.ok === false && (payload?.restored ?? 0) === 0
11511
+ && !Array.isArray(payload?.conflicts) && !Array.isArray(payload?.failed)) {
11512
+ throw new Error(payload?.error?.message ?? t('undoDeleteNone'))
11513
+ }
11514
+ const restored = Number(payload?.restored) || 0
11515
+ const conflicts = Array.isArray(payload?.conflicts) ? payload.conflicts.length : 0
11516
+ const failedCount = Array.isArray(payload?.failed) ? payload.failed.length : 0
11517
+ if (restored === 0) {
11518
+ showPasteNotice('fail', t('undoDeleteNone'))
11519
+ } else if (conflicts > 0 || failedCount > 0) {
11520
+ showPasteNotice('fail', format(t('undoDeletePartial'), {
11521
+ n: restored, fail: failedCount, conflict: conflicts,
11522
+ }))
11523
+ } else {
11524
+ showPasteNotice('ok', format(t('undoDeleteDone'), {
11525
+ n: restored, where: String(entry.where ?? ''), kind: String(entry.kindLabel ?? ''),
11526
+ }))
11527
+ }
11528
+ } else if (entry.kind === 'hide') {
11529
+ const rels = Array.isArray(entry.rels) ? entry.rels : []
11530
+ const payload = await callHost('unhide', { paths: rels })
11531
+ if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('ctxHideFailed'))
11532
+ showPasteNotice('ok', format(t('undoHideDone'), {
11533
+ n: rels.length, where: String(entry.where ?? ''), kind: String(entry.kindLabel ?? ''),
11534
+ }))
11535
+ }
11536
+ kickChanges()
11537
+ await load(undefined, kind, scope, page)
11538
+ .then((data) => setView({ status: 'ready', data }))
11539
+ .catch(() => { /* 刷新失败保持当前列表,撤销本身已生效 */ })
11540
+ } catch (error) {
11541
+ showPasteNotice('fail', format(t('undoFailed'), { message: String(error?.message ?? error) }))
11542
+ }
11543
+ }, [callHost, load, kind, scope, page, t, showPasteNotice, kickChanges, viewKeyOf])
11544
+
11545
+ React.useEffect(() => { undoRef.current = runUndo }, [runUndo])
11546
+
11547
+ /**
11548
+ * Ctrl+Z / Cmd+Z:撤销最近一次删除或隐藏。
11549
+ *
11550
+ * 光标在输入框里一律放行 —— 那里要撤的是人自己打的字。
11551
+ * Ctrl+Shift+Z 也不拦(留给「重做」,本版没做,别占着坑还不干活)。
11552
+ */
11553
+ React.useEffect(() => {
11554
+ const onKey = (event) => {
11555
+ if (!(event.ctrlKey || event.metaKey)) return
11556
+ if (event.shiftKey || event.altKey) return
11557
+ if (String(event.key).toLowerCase() !== 'z') return
11558
+ if (isTypingTarget(event.target)) return
11559
+ event.preventDefault()
11560
+ void runUndo()
11561
+ }
11562
+ window.addEventListener('keydown', onKey)
11563
+ return () => window.removeEventListener('keydown', onKey)
11564
+ }, [runUndo])
11565
+
10968
11566
  // 兜底自动刷新:轮询已覆盖绝大部分,这里放长周期防漏(外部程序写入 fs.watch 漏报时)
10969
11567
  React.useEffect(() => {
10970
11568
  if (viewer !== null) return undefined
@@ -11124,6 +11722,17 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11124
11722
  onClick: () => setSettingsOpen(true),
11125
11723
  }, '⚙')
11126
11724
 
11725
+ // 导出记录入口(v1.6.2):常驻在标题栏,不依赖「有没有选中」——
11726
+ // 老板要的就是隔天/换个对话还能把上次导的清单拎出来用。
11727
+ const exportHistoryBtn = h('button', {
11728
+ type: 'button',
11729
+ key: 'exportHistory',
11730
+ className: 'dg-btn dg-btnIcon',
11731
+ 'data-gallery-export-history': true,
11732
+ title: t('exportHistoryHint'),
11733
+ onClick: () => { openExportHistory() },
11734
+ }, '\u{1F4C1}')
11735
+
11127
11736
  const header = h('div', { className: 'dg-header', key: 'header' }, [
11128
11737
  h('div', { className: 'dg-headerInfo', key: 'info' }, [
11129
11738
  h('span', { className: 'dg-title', key: 'title' },
@@ -11172,6 +11781,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11172
11781
  return !v
11173
11782
  }),
11174
11783
  }, batchMode ? t('batchModeExit') : t('batchModeEnter')),
11784
+ exportHistoryBtn,
11175
11785
  settingsBtn,
11176
11786
  h('button', {
11177
11787
  type: 'button',
@@ -11840,13 +12450,16 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11840
12450
 
11841
12451
  if (useGroups) {
11842
12452
 
11843
- const cardFor = (item, groupKey, listForViewer, groupMeta) => {
12453
+ const cardFor = (item, groupKey, listForViewer, groupMeta, nameCounts) => {
11844
12454
  // 分组里的文件也走同一套卡片组件
11845
12455
  const enriched = {
11846
12456
  ...item,
11847
12457
  name: item.name ?? item.relPath.split('/').pop(),
11848
12458
  extension: item.extension ?? ('.' + (item.relPath.split('.').pop() || '')),
11849
12459
  }
12460
+ // v1.6.3:同名统计由调用方算一次传进来(这里不再逐卡重算 O(n),
12461
+ // 「再显示」把一组堆到上千张时逐卡重算会明显卡顿)。
12462
+ const sameNames = nameCounts instanceof Map ? nameCounts : countNamesOf(listForViewer)
11850
12463
  // 音视频分组视图:必须走 MediaCard,否则会被当成图片卡片渲染(v0.10.1)
11851
12464
  if (kind === 'media') {
11852
12465
  return wrapCard(h(MediaCard, {
@@ -11900,6 +12513,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11900
12513
  item: enriched,
11901
12514
  t,
11902
12515
  limiter: limiter.current,
12516
+ nameCounts: sameNames,
11903
12517
  onContextMenu: openContextMenu,
11904
12518
  // v0.17.0:双击写进输入框
11905
12519
  onDoubleClick: (target, event) => { handleCardDoubleClick(target, event) },
@@ -11922,6 +12536,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11922
12536
  // 左侧会话列表快照只取一次:宿主渐进渲染,折叠行不在 DOM,
11923
12537
  // 因此按「ID + 归一化标题」双重判定,而不是逐组查行是否存在。
11924
12538
  const sidebarSnapshot = readSidebarSessions()
12539
+ // v1.6.4:共用归属索引(整块只建一次;后端给了 sharedCount 时只作兜底)
12540
+ const shareInfo = shareIndexOf(data)
11925
12541
  const groupNodes = data.groups.map((group, gi) => {
11926
12542
  const groupKey = group.sessionId ?? '__history__'
11927
12543
  const isOpen = openGroups.has(groupKey)
@@ -11933,6 +12549,16 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11933
12549
  const allFiles = [...(Array.isArray(group.files) ? group.files : []), ...extra]
11934
12550
  const visibleFiles = allFiles.filter(
11935
12551
  (f) => categoryFilter[bucketOf(f)] !== false)
12552
+ // v1.6.3:本组同名表(每组算一次)
12553
+ const groupNameCounts = countNamesOf(visibleFiles)
12554
+ // v1.6.4:跨对话共用。后端按**全量**算好(前端每组只拿 60 条,自己数会偏小);
12555
+ // 旧版后端没有这个字段时,退回前端按已加载条目录算。
12556
+ const sharedCount = typeof group.sharedCount === 'number'
12557
+ ? group.sharedCount
12558
+ : (shareInfo.countByGroup.get(group) ?? 0)
12559
+ const sharedPeers = Array.isArray(group.sharedPeers)
12560
+ ? group.sharedPeers
12561
+ : sharedPeersOf(group, shareInfo)
11936
12562
 
11937
12563
  const chips = []
11938
12564
  if (group.counts.final > 0) {
@@ -11996,6 +12622,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
11996
12622
  h('span', { className: 'dg-groupDate', key: 'd' },
11997
12623
  group.isHistory ? format(t('groupFiles'), { n: group.fileCount }) : formatTime(group.createdAt)),
11998
12624
  h('span', { className: 'dg-groupChips', key: 'c' }, chips),
12625
+ // v1.6.4:共用归属标注 —— 只在真有共用件时出现,「历史资产」池不标
12626
+ sharedCount > 0 && group.isHistory !== true
12627
+ ? h('span', {
12628
+ className: 'dg-groupShared',
12629
+ key: 'sh',
12630
+ 'data-gallery-group-shared': String(sharedCount),
12631
+ title: sharedTipOf(t, sharedCount, sharedPeers),
12632
+ }, format(t('groupShared'), { n: sharedCount }))
12633
+ : null,
11999
12634
  ]),
12000
12635
  isOpen
12001
12636
  ? [
@@ -12016,7 +12651,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12016
12651
  h('div', { className: 'dg-groupBody', key: 'body' }, [
12017
12652
  visibleFiles.length > 0
12018
12653
  ? h('div', { className: `dg-grid${kind === 'file' ? ' dg-fileGrid' : ''}`, key: 'grid' },
12019
- visibleFiles.map((f) => cardFor(f, headKey, visibleFiles, group)))
12654
+ visibleFiles.map((f) => cardFor(f, headKey, visibleFiles, group, groupNameCounts)))
12020
12655
  : h('div', { className: 'dg-groupEmpty', key: 'empty' }, t('groupEmpty')),
12021
12656
  allFiles.length < Number(group.fileCount ?? 0)
12022
12657
  ? h('button', {
@@ -12108,6 +12743,9 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12108
12743
  onContextMenu: openContextMenu,
12109
12744
  }), item, item.relPath))
12110
12745
 
12746
+ // v1.6.3:扁平视图(当前对话)也按同一份同名表标注目录,
12747
+ // 否则「图片」视图会与分组视图两套口径(分组有提示、扁平没有)。
12748
+ const flatNameCounts = countNamesOf(visibleItems)
12111
12749
  const gridChildren = visibleItems.map((item) => wrapCard(kind === 'file'
12112
12750
  ? h(FileCard, {
12113
12751
  key: item.relPath,
@@ -12138,6 +12776,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12138
12776
  item,
12139
12777
  t,
12140
12778
  limiter: limiter.current,
12779
+ nameCounts: flatNameCounts,
12141
12780
  onContextMenu: openContextMenu,
12142
12781
  // v0.17.0:双击写进输入框(扁平视图)
12143
12782
  onDoubleClick: (target, event) => { handleCardDoubleClick(target, event) },
@@ -12318,6 +12957,103 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12318
12957
  })
12319
12958
  : null
12320
12959
 
12960
+ /**
12961
+ * 导出记录面板(v1.6.2)。
12962
+ * 列表只做三件事:说清「这批是哪来的、什么时候、多少条」,并允许再引用一次。
12963
+ * 每条的「写进输入框」把 CSV 绝对路径递给助手 —— 这是老板要的「以后还能用」。
12964
+ */
12965
+ const exportRowAction = (label, onClick, disabled) => h('button', {
12966
+ type: 'button',
12967
+ className: 'dg-btn dg-btnSmall',
12968
+ key: `act-${label}`,
12969
+ disabled: disabled === true,
12970
+ onClick,
12971
+ }, label)
12972
+ const exportRows = exportHistory.status === 'failed'
12973
+ ? [h('div', { className: 'dg-exportEmpty dg-exportFail', key: 'failed' },
12974
+ format(t('exportHistoryFailed'), { message: String(exportHistory.message ?? '') }))]
12975
+ : exportHistory.items.length === 0
12976
+ ? [h('div', { className: 'dg-exportEmpty', key: 'empty' },
12977
+ exportHistory.status === 'loading' ? t('exportHistoryLoading') : t('exportHistoryEmpty'))]
12978
+ : exportHistory.items.map((row, index) => {
12979
+ const file = String(row?.file ?? '')
12980
+ if (file === '') return null
12981
+ const full = exportHistory.dir === '' ? file : `${exportHistory.dir}\\${file}`
12982
+ const exists = row?.exists !== false
12983
+ const at = Number(row?.at) || 0
12984
+ const total = Number(row?.total)
12985
+ const src = String(row?.sessionTitle ?? '') !== ''
12986
+ ? String(row.sessionTitle)
12987
+ : (row?.scope === 'global'
12988
+ ? t('exportHistoryGlobal')
12989
+ : (row?.legacy === true ? t('exportHistoryLegacy') : t('exportHistoryUnknownSource')))
12990
+ const meta = [
12991
+ src,
12992
+ at > 0 ? formatTime(at) : '',
12993
+ Number.isFinite(total) && total > 0 ? format(t('exportHistoryCount'), { n: total }) : '',
12994
+ exists ? '' : t('exportHistoryMissing'),
12995
+ ].filter((x) => x !== '').join(' · ')
12996
+ return h('div', { className: 'dg-exportRow', key: `export${index}`, 'data-gallery-export-row': index }, [
12997
+ h('div', { className: 'dg-exportMain', key: 'main' }, [
12998
+ h('div', { className: 'dg-exportName', key: 'name', title: file }, file),
12999
+ h('div', { className: `dg-exportMeta${exists ? '' : ' dg-exportMetaGone'}`, key: 'meta' }, meta),
13000
+ ]),
13001
+ h('div', { className: 'dg-exportActs', key: 'acts' }, [
13002
+ exportRowAction(t('exportToComposer'), () => {
13003
+ void writeDraftToComposer(`交付清单${Number.isFinite(total) && total > 0 ? `(${total} 条)` : ''}:${full}`, sessionId)
13004
+ .then((result) => {
13005
+ if (result?.ok === true) showPasteNotice('ok', t('exportDraftReady'))
13006
+ else { void copyText(full); showPasteNotice('fail', t('exportDraftInClipboard')) }
13007
+ })
13008
+ .catch(() => {
13009
+ void copyText(full)
13010
+ showPasteNotice('fail', t('exportDraftInClipboard'))
13011
+ })
13012
+ }, !exists),
13013
+ exportRowAction(t('exportCopyPath'), () => {
13014
+ void copyText(full).then((ok) => {
13015
+ showPasteNotice(ok ? 'ok' : 'fail', ok ? t('exportPathCopied') : t('exportPathCopyFailed'))
13016
+ })
13017
+ }, !exists),
13018
+ ]),
13019
+ ])
13020
+ }).filter((node) => node !== null)
13021
+
13022
+ const exportHistoryLayer = exportHistoryOpen
13023
+ ? h('div', { className: 'dg-settingsLayer', key: 'exportHistoryLayer' }, [
13024
+ h('div', { className: 'dg-settings dg-exportPanel', 'data-gallery-export-panel': true }, [
13025
+ h('div', { className: 'dg-settingsHead', key: 'head' }, [
13026
+ h('span', { className: 'dg-settingsTitle', key: 'title' }, t('exportHistoryTitle')),
13027
+ h('button', {
13028
+ type: 'button', className: 'dg-btn dg-btnSmall', key: 'refresh',
13029
+ 'data-gallery-export-refresh': true,
13030
+ onClick: () => { void loadExportHistory() },
13031
+ }, t('exportHistoryRefresh')),
13032
+ h('button', {
13033
+ type: 'button', className: 'dg-btn dg-btnSmall', key: 'close',
13034
+ 'data-gallery-export-close': true,
13035
+ onClick: () => setExportHistoryOpen(false),
13036
+ }, '✕'),
13037
+ ]),
13038
+ h('div', { className: 'dg-exportHint', key: 'hint' }, t('exportHistoryHint')),
13039
+ h('div', { className: 'dg-exportList', key: 'list' }, exportRows),
13040
+ h('div', { className: 'dg-exportFoot', key: 'foot' }, [
13041
+ h('span', { className: 'dg-exportDir', key: 'dir', title: exportHistory.dir }, exportHistory.dir),
13042
+ h('button', {
13043
+ type: 'button', className: 'dg-btn dg-btnSmall', key: 'open',
13044
+ onClick: () => {
13045
+ void callHost('openExportDir', {}).then((r) => {
13046
+ if (r?.ok === false) throw new Error(r?.error?.message ?? t('exportOpenFailed'))
13047
+ }).catch((error) => {
13048
+ showPasteNotice('fail', format(t('exportOpenFailed'), { message: String(error?.message ?? error) }))
13049
+ })
13050
+ },
13051
+ }, t('exportOpenDir')),
13052
+ ]),
13053
+ ]),
13054
+ ])
13055
+ : null
13056
+
12321
13057
  // 反馈篮(S3-a):列出已标记条目 + 带批注的卡片(v0.14.3 批注并入反馈)
12322
13058
  // 批注属于「反馈」这一侧:它不进 marks(不参与表态/筛选/落盘),
12323
13059
  // 但只要有批注,这张卡就出现在反馈篮里,草稿会按 Annotation N 逐条带出说明与框选区域。
@@ -12568,6 +13304,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12568
13304
  viewerLayer,
12569
13305
  mediaLayer,
12570
13306
  settingsLayer,
13307
+ exportHistoryLayer,
12571
13308
  ctxLayer,
12572
13309
  pasteLayer,
12573
13310
  confirmLayer,
@@ -12578,10 +13315,29 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
12578
13315
  ? null
12579
13316
  : h('div', {
12580
13317
  className: 'dg-pasteNotice'
12581
- + (pasteNotice.kind === 'ok' ? ' dg-pasteOk' : ' dg-pasteFail'),
13318
+ + (pasteNotice.kind === 'ok' ? ' dg-pasteOk' : ' dg-pasteFail')
13319
+ + (pasteNotice.actions === null ? '' : ' dg-pasteNoticeAction'),
12582
13320
  key: 'pasteNotice',
12583
13321
  'data-gallery-paste-notice': pasteNotice.kind,
12584
- }, pasteNotice.text),
13322
+ }, [
13323
+ h('span', { className: 'dg-pasteText', key: 'text' }, pasteNotice.text),
13324
+ pasteNotice.actions === null
13325
+ ? null
13326
+ : h('span', { className: 'dg-pasteBtns', key: 'btns' },
13327
+ pasteNotice.actions.map((action, index) => h('button', {
13328
+ type: 'button',
13329
+ className: 'dg-pasteBtn',
13330
+ key: `a${index}`,
13331
+ 'data-gallery-paste-action': index,
13332
+ // 按下就 preventDefault:别让按钮抢走焦点,也别触发网格的键盘处理
13333
+ onMouseDown: (event) => event.preventDefault(),
13334
+ onClick: () => {
13335
+ // 先收掉提示,再执行;执行完自己会给新提示(或不需要)
13336
+ setPasteNotice(null)
13337
+ try { action.onClick?.() } catch (error) { console.warn('dsh-gallery: 提示按钮失败', error) }
13338
+ },
13339
+ }, action.label))),
13340
+ ]),
12585
13341
  ])
12586
13342
  }
12587
13343