dsh-wiki-notes 0.0.0-stage → 1.1.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/lib/client.js ADDED
@@ -0,0 +1,689 @@
1
+ /**
2
+ * dsh-wiki-notes —— 浏览器半侧(手写 __ModuleLoader__ bundle,不需要构建工具)。
3
+ *
4
+ * 在设置页里加一个「知识库」入口,可以:
5
+ * - 看到当前生效的库路径,以及它是从哪一层来的(config > 环境变量 > 配置文件 > 默认);
6
+ * - 先「测试」一个候选路径能不能扫出页面,再决定要不要「保存」;
7
+ * - 看库的规模与红链数量,随时重扫。
8
+ *
9
+ * 与宿主半侧只走同源 HTTP(/api/wiki-notes/*),不碰 RPC:失败模式最少。
10
+ * 改完用 `node --check lib/client.js` 验语法(它是表达式不是语句)。
11
+ */
12
+
13
+ window.__ModuleLoader__.load({
14
+ id: 'dsh-wiki-notes',
15
+ factory: function (require) {
16
+ var module = { exports: {} }
17
+ var exports = module.exports
18
+
19
+ var React = require('react')
20
+ var h = React.createElement
21
+ var useCallback = React.useCallback
22
+ var useEffect = React.useEffect
23
+ var useState = React.useState
24
+
25
+ var API = '/api/wiki-notes'
26
+
27
+ /* ------------------------------ HTTP ------------------------------ */
28
+
29
+ function readJson(res) {
30
+ return res.text().then(function (text) {
31
+ var data = null
32
+ try {
33
+ data = text === '' ? null : JSON.parse(text)
34
+ } catch (error) {
35
+ data = null
36
+ }
37
+ if (!res.ok) {
38
+ var message = data && data.error ? data.error : 'HTTP ' + res.status
39
+ var failure = new Error(message)
40
+ failure.status = res.status
41
+ throw failure
42
+ }
43
+ return data
44
+ })
45
+ }
46
+
47
+ function apiGet(path) {
48
+ return fetch(API + path, { cache: 'no-store' }).then(readJson)
49
+ }
50
+
51
+ function apiPost(path, body) {
52
+ return fetch(API + path, {
53
+ method: 'POST',
54
+ headers: { 'content-type': 'application/json' },
55
+ body: JSON.stringify(body || {}),
56
+ }).then(readJson)
57
+ }
58
+
59
+ /* ------------------------------ 小组件 ------------------------------ */
60
+
61
+ function Stat(props) {
62
+ return h(
63
+ 'div',
64
+ { className: 'wn-stat' + (props.tone ? ' wn-stat-' + props.tone : ''), title: props.hint || undefined },
65
+ h('div', { className: 'wn-stat-value' }, props.value),
66
+ h('div', { className: 'wn-stat-label' }, props.label),
67
+ )
68
+ }
69
+
70
+ function Notice(props) {
71
+ if (!props.message) return null
72
+ var tone = props.tone || 'info'
73
+ var mark = tone === 'ok' ? '✓' : tone === 'err' ? '!' : tone === 'warn' ? '!' : 'i'
74
+ return h(
75
+ 'div',
76
+ { className: 'wn-notice wn-notice-' + tone },
77
+ h('span', { className: 'wn-notice-mark' }, mark),
78
+ h('span', { className: 'wn-notice-text' }, props.message),
79
+ )
80
+ }
81
+
82
+ function sourceTone(source) {
83
+ if (source === 'env') return 'warn'
84
+ if (source === 'default') return 'muted'
85
+ if (source === 'unset') return 'warn'
86
+ return 'ok'
87
+ }
88
+
89
+ /* ------------------------------ 设置页 ------------------------------ */
90
+
91
+ function WikiNotesSection(props) {
92
+ var stateTuple = useState(null)
93
+ var state = stateTuple[0]
94
+ var setState = stateTuple[1]
95
+
96
+ var draftTuple = useState('')
97
+ var draft = draftTuple[0]
98
+ var setDraft = draftTuple[1]
99
+
100
+ var busyTuple = useState('')
101
+ var busy = busyTuple[0]
102
+ var setBusy = busyTuple[1]
103
+
104
+ var noticeTuple = useState(null)
105
+ var notice = noticeTuple[0]
106
+ var setNotice = noticeTuple[1]
107
+
108
+ var probeTuple = useState(null)
109
+ var probe = probeTuple[0]
110
+ var setProbe = probeTuple[1]
111
+
112
+ // 测试结果单独存在这里:只贴着「测试」那条操作栏显示,不跟保存/重扫的提示混在一起。
113
+ var probeNoteTuple = useState(null)
114
+ var probeNote = probeNoteTuple[0]
115
+ var setProbeNote = probeNoteTuple[1]
116
+
117
+ // 提示词草稿:只在首次读状态时初始化,之后由用户编辑/保存推动,
118
+ // 免得「保存路径」时把正在编辑的提示词打回服务端旧值。
119
+ var promptTuple = useState(null)
120
+ var promptDraft = promptTuple[0]
121
+ var setPromptDraft = promptTuple[1]
122
+
123
+ var apply = useCallback(function (data) {
124
+ setState(data)
125
+ setDraft(data && typeof data.root === 'string' ? data.root : '')
126
+ }, [])
127
+
128
+ var refresh = useCallback(
129
+ function () {
130
+ setBusy('load')
131
+ return apiGet('/state')
132
+ .then(function (data) {
133
+ apply(data)
134
+ setPromptDraft(function (current) {
135
+ return current === null ? data.prompt || { enabled: true, override: '', extra: '' } : current
136
+ })
137
+ return data
138
+ })
139
+ .catch(function (error) {
140
+ setNotice({ tone: 'err', text: '读状态失败:' + error.message })
141
+ })
142
+ .then(function () {
143
+ setBusy('')
144
+ })
145
+ },
146
+ [apply],
147
+ )
148
+
149
+ useEffect(
150
+ function () {
151
+ refresh()
152
+ },
153
+ [refresh],
154
+ )
155
+
156
+ // 统一管 busy 与异常。成功文案由各 handler 自己给 —— 早先这里塞一句通用
157
+ // describe,会把 handler 刚写进去的「保存失败」错误提示盖成成功,必须各管各的。
158
+ function run(kind, task) {
159
+ setBusy(kind)
160
+ setNotice(null)
161
+ return Promise.resolve()
162
+ .then(function () {
163
+ return task()
164
+ })
165
+ .catch(function (error) {
166
+ setNotice({ tone: 'err', text: error.message })
167
+ return null
168
+ })
169
+ .then(function (data) {
170
+ setBusy('')
171
+ return data
172
+ })
173
+ }
174
+
175
+ function onSavePrompt() {
176
+ run('prompt', function () {
177
+ return apiPost('/prompt', promptDraft).then(function (data) {
178
+ setState(data)
179
+ setPromptDraft(data.prompt)
180
+ setNotice({ tone: 'ok', text: '提示词已保存,下一回合生效。' })
181
+ })
182
+ })
183
+ }
184
+
185
+ function onCheck() {
186
+ var target = draft.trim()
187
+ setProbe(null)
188
+ // 点下去立刻给一句反馈:否则请求慢或失败时,界面看起来像「点了没反应」。
189
+ setProbeNote({ tone: '', text: target === '' ? '输入框是空的——先填一个笔记目录。' : '正在扫描:' + target + ' …' })
190
+ if (target === '') return null
191
+ return run('check', function () {
192
+ return apiPost('/check', { root: target }).then(function (result) {
193
+ setProbe(result)
194
+ if (result && result.ok === true) {
195
+ var stats = result.stats || {}
196
+ setProbeNote({
197
+ tone: 'ok',
198
+ text: '这条路径能扫:' + (stats.pages || 0) + ' 页 / ' + (stats.resources || 0) + ' 份资料(' + (result.ms || 0) + ' ms)',
199
+ })
200
+ } else {
201
+ setProbeNote({ tone: 'err', text: (result && result.error) || '这个路径扫不出页面' })
202
+ }
203
+ return result
204
+ })
205
+ })
206
+ }
207
+
208
+ function onSave() {
209
+ var target = draft.trim()
210
+ run('save', function () {
211
+ return apiPost('/save', { root: target }).then(function (data) {
212
+ // 服务端拒绝保存(路径扫不出页面)时不会落盘,也不该改输入框里的草稿
213
+ if (data && data.ok === false && data.saved === false) {
214
+ setNotice({ tone: 'err', text: '没有保存:' + (data.error || '这个路径扫不出页面') })
215
+ return data
216
+ }
217
+ apply(data)
218
+ setProbe(null)
219
+ if (data && data.ok === false) {
220
+ setNotice({ tone: 'err', text: '已保存,但这个路径读不出来:' + (data.error || '未知错误') })
221
+ } else {
222
+ var stats = (data && data.stats) || {}
223
+ setNotice({ tone: 'ok', text: '已保存并生效:扫描到 ' + (stats.pages || 0) + ' 页' })
224
+ }
225
+ return data
226
+ })
227
+ })
228
+ }
229
+
230
+ function onRescan() {
231
+ run('scan', function () {
232
+ return apiPost('/rescan', {}).then(function (data) {
233
+ // 只更新 state,不碰 draft —— 用户可能正在输入另一个路径
234
+ setState(data)
235
+ var stats = (data && data.stats) || {}
236
+ setNotice({ tone: 'ok', text: '已重新扫描:' + (stats.pages || 0) + ' 页' })
237
+ return data
238
+ })
239
+ })
240
+ }
241
+
242
+ function onReset() {
243
+ run('save', function () {
244
+ return apiPost('/save', { root: '' }).then(function (data) {
245
+ apply(data)
246
+ setProbe(null)
247
+ setNotice({ tone: 'ok', text: '已清掉配置文件,回到上一层(环境变量或内置默认)' })
248
+ return data
249
+ })
250
+ })
251
+ }
252
+
253
+ var stats = (state && state.stats) || {}
254
+ var savedRoot = state && typeof state.savedRoot === 'string' ? state.savedRoot : ''
255
+ var envRoot = state && typeof state.envRoot === 'string' ? state.envRoot : ''
256
+ var changed = state !== null && draft.trim() !== (state.root || '')
257
+ // 空状态:一次都没配过库路径(区别于「配了但扫不到」——那是另一条提示)
258
+ var isUnset = state !== null && (state.source === 'unset' || state.root === '')
259
+
260
+ return h(
261
+ 'div',
262
+ { className: 'wn-root' },
263
+
264
+ h(
265
+ 'div',
266
+ { className: 'wn-head' },
267
+ h('div', { className: 'wn-title' }, '知识库'),
268
+ h(
269
+ 'div',
270
+ { className: 'wn-sub' },
271
+ '模型通过 wiki_recall 工具检索这个库(只读)。这里只改「库在哪」,不改「怎么检索」。',
272
+ ),
273
+ ),
274
+
275
+ state === null
276
+ ? h(
277
+ 'div',
278
+ { className: 'wn-loading' },
279
+ h('span', { className: 'wn-dim' }, busy === 'load' ? '读取中…' : '未连接宿主(插件没启动或 API 不可达)'),
280
+ busy === 'load' ? null : h('button', { className: 'wn-btn', onClick: refresh }, '重试'),
281
+ )
282
+ : h(
283
+ 'div',
284
+ { className: 'wn-statusbar' },
285
+ h('span', { className: 'wn-dot ' + (state.watch === 'on' ? 'wn-dot-on' : 'wn-dot-off') }),
286
+ h(
287
+ 'span',
288
+ null,
289
+ state.watch === 'on' ? '实时同步:改完笔记立刻可见' : '未监听目录:改完笔记最多 30 秒后生效',
290
+ ),
291
+ (state.stats && (state.stats.pages || 0) > 0)
292
+ ? h(
293
+ 'span',
294
+ { className: 'wn-statusbar-extra' },
295
+ '· 扫描 ' + state.stats.pages + ' 页 / ' + (state.stats.scannedMs || 0) + ' ms',
296
+ )
297
+ : null,
298
+ ),
299
+
300
+ state === null
301
+ ? null
302
+ : h(
303
+ 'div',
304
+ { className: 'wn-stats' },
305
+ h(Stat, { value: stats.pages || 0, label: '页面' }),
306
+ h(Stat, { value: stats.resources || 0, label: '资料' }),
307
+ h(Stat, {
308
+ value: stats.brokenPages || 0,
309
+ label: '有红链的页',
310
+ tone: (stats.brokenPages || 0) > 0 ? 'warn' : '',
311
+ hint: '红链 = 笔记里提到、但库里还没有对应页面的双链。数量多说明有概念只被引用、还没成页。',
312
+ }),
313
+ ),
314
+
315
+ (state !== null && state.scale) ? h('div', { className: 'wn-scale' }, state.scale) : null,
316
+
317
+ (state !== null && Array.isArray(state.topics) && state.topics.length > 0)
318
+ ? h(
319
+ 'div',
320
+ { className: 'wn-topics' },
321
+ h('div', { className: 'wn-topics-label' }, '模型每回合会看到这些主题词,沾到它们的问题它会自己来查库:'),
322
+ h(
323
+ 'div',
324
+ { className: 'wn-chips' },
325
+ state.topics.map((item) =>
326
+ h('span', { key: item.tag, className: 'wn-chip' }, item.tag + ' \u00d7' + item.count),
327
+ ),
328
+ ),
329
+ )
330
+ : null,
331
+
332
+ (state !== null && !isUnset && (stats.pages || 0) > 0 && !(Array.isArray(state.topics) && state.topics.length > 0))
333
+ ? h(Notice, { tone: 'warn', message: '这些页都没有 标签 字段——模型不会自己想起查库,只能由你每次说「我笔记里」。' })
334
+ : null,
335
+
336
+ (state !== null && Array.isArray(state.topics) && state.topics.length > 0 && state.topicFilter)
337
+ ? h(
338
+ 'label',
339
+ { className: 'wn-toggle' },
340
+ h('input', {
341
+ type: 'checkbox',
342
+ checked: state.topicFilter.minCount >= 2,
343
+ disabled: busy !== '',
344
+ onChange: function (event) {
345
+ var next = { minCount: event.target.checked ? 2 : 1, stopwords: state.topicFilter.stopwords !== false }
346
+ setBusy('topics')
347
+ setNotice(null)
348
+ apiPost('/topics', next)
349
+ .then(function (data) {
350
+ setState(data)
351
+ setNotice({ tone: 'ok', text: next.minCount >= 2 ? '已只统计出现 ≥2 次的标签。' : '已放开:出现一次的标签也参与排名。' })
352
+ })
353
+ .catch(function (error) { setNotice({ tone: 'err', text: '保存失败:' + error.message }) })
354
+ .then(function () { setBusy('') })
355
+ },
356
+ }),
357
+ h('span', {}, '只统计出现 ≥2 次的标签'),
358
+ h('span', { className: 'wn-hint wn-hint-dim' }, '(挡掉只属于一篇笔记的专有名词,以及 meta 这类结构页标签)'),
359
+ (state.topicFilter.fallback === true && state.topicFilter.minCount >= 2)
360
+ ? h('span', { className: 'wn-hint wn-hint-warn' }, '这个库的标签全都只出现过一次,阈值这次没生效(否则一个主题词都剩不下)。')
361
+ : null,
362
+ )
363
+ : null,
364
+
365
+ (state !== null && state.ok === false)
366
+ ? h(Notice, { tone: 'err', message: '当前库读不出来:' + (state.error || '未知错误') })
367
+ : null,
368
+
369
+ (state !== null && !isUnset && (stats.pages || 0) === 0)
370
+ ? h(Notice, { tone: 'warn', message: '这个路径里没扫到任何 .md 页面 —— 确认它指向的是笔记目录本身,而不是它的上一级。' })
371
+ : null,
372
+
373
+ (state !== null && state.scannedRoot && state.scannedRoot !== state.root)
374
+ ? h(Notice, { tone: 'warn', message: '这个路径本身不是知识层,实际读的是它里面的:' + state.scannedRoot })
375
+ : null,
376
+
377
+ state === null
378
+ ? null
379
+ : h(
380
+ 'div',
381
+ { className: 'wn-card' + (isUnset ? ' wn-card-empty' : '') },
382
+ h(
383
+ 'div',
384
+ { className: 'wn-card-head' },
385
+ h('span', { className: 'wn-card-title' }, isUnset ? '还没配置' : '当前生效'),
386
+ h(
387
+ 'span',
388
+ { className: 'wn-badge wn-badge-' + sourceTone(state.source) },
389
+ state.sourceLabel || state.source || '',
390
+ ),
391
+ ),
392
+
393
+ isUnset
394
+ ? h(
395
+ 'div',
396
+ { className: 'wn-steps' },
397
+ h('div', { className: 'wn-step' }, h('span', { className: 'wn-step-n' }, '1'), '填一个放着 .md 笔记的目录(是它本身,不是上一级)'),
398
+ h('div', { className: 'wn-step' }, h('span', { className: 'wn-step-n' }, '2'), '点「测试」—— 只看能扫出多少页,不会改动任何东西'),
399
+ h('div', { className: 'wn-step' }, h('span', { className: 'wn-step-n' }, '3'), '点「保存并生效」,之后模型就能查这个库了'),
400
+ )
401
+ : h('div', { className: 'wn-path' }, state.root || '(空)'),
402
+
403
+ h(
404
+ 'div',
405
+ { className: 'wn-field-row' },
406
+ h('input', {
407
+ className: 'wn-input',
408
+ value: draft,
409
+ spellCheck: false,
410
+ 'aria-label': '知识库目录路径',
411
+ placeholder: '例如 D:\\笔记\\我的知识库 或 /home/me/notes',
412
+ onChange: function (event) {
413
+ setDraft(event.target.value)
414
+ setProbe(null)
415
+ },
416
+ onKeyDown: function (event) {
417
+ if (event.key === 'Enter' && busy === '') onCheck()
418
+ },
419
+ }),
420
+ ),
421
+
422
+ h(
423
+ 'div',
424
+ { className: 'wn-actions' },
425
+ h('button', { className: 'wn-btn', disabled: busy !== '', onClick: onCheck }, busy === 'check' ? '测试中…' : '测试'),
426
+ h(
427
+ 'button',
428
+ {
429
+ className: 'wn-btn wn-btn-primary',
430
+ disabled: busy !== '' || (!changed && draft.trim() === (state.root || '')),
431
+ onClick: onSave,
432
+ },
433
+ busy === 'save' ? '保存中…' : changed ? '保存并生效' : '已保存',
434
+ ),
435
+ h('button', { className: 'wn-btn', disabled: busy !== '', onClick: onRescan }, busy === 'scan' ? '扫描中…' : '重新扫描'),
436
+ h('span', { className: 'wn-actions-spacer' }),
437
+ savedRoot !== ''
438
+ ? h('button', { className: 'wn-btn wn-btn-ghost', disabled: busy !== '', onClick: onReset }, '清掉配置')
439
+ : null,
440
+ ),
441
+
442
+ (probeNote || (probe && probe.ok === true && (probe.stats || probe.hint)))
443
+ ? h(
444
+ 'div',
445
+ { className: 'wn-probe-box' },
446
+ probeNote ? h(Notice, { tone: probeNote.tone, message: probeNote.text }) : null,
447
+ (probe && probe.ok === true && probe.stats)
448
+ ? h(
449
+ 'div',
450
+ { className: 'wn-chips' },
451
+ h('span', { className: 'wn-chip' }, (probe.stats.pages || 0) + ' 页'),
452
+ h('span', { className: 'wn-chip' }, (probe.stats.resources || 0) + ' 份资料'),
453
+ h(
454
+ 'span',
455
+ { className: 'wn-chip' + ((probe.stats.brokenPages || 0) > 0 ? ' wn-chip-warn' : '') },
456
+ (probe.stats.brokenPages || 0) + ' 页有红链',
457
+ ),
458
+ h('span', { className: 'wn-chip wn-chip-dim' }, (probe.ms || 0) + ' ms'),
459
+ )
460
+ : null,
461
+ (probe && probe.ok === true && probe.hint) ? h(Notice, { tone: 'warn', message: probe.hint }) : null,
462
+ )
463
+ : null,
464
+
465
+ promptDraft === null
466
+ ? null
467
+ : h(
468
+ 'div',
469
+ { className: 'wn-prompt' },
470
+ h(
471
+ 'label',
472
+ { className: 'wn-prompt-head' },
473
+ h('input', {
474
+ type: 'checkbox',
475
+ checked: promptDraft.enabled !== false,
476
+ onChange: function (event) {
477
+ setPromptDraft({ enabled: event.target.checked, override: promptDraft.override, extra: promptDraft.extra })
478
+ },
479
+ }),
480
+ '每回合注入一段提示词,让模型自己知道该来查库',
481
+ ),
482
+ h('div', { className: 'wn-hint' }, '关掉后不占上下文,但模型只在你说「我笔记里」时才会查。'),
483
+ h('textarea', {
484
+ className: 'wn-textarea',
485
+ rows: 3,
486
+ disabled: promptDraft.enabled === false,
487
+ value: promptDraft.override,
488
+ placeholder: '留空 = 自动用下面这段(按标签算出来的)',
489
+ onChange: function (event) {
490
+ setPromptDraft({ enabled: promptDraft.enabled, override: event.target.value, extra: promptDraft.extra })
491
+ },
492
+ }),
493
+ h('textarea', {
494
+ className: 'wn-textarea',
495
+ rows: 2,
496
+ disabled: promptDraft.enabled === false,
497
+ value: promptDraft.extra,
498
+ placeholder: '追加一句(可选),例如:不确定时先查库再回答',
499
+ onChange: function (event) {
500
+ setPromptDraft({ enabled: promptDraft.enabled, override: promptDraft.override, extra: event.target.value })
501
+ },
502
+ }),
503
+ h('div', { className: 'wn-preview-label' }, '现在实际注入的是:'),
504
+ h(
505
+ 'pre',
506
+ { className: 'wn-preview' },
507
+ state && state.topicPreview
508
+ ? state.topicPreview
509
+ : state && state.prompt && state.prompt.enabled === false
510
+ ? '(空——提示词开关是关的,模型不会看到这段)'
511
+ : '(空——这个库的页面没有 标签 或 tags 字段,没有主题词可用)',
512
+ ),
513
+ h(
514
+ 'div',
515
+ { className: 'wn-actions' },
516
+ h(
517
+ 'button',
518
+ { className: 'wn-btn', disabled: busy !== '', onClick: onSavePrompt },
519
+ busy === 'prompt' ? '保存中…' : '保存提示词',
520
+ ),
521
+ h('span', { className: 'wn-actions-spacer' }),
522
+ h('span', { className: 'wn-hint' }, '(预览是上一次扫描的结果,保存后刷新即更新)'),
523
+ ),
524
+ ),
525
+
526
+ h(Notice, { tone: notice && notice.tone, message: notice && notice.text }),
527
+
528
+ envRoot !== ''
529
+ ? h(Notice, { tone: 'warn', message: '环境变量 DSH_WIKI_ROOT 正在覆盖这个值(' + envRoot + '),保存也盖不过它。' })
530
+ : null,
531
+
532
+ h(
533
+ 'details',
534
+ { className: 'wn-details' },
535
+ h('summary', null, '配置来源与优先级'),
536
+ h(
537
+ 'div',
538
+ { className: 'wn-details-body' },
539
+ h('div', { className: 'wn-hint' }, '当前值来自:' + (state.sourceLabel || '?')),
540
+ h('div', { className: 'wn-hint' }, '配置文件:' + (state.configFile || '?')),
541
+ savedRoot !== ''
542
+ ? h('div', { className: 'wn-hint' }, '文件里的值:' + savedRoot)
543
+ : h('div', { className: 'wn-hint' }, '还没有配置文件,保存后会写一个。'),
544
+ h('div', { className: 'wn-hint' }, '内置默认:' + (state.defaultRoot || '(空)')),
545
+ h('div', { className: 'wn-hint wn-hint-dim' }, '优先级:插件 config > 环境变量 > 配置文件 > 内置默认'),
546
+ ),
547
+ ),
548
+ ),
549
+
550
+ h('div', { className: 'wn-foot' }, '只读:这个页面不会改知识库里的任何文件。'),
551
+ ) }
552
+
553
+ /* ------------------------------ 样式 ------------------------------ */
554
+
555
+ var CSS = [
556
+ '.wn-root{',
557
+ '--wn-fg:var(--dsw-alias-label-primary,#1f1c18);',
558
+ '--wn-muted:var(--dsw-alias-label-secondary,#6f6558);',
559
+ '--wn-faint:var(--dsw-alias-label-tertiary,var(--dsw-alias-label-dimmed,#8a7f6e));',
560
+ '--wn-card:var(--dsw-alias-bg-layer-1,#fffdf8);',
561
+ '--wn-bar:var(--dsw-alias-bg-layer-2,#f4efe4);',
562
+ '--wn-field:var(--dsw-alias-bg-layer-3,var(--dsw-alias-bg-layer-2,#fbf7ef));',
563
+ '--wn-line:var(--dsw-alias-border-l2,#e3daca);',
564
+ '--wn-line-soft:var(--dsw-alias-border-l1,#ece5d8);',
565
+ '--wn-brand:var(--dsw-alias-brand-primary,var(--dsw-alias-button-primary-fill,#1f1c18));',
566
+ '--wn-brand-fg:var(--dsw-alias-label-primary-foreground,#fffdf8);',
567
+ '--wn-ok:var(--dsw-alias-state-success-primary,#2f6b46);',
568
+ '--wn-warn:var(--dsw-alias-state-warn-primary,#8a6a2f);',
569
+ '--wn-err:var(--dsw-alias-state-error-primary,#a83a2c);',
570
+ "font-family:var(--dsw-font-family-sans,var(--dsw-font-family,-apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Microsoft YaHei\",sans-serif));",
571
+ 'color:var(--wn-fg);display:flex;flex-direction:column;gap:14px;padding:2px;box-sizing:border-box;max-width:100%;}',
572
+ '.wn-title{font-size:15px;font-weight:650;letter-spacing:.2px;}',
573
+ '.wn-sub{font-size:12.5px;color:var(--wn-muted);margin-top:5px;line-height:1.6;}',
574
+ '.wn-dim{font-size:12.5px;color:var(--wn-faint);}',
575
+ '.wn-stats{display:flex;gap:10px;flex-wrap:wrap;}',
576
+ '.wn-stat{flex:1 1 96px;min-width:96px;background:var(--wn-bar);border:1px solid var(--wn-line-soft);border-radius:10px;padding:10px 12px;}',
577
+ '.wn-stat-value{font-size:22px;font-weight:600;line-height:1.15;font-variant-numeric:tabular-nums;}',
578
+ '.wn-stat-label{font-size:11.5px;color:var(--wn-muted);margin-top:3px;}',
579
+ '.wn-stat-warn .wn-stat-value{color:var(--wn-warn);}',
580
+ '.wn-scale{font-size:12px;color:var(--wn-faint);}',
581
+ '.wn-card{background:var(--wn-card);border:1px solid var(--wn-line);border-radius:12px;padding:13px 14px;display:flex;flex-direction:column;gap:10px;}',
582
+ '.wn-card-head{display:flex;align-items:center;gap:8px;}',
583
+ '.wn-card-title{font-size:12.5px;font-weight:600;color:var(--wn-muted);}',
584
+ '.wn-badge{font-size:11px;padding:2px 7px;border-radius:999px;border:1px solid var(--wn-line);color:var(--wn-muted);background:var(--wn-bar);white-space:nowrap;}',
585
+ '.wn-badge-ok{color:var(--wn-ok);border-color:color-mix(in srgb,var(--wn-ok) 35%,transparent);}',
586
+ '.wn-badge-warn{color:var(--wn-warn);border-color:color-mix(in srgb,var(--wn-warn) 35%,transparent);}',
587
+ '.wn-badge-muted{color:var(--wn-faint);}',
588
+ '.wn-path{word-break:break-all;font-family:var(--dsw-font-family-mono,ui-monospace,SFMono-Regular,Menlo,Consolas,monospace);font-size:12px;background:var(--wn-field);border:1px solid var(--wn-line-soft);border-radius:8px;padding:8px 10px;}',
589
+ '.wn-field-row{display:flex;gap:8px;}',
590
+ '.wn-input{flex:1 1 auto;min-width:0;box-sizing:border-box;font-size:12.5px;font-family:var(--dsw-font-family-mono,ui-monospace,SFMono-Regular,Menlo,Consolas,monospace);color:var(--wn-fg);background:var(--wn-field);border:1px solid var(--wn-line);border-radius:8px;padding:8px 10px;outline:none;}',
591
+ '.wn-input:focus{border-color:var(--wn-brand);box-shadow:0 0 0 3px color-mix(in srgb,var(--wn-brand) 18%,transparent);}',
592
+ '.wn-actions{display:flex;gap:8px;flex-wrap:wrap;}',
593
+ '.wn-probe-box{display:flex;flex-direction:column;gap:8px;}',
594
+ '.wn-loading{display:flex;align-items:center;gap:10px;}',
595
+ '.wn-btn{font-size:12.5px;padding:7px 13px;border-radius:8px;border:1px solid var(--wn-line);background:var(--wn-bar);color:var(--wn-fg);cursor:pointer;white-space:nowrap;}',
596
+ '.wn-btn:hover:not(:disabled){filter:brightness(.97);}',
597
+ '.wn-btn:disabled{opacity:.5;cursor:default;}',
598
+ '.wn-btn:focus-visible,.wn-input:focus-visible{outline:2px solid var(--wn-brand);outline-offset:2px;}',
599
+ '.wn-btn-primary{background:var(--wn-brand);color:var(--wn-brand-fg);border-color:transparent;}',
600
+ '.wn-btn-ghost{background:transparent;color:var(--wn-muted);}',
601
+ '.wn-notice{font-size:12.5px;line-height:1.55;padding:8px 11px;border-radius:8px;border:1px solid var(--wn-line-soft);background:var(--wn-bar);color:var(--wn-muted);}',
602
+ '.wn-notice-ok{color:var(--wn-ok);border-color:color-mix(in srgb,var(--wn-ok) 30%,transparent);background:color-mix(in srgb,var(--wn-ok) 8%,transparent);}',
603
+ '.wn-notice-err{color:var(--wn-err);border-color:color-mix(in srgb,var(--wn-err) 30%,transparent);background:color-mix(in srgb,var(--wn-err) 8%,transparent);}',
604
+ '.wn-notice-warn{color:var(--wn-warn);border-color:color-mix(in srgb,var(--wn-warn) 30%,transparent);background:color-mix(in srgb,var(--wn-warn) 8%,transparent);}',
605
+ '.wn-probe{font-size:12px;color:var(--wn-muted);line-height:1.6;}',
606
+ '.wn-hint{font-size:11.5px;color:var(--wn-faint);line-height:1.65;word-break:break-all;}',
607
+ '.wn-prompt{display:flex;flex-direction:column;gap:7px;border-top:1px dashed var(--wn-line-soft);padding-top:11px;}',
608
+ '.wn-prompt-head{display:flex;align-items:center;gap:7px;font-size:12.5px;color:var(--wn-fg);cursor:pointer;}',
609
+ '.wn-textarea{font:inherit;font-size:12.5px;line-height:1.6;padding:8px 10px;border-radius:8px;border:1px solid var(--wn-line);background:var(--wn-bar);color:var(--wn-fg);resize:vertical;}',
610
+ '.wn-textarea:focus-visible{outline:2px solid var(--wn-brand);outline-offset:2px;}',
611
+ '.wn-textarea:disabled{opacity:.5;}',
612
+ '.wn-preview-label{font-size:11.5px;color:var(--wn-muted);}',
613
+ '.wn-preview{margin:0;font-size:11.5px;line-height:1.6;white-space:pre-wrap;word-break:break-word;padding:8px 10px;border-radius:8px;background:var(--wn-bar);border:1px solid var(--wn-line-soft);color:var(--wn-muted);max-height:180px;overflow:auto;}',
614
+ '.wn-hint-warn{color:var(--wn-warn);}',
615
+ '.wn-hint-dim{opacity:.75;}',
616
+ '.wn-head{display:flex;flex-direction:column;gap:3px;}',
617
+ '.wn-statusbar{display:flex;align-items:center;gap:7px;flex-wrap:wrap;font-size:11.5px;color:var(--wn-faint);}',
618
+ '.wn-dot{width:7px;height:7px;border-radius:50%;flex:0 0 auto;}',
619
+ '.wn-dot-on{background:var(--wn-ok);box-shadow:0 0 0 3px color-mix(in srgb,var(--wn-ok) 16%,transparent);}',
620
+ '.wn-dot-off{background:var(--wn-faint);opacity:.5;}',
621
+ '.wn-card-empty{border-style:dashed;}',
622
+ '.wn-steps{display:flex;flex-direction:column;gap:7px;margin:2px 0;}',
623
+ '.wn-step{display:flex;gap:8px;align-items:flex-start;font-size:12.5px;line-height:1.6;color:var(--wn-muted);}',
624
+ '.wn-step-n{flex:0 0 auto;width:17px;height:17px;border-radius:50%;background:var(--wn-bar);border:1px solid var(--wn-line);color:var(--wn-muted);font-size:11px;line-height:15px;text-align:center;font-weight:600;}',
625
+ '.wn-chips{display:flex;gap:6px;flex-wrap:wrap;}',
626
+ '.wn-topics{display:flex;flex-direction:column;gap:6px;}',
627
+ '.wn-topics-label{font-size:11.5px;color:var(--wn-muted);}',
628
+ '.wn-toggle{display:flex;align-items:baseline;gap:6px;flex-wrap:wrap;font-size:11.5px;color:var(--wn-muted);cursor:pointer;}',
629
+ '.wn-toggle input{cursor:pointer;}',
630
+ '.wn-chip{font-size:11.5px;padding:2px 8px;border-radius:999px;background:var(--wn-bar);border:1px solid var(--wn-line-soft);color:var(--wn-muted);}',
631
+ '.wn-chip-warn{color:var(--wn-warn);border-color:color-mix(in srgb,var(--wn-warn) 35%,transparent);}',
632
+ '.wn-chip-dim{color:var(--wn-faint);}',
633
+ '.wn-actions-spacer{flex:1 1 auto;}',
634
+ '.wn-details{border-top:1px solid var(--wn-line-soft);padding-top:9px;margin-top:2px;}',
635
+ '.wn-details summary{font-size:11.5px;color:var(--wn-muted);cursor:pointer;user-select:none;list-style:none;}',
636
+ '.wn-details summary::-webkit-details-marker{display:none;}',
637
+ '.wn-details summary::before{content:"▸ ";color:var(--wn-faint);}',
638
+ '.wn-details[open] summary::before{content:"▾ ";}',
639
+ '.wn-details-body{display:flex;flex-direction:column;gap:4px;padding-top:8px;}',
640
+ '.wn-notice{display:flex;gap:7px;align-items:flex-start;}',
641
+ '.wn-notice-mark{flex:0 0 auto;font-weight:700;opacity:.85;}',
642
+ '.wn-notice-text{flex:1 1 auto;}',
643
+ '.wn-foot{font-size:11.5px;color:var(--wn-faint);border-top:1px solid var(--wn-line-soft);padding-top:10px;}',
644
+ '}',
645
+ ].join('')
646
+
647
+ /* ------------------------------ 注册 ------------------------------ */
648
+
649
+ function apply(ctx) {
650
+ ctx.effect(function () {
651
+ var id = 'dsh-wiki-notes-styles'
652
+ if (document.getElementById(id) === null) {
653
+ var style = document.createElement('style')
654
+ style.id = id
655
+ style.textContent = CSS
656
+ document.head.appendChild(style)
657
+ }
658
+ return function () {
659
+ var element = document.getElementById(id)
660
+ if (element !== null && element.parentNode !== null) element.parentNode.removeChild(element)
661
+ }
662
+ }, 'dsh-wiki-notes: styles')
663
+
664
+ // settings.section = 设置弹层左侧的一级入口
665
+ ctx.slots.inject('settings.section', function () {
666
+ return ctx.slots.register(
667
+ {
668
+ name: 'settings.section',
669
+ id: 'wiki-notes',
670
+ order: 47,
671
+ label: function () {
672
+ return '知识库'
673
+ },
674
+ },
675
+ function (props) {
676
+ return h(WikiNotesSection, props !== null && props !== undefined ? props : {})
677
+ },
678
+ )
679
+ })
680
+ }
681
+
682
+ module.exports = {
683
+ name: 'wiki-notes',
684
+ inject: ['slots'],
685
+ apply: apply,
686
+ }
687
+ return module.exports
688
+ },
689
+ })