dsh-knit 0.11.0 → 0.12.1
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 +578 -0
- package/README.en.md +6 -4
- package/README.md +4 -3
- package/package.json +4 -3
- package/src/client/client.js +228 -10
- package/src/host/index.js +18 -1
- package/src/host/links.js +304 -0
- package/test/client.test.mjs +180 -0
- package/test/fixture.mjs +6 -1
- package/test/host-http.test.mjs +80 -2
- package/test/i18n.test.mjs +123 -3
- package/test/links.test.mjs +271 -0
package/src/client/client.js
CHANGED
|
@@ -68,6 +68,17 @@ window.__ModuleLoader__.load({
|
|
|
68
68
|
'list.empty': '这个工作区里还没有 Markdown 文档。',
|
|
69
69
|
'list.emptyMedia': '这个工作区里还没有图片或视频。',
|
|
70
70
|
'list.noMatch': '没有匹配「{query}」的文档。',
|
|
71
|
+
// 文档列表这个 listbox 的无障碍名字(原先硬编码在 JSX 里,英文界面下会漏出中文)
|
|
72
|
+
'list.aria': '最近文档',
|
|
73
|
+
|
|
74
|
+
// 相对时间。⚠️ 这六条原先**硬编码在 relTime() 里**,英文界面下会漏出中文
|
|
75
|
+
// (2026-09-19 被真机截图抓出来的)。**加时间粒度时必须同时加中英两条。**
|
|
76
|
+
'time.justNow': '刚刚',
|
|
77
|
+
'time.minutesAgo': '{n}分钟前',
|
|
78
|
+
'time.hoursAgo': '{n}小时前',
|
|
79
|
+
'time.yesterday': '昨天',
|
|
80
|
+
'time.daysAgo': '{n}天前',
|
|
81
|
+
'time.monthDay': '{month}月{day}日',
|
|
71
82
|
|
|
72
83
|
'media.play': '播放视频',
|
|
73
84
|
|
|
@@ -85,6 +96,15 @@ window.__ModuleLoader__.load({
|
|
|
85
96
|
'preview.openLocalBtn': '在本地打开',
|
|
86
97
|
'preview.close': '收起预览',
|
|
87
98
|
'preview.resizeTitle': '拖动调整高度',
|
|
99
|
+
// v0.12 引用条。⚠️ 不放任何表情符号(test/i18n.test.mjs 有守卫)。
|
|
100
|
+
'links.summary': '被引用 {in} · 引用了 {out}',
|
|
101
|
+
'links.incoming': '被引用',
|
|
102
|
+
'links.outgoing': '引用了',
|
|
103
|
+
'links.noneIn': '没有被引用',
|
|
104
|
+
'links.noneOut': '没有引用别的文档',
|
|
105
|
+
'links.more': '还有 {count} 篇',
|
|
106
|
+
'links.failed': '引用关系读取失败',
|
|
107
|
+
'links.incomplete': '工作区较大,结果可能不完整',
|
|
88
108
|
'preview.rawFallback': '原生 Markdown 渲染不可用,下面是纯文本。请看控制台的 [knit] 日志。',
|
|
89
109
|
'code.copy': '复制',
|
|
90
110
|
'code.copied': '已复制',
|
|
@@ -157,6 +177,18 @@ window.__ModuleLoader__.load({
|
|
|
157
177
|
'list.empty': 'No Markdown documents in this workspace yet.',
|
|
158
178
|
'list.emptyMedia': 'No images or videos in this workspace yet.',
|
|
159
179
|
'list.noMatch': 'No documents match “{query}”.',
|
|
180
|
+
// Accessible name of the document listbox (was hardcoded in JSX before)
|
|
181
|
+
'list.aria': 'Recent documents',
|
|
182
|
+
|
|
183
|
+
// Relative time. ⚠️ These six used to be **hardcoded inside relTime()** and leaked
|
|
184
|
+
// Chinese into the English UI (caught by a real-machine screenshot, 2026-09-19).
|
|
185
|
+
// **Add both languages whenever you add a granularity.**
|
|
186
|
+
'time.justNow': 'just now',
|
|
187
|
+
'time.minutesAgo': '{n} min ago',
|
|
188
|
+
'time.hoursAgo': '{n} h ago',
|
|
189
|
+
'time.yesterday': 'yesterday',
|
|
190
|
+
'time.daysAgo': '{n} d ago',
|
|
191
|
+
'time.monthDay': '{month}/{day}',
|
|
160
192
|
|
|
161
193
|
'media.play': 'Play video',
|
|
162
194
|
|
|
@@ -174,6 +206,14 @@ window.__ModuleLoader__.load({
|
|
|
174
206
|
'preview.openLocalBtn': 'Open locally',
|
|
175
207
|
'preview.close': 'Close preview',
|
|
176
208
|
'preview.resizeTitle': 'Drag to resize',
|
|
209
|
+
'links.summary': 'Referenced by {in} · links to {out}',
|
|
210
|
+
'links.incoming': 'Referenced by',
|
|
211
|
+
'links.outgoing': 'Links to',
|
|
212
|
+
'links.noneIn': 'Not referenced by anything',
|
|
213
|
+
'links.noneOut': 'Links to no other document',
|
|
214
|
+
'links.more': '{count} more',
|
|
215
|
+
'links.failed': 'Could not read references',
|
|
216
|
+
'links.incomplete': 'Large workspace — results may be incomplete',
|
|
177
217
|
'preview.rawFallback': 'Native Markdown rendering is unavailable — showing plain text. Check the [knit] logs in the console.',
|
|
178
218
|
'code.copy': 'Copy',
|
|
179
219
|
'code.copied': 'Copied',
|
|
@@ -283,6 +323,9 @@ window.__ModuleLoader__.load({
|
|
|
283
323
|
const LIST_API = '/knit/api/recent'
|
|
284
324
|
const DOC_API = '/knit/api/doc'
|
|
285
325
|
const RAW_API = '/knit/api/raw'
|
|
326
|
+
// v0.12:某篇的「谁引用了它 / 它引用了谁」。与上面三条一样是**同源相对地址**,
|
|
327
|
+
// 所以仍然满足「客户端零网络出口」那条守卫(test/security.test.mjs)。
|
|
328
|
+
const LINKS_API = '/knit/api/links'
|
|
286
329
|
|
|
287
330
|
/** 轮询间隔。 */
|
|
288
331
|
const POLL_MS = 5000
|
|
@@ -529,6 +572,32 @@ body[data-ds-dark-theme] .knit-preview{box-shadow:0 -8px 24px rgba(0,0,0,.38)}
|
|
|
529
572
|
color:var(--dsw-alias-label-secondary,#9aa0a6);font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
530
573
|
.knit-preview-note{font-size:11px;color:var(--dsw-alias-label-caption,#80868b);padding:2px 0 8px}
|
|
531
574
|
|
|
575
|
+
/* ── 引用条(v0.12)────────────────────────────────────
|
|
576
|
+
夹在预览头与正文之间的一层。全用中性令牌:它是「信息」,不是「操作」。
|
|
577
|
+
注意 CSS 里不要写反引号 —— 这段样式是模板字符串,一个反引号就会把它截断。 */
|
|
578
|
+
.knit-links{flex:none;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.08));
|
|
579
|
+
font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
|
|
580
|
+
.knit-links-state{padding:5px 12px;color:var(--dsw-alias-label-caption,#80868b)}
|
|
581
|
+
.knit-links-head{box-sizing:border-box;display:flex;align-items:center;gap:6px;width:100%;
|
|
582
|
+
padding:5px 12px;background:transparent;border:none;cursor:pointer;text-align:left;
|
|
583
|
+
font:inherit;color:inherit}
|
|
584
|
+
.knit-links-head:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
585
|
+
.knit-links-arrow{flex:none;width:10px;font-size:9px;opacity:.75}
|
|
586
|
+
.knit-links-summary{flex:1 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
587
|
+
.knit-links-note{padding:2px 12px 6px;color:var(--dsw-alias-label-caption,#80868b)}
|
|
588
|
+
.knit-links-body{padding:0 12px 8px;max-height:180px;overflow:auto}
|
|
589
|
+
.knit-links-group + .knit-links-group{margin-top:6px}
|
|
590
|
+
.knit-links-label{font-weight:600;color:var(--dsw-alias-label-caption,#80868b);margin-bottom:2px}
|
|
591
|
+
.knit-links-empty{color:var(--dsw-alias-label-caption,#80868b);padding:1px 0}
|
|
592
|
+
.knit-links-list{list-style:none;margin:0;padding:0}
|
|
593
|
+
.knit-link-row{box-sizing:border-box;display:block;width:100%;text-align:left;padding:2px 4px;
|
|
594
|
+
border:none;background:transparent;border-radius:4px;cursor:pointer;font:inherit;color:inherit}
|
|
595
|
+
.knit-link-row:hover{background:var(--knit-hover-bg,rgba(255,255,255,.03))}
|
|
596
|
+
.knit-link-name{display:block;color:var(--dsw-alias-label-primary,#e8eaed);
|
|
597
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
598
|
+
.knit-link-path{display:block;font-size:10px;color:var(--dsw-alias-label-caption,#80868b);
|
|
599
|
+
overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
600
|
+
|
|
532
601
|
/* ── 类型切换(文档 / 图片与视频 / 全部)────────────── */
|
|
533
602
|
/* 选中态与下面的列表行、上面的排序切换共用一套中性灰填充,**不要品牌色描边**:
|
|
534
603
|
用户的原话是「选中的时候不用加绿色、蓝色的描边,就跟下面列表一样,
|
|
@@ -835,22 +904,27 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
835
904
|
|
|
836
905
|
/**
|
|
837
906
|
* 人类可读的相对时间。
|
|
907
|
+
*
|
|
908
|
+
* ⚠️ **文案必须走 `t()`。** 这六条原先硬编码中文,英文界面下会漏出「3 分钟前」——
|
|
909
|
+
* 2026-09-19 的真机截图把它抓出来了(`test/i18n.test.mjs` 有守卫:
|
|
910
|
+
* 英文渲染出来的整棵树里不许出现汉字)。
|
|
911
|
+
*
|
|
838
912
|
* @param {number} ms - 文件 mtime(epoch ms)
|
|
839
913
|
* @param {number} now - 当前时间
|
|
840
|
-
* @returns {string} 刚刚 / X分钟前 / X小时前 / 昨天 / X天前 /
|
|
914
|
+
* @returns {string} 刚刚 / X分钟前 / X小时前 / 昨天 / X天前 / 月日(按当前语言)
|
|
841
915
|
*/
|
|
842
916
|
function relTime(ms, now) {
|
|
843
917
|
const diff = Math.max(0, now - ms)
|
|
844
918
|
const min = Math.floor(diff / 60000)
|
|
845
|
-
if (min < 1) return '
|
|
846
|
-
if (min < 60) return
|
|
919
|
+
if (min < 1) return t('time.justNow')
|
|
920
|
+
if (min < 60) return t('time.minutesAgo', { n: min })
|
|
847
921
|
const hour = Math.floor(min / 60)
|
|
848
|
-
if (hour < 24) return
|
|
922
|
+
if (hour < 24) return t('time.hoursAgo', { n: hour })
|
|
849
923
|
const day = Math.floor(hour / 24)
|
|
850
|
-
if (day === 1) return '
|
|
851
|
-
if (day < 30) return
|
|
924
|
+
if (day === 1) return t('time.yesterday')
|
|
925
|
+
if (day < 30) return t('time.daysAgo', { n: day })
|
|
852
926
|
const d = new Date(ms)
|
|
853
|
-
return
|
|
927
|
+
return t('time.monthDay', { month: d.getMonth() + 1, day: d.getDate() })
|
|
854
928
|
}
|
|
855
929
|
|
|
856
930
|
/**
|
|
@@ -988,10 +1062,76 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
988
1062
|
* @param {{preview:object,pathImages:object|null,fullscreen:boolean,onClose:Function,onOpenLocal:Function|null,onToggleFullscreen:Function,onResizeStart:Function}} props - 渲染入参
|
|
989
1063
|
* @returns {import('react').ReactElement} 元素
|
|
990
1064
|
*/
|
|
991
|
-
function PreviewPanel({ preview, pathImages, fullscreen, ratio, reading, onClose, onOpenLocal, onToggleFullscreen, onResizeStart, onScrollBody }) {
|
|
1065
|
+
function PreviewPanel({ preview, pathImages, fullscreen, ratio, reading, links, linksExpanded, onToggleLinks, onOpenLink, onClose, onOpenLocal, onToggleFullscreen, onResizeStart, onScrollBody }) {
|
|
992
1066
|
const isMedia = preview.kind === 'image' || preview.kind === 'video'
|
|
993
1067
|
const previewPath = splitRelPath(preview.rel)
|
|
994
1068
|
|
|
1069
|
+
/* ── v0.12 引用条 ────────────────────────────────────
|
|
1070
|
+
* 位置:预览头**下面**、正文**上面** —— 一条可折叠的窄条。
|
|
1071
|
+
*
|
|
1072
|
+
* 为什么不塞进正文:正文是 Markdown 渲染的,插进去会**被滚动带走**,
|
|
1073
|
+
* 还容易跟渲染器打架。预览头也放不下(38px 里已经有面包屑 + 三个按钮 + 拖拽把手)。
|
|
1074
|
+
*
|
|
1075
|
+
* 默认**折叠**,只显示两个计数,展开才占高度。空态与失败态文案**分开** ——
|
|
1076
|
+
* 「没有被引用」是一个结论,「读取失败」是另一个,不能都显示成空白。
|
|
1077
|
+
*/
|
|
1078
|
+
const linkItems = (title, items, emptyText) => h('div', { className: 'knit-links-group' },
|
|
1079
|
+
h('div', { className: 'knit-links-label' }, title),
|
|
1080
|
+
items.length === 0
|
|
1081
|
+
? h('div', { className: 'knit-links-empty' }, emptyText)
|
|
1082
|
+
: h('ul', { className: 'knit-links-list' },
|
|
1083
|
+
items.map((item) => h('li', { key: item.rel },
|
|
1084
|
+
h('button', {
|
|
1085
|
+
type: 'button',
|
|
1086
|
+
className: 'knit-link-row',
|
|
1087
|
+
title: item.rel,
|
|
1088
|
+
onClick: () => onOpenLink(item),
|
|
1089
|
+
},
|
|
1090
|
+
h('span', { className: 'knit-link-name' }, item.title),
|
|
1091
|
+
h('span', { className: 'knit-link-path' }, item.rel))))))
|
|
1092
|
+
|
|
1093
|
+
const linksBar = (() => {
|
|
1094
|
+
if (!links || !onToggleLinks) return null
|
|
1095
|
+
if (links.status === 'loading') {
|
|
1096
|
+
return h('div', { className: 'knit-links' },
|
|
1097
|
+
h('div', { className: 'knit-links-state' }, t('preview.loading')))
|
|
1098
|
+
}
|
|
1099
|
+
if (links.status !== 'ready') {
|
|
1100
|
+
return h('div', { className: 'knit-links' },
|
|
1101
|
+
h('div', { className: 'knit-links-state' }, t('links.failed')))
|
|
1102
|
+
}
|
|
1103
|
+
const incoming = links.incoming || []
|
|
1104
|
+
const outgoing = links.outgoing || []
|
|
1105
|
+
return h('div', { className: `knit-links${linksExpanded ? ' is-open' : ''}` },
|
|
1106
|
+
h('button', {
|
|
1107
|
+
type: 'button',
|
|
1108
|
+
className: 'knit-links-head',
|
|
1109
|
+
'aria-expanded': linksExpanded ? 'true' : 'false',
|
|
1110
|
+
onClick: onToggleLinks,
|
|
1111
|
+
title: links.rel,
|
|
1112
|
+
},
|
|
1113
|
+
h('span', { className: 'knit-links-arrow' }, linksExpanded ? '▾' : '▸'),
|
|
1114
|
+
h('span', { className: 'knit-links-summary' },
|
|
1115
|
+
t('links.summary', { in: links.incomingTotal || 0, out: links.outgoingTotal || 0 }))),
|
|
1116
|
+
links.limited
|
|
1117
|
+
? h('div', { className: 'knit-links-note' }, t('links.incomplete'))
|
|
1118
|
+
: null,
|
|
1119
|
+
linksExpanded
|
|
1120
|
+
? h('div', { className: 'knit-links-body' },
|
|
1121
|
+
linkItems(t('links.incoming'), incoming, t('links.noneIn')),
|
|
1122
|
+
linkItems(t('links.outgoing'), outgoing, t('links.noneOut')),
|
|
1123
|
+
(links.incomingTotal > incoming.length || links.outgoingTotal > outgoing.length)
|
|
1124
|
+
? h('div', { className: 'knit-links-note' },
|
|
1125
|
+
t('links.more', {
|
|
1126
|
+
count: Math.max(
|
|
1127
|
+
(links.incomingTotal || 0) - incoming.length,
|
|
1128
|
+
(links.outgoingTotal || 0) - outgoing.length,
|
|
1129
|
+
),
|
|
1130
|
+
}))
|
|
1131
|
+
: null)
|
|
1132
|
+
: null)
|
|
1133
|
+
})()
|
|
1134
|
+
|
|
995
1135
|
// 图片/视频不读正文,直接用同源字节地址渲染;Markdown 才走加载 / MarkdownText / 降级。
|
|
996
1136
|
const body = preview.status === 'loading'
|
|
997
1137
|
? h('div', { className: 'knit-preview-note' }, t('preview.loading'))
|
|
@@ -1057,6 +1197,8 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1057
1197
|
title: onOpenLocal ? t('preview.openLocal', { path: preview.rel }) : preview.rel,
|
|
1058
1198
|
}, t('preview.openLocalBtn')),
|
|
1059
1199
|
h('button', { className: 'knit-preview-close', onClick: onClose, title: t('preview.close') }, '✕')),
|
|
1200
|
+
// v0.12 引用条:夹在头与正文之间,不参与正文滚动
|
|
1201
|
+
linksBar,
|
|
1060
1202
|
h('div', {
|
|
1061
1203
|
className: `knit-preview-body${isMedia ? ' is-media' : ''}`,
|
|
1062
1204
|
onScroll: onScrollBody,
|
|
@@ -1102,6 +1244,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1102
1244
|
// 阅读态也不会丢。放在最后,不动前面任何 hook 的槽位。
|
|
1103
1245
|
const [readingTick, setReadingTick] = React.useState(0)
|
|
1104
1246
|
|
|
1247
|
+
// v0.12 引用关系。`null` = 还没请求;请求回来是 `{status, incoming, outgoing, …}`。
|
|
1248
|
+
// **只跟着 previewRel 走**,绝不进列表轮询路径 —— 那份解析要读全库,
|
|
1249
|
+
// 塞进「每 5 秒一次」会把面板拖垮(SDD §3.5)。
|
|
1250
|
+
const [links, setLinks] = React.useState(null)
|
|
1251
|
+
const [linksExpandedTick, setLinksExpandedTick] = React.useState(0)
|
|
1252
|
+
|
|
1105
1253
|
React.useEffect(() => {
|
|
1106
1254
|
const host = listRef.current
|
|
1107
1255
|
if (!host || typeof ResizeObserver === 'undefined') return undefined
|
|
@@ -1321,6 +1469,12 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1321
1469
|
// 预览进入 loading 时去宿主取正文
|
|
1322
1470
|
const previewRel = preview && preview.rel
|
|
1323
1471
|
const previewStatus = preview && preview.status
|
|
1472
|
+
/**
|
|
1473
|
+
* 只有 Markdown 有引用关系 —— 链接图里只有 `.md`,所以对图片/视频请求
|
|
1474
|
+
* 必然拿到 `knit/not-found`,面板会把它显示成「读取失败」。
|
|
1475
|
+
* **与其显示一个假的失败,不如压根不请求、也不显示这一条。**
|
|
1476
|
+
*/
|
|
1477
|
+
const previewIsDoc = !preview || (preview.kind !== 'image' && preview.kind !== 'video')
|
|
1324
1478
|
|
|
1325
1479
|
/** 阅读态 = 当前这一篇被滚过。换一篇自然为 false(派生,不用复位 effect)。 */
|
|
1326
1480
|
const reading = Boolean(previewRel) && readingDocs.has(readingKey(sessionId, previewRel))
|
|
@@ -1372,6 +1526,51 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1372
1526
|
return () => { alive = false }
|
|
1373
1527
|
}, [previewRel, previewStatus, sessionId])
|
|
1374
1528
|
|
|
1529
|
+
/**
|
|
1530
|
+
* v0.12:引用关系。**只在打开某一篇时请求一次**,换篇重取。
|
|
1531
|
+
*
|
|
1532
|
+
* 两条刻意的选择:
|
|
1533
|
+
* - 不依赖 `previewStatus` —— 引用关系与「正文读没读出来」无关
|
|
1534
|
+
* - 不进列表轮询 —— 全库解析很贵,只在用户真打开一篇时才发生
|
|
1535
|
+
* 服务端按签名缓存,所以连续换篇不会重复解析。
|
|
1536
|
+
*/
|
|
1537
|
+
React.useEffect(() => {
|
|
1538
|
+
if (!previewRel || !previewIsDoc) {
|
|
1539
|
+
setLinks(null)
|
|
1540
|
+
return undefined
|
|
1541
|
+
}
|
|
1542
|
+
let alive = true
|
|
1543
|
+
setLinks({ status: 'loading' })
|
|
1544
|
+
const run = async () => {
|
|
1545
|
+
try {
|
|
1546
|
+
const url = `${LINKS_API}?sessionId=${encodeURIComponent(sessionId)}&rel=${encodeURIComponent(previewRel)}`
|
|
1547
|
+
const res = await fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store' })
|
|
1548
|
+
const data = await res.json()
|
|
1549
|
+
if (!alive) return
|
|
1550
|
+
setLinks(data && data.ok
|
|
1551
|
+
? { status: 'ready', ...data }
|
|
1552
|
+
: { status: 'error', error: hostMessage(data) })
|
|
1553
|
+
} catch (error) {
|
|
1554
|
+
if (!alive) return
|
|
1555
|
+
setLinks({ status: 'error', error: String((error && error.message) || error) })
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
run()
|
|
1559
|
+
return () => { alive = false }
|
|
1560
|
+
}, [previewRel, previewIsDoc, sessionId])
|
|
1561
|
+
|
|
1562
|
+
/** 展开 / 收起引用条。真相在模块级 `expandedLinks`,组件只留计数器(理由同阅读态)。 */
|
|
1563
|
+
const toggleLinks = React.useCallback(() => {
|
|
1564
|
+
if (!previewRel) return
|
|
1565
|
+
const key = readingKey(sessionId, previewRel)
|
|
1566
|
+
if (expandedLinks.has(key)) expandedLinks.delete(key)
|
|
1567
|
+
else expandedLinks.add(key)
|
|
1568
|
+
setLinksExpandedTick((n) => n + 1)
|
|
1569
|
+
}, [previewRel, sessionId])
|
|
1570
|
+
const linksExpanded = Boolean(previewRel)
|
|
1571
|
+
&& expandedLinks.has(readingKey(sessionId, previewRel))
|
|
1572
|
+
void linksExpandedTick
|
|
1573
|
+
|
|
1375
1574
|
// 相对路径图片解析器:按当前文档所在目录解析。MarkdownText 按引用身份 memo,
|
|
1376
1575
|
// 所以必须 useMemo 住,否则每帧都会重解析整篇 markdown。
|
|
1377
1576
|
const pathImages = React.useMemo(
|
|
@@ -1543,7 +1742,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1543
1742
|
tabIndex: 0,
|
|
1544
1743
|
onKeyDown: onListKeyDown,
|
|
1545
1744
|
role: 'listbox',
|
|
1546
|
-
'aria-label': '
|
|
1745
|
+
'aria-label': t('list.aria'),
|
|
1547
1746
|
}, body),
|
|
1548
1747
|
preview ? h(PreviewPanel, {
|
|
1549
1748
|
preview,
|
|
@@ -1552,6 +1751,14 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1552
1751
|
ratio,
|
|
1553
1752
|
reading,
|
|
1554
1753
|
onScrollBody,
|
|
1754
|
+
// v0.12 引用条
|
|
1755
|
+
links,
|
|
1756
|
+
linksExpanded,
|
|
1757
|
+
onToggleLinks: toggleLinks,
|
|
1758
|
+
// 点引用列表里的一项 → 就地预览那一篇。
|
|
1759
|
+
// **走订阅制 requestPreview,不碰列表** —— 用户点一下就该立刻有反应
|
|
1760
|
+
// (AGENTS.md §6.4 的教训:即时信号别藏在轮询里)。
|
|
1761
|
+
onOpenLink: (item) => requestPreview(item),
|
|
1555
1762
|
// 拿不到绝对路径就不给点(而不是点了没反应)
|
|
1556
1763
|
onOpenLocal: previewAbsPath ? openPreviewLocal : null,
|
|
1557
1764
|
onClose: closePreview,
|
|
@@ -1922,6 +2129,17 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
1922
2129
|
*/
|
|
1923
2130
|
const readingDocs = new Set()
|
|
1924
2131
|
|
|
2132
|
+
/**
|
|
2133
|
+
* 已经**展开过引用条**的文档,key 见 `readingKey`(同一个 key 约定)。
|
|
2134
|
+
*
|
|
2135
|
+
* 与 `readingDocs` 同一条理由(见 `AGENTS.md` §6.9):**「用户做过的事」不能只放
|
|
2136
|
+
* 组件 state** —— 宿主重挂载会把它清零,用户就得再点一次。
|
|
2137
|
+
* 语义是「这一篇在这个会话里被展开过」。
|
|
2138
|
+
*
|
|
2139
|
+
* @type {Set<string>}
|
|
2140
|
+
*/
|
|
2141
|
+
const expandedLinks = new Set()
|
|
2142
|
+
|
|
1925
2143
|
/**
|
|
1926
2144
|
* 阅读态的 key:同一会话里的同一篇文档算一个。
|
|
1927
2145
|
* @param {string} sessionId - 会话 id
|
|
@@ -2063,7 +2281,7 @@ body[data-ds-dark-theme] .knit-icon{color:#fff}
|
|
|
2063
2281
|
|
|
2064
2282
|
bsCtx.effect(() => bs.registerTab({
|
|
2065
2283
|
id: BS_TAB_ID,
|
|
2066
|
-
title: () => '
|
|
2284
|
+
title: () => t('guide.title'),
|
|
2067
2285
|
icon: KnitGlyph,
|
|
2068
2286
|
order: 30,
|
|
2069
2287
|
single: true, // 同类型只开一个
|
package/src/host/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import { join, relative, resolve, sep } from 'node:path'
|
|
|
19
19
|
import { homedir } from 'node:os'
|
|
20
20
|
import { extractKeywords, rankByRelevance, topicLabel } from './relevance.js'
|
|
21
21
|
import { registerKnitDocsTool } from './tool.js'
|
|
22
|
+
// v0.12:引用关系。`links.js` **不反过来 import 本文件**(依赖由这里注入),所以没有环。
|
|
23
|
+
import { buildLinkGraph, linksOf } from './links.js'
|
|
22
24
|
|
|
23
25
|
export const name = 'dsh-knit'
|
|
24
26
|
|
|
@@ -844,6 +846,21 @@ export function apply(ctx) {
|
|
|
844
846
|
return
|
|
845
847
|
}
|
|
846
848
|
|
|
849
|
+
if (url.pathname === `${ROUTE_PREFIX}/api/links`) {
|
|
850
|
+
// v0.12:某篇的「谁引用了它 / 它引用了谁」。
|
|
851
|
+
// 形态逐字照抄 /api/doc —— 缺 rel 走同一个错误码,不新增读文件原语:
|
|
852
|
+
// 图只用 collectDocs / readDocument 建,两者本身已强制「必须在工作区内」。
|
|
853
|
+
const rel = url.searchParams.get('rel') || ''
|
|
854
|
+
if (!rel) {
|
|
855
|
+
sendJson(res, 400, { ok: false, code: ERROR_CODES.missingRel })
|
|
856
|
+
return
|
|
857
|
+
}
|
|
858
|
+
const graph = await buildLinkGraph(root, { list: collectDocs, read: readDocument })
|
|
859
|
+
const payload = linksOf(graph, rel)
|
|
860
|
+
sendJson(res, payload.ok ? 200 : 404, payload)
|
|
861
|
+
return
|
|
862
|
+
}
|
|
863
|
+
|
|
847
864
|
sendJson(res, 404, { ok: false, code: ERROR_CODES.notFoundRoute })
|
|
848
865
|
} catch (error) {
|
|
849
866
|
sendJson(res, 500, { ok: false, code: ERROR_CODES.internal, detail: String((error && error.message) || error) })
|
|
@@ -852,7 +869,7 @@ export function apply(ctx) {
|
|
|
852
869
|
|
|
853
870
|
webCtx.effect(() => {
|
|
854
871
|
const unregister = webCtx.webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler })
|
|
855
|
-
console.log(`[${name}] route ready: ${ROUTE_PREFIX}/api/recent, ${ROUTE_PREFIX}/api/doc, ${ROUTE_PREFIX}/api/raw`)
|
|
872
|
+
console.log(`[${name}] route ready: ${ROUTE_PREFIX}/api/recent, ${ROUTE_PREFIX}/api/doc, ${ROUTE_PREFIX}/api/raw, ${ROUTE_PREFIX}/api/links`)
|
|
856
873
|
return () => unregister()
|
|
857
874
|
}, 'dsh-knit: host route')
|
|
858
875
|
})
|