dsh-knit 0.25.0 → 0.27.0
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 +76 -0
- package/README.en.md +13 -7
- package/README.md +11 -6
- package/SECURITY.md +12 -3
- package/package.json +6 -2
- package/src/client/client.js +1619 -117
- package/src/host/git.js +184 -3
- package/src/host/index.js +236 -2
- package/test/client.test.mjs +88 -16
- package/test/comments.test.mjs +1004 -0
- package/test/git-changes.test.mjs +197 -3
- package/test/harness.mjs +6 -0
package/src/client/client.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* 面板本身:列表(相关性或 mtime 排序 + 过滤 + 键盘导航)+ 列表下方的就地预览。
|
|
9
9
|
* 两个宿主共用同一个 KnitBody,只在「怎么开新标签页」上用适配器分叉。
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* 构建:源码在 `tools/client-src/*.js`,由 `node tools/build-client.mjs` 拼成
|
|
12
|
+
* `src/client/client.js`(DSH 仍只加载这一个文件;无 bundler、无 JSX)。
|
|
12
13
|
*/
|
|
13
14
|
window.__ModuleLoader__.load({
|
|
14
15
|
id: 'dsh-knit',
|
|
@@ -41,6 +42,8 @@ window.__ModuleLoader__.load({
|
|
|
41
42
|
'count.code.filtered': '{hit} / {total} 个代码文件',
|
|
42
43
|
'count.media': '{n} 个媒体',
|
|
43
44
|
'count.media.filtered': '{hit} / {total} 个媒体',
|
|
45
|
+
'count.changes': '{n} 个变更文件',
|
|
46
|
+
'count.changes.filtered': '{hit} / {total} 个变更文件',
|
|
44
47
|
'action.refresh': '刷新',
|
|
45
48
|
'path.openTitle': '在文件管理器中打开',
|
|
46
49
|
'peek.empty': '这个工作区里还没有 Markdown 文档。',
|
|
@@ -49,6 +52,7 @@ window.__ModuleLoader__.load({
|
|
|
49
52
|
'sort.relevance': '相关',
|
|
50
53
|
'sort.time': '最新',
|
|
51
54
|
'sort.mediaTimeTitle': '图片一律按时间排序(最新在前)',
|
|
55
|
+
'sort.changesTitle': '变更按文件修改时间列出(最新在前)',
|
|
52
56
|
'sort.relevanceTitle': '按与当前对话的相关性排序(纯本地关键词匹配,不调模型)',
|
|
53
57
|
'sort.timeTitle': '按文件修改时间倒序',
|
|
54
58
|
|
|
@@ -64,6 +68,7 @@ window.__ModuleLoader__.load({
|
|
|
64
68
|
// 只扫图片与视频(宿主按扩展名放行,没有音频);③ 「媒体」省 3 个字,窄侧栏少一次
|
|
65
69
|
// 省略号。**含义由空态说明**(list.emptyMedia 仍写「还没有图片或视频」)。
|
|
66
70
|
'kind.media': '媒体',
|
|
71
|
+
'kind.changes': '变更',
|
|
67
72
|
'kind.title': '切换要列出的产物类型',
|
|
68
73
|
|
|
69
74
|
'filter.placeholder': '过滤文档',
|
|
@@ -296,6 +301,24 @@ window.__ModuleLoader__.load({
|
|
|
296
301
|
'list.empty': '这个工作区里还没有 Markdown 文档。',
|
|
297
302
|
'list.emptyCode': '这个工作区里还没有可纳入上下文的代码文件。',
|
|
298
303
|
'list.emptyMedia': '这个工作区里还没有图片或视频。',
|
|
304
|
+
'list.emptyChanges': '工作区里没有未提交的改动。',
|
|
305
|
+
'list.changeOnlyOther': '有 {n} 个变更文件,但没有可列出的 Markdown / 代码。',
|
|
306
|
+
'list.changesLoading': '正在读取 Git 变更…',
|
|
307
|
+
'changes.unavailable': '读不到 Git 变更:{reason}',
|
|
308
|
+
'changes.status.modified': '修改',
|
|
309
|
+
'changes.status.added': '新增',
|
|
310
|
+
'changes.status.deleted': '删除',
|
|
311
|
+
'changes.status.renamed': '重命名',
|
|
312
|
+
'changes.status.untracked': '新文件',
|
|
313
|
+
'changes.status.unmerged': '冲突',
|
|
314
|
+
'changes.status.copied': '复制',
|
|
315
|
+
'changes.binary': '二进制',
|
|
316
|
+
'changes.lines': '行数统计不可用',
|
|
317
|
+
'diff.loading': '正在读取 diff…',
|
|
318
|
+
'diff.failed': '读取 diff 失败',
|
|
319
|
+
'diff.binary': '二进制文件,没有文本 diff',
|
|
320
|
+
'diff.truncated': 'diff 已截断',
|
|
321
|
+
'changes.title': '未提交的改动(只读 git status + numstat)',
|
|
299
322
|
'list.noMatch': '没有匹配「{query}」的文档。',
|
|
300
323
|
// 文档列表这个 listbox 的无障碍名字(原先硬编码在 JSX 里,英文界面下会漏出中文)
|
|
301
324
|
'list.aria': '最近文档',
|
|
@@ -318,6 +341,40 @@ window.__ModuleLoader__.load({
|
|
|
318
341
|
// v0.25 预览里的查找(Cmd+F)。数字用 {current}/{total},两种语言同形。
|
|
319
342
|
'lightbox.aria': '查看大图:{name}',
|
|
320
343
|
'lightbox.close': '关闭(Esc)',
|
|
344
|
+
/* v0.26 图内评论:pin / 就地编辑 / 底部评论栏。
|
|
345
|
+
发送出去的文本**不走这两本词典** —— 它是给 agent 的事实格式(§四),不随界面语言变。 */
|
|
346
|
+
'lightbox.comment.enter': '评论',
|
|
347
|
+
'lightbox.comment.exit': '退出评论',
|
|
348
|
+
'lightbox.comment.title': '在图上点一下落 pin,写一句给 agent',
|
|
349
|
+
'lightbox.comment.placeholder': '哪里不对?写一句…',
|
|
350
|
+
'lightbox.comment.pinAria': '第 {n} 条评论',
|
|
351
|
+
'lightbox.comment.new': '新评论',
|
|
352
|
+
'lightbox.comment.edit': '评论 {n}',
|
|
353
|
+
'lightbox.comment.cancel': '取消',
|
|
354
|
+
'lightbox.comment.save': '保存',
|
|
355
|
+
'lightbox.comment.delete': '删除',
|
|
356
|
+
'lightbox.comment.empty': '这张图还没有评论',
|
|
357
|
+
'lightbox.comment.emptyHint': '点一下图片上的位置,写下第一条评论',
|
|
358
|
+
'lightbox.comment.count': '{n} 条评论',
|
|
359
|
+
'lightbox.comment.send': '发送',
|
|
360
|
+
'lightbox.comment.sendTitle': '把坐标和文字投进输入框(不会自动发送)',
|
|
361
|
+
'lightbox.comment.sent': '已投进输入框(含原图附件),按 Enter 发送',
|
|
362
|
+
'lightbox.comment.sentNoImage': '已投递文本,但图片附件没带上(请手动把图拖进输入框)',
|
|
363
|
+
'lightbox.comment.copied': '输入框没接住,已复制到剪贴板',
|
|
364
|
+
'lightbox.comment.downloaded': '输入框没接住,已下载为 txt',
|
|
365
|
+
'lightbox.comment.sendFailed': '投递失败,请手动复制',
|
|
366
|
+
'lightbox.comment.tooLong': '一条最多 {max} 字',
|
|
367
|
+
'lightbox.comment.full': '一张图最多 {max} 条评论',
|
|
368
|
+
'lightbox.canvas.back': '返回',
|
|
369
|
+
'lightbox.canvas.backTitle': '关掉画布,回到媒体列表',
|
|
370
|
+
'lightbox.canvas.fullscreen': '全屏',
|
|
371
|
+
'lightbox.canvas.fullscreenTitle': '在整屏里看细节(评论会保留)',
|
|
372
|
+
'lightbox.canvas.dock': '画布',
|
|
373
|
+
'lightbox.canvas.dockTitle': '回到 Knit 面板里的画布(不盖住会话)',
|
|
374
|
+
'lightbox.canvas.commentHint': '评论',
|
|
375
|
+
'lightbox.canvas.hintTitle': '点击在 Knit 面板里打开画布并评论(不盖住会话)',
|
|
376
|
+
'lightbox.canvas.prev': '上一张',
|
|
377
|
+
'lightbox.canvas.next': '下一张',
|
|
321
378
|
'attach.badge': '对话',
|
|
322
379
|
'attach.title': '对话里生成的图,还没保存到本地',
|
|
323
380
|
'fav.off': '收藏',
|
|
@@ -398,6 +455,7 @@ window.__ModuleLoader__.load({
|
|
|
398
455
|
'host.mediaTooLarge': '视频过大',
|
|
399
456
|
'host.readFailed': '读取失败',
|
|
400
457
|
'host.missingRel': '缺少 rel 参数',
|
|
458
|
+
'host.diffFailed': '读取 diff 失败',
|
|
401
459
|
'host.internal': '宿主内部错误',
|
|
402
460
|
}
|
|
403
461
|
|
|
@@ -414,6 +472,8 @@ window.__ModuleLoader__.load({
|
|
|
414
472
|
'count.code.filtered': '{hit} / {total} code files',
|
|
415
473
|
'count.media': '{n} media',
|
|
416
474
|
'count.media.filtered': '{hit} / {total} media',
|
|
475
|
+
'count.changes': '{n} changed files',
|
|
476
|
+
'count.changes.filtered': '{hit} / {total} changed files',
|
|
417
477
|
'action.refresh': 'Refresh',
|
|
418
478
|
'path.openTitle': 'Open in file manager',
|
|
419
479
|
'peek.empty': 'No Markdown documents in this workspace yet.',
|
|
@@ -422,6 +482,7 @@ window.__ModuleLoader__.load({
|
|
|
422
482
|
'sort.relevance': 'Relevant',
|
|
423
483
|
'sort.time': 'Recent',
|
|
424
484
|
'sort.mediaTimeTitle': 'Images are always sorted by newest first',
|
|
485
|
+
'sort.changesTitle': 'Changes are listed by file modification time (newest first)',
|
|
425
486
|
'sort.relevanceTitle': 'Sort by relevance to the current conversation (local keyword matching, no model call)',
|
|
426
487
|
'sort.timeTitle': 'Sort by file modified time, newest first',
|
|
427
488
|
|
|
@@ -431,6 +492,7 @@ window.__ModuleLoader__.load({
|
|
|
431
492
|
// follows the same word as count.media ("{n} media"): the tab says Media, and the
|
|
432
493
|
// explicit "images and videos" wording stays in the empty state / README prose.
|
|
433
494
|
'kind.media': 'Media',
|
|
495
|
+
'kind.changes': 'Changes',
|
|
434
496
|
'kind.title': 'Switch which artifacts are listed',
|
|
435
497
|
|
|
436
498
|
'filter.placeholder': 'Filter docs',
|
|
@@ -618,6 +680,24 @@ window.__ModuleLoader__.load({
|
|
|
618
680
|
'list.empty': 'No Markdown documents in this workspace yet.',
|
|
619
681
|
'list.emptyCode': 'No code files eligible for context in this workspace yet.',
|
|
620
682
|
'list.emptyMedia': 'No images or videos in this workspace yet.',
|
|
683
|
+
'list.emptyChanges': 'No uncommitted changes in this workspace.',
|
|
684
|
+
'list.changeOnlyOther': '{n} changed file(s), but no Markdown / code to list.',
|
|
685
|
+
'list.changesLoading': 'Reading Git changes…',
|
|
686
|
+
'changes.unavailable': 'Git changes unavailable: {reason}',
|
|
687
|
+
'changes.status.modified': 'Modified',
|
|
688
|
+
'changes.status.added': 'Added',
|
|
689
|
+
'changes.status.deleted': 'Deleted',
|
|
690
|
+
'changes.status.renamed': 'Renamed',
|
|
691
|
+
'changes.status.untracked': 'Untracked',
|
|
692
|
+
'changes.status.unmerged': 'Conflict',
|
|
693
|
+
'changes.status.copied': 'Copied',
|
|
694
|
+
'changes.binary': 'binary',
|
|
695
|
+
'changes.lines': 'line counts unavailable',
|
|
696
|
+
'diff.loading': 'Reading diff…',
|
|
697
|
+
'diff.failed': 'Could not read the diff',
|
|
698
|
+
'diff.binary': 'Binary file — no text diff',
|
|
699
|
+
'diff.truncated': 'Diff truncated',
|
|
700
|
+
'changes.title': 'Uncommitted changes (read-only git status + numstat)',
|
|
621
701
|
'list.noMatch': 'No documents match “{query}”.',
|
|
622
702
|
// Accessible name of the document listbox (was hardcoded in JSX before)
|
|
623
703
|
'list.aria': 'Recent documents',
|
|
@@ -640,6 +720,38 @@ window.__ModuleLoader__.load({
|
|
|
640
720
|
'preview.truncated': '(large file — showing the first 512 KB)',
|
|
641
721
|
'lightbox.aria': 'Image viewer: {name}',
|
|
642
722
|
'lightbox.close': 'Close (Esc)',
|
|
723
|
+
'lightbox.comment.enter': 'Comment',
|
|
724
|
+
'lightbox.comment.exit': 'Exit comment',
|
|
725
|
+
'lightbox.comment.title': 'Click the image to drop a pin, then write one line for the agent',
|
|
726
|
+
'lightbox.comment.placeholder': 'What is wrong here?',
|
|
727
|
+
'lightbox.comment.pinAria': 'Comment {n}',
|
|
728
|
+
'lightbox.comment.new': 'New comment',
|
|
729
|
+
'lightbox.comment.edit': 'Comment {n}',
|
|
730
|
+
'lightbox.comment.cancel': 'Cancel',
|
|
731
|
+
'lightbox.comment.save': 'Save',
|
|
732
|
+
'lightbox.comment.delete': 'Delete',
|
|
733
|
+
'lightbox.comment.empty': 'No comments on this image yet',
|
|
734
|
+
'lightbox.comment.emptyHint': 'Click a spot on the image to add the first comment',
|
|
735
|
+
'lightbox.comment.count': '{n} comments',
|
|
736
|
+
'lightbox.comment.send': 'Send',
|
|
737
|
+
'lightbox.comment.sendTitle': 'Insert the coordinates and text into the composer (it will not be sent automatically)',
|
|
738
|
+
'lightbox.comment.sent': 'Inserted into the composer with the original image — press Enter to send',
|
|
739
|
+
'lightbox.comment.sentNoImage': 'Text inserted, but the image attachment failed — drag the image into the composer',
|
|
740
|
+
'lightbox.comment.copied': 'Composer did not accept it — copied to clipboard',
|
|
741
|
+
'lightbox.comment.downloaded': 'Composer did not accept it — downloaded as a txt file',
|
|
742
|
+
'lightbox.comment.sendFailed': 'Delivery failed — copy it manually',
|
|
743
|
+
'lightbox.comment.tooLong': 'Up to {max} characters per note',
|
|
744
|
+
'lightbox.comment.full': 'Up to {max} comments per image',
|
|
745
|
+
'lightbox.canvas.back': 'Back',
|
|
746
|
+
'lightbox.canvas.backTitle': 'Close the canvas and return to the media list',
|
|
747
|
+
'lightbox.canvas.fullscreen': 'Full screen',
|
|
748
|
+
'lightbox.canvas.fullscreenTitle': 'View details full screen (comments are kept)',
|
|
749
|
+
'lightbox.canvas.dock': 'Canvas',
|
|
750
|
+
'lightbox.canvas.dockTitle': 'Back to the canvas inside the Knit panel (the conversation stays visible)',
|
|
751
|
+
'lightbox.canvas.commentHint': 'Comment',
|
|
752
|
+
'lightbox.canvas.hintTitle': 'Click to open the canvas in the Knit panel and comment (the conversation stays visible)',
|
|
753
|
+
'lightbox.canvas.prev': 'Previous image',
|
|
754
|
+
'lightbox.canvas.next': 'Next image',
|
|
643
755
|
'attach.badge': 'Chat',
|
|
644
756
|
'attach.title': 'Generated in this chat — not saved locally yet',
|
|
645
757
|
'fav.off': 'Favorite',
|
|
@@ -702,6 +814,7 @@ window.__ModuleLoader__.load({
|
|
|
702
814
|
'host.mediaTooLarge': 'Video too large',
|
|
703
815
|
'host.readFailed': 'Read failed',
|
|
704
816
|
'host.missingRel': 'Missing the rel parameter',
|
|
817
|
+
'host.diffFailed': 'Could not read the diff',
|
|
705
818
|
'host.internal': 'Internal host error',
|
|
706
819
|
}
|
|
707
820
|
|
|
@@ -741,6 +854,7 @@ window.__ModuleLoader__.load({
|
|
|
741
854
|
'knit/media-too-large': 'host.mediaTooLarge',
|
|
742
855
|
'knit/read-failed': 'host.readFailed',
|
|
743
856
|
'knit/missing-rel': 'host.missingRel',
|
|
857
|
+
'knit/diff-failed': 'host.diffFailed',
|
|
744
858
|
'knit/internal': 'host.internal',
|
|
745
859
|
}
|
|
746
860
|
|
|
@@ -836,6 +950,8 @@ window.__ModuleLoader__.load({
|
|
|
836
950
|
/* v0.25:Git 变更关联的**独立接口**。它与列表接口分开,所以「列表的响应形状」
|
|
837
951
|
不会被这个功能碰到;关掉功能时客户端连这个请求都不发。 */
|
|
838
952
|
const CHANGES_API = '/knit/api/changes'
|
|
953
|
+
const STATUS_API = '/knit/api/status'
|
|
954
|
+
const DIFF_API = '/knit/api/diff'
|
|
839
955
|
/* v0.25:媒体档额外显示「对话里工具产出的图」——**独立接口**,`/api/recent` 一个字节没动。
|
|
840
956
|
列表零 I/O(元数据全在会话事件里);字节按 **sha256** 取(见 `attachmentUrl`)。 */
|
|
841
957
|
const ATTACH_LIST_API = '/knit/api/attachments'
|
|
@@ -895,6 +1011,8 @@ window.__ModuleLoader__.load({
|
|
|
895
1011
|
*/
|
|
896
1012
|
const KIND_CODE = 'code'
|
|
897
1013
|
const KIND_MEDIA = 'media'
|
|
1014
|
+
/** v0.26.x:「变更」档 —— 未提交改动(跨 Markdown / 代码)。 */
|
|
1015
|
+
const KIND_CHANGES = 'changes'
|
|
898
1016
|
|
|
899
1017
|
/**
|
|
900
1018
|
* v0.19:分类层给的「生成产物」档(`.map` / `*.min.js` / `package-lock.json` …)。
|
|
@@ -1092,12 +1210,536 @@ window.__ModuleLoader__.load({
|
|
|
1092
1210
|
return { start, items: list.slice(start, start + size) }
|
|
1093
1211
|
}
|
|
1094
1212
|
|
|
1213
|
+
/* ── v0.26:图内评论(pin 评论)────────────────────────────────────────
|
|
1214
|
+
起点是 Codex 画布与 Infini 分享包的**坐标格式**:
|
|
1215
|
+
每条评论 { n, xPct, yPct, text },xPct / yPct 是相对**图片实际绘制矩形**
|
|
1216
|
+
(object-fit: contain 之后那一块)的 0–100 百分比。
|
|
1217
|
+
⚠️ 命门在坐标:**百分比只能从 contentRect 算**,不能从 stage 框算 ——
|
|
1218
|
+
图不是等比铺满 stage(letterbox 的空白也算在 stage 里),拿 stage 算会让
|
|
1219
|
+
所有 pin 在窄视口 / 方图上整体偏移。window resize / 面板宽度变化 / 滚动后
|
|
1220
|
+
都要重算(measureCommentBox + ResizeObserver + resize / scroll 监听)。
|
|
1221
|
+
P0 **不落盘**:评论只活在这个组件的 state 里,退出查看器仍在、硬刷新丢失。
|
|
1222
|
+
*/
|
|
1223
|
+
|
|
1224
|
+
/** 一条评论最多几个字(超出提示,不截断用户输入)。 */
|
|
1225
|
+
const COMMENT_MAX_CHARS = 200
|
|
1226
|
+
/** 一张图最多几条评论(到顶就不许再落新 pin)。 */
|
|
1227
|
+
const COMMENT_MAX = 50
|
|
1228
|
+
/** 底部评论栏里一条文字摘要最多显示几个字。 */
|
|
1229
|
+
const COMMENT_SUMMARY_CHARS = 28
|
|
1230
|
+
/** 评论编辑气泡的基准尺寸(px):用来算「会不会出屏 / 该往哪边翻」。 */
|
|
1231
|
+
const COMMENT_POP_W = 280
|
|
1232
|
+
const COMMENT_POP_H = 172
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* `object-fit` 之后**真正画出图**的那块矩形(视口坐标)。
|
|
1236
|
+
*
|
|
1237
|
+
* 为什么不能直接用 img 元素盒:`object-fit: contain` 时盒子里会留 letterbox 空白,
|
|
1238
|
+
* 百分比按盒子算会在空白里也落 pin,并且整体偏移。拿 naturalWidth / naturalHeight
|
|
1239
|
+
* 反推缩放比,才能得到「图上这一点」的真实位置。
|
|
1240
|
+
*
|
|
1241
|
+
* @param {{left:number,top:number,width:number,height:number}} imgRect - img 元素盒
|
|
1242
|
+
* @param {{width:number,height:number}} natural - naturalWidth / naturalHeight
|
|
1243
|
+
* @param {'contain'|'cover'|'fill'} [mode] - object-fit 模式
|
|
1244
|
+
* @returns {{left:number,top:number,width:number,height:number}|null} 绘制矩形
|
|
1245
|
+
*/
|
|
1246
|
+
function contentRect(imgRect, natural, mode = 'contain') {
|
|
1247
|
+
if (!imgRect || !natural) return null
|
|
1248
|
+
const boxW = Number(imgRect.width)
|
|
1249
|
+
const boxH = Number(imgRect.height)
|
|
1250
|
+
const natW = Number(natural.width)
|
|
1251
|
+
const natH = Number(natural.height)
|
|
1252
|
+
if (!(boxW > 0) || !(boxH > 0) || !(natW > 0) || !(natH > 0)) return null
|
|
1253
|
+
const fit = mode === 'cover' ? 'cover' : mode === 'fill' ? 'fill' : 'contain'
|
|
1254
|
+
let width = boxW
|
|
1255
|
+
let height = boxH
|
|
1256
|
+
if (fit !== 'fill') {
|
|
1257
|
+
const scale = fit === 'cover'
|
|
1258
|
+
? Math.max(boxW / natW, boxH / natH)
|
|
1259
|
+
: Math.min(boxW / natW, boxH / natH)
|
|
1260
|
+
width = natW * scale
|
|
1261
|
+
height = natH * scale
|
|
1262
|
+
}
|
|
1263
|
+
const left = Number.isFinite(Number(imgRect.left)) ? Number(imgRect.left) : 0
|
|
1264
|
+
const top = Number.isFinite(Number(imgRect.top)) ? Number(imgRect.top) : 0
|
|
1265
|
+
return { left: left + (boxW - width) / 2, top: top + (boxH - height) / 2, width, height }
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/** 百分比保留到千分位,避免浮点噪声把「同一个点」写成两个值。 */
|
|
1269
|
+
function roundPct(value) {
|
|
1270
|
+
return Math.min(100, Math.max(0, Math.round(Number(value) * 1000) / 1000))
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
/**
|
|
1274
|
+
* 视口坐标 → 内容框里的百分比。**纯函数**。
|
|
1275
|
+
* @param {{x:number,y:number}} point - 视口坐标
|
|
1276
|
+
* @param {{left:number,top:number,width:number,height:number}} rect - contentRect 的结果
|
|
1277
|
+
* @returns {{xPct:number,yPct:number}|null} 0–100 的百分比
|
|
1278
|
+
*/
|
|
1279
|
+
function pctFromPoint(point, rect) {
|
|
1280
|
+
if (!point || !rect) return null
|
|
1281
|
+
const x = Number(point.x)
|
|
1282
|
+
const y = Number(point.y)
|
|
1283
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) return null
|
|
1284
|
+
if (!(rect.width > 0) || !(rect.height > 0)) return null
|
|
1285
|
+
return {
|
|
1286
|
+
xPct: roundPct(((x - rect.left) / rect.width) * 100),
|
|
1287
|
+
yPct: roundPct(((y - rect.top) / rect.height) * 100),
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* 百分比 → 视口坐标(`pctFromPoint` 的逆运算)。**纯函数**。
|
|
1293
|
+
* @param {{xPct:number,yPct:number}} pct - 0–100 的百分比
|
|
1294
|
+
* @param {{left:number,top:number,width:number,height:number}} rect - contentRect 的结果
|
|
1295
|
+
* @returns {{x:number,y:number}|null} 视口坐标
|
|
1296
|
+
*/
|
|
1297
|
+
function pointFromPct(pct, rect) {
|
|
1298
|
+
if (!pct || !rect) return null
|
|
1299
|
+
const xPct = Number(pct.xPct)
|
|
1300
|
+
const yPct = Number(pct.yPct)
|
|
1301
|
+
if (!Number.isFinite(xPct) || !Number.isFinite(yPct)) return null
|
|
1302
|
+
return {
|
|
1303
|
+
x: rect.left + (Math.min(100, Math.max(0, xPct)) / 100) * rect.width,
|
|
1304
|
+
y: rect.top + (Math.min(100, Math.max(0, yPct)) / 100) * rect.height,
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* 把任意来源的评论表洗成**可信的形状**:畸形回空、坐标夹到 0–100、
|
|
1310
|
+
* 空文本不占位、条数封顶、编号从 1 连续重排。**纯函数**。
|
|
1311
|
+
*
|
|
1312
|
+
* ⚠️ 编号连续是刻意的:删掉中间一条之后,剩下的必须重新从 1 排 ——
|
|
1313
|
+
* 否则发送文本里会出现「1. 3. 4.」,agent 读起来像漏了内容。
|
|
1314
|
+
*
|
|
1315
|
+
* @param {object[]|null} raw - 任意输入(localStorage / 手改 / 旧版本)
|
|
1316
|
+
* @returns {{n:number,xPct:number,yPct:number,text:string}[]} 干净列表
|
|
1317
|
+
*/
|
|
1318
|
+
function normalizeComments(raw) {
|
|
1319
|
+
if (!Array.isArray(raw)) return []
|
|
1320
|
+
const out = []
|
|
1321
|
+
for (const item of raw) {
|
|
1322
|
+
if (out.length >= COMMENT_MAX) break
|
|
1323
|
+
if (!item || typeof item !== 'object') continue
|
|
1324
|
+
const text = typeof item.text === 'string' ? item.text : ''
|
|
1325
|
+
if (!text.trim()) continue
|
|
1326
|
+
const xPct = Number(item.xPct)
|
|
1327
|
+
const yPct = Number(item.yPct)
|
|
1328
|
+
if (!Number.isFinite(xPct) || !Number.isFinite(yPct)) continue
|
|
1329
|
+
out.push({ n: out.length + 1, xPct: roundPct(xPct), yPct: roundPct(yPct), text })
|
|
1330
|
+
}
|
|
1331
|
+
return out
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
* 下一条评论的编号(1 起、连续)。**纯函数**。
|
|
1336
|
+
* @param {{n:number}[]|null} list - 当前评论
|
|
1337
|
+
* @returns {number} 下一个编号
|
|
1338
|
+
*/
|
|
1339
|
+
function nextNumber(list) {
|
|
1340
|
+
const items = normalizeComments(list)
|
|
1341
|
+
// normalizeComments 已经保证连续,最后一条的 n + 1 就是下一个
|
|
1342
|
+
if (items.length) return items[items.length - 1].n + 1
|
|
1343
|
+
// 还没成形(比如只有 {n} 没有坐标)时按「有几条」兜底,仍然从 1 起连续
|
|
1344
|
+
const count = Array.isArray(list) ? list.filter((item) => item && typeof item === 'object').length : 0
|
|
1345
|
+
return count + 1
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
/** 评论栏里的一行摘要(按字数截,末尾补省略号)。**纯函数**。 */
|
|
1349
|
+
function commentSummary(text, max) {
|
|
1350
|
+
const raw = String(text === undefined || text === null ? '' : text)
|
|
1351
|
+
const limit = Number.isFinite(max) ? Math.max(1, Math.round(max)) : COMMENT_SUMMARY_CHARS
|
|
1352
|
+
return raw.length > limit ? `${raw.slice(0, limit)}…` : raw
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* §四 的发送文本行。**纯函数**(但格式是「事实标准」,刻意不随界面语言变)。
|
|
1357
|
+
*
|
|
1358
|
+
* 单图:
|
|
1359
|
+
* 图像 1:<文件名或 rel>(sha256 <前 12 位,若有>)
|
|
1360
|
+
* 1.(x:62.5%,y:31.0%)文案
|
|
1361
|
+
*
|
|
1362
|
+
* @param {{n:number,xPct:number,yPct:number,text:string}[]} list - 评论
|
|
1363
|
+
* @param {{name?:string,rel?:string,sha?:string,index?:number}} [image] - 身份 + 在输入框附件里的序号
|
|
1364
|
+
* @returns {string[]} 文本行
|
|
1365
|
+
*/
|
|
1366
|
+
function commentLines(list, image) {
|
|
1367
|
+
const lines = []
|
|
1368
|
+
const label = image && (image.rel || image.name)
|
|
1369
|
+
if (label) {
|
|
1370
|
+
const sha = image.sha ? String(image.sha).slice(0, 12) : ''
|
|
1371
|
+
/* 编号必须与**输入框里的附件顺序**一致:第一张附过去是「图像 1」,第二张是「图像 2」。
|
|
1372
|
+
不传 index(旧调用 / 单测)时回落 1。 */
|
|
1373
|
+
const index = image && Number.isFinite(image.index) && image.index > 0 ? Math.round(image.index) : 1
|
|
1374
|
+
lines.push(`图像 ${index}:${label}${sha ? `(sha256 ${sha})` : ''}`)
|
|
1375
|
+
}
|
|
1376
|
+
for (const item of normalizeComments(list)) {
|
|
1377
|
+
lines.push(`${item.n}.(x:${item.xPct.toFixed(1)}%,y:${item.yPct.toFixed(1)}%)${item.text}`)
|
|
1378
|
+
}
|
|
1379
|
+
return lines
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
/**
|
|
1383
|
+
* 评论挂在谁身上:工作区图用 rel;对话里生成的图没有路径,用附件 sha256 id。
|
|
1384
|
+
* **纯函数**。
|
|
1385
|
+
* @param {object|null} doc - 媒体条目
|
|
1386
|
+
* @returns {string} 锚点 id(空串表示无可锚定)
|
|
1387
|
+
*/
|
|
1388
|
+
function anchorIdFor(doc) {
|
|
1389
|
+
if (!doc) return ''
|
|
1390
|
+
if (doc.attachmentId) return String(doc.attachmentId)
|
|
1391
|
+
const rel = String(doc.rel || '')
|
|
1392
|
+
if (/^sha256:[0-9a-f]{64}$/i.test(rel)) return rel
|
|
1393
|
+
return rel || (doc.path ? String(doc.path) : '')
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
/**
|
|
1397
|
+
* 这张图的 sha256(有就取,没有就空串)。工作区图通常没有,对话图一定有。
|
|
1398
|
+
* @param {object|null} doc - 媒体条目
|
|
1399
|
+
* @returns {string} 64 位十六进制,或空串
|
|
1400
|
+
*/
|
|
1401
|
+
function shaOfDoc(doc) {
|
|
1402
|
+
if (!doc) return ''
|
|
1403
|
+
const direct = doc.sha256 || doc.sha
|
|
1404
|
+
if (typeof direct === 'string' && /^[0-9a-f]{64}$/i.test(direct)) return direct
|
|
1405
|
+
const id = String(doc.attachmentId || doc.rel || '')
|
|
1406
|
+
const match = /^sha256:([0-9a-f]{64})$/i.exec(id)
|
|
1407
|
+
return match ? match[1] : ''
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/** 取某张图的评论(没有就空表)。**纯函数**。 */
|
|
1411
|
+
function commentsFor(store, anchor) {
|
|
1412
|
+
if (!store || typeof store !== 'object' || !anchor) return []
|
|
1413
|
+
return normalizeComments(store[anchor])
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* 写回某张图的评论:返回**新对象**(不原地改 state),空表则删键不留垃圾。
|
|
1418
|
+
* **纯函数**。
|
|
1419
|
+
*/
|
|
1420
|
+
function withComments(store, anchor, list) {
|
|
1421
|
+
const base = store && typeof store === 'object' ? store : {}
|
|
1422
|
+
const next = { ...base }
|
|
1423
|
+
if (!anchor) return next
|
|
1424
|
+
const clean = normalizeComments(list)
|
|
1425
|
+
if (clean.length) next[anchor] = clean
|
|
1426
|
+
else delete next[anchor]
|
|
1427
|
+
return next
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* 图片内容框在**视口坐标**里的矩形(渲染 pin / 编辑气泡用)。
|
|
1432
|
+
*
|
|
1433
|
+
* 与 `commentClickPct` 共用 `contentRect`:落点与画点永远同一个矩形。
|
|
1434
|
+
* @param {object} imgEl - `.knit-lightbox-img`
|
|
1435
|
+
* @returns {{left:number,top:number,width:number,height:number}|null} 矩形
|
|
1436
|
+
*/
|
|
1437
|
+
function contentViewportOf(imgEl) {
|
|
1438
|
+
try {
|
|
1439
|
+
if (!imgEl || typeof imgEl.getBoundingClientRect !== 'function') return null
|
|
1440
|
+
const imgRect = imgEl.getBoundingClientRect()
|
|
1441
|
+
const natural = { width: imgEl.naturalWidth, height: imgEl.naturalHeight }
|
|
1442
|
+
return contentRect(imgRect, natural) || {
|
|
1443
|
+
left: imgRect.left, top: imgRect.top, width: imgRect.width, height: imgRect.height,
|
|
1444
|
+
}
|
|
1445
|
+
} catch { return null }
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* 评论编辑气泡摆哪:**贴着 pin**,但出屏就从另一侧长出来(与 Infini 分享包同一套翻边逻辑)。
|
|
1450
|
+
*
|
|
1451
|
+
* 真机上「气泡停在图片边外」就是没有这一步:只按百分比放,靠右/靠下时半截出屏。
|
|
1452
|
+
* 规则:默认在 pin 右下;右边放不下翻左,下面放不下翻上;最后再夹进视口。
|
|
1453
|
+
* **纯函数**:只吃三个盒子,不读 DOM。
|
|
1454
|
+
*
|
|
1455
|
+
* @param {{x:number,y:number}} anchor - pin 的视口坐标
|
|
1456
|
+
* @param {{width:number,height:number}} size - 气泡尺寸
|
|
1457
|
+
* @param {{width:number,height:number}} view - 视口尺寸
|
|
1458
|
+
* @param {{gap?:number,margin?:number}} [opts] - 间距与视口留白
|
|
1459
|
+
* @returns {{left:number,top:number,placement:'right'|'left',side:'below'|'above'}} 盒子
|
|
1460
|
+
*/
|
|
1461
|
+
function commentPopoverBox(anchor, size, view, opts = {}) {
|
|
1462
|
+
const gap = Number.isFinite(opts.gap) ? opts.gap : 14
|
|
1463
|
+
const margin = Number.isFinite(opts.margin) ? opts.margin : 12
|
|
1464
|
+
const viewW = view && Number.isFinite(view.width) && view.width > 0 ? view.width : 1024
|
|
1465
|
+
const viewH = view && Number.isFinite(view.height) && view.height > 0 ? view.height : 768
|
|
1466
|
+
const width = Math.max(1, Math.min(size && Number.isFinite(size.width) ? size.width : COMMENT_POP_W, viewW - margin * 2))
|
|
1467
|
+
const height = Math.max(1, Math.min(size && Number.isFinite(size.height) ? size.height : COMMENT_POP_H, viewH - margin * 2))
|
|
1468
|
+
const ax = anchor && Number.isFinite(anchor.x) ? anchor.x : viewW / 2
|
|
1469
|
+
const ay = anchor && Number.isFinite(anchor.y) ? anchor.y : viewH / 2
|
|
1470
|
+
|
|
1471
|
+
let placement = 'right'
|
|
1472
|
+
let left = ax + gap
|
|
1473
|
+
if (left + width > viewW - margin) { left = ax - width - gap; placement = 'left' }
|
|
1474
|
+
left = Math.min(Math.max(margin, left), Math.max(margin, viewW - width - margin))
|
|
1475
|
+
|
|
1476
|
+
let side = 'below'
|
|
1477
|
+
let top = ay + gap
|
|
1478
|
+
if (top + height > viewH - margin) { top = ay - height - gap; side = 'above' }
|
|
1479
|
+
top = Math.min(Math.max(margin, top), Math.max(margin, viewH - height - margin))
|
|
1480
|
+
return { left, top, placement, side }
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
/**
|
|
1484
|
+
* 一次点击落在**图片内容框**的百分比。
|
|
1485
|
+
*
|
|
1486
|
+
* ⚠️ 这里必须是 `contentRect` → `pctFromPoint` 这条链,**不能**用 stage 的宽度。
|
|
1487
|
+
* 源码守卫(test/comments.test.mjs)会检查这个函数的形状;改坏了会红。
|
|
1488
|
+
*
|
|
1489
|
+
* @param {{clientX:number,clientY:number}} event - 点击事件
|
|
1490
|
+
* @param {object} imgEl - `.knit-lightbox-img`
|
|
1491
|
+
* @returns {{xPct:number,yPct:number}|null} 百分比
|
|
1492
|
+
*/
|
|
1493
|
+
function commentClickPct(event, imgEl) {
|
|
1494
|
+
try {
|
|
1495
|
+
if (!event || !imgEl || typeof imgEl.getBoundingClientRect !== 'function') return null
|
|
1496
|
+
const imgRect = imgEl.getBoundingClientRect()
|
|
1497
|
+
const natural = { width: imgEl.naturalWidth, height: imgEl.naturalHeight }
|
|
1498
|
+
const rect = contentRect(imgRect, natural)
|
|
1499
|
+
if (!rect) return null
|
|
1500
|
+
return pctFromPoint({ x: event.clientX, y: event.clientY }, rect)
|
|
1501
|
+
} catch { return null }
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* 键盘事件是不是发生在**评论输入框**里。
|
|
1506
|
+
*
|
|
1507
|
+
* 必须在「查看器根上的捕获阶段处理器」里先判它:Escape / 方向键在输入框里
|
|
1508
|
+
* 属于「取消编辑 / 移光标」,如果照旧交给查看器,会变成「关查看器 / 翻图」。
|
|
1509
|
+
*
|
|
1510
|
+
* @param {object} event - 键盘事件
|
|
1511
|
+
* @returns {boolean} 是否在评论输入框内
|
|
1512
|
+
*/
|
|
1513
|
+
function commentEditorTarget(event) {
|
|
1514
|
+
const target = event && event.target
|
|
1515
|
+
if (!target) return false
|
|
1516
|
+
if (target.isContentEditable) return true
|
|
1517
|
+
try {
|
|
1518
|
+
if (typeof target.closest === 'function') return !!target.closest('[data-knit-comment-editor]')
|
|
1519
|
+
} catch { /* 老宿主 / 测试替身:当作不在输入框 */ }
|
|
1520
|
+
return false
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* 把评论关联的那张图读成 `File`(**同源、本机**:/knit/api/raw 或 /knit/api/attachment)。
|
|
1525
|
+
*
|
|
1526
|
+
* 为什么要附件:只发文字时,agent 只能看到文件名/rel;同名文件、被移动的文件、
|
|
1527
|
+
* 以及对话里生成的图(没有路径,只有 sha256)都可能对不上。Codex Canvas 的评论
|
|
1528
|
+
* 也是把原图随评论一起提交 —— 这里附**原图**(不带 pin),pin 的坐标已经在文本里。
|
|
1529
|
+
*
|
|
1530
|
+
* @param {string} src - 同源图片地址
|
|
1531
|
+
* @param {string} name - 附件文件名
|
|
1532
|
+
* @param {{fetch?:Function, File?:Function}} [env] - 可注入(测试用)
|
|
1533
|
+
* @returns {Promise<object|null>} File 或 null
|
|
1534
|
+
*/
|
|
1535
|
+
async function imageFileFrom(src, name, env = {}) {
|
|
1536
|
+
try {
|
|
1537
|
+
const fetchFn = env.fetch || (typeof fetch === 'function' ? fetch : null)
|
|
1538
|
+
const FileCtor = env.File || (typeof File === 'function' ? File : null)
|
|
1539
|
+
if (!fetchFn || !FileCtor || !src) return null
|
|
1540
|
+
const response = await fetchFn(src, { credentials: 'same-origin' })
|
|
1541
|
+
if (!response || response.ok === false) return null
|
|
1542
|
+
const blob = await response.blob()
|
|
1543
|
+
if (!blob || !Number(blob.size)) return null
|
|
1544
|
+
const type = blob.type || 'image/png'
|
|
1545
|
+
const fallback = type.includes('jpeg') ? 'image.jpg' : type.includes('webp') ? 'image.webp' : 'image.png'
|
|
1546
|
+
return new FileCtor([blob], name || fallback, { type })
|
|
1547
|
+
} catch { return null }
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
/**
|
|
1551
|
+
* 造一个合成 paste 事件(真浏览器用原生构造器;测试替身用同契约的普通对象)。
|
|
1552
|
+
* 事件里**同时**带 text/plain 与(可选)图片 File —— DSH 输入框的 paste 处理器
|
|
1553
|
+
* 会先 intake 文件、再插入文本(`keymap.ts` 的 PASTE_COMMAND)。
|
|
1554
|
+
* @param {string} text - 要粘贴的纯文本
|
|
1555
|
+
* @param {object|null} win - window
|
|
1556
|
+
* @param {object|null} [file] - 可选图片 File
|
|
1557
|
+
* @returns {object} 事件
|
|
1558
|
+
*/
|
|
1559
|
+
function buildPasteEvent(text, win, file) {
|
|
1560
|
+
const payload = String(text)
|
|
1561
|
+
const DT = win && win.DataTransfer
|
|
1562
|
+
const CE = win && win.ClipboardEvent
|
|
1563
|
+
if (typeof DT === 'function' && typeof CE === 'function') {
|
|
1564
|
+
try {
|
|
1565
|
+
const transfer = new DT()
|
|
1566
|
+
transfer.setData('text/plain', payload)
|
|
1567
|
+
if (file && transfer.items && typeof transfer.items.add === 'function') transfer.items.add(file)
|
|
1568
|
+
return new CE('paste', { clipboardData: transfer, bubbles: true, cancelable: true })
|
|
1569
|
+
} catch { /* 落下去用普通对象 */ }
|
|
1570
|
+
}
|
|
1571
|
+
return {
|
|
1572
|
+
type: 'paste',
|
|
1573
|
+
clipboardData: {
|
|
1574
|
+
getData: (kind) => (kind === 'text/plain' || !kind ? payload : ''),
|
|
1575
|
+
files: file ? [file] : [],
|
|
1576
|
+
items: file ? [{ kind: 'file', type: file.type || '', getAsFile: () => file }] : [],
|
|
1577
|
+
},
|
|
1578
|
+
bubbles: true,
|
|
1579
|
+
cancelable: true,
|
|
1580
|
+
defaultPrevented: false,
|
|
1581
|
+
preventDefault() { this.defaultPrevented = true },
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
/** 造一个合成 drop 事件(契约同上)。 */
|
|
1586
|
+
function buildDropEvent(text, win) {
|
|
1587
|
+
const payload = String(text)
|
|
1588
|
+
const DT = win && win.DataTransfer
|
|
1589
|
+
const DE = win && win.DragEvent
|
|
1590
|
+
if (typeof DT === 'function' && typeof DE === 'function') {
|
|
1591
|
+
try {
|
|
1592
|
+
const transfer = new DT()
|
|
1593
|
+
transfer.setData('text/plain', payload)
|
|
1594
|
+
return new DE('drop', { dataTransfer: transfer, bubbles: true, cancelable: true })
|
|
1595
|
+
} catch { /* 落下去用普通对象 */ }
|
|
1596
|
+
}
|
|
1597
|
+
return {
|
|
1598
|
+
type: 'drop',
|
|
1599
|
+
dataTransfer: { getData: (kind) => (kind === 'text/plain' || !kind ? payload : '') },
|
|
1600
|
+
bubbles: true,
|
|
1601
|
+
cancelable: true,
|
|
1602
|
+
defaultPrevented: false,
|
|
1603
|
+
preventDefault() { this.defaultPrevented = true },
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* 输入框当前状态:已附件几张图、有没有正文。**只读 DOM,不改任何东西**。
|
|
1609
|
+
*
|
|
1610
|
+
* 用途有两个:
|
|
1611
|
+
* ① 新评论的编号 = 已有附件数 + 1(「附件一就是图像一」);
|
|
1612
|
+
* ② 已经有正文时,这次投递前面要空一行(独立段落),不能拼在上一句后面。
|
|
1613
|
+
*
|
|
1614
|
+
* @param {object|null} doc - document(测试可注入)
|
|
1615
|
+
* @returns {{count:number, hasText:boolean}} 状态
|
|
1616
|
+
*/
|
|
1617
|
+
function composerState(doc) {
|
|
1618
|
+
const empty = { count: 0, hasText: false }
|
|
1619
|
+
try {
|
|
1620
|
+
if (!doc || typeof doc.querySelector !== 'function') return empty
|
|
1621
|
+
const input = doc.querySelector('[data-composer-input]')
|
|
1622
|
+
if (!input) return empty
|
|
1623
|
+
const hasText = typeof input.textContent === 'string' && input.textContent.trim() !== ''
|
|
1624
|
+
let count = 0
|
|
1625
|
+
const card = typeof input.closest === 'function' ? input.closest('[data-composer-card]') : null
|
|
1626
|
+
if (card && typeof card.querySelectorAll === 'function') {
|
|
1627
|
+
count = [...card.querySelectorAll('img')].filter((img) => {
|
|
1628
|
+
const src = String((img && img.src) || '')
|
|
1629
|
+
if (src.startsWith('blob:')) return true
|
|
1630
|
+
const parent = img && img.parentElement
|
|
1631
|
+
return /thumbnail/i.test(String((parent && parent.className) || ''))
|
|
1632
|
+
}).length
|
|
1633
|
+
}
|
|
1634
|
+
return { count, hasText }
|
|
1635
|
+
} catch { return empty }
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
/** 把光标放到输入框末尾(否则 paste 会插在当前光标处,段落会断在中间)。 */
|
|
1639
|
+
function caretToEnd(input, win, doc) {
|
|
1640
|
+
try {
|
|
1641
|
+
if (!input || !win || typeof win.getSelection !== 'function') return
|
|
1642
|
+
if (!doc || typeof doc.createRange !== 'function') return
|
|
1643
|
+
const selection = win.getSelection()
|
|
1644
|
+
if (!selection) return
|
|
1645
|
+
const range = doc.createRange()
|
|
1646
|
+
range.selectNodeContents(input)
|
|
1647
|
+
range.collapse(false)
|
|
1648
|
+
selection.removeAllRanges()
|
|
1649
|
+
selection.addRange(range)
|
|
1650
|
+
} catch { /* 拿不到 selection 就按默认光标位置投递 */ }
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* 把一段文本投进**输入框**(不发送)。通道照 dsh-image-annotate 的已验证做法:
|
|
1655
|
+
* 合成 paste 到 `[data-composer-input]`;失败按序回落 document drop → clipboard → 下载。
|
|
1656
|
+
*
|
|
1657
|
+
* ⚠️ 只借通道,不引入依赖、不 import 那个插件;零网络出口(clipboard / 下载都是本机)。
|
|
1658
|
+
*
|
|
1659
|
+
* @param {string} text - 要投递的文本
|
|
1660
|
+
* @param {{document?:object, window?:object, fetch?:Function, File?:Function, attachment?:{src:string,name?:string}}} [env] - 可注入(测试用)
|
|
1661
|
+
* @returns {Promise<{ok:boolean, via:'paste'|'drop'|'clipboard'|'download'|'none', image:boolean}>} 结果
|
|
1662
|
+
*/
|
|
1663
|
+
async function deliverCommentText(text, env = {}) {
|
|
1664
|
+
const payload = String(text === undefined || text === null ? '' : text)
|
|
1665
|
+
if (!payload) return { ok: false, via: 'none', image: false }
|
|
1666
|
+
const doc = env.document === undefined ? (typeof document === 'undefined' ? null : document) : env.document
|
|
1667
|
+
const win = env.window === undefined ? (typeof window === 'undefined' ? null : window) : env.window
|
|
1668
|
+
const file = env.attachment ? await imageFileFrom(env.attachment.src, env.attachment.name, env) : null
|
|
1669
|
+
/* 每次发送 = **独立段落**:输入框里已经有正文时,前面空两行再投;没有就原样。
|
|
1670
|
+
(只加前缀不补后缀 —— 下一次发送自己会补,避免末尾多出空行。) */
|
|
1671
|
+
const existing = (() => {
|
|
1672
|
+
try {
|
|
1673
|
+
const probe = doc && typeof doc.querySelector === 'function' ? doc.querySelector('[data-composer-input]') : null
|
|
1674
|
+
return probe && typeof probe.textContent === 'string' ? probe.textContent.trim() : ''
|
|
1675
|
+
} catch { return '' }
|
|
1676
|
+
})()
|
|
1677
|
+
const body = existing ? `\n\n${payload}` : payload
|
|
1678
|
+
|
|
1679
|
+
// ① 合成 paste 到输入框(文本 + 图片 File 同一个事件)
|
|
1680
|
+
const input = doc && typeof doc.querySelector === 'function' ? doc.querySelector('[data-composer-input]') : null
|
|
1681
|
+
if (input && typeof input.dispatchEvent === 'function') {
|
|
1682
|
+
try { if (typeof input.focus === 'function') input.focus() } catch { /* 拿不到焦点也继续 */ }
|
|
1683
|
+
try { caretToEnd(input, win, doc) } catch { /* 光标放不到末尾就按默认位置 */ }
|
|
1684
|
+
const before = typeof input.textContent === 'string' ? input.textContent : ''
|
|
1685
|
+
try {
|
|
1686
|
+
const event = buildPasteEvent(body, win, file)
|
|
1687
|
+
const notPrevented = input.dispatchEvent(event)
|
|
1688
|
+
const after = typeof input.textContent === 'string' ? input.textContent : ''
|
|
1689
|
+
/* 宿主(Lexical)收到 paste 会 `preventDefault()` ⇒ dispatchEvent 返回 false。
|
|
1690
|
+
⚠️ **不要在这里补第二次 paste**:编辑器的文本更新不保证同步,`textContent` 可能
|
|
1691
|
+
还没变,补一次就会把同一段文本/图片塞两遍(真机踩过:输入框里出现两遍)。
|
|
1692
|
+
preventDefault 返回 true 而 textContent 仍没变(极老宿主)时交给下面的 drop 回落。 */
|
|
1693
|
+
if (notPrevented === false || (event && event.defaultPrevented) || after !== before) {
|
|
1694
|
+
return { ok: true, via: 'paste', image: !!file }
|
|
1695
|
+
}
|
|
1696
|
+
} catch { /* 换下一条通道 */ }
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
// ② document 上的 drop
|
|
1700
|
+
if (doc && typeof doc.dispatchEvent === 'function') {
|
|
1701
|
+
try {
|
|
1702
|
+
const event = buildDropEvent(body, win)
|
|
1703
|
+
if (doc.dispatchEvent(event) === false || (event && event.defaultPrevented)) return { ok: true, via: 'drop', image: false }
|
|
1704
|
+
} catch { /* 换下一条通道 */ }
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// ③ 剪贴板
|
|
1708
|
+
try {
|
|
1709
|
+
const clipboard = win && win.navigator && win.navigator.clipboard
|
|
1710
|
+
if (clipboard && typeof clipboard.writeText === 'function') {
|
|
1711
|
+
await clipboard.writeText(body)
|
|
1712
|
+
return { ok: true, via: 'clipboard', image: false }
|
|
1713
|
+
}
|
|
1714
|
+
} catch { /* 换下一条通道 */ }
|
|
1715
|
+
|
|
1716
|
+
// ④ 下载一个 .txt
|
|
1717
|
+
try {
|
|
1718
|
+
const BlobCtor = win && win.Blob
|
|
1719
|
+
const UrlApi = win && win.URL
|
|
1720
|
+
if (BlobCtor && UrlApi && typeof UrlApi.createObjectURL === 'function' && doc && typeof doc.createElement === 'function') {
|
|
1721
|
+
const url = UrlApi.createObjectURL(new BlobCtor([body], { type: 'text/plain;charset=utf-8' }))
|
|
1722
|
+
const anchor = doc.createElement('a')
|
|
1723
|
+
anchor.href = url
|
|
1724
|
+
anchor.download = 'knit-comments.txt'
|
|
1725
|
+
if (typeof anchor.click === 'function') anchor.click()
|
|
1726
|
+
if (typeof UrlApi.revokeObjectURL === 'function') UrlApi.revokeObjectURL(url)
|
|
1727
|
+
return { ok: true, via: 'download', image: false }
|
|
1728
|
+
}
|
|
1729
|
+
} catch { /* 全部通道都不行 */ }
|
|
1730
|
+
|
|
1731
|
+
return { ok: false, via: 'none', image: false }
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1095
1734
|
/** 浮窗与卡片之间的间距。 */
|
|
1096
1735
|
const HOVER_SHOT_GAP = 12
|
|
1097
1736
|
/** 浮窗与视口边缘的最小留白。 */
|
|
1098
1737
|
const HOVER_SHOT_MARGIN = 12
|
|
1099
1738
|
/** 停多久才出现 —— 短了会在鼠标扫过时一路闪,长了会显得没反应。 */
|
|
1100
1739
|
const HOVER_SHOT_DELAY_MS = 350
|
|
1740
|
+
/** 从卡片挪到浮窗上要多久才收 —— 浮窗现在是**评论入口**(可点),
|
|
1741
|
+
立即收会让鼠标还没走到按钮它就消失了。 */
|
|
1742
|
+
const HOVER_SHOT_HIDE_MS = 220
|
|
1101
1743
|
|
|
1102
1744
|
/**
|
|
1103
1745
|
* 算悬停浮窗的盒子。**纯函数**:只吃两个矩形,不做任何 DOM 读。
|
|
@@ -1917,11 +2559,16 @@ button.knit-why:hover,button.knit-why:focus-visible{color:var(--dsw-alias-label-
|
|
|
1917
2559
|
⚠️ pointer-events:none 是必须的:它只是看一眼,绝不许挡住卡片的点击。
|
|
1918
2560
|
尺寸由 JS 下发(上限 800,按可用空间收缩),这里只负责「图在盒子里等比铺满」。 */
|
|
1919
2561
|
.knit-shot{position:fixed;z-index:60;display:flex;align-items:center;justify-content:center;
|
|
1920
|
-
padding:6px;border-radius:12px;pointer-events:
|
|
2562
|
+
padding:6px;border-radius:12px;pointer-events:auto;cursor:pointer;
|
|
1921
2563
|
background:var(--dsw-alias-bg-layer-2,#2c2c2e);
|
|
1922
2564
|
border:.5px solid var(--dsw-alias-border-l4,rgba(255,255,255,.12));
|
|
1923
2565
|
box-shadow:0 12px 32px rgba(0,0,0,.32)}
|
|
1924
2566
|
.knit-shot img{display:block;max-width:100%;max-height:100%;border-radius:8px;object-fit:contain}
|
|
2567
|
+
.knit-shot-hint{position:absolute;left:50%;bottom:12px;transform:translateX(-50%);
|
|
2568
|
+
padding:4px 12px;border-radius:999px;font-size:12px;line-height:1.4;white-space:nowrap;
|
|
2569
|
+
color:var(--dsw-alias-label-primary-inverted);
|
|
2570
|
+
background:var(--dsw-alias-brand-primary-new-colorprimary-new-color)}
|
|
2571
|
+
.knit-shot:hover .knit-shot-hint{opacity:1}
|
|
1925
2572
|
/* v0.25 媒体档「双击全屏」:整窗遮罩 + 毛玻璃。层级在悬停浮窗(60)与菜单之上。
|
|
1926
2573
|
左侧留 96px 给缩略图带(它绝对定位在遮罩里);图片按 contain 铺满剩下的区域。 */
|
|
1927
2574
|
.knit-lightbox{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;
|
|
@@ -1931,20 +2578,23 @@ button.knit-why:hover,button.knit-why:focus-visible{color:var(--dsw-alias-label-
|
|
|
1931
2578
|
⚠️ 这两个变量故意**挂在查看器自己身上** —— 它被 portal 到 document.body 之后
|
|
1932
2579
|
不在 .knit-root 里了,读不到那层的变量(第一版就是这么静默变成透明遮罩的)。 */
|
|
1933
2580
|
--knit-scrim:rgba(255,255,255,.62);
|
|
2581
|
+
/* 评论栏底:面板画布能吃到 .knit-root 的 --knit-active-bg;整屏 portal 里读不到,
|
|
2582
|
+
就回落到官方交互令牌。浅色下两者都是可见的灰,不会和纯白画布糊在一起。 */
|
|
2583
|
+
--knit-comment-surface:var(--knit-active-bg,var(--dsw-alias-interactive-bg-active));
|
|
1934
2584
|
background:var(--knit-scrim);backdrop-filter:blur(22px) saturate(1.1);
|
|
1935
2585
|
-webkit-backdrop-filter:blur(22px) saturate(1.1)}
|
|
1936
2586
|
body[data-ds-dark-theme] .knit-lightbox{--knit-scrim:rgba(18,18,20,.72)}
|
|
1937
2587
|
.knit-lightbox-stage{flex:1 1 auto;min-width:0;min-height:0;display:flex;align-items:center;
|
|
1938
|
-
justify-content:center;cursor:default}
|
|
2588
|
+
justify-content:center;cursor:default;position:relative}
|
|
1939
2589
|
.knit-lightbox-img{max-width:100%;max-height:100%;object-fit:contain;border-radius:10px;cursor:default;
|
|
1940
2590
|
box-shadow:0 24px 64px rgba(0,0,0,.36);background:var(--dsw-alias-bg-base,#fff)}
|
|
1941
|
-
.knit-lightbox-tools{position:absolute;top:18px;right:62px;display:flex;align-items:center;gap:6px}
|
|
1942
|
-
.knit-lightbox-close{position:absolute;top:18px;right:18px;width:34px;height:34px;padding:0;
|
|
2591
|
+
.knit-lightbox-tools{position:absolute;top:18px;right:62px;z-index:2;display:flex;align-items:center;gap:6px}
|
|
2592
|
+
.knit-lightbox-close{position:absolute;top:18px;right:18px;z-index:2;width:34px;height:34px;padding:0;
|
|
1943
2593
|
display:flex;align-items:center;justify-content:center;border:0;border-radius:10px;
|
|
1944
2594
|
cursor:pointer;font-family:inherit;font-size:15px;line-height:1;
|
|
1945
2595
|
color:var(--dsw-alias-label-primary,#0f1115);background:transparent;opacity:.7}
|
|
1946
2596
|
.knit-lightbox-close:hover{opacity:1;background:var(--knit-hover-bg,transparent)}
|
|
1947
|
-
.knit-lightbox-rail{position:absolute;left:10px;top:50%;transform:translateY(-50%);display:flex;
|
|
2597
|
+
.knit-lightbox-rail{position:absolute;left:10px;top:50%;z-index:2;transform:translateY(-50%);display:flex;
|
|
1948
2598
|
flex-direction:column;gap:6px;max-height:88vh;overflow-y:auto;padding:4px;cursor:default}
|
|
1949
2599
|
.knit-lightbox-thumb{flex:none;width:64px;height:64px;padding:0;border:0;border-radius:8px;overflow:hidden;
|
|
1950
2600
|
cursor:pointer;background:transparent;opacity:.68;transition:opacity .16s ease}
|
|
@@ -1953,6 +2603,89 @@ body[data-ds-dark-theme] .knit-lightbox{--knit-scrim:rgba(18,18,20,.72)}
|
|
|
1953
2603
|
.knit-lightbox-thumb.active{opacity:1;box-shadow:0 0 0 2px var(--knit-accent,var(--dsw-alias-brand-primary-new-colorprimary-new-color))}
|
|
1954
2604
|
@media (prefers-reduced-motion: reduce){.knit-lightbox-thumb{transition:none}}
|
|
1955
2605
|
|
|
2606
|
+
/* ── v0.26 图内评论 ───────────────────────────────────────────
|
|
2607
|
+
pin = 圆点 + 序号(用户 2026-11 选的最轻形态,不做引线标注块)。
|
|
2608
|
+
⚠️ 颜色一律吃 DSH 语义 token(查看器被 portal 到 body,读不到 .knit-root 那层变量);
|
|
2609
|
+
**这里一个硬编码色值都不许出现**,源码守卫 test/comments.test.mjs 会逐条扫本段。
|
|
2610
|
+
⚠️ pin 层 pointer-events:none,只有 pin 与编辑框恢复 auto ——
|
|
2611
|
+
否则整块覆盖层会吃掉「点图片以外关闭」与 stage 的落点点击。 */
|
|
2612
|
+
.knit-lightbox-pins{position:absolute;inset:0;pointer-events:none;z-index:1}
|
|
2613
|
+
.knit-lightbox-pin{position:absolute;transform:translate(-50%,-50%);width:22px;height:22px;padding:0;
|
|
2614
|
+
display:flex;align-items:center;justify-content:center;border:0;border-radius:50%;
|
|
2615
|
+
cursor:pointer;pointer-events:auto;font-family:inherit;font-size:11px;font-weight:600;line-height:1;
|
|
2616
|
+
color:var(--dsw-alias-label-primary-inverted);
|
|
2617
|
+
background:var(--dsw-alias-brand-primary-new-colorprimary-new-color);
|
|
2618
|
+
box-shadow:0 0 0 2px var(--dsw-alias-bg-base)}
|
|
2619
|
+
.knit-lightbox-pin:hover{opacity:.86}
|
|
2620
|
+
.knit-lightbox-pin.draft{opacity:.55;pointer-events:none}
|
|
2621
|
+
.knit-lightbox-pin:focus-visible{outline:2px solid var(--dsw-alias-border-l4);outline-offset:2px}
|
|
2622
|
+
.knit-lightbox-editor{position:absolute;pointer-events:auto;box-sizing:border-box;
|
|
2623
|
+
display:flex;flex-direction:column;gap:7px;width:280px;max-width:calc(100vw - 24px);padding:9px;
|
|
2624
|
+
border-radius:10px;background:var(--dsw-alias-bg-layer-2);
|
|
2625
|
+
border:.5px solid var(--dsw-alias-border-l3);color:var(--dsw-alias-label-primary)}
|
|
2626
|
+
.knit-lightbox-editor-head{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
2627
|
+
.knit-lightbox-editor-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
2628
|
+
.knit-lightbox-editor-pos{font-size:11px;color:var(--dsw-alias-label-caption);white-space:nowrap}
|
|
2629
|
+
.knit-lightbox-editor-input{width:100%;box-sizing:border-box;padding:6px 8px;border-radius:8px;
|
|
2630
|
+
border:.5px solid var(--dsw-alias-border-l4);background:var(--dsw-alias-bg-base);
|
|
2631
|
+
color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;line-height:1.5;outline:none}
|
|
2632
|
+
.knit-lightbox-editor-input:focus{border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color)}
|
|
2633
|
+
.knit-lightbox-editor-foot{display:flex;align-items:center;justify-content:flex-end;gap:6px}
|
|
2634
|
+
.knit-lightbox-editor-count{margin-right:auto;font-size:11px;color:var(--dsw-alias-label-caption)}
|
|
2635
|
+
.knit-lightbox-editor-hint{font-size:11px;color:var(--dsw-alias-label-caption);line-height:1.4}
|
|
2636
|
+
.knit-lightbox-comments{position:fixed;left:50%;bottom:18px;z-index:2;transform:translateX(-50%);box-sizing:border-box;
|
|
2637
|
+
width:min(560px,calc(100vw - 160px));display:flex;align-items:flex-end;gap:12px;padding:10px 12px;
|
|
2638
|
+
min-height:54px;border-radius:12px;background:var(--knit-comment-surface);
|
|
2639
|
+
border:.5px solid var(--dsw-alias-border-l4);
|
|
2640
|
+
box-shadow:0 10px 28px var(--dsw-alias-interactive-bg-hover);
|
|
2641
|
+
color:var(--dsw-alias-label-primary);cursor:default}
|
|
2642
|
+
.knit-lightbox-comments-empty{display:flex;flex-direction:column;gap:2px;padding:2px 0}
|
|
2643
|
+
.knit-lightbox-comments-emptyTitle{font-size:12px;color:var(--dsw-alias-label-secondary)}
|
|
2644
|
+
.knit-lightbox-comments-emptyHint{font-size:11px;color:var(--dsw-alias-label-caption)}
|
|
2645
|
+
.knit-lightbox-comments-send{height:30px;padding:0 16px;font-weight:600;
|
|
2646
|
+
color:var(--dsw-alias-label-primary-inverted);
|
|
2647
|
+
background:var(--dsw-alias-brand-primary-new-colorprimary-new-color);
|
|
2648
|
+
border-color:transparent}
|
|
2649
|
+
.knit-lightbox-comments-send:disabled{color:var(--dsw-alias-label-caption);
|
|
2650
|
+
background:var(--dsw-alias-interactive-bg-active);border-color:var(--dsw-alias-border-l4)}
|
|
2651
|
+
.knit-lightbox-nav{width:30px;height:30px;padding:0;font-size:16px;line-height:1}
|
|
2652
|
+
.knit-lightbox-dockcount{margin-left:auto;font-size:11px;color:var(--dsw-alias-label-caption);white-space:nowrap}
|
|
2653
|
+
.knit-lightbox-comments-list{flex:1 1 auto;min-width:0;display:flex;flex-direction:column;gap:3px;
|
|
2654
|
+
max-height:30vh;overflow-y:auto}
|
|
2655
|
+
.knit-lightbox-comment-row{display:flex;align-items:center;gap:8px;min-width:0}
|
|
2656
|
+
.knit-lightbox-comment-n{flex:none;font-size:11px;font-weight:600;
|
|
2657
|
+
color:var(--dsw-alias-brand-primary-new-colorprimary-new-color)}
|
|
2658
|
+
.knit-lightbox-comment-text{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;
|
|
2659
|
+
white-space:nowrap;font-size:12px;color:var(--dsw-alias-label-secondary);cursor:pointer;
|
|
2660
|
+
background:transparent;border:0;padding:0;text-align:left;font-family:inherit}
|
|
2661
|
+
.knit-lightbox-comment-text:hover{color:var(--dsw-alias-label-primary)}
|
|
2662
|
+
.knit-lightbox-comment-del{flex:none;width:20px;height:20px;padding:0;border:0;border-radius:6px;
|
|
2663
|
+
background:transparent;color:var(--dsw-alias-label-caption);cursor:pointer;font-family:inherit;
|
|
2664
|
+
font-size:11px;line-height:1}
|
|
2665
|
+
.knit-lightbox-comment-del:hover{background:var(--dsw-alias-interactive-bg-hover);
|
|
2666
|
+
color:var(--dsw-alias-label-primary)}
|
|
2667
|
+
.knit-lightbox-comments-right{flex:none;display:flex;flex-direction:column;align-items:flex-end;gap:4px}
|
|
2668
|
+
.knit-lightbox-comments-status{font-size:11px;color:var(--dsw-alias-label-caption);text-align:right}
|
|
2669
|
+
.knit-lightbox-comments-empty{font-size:12px;color:var(--dsw-alias-label-caption)}
|
|
2670
|
+
/* v0.26 返工:面板内画布(lightboxDock)—— 与整屏查看器共用同一份 DOM,
|
|
2671
|
+
只把「定位 / 底色 / 左右留白 / 评论栏位置」换掉,评论逻辑一行不分叉。
|
|
2672
|
+
⚠️ 会话永远不被盖住:它只是面板里的一个视图,且面板本身就在会话旁边。 */
|
|
2673
|
+
.knit-canvas{flex:1 1 auto;min-height:0;position:relative;display:flex;
|
|
2674
|
+
margin:6px 8px 8px;border-radius:12px;overflow:hidden;
|
|
2675
|
+
background:var(--dsw-alias-bg-base);border:.5px solid var(--dsw-alias-border-l3)}
|
|
2676
|
+
.knit-lightbox.docked{position:relative;inset:auto;z-index:auto;width:100%;height:100%;
|
|
2677
|
+
padding:8px;display:flex;align-items:stretch;justify-content:center;cursor:default;
|
|
2678
|
+
background:transparent;backdrop-filter:none;-webkit-backdrop-filter:none;border-radius:0}
|
|
2679
|
+
.knit-lightbox.docked .knit-lightbox-tools{top:10px;right:10px;z-index:3}
|
|
2680
|
+
.knit-lightbox.docked .knit-lightbox-comments{position:absolute;left:10px;right:10px;bottom:10px;
|
|
2681
|
+
width:auto;transform:none;max-height:44%}
|
|
2682
|
+
.knit-lightbox-dockhead{position:absolute;left:12px;top:10px;right:280px;z-index:2;
|
|
2683
|
+
display:flex;align-items:baseline;gap:8px;min-width:0;pointer-events:none}
|
|
2684
|
+
.knit-lightbox-dockname{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary);
|
|
2685
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2686
|
+
.knit-lightbox-dockctx{flex:none;font-size:11px;color:var(--dsw-alias-label-caption);
|
|
2687
|
+
max-width:45%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:left}
|
|
2688
|
+
|
|
1956
2689
|
/* ── 列表下方的预览面板 ───────────────────────────────
|
|
1957
2690
|
要让人一眼看出「这是另一层,不是列表的续行」,靠**结构**而不是底色:
|
|
1958
2691
|
① 顶部圆角 + 更强的上边界;② 一层向上的柔影。
|
|
@@ -2020,6 +2753,47 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
|
|
|
2020
2753
|
刻意**不是**一个胶囊:没有底色、没有边框、没有圆角 —— 它是一条弱注释,
|
|
2021
2754
|
不是标签墙。字号比标题小两档,颜色用 caption,永远不抢标题。
|
|
2022
2755
|
窄侧边栏里它 flex:none,压缩的是标题(.knit-title 会省略号收尾)而不是它。 */
|
|
2756
|
+
.knit-change-badge{margin-left:6px;flex:none;font-size:10px;line-height:16px;padding:0 5px;
|
|
2757
|
+
border-radius:4px;background:var(--knit-chip-bg);color:var(--dsw-alias-label-secondary)}
|
|
2758
|
+
.knit-change-count{display:inline-flex;gap:4px;flex:none;margin-left:6px;font-size:11px;
|
|
2759
|
+
font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-caption)}
|
|
2760
|
+
.knit-change-add{color:var(--dsw-alias-state-success-primary)}
|
|
2761
|
+
.knit-change-del{color:var(--dsw-alias-label-error)}
|
|
2762
|
+
.knit-change-binary{color:var(--dsw-alias-label-caption)}
|
|
2763
|
+
/* v0.26.x 变更档:逐行 diff(只画内容行,不接语法高亮 / 折叠 / 编辑器) */
|
|
2764
|
+
.knit-diff{display:flex;flex-direction:column;gap:8px;min-height:100%;overflow-x:auto}
|
|
2765
|
+
.knit-diff-sum{display:flex;align-items:baseline;gap:8px;flex-wrap:wrap;font-size:11px;
|
|
2766
|
+
color:var(--dsw-alias-label-caption);position:sticky;top:0;z-index:1;padding:2px 0;
|
|
2767
|
+
background:var(--dsw-alias-bg-base)}
|
|
2768
|
+
.knit-diff-file{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
2769
|
+
color:var(--dsw-alias-label-secondary)}
|
|
2770
|
+
.knit-diff-add{color:var(--dsw-alias-state-success-primary);font-variant-numeric:tabular-nums}
|
|
2771
|
+
.knit-diff-del{color:var(--dsw-alias-label-error);font-variant-numeric:tabular-nums}
|
|
2772
|
+
.knit-diff-note{color:var(--dsw-alias-label-caption)}
|
|
2773
|
+
.knit-diff-body{display:flex;flex-direction:column;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
2774
|
+
font-size:11.5px;line-height:1.7;min-width:max-content;border-radius:6px;overflow:hidden}
|
|
2775
|
+
/* 行底:用**语义色 + 低透明度覆盖层**,不写死 rgba、也不用 color-mix(AGENTS §6.3)。
|
|
2776
|
+
绿 / 红只表达 diff 的增删,不表达好坏;正文仍在最上层。 */
|
|
2777
|
+
.knit-diff-line{position:relative;display:flex;align-items:baseline;gap:8px;white-space:pre;
|
|
2778
|
+
padding:0 8px 0 4px;border-left:2px solid transparent}
|
|
2779
|
+
.knit-diff-line.add,.knit-diff-line.del{background:var(--knit-hover-bg,var(--dsw-alias-interactive-bg-hover))}
|
|
2780
|
+
.knit-diff-line.add{border-left-color:var(--dsw-alias-state-success-primary)}
|
|
2781
|
+
.knit-diff-line.del{border-left-color:var(--dsw-alias-label-error)}
|
|
2782
|
+
.knit-diff-line.add::before,.knit-diff-line.del::before{content:'';position:absolute;inset:0;
|
|
2783
|
+
pointer-events:none;z-index:0}
|
|
2784
|
+
.knit-diff-line.add::before{background:var(--dsw-alias-state-success-primary);opacity:.13}
|
|
2785
|
+
.knit-diff-line.del::before{background:var(--dsw-alias-label-error);opacity:.11}
|
|
2786
|
+
.knit-diff-line > *{position:relative;z-index:1}
|
|
2787
|
+
.knit-diff-line.hunk{color:var(--dsw-alias-label-caption);background:transparent;
|
|
2788
|
+
border-left-color:transparent;margin-top:6px;padding-top:2px;padding-bottom:2px}
|
|
2789
|
+
.knit-diff-old,.knit-diff-new{flex:none;width:40px;text-align:right;color:var(--dsw-alias-label-caption);
|
|
2790
|
+
font-variant-numeric:tabular-nums;user-select:none;font-size:11px}
|
|
2791
|
+
.knit-diff-line.add .knit-diff-old,.knit-diff-line.add .knit-diff-new{color:var(--dsw-alias-state-success-primary)}
|
|
2792
|
+
.knit-diff-line.del .knit-diff-old,.knit-diff-line.del .knit-diff-new{color:var(--dsw-alias-label-error)}
|
|
2793
|
+
.knit-diff-sign{flex:none;width:12px;text-align:center;color:var(--dsw-alias-label-secondary);font-weight:600}
|
|
2794
|
+
.knit-diff-line.add .knit-diff-sign{color:var(--dsw-alias-state-success-primary)}
|
|
2795
|
+
.knit-diff-line.del .knit-diff-sign{color:var(--dsw-alias-label-error)}
|
|
2796
|
+
.knit-diff-text{flex:none;min-width:0;color:var(--dsw-alias-label-primary)}
|
|
2023
2797
|
.knit-lang{flex:none;margin-left:6px;font-size:10px;letter-spacing:.04em;
|
|
2024
2798
|
text-transform:uppercase;color:var(--dsw-alias-label-caption,#80868b)}
|
|
2025
2799
|
|
|
@@ -2257,7 +3031,16 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2257
3031
|
*/
|
|
2258
3032
|
function ensureStyle() {
|
|
2259
3033
|
if (typeof document === 'undefined') return
|
|
2260
|
-
|
|
3034
|
+
const existing = document.getElementById(STYLE_ID)
|
|
3035
|
+
if (existing) {
|
|
3036
|
+
/* ⚠️ **必须比对内容,不能「有就跳过」**:客户端插件热换(HMR)只替换 JS 模块、
|
|
3037
|
+
不重载页面,`<style>` 元素会留在 DOM 里 —— 旧版那行 `if (existing) return`
|
|
3038
|
+
于是让新加的规则一条都不生效:新 DOM 按旧 CSS 排版,评论编辑框/评论栏被当成
|
|
3039
|
+
普通 flex 子项挤到图片右边(真机就是这么看到「停在边上」的)。
|
|
3040
|
+
现在内容不一致就整段换掉,下一次渲染立刻追上当前代码。 */
|
|
3041
|
+
if (existing.textContent !== CSS) existing.textContent = CSS
|
|
3042
|
+
return
|
|
3043
|
+
}
|
|
2261
3044
|
const el = document.createElement('style')
|
|
2262
3045
|
el.id = STYLE_ID
|
|
2263
3046
|
el.textContent = CSS
|
|
@@ -2302,11 +3085,11 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2302
3085
|
*
|
|
2303
3086
|
* v0.23.1:「全部」档已整体删除 ⇒ 白名单里的 `'all'` 也删掉 ——
|
|
2304
3087
|
* 老用户 localStorage 里存着 `'all'` 时**回落到 `文档`**(不空白、不抛)。
|
|
2305
|
-
* @returns {'doc'|'code'|'media'} 类型
|
|
3088
|
+
* @returns {'doc'|'code'|'media'|'changes'} 类型
|
|
2306
3089
|
*/
|
|
2307
3090
|
function readKindPref() {
|
|
2308
3091
|
const v = readPref(KIND_KEY)
|
|
2309
|
-
return v === KIND_MEDIA || v === KIND_CODE ? v : KIND_DOC
|
|
3092
|
+
return v === KIND_MEDIA || v === KIND_CODE || v === KIND_CHANGES ? v : KIND_DOC
|
|
2310
3093
|
}
|
|
2311
3094
|
|
|
2312
3095
|
/**
|
|
@@ -2654,6 +3437,65 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
2654
3437
|
}))
|
|
2655
3438
|
}
|
|
2656
3439
|
|
|
3440
|
+
/**
|
|
3441
|
+
* 一个变更条目 → 状态词(只给一枚主徽标,`kinds` 的完整集合仍随行带出)。
|
|
3442
|
+
* @param {string[]} kinds - `git status` 的 kinds
|
|
3443
|
+
* @returns {string} modified|added|deleted|renamed|untracked|unmerged|copied
|
|
3444
|
+
*/
|
|
3445
|
+
function changeStatusOfFile(kinds) {
|
|
3446
|
+
const list = Array.isArray(kinds) ? kinds : []
|
|
3447
|
+
if (list.includes('unmerged')) return 'unmerged'
|
|
3448
|
+
if (list.includes('untracked')) return 'untracked'
|
|
3449
|
+
if (list.includes('deleted')) return 'deleted'
|
|
3450
|
+
if (list.includes('renamed')) return 'renamed'
|
|
3451
|
+
if (list.includes('added')) return 'added'
|
|
3452
|
+
if (list.includes('copied')) return 'copied'
|
|
3453
|
+
return 'modified'
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
/**
|
|
3457
|
+
* `/knit/api/status` 的 `git.files` → 列表行(只做形状映射;只收 Markdown / 代码)。
|
|
3458
|
+
*
|
|
3459
|
+
* 变更档的列表行**就是**既有 `DocRow`:点开走同一条预览路径,不新开第二套渲染。
|
|
3460
|
+
* 额外的 `change` 字段只负责状态徽标与 `+N −N`,不影响键盘 / 预览。
|
|
3461
|
+
*
|
|
3462
|
+
* @param {object|null} data - `/knit/api/status` 的载荷
|
|
3463
|
+
* @returns {Array<object>} 行(`rel/title/name/summary/kind/mtimeMs/change`)
|
|
3464
|
+
*/
|
|
3465
|
+
function changeDocsOf(data) {
|
|
3466
|
+
const files = data && data.git && Array.isArray(data.git.files) ? data.git.files : []
|
|
3467
|
+
const out = []
|
|
3468
|
+
for (const file of files) {
|
|
3469
|
+
if (!file || file.isDir === true) continue
|
|
3470
|
+
const kind = file.kind
|
|
3471
|
+
if (kind !== ARTIFACT_DOC && kind !== ARTIFACT_CODE) continue
|
|
3472
|
+
const rel = String(file.rel || '')
|
|
3473
|
+
if (!rel) continue
|
|
3474
|
+
const parts = rel.split('/')
|
|
3475
|
+
const name = parts[parts.length - 1]
|
|
3476
|
+
const dir = parts.slice(0, -1).join('/')
|
|
3477
|
+
out.push({
|
|
3478
|
+
rel,
|
|
3479
|
+
title: name,
|
|
3480
|
+
name,
|
|
3481
|
+
summary: dir ? `${dir}/` : '',
|
|
3482
|
+
kind,
|
|
3483
|
+
mtimeMs: Number.isFinite(file.mtimeMs) ? file.mtimeMs : 0,
|
|
3484
|
+
size: Number.isFinite(file.bytes) ? file.bytes : 0,
|
|
3485
|
+
change: {
|
|
3486
|
+
status: changeStatusOfFile(file.kinds),
|
|
3487
|
+
added: Number.isFinite(file.added) ? file.added : null,
|
|
3488
|
+
removed: Number.isFinite(file.removed) ? file.removed : null,
|
|
3489
|
+
binary: file.binary === true,
|
|
3490
|
+
untracked: file.untracked === true,
|
|
3491
|
+
deleted: file.deleted === true,
|
|
3492
|
+
...(file.origRel ? { origRel: file.origRel } : {}),
|
|
3493
|
+
},
|
|
3494
|
+
})
|
|
3495
|
+
}
|
|
3496
|
+
return out
|
|
3497
|
+
}
|
|
3498
|
+
|
|
2657
3499
|
/**
|
|
2658
3500
|
* 一个条目符不符合过滤框里的那串字(标题 / 摘要 / 相对路径)。
|
|
2659
3501
|
*
|
|
@@ -3174,7 +4016,9 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3174
4016
|
// 全部是**可选** props:平铺列表(时间序 / 过滤结果)一个都不传,那一屏与 v0.20
|
|
3175
4017
|
// 逐字相同。`onAct` 为 null ⇒ 不渲染动作按钮;`relations` 为空 ⇒ 「为什么」退回
|
|
3176
4018
|
// 纯文本(没有证据就不装成有证据的样子)。
|
|
3177
|
-
prov, pinned, onAct, relations, relationsTotal, whyOpen, onWhyToggle, onOpenRelation
|
|
4019
|
+
prov, pinned, onAct, relations, relationsTotal, whyOpen, onWhyToggle, onOpenRelation,
|
|
4020
|
+
// v0.26.x 变更档:一个可选的 `change` 只负责「状态徽标 + +N −N」,其余路径不变。
|
|
4021
|
+
change }) {
|
|
3178
4022
|
const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
|
|
3179
4023
|
const rowRef = React.useRef(null)
|
|
3180
4024
|
/* v0.19:只有**代码行**带语言徽章。
|
|
@@ -3293,6 +4137,14 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3293
4137
|
fresh ? h('span', { className: 'knit-badge' }, '🆕') : null,
|
|
3294
4138
|
doc.title || doc.name,
|
|
3295
4139
|
lang ? h('span', { className: 'knit-lang' }, lang) : null),
|
|
4140
|
+
change
|
|
4141
|
+
? h('span', { className: 'knit-change-badge' }, t(`changes.status.${change.status}`))
|
|
4142
|
+
: null,
|
|
4143
|
+
change && !change.binary && (Number.isFinite(change.added) || Number.isFinite(change.removed))
|
|
4144
|
+
? h('span', { className: 'knit-change-count' },
|
|
4145
|
+
Number.isFinite(change.added) ? h('span', { className: 'knit-change-add' }, `+${change.added}`) : null,
|
|
4146
|
+
Number.isFinite(change.removed) ? h('span', { className: 'knit-change-del' }, `−${change.removed}`) : null)
|
|
4147
|
+
: (change && change.binary ? h('span', { className: 'knit-change-count knit-change-binary' }, t('changes.binary')) : null),
|
|
3296
4148
|
// v0.17:生命周期状态(文案已算好;没有证据时是 null,一个节点都不加)。
|
|
3297
4149
|
// 插在**标题与时间之间**:`.knit-title` 是 flex:1 1 auto,会把状态与时间一起推到
|
|
3298
4150
|
// 行尾,状态在时间左侧、行尾仍然是时间。
|
|
@@ -3309,7 +4161,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
3309
4161
|
h('div', { className: 'knit-time' }, relTime(doc.mtimeMs, now))),
|
|
3310
4162
|
doc.summary
|
|
3311
4163
|
? h('div', { className: 'knit-sum' }, doc.summary)
|
|
3312
|
-
: h('div', { className: 'knit-sum empty' }, t('summary.empty')),
|
|
4164
|
+
: (change ? null : h('div', { className: 'knit-sum empty' }, t('summary.empty'))),
|
|
3313
4165
|
// ⚠️ **列表行里不再有路径**(2026-09-29 用户要求):「文档列表中的文档路径,我觉得
|
|
3314
4166
|
// 不需要出现了,因为点开查看文档详情的时候已经有了,所以这里是重复的,隐藏掉」。
|
|
3315
4167
|
// —— 这是**重复信息**,不是「多列砍字段」那种静默降级:预览头
|
|
@@ -4240,6 +5092,34 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4240
5092
|
* `find`(v0.25)= 查找条那一组:状态在 `KnitBody`(快捷键挂在面板根上,
|
|
4241
5093
|
* 所以状态不能只活在这一层);`bodyRef` = 正文容器 ref,由 `KnitBody` 拿去做 DOM 命中绘制。
|
|
4242
5094
|
*/
|
|
5095
|
+
/**
|
|
5096
|
+
* 逐行 diff 视图(「变更」档点开一行)。只画宿主解析好的内容行:
|
|
5097
|
+
* 旧行号 / 新行号 / +/- / 文本;不加语法高亮、不做折叠(不是编辑器)。
|
|
5098
|
+
* @param {{diff: object}} props - `/knit/api/diff` 的载荷
|
|
5099
|
+
* @returns {import('react').ReactElement} 元素
|
|
5100
|
+
*/
|
|
5101
|
+
function DiffPane({ diff }) {
|
|
5102
|
+
const lines = Array.isArray(diff.lines) ? diff.lines : []
|
|
5103
|
+
const rows = lines.map((line, i) => h('div', {
|
|
5104
|
+
key: `${i}-${line.type}`,
|
|
5105
|
+
className: `knit-diff-line ${line.type}`,
|
|
5106
|
+
},
|
|
5107
|
+
h('span', { className: 'knit-diff-old' }, line.oldNo == null ? '' : String(line.oldNo)),
|
|
5108
|
+
h('span', { className: 'knit-diff-new' }, line.newNo == null ? '' : String(line.newNo)),
|
|
5109
|
+
h('span', { className: 'knit-diff-sign' }, line.type === 'add' ? '+' : line.type === 'del' ? '−' : ' '),
|
|
5110
|
+
h('span', { className: 'knit-diff-text' }, line.text === '' ? ' ' : line.text)))
|
|
5111
|
+
const head = h('div', { className: 'knit-diff-sum' },
|
|
5112
|
+
h('span', { className: 'knit-diff-file' }, diff.rel || ''),
|
|
5113
|
+
h('span', { className: 'knit-diff-add' }, `+${Number(diff.added) || 0}`),
|
|
5114
|
+
h('span', { className: 'knit-diff-del' }, `−${Number(diff.removed) || 0}`),
|
|
5115
|
+
diff.binary ? h('span', { className: 'knit-diff-note' }, t('changes.binary')) : null,
|
|
5116
|
+
diff.truncated ? h('span', { className: 'knit-diff-note' }, t('diff.truncated')) : null)
|
|
5117
|
+
const body = diff.binary
|
|
5118
|
+
? h('div', { className: 'knit-preview-note' }, t('diff.binary'))
|
|
5119
|
+
: h('div', { className: 'knit-diff-body' }, rows)
|
|
5120
|
+
return h('div', { className: 'knit-diff' }, head, body)
|
|
5121
|
+
}
|
|
5122
|
+
|
|
4243
5123
|
function PreviewPanel({ preview, pathImages, fullscreen, ratio, links, linksExpanded, onToggleLinks, onOpenLink, onClose, onOpenLocal, onReveal, onOpenMap, onOpenWeb, onToggleFullscreen, onResizeStart, find, bodyRef, favorite, onToggleFavorite }) {
|
|
4244
5124
|
const isMedia = preview.kind === 'image' || preview.kind === 'video'
|
|
4245
5125
|
const previewPath = splitRelPath(preview.rel)
|
|
@@ -4396,7 +5276,13 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4396
5276
|
// v0.19:代码(含 `.map` 这类生成产物)走轻量 CodePane —— **绝不能落到
|
|
4397
5277
|
// MarkdownText 那支**,否则 `#` 开头的注释会变成标题、`*` 会变成列表。
|
|
4398
5278
|
const isCode = preview.kind === ARTIFACT_CODE || preview.kind === KIND_GENERATED
|
|
4399
|
-
const body = preview.
|
|
5279
|
+
const body = preview.diff
|
|
5280
|
+
? (preview.diff.loading
|
|
5281
|
+
? h('div', { className: 'knit-preview-note' }, t('diff.loading'))
|
|
5282
|
+
: preview.diff.error
|
|
5283
|
+
? h('div', { className: 'knit-preview-note' }, t('diff.failed'))
|
|
5284
|
+
: h(DiffPane, { diff: preview.diff }))
|
|
5285
|
+
: preview.status === 'loading'
|
|
4400
5286
|
? h('div', { className: 'knit-preview-note' }, t('preview.loading'))
|
|
4401
5287
|
: preview.status === 'error'
|
|
4402
5288
|
? h('div', { className: 'knit-preview-note' }, t('list.failed', { error: preview.error }))
|
|
@@ -4480,7 +5366,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4480
5366
|
: null,
|
|
4481
5367
|
h('span', { className: 'knit-preview-name' }, previewPath.name)),
|
|
4482
5368
|
// 复制整篇(只给代码;MarkdownText 自己带代码块复制)
|
|
4483
|
-
isCodeView
|
|
5369
|
+
isCodeView && !preview.diff
|
|
4484
5370
|
? h('button', {
|
|
4485
5371
|
className: 'knit-btn',
|
|
4486
5372
|
onClick: onCopySource,
|
|
@@ -4489,7 +5375,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4489
5375
|
: null,
|
|
4490
5376
|
// Source map:**低权重**入口 —— 只在同名 `<file>.map` 真的存在时出现,
|
|
4491
5377
|
// 且 `.map` 本身不参与检索(需求 §6 §28)。点开仍是这个面板,纯文本。
|
|
4492
|
-
isCodeView && preview.mapRel
|
|
5378
|
+
isCodeView && !preview.diff && preview.mapRel
|
|
4493
5379
|
? h('button', {
|
|
4494
5380
|
className: 'knit-btn knit-btn-quiet',
|
|
4495
5381
|
onClick: () => { if (onOpenMap) onOpenMap(preview.mapRel) },
|
|
@@ -4741,7 +5627,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4741
5627
|
|
|
4742
5628
|
⇒ 请求**就是 time**(不只改显示):这样宿主不做无用的相关度计算、截断也按时间切。
|
|
4743
5629
|
排序偏好本身**不做修改** —— 切回文档/代码还是你原来选的那个。 */
|
|
4744
|
-
const effectiveSort = kind === KIND_MEDIA ? 'time' : sort
|
|
5630
|
+
const effectiveSort = kind === KIND_MEDIA || kind === KIND_CHANGES ? 'time' : sort
|
|
4745
5631
|
|
|
4746
5632
|
const load = React.useCallback(async (alive) => {
|
|
4747
5633
|
const live = () => typeof alive !== 'function' || alive()
|
|
@@ -4767,6 +5653,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4767
5653
|
const sig = JSON.stringify(data)
|
|
4768
5654
|
setState((prev) => (prev.status === 'ready' && prev.sig === sig ? prev : {
|
|
4769
5655
|
status: 'ready',
|
|
5656
|
+
// 变更档的独立载荷不归 load 管;轮询时原样带过去,别被列表刷新抹掉。
|
|
5657
|
+
changesStatus: prev.changesStatus || null,
|
|
4770
5658
|
docs: data.docs || [],
|
|
4771
5659
|
root: data.root || '',
|
|
4772
5660
|
// v0.19 修订:`hostRoot` 是同一个工作区、但符号链接已展开的那份路径。
|
|
@@ -4892,12 +5780,23 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4892
5780
|
}, [sessionId, load])
|
|
4893
5781
|
|
|
4894
5782
|
/* ── 过滤:纯客户端,不重新请求宿主 ─────────────── */
|
|
5783
|
+
/* v0.26.x「变更」档:数据来自独立 `/api/status`,**不混进 state.docs** ——
|
|
5784
|
+
列表刷新(5 s 轮询)与变更读取互不影响。`changesStatus` 挂在 state 上是为了
|
|
5785
|
+
避免新增 hook 位置(测试按位预置 hook);它是纯缓存,不参与排序。 */
|
|
5786
|
+
const changesStatus = state.changesStatus || null
|
|
5787
|
+
const changeView = changeStatusOf(changesStatus)
|
|
5788
|
+
const changeDocsAll = changeDocsOf(changesStatus)
|
|
5789
|
+
const changeText = query.trim().toLowerCase()
|
|
5790
|
+
const changeDocs = changeText
|
|
5791
|
+
? changeDocsAll.filter((doc) => docMatchesQuery(doc, changeText))
|
|
5792
|
+
: changeDocsAll
|
|
4895
5793
|
const visibleDocs = React.useMemo(() => {
|
|
5794
|
+
if (kind === KIND_CHANGES) return changeDocs
|
|
4896
5795
|
const all = Array.isArray(state.docs) ? state.docs : []
|
|
4897
5796
|
const q = query.trim().toLowerCase()
|
|
4898
5797
|
if (!q) return all
|
|
4899
5798
|
return all.filter((doc) => docMatchesQuery(doc, q))
|
|
4900
|
-
}, [state.docs, query])
|
|
5799
|
+
}, [kind, changeDocs, state.docs, query])
|
|
4901
5800
|
|
|
4902
5801
|
// ResizeObserver 量到的是 .knit-list(它自己也有左右内边距),
|
|
4903
5802
|
// 网格的可用宽度 = 列表宽度 − 列表内边距 − 网格内边距。
|
|
@@ -4937,7 +5836,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
4937
5836
|
renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark, withLife))
|
|
4938
5837
|
}
|
|
4939
5838
|
|
|
4940
|
-
const relevance = state.mode === 'relevance'
|
|
5839
|
+
const relevance = state.mode === 'relevance' && kind !== KIND_CHANGES
|
|
4941
5840
|
const filtering = query.trim().length > 0
|
|
4942
5841
|
|
|
4943
5842
|
/**
|
|
@@ -5130,7 +6029,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5130
6029
|
const merged = (Array.isArray(visibleDocs) ? visibleDocs : []).concat(attachmentDocs)
|
|
5131
6030
|
return orderFavorites(merged.slice().sort(byTimeDesc), favoriteSet)
|
|
5132
6031
|
}, [visibleDocs, favoriteSet, attachmentDocs])
|
|
5133
|
-
const navDocs = kind === KIND_MEDIA && !contextView ? mediaDocs : (contextView ? contextView.flat : visibleDocs)
|
|
6032
|
+
const navDocs = kind === KIND_CHANGES ? visibleDocs : (kind === KIND_MEDIA && !contextView ? mediaDocs : (contextView ? contextView.flat : visibleDocs))
|
|
5134
6033
|
|
|
5135
6034
|
// cursor 消失(被过滤掉 / 被上限截断 / 列表刷新)时落回第一项
|
|
5136
6035
|
React.useEffect(() => {
|
|
@@ -5215,6 +6114,32 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5215
6114
|
})
|
|
5216
6115
|
}, [previewFor])
|
|
5217
6116
|
|
|
6117
|
+
/**
|
|
6118
|
+
* 「变更」档点开一行:拉 `/api/diff`,在同一个预览面板里画逐行 diff。
|
|
6119
|
+
* 普通行仍走 `togglePreview`;这里只是给变更行换一个打开方式,不新增第二套面板。
|
|
6120
|
+
*/
|
|
6121
|
+
const openDiff = async (doc) => {
|
|
6122
|
+
if (!doc) return
|
|
6123
|
+
setNotice('')
|
|
6124
|
+
setCursor(doc.rel)
|
|
6125
|
+
setPreview({
|
|
6126
|
+
rel: doc.rel, title: doc.title || doc.name, path: '', text: '', status: 'ready',
|
|
6127
|
+
kind: doc.kind || ARTIFACT_CODE, diff: { loading: true },
|
|
6128
|
+
added: doc.change ? doc.change.added : null, removed: doc.change ? doc.change.removed : null,
|
|
6129
|
+
})
|
|
6130
|
+
try {
|
|
6131
|
+
const res = await fetch(`${DIFF_API}?sessionId=${encodeURIComponent(sessionId)}&rel=${encodeURIComponent(doc.rel)}`, {
|
|
6132
|
+
headers: { accept: 'application/json' }, cache: 'no-store',
|
|
6133
|
+
})
|
|
6134
|
+
const data = await res.json()
|
|
6135
|
+
setPreview((prev) => (prev && prev.rel === doc.rel
|
|
6136
|
+
? { ...prev, diff: data && data.ok ? data : { error: true } }
|
|
6137
|
+
: prev))
|
|
6138
|
+
} catch {
|
|
6139
|
+
setPreview((prev) => (prev && prev.rel === doc.rel ? { ...prev, diff: { error: true } } : prev))
|
|
6140
|
+
}
|
|
6141
|
+
}
|
|
6142
|
+
|
|
5218
6143
|
/** 收起预览;全屏时顺带退出全屏。 */
|
|
5219
6144
|
const closePreview = React.useCallback(() => {
|
|
5220
6145
|
setPreview(null)
|
|
@@ -5257,6 +6182,10 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5257
6182
|
存的是 `rel` 而不是下标 —— 列表每 5 秒会换一份,下标会漂;`rel` 不会。
|
|
5258
6183
|
列表里找不到它了(被删 / 被存进项目 / 切了档)就自己关掉。 */
|
|
5259
6184
|
const [lightboxRel, setLightboxRel] = React.useState('')
|
|
6185
|
+
/* v0.26 返工:`docked` = 在 **Knit 面板里**显示画布(不盖会话、身份清楚);
|
|
6186
|
+
`false` = 原来的整屏查看器(只在「全屏」按钮里用)。
|
|
6187
|
+
⚠️ 默认双击仍是整屏(v0.25 的既有语义不动);**评论入口走 hover 大图 → 面板画布**。 */
|
|
6188
|
+
const [lightboxDock, setLightboxDock] = React.useState(false)
|
|
5260
6189
|
const lightboxRef = React.useRef(null)
|
|
5261
6190
|
const lightboxIndex = React.useMemo(
|
|
5262
6191
|
() => (lightboxRel ? mediaDocs.findIndex((doc) => doc.rel === lightboxRel) : -1),
|
|
@@ -5270,12 +6199,17 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5270
6199
|
React.useEffect(() => {
|
|
5271
6200
|
if (lightboxRel && lightboxIndex < 0) setLightboxRel('')
|
|
5272
6201
|
}, [lightboxRel, lightboxIndex])
|
|
5273
|
-
const lightboxOpen = React.useCallback((doc) => {
|
|
6202
|
+
const lightboxOpen = React.useCallback((doc, opts = {}) => {
|
|
5274
6203
|
if (!doc || doc.kind !== 'image') return
|
|
5275
6204
|
setLightboxRel(doc.rel)
|
|
6205
|
+
setLightboxDock(opts.dock === true)
|
|
6206
|
+
// 面板画布从 hover 的「评论」进来时直接落在评论模式;整屏查看默认干净
|
|
6207
|
+
setCommentOn(opts.comment === true)
|
|
5276
6208
|
// 悬停浮窗这时必须收掉:它在查看器下面,留着就是两层大字
|
|
5277
6209
|
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
|
|
5278
6210
|
hoverTimerRef.current = 0
|
|
6211
|
+
if (hoverHideRef.current) clearTimeout(hoverHideRef.current)
|
|
6212
|
+
hoverHideRef.current = 0
|
|
5279
6213
|
setHoverShot(null)
|
|
5280
6214
|
}, [])
|
|
5281
6215
|
const lightboxClose = React.useCallback(() => setLightboxRel(''), [])
|
|
@@ -5773,6 +6707,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5773
6707
|
const motionRows = (() => {
|
|
5774
6708
|
if (state.status === 'error' || state.docs.length === 0 || visibleDocs.length === 0) return []
|
|
5775
6709
|
if (kind === KIND_MEDIA) return [] // 媒体格子不参与:网格里收起高度没有意义
|
|
6710
|
+
if (kind === KIND_CHANGES) return [] // 变更档:列表每次刷新可能整批换,别让整屏飞
|
|
5776
6711
|
if (contextView) {
|
|
5777
6712
|
// 有包(相关序):三层的 key 就是运动分组 —— 「全部」与「文档」走同一条路。
|
|
5778
6713
|
const rows = []
|
|
@@ -5885,8 +6820,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5885
6820
|
active: Boolean(preview && preview.rel === doc.rel),
|
|
5886
6821
|
cursor: doc.rel === cursor,
|
|
5887
6822
|
optionId: docOptionId(doc),
|
|
5888
|
-
onSelect: togglePreview,
|
|
5889
|
-
onOpenTab,
|
|
6823
|
+
onSelect: doc.change ? () => openDiff(doc) : togglePreview,
|
|
6824
|
+
onOpenTab: doc.change ? () => openDiff(doc) : onOpenTab,
|
|
5890
6825
|
// v0.20(需求 §12):只有真的带命中片段的条目才渲染那一行 —— 没有就不渲染,
|
|
5891
6826
|
// 不编造一个「命中片段:—」的占位(§26:只展示可验证信息)。
|
|
5892
6827
|
passage: firstMatchOf(doc),
|
|
@@ -5922,6 +6857,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5922
6857
|
// 平铺列表里的条目来源未知,不能替它认领一个「检索」。
|
|
5923
6858
|
const controllable = Boolean(contextView && !isMedia(doc))
|
|
5924
6859
|
return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary,
|
|
6860
|
+
change: doc.change || null,
|
|
5925
6861
|
prov: provText(doc.provenance),
|
|
5926
6862
|
pinned: doc.provenance === 'manual',
|
|
5927
6863
|
onAct: controllable ? act : null,
|
|
@@ -5947,15 +6883,36 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
5947
6883
|
|
|
5948
6884
|
// 媒体视图:一格都不隐藏 —— 一屏两行以外的部分在媒体区**内部滚动**,
|
|
5949
6885
|
// 既不让面板被整面媒体墙顶爆,也不会像旧版那样把剩下的条目直接切掉。
|
|
5950
|
-
const emptyText = kind ===
|
|
5951
|
-
? t('list.
|
|
5952
|
-
: kind ===
|
|
5953
|
-
? t('list.
|
|
5954
|
-
:
|
|
6886
|
+
const emptyText = kind === KIND_CHANGES
|
|
6887
|
+
? t('list.emptyChanges')
|
|
6888
|
+
: kind === KIND_MEDIA
|
|
6889
|
+
? t('list.emptyMedia')
|
|
6890
|
+
: kind === KIND_CODE
|
|
6891
|
+
? t('list.emptyCode')
|
|
6892
|
+
: t('list.empty')
|
|
5955
6893
|
/* ⚠️ 为什么是**函数**而不是常量:这里要读「面板末尾才声明」的状态(媒体收藏)。
|
|
5956
6894
|
写成常量会在这一行就求值 ⇒ TDZ(`Cannot access 'favoriteSet' before initialization`)。
|
|
5957
6895
|
包成函数、在 return 里调用一次,既不改渲染结果,也不会再被后面的新状态绊倒。 */
|
|
5958
|
-
|
|
6896
|
+
/* 变更档自己的三态:还没读到 / 读不到(带原因)/ 读到了但没东西可列。
|
|
6897
|
+
⚠️ 它**不**看 `state.status` —— 那是文档列表的加载态,与 git 无关。 */
|
|
6898
|
+
const changesListBody = () => {
|
|
6899
|
+
if (changesStatus === null) return h('div', { className: 'knit-msg' }, t('list.changesLoading'))
|
|
6900
|
+
if (!changeView.read) {
|
|
6901
|
+
return h('div', { className: 'knit-msg' },
|
|
6902
|
+
t('changes.unavailable', { reason: t(changeReasonKey(changeView.reason)) }))
|
|
6903
|
+
}
|
|
6904
|
+
if (changeView.filesTotal === 0) return h('div', { className: 'knit-msg' }, t('list.emptyChanges'))
|
|
6905
|
+
if (changeDocsAll.length === 0) {
|
|
6906
|
+
return h('div', { className: 'knit-msg' }, t('list.changeOnlyOther', { n: changeView.filesTotal }))
|
|
6907
|
+
}
|
|
6908
|
+
if (changeDocs.length === 0) {
|
|
6909
|
+
return h('div', { className: 'knit-msg' }, t('list.noMatch', { query: query.trim() }))
|
|
6910
|
+
}
|
|
6911
|
+
return docsGrid(changeDocs)
|
|
6912
|
+
}
|
|
6913
|
+
const listBody = () => (kind === KIND_CHANGES
|
|
6914
|
+
? changesListBody()
|
|
6915
|
+
: state.status === 'loading' && state.docs.length === 0
|
|
5959
6916
|
? h('div', { className: 'knit-msg' }, t('list.scanning'))
|
|
5960
6917
|
: state.status === 'error'
|
|
5961
6918
|
? h('div', { className: 'knit-msg' }, t('list.failed', { error: state.error }), h('br'), t('list.failedHint'))
|
|
@@ -6218,18 +7175,22 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6218
7175
|
// ⚠️ 2026-10-09 用户要求:**屏幕上只留阿拉伯数字**(`9` / `3 / 79`)——
|
|
6219
7176
|
// 量词本来就随档位变(同一位置换个档就换一种中文,读起来像两套东西)。
|
|
6220
7177
|
// 整句降级成 `title`(悬停仍读得到「9 个代码文件」),i18n 键不闲置。
|
|
6221
|
-
const countKey = kind ===
|
|
6222
|
-
? (filtering ? 'count.
|
|
6223
|
-
: kind ===
|
|
6224
|
-
? (filtering ? 'count.
|
|
6225
|
-
:
|
|
7178
|
+
const countKey = kind === KIND_CHANGES
|
|
7179
|
+
? (filtering ? 'count.changes.filtered' : 'count.changes')
|
|
7180
|
+
: kind === KIND_MEDIA
|
|
7181
|
+
? (filtering ? 'count.media.filtered' : 'count.media')
|
|
7182
|
+
: kind === KIND_CODE
|
|
7183
|
+
? (filtering ? 'count.code.filtered' : 'count.code')
|
|
7184
|
+
: (filtering ? 'count.filtered' : 'count')
|
|
7185
|
+
const countTotal = kind === KIND_CHANGES ? changeView.filesTotal : state.total
|
|
7186
|
+
const countVisible = kind === KIND_CHANGES ? changeDocs.length : visibleDocs.length
|
|
6226
7187
|
// 可见文本 = 纯数字;整句(含量词)只出现在 title 里。
|
|
6227
7188
|
const countText = filtering
|
|
6228
|
-
? `${
|
|
6229
|
-
: String(
|
|
7189
|
+
? `${countVisible} / ${countTotal}`
|
|
7190
|
+
: String(countTotal ?? 0)
|
|
6230
7191
|
const countTitle = filtering
|
|
6231
|
-
? t(countKey, { hit:
|
|
6232
|
-
: t(countKey, { n:
|
|
7192
|
+
? t(countKey, { hit: countVisible, total: countTotal })
|
|
7193
|
+
: t(countKey, { n: countTotal })
|
|
6233
7194
|
|
|
6234
7195
|
/* ── v0.21 检索状态摘要(需求 §6.3;2026-10-09 用户规格重排)──────────
|
|
6235
7196
|
每一格都是**已经发生的事实**,不是估算:
|
|
@@ -6282,7 +7243,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6282
7243
|
⚠️ **不再看 provider 配没配**(本次放宽):未配也出现 —— Knit 还没有设置页,
|
|
6283
7244
|
藏起来用户就永远打不开这个功能;菜单里如实写状态,并就地给配置入口。
|
|
6284
7245
|
⚠️ **永远不做置灰禁用态**。 */
|
|
6285
|
-
const showRetrieval = sort === 'relevance'
|
|
7246
|
+
const showRetrieval = sort === 'relevance' && kind !== KIND_CHANGES
|
|
6286
7247
|
const semReason = semInfo && typeof semInfo.reason === 'string' ? semInfo.reason : null
|
|
6287
7248
|
/** 菜单底部那行状态:如实说这一档现在到底生效成什么(不美化、不猜)。 */
|
|
6288
7249
|
const semStateText = !semOn
|
|
@@ -6594,6 +7555,9 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6594
7555
|
if (!event) return
|
|
6595
7556
|
// ⚠️ 查看器是**最上层**:它开着时 Esc / ← / → 先归它(不许漏到列表的键盘导航上)
|
|
6596
7557
|
if (lightboxRel) {
|
|
7558
|
+
// 评论输入框里的 Escape / 方向键属于「取消编辑 / 移光标」,不许被查看器抢走
|
|
7559
|
+
// (这里在捕获阶段,输入框自己的 onKeyDown 还没跑)。判定只看 DOM 归属。
|
|
7560
|
+
if (commentEditorTarget(event)) return
|
|
6597
7561
|
if (event.key === 'Escape') {
|
|
6598
7562
|
event.preventDefault(); event.stopPropagation(); lightboxClose(); return
|
|
6599
7563
|
}
|
|
@@ -6628,6 +7592,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6628
7592
|
只对图片;停 HOVER_SHOT_DELAY_MS 才出现;离开 / 滚动 / 换档立刻收。 */
|
|
6629
7593
|
const [hoverShot, setHoverShot] = React.useState(null)
|
|
6630
7594
|
const hoverTimerRef = React.useRef(0)
|
|
7595
|
+
const hoverHideRef = React.useRef(0)
|
|
6631
7596
|
const hoverStart = React.useCallback((doc, src, event) => {
|
|
6632
7597
|
if (!doc || doc.kind !== 'image' || !src) return
|
|
6633
7598
|
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
|
|
@@ -6644,18 +7609,606 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6644
7609
|
const box = hoverShotBox(rect, view)
|
|
6645
7610
|
hoverTimerRef.current = setTimeout(() => {
|
|
6646
7611
|
hoverTimerRef.current = 0
|
|
6647
|
-
setHoverShot({ rel: doc.rel, src, box })
|
|
7612
|
+
setHoverShot({ rel: doc.rel, src, box, doc })
|
|
6648
7613
|
}, HOVER_SHOT_DELAY_MS)
|
|
6649
7614
|
}, [])
|
|
7615
|
+
/** 离开卡片:**延迟**收起,给「鼠标挪进浮窗点评论」留出通路。 */
|
|
6650
7616
|
const hoverEnd = React.useCallback(() => {
|
|
6651
7617
|
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
|
|
6652
7618
|
hoverTimerRef.current = 0
|
|
7619
|
+
if (hoverHideRef.current) clearTimeout(hoverHideRef.current)
|
|
7620
|
+
hoverHideRef.current = setTimeout(() => {
|
|
7621
|
+
hoverHideRef.current = 0
|
|
7622
|
+
setHoverShot((prev) => (prev ? null : prev))
|
|
7623
|
+
}, HOVER_SHOT_HIDE_MS)
|
|
7624
|
+
}, [])
|
|
7625
|
+
/** 鼠标已经进到浮窗上:取消收起。 */
|
|
7626
|
+
const hoverKeep = React.useCallback(() => {
|
|
7627
|
+
if (hoverHideRef.current) clearTimeout(hoverHideRef.current)
|
|
7628
|
+
hoverHideRef.current = 0
|
|
7629
|
+
}, [])
|
|
7630
|
+
/** 立刻收(滚动 / 打开画布 / 卸载)。 */
|
|
7631
|
+
const hoverClose = React.useCallback(() => {
|
|
7632
|
+
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
|
|
7633
|
+
if (hoverHideRef.current) clearTimeout(hoverHideRef.current)
|
|
7634
|
+
hoverTimerRef.current = 0
|
|
7635
|
+
hoverHideRef.current = 0
|
|
6653
7636
|
setHoverShot((prev) => (prev ? null : prev))
|
|
6654
7637
|
}, [])
|
|
6655
7638
|
React.useEffect(() => () => {
|
|
6656
7639
|
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
|
|
7640
|
+
if (hoverHideRef.current) clearTimeout(hoverHideRef.current)
|
|
7641
|
+
}, [])
|
|
7642
|
+
|
|
7643
|
+
/* ── v0.26:图内评论(**追加在末尾**:替身按下标 seed useState / useRef)
|
|
7644
|
+
commentsByAnchor 按身份锚定(工作区图 = rel;对话图 = 附件 sha256 id)。
|
|
7645
|
+
P0 只活在内存里:退出查看器仍在、硬刷新丢 —— **不写 localStorage**(有守卫)。
|
|
7646
|
+
落点由 commentClickPct 从图片**绘制矩形**算;渲染层用同一份
|
|
7647
|
+
contentViewportOf(img),再换算成**相对画布表面**的坐标(整屏查看器 / 面板画布共用一套),
|
|
7648
|
+
**落点与画点同一个矩形**。窗口缩放 / 面板宽度变化 / 滚动都会重算(下一个 effect)。 */
|
|
7649
|
+
const [commentOn, setCommentOn] = React.useState(false)
|
|
7650
|
+
const [commentsByAnchor, setCommentsByAnchor] = React.useState({})
|
|
7651
|
+
const [commentDraft, setCommentDraft] = React.useState(null)
|
|
7652
|
+
const [commentBox, setCommentBox] = React.useState(null)
|
|
7653
|
+
const [commentSurface, setCommentSurface] = React.useState(null)
|
|
7654
|
+
const [commentStatus, setCommentStatus] = React.useState('')
|
|
7655
|
+
const commentStageRef = React.useRef(null)
|
|
7656
|
+
const commentImgRef = React.useRef(null)
|
|
7657
|
+
const commentAnchor = lightboxDoc ? anchorIdFor(lightboxDoc) : ''
|
|
7658
|
+
const commentList = commentsFor(commentsByAnchor, commentAnchor)
|
|
7659
|
+
|
|
7660
|
+
/** 量一次:内容框相对**画布表面**(`.knit-lightbox` 根)的盒子 + 表面尺寸。 */
|
|
7661
|
+
const measureCommentBox = React.useCallback(() => {
|
|
7662
|
+
const img = commentImgRef.current
|
|
7663
|
+
const surface = lightboxRef.current
|
|
7664
|
+
if (!img || !surface || typeof surface.getBoundingClientRect !== 'function') return
|
|
7665
|
+
const rect = contentViewportOf(img)
|
|
7666
|
+
if (!rect) return
|
|
7667
|
+
const srect = surface.getBoundingClientRect()
|
|
7668
|
+
setCommentBox({
|
|
7669
|
+
left: rect.left - srect.left,
|
|
7670
|
+
top: rect.top - srect.top,
|
|
7671
|
+
width: rect.width,
|
|
7672
|
+
height: rect.height,
|
|
7673
|
+
})
|
|
7674
|
+
setCommentSurface({ width: srect.width, height: srect.height })
|
|
6657
7675
|
}, [])
|
|
6658
7676
|
|
|
7677
|
+
// 换图 / 关闭:丢掉半截草稿与提示;关掉查看器时连评论模式一起退出。
|
|
7678
|
+
React.useEffect(() => {
|
|
7679
|
+
setCommentDraft(null)
|
|
7680
|
+
setCommentStatus('')
|
|
7681
|
+
if (!lightboxRel) {
|
|
7682
|
+
setCommentOn(false)
|
|
7683
|
+
setLightboxDock(false)
|
|
7684
|
+
setCommentBox(null)
|
|
7685
|
+
setCommentSurface(null)
|
|
7686
|
+
}
|
|
7687
|
+
}, [lightboxRel])
|
|
7688
|
+
|
|
7689
|
+
// 窗口缩放 / 面板宽度变化 / 滚动:**重新量**(一次算完就不管 = pin 必跑位)。
|
|
7690
|
+
React.useEffect(() => {
|
|
7691
|
+
if (!lightboxRel) return undefined
|
|
7692
|
+
measureCommentBox()
|
|
7693
|
+
let observer = null
|
|
7694
|
+
try {
|
|
7695
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
7696
|
+
observer = new ResizeObserver(measureCommentBox)
|
|
7697
|
+
if (lightboxRef.current) observer.observe(lightboxRef.current)
|
|
7698
|
+
if (commentImgRef.current) observer.observe(commentImgRef.current)
|
|
7699
|
+
}
|
|
7700
|
+
} catch { observer = null }
|
|
7701
|
+
const win = typeof window === 'undefined' ? null : window
|
|
7702
|
+
if (win && typeof win.addEventListener === 'function') {
|
|
7703
|
+
win.addEventListener('resize', measureCommentBox)
|
|
7704
|
+
win.addEventListener('scroll', measureCommentBox, true)
|
|
7705
|
+
}
|
|
7706
|
+
return () => {
|
|
7707
|
+
if (observer && typeof observer.disconnect === 'function') observer.disconnect()
|
|
7708
|
+
if (win && typeof win.removeEventListener === 'function') {
|
|
7709
|
+
win.removeEventListener('resize', measureCommentBox)
|
|
7710
|
+
win.removeEventListener('scroll', measureCommentBox, true)
|
|
7711
|
+
}
|
|
7712
|
+
}
|
|
7713
|
+
}, [lightboxRel, lightboxDock, measureCommentBox])
|
|
7714
|
+
|
|
7715
|
+
const toggleCommentMode = React.useCallback((event) => {
|
|
7716
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7717
|
+
setCommentDraft(null)
|
|
7718
|
+
setCommentStatus('')
|
|
7719
|
+
setCommentOn((current) => !current)
|
|
7720
|
+
}, [])
|
|
7721
|
+
|
|
7722
|
+
/** 评论模式里点图片:落点 → 百分比 → 就地开一个空草稿。 */
|
|
7723
|
+
const onCommentStageClick = React.useCallback((event) => {
|
|
7724
|
+
if (!commentOn || !lightboxDoc) return
|
|
7725
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7726
|
+
if (commentList.length >= COMMENT_MAX) {
|
|
7727
|
+
setCommentStatus('lightbox.comment.full')
|
|
7728
|
+
return
|
|
7729
|
+
}
|
|
7730
|
+
const stage = commentStageRef.current || (event && event.currentTarget)
|
|
7731
|
+
const img = commentImgRef.current
|
|
7732
|
+
|| (stage && typeof stage.querySelector === 'function' ? stage.querySelector('.knit-lightbox-img') : null)
|
|
7733
|
+
const pct = commentClickPct(event, img)
|
|
7734
|
+
if (!pct) return
|
|
7735
|
+
setCommentStatus('')
|
|
7736
|
+
setCommentDraft({
|
|
7737
|
+
anchor: commentAnchor,
|
|
7738
|
+
n: nextNumber(commentList),
|
|
7739
|
+
xPct: pct.xPct,
|
|
7740
|
+
yPct: pct.yPct,
|
|
7741
|
+
text: '',
|
|
7742
|
+
isNew: true,
|
|
7743
|
+
})
|
|
7744
|
+
}, [commentOn, lightboxDoc, commentAnchor, commentList])
|
|
7745
|
+
|
|
7746
|
+
/** 点已有 pin / 评论栏里那一行 → 就地重编辑。 */
|
|
7747
|
+
const openCommentEditor = React.useCallback((event, comment) => {
|
|
7748
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7749
|
+
if (!comment) return
|
|
7750
|
+
setCommentStatus('')
|
|
7751
|
+
setCommentDraft({
|
|
7752
|
+
anchor: commentAnchor,
|
|
7753
|
+
n: comment.n,
|
|
7754
|
+
xPct: comment.xPct,
|
|
7755
|
+
yPct: comment.yPct,
|
|
7756
|
+
text: comment.text,
|
|
7757
|
+
isNew: false,
|
|
7758
|
+
})
|
|
7759
|
+
}, [commentAnchor])
|
|
7760
|
+
|
|
7761
|
+
/** Enter / 保存:空文本不落;超 200 字**不截断**,提示后留在编辑态。 */
|
|
7762
|
+
const saveComment = React.useCallback(() => {
|
|
7763
|
+
const draft = commentDraft
|
|
7764
|
+
if (!draft) return
|
|
7765
|
+
const text = String(draft.text || '')
|
|
7766
|
+
if (!text.trim()) { setCommentDraft(null); setCommentStatus(''); return }
|
|
7767
|
+
if (text.length > COMMENT_MAX_CHARS) { setCommentStatus('lightbox.comment.tooLong'); return }
|
|
7768
|
+
const current = commentsFor(commentsByAnchor, draft.anchor)
|
|
7769
|
+
const next = draft.isNew
|
|
7770
|
+
? normalizeComments(current.concat([{ n: draft.n, xPct: draft.xPct, yPct: draft.yPct, text }]))
|
|
7771
|
+
: normalizeComments(current.map((item) => (item.n === draft.n ? { ...item, text } : item)))
|
|
7772
|
+
setCommentsByAnchor(withComments(commentsByAnchor, draft.anchor, next))
|
|
7773
|
+
setCommentDraft(null)
|
|
7774
|
+
setCommentStatus('')
|
|
7775
|
+
}, [commentDraft, commentsByAnchor])
|
|
7776
|
+
|
|
7777
|
+
const deleteComment = React.useCallback((n) => {
|
|
7778
|
+
const anchor = commentDraft ? commentDraft.anchor : commentAnchor
|
|
7779
|
+
const current = commentsFor(commentsByAnchor, anchor)
|
|
7780
|
+
setCommentsByAnchor(withComments(commentsByAnchor, anchor, current.filter((item) => item.n !== n)))
|
|
7781
|
+
setCommentDraft((draft) => (draft && draft.n === n ? null : draft))
|
|
7782
|
+
}, [commentDraft, commentAnchor, commentsByAnchor])
|
|
7783
|
+
|
|
7784
|
+
/** 发送 = 只**投递**(§四 文本),绝不自动发送。 */
|
|
7785
|
+
const sendComments = React.useCallback(async () => {
|
|
7786
|
+
if (!lightboxDoc) return
|
|
7787
|
+
const list = commentsFor(commentsByAnchor, anchorIdFor(lightboxDoc))
|
|
7788
|
+
if (!list.length) return
|
|
7789
|
+
/* 文本身份:工作区图用 **rel**(比文件名唯一,agent 能直接定位);对话图没有路径,
|
|
7790
|
+
用文件名 + 附件 sha。图片本身作为附件随 paste 一起进输入框(不再是「只发文字」)。 */
|
|
7791
|
+
const label = lightboxDoc.conversation
|
|
7792
|
+
? (lightboxDoc.name || 'image')
|
|
7793
|
+
: lightboxDoc.rel
|
|
7794
|
+
/* 附件序号就是图像序号:输入框里已经有 N 张附件 ⇒ 这一张是「图像 N+1」。 */
|
|
7795
|
+
const composer = composerState(typeof document === 'undefined' ? null : document)
|
|
7796
|
+
const text = commentLines(list, {
|
|
7797
|
+
rel: label,
|
|
7798
|
+
sha: shaOfDoc(lightboxDoc),
|
|
7799
|
+
index: composer.count + 1,
|
|
7800
|
+
}).join('\n')
|
|
7801
|
+
const result = await deliverCommentText(text, {
|
|
7802
|
+
attachment: {
|
|
7803
|
+
src: srcFor(lightboxDoc),
|
|
7804
|
+
name: lightboxDoc.name || String(lightboxDoc.rel).split('/').pop() || 'knit-image.png',
|
|
7805
|
+
},
|
|
7806
|
+
})
|
|
7807
|
+
setCommentStatus(!result.ok
|
|
7808
|
+
? 'lightbox.comment.sendFailed'
|
|
7809
|
+
: result.via === 'clipboard'
|
|
7810
|
+
? 'lightbox.comment.copied'
|
|
7811
|
+
: result.via === 'download'
|
|
7812
|
+
? 'lightbox.comment.downloaded'
|
|
7813
|
+
: result.image
|
|
7814
|
+
? 'lightbox.comment.sent'
|
|
7815
|
+
: 'lightbox.comment.sentNoImage')
|
|
7816
|
+
}, [lightboxDoc, commentsByAnchor])
|
|
7817
|
+
|
|
7818
|
+
const cancelCommentDraft = React.useCallback(() => {
|
|
7819
|
+
setCommentDraft(null)
|
|
7820
|
+
setCommentStatus('')
|
|
7821
|
+
}, [])
|
|
7822
|
+
|
|
7823
|
+
const commentStatusText = commentStatus
|
|
7824
|
+
? t(commentStatus, { max: commentStatus === 'lightbox.comment.full' ? COMMENT_MAX : COMMENT_MAX_CHARS })
|
|
7825
|
+
: ''
|
|
7826
|
+
|
|
7827
|
+
/* 编辑气泡落点:优先贴着 pin(**相对画布表面**的坐标);量不到尺寸就回退表面中心
|
|
7828
|
+
—— 气泡本身仍然由 commentPopoverBox 夹进表面,不会跑到外面(整屏与面板画布共用)。 */
|
|
7829
|
+
const commentView = {
|
|
7830
|
+
width: commentSurface && Number.isFinite(commentSurface.width) ? commentSurface.width : (
|
|
7831
|
+
typeof window !== 'undefined' && Number.isFinite(window.innerWidth) ? window.innerWidth : 1024),
|
|
7832
|
+
height: commentSurface && Number.isFinite(commentSurface.height) ? commentSurface.height : (
|
|
7833
|
+
typeof window !== 'undefined' && Number.isFinite(window.innerHeight) ? window.innerHeight : 768),
|
|
7834
|
+
}
|
|
7835
|
+
const commentAnchorPoint = commentDraft && commentBox
|
|
7836
|
+
? {
|
|
7837
|
+
x: commentBox.left + (commentBox.width * commentDraft.xPct) / 100,
|
|
7838
|
+
y: commentBox.top + (commentBox.height * commentDraft.yPct) / 100,
|
|
7839
|
+
}
|
|
7840
|
+
: null
|
|
7841
|
+
const commentEditorBox = commentDraft
|
|
7842
|
+
? commentPopoverBox(commentAnchorPoint, { width: COMMENT_POP_W, height: COMMENT_POP_H }, commentView)
|
|
7843
|
+
: null
|
|
7844
|
+
|
|
7845
|
+
/* v0.26.x「变更」档:独立的只读状态读取(不混进列表轮询)。
|
|
7846
|
+
· 只在**变更档且面板可见**时请求;切走 / 收起来就停(和列表同一条「看不见不花钱」纪律);
|
|
7847
|
+
· 载荷放 `state.changesStatus`,`load()` 轮询时原样带过去;
|
|
7848
|
+
· 失败有独立形状(`{failed,reason}`),不会把「读不到」显示成「没有改动」。 */
|
|
7849
|
+
React.useEffect(() => {
|
|
7850
|
+
if (visible === false || kind !== KIND_CHANGES) return undefined
|
|
7851
|
+
let alive = true
|
|
7852
|
+
let timer = null
|
|
7853
|
+
const run = async () => {
|
|
7854
|
+
if (!sessionId) return
|
|
7855
|
+
try {
|
|
7856
|
+
const res = await fetch(`${STATUS_API}?sessionId=${encodeURIComponent(sessionId)}`, {
|
|
7857
|
+
headers: { accept: 'application/json' }, cache: 'no-store',
|
|
7858
|
+
})
|
|
7859
|
+
const data = await res.json()
|
|
7860
|
+
if (!alive) return
|
|
7861
|
+
const next = data && data.ok ? data : { failed: true, reason: 'request' }
|
|
7862
|
+
const sig = JSON.stringify(next)
|
|
7863
|
+
setState((prev) => {
|
|
7864
|
+
if (prev.changesStatus && prev.changesStatus.sig === sig) return prev
|
|
7865
|
+
return { ...prev, changesStatus: { ...next, sig } }
|
|
7866
|
+
})
|
|
7867
|
+
} catch {
|
|
7868
|
+
if (!alive) return
|
|
7869
|
+
const next = { failed: true, reason: 'request' }
|
|
7870
|
+
const sig = JSON.stringify(next)
|
|
7871
|
+
setState((prev) => (prev.changesStatus && prev.changesStatus.sig === sig
|
|
7872
|
+
? prev : { ...prev, changesStatus: { ...next, sig } }))
|
|
7873
|
+
}
|
|
7874
|
+
}
|
|
7875
|
+
const loop = async () => { await run(); if (alive) timer = setTimeout(loop, POLL_MS) }
|
|
7876
|
+
loop()
|
|
7877
|
+
return () => { alive = false; if (timer) clearTimeout(timer) }
|
|
7878
|
+
}, [visible, kind, sessionId])
|
|
7879
|
+
|
|
7880
|
+
/* v0.26 返工:画布内容只渲染一次,但有两种挂载点 ——
|
|
7881
|
+
· `lightboxDock` = Knit 面板里的画布(会话不盖住、身份清楚)
|
|
7882
|
+
· 否则 = 原来的整屏查看器(portal 到 body)
|
|
7883
|
+
两者共用同一份 DOM / 同一套评论状态,切换不丢。 */
|
|
7884
|
+
const lightboxContent = lightboxDoc
|
|
7885
|
+
? h('div', {
|
|
7886
|
+
className: `knit-lightbox${lightboxDock ? ' docked' : ''}`,
|
|
7887
|
+
role: 'dialog',
|
|
7888
|
+
'aria-modal': lightboxDock ? 'false' : 'true',
|
|
7889
|
+
'aria-label': t('lightbox.aria', { name: lightboxDoc.name || lightboxDoc.rel }),
|
|
7890
|
+
tabIndex: 0,
|
|
7891
|
+
ref: lightboxRef,
|
|
7892
|
+
onClick: lightboxClose,
|
|
7893
|
+
/* 面板画布:滚轮在**画布任意位置**都能换图(评论栏除外,那里要滚评论列表)。
|
|
7894
|
+
整屏仍只在图片区接管滚轮(左列要滚缩略图)。 */
|
|
7895
|
+
onWheel: lightboxDock
|
|
7896
|
+
? (event) => {
|
|
7897
|
+
const target = event && event.target
|
|
7898
|
+
if (target && typeof target.closest === 'function' && target.closest('.knit-lightbox-comments')) return
|
|
7899
|
+
const delta = event && (event.deltaY || event.deltaX)
|
|
7900
|
+
if (!delta) return
|
|
7901
|
+
lightboxStep(delta > 0 ? 1 : -1)
|
|
7902
|
+
}
|
|
7903
|
+
: undefined,
|
|
7904
|
+
},
|
|
7905
|
+
lightboxDock
|
|
7906
|
+
? h('div', { className: 'knit-lightbox-dockhead' },
|
|
7907
|
+
h('span', { className: 'knit-lightbox-dockname', title: lightboxDoc.rel },
|
|
7908
|
+
lightboxDoc.name || lightboxDoc.rel),
|
|
7909
|
+
h('span', { className: 'knit-lightbox-dockctx', title: lightboxDoc.rel },
|
|
7910
|
+
lightboxDoc.conversation
|
|
7911
|
+
? t('attach.title')
|
|
7912
|
+
: (String(lightboxDoc.rel).includes('/')
|
|
7913
|
+
? String(lightboxDoc.rel).slice(0, String(lightboxDoc.rel).lastIndexOf('/') + 1)
|
|
7914
|
+
: '')),
|
|
7915
|
+
mediaDocs.length > 1
|
|
7916
|
+
? h('span', { className: 'knit-lightbox-dockcount' }, `${lightboxIndex + 1}/${mediaDocs.length}`)
|
|
7917
|
+
: null)
|
|
7918
|
+
: h('div', {
|
|
7919
|
+
className: 'knit-lightbox-rail',
|
|
7920
|
+
ref: lightboxRailRef,
|
|
7921
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
7922
|
+
}, lightboxRailView.items.map((doc, i) => h('button', {
|
|
7923
|
+
key: doc.rel,
|
|
7924
|
+
type: 'button',
|
|
7925
|
+
className: `knit-lightbox-thumb${doc.rel === lightboxDoc.rel ? ' active' : ''}`,
|
|
7926
|
+
title: doc.name || doc.rel,
|
|
7927
|
+
'data-thumb-index': lightboxRailView.start + i,
|
|
7928
|
+
onClick: () => setLightboxRel(doc.rel),
|
|
7929
|
+
}, h('img', { src: srcFor(doc), alt: '', draggable: false })))),
|
|
7930
|
+
/* 查看器工具条:「收藏」「本地打开」原来只活在**被撤掉的**媒体预览头里 ——
|
|
7931
|
+
不搬过来就等于静默丢掉两个功能(用户 2026-10-21 明确要过「收藏排第一」)。
|
|
7932
|
+
收藏只对工作区文件有意义(对话里的图还没有路径),所以对话图不显示这一条。 */
|
|
7933
|
+
h('div', { className: 'knit-lightbox-tools' },
|
|
7934
|
+
/* 面板画布只留评论相关动作(评论 / 全屏 / 返回)—— 面板窄,塞五个按钮会跟标题打架;
|
|
7935
|
+
收藏 / 本地打开在整屏里仍然有,图标与入口一个没丢。 */
|
|
7936
|
+
lightboxDock || lightboxDoc.conversation
|
|
7937
|
+
? null
|
|
7938
|
+
: h('button', {
|
|
7939
|
+
className: 'knit-btn',
|
|
7940
|
+
type: 'button',
|
|
7941
|
+
onClick: () => toggleFavorite(lightboxDoc.rel),
|
|
7942
|
+
title: favoriteSet.has(lightboxDoc.rel) ? t('fav.removeTitle') : t('fav.addTitle'),
|
|
7943
|
+
}, favoriteSet.has(lightboxDoc.rel) ? t('fav.on') : t('fav.off')),
|
|
7944
|
+
lightboxDock || lightboxDoc.conversation
|
|
7945
|
+
? null
|
|
7946
|
+
: h('button', {
|
|
7947
|
+
className: 'knit-btn',
|
|
7948
|
+
type: 'button',
|
|
7949
|
+
onClick: lightboxOpenLocal,
|
|
7950
|
+
title: t('preview.openLocal', { path: lightboxDoc.rel }),
|
|
7951
|
+
}, t('preview.openLocalBtn')),
|
|
7952
|
+
/* v0.26 评论模式:二态入口。点它只切模式,不许冒泡去关查看器。 */
|
|
7953
|
+
h('button', {
|
|
7954
|
+
className: `knit-btn${commentOn ? ' active' : ''}`,
|
|
7955
|
+
type: 'button',
|
|
7956
|
+
title: t('lightbox.comment.title'),
|
|
7957
|
+
'aria-pressed': commentOn ? 'true' : 'false',
|
|
7958
|
+
'data-knit-comment-toggle': '1',
|
|
7959
|
+
onClick: toggleCommentMode,
|
|
7960
|
+
}, commentOn ? t('lightbox.comment.exit') : t('lightbox.comment.enter')),
|
|
7961
|
+
/* 画布 / 整屏互相切换:评论在面板画布里做,看细节再进整屏 */
|
|
7962
|
+
lightboxDock
|
|
7963
|
+
? h('button', {
|
|
7964
|
+
className: 'knit-btn knit-lightbox-nav',
|
|
7965
|
+
type: 'button',
|
|
7966
|
+
title: t('lightbox.canvas.prev'),
|
|
7967
|
+
'aria-label': t('lightbox.canvas.prev'),
|
|
7968
|
+
'data-knit-canvas-prev': '1',
|
|
7969
|
+
onClick: (event) => {
|
|
7970
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7971
|
+
lightboxStep(-1)
|
|
7972
|
+
},
|
|
7973
|
+
}, '‹')
|
|
7974
|
+
: null,
|
|
7975
|
+
lightboxDock
|
|
7976
|
+
? h('button', {
|
|
7977
|
+
className: 'knit-btn knit-lightbox-nav',
|
|
7978
|
+
type: 'button',
|
|
7979
|
+
title: t('lightbox.canvas.next'),
|
|
7980
|
+
'aria-label': t('lightbox.canvas.next'),
|
|
7981
|
+
'data-knit-canvas-next': '1',
|
|
7982
|
+
onClick: (event) => {
|
|
7983
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7984
|
+
lightboxStep(1)
|
|
7985
|
+
},
|
|
7986
|
+
}, '›')
|
|
7987
|
+
: null,
|
|
7988
|
+
lightboxDock
|
|
7989
|
+
? h('button', {
|
|
7990
|
+
className: 'knit-btn',
|
|
7991
|
+
type: 'button',
|
|
7992
|
+
title: t('lightbox.canvas.fullscreenTitle'),
|
|
7993
|
+
'data-knit-canvas-fullscreen': '1',
|
|
7994
|
+
onClick: (event) => {
|
|
7995
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
7996
|
+
setLightboxDock(false)
|
|
7997
|
+
},
|
|
7998
|
+
}, t('lightbox.canvas.fullscreen'))
|
|
7999
|
+
: h('button', {
|
|
8000
|
+
className: 'knit-btn',
|
|
8001
|
+
type: 'button',
|
|
8002
|
+
title: t('lightbox.canvas.dockTitle'),
|
|
8003
|
+
'data-knit-canvas-dock': '1',
|
|
8004
|
+
onClick: (event) => {
|
|
8005
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
8006
|
+
setLightboxDock(true)
|
|
8007
|
+
},
|
|
8008
|
+
}, t('lightbox.canvas.dock')),
|
|
8009
|
+
lightboxDock
|
|
8010
|
+
? h('button', {
|
|
8011
|
+
className: 'knit-btn',
|
|
8012
|
+
type: 'button',
|
|
8013
|
+
title: t('lightbox.canvas.backTitle'),
|
|
8014
|
+
'data-knit-canvas-back': '1',
|
|
8015
|
+
onClick: (event) => {
|
|
8016
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
8017
|
+
lightboxClose()
|
|
8018
|
+
},
|
|
8019
|
+
}, t('lightbox.canvas.back'))
|
|
8020
|
+
: null),
|
|
8021
|
+
/* 右上角 ✕ —— 照 DSH 自带查看器那套(全屏之后必须有一个**看得见的**出口:
|
|
8022
|
+
光靠「点图片以外」和 Esc,第一次用的人不知道往哪点)。 */
|
|
8023
|
+
lightboxDock
|
|
8024
|
+
? null
|
|
8025
|
+
: h('button', {
|
|
8026
|
+
className: 'knit-lightbox-close',
|
|
8027
|
+
type: 'button',
|
|
8028
|
+
title: t('lightbox.close'),
|
|
8029
|
+
'aria-label': t('lightbox.close'),
|
|
8030
|
+
onClick: () => lightboxClose(),
|
|
8031
|
+
}, '✕'),
|
|
8032
|
+
/* 滚轮翻页:只在**图片这一块**生效。左列自己会滚(它 overflow-y:auto),
|
|
8033
|
+
在它上面滚轮应该滚列表,而不是换图 —— 所以监听挂在 stage 上、不挂在遮罩上。 */
|
|
8034
|
+
h('div', {
|
|
8035
|
+
className: 'knit-lightbox-stage',
|
|
8036
|
+
ref: commentStageRef,
|
|
8037
|
+
/* 评论模式:点图落 pin(handler 里 stopPropagation,不关查看器)。
|
|
8038
|
+
非评论模式:不拦,冒泡到遮罩 = 点图片以外才关的既有语义不变。 */
|
|
8039
|
+
onClick: commentOn ? onCommentStageClick : undefined,
|
|
8040
|
+
style: commentOn ? { cursor: 'crosshair' } : undefined,
|
|
8041
|
+
onWheel: lightboxDock ? undefined : (event) => {
|
|
8042
|
+
const delta = event && (event.deltaY || event.deltaX)
|
|
8043
|
+
if (!delta) return
|
|
8044
|
+
lightboxStep(delta > 0 ? 1 : -1)
|
|
8045
|
+
},
|
|
8046
|
+
},
|
|
8047
|
+
h('img', {
|
|
8048
|
+
className: 'knit-lightbox-img',
|
|
8049
|
+
ref: commentImgRef,
|
|
8050
|
+
src: srcFor(lightboxDoc),
|
|
8051
|
+
alt: lightboxDoc.name || '',
|
|
8052
|
+
draggable: false,
|
|
8053
|
+
style: commentOn ? { cursor: 'crosshair' } : undefined,
|
|
8054
|
+
onLoad: measureCommentBox,
|
|
8055
|
+
onClick: (event) => {
|
|
8056
|
+
// 评论模式下把点击让给 stage(要换算成图片上的百分比)
|
|
8057
|
+
if (!commentOn && event && event.stopPropagation) event.stopPropagation()
|
|
8058
|
+
},
|
|
8059
|
+
}),
|
|
8060
|
+
commentOn
|
|
8061
|
+
? h('div', {
|
|
8062
|
+
className: 'knit-lightbox-pins',
|
|
8063
|
+
/* 覆盖层 = **画布表面**(整屏 root / 面板画布 root 都是同一个根);
|
|
8064
|
+
pin 的像素位置由 commentBox(与落点**同一个**绘制矩形,换算到表面坐标)算。
|
|
8065
|
+
拿不到尺寸(测试替身 / 图还没 load)时先不画位置,量到即重排。 */
|
|
8066
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
8067
|
+
},
|
|
8068
|
+
commentList.map((item) => h('button', {
|
|
8069
|
+
key: item.n,
|
|
8070
|
+
type: 'button',
|
|
8071
|
+
className: 'knit-lightbox-pin',
|
|
8072
|
+
style: commentBox
|
|
8073
|
+
? {
|
|
8074
|
+
left: `${commentBox.left + (commentBox.width * item.xPct) / 100}px`,
|
|
8075
|
+
top: `${commentBox.top + (commentBox.height * item.yPct) / 100}px`,
|
|
8076
|
+
}
|
|
8077
|
+
: null,
|
|
8078
|
+
title: item.text,
|
|
8079
|
+
'aria-label': t('lightbox.comment.pinAria', { n: item.n }),
|
|
8080
|
+
'data-knit-comment-pin': String(item.n),
|
|
8081
|
+
onClick: (event) => openCommentEditor(event, item),
|
|
8082
|
+
}, String(item.n))),
|
|
8083
|
+
/* 草稿 pin:点下去的那一点要**看得见**(不然输入框像浮在图上)。
|
|
8084
|
+
与 Infini 的 .pin.draft 同一语义:半透明、不可点、编号就是即将保存的 n。 */
|
|
8085
|
+
commentDraft && commentDraft.isNew
|
|
8086
|
+
? h('span', {
|
|
8087
|
+
className: 'knit-lightbox-pin draft',
|
|
8088
|
+
/* 有绘制矩形就落真实像素位置;量不到(测试替身 / 图还没 load)时
|
|
8089
|
+
用百分比近似,等测量回来即对齐 —— 草稿点本身必须看得见。 */
|
|
8090
|
+
style: commentBox
|
|
8091
|
+
? {
|
|
8092
|
+
left: `${commentBox.left + (commentBox.width * commentDraft.xPct) / 100}px`,
|
|
8093
|
+
top: `${commentBox.top + (commentBox.height * commentDraft.yPct) / 100}px`,
|
|
8094
|
+
}
|
|
8095
|
+
: { left: `${commentDraft.xPct}%`, top: `${commentDraft.yPct}%` },
|
|
8096
|
+
'aria-hidden': 'true',
|
|
8097
|
+
}, String(commentDraft.n))
|
|
8098
|
+
: null,
|
|
8099
|
+
commentDraft
|
|
8100
|
+
? h('div', {
|
|
8101
|
+
className: 'knit-lightbox-editor',
|
|
8102
|
+
'data-knit-comment-editor': '',
|
|
8103
|
+
/* **贴着 pin**的气泡:出屏按 commentPopoverBox 翻边 + 夹进视口
|
|
8104
|
+
(与 Infini 分享包同一套规则),不再「按百分比放到图片边上」。 */
|
|
8105
|
+
style: { left: `${commentEditorBox.left}px`, top: `${commentEditorBox.top}px` },
|
|
8106
|
+
'data-placement': commentEditorBox.placement,
|
|
8107
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
8108
|
+
},
|
|
8109
|
+
h('div', { className: 'knit-lightbox-editor-head' },
|
|
8110
|
+
h('span', { className: 'knit-lightbox-editor-title' }, commentDraft.isNew
|
|
8111
|
+
? t('lightbox.comment.new')
|
|
8112
|
+
: t('lightbox.comment.edit', { n: commentDraft.n })),
|
|
8113
|
+
h('span', { className: 'knit-lightbox-editor-pos' },
|
|
8114
|
+
`x ${commentDraft.xPct.toFixed(1)}% · y ${commentDraft.yPct.toFixed(1)}%`),
|
|
8115
|
+
),
|
|
8116
|
+
h('input', {
|
|
8117
|
+
className: 'knit-lightbox-editor-input',
|
|
8118
|
+
type: 'text',
|
|
8119
|
+
value: commentDraft.text,
|
|
8120
|
+
autoFocus: true,
|
|
8121
|
+
placeholder: t('lightbox.comment.placeholder'),
|
|
8122
|
+
'aria-label': t('lightbox.comment.placeholder'),
|
|
8123
|
+
onChange: (event) => {
|
|
8124
|
+
const value = event && event.target ? event.target.value : ''
|
|
8125
|
+
setCommentDraft({ ...commentDraft, text: String(value) })
|
|
8126
|
+
},
|
|
8127
|
+
onKeyDown: (event) => {
|
|
8128
|
+
if (!event) return
|
|
8129
|
+
if (event.key === 'Enter') {
|
|
8130
|
+
event.preventDefault(); event.stopPropagation(); saveComment(); return
|
|
8131
|
+
}
|
|
8132
|
+
if (event.key === 'Escape') {
|
|
8133
|
+
event.preventDefault(); event.stopPropagation(); cancelCommentDraft()
|
|
8134
|
+
}
|
|
8135
|
+
},
|
|
8136
|
+
}),
|
|
8137
|
+
commentStatus === 'lightbox.comment.tooLong'
|
|
8138
|
+
? h('span', { className: 'knit-lightbox-editor-hint' }, commentStatusText)
|
|
8139
|
+
: null,
|
|
8140
|
+
h('div', { className: 'knit-lightbox-editor-foot' },
|
|
8141
|
+
commentDraft.isNew
|
|
8142
|
+
? null
|
|
8143
|
+
: h('button', {
|
|
8144
|
+
className: 'knit-btn',
|
|
8145
|
+
type: 'button',
|
|
8146
|
+
onClick: () => deleteComment(commentDraft.n),
|
|
8147
|
+
}, t('lightbox.comment.delete')),
|
|
8148
|
+
h('span', { className: 'knit-lightbox-editor-count' },
|
|
8149
|
+
`${String(commentDraft.text || '').length}/${COMMENT_MAX_CHARS}`),
|
|
8150
|
+
h('button', {
|
|
8151
|
+
className: 'knit-btn',
|
|
8152
|
+
type: 'button',
|
|
8153
|
+
onClick: cancelCommentDraft,
|
|
8154
|
+
}, t('lightbox.comment.cancel')),
|
|
8155
|
+
h('button', {
|
|
8156
|
+
className: 'knit-btn',
|
|
8157
|
+
type: 'button',
|
|
8158
|
+
onClick: saveComment,
|
|
8159
|
+
}, t('lightbox.comment.save'))))
|
|
8160
|
+
: null
|
|
8161
|
+
)
|
|
8162
|
+
: null),
|
|
8163
|
+
commentOn
|
|
8164
|
+
? h('div', {
|
|
8165
|
+
className: 'knit-lightbox-comments',
|
|
8166
|
+
role: 'region',
|
|
8167
|
+
'aria-label': t('lightbox.comment.count', { n: commentList.length }),
|
|
8168
|
+
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
8169
|
+
},
|
|
8170
|
+
h('div', { className: 'knit-lightbox-comments-list' },
|
|
8171
|
+
commentList.length
|
|
8172
|
+
? commentList.map((item) => h('div', {
|
|
8173
|
+
key: item.n,
|
|
8174
|
+
className: 'knit-lightbox-comment-row',
|
|
8175
|
+
},
|
|
8176
|
+
h('span', { className: 'knit-lightbox-comment-n' }, String(item.n)),
|
|
8177
|
+
h('button', {
|
|
8178
|
+
className: 'knit-lightbox-comment-text',
|
|
8179
|
+
type: 'button',
|
|
8180
|
+
title: item.text,
|
|
8181
|
+
onClick: (event) => openCommentEditor(event, item),
|
|
8182
|
+
}, commentSummary(item.text)),
|
|
8183
|
+
h('button', {
|
|
8184
|
+
className: 'knit-lightbox-comment-del',
|
|
8185
|
+
type: 'button',
|
|
8186
|
+
title: t('lightbox.comment.delete'),
|
|
8187
|
+
'aria-label': t('lightbox.comment.delete'),
|
|
8188
|
+
onClick: () => deleteComment(item.n),
|
|
8189
|
+
}, '✕'),
|
|
8190
|
+
))
|
|
8191
|
+
: h('div', { className: 'knit-lightbox-comments-empty' },
|
|
8192
|
+
h('span', { className: 'knit-lightbox-comments-emptyTitle' }, t('lightbox.comment.empty')),
|
|
8193
|
+
h('span', { className: 'knit-lightbox-comments-emptyHint' }, t('lightbox.comment.emptyHint'))),
|
|
8194
|
+
),
|
|
8195
|
+
h('div', { className: 'knit-lightbox-comments-right' },
|
|
8196
|
+
commentStatusText
|
|
8197
|
+
? h('span', { className: 'knit-lightbox-comments-status' }, commentStatusText)
|
|
8198
|
+
: null,
|
|
8199
|
+
h('button', {
|
|
8200
|
+
className: 'knit-btn knit-lightbox-comments-send',
|
|
8201
|
+
type: 'button',
|
|
8202
|
+
disabled: !commentList.length,
|
|
8203
|
+
title: t('lightbox.comment.sendTitle'),
|
|
8204
|
+
'data-knit-comment-send': '1',
|
|
8205
|
+
onClick: sendComments,
|
|
8206
|
+
}, t('lightbox.comment.send')),
|
|
8207
|
+
),
|
|
8208
|
+
)
|
|
8209
|
+
: null)
|
|
8210
|
+
: null
|
|
8211
|
+
|
|
6659
8212
|
return h('div', {
|
|
6660
8213
|
className: `knit-root${fullscreen ? ' fullscreen' : ''}`,
|
|
6661
8214
|
ref: rootRef,
|
|
@@ -6699,14 +8252,14 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6699
8252
|
h('button', {
|
|
6700
8253
|
className: `knit-seg-btn${effectiveSort === 'relevance' ? ' active' : ''}`,
|
|
6701
8254
|
onClick: () => pickSort('relevance'),
|
|
6702
|
-
disabled: kind === KIND_MEDIA,
|
|
6703
|
-
title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.relevanceTitle'),
|
|
8255
|
+
disabled: kind === KIND_MEDIA || kind === KIND_CHANGES,
|
|
8256
|
+
title: kind === KIND_CHANGES ? t('sort.changesTitle') : (kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.relevanceTitle')),
|
|
6704
8257
|
}, t('sort.relevance')),
|
|
6705
8258
|
h('button', {
|
|
6706
8259
|
className: `knit-seg-btn${effectiveSort === 'time' ? ' active' : ''}`,
|
|
6707
8260
|
onClick: () => pickSort('time'),
|
|
6708
|
-
disabled: kind === KIND_MEDIA,
|
|
6709
|
-
title: kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.timeTitle'),
|
|
8261
|
+
disabled: kind === KIND_MEDIA || kind === KIND_CHANGES,
|
|
8262
|
+
title: kind === KIND_CHANGES ? t('sort.changesTitle') : (kind === KIND_MEDIA ? t('sort.mediaTimeTitle') : t('sort.timeTitle')),
|
|
6710
8263
|
}, t('sort.time'))),
|
|
6711
8264
|
// ⚠️ 2026-10-12 用户裁决:排序组与类型组之间**那根竖线去掉了** —— 它的类名与 CSS 规则都已整体删除。
|
|
6712
8265
|
// 两组靠 `.knit-bar` 的 gap 分开就够 —— 「边界」不再需要一根线来表达。
|
|
@@ -6714,7 +8267,7 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6714
8267
|
// v0.23.1(2026-10-12 用户裁决):**三档**「文档 / 代码 / 媒体」——
|
|
6715
8268
|
// 「全部」那一档连同它的混合浏览视图在整个界面上删除了(三档等距、页签样式不变)。
|
|
6716
8269
|
// **没有第二层分类** —— 代码里不按语言(JS / TS / Python…)分组(需求 §46)。
|
|
6717
|
-
[[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media']].map(([value, labelKey]) =>
|
|
8270
|
+
[[KIND_DOC, 'kind.doc'], [KIND_CODE, 'kind.code'], [KIND_MEDIA, 'kind.media'], [KIND_CHANGES, 'kind.changes']].map(([value, labelKey]) =>
|
|
6718
8271
|
h('button', {
|
|
6719
8272
|
type: 'button',
|
|
6720
8273
|
key: value,
|
|
@@ -6778,18 +8331,20 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6778
8331
|
摘要这一行永远紧贴工具栏,位置不随开关变;观察层仍是「列表上方的观察层」,
|
|
6779
8332
|
而且比原来更贴近列表。⚠️ 别再把它挪回 `.knit-bar` 后面(有守卫钉着顺序)。
|
|
6780
8333
|
v0.15:开了才显示。不是弹窗、不是新页面、不是 Dashboard。 */
|
|
6781
|
-
usageOn ? lensNode : null,
|
|
8334
|
+
usageOn && kind !== KIND_CHANGES ? lensNode : null,
|
|
6782
8335
|
// 列表节点**直接挂上去**(2026-09-29 起永远单栏;曾经它要交给一个 IIFE
|
|
6783
8336
|
// 决定塞进单栏还是双栏的左列)。**输出与 v0.13 逐字一致** ——
|
|
6784
8337
|
// 时间序、媒体档、「全部」都不受影响。
|
|
6785
|
-
(
|
|
8338
|
+
(lightboxDoc && lightboxDock
|
|
8339
|
+
? h('div', { className: 'knit-canvas' }, lightboxContent)
|
|
8340
|
+
: (() => {
|
|
6786
8341
|
const listNode = h('div', {
|
|
6787
8342
|
className: 'knit-list',
|
|
6788
8343
|
ref: listRef,
|
|
6789
8344
|
tabIndex: 0,
|
|
6790
8345
|
onKeyDown: onListKeyDown,
|
|
6791
8346
|
// v0.25:滚动就收起悬停大图 —— 它是 fixed 定位,不跟着卡片走,留着只会错位
|
|
6792
|
-
onScroll:
|
|
8347
|
+
onScroll: hoverClose,
|
|
6793
8348
|
role: 'listbox',
|
|
6794
8349
|
'aria-label': t('list.aria'),
|
|
6795
8350
|
// 焦点始终在容器上(roving 焦点会打断「移动即预览」),
|
|
@@ -6811,8 +8366,8 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6811
8366
|
`role=listbox` 的直接子级只能是 option,多一层 group 会让辅助技术
|
|
6812
8367
|
把选项算成另一个集合(这条纪律与右栏无关,别跟着一起删)。 */
|
|
6813
8368
|
return listNode
|
|
6814
|
-
})(),
|
|
6815
|
-
preview ? h(PreviewPanel, {
|
|
8369
|
+
})()),
|
|
8370
|
+
preview && !(lightboxDoc && lightboxDock) ? h(PreviewPanel, {
|
|
6816
8371
|
preview,
|
|
6817
8372
|
pathImages,
|
|
6818
8373
|
fullscreen,
|
|
@@ -6870,81 +8425,28 @@ video.knit-preview-media{width:100%;background:#000}
|
|
|
6870
8425
|
width: `${hoverShot.box.width}px`,
|
|
6871
8426
|
height: `${hoverShot.box.height}px`,
|
|
6872
8427
|
},
|
|
6873
|
-
|
|
8428
|
+
role: 'button',
|
|
8429
|
+
tabIndex: 0,
|
|
8430
|
+
title: t('lightbox.canvas.hintTitle'),
|
|
8431
|
+
'data-knit-hover-shot': '1',
|
|
8432
|
+
onMouseEnter: hoverKeep,
|
|
8433
|
+
onMouseLeave: hoverEnd,
|
|
8434
|
+
onClick: (event) => {
|
|
8435
|
+
if (event && event.stopPropagation) event.stopPropagation()
|
|
8436
|
+
const doc = hoverShot.doc
|
|
8437
|
+
hoverClose()
|
|
8438
|
+
if (doc) lightboxOpen(doc, { dock: true, comment: true })
|
|
8439
|
+
},
|
|
8440
|
+
},
|
|
8441
|
+
h('img', { src: hoverShot.src, alt: '', draggable: false }),
|
|
8442
|
+
h('span', { className: 'knit-shot-hint' }, t('lightbox.canvas.commentHint')))
|
|
6874
8443
|
: null,
|
|
6875
8444
|
/* v0.25:媒体档「双击全屏」查看器。
|
|
6876
8445
|
· 点**图片以外**(遮罩)⇒ 关;点图片本身 ⇒ 不关(`stopPropagation`),
|
|
6877
8446
|
否则「点一下想看清细节」就把查看器点没了;
|
|
6878
8447
|
· 左侧一列缩略图(当前这张附近 10 张)——点它换图,也不许冒泡去关;
|
|
6879
8448
|
· `role="dialog"` + `aria-modal` + 可聚焦:Esc / ← → 由根上的捕获阶段接管。 */
|
|
6880
|
-
lightboxDoc
|
|
6881
|
-
? mountLightbox(h('div', {
|
|
6882
|
-
className: 'knit-lightbox',
|
|
6883
|
-
role: 'dialog',
|
|
6884
|
-
'aria-modal': 'true',
|
|
6885
|
-
'aria-label': t('lightbox.aria', { name: lightboxDoc.name || lightboxDoc.rel }),
|
|
6886
|
-
tabIndex: 0,
|
|
6887
|
-
ref: lightboxRef,
|
|
6888
|
-
onClick: lightboxClose,
|
|
6889
|
-
},
|
|
6890
|
-
h('div', {
|
|
6891
|
-
className: 'knit-lightbox-rail',
|
|
6892
|
-
ref: lightboxRailRef,
|
|
6893
|
-
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
6894
|
-
}, lightboxRailView.items.map((doc, i) => h('button', {
|
|
6895
|
-
key: doc.rel,
|
|
6896
|
-
type: 'button',
|
|
6897
|
-
className: `knit-lightbox-thumb${doc.rel === lightboxDoc.rel ? ' active' : ''}`,
|
|
6898
|
-
title: doc.name || doc.rel,
|
|
6899
|
-
'data-thumb-index': lightboxRailView.start + i,
|
|
6900
|
-
onClick: () => setLightboxRel(doc.rel),
|
|
6901
|
-
}, h('img', { src: srcFor(doc), alt: '', draggable: false })))),
|
|
6902
|
-
/* 查看器工具条:「收藏」「本地打开」原来只活在**被撤掉的**媒体预览头里 ——
|
|
6903
|
-
不搬过来就等于静默丢掉两个功能(用户 2026-10-21 明确要过「收藏排第一」)。
|
|
6904
|
-
收藏只对工作区文件有意义(对话里的图还没有路径),所以对话图不显示这一条。 */
|
|
6905
|
-
h('div', { className: 'knit-lightbox-tools' },
|
|
6906
|
-
lightboxDoc.conversation
|
|
6907
|
-
? null
|
|
6908
|
-
: h('button', {
|
|
6909
|
-
className: 'knit-btn',
|
|
6910
|
-
type: 'button',
|
|
6911
|
-
onClick: () => toggleFavorite(lightboxDoc.rel),
|
|
6912
|
-
title: favoriteSet.has(lightboxDoc.rel) ? t('fav.removeTitle') : t('fav.addTitle'),
|
|
6913
|
-
}, favoriteSet.has(lightboxDoc.rel) ? t('fav.on') : t('fav.off')),
|
|
6914
|
-
lightboxDoc.conversation
|
|
6915
|
-
? null
|
|
6916
|
-
: h('button', {
|
|
6917
|
-
className: 'knit-btn',
|
|
6918
|
-
type: 'button',
|
|
6919
|
-
onClick: lightboxOpenLocal,
|
|
6920
|
-
title: t('preview.openLocal', { path: lightboxDoc.rel }),
|
|
6921
|
-
}, t('preview.openLocalBtn'))),
|
|
6922
|
-
/* 右上角 ✕ —— 照 DSH 自带查看器那套(全屏之后必须有一个**看得见的**出口:
|
|
6923
|
-
光靠「点图片以外」和 Esc,第一次用的人不知道往哪点)。 */
|
|
6924
|
-
h('button', {
|
|
6925
|
-
className: 'knit-lightbox-close',
|
|
6926
|
-
type: 'button',
|
|
6927
|
-
title: t('lightbox.close'),
|
|
6928
|
-
'aria-label': t('lightbox.close'),
|
|
6929
|
-
onClick: () => lightboxClose(),
|
|
6930
|
-
}, '✕'),
|
|
6931
|
-
/* 滚轮翻页:只在**图片这一块**生效。左列自己会滚(它 overflow-y:auto),
|
|
6932
|
-
在它上面滚轮应该滚列表,而不是换图 —— 所以监听挂在 stage 上、不挂在遮罩上。 */
|
|
6933
|
-
h('div', {
|
|
6934
|
-
className: 'knit-lightbox-stage',
|
|
6935
|
-
onWheel: (event) => {
|
|
6936
|
-
const delta = event && (event.deltaY || event.deltaX)
|
|
6937
|
-
if (!delta) return
|
|
6938
|
-
lightboxStep(delta > 0 ? 1 : -1)
|
|
6939
|
-
},
|
|
6940
|
-
}, h('img', {
|
|
6941
|
-
className: 'knit-lightbox-img',
|
|
6942
|
-
src: srcFor(lightboxDoc),
|
|
6943
|
-
alt: lightboxDoc.name || '',
|
|
6944
|
-
draggable: false,
|
|
6945
|
-
onClick: (event) => { if (event && event.stopPropagation) event.stopPropagation() },
|
|
6946
|
-
}))))
|
|
6947
|
-
: null)
|
|
8449
|
+
lightboxDoc && !lightboxDock ? mountLightbox(lightboxContent) : null)
|
|
6948
8450
|
}
|
|
6949
8451
|
|
|
6950
8452
|
/* ── 会话入口按钮 ───────────────────────────────── */
|