dsh-gallery 0.15.0 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +37 -5
- package/client.js +1324 -25
- package/host/clipboard.js +211 -0
- package/host/derive.js +62 -0
- package/host/http.js +448 -1
- package/host/scan.js +33 -5
- package/host/session-index.js +34 -1
- package/host/trim.js +134 -0
- package/package.json +100 -91
package/client.js
CHANGED
|
@@ -68,6 +68,37 @@ function clamp01(v) {
|
|
|
68
68
|
return n
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/** 把数夹到 [min, max] 闭区间内。 */
|
|
72
|
+
function clampNum(v, min, max) {
|
|
73
|
+
const n = Number(v)
|
|
74
|
+
if (!Number.isFinite(n)) return min
|
|
75
|
+
if (n < min) return min
|
|
76
|
+
if (n > max) return max
|
|
77
|
+
return n
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* v0.16.0 选段播放决策(纯函数,便于单测)。
|
|
82
|
+
*
|
|
83
|
+
* 老板 2026-11-13 11:56 反馈:播放必须跟选段走 —— **从入点起播、到出点结束**,
|
|
84
|
+
* 而不是播放器自己按整段播(截图里选段是 2:16–3:21,播放头却停在 0:29)。
|
|
85
|
+
* 拖动端点 / 点轨道时(scrubbing)不做钳制,否则播放头会被反复拽回,没法目视选帧。
|
|
86
|
+
*
|
|
87
|
+
* @returns {{ action: 'none' | 'stop' | 'seekIn', seekTo?: number }}
|
|
88
|
+
*/
|
|
89
|
+
function trimPlaybackDecision(now, inPoint, outPoint, opts) {
|
|
90
|
+
const o = opts || {}
|
|
91
|
+
if (!Number.isFinite(now)) return { action: 'none' }
|
|
92
|
+
// 区间还没初始化(或过短)时不要干预原生播放
|
|
93
|
+
if (!(outPoint > inPoint + 0.05)) return { action: 'none' }
|
|
94
|
+
if (o.scrubbing === true) return { action: 'none' }
|
|
95
|
+
// 到出点:停住,不循环 —— 老板要的是「到出点结束」
|
|
96
|
+
if (now >= outPoint - 0.02) return { action: 'stop', seekTo: Math.min(now, outPoint) }
|
|
97
|
+
// 播放跑到入点之前(例如用原生进度条拖到了区间外)→ 拉回入点
|
|
98
|
+
if (now < inPoint - 0.25 && o.paused !== true) return { action: 'seekIn', seekTo: inPoint }
|
|
99
|
+
return { action: 'none' }
|
|
100
|
+
}
|
|
101
|
+
|
|
71
102
|
/** 校验并规整一条批注;不合法返回 null。 */
|
|
72
103
|
function normalizeAnnotation(a) {
|
|
73
104
|
if (a === null || typeof a !== "object") return null
|
|
@@ -710,6 +741,8 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
710
741
|
ctxDeleteConfirm: '确认删除?此操作不可恢复',
|
|
711
742
|
ctxDeleteYes: '确认删除',
|
|
712
743
|
ctxDeleteNo: '取消',
|
|
744
|
+
// 批注删除按钮的 title 与卡片删除共用 t('delete')
|
|
745
|
+
delete: '删除',
|
|
713
746
|
ctxHiddenDone: '已隐藏,可在设置里恢复',
|
|
714
747
|
ctxDeleting: '删除中…',
|
|
715
748
|
ctxDeleteFailed: '删除失败',
|
|
@@ -837,6 +870,51 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
837
870
|
meta: '{size} · {time}',
|
|
838
871
|
scanned: '已扫描 {dirs} 个目录',
|
|
839
872
|
capped: '已达扫描上限,结果可能不完整',
|
|
873
|
+
// v0.16.0 粘贴 / 裁剪 / 音视频选段
|
|
874
|
+
ctxPaste: '粘贴',
|
|
875
|
+
pasteToCurrent: '粘贴到当前对话素材',
|
|
876
|
+
pasteHint: '作为「素材」放进鼠标所在的对话;不在任何分组内则放进当前对话',
|
|
877
|
+
pasteImageOk: '已粘贴图片:{name}(到「{target}」)',
|
|
878
|
+
pasteFileOk: '已粘贴文件:{name}(到「{target}」)',
|
|
879
|
+
pasteEmpty: '剪贴板里没有可粘贴的图片或文件',
|
|
880
|
+
pasteFailed: '粘贴失败:{message}',
|
|
881
|
+
pasteFileByKey: '剪贴板里没有可粘贴的图片或文件;请在资源管理器里复制文件后重试',
|
|
882
|
+
pasteUnsupported: '这类文件拿不到磁盘路径,请在资源管理器里复制后重试',
|
|
883
|
+
// v0.16.0 单文件 / 批量复制 + 任意文件粘贴
|
|
884
|
+
ctxCopyFile: '复制文件',
|
|
885
|
+
ctxCopyFileHint: '把该文件写入系统剪贴板,可在别的对话或资源管理器里粘贴',
|
|
886
|
+
batchCopyFiles: '复制所选文件',
|
|
887
|
+
batchCopyHint: '把选中的文件写入系统剪贴板,可在别的对话或资源管理器里粘贴',
|
|
888
|
+
copyOk: '已复制 {n} 个文件到剪贴板;切到目标对话后右键「粘贴」或按 Ctrl+V',
|
|
889
|
+
copyOkInternal: '已复制 {n} 个文件(系统剪贴板不可用,仅插件内粘贴有效)',
|
|
890
|
+
copyFailed: '复制失败:{message}',
|
|
891
|
+
pasteFilesOk: '已粘贴 {n} 个文件到「{target}」:{name}',
|
|
892
|
+
// v0.16.2 粘贴落点:全局视图下按「鼠标所在的对话组」决定,不是永远当前对话
|
|
893
|
+
pasteTargetCurrent: '当前对话',
|
|
894
|
+
pasteTo: '粘贴到「{target}」',
|
|
895
|
+
viewerCopyFile: '复制',
|
|
896
|
+
viewerCopyFileHint: 'Ctrl+C 复制当前文件(剪贴板里是文件本身,可直接在资源管理器或其他对话粘贴)',
|
|
897
|
+
cropEnter: '裁剪',
|
|
898
|
+
cropExit: '退出裁剪',
|
|
899
|
+
cropConfirm: '确认裁剪',
|
|
900
|
+
cropCancel: '取消',
|
|
901
|
+
cropHint: '拖动框选要保留的区域;放大镜显示光标处细节,可拖角调整、拖动框移动',
|
|
902
|
+
cropSaving: '正在裁剪…',
|
|
903
|
+
cropSaved: '已裁剪:{name}(已加入「{target}」素材)',
|
|
904
|
+
cropFailed: '裁剪失败:{message}',
|
|
905
|
+
cropMinSize: '选区太小',
|
|
906
|
+
trimEnter: '裁剪片段',
|
|
907
|
+
trimExit: '退出裁剪',
|
|
908
|
+
trimPreview: '从入点播放',
|
|
909
|
+
trimPause: '暂停',
|
|
910
|
+
trimSave: '保存片段',
|
|
911
|
+
trimSaving: '正在裁剪音视频…',
|
|
912
|
+
trimSaved: '已保存片段:{name}(已加入当前对话素材)',
|
|
913
|
+
trimFailed: '裁剪失败:{message}',
|
|
914
|
+
trimIn: '入点',
|
|
915
|
+
trimOut: '出点',
|
|
916
|
+
trimDragHint: '拖蓝色入点 / 橙色出点选段,也可点轨道设定就近端点;播放自动从入点开始、到出点暂停,拖端点时画面跟着走',
|
|
917
|
+
trimNoDuration: '媒体尚未就绪,无法裁剪',
|
|
840
918
|
}
|
|
841
919
|
|
|
842
920
|
const en = {
|
|
@@ -1044,6 +1122,7 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1044
1122
|
ctxDeleteConfirm: 'Delete permanently? This cannot be undone',
|
|
1045
1123
|
ctxDeleteYes: 'Delete',
|
|
1046
1124
|
ctxDeleteNo: 'Cancel',
|
|
1125
|
+
delete: 'Delete',
|
|
1047
1126
|
ctxHiddenDone: 'Hidden. Restore it in settings later.',
|
|
1048
1127
|
ctxDeleting: 'Deleting…',
|
|
1049
1128
|
ctxDeleteFailed: 'Delete failed',
|
|
@@ -1168,6 +1247,51 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1168
1247
|
meta: '{size} · {time}',
|
|
1169
1248
|
scanned: 'Scanned {dirs} folders',
|
|
1170
1249
|
capped: 'Scan limit reached; results may be incomplete',
|
|
1250
|
+
// v0.16.0 paste / image crop / media trim
|
|
1251
|
+
ctxPaste: 'Paste',
|
|
1252
|
+
pasteToCurrent: 'Paste into current chat assets',
|
|
1253
|
+
pasteHint: 'Add as "source" assets to the chat group under the cursor; falls back to this chat',
|
|
1254
|
+
pasteImageOk: 'Pasted image: {name} (into "{target}")',
|
|
1255
|
+
pasteFileOk: 'Pasted file: {name} (into "{target}")',
|
|
1256
|
+
pasteEmpty: 'No image or file to paste in the clipboard',
|
|
1257
|
+
pasteFailed: 'Paste failed: {message}',
|
|
1258
|
+
pasteFileByKey: 'No image or file to paste; copy files in Explorer and try again',
|
|
1259
|
+
pasteUnsupported: 'No disk path for this file; copy it in Explorer and try again',
|
|
1260
|
+
// v0.16.0 single / batch copy + any-file paste
|
|
1261
|
+
ctxCopyFile: 'Copy file',
|
|
1262
|
+
ctxCopyFileHint: 'Write this file to the system clipboard; paste it in another chat or Explorer',
|
|
1263
|
+
batchCopyFiles: 'Copy selected files',
|
|
1264
|
+
batchCopyHint: 'Write the selected files to the system clipboard; paste them in another chat or Explorer',
|
|
1265
|
+
copyOk: 'Copied {n} file(s) to the clipboard; right-click "Paste" or press Ctrl+V in the target chat',
|
|
1266
|
+
copyOkInternal: 'Copied {n} file(s) (system clipboard unavailable; in-plugin paste only)',
|
|
1267
|
+
copyFailed: 'Copy failed: {message}',
|
|
1268
|
+
pasteFilesOk: 'Pasted {n} file(s) into "{target}": {name}',
|
|
1269
|
+
// v0.16.2 paste destination follows the hovered chat group in the global view
|
|
1270
|
+
pasteTargetCurrent: 'this chat',
|
|
1271
|
+
pasteTo: 'Paste into "{target}"',
|
|
1272
|
+
viewerCopyFile: 'Copy',
|
|
1273
|
+
viewerCopyFileHint: 'Ctrl+C copies this file to the clipboard (paste it in Explorer or another chat)',
|
|
1274
|
+
cropEnter: 'Crop',
|
|
1275
|
+
cropExit: 'Exit crop',
|
|
1276
|
+
cropConfirm: 'Apply crop',
|
|
1277
|
+
cropCancel: 'Cancel',
|
|
1278
|
+
cropHint: 'Drag to select the area to keep; the magnifier shows cursor detail; drag corners to resize, drag the box to move',
|
|
1279
|
+
cropSaving: 'Cropping…',
|
|
1280
|
+
cropSaved: 'Cropped: {name} (added to "{target}" assets)',
|
|
1281
|
+
cropFailed: 'Crop failed: {message}',
|
|
1282
|
+
cropMinSize: 'Selection too small',
|
|
1283
|
+
trimEnter: 'Trim clip',
|
|
1284
|
+
trimExit: 'Exit trim',
|
|
1285
|
+
trimPreview: 'Play from in',
|
|
1286
|
+
trimPause: 'Pause',
|
|
1287
|
+
trimSave: 'Save clip',
|
|
1288
|
+
trimSaving: 'Trimming media…',
|
|
1289
|
+
trimSaved: 'Saved clip: {name} (added to current chat assets)',
|
|
1290
|
+
trimFailed: 'Trim failed: {message}',
|
|
1291
|
+
trimIn: 'In',
|
|
1292
|
+
trimOut: 'Out',
|
|
1293
|
+
trimDragHint: 'Drag the blue In / orange Out handle, or click the track to set the nearest endpoint; playback starts at the in-point and stops at the out-point',
|
|
1294
|
+
trimNoDuration: 'Media not ready yet — cannot trim',
|
|
1171
1295
|
}
|
|
1172
1296
|
|
|
1173
1297
|
/** 格式化 / 图片压缩 / 并发限流工具。 */
|
|
@@ -1234,7 +1358,24 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
1234
1358
|
body: JSON.stringify({ op, ...(payload ?? {}) }),
|
|
1235
1359
|
signal: merged,
|
|
1236
1360
|
})
|
|
1237
|
-
if (!response.ok)
|
|
1361
|
+
if (!response.ok) {
|
|
1362
|
+
// Host 的 op 路由会把具体原因放在 { error: { message } } 里。
|
|
1363
|
+
// 旧实现只抛 `HTTP 500`,老板截图只剩状态码、没法排障 —— 这里把原因带出来。
|
|
1364
|
+
let detail = ''
|
|
1365
|
+
try {
|
|
1366
|
+
const text = await response.text()
|
|
1367
|
+
try {
|
|
1368
|
+
const parsed = JSON.parse(text)
|
|
1369
|
+
const msg = parsed?.error?.message ?? parsed?.message
|
|
1370
|
+
if (typeof msg === 'string') detail = msg
|
|
1371
|
+
} catch {
|
|
1372
|
+
// 网关可能返回 HTML / 纯文本,取一小段兜底(别把整页 HTML 塞进提示)
|
|
1373
|
+
if (text.length < 300 && !text.includes('<')) detail = text.trim()
|
|
1374
|
+
}
|
|
1375
|
+
} catch { /* body 读不动就只报状态码 */ }
|
|
1376
|
+
if (detail.length > 240) detail = `${detail.slice(0, 240)}…`
|
|
1377
|
+
throw new Error(detail === '' ? `HTTP ${response.status}` : `HTTP ${response.status}: ${detail}`)
|
|
1378
|
+
}
|
|
1238
1379
|
return await response.json()
|
|
1239
1380
|
} catch (error) {
|
|
1240
1381
|
// 组件卸载造成的取消仍按 AbortError 交给上层忽略;只有自己的超时转成可读错误
|
|
@@ -2544,8 +2685,11 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
2544
2685
|
.dg-mediaStage {
|
|
2545
2686
|
display: flex; align-items: center; justify-content: center;
|
|
2546
2687
|
background: #000; min-height: 120px;
|
|
2547
|
-
padding: 0;
|
|
2688
|
+
padding: 0; overflow: hidden; flex: 1 1 auto;
|
|
2548
2689
|
}
|
|
2690
|
+
/* 选段条展开时把舞台的最小高度让出来,否则小窗口下轨道会被面板裁掉 */
|
|
2691
|
+
.dg-mediaPanel.is-trim .dg-mediaStage { min-height: 0; }
|
|
2692
|
+
.dg-mediaPanel.is-trim .dg-mediaStage video { max-height: 50vh; }
|
|
2549
2693
|
.dg-mediaPanelVideo .dg-mediaStage video { width: 100%; max-height: 60vh; display: block; }
|
|
2550
2694
|
.dg-mediaPanelAudio .dg-mediaStage { padding: 24px 16px; background: transparent; }
|
|
2551
2695
|
.dg-mediaPanelAudio .dg-mediaStage audio { width: 100%; }
|
|
@@ -2949,6 +3093,84 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
2949
3093
|
border-color: #1d9e75 !important; font-weight: 600;
|
|
2950
3094
|
}
|
|
2951
3095
|
.dg-polyPanelOps .dg-polyClose:disabled { opacity: 0.45; }
|
|
3096
|
+
|
|
3097
|
+
/* v0.16.0 粘贴结果提示 */
|
|
3098
|
+
.dg-pasteNotice {
|
|
3099
|
+
position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
|
|
3100
|
+
z-index: 50; max-width: 84%; box-sizing: border-box;
|
|
3101
|
+
padding: 8px 14px; border-radius: 8px; font-size: 12px; line-height: 1.4;
|
|
3102
|
+
background: #1b1e24; color: #e8eaed; box-shadow: 0 8px 28px rgba(0,0,0,0.6);
|
|
3103
|
+
border: 1px solid rgba(255,255,255,0.18); pointer-events: none; word-break: break-all;
|
|
3104
|
+
}
|
|
3105
|
+
.dg-pasteOk { border-color: rgba(94,214,150,0.6); }
|
|
3106
|
+
.dg-pasteFail { border-color: rgba(255,107,107,0.6); color: #ffd2d2; }
|
|
3107
|
+
|
|
3108
|
+
/* v0.16.0 图片裁剪层 + 微信式圆形放大镜
|
|
3109
|
+
坐标系说明:裁剪框/放大镜都用 getBoundingClientRect 的**视口坐标**定位,
|
|
3110
|
+
所以这一层必须 fixed 铺满视口,absolute 会相对 stage 偏移导致框错位。 */
|
|
3111
|
+
.dg-cropLayer { position: fixed; inset: 0; z-index: 60; cursor: crosshair; }
|
|
3112
|
+
.dg-cropRect {
|
|
3113
|
+
position: absolute; border: 1px solid #6a92ff;
|
|
3114
|
+
box-shadow: 0 0 0 9999px rgba(0,0,0,0.5); box-sizing: border-box;
|
|
3115
|
+
cursor: move; background: rgba(106,146,255,0.06);
|
|
3116
|
+
}
|
|
3117
|
+
.dg-cropHandle {
|
|
3118
|
+
position: absolute; width: 13px; height: 13px; background: #6a92ff;
|
|
3119
|
+
border: 2px solid #fff; border-radius: 2px; box-sizing: border-box;
|
|
3120
|
+
}
|
|
3121
|
+
.dg-cropHandleNW { left: -7px; top: -7px; cursor: nwse-resize; }
|
|
3122
|
+
.dg-cropHandleNE { right: -7px; top: -7px; cursor: nesw-resize; }
|
|
3123
|
+
.dg-cropHandleSW { left: -7px; bottom: -7px; cursor: nesw-resize; }
|
|
3124
|
+
.dg-cropHandleSE { right: -7px; bottom: -7px; cursor: nwse-resize; }
|
|
3125
|
+
.dg-cropMagnifier {
|
|
3126
|
+
position: absolute; width: 130px; height: 130px; border-radius: 50%;
|
|
3127
|
+
border: 2px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,0.6);
|
|
3128
|
+
pointer-events: none; overflow: hidden; background: #000; transform: translate(-50%, -50%);
|
|
3129
|
+
}
|
|
3130
|
+
.dg-cropMagnifier canvas { display: block; width: 100%; height: 100%; }
|
|
3131
|
+
.dg-cropPanel {
|
|
3132
|
+
/* 位置由组件按裁剪框实时算好、以内联 left/top 注入:贴在选区下方,
|
|
3133
|
+
靠窗口下沿时自动翻到选区上方。千万别写死 left/bottom ——
|
|
3134
|
+
cropLayer 是 fixed inset:0,写死就会跑到视口左下角,离选区十万八千里。 */
|
|
3135
|
+
position: absolute; z-index: 6; width: 300px;
|
|
3136
|
+
box-sizing: border-box; background: #1b1e24; color: #e8eaed;
|
|
3137
|
+
border: 1px solid rgba(106,146,255,0.55); border-radius: 8px; padding: 10px;
|
|
3138
|
+
box-shadow: 0 8px 28px rgba(0,0,0,0.6);
|
|
3139
|
+
}
|
|
3140
|
+
.dg-cropPanelHead { font-size: 12px; font-weight: 600; color: #a9c4ff; margin-bottom: 6px; }
|
|
3141
|
+
.dg-cropPanelHint { font-size: 11px; color: #b9c2cf; line-height: 1.5; margin-top: 6px; }
|
|
3142
|
+
.dg-cropPanelOps { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
|
|
3143
|
+
|
|
3144
|
+
/* v0.16.0 音视频选段轨道 */
|
|
3145
|
+
.dg-trimWrap { padding: 6px 10px 2px; box-sizing: border-box; }
|
|
3146
|
+
.dg-trimHint { font-size: 11px; color: #b9c2cf; margin-bottom: 6px; }
|
|
3147
|
+
.dg-trimTrack {
|
|
3148
|
+
position: relative; height: 30px; border-radius: 6px;
|
|
3149
|
+
background: rgba(255,255,255,0.08); overflow: hidden; user-select: none;
|
|
3150
|
+
}
|
|
3151
|
+
.dg-trimTrackBg { position: absolute; inset: 0; }
|
|
3152
|
+
.dg-trimRegion { position: absolute; top: 0; bottom: 0; background: rgba(106,146,255,0.35); }
|
|
3153
|
+
.dg-trimHandle {
|
|
3154
|
+
position: absolute; top: 0; bottom: 0; width: 12px; background: #6a92ff;
|
|
3155
|
+
border-radius: 2px; cursor: ew-resize; box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
|
|
3156
|
+
/* 以时间点为**中心**;left 由内联样式给出并钳到 1%–99%。
|
|
3157
|
+
否则 outPoint=duration 时 left:100% 会让整条手柄溢出轨道被裁掉(只剩入点可见)。 */
|
|
3158
|
+
transform: translateX(-50%); z-index: 2;
|
|
3159
|
+
}
|
|
3160
|
+
.dg-trimHandleOut { background: #ff9e64; } /* 与入点区分,一眼看出有两个端点 */
|
|
3161
|
+
/* 播放头:让「播放跟随选定点」在轨道上可见;pointer-events:none 才不挡拖手柄 */
|
|
3162
|
+
.dg-trimPlayhead {
|
|
3163
|
+
position: absolute; top: 0; bottom: 0; width: 2px; background: #fff;
|
|
3164
|
+
box-shadow: 0 0 0 1px rgba(0,0,0,0.55); pointer-events: none; z-index: 4;
|
|
3165
|
+
}
|
|
3166
|
+
.dg-trimPlayhead::after {
|
|
3167
|
+
content: ''; position: absolute; top: 0; left: -3px;
|
|
3168
|
+
border-left: 4px solid transparent; border-right: 4px solid transparent;
|
|
3169
|
+
border-top: 6px solid #fff;
|
|
3170
|
+
}
|
|
3171
|
+
.dg-trimTicks { position: absolute; inset: 0; pointer-events: none; }
|
|
3172
|
+
.dg-trimLabel { position: absolute; top: 50%; transform: translateY(-50%); font-size: 10px; color: #e8eaed; pointer-events: none; }
|
|
3173
|
+
.dg-trimOps { display: flex; justify-content: center; gap: 8px; margin: 8px 0 4px; }
|
|
2952
3174
|
`
|
|
2953
3175
|
|
|
2954
3176
|
|
|
@@ -3010,6 +3232,125 @@ async function encodeMaskPngBytes(imageData, width, height) {
|
|
|
3010
3232
|
}
|
|
3011
3233
|
}
|
|
3012
3234
|
|
|
3235
|
+
/**
|
|
3236
|
+
* 取 File 的真实磁盘路径(Electron)。
|
|
3237
|
+
*
|
|
3238
|
+
* 为什么不能只看 `file.path`:Electron 32 起已移除 `File.prototype.path`,
|
|
3239
|
+
* 而 DSH 宿主是 Electron 44 —— 只看 file.path 会让「复制的文件」全部落到
|
|
3240
|
+
* 「当图片读」的分支,非图片文件直接失败。必须补 `webUtils.getPathForFile(file)`。
|
|
3241
|
+
*
|
|
3242
|
+
* @returns {string} 绝对路径;拿不到返回空串
|
|
3243
|
+
*/
|
|
3244
|
+
function filePathOf(file) {
|
|
3245
|
+
if (file === null || file === undefined) return ''
|
|
3246
|
+
// ① 旧 Electron / 部分定制运行环境仍可能带 path
|
|
3247
|
+
if (typeof file.path === 'string' && file.path !== '') return file.path
|
|
3248
|
+
// ② 新 Electron 的正规入口:webUtils.getPathForFile
|
|
3249
|
+
try {
|
|
3250
|
+
const g = globalThis
|
|
3251
|
+
const req = typeof g.require === 'function' ? g.require : null
|
|
3252
|
+
if (req !== null) {
|
|
3253
|
+
const electron = req('electron')
|
|
3254
|
+
const webUtils = electron?.webUtils
|
|
3255
|
+
if (webUtils !== null && webUtils !== undefined && typeof webUtils.getPathForFile === 'function') {
|
|
3256
|
+
const p = webUtils.getPathForFile(file)
|
|
3257
|
+
if (typeof p === 'string' && p !== '') return p
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
} catch { /* 渲染进程未开 node 集成时正常失败,走下一档 */ }
|
|
3261
|
+
return ''
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
/**
|
|
3265
|
+
* v0.16.0 粘贴入口的剪贴板解析(纯逻辑,可单测)。
|
|
3266
|
+
*
|
|
3267
|
+
* Electron 渲染进程里:截图/复制的图片与复制的文件都走 `paste` 事件的
|
|
3268
|
+
* `clipboardData.items`(`kind === 'file'`)。区别在能否拿到磁盘路径:
|
|
3269
|
+
* ① 复制的文件(资源管理器里 Ctrl+C):webUtils 给到真实绝对路径;
|
|
3270
|
+
* ② 截图/复制的图片:没有路径,但 `getAsFile()` 给到 Blob,可转 base64。
|
|
3271
|
+
* 所以:有路径 → 走「粘贴文件」(Host 直接 copyFile);无路径 → 按图片转 base64。
|
|
3272
|
+
*/
|
|
3273
|
+
function extractFromPasteEvent(clipboardData) {
|
|
3274
|
+
/** @type {File[]} */
|
|
3275
|
+
const images = []
|
|
3276
|
+
/** @type {{ path: string, name: string }[]} */
|
|
3277
|
+
const files = []
|
|
3278
|
+
if (clipboardData === null || clipboardData === undefined) return { images, files }
|
|
3279
|
+
const items = clipboardData.items
|
|
3280
|
+
if (items === null || items === undefined) return { images, files }
|
|
3281
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
3282
|
+
const it = items[i]
|
|
3283
|
+
if (it === null || it === undefined || it.kind !== 'file') continue
|
|
3284
|
+
let file = null
|
|
3285
|
+
try { file = it.getAsFile() } catch { continue }
|
|
3286
|
+
if (file === null) continue
|
|
3287
|
+
const p = filePathOf(file)
|
|
3288
|
+
if (p !== '') {
|
|
3289
|
+
const name = (typeof file.name === 'string' && file.name !== '') ? file.name : (p.split(/[\\/]/).pop() || 'file')
|
|
3290
|
+
files.push({ path: p, name })
|
|
3291
|
+
} else {
|
|
3292
|
+
// 无磁盘路径的 Blob 只有图片能直接转 base64 落盘。音视频 / PDF / ZIP
|
|
3293
|
+
// 在 Chromium 里拿不到路径,若塞进 images 会让 ingestPasted 判「不支持」
|
|
3294
|
+
// 而短路,Host 的系统剪贴板兜底就没机会跑 —— 这里明确跳过。
|
|
3295
|
+
const mime = typeof file.type === 'string' ? file.type : ''
|
|
3296
|
+
if (mime === '' || mime.startsWith('image/')) images.push(file)
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
return { images, files }
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
/**
|
|
3303
|
+
* v0.16.0:判断是不是「纯文本粘贴」—— 这类粘贴必须放行,不能抢。
|
|
3304
|
+
* 从资源管理器复制的文件在 Chromium 里可能只挂一个 text/plain 条目,
|
|
3305
|
+
* 但它同时带 Files / 非纯文本类型;只有**真的只有文本**才放行。
|
|
3306
|
+
*/
|
|
3307
|
+
function isPlainTextPaste(clipboardData) {
|
|
3308
|
+
if (clipboardData === null || clipboardData === undefined) return false
|
|
3309
|
+
const types = Array.from(clipboardData.types ?? [])
|
|
3310
|
+
if (types.length === 0) return false
|
|
3311
|
+
if (!types.every((x) => x === 'text/plain')) return false
|
|
3312
|
+
let text = ''
|
|
3313
|
+
try { text = String(clipboardData.getData('text/plain') ?? '') } catch { return false }
|
|
3314
|
+
return text !== ''
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
/** 把 File/Blob 读成 dataURL(含 `data:…;base64,` 前缀)。 */
|
|
3318
|
+
function fileToDataUrl(file) {
|
|
3319
|
+
return new Promise((resolve, reject) => {
|
|
3320
|
+
const reader = new FileReader()
|
|
3321
|
+
reader.onload = () => resolve(String(reader.result))
|
|
3322
|
+
reader.onerror = () => reject(reader.error ?? new Error('FileReader failed'))
|
|
3323
|
+
reader.readAsDataURL(file)
|
|
3324
|
+
})
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
/**
|
|
3328
|
+
* 程序化读剪贴板(右键菜单「粘贴」用,无 paste 事件)。
|
|
3329
|
+
* `navigator.clipboard.read()` 能拿到图片(截图/复制的图),但拿不到任意文件,
|
|
3330
|
+
* 所以这里只返回图片;文件类粘贴统一走 Ctrl+V(见 extractFromPasteEvent)。
|
|
3331
|
+
* @returns {Promise<File[]>} 图片 Blob 列表
|
|
3332
|
+
*/
|
|
3333
|
+
async function readClipboardImages() {
|
|
3334
|
+
const nav = navigator
|
|
3335
|
+
if (nav === null || nav === undefined || nav.clipboard === null || nav.clipboard === undefined) return []
|
|
3336
|
+
if (typeof nav.clipboard.read !== 'function') return []
|
|
3337
|
+
let items = []
|
|
3338
|
+
try { items = await nav.clipboard.read() } catch { return [] }
|
|
3339
|
+
/** @type {File[]} */
|
|
3340
|
+
const out = []
|
|
3341
|
+
for (const ci of items) {
|
|
3342
|
+
if (ci === null || ci === undefined || typeof ci.types === 'undefined') continue
|
|
3343
|
+
for (const type of ci.types) {
|
|
3344
|
+
if (typeof type !== 'string' || !type.startsWith('image/')) continue
|
|
3345
|
+
try {
|
|
3346
|
+
const blob = await ci.getType(type)
|
|
3347
|
+
if (blob !== null) out.push(blob)
|
|
3348
|
+
} catch { /* 忽略单个类型失败 */ }
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return out
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3013
3354
|
/**
|
|
3014
3355
|
* 文件卡片:三段式布局。
|
|
3015
3356
|
* ① 头部:类型图标 + 文件名 + 简介(悬停展开,此处用大小/时间)
|
|
@@ -4082,14 +4423,30 @@ function serializeFeedback(feedback) {
|
|
|
4082
4423
|
style: { left: `${pos.left}px`, top: `${pos.top}px` },
|
|
4083
4424
|
}, [
|
|
4084
4425
|
h('div', { className: 'dg-ctxHead', key: 'head' }, item.name),
|
|
4426
|
+
// v0.16.0:列表级「粘贴」(右键任意处都可出现);无 item 的空白区菜单只给这一项
|
|
4427
|
+
actions.onPaste !== undefined
|
|
4428
|
+
? entry('paste', t('ctxPaste'), '📥', () => actions.onPaste())
|
|
4429
|
+
: null,
|
|
4085
4430
|
// 「查看原图」只对图片出现:文件卡片没有原图概念,避免无效按钮
|
|
4086
4431
|
actions.onOpenOriginal !== undefined
|
|
4087
4432
|
? entry('original', t('ctxOpenOriginal'), '🔍', () => actions.onOpenOriginal())
|
|
4088
4433
|
: null,
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4434
|
+
actions.onHide !== undefined
|
|
4435
|
+
? entry('hide', t('ctxHide'), '🚫', () => actions.onHide())
|
|
4436
|
+
: null,
|
|
4437
|
+
actions.onReveal !== undefined
|
|
4438
|
+
? entry('reveal', t('ctxReveal'), '📂', () => actions.onReveal())
|
|
4439
|
+
: null,
|
|
4440
|
+
actions.onCopy !== undefined
|
|
4441
|
+
? entry('copy', t('ctxCopy'), '⧉', () => actions.onCopy())
|
|
4442
|
+
: null,
|
|
4443
|
+
// v0.16.0:复制**文件本体**到系统剪贴板(与上面的「复制路径」文本区分)
|
|
4444
|
+
actions.onCopyFile !== undefined
|
|
4445
|
+
? entry('copyFile', t('ctxCopyFile'), '📄', () => actions.onCopyFile())
|
|
4446
|
+
: null,
|
|
4447
|
+
actions.onDelete !== undefined
|
|
4448
|
+
? entry('delete', t('ctxDelete'), '🗑', () => actions.onDelete(), true)
|
|
4449
|
+
: null,
|
|
4093
4450
|
// ---- v0.14.2 手动标签:表态层已下线,只留「改标签 / 恢复自动」两个入口 ----
|
|
4094
4451
|
actions.onEditLabel !== undefined
|
|
4095
4452
|
? h('div', { className: 'dg-ctxDivider', key: 'labelDivider' }, t('labelEdit'))
|
|
@@ -4432,6 +4789,18 @@ function serializeFeedback(feedback) {
|
|
|
4432
4789
|
const [dims, setDims] = React.useState(null)
|
|
4433
4790
|
// 截帧结果提示(成功/失败),2.5 秒自动消失
|
|
4434
4791
|
const [grabNotice, setGrabNotice] = React.useState(null)
|
|
4792
|
+
// v0.16.0 音视频选段(入点/出点裁剪)
|
|
4793
|
+
const [duration, setDuration] = React.useState(0)
|
|
4794
|
+
const [trimActive, setTrimActive] = React.useState(false)
|
|
4795
|
+
const [inPoint, setInPoint] = React.useState(0)
|
|
4796
|
+
const [outPoint, setOutPoint] = React.useState(0)
|
|
4797
|
+
const [trimBusy, setTrimBusy] = React.useState(false)
|
|
4798
|
+
// previewing = 正在按选区播放(到出点会自动置 false);不再是「循环预览」开关
|
|
4799
|
+
const [previewing, setPreviewing] = React.useState(false)
|
|
4800
|
+
const [playhead, setPlayhead] = React.useState(0)
|
|
4801
|
+
const trimTrackRef = React.useRef(null)
|
|
4802
|
+
// 拖动端点期间不做区间钳制,否则播放头会被反复拽回、没法目视选帧
|
|
4803
|
+
const scrubbingRef = React.useRef(false)
|
|
4435
4804
|
|
|
4436
4805
|
// 取回完整文件为 blob 并建 URL(支持 seek 的唯一可靠路径)
|
|
4437
4806
|
React.useEffect(() => {
|
|
@@ -4589,13 +4958,233 @@ function serializeFeedback(feedback) {
|
|
|
4589
4958
|
return () => clearTimeout(timer)
|
|
4590
4959
|
}, [grabNotice])
|
|
4591
4960
|
|
|
4961
|
+
/**
|
|
4962
|
+
* v0.16.0:把播放头移到指定秒(拖端点 / 点轨道 / 从入点重播共用)。
|
|
4963
|
+
* 只改 currentTime 不换 src —— React 复用同一个 <video> DOM,播放不会被重建。
|
|
4964
|
+
*/
|
|
4965
|
+
const seekMedia = (sec) => {
|
|
4966
|
+
const v = videoRef.current
|
|
4967
|
+
if (v === null || duration <= 0) return
|
|
4968
|
+
try { v.currentTime = clampNum(sec, 0, duration) } catch { /* 元数据未就绪 */ }
|
|
4969
|
+
}
|
|
4970
|
+
/** 播放头跟随选段:更新轨道指示线 + 到出点暂停 + 区间外起播拉回入点。 */
|
|
4971
|
+
const onMediaTimeUpdate = (event) => {
|
|
4972
|
+
const v = event.currentTarget
|
|
4973
|
+
const now = v.currentTime
|
|
4974
|
+
// 只在选段态更新播放头:没开选段时不必每 250ms 重渲染整个播放器
|
|
4975
|
+
if (trimActive && Number.isFinite(now)) setPlayhead(now)
|
|
4976
|
+
if (!trimActive) return
|
|
4977
|
+
const d = trimPlaybackDecision(now, inPoint, outPoint, {
|
|
4978
|
+
paused: v.paused, scrubbing: scrubbingRef.current,
|
|
4979
|
+
})
|
|
4980
|
+
if (d.action === 'stop') {
|
|
4981
|
+
try {
|
|
4982
|
+
if (typeof d.seekTo === 'number' && Math.abs(v.currentTime - d.seekTo) > 0.001) v.currentTime = d.seekTo
|
|
4983
|
+
v.pause()
|
|
4984
|
+
} catch { /* 忽略 */ }
|
|
4985
|
+
setPreviewing(false)
|
|
4986
|
+
} else if (d.action === 'seekIn') {
|
|
4987
|
+
try { v.currentTime = d.seekTo } catch { /* 忽略 */ }
|
|
4988
|
+
}
|
|
4989
|
+
}
|
|
4990
|
+
/** 用户按原生播放键时,播放头若不在选区内,直接跳到入点起播。 */
|
|
4991
|
+
const onMediaPlay = (event) => {
|
|
4992
|
+
if (!trimActive) return
|
|
4993
|
+
const v = event.currentTarget
|
|
4994
|
+
const now = v.currentTime
|
|
4995
|
+
if (!(outPoint > inPoint + 0.05)) return
|
|
4996
|
+
if (now < inPoint - 0.25 || now >= outPoint - 0.05) {
|
|
4997
|
+
try { v.currentTime = inPoint } catch { /* 忽略 */ }
|
|
4998
|
+
}
|
|
4999
|
+
}
|
|
5000
|
+
// v0.16.0 音视频选段:秒数 → m:ss
|
|
5001
|
+
const fmtClock = (sec) => {
|
|
5002
|
+
const s = Math.max(0, Math.floor(Number(sec) || 0))
|
|
5003
|
+
const m = Math.floor(s / 60)
|
|
5004
|
+
const r = s % 60
|
|
5005
|
+
return `${m}:${String(r).padStart(2, '0')}`
|
|
5006
|
+
}
|
|
5007
|
+
// 轨道坐标 → 时间
|
|
5008
|
+
const timeFromClientX = (clientX) => {
|
|
5009
|
+
const track = trimTrackRef.current
|
|
5010
|
+
if (track === null || duration <= 0) return 0
|
|
5011
|
+
const r = track.getBoundingClientRect()
|
|
5012
|
+
if (r.width <= 0) return 0
|
|
5013
|
+
return clampNum((clientX - r.left) / r.width, 0, 1) * duration
|
|
5014
|
+
}
|
|
5015
|
+
// 拖动入点/出点滑块(用 window 监听保证拖出元素也不丢)
|
|
5016
|
+
const startTrimDrag = (e, which) => {
|
|
5017
|
+
e.preventDefault()
|
|
5018
|
+
e.stopPropagation()
|
|
5019
|
+
try { e.currentTarget.setPointerCapture(e.pointerId) } catch {}
|
|
5020
|
+
// 拖动期间暂停区间钳制,让画面**跟着端点走**(老板要的「播放跟随选定点」)
|
|
5021
|
+
scrubbingRef.current = true
|
|
5022
|
+
const move = (ev) => {
|
|
5023
|
+
const t = timeFromClientX(ev.clientX)
|
|
5024
|
+
if (which === 'in') {
|
|
5025
|
+
const n = clampNum(t, 0, Math.max(0, outPoint - 0.1))
|
|
5026
|
+
setInPoint(n); seekMedia(n); setPlayhead(n)
|
|
5027
|
+
} else if (which === 'out') {
|
|
5028
|
+
const n = clampNum(t, Math.min(duration, inPoint + 0.1), duration)
|
|
5029
|
+
setOutPoint(n); seekMedia(n); setPlayhead(n)
|
|
5030
|
+
}
|
|
5031
|
+
}
|
|
5032
|
+
const up = () => {
|
|
5033
|
+
scrubbingRef.current = false
|
|
5034
|
+
window.removeEventListener('pointermove', move)
|
|
5035
|
+
window.removeEventListener('pointerup', up)
|
|
5036
|
+
}
|
|
5037
|
+
window.addEventListener('pointermove', move)
|
|
5038
|
+
window.addEventListener('pointerup', up)
|
|
5039
|
+
}
|
|
5040
|
+
/**
|
|
5041
|
+
* 点轨道空白处也能设点:把离点击位置**最近**的那个端点移过来。
|
|
5042
|
+
* 手柄自身的 onPointerDown 已 stopPropagation,不会误触发这里。
|
|
5043
|
+
* 有了这条,即使出点贴到最右端,老板也能直接点轨道右侧把它拉回来。
|
|
5044
|
+
*/
|
|
5045
|
+
const onTrackPointerDown = (e) => {
|
|
5046
|
+
if (duration <= 0) return
|
|
5047
|
+
e.preventDefault()
|
|
5048
|
+
const t = timeFromClientX(e.clientX)
|
|
5049
|
+
let n
|
|
5050
|
+
if (Math.abs(t - inPoint) <= Math.abs(t - outPoint)) {
|
|
5051
|
+
n = clampNum(t, 0, Math.max(0, outPoint - 0.1))
|
|
5052
|
+
setInPoint(n)
|
|
5053
|
+
} else {
|
|
5054
|
+
n = clampNum(t, Math.min(duration, inPoint + 0.1), duration)
|
|
5055
|
+
setOutPoint(n)
|
|
5056
|
+
}
|
|
5057
|
+
// 点轨道设点后,播放头也跳到该点,方便目视核对这一帧
|
|
5058
|
+
seekMedia(n); setPlayhead(n)
|
|
5059
|
+
}
|
|
5060
|
+
/**
|
|
5061
|
+
* 进入选段 / 拿到时长后:立刻把播放头移到入点并起播。
|
|
5062
|
+
*
|
|
5063
|
+
* 老板 11:56 反馈的根因就在这里 —— 原来只有点「预览选区」才 seek,
|
|
5064
|
+
* 不点的话播放器一直按整段自动播(选段 2:16–3:21,播放头却停在 0:29)。
|
|
5065
|
+
* 依赖数组刻意不含 inPoint/outPoint:拖动端点不该重复触发这个 effect。
|
|
5066
|
+
*/
|
|
5067
|
+
React.useEffect(() => {
|
|
5068
|
+
if (!trimActive || duration <= 0) return
|
|
5069
|
+
const initIn = outPoint > 0 ? inPoint : duration * 0.2
|
|
5070
|
+
if (outPoint <= 0) {
|
|
5071
|
+
setInPoint(duration * 0.2); setOutPoint(duration * 0.8)
|
|
5072
|
+
}
|
|
5073
|
+
seekMedia(initIn)
|
|
5074
|
+
setPlayhead(initIn)
|
|
5075
|
+
const v = videoRef.current
|
|
5076
|
+
if (v === null) return
|
|
5077
|
+
try { v.play().catch(() => {}) } catch { /* 自动播放被拦就等用户点按钮 */ }
|
|
5078
|
+
setPreviewing(true)
|
|
5079
|
+
}, [trimActive, duration])
|
|
5080
|
+
// 退出选段时清掉「按选区播放」标记,恢复原生自由播放
|
|
5081
|
+
React.useEffect(() => {
|
|
5082
|
+
if (!trimActive) setPreviewing(false)
|
|
5083
|
+
}, [trimActive])
|
|
5084
|
+
const saveTrim = React.useCallback(async () => {
|
|
5085
|
+
if (duration <= 0 || outPoint <= inPoint + 0.05) {
|
|
5086
|
+
setGrabNotice({ kind: 'fail', text: t('cropMinSize') })
|
|
5087
|
+
return
|
|
5088
|
+
}
|
|
5089
|
+
setTrimBusy(true)
|
|
5090
|
+
try {
|
|
5091
|
+
const payload = await callHost('cropMedia', {
|
|
5092
|
+
path: item.relPath,
|
|
5093
|
+
start: Math.round(inPoint * 1000) / 1000,
|
|
5094
|
+
end: Math.round(outPoint * 1000) / 1000,
|
|
5095
|
+
kind: isVideo ? 'video' : 'audio',
|
|
5096
|
+
// v0.16.1:带上对话身份,Host 才能把片段登记回当前对话组;
|
|
5097
|
+
// 不传的话全局资产会把它扔进「未归类」,界面上等于「切了但没生成」。
|
|
5098
|
+
sessionId: sessionId ?? '',
|
|
5099
|
+
sessionTitle: sessionTitle ?? '',
|
|
5100
|
+
sessionCreatedAt: sessionCreatedAt ?? 0,
|
|
5101
|
+
})
|
|
5102
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? 'cropMedia failed')
|
|
5103
|
+
if (typeof onSaved === 'function') onSaved(payload)
|
|
5104
|
+
setGrabNotice({ kind: 'ok', text: format(t('trimSaved'), { name: payload?.name ?? '' }) })
|
|
5105
|
+
} catch (error) {
|
|
5106
|
+
setGrabNotice({ kind: 'fail', text: format(t('trimFailed'), { message: String(error?.message ?? error) }) })
|
|
5107
|
+
} finally {
|
|
5108
|
+
setTrimBusy(false)
|
|
5109
|
+
}
|
|
5110
|
+
}, [duration, inPoint, outPoint, isVideo, item.relPath, onSaved, t, sessionId, sessionTitle, sessionCreatedAt])
|
|
5111
|
+
const trimUI = (trimActive && duration > 0)
|
|
5112
|
+
? h('div', {
|
|
5113
|
+
className: 'dg-trimWrap', key: 'trim', 'data-gallery-trim': item.relPath,
|
|
5114
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
5115
|
+
}, [
|
|
5116
|
+
h('div', { className: 'dg-trimHint', key: 'hint' }, t('trimDragHint')),
|
|
5117
|
+
h('div', {
|
|
5118
|
+
className: 'dg-trimTrack', key: 'track', ref: trimTrackRef,
|
|
5119
|
+
'data-gallery-trim-track': true,
|
|
5120
|
+
onPointerDown: onTrackPointerDown,
|
|
5121
|
+
}, [
|
|
5122
|
+
h('div', {
|
|
5123
|
+
className: 'dg-trimRegion', key: 'region',
|
|
5124
|
+
style: {
|
|
5125
|
+
left: `${(inPoint / duration) * 100}%`,
|
|
5126
|
+
width: `${((outPoint - inPoint) / duration) * 100}%`,
|
|
5127
|
+
},
|
|
5128
|
+
}),
|
|
5129
|
+
h('div', {
|
|
5130
|
+
className: 'dg-trimHandle dg-trimHandleIn', key: 'in',
|
|
5131
|
+
'data-gallery-trim-in': true,
|
|
5132
|
+
// 钳到 1%–99%:配合 CSS 的 translateX(-50%),贴边时仍露出半个手柄可拖
|
|
5133
|
+
style: { left: `${clampNum((inPoint / duration) * 100, 1, 99)}%` },
|
|
5134
|
+
onPointerDown: (e) => startTrimDrag(e, 'in'),
|
|
5135
|
+
}),
|
|
5136
|
+
h('div', {
|
|
5137
|
+
className: 'dg-trimHandle dg-trimHandleOut', key: 'out',
|
|
5138
|
+
'data-gallery-trim-out': true,
|
|
5139
|
+
style: { left: `${clampNum((outPoint / duration) * 100, 1, 99)}%` },
|
|
5140
|
+
onPointerDown: (e) => startTrimDrag(e, 'out'),
|
|
5141
|
+
}),
|
|
5142
|
+
// 白色播放头:让「播放跟随选定点」在轨道上可见
|
|
5143
|
+
h('div', {
|
|
5144
|
+
className: 'dg-trimPlayhead', key: 'playhead',
|
|
5145
|
+
'data-gallery-trim-playhead': true,
|
|
5146
|
+
style: { left: `${clampNum((playhead / duration) * 100, 0, 100)}%` },
|
|
5147
|
+
}),
|
|
5148
|
+
]),
|
|
5149
|
+
h('div', {
|
|
5150
|
+
className: 'dg-trimLabels', key: 'labels',
|
|
5151
|
+
style: { display: 'flex', justifyContent: 'space-between', fontSize: '11px', color: '#b9c2cf', marginTop: '4px' },
|
|
5152
|
+
}, [
|
|
5153
|
+
h('span', { key: 'li' }, `${t('trimIn')} ${fmtClock(inPoint)}`),
|
|
5154
|
+
h('span', { key: 'lo' }, `${t('trimOut')} ${fmtClock(outPoint)}`),
|
|
5155
|
+
]),
|
|
5156
|
+
h('div', { className: 'dg-trimOps', key: 'ops' }, [
|
|
5157
|
+
h('button', {
|
|
5158
|
+
type: 'button', className: 'dg-btn', key: 'preview',
|
|
5159
|
+
onClick: (e) => {
|
|
5160
|
+
e.stopPropagation()
|
|
5161
|
+
const v = videoRef.current
|
|
5162
|
+
if (previewing) {
|
|
5163
|
+
try { v?.pause() } catch { /* 忽略 */ }
|
|
5164
|
+
setPreviewing(false)
|
|
5165
|
+
} else {
|
|
5166
|
+
// 从入点重播(播放到出点由 onMediaTimeUpdate 自动停住)
|
|
5167
|
+
seekMedia(inPoint); setPlayhead(inPoint)
|
|
5168
|
+
try { v?.play().catch(() => {}) } catch { /* 忽略 */ }
|
|
5169
|
+
setPreviewing(true)
|
|
5170
|
+
}
|
|
5171
|
+
},
|
|
5172
|
+
}, previewing ? `⏸ ${t('trimPause')}` : `▶ ${t('trimPreview')}`),
|
|
5173
|
+
h('button', {
|
|
5174
|
+
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'save', disabled: trimBusy,
|
|
5175
|
+
onClick: (e) => { e.stopPropagation(); void saveTrim() },
|
|
5176
|
+
}, trimBusy ? t('trimSaving') : t('trimSave')),
|
|
5177
|
+
]),
|
|
5178
|
+
])
|
|
5179
|
+
: null
|
|
5180
|
+
|
|
4592
5181
|
return h('div', {
|
|
4593
5182
|
className: 'dg-mediaLayer',
|
|
4594
5183
|
key: 'mediaLayer',
|
|
4595
5184
|
'data-gallery-player': item.relPath,
|
|
4596
5185
|
onClick: onClose,
|
|
4597
5186
|
}, h('div', {
|
|
4598
|
-
className: `dg-mediaPanel${isVideo ? ' dg-mediaPanelVideo' : ' dg-mediaPanelAudio'}`,
|
|
5187
|
+
className: `dg-mediaPanel${isVideo ? ' dg-mediaPanelVideo' : ' dg-mediaPanelAudio'}${trimActive ? ' is-trim' : ''}`,
|
|
4599
5188
|
key: 'panel',
|
|
4600
5189
|
onClick: (event) => event.stopPropagation(),
|
|
4601
5190
|
}, [
|
|
@@ -4612,6 +5201,23 @@ function serializeFeedback(feedback) {
|
|
|
4612
5201
|
onClick: (event) => { event.stopPropagation(); grabFrame() },
|
|
4613
5202
|
}, ['📷 ', t('mediaGrabFrame')])
|
|
4614
5203
|
: null,
|
|
5204
|
+
// v0.16.0 选段裁剪:开关入点/出点选段 UI
|
|
5205
|
+
source.status === 'ready' && !failed
|
|
5206
|
+
? h('button', {
|
|
5207
|
+
type: 'button',
|
|
5208
|
+
className: `dg-btn${trimActive ? ' dg-btnActive' : ''}`,
|
|
5209
|
+
key: 'trim',
|
|
5210
|
+
'data-gallery-trim-toggle': item.relPath,
|
|
5211
|
+
title: trimActive ? t('trimExit') : t('trimEnter'),
|
|
5212
|
+
'aria-label': trimActive ? t('trimExit') : t('trimEnter'),
|
|
5213
|
+
onClick: (event) => {
|
|
5214
|
+
event.stopPropagation()
|
|
5215
|
+
// 默认选区与「跳到入点起播」都交给下面的进入 effect,
|
|
5216
|
+
// 这里只做状态切换(updater 里不要塞副作用)。
|
|
5217
|
+
setTrimActive((v) => !v)
|
|
5218
|
+
},
|
|
5219
|
+
}, ['✂ ', trimActive ? t('trimExit') : t('trimEnter')])
|
|
5220
|
+
: null,
|
|
4615
5221
|
h('button', {
|
|
4616
5222
|
type: 'button', className: 'dg-btn', key: 'close',
|
|
4617
5223
|
title: t('mediaCloseHint'), 'aria-label': t('mediaCloseHint'),
|
|
@@ -4676,10 +5282,13 @@ function serializeFeedback(feedback) {
|
|
|
4676
5282
|
preload: 'metadata',
|
|
4677
5283
|
key: 'v',
|
|
4678
5284
|
'data-gallery-video': item.relPath,
|
|
5285
|
+
onTimeUpdate: onMediaTimeUpdate,
|
|
5286
|
+
onPlay: onMediaPlay,
|
|
4679
5287
|
onError: () => setFailed(true),
|
|
4680
5288
|
onLoadedMetadata: (event) => {
|
|
4681
5289
|
const v = event.currentTarget
|
|
4682
5290
|
if (v.videoWidth > 0) setDims({ w: v.videoWidth, h: v.videoHeight })
|
|
5291
|
+
if (Number.isFinite(v.duration) && v.duration > 0) setDuration(v.duration)
|
|
4683
5292
|
},
|
|
4684
5293
|
})
|
|
4685
5294
|
: h('audio', {
|
|
@@ -4689,9 +5298,17 @@ function serializeFeedback(feedback) {
|
|
|
4689
5298
|
preload: 'metadata',
|
|
4690
5299
|
key: 'a',
|
|
4691
5300
|
'data-gallery-audio': item.relPath,
|
|
5301
|
+
ref: videoRef,
|
|
5302
|
+
onTimeUpdate: onMediaTimeUpdate,
|
|
5303
|
+
onPlay: onMediaPlay,
|
|
4692
5304
|
onError: () => setFailed(true),
|
|
5305
|
+
onLoadedMetadata: (event) => {
|
|
5306
|
+
const a = event.currentTarget
|
|
5307
|
+
if (Number.isFinite(a.duration) && a.duration > 0) setDuration(a.duration)
|
|
5308
|
+
},
|
|
4693
5309
|
})
|
|
4694
5310
|
)),
|
|
5311
|
+
trimUI,
|
|
4695
5312
|
h('div', { className: 'dg-mediaFoot', key: 'foot' }, [
|
|
4696
5313
|
h('span', { className: 'dg-mediaFootName', key: 'name', title: item.relPath }, item.name),
|
|
4697
5314
|
h('span', { className: 'dg-mediaFootMeta', key: 'meta' },
|
|
@@ -4938,7 +5555,279 @@ ${absPath}
|
|
|
4938
5555
|
* - 右键预览区、按 O、点底部按钮 三种方式切换
|
|
4939
5556
|
* - 切换时**保留当前缩放与位置**,否则切过去跳回 1x 就没法对比
|
|
4940
5557
|
*/
|
|
4941
|
-
|
|
5558
|
+
|
|
5559
|
+
/**
|
|
5560
|
+
* v0.16.0 图片裁剪 + 微信式圆形放大镜。
|
|
5561
|
+
*
|
|
5562
|
+
* 设计要点:
|
|
5563
|
+
* · 固定覆盖层(viewport 坐标),与查看器的 pan/zoom 解耦 —— 归一化坐标由图片在屏幕上的
|
|
5564
|
+
* 实际矩形算出,无论放大/平移都准确。
|
|
5565
|
+
* · 放大镜与最终裁图都从「全分辨率源图」取像素(fetchRaw 现拉),保证细节真实、不被预览缩放糊掉。
|
|
5566
|
+
* · 裁剪结果(归一化矩形)交给上层 callHost('cropImage'),落盘到源图同目录并标素材。
|
|
5567
|
+
* · 零自动发送红线不变:本组件只产出 PNG,落盘与登记由 Host 完成。
|
|
5568
|
+
*/
|
|
5569
|
+
function ImageCropper({ t, item, imgRef, onCrop, onCancel }) {
|
|
5570
|
+
const [rect, setRect] = React.useState(null) // {x,y,w,h} 归一化 0–1(相对图片宽高)
|
|
5571
|
+
const [drag, setDrag] = React.useState(null) // { mode:'new'|'move'|'nw'|'ne'|'sw'|'se', sx, sy, startRect }
|
|
5572
|
+
const [mag, setMag] = React.useState(null) // { cx, cy(视口), nx, ny(归一化) }
|
|
5573
|
+
const [full, setFull] = React.useState(null) // 全分辨率 HTMLImageElement
|
|
5574
|
+
const [busy, setBusy] = React.useState(false)
|
|
5575
|
+
const magCanvasRef = React.useRef(null)
|
|
5576
|
+
|
|
5577
|
+
// 载入全分辨率源图(放大镜取真实像素 + 最终裁图)
|
|
5578
|
+
React.useEffect(() => {
|
|
5579
|
+
let alive = true
|
|
5580
|
+
const controller = new AbortController()
|
|
5581
|
+
fetchRaw(item.relPath, controller.signal)
|
|
5582
|
+
.then((blob) => {
|
|
5583
|
+
if (!alive) return
|
|
5584
|
+
const url = URL.createObjectURL(blob)
|
|
5585
|
+
const im = new Image()
|
|
5586
|
+
im.onload = () => { if (alive) setFull(im) }
|
|
5587
|
+
im.onerror = () => {}
|
|
5588
|
+
im.src = url
|
|
5589
|
+
})
|
|
5590
|
+
.catch(() => {})
|
|
5591
|
+
return () => { alive = false; controller.abort() }
|
|
5592
|
+
}, [item.relPath])
|
|
5593
|
+
|
|
5594
|
+
// 图片在屏幕上的实际矩形(getBoundingClientRect 含 zoom/pan 变换后的真实位置)
|
|
5595
|
+
const imgRect = () => {
|
|
5596
|
+
const el = imgRef.current
|
|
5597
|
+
if (el === null) return null
|
|
5598
|
+
const r = el.getBoundingClientRect()
|
|
5599
|
+
if (r.width <= 0 || r.height <= 0) return null
|
|
5600
|
+
return r
|
|
5601
|
+
}
|
|
5602
|
+
const toNorm = (clientX, clientY) => {
|
|
5603
|
+
const r = imgRect()
|
|
5604
|
+
if (r === null) return null
|
|
5605
|
+
return {
|
|
5606
|
+
x: clamp01((clientX - r.left) / r.width),
|
|
5607
|
+
y: clamp01((clientY - r.top) / r.height),
|
|
5608
|
+
}
|
|
5609
|
+
}
|
|
5610
|
+
// 由拖拽状态与新归一化点计算矩形;负宽高先规范化再夹到图像内。
|
|
5611
|
+
const computeRect = (d, n) => {
|
|
5612
|
+
if (d.mode === 'new') {
|
|
5613
|
+
return {
|
|
5614
|
+
x: Math.min(d.sx, n.x), y: Math.min(d.sy, n.y),
|
|
5615
|
+
w: Math.abs(n.x - d.sx), h: Math.abs(n.y - d.sy),
|
|
5616
|
+
}
|
|
5617
|
+
}
|
|
5618
|
+
const s = d.startRect
|
|
5619
|
+
if (s === null) return null
|
|
5620
|
+
let x = s.x
|
|
5621
|
+
let y = s.y
|
|
5622
|
+
let w = s.w
|
|
5623
|
+
let h = s.h
|
|
5624
|
+
if (d.mode === 'move') {
|
|
5625
|
+
x = clamp01(s.x + (n.x - d.sx))
|
|
5626
|
+
y = clamp01(s.y + (n.y - d.sy))
|
|
5627
|
+
x = Math.min(x, 1 - s.w)
|
|
5628
|
+
y = Math.min(y, 1 - s.h)
|
|
5629
|
+
return { x: Math.max(0, x), y: Math.max(0, y), w: s.w, h: s.h }
|
|
5630
|
+
}
|
|
5631
|
+
if (d.mode === 'se') { w = n.x - s.x; h = n.y - s.y }
|
|
5632
|
+
else if (d.mode === 'ne') { y = n.y; w = n.x - s.x; h = (s.y + s.h) - n.y }
|
|
5633
|
+
else if (d.mode === 'sw') { x = n.x; w = (s.x + s.w) - n.x; h = n.y - s.y }
|
|
5634
|
+
else if (d.mode === 'nw') { x = n.x; y = n.y; w = (s.x + s.w) - n.x; h = (s.y + s.h) - n.y }
|
|
5635
|
+
if (w < 0) { x += w; w = -w }
|
|
5636
|
+
if (h < 0) { y += h; h = -h }
|
|
5637
|
+
x = clamp01(x); y = clamp01(y); w = clamp01(w); h = clamp01(h)
|
|
5638
|
+
if (x + w > 1) w = 1 - x
|
|
5639
|
+
if (y + h > 1) h = 1 - y
|
|
5640
|
+
return { x, y, w, h }
|
|
5641
|
+
}
|
|
5642
|
+
const startDrag = (e, mode) => {
|
|
5643
|
+
e.preventDefault()
|
|
5644
|
+
e.stopPropagation()
|
|
5645
|
+
const n = toNorm(e.clientX, e.clientY)
|
|
5646
|
+
if (n === null) return
|
|
5647
|
+
try { e.currentTarget.setPointerCapture(e.pointerId) } catch {}
|
|
5648
|
+
setDrag({ mode, sx: n.x, sy: n.y, startRect: rect })
|
|
5649
|
+
}
|
|
5650
|
+
const onLayerDown = (e) => {
|
|
5651
|
+
const n = toNorm(e.clientX, e.clientY)
|
|
5652
|
+
if (n === null) return
|
|
5653
|
+
try { e.currentTarget.setPointerCapture(e.pointerId) } catch {}
|
|
5654
|
+
setDrag({ mode: 'new', sx: n.x, sy: n.y, startRect: null })
|
|
5655
|
+
setRect({ x: n.x, y: n.y, w: 0, h: 0 })
|
|
5656
|
+
}
|
|
5657
|
+
const onLayerMove = (e) => {
|
|
5658
|
+
const n = toNorm(e.clientX, e.clientY)
|
|
5659
|
+
if (n === null) return
|
|
5660
|
+
setMag({ cx: e.clientX, cy: e.clientY, nx: n.x, ny: n.y })
|
|
5661
|
+
if (drag === null) return
|
|
5662
|
+
setRect((cur) => computeRect(drag, n, cur))
|
|
5663
|
+
}
|
|
5664
|
+
const onLayerUp = () => setDrag(null)
|
|
5665
|
+
|
|
5666
|
+
// 放大镜绘制:从全分辨率源图取光标处的 3× 局部放大;越界区域填黑(与相机放大镜一致)。
|
|
5667
|
+
React.useEffect(() => {
|
|
5668
|
+
const canvas = magCanvasRef.current
|
|
5669
|
+
if (canvas === null || full === null || mag === null) return
|
|
5670
|
+
const ctx = canvas.getContext('2d')
|
|
5671
|
+
if (ctx === null) return
|
|
5672
|
+
const SIZE = canvas.width
|
|
5673
|
+
const FACTOR = 3
|
|
5674
|
+
const FW = full.naturalWidth
|
|
5675
|
+
const FH = full.naturalHeight
|
|
5676
|
+
const halfSrc = (SIZE / FACTOR) / 2
|
|
5677
|
+
const sx = clampNum(mag.nx * FW - halfSrc, 0, Math.max(0, FW - SIZE / FACTOR))
|
|
5678
|
+
const sy = clampNum(mag.ny * FH - halfSrc, 0, Math.max(0, FH - SIZE / FACTOR))
|
|
5679
|
+
ctx.fillStyle = '#000'
|
|
5680
|
+
ctx.fillRect(0, 0, SIZE, SIZE)
|
|
5681
|
+
ctx.drawImage(full, sx, sy, SIZE / FACTOR, SIZE / FACTOR, 0, 0, SIZE, SIZE)
|
|
5682
|
+
ctx.strokeStyle = 'rgba(255,255,255,0.85)'
|
|
5683
|
+
ctx.lineWidth = 1
|
|
5684
|
+
ctx.beginPath()
|
|
5685
|
+
ctx.moveTo(SIZE / 2, 0); ctx.lineTo(SIZE / 2, SIZE)
|
|
5686
|
+
ctx.moveTo(0, SIZE / 2); ctx.lineTo(SIZE, SIZE / 2)
|
|
5687
|
+
ctx.stroke()
|
|
5688
|
+
}, [mag, full])
|
|
5689
|
+
|
|
5690
|
+
const confirmCrop = () => {
|
|
5691
|
+
if (full === null || rect === null || rect.w < 0.02 || rect.h < 0.02) return
|
|
5692
|
+
setBusy(true)
|
|
5693
|
+
const FW = full.naturalWidth
|
|
5694
|
+
const FH = full.naturalHeight
|
|
5695
|
+
const sx = Math.round(rect.x * FW)
|
|
5696
|
+
const sy = Math.round(rect.y * FH)
|
|
5697
|
+
const sw = Math.max(1, Math.round(rect.w * FW))
|
|
5698
|
+
const sh = Math.max(1, Math.round(rect.h * FH))
|
|
5699
|
+
try {
|
|
5700
|
+
const canvas = document.createElement('canvas')
|
|
5701
|
+
canvas.width = sw
|
|
5702
|
+
canvas.height = sh
|
|
5703
|
+
const c2d = canvas.getContext('2d')
|
|
5704
|
+
if (c2d === null) throw new Error('no 2d context')
|
|
5705
|
+
c2d.drawImage(full, sx, sy, sw, sh, 0, 0, sw, sh)
|
|
5706
|
+
canvas.toBlob((blob) => {
|
|
5707
|
+
if (blob === null) { setBusy(false); return }
|
|
5708
|
+
const fr = new FileReader()
|
|
5709
|
+
fr.onload = () => {
|
|
5710
|
+
const dataUrl = String(fr.result)
|
|
5711
|
+
const comma = dataUrl.indexOf(',')
|
|
5712
|
+
const base64 = comma >= 0 ? dataUrl.slice(comma + 1) : dataUrl
|
|
5713
|
+
setBusy(false)
|
|
5714
|
+
onCrop(base64)
|
|
5715
|
+
}
|
|
5716
|
+
fr.onerror = () => setBusy(false)
|
|
5717
|
+
fr.readAsDataURL(blob)
|
|
5718
|
+
}, 'image/png')
|
|
5719
|
+
} catch (error) {
|
|
5720
|
+
setBusy(false)
|
|
5721
|
+
console.error('dsh-gallery: 裁剪失败', error)
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
|
|
5725
|
+
const r = imgRect()
|
|
5726
|
+
const rectStyle = rect !== null && r !== null
|
|
5727
|
+
? {
|
|
5728
|
+
left: `${r.left + rect.x * r.width}px`,
|
|
5729
|
+
top: `${r.top + rect.y * r.height}px`,
|
|
5730
|
+
width: `${rect.w * r.width}px`,
|
|
5731
|
+
height: `${rect.h * r.height}px`,
|
|
5732
|
+
}
|
|
5733
|
+
: {}
|
|
5734
|
+
const magX = mag !== null ? clampNum(mag.cx + 72, 72, (typeof window !== 'undefined' ? window.innerWidth : 9999) - 72) : 0
|
|
5735
|
+
const magY = mag !== null ? clampNum(mag.cy - 72, 72, (typeof window !== 'undefined' ? window.innerHeight : 9999) - 72) : 0
|
|
5736
|
+
|
|
5737
|
+
/**
|
|
5738
|
+
* 操作面板跟着选区走(微信截图式):水平居中于裁剪框、贴在框下方 12px;
|
|
5739
|
+
* 若框贴着窗口下沿,翻到框上方。还没画框时贴在图片下沿中央。
|
|
5740
|
+
* 全部用视口坐标 —— cropLayer 是 fixed inset:0,absolute 子元素即相对视口。
|
|
5741
|
+
*/
|
|
5742
|
+
const PANEL_W = 300
|
|
5743
|
+
const PANEL_H = 118
|
|
5744
|
+
const panelStyle = (() => {
|
|
5745
|
+
const vw = Number(typeof window !== 'undefined' ? window.innerWidth : 0) || 1280
|
|
5746
|
+
const vh = Number(typeof window !== 'undefined' ? window.innerHeight : 0) || 800
|
|
5747
|
+
const maxLeft = Math.max(8, vw - PANEL_W - 8)
|
|
5748
|
+
const maxTop = Math.max(8, vh - PANEL_H - 8)
|
|
5749
|
+
const hasBox = rect !== null && r !== null && rect.w > 0.02 && rect.h > 0.02
|
|
5750
|
+
let cx
|
|
5751
|
+
let boxTop
|
|
5752
|
+
let boxBottom
|
|
5753
|
+
if (hasBox) {
|
|
5754
|
+
boxTop = r.top + rect.y * r.height
|
|
5755
|
+
const boxLeft = r.left + rect.x * r.width
|
|
5756
|
+
cx = boxLeft + (rect.w * r.width) / 2
|
|
5757
|
+
boxBottom = boxTop + rect.h * r.height
|
|
5758
|
+
} else if (r !== null) {
|
|
5759
|
+
cx = r.left + r.width / 2
|
|
5760
|
+
boxTop = r.top
|
|
5761
|
+
boxBottom = r.bottom - PANEL_H - 16
|
|
5762
|
+
} else {
|
|
5763
|
+
cx = vw / 2
|
|
5764
|
+
boxTop = 0
|
|
5765
|
+
boxBottom = vh - PANEL_H - 20
|
|
5766
|
+
}
|
|
5767
|
+
const left = clampNum(cx - PANEL_W / 2, 8, maxLeft)
|
|
5768
|
+
let top = hasBox ? boxBottom + 12 : boxBottom
|
|
5769
|
+
if (hasBox && top + PANEL_H > vh - 8) top = boxTop - PANEL_H - 12
|
|
5770
|
+
return { left: `${left}px`, top: `${clampNum(top, 8, maxTop)}px` }
|
|
5771
|
+
})()
|
|
5772
|
+
|
|
5773
|
+
return h('div', {
|
|
5774
|
+
className: 'dg-cropLayer',
|
|
5775
|
+
key: 'cropLayer',
|
|
5776
|
+
'data-gallery-crop-layer': true,
|
|
5777
|
+
onPointerDown: onLayerDown,
|
|
5778
|
+
onPointerMove: onLayerMove,
|
|
5779
|
+
onPointerUp: onLayerUp,
|
|
5780
|
+
onPointerLeave: () => { setMag(null); setDrag(null) },
|
|
5781
|
+
onContextMenu: (e) => e.preventDefault(),
|
|
5782
|
+
}, [
|
|
5783
|
+
rect !== null
|
|
5784
|
+
? h('div', {
|
|
5785
|
+
className: 'dg-cropRect',
|
|
5786
|
+
key: 'rect',
|
|
5787
|
+
'data-gallery-crop-rect': true,
|
|
5788
|
+
style: rectStyle,
|
|
5789
|
+
onPointerDown: (e) => startDrag(e, 'move'),
|
|
5790
|
+
}, [
|
|
5791
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNW', key: 'nw', onPointerDown: (e) => startDrag(e, 'nw') }),
|
|
5792
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleNE', key: 'ne', onPointerDown: (e) => startDrag(e, 'ne') }),
|
|
5793
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSW', key: 'sw', onPointerDown: (e) => startDrag(e, 'sw') }),
|
|
5794
|
+
h('div', { className: 'dg-cropHandle dg-cropHandleSE', key: 'se', onPointerDown: (e) => startDrag(e, 'se') }),
|
|
5795
|
+
])
|
|
5796
|
+
: null,
|
|
5797
|
+
mag !== null && full !== null
|
|
5798
|
+
? h('div', {
|
|
5799
|
+
className: 'dg-cropMagnifier',
|
|
5800
|
+
key: 'mag',
|
|
5801
|
+
style: { left: `${magX}px`, top: `${magY}px` },
|
|
5802
|
+
}, h('canvas', { ref: magCanvasRef, width: 130, height: 130, key: 'magCanvas' }))
|
|
5803
|
+
: null,
|
|
5804
|
+
h('div', {
|
|
5805
|
+
className: 'dg-cropPanel',
|
|
5806
|
+
key: 'panel',
|
|
5807
|
+
'data-gallery-crop-panel': true,
|
|
5808
|
+
style: panelStyle,
|
|
5809
|
+
onPointerDown: (e) => e.stopPropagation(),
|
|
5810
|
+
onPointerMove: (e) => e.stopPropagation(), // 别让放大镜跟着面板上的鼠标乱跑
|
|
5811
|
+
onPointerEnter: () => setMag(null), // 鼠标进面板就收起放大镜
|
|
5812
|
+
}, [
|
|
5813
|
+
h('div', { className: 'dg-cropPanelHead', key: 'h' }, t('cropEnter')),
|
|
5814
|
+
h('div', { className: 'dg-cropPanelHint', key: 'hint' }, t('cropHint')),
|
|
5815
|
+
h('div', { className: 'dg-cropPanelOps', key: 'ops' }, [
|
|
5816
|
+
h('button', {
|
|
5817
|
+
type: 'button', className: 'dg-btn', key: 'cancel',
|
|
5818
|
+
onClick: (e) => { e.stopPropagation(); onCancel() },
|
|
5819
|
+
}, t('cropCancel')),
|
|
5820
|
+
h('button', {
|
|
5821
|
+
type: 'button', className: 'dg-btn dg-btnPrimary', key: 'ok', disabled: busy,
|
|
5822
|
+
'data-gallery-crop-confirm': true,
|
|
5823
|
+
onClick: (e) => { e.stopPropagation(); confirmCrop() },
|
|
5824
|
+
}, busy ? t('cropSaving') : t('cropConfirm')),
|
|
5825
|
+
]),
|
|
5826
|
+
]),
|
|
5827
|
+
])
|
|
5828
|
+
}
|
|
5829
|
+
|
|
5830
|
+
function Viewer({ items, index, onClose, onStep, t, initialOriginal, annotations, onAddAnnotation, onRemoveAnnotation, onExportMask, onCrop, onCopyFile }) {
|
|
4942
5831
|
const item = items[index]
|
|
4943
5832
|
// 文件预览已改走 DSH 原生侧栏(session 地址);此处 Viewer 仅处理图片,isText 恒 false,
|
|
4944
5833
|
// 下面的文本分支保留为死代码,供 v0.2 若需插件内预览时复用
|
|
@@ -5027,6 +5916,7 @@ ${absPath}
|
|
|
5027
5916
|
originalRequestedRef.current = false
|
|
5028
5917
|
setOriginalMode(false)
|
|
5029
5918
|
setOriginal({ status: 'idle' })
|
|
5919
|
+
setCropActive(false)
|
|
5030
5920
|
return () => {
|
|
5031
5921
|
if (originalAbortRef.current !== null) originalAbortRef.current.abort()
|
|
5032
5922
|
}
|
|
@@ -5196,6 +6086,8 @@ ${absPath}
|
|
|
5196
6086
|
// 中键按下时阻止浏览器默认的自动滚动
|
|
5197
6087
|
/** 批注模式(v0.14.0):开启后指针交给 SVG 标注层,查看器的缩放/拖拽暂停。 */
|
|
5198
6088
|
const [annotActive, setAnnotActive] = React.useState(false)
|
|
6089
|
+
/** v0.16.0 裁剪模式:开启后覆盖裁剪层(含放大镜),查看器自身的平移/点击关闭暂停。 */
|
|
6090
|
+
const [cropActive, setCropActive] = React.useState(false)
|
|
5199
6091
|
const annotsOfCurrent = React.useMemo(
|
|
5200
6092
|
() => (typeof annotations === 'function' ? annotations(item) : []),
|
|
5201
6093
|
[annotations, item],
|
|
@@ -5211,6 +6103,8 @@ ${absPath}
|
|
|
5211
6103
|
const onClickBody = (event) => {
|
|
5212
6104
|
// 标注模式下点图只用于画框,不能顺手把大图关掉(老板 20:32 指出的冲突)
|
|
5213
6105
|
if (annotActive) return
|
|
6106
|
+
// v0.16.0 裁剪模式下点击被裁剪层接管,不应关闭查看器
|
|
6107
|
+
if (cropActive) return
|
|
5214
6108
|
event.preventDefault()
|
|
5215
6109
|
if (lastDragMoved.current === true) {
|
|
5216
6110
|
lastDragMoved.current = false
|
|
@@ -5320,11 +6214,20 @@ ${absPath}
|
|
|
5320
6214
|
// 原图/预览切换:保留当前 zoom 与 pan,方便对比同一点细节
|
|
5321
6215
|
event.preventDefault()
|
|
5322
6216
|
toggleOriginal()
|
|
6217
|
+
} else if ((event.ctrlKey || event.metaKey) && (key === 'c' || key === 'C')) {
|
|
6218
|
+
// v0.16.3:Ctrl+C 复制**当前查看的这一份文件**(不是画面截图)。
|
|
6219
|
+
// 剪贴板里是文件对象,能直接粘到资源管理器 / 其他对话。
|
|
6220
|
+
// 有选中文本时让位给浏览器默认复制,别抢用户想复制的批注文字。
|
|
6221
|
+
const sel = typeof window.getSelection === 'function' ? window.getSelection() : null
|
|
6222
|
+
if (sel !== null && String(sel).trim() !== '') return
|
|
6223
|
+
if (typeof onCopyFile !== 'function') return
|
|
6224
|
+
event.preventDefault()
|
|
6225
|
+
onCopyFile(item.relPath)
|
|
5323
6226
|
}
|
|
5324
6227
|
}
|
|
5325
6228
|
window.addEventListener('keydown', onKey)
|
|
5326
6229
|
return () => window.removeEventListener('keydown', onKey)
|
|
5327
|
-
}, [onClose, onStep, panStep, zoomBy, toggleOriginal])
|
|
6230
|
+
}, [onClose, onStep, panStep, zoomBy, toggleOriginal, onCopyFile, item.relPath])
|
|
5328
6231
|
|
|
5329
6232
|
const sliderDragRef = React.useRef(null)
|
|
5330
6233
|
const onSliderPointerDown = (event) => {
|
|
@@ -5482,6 +6385,22 @@ ${absPath}
|
|
|
5482
6385
|
setAnnotActive((v) => !v)
|
|
5483
6386
|
},
|
|
5484
6387
|
}, annotActive ? `✎ ${t('annotExit')}` : `✎ ${t('annotEnter')}`),
|
|
6388
|
+
// v0.16.0 裁剪:开关裁剪覆盖层(含放大镜);裁剪态下查看器自身的平移/关闭暂停
|
|
6389
|
+
// 只在图片真正就绪时出现 —— 二进制/加载失败没有可裁的像素
|
|
6390
|
+
state.status === 'ready'
|
|
6391
|
+
? h('button', {
|
|
6392
|
+
type: 'button',
|
|
6393
|
+
className: `dg-btn${cropActive ? ' dg-btnActive' : ''}`,
|
|
6394
|
+
key: 'crop',
|
|
6395
|
+
'data-gallery-crop-toggle': true,
|
|
6396
|
+
'aria-pressed': cropActive,
|
|
6397
|
+
title: cropActive ? t('cropExit') : t('cropEnter'),
|
|
6398
|
+
onClick: (event) => {
|
|
6399
|
+
event.stopPropagation()
|
|
6400
|
+
setCropActive((v) => !v)
|
|
6401
|
+
},
|
|
6402
|
+
}, cropActive ? `✂ ${t('cropExit')}` : `✂ ${t('cropEnter')}`)
|
|
6403
|
+
: null,
|
|
5485
6404
|
// 「拖到对话」确定性入口:Viewer 大图本身 draggable:false + pointerEvents:none
|
|
5486
6405
|
// (标注态的中键平移 / 右键多边形都依赖它),所以不改大图,另给一个可拖按钮。
|
|
5487
6406
|
// 这个按钮同时是「新 client.js 已加载」的可见标记 —— 看到它就说明面板不是旧模块。
|
|
@@ -5496,6 +6415,19 @@ ${absPath}
|
|
|
5496
6415
|
'aria-label': '拖到对话',
|
|
5497
6416
|
onClick: (event) => event.stopPropagation(),
|
|
5498
6417
|
}, '⇥ 拖到对话'),
|
|
6418
|
+
// v0.16.3:Ctrl+C 复制当前文件;按钮是这条快捷键的可见入口(远程控制也能点)
|
|
6419
|
+
h('button', {
|
|
6420
|
+
type: 'button',
|
|
6421
|
+
className: 'dg-btn',
|
|
6422
|
+
key: 'copyFile',
|
|
6423
|
+
'data-gallery-copy-file': item.relPath,
|
|
6424
|
+
title: t('viewerCopyFileHint'),
|
|
6425
|
+
'aria-label': t('viewerCopyFile'),
|
|
6426
|
+
onClick: (event) => {
|
|
6427
|
+
event.stopPropagation()
|
|
6428
|
+
if (typeof onCopyFile === 'function') onCopyFile(item.relPath)
|
|
6429
|
+
},
|
|
6430
|
+
}, `⧉ ${t('viewerCopyFile')}`),
|
|
5499
6431
|
h('button', { type: 'button', className: 'dg-btn', key: 'prev', onClick: () => onStep(-1), 'aria-label': t('prev') }, '‹'),
|
|
5500
6432
|
h('button', { type: 'button', className: 'dg-btn', key: 'next', onClick: () => onStep(1), 'aria-label': t('next') }, '›'),
|
|
5501
6433
|
h('button', { type: 'button', className: 'dg-btn', key: 'close', onClick: onClose, 'aria-label': t('close') }, '✕'),
|
|
@@ -5577,6 +6509,20 @@ ${absPath}
|
|
|
5577
6509
|
state.status === 'failed' ? `${t('thumbFailed')}:${item.name}` : t('loading')),
|
|
5578
6510
|
),
|
|
5579
6511
|
slider,
|
|
6512
|
+
// v0.16.0 裁剪覆盖层:裁剪模式开启时显示(含微信式放大镜),固定在视口上、与 pan/zoom 解耦
|
|
6513
|
+
cropActive && isImageItem(item) && !isText && state.status === 'ready'
|
|
6514
|
+
? h(ImageCropper, {
|
|
6515
|
+
key: 'cropper',
|
|
6516
|
+
t,
|
|
6517
|
+
item,
|
|
6518
|
+
imgRef,
|
|
6519
|
+
onCrop: (base64) => {
|
|
6520
|
+
setCropActive(false)
|
|
6521
|
+
if (typeof onCrop === 'function') onCrop(item.relPath, base64)
|
|
6522
|
+
},
|
|
6523
|
+
onCancel: () => setCropActive(false),
|
|
6524
|
+
})
|
|
6525
|
+
: null,
|
|
5580
6526
|
]),
|
|
5581
6527
|
// 原图加载状态条:失败要能看见并知道原因,否则用户以为图坏了
|
|
5582
6528
|
original.status === 'failed'
|
|
@@ -6619,6 +7565,18 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
6619
7565
|
// 让回调(如右键菜单)读到最新值而不必重建依赖
|
|
6620
7566
|
const viewerRef = React.useRef(null)
|
|
6621
7567
|
React.useEffect(() => { viewerRef.current = viewer }, [viewer])
|
|
7568
|
+
/**
|
|
7569
|
+
* v0.16.2 粘贴落点:全局视图下「鼠标所在的对话组」。
|
|
7570
|
+
*
|
|
7571
|
+
* 此前粘贴固定用 slot 的 sessionId(= 当前对话),所以在任何历史对话组里
|
|
7572
|
+
* 粘贴都会跑到当前对话目录,老板报的正是这个。这里记下 hover / 右键所在的
|
|
7573
|
+
* 组(`{ sessionId, title, createdAt }`),粘贴时优先用它,没有才退回当前对话。
|
|
7574
|
+
*
|
|
7575
|
+
* 🔴 用 ref 不用 useState:onMouseEnter 改它不该触发整表重渲染;而且粘贴是
|
|
7576
|
+
* 异步事件,必须读「事件发生那一刻」的值,渲染期快照会过期。
|
|
7577
|
+
* null 表示「没有指定组」→ 落回当前对话。
|
|
7578
|
+
*/
|
|
7579
|
+
const pasteTargetRef = React.useRef(null)
|
|
6622
7580
|
const limiter = React.useRef(null)
|
|
6623
7581
|
if (limiter.current === null) limiter.current = createLimiter(MAX_CONCURRENT)
|
|
6624
7582
|
|
|
@@ -6708,6 +7666,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
6708
7666
|
// 组内中间产物开关已并入顶部分类筛选(v0.14.3)。
|
|
6709
7667
|
// 右键菜单:{ item, absPath, x, y }
|
|
6710
7668
|
const [ctxMenu, setCtxMenu] = React.useState(null)
|
|
7669
|
+
// v0.16.0:右键空白处(非卡片)弹出的「粘贴」菜单
|
|
7670
|
+
const [pasteMenu, setPasteMenu] = React.useState(null)
|
|
6711
7671
|
// 删除确认:{ item, busy }
|
|
6712
7672
|
const [deleteTarget, setDeleteTarget] = React.useState(null)
|
|
6713
7673
|
// ---- v0.14.2:反馈篮条目(marks,一次性)与手动标签(labels,持久)分开 ----
|
|
@@ -7003,7 +7963,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7003
7963
|
* 分组视图下卡片来自 `data.groups[i].files`,与当前页的扁平 `items` 是两个不同的集合,
|
|
7004
7964
|
* 直接用全局 `items` 的索引会「点哪张都跳出同一张图」。
|
|
7005
7965
|
*/
|
|
7006
|
-
const openViewer = React.useCallback((index, anchorEl, list, asOriginal) => {
|
|
7966
|
+
const openViewer = React.useCallback((index, anchorEl, list, asOriginal, origin) => {
|
|
7007
7967
|
const scroller = bodyScrollRef.current
|
|
7008
7968
|
if (scroller !== null) {
|
|
7009
7969
|
savedScrollRef.current = {
|
|
@@ -7022,7 +7982,14 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7022
7982
|
width: it.width ?? null,
|
|
7023
7983
|
height: it.height ?? null,
|
|
7024
7984
|
}))
|
|
7025
|
-
|
|
7985
|
+
// v0.16.2:记住这张图属于哪个对话组 —— 裁剪产物要跟着来源组落盘,
|
|
7986
|
+
// 不能一律塞进当前对话(否则在历史对话的图上裁剪,产物跑到别的对话)。
|
|
7987
|
+
const originSid = String(origin?.sessionId ?? '')
|
|
7988
|
+
setViewer({
|
|
7989
|
+
index, list: snapshot, asOriginal: asOriginal === true,
|
|
7990
|
+
originSid: originSid === '__history__' ? '' : originSid,
|
|
7991
|
+
originTitle: originSid === '__history__' ? '' : String(origin?.title ?? ''),
|
|
7992
|
+
})
|
|
7026
7993
|
}, [])
|
|
7027
7994
|
|
|
7028
7995
|
/**
|
|
@@ -7036,7 +8003,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7036
8003
|
const cur = viewerRef.current
|
|
7037
8004
|
if (cur !== null && Array.isArray(cur.list)) {
|
|
7038
8005
|
const i = cur.list.findIndex(samePath)
|
|
7039
|
-
|
|
8006
|
+
// 沿用原查看器已记录的来源组,别因为「查看原图」把归属丢掉
|
|
8007
|
+
if (i >= 0) { openViewer(i, null, cur.list, true, { sessionId: cur.originSid ?? '' }); return }
|
|
7040
8008
|
}
|
|
7041
8009
|
// 2) 全局 items(扁平/分页视图)
|
|
7042
8010
|
const flat = itemsRef.current ?? []
|
|
@@ -7048,7 +8016,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7048
8016
|
for (const g of groups) {
|
|
7049
8017
|
if (!Array.isArray(g.files)) continue
|
|
7050
8018
|
const k = g.files.findIndex(samePath)
|
|
7051
|
-
if (k >= 0) { openViewer(k, null, g.files, true); return }
|
|
8019
|
+
if (k >= 0) { openViewer(k, null, g.files, true, { sessionId: g.sessionId }); return }
|
|
7052
8020
|
}
|
|
7053
8021
|
}
|
|
7054
8022
|
// 4) 兜底:单独一张(此时左右切图无意义,但不至于打不开)
|
|
@@ -7119,6 +8087,259 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7119
8087
|
}
|
|
7120
8088
|
}, [load, kind, scope, page])
|
|
7121
8089
|
|
|
8090
|
+
// ---- v0.16.0 粘贴:剪贴板图片/文件作为「素材」落当前对话 ----
|
|
8091
|
+
/** 粘贴提示(成功/失败),3 秒自动消失。 */
|
|
8092
|
+
const [pasteNotice, setPasteNotice] = React.useState(null)
|
|
8093
|
+
React.useEffect(() => {
|
|
8094
|
+
if (pasteNotice === null) return undefined
|
|
8095
|
+
const timer = setTimeout(() => setPasteNotice(null), 3000)
|
|
8096
|
+
return () => clearTimeout(timer)
|
|
8097
|
+
}, [pasteNotice])
|
|
8098
|
+
|
|
8099
|
+
const showPasteNotice = React.useCallback((kindOf, text) => {
|
|
8100
|
+
setPasteNotice({ kind: kindOf, text })
|
|
8101
|
+
}, [])
|
|
8102
|
+
|
|
8103
|
+
/**
|
|
8104
|
+
* v0.16.2 粘贴落点解析:hover 的对话组优先,否则 slot 的当前对话。
|
|
8105
|
+
*
|
|
8106
|
+
* 这两个 helper 必须在所有粘贴 / 裁剪回调**之前**声明 ——
|
|
8107
|
+
* 回调体内的引用是惰性的,但一旦写进 useCallback 依赖数组就会在渲染时
|
|
8108
|
+
* 立即求值,引用后面声明的 const 会直接 TDZ 白屏(v0.16.0 踩过)。
|
|
8109
|
+
*/
|
|
8110
|
+
const pasteTargetSid = () => {
|
|
8111
|
+
// 查看器打开时,图是从哪个组点开的就落哪个组 —— 覆盖层是模态的,
|
|
8112
|
+
// 此时鼠标已经不在组的 DOM 里,靠 hover 记的落点会被 mouseleave 清掉。
|
|
8113
|
+
const viewerSid = String(viewerRef.current?.originSid ?? '')
|
|
8114
|
+
if (viewerSid !== '') return viewerSid
|
|
8115
|
+
const sid = String(pasteTargetRef.current?.sessionId ?? '')
|
|
8116
|
+
return sid !== '' ? sid : String(sessionId ?? '')
|
|
8117
|
+
}
|
|
8118
|
+
/** 提示文案里的落点名:组标题,没有则「当前对话」。 */
|
|
8119
|
+
const pasteTargetLabel = () => {
|
|
8120
|
+
const viewerTitle = String(viewerRef.current?.originTitle ?? '')
|
|
8121
|
+
if (viewerTitle !== '') return viewerTitle
|
|
8122
|
+
const target = pasteTargetRef.current
|
|
8123
|
+
if (target === null || String(target.sessionId ?? '') === '') return t('pasteTargetCurrent')
|
|
8124
|
+
return String(target.title ?? '') || t('pasteTargetCurrent')
|
|
8125
|
+
}
|
|
8126
|
+
|
|
8127
|
+
/**
|
|
8128
|
+
* v0.16.0 从**系统剪贴板**读文件列表并落盘 —— 音视频 / 任意文件的主通道。
|
|
8129
|
+
*
|
|
8130
|
+
* Chromium 的 paste 事件对「资源管理器 Ctrl+C 的文件」不给 File 对象,
|
|
8131
|
+
* 只能让 Host 用 PowerShell 读 CF_HDROP;系统剪贴板没有文件列表时,
|
|
8132
|
+
* Host 会退回插件内部剪贴板(复制→粘贴仍闭环)。
|
|
8133
|
+
*
|
|
8134
|
+
* 🔴 必须定义在 doPasteEvent 之前:useCallback 的依赖数组是渲染时立即求值的。
|
|
8135
|
+
* @returns {Promise<boolean>} 是否确实粘进了文件
|
|
8136
|
+
*/
|
|
8137
|
+
const pasteFromClipboard = React.useCallback(async () => {
|
|
8138
|
+
let payload = null
|
|
8139
|
+
try { payload = await callHost('clipboardFiles') } catch (error) {
|
|
8140
|
+
showPasteNotice('fail', format(t('pasteFailed'), { message: String(error?.message ?? error) }))
|
|
8141
|
+
return false
|
|
8142
|
+
}
|
|
8143
|
+
const files = Array.isArray(payload?.files) ? payload.files : []
|
|
8144
|
+
if (files.length === 0) return false
|
|
8145
|
+
let result = null
|
|
8146
|
+
try {
|
|
8147
|
+
result = await callHost('pasteFiles', {
|
|
8148
|
+
// v0.16.2:落到「鼠标所在的对话组」,没指定才落当前对话
|
|
8149
|
+
sessionId: pasteTargetSid(),
|
|
8150
|
+
srcPaths: files.map((f) => f.path),
|
|
8151
|
+
})
|
|
8152
|
+
} catch (error) {
|
|
8153
|
+
showPasteNotice('fail', format(t('pasteFailed'), { message: String(error?.message ?? error) }))
|
|
8154
|
+
return false
|
|
8155
|
+
}
|
|
8156
|
+
const okFiles = Array.isArray(result?.files) ? result.files : []
|
|
8157
|
+
if (okFiles.length === 0) {
|
|
8158
|
+
showPasteNotice('fail', format(t('pasteFailed'), { message: result?.error?.message ?? 'pasteFiles failed' }))
|
|
8159
|
+
return false
|
|
8160
|
+
}
|
|
8161
|
+
showPasteNotice('ok', format(t('pasteFilesOk'), {
|
|
8162
|
+
n: okFiles.length, name: okFiles[0].name ?? '', target: pasteTargetLabel(),
|
|
8163
|
+
}))
|
|
8164
|
+
void refresh()
|
|
8165
|
+
if (Array.isArray(result?.failed) && result.failed.length > 0) {
|
|
8166
|
+
console.warn('dsh-gallery: 部分文件粘贴失败', result.failed)
|
|
8167
|
+
}
|
|
8168
|
+
return true
|
|
8169
|
+
}, [callHost, sessionId, refresh, t, showPasteNotice])
|
|
8170
|
+
|
|
8171
|
+
/** 真正落盘:把解析出的图片(images)/文件(files)交给 Host 分别粘贴。 */
|
|
8172
|
+
const ingestPasted = React.useCallback(async ({ images, files }) => {
|
|
8173
|
+
let okCount = 0
|
|
8174
|
+
let lastErr = ''
|
|
8175
|
+
let skipped = 0
|
|
8176
|
+
for (const file of images) {
|
|
8177
|
+
// 没有磁盘路径、MIME 又不是图片的(如复制的 PDF/zip):读成 base64 也过不了
|
|
8178
|
+
// PNG 校验,直接跳过并计数,最后给一条明确的「请拖入画廊」提示。
|
|
8179
|
+
const mime = typeof file?.type === 'string' ? file.type : ''
|
|
8180
|
+
if (mime !== '' && !mime.startsWith('image/')) { skipped += 1; continue }
|
|
8181
|
+
try {
|
|
8182
|
+
const dataUrl = await fileToDataUrl(file)
|
|
8183
|
+
const comma = dataUrl.indexOf(',')
|
|
8184
|
+
const base64 = comma >= 0 ? dataUrl.slice(comma + 1) : dataUrl
|
|
8185
|
+
const payload = await callHost('pasteImage', { sessionId: pasteTargetSid(), data: base64, ext: 'png' })
|
|
8186
|
+
if (payload?.ok === true) { okCount += 1; showPasteNotice('ok', format(t('pasteImageOk'), { name: payload.name ?? '', target: pasteTargetLabel() })) }
|
|
8187
|
+
else lastErr = payload?.error?.message ?? 'pasteImage failed'
|
|
8188
|
+
} catch (error) {
|
|
8189
|
+
lastErr = String(error?.message ?? error)
|
|
8190
|
+
}
|
|
8191
|
+
}
|
|
8192
|
+
for (const f of files) {
|
|
8193
|
+
try {
|
|
8194
|
+
const payload = await callHost('pasteFile', { sessionId: pasteTargetSid(), srcPath: f.path, name: f.name })
|
|
8195
|
+
if (payload?.ok === true) { okCount += 1; showPasteNotice('ok', format(t('pasteFileOk'), { name: payload.name ?? '', target: pasteTargetLabel() })) }
|
|
8196
|
+
else lastErr = payload?.error?.message ?? 'pasteFile failed'
|
|
8197
|
+
} catch (error) {
|
|
8198
|
+
lastErr = String(error?.message ?? error)
|
|
8199
|
+
}
|
|
8200
|
+
}
|
|
8201
|
+
if (okCount > 0) {
|
|
8202
|
+
void refresh()
|
|
8203
|
+
if (lastErr !== '') console.warn('dsh-gallery: 部分粘贴失败', lastErr)
|
|
8204
|
+
} else if (lastErr !== '') {
|
|
8205
|
+
showPasteNotice('fail', format(t('pasteFailed'), { message: lastErr }))
|
|
8206
|
+
} else if (skipped > 0) {
|
|
8207
|
+
showPasteNotice('fail', t('pasteUnsupported'))
|
|
8208
|
+
} else {
|
|
8209
|
+
showPasteNotice('fail', t('pasteEmpty'))
|
|
8210
|
+
}
|
|
8211
|
+
}, [sessionId, refresh, t, showPasteNotice])
|
|
8212
|
+
|
|
8213
|
+
/** Ctrl+V:优先吃 paste 事件的图片/文件;事件没给文件信息时退到系统剪贴板。 */
|
|
8214
|
+
const doPasteEvent = React.useCallback(async (clipboardData, event) => {
|
|
8215
|
+
const parsed = extractFromPasteEvent(clipboardData)
|
|
8216
|
+
if (parsed.images.length > 0 || parsed.files.length > 0) {
|
|
8217
|
+
if (typeof event?.preventDefault === 'function') event.preventDefault()
|
|
8218
|
+
await ingestPasted(parsed)
|
|
8219
|
+
return true
|
|
8220
|
+
}
|
|
8221
|
+
return pasteFromClipboard()
|
|
8222
|
+
}, [ingestPasted, pasteFromClipboard])
|
|
8223
|
+
|
|
8224
|
+
/** 右键菜单「粘贴」:先图片(Clipboard API),再文件(含音视频,系统剪贴板)。 */
|
|
8225
|
+
const doPaste = React.useCallback(async () => {
|
|
8226
|
+
const images = await readClipboardImages()
|
|
8227
|
+
if (images.length > 0) {
|
|
8228
|
+
await ingestPasted({ images, files: [] })
|
|
8229
|
+
return
|
|
8230
|
+
}
|
|
8231
|
+
const got = await pasteFromClipboard()
|
|
8232
|
+
if (!got) showPasteNotice('fail', t('pasteEmpty'))
|
|
8233
|
+
}, [ingestPasted, pasteFromClipboard, showPasteNotice, t])
|
|
8234
|
+
|
|
8235
|
+
/** v0.16.0 图片裁剪:把裁剪出的 PNG base64 交给 Host 落盘(源图同目录,标素材)。 */
|
|
8236
|
+
const doCrop = React.useCallback(async (relPath, base64) => {
|
|
8237
|
+
try {
|
|
8238
|
+
// v0.16.2:裁剪产物跟「这张图所属的对话」走,而不是永远跟当前对话。
|
|
8239
|
+
// 来源组由 openViewer 记在 viewer.originSid(打开查看器时就知道图来自哪个组);
|
|
8240
|
+
// 没有来源组(扁平视图)时才退回 hover 组 / 当前对话。
|
|
8241
|
+
// 组标题 / 创建时间由 Host 读会话日志补(这里读不到 `data`:声明在后面,会 TDZ)。
|
|
8242
|
+
const originSid = String(viewerRef.current?.originSid ?? '')
|
|
8243
|
+
const payload = await callHost('cropImage', {
|
|
8244
|
+
path: relPath, data: base64,
|
|
8245
|
+
sessionId: originSid !== '' ? originSid : pasteTargetSid(),
|
|
8246
|
+
})
|
|
8247
|
+
if (payload?.ok === false) throw new Error(payload?.error?.message ?? 'cropImage failed')
|
|
8248
|
+
const originLabel = String(viewerRef.current?.originTitle ?? '') || pasteTargetLabel()
|
|
8249
|
+
showPasteNotice('ok', format(t('cropSaved'), { name: payload?.name ?? '', target: originLabel }))
|
|
8250
|
+
void refresh()
|
|
8251
|
+
} catch (error) {
|
|
8252
|
+
showPasteNotice('fail', format(t('cropFailed'), { message: String(error?.message ?? error) }))
|
|
8253
|
+
}
|
|
8254
|
+
}, [callHost, refresh, t, showPasteNotice, sessionId])
|
|
8255
|
+
|
|
8256
|
+
/**
|
|
8257
|
+
* v0.16.0 粘贴事件接线。
|
|
8258
|
+
*
|
|
8259
|
+
* 🔴 这些必须放在 `doPasteEvent` **之后**:React 的 useCallback / useEffect
|
|
8260
|
+
* 会在渲染时立即求值依赖数组,若引用后面才声明的 const 会触发 TDZ
|
|
8261
|
+
* (ReferenceError: Cannot access 'doPasteEvent' before initialization),
|
|
8262
|
+
* 整个 GalleryBody 渲染抛错 → 面板白屏。v0.16.0 首版就踩过这个坑。
|
|
8263
|
+
*/
|
|
8264
|
+
/** 画廊区域粘贴(Ctrl+V)。只拦截含图片/文件的粘贴,纯文本放行。 */
|
|
8265
|
+
const onBodyPaste = React.useCallback((event) => {
|
|
8266
|
+
if (event?.defaultPrevented === true) return
|
|
8267
|
+
if (isPlainTextPaste(event.clipboardData)) return
|
|
8268
|
+
// 🔴 preventDefault 必须在同步阶段调用:后面读系统剪贴板是异步的
|
|
8269
|
+
event.preventDefault()
|
|
8270
|
+
void doPasteEvent(event.clipboardData, event)
|
|
8271
|
+
}, [doPasteEvent])
|
|
8272
|
+
|
|
8273
|
+
/**
|
|
8274
|
+
* Ctrl+V 的真正落点。
|
|
8275
|
+
*
|
|
8276
|
+
* 面板的 body 是普通 div,**不可聚焦**,浏览器不会把 paste 事件投给它。
|
|
8277
|
+
* 所以必须挂 document 级监听,再用两道门控避免抢走对话输入框的粘贴:
|
|
8278
|
+
* ① 鼠标必须悬停在本面板上(hoveringRef);
|
|
8279
|
+
* ② 焦点不能在 input/textarea/contenteditable 里。
|
|
8280
|
+
*/
|
|
8281
|
+
const hoveringRef = React.useRef(false)
|
|
8282
|
+
React.useEffect(() => {
|
|
8283
|
+
const onDocPaste = (event) => {
|
|
8284
|
+
if (hoveringRef.current !== true) return
|
|
8285
|
+
if (event?.defaultPrevented === true) return
|
|
8286
|
+
const ae = document.activeElement
|
|
8287
|
+
const tag = (ae?.tagName ?? '').toLowerCase()
|
|
8288
|
+
if (tag === 'input' || tag === 'textarea' || ae?.isContentEditable === true) return
|
|
8289
|
+
if (isPlainTextPaste(event.clipboardData)) return
|
|
8290
|
+
// 🔴 同步拦截:哪怕 paste 事件没给任何 File(资源管理器复制文件的常态),
|
|
8291
|
+
// 也要拦下来,异步让 Host 去读系统剪贴板的文件列表。
|
|
8292
|
+
event.preventDefault()
|
|
8293
|
+
void doPasteEvent(event.clipboardData, event)
|
|
8294
|
+
}
|
|
8295
|
+
document.addEventListener('paste', onDocPaste)
|
|
8296
|
+
return () => document.removeEventListener('paste', onDocPaste)
|
|
8297
|
+
}, [doPasteEvent])
|
|
8298
|
+
|
|
8299
|
+
/** 右键空白处(非卡片)弹出「粘贴」菜单。卡片已 stopPropagation,不会到这里。 */
|
|
8300
|
+
const onBodyContextMenu = React.useCallback((event) => {
|
|
8301
|
+
event.preventDefault()
|
|
8302
|
+
event.stopPropagation()
|
|
8303
|
+
// v0.16.2:右键落在哪个组里,粘贴就落到那个对话。
|
|
8304
|
+
// 卡片自己 stopPropagation,所以这里命中的是「组内空白处」。
|
|
8305
|
+
const el = typeof event.target?.closest === 'function'
|
|
8306
|
+
? event.target.closest('[data-gallery-group]')
|
|
8307
|
+
: null
|
|
8308
|
+
const sid = el === null ? '' : String(el.getAttribute('data-gallery-group') ?? '')
|
|
8309
|
+
const targetTitle = el === null ? '' : String(el.getAttribute('data-gallery-group-title') ?? '')
|
|
8310
|
+
pasteTargetRef.current = sid === '' || sid === '__history__'
|
|
8311
|
+
? null
|
|
8312
|
+
: { sessionId: sid, title: targetTitle, createdAt: 0 }
|
|
8313
|
+
setCtxMenu(null)
|
|
8314
|
+
setPasteMenu({
|
|
8315
|
+
x: event.clientX,
|
|
8316
|
+
y: event.clientY,
|
|
8317
|
+
targetLabel: pasteTargetRef.current === null ? t('pasteTargetCurrent') : (targetTitle || t('pasteTargetCurrent')),
|
|
8318
|
+
})
|
|
8319
|
+
}, [t])
|
|
8320
|
+
|
|
8321
|
+
/**
|
|
8322
|
+
* v0.16.0 复制资产(单文件右键 / 批量选择共用)。
|
|
8323
|
+
* 只把 roots 内的相对路径交给 Host,由 Host 解析绝对路径并写系统剪贴板;
|
|
8324
|
+
* 前端不拼路径、不改原文件、零自动发送。
|
|
8325
|
+
*/
|
|
8326
|
+
const doCopyAssets = React.useCallback(async (relPaths) => {
|
|
8327
|
+
const paths = [...new Set((Array.isArray(relPaths) ? relPaths : [])
|
|
8328
|
+
.map((p) => String(p ?? '')).filter((p) => p !== ''))]
|
|
8329
|
+
if (paths.length === 0) return
|
|
8330
|
+
try {
|
|
8331
|
+
const payload = await callHost('copyAssets', { paths })
|
|
8332
|
+
if (payload?.ok !== true) throw new Error(payload?.error?.message ?? 'copyAssets failed')
|
|
8333
|
+
const text = payload?.mode === 'internal' ? t('copyOkInternal') : t('copyOk')
|
|
8334
|
+
showPasteNotice('ok', format(text, { n: payload.count ?? paths.length }))
|
|
8335
|
+
if (Array.isArray(payload?.missed) && payload.missed.length > 0) {
|
|
8336
|
+
console.warn('dsh-gallery: 复制时跳过了不在扫描根目录内的项', payload.missed)
|
|
8337
|
+
}
|
|
8338
|
+
} catch (error) {
|
|
8339
|
+
showPasteNotice('fail', format(t('copyFailed'), { message: String(error?.message ?? error) }))
|
|
8340
|
+
}
|
|
8341
|
+
}, [callHost, t, showPasteNotice])
|
|
8342
|
+
|
|
7122
8343
|
React.useEffect(() => {
|
|
7123
8344
|
let alive = true
|
|
7124
8345
|
const controller = new AbortController()
|
|
@@ -7414,6 +8635,13 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7414
8635
|
title: t('labelEditHint'),
|
|
7415
8636
|
onClick: () => openBatchLabelDialog(),
|
|
7416
8637
|
}, t('labelBatch')),
|
|
8638
|
+
// v0.16.0 批量复制:把选中资产写进系统剪贴板文件列表(跨对话调动)
|
|
8639
|
+
h('button', {
|
|
8640
|
+
type: 'button', className: 'dg-btn dg-btnSmall', key: 'copyFiles',
|
|
8641
|
+
'data-gallery-batch-copy': true,
|
|
8642
|
+
title: t('batchCopyHint'),
|
|
8643
|
+
onClick: () => { void doCopyAssets([...selected]) },
|
|
8644
|
+
}, `⧉ ${t('batchCopyFiles')} (${selectedCount})`),
|
|
7417
8645
|
h('button', {
|
|
7418
8646
|
type: 'button', className: 'dg-btn dg-btnSmall', key: 'clearmark',
|
|
7419
8647
|
'data-gallery-batch-clear': true,
|
|
@@ -7653,7 +8881,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7653
8881
|
}
|
|
7654
8882
|
|
|
7655
8883
|
if (useGroups) {
|
|
7656
|
-
const cardFor = (item, groupKey, listForViewer) => {
|
|
8884
|
+
const cardFor = (item, groupKey, listForViewer, groupMeta) => {
|
|
7657
8885
|
// 分组里的文件也走同一套卡片组件
|
|
7658
8886
|
const enriched = {
|
|
7659
8887
|
...item,
|
|
@@ -7672,7 +8900,8 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7672
8900
|
},
|
|
7673
8901
|
t,
|
|
7674
8902
|
absPath: buildAbsPath(data.root, item.relPath),
|
|
7675
|
-
|
|
8903
|
+
// v0.16.2:选段产物跟来源组走(groupKey 就是该组 sessionId)
|
|
8904
|
+
onPlay: (target) => setMediaPlaying({ ...target, originSessionId: groupKey }),
|
|
7676
8905
|
onContextMenu: openContextMenu,
|
|
7677
8906
|
}), item, `${groupKey}:${item.relPath}`)
|
|
7678
8907
|
}
|
|
@@ -7705,14 +8934,15 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7705
8934
|
onOpen: (opened, anchorEl) => {
|
|
7706
8935
|
// 用**该组当前可见的文件**作为查看器列表:
|
|
7707
8936
|
// 左右切图应在本组内循环,而不是跳到别的对话的图。
|
|
7708
|
-
const list = Array.isArray(listForViewer) ? listForViewer :
|
|
8937
|
+
const list = Array.isArray(listForViewer) ? listForViewer : (groupMeta?.files ?? [])
|
|
7709
8938
|
let pos = list.indexOf(opened)
|
|
7710
8939
|
if (pos < 0) {
|
|
7711
8940
|
// 对象引用对不上时按 relPath 找(enriched 是浅拷贝,引用可能不同)
|
|
7712
8941
|
pos = list.findIndex((f) => f.relPath === opened.relPath)
|
|
7713
8942
|
}
|
|
7714
8943
|
if (pos < 0) return
|
|
7715
|
-
|
|
8944
|
+
// v0.16.2:把这张图所属的组带给查看器,裁剪产物要落回同一个对话
|
|
8945
|
+
openViewer(pos, anchorEl ?? null, list, false, { sessionId: groupKey, title: groupMeta?.title ?? '' })
|
|
7716
8946
|
},
|
|
7717
8947
|
}), item, `${groupKey}:${item.relPath}`)
|
|
7718
8948
|
}
|
|
@@ -7755,6 +8985,17 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7755
8985
|
key: `g:${headKey}`,
|
|
7756
8986
|
'data-gallery-group': headKey,
|
|
7757
8987
|
'data-gallery-group-current': group.isCurrent === true ? '1' : '0',
|
|
8988
|
+
'data-gallery-group-title': group.title ?? '',
|
|
8989
|
+
/**
|
|
8990
|
+
* v0.16.2:鼠标停在哪一组,粘贴/裁剪就落到那一组。
|
|
8991
|
+
* 「未归类」池没有对应会话,置 null 退回当前对话(不能凭空造目录)。
|
|
8992
|
+
*/
|
|
8993
|
+
onMouseEnter: () => {
|
|
8994
|
+
pasteTargetRef.current = group.isHistory === true || !group.sessionId
|
|
8995
|
+
? null
|
|
8996
|
+
: { sessionId: group.sessionId, title: group.title ?? '', createdAt: group.createdAt ?? 0 }
|
|
8997
|
+
},
|
|
8998
|
+
onMouseLeave: () => { pasteTargetRef.current = null },
|
|
7758
8999
|
}, [
|
|
7759
9000
|
h('button', {
|
|
7760
9001
|
type: 'button',
|
|
@@ -7800,7 +9041,7 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7800
9041
|
h('div', { className: 'dg-groupBody', key: 'body' }, [
|
|
7801
9042
|
visibleFiles.length > 0
|
|
7802
9043
|
? h('div', { className: `dg-grid${kind === 'file' ? ' dg-fileGrid' : ''}`, key: 'grid' },
|
|
7803
|
-
visibleFiles.map((f) => cardFor(f, headKey, visibleFiles)))
|
|
9044
|
+
visibleFiles.map((f) => cardFor(f, headKey, visibleFiles, group)))
|
|
7804
9045
|
: h('div', { className: 'dg-groupEmpty', key: 'empty' }, t('groupEmpty')),
|
|
7805
9046
|
group.truncated
|
|
7806
9047
|
? h('div', { className: 'dg-groupEmpty', key: 'trunc', style: { marginTop: '8px' } },
|
|
@@ -7812,12 +9053,21 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7812
9053
|
])
|
|
7813
9054
|
})
|
|
7814
9055
|
|
|
7815
|
-
body = h('div', {
|
|
9056
|
+
body = h('div', {
|
|
9057
|
+
className: 'dg-bodyWrap',
|
|
9058
|
+
key: 'bodyWrap',
|
|
9059
|
+
// hover 门控:Ctrl+V 只在鼠标位于面板上时接管(见 hoveringRef 注释)
|
|
9060
|
+
onMouseEnter: () => { hoveringRef.current = true },
|
|
9061
|
+
// 离开面板就清掉粘贴落点,绝不让「上次 hover 的组」残留
|
|
9062
|
+
onMouseLeave: () => { hoveringRef.current = false; pasteTargetRef.current = null },
|
|
9063
|
+
}, [
|
|
7816
9064
|
h('div', {
|
|
7817
9065
|
className: `dg-body${kind === 'file' ? ' dg-fileBody' : ''}`,
|
|
7818
9066
|
key: 'body',
|
|
7819
9067
|
'data-gallery-body': true,
|
|
7820
9068
|
ref: bodyScrollRef,
|
|
9069
|
+
onPaste: onBodyPaste,
|
|
9070
|
+
onContextMenu: onBodyContextMenu,
|
|
7821
9071
|
}, [
|
|
7822
9072
|
h('div', { className: 'dg-groups', key: 'groups' }, groupNodes),
|
|
7823
9073
|
data.scan.capped
|
|
@@ -7871,12 +9121,19 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7871
9121
|
onOpen: (opened, anchorEl) => openViewer(visibleItems.indexOf(opened), anchorEl, visibleItems),
|
|
7872
9122
|
}), item, item.relPath))
|
|
7873
9123
|
// 网格区外面包一层定位容器,右侧放滚动辅助列(无滚轮场景用)
|
|
7874
|
-
body = h('div', {
|
|
9124
|
+
body = h('div', {
|
|
9125
|
+
className: 'dg-bodyWrap',
|
|
9126
|
+
key: 'bodyWrap',
|
|
9127
|
+
onMouseEnter: () => { hoveringRef.current = true },
|
|
9128
|
+
onMouseLeave: () => { hoveringRef.current = false; pasteTargetRef.current = null },
|
|
9129
|
+
}, [
|
|
7875
9130
|
h('div', {
|
|
7876
9131
|
className: `dg-body${kind === 'file' ? ' dg-fileBody' : ''}`,
|
|
7877
9132
|
key: 'body',
|
|
7878
9133
|
'data-gallery-body': true,
|
|
7879
9134
|
ref: bodyScrollRef,
|
|
9135
|
+
onPaste: onBodyPaste,
|
|
9136
|
+
onContextMenu: onBodyContextMenu,
|
|
7880
9137
|
}, [
|
|
7881
9138
|
(visibleItems.length > 0
|
|
7882
9139
|
? h('div', { className: `dg-grid${kind === 'file' ? ' dg-fileGrid' : ''}${kind === 'media' ? ' dg-mediaGrid' : ''}`, key: 'grid' }, kind === 'media' ? mediaGridChildren : gridChildren)
|
|
@@ -7978,7 +9235,14 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7978
9235
|
// 用 viewer.list(打开时记录的快照),不用全局 items:
|
|
7979
9236
|
// 分组视图下卡片来自组内文件,与当前页的扁平 items 不是同一个集合。
|
|
7980
9237
|
const viewerLayer = viewer !== null && Array.isArray(viewer.list) && viewer.list.length > 0
|
|
7981
|
-
? h('div', {
|
|
9238
|
+
? h('div', {
|
|
9239
|
+
className: 'dg-viewerLayer',
|
|
9240
|
+
key: 'viewerLayer',
|
|
9241
|
+
// 查看器是独立覆盖层:鼠标在这里也要让 Ctrl+V 生效,
|
|
9242
|
+
// 落点由 pasteTargetSid 从 viewer.originSid 取(不是 hover 的组)。
|
|
9243
|
+
onMouseEnter: () => { hoveringRef.current = true },
|
|
9244
|
+
onMouseLeave: () => { hoveringRef.current = false },
|
|
9245
|
+
},
|
|
7982
9246
|
h(Viewer, {
|
|
7983
9247
|
annotations: annotationsOf,
|
|
7984
9248
|
onAddAnnotation: addAnnotation,
|
|
@@ -7990,21 +9254,28 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
7990
9254
|
initialOriginal: viewer.asOriginal === true,
|
|
7991
9255
|
onClose: closeViewer,
|
|
7992
9256
|
onStep: step,
|
|
9257
|
+
onCrop: doCrop,
|
|
9258
|
+
// v0.16.3:Ctrl+C / 顶部按钮 → 复制当前文件(复用 copyAssets,Host 解析绝对路径写剪贴板)
|
|
9259
|
+
onCopyFile: (relPath) => { void doCopyAssets([relPath]) },
|
|
7993
9260
|
}))
|
|
7994
9261
|
: null
|
|
7995
9262
|
|
|
7996
9263
|
// 音视频播放器层(v0.10.1)
|
|
7997
|
-
//
|
|
9264
|
+
// 截帧要挂到对话:把当前组标题 / 创建时间一并传下去登记
|
|
9265
|
+
// v0.16.2:在全局视图里播放别组的素材,产物要落回**那个组**,
|
|
9266
|
+
// 标题/创建时间留空由 Host 读会话日志补(传错组名比留空更糟)。
|
|
9267
|
+
const mediaOriginSid = mediaPlaying === null ? '' : String(mediaPlaying.originSessionId ?? '')
|
|
9268
|
+
const mediaSameAsCurrent = mediaOriginSid === '' || mediaOriginSid === String(sessionId ?? '')
|
|
7998
9269
|
const mediaLayer = mediaPlaying !== null
|
|
7999
9270
|
? h(MediaPlayer, {
|
|
8000
9271
|
key: 'mediaPlayer',
|
|
8001
9272
|
item: mediaPlaying,
|
|
8002
9273
|
t,
|
|
8003
|
-
sessionId: sessionId ?? '',
|
|
8004
|
-
sessionTitle: Array.isArray(data?.groups)
|
|
9274
|
+
sessionId: mediaSameAsCurrent ? (sessionId ?? '') : mediaOriginSid,
|
|
9275
|
+
sessionTitle: mediaSameAsCurrent && Array.isArray(data?.groups)
|
|
8005
9276
|
? (data.groups.find((g) => g.isCurrent)?.title ?? '')
|
|
8006
9277
|
: '',
|
|
8007
|
-
sessionCreatedAt: Array.isArray(data?.groups)
|
|
9278
|
+
sessionCreatedAt: mediaSameAsCurrent && Array.isArray(data?.groups)
|
|
8008
9279
|
? (data.groups.find((g) => g.isCurrent)?.createdAt ?? 0)
|
|
8009
9280
|
: 0,
|
|
8010
9281
|
onSaved: () => { void refresh() },
|
|
@@ -8137,7 +9408,11 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8137
9408
|
onHide: () => { void doHide(ctxMenu.item) },
|
|
8138
9409
|
onReveal: () => { void doReveal(ctxMenu.item) },
|
|
8139
9410
|
onCopy: () => { void copyText(ctxMenu.absPath) },
|
|
9411
|
+
// v0.16.0 单文件复制:写系统剪贴板文件列表,可在别的对话粘贴
|
|
9412
|
+
onCopyFile: () => { void doCopyAssets([ctxMenu.item.relPath]) },
|
|
8140
9413
|
onDelete: () => setDeleteTarget({ item: ctxMenu.item, busy: false }),
|
|
9414
|
+
// v0.16.0:列表级粘贴(右键任意卡片也出现)
|
|
9415
|
+
onPaste: () => { void doPaste() },
|
|
8141
9416
|
// v0.14.2:改标签 / 恢复自动,表态层已下线
|
|
8142
9417
|
onEditLabel: () => {
|
|
8143
9418
|
const target = ctxMenu.item
|
|
@@ -8164,6 +9439,20 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8164
9439
|
})
|
|
8165
9440
|
: null
|
|
8166
9441
|
|
|
9442
|
+
// v0.16.0:右键空白处(非卡片)的「粘贴」菜单;只给粘贴一项
|
|
9443
|
+
const pasteLayer = pasteMenu !== null
|
|
9444
|
+
? h(ContextMenu, {
|
|
9445
|
+
key: 'pasteMenu',
|
|
9446
|
+
t,
|
|
9447
|
+
x: pasteMenu.x,
|
|
9448
|
+
y: pasteMenu.y,
|
|
9449
|
+
// 菜单标题直接写清落点,避免「粘到哪去了」说不清
|
|
9450
|
+
item: { relPath: '', name: format(t('pasteTo'), { target: pasteMenu.targetLabel ?? t('pasteTargetCurrent') }) },
|
|
9451
|
+
onClose: () => setPasteMenu(null),
|
|
9452
|
+
actions: { onPaste: () => { void doPaste() } },
|
|
9453
|
+
})
|
|
9454
|
+
: null
|
|
9455
|
+
|
|
8167
9456
|
// 删除确认弹窗
|
|
8168
9457
|
const confirmLayer = deleteTarget !== null
|
|
8169
9458
|
? h(ConfirmDialog, {
|
|
@@ -8189,9 +9478,19 @@ function AnnotationLayer({ t, annotations, onAdd, onRemove, active, dragging, fr
|
|
|
8189
9478
|
mediaLayer,
|
|
8190
9479
|
settingsLayer,
|
|
8191
9480
|
ctxLayer,
|
|
9481
|
+
pasteLayer,
|
|
8192
9482
|
confirmLayer,
|
|
8193
9483
|
feedbackLayer,
|
|
8194
9484
|
labelLayer,
|
|
9485
|
+
// v0.16.0 粘贴结果提示(贴在根级,跟随画廊不随网格滚动)
|
|
9486
|
+
pasteNotice === null
|
|
9487
|
+
? null
|
|
9488
|
+
: h('div', {
|
|
9489
|
+
className: 'dg-pasteNotice'
|
|
9490
|
+
+ (pasteNotice.kind === 'ok' ? ' dg-pasteOk' : ' dg-pasteFail'),
|
|
9491
|
+
key: 'pasteNotice',
|
|
9492
|
+
'data-gallery-paste-notice': pasteNotice.kind,
|
|
9493
|
+
}, pasteNotice.text),
|
|
8195
9494
|
])
|
|
8196
9495
|
}
|
|
8197
9496
|
|