dsh-gallery 0.12.1 → 0.13.7
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/CHANGELOG.md +603 -0
- package/README.md +122 -13
- package/client.js +1736 -33
- package/host/feedback-text.js +193 -0
- package/host/http.js +312 -103
- package/host/marks.js +136 -0
- package/host/settings.js +3 -1
- package/package.json +9 -3
package/client.js
CHANGED
|
@@ -109,6 +109,37 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
109
109
|
catLegendInput: '输入素材',
|
|
110
110
|
catLegendIntermediate: '中间产物',
|
|
111
111
|
catLegendUnknown: '未归类',
|
|
112
|
+
catFilterFinalConfirmed: '最终交付·已确认',
|
|
113
|
+
catFilterFinalPending: '最终交付·待确认',
|
|
114
|
+
filterShowHint: '点击显示「{label}」',
|
|
115
|
+
filterHideHint: '点击隐藏「{label}」',
|
|
116
|
+
confirmBadgeLabel: '已确认',
|
|
117
|
+
confirmBadgeHint: '这张已定为最终版(判断已锁住,刷新/重启都保留)',
|
|
118
|
+
batchSelect: '选中以批量处理',
|
|
119
|
+
batchUnselect: '取消选中',
|
|
120
|
+
batchBarTitle: '已选 {n} 个',
|
|
121
|
+
batchConfirm: '确认',
|
|
122
|
+
batchUnconfirm: '取消确认',
|
|
123
|
+
batchClearMark: '清除标记',
|
|
124
|
+
batchClearSelection: '取消选择',
|
|
125
|
+
batchHintConfirm: '把选中卡片标为「已确认」(只改标记,不碰文件)',
|
|
126
|
+
batchHintClearMark: '清掉选中卡片的标记(只改标记,不碰文件)',
|
|
127
|
+
discardEntry: '清掉废稿({n})',
|
|
128
|
+
discardEntryHint: '删除所有标过「不要这张」的文件 —— 永久删除,不进回收站',
|
|
129
|
+
discardDialogTitle: '确认删除废稿',
|
|
130
|
+
discardDialogWarn: '以下文件将被永久删除,不进回收站,删除后无法恢复。',
|
|
131
|
+
discardDialogCount: '共 {n} 个文件',
|
|
132
|
+
discardDialogTooMany: '单批最多 10 个,当前 {n} 个。请分批处理。',
|
|
133
|
+
discardDialogConfirm: '永久删除这 {n} 个文件',
|
|
134
|
+
discardDialogCancel: '取消',
|
|
135
|
+
discardDialogDeleting: '正在删除…',
|
|
136
|
+
discardDone: '已永久删除 {n} 个文件',
|
|
137
|
+
discardFailed: '删除失败:{msg}',
|
|
138
|
+
discardDigestMismatch: '文件清单已变化,请重新确认',
|
|
139
|
+
scanModeEnter: '批量选择',
|
|
140
|
+
scanModeExit: '退出批量',
|
|
141
|
+
shownOfTotal: '已显示 {shown} / 共 {total}',
|
|
142
|
+
|
|
112
143
|
catLegendHint: '边框颜色代表资产类型;「未归类」是会话记录里查不到归属的历史文件',
|
|
113
144
|
// ===== 全局按对话分组 =====
|
|
114
145
|
groupCount: '{count} 个',
|
|
@@ -188,6 +219,44 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
188
219
|
mediaOpenExternal: '用系统播放器打开',
|
|
189
220
|
mediaBlobSeekHint: '载入完成后可拖动进度条(宿主转发时丢了 Content-Length,直链无法 seek)',
|
|
190
221
|
mediaOpenFolder: '打开所在文件夹',
|
|
222
|
+
ctxMarkSection: '标记(进反馈篮)',
|
|
223
|
+
ctxMarkApprove: '通过',
|
|
224
|
+
ctxMarkReject: '不要这张',
|
|
225
|
+
ctxMarkFinalize: '定为最终版',
|
|
226
|
+
ctxMarkUnconfirm: '取消确认',
|
|
227
|
+
ctxMarkRedo: '单维重做',
|
|
228
|
+
ctxMarkRegen: '选择性重生成',
|
|
229
|
+
ctxMarkReference: '设为参照',
|
|
230
|
+
feedbackTargetCurrent: '当前对话',
|
|
231
|
+
feedbackBasketTitle: '反馈篮',
|
|
232
|
+
feedbackBlockedForeign: '含其他会话条目,无法生成',
|
|
233
|
+
feedbackBlockedEmpty: '还没有标记',
|
|
234
|
+
feedbackBasketToggle: '反馈篮',
|
|
235
|
+
feedbackBasketToggleN: '反馈篮 · {n} 条',
|
|
236
|
+
feedbackBasketToggleHint: '打开/关闭反馈篮,可在此生成决策草稿',
|
|
237
|
+
feedbackBasketTitleN: '反馈篮 · {n} 条',
|
|
238
|
+
feedbackBasketEmpty: '还没有标记任何条目。在卡片上右键选择动作即可加入。',
|
|
239
|
+
feedbackTargetSession: '将发往会话:{title}',
|
|
240
|
+
feedbackForeignWarn: '有 {n} 条来自其他会话,不能一起提交(请先切到那个会话)。',
|
|
241
|
+
feedbackForeignWarnShort: '含其他会话的条目,已禁用提交',
|
|
242
|
+
feedbackEdit: '编辑',
|
|
243
|
+
feedbackEditTitle: '编辑:{name}',
|
|
244
|
+
feedbackReasonLabel: '理由(可选)',
|
|
245
|
+
feedbackChangeOnlyLabel: '只改(逗号分隔,可选)',
|
|
246
|
+
feedbackKeepLabel: '锁死不动(逗号分隔,可选)',
|
|
247
|
+
feedbackEditSave: '保存',
|
|
248
|
+
feedbackClear: '清空',
|
|
249
|
+
feedbackGenerateDraft: '生成决策草稿',
|
|
250
|
+
feedbackGenerating: '正在生成…',
|
|
251
|
+
feedbackGenerateHint: '生成草稿并写入输入框,由你确认后手动发送',
|
|
252
|
+
feedbackDraftReady: '草稿已写入输入框(未发送)。确认无误请自行发送。',
|
|
253
|
+
feedbackDraftInClipboard: '草稿已复制到剪贴板(输入框通道不可用),请手动粘贴。',
|
|
254
|
+
feedbackDraftFailed: '生成草稿失败',
|
|
255
|
+
feedbackChangeOnly: '只改',
|
|
256
|
+
feedbackReasonPlaceholder: '为什么(可选)',
|
|
257
|
+
feedbackChangePlaceholder: '只改哪些(逗号分隔,可选)',
|
|
258
|
+
feedbackKeepPlaceholder: '哪些锁死(逗号分隔,可选)',
|
|
259
|
+
feedbackMarked: '已标记',
|
|
191
260
|
mediaOpenFolderHint: '在资源管理器里选中该文件',
|
|
192
261
|
mediaOpenFailed: '打开失败:{message}',
|
|
193
262
|
mediaOpenOk: '已交给系统处理',
|
|
@@ -275,6 +344,37 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
275
344
|
catLegendInput: 'Input material',
|
|
276
345
|
catLegendIntermediate: 'Interim product',
|
|
277
346
|
catLegendUnknown: 'Unclassified',
|
|
347
|
+
catFilterFinalConfirmed: 'Final · confirmed',
|
|
348
|
+
catFilterFinalPending: 'Final · pending',
|
|
349
|
+
filterShowHint: 'Click to show "{label}"',
|
|
350
|
+
filterHideHint: 'Click to hide "{label}"',
|
|
351
|
+
confirmBadgeLabel: 'Confirmed',
|
|
352
|
+
confirmBadgeHint: 'Marked as final (the decision is persisted across refresh and restart)',
|
|
353
|
+
batchSelect: 'Select for batch actions',
|
|
354
|
+
batchUnselect: 'Deselect',
|
|
355
|
+
batchBarTitle: '{n} selected',
|
|
356
|
+
batchConfirm: 'Confirm',
|
|
357
|
+
batchUnconfirm: 'Unconfirm',
|
|
358
|
+
batchClearMark: 'Clear marks',
|
|
359
|
+
batchClearSelection: 'Clear selection',
|
|
360
|
+
batchHintConfirm: 'Mark selected cards as confirmed (marks only, files untouched)',
|
|
361
|
+
batchHintClearMark: 'Clear marks on selected cards (marks only, files untouched)',
|
|
362
|
+
discardEntry: 'Delete discarded ({n})',
|
|
363
|
+
discardEntryHint: 'Permanently delete every file marked "reject" — bypasses the recycle bin',
|
|
364
|
+
discardDialogTitle: 'Confirm deleting discarded files',
|
|
365
|
+
discardDialogWarn: 'These files will be permanently deleted. They do not go to the recycle bin and cannot be restored.',
|
|
366
|
+
discardDialogCount: '{n} file(s)',
|
|
367
|
+
discardDialogTooMany: 'At most 10 per batch; you have {n}. Please process in batches.',
|
|
368
|
+
discardDialogConfirm: 'Permanently delete these {n} files',
|
|
369
|
+
discardDialogCancel: 'Cancel',
|
|
370
|
+
discardDialogDeleting: 'Deleting…',
|
|
371
|
+
discardDone: 'Permanently deleted {n} file(s)',
|
|
372
|
+
discardFailed: 'Delete failed: {msg}',
|
|
373
|
+
discardDigestMismatch: 'The file list changed; please confirm again',
|
|
374
|
+
scanModeEnter: 'Select',
|
|
375
|
+
scanModeExit: 'Exit selection',
|
|
376
|
+
shownOfTotal: '{shown} of {total} shown',
|
|
377
|
+
|
|
278
378
|
catLegendHint: 'Border color shows the asset type; “Unclassified” means the session logs have no record of it',
|
|
279
379
|
// Grouped by conversation (global view)
|
|
280
380
|
groupCount: '{count} files',
|
|
@@ -352,6 +452,44 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
352
452
|
mediaOpenExternal: 'Open in system player',
|
|
353
453
|
mediaBlobSeekHint: 'Seeking works once loaded (the desktop shell drops Content-Length, so a direct link cannot seek)',
|
|
354
454
|
mediaOpenFolder: 'Open containing folder',
|
|
455
|
+
ctxMarkSection: 'Mark (to feedback basket)',
|
|
456
|
+
ctxMarkApprove: 'Approve',
|
|
457
|
+
ctxMarkReject: 'Reject',
|
|
458
|
+
ctxMarkFinalize: 'Finalize',
|
|
459
|
+
ctxMarkUnconfirm: 'Unconfirm',
|
|
460
|
+
ctxMarkRedo: 'Redo one dimension',
|
|
461
|
+
ctxMarkRegen: 'Regenerate selection',
|
|
462
|
+
ctxMarkReference: 'Set as reference',
|
|
463
|
+
feedbackTargetCurrent: 'current conversation',
|
|
464
|
+
feedbackBasketTitle: 'Feedback basket',
|
|
465
|
+
feedbackBlockedForeign: 'Contains other-session items',
|
|
466
|
+
feedbackBlockedEmpty: 'Nothing marked yet',
|
|
467
|
+
feedbackBasketToggle: 'Feedback basket',
|
|
468
|
+
feedbackBasketToggleN: 'Basket · {n}',
|
|
469
|
+
feedbackBasketToggleHint: 'Toggle the feedback basket to generate a draft',
|
|
470
|
+
feedbackBasketTitleN: 'Feedback basket · {n} item(s)',
|
|
471
|
+
feedbackBasketEmpty: 'Nothing marked yet. Right-click a card and pick an action.',
|
|
472
|
+
feedbackTargetSession: 'Will be sent to session: {title}',
|
|
473
|
+
feedbackForeignWarn: '{n} item(s) belong to another session and cannot be sent together.',
|
|
474
|
+
feedbackForeignWarnShort: 'Contains items from another session — submit disabled',
|
|
475
|
+
feedbackEdit: 'Edit',
|
|
476
|
+
feedbackEditTitle: 'Edit: {name}',
|
|
477
|
+
feedbackReasonLabel: 'Reason (optional)',
|
|
478
|
+
feedbackChangeOnlyLabel: 'Only change (comma separated, optional)',
|
|
479
|
+
feedbackKeepLabel: 'Keep locked (comma separated, optional)',
|
|
480
|
+
feedbackEditSave: 'Save',
|
|
481
|
+
feedbackClear: 'Clear',
|
|
482
|
+
feedbackGenerateDraft: 'Generate decision draft',
|
|
483
|
+
feedbackGenerating: 'Generating…',
|
|
484
|
+
feedbackGenerateHint: 'Writes the draft into the composer; you confirm and send it yourself',
|
|
485
|
+
feedbackDraftReady: 'Draft written into the composer (not sent). Review it and send when ready.',
|
|
486
|
+
feedbackDraftInClipboard: 'Draft copied to clipboard (composer channel unavailable) — paste it manually.',
|
|
487
|
+
feedbackDraftFailed: 'Could not generate the draft',
|
|
488
|
+
feedbackChangeOnly: 'changeOnly',
|
|
489
|
+
feedbackReasonPlaceholder: 'Why (optional)',
|
|
490
|
+
feedbackChangePlaceholder: 'Only change (comma separated, optional)',
|
|
491
|
+
feedbackKeepPlaceholder: 'Keep locked (comma separated, optional)',
|
|
492
|
+
feedbackMarked: 'marked',
|
|
355
493
|
mediaOpenFolderHint: 'Show the file in the file manager',
|
|
356
494
|
mediaOpenFailed: 'Could not open: {message}',
|
|
357
495
|
mediaOpenOk: 'Handed to the system',
|
|
@@ -649,11 +787,12 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
649
787
|
.dg-scopeBtn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
|
|
650
788
|
.dg-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
651
789
|
.dg-sub { color: var(--dsw-alias-label-secondary); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
790
|
+
/* ⚠️ 硬编码:宿主 --dsw-alias-* 变量为空字符串时不会启用 var() 的 fallback */
|
|
652
791
|
.dg-btn {
|
|
653
792
|
appearance: none;
|
|
654
|
-
border: 1px solid
|
|
655
|
-
background:
|
|
656
|
-
color:
|
|
793
|
+
border: 1px solid rgba(255, 255, 255, 0.18);
|
|
794
|
+
background: #2a2f38;
|
|
795
|
+
color: #e8eaed;
|
|
657
796
|
border-radius: 6px;
|
|
658
797
|
padding: 4px 10px;
|
|
659
798
|
font-size: 12px;
|
|
@@ -661,9 +800,9 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
661
800
|
cursor: pointer;
|
|
662
801
|
flex: 0 0 auto;
|
|
663
802
|
}
|
|
664
|
-
.dg-btn:hover:not(:disabled) { border-color:
|
|
665
|
-
.dg-btn:disabled { opacity:
|
|
666
|
-
.dg-btn:focus-visible { outline: 2px solid
|
|
803
|
+
.dg-btn:hover:not(:disabled) { background: #353b45; border-color: rgba(255, 255, 255, 0.32); }
|
|
804
|
+
.dg-btn:disabled { opacity: 1; background: #3a4250; color: #c3cad6; cursor: default; }
|
|
805
|
+
.dg-btn:focus-visible { outline: 2px solid #4a7cff; outline-offset: 1px; }
|
|
667
806
|
.dg-btnIcon { min-width: 30px; padding: 4px 8px; font-size: 14px; line-height: 18px; }
|
|
668
807
|
|
|
669
808
|
/* ===== 设置面板 ===== */
|
|
@@ -1578,6 +1717,192 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
1578
1717
|
|
|
1579
1718
|
.dg-open { white-space: nowrap; }
|
|
1580
1719
|
.dg-openCompact { padding: 2px 6px; line-height: 16px; font-size: 12px; }
|
|
1720
|
+
|
|
1721
|
+
/* ---------- 反馈篮(S3-a)---------- */
|
|
1722
|
+
/* ⚠️ 配色全部硬编码:宿主 --dsw-alias-* 变量「已定义但值为空」,
|
|
1723
|
+
var(--x, fallback) 的 fallback 不会生效,整条声明会作废 → 继承父级深色。 */
|
|
1724
|
+
.dg-feedbackLayer {
|
|
1725
|
+
/* 非模态:z-index 必须低于 .dg-ctxLayer(60),否则右键菜单被盖住 */
|
|
1726
|
+
position: fixed; inset: 0; z-index: 50;
|
|
1727
|
+
display: flex; align-items: flex-end; justify-content: flex-end;
|
|
1728
|
+
padding: 16px;
|
|
1729
|
+
/* 不再铺全屏黑幕;遮罩层本身不拦截点击,只有面板本体拦截 */
|
|
1730
|
+
background: transparent;
|
|
1731
|
+
pointer-events: none;
|
|
1732
|
+
}
|
|
1733
|
+
.dg-feedback {
|
|
1734
|
+
/* 只有面板本体接收点击,其余区域穿透到底层卡片 */
|
|
1735
|
+
pointer-events: auto;
|
|
1736
|
+
width: min(420px, 46vw); max-height: 60vh;
|
|
1737
|
+
display: flex; flex-direction: column;
|
|
1738
|
+
background: #1b1e24; color: #e8eaed;
|
|
1739
|
+
border: 1px solid rgba(255, 255, 255, 0.14);
|
|
1740
|
+
border-radius: 10px; overflow: hidden;
|
|
1741
|
+
/* 用阴影做层次,代替原来的黑幕 */
|
|
1742
|
+
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
|
|
1743
|
+
}
|
|
1744
|
+
.dg-feedbackHead {
|
|
1745
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
1746
|
+
padding: 12px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.10);
|
|
1747
|
+
background: #22262e;
|
|
1748
|
+
}
|
|
1749
|
+
.dg-feedbackTitle { font-size: 14px; font-weight: 600; color: #f0f2f5; }
|
|
1750
|
+
.dg-feedbackTarget {
|
|
1751
|
+
padding: 8px 14px; font-size: 12px;
|
|
1752
|
+
background: rgba(74, 124, 255, 0.16); color: #a9c2ff;
|
|
1753
|
+
border-bottom: 1px solid rgba(74, 124, 255, 0.26);
|
|
1754
|
+
}
|
|
1755
|
+
/* 警告条:高对比 + 图标,让"为什么不能生成"一眼可见 */
|
|
1756
|
+
.dg-feedbackWarn {
|
|
1757
|
+
padding: 9px 14px; font-size: 12px; font-weight: 600;
|
|
1758
|
+
background: #4a3618; color: #ffd08a;
|
|
1759
|
+
border-bottom: 1px solid #7a5a20;
|
|
1760
|
+
}
|
|
1761
|
+
.dg-feedbackWarn::before { content: "⚠ "; }
|
|
1762
|
+
.dg-feedbackList {
|
|
1763
|
+
list-style: none; margin: 0; padding: 8px 10px; overflow: auto; flex: 1;
|
|
1764
|
+
}
|
|
1765
|
+
.dg-feedbackItem {
|
|
1766
|
+
display: flex; align-items: center; gap: 8px;
|
|
1767
|
+
padding: 8px 6px; font-size: 12px;
|
|
1768
|
+
color: #e8eaed;
|
|
1769
|
+
border-bottom: 1px solid rgba(255, 255, 255, 0.06);
|
|
1770
|
+
}
|
|
1771
|
+
.dg-feedbackNo {
|
|
1772
|
+
flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
|
|
1773
|
+
display: flex; align-items: center; justify-content: center;
|
|
1774
|
+
background: #4a7cff; color: #ffffff; font-size: 11px; font-weight: 600;
|
|
1775
|
+
}
|
|
1776
|
+
.dg-feedbackAction { flex: 0 0 auto; color: #8fb6ff; font-weight: 600; }
|
|
1777
|
+
.dg-feedbackName { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e8eaed; }
|
|
1778
|
+
.dg-feedbackDim { flex: 0 0 auto; color: #a9b1bd; font-size: 11px; }
|
|
1779
|
+
.dg-feedbackOps { flex: 0 0 auto; display: flex; gap: 4px; }
|
|
1780
|
+
|
|
1781
|
+
/* 反馈篮作用域内的按钮:硬编码,不依赖宿主变量 */
|
|
1782
|
+
.dg-feedback .dg-btn {
|
|
1783
|
+
border: 1px solid rgba(255, 255, 255, 0.22);
|
|
1784
|
+
background: #2a2f38;
|
|
1785
|
+
color: #e8eaed;
|
|
1786
|
+
}
|
|
1787
|
+
.dg-feedback .dg-btn:hover:not(:disabled) { background: #353b45; border-color: rgba(255, 255, 255, 0.35); }
|
|
1788
|
+
.dg-feedback .dg-btn:disabled {
|
|
1789
|
+
/* 不只靠 opacity:改为清晰可读的灰底浅字,让"禁用"能被看见 */
|
|
1790
|
+
opacity: 1;
|
|
1791
|
+
background: #3a4250;
|
|
1792
|
+
color: #c3cad6;
|
|
1793
|
+
border-color: rgba(255, 255, 255, 0.14);
|
|
1794
|
+
cursor: default;
|
|
1795
|
+
}
|
|
1796
|
+
.dg-feedback .dg-primaryBtn {
|
|
1797
|
+
background: #4a7cff; color: #ffffff; border-color: #4a7cff; font-weight: 600;
|
|
1798
|
+
}
|
|
1799
|
+
.dg-feedback .dg-primaryBtn:hover:not(:disabled) { background: #5b88ff; border-color: #5b88ff; }
|
|
1800
|
+
.dg-feedback .dg-primaryBtn:disabled {
|
|
1801
|
+
opacity: 1;
|
|
1802
|
+
background: #3a4250; color: #c3cad6; border-color: rgba(255, 255, 255, 0.14);
|
|
1803
|
+
}
|
|
1804
|
+
.dg-feedback .dg-btnSmall { padding: 3px 9px; font-size: 11px; }
|
|
1805
|
+
|
|
1806
|
+
.dg-feedbackActions {
|
|
1807
|
+
display: flex; justify-content: flex-end; gap: 8px;
|
|
1808
|
+
padding: 10px 14px; border-top: 1px solid rgba(255, 255, 255, 0.10);
|
|
1809
|
+
background: #22262e;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
|
|
1813
|
+
/* ---------- 反馈篮编辑弹窗(S3-a)---------- */
|
|
1814
|
+
.dg-feedbackEdit {
|
|
1815
|
+
padding: 10px 14px; border-top: 1px solid var(--dsw-alias-border-l2, rgba(255,255,255,0.10));
|
|
1816
|
+
background: rgba(255, 255, 255, 0.03);
|
|
1817
|
+
display: flex; flex-direction: column; gap: 8px;
|
|
1818
|
+
}
|
|
1819
|
+
.dg-feedbackEditHead { font-size: 12px; font-weight: 600; color: #e8eaed; }
|
|
1820
|
+
.dg-feedbackField { display: flex; flex-direction: column; gap: 4px; }
|
|
1821
|
+
.dg-feedbackLabel { font-size: 11px; color: #a9b1bd; }
|
|
1822
|
+
.dg-feedbackTextarea { resize: vertical; min-height: 44px; font: inherit; }
|
|
1823
|
+
.dg-feedbackEditActions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
|
|
1824
|
+
|
|
1825
|
+
/* 反馈篮独立入口按钮(S3-a) */
|
|
1826
|
+
.dg-basketToggle {
|
|
1827
|
+
position: fixed; right: 16px; bottom: 16px; z-index: 45;
|
|
1828
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
|
|
1829
|
+
}
|
|
1830
|
+
.dg-basketToggle[data-gallery-basket-count="0"] { color: #a9b1bd; }
|
|
1831
|
+
|
|
1832
|
+
/* ---------- v0.13.7:分类开关 / 确认角标 / 批量 / 删除对话框 ---------- */
|
|
1833
|
+
|
|
1834
|
+
/* 分类开关(原 legend,现可点) */
|
|
1835
|
+
.dg-legendToggle {
|
|
1836
|
+
appearance: none; border: 1px solid transparent; background: transparent;
|
|
1837
|
+
cursor: pointer; padding: 2px 6px; border-radius: 5px;
|
|
1838
|
+
font: inherit; color: inherit;
|
|
1839
|
+
display: inline-flex; align-items: center; gap: 5px;
|
|
1840
|
+
}
|
|
1841
|
+
.dg-legendToggle:hover { border-color: rgba(255, 255, 255, 0.18); background: rgba(255, 255, 255, 0.06); }
|
|
1842
|
+
.dg-legendToggle.dg-legendOff { opacity: 0.42; }
|
|
1843
|
+
.dg-legendToggle.dg-legendOff .dg-legendSwatch { filter: grayscale(1); }
|
|
1844
|
+
.dg-legendCount { font-size: 11px; color: #a9b1bd; margin-left: 2px; }
|
|
1845
|
+
.dg-legendSwatchPending { opacity: 0.55; border-style: dashed !important; }
|
|
1846
|
+
|
|
1847
|
+
/* 卡片包装层 + 确认角标 + 多选框 */
|
|
1848
|
+
.dg-cardWrap { position: relative; }
|
|
1849
|
+
.dg-cardConfirmed > :first-child { outline: 2px solid #4a9d5f; outline-offset: -2px; }
|
|
1850
|
+
.dg-cardChecked > :first-child { outline: 2px solid #4a7cff; outline-offset: -2px; }
|
|
1851
|
+
.dg-confirmBadge {
|
|
1852
|
+
position: absolute; top: 6px; left: 6px; z-index: 3;
|
|
1853
|
+
display: inline-flex; align-items: center; gap: 3px;
|
|
1854
|
+
padding: 1px 6px; border-radius: 9px;
|
|
1855
|
+
background: #4a9d5f; color: #fff; font-size: 10px; font-weight: 600;
|
|
1856
|
+
pointer-events: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
|
|
1857
|
+
}
|
|
1858
|
+
.dg-cardCheck {
|
|
1859
|
+
position: absolute; top: 6px; right: 6px; z-index: 4;
|
|
1860
|
+
width: 20px; height: 20px; border-radius: 4px;
|
|
1861
|
+
border: 1.5px solid rgba(255, 255, 255, 0.65);
|
|
1862
|
+
background: rgba(0, 0, 0, 0.45); color: #fff;
|
|
1863
|
+
font-size: 12px; line-height: 1; cursor: pointer;
|
|
1864
|
+
display: flex; align-items: center; justify-content: center;
|
|
1865
|
+
}
|
|
1866
|
+
.dg-cardCheck:hover { border-color: #fff; background: rgba(0, 0, 0, 0.7); }
|
|
1867
|
+
.dg-cardCheckOn { background: #4a7cff; border-color: #4a7cff; }
|
|
1868
|
+
|
|
1869
|
+
/* 批量操作条 */
|
|
1870
|
+
.dg-batchBar {
|
|
1871
|
+
display: flex; align-items: center; justify-content: space-between; gap: 10px;
|
|
1872
|
+
padding: 6px 10px; margin: 0 0 6px;
|
|
1873
|
+
background: rgba(74, 124, 255, 0.14);
|
|
1874
|
+
border: 1px solid rgba(74, 124, 255, 0.35); border-radius: 6px;
|
|
1875
|
+
font-size: 12px;
|
|
1876
|
+
}
|
|
1877
|
+
.dg-batchCount { font-weight: 600; color: #a9c2ff; white-space: nowrap; }
|
|
1878
|
+
.dg-batchOps { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
1879
|
+
|
|
1880
|
+
/* 危险动作按钮(清掉废稿) */
|
|
1881
|
+
.dg-dangerBtn { border-color: rgba(220, 80, 80, 0.55) !important; color: #ff9c9c !important; }
|
|
1882
|
+
.dg-dangerBtn:hover:not(:disabled) { background: rgba(220, 80, 80, 0.18) !important; border-color: #ff9c9c !important; }
|
|
1883
|
+
.dg-dangerText { color: #ff9c9c; font-size: 12px; font-weight: 600; }
|
|
1884
|
+
|
|
1885
|
+
/* 删除确认对话框 */
|
|
1886
|
+
.dg-modalLayer {
|
|
1887
|
+
position: fixed; inset: 0; z-index: 80;
|
|
1888
|
+
display: flex; align-items: center; justify-content: center;
|
|
1889
|
+
background: rgba(0, 0, 0, 0.66);
|
|
1890
|
+
}
|
|
1891
|
+
.dg-modal {
|
|
1892
|
+
width: min(560px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
|
|
1893
|
+
background: #1b1e24; color: #e8eaed;
|
|
1894
|
+
border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 10px; overflow: hidden;
|
|
1895
|
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
|
|
1896
|
+
}
|
|
1897
|
+
.dg-modalHead { padding: 12px 14px; font-size: 14px; font-weight: 600; border-bottom: 1px solid rgba(255, 255, 255, 0.1); background: #22262e; }
|
|
1898
|
+
.dg-modalBody { padding: 12px 14px; overflow: auto; flex: 1; font-size: 12px; }
|
|
1899
|
+
.dg-modalSub { color: #a9b1bd; margin: 6px 0; }
|
|
1900
|
+
.dg-modalOps { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px; border-top: 1px solid rgba(255, 255, 255, 0.1); background: #22262e; }
|
|
1901
|
+
.dg-discardList { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow: auto; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 6px; }
|
|
1902
|
+
.dg-discardList li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
|
|
1903
|
+
.dg-discardList li:last-child { border-bottom: none; }
|
|
1904
|
+
.dg-discardPath { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
|
|
1905
|
+
.dg-discardSize { color: #a9b1bd; white-space: nowrap; }
|
|
1581
1906
|
`
|
|
1582
1907
|
|
|
1583
1908
|
|
|
@@ -1651,6 +1976,715 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
1651
1976
|
* 删除需要二次确认(走 ConfirmDialog)。
|
|
1652
1977
|
*/
|
|
1653
1978
|
|
|
1979
|
+
/**
|
|
1980
|
+
* 反馈契约 v1 —— 纯函数,Host 与 Client 双端复用。
|
|
1981
|
+
*
|
|
1982
|
+
* 由 scripts/build.mjs 沿用 protocol.js 的做法:
|
|
1983
|
+
* · 剥掉 export 注入 client bundle
|
|
1984
|
+
* · 生成 host/feedback-text.js 供 Host 侧 import
|
|
1985
|
+
*
|
|
1986
|
+
* 设计原则(调研结论,见 docs/migration.md 与调研报告):
|
|
1987
|
+
* 1. 反馈是**契约**不是自由文本:带锚点(relPath)、动作类型、理由、目标会话。
|
|
1988
|
+
* 2. **攒批 + 一次发送**:多条标记合成一条消息,不逐条发。
|
|
1989
|
+
* 3. **人确认闸门**:本模块只负责「产出草稿文本」,发送由用户在 composer 里点。
|
|
1990
|
+
* 4. **显式 changeOnly / keep**:生成类工作流实证「只改 X、其余锁死」远好于「再改改」。
|
|
1991
|
+
* 5. 逐条用 `Annotation N:` 编号,便于模型逐条回应(参考 dsh-quote-annotate-pro 契约)。
|
|
1992
|
+
*/
|
|
1993
|
+
|
|
1994
|
+
/** 首版 6 个动作。值即契约里的 action 字符串,不要随意改(已写进 marks 文件)。 */
|
|
1995
|
+
const ACTIONS = [
|
|
1996
|
+
'approve',
|
|
1997
|
+
'reject',
|
|
1998
|
+
'finalize',
|
|
1999
|
+
'redo-one-dim',
|
|
2000
|
+
'regenerate-selected',
|
|
2001
|
+
'set-reference',
|
|
2002
|
+
]
|
|
2003
|
+
|
|
2004
|
+
/** 动作 → 中文动词(生成草稿正文用)。 */
|
|
2005
|
+
const ACTION_LABELS_ZH = {
|
|
2006
|
+
approve: '通过',
|
|
2007
|
+
reject: '不要这张',
|
|
2008
|
+
finalize: '定为最终版',
|
|
2009
|
+
'redo-one-dim': '单维重做',
|
|
2010
|
+
'regenerate-selected': '选择性重生成',
|
|
2011
|
+
'set-reference': '设为参照',
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
/** 动作 → 英文动词。 */
|
|
2015
|
+
const ACTION_LABELS_EN = {
|
|
2016
|
+
approve: 'approve',
|
|
2017
|
+
reject: 'reject',
|
|
2018
|
+
finalize: 'finalize',
|
|
2019
|
+
'redo-one-dim': 'redo one dimension',
|
|
2020
|
+
'regenerate-selected': 'regenerate',
|
|
2021
|
+
'set-reference': 'set as reference',
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
/** 契约版本。检查项会核对。 */
|
|
2025
|
+
const SCHEMA = 1
|
|
2026
|
+
|
|
2027
|
+
/** 来源标识。 */
|
|
2028
|
+
const SOURCE = 'dsh-gallery'
|
|
2029
|
+
|
|
2030
|
+
/** 常用「只改」维度候选(给 UI 做快捷输入,不是强制枚举)。 */
|
|
2031
|
+
const CHANGE_CANDIDATES = [
|
|
2032
|
+
'色调', '亮度', '材质', '构图', '透视', '比例', '文字', '光线', '风格', '细节',
|
|
2033
|
+
]
|
|
2034
|
+
|
|
2035
|
+
/** 常用的「锁死」项候选。 */
|
|
2036
|
+
const KEEP_CANDIDATES = [
|
|
2037
|
+
'构图', '人物位置', '主体比例', '透视角度', '文字内容', '整体风格', '配色基调',
|
|
2038
|
+
]
|
|
2039
|
+
|
|
2040
|
+
/**
|
|
2041
|
+
* 构造一条反馈项。
|
|
2042
|
+
* @param item - { relPath, category, action, reason?, changeOnly?, keep?, preserve?, region?, params? }
|
|
2043
|
+
* @returns 规范化后的 feedback item
|
|
2044
|
+
*/
|
|
2045
|
+
function makeItem(item) {
|
|
2046
|
+
const out = {
|
|
2047
|
+
relPath: String(item?.relPath ?? ''),
|
|
2048
|
+
category: String(item?.category ?? 'unknown'),
|
|
2049
|
+
action: ACTIONS.includes(item?.action) ? item.action : 'approve',
|
|
2050
|
+
}
|
|
2051
|
+
if (typeof item?.reason === 'string' && item.reason.trim() !== '') out.reason = item.reason.trim()
|
|
2052
|
+
if (Array.isArray(item?.changeOnly) && item.changeOnly.length > 0) {
|
|
2053
|
+
out.changeOnly = item.changeOnly.map((x) => String(x)).filter((x) => x !== '')
|
|
2054
|
+
}
|
|
2055
|
+
if (Array.isArray(item?.keep) && item.keep.length > 0) {
|
|
2056
|
+
out.keep = item.keep.map((x) => String(x)).filter((x) => x !== '')
|
|
2057
|
+
}
|
|
2058
|
+
if (Array.isArray(item?.preserve) && item.preserve.length > 0) {
|
|
2059
|
+
out.preserve = item.preserve.map((x) => String(x)).filter((x) => x !== '')
|
|
2060
|
+
}
|
|
2061
|
+
if (item?.region !== undefined && item.region !== null) out.region = item.region
|
|
2062
|
+
if (item?.params !== undefined && item.params !== null) out.params = item.params
|
|
2063
|
+
return out
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
/**
|
|
2067
|
+
* 构造一份反馈草稿(契约对象)。
|
|
2068
|
+
* @param args - { sessionId, items, status? }
|
|
2069
|
+
*/
|
|
2070
|
+
function makeFeedback(args) {
|
|
2071
|
+
return {
|
|
2072
|
+
schema: SCHEMA,
|
|
2073
|
+
source: SOURCE,
|
|
2074
|
+
sessionId: String(args?.sessionId ?? ''),
|
|
2075
|
+
status: args?.status === 'sent' ? 'sent' : 'draft',
|
|
2076
|
+
items: (Array.isArray(args?.items) ? args.items : []).map(makeItem),
|
|
2077
|
+
createdAt: typeof args?.createdAt === 'number' ? args.createdAt : Date.now(),
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/** 文件名取路径末段。 */
|
|
2082
|
+
function baseName(relPath) {
|
|
2083
|
+
const s = String(relPath ?? '')
|
|
2084
|
+
const i = s.lastIndexOf('/')
|
|
2085
|
+
return i >= 0 ? s.slice(i + 1) : s
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* 把契约渲染成**人类与模型都能读的草稿正文**。
|
|
2090
|
+
*
|
|
2091
|
+
* 关键要求(调研结论 4):每条必须同时写「只改 X」与「其余锁死」,
|
|
2092
|
+
* 否则模型容易把整张重画。
|
|
2093
|
+
*
|
|
2094
|
+
* @param feedback - makeFeedback() 的产物
|
|
2095
|
+
* @param options - { locale?: 'zh'|'en', targetSessionTitle?: string }
|
|
2096
|
+
* @returns 纯文本(可直接 setDraft 进 composer)
|
|
2097
|
+
*/
|
|
2098
|
+
function renderFeedbackText(feedback, options) {
|
|
2099
|
+
const locale = options?.locale === 'en' ? 'en' : 'zh'
|
|
2100
|
+
const labels = locale === 'en' ? ACTION_LABELS_EN : ACTION_LABELS_ZH
|
|
2101
|
+
const items = Array.isArray(feedback?.items) ? feedback.items : []
|
|
2102
|
+
|
|
2103
|
+
if (items.length === 0) {
|
|
2104
|
+
return locale === 'en'
|
|
2105
|
+
? '(No items in the feedback basket.)'
|
|
2106
|
+
: '(反馈篮里还没有条目。)'
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
const lines = []
|
|
2110
|
+
if (locale === 'en') {
|
|
2111
|
+
lines.push(`[Feedback from dsh-gallery · ${items.length} item(s)]`)
|
|
2112
|
+
lines.push('')
|
|
2113
|
+
lines.push('Reply item by item using the `Annotation N:` prefix, so each decision maps to one annotation.')
|
|
2114
|
+
lines.push('')
|
|
2115
|
+
} else {
|
|
2116
|
+
lines.push(`【产出画廊反馈 · 共 ${items.length} 条】`)
|
|
2117
|
+
lines.push('')
|
|
2118
|
+
lines.push('请按 `Annotation 1:`、`Annotation 2:` … 逐条回应,让每条决定都对应到一个批注。')
|
|
2119
|
+
lines.push('')
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
items.forEach((item, idx) => {
|
|
2123
|
+
const n = idx + 1
|
|
2124
|
+
const name = baseName(item.relPath)
|
|
2125
|
+
const verb = labels[item.action] ?? item.action
|
|
2126
|
+
lines.push(`Annotation ${n}:${verb} —— ${name}`)
|
|
2127
|
+
lines.push(`${locale === 'en' ? 'Path' : '路径'}:${item.relPath}`)
|
|
2128
|
+
if (item.reason !== undefined) {
|
|
2129
|
+
lines.push(`${locale === 'en' ? 'Reason' : '理由'}:${item.reason}`)
|
|
2130
|
+
}
|
|
2131
|
+
if (Array.isArray(item.changeOnly) && item.changeOnly.length > 0) {
|
|
2132
|
+
lines.push(locale === 'en'
|
|
2133
|
+
? `changeOnly: ${item.changeOnly.join(' / ')}`
|
|
2134
|
+
: `只改:${item.changeOnly.join(' / ')}`)
|
|
2135
|
+
}
|
|
2136
|
+
if (Array.isArray(item.keep) && item.keep.length > 0) {
|
|
2137
|
+
lines.push(locale === 'en'
|
|
2138
|
+
? `keep locked: ${item.keep.join(' / ')}`
|
|
2139
|
+
: `锁死(其余不动):${item.keep.join(' / ')}`)
|
|
2140
|
+
}
|
|
2141
|
+
if (Array.isArray(item.preserve) && item.preserve.length > 0) {
|
|
2142
|
+
lines.push(locale === 'en'
|
|
2143
|
+
? `preserve: ${item.preserve.join(' / ')}`
|
|
2144
|
+
: `保留:${item.preserve.join(' / ')}`)
|
|
2145
|
+
}
|
|
2146
|
+
if (item.region !== undefined && item.region !== null) {
|
|
2147
|
+
lines.push(`${locale === 'en' ? 'Region' : '区域'}:${JSON.stringify(item.region)}`)
|
|
2148
|
+
}
|
|
2149
|
+
if (item.params !== undefined && item.params !== null) {
|
|
2150
|
+
lines.push(`${locale === 'en' ? 'Params' : '参数'}:${JSON.stringify(item.params)}`)
|
|
2151
|
+
}
|
|
2152
|
+
lines.push('')
|
|
2153
|
+
})
|
|
2154
|
+
|
|
2155
|
+
// 收口指令:把「锁死」原则再强调一次(防模型整张重画)
|
|
2156
|
+
if (locale === 'en') {
|
|
2157
|
+
lines.push('Unless an annotation says otherwise, keep everything else unchanged — do not regenerate wholesale.')
|
|
2158
|
+
} else {
|
|
2159
|
+
lines.push('除上述明确要改的部分外,其余全部保持原样,不要整张重做。')
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
return lines.join('\n')
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
/**
|
|
2166
|
+
* 把契约序列化成 JSON(导出 / 落盘 / 审计用,与渲染同一个 shape)。
|
|
2167
|
+
*/
|
|
2168
|
+
function serializeFeedback(feedback) {
|
|
2169
|
+
return JSON.stringify(feedback, null, 2)
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
|
|
2173
|
+
/**
|
|
2174
|
+
* 反馈篮状态与草稿生成(S3-a)。
|
|
2175
|
+
*
|
|
2176
|
+
* 设计要点(严格按调研结论与老板指令):
|
|
2177
|
+
* 1. **零 inject**:不依赖 conversation.input 服务也能工作 ——
|
|
2178
|
+
* 优先用 ctx.get('conversation.input') 的官方 setDraft;
|
|
2179
|
+
* 拿不到时退化为「把草稿文本塞进剪贴板 + 提示用户粘贴」,绝不自动发送。
|
|
2180
|
+
* 2. **人确认闸门**:只写 composer 草稿,**永不调用 submit()**。
|
|
2181
|
+
* 3. **攒批合并**:连点防抖,多条标记合成一条消息。
|
|
2182
|
+
* 4. **显式目标会话**:全局视图下必须标明这份反馈发给哪个会话。
|
|
2183
|
+
* 5. **历史会话禁用**:卡片归属会话不是当前会话时,提交按钮禁用。
|
|
2184
|
+
*/
|
|
2185
|
+
|
|
2186
|
+
/** 最近一次生成的草稿文本(供 seam.getFeedbackDraft() 读)。 */
|
|
2187
|
+
const draftRef = { current: '' }
|
|
2188
|
+
|
|
2189
|
+
/** 反馈篮内部使用的动作定义(与 shared 的 ACTIONS 对齐,这里只放 UI 需要的)。 */
|
|
2190
|
+
const FEEDBACK_ACTIONS_UI = [
|
|
2191
|
+
{ id: 'approve', labelZh: '通过', labelEn: 'Approve', icon: '✓' },
|
|
2192
|
+
{ id: 'reject', labelZh: '不要这张', labelEn: 'Reject', icon: '✕' },
|
|
2193
|
+
{ id: 'finalize', labelZh: '定为最终版', labelEn: 'Finalize', icon: '★' },
|
|
2194
|
+
{ id: 'redo-one-dim', labelZh: '单维重做', labelEn: 'Redo one dim', icon: '↻' },
|
|
2195
|
+
{ id: 'regenerate-selected', labelZh: '选择性重生成', labelEn: 'Regenerate', icon: '⟳' },
|
|
2196
|
+
{ id: 'set-reference', labelZh: '设为参照', labelEn: 'Set reference', icon: '◎' },
|
|
2197
|
+
]
|
|
2198
|
+
|
|
2199
|
+
/**
|
|
2200
|
+
* 把草稿写进 composer —— **优先官方通道,拿不到就退化为剪贴板**。
|
|
2201
|
+
*
|
|
2202
|
+
* 官方通道(已实证):ctx.get('conversation.input').for(ctx).setDraft(text)
|
|
2203
|
+
* · setDraft 只替换草稿文本,不会发送 —— 满足「人确认闸门」。
|
|
2204
|
+
* · 若 actx 没有 session 绑定会抛错,此时退化为剪贴板。
|
|
2205
|
+
*
|
|
2206
|
+
* @returns { ok: boolean, via: 'composer' | 'clipboard' | 'failed', reason?: string }
|
|
2207
|
+
*/
|
|
2208
|
+
/**
|
|
2209
|
+
* 把草稿写进 composer —— **零 inject 的纯 DOM 路径**。
|
|
2210
|
+
*
|
|
2211
|
+
* 为什么不用官方 conversation.input 服务(A 方案已废弃):
|
|
2212
|
+
* 实测在 inject 里声明 `conversation.input` 会让 Cordis 插件在 web boot
|
|
2213
|
+
* 阶段一直 pending("waiting for service: conversation.input"),宿主判定
|
|
2214
|
+
* 启动失败、页面永久停在 "Loading plugins…"、主进程退出。
|
|
2215
|
+
* 且源码 L19270/19278 实证:slot props 只传 `{}`,不透传 input,
|
|
2216
|
+
* 所以零 inject 根本拿不到这个服务。
|
|
2217
|
+
*
|
|
2218
|
+
* 实现三条纯 DOM 路径,按序尝试,用 **Lexical 内部 state** 判断成功:
|
|
2219
|
+
* 1) beforeinput + input 事件(Lexical 的 onBeforeInput 入口)
|
|
2220
|
+
* 2) 模拟 paste(ClipboardEvent + DataTransfer,Lexical 有完整 paste 处理)
|
|
2221
|
+
* 3) execCommand('insertText') ← 已知只改 DOM 不同步 state,仅最后兜底
|
|
2222
|
+
*
|
|
2223
|
+
* 判据不是 innerText(那会假的通过),而是 editor.getEditorState() 里真实文本增长。
|
|
2224
|
+
* 绝不调用 submit() / 任何发送动作。
|
|
2225
|
+
*
|
|
2226
|
+
* @returns { ok, via, detail?, reason? }
|
|
2227
|
+
*/
|
|
2228
|
+
/**
|
|
2229
|
+
* 把草稿写进 composer —— **零 inject 的纯 DOM 路径**。
|
|
2230
|
+
*
|
|
2231
|
+
* 为什么不用官方 conversation.input 服务(A 方案已废弃):
|
|
2232
|
+
* 实测在 inject 里声明 `conversation.input` 会让 Cordis 插件在 web boot
|
|
2233
|
+
* 阶段一直 pending("waiting for service: conversation.input"),宿主判定
|
|
2234
|
+
* 启动失败、页面永久停在 "Loading plugins…"、主进程退出。
|
|
2235
|
+
* 且源码 L19270/19278 实证:slot props 只传 `{}`,不透传 input,
|
|
2236
|
+
* 所以零 inject 根本拿不到这个服务。
|
|
2237
|
+
*
|
|
2238
|
+
* ⚠️ **关键:Lexical 的 state 更新是异步 flush。**
|
|
2239
|
+
* dispatch 事件后**立即**读 getEditorState() 永远读到旧 state ——
|
|
2240
|
+
* 这会把"其实成功"的路径判成失败(假阴性),进而让后续路径重复插入,
|
|
2241
|
+
* 最终草稿被写进 4 份(真机实测:1524 字 ≈ 381×4)。
|
|
2242
|
+
*
|
|
2243
|
+
* 所以每条路径 dispatch 后必须 **await 一个宏任务再读 state**,
|
|
2244
|
+
* 并且**一旦成功立即 return 短路**,不再尝试后续路径。
|
|
2245
|
+
*
|
|
2246
|
+
* 三条路径(按序,成功即停):
|
|
2247
|
+
* 1) beforeinput + input 事件(Lexical 的 onBeforeInput 入口,L6592)
|
|
2248
|
+
* 2) 模拟 paste(ClipboardEvent + DataTransfer,Lexical 有完整 paste 处理,L6587/L10559)
|
|
2249
|
+
* 3) execCommand('insertText') —— 仅最后兜底
|
|
2250
|
+
*
|
|
2251
|
+
* 判据始终是 **Lexical 内部 state 的真实文本**(不是 innerText),且必须等 flush。
|
|
2252
|
+
* 绝不调用 submit() / 任何发送动作。
|
|
2253
|
+
*
|
|
2254
|
+
* @returns { ok, via, detail?, reason? }
|
|
2255
|
+
*/
|
|
2256
|
+
async function writeDraftToComposer(text, sessionId) {
|
|
2257
|
+
const COMPOSER_SEL = '[data-composer-input][data-lexical-editor="true"]'
|
|
2258
|
+
const FALLBACK_SEL = '[data-lexical-editor="true"]'
|
|
2259
|
+
/** 等 Lexical flush 的宏任务时间。80ms 是实测稳妥值(60 起,留余量)。 */
|
|
2260
|
+
const FLUSH_WAIT_MS = 80
|
|
2261
|
+
|
|
2262
|
+
const waitFlush = () => new Promise((resolve) => setTimeout(resolve, FLUSH_WAIT_MS))
|
|
2263
|
+
|
|
2264
|
+
const findComposer = () => document.querySelector(COMPOSER_SEL)
|
|
2265
|
+
?? document.querySelector(FALLBACK_SEL)
|
|
2266
|
+
?? document.querySelector('[contenteditable="true"]')
|
|
2267
|
+
|
|
2268
|
+
/** 从 DOM 拿 Lexical editor 实例(Lexical 官方在 editable 元素上挂)。 */
|
|
2269
|
+
const editorOf = (el) => (el === null ? null : (el.__lexicalEditor ?? el._lexicalEditor ?? null))
|
|
2270
|
+
|
|
2271
|
+
/** 读编辑器**内部 state** 的真实文本。 */
|
|
2272
|
+
const stateText = (ed) => {
|
|
2273
|
+
if (ed === null) return { ok: false, size: -1, text: '', why: 'no-editor' }
|
|
2274
|
+
try {
|
|
2275
|
+
const st = ed.getEditorState()
|
|
2276
|
+
let out = ''
|
|
2277
|
+
st.read(() => {
|
|
2278
|
+
const root = st._nodeMap.get('root')
|
|
2279
|
+
if (root === undefined) return
|
|
2280
|
+
const walk = (n) => {
|
|
2281
|
+
if (n === null || n === undefined) return ''
|
|
2282
|
+
if (typeof n.getTextContent === 'function') {
|
|
2283
|
+
const t = n.getTextContent()
|
|
2284
|
+
if (t !== '') return t
|
|
2285
|
+
}
|
|
2286
|
+
const kids = typeof n.getChildren === 'function' ? n.getChildren() : []
|
|
2287
|
+
return kids.map(walk).join('')
|
|
2288
|
+
}
|
|
2289
|
+
out = walk(root)
|
|
2290
|
+
})
|
|
2291
|
+
return { ok: true, size: out.length, text: out }
|
|
2292
|
+
} catch (error) {
|
|
2293
|
+
return { ok: false, size: -1, text: '', why: String(error?.message ?? error) }
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
const el = findComposer()
|
|
2298
|
+
if (el === null) {
|
|
2299
|
+
// composer 不在此刻的 DOM 里(还没渲染/不在会话页)→ 只能落剪贴板
|
|
2300
|
+
const copied = await copyText(text)
|
|
2301
|
+
draftRef.current = text
|
|
2302
|
+
return copied
|
|
2303
|
+
? { ok: false, via: 'clipboard', reason: 'composer-not-found' }
|
|
2304
|
+
: { ok: false, via: 'failed', reason: 'composer-not-found-copy-failed' }
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
const ed = editorOf(el)
|
|
2308
|
+
|
|
2309
|
+
// ---- 幂等:写入前先等一次 flush,确认当前 state,避免重复插入 ----
|
|
2310
|
+
await waitFlush()
|
|
2311
|
+
const before = stateText(ed)
|
|
2312
|
+
|
|
2313
|
+
// 用草稿头(前 24 字)判断,而不是全串匹配 ——
|
|
2314
|
+
// 全串匹配在「草稿后面跟了用户自己打的字」时会失效(state 里包含但不再是完整 text)。
|
|
2315
|
+
const headProbe = text.trim().slice(0, Math.min(24, text.trim().length))
|
|
2316
|
+
if (before.ok && headProbe !== '' && before.text.includes(headProbe)) {
|
|
2317
|
+
draftRef.current = text
|
|
2318
|
+
return { ok: true, via: 'composer', detail: 'already-present' }
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
try { el.focus() } catch { /* 忽略 */ }
|
|
2322
|
+
|
|
2323
|
+
/** 统一判定:等 flush → 读 state → 看是否比 before 长且含目标片段。 */
|
|
2324
|
+
const verify = async (probeFragment) => {
|
|
2325
|
+
await waitFlush()
|
|
2326
|
+
const after = stateText(ed)
|
|
2327
|
+
if (!after.ok) return { ok: false, size: -1 }
|
|
2328
|
+
// 双重判据:长度增长 + 含目标片段(防止别的操作同时改 state 造成误判)
|
|
2329
|
+
const grew = after.size > before.size
|
|
2330
|
+
const contains = probeFragment === undefined
|
|
2331
|
+
? true
|
|
2332
|
+
: after.text.includes(probeFragment)
|
|
2333
|
+
return { ok: grew && contains, size: after.size }
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// 用于确认"确实插入了本次文本"的探针片段(取前 24 字,足够区分)
|
|
2337
|
+
const probe = text.trim().slice(0, Math.min(24, text.trim().length))
|
|
2338
|
+
|
|
2339
|
+
// ---- 路径 1:**只发 beforeinput**(不跟 input)----
|
|
2340
|
+
// ⚠️ 真机实证:beforeinput 与 input 在同一同步块连发时,Lexical 在 flush 前
|
|
2341
|
+
// 把两次都排进更新队列 → **各插入一份 → 草稿变 2 份**(770 字 ≈ 385×2)。
|
|
2342
|
+
// 微探针:单独 beforeinput → 等 160ms → state 6 字;
|
|
2343
|
+
// 再单独 input → 等 160ms → state 仍 6 字(第二个被忽略)。
|
|
2344
|
+
// 即:只要中间等 flush 就不会双插;最可靠是根本不发 input。
|
|
2345
|
+
// 实证:只发一次 beforeinput(完整 385 字草稿)+ 等 300ms
|
|
2346
|
+
// → draftLen=385、stateLen=385、"Annotation 1" 恰 2 次、singleCopy=true。
|
|
2347
|
+
try {
|
|
2348
|
+
el.dispatchEvent(new InputEvent('beforeinput', {
|
|
2349
|
+
inputType: 'insertText', data: text, bubbles: true, cancelable: true, composed: true,
|
|
2350
|
+
}))
|
|
2351
|
+
const v1 = await verify(probe)
|
|
2352
|
+
if (v1.ok) {
|
|
2353
|
+
draftRef.current = text
|
|
2354
|
+
return { ok: true, via: 'composer', detail: 'beforeinput' }
|
|
2355
|
+
}
|
|
2356
|
+
} catch (error) {
|
|
2357
|
+
console.warn('dsh-gallery: beforeinput 路径失败', error)
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
// 路径 1 失败后,重新取 before(可能 state 已被上面的动作部分改动)
|
|
2361
|
+
await waitFlush()
|
|
2362
|
+
const before2 = stateText(ed)
|
|
2363
|
+
|
|
2364
|
+
// ---- 路径 2:模拟 paste(成功即短路)----
|
|
2365
|
+
try {
|
|
2366
|
+
const dt = new DataTransfer()
|
|
2367
|
+
dt.setData('text/plain', text)
|
|
2368
|
+
dt.setData('text/html', '<p>' + text
|
|
2369
|
+
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
2370
|
+
.replace(/\n/g, '<br>') + '</p>')
|
|
2371
|
+
const ev = new ClipboardEvent('paste', { bubbles: true, cancelable: true })
|
|
2372
|
+
try { Object.defineProperty(ev, 'clipboardData', { value: dt, configurable: true }) } catch { /* 忽略 */ }
|
|
2373
|
+
el.dispatchEvent(ev)
|
|
2374
|
+
await waitFlush()
|
|
2375
|
+
const after2 = stateText(ed)
|
|
2376
|
+
if (after2.ok && after2.size > before2.size && after2.text.includes(probe)) {
|
|
2377
|
+
draftRef.current = text
|
|
2378
|
+
return { ok: true, via: 'composer', detail: 'paste' }
|
|
2379
|
+
}
|
|
2380
|
+
} catch (error) {
|
|
2381
|
+
console.warn('dsh-gallery: paste 路径失败', error)
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// ---- 路径 3:execCommand(仅最后兜底,同样等 flush 后判)----
|
|
2385
|
+
await waitFlush()
|
|
2386
|
+
const before3 = stateText(ed)
|
|
2387
|
+
try {
|
|
2388
|
+
document.execCommand('insertText', false, text)
|
|
2389
|
+
await waitFlush()
|
|
2390
|
+
const after3 = stateText(ed)
|
|
2391
|
+
if (after3.ok && after3.size > before3.size && after3.text.includes(probe)) {
|
|
2392
|
+
draftRef.current = text
|
|
2393
|
+
return { ok: true, via: 'composer', detail: 'execCommand' }
|
|
2394
|
+
}
|
|
2395
|
+
} catch (error) {
|
|
2396
|
+
console.warn('dsh-gallery: execCommand 路径失败', error)
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
// ---- 全部路径都没让 state 增长 ----
|
|
2400
|
+
// 最后复查一次:只有「长度接近 + 草稿头出现恰 1 次」才算成功。
|
|
2401
|
+
// 不能用 includes(probe) 就判 —— 半份写入也会通过(那是静默的数据污染)。
|
|
2402
|
+
await waitFlush()
|
|
2403
|
+
const finalState = stateText(ed)
|
|
2404
|
+
if (finalState.ok) {
|
|
2405
|
+
const headCount = headProbe === ''
|
|
2406
|
+
? 0
|
|
2407
|
+
: (finalState.text.split(headProbe).length - 1)
|
|
2408
|
+
const lengthClose = Math.abs(finalState.text.length - text.length) <= 8
|
|
2409
|
+
if (headCount === 1 && lengthClose) {
|
|
2410
|
+
draftRef.current = text
|
|
2411
|
+
return { ok: true, via: 'composer', detail: 'late-flush' }
|
|
2412
|
+
}
|
|
2413
|
+
if (headCount > 1) {
|
|
2414
|
+
// 出现多次 = 重复写入,这是数据污染,必须如实报失败
|
|
2415
|
+
console.warn('dsh-gallery: 检测到草稿重复写入 ' + headCount + ' 份')
|
|
2416
|
+
return { ok: false, via: 'failed', reason: 'duplicate-write-' + headCount }
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
// 真失败 → 剪贴板,notice 明确「未写入输入框」
|
|
2421
|
+
const copied = await copyText(text)
|
|
2422
|
+
draftRef.current = text
|
|
2423
|
+
return copied
|
|
2424
|
+
? { ok: false, via: 'clipboard', reason: 'all-dom-paths-failed' }
|
|
2425
|
+
: { ok: false, via: 'failed', reason: 'all-dom-paths-failed-copy-failed' }
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
/**
|
|
2429
|
+
* 反馈篮:一个受控组件,管理条目列表 + 生成草稿。
|
|
2430
|
+
*
|
|
2431
|
+
* @param t - 文案
|
|
2432
|
+
* @param items - 已标记条目(由 GalleryBody 传入,含 relPath / category / mark)
|
|
2433
|
+
* @param currentSessionId - 当前会话 id(用于判断「历史会话卡片禁止提交」)
|
|
2434
|
+
* @param targetSessionTitle - 目标会话标题(全局视图展示用)
|
|
2435
|
+
* @param onClose - 关闭
|
|
2436
|
+
* @param onRemove - 删除某条
|
|
2437
|
+
* @param onEdit - 编辑某条
|
|
2438
|
+
* @param onClear - 清空
|
|
2439
|
+
* @param onSubmitDraft - 生成草稿后的回调(用于提示)
|
|
2440
|
+
*/
|
|
2441
|
+
function FeedbackBasket({ t, items, currentSessionId, targetSessionTitle,
|
|
2442
|
+
onClose, onRemove, onEdit, onClear, onEditSave }) {
|
|
2443
|
+
// 语言判断:用 t 探测一个已知键 —— 命中中文就按 zh 渲染,否则 en。
|
|
2444
|
+
// (不引入 detectLocale,插件没有这个工具函数)
|
|
2445
|
+
const [locale] = React.useState(() => {
|
|
2446
|
+
try {
|
|
2447
|
+
const probe = t('feedbackBasketTitle')
|
|
2448
|
+
return (typeof probe === 'string' && /[\u4e00-\u9fa5]/.test(probe)) ? 'zh' : 'en'
|
|
2449
|
+
} catch { return 'zh' }
|
|
2450
|
+
})
|
|
2451
|
+
const [busy, setBusy] = React.useState(false)
|
|
2452
|
+
const [notice, setNotice] = React.useState(null)
|
|
2453
|
+
// 编辑弹窗:正在编辑的条目 + 三个字段的草稿值
|
|
2454
|
+
const [editing, setEditing] = React.useState(null)
|
|
2455
|
+
const [editReason, setEditReason] = React.useState('')
|
|
2456
|
+
const [editChangeOnly, setEditChangeOnly] = React.useState('')
|
|
2457
|
+
const [editKeep, setEditKeep] = React.useState('')
|
|
2458
|
+
|
|
2459
|
+
/** 打开编辑弹窗,把该条已有值填进去。 */
|
|
2460
|
+
const beginEdit = React.useCallback((it) => {
|
|
2461
|
+
setEditing(it)
|
|
2462
|
+
setEditReason(typeof it.mark?.reason === 'string' ? it.mark.reason : '')
|
|
2463
|
+
setEditChangeOnly(Array.isArray(it.mark?.changeOnly) ? it.mark.changeOnly.join(',') : '')
|
|
2464
|
+
setEditKeep(Array.isArray(it.mark?.keep) ? it.mark.keep.join(',') : '')
|
|
2465
|
+
}, [])
|
|
2466
|
+
|
|
2467
|
+
/** 保存编辑:逗号/中文逗号分隔 → 数组。 */
|
|
2468
|
+
const commitEdit = React.useCallback(() => {
|
|
2469
|
+
if (editing === null) return
|
|
2470
|
+
const splitList = (text) => String(text ?? '')
|
|
2471
|
+
.split(/[,,、;;]/)
|
|
2472
|
+
.map((x) => x.trim())
|
|
2473
|
+
.filter((x) => x !== '')
|
|
2474
|
+
const patch = {
|
|
2475
|
+
reason: editReason.trim() === '' ? undefined : editReason.trim(),
|
|
2476
|
+
changeOnly: splitList(editChangeOnly),
|
|
2477
|
+
keep: splitList(editKeep),
|
|
2478
|
+
}
|
|
2479
|
+
// 空数组不写进契约(避免草稿里出现空的「只改:」)
|
|
2480
|
+
if (patch.changeOnly.length === 0) delete patch.changeOnly
|
|
2481
|
+
if (patch.keep.length === 0) delete patch.keep
|
|
2482
|
+
if (typeof onEditSave === 'function') onEditSave(editing.relPath, patch)
|
|
2483
|
+
setEditing(null)
|
|
2484
|
+
}, [editing, editReason, editChangeOnly, editKeep, onEditSave])
|
|
2485
|
+
|
|
2486
|
+
// 历史会话判定:条目归属会话与当前会话不同 → 禁止提交
|
|
2487
|
+
const foreignItems = items.filter((it) => it.sessionId !== undefined
|
|
2488
|
+
&& it.sessionId !== '' && currentSessionId !== '' && it.sessionId !== currentSessionId)
|
|
2489
|
+
const canSubmit = items.length > 0 && foreignItems.length === 0 && busy === false
|
|
2490
|
+
|
|
2491
|
+
/** 生成草稿并写进 composer(不发送)。 */
|
|
2492
|
+
const generateDraft = React.useCallback(async () => {
|
|
2493
|
+
if (!canSubmit) return
|
|
2494
|
+
setBusy(true)
|
|
2495
|
+
setNotice(null)
|
|
2496
|
+
try {
|
|
2497
|
+
const feedback = makeFeedback({
|
|
2498
|
+
sessionId: currentSessionId,
|
|
2499
|
+
items: items.map((it) => ({
|
|
2500
|
+
relPath: it.relPath,
|
|
2501
|
+
category: it.category ?? 'unknown',
|
|
2502
|
+
action: it.mark?.action ?? 'approve',
|
|
2503
|
+
reason: it.mark?.reason,
|
|
2504
|
+
changeOnly: it.mark?.changeOnly,
|
|
2505
|
+
keep: it.mark?.keep,
|
|
2506
|
+
preserve: it.mark?.preserve,
|
|
2507
|
+
})),
|
|
2508
|
+
})
|
|
2509
|
+
const text = renderFeedbackText(feedback, { locale, targetSessionTitle })
|
|
2510
|
+
const result = await writeDraftToComposer(text, currentSessionId)
|
|
2511
|
+
if (result.ok) {
|
|
2512
|
+
setNotice({
|
|
2513
|
+
kind: result.via === 'composer' ? 'ok' : 'failed',
|
|
2514
|
+
text: result.via === 'composer'
|
|
2515
|
+
? t('feedbackDraftReady')
|
|
2516
|
+
: t('feedbackDraftInClipboard'),
|
|
2517
|
+
})
|
|
2518
|
+
} else {
|
|
2519
|
+
setNotice({ kind: 'failed', text: t('feedbackDraftFailed') })
|
|
2520
|
+
}
|
|
2521
|
+
} catch (error) {
|
|
2522
|
+
setNotice({ kind: 'failed', text: `${t('feedbackDraftFailed')}:${String(error?.message ?? error)}` })
|
|
2523
|
+
} finally {
|
|
2524
|
+
setBusy(false)
|
|
2525
|
+
}
|
|
2526
|
+
}, [canSubmit, items, currentSessionId, locale, targetSessionTitle, t])
|
|
2527
|
+
|
|
2528
|
+
return h('div', { className: 'dg-feedbackLayer', key: 'feedbackLayer' }, [
|
|
2529
|
+
h('div', {
|
|
2530
|
+
className: 'dg-feedback',
|
|
2531
|
+
key: 'panel',
|
|
2532
|
+
role: 'dialog',
|
|
2533
|
+
'aria-modal': false,
|
|
2534
|
+
'aria-label': t('feedbackBasketTitle'),
|
|
2535
|
+
'data-gallery-feedback-panel': true,
|
|
2536
|
+
}, [
|
|
2537
|
+
h('div', { className: 'dg-feedbackHead', key: 'head' }, [
|
|
2538
|
+
h('span', { className: 'dg-feedbackTitle', key: 'title' },
|
|
2539
|
+
format(t('feedbackBasketTitleN'), { n: items.length }),
|
|
2540
|
+
),
|
|
2541
|
+
h('button', {
|
|
2542
|
+
type: 'button', className: 'dg-btn', key: 'close',
|
|
2543
|
+
'aria-label': t('close'), onClick: onClose,
|
|
2544
|
+
}, '✕'),
|
|
2545
|
+
]),
|
|
2546
|
+
|
|
2547
|
+
// 目标会话提示(全局视图必须显式标)
|
|
2548
|
+
targetSessionTitle !== ''
|
|
2549
|
+
? h('div', { className: 'dg-feedbackTarget', key: 'target', 'data-gallery-feedback-target': targetSessionTitle },
|
|
2550
|
+
format(t('feedbackTargetSession'), { title: targetSessionTitle }))
|
|
2551
|
+
: null,
|
|
2552
|
+
|
|
2553
|
+
// 历史会话条目警告
|
|
2554
|
+
foreignItems.length > 0
|
|
2555
|
+
? h('div', { className: 'dg-feedbackWarn', key: 'foreign', 'data-gallery-feedback-foreign': foreignItems.length },
|
|
2556
|
+
format(t('feedbackForeignWarn'), { n: foreignItems.length }))
|
|
2557
|
+
: null,
|
|
2558
|
+
|
|
2559
|
+
items.length === 0
|
|
2560
|
+
? h('p', { className: 'dg-status', key: 'empty' }, t('feedbackBasketEmpty'))
|
|
2561
|
+
: h('ul', { className: 'dg-feedbackList', key: 'list' },
|
|
2562
|
+
items.map((it, idx) => {
|
|
2563
|
+
const actionDef = FEEDBACK_ACTIONS_UI.find((a) => a.id === it.mark?.action)
|
|
2564
|
+
const label = actionDef === undefined
|
|
2565
|
+
? (it.mark?.action ?? '')
|
|
2566
|
+
: (locale === 'en' ? actionDef.labelEn : actionDef.labelZh)
|
|
2567
|
+
return h('li', {
|
|
2568
|
+
className: 'dg-feedbackItem',
|
|
2569
|
+
key: it.relPath,
|
|
2570
|
+
'data-gallery-feedback-item': it.relPath,
|
|
2571
|
+
'data-gallery-feedback-no': idx + 1,
|
|
2572
|
+
}, [
|
|
2573
|
+
h('span', { className: 'dg-feedbackNo', key: 'n' }, String(idx + 1)),
|
|
2574
|
+
h('span', { className: 'dg-feedbackAction', key: 'a' }, label),
|
|
2575
|
+
h('span', { className: 'dg-feedbackName', key: 'name', title: it.relPath },
|
|
2576
|
+
it.relPath.split('/').pop() ?? it.relPath),
|
|
2577
|
+
(it.mark?.changeOnly !== undefined && it.mark.changeOnly.length > 0)
|
|
2578
|
+
? h('span', { className: 'dg-feedbackDim', key: 'co' },
|
|
2579
|
+
`${t('feedbackChangeOnly')}:${it.mark.changeOnly.join('/')}`)
|
|
2580
|
+
: null,
|
|
2581
|
+
h('span', { className: 'dg-feedbackOps', key: 'ops' }, [
|
|
2582
|
+
h('button', {
|
|
2583
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'edit',
|
|
2584
|
+
'data-gallery-feedback-edit': it.relPath,
|
|
2585
|
+
onClick: () => beginEdit(it),
|
|
2586
|
+
}, t('feedbackEdit')),
|
|
2587
|
+
h('button', {
|
|
2588
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'del',
|
|
2589
|
+
'data-gallery-feedback-remove': it.relPath,
|
|
2590
|
+
onClick: () => onRemove(it.relPath),
|
|
2591
|
+
}, '✕'),
|
|
2592
|
+
]),
|
|
2593
|
+
])
|
|
2594
|
+
}),
|
|
2595
|
+
),
|
|
2596
|
+
|
|
2597
|
+
notice === null
|
|
2598
|
+
? null
|
|
2599
|
+
: h('p', {
|
|
2600
|
+
className: `dg-status ${notice.kind === 'ok' ? 'dg-ok' : 'dg-error'}`,
|
|
2601
|
+
key: 'notice',
|
|
2602
|
+
'data-gallery-feedback-notice': notice.kind,
|
|
2603
|
+
}, notice.text),
|
|
2604
|
+
|
|
2605
|
+
// ---- 编辑弹窗(理由 / 只改 / 锁死)----
|
|
2606
|
+
editing === null
|
|
2607
|
+
? null
|
|
2608
|
+
: h('div', { className: 'dg-feedbackEdit', key: 'editForm', 'data-gallery-feedback-edit-form': editing.relPath }, [
|
|
2609
|
+
h('div', { className: 'dg-feedbackEditHead', key: 'h' },
|
|
2610
|
+
format(t('feedbackEditTitle'), { name: editing.relPath.split('/').pop() ?? editing.relPath }),
|
|
2611
|
+
),
|
|
2612
|
+
h('label', { className: 'dg-feedbackField', key: 'reason' }, [
|
|
2613
|
+
h('span', { className: 'dg-feedbackLabel', key: 'l' }, t('feedbackReasonLabel')),
|
|
2614
|
+
h('textarea', {
|
|
2615
|
+
className: 'dg-input dg-feedbackTextarea',
|
|
2616
|
+
key: 'in',
|
|
2617
|
+
rows: 2,
|
|
2618
|
+
value: editReason,
|
|
2619
|
+
placeholder: t('feedbackReasonPlaceholder'),
|
|
2620
|
+
'data-gallery-feedback-edit-reason': true,
|
|
2621
|
+
onChange: (event) => setEditReason(event.target.value),
|
|
2622
|
+
}),
|
|
2623
|
+
]),
|
|
2624
|
+
h('label', { className: 'dg-feedbackField', key: 'co' }, [
|
|
2625
|
+
h('span', { className: 'dg-feedbackLabel', key: 'l' }, t('feedbackChangeOnlyLabel')),
|
|
2626
|
+
h('input', {
|
|
2627
|
+
type: 'text',
|
|
2628
|
+
className: 'dg-input',
|
|
2629
|
+
key: 'in',
|
|
2630
|
+
value: editChangeOnly,
|
|
2631
|
+
placeholder: t('feedbackChangePlaceholder'),
|
|
2632
|
+
'data-gallery-feedback-edit-change': true,
|
|
2633
|
+
onChange: (event) => setEditChangeOnly(event.target.value),
|
|
2634
|
+
}),
|
|
2635
|
+
]),
|
|
2636
|
+
h('label', { className: 'dg-feedbackField', key: 'keep' }, [
|
|
2637
|
+
h('span', { className: 'dg-feedbackLabel', key: 'l' }, t('feedbackKeepLabel')),
|
|
2638
|
+
h('input', {
|
|
2639
|
+
type: 'text',
|
|
2640
|
+
className: 'dg-input',
|
|
2641
|
+
key: 'in',
|
|
2642
|
+
value: editKeep,
|
|
2643
|
+
placeholder: t('feedbackKeepPlaceholder'),
|
|
2644
|
+
'data-gallery-feedback-edit-keep': true,
|
|
2645
|
+
onChange: (event) => setEditKeep(event.target.value),
|
|
2646
|
+
}),
|
|
2647
|
+
]),
|
|
2648
|
+
h('div', { className: 'dg-feedbackEditActions', key: 'acts' }, [
|
|
2649
|
+
h('button', {
|
|
2650
|
+
type: 'button', className: 'dg-btn', key: 'cancel',
|
|
2651
|
+
'data-gallery-feedback-edit-cancel': true,
|
|
2652
|
+
onClick: () => setEditing(null),
|
|
2653
|
+
}, t('cancel')),
|
|
2654
|
+
h('button', {
|
|
2655
|
+
type: 'button', className: 'dg-btn dg-primaryBtn', key: 'save',
|
|
2656
|
+
'data-gallery-feedback-edit-save': true,
|
|
2657
|
+
onClick: commitEdit,
|
|
2658
|
+
}, t('feedbackEditSave')),
|
|
2659
|
+
]),
|
|
2660
|
+
]),
|
|
2661
|
+
|
|
2662
|
+
h('div', { className: 'dg-feedbackActions', key: 'actions' }, [
|
|
2663
|
+
h('button', {
|
|
2664
|
+
type: 'button', className: 'dg-btn', key: 'clear',
|
|
2665
|
+
'data-gallery-feedback-clear': true,
|
|
2666
|
+
disabled: busy || items.length === 0,
|
|
2667
|
+
onClick: onClear,
|
|
2668
|
+
}, t('feedbackClear')),
|
|
2669
|
+
h('button', {
|
|
2670
|
+
type: 'button', className: 'dg-btn dg-primaryBtn', key: 'submit',
|
|
2671
|
+
'data-gallery-feedback-generate': true,
|
|
2672
|
+
disabled: !canSubmit,
|
|
2673
|
+
title: foreignItems.length > 0 ? t('feedbackForeignWarnShort') : t('feedbackGenerateHint'),
|
|
2674
|
+
onClick: () => { void generateDraft() },
|
|
2675
|
+
}, busy
|
|
2676
|
+
? t('feedbackGenerating')
|
|
2677
|
+
// 禁用时直接把原因写在按钮上,不只靠悬停 title
|
|
2678
|
+
: foreignItems.length > 0
|
|
2679
|
+
? t('feedbackBlockedForeign')
|
|
2680
|
+
: items.length === 0
|
|
2681
|
+
? t('feedbackBlockedEmpty')
|
|
2682
|
+
: t('feedbackGenerateDraft')),
|
|
2683
|
+
]),
|
|
2684
|
+
]),
|
|
2685
|
+
])
|
|
2686
|
+
}
|
|
2687
|
+
|
|
1654
2688
|
function ContextMenu({ t, x, y, item, actions, onClose }) {
|
|
1655
2689
|
const menuRef = React.useRef(null)
|
|
1656
2690
|
const [pos, setPos] = React.useState({ left: x, top: y })
|
|
@@ -1721,6 +2755,32 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
1721
2755
|
entry('reveal', t('ctxReveal'), '📂', () => actions.onReveal()),
|
|
1722
2756
|
entry('copy', t('ctxCopy'), '⧉', () => actions.onCopy()),
|
|
1723
2757
|
entry('delete', t('ctxDelete'), '🗑', () => actions.onDelete(), true),
|
|
2758
|
+
// ---- 反馈标记(S3-a):6 个动作,选中后进反馈篮,不直接发送 ----
|
|
2759
|
+
actions.onMark !== undefined
|
|
2760
|
+
? h('div', { className: 'dg-ctxDivider', key: 'markDivider' }, t('ctxMarkSection'))
|
|
2761
|
+
: null,
|
|
2762
|
+
actions.onMark !== undefined
|
|
2763
|
+
? entry('mark-approve', t('ctxMarkApprove'), '✓', () => actions.onMark('approve'))
|
|
2764
|
+
: null,
|
|
2765
|
+
actions.onMark !== undefined
|
|
2766
|
+
? entry('mark-reject', t('ctxMarkReject'), '✕', () => actions.onMark('reject'))
|
|
2767
|
+
: null,
|
|
2768
|
+
actions.onMark !== undefined
|
|
2769
|
+
? entry('mark-finalize', t('ctxMarkFinalize'), '★', () => actions.onMark('finalize'))
|
|
2770
|
+
: null,
|
|
2771
|
+
// v0.13.7:已确认的卡片给出「取消确认」,退回待确认
|
|
2772
|
+
actions.onUnconfirm !== undefined && actions.confirmed === true
|
|
2773
|
+
? entry('mark-unconfirm', t('ctxMarkUnconfirm'), '☆', () => actions.onUnconfirm())
|
|
2774
|
+
: null,
|
|
2775
|
+
actions.onMark !== undefined
|
|
2776
|
+
? entry('mark-redo', t('ctxMarkRedo'), '↻', () => actions.onMark('redo-one-dim'))
|
|
2777
|
+
: null,
|
|
2778
|
+
actions.onMark !== undefined
|
|
2779
|
+
? entry('mark-regen', t('ctxMarkRegen'), '⟳', () => actions.onMark('regenerate-selected'))
|
|
2780
|
+
: null,
|
|
2781
|
+
actions.onMark !== undefined
|
|
2782
|
+
? entry('mark-ref', t('ctxMarkReference'), '◎', () => actions.onMark('set-reference'))
|
|
2783
|
+
: null,
|
|
1724
2784
|
]))
|
|
1725
2785
|
}
|
|
1726
2786
|
|
|
@@ -1871,6 +2931,7 @@ const AUDIO_EXTS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.oga', '.o
|
|
|
1871
2931
|
tabIndex: 0,
|
|
1872
2932
|
title: `${item.name}\n${absPath}\n${t('mediaOpenHint')}`,
|
|
1873
2933
|
'data-gallery-media': item.relPath,
|
|
2934
|
+
'data-gallery-relpath': item.relPath,
|
|
1874
2935
|
'data-gallery-media-type': item.mediaType ?? '',
|
|
1875
2936
|
onClick: () => onPlay(item),
|
|
1876
2937
|
onContextMenu: (event) => {
|
|
@@ -2272,6 +3333,7 @@ ${absPath}
|
|
|
2272
3333
|
}
|
|
2273
3334
|
},
|
|
2274
3335
|
'data-gallery-file': item.relPath,
|
|
3336
|
+
'data-gallery-relpath': item.relPath,
|
|
2275
3337
|
}, [
|
|
2276
3338
|
// ① 头部
|
|
2277
3339
|
h('div', { className: 'dg-fcHead', key: 'head' }, [
|
|
@@ -2375,6 +3437,7 @@ ${absPath}
|
|
|
2375
3437
|
className: `dg-card dg-cat-${item.category || 'none'}`,
|
|
2376
3438
|
title: `${item.relPath}${item.category ? `\n[${t('cat' + item.category[0].toUpperCase() + item.category.slice(1))}]` : ''}`,
|
|
2377
3439
|
'data-gallery-card': item.relPath,
|
|
3440
|
+
'data-gallery-relpath': item.relPath,
|
|
2378
3441
|
'data-gallery-category': item.category || '',
|
|
2379
3442
|
onClick: (event) => onOpen(item, event.currentTarget),
|
|
2380
3443
|
onContextMenu: (event) => {
|
|
@@ -3299,6 +4362,33 @@ ${absPath}
|
|
|
3299
4362
|
const groupsInitRef = React.useRef(false)
|
|
3300
4363
|
// 全局分组:哪些组显示了中间产物
|
|
3301
4364
|
const [showInterim, setShowInterim] = React.useState({})
|
|
4365
|
+
/**
|
|
4366
|
+
* 分类显隐开关(v0.13.7)。
|
|
4367
|
+
*
|
|
4368
|
+
* 只记本次使用:不持久化,重开面板 / 重启回全显示。
|
|
4369
|
+
* 理由:用户若忘了自己关过哪一类,会以为文件丢了 —— 每次从全显示开始最不容易误解。
|
|
4370
|
+
*
|
|
4371
|
+
* 键:
|
|
4372
|
+
* finalConfirmed —— 最终交付·已确认(确认态,见 3.2)
|
|
4373
|
+
* finalPending —— 最终交付·待确认
|
|
4374
|
+
* input —— 输入素材
|
|
4375
|
+
* intermediate —— 中间产物(与组内开关同源)
|
|
4376
|
+
* unknown —— 未归类
|
|
4377
|
+
*/
|
|
4378
|
+
const [categoryFilter, setCategoryFilter] = React.useState({
|
|
4379
|
+
finalConfirmed: true,
|
|
4380
|
+
finalPending: true,
|
|
4381
|
+
input: true,
|
|
4382
|
+
intermediate: true,
|
|
4383
|
+
unknown: true,
|
|
4384
|
+
})
|
|
4385
|
+
/** 批量选择(v0.13.7):选中的 relPath 集合。清空条件:切 kind / 切 scope / 刷新后失效项自动剔除。 */
|
|
4386
|
+
const [selected, setSelected] = React.useState(new Set())
|
|
4387
|
+
/** 批量模式:用户显式开启,或已有选中项时自动生效(避免勾了看不见批量条)。 */
|
|
4388
|
+
const [batchMode, setBatchMode] = React.useState(false)
|
|
4389
|
+
const selectMode = batchMode || selected.size > 0
|
|
4390
|
+
/** 清废稿确认对话框:null=关闭;{ phase:'list'|'deleting', files, digest, count } */
|
|
4391
|
+
const [discardDialog, setDiscardDialog] = React.useState(null)
|
|
3302
4392
|
const toggleGroup = React.useCallback((key) => {
|
|
3303
4393
|
setOpenGroups((prev) => {
|
|
3304
4394
|
const next = new Set(prev)
|
|
@@ -3314,12 +4404,209 @@ ${absPath}
|
|
|
3314
4404
|
const [ctxMenu, setCtxMenu] = React.useState(null)
|
|
3315
4405
|
// 删除确认:{ item, busy }
|
|
3316
4406
|
const [deleteTarget, setDeleteTarget] = React.useState(null)
|
|
4407
|
+
// ---- 反馈标记(S3-a)----
|
|
4408
|
+
// marks: { [relPath]: { action, reason?, changeOnly?, keep? } }
|
|
4409
|
+
const [marks, setMarks] = React.useState({})
|
|
4410
|
+
// 反馈篮是否打开
|
|
4411
|
+
const [basketOpen, setBasketOpen] = React.useState(false)
|
|
4412
|
+
// 编辑中的条目(null 表示不编辑)
|
|
4413
|
+
const [editingItem, setEditingItem] = React.useState(null)
|
|
3317
4414
|
// 网格滚动位置:打开查看器前记录,关闭后恢复,让视图停在原缩略图处
|
|
3318
4415
|
const bodyScrollRef = React.useRef(null)
|
|
3319
4416
|
const savedScrollRef = React.useRef(null)
|
|
3320
4417
|
|
|
4418
|
+
// 首次挂载时拉取已有标记(持久化在 dsh-gallery-marks.json)
|
|
4419
|
+
React.useEffect(() => {
|
|
4420
|
+
let alive = true
|
|
4421
|
+
callHost('getMarks', {})
|
|
4422
|
+
.then((payload) => {
|
|
4423
|
+
if (!alive) return
|
|
4424
|
+
if (payload?.ok === false) return
|
|
4425
|
+
if (payload !== null && typeof payload.marks === 'object' && payload.marks !== null) {
|
|
4426
|
+
setMarks(payload.marks)
|
|
4427
|
+
}
|
|
4428
|
+
})
|
|
4429
|
+
.catch((error) => console.warn('dsh-gallery: getMarks 失败', error))
|
|
4430
|
+
return () => { alive = false }
|
|
4431
|
+
}, [])
|
|
4432
|
+
|
|
4433
|
+
/**
|
|
4434
|
+
* 给某卡片设标记 → 进反馈篮。
|
|
4435
|
+
* 只改本地状态 + 落盘 marks,**绝不发送任何消息**。
|
|
4436
|
+
*/
|
|
4437
|
+
/**
|
|
4438
|
+
* 卡片的「确认态」—— 唯一真源是 marks 里的 confirmed 字段(v0.13.7)。
|
|
4439
|
+
*
|
|
4440
|
+
* **数据边界(最要紧)**:确认态只读标记文件,绝不读 / 写自动分类。
|
|
4441
|
+
* 分类是机器猜的、会随 5 秒刷新变;判断是人给的、必须留得住。
|
|
4442
|
+
*/
|
|
4443
|
+
const isConfirmed = React.useCallback((relPath) => {
|
|
4444
|
+
return marks[relPath]?.confirmed === true
|
|
4445
|
+
}, [marks])
|
|
4446
|
+
|
|
4447
|
+
/**
|
|
4448
|
+
* 卡片的分类分组(用于顶部开关筛选):
|
|
4449
|
+
* finalConfirmed / finalPending / input / intermediate / unknown
|
|
4450
|
+
*
|
|
4451
|
+
* 注意「最终交付」拆两态:靠确认态区分,不靠自动分类的 final。
|
|
4452
|
+
* 一张 final 的卡片若没确认 → finalPending;确认了 → finalConfirmed。
|
|
4453
|
+
*/
|
|
4454
|
+
const bucketOf = React.useCallback((file) => {
|
|
4455
|
+
if (isConfirmed(file.relPath)) return 'finalConfirmed'
|
|
4456
|
+
if (file.category === 'final') return 'finalPending'
|
|
4457
|
+
if (file.category === 'input') return 'input'
|
|
4458
|
+
if (file.category === 'intermediate') return 'intermediate'
|
|
4459
|
+
return 'unknown'
|
|
4460
|
+
}, [isConfirmed])
|
|
4461
|
+
|
|
4462
|
+
/** 切一个分类的显隐。 */
|
|
4463
|
+
const toggleCategory = React.useCallback((key) => {
|
|
4464
|
+
setCategoryFilter((prev) => ({ ...prev, [key]: !prev[key] }))
|
|
4465
|
+
}, [])
|
|
4466
|
+
|
|
4467
|
+
/** 批量选择切换。 */
|
|
4468
|
+
const toggleSelect = React.useCallback((relPath) => {
|
|
4469
|
+
setSelected((prev) => {
|
|
4470
|
+
const next = new Set(prev)
|
|
4471
|
+
if (next.has(relPath)) next.delete(relPath)
|
|
4472
|
+
else next.add(relPath)
|
|
4473
|
+
return next
|
|
4474
|
+
})
|
|
4475
|
+
}, [])
|
|
4476
|
+
|
|
4477
|
+
/** 批量:确认 / 取消确认 / 清除标记(只改标记,不碰磁盘)。 */
|
|
4478
|
+
const batchMark = React.useCallback(async (action) => {
|
|
4479
|
+
const paths = [...selected]
|
|
4480
|
+
if (paths.length === 0) return
|
|
4481
|
+
const updates = paths.map((p) => ({
|
|
4482
|
+
path: p,
|
|
4483
|
+
// 确认:保留原有 action,加 confirmed:true
|
|
4484
|
+
// 取消确认:去掉 confirmed
|
|
4485
|
+
// 清除:整条删掉
|
|
4486
|
+
mark: action === 'clear'
|
|
4487
|
+
? null
|
|
4488
|
+
: action === 'confirm'
|
|
4489
|
+
? { ...(marks[p] ?? { action: 'finalize' }), confirmed: true }
|
|
4490
|
+
: (() => {
|
|
4491
|
+
const cur = marks[p]
|
|
4492
|
+
if (cur === undefined) return null
|
|
4493
|
+
const next = { ...cur }
|
|
4494
|
+
delete next.confirmed
|
|
4495
|
+
// 若原来只为确认而建的 finalize 标记,取消后整条删掉
|
|
4496
|
+
if (next.action === 'finalize' && Object.keys(next).filter((k) => k !== 'action' && k !== 'markedAt').length === 0) {
|
|
4497
|
+
return null
|
|
4498
|
+
}
|
|
4499
|
+
return next
|
|
4500
|
+
})(),
|
|
4501
|
+
}))
|
|
4502
|
+
// 本地先行(乐观更新)
|
|
4503
|
+
setMarks((prev) => {
|
|
4504
|
+
const next = { ...prev }
|
|
4505
|
+
for (const u of updates) {
|
|
4506
|
+
if (u.mark === null) delete next[u.path]
|
|
4507
|
+
else next[u.path] = u.mark
|
|
4508
|
+
}
|
|
4509
|
+
return next
|
|
4510
|
+
})
|
|
4511
|
+
try {
|
|
4512
|
+
const payload = await callHost('marksBatch', { updates })
|
|
4513
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
|
|
4514
|
+
if (payload?.marks !== undefined) setMarks(payload.marks)
|
|
4515
|
+
} catch (error) {
|
|
4516
|
+
console.warn('dsh-gallery: 批量标记失败', error)
|
|
4517
|
+
}
|
|
4518
|
+
setSelected(new Set())
|
|
4519
|
+
}, [selected, marks, t])
|
|
4520
|
+
|
|
4521
|
+
const doMark = React.useCallback(async (item, action, extra) => {
|
|
4522
|
+
/**
|
|
4523
|
+
* v0.13.7:`finalize` = 「定为最终版」要写成**持久确认态**。
|
|
4524
|
+
*
|
|
4525
|
+
* confirmed 字段是唯一真源:存进 marks 文件,刷新 / 重扫 / 切会话 / 重启都在。
|
|
4526
|
+
* **绝不回写自动分类** —— 分类是机器猜的会变,判断是人给的必须留得住。
|
|
4527
|
+
*/
|
|
4528
|
+
const mark = { action, ...(extra ?? {}), ...(action === 'finalize' ? { confirmed: true } : {}) }
|
|
4529
|
+
setMarks((prev) => ({ ...prev, [item.relPath]: mark }))
|
|
4530
|
+
setBasketOpen(true)
|
|
4531
|
+
try {
|
|
4532
|
+
const payload = await callHost('marks', { path: item.relPath, mark })
|
|
4533
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
|
|
4534
|
+
} catch (error) {
|
|
4535
|
+
console.warn('dsh-gallery: 标记落盘失败', error)
|
|
4536
|
+
}
|
|
4537
|
+
}, [t])
|
|
4538
|
+
|
|
4539
|
+
/**
|
|
4540
|
+
* 更新一条标记的附加字段(理由 / 只改 / 锁死)。
|
|
4541
|
+
* 供反馈篮的编辑弹窗调用 —— 让调研结论 4(显式只改 + 其余锁死)真正可填。
|
|
4542
|
+
*/
|
|
4543
|
+
const updateMark = React.useCallback(async (relPath, patch) => {
|
|
4544
|
+
let nextMark = null
|
|
4545
|
+
setMarks((prev) => {
|
|
4546
|
+
const cur = prev[relPath]
|
|
4547
|
+
if (cur === undefined) return prev
|
|
4548
|
+
nextMark = { ...cur, ...patch }
|
|
4549
|
+
return { ...prev, [relPath]: nextMark }
|
|
4550
|
+
})
|
|
4551
|
+
if (nextMark !== null) {
|
|
4552
|
+
try {
|
|
4553
|
+
await callHost('marks', { path: relPath, mark: nextMark })
|
|
4554
|
+
} catch (error) {
|
|
4555
|
+
console.warn('dsh-gallery: 更新标记失败', error)
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
}, [])
|
|
4559
|
+
|
|
4560
|
+
/** 取消确认(v0.13.7):把 confirmed 去掉,退回「待确认」。 */
|
|
4561
|
+
const unconfirmOne = React.useCallback(async (relPath) => {
|
|
4562
|
+
const cur = marks[relPath]
|
|
4563
|
+
if (cur === undefined) return
|
|
4564
|
+
const next = { ...cur }
|
|
4565
|
+
delete next.confirmed
|
|
4566
|
+
const cleaned = (next.action === 'finalize' &&
|
|
4567
|
+
Object.keys(next).filter((k) => k !== 'action' && k !== 'markedAt').length === 0)
|
|
4568
|
+
? null
|
|
4569
|
+
: next
|
|
4570
|
+
setMarks((prev) => {
|
|
4571
|
+
const n = { ...prev }
|
|
4572
|
+
if (cleaned === null) delete n[relPath]
|
|
4573
|
+
else n[relPath] = cleaned
|
|
4574
|
+
return n
|
|
4575
|
+
})
|
|
4576
|
+
try {
|
|
4577
|
+
await callHost('marks', { path: relPath, mark: cleaned })
|
|
4578
|
+
} catch (error) {
|
|
4579
|
+
console.warn('dsh-gallery: 取消确认失败', error)
|
|
4580
|
+
}
|
|
4581
|
+
}, [marks])
|
|
4582
|
+
|
|
4583
|
+
/** 移除一条标记。 */
|
|
4584
|
+
const removeMark = React.useCallback(async (relPath) => {
|
|
4585
|
+
setMarks((prev) => {
|
|
4586
|
+
const next = { ...prev }
|
|
4587
|
+
delete next[relPath]
|
|
4588
|
+
return next
|
|
4589
|
+
})
|
|
4590
|
+
try {
|
|
4591
|
+
await callHost('marks', { path: relPath, mark: null })
|
|
4592
|
+
} catch (error) {
|
|
4593
|
+
console.warn('dsh-gallery: 清除标记失败', error)
|
|
4594
|
+
}
|
|
4595
|
+
}, [])
|
|
4596
|
+
|
|
4597
|
+
/** 清空全部标记。 */
|
|
4598
|
+
const clearMarks = React.useCallback(async () => {
|
|
4599
|
+
const paths = Object.keys(marks)
|
|
4600
|
+
setMarks({})
|
|
4601
|
+
for (const relPath of paths) {
|
|
4602
|
+
try { await callHost('marks', { path: relPath, mark: null }) } catch { /* 忽略单条失败 */ }
|
|
4603
|
+
}
|
|
4604
|
+
}, [marks])
|
|
4605
|
+
|
|
3321
4606
|
/** 打开右键菜单。 */
|
|
3322
4607
|
const openContextMenu = React.useCallback((item, absPath, event) => {
|
|
4608
|
+
// seam 兜底:记下最近右键的卡片,供独立包 getSelection() 用
|
|
4609
|
+
lastContextRelPath.current = item.relPath
|
|
3323
4610
|
setCtxMenu({
|
|
3324
4611
|
item,
|
|
3325
4612
|
absPath: absPath ?? buildAbsPath(view.status === 'ready' ? view.data.root : '', item.relPath),
|
|
@@ -3605,31 +4892,245 @@ ${absPath}
|
|
|
3605
4892
|
|
|
3606
4893
|
// 分类图例:告诉用户三种边框颜色代表什么(只在有数据时显示)
|
|
3607
4894
|
// 「未归类」只有在确实存在这类文件时才显示,避免图例噪音
|
|
4895
|
+
// 反馈篮独立入口(S3-a):关闭后能重新打开,不必再标记一张卡
|
|
4896
|
+
const markedCount = Object.keys(marks).length
|
|
4897
|
+
const basketToggle = h('button', {
|
|
4898
|
+
type: 'button',
|
|
4899
|
+
className: 'dg-btn dg-basketToggle',
|
|
4900
|
+
key: 'basketToggle',
|
|
4901
|
+
'data-gallery-open-basket': true,
|
|
4902
|
+
'data-gallery-basket-count': markedCount,
|
|
4903
|
+
title: t('feedbackBasketToggleHint'),
|
|
4904
|
+
'aria-label': t('feedbackBasketToggleHint'),
|
|
4905
|
+
onClick: () => setBasketOpen((v) => !v),
|
|
4906
|
+
}, markedCount > 0
|
|
4907
|
+
? format(t('feedbackBasketToggleN'), { n: markedCount })
|
|
4908
|
+
: t('feedbackBasketToggle'))
|
|
4909
|
+
|
|
4910
|
+
/**
|
|
4911
|
+
* 各分类的全局计数(供顶部开关显示数字 + 判断「已显示 N / 共 M」)。
|
|
4912
|
+
* v0.13.7:确认态计数来自 marks,不来自自动分类。
|
|
4913
|
+
*/
|
|
4914
|
+
const catCounts = React.useMemo(() => {
|
|
4915
|
+
const c = { finalConfirmed: 0, finalPending: 0, input: 0, intermediate: 0, unknown: 0 }
|
|
4916
|
+
for (const it of items) {
|
|
4917
|
+
const b = bucketOf(it)
|
|
4918
|
+
if (Object.prototype.hasOwnProperty.call(c, b)) c[b] += 1
|
|
4919
|
+
}
|
|
4920
|
+
return c
|
|
4921
|
+
}, [items, bucketOf])
|
|
4922
|
+
const confirmedCount = catCounts.finalConfirmed
|
|
4923
|
+
const pendingCount = catCounts.finalPending
|
|
4924
|
+
const inputCount = catCounts.input
|
|
4925
|
+
const interimCount = catCounts.intermediate
|
|
4926
|
+
const unknownCount = catCounts.unknown
|
|
4927
|
+
|
|
4928
|
+
/** 按当前开关过滤后的可见文件数(供「已显示 N / 共 M」)。 */
|
|
4929
|
+
const visibleStats = React.useMemo(() => {
|
|
4930
|
+
let shown = 0
|
|
4931
|
+
let total = 0
|
|
4932
|
+
for (const it of items) {
|
|
4933
|
+
total += 1
|
|
4934
|
+
if (categoryFilter[bucketOf(it)] !== false) shown += 1
|
|
4935
|
+
}
|
|
4936
|
+
return { shown, total }
|
|
4937
|
+
}, [items, categoryFilter, bucketOf])
|
|
4938
|
+
|
|
3608
4939
|
const hasUnknown = data !== null && Array.isArray(data.groups) &&
|
|
3609
4940
|
data.groups.some((gr) => (gr.counts?.unknown ?? 0) > 0)
|
|
4941
|
+
/**
|
|
4942
|
+
* 分类开关(v0.13.7):原来只是说明色块,现在可点。
|
|
4943
|
+
*
|
|
4944
|
+
* 规则:
|
|
4945
|
+
* · 彩色 = 显示,灰色 = 不显示
|
|
4946
|
+
* · 只有「最终交付」拆两态(已确认 / 待确认);其余五种表态不进这里
|
|
4947
|
+
* · 「未归类」只在确实存在时出现
|
|
4948
|
+
* · 只记本次使用,不持久化
|
|
4949
|
+
*/
|
|
4950
|
+
const filterToggle = (key, label, swatchClass, count, alwaysShow) => {
|
|
4951
|
+
const on = categoryFilter[key] !== false
|
|
4952
|
+
if (!on && !alwaysShow && count === 0) return null
|
|
4953
|
+
return h('button', {
|
|
4954
|
+
type: 'button',
|
|
4955
|
+
key: 'tog:' + key,
|
|
4956
|
+
className: `dg-legendItem dg-legendToggle${on ? '' : ' dg-legendOff'}`,
|
|
4957
|
+
'data-gallery-filter': key,
|
|
4958
|
+
'data-gallery-filter-on': on ? '1' : '0',
|
|
4959
|
+
title: on ? format(t('filterHideHint'), { label }) : format(t('filterShowHint'), { label }),
|
|
4960
|
+
onClick: () => toggleCategory(key),
|
|
4961
|
+
}, [
|
|
4962
|
+
h('span', { className: `dg-legendSwatch ${swatchClass}`, key: 's' }),
|
|
4963
|
+
h('span', { key: 'l' }, label),
|
|
4964
|
+
count > 0 ? h('span', { className: 'dg-legendCount', key: 'n' }, String(count)) : null,
|
|
4965
|
+
])
|
|
4966
|
+
}
|
|
4967
|
+
|
|
3610
4968
|
const legend = data !== null && items.length > 0
|
|
3611
|
-
? h('div', { className: 'dg-legend', key: 'legend',
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
h('span', { className: 'dg-legendItem', key: 'm' }, [
|
|
3621
|
-
h('span', { className: 'dg-legendSwatch dg-legendSwatch-intermediate', key: 's' }),
|
|
3622
|
-
h('span', { key: 'l' }, t('catLegendIntermediate')),
|
|
3623
|
-
]),
|
|
4969
|
+
? h('div', { className: 'dg-legend', key: 'legend', 'data-gallery-filterbar': true }, [
|
|
4970
|
+
// 最终交付 · 已确认
|
|
4971
|
+
filterToggle('finalConfirmed', t('catFilterFinalConfirmed'),
|
|
4972
|
+
'dg-legendSwatch-final', confirmedCount, true),
|
|
4973
|
+
// 最终交付 · 待确认
|
|
4974
|
+
filterToggle('finalPending', t('catFilterFinalPending'),
|
|
4975
|
+
'dg-legendSwatch-final dg-legendSwatchPending', pendingCount, true),
|
|
4976
|
+
filterToggle('input', t('catLegendInput'), 'dg-legendSwatch-input', inputCount, true),
|
|
4977
|
+
filterToggle('intermediate', t('catLegendIntermediate'), 'dg-legendSwatch-intermediate', interimCount, true),
|
|
3624
4978
|
hasUnknown
|
|
3625
|
-
?
|
|
3626
|
-
h('span', { className: 'dg-legendSwatch dg-legendSwatch-unknown', key: 's' }),
|
|
3627
|
-
h('span', { key: 'l' }, t('catLegendUnknown')),
|
|
3628
|
-
])
|
|
4979
|
+
? filterToggle('unknown', t('catLegendUnknown'), 'dg-legendSwatch-unknown', unknownCount, true)
|
|
3629
4980
|
: null,
|
|
3630
4981
|
])
|
|
3631
4982
|
: null
|
|
3632
4983
|
|
|
4984
|
+
/**
|
|
4985
|
+
* 批量操作条(v0.13.7)—— 有选中项时出现。
|
|
4986
|
+
* 三个动作:确认 / 取消确认 / 清除标记,**全部只改标记、不碰磁盘**。
|
|
4987
|
+
*/
|
|
4988
|
+
const selectedCount = selected.size
|
|
4989
|
+
const batchBar = selectedCount > 0
|
|
4990
|
+
? h('div', { className: 'dg-batchBar', key: 'batchBar', 'data-gallery-batch-bar': true }, [
|
|
4991
|
+
h('span', { className: 'dg-batchCount', key: 'n' }, format(t('batchBarTitle'), { n: selectedCount })),
|
|
4992
|
+
h('div', { className: 'dg-batchOps', key: 'ops' }, [
|
|
4993
|
+
h('button', {
|
|
4994
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'confirm',
|
|
4995
|
+
'data-gallery-batch-confirm': true,
|
|
4996
|
+
title: t('batchHintConfirm'),
|
|
4997
|
+
onClick: () => { void batchMark('confirm') },
|
|
4998
|
+
}, t('batchConfirm')),
|
|
4999
|
+
h('button', {
|
|
5000
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'unconfirm',
|
|
5001
|
+
'data-gallery-batch-unconfirm': true,
|
|
5002
|
+
onClick: () => { void batchMark('unconfirm') },
|
|
5003
|
+
}, t('batchUnconfirm')),
|
|
5004
|
+
h('button', {
|
|
5005
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearmark',
|
|
5006
|
+
'data-gallery-batch-clear': true,
|
|
5007
|
+
title: t('batchHintClearMark'),
|
|
5008
|
+
onClick: () => { void batchMark('clear') },
|
|
5009
|
+
}, t('batchClearMark')),
|
|
5010
|
+
h('button', {
|
|
5011
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearSel',
|
|
5012
|
+
'data-gallery-batch-clearsel': true,
|
|
5013
|
+
onClick: () => { setSelected(new Set()); setBatchMode(false) },
|
|
5014
|
+
}, t('batchClearSelection')),
|
|
5015
|
+
]),
|
|
5016
|
+
])
|
|
5017
|
+
: null
|
|
5018
|
+
|
|
5019
|
+
/**
|
|
5020
|
+
* 「清掉废稿」入口(v0.13.7)—— 只在确实有 reject 标记时出现。
|
|
5021
|
+
* 这是**唯一会碰磁盘**的批量动作,走独立两阶段确认。
|
|
5022
|
+
*/
|
|
5023
|
+
const discardPaths = React.useMemo(
|
|
5024
|
+
() => Object.keys(marks).filter((rp) => marks[rp]?.action === 'reject'),
|
|
5025
|
+
[marks],
|
|
5026
|
+
)
|
|
5027
|
+
const discardEntry = discardPaths.length > 0
|
|
5028
|
+
? h('button', {
|
|
5029
|
+
type: 'button',
|
|
5030
|
+
className: 'dg-btn dg-btnSmall dg-dangerBtn',
|
|
5031
|
+
key: 'discardEntry',
|
|
5032
|
+
'data-gallery-discard-entry': true,
|
|
5033
|
+
'data-gallery-discard-count': discardPaths.length,
|
|
5034
|
+
title: t('discardEntryHint'),
|
|
5035
|
+
onClick: () => { void openDiscardDialog() },
|
|
5036
|
+
}, format(t('discardEntry'), { n: discardPaths.length }))
|
|
5037
|
+
: null
|
|
5038
|
+
|
|
5039
|
+
/** 打开删除确认:先向 Host 要清单(dryRun,不动磁盘)。 */
|
|
5040
|
+
const openDiscardDialog = React.useCallback(async () => {
|
|
5041
|
+
try {
|
|
5042
|
+
const payload = await callHost('deleteDiscarded', { paths: discardPaths, dryRun: true })
|
|
5043
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? t('errorTitle'))
|
|
5044
|
+
setDiscardDialog({
|
|
5045
|
+
phase: 'list',
|
|
5046
|
+
files: payload?.files ?? [],
|
|
5047
|
+
digest: payload?.digest ?? '',
|
|
5048
|
+
count: payload?.count ?? 0,
|
|
5049
|
+
rejected: payload?.rejected ?? [],
|
|
5050
|
+
})
|
|
5051
|
+
} catch (error) {
|
|
5052
|
+
console.error('dsh-gallery: 取删除清单失败', error)
|
|
5053
|
+
}
|
|
5054
|
+
}, [discardPaths, t])
|
|
5055
|
+
|
|
5056
|
+
/** 真正执行删除(两阶段第二段)。 */
|
|
5057
|
+
const runDiscard = React.useCallback(async () => {
|
|
5058
|
+
if (discardDialog === null) return
|
|
5059
|
+
if (discardDialog.count > 10) return
|
|
5060
|
+
setDiscardDialog((prev) => (prev === null ? null : { ...prev, phase: 'deleting' }))
|
|
5061
|
+
try {
|
|
5062
|
+
const payload = await callHost('deleteDiscarded', {
|
|
5063
|
+
paths: discardPaths,
|
|
5064
|
+
confirm: true,
|
|
5065
|
+
digest: discardDialog.digest,
|
|
5066
|
+
})
|
|
5067
|
+
if (payload?.ok === false) {
|
|
5068
|
+
const code = payload?.error?.code
|
|
5069
|
+
throw new Error(
|
|
5070
|
+
code === 'digest-mismatch' ? t('discardDigestMismatch')
|
|
5071
|
+
: code === 'batch-too-large' ? format(t('discardDialogTooMany'), { n: discardPaths.length })
|
|
5072
|
+
: (payload?.error?.message ?? t('errorTitle')))
|
|
5073
|
+
}
|
|
5074
|
+
const deleted = payload?.deleted ?? []
|
|
5075
|
+
// 同步清本地状态:marks + 反馈篮(先拿被删路径,再剔)
|
|
5076
|
+
if (payload?.marks !== undefined) setMarks(payload.marks)
|
|
5077
|
+
// 反馈篮条目由 setMarks + 篮内渲染源自动同步,无需单独删
|
|
5078
|
+
setSelected(new Set())
|
|
5079
|
+
setDiscardDialog(null)
|
|
5080
|
+
console.info('dsh-gallery:', format(t('discardDone'), { n: deleted.length }))
|
|
5081
|
+
void refresh()
|
|
5082
|
+
} catch (error) {
|
|
5083
|
+
console.error('dsh-gallery: 删除失败', error)
|
|
5084
|
+
setDiscardDialog((prev) => (prev === null ? null : { ...prev, phase: 'list', error: String(error?.message ?? error) }))
|
|
5085
|
+
}
|
|
5086
|
+
}, [discardDialog, discardPaths, t])
|
|
5087
|
+
|
|
5088
|
+
/** 删除确认对话框(两阶段:清单 → 真删)。 */
|
|
5089
|
+
const discardDialogNode = discardDialog !== null
|
|
5090
|
+
? h('div', { className: 'dg-modalLayer', key: 'discardModal', 'data-gallery-discard-dialog': true }, [
|
|
5091
|
+
h('div', { className: 'dg-modal', role: 'dialog', 'aria-modal': 'true' }, [
|
|
5092
|
+
h('div', { className: 'dg-modalHead', key: 'h' }, t('discardDialogTitle')),
|
|
5093
|
+
h('div', { className: 'dg-modalBody', key: 'b' }, [
|
|
5094
|
+
h('p', { className: 'dg-dangerText', key: 'warn' }, t('discardDialogWarn')),
|
|
5095
|
+
discardDialog.count > 10
|
|
5096
|
+
? h('p', { className: 'dg-dangerText', key: 'tooMany' },
|
|
5097
|
+
format(t('discardDialogTooMany'), { n: discardDialog.count }))
|
|
5098
|
+
: null,
|
|
5099
|
+
h('p', { className: 'dg-modalSub', key: 'cnt' }, format(t('discardDialogCount'), { n: discardDialog.count })),
|
|
5100
|
+
// **完整路径逐条列出**(安全闸门要求,不许「已选 N 个」一句带过)
|
|
5101
|
+
h('ul', { className: 'dg-discardList', key: 'list', 'data-gallery-discard-files': true },
|
|
5102
|
+
(discardDialog.files ?? []).map((f) => h('li', {
|
|
5103
|
+
key: f.absolute,
|
|
5104
|
+
title: f.absolute,
|
|
5105
|
+
'data-gallery-discard-file': f.absolute,
|
|
5106
|
+
}, [
|
|
5107
|
+
h('span', { className: 'dg-discardPath', key: 'p' }, f.path),
|
|
5108
|
+
h('span', { className: 'dg-discardSize', key: 's' }, formatBytes(f.size)),
|
|
5109
|
+
]))),
|
|
5110
|
+
discardDialog.error !== undefined
|
|
5111
|
+
? h('p', { className: 'dg-dangerText', key: 'err' },
|
|
5112
|
+
format(t('discardFailed'), { msg: discardDialog.error }))
|
|
5113
|
+
: null,
|
|
5114
|
+
]),
|
|
5115
|
+
h('div', { className: 'dg-modalOps', key: 'o' }, [
|
|
5116
|
+
h('button', {
|
|
5117
|
+
type: 'button', className: 'dg-btn', key: 'cancel',
|
|
5118
|
+
disabled: discardDialog.phase === 'deleting',
|
|
5119
|
+
onClick: () => setDiscardDialog(null),
|
|
5120
|
+
}, t('discardDialogCancel')),
|
|
5121
|
+
h('button', {
|
|
5122
|
+
type: 'button', className: 'dg-btn dg-dangerBtn', key: 'ok',
|
|
5123
|
+
'data-gallery-discard-confirm': true,
|
|
5124
|
+
disabled: discardDialog.phase === 'deleting' || discardDialog.count > 10 || discardDialog.count === 0,
|
|
5125
|
+
onClick: () => { void runDiscard() },
|
|
5126
|
+
}, discardDialog.phase === 'deleting'
|
|
5127
|
+
? t('discardDialogDeleting')
|
|
5128
|
+
: format(t('discardDialogConfirm'), { n: discardDialog.count })),
|
|
5129
|
+
]),
|
|
5130
|
+
]),
|
|
5131
|
+
])
|
|
5132
|
+
: null
|
|
5133
|
+
|
|
3633
5134
|
let body
|
|
3634
5135
|
if (view.status === 'loading') {
|
|
3635
5136
|
body = h('div', { className: 'dg-body', key: 'body' }, h('p', { className: 'dg-status' }, t('loading')))
|
|
@@ -3675,6 +5176,51 @@ ${absPath}
|
|
|
3675
5176
|
const useGroups = scope === 'global' && Array.isArray(data.groups) && data.groups.length > 0
|
|
3676
5177
|
|
|
3677
5178
|
if (useGroups) {
|
|
5179
|
+
/**
|
|
5180
|
+
* 卡片包装层(v0.13.7):给任意卡片加「确认角标」+「批量多选框」。
|
|
5181
|
+
*
|
|
5182
|
+
* 为什么不改三个卡片组件:Card / FileCard / MediaCard 各自有复杂的内部结构,
|
|
5183
|
+
* 在它们外面套一层 absolute 定位的 overlay 最省事,也不会影响既有交互
|
|
5184
|
+
* (右键、点击预览、拖拽都不受影响,因为我们只加 pointer-events 可控的子元素)。
|
|
5185
|
+
*/
|
|
5186
|
+
const wrapCard = (node, item, key) => {
|
|
5187
|
+
const confirmed = isConfirmed(item.relPath)
|
|
5188
|
+
const checked = selected.has(item.relPath)
|
|
5189
|
+
const showCheckbox = selectMode || checked
|
|
5190
|
+
return h('div', {
|
|
5191
|
+
className: `dg-cardWrap${confirmed ? ' dg-cardConfirmed' : ''}${checked ? ' dg-cardChecked' : ''}`,
|
|
5192
|
+
key: key + ':wrap',
|
|
5193
|
+
'data-gallery-card-wrap': item.relPath,
|
|
5194
|
+
'data-gallery-confirmed': confirmed ? '1' : '0',
|
|
5195
|
+
}, [
|
|
5196
|
+
node,
|
|
5197
|
+
// 确认角标(只在确认态出现,与自动分色边框区分开)
|
|
5198
|
+
confirmed
|
|
5199
|
+
? h('div', {
|
|
5200
|
+
className: 'dg-confirmBadge',
|
|
5201
|
+
key: 'badge',
|
|
5202
|
+
'data-gallery-confirm-badge': true,
|
|
5203
|
+
title: t('confirmBadgeHint'),
|
|
5204
|
+
}, [h('span', { key: 'i' }, '✓'), h('span', { key: 'l' }, t('confirmBadgeLabel'))])
|
|
5205
|
+
: null,
|
|
5206
|
+
// 多选框(批量模式下常显,或已选中时显示)
|
|
5207
|
+
showCheckbox
|
|
5208
|
+
? h('button', {
|
|
5209
|
+
type: 'button',
|
|
5210
|
+
className: `dg-cardCheck${checked ? ' dg-cardCheckOn' : ''}`,
|
|
5211
|
+
key: 'check',
|
|
5212
|
+
'data-gallery-card-check': item.relPath,
|
|
5213
|
+
title: checked ? t('batchUnselect') : t('batchSelect'),
|
|
5214
|
+
onClick: (e) => {
|
|
5215
|
+
e.stopPropagation()
|
|
5216
|
+
e.preventDefault()
|
|
5217
|
+
toggleSelect(item.relPath)
|
|
5218
|
+
},
|
|
5219
|
+
}, checked ? '✓' : '')
|
|
5220
|
+
: null,
|
|
5221
|
+
])
|
|
5222
|
+
}
|
|
5223
|
+
|
|
3678
5224
|
const cardFor = (item, groupKey, listForViewer) => {
|
|
3679
5225
|
// 分组里的文件也走同一套卡片组件
|
|
3680
5226
|
const enriched = {
|
|
@@ -3684,7 +5230,7 @@ ${absPath}
|
|
|
3684
5230
|
}
|
|
3685
5231
|
// 音视频分组视图:必须走 MediaCard,否则会被当成图片卡片渲染(v0.10.1)
|
|
3686
5232
|
if (kind === 'media') {
|
|
3687
|
-
return h(MediaCard, {
|
|
5233
|
+
return wrapCard(h(MediaCard, {
|
|
3688
5234
|
key: `${groupKey}:${item.relPath}`,
|
|
3689
5235
|
item: {
|
|
3690
5236
|
...enriched,
|
|
@@ -3696,10 +5242,10 @@ ${absPath}
|
|
|
3696
5242
|
absPath: buildAbsPath(data.root, item.relPath),
|
|
3697
5243
|
onPlay: (target) => setMediaPlaying(target),
|
|
3698
5244
|
onContextMenu: openContextMenu,
|
|
3699
|
-
})
|
|
5245
|
+
}), item, `${groupKey}:${item.relPath}`)
|
|
3700
5246
|
}
|
|
3701
5247
|
if (kind === 'file') {
|
|
3702
|
-
return h(FileCard, {
|
|
5248
|
+
return wrapCard(h(FileCard, {
|
|
3703
5249
|
key: `${groupKey}:${item.relPath}`,
|
|
3704
5250
|
item: enriched,
|
|
3705
5251
|
t,
|
|
@@ -3716,9 +5262,9 @@ ${absPath}
|
|
|
3716
5262
|
}
|
|
3717
5263
|
},
|
|
3718
5264
|
onCopy: (abs) => { void copyText(abs) },
|
|
3719
|
-
})
|
|
5265
|
+
}), item, `${groupKey}:${item.relPath}`)
|
|
3720
5266
|
}
|
|
3721
|
-
return h(Card, {
|
|
5267
|
+
return wrapCard(h(Card, {
|
|
3722
5268
|
key: `${groupKey}:${item.relPath}`,
|
|
3723
5269
|
item: enriched,
|
|
3724
5270
|
t,
|
|
@@ -3736,7 +5282,7 @@ ${absPath}
|
|
|
3736
5282
|
if (pos < 0) return
|
|
3737
5283
|
openViewer(pos, anchorEl ?? null, list)
|
|
3738
5284
|
},
|
|
3739
|
-
})
|
|
5285
|
+
}), item, `${groupKey}:${item.relPath}`)
|
|
3740
5286
|
}
|
|
3741
5287
|
|
|
3742
5288
|
const groupNodes = data.groups.map((group, gi) => {
|
|
@@ -3746,12 +5292,24 @@ ${absPath}
|
|
|
3746
5292
|
// - 当前对话:**默认显示**(用户刚做完的就是要看过程,可选收起)
|
|
3747
5293
|
// - 其他对话 / 历史资产:**默认隐藏**(避免别人调试图淹没列表)
|
|
3748
5294
|
// 用户手动切换后,以 showInterim 里记录的为准(true=显示 / false=隐藏)。
|
|
5295
|
+
// 组内「显示中间产物」与顶部「中间产物」开关**同源**(v0.13.7):
|
|
5296
|
+
// 顶部开关关掉 → 全局都不显示中间产物;
|
|
5297
|
+
// 顶部开着 + 组内开关 → 由组内决定(默认当前对话显示、历史隐藏)。
|
|
5298
|
+
// 不搞两套打架的开关。
|
|
3749
5299
|
const interimDefault = group.isCurrent === true
|
|
3750
5300
|
const stored = showInterim[groupKey]
|
|
3751
|
-
const
|
|
3752
|
-
const
|
|
3753
|
-
|
|
3754
|
-
|
|
5301
|
+
const groupWantsIntermediate = stored === undefined ? interimDefault : stored
|
|
5302
|
+
const globalAllowsIntermediate = categoryFilter.intermediate !== false
|
|
5303
|
+
const showIntermediate = groupWantsIntermediate && globalAllowsIntermediate
|
|
5304
|
+
|
|
5305
|
+
// 分类开关过滤:按 bucketOf 判断该文件属哪一类,再查开关
|
|
5306
|
+
const visibleFiles = group.files.filter((f) => {
|
|
5307
|
+
const bucket = bucketOf(f)
|
|
5308
|
+
if (categoryFilter[bucket] === false) return false
|
|
5309
|
+
// 中间产物额外受组内开关控制(上面已算好)
|
|
5310
|
+
if (f.category === 'intermediate' && !showIntermediate) return false
|
|
5311
|
+
return true
|
|
5312
|
+
})
|
|
3755
5313
|
const hiddenCount = group.files.length - visibleFiles.length
|
|
3756
5314
|
|
|
3757
5315
|
const chips = []
|
|
@@ -3967,6 +5525,41 @@ ${absPath}
|
|
|
3967
5525
|
})
|
|
3968
5526
|
: null
|
|
3969
5527
|
|
|
5528
|
+
// 反馈篮(S3-a):列出已标记条目 + 生成决策草稿
|
|
5529
|
+
const markedList = Object.keys(marks).map((relPath) => {
|
|
5530
|
+
// 从当前视图里找该条目,拿 category / sessionId
|
|
5531
|
+
const flat = (Array.isArray(data?.items) ? data.items : [])
|
|
5532
|
+
const groupsList = Array.isArray(data?.groups)
|
|
5533
|
+
? data.groups.flatMap((gr) => (Array.isArray(gr.files) ? gr.files.map((f) => ({ ...f, sessionId: gr.sessionId })) : []))
|
|
5534
|
+
: []
|
|
5535
|
+
const found = flat.find((it) => it.relPath === relPath)
|
|
5536
|
+
?? groupsList.find((it) => it.relPath === relPath)
|
|
5537
|
+
return {
|
|
5538
|
+
relPath,
|
|
5539
|
+
category: found?.category ?? 'unknown',
|
|
5540
|
+
sessionId: found?.sessionId,
|
|
5541
|
+
mark: marks[relPath],
|
|
5542
|
+
}
|
|
5543
|
+
})
|
|
5544
|
+
const feedbackLayer = basketOpen && markedList.length >= 0
|
|
5545
|
+
? h(FeedbackBasket, {
|
|
5546
|
+
key: 'feedbackLayer',
|
|
5547
|
+
t,
|
|
5548
|
+
items: markedList,
|
|
5549
|
+
currentSessionId: sessionId ?? '',
|
|
5550
|
+
targetSessionTitle: scope === 'global'
|
|
5551
|
+
? (view.status === 'ready' && Array.isArray(view.data?.groups)
|
|
5552
|
+
? (view.data.groups.find((g) => g.isCurrent)?.title ?? t('feedbackTargetCurrent'))
|
|
5553
|
+
: t('feedbackTargetCurrent'))
|
|
5554
|
+
: '',
|
|
5555
|
+
onClose: () => { setBasketOpen(false); setEditingItem(null) },
|
|
5556
|
+
onRemove: (relPath) => { void removeMark(relPath) },
|
|
5557
|
+
onEdit: (it) => { setEditingItem(it) },
|
|
5558
|
+
onEditSave: (relPath, patch) => { void updateMark(relPath, patch) },
|
|
5559
|
+
onClear: () => { void clearMarks() },
|
|
5560
|
+
})
|
|
5561
|
+
: null
|
|
5562
|
+
|
|
3970
5563
|
// 右键菜单
|
|
3971
5564
|
const ctxLayer = ctxMenu !== null
|
|
3972
5565
|
? h(ContextMenu, {
|
|
@@ -3985,6 +5578,14 @@ ${absPath}
|
|
|
3985
5578
|
onReveal: () => { void doReveal(ctxMenu.item) },
|
|
3986
5579
|
onCopy: () => { void copyText(ctxMenu.absPath) },
|
|
3987
5580
|
onDelete: () => setDeleteTarget({ item: ctxMenu.item, busy: false }),
|
|
5581
|
+
// 6 个反馈动作(S3-a):选中即进反馈篮,不发送
|
|
5582
|
+
confirmed: marks[ctxMenu.item.relPath]?.confirmed === true,
|
|
5583
|
+
onUnconfirm: () => { void unconfirmOne(ctxMenu.item.relPath) },
|
|
5584
|
+
onMark: (action) => {
|
|
5585
|
+
const target = ctxMenu.item
|
|
5586
|
+
closeContextMenu()
|
|
5587
|
+
void doMark(target, action)
|
|
5588
|
+
},
|
|
3988
5589
|
},
|
|
3989
5590
|
})
|
|
3990
5591
|
: null
|
|
@@ -4003,6 +5604,10 @@ ${absPath}
|
|
|
4003
5604
|
|
|
4004
5605
|
return h('div', { className: 'dg-root', 'data-gallery-root': true }, [
|
|
4005
5606
|
header,
|
|
5607
|
+
basketToggle,
|
|
5608
|
+
batchBar,
|
|
5609
|
+
discardEntry,
|
|
5610
|
+
discardDialogNode,
|
|
4006
5611
|
legend,
|
|
4007
5612
|
body,
|
|
4008
5613
|
pager,
|
|
@@ -4011,6 +5616,7 @@ ${absPath}
|
|
|
4011
5616
|
settingsLayer,
|
|
4012
5617
|
ctxLayer,
|
|
4013
5618
|
confirmLayer,
|
|
5619
|
+
feedbackLayer,
|
|
4014
5620
|
])
|
|
4015
5621
|
}
|
|
4016
5622
|
|
|
@@ -4251,6 +5857,90 @@ ${absPath}
|
|
|
4251
5857
|
}, wide ? t('type.label') : '▦')
|
|
4252
5858
|
}
|
|
4253
5859
|
|
|
5860
|
+
|
|
5861
|
+
/**
|
|
5862
|
+
* 画廊对外 seam(S3-a v1)。
|
|
5863
|
+
*
|
|
5864
|
+
* 给独立包 / 未来扩展一个稳定入口,避免依赖 DOM 猜测。
|
|
5865
|
+
* 契约版本放在 version 字段,check.mjs 第 17 项会核对。
|
|
5866
|
+
*
|
|
5867
|
+
* 注意:这是**只读 + 标记**的窄接口,不含发送能力 ——
|
|
5868
|
+
* 发送永远由用户在 composer 里手动确认。
|
|
5869
|
+
*/
|
|
5870
|
+
/** 最近一次右键选中的卡片 relPath(seam.getSelection 的兜底来源)。 */
|
|
5871
|
+
const lastContextRelPath = { current: null }
|
|
5872
|
+
|
|
5873
|
+
function installSeam() {
|
|
5874
|
+
const seam = {
|
|
5875
|
+
version: 1,
|
|
5876
|
+
/**
|
|
5877
|
+
* 当前选中的卡片(查看器打开时是那张图;否则 null)。
|
|
5878
|
+
* @returns { relPath: string } | null
|
|
5879
|
+
*/
|
|
5880
|
+
/**
|
|
5881
|
+
* 当前选中项。
|
|
5882
|
+
*
|
|
5883
|
+
* 优先级:
|
|
5884
|
+
* 1. 查看器已打开 → 那张图(最明确的「当前选中」)
|
|
5885
|
+
* 2. 否则 → 最近一次右键选中的卡片(lastContextRelPath)
|
|
5886
|
+
* 3. 都没有 → 用 a11y 焦点/悬停兜底(:focus 的卡片)
|
|
5887
|
+
*
|
|
5888
|
+
* 每个卡片都挂 data-gallery-relpath,独立包可据此定位。
|
|
5889
|
+
*/
|
|
5890
|
+
getSelection() {
|
|
5891
|
+
// 1. 查看器内的图
|
|
5892
|
+
const viewerEl = document.querySelector('[data-gallery-viewer] [data-gallery-src-relpath]')
|
|
5893
|
+
if (viewerEl !== null) {
|
|
5894
|
+
const relPath = viewerEl.getAttribute('data-gallery-src-relpath')
|
|
5895
|
+
if (relPath !== null && relPath !== '') return { relPath, source: 'viewer' }
|
|
5896
|
+
}
|
|
5897
|
+
// 2. 最近右键选中的卡片
|
|
5898
|
+
if (lastContextRelPath.current !== null) {
|
|
5899
|
+
return { relPath: lastContextRelPath.current, source: 'context-menu' }
|
|
5900
|
+
}
|
|
5901
|
+
// 3. 焦点中的卡片(键盘/无鼠标场景)
|
|
5902
|
+
const focused = document.querySelector('[data-gallery-relpath]:focus')
|
|
5903
|
+
if (focused !== null) {
|
|
5904
|
+
const relPath = focused.getAttribute('data-gallery-relpath')
|
|
5905
|
+
if (relPath !== null && relPath !== '') return { relPath, source: 'focus' }
|
|
5906
|
+
}
|
|
5907
|
+
return null
|
|
5908
|
+
},
|
|
5909
|
+
/**
|
|
5910
|
+
* 订阅「选中项变化」。返回退订函数。
|
|
5911
|
+
* 实现方式:观察 DOM 属性变化(低成本、零依赖)。
|
|
5912
|
+
*/
|
|
5913
|
+
subscribe(fn) {
|
|
5914
|
+
if (typeof fn !== 'function') return () => {}
|
|
5915
|
+
const target = document.querySelector('[data-gallery-root]')
|
|
5916
|
+
if (target === null || typeof MutationObserver !== 'function') return () => {}
|
|
5917
|
+
const observer = new MutationObserver(() => { try { fn(seam.getSelection()) } catch { /* 忽略订阅者异常 */ } })
|
|
5918
|
+
observer.observe(target, { subtree: true, attributes: true, attributeFilter: ['data-gallery-viewer'] })
|
|
5919
|
+
return () => observer.disconnect()
|
|
5920
|
+
},
|
|
5921
|
+
/** 当前所有标记(异步,来自 Host)。 */
|
|
5922
|
+
async getMarks() {
|
|
5923
|
+
try {
|
|
5924
|
+
const payload = await callHost('getMarks', {})
|
|
5925
|
+
return payload?.ok === false ? {} : (payload?.marks ?? {})
|
|
5926
|
+
} catch { return {} }
|
|
5927
|
+
},
|
|
5928
|
+
/** 设/清一条标记。 */
|
|
5929
|
+
async setMark(relPath, mark) {
|
|
5930
|
+
try {
|
|
5931
|
+
const payload = await callHost('marks', { path: relPath, mark: mark ?? null })
|
|
5932
|
+
return payload?.ok !== false
|
|
5933
|
+
} catch { return false }
|
|
5934
|
+
},
|
|
5935
|
+
/** 当前反馈草稿文本(若反馈篮已生成过;未生成返回空串)。 */
|
|
5936
|
+
getFeedbackDraft() {
|
|
5937
|
+
return draftRef.current ?? ''
|
|
5938
|
+
},
|
|
5939
|
+
}
|
|
5940
|
+
window.dshGallerySeam = seam
|
|
5941
|
+
return seam
|
|
5942
|
+
}
|
|
5943
|
+
|
|
4254
5944
|
/** 对话区入口:编辑框右侧的紧凑按钮。 */
|
|
4255
5945
|
function ComposerButton({ t }) {
|
|
4256
5946
|
return h('button', {
|
|
@@ -4270,6 +5960,11 @@ ${absPath}
|
|
|
4270
5960
|
}
|
|
4271
5961
|
|
|
4272
5962
|
return {
|
|
5963
|
+
// ⚠️ 不要声明 conversation.input / sessions / agents。
|
|
5964
|
+
// 实测:inject 声明 conversation.input 会让 Cordis 插件在 web boot 阶段
|
|
5965
|
+
// 一直 pending("waiting for service: conversation.input"),宿主判定启动失败、
|
|
5966
|
+
// 页面永久停在 "Loading plugins…"、主进程退出。
|
|
5967
|
+
// 因此草稿写入走零 inject 的纯 DOM 路径(见 05-feedback.js 的 writeDraftToComposer)。
|
|
4273
5968
|
inject: ['slots', 'locale', 'sidebarRightTabs', 'sidebarRight'],
|
|
4274
5969
|
apply(ctx) {
|
|
4275
5970
|
ctxRef.current = ctx
|
|
@@ -4277,6 +5972,14 @@ ${absPath}
|
|
|
4277
5972
|
const t = ctx.locale.bind(NS)
|
|
4278
5973
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-gallery: dictionaries')
|
|
4279
5974
|
|
|
5975
|
+
// seam v1(S3-a):对外暴露窄接口,供独立包 / 扩展使用
|
|
5976
|
+
ctx.effect(() => {
|
|
5977
|
+
const seam = installSeam()
|
|
5978
|
+
return () => {
|
|
5979
|
+
if (window.dshGallerySeam === seam) delete window.dshGallerySeam
|
|
5980
|
+
}
|
|
5981
|
+
}, 'dsh-gallery: seam')
|
|
5982
|
+
|
|
4280
5983
|
ctx.effect(() => {
|
|
4281
5984
|
const tag = document.createElement('style')
|
|
4282
5985
|
tag.dataset.plugin = 'dsh-gallery'
|