dsh-knit 0.16.0 → 0.18.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 +303 -5
- package/README.en.md +141 -29
- package/README.md +119 -23
- package/package.json +2 -2
- package/src/client/client.js +1224 -77
- package/src/host/feedback.js +241 -11
- package/src/host/index.js +189 -22
- package/test/client.test.mjs +1118 -17
- package/test/document-lifecycle.test.mjs +513 -0
- package/test/harness.mjs +11 -2
- package/test/host-http.test.mjs +129 -2
- package/test/i18n.test.mjs +223 -1
- package/test/tier1.test.mjs +4 -2
package/src/client/client.js
CHANGED
|
@@ -47,7 +47,13 @@ window.__ModuleLoader__.load({
|
|
|
47
47
|
|
|
48
48
|
'kind.all': '全部',
|
|
49
49
|
'kind.doc': '文档',
|
|
50
|
-
|
|
50
|
+
// ⚠️ 2026-10-06 用户定:类型页签与「全部」分区标题都用**「媒体」**,不用「图片与视频」
|
|
51
|
+
// (原话:「我想修改成 媒体 或者 多媒体,你觉得呢?」→ 随后确认「媒体」)。
|
|
52
|
+
// 理由:① 这一档的计数本来就是「{n} 个媒体」(count.media),页签叫「图片与视频」
|
|
53
|
+
// 是唯一的例外;② 「多媒体」在中文 IT 语境里带 AV / 课件味,还暗示音频,而这一档
|
|
54
|
+
// 只扫图片与视频(宿主按扩展名放行,没有音频);③ 「媒体」省 3 个字,窄侧栏少一次
|
|
55
|
+
// 省略号。**含义由空态说明**(list.emptyMedia 仍写「还没有图片或视频」)。
|
|
56
|
+
'kind.media': '媒体',
|
|
51
57
|
'kind.title': '切换要列出的产物类型',
|
|
52
58
|
|
|
53
59
|
'filter.placeholder': '过滤文档',
|
|
@@ -56,15 +62,57 @@ window.__ModuleLoader__.load({
|
|
|
56
62
|
'usage.toggle': '使用情况',
|
|
57
63
|
'usage.toggleTitle': '打开后开始统计这个会话:先看的那篇有没有被读、有多少次读落在包外、上下文换过几回。只记事实,不给分数。',
|
|
58
64
|
'usage.none': '还没有记录',
|
|
59
|
-
'usage.epoch': '当前上下文 · Epoch {n}',
|
|
60
|
-
'usage.primaryRead': '先看的「{rel}」已读',
|
|
61
|
-
'usage.primaryUnread': '先看的「{rel}」还没读',
|
|
62
|
-
'usage.supporting': '辅助 {read}/{total}',
|
|
63
|
-
'usage.reads': '读了 {n} 次',
|
|
64
|
-
'usage.outside': '包外 {n} 篇',
|
|
65
|
-
'usage.changes': '上下文换过 {n} 次',
|
|
66
65
|
'usage.note': '只统计本会话 · 数据在内核内存里,重启 DSH 就没了',
|
|
67
66
|
|
|
67
|
+
// ── v0.18 Context Usage Lens ────────────────────────────────
|
|
68
|
+
// 这一层只回答一件事:「Knit 交出去的那份 Context,被怎样消费了」。
|
|
69
|
+
// ⚠️ 它**不是** Dashboard:没有 KPI 大数字、没有百分比、没有评分、没有图表、
|
|
70
|
+
// 没有进度条、没有「使用率 / 健康度 / 认可度」。字号一律弱于文档标题 ——
|
|
71
|
+
// 层级只靠空间与灰阶(AGENTS.md §6.3 / §7.1)。
|
|
72
|
+
// ⚠️ 每一条都是**事实陈述**,不是评价:不许写成「Agent 没看这篇 / 用错了 /
|
|
73
|
+
// Knit 漏了 / 推荐得不准」。「最近读取」也不是「正在阅读」—— 证明不了。
|
|
74
|
+
'lens.title': '使用情况',
|
|
75
|
+
'lens.expand': '展开使用情况',
|
|
76
|
+
'lens.collapse': '收起使用情况',
|
|
77
|
+
'lens.epoch': 'Epoch {n}',
|
|
78
|
+
'lens.reads': '{n} 次读取',
|
|
79
|
+
'lens.outside': '{n} 篇包外',
|
|
80
|
+
'lens.changes': '上下文变化 {n} 次',
|
|
81
|
+
'lens.currentContext': '当前上下文',
|
|
82
|
+
'lens.recentRead': '最近读取',
|
|
83
|
+
'lens.recentNone': '暂无记录',
|
|
84
|
+
'lens.outsideDocs': '上下文外读取',
|
|
85
|
+
'lens.more': '还有 {n} 篇',
|
|
86
|
+
'lens.openDoc': '打开 {rel}',
|
|
87
|
+
'lens.delta': '上下文变化',
|
|
88
|
+
'lens.locate': '定位到{tier}上下文',
|
|
89
|
+
// 读屏专用(md §六十三):**屏幕上不出现这句话**,视觉给的是「层名 + n / m + 圆点」。
|
|
90
|
+
'lens.coverageAria': '{tier}上下文:{read} / {total} 篇已读',
|
|
91
|
+
// 上下文变化那一行的右侧说明(md §三十八「上下文变化 最近一次 ›」):
|
|
92
|
+
// 变化永远只说**最近一次**,所以这里不写条数(条数由展开后的行数承担)。
|
|
93
|
+
'lens.deltaLatest': '最近一次',
|
|
94
|
+
|
|
95
|
+
// ── v0.17 文档生命周期(Document Lifecycle)──────────────────
|
|
96
|
+
// ⚠️ 四态全是**事实**,不是评价:「读后已更新」只说「文件在最后一次成功读取之后
|
|
97
|
+
// 变过」,绝不许写成「Agent 还不知道最新版本」「Agent 用了旧版本」这类推断。
|
|
98
|
+
// ⚠️ 「上下文外读取」只陈述「这篇不在当前包内、但被成功读过」。
|
|
99
|
+
// ⚠️ `readCountShort` 是给行尾用的:行首的 glyph 已经说了「读过了」,
|
|
100
|
+
// 行尾只需要补一个「几次」—— 再说一遍「已读」是重复信息。
|
|
101
|
+
'usage.deltaEnter': '进入',
|
|
102
|
+
'usage.deltaLeave': '离开',
|
|
103
|
+
'usage.deltaMove': '换层',
|
|
104
|
+
'usage.deltaTask': '任务上下文已更新',
|
|
105
|
+
'usage.deltaMore': '还有 {n} 条',
|
|
106
|
+
'lifecycle.unread': '未读',
|
|
107
|
+
'lifecycle.read': '已读',
|
|
108
|
+
'lifecycle.readCount': '已读 ×{n}',
|
|
109
|
+
'lifecycle.readCountShort': '×{n}',
|
|
110
|
+
'lifecycle.updatedAfterRead': '读后已更新',
|
|
111
|
+
'lifecycle.rereadAfterUpdate': '修改后已重新读取',
|
|
112
|
+
'tierName.primary': '主要',
|
|
113
|
+
'tierName.supporting': '辅助',
|
|
114
|
+
'tierName.related': '相关',
|
|
115
|
+
|
|
68
116
|
// ── v0.14 当前任务上下文(Context Pack)──────────────────────
|
|
69
117
|
// ⚠️ 文案纪律:不出现「AI / 智能 / 推荐 / 置信度 / 百分比」。
|
|
70
118
|
// 这一层是确定性规则算出来的,说成 AI 就是在骗用户。也不能放表情符号
|
|
@@ -193,7 +241,10 @@ window.__ModuleLoader__.load({
|
|
|
193
241
|
|
|
194
242
|
'kind.all': 'All',
|
|
195
243
|
'kind.doc': 'Docs',
|
|
196
|
-
|
|
244
|
+
// 2026-10-06: user picked 「媒体」 for the tab + the "All" section title, so English
|
|
245
|
+
// follows the same word as count.media ("{n} media"): the tab says Media, and the
|
|
246
|
+
// explicit "images and videos" wording stays in the empty state / README prose.
|
|
247
|
+
'kind.media': 'Media',
|
|
197
248
|
'kind.title': 'Switch which artifacts are listed',
|
|
198
249
|
|
|
199
250
|
'filter.placeholder': 'Filter docs',
|
|
@@ -202,15 +253,52 @@ window.__ModuleLoader__.load({
|
|
|
202
253
|
'usage.toggle': 'Usage',
|
|
203
254
|
'usage.toggleTitle': 'Measure this session: whether the primary doc was read, how many reads fell outside the pack, how often the context changed. Facts only — no score.',
|
|
204
255
|
'usage.none': 'Nothing recorded yet',
|
|
205
|
-
'usage.epoch': 'Context · Epoch {n}',
|
|
206
|
-
'usage.primaryRead': 'primary read ({rel})',
|
|
207
|
-
'usage.primaryUnread': 'primary not read yet ({rel})',
|
|
208
|
-
'usage.supporting': 'supporting {read}/{total}',
|
|
209
|
-
'usage.reads': '{n} reads',
|
|
210
|
-
'usage.outside': '{n} outside the pack',
|
|
211
|
-
'usage.changes': 'context changed {n}×',
|
|
212
256
|
'usage.note': 'This session only · kept in kernel memory, gone after a DSH restart',
|
|
213
257
|
|
|
258
|
+
// ── v0.18 Context Usage Lens ───────────────────────────────
|
|
259
|
+
// Answers exactly one question: how was the context Knit handed over actually
|
|
260
|
+
// consumed. ⚠️ Not a dashboard: no KPI figures, no percentages, no scores, no
|
|
261
|
+
// charts, no progress bars, no "usage rate / health / confidence". Every line is
|
|
262
|
+
// a fact, never a judgement — and "recent read" is not "currently reading".
|
|
263
|
+
'lens.title': 'Usage',
|
|
264
|
+
'lens.expand': 'Expand usage',
|
|
265
|
+
'lens.collapse': 'Collapse usage',
|
|
266
|
+
'lens.epoch': 'Epoch {n}',
|
|
267
|
+
'lens.reads': '{n} reads',
|
|
268
|
+
'lens.outside': '{n} outside the pack',
|
|
269
|
+
'lens.changes': 'context changed {n}×',
|
|
270
|
+
'lens.currentContext': 'Current context',
|
|
271
|
+
'lens.recentRead': 'Recent read',
|
|
272
|
+
'lens.recentNone': 'Nothing yet',
|
|
273
|
+
'lens.outsideDocs': 'Reads outside context',
|
|
274
|
+
'lens.more': '{n} more',
|
|
275
|
+
'lens.openDoc': 'Open {rel}',
|
|
276
|
+
'lens.delta': 'Context changes',
|
|
277
|
+
'lens.locate': 'Locate {tier} context',
|
|
278
|
+
'lens.coverageAria': '{tier} context: {read} / {total} read',
|
|
279
|
+
'lens.deltaLatest': 'Latest',
|
|
280
|
+
|
|
281
|
+
// ── v0.17 document lifecycle ───────────────────────────────
|
|
282
|
+
// ⚠️ All four states are facts, never judgements: "Updated after read" only says the
|
|
283
|
+
// file changed after the last successful read. Never "the agent has not seen the
|
|
284
|
+
// latest version" or "the agent used a stale copy" — that would be inference.
|
|
285
|
+
// ⚠️ `readCountShort` is for the row tail: the leading glyph already says it was
|
|
286
|
+
// read, so the tail only adds the count — repeating "read" would be redundant.
|
|
287
|
+
'usage.deltaEnter': 'Entered',
|
|
288
|
+
'usage.deltaLeave': 'Left',
|
|
289
|
+
'usage.deltaMove': 'Moved tier',
|
|
290
|
+
'usage.deltaTask': 'Task context updated',
|
|
291
|
+
'usage.deltaMore': '+{n} more',
|
|
292
|
+
'lifecycle.unread': 'Unread',
|
|
293
|
+
'lifecycle.read': 'Read',
|
|
294
|
+
'lifecycle.readCount': 'Read ×{n}',
|
|
295
|
+
'lifecycle.readCountShort': '×{n}',
|
|
296
|
+
'lifecycle.updatedAfterRead': 'Updated after read',
|
|
297
|
+
'lifecycle.rereadAfterUpdate': 'Re-read after update',
|
|
298
|
+
'tierName.primary': 'Primary',
|
|
299
|
+
'tierName.supporting': 'Supporting',
|
|
300
|
+
'tierName.related': 'Related',
|
|
301
|
+
|
|
214
302
|
// ── v0.14 current-task context (Context Pack) ──────────────
|
|
215
303
|
// ⚠️ Never say "AI", "smart", "recommended", "confidence" or show percentages:
|
|
216
304
|
// this tiering is deterministic local rules, and pretending otherwise is a lie.
|
|
@@ -575,35 +663,201 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
575
663
|
.knit-head .knit-root-path:disabled{cursor:default;text-decoration:none}
|
|
576
664
|
.knit-count{font-size:11px;color:var(--dsw-alias-label-caption,#80868b);flex:none}
|
|
577
665
|
.knit-btn{flex:none;display:inline-flex;align-items:center;justify-content:center;
|
|
578
|
-
height:
|
|
666
|
+
height:28px;padding:0 10px;border-radius:8px;cursor:pointer;
|
|
579
667
|
background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);
|
|
580
|
-
border:.5px solid var(--dsw-alias-border-l4,rgba(255,255,255,.08));font-size:
|
|
668
|
+
border:.5px solid var(--dsw-alias-border-l4,rgba(255,255,255,.08));font-size:12px;
|
|
669
|
+
transition:background .16s ease,color .16s ease}
|
|
581
670
|
.knit-btn:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03));
|
|
582
671
|
color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
583
672
|
.knit-btn.active{background:var(--knit-active-bg,rgba(255,255,255,.085));
|
|
584
673
|
color:var(--dsw-alias-label-primary,#e8eaed);border-color:var(--dsw-alias-border-l4,rgba(255,255,255,.22))}
|
|
674
|
+
/* 排序切换与搜索框:v0.18 UI 迭代(md §四~§六)把这两个控件**按输入控件的尺度重做** ——
|
|
675
|
+
圆角 10px / 字号 13px。原来那套 22px 迷你胶囊读起来像「标签」而不是控件,
|
|
676
|
+
与 14px 的页签、15px 的 Usage 标题差了两档,是「审美欠缺」最直观的一处。
|
|
677
|
+
⚠️ 高度:md 写 36px,2026-10-06 用户看了真机后定成 **28px**(「太高了,不需要这么高」),
|
|
678
|
+
与左边的「使用情况 / 刷新」同高。
|
|
679
|
+
⚠️ 描边色:用 **--dsw-alias-border-l3**,与 DSH 主区「对话」页签下面那条横线(官方
|
|
680
|
+
.wSkVaW_header 的 border-bottom: .5px solid rgba(0,0,0,.12) = 浅色下的 border-l3)
|
|
681
|
+
同一个 token —— 2026-10-06 用户要求「描边色值改成跟那条横一样」。不用更深的 l4:
|
|
682
|
+
l4(浅色 rgba(0,0,0,.161))比官方分割线重一档,摆在页签下面像两个输入框框住了内容。
|
|
683
|
+
⚠️ 描边粗细:**0.5px**(2026-10-06 用户第二轮要求「描边色值修改成 0.5px」)—— 官方那条
|
|
684
|
+
横本身就是 .5px,色值对上而粗细仍写 1px,高分屏上比它粗一倍。三处同粗:.knit-seg
|
|
685
|
+
外框、.knit-seg 内部竖线、.knit-filter。CSS 里统一写 0.5px(与官方 .wSkVaW_header 的 .5px 同值)。
|
|
686
|
+
⚠️ 选中态只改**底色 + 字重 600**(不是 700),hover 只改底色 —— 不许 scale / translate /
|
|
687
|
+
box-shadow(md §五)。暗色下靠 --knit-active-bg 这个 token,不写死颜色。 */
|
|
585
688
|
.knit-bar{display:flex;align-items:center;gap:8px;padding:0 12px 8px;flex:none}
|
|
586
|
-
.knit-seg{display:inline-flex;flex:none;border-radius:
|
|
587
|
-
border
|
|
588
|
-
.knit-seg-btn{height:
|
|
589
|
-
background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6)
|
|
689
|
+
.knit-seg{display:inline-flex;flex:none;border-radius:10px;overflow:hidden;
|
|
690
|
+
border:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
691
|
+
.knit-seg-btn{height:28px;padding:0 15px;cursor:pointer;font-size:13px;font-weight:400;
|
|
692
|
+
border:none;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);
|
|
693
|
+
transition:background .16s ease,color .16s ease}
|
|
694
|
+
.knit-seg-btn + .knit-seg-btn{border-left:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))}
|
|
590
695
|
.knit-seg-btn:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
591
696
|
.knit-seg-btn.active{background:var(--knit-active-bg,rgba(255,255,255,.085));
|
|
592
697
|
color:var(--dsw-alias-label-primary,#e8eaed);font-weight:600}
|
|
593
|
-
.knit-filter{flex:1;min-width:0;height:
|
|
698
|
+
.knit-filter{flex:1;min-width:0;height:28px;padding:0 12px;border-radius:10px;font-size:13px;
|
|
594
699
|
background:transparent;color:var(--dsw-alias-label-primary,#e8eaed);
|
|
595
|
-
border
|
|
700
|
+
border:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12));outline:none;
|
|
701
|
+
transition:border-color .16s ease}
|
|
596
702
|
.knit-filter:focus{border-color:var(--knit-accent)}
|
|
597
703
|
.knit-filter::placeholder{color:var(--dsw-alias-label-caption,#80868b)}
|
|
598
|
-
/* v0.15
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
704
|
+
/* v0.15「使用情况」→ v0.18「Context Usage Lens」:**列表上方的一块轻量观察层**。
|
|
705
|
+
不是弹窗、不是新页面、不是 Dashboard、不画卡片、不画进度条、不用品牌色。
|
|
706
|
+
它占的是原来「相关性排序」那一行的位置 —— 2026-09-30 用户裁决那一行整个删掉
|
|
707
|
+
(排序方式由「相关 / 最新」那个切换按钮自己表达,再说一遍是重复),
|
|
708
|
+
于是它是类型页签下面、列表上面唯一的一块弱化信息,不是一块新面板。
|
|
602
709
|
⚠️ 全宽横线一律不画:2026-09-29 用户要求**减少全宽分割线** ——
|
|
603
|
-
「页面上横线一多,读起来就像文件管理表格」。层级由空间与字号建立。
|
|
604
|
-
.knit-
|
|
605
|
-
|
|
606
|
-
|
|
710
|
+
「页面上横线一多,读起来就像文件管理表格」。层级由空间与字号建立。
|
|
711
|
+
⚠️ 它**自己不滚动**:滚动统一交给 .knit-list —— 窄侧栏里滚轮套滚轮很难用。
|
|
712
|
+
⚠️ 这一条不许加 background / width / 品牌色(有守卫盯着,见 client.test.mjs)。 */
|
|
713
|
+
.knit-usage{flex:none;padding:12px 12px 10px;font-size:12px;line-height:1.5;
|
|
714
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
715
|
+
/* Lens 标题行:整行可点,展开 / 收起。**「使用情况」开关管统计开不开,
|
|
716
|
+
这一行管「统计开着但看不看细节」—— 两件事**(2026-10-05 规格 §25)。
|
|
717
|
+
v0.18 UI 迭代(2026-10-06,依 '02_方案与 Demo/dsh-knit V0.18 UI 重构开发提示词.md'
|
|
718
|
+
§七 / §四十七 的尺度表):标题 15px/600(它是这一块的**标题**,不是元信息)、
|
|
719
|
+
Epoch 12px 弱化靠右、**不做成 Badge**(不画底、不画边)。 */
|
|
720
|
+
.knit-lens-head{display:flex;align-items:baseline;gap:8px;width:100%;appearance:none;
|
|
721
|
+
border:0;background:none;margin:0;padding:0;font:inherit;cursor:pointer;text-align:left;
|
|
722
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
723
|
+
.knit-lens-head:hover{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
724
|
+
.knit-lens-head:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
725
|
+
.knit-lens-title{flex:none;font-size:15px;font-weight:600;line-height:20px;
|
|
726
|
+
color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
727
|
+
.knit-lens-epoch{flex:none;margin-left:auto;font-size:12px;font-weight:400;line-height:20px;
|
|
728
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
729
|
+
/* 摘要行:三件事实,一行。放不下就省略号 —— 绝不换行把列表顶下去。
|
|
730
|
+
12px/18px、与标题 4~6px(md §九 / §十)。 */
|
|
731
|
+
.knit-lens-sum{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
|
|
732
|
+
margin-top:5px;font-size:12px;line-height:18px}
|
|
733
|
+
.knit-lens-sec{margin-top:13px}
|
|
734
|
+
.knit-lens-name{margin-bottom:6px;font-size:12px;font-weight:500;
|
|
735
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
736
|
+
/* 「当前上下文」这一句是**分节标题**(比层名与行标签高一档,md §十三:13px/500);
|
|
737
|
+
距摘要行 12~14px 由 .knit-lens-sec 的 margin-top 给。 */
|
|
738
|
+
.knit-lens-cap{margin-bottom:6px;font-size:13px;font-weight:500;
|
|
739
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
740
|
+
/* 当前上下文 Coverage:三层各「层名 + 已读 ÷ 总数 + 状态点」。
|
|
741
|
+
v0.18 UI 迭代(md §十二~§十九):三层用 '1fr 1.2fr 1.8fr' 的**网格**(Related 通常
|
|
742
|
+
最多),层名与 'n / m' 落在**同一行**(数值右对齐),状态点是**真的 9px 圆点** ——
|
|
743
|
+
不再是 '○ ●' 字符:字符圆点在不同字体 / 字号下大小不一,正是「不像设计稿」的那一处。
|
|
744
|
+
⚠️ 不是三张 Card:默认不画底、不画边,只有 hover 时一层很淡的底(md §十三 / §五十一)。
|
|
745
|
+
⚠️ 分母是这一层当前真实几篇:Primary 不存在时整列不显示(不画 0 / 0 的假层)。 */
|
|
746
|
+
.knit-cov{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.2fr) minmax(0,1.8fr);
|
|
747
|
+
column-gap:14px;align-items:start;margin:0 -8px}
|
|
748
|
+
.knit-cov-col{display:grid;grid-template-columns:1fr auto;column-gap:8px;row-gap:7px;
|
|
749
|
+
align-items:center;appearance:none;border:0;margin:0;padding:6px 8px;
|
|
750
|
+
background:transparent;font:inherit;cursor:pointer;text-align:left;border-radius:10px;
|
|
751
|
+
color:var(--dsw-alias-label-caption,#80868b);transition:background .16s ease}
|
|
752
|
+
.knit-cov-col:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
753
|
+
.knit-cov-col:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
754
|
+
.knit-cov-name{grid-column:1;min-width:0;overflow:hidden;text-overflow:ellipsis;
|
|
755
|
+
white-space:nowrap;font-size:12px;font-weight:500;
|
|
756
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
757
|
+
/* 状态点:**真 CSS 圆** —— 未读=空心环(1px 中性边)、已读=中性填充;'○→●' 只做
|
|
758
|
+
background / border-color 两笔 220ms 过渡,不弹跳、不闪烁。
|
|
759
|
+
⚠️ 轮询不动数据就不动 className,于是补间不会被重播。
|
|
760
|
+
⚠️ 只用中性 token:没有绿 / 红 / 黄 / 蓝 —— 读没读过不是「好 / 坏」(PRD §7.3)。
|
|
761
|
+
⚠️ 与文档行里的 .knit-glyph-mark **同一对 token、同一个直径**:md §二十九 要求
|
|
762
|
+
生命周期那枚空心圆与这里的空心圆「视觉完全一致」。 */
|
|
763
|
+
.knit-cov-dots{grid-column:1 / -1;display:flex;flex-wrap:wrap;gap:6px;row-gap:5px;
|
|
764
|
+
min-height:6px;align-items:center}
|
|
765
|
+
/* ⚠️ 圆点直径 6px(2026-10-06 用户定:「9px 真圆请改成 6px」)。
|
|
766
|
+
Coverage 与文档行的 glyph 必须**同一个直径、同一对 token**(守卫会比对两处)。 */
|
|
767
|
+
.knit-cov-dot{flex:none;display:block;width:6px;height:6px;border-radius:50%;
|
|
768
|
+
border:1px solid var(--dsw-alias-label-caption,#80868b);background:transparent;
|
|
769
|
+
transition:background .22s ease,border-color .22s ease}
|
|
770
|
+
.knit-cov-dot.on{background:var(--dsw-alias-label-caption,#80868b);
|
|
771
|
+
border-color:var(--dsw-alias-label-caption,#80868b)}
|
|
772
|
+
.knit-cov-num{grid-column:2;text-align:right;font-size:11px;font-weight:400;
|
|
773
|
+
font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-caption,#80868b)}
|
|
774
|
+
/* 最近读取:**可点的一行**(文件名 · 相对时间 ›)。整行可点、hover 只改底色。
|
|
775
|
+
v0.18 UI 迭代(md §二十一 / §二十二):高 38px、左右 10px、圆角 8px、
|
|
776
|
+
文件 12px、时间 11px、箭头 16px。
|
|
777
|
+
⚠️ 语义仍是「最近一次成功 read」:文案不许写成「当前正在阅读」。 */
|
|
778
|
+
.knit-read-row{display:flex;align-items:center;gap:10px;width:100%;appearance:none;
|
|
779
|
+
border:0;background:none;margin:0;padding:0 10px;height:38px;border-radius:8px;font:inherit;
|
|
780
|
+
text-align:left;cursor:pointer;color:var(--dsw-alias-label-primary,#e8eaed);
|
|
781
|
+
transition:background .16s ease}
|
|
782
|
+
.knit-read-row:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
783
|
+
.knit-read-row:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
784
|
+
.knit-read-rel{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;
|
|
785
|
+
white-space:nowrap;font-size:12px}
|
|
786
|
+
.knit-read-time{flex:none;font-size:11px;color:var(--dsw-alias-label-caption,#80868b)}
|
|
787
|
+
.knit-read-go{flex:none;font-size:16px;line-height:1;
|
|
788
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
789
|
+
.knit-lens-empty{opacity:.75}
|
|
790
|
+
/* 包外读取:每一行都是**可点对象**(点开预览),但不许加入 Context ——
|
|
791
|
+
V0.18 不做 Context Control,这里是「看一眼」,不是「改上下文」。
|
|
792
|
+
v0.18 UI 迭代(md §三十四~§三十七):展开后逐行
|
|
793
|
+
'01 docs/… ×3 已读'(序号 + 路径 + 次数 + 状态),11px、行内不画线。 */
|
|
794
|
+
.knit-out-row{display:flex;align-items:center;gap:9px;width:100%;appearance:none;
|
|
795
|
+
border:0;background:none;margin:0;padding:5px 9px 5px 17px;border-radius:8px;font:inherit;
|
|
796
|
+
text-align:left;cursor:pointer;color:var(--dsw-alias-label-caption,#80868b);
|
|
797
|
+
transition:background .16s ease}
|
|
798
|
+
.knit-out-row:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03));
|
|
799
|
+
color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
800
|
+
.knit-out-row:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
801
|
+
.knit-out-num{flex:none;width:18px;text-align:right;font-size:11px;
|
|
802
|
+
font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-caption,#80868b);opacity:.75}
|
|
803
|
+
.knit-out-rel{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;
|
|
804
|
+
white-space:nowrap;font-size:11px}
|
|
805
|
+
.knit-out-count{flex:none;font-size:11px;font-variant-numeric:tabular-nums}
|
|
806
|
+
/* 行内生命周期 glyph(v0.17 起):**极小、中性、不抢标题**。点它 = 打开 / 选中这篇。
|
|
807
|
+
v0.18 UI 迭代(md §二十七~§二十九):四态改成与 Coverage **同一套**圆点语言 ——
|
|
808
|
+
未读=空心环、已读=实心、读后已更新=空心环 + 中心点、修改后已重新读取= ↻ 字符。
|
|
809
|
+
两者用同一对 token、同一个 9px 直径,所以「同一套状态语言」不靠自觉。
|
|
810
|
+
⚠️ 类名不能叫 knit-life-*:byClass 是子串匹配,会和 .knit-life 撞。 */
|
|
811
|
+
.knit-glyph{flex:none;display:inline-flex;align-items:center;justify-content:center;
|
|
812
|
+
appearance:none;border:0;background:none;margin:0;padding:0;width:14px;height:18px;
|
|
813
|
+
cursor:pointer;color:var(--dsw-alias-label-caption,#80868b)}
|
|
814
|
+
.knit-glyph:hover{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
815
|
+
.knit-glyph:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
816
|
+
.knit-glyph-mark{flex:none;display:block;width:6px;height:6px;border-radius:50%;
|
|
817
|
+
border:1px solid var(--dsw-alias-label-caption,#80868b);background:transparent;
|
|
818
|
+
transition:background .22s ease,border-color .22s ease}
|
|
819
|
+
.knit-glyph-mark[data-mark="read"]{background:var(--dsw-alias-label-caption,#80868b)}
|
|
820
|
+
.knit-glyph-mark[data-mark="updated"]{position:relative}
|
|
821
|
+
.knit-glyph-mark[data-mark="updated"]::after{content:'';position:absolute;inset:1.5px;
|
|
822
|
+
border-radius:50%;background:var(--dsw-alias-label-caption,#80868b)}
|
|
823
|
+
.knit-glyph-mark[data-mark="reread"]{width:9px;height:9px;border:0;background:transparent;
|
|
824
|
+
font-size:9px;line-height:9px;text-align:center}
|
|
825
|
+
/* Coverage 点某一层 → 那一层**短暂高亮**(空间定位,不画横线、不加箭头)。
|
|
826
|
+
1200ms 轻微背景(md §十七原写 500~700ms,2026-10-06 用户看真机后定成 1200ms),
|
|
827
|
+
不许闪红、不许位移。CSS transition 的时长必须与 FLASH_MS 一致,否则会出现「已经取消高亮
|
|
828
|
+
但背景还在慢慢褪」的错帧。 */
|
|
829
|
+
.knit-tier{transition:background 1.2s ease}
|
|
830
|
+
.knit-tier.flash{background:var(--knit-hover-bg,rgba(255,255,255,.03));border-radius:10px}
|
|
831
|
+
|
|
832
|
+
/* v0.17 文档生命周期(Document Lifecycle)—— 三条新信息,都只是**事实**。
|
|
833
|
+
⚠️ 状态是文字,不是徽章:不加底色、不加边框、不用红绿 —— 红绿会把「事实」读成
|
|
834
|
+
「好 / 坏」(PRD §7.3)。永远不抢标题(标题 14px)。
|
|
835
|
+
v0.18 UI 迭代:10.5px → **11px** —— md §四十七 的尺度表里最小一档就是 11px。
|
|
836
|
+
⚠️ 折叠块沿用 .knit-usage 的弱化灰阶:它们是同一行事实的展开,不是新卡片。
|
|
837
|
+
⚠️ 这一段**不含反引号**,整段可以直接放在 CSS 模板串里。 */
|
|
838
|
+
.knit-life{flex:none;font-size:11px;line-height:1.4;white-space:nowrap;
|
|
839
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
840
|
+
.knit-usage-more{margin-top:10px}
|
|
841
|
+
/* 菜单式展开行(包外读取 / 上下文变化):整行可点、高 38px、圆角 8px、hover 只改底色;
|
|
842
|
+
左边是标题,右边是「数量 / 最近一次 + ›」,展开后箭头换成 ⌃(md §三十四 / §三十八)。 */
|
|
843
|
+
.knit-more-btn{display:flex;align-items:center;gap:10px;width:100%;
|
|
844
|
+
appearance:none;border:0;background:none;margin:0;padding:0 10px;height:38px;
|
|
845
|
+
border-radius:8px;font:inherit;font-size:12px;line-height:1;cursor:pointer;text-align:left;
|
|
846
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6);transition:background .16s ease}
|
|
847
|
+
.knit-more-btn:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03));
|
|
848
|
+
color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
849
|
+
.knit-more-btn:focus-visible{outline:1px solid var(--knit-accent);outline-offset:1px}
|
|
850
|
+
.knit-more-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;
|
|
851
|
+
white-space:nowrap}
|
|
852
|
+
.knit-more-meta{flex:none;font-size:11px;font-variant-numeric:tabular-nums;
|
|
853
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
854
|
+
.knit-gap-row,.knit-delta-row{display:flex;gap:9px;align-items:baseline;
|
|
855
|
+
padding:3px 9px 3px 17px;font-size:11px;
|
|
856
|
+
color:var(--dsw-alias-label-caption,#80868b)}
|
|
857
|
+
.knit-gap-rel,.knit-delta-rel{flex:1 1 auto;min-width:0;overflow:hidden;
|
|
858
|
+
text-overflow:ellipsis;white-space:nowrap}
|
|
859
|
+
.knit-delta-head{margin-top:8px;padding:0 9px 0 17px;font-size:11px;font-weight:500;
|
|
860
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
607
861
|
|
|
608
862
|
|
|
609
863
|
/* ── v0.14 右栏(Context Pack 面板)已整体删除(2026-09-29)────────
|
|
@@ -639,7 +893,7 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
639
893
|
.knit-tierhint{font-weight:400}
|
|
640
894
|
/* 「为什么在这里」:比摘要更弱的一行,只在 Context Pack 的条目上出现。
|
|
641
895
|
11px 而不是 10px,因为它承担的是**信息**(可核验的理由),不是装饰标注。 */
|
|
642
|
-
.knit-why{padding-top:2px;font-size:11px;line-height:
|
|
896
|
+
.knit-why{padding-top:2px;font-size:11px;line-height:17px;color:var(--dsw-alias-text-tertiary)}
|
|
643
897
|
/* 滚动条**不要自己画**:DSH 主题里已有全局样式
|
|
644
898
|
(::-webkit-scrollbar 宽 8px + --dsh-scrollbar-thumb,见 dsh-client-ui-theme)。
|
|
645
899
|
曾经在这里写死 6px 宽 + rgba(255,255,255,.14) 的滑块 —— 白色 14% 在白底上完全隐形,
|
|
@@ -688,6 +942,18 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
688
942
|
再加描边会与 .active 的整块背景重复,显得突兀。
|
|
689
943
|
(曾经有一条 「.knit-multicol .knit-doc.cursor」 的中性环,是为多列网格补的 ——
|
|
690
944
|
多列没了,那条也删了。) */
|
|
945
|
+
/* ── 列表进出动效的**静态**部分(v0.17,2026-10-03 用户要求)───────────────
|
|
946
|
+
补间本身在 JS 里用 WAAPI 跑(见 client.js 的 DocRow 与 MOTION_* 那段)—— 高度要按
|
|
947
|
+
量出来的自然高度补间,CSS 的 @keyframes 做不到(height:auto 不可插值)。这里只管两件事:
|
|
948
|
+
① .leaving =正在离开的幽灵行:不吃指针事件、内容裁掉;
|
|
949
|
+
② 系统开了「减弱动态效果」时,连底色过渡一起去掉(进出本来就不播)。 */
|
|
950
|
+
.knit-doc.leaving{pointer-events:none;user-select:none;overflow:hidden}
|
|
951
|
+
@media (prefers-reduced-motion: reduce){
|
|
952
|
+
.knit-doc{transition:none}
|
|
953
|
+
.knit-cov-dots,.knit-cov-dot{transition:none}
|
|
954
|
+
.knit-tier,.knit-tier.flash{transition:none}
|
|
955
|
+
.knit-cov-col,.knit-read-row,.knit-out-row,.knit-more-btn,.knit-glyph-mark{transition:none}
|
|
956
|
+
}
|
|
691
957
|
/* 行一=**标题行**:Primary 点 + 标题 + 相对时间(**时间靠右**)。
|
|
692
958
|
2026-09-29 这一天里这一行改了三次:先是「序号 + 标题 + 时间」,然后
|
|
693
959
|
「时间跟那个置顶的序号可以一行」(序号留下、标题移出去),再后来
|
|
@@ -707,7 +973,7 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
707
973
|
它=.knit-title 的 14px × 1.4。格的 align-items:start 让这一列从卡片顶边
|
|
708
974
|
开始排,所以只要这个行盒与标题行盒等高,两个字号不同的文本就自然居中。
|
|
709
975
|
**改 .knit-title 的字号或行高时,这里必须同步改**,否则序号会与标题错开。 */
|
|
710
|
-
.knit-num,.knit-gapmark{grid-column:1;font-size:
|
|
976
|
+
.knit-num,.knit-gapmark{grid-column:1;font-size:11px;line-height:19.6px;font-variant-numeric:tabular-nums;
|
|
711
977
|
color:var(--dsw-alias-label-caption,#80868b)}
|
|
712
978
|
/* 中性占位标记(2026-10-01 用户反馈):「其他相关文档」那一节没有序号,空着的那一格
|
|
713
979
|
被读成「漏了一个号」(原话:「没有序号以后左边就空了,视觉上比较割裂,就觉得是个 bug 一样」)。
|
|
@@ -725,7 +991,7 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
725
991
|
⚠️ 这条推翻了同一天早先的写法(那时候时间跟在点后面左对齐,理由是
|
|
726
992
|
「元信息行读起来像一句话」)—— 时间现在和标题同一行,左对齐会把标题夹在中间。
|
|
727
993
|
靠 .knit-title 的 flex:1 1 auto 把时间挤到行尾;这里只要 flex:none 不被压扁。 */
|
|
728
|
-
.knit-time{flex:none;font-size:
|
|
994
|
+
.knit-time{flex:none;font-size:11px;color:var(--dsw-alias-label-caption,#80868b)}
|
|
729
995
|
/* 标题现在和 Primary 点、时间**同行**(见 .knit-row1 的说明;margin-bottom 移到了那一行)。
|
|
730
996
|
仍是单行省略 —— 列表是扫读用的,想看全标题就预览或打开;折行会让每条卡高度不一,
|
|
731
997
|
「移动到下一项」的位移就没法预期。
|
|
@@ -733,7 +999,7 @@ body[data-ds-dark-theme] .knit-root{
|
|
|
733
999
|
去掉 min-width:0,标题会把整行撑宽(省略号失效);去掉 flex-grow,时间会紧贴标题而不是靠右。 */
|
|
734
1000
|
.knit-title{flex:1 1 auto;min-width:0;font-weight:600;font-size:14px;line-height:1.4;
|
|
735
1001
|
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
736
|
-
.knit-sum{font-size:12px;line-height:
|
|
1002
|
+
.knit-sum{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#9aa0a6);
|
|
737
1003
|
display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
738
1004
|
.knit-sum.empty{font-style:italic;color:var(--dsw-alias-label-caption,#80868b)}
|
|
739
1005
|
/* ── 列表行里为什么没有路径(2026-09-29) ────────────────────
|
|
@@ -861,9 +1127,9 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
|
|
|
861
1127
|
2px 下划线表达,页签条本身不画线(也不是「下划线悬空」:它画在自己的文字下面)。
|
|
862
1128
|
⚠️ 排序切换(.knit-seg-btn,Design §18)是**另一个控件**,它保持灰底不变。 */
|
|
863
1129
|
.knit-types{display:flex;gap:14px;padding:0 12px;flex:none}
|
|
864
|
-
.knit-type-btn{flex:none;height:
|
|
1130
|
+
.knit-type-btn{flex:none;height:30px;padding:0;cursor:pointer;
|
|
865
1131
|
border:none;border-bottom:2px solid transparent;background:transparent;
|
|
866
|
-
color:var(--dsw-alias-label-secondary,#9aa0a6);font-family:inherit;font-size:
|
|
1132
|
+
color:var(--dsw-alias-label-secondary,#9aa0a6);font-family:inherit;font-size:14px;
|
|
867
1133
|
white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
|
|
868
1134
|
transition:color .15s,border-color .15s}
|
|
869
1135
|
.knit-type-btn:hover{color:var(--dsw-alias-label-primary,#e8eaed)}
|
|
@@ -1347,16 +1613,373 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1347
1613
|
return `knit-opt-${safe}-${(hash >>> 0).toString(36)}`
|
|
1348
1614
|
}
|
|
1349
1615
|
|
|
1350
|
-
|
|
1616
|
+
/* ── v0.18 Context Usage Lens 的纯函数 ────────────────────────────
|
|
1617
|
+
这一层只把**已经有的事实**重新组织一遍:不新增采集、不新增存储、不新增事件、
|
|
1618
|
+
不新增第二个生命周期口径。「能派生就不要存储」—— Coverage 是拿当前 Context
|
|
1619
|
+
Pack 的三层 rels 加上 `usage.lifecycle` **现算**出来的,没有任何一份自己的 state。
|
|
1620
|
+
⚠️ 全部是纯函数(不吃 React、不读 DOM),所以测试可以直接对拍。
|
|
1621
|
+
⚠️ 这一段**不含反引号**,整段可以直接放进 CSS/代码模板串里。 */
|
|
1622
|
+
|
|
1623
|
+
/** 生命周期四态的 glyph。**不是颜色、不是徽章** —— 它只是一枚字符。
|
|
1624
|
+
* ⚠️ 四态一律中性:不许「绿=已读 / 红=未读 / 黄=更新」——
|
|
1625
|
+
* 生命周期是**事实**,不是风险等级(PRD §7.3)。 */
|
|
1626
|
+
const LIFE_GLYPH = {
|
|
1627
|
+
unread: '○',
|
|
1628
|
+
read: '●',
|
|
1629
|
+
updated_after_read: '△',
|
|
1630
|
+
reread_after_update: '↻',
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/** 某篇的读取状态:**没有记录就是未读**(这是事实,不是猜测)。
|
|
1634
|
+
* 认不出的状态一律退回 `unread` —— 宿主加了新状态时,界面显示「未读」而不是空白。 */
|
|
1635
|
+
function lifeStatusOf(lifecycle, rel) {
|
|
1636
|
+
const row = lifecycle && typeof lifecycle === 'object' ? lifecycle[rel] : null
|
|
1637
|
+
const status = row && typeof row.status === 'string' ? row.status : 'unread'
|
|
1638
|
+
return LIFE_GLYPH[status] ? status : 'unread'
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
/** Coverage:三层各自的 `{ total, read, rels }`。
|
|
1642
|
+
* `tierRels` = `{ primary: [...rel], supporting: [...], related: [...] }`;
|
|
1643
|
+
* `rels` 里每一项带 `read` 布尔(状态点要用它)。
|
|
1644
|
+
* ⚠️ 分母是**这一层当前真实有几篇**,不是 Context Pack 的 `matched/total`;
|
|
1645
|
+
* 所以 Primary 不存在时是 `{ total: 0, read: 0, rels: [] }`,面板显示 `0 / 0`
|
|
1646
|
+
* —— Knit 不能假设每一份上下文都有 Primary。 */
|
|
1647
|
+
function coverageOf(tierRels, lifecycle) {
|
|
1648
|
+
const out = {}
|
|
1649
|
+
for (const key of ['primary', 'supporting', 'related']) {
|
|
1650
|
+
const list = tierRels && Array.isArray(tierRels[key]) ? tierRels[key] : []
|
|
1651
|
+
const rels = []
|
|
1652
|
+
let read = 0
|
|
1653
|
+
for (const item of list) {
|
|
1654
|
+
const rel = typeof item === 'string' ? item : (item && item.rel)
|
|
1655
|
+
if (!rel) continue
|
|
1656
|
+
const isRead = lifeStatusOf(lifecycle, rel) !== 'unread'
|
|
1657
|
+
if (isRead) read += 1
|
|
1658
|
+
rels.push({ rel, read: isRead })
|
|
1659
|
+
}
|
|
1660
|
+
out[key] = { total: rels.length, read, rels }
|
|
1661
|
+
}
|
|
1662
|
+
return out
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/** 包外读取的**事实排序**:读得最多的在前,同次数按**最后读**的先后。
|
|
1666
|
+
* ⚠️ 宿主回的是**首次读的顺序**(`seq` = firstRead.seq,阅读顺序);面板要回答的是
|
|
1667
|
+
* 「哪几篇被反复读」—— 两件事,所以在客户端重排,不动宿主。
|
|
1668
|
+
* ⚠️ 载荷里没有 `lastRead.seq`(只有首次读的 `seq` 与 `lastReadAt`),
|
|
1669
|
+
* 于是同计数时按 `lastReadAt` 降序 —— 它对应的就是规格里的「最后读的那一次更靠前」。 */
|
|
1670
|
+
function groupOutsideDocs(outsideDocs) {
|
|
1671
|
+
const list = Array.isArray(outsideDocs) ? outsideDocs.slice() : []
|
|
1672
|
+
return list.sort((a, b) => {
|
|
1673
|
+
const ca = Number(a && a.count) || 0
|
|
1674
|
+
const cb = Number(b && b.count) || 0
|
|
1675
|
+
if (cb !== ca) return cb - ca
|
|
1676
|
+
const ta = Number(a && a.lastReadAt) || 0
|
|
1677
|
+
const tb = Number(b && b.lastReadAt) || 0
|
|
1678
|
+
if (tb !== ta) return tb - ta
|
|
1679
|
+
const sa = Number(a && a.seq) || 0
|
|
1680
|
+
const sb = Number(b && b.seq) || 0
|
|
1681
|
+
if (sb !== sa) return sb - sa
|
|
1682
|
+
return String((a && a.rel) || '').localeCompare(String((b && b.rel) || ''))
|
|
1683
|
+
})
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
/** 最近一次 Context Delta 按「进 / 出 / 换层」拆开(只拆,不排序、不丢弃)。
|
|
1687
|
+
* ⚠️ v0.15 那种把 `appeared` 写成**字符串数组**的旧载荷也认 ——
|
|
1688
|
+
* 客户端不能因为宿主版本不同就崩。 */
|
|
1689
|
+
function groupDelta(delta) {
|
|
1690
|
+
const out = { enter: [], leave: [], move: [] }
|
|
1691
|
+
if (!delta) return out
|
|
1692
|
+
const push = (target, item) => {
|
|
1693
|
+
const rel = typeof item === 'string' ? item : (item && item.rel)
|
|
1694
|
+
if (!rel) return
|
|
1695
|
+
target.push(typeof item === 'string' ? { rel } : item)
|
|
1696
|
+
}
|
|
1697
|
+
for (const item of Array.isArray(delta.appeared) ? delta.appeared : []) push(out.enter, item)
|
|
1698
|
+
for (const item of Array.isArray(delta.disappeared) ? delta.disappeared : []) push(out.leave, item)
|
|
1699
|
+
for (const item of Array.isArray(delta.moved) ? delta.moved : []) push(out.move, item)
|
|
1700
|
+
return out
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
/** 面板矮到这个高度以下就进「小高度」档:只留 Summary / Coverage / Recent Read,
|
|
1704
|
+
* Outside / Delta 收成标题(点开照常能用)。⚠️ 不是「藏起来」,是「别先占高度」。 */
|
|
1705
|
+
const COMPACT_PANEL_PX = 420
|
|
1706
|
+
/** 包外读取默认最多铺几行,其余折成「还有 N 篇」。 */
|
|
1707
|
+
const MAX_OUTSIDE_SHOWN = 10
|
|
1708
|
+
/** 上下文变化:收起时最多 3 条,展开后每个分类最多 5 条(v0.17 规则,保持不变)。 */
|
|
1709
|
+
const MAX_DELTA_SHOWN = 3
|
|
1710
|
+
const MAX_DELTA_GROUP = 5
|
|
1711
|
+
/** 点 Coverage 之后那一层高亮多久(毫秒)。只是「我把你送到这儿了」的一下提示。
|
|
1712
|
+
* v0.18 UI 迭代(md §十七):原写 500~700ms、取 650;2026-10-06 用户看真机后定成 **1200**,
|
|
1713
|
+
* 「停留久一点才看得清是哪一层」。CSS 里 `.knit-tier{transition:background 1.2s}` 必须同步。 */
|
|
1714
|
+
const FLASH_MS = 1200
|
|
1715
|
+
|
|
1716
|
+
/* ── 列表进出动效(v0.17)─────────────────────────────────────────
|
|
1717
|
+
用户原话(2026-10-03):「文档列表,新读取跟挤掉旧的未读的,这里的交互可能要优化,
|
|
1718
|
+
因为现在是一闪一闪的,就非常的快……如果说从当前的,如辅助上下文中新增,它应该是
|
|
1719
|
+
从低向上的,有种交互动效飞上的感觉,然后消失的时候从上到下,就隐掉了」。
|
|
1720
|
+
|
|
1721
|
+
手感来自 `02_方案与 Demo/knit-list-motion-prototype.html`(用户点头的那一版):
|
|
1722
|
+
缓动 cubic-bezier(.22,1,.36,1)、进入 translateY(26px)→0 + 渐现 + blur(3px)→0、
|
|
1723
|
+
离开高度收到 0 且**自上而下**擦掉。参数照抄原型,不要再另调。
|
|
1724
|
+
|
|
1725
|
+
⚠️ 只碰**文档行**(`.knit-doc`):媒体格子是网格布局,收起高度没有意义。
|
|
1726
|
+
⚠️ 补间用 WAAPI(`Element.animate`)手写,不用 @keyframes —— 高度要按量出来的
|
|
1727
|
+
自然高度补间,而 CSS 里 `height:auto` 不可插值。
|
|
1728
|
+
⚠️ 行节点是按 key 复用的(`doc.path || doc.rel`),所以「闪」不是重挂 —— 是增删
|
|
1729
|
+
瞬间落位、一点过渡都没有。因此动效分三件独立的事:**新来的行自己飞进来**、
|
|
1730
|
+
**走了的行留一个幽灵行把高度收掉**(React 一删节点就没机会补间了)、
|
|
1731
|
+
**活下来的行换了位置(换层 / 重排)走 FLIP** —— 量出新位置、先从老位置拉回来
|
|
1732
|
+
再补间归位,逻辑也在 `KnitBody` 那次提交后的 layout effect 里(那里才有列表)。 */
|
|
1733
|
+
const MOTION_ENTER_MS = 320
|
|
1734
|
+
const MOTION_EXIT_MS = 260
|
|
1735
|
+
const MOTION_STAGGER_MS = 45
|
|
1736
|
+
const MOTION_STAGGER_MAX = 6
|
|
1737
|
+
const MOTION_EASE = 'cubic-bezier(.22,1,.36,1)'
|
|
1738
|
+
/** 幽灵行所在的「区」:分层视图用层名,平铺与「全部」各一个 —— 幽灵要插回原位。 */
|
|
1739
|
+
const MOTION_TIER_FLAT = 'flat'
|
|
1740
|
+
const MOTION_TIER_ALL_DOCS = 'all-docs'
|
|
1741
|
+
/** 幸存行位移(换层 / 重排)的 FLIP 时长:比进入略长,它要真的「走」完一段距离。 */
|
|
1742
|
+
const MOTION_MOVE_MS = 340
|
|
1743
|
+
/** 位移小于这个像素数(含亚像素抖动)就当没动过,不排补间。 */
|
|
1744
|
+
const MOTION_MOVE_EPS = 0.5
|
|
1745
|
+
|
|
1746
|
+
/**
|
|
1747
|
+
* 这台机器上要不要播动效。
|
|
1748
|
+
*
|
|
1749
|
+
* 三种情况**不播**:没有 DOM(Node 里的测试替身)、浏览器/系统要求「减弱动态效果」、
|
|
1750
|
+
* 以及不认 WAAPI 的宿主。返回假时一行补间都不排、也不留幽灵行 —— 渲染树与没有这段动效时逐字一致。
|
|
1751
|
+
*
|
|
1752
|
+
* @returns {boolean} 是否播动效
|
|
1753
|
+
*/
|
|
1754
|
+
function motionAllowed() {
|
|
1755
|
+
if (typeof document === 'undefined' || typeof document.createElement !== 'function') return false
|
|
1756
|
+
if (typeof Element !== 'function' || typeof Element.prototype.animate !== 'function') return false
|
|
1757
|
+
const view = typeof window === 'undefined' ? null : window
|
|
1758
|
+
if (view && typeof view.matchMedia === 'function') {
|
|
1759
|
+
try {
|
|
1760
|
+
if (view.matchMedia('(prefers-reduced-motion: reduce)').matches) return false
|
|
1761
|
+
} catch (err) { /* matchMedia 抛错就当用户没提要求 */ }
|
|
1762
|
+
}
|
|
1763
|
+
return true
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
/**
|
|
1767
|
+
* 算这一帧哪些行是**新来的**、哪些行**走了**(纯函数,测试直接喂它)。
|
|
1768
|
+
*
|
|
1769
|
+
* 「走了」的行带回它上一帧的 `tierKey` / `index` —— 幽灵行要靠这两个值插回原来的位置,
|
|
1770
|
+
* 不能一律塞到列表末尾(那样看起来是「这篇文档跳到了下面然后消失」)。
|
|
1771
|
+
*
|
|
1772
|
+
* ⚠️ 视图整体换掉时(换类型 / 换排序 / 搜索词变了)返回空:那是「换屏」,不是
|
|
1773
|
+
* 「列表里多了一行」,整屏一起飞会很吵(原型里首屏也刻意不播)。
|
|
1774
|
+
* ⚠️ 同一篇**换层**(rel 不变、tierKey 变了)既不算进入也不算离开 —— 这不是「不播」:
|
|
1775
|
+
* 那一行交给 `KnitBody` 里的 FLIP(`motionShift` + 上一帧按 rel 记下的矩形)。跨分区时
|
|
1776
|
+
* React 会重建节点,但位置是按 **rel** 记的,所以它照样能从老位置补间到新位置;
|
|
1777
|
+
* 在这里把它当「进入」反而会让它先闪一下再飞,两段补间会互相打架。
|
|
1778
|
+
*
|
|
1779
|
+
* @param {{view: string, rows: object[]}|null} prev - 上一帧的快照(没提交过就是 null)
|
|
1780
|
+
* @param {string} view - 本帧的视图签名
|
|
1781
|
+
* @param {object[]} rows - 本帧的行表,顺序=屏幕顺序
|
|
1782
|
+
* @returns {{entered: Array<{rel: string, delay: number}>, left: object[]}} 新来的 / 走了的
|
|
1783
|
+
*/
|
|
1784
|
+
function planRowMotion(prev, view, rows) {
|
|
1785
|
+
const next = (Array.isArray(rows) ? rows : []).filter((row) => row && row.rel)
|
|
1786
|
+
if (!prev || prev.view !== view) return { entered: [], left: [] }
|
|
1787
|
+
const before = new Map((prev.rows || []).map((row) => [row.rel, row]))
|
|
1788
|
+
const after = new Set(next.map((row) => row.rel))
|
|
1789
|
+
const entered = []
|
|
1790
|
+
let order = 0
|
|
1791
|
+
for (const row of next) {
|
|
1792
|
+
if (before.has(row.rel)) continue
|
|
1793
|
+
entered.push({ rel: row.rel, delay: Math.min(order, MOTION_STAGGER_MAX) * MOTION_STAGGER_MS })
|
|
1794
|
+
order += 1
|
|
1795
|
+
}
|
|
1796
|
+
return {
|
|
1797
|
+
entered,
|
|
1798
|
+
left: (prev.rows || []).filter((row) => row && row.rel && !after.has(row.rel)),
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/**
|
|
1803
|
+
* 幸存行这一帧**相对上一帧挪了多远**(FLIP 的第一步:算反方向的位移)。
|
|
1804
|
+
*
|
|
1805
|
+
* 纯函数:喂两个 `{left, top}` 位置(**布局坐标**,见 `rowLayoutPoint`),返回要「拉回来」的
|
|
1806
|
+
* 位移;没得比或者没动过就返回 `null`。
|
|
1807
|
+
*
|
|
1808
|
+
* ⚠️ 阈值不是洁癖:`offsetTop` 也会给亚像素值,浏览器缩放导致的零点几像素抖动如果也排一段
|
|
1809
|
+
* 补间,那一屏会一直有东西在微微地飘。
|
|
1810
|
+
*
|
|
1811
|
+
* @param {{left: number, top: number}|null} prev - 上一帧的位置(没记过就是 null)
|
|
1812
|
+
* @param {{left: number, top: number}|null} now - 这一帧的位置
|
|
1813
|
+
* @param {number} [threshold] - 小于它就算没动(默认 `MOTION_MOVE_EPS`)
|
|
1814
|
+
* @returns {{dx: number, dy: number}|null} 位移(正数=上一帧更靠右下,要往左上拉)
|
|
1815
|
+
*/
|
|
1816
|
+
function motionShift(prev, now, threshold = MOTION_MOVE_EPS) {
|
|
1817
|
+
if (!prev || !now) return null
|
|
1818
|
+
const dx = prev.left - now.left
|
|
1819
|
+
const dy = prev.top - now.top
|
|
1820
|
+
if (!Number.isFinite(dx) || !Number.isFinite(dy)) return null
|
|
1821
|
+
if (Math.abs(dx) < threshold && Math.abs(dy) < threshold) return null
|
|
1822
|
+
return { dx, dy }
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
/**
|
|
1826
|
+
* 一行在**列表自己的坐标系**里的位置 —— FLIP 量位置只能用这个。
|
|
1827
|
+
*
|
|
1828
|
+
* ⚠️ 不能拿 `getBoundingClientRect()` 当「位置」:它是**视口坐标**,于是三件与「谁换了位置」
|
|
1829
|
+
* 毫无关系的机械动作都会让整屏的行凭空产生位移 ——
|
|
1830
|
+
* ① 容器滚动(含滚动位置被 clamp);
|
|
1831
|
+
* ② 容器自己的高度 / 顶边变了(预览面板一开一合、头上那块「使用情况」长高一行);
|
|
1832
|
+
* ③ 行上挂着 transform(`.knit-doc:hover{transform:translateX(-2px)}` 是死区 0.5px 的四倍)。
|
|
1833
|
+
* 2026-10-04 交互审用户报的两件事都是它:「我一点它就跳……闪得很快」与「我没有输入任何对话,
|
|
1834
|
+
* 文档列表就开始跳动」。`offsetTop/offsetLeft` 是**布局坐标**:不含滚动、不含 transform,
|
|
1835
|
+
* 容器自己怎么变都不动它。节点拿不到 offset*(测试替身 / 已卸载)时才退回视口矩形,并减掉
|
|
1836
|
+
* 容器那一块,好歹把滚动与容器位移去掉。
|
|
1837
|
+
*
|
|
1838
|
+
* @param {{getBoundingClientRect?: Function, scrollLeft?: number, scrollTop?: number}|null} host - 列表容器
|
|
1839
|
+
* @param {object} el - 行节点
|
|
1840
|
+
* @returns {{left: number, top: number}|null} 布局坐标;量不到就是 null
|
|
1841
|
+
*/
|
|
1842
|
+
function rowLayoutPoint(host, el) {
|
|
1843
|
+
if (!el) return null
|
|
1844
|
+
if (Number.isFinite(el.offsetTop) && Number.isFinite(el.offsetLeft)) {
|
|
1845
|
+
return { left: el.offsetLeft, top: el.offsetTop }
|
|
1846
|
+
}
|
|
1847
|
+
if (typeof el.getBoundingClientRect !== 'function') return null
|
|
1848
|
+
const box = el.getBoundingClientRect()
|
|
1849
|
+
if (!box) return null
|
|
1850
|
+
const base = host && typeof host.getBoundingClientRect === 'function'
|
|
1851
|
+
? host.getBoundingClientRect()
|
|
1852
|
+
: null
|
|
1853
|
+
if (!base) return { left: box.left, top: box.top }
|
|
1854
|
+
return {
|
|
1855
|
+
left: box.left - base.left + (Number.isFinite(host.scrollLeft) ? host.scrollLeft : 0),
|
|
1856
|
+
top: box.top - base.top + (Number.isFinite(host.scrollTop) ? host.scrollTop : 0),
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* 给这一帧**挪了位置**的幸存行排 FLIP,并返回这一帧的位置表留给下一帧。
|
|
1862
|
+
*
|
|
1863
|
+
* 换层(同一个 rel 从「包外」升进「Primary」)与区内重排都走这里。位置按 **rel** 记 ——
|
|
1864
|
+
* 跨分区时 React 会重建节点,老节点量到的位置照样能用在新节点上。
|
|
1865
|
+
*
|
|
1866
|
+
* ⚠️ 调用点必须是**提交之后**、绘制之前的 layout effect,而且在 `DocRow` 的进 / 出补间
|
|
1867
|
+
* **之后**(React 是子先父后):那一刻新行已经是 0 高、幽灵行还占着原高度,所以这里
|
|
1868
|
+
* 量到的位移就只剩「真的挪了位置」的行,不会和进 / 出补间算两遍。
|
|
1869
|
+
* ⚠️ `skip` 里的行(正在进 / 出的)一个都不碰:它们有自己的补间;幽灵行连数据都没有。
|
|
1870
|
+
* ⚠️ 只补 `transform`,不碰高度 —— 高度是进 / 出补间的事,两处都改会互相踩。
|
|
1871
|
+
*
|
|
1872
|
+
* @param {{querySelectorAll: Function}|null} host - 列表容器(`.knit-list`)
|
|
1873
|
+
* @param {Map<string, {left: number, top: number}>} before - 上一帧的位置表(按 rel,布局坐标)
|
|
1874
|
+
* @param {Set<string>} [skip] - 这一帧正在进 / 出的 rel
|
|
1875
|
+
* @returns {Map<string, {left: number, top: number}>} 这一帧的位置表(按 rel,布局坐标)
|
|
1876
|
+
*/
|
|
1877
|
+
function applyRowFlips(host, before, skip) {
|
|
1878
|
+
const after = new Map()
|
|
1879
|
+
const was = before instanceof Map ? before : new Map()
|
|
1880
|
+
const nodes = host && typeof host.querySelectorAll === 'function'
|
|
1881
|
+
? host.querySelectorAll('.knit-doc[data-knit-rel]') : []
|
|
1882
|
+
for (const el of nodes) {
|
|
1883
|
+
const rel = el && typeof el.getAttribute === 'function' ? el.getAttribute('data-knit-rel') : null
|
|
1884
|
+
if (!rel || (skip && skip.has(rel))) continue
|
|
1885
|
+
const point = rowLayoutPoint(host, el)
|
|
1886
|
+
if (!point) continue
|
|
1887
|
+
const shift = motionShift(was.get(rel), point)
|
|
1888
|
+
if (shift && typeof el.animate === 'function') {
|
|
1889
|
+
const anim = el.animate([
|
|
1890
|
+
{ transform: `translate(${shift.dx}px, ${shift.dy}px)` },
|
|
1891
|
+
{ transform: 'translate(0px, 0px)' },
|
|
1892
|
+
], { duration: MOTION_MOVE_MS, easing: MOTION_EASE })
|
|
1893
|
+
if (anim && anim.finished && typeof anim.finished.catch === 'function') anim.finished.catch(() => {})
|
|
1894
|
+
}
|
|
1895
|
+
after.set(rel, { left: point.left, top: point.top })
|
|
1896
|
+
}
|
|
1897
|
+
return after
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
/**
|
|
1901
|
+
* 把要「离开」的行插回它们**原来的位置**(纯函数)。
|
|
1902
|
+
*
|
|
1903
|
+
* 位置是上一帧记下来的 `index` —— 不插回原位的话,看到的会是「这篇文档跳到了列表
|
|
1904
|
+
* 末尾才消失」。数据里已经有同一篇时跳过:那一行还活着(比如它只是换了层),
|
|
1905
|
+
* 不该在同一区里再多出一个幽灵。
|
|
1906
|
+
*
|
|
1907
|
+
* @param {object[]} docs - 这一区这一帧的数据
|
|
1908
|
+
* @param {object[]} ghosts - 全部要离开的行(`{rel, doc, tierKey, index}`)
|
|
1909
|
+
* @param {string} tierKey - 哪一个区(分层视图=层名,平铺 / 「全部」各一个常量)
|
|
1910
|
+
* @returns {object[]} 带幽灵行的新数组(这一区没幽灵时原样返回)
|
|
1911
|
+
*/
|
|
1912
|
+
function mergeGhostRows(docs, ghosts, tierKey) {
|
|
1913
|
+
const mine = []
|
|
1914
|
+
for (const ghost of Array.isArray(ghosts) ? ghosts : []) {
|
|
1915
|
+
if (ghost && ghost.tierKey === tierKey) mine.push(ghost)
|
|
1916
|
+
}
|
|
1917
|
+
if (mine.length === 0) return docs
|
|
1918
|
+
mine.sort((a, b) => a.index - b.index)
|
|
1919
|
+
const out = docs.slice()
|
|
1920
|
+
for (const ghost of mine) {
|
|
1921
|
+
if (out.some((doc) => doc.rel === ghost.rel)) continue
|
|
1922
|
+
out.splice(Math.min(ghost.index, out.length), 0, { ...ghost.doc, knitLeaving: true })
|
|
1923
|
+
}
|
|
1924
|
+
return out
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
function DocRow({ doc, now, active, cursor, relevance, why, num, mark, primary, life,
|
|
1928
|
+
glyph, onGlyph, onSelect, onOpenTab, optionId, entering, leaving }) {
|
|
1351
1929
|
const fresh = now - doc.mtimeMs < NEW_WINDOW_MS
|
|
1930
|
+
const rowRef = React.useRef(null)
|
|
1931
|
+
|
|
1932
|
+
/* 进 / 出两段补间都跑在 **layout effect** 里:放到 paint 之后会先闪一帧完整高度的
|
|
1933
|
+
行,那正是用户抱怨的那一下。没有 DOM 时 `motionAllowed()` 直接挡掉。 */
|
|
1934
|
+
React.useLayoutEffect(() => {
|
|
1935
|
+
if (!motionAllowed()) return
|
|
1936
|
+
const el = rowRef.current
|
|
1937
|
+
if (!el || typeof el.getBoundingClientRect !== 'function') return
|
|
1938
|
+
const box = el.getBoundingClientRect()
|
|
1939
|
+
const height = box && box.height > 0 ? box.height : 0
|
|
1940
|
+
if (height <= 0) return
|
|
1941
|
+
// 量的高度是 border-box,补间也得按 border-box 算,否则第一帧会把行撑高一个内边距。
|
|
1942
|
+
el.style.boxSizing = 'border-box'
|
|
1943
|
+
if (leaving) {
|
|
1944
|
+
// 离开:高度收到 0,同时**自上而下**擦掉(clip-path 的 top 从 0 涨到 100%),
|
|
1945
|
+
// 末尾补一点模糊 —— 与原型里那条 mask 擦除是同一个读法。
|
|
1946
|
+
el.style.overflow = 'hidden'
|
|
1947
|
+
const anim = el.animate([
|
|
1948
|
+
{ height: `${height}px`, clipPath: 'inset(0% 0 0 0)', opacity: 1, filter: 'blur(0px)' },
|
|
1949
|
+
{ height: `${height * 0.55}px`, clipPath: 'inset(45% 0 0 0)', opacity: 0.7, filter: 'blur(1px)', offset: 0.55 },
|
|
1950
|
+
{ height: '0px', clipPath: 'inset(100% 0 0 0)', opacity: 0, filter: 'blur(2px)' },
|
|
1951
|
+
], { duration: MOTION_EXIT_MS, easing: MOTION_EASE, fill: 'forwards' })
|
|
1952
|
+
if (anim && anim.finished && typeof anim.finished.catch === 'function') anim.finished.catch(() => {})
|
|
1953
|
+
return
|
|
1954
|
+
}
|
|
1955
|
+
if (entering === null || entering === undefined) return
|
|
1956
|
+
// 进入:先把高度收成 0 再补间到自然高度 —— 下面的行是被**挤**下去的,不是跳下去的
|
|
1957
|
+
// (原型里踩过的坑:不先量自然高度,插入瞬间会把下面那行蹬一下)。
|
|
1958
|
+
el.style.overflow = 'hidden'
|
|
1959
|
+
const anim = el.animate([
|
|
1960
|
+
{ height: '0px', transform: 'translateY(26px)', opacity: 0, filter: 'blur(3px)' },
|
|
1961
|
+
{ height: `${height}px`, transform: 'translateY(0)', opacity: 1, filter: 'blur(0px)' },
|
|
1962
|
+
], { duration: MOTION_ENTER_MS, delay: entering, easing: MOTION_EASE, fill: 'both' })
|
|
1963
|
+
const done = anim && anim.finished
|
|
1964
|
+
if (done && typeof done.then === 'function') {
|
|
1965
|
+
done.then(() => { el.style.height = ''; el.style.overflow = '' }).catch(() => {})
|
|
1966
|
+
} else {
|
|
1967
|
+
el.style.height = ''
|
|
1968
|
+
el.style.overflow = ''
|
|
1969
|
+
}
|
|
1970
|
+
})
|
|
1352
1971
|
|
|
1353
1972
|
return h('div', {
|
|
1354
|
-
className: `knit-doc${active ? ' active' : ''}${cursor ? ' cursor' : ''}${fresh ? ' fresh' : ''}`,
|
|
1973
|
+
className: `knit-doc${active ? ' active' : ''}${cursor ? ' cursor' : ''}${fresh ? ' fresh' : ''}${leaving ? ' leaving' : ''}`,
|
|
1974
|
+
ref: rowRef,
|
|
1355
1975
|
// listbox 的选项语义:有 role 才能被读成「N 项中的第 i 项」,
|
|
1356
1976
|
// 有 aria-selected 才能播报「当前选中」。
|
|
1357
1977
|
role: 'option',
|
|
1358
1978
|
id: optionId,
|
|
1359
1979
|
'aria-selected': active ? 'true' : 'false',
|
|
1980
|
+
// 「正在离开」的幽灵行已经不在数据里了(点不动、键盘也到不了),
|
|
1981
|
+
// 只是占着位置把高度收掉 —— 别让它被读成一项。
|
|
1982
|
+
'aria-hidden': leaving ? 'true' : undefined,
|
|
1360
1983
|
'data-knit-rel': doc.rel,
|
|
1361
1984
|
title: t('row.tooltip', { path: doc.rel }),
|
|
1362
1985
|
onClick: () => onSelect(doc),
|
|
@@ -1381,10 +2004,44 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1381
2004
|
h('div', { className: 'knit-row1' },
|
|
1382
2005
|
// v0.14(Design §13):Primary 唯一允许的标记 —— 5px 黑点。
|
|
1383
2006
|
// 不是星标、不是徽章、不是 AI 图标:「重要来自位置和结构,不来自图标」。
|
|
1384
|
-
|
|
2007
|
+
// v0.18:**统计开着时这一格让给生命周期 glyph**(○ ● △ ↻)——
|
|
2008
|
+
// 2026-10-05 规格 §13 给的 ASCII 每一行只有一个标记,而层名已经由分组标题
|
|
2009
|
+
// (「主要上下文」)说了,glyph 才是这一版新加的那条事实。usage 关掉时
|
|
2010
|
+
// 这一行与 v0.17 逐字一致(`knit-dot` 照旧)。
|
|
2011
|
+
primary && !glyph ? h('span', { className: 'knit-dot', 'aria-hidden': 'true' }) : null,
|
|
2012
|
+
// 生命周期 glyph:极小、中性、点它=打开 / 选中这篇(**已经打开则保持原预览**)。
|
|
2013
|
+
// ⚠️ 它是真 `button`:键盘 Tab 得到、读屏读得出,不是 div + onClick。
|
|
2014
|
+
glyph ? h('button', {
|
|
2015
|
+
className: 'knit-glyph',
|
|
2016
|
+
type: 'button',
|
|
2017
|
+
title: glyph.title,
|
|
2018
|
+
'aria-label': glyph.title,
|
|
2019
|
+
onClick: (event) => {
|
|
2020
|
+
if (event && typeof event.stopPropagation === 'function') event.stopPropagation()
|
|
2021
|
+
onGlyph(doc)
|
|
2022
|
+
},
|
|
2023
|
+
},
|
|
2024
|
+
// v0.18 UI 迭代(md §二十七~§二十九):四态画成与 Coverage **同一套** 9px 圆点 ——
|
|
2025
|
+
// 未读=空心环、已读=实心、读后已更新=空心环 + 中心点、修改后已重新读取= ↻ 字符。
|
|
2026
|
+
// 两处用同一对 token、同一个直径,所以「同一套状态语言」不靠自觉。
|
|
2027
|
+
// ⚠️ 状态词仍然只在 title / aria-label 里;行尾那一段文字由 `.knit-life` 说。
|
|
2028
|
+
h('span', {
|
|
2029
|
+
className: 'knit-glyph-mark',
|
|
2030
|
+
'data-mark': glyph.status === 'read' ? 'read'
|
|
2031
|
+
: glyph.status === 'updated_after_read' ? 'updated'
|
|
2032
|
+
: glyph.status === 'reread_after_update' ? 'reread' : 'unread',
|
|
2033
|
+
'aria-hidden': 'true',
|
|
2034
|
+
}, glyph.status === 'reread_after_update' ? glyph.char : null)) : null,
|
|
1385
2035
|
h('div', { className: 'knit-title' },
|
|
1386
2036
|
fresh ? h('span', { className: 'knit-badge' }, '🆕') : null,
|
|
1387
2037
|
doc.title || doc.name),
|
|
2038
|
+
// v0.17:生命周期状态(文案已算好;没有证据时是 null,一个节点都不加)。
|
|
2039
|
+
// 插在**标题与时间之间**:`.knit-title` 是 flex:1 1 auto,会把状态与时间一起推到
|
|
2040
|
+
// 行尾,状态在时间左侧、行尾仍然是时间。
|
|
2041
|
+
// ⚠️ 状态是**纯文字**:不加图标、不加底色、不加边框、不用红绿表达好坏 ——
|
|
2042
|
+
// 它陈述事实,不是评分(AGENTS.md §6.2 / PRD §7.3)。字号比标题弱一档,
|
|
2043
|
+
// 永远不抢标题。
|
|
2044
|
+
life ? h('span', { className: 'knit-life' }, life) : null,
|
|
1388
2045
|
// 时间在标题右边的行尾 —— 靠 .knit-title 的 flex-grow 推过去,不是靠 margin。
|
|
1389
2046
|
h('div', { className: 'knit-time' }, relTime(doc.mtimeMs, now))),
|
|
1390
2047
|
doc.summary
|
|
@@ -1581,7 +2238,15 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1581
2238
|
|
|
1582
2239
|
return h('div', {
|
|
1583
2240
|
className: 'knit-preview',
|
|
1584
|
-
|
|
2241
|
+
/* ⚠️ 高度**打开期间是固定的**(= 拖出来的那个比例),不是 `maxHeight`(2026-10-04 交互审)。
|
|
2242
|
+
原来是 `maxHeight: 46%` ⇒ 面板高度由**内容**决定,于是:
|
|
2243
|
+
① 点一篇 → 先出「加载中」(一两行高),正文到了再窜到 46% ⇒ 列表跟着一伸一缩;
|
|
2244
|
+
② 在预览里点「相关文档」换一篇 ⇒ 正文长短变了 ⇒ 列表又跟着一伸一缩。
|
|
2245
|
+
用户的原话是「我选中一个文档查看全文……我一点它就跳,我一点它就很跳,闪的很快」。
|
|
2246
|
+
固定高度之后这两次几何变化一次都不发生:加载中 / 换篇都不再改动列表的高度,
|
|
2247
|
+
长文照样在 `.knit-preview-body` 里滚(它本来就是 `overflow-y:auto`)。
|
|
2248
|
+
短文档会因此下方留白 —— 这是拿「点一下不跳」换来的,别再改回 maxHeight。 */
|
|
2249
|
+
style: fullscreen ? undefined : { height: `${Math.round(ratio * 100)}%` },
|
|
1585
2250
|
},
|
|
1586
2251
|
fullscreen ? null : h('div', { className: 'knit-resize', onPointerDown: onResizeStart, title: t('preview.resizeTitle') }),
|
|
1587
2252
|
h('div', { className: 'knit-preview-head' },
|
|
@@ -1674,6 +2339,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1674
2339
|
// 的顺序被测试按位预置,别插队。
|
|
1675
2340
|
const [usageOn, setUsageOn] = React.useState(readUsagePref)
|
|
1676
2341
|
|
|
2342
|
+
// v0.17:两个折叠块的开合状态(上下文外读取 / 最近一次变化)。
|
|
2343
|
+
// **纯瞬时 UI 状态** —— 不写 pref、不进 `dsh-knit:*` 存储,刷新即回默认(收起)。
|
|
2344
|
+
// 仍然放在最后:前面那些 hook 的位置被测试按位预置,别插队。
|
|
2345
|
+
const [gapOpen, setGapOpen] = React.useState(false)
|
|
2346
|
+
const [deltaOpen, setDeltaOpen] = React.useState(false)
|
|
2347
|
+
|
|
1677
2348
|
/* ── 曾经在这里的三个状态 + 一个 ref:右栏的形态 ──────────
|
|
1678
2349
|
`packWidth`(310) / `packFloat`(null) / `packSnap`(false) / `packColRef`。
|
|
1679
2350
|
**2026-09-29 随右栏一起删除**。当时它们**只存在内存里**(刷新回默认值),
|
|
@@ -1793,12 +2464,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1793
2464
|
* 时间序、筛选结果、「其他相关文档」都不编号 —— 但**这一屏里有号时**,没号的行会在
|
|
1794
2465
|
* 同一列拿到 `mark`(渲染 `.knit-gapmark` 占位),算法见下面。
|
|
1795
2466
|
*/
|
|
1796
|
-
const docsGrid = (docs, numbers, primary) => {
|
|
2467
|
+
const docsGrid = (docs, numbers, primary, withLife) => {
|
|
1797
2468
|
// 一屏里「要么都有号、要么都没有」(2026-10-01):只要这个视图里存在序号,
|
|
1798
2469
|
// 没号的那些行(「其他相关文档」)就在同一列渲染占位标记;整屏没号时不渲染。
|
|
1799
2470
|
const mark = Boolean(numbers && numbers.size > 0)
|
|
1800
2471
|
return docs.map((doc) =>
|
|
1801
|
-
renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark))
|
|
2472
|
+
renderEntry(doc, numbers ? numbers.get(doc.rel) || 0 : 0, Boolean(primary), mark, withLife))
|
|
1802
2473
|
}
|
|
1803
2474
|
|
|
1804
2475
|
const relevance = state.mode === 'relevance'
|
|
@@ -1817,8 +2488,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1817
2488
|
* @returns {Array} 节点数组
|
|
1818
2489
|
*/
|
|
1819
2490
|
const contextBody = (view) => view.sections.map((section) => h('div', {
|
|
1820
|
-
|
|
2491
|
+
// 点 Coverage 定位过来时,这一层短暂亮一下(`flashTier`,900ms 后自己收掉)。
|
|
2492
|
+
// 不画箭头、不画横线 —— 用**空间**说「就是这里」。
|
|
2493
|
+
className: `knit-tier${flashTier === section.key ? ' flash' : ''}`,
|
|
1821
2494
|
key: section.key,
|
|
2495
|
+
// Coverage 的定位锚点:点某一层 → `[data-knit-tier=...]` 滚进视口。
|
|
2496
|
+
'data-knit-tier': section.key,
|
|
1822
2497
|
role: 'presentation',
|
|
1823
2498
|
},
|
|
1824
2499
|
// ⚠️ 这几个类名**互不为子串**:`byClass` 是子串匹配,若叫
|
|
@@ -1827,7 +2502,9 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1827
2502
|
h('div', { className: 'knit-tierline', role: 'presentation' },
|
|
1828
2503
|
h('span', { className: 'knit-tiername' }, t(section.titleKey)),
|
|
1829
2504
|
section.hintKey ? h('span', { className: 'knit-tierhint' }, t(section.hintKey)) : null),
|
|
1830
|
-
|
|
2505
|
+
// ⚠️ 幽灵行(正在离开的)也走 `docsGrid`,所以它照样是一个 `.knit-doc` ——
|
|
2506
|
+
// 会被 `byClass` 数到,但**不在** `navDocs` 里(键盘与 cursor 都到不了)。
|
|
2507
|
+
docsGrid(withGhosts(section.key, section.docs), view.numbers, section.key === 'primary', true)))
|
|
1831
2508
|
|
|
1832
2509
|
/* ── 曾经在这里的一个函数:`contextPanel` ─────────────────
|
|
1833
2510
|
它渲染右栏那三样东西(当前任务原文 / 「命中 N 篇」/ 三条证据行)。
|
|
@@ -1912,15 +2589,23 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1912
2589
|
if (!navDocs.some((doc) => doc.rel === cursor)) setCursor(navDocs[0].rel)
|
|
1913
2590
|
}, [navDocs, cursor])
|
|
1914
2591
|
|
|
1915
|
-
|
|
2592
|
+
/* 键盘焦点跟手滚进视口(测试环境没有 DOM,静默跳过)。
|
|
2593
|
+
⚠️ 2026-10-04(交互审的那个 bug):这里曾经把 `state.docs` 也放进依赖里,而那是**每 5 秒
|
|
2594
|
+
轮询一次的新数组** —— 于是「刷新到了新数据」被当成了「用户按了方向键」。光标默认落在第一行,
|
|
2595
|
+
用户往下滚过之后那一行必然不在视口里 ⇒ 列表每 5 秒被拽回第一行一次,用户的原话是
|
|
2596
|
+
「我没有输入任何的对话……文档列表就开始跳动」。滚动**只在光标真的换了**(或搜索词变了)时发生,
|
|
2597
|
+
而且只在列表拿着键盘焦点时发生 —— 这条服务的是键盘导航;鼠标点过 / 悬停过的行本来就在视口里,
|
|
2598
|
+
而「数据刷新」一次都不该动列表。 */
|
|
1916
2599
|
React.useEffect(() => {
|
|
1917
2600
|
if (!cursor || typeof document === 'undefined') return
|
|
1918
2601
|
const host = listRef.current
|
|
1919
2602
|
if (!host || typeof host.querySelector !== 'function') return
|
|
2603
|
+
const active = document.activeElement
|
|
2604
|
+
if (active !== host && !(active && host.contains && host.contains(active))) return
|
|
1920
2605
|
const escaped = typeof CSS !== 'undefined' && CSS.escape ? CSS.escape(cursor) : cursor
|
|
1921
2606
|
const el = host.querySelector(`[data-knit-rel="${escaped}"]`)
|
|
1922
2607
|
if (el && typeof el.scrollIntoView === 'function') el.scrollIntoView({ block: 'nearest' })
|
|
1923
|
-
}, [cursor, query
|
|
2608
|
+
}, [cursor, query])
|
|
1924
2609
|
|
|
1925
2610
|
// 预览高度:拖完就记住
|
|
1926
2611
|
React.useEffect(() => { writePref(RATIO_KEY, String(ratio)) }, [ratio])
|
|
@@ -2177,8 +2862,243 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2177
2862
|
|
|
2178
2863
|
|
|
2179
2864
|
|
|
2180
|
-
/**
|
|
2181
|
-
|
|
2865
|
+
/**
|
|
2866
|
+
* v0.17:这一篇当前的**事实状态**,文案已按语言算好(没有证据时是 null)。
|
|
2867
|
+
*
|
|
2868
|
+
* ⚠️ 只有「使用情况」开着、并且宿主真的回传了 `usage` 时才有文案 —— 关掉时
|
|
2869
|
+
* 一个状态节点都不渲染,DOM 与 v0.16 逐字一致。
|
|
2870
|
+
* ⚠️ `lifecycle` 里没有这篇 = 本会话没有一次成功 read ⇒ 未读。这是事实陈述,
|
|
2871
|
+
* 不是「你漏了它」的提醒,更不许写成「Agent 忽略了它」(PRD §8)。
|
|
2872
|
+
* ⚠️ 状态值本身是英文(数据层只有一个口径),中文只存在于词典(§15.4 / §24)。
|
|
2873
|
+
*
|
|
2874
|
+
/**
|
|
2875
|
+
* v0.17 → v0.18:生命周期现在是**一枚 glyph + 一段极短的文字**。
|
|
2876
|
+
* `○ 未读` / `● 已读 ×n` / `△ 读后已更新` / `↻ 修改后已重新读取`。
|
|
2877
|
+
*
|
|
2878
|
+
* ⚠️ tooltip 与 `aria-label` 挂在 **glyph** 上:`.knit-life` 只许有一个 `className`
|
|
2879
|
+
* prop(client.test.mjs 有守卫盯着)—— 状态是文字,不是可交互控件。
|
|
2880
|
+
* ⚠️ 没有记录就是「未读」:这是**事实**,不是猜测。
|
|
2881
|
+
*
|
|
2882
|
+
* @param {string} rel - 相对路径
|
|
2883
|
+
* @returns {{status:string,char:string,text:string,title:string}|null}
|
|
2884
|
+
*/
|
|
2885
|
+
const lifeInfo = (rel) => {
|
|
2886
|
+
if (!usageOn) return null
|
|
2887
|
+
const usageNow = state.usage
|
|
2888
|
+
if (!usageNow || !usageNow.stats) return null
|
|
2889
|
+
const row = usageNow.lifecycle && usageNow.lifecycle[rel]
|
|
2890
|
+
const status = row && row.status ? row.status : 'unread'
|
|
2891
|
+
const char = LIFE_GLYPH[status] || LIFE_GLYPH.unread
|
|
2892
|
+
const count = row && Number.isFinite(row.count) ? row.count : 0
|
|
2893
|
+
if (status === 'updated_after_read') {
|
|
2894
|
+
return { status, char, text: t('lifecycle.updatedAfterRead'),
|
|
2895
|
+
title: t('lifecycle.updatedAfterRead') }
|
|
2896
|
+
}
|
|
2897
|
+
if (status === 'reread_after_update') {
|
|
2898
|
+
return { status, char, text: t('lifecycle.rereadAfterUpdate'),
|
|
2899
|
+
title: t('lifecycle.rereadAfterUpdate') }
|
|
2900
|
+
}
|
|
2901
|
+
if (status === 'read') {
|
|
2902
|
+
// 读了几次只说次数:`×3`。**不排序、不评分、不建议**。
|
|
2903
|
+
return { status, char, text: t('lifecycle.readCountShort', { n: count }),
|
|
2904
|
+
title: t('lifecycle.readCount', { n: count }) }
|
|
2905
|
+
}
|
|
2906
|
+
return { status: 'unread', char: LIFE_GLYPH.unread,
|
|
2907
|
+
text: t('lifecycle.unread'), title: t('lifecycle.unread') }
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
/** 只有文字的那一半(行尾 `.knit-life`);没有证据时 null,一个节点都不加。 */
|
|
2911
|
+
const lifecycleLabel = (rel) => {
|
|
2912
|
+
const info = lifeInfo(rel)
|
|
2913
|
+
return info ? info.text : null
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2916
|
+
/**
|
|
2917
|
+
* 状态词(**不带次数**)—— 给「次数已经在同一行单独显示」的地方用。
|
|
2918
|
+
* 包外行左边已经有一个 `×N`(它同时是这一档的排序键),再让 lifecycle 说一遍 `×N`
|
|
2919
|
+
* 就会渲染成 `client.js ×71 ×71`(2026-10-05 用真实载荷渲染时抓到)。
|
|
2920
|
+
* `read` 换成短词「已读」;其余三态本来就是词,照旧。
|
|
2921
|
+
*/
|
|
2922
|
+
const lifeWord = (rel) => {
|
|
2923
|
+
const info = lifeInfo(rel)
|
|
2924
|
+
if (!info) return null
|
|
2925
|
+
return info.status === 'read' ? t('lifecycle.read') : info.text
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
/* ── 列表进出动效:这一帧谁新来了、谁走了 ─────────────────────────
|
|
2929
|
+
(参数与手感见模块级 `planRowMotion` / `MOTION_*` 那段注释。)
|
|
2930
|
+
|
|
2931
|
+
⚠️ 渲染期**只读** `motionRef`,落盘与计时器都在下面的 layout effect 里 ——
|
|
2932
|
+
并发渲染下这一帧可能根本没提交,渲染里写 ref 会把幽灵行记进一个被丢掉的帧。 */
|
|
2933
|
+
const motionRef = React.useRef({
|
|
2934
|
+
committed: null,
|
|
2935
|
+
ghosts: new Map(),
|
|
2936
|
+
timers: new Map(),
|
|
2937
|
+
positions: new Map(),
|
|
2938
|
+
// 位置表是在**哪一屏**量下来的(视图签名)。换屏时必须整表作废:见下面 settled 那条。
|
|
2939
|
+
view: '',
|
|
2940
|
+
// 进 / 出补间还在飞的截止时刻(毫秒时间戳)。那段时间里行高是中间态,量不得。
|
|
2941
|
+
tweenUntil: 0,
|
|
2942
|
+
})
|
|
2943
|
+
const [, setMotionSeq] = React.useState(0)
|
|
2944
|
+
|
|
2945
|
+
/* ── v0.18 Usage Lens:三个新状态 + 两个新 effect ────────────────
|
|
2946
|
+
⚠️ 这些 hook 必须留在**本组件最后一个 hook 之后**:假 React(test/harness.mjs)
|
|
2947
|
+
按调用顺序分配槽位,`harness.seed()` 又按顺序预置 —— 插在中间会让所有老用例错位。 */
|
|
2948
|
+
|
|
2949
|
+
/** Lens 的展开 / 收起。它与「使用情况」开关是**两个状态**(规格 §25):
|
|
2950
|
+
* 开关管「统计开不开」,这一位只管「统计开着,但暂时不想看细节」。默认展开。 */
|
|
2951
|
+
const [lensOpen, setLensOpen] = React.useState(true)
|
|
2952
|
+
/** 正在短暂高亮的那一层(点 Coverage 定位用);空串=没有高亮。 */
|
|
2953
|
+
const [flashTier, setFlashTier] = React.useState('')
|
|
2954
|
+
/** 面板高度(px)。0 = 量不到(测试替身 / 首帧)——那时按「不矮」处理,不降级。 */
|
|
2955
|
+
const [panelH, setPanelH] = React.useState(0)
|
|
2956
|
+
|
|
2957
|
+
/** 点 Coverage 的某一层 → 滚到那一层 + 短暂高亮。
|
|
2958
|
+
* ⚠️ 滚的是 `.knit-list`(唯一滚动容器):Lens 自己不滚动,也不新增容器。
|
|
2959
|
+
* ⚠️ 高亮走 state 而不是直接改 classList —— 这样测试替身里也能断言到结果。 */
|
|
2960
|
+
const locateTier = (key) => {
|
|
2961
|
+
setFlashTier(key)
|
|
2962
|
+
const host = listRef.current
|
|
2963
|
+
if (host && typeof host.querySelector === 'function') {
|
|
2964
|
+
const el = host.querySelector(`[data-knit-tier="${key}"]`)
|
|
2965
|
+
if (el && typeof el.scrollIntoView === 'function') {
|
|
2966
|
+
// v0.18 UI 迭代(md §十七):把那一层滚到**视口中部**,并且只在允许动效时
|
|
2967
|
+
// 用平滑滚动(`motionAllowed()` 已经把「减弱动态效果」挡在外面 ⇒ 那时是瞬移,
|
|
2968
|
+
// 与 md §十八 的 `scroll-behavior:auto` 同义)。
|
|
2969
|
+
el.scrollIntoView({ behavior: motionAllowed() ? 'smooth' : 'auto', block: 'center' })
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
/** 打开某一篇 —— 它**可能不在当前列表里**(包外文档就不在 `state.docs` 里)。
|
|
2975
|
+
* 走模块级 `requestPreview`:与工具输出、其他座位共用同一条打开路径。
|
|
2976
|
+
* ⚠️ **不重新请求列表**:只换预览(规格 §16)。已经打开同一篇就保持原预览。 */
|
|
2977
|
+
const openDocByRel = (rel) => {
|
|
2978
|
+
if (!rel) return
|
|
2979
|
+
if (preview && preview.rel === rel) return
|
|
2980
|
+
requestPreview({ rel, title: rel })
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
// 高亮只亮一下,然后自己收掉(不靠 hover、不靠「点了别处」)。
|
|
2984
|
+
React.useEffect(() => {
|
|
2985
|
+
if (!flashTier) return undefined
|
|
2986
|
+
const timer = setTimeout(() => setFlashTier(''), FLASH_MS)
|
|
2987
|
+
return () => clearTimeout(timer)
|
|
2988
|
+
}, [flashTier])
|
|
2989
|
+
|
|
2990
|
+
// 面板矮的时候 Lens 要降级(Summary + Coverage + 最近读取;Outside / Delta 收成标题)。
|
|
2991
|
+
React.useEffect(() => {
|
|
2992
|
+
if (typeof ResizeObserver !== 'function' || !rootRef.current) return undefined
|
|
2993
|
+
const observer = new ResizeObserver((entries) => {
|
|
2994
|
+
const box = entries && entries[0] && entries[0].contentRect
|
|
2995
|
+
const height = box ? box.height : 0
|
|
2996
|
+
if (height) setPanelH((current) => (Math.abs(current - height) < 1 ? current : height))
|
|
2997
|
+
})
|
|
2998
|
+
observer.observe(rootRef.current)
|
|
2999
|
+
return () => observer.disconnect()
|
|
3000
|
+
}, [])
|
|
3001
|
+
const motionOn = motionAllowed()
|
|
3002
|
+
// 视图签名:换类型 / 换排序 / 搜索词变了都算「换屏」——整屏一起飞会很吵。
|
|
3003
|
+
const motionView = `${kind}|${state.mode}|${query.trim()}`
|
|
3004
|
+
// 只列**真会渲染成 .knit-doc 的行**,顺序=屏幕顺序(幽灵行要按这个位置插回去)。
|
|
3005
|
+
const motionRows = (() => {
|
|
3006
|
+
if (state.status === 'error' || state.docs.length === 0 || visibleDocs.length === 0) return []
|
|
3007
|
+
if (kind === KIND_MEDIA) return [] // 媒体格子不参与:网格里收起高度没有意义
|
|
3008
|
+
if (kind === KIND_ALL) {
|
|
3009
|
+
if (docItems.length === 0) return []
|
|
3010
|
+
return shownDocs.map((doc, index) => (
|
|
3011
|
+
{ rel: doc.rel, tierKey: MOTION_TIER_ALL_DOCS, index, doc }))
|
|
3012
|
+
}
|
|
3013
|
+
if (contextView) {
|
|
3014
|
+
const rows = []
|
|
3015
|
+
for (const section of contextView.sections) {
|
|
3016
|
+
section.docs.forEach((doc, index) => rows.push(
|
|
3017
|
+
{ rel: doc.rel, tierKey: section.key, index, doc }))
|
|
3018
|
+
}
|
|
3019
|
+
return rows
|
|
3020
|
+
}
|
|
3021
|
+
return visibleDocs.map((doc, index) => (
|
|
3022
|
+
{ rel: doc.rel, tierKey: MOTION_TIER_FLAT, index, doc }))
|
|
3023
|
+
})()
|
|
3024
|
+
const motion = (() => {
|
|
3025
|
+
const live = new Set(motionRows.map((row) => row.rel))
|
|
3026
|
+
const plan = motionOn
|
|
3027
|
+
? planRowMotion(motionRef.current.committed, motionView, motionRows)
|
|
3028
|
+
: { entered: [], left: [] }
|
|
3029
|
+
const ghosts = new Map()
|
|
3030
|
+
if (motionOn) {
|
|
3031
|
+
// 上一帧留下的幽灵,这一帧还不在数据里 ⇒ 继续收着(同一篇回来了就撤掉)。
|
|
3032
|
+
for (const [rel, ghost] of motionRef.current.ghosts) if (!live.has(rel)) ghosts.set(rel, ghost)
|
|
3033
|
+
for (const row of plan.left) {
|
|
3034
|
+
if (ghosts.has(row.rel)) continue
|
|
3035
|
+
ghosts.set(row.rel, { rel: row.rel, doc: row.doc, tierKey: row.tierKey, index: row.index })
|
|
3036
|
+
}
|
|
3037
|
+
}
|
|
3038
|
+
return { entered: new Map(plan.entered.map((row) => [row.rel, row.delay])), ghosts, live }
|
|
3039
|
+
})()
|
|
3040
|
+
React.useLayoutEffect(() => {
|
|
3041
|
+
const store = motionRef.current
|
|
3042
|
+
store.committed = motionOn && motionRows.length > 0 ? { view: motionView, rows: motionRows } : null
|
|
3043
|
+
store.ghosts = motion.ghosts
|
|
3044
|
+
for (const [rel, timer] of store.timers) {
|
|
3045
|
+
if (motion.ghosts.has(rel)) continue
|
|
3046
|
+
clearTimeout(timer)
|
|
3047
|
+
store.timers.delete(rel)
|
|
3048
|
+
}
|
|
3049
|
+
for (const rel of motion.ghosts.keys()) {
|
|
3050
|
+
if (store.timers.has(rel)) continue
|
|
3051
|
+
// 补间跑完(外加一点交错余量)就把幽灵行摘掉 —— 摘的时候高度已经是 0,
|
|
3052
|
+
// 所以下面的行不会再跳一下。
|
|
3053
|
+
const timer = setTimeout(() => {
|
|
3054
|
+
store.timers.delete(rel)
|
|
3055
|
+
if (!store.ghosts.has(rel)) return
|
|
3056
|
+
const next = new Map(store.ghosts)
|
|
3057
|
+
next.delete(rel)
|
|
3058
|
+
store.ghosts = next
|
|
3059
|
+
setMotionSeq((n) => n + 1)
|
|
3060
|
+
}, MOTION_EXIT_MS + MOTION_STAGGER_MS)
|
|
3061
|
+
store.timers.set(rel, timer)
|
|
3062
|
+
}
|
|
3063
|
+
/* ── 活下来的行换了位置:FLIP(算法在模块级 `applyRowFlips`)────
|
|
3064
|
+
正在进 / 出的行不参与:它们有自己的补间(幽灵行连数据都没有,别去量)。
|
|
3065
|
+
|
|
3066
|
+
⚠️ 另外两种时候**一个都不量**(2026-10-04 交互审那两个 bug 的正主):
|
|
3067
|
+
① **换屏**(视图签名变了):那是「整屏换了一批内容」,不是「列表里有人挪了位置」。
|
|
3068
|
+
`planRowMotion` 对换屏就是不播,FLIP 却会照两张布局的差把每一行都补一遍 ——
|
|
3069
|
+
换排序 / 第一次拿到数据 / 搜索词一变,整屏一起飞。
|
|
3070
|
+
② **进 / 出补间还在飞**:那几百毫秒里行高在 0 与自然高之间,量到的全是中间态。
|
|
3071
|
+
拿中间态当基准,等补间落地后下一帧就把这段位移当成「有人挪了位置」再补一遍 ——
|
|
3072
|
+
一屏就这么飘起来(而且会一直飘:每次进 / 出都留下一个错基准)。
|
|
3073
|
+
两种时候都把位置表**清空**(不是照记):清空等于「没有上一帧可比」,下一帧只会安静
|
|
3074
|
+
落位、不补间;等落地后再量一帧,基准就又是干净的了。 */
|
|
3075
|
+
const tweening = store.tweenUntil > Date.now()
|
|
3076
|
+
if (motion.entered.size > 0 || motion.ghosts.size > 0) {
|
|
3077
|
+
// 取较长的那一套(进入 + 一点交错余量),离开比它短,等它一定够了。
|
|
3078
|
+
store.tweenUntil = Date.now() + MOTION_ENTER_MS + MOTION_STAGGER_MS
|
|
3079
|
+
}
|
|
3080
|
+
const skip = new Set([...motion.entered.keys(), ...motion.ghosts.keys()])
|
|
3081
|
+
const settled = motionOn
|
|
3082
|
+
&& motionRows.length > 0
|
|
3083
|
+
&& !tweening
|
|
3084
|
+
&& motion.entered.size === 0
|
|
3085
|
+
&& motion.ghosts.size === 0
|
|
3086
|
+
&& store.view === motionView
|
|
3087
|
+
store.positions = settled ? applyRowFlips(listRef.current, store.positions, skip) : new Map()
|
|
3088
|
+
store.view = motionView
|
|
3089
|
+
})
|
|
3090
|
+
React.useEffect(() => () => {
|
|
3091
|
+
for (const timer of motionRef.current.timers.values()) clearTimeout(timer)
|
|
3092
|
+
motionRef.current.timers.clear()
|
|
3093
|
+
}, [])
|
|
3094
|
+
/** 把这一帧要「离开」的行按原位插回去(只在真机上会非空,逻辑在 `mergeGhostRows`)。 */
|
|
3095
|
+
const withGhosts = (tierKey, docs) =>
|
|
3096
|
+
mergeGhostRows(docs, [...motion.ghosts.values()], tierKey)
|
|
3097
|
+
|
|
3098
|
+
/** 渲染一个条目:媒体一律出方形卡片(媒体视图与「全部」的媒体区共用),其余出文档行。
|
|
3099
|
+
* `withLife` 只有**分层视图**(Context Pack 三层 + 其他相关文档)才给真 —— 时间序、
|
|
3100
|
+
* 筛选结果、「全部」都不显示生命周期:那一屏说的不是「这个包里的文档现在什么状态」。 */
|
|
3101
|
+
const renderEntry = (doc, num, primary, mark, withLife) => {
|
|
2182
3102
|
const common = {
|
|
2183
3103
|
key: doc.path || doc.rel,
|
|
2184
3104
|
doc,
|
|
@@ -2194,7 +3114,20 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2194
3114
|
// 于是返回空串,那一行不渲染。
|
|
2195
3115
|
// `num` / `primary` 只有分层视图会传(Design §11 / §13);平铺列表照旧无序号。
|
|
2196
3116
|
// `mark`=没号时同列的占位标记,只在「这一屏里有号」时为真。
|
|
2197
|
-
|
|
3117
|
+
// 进出动效只在真机上跑(`motionOn`):测试替身没有 DOM,`motionAllowed()` 挡掉,
|
|
3118
|
+
// 于是渲染树里既没有 `entering` 也没有 `leaving`,与没有这段动效时逐字一致。
|
|
3119
|
+
// v0.18:生命周期现在是**一枚 glyph + 一段极短的文字**。glyph 可点:
|
|
3120
|
+
// 点它=打开 / 选中这一篇(**已经打开则保持原预览**,不重开也不重拉)。
|
|
3121
|
+
const info = withLife ? lifeInfo(doc.rel) : null
|
|
3122
|
+
return h(DocRow, { ...common, relevance, why: whyText(doc.reason), num, mark, primary,
|
|
3123
|
+
life: info ? info.text : null,
|
|
3124
|
+
glyph: info,
|
|
3125
|
+
onGlyph: (target) => {
|
|
3126
|
+
if (preview && preview.rel === target.rel) return
|
|
3127
|
+
openPreview(target)
|
|
3128
|
+
},
|
|
3129
|
+
entering: motion.entered.has(doc.rel) ? motion.entered.get(doc.rel) : null,
|
|
3130
|
+
leaving: Boolean(doc.knitLeaving) })
|
|
2198
3131
|
}
|
|
2199
3132
|
|
|
2200
3133
|
/** 「全部」的分区标题:类型名 + 「已显示 / 总数」+ 被截断时的「查看全部」。 */
|
|
@@ -2216,7 +3149,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2216
3149
|
const allSections = [
|
|
2217
3150
|
docItems.length === 0 ? null : h('div', { className: 'knit-section', key: 'docs' },
|
|
2218
3151
|
sectionHead('kind.doc', shownDocs.length, docItems.length, KIND_DOC),
|
|
2219
|
-
docsGrid(shownDocs)),
|
|
3152
|
+
docsGrid(withGhosts(MOTION_TIER_ALL_DOCS, shownDocs))),
|
|
2220
3153
|
mediaItems.length === 0 ? null : h('div', { className: 'knit-section', key: 'media' },
|
|
2221
3154
|
// 媒体不截断,所以只给一个标题,不给「已显示 / 总数」和「查看全部」
|
|
2222
3155
|
h('div', { className: 'knit-section-head' },
|
|
@@ -2242,7 +3175,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2242
3175
|
? allSections
|
|
2243
3176
|
: contextView
|
|
2244
3177
|
? contextBody(contextView)
|
|
2245
|
-
: docsGrid(visibleDocs)
|
|
3178
|
+
: docsGrid(withGhosts(MOTION_TIER_FLAT, visibleDocs))
|
|
2246
3179
|
|
|
2247
3180
|
// 排序说明那一行(.knit-topic)**2026-09-30 已整体删除**:排序方式由头部那个
|
|
2248
3181
|
// 「相关 / 最新」切换按钮自己表达(按钮上就写着当前选的是哪个),再补一句
|
|
@@ -2250,32 +3183,245 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2250
3183
|
// title 里(可见文本本来就不许出现关键词,test/i18n.test.mjs 有守卫)。
|
|
2251
3184
|
// ⚠️ i18n 里那四个 topic.* 键已同时删除,不要为了「以后可能用」留着。
|
|
2252
3185
|
|
|
2253
|
-
/* v0.
|
|
2254
|
-
|
|
3186
|
+
/* v0.18「Context Usage Lens」:列表**上方**的一块轻量观察层。
|
|
3187
|
+
它按**视觉层级**回答四件事(规格 §9 的三层):
|
|
3188
|
+
Level 1 当前上下文 Coverage(这一份上下文被用到什么程度)
|
|
3189
|
+
Level 2 最近读取(最近一次成功读的是什么)
|
|
3190
|
+
Level 3 上下文外读取 / 上下文变化(辅助事实)
|
|
3191
|
+
三块不能一样重 —— 靠**空间与字号**拉开,不靠横线、不靠颜色、不靠卡片。
|
|
2255
3192
|
⚠️ 不许出现分数 / 百分比 / 评分条 / 置信度 / 「AI 判断」这类词:用户要知道的是
|
|
2256
|
-
「这份上下文有没有被用上」,不是「它好不好用」。**没有任何一行是估算出来的。**
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
if (
|
|
2274
|
-
if (s.outside) parts.push(t('usage.outside', { n: s.outside }))
|
|
2275
|
-
if (s.churn && s.churn.snapshots) parts.push(t('usage.changes', { n: s.churn.snapshots }))
|
|
3193
|
+
「这份上下文有没有被用上」,不是「它好不好用」。**没有任何一行是估算出来的。**
|
|
3194
|
+
⚠️ 关掉使用情况时**一个节点都不加**(`.knit-usage` 整个不渲染,与 v0.17 一致)。*/
|
|
3195
|
+
|
|
3196
|
+
const usageNow = usageOn && state.usage && state.usage.stats ? state.usage : null
|
|
3197
|
+
// 「Epoch N」只在标题行显示一次:`epochId` 是**累计编号**(换一次 +1),
|
|
3198
|
+
// 一份包都没交过时是 null,整个角标不显示(SDD §20)。
|
|
3199
|
+
const epochText = usageNow && Number.isInteger(usageNow.epochId)
|
|
3200
|
+
? t('lens.epoch', { n: usageNow.epochId })
|
|
3201
|
+
: ''
|
|
3202
|
+
// 摘要行=三件纯事实,一行读完。**不写 Primary 文件名、不写「辅助 0/3」**——
|
|
3203
|
+
// 那两件事下面的 Coverage 说得更准、更短(规格 §10)。
|
|
3204
|
+
const lensSummary = (() => {
|
|
3205
|
+
if (!usageNow) return t('usage.none')
|
|
3206
|
+
const s = usageNow.stats
|
|
3207
|
+
const parts = [t('lens.reads', { n: s.reads || 0 })]
|
|
3208
|
+
if (s.outside) parts.push(t('lens.outside', { n: s.outside }))
|
|
3209
|
+
const changes = s.churn && s.churn.snapshots ? s.churn.snapshots : 0
|
|
3210
|
+
if (changes) parts.push(t('lens.changes', { n: changes }))
|
|
2276
3211
|
return parts.join(' · ')
|
|
2277
3212
|
})()
|
|
2278
3213
|
|
|
3214
|
+
/* v0.17 的三条事实 —— 全部只在「使用情况」开着、且宿主真的回传了 `usage` 时出现。
|
|
3215
|
+
⚠️ 这里没有时间线、没有全量事件、没有评分 —— 「最近一次」就只有一条。 */
|
|
3216
|
+
|
|
3217
|
+
// ── Level 1:当前上下文 Coverage ────────────────────────────────
|
|
3218
|
+
// ⚠️ 用 `state.context` 的三层**原始** rels(不是 `contextView`:那一份被过滤框
|
|
3219
|
+
// 子集化、而且只在文档档 + 相关序成立),再叠上 `usage.lifecycle` —— 纯派生,
|
|
3220
|
+
// 不新增任何一份自己的状态(「能派生就不要存储」)。
|
|
3221
|
+
const coverage = coverageOf({
|
|
3222
|
+
primary: (state.context && state.context.primary) || [],
|
|
3223
|
+
supporting: (state.context && state.context.supporting) || [],
|
|
3224
|
+
related: (state.context && state.context.related) || [],
|
|
3225
|
+
}, usageNow ? usageNow.lifecycle : null)
|
|
3226
|
+
const coverageNode = contextView ? h('div', { className: 'knit-lens-sec', key: 'cov' },
|
|
3227
|
+
h('div', { className: 'knit-lens-cap' }, t('lens.currentContext')),
|
|
3228
|
+
h('div', { className: 'knit-cov' },
|
|
3229
|
+
['primary', 'supporting', 'related']
|
|
3230
|
+
// Primary 可以被一份包整体缺席 —— 那就整列不显示,而不是画一个
|
|
3231
|
+
// 「0 / 0」的假层(规格 §11:Knit 不能假设一定有 Primary)。
|
|
3232
|
+
.filter((key) => !(key === 'primary' && coverage.primary.total === 0))
|
|
3233
|
+
.map((key) => h('button', {
|
|
3234
|
+
className: 'knit-cov-col',
|
|
3235
|
+
key,
|
|
3236
|
+
type: 'button',
|
|
3237
|
+
title: t('lens.locate', { tier: t(`tierName.${key}`) }),
|
|
3238
|
+
// 读屏的说法是完整一句「主要上下文:0 / 1 篇已读」(md §六十三)——
|
|
3239
|
+
// 但**视觉上不显示这句话**:屏幕上给的是层名 + `n / m` + 圆点。
|
|
3240
|
+
'aria-label': t('lens.coverageAria', {
|
|
3241
|
+
tier: t(`tierName.${key}`),
|
|
3242
|
+
read: coverage[key].read,
|
|
3243
|
+
total: coverage[key].total,
|
|
3244
|
+
}),
|
|
3245
|
+
onClick: () => locateTier(key),
|
|
3246
|
+
},
|
|
3247
|
+
// 视觉(点)与文本(已读 ÷ 本层总数)**同时**存在:只给点读不出「读了几篇」,
|
|
3248
|
+
// 只给数字又看不出「是哪几篇」。没有进度条、没有百分比。
|
|
3249
|
+
// ⚠️ **顺序**是「层名 → 数字 → 圆点」,不要调换:这三个是 grid 的同一套单元格,
|
|
3250
|
+
// 自动排布按 DOM 顺序找空位 —— 层名占第 1 行第 1 列、数字占第 1 行第 2 列、
|
|
3251
|
+
// 圆点那一条横跨两列,于是必然落到第 2 行(换顺序数字会被挤到圆点下面一行)。
|
|
3252
|
+
h('span', { className: 'knit-cov-name' }, t(`tierName.${key}`)),
|
|
3253
|
+
h('span', { className: 'knit-cov-num' },
|
|
3254
|
+
`${coverage[key].read} / ${coverage[key].total}`),
|
|
3255
|
+
// v0.18 UI 迭代:**真的圆**(9px,见 CSS),不再是 `○ ●` 字符 —— 字符圆点在不同
|
|
3256
|
+
// 字体下大小不一,正是「不像设计稿」的那一处。点本身对读屏是装饰(aria-hidden),
|
|
3257
|
+
// 「几篇已读」由上面那个 aria-label 的完整句子说。
|
|
3258
|
+
h('span', { className: 'knit-cov-dots' },
|
|
3259
|
+
coverage[key].rels.map((item) => h('span', {
|
|
3260
|
+
className: `knit-cov-dot${item.read ? ' on' : ''}`,
|
|
3261
|
+
key: item.rel,
|
|
3262
|
+
'aria-hidden': 'true',
|
|
3263
|
+
}))))))) : null
|
|
3264
|
+
|
|
3265
|
+
// ── Level 2:最近读取(最近一次**成功** read;不是「正在阅读」)──────
|
|
3266
|
+
const recent = usageNow && usageNow.recentRead ? usageNow.recentRead : null
|
|
3267
|
+
const recentNode = h('div', { className: 'knit-lens-sec', key: 'recent' },
|
|
3268
|
+
h('div', { className: 'knit-lens-name' }, t('lens.recentRead')),
|
|
3269
|
+
recent && recent.rel
|
|
3270
|
+
? h('button', {
|
|
3271
|
+
className: 'knit-read-row',
|
|
3272
|
+
type: 'button',
|
|
3273
|
+
title: t('lens.openDoc', { rel: recent.rel }),
|
|
3274
|
+
// 这一行整行可点(打开预览),所以它需要一个**完整的可访问名**(md §二十二):
|
|
3275
|
+
// 只有 title 的话读屏在部分平台读不出「这是干什么的」。
|
|
3276
|
+
'aria-label': t('lens.openDoc', { rel: recent.rel }),
|
|
3277
|
+
onClick: () => openDocByRel(recent.rel),
|
|
3278
|
+
},
|
|
3279
|
+
h('span', { className: 'knit-read-rel' }, recent.rel),
|
|
3280
|
+
h('span', { className: 'knit-read-time' }, relTime(recent.at, tick)),
|
|
3281
|
+
// 箭头是装饰(对读屏隐藏);不要前导空格 —— 间距由 .knit-read-row 的 gap 给。
|
|
3282
|
+
h('span', { className: 'knit-read-go', 'aria-hidden': 'true' }, '›'))
|
|
3283
|
+
: h('div', { className: 'knit-lens-empty' }, t('lens.recentNone')))
|
|
3284
|
+
|
|
3285
|
+
// ── Level 3a:上下文外读取(可浏览集合;排序是**事实排序**)─────────
|
|
3286
|
+
const outsideList = usageNow && Array.isArray(usageNow.outsideDocs) ? usageNow.outsideDocs : []
|
|
3287
|
+
const outsideSorted = groupOutsideDocs(outsideList)
|
|
3288
|
+
const outsideNode = outsideSorted.length > 0
|
|
3289
|
+
? h('div', { className: 'knit-usage-more', key: 'gap' },
|
|
3290
|
+
h('button', {
|
|
3291
|
+
className: 'knit-more-btn',
|
|
3292
|
+
type: 'button',
|
|
3293
|
+
'aria-expanded': gapOpen ? 'true' : 'false',
|
|
3294
|
+
onClick: () => setGapOpen((value) => !value),
|
|
3295
|
+
},
|
|
3296
|
+
// 菜单行的三段(md §三十四):「label ── 数量 ›」。原来把两条信息压在一个字符串里
|
|
3297
|
+
// (`上下文外读取 · 20`),数字既不右对齐、也不能单独参与排版。
|
|
3298
|
+
h('span', { className: 'knit-more-label' }, t('lens.outsideDocs')),
|
|
3299
|
+
h('span', { className: 'knit-more-meta' }, String(outsideSorted.length)),
|
|
3300
|
+
h('span', { className: 'knit-read-go', 'aria-hidden': 'true' }, gapOpen ? '⌃' : '›')),
|
|
3301
|
+
gapOpen ? h('div', { className: 'knit-gap-list' },
|
|
3302
|
+
// 每一行都是**可点对象**(点开预览),但**不许**加入 Context ——
|
|
3303
|
+
// V0.18 不做 Context Control(规格 §19)。
|
|
3304
|
+
// 行首序号(md §三十六):让展开的包外列表可数,并把 rel 与次数隔开。
|
|
3305
|
+
// 序号说的是**位置**(第几篇),不是评分。
|
|
3306
|
+
outsideSorted.slice(0, MAX_OUTSIDE_SHOWN).map((row, i) => h('button', {
|
|
3307
|
+
className: 'knit-out-row',
|
|
3308
|
+
key: row.rel,
|
|
3309
|
+
type: 'button',
|
|
3310
|
+
title: t('lens.openDoc', { rel: row.rel }),
|
|
3311
|
+
onClick: () => openDocByRel(row.rel),
|
|
3312
|
+
},
|
|
3313
|
+
h('span', { className: 'knit-out-num' }, String(i + 1).padStart(2, '0')),
|
|
3314
|
+
h('span', { className: 'knit-out-rel' }, row.rel),
|
|
3315
|
+
h('span', { className: 'knit-out-count' }, `×${row.count}`),
|
|
3316
|
+
// 每一行都带生命周期:**复用 v0.17 那一份数据**,不维护第二套。
|
|
3317
|
+
// ⚠️ 用 `lifeWord`(状态词)而不是 `lifecycleLabel`(短次数):左边已经有 `×N` 了。
|
|
3318
|
+
h('span', { className: 'knit-life' }, lifeWord(row.rel)))),
|
|
3319
|
+
outsideSorted.length > MAX_OUTSIDE_SHOWN
|
|
3320
|
+
? h('div', { className: 'knit-gap-row' },
|
|
3321
|
+
h('span', { className: 'knit-gap-rel' },
|
|
3322
|
+
t('lens.more', { n: outsideSorted.length - MAX_OUTSIDE_SHOWN })))
|
|
3323
|
+
: null) : null)
|
|
3324
|
+
: null
|
|
3325
|
+
|
|
3326
|
+
// 层级的**短名**:分组标题那套长文案(主要上下文 / 辅助上下文 / 相关上下文)在变化行里太长。
|
|
3327
|
+
const tierShort = (key) => {
|
|
3328
|
+
if (key === 'primary') return t('tierName.primary')
|
|
3329
|
+
if (key === 'supporting') return t('tierName.supporting')
|
|
3330
|
+
if (key === 'related') return t('tierName.related')
|
|
3331
|
+
return ''
|
|
3332
|
+
}
|
|
3333
|
+
const delta = usageNow && usageNow.latestDelta ? usageNow.latestDelta : null
|
|
3334
|
+
const deltaLine = (text, key) => h('div', { className: 'knit-delta-row', key },
|
|
3335
|
+
h('span', { className: 'knit-delta-rel' }, text))
|
|
3336
|
+
/** `moved` 的两种载荷都认:v0.17 起宿主给的是 `{tier,rank}`,旧夹具里是裸层名。 */
|
|
3337
|
+
const tierOf = (value) => (value && typeof value === 'object' ? value.tier : value)
|
|
3338
|
+
const deltaText = (kind, item) => {
|
|
3339
|
+
if (kind === 'enter') return `+ ${item.rel}`
|
|
3340
|
+
if (kind === 'leave') return `- ${item.rel}`
|
|
3341
|
+
return `↔ ${item.rel} · ${tierShort(tierOf(item.from))} → ${tierShort(tierOf(item.to))}`
|
|
3342
|
+
}
|
|
3343
|
+
// 摘要行的符号只用 `+` `-` `↔` 三个通用符号,不用颜色区分「进 / 出」。
|
|
3344
|
+
const grouped = groupDelta(delta)
|
|
3345
|
+
const deltaDigest = []
|
|
3346
|
+
for (const item of grouped.enter) {
|
|
3347
|
+
deltaDigest.push({ key: `plus-${item.rel}`, text: deltaText('enter', item) })
|
|
3348
|
+
}
|
|
3349
|
+
for (const item of grouped.leave) {
|
|
3350
|
+
deltaDigest.push({ key: `minus-${item.rel}`, text: deltaText('leave', item) })
|
|
3351
|
+
}
|
|
3352
|
+
for (const item of grouped.move) {
|
|
3353
|
+
deltaDigest.push({ key: `move-${item.rel}`, text: deltaText('move', item) })
|
|
3354
|
+
}
|
|
3355
|
+
if (delta && delta.taskChanged) deltaDigest.push({ key: 'task', text: t('usage.deltaTask') })
|
|
3356
|
+
const deltaGroups = [
|
|
3357
|
+
{ key: 'enter', label: t('usage.deltaEnter'),
|
|
3358
|
+
rows: grouped.enter.map((item) => ({ key: `plus-${item.rel}`, text: deltaText('enter', item) })) },
|
|
3359
|
+
{ key: 'leave', label: t('usage.deltaLeave'),
|
|
3360
|
+
rows: grouped.leave.map((item) => ({ key: `minus-${item.rel}`, text: deltaText('leave', item) })) },
|
|
3361
|
+
{ key: 'move', label: t('usage.deltaMove'),
|
|
3362
|
+
rows: grouped.move.map((item) => ({ key: `move-${item.rel}`, text: deltaText('move', item) })) },
|
|
3363
|
+
].filter((group) => group.rows.length > 0)
|
|
3364
|
+
// ⚠️ `compact` 必须在 `previewLines` 之前算出来(TDZ)。
|
|
3365
|
+
const compact = panelH > 0 && panelH < COMPACT_PANEL_PX
|
|
3366
|
+
// 面板矮的时候收起态**不铺摘要行** —— 只留标题,点开照常看得到。
|
|
3367
|
+
const previewLines = compact ? [] : deltaDigest.slice(0, MAX_DELTA_SHOWN)
|
|
3368
|
+
const deltaNode = delta
|
|
3369
|
+
? h('div', { className: 'knit-usage-more', key: 'delta' },
|
|
3370
|
+
h('button', {
|
|
3371
|
+
className: 'knit-more-btn',
|
|
3372
|
+
type: 'button',
|
|
3373
|
+
'aria-expanded': deltaOpen ? 'true' : 'false',
|
|
3374
|
+
onClick: () => setDeltaOpen((value) => !value),
|
|
3375
|
+
},
|
|
3376
|
+
// 菜单行的三段(md §三十八):「上下文变化 ── 最近一次 ›」。
|
|
3377
|
+
// ⚠️ 这里**不再写条数**(原来是 `上下文变化 · 11`):变化永远只说最近一次,
|
|
3378
|
+
// 「有几条」由展开后的行数与「还有 N 条」承担 —— 数字写在按钮上时,
|
|
3379
|
+
// 折叠摘要、分组尾巴、按钮三处会各自算一遍,很容易自相矛盾。
|
|
3380
|
+
h('span', { className: 'knit-more-label' }, t('lens.delta')),
|
|
3381
|
+
h('span', { className: 'knit-more-meta' }, t('lens.deltaLatest')),
|
|
3382
|
+
h('span', { className: 'knit-read-go', 'aria-hidden': 'true' }, deltaOpen ? '⌃' : '›')),
|
|
3383
|
+
// ⚠️ 展开后**不再画折叠摘要**:分组视图是它的超集(三行摘要 + 「还有 N 条」再叠上
|
|
3384
|
+
// 分组明细,同一条事实会在同一块里出现两遍 —— 2026-10-05 用真实载荷渲染时抓到)。
|
|
3385
|
+
deltaOpen ? null : previewLines.map((line) => deltaLine(line.text, line.key)),
|
|
3386
|
+
!deltaOpen && !compact && deltaDigest.length > MAX_DELTA_SHOWN
|
|
3387
|
+
? deltaLine(t('usage.deltaMore', { n: deltaDigest.length - MAX_DELTA_SHOWN }), 'more')
|
|
3388
|
+
: null,
|
|
3389
|
+
deltaOpen ? deltaGroups
|
|
3390
|
+
.map((group) => [
|
|
3391
|
+
h('div', { className: 'knit-delta-head', key: `${group.key}-head` }, group.label),
|
|
3392
|
+
...group.rows.slice(0, MAX_DELTA_GROUP)
|
|
3393
|
+
.map((line) => deltaLine(line.text, `${group.key}-${line.key}`)),
|
|
3394
|
+
group.rows.length > MAX_DELTA_GROUP
|
|
3395
|
+
? deltaLine(t('usage.deltaMore', { n: group.rows.length - MAX_DELTA_GROUP }),
|
|
3396
|
+
`${group.key}-more`)
|
|
3397
|
+
: null,
|
|
3398
|
+
]) : null,
|
|
3399
|
+
// ⚠️ 「任务上下文已更新」不是进出换层,没有分组标题可挂 —— 但它算在
|
|
3400
|
+
// `deltaDigest.length` 里(按钮上那个数字就是它)。展开时漏掉这一行,
|
|
3401
|
+
// 就会出现「按钮说 6 条、下面只列出 5 行」的自相矛盾(2026-10-05 用真实载荷渲染时抓到)。
|
|
3402
|
+
// 它在摘要里的位置本来就是最后一条,这里也放最后。
|
|
3403
|
+
deltaOpen && delta && delta.taskChanged
|
|
3404
|
+
? deltaLine(t('usage.deltaTask'), 'task')
|
|
3405
|
+
: null)
|
|
3406
|
+
: null
|
|
3407
|
+
|
|
3408
|
+
// ── Lens 整块:标题行(可点,展开 / 收起)+ 摘要行 + 细节 ──────────
|
|
3409
|
+
// ⚠️ 「收起」不等于「关掉统计」:收起只表示「统计开着,但暂时不想看细节」(规格 §25)。
|
|
3410
|
+
const lensNode = h('div', { className: 'knit-usage', title: t('usage.note') },
|
|
3411
|
+
h('button', {
|
|
3412
|
+
className: 'knit-lens-head',
|
|
3413
|
+
type: 'button',
|
|
3414
|
+
'aria-expanded': lensOpen ? 'true' : 'false',
|
|
3415
|
+
title: lensOpen ? t('lens.collapse') : t('lens.expand'),
|
|
3416
|
+
onClick: () => setLensOpen((value) => !value),
|
|
3417
|
+
},
|
|
3418
|
+
h('span', { className: 'knit-lens-title' }, t('lens.title')),
|
|
3419
|
+
epochText ? h('span', { className: 'knit-lens-epoch' }, epochText) : null,
|
|
3420
|
+
h('span', { className: 'knit-read-go', 'aria-hidden': 'true' }, lensOpen ? ' ˄' : ' ˅')),
|
|
3421
|
+
h('div', { className: 'knit-lens-sum' }, lensSummary),
|
|
3422
|
+
lensOpen ? h('div', { className: 'knit-lens-body' },
|
|
3423
|
+
coverageNode, recentNode, outsideNode, deltaNode) : null)
|
|
3424
|
+
|
|
2279
3425
|
// 不同类型用不同量词:文档「篇」、媒体「个」、混排「项」。
|
|
2280
3426
|
const countKey = kind === KIND_MEDIA
|
|
2281
3427
|
? (filtering ? 'count.media.filtered' : 'count.media')
|
|
@@ -2344,8 +3490,9 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2344
3490
|
title: t('kind.title'),
|
|
2345
3491
|
onClick: () => pickKind(value),
|
|
2346
3492
|
}, t(labelKey)))),
|
|
2347
|
-
// v0.15
|
|
2348
|
-
|
|
3493
|
+
// v0.15:开了才显示。v0.18:这一块是「Context Usage Lens」——
|
|
3494
|
+
// 列表**上方**的观察层,不是弹窗、不是新页面、不是 Dashboard。
|
|
3495
|
+
usageOn ? lensNode : null,
|
|
2349
3496
|
notice ? h('div', { className: 'knit-notice' }, notice) : null,
|
|
2350
3497
|
// 列表节点**直接挂上去**(2026-09-29 起永远单栏;曾经它要交给一个 IIFE
|
|
2351
3498
|
// 决定塞进单栏还是双栏的左列)。**输出与 v0.13 逐字一致** ——
|