@cheemsup/dsh-plugin-console 0.1.1 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 定制编辑器:把「预演」页看到的构造真正变成可改、可存、可应用的东西。
2
+ * 定制编辑器:把「上下文预演」页看到的构造真正变成可改、可存、可应用的东西。
3
3
  *
4
4
  * 数据变换(草稿指纹 / 基线 → 草稿 / 草稿 → 配方)在 `client.draft.js` 里,
5
5
  * 是三个不碰 React 的纯函数;本文件只做渲染,状态与动作全部来自视图上下文 `vc`。
@@ -222,7 +222,7 @@ window.__ModuleLoader__.load({
222
222
  {
223
223
  type: 'button',
224
224
  className: 'ptBtn ptBtnLarge',
225
- title: '调用首请求预演查看结果',
225
+ title: '调用上下文预演查看结果',
226
226
  onClick: () => void vc.previewApplied(),
227
227
  },
228
228
  '预览定制结果',
@@ -238,7 +238,7 @@ window.__ModuleLoader__.load({
238
238
  return h(
239
239
  'div',
240
240
  { className: 'ptCardRow', style: { marginBottom: '10px' } },
241
- textButton('← 返回预演', () => vc.setEditing(false), { title: '回到最终构造,不保存当前改动' }),
241
+ textButton('← 返回上下文预演', () => vc.setEditing(false), { title: '回到最终构造,不保存当前改动' }),
242
242
  )
243
243
  }
244
244
 
@@ -0,0 +1,487 @@
1
+ /**
2
+ * 禁用预演的上下游关系树:纯计算,不碰 React。
3
+ *
4
+ * 为什么是树而不是三列清单:插件的依赖可以往下走很多层(一个服务有多个消费者,
5
+ * 消费者又提供别的服务),扁平的「上游 / 目标 / 下游」清单表达不了层级,也容易
6
+ * 把「第二层受影响」误读成「直接依赖」。这里按行 id 去重、按深度截断,环路只画
7
+ * 一条回边,不重复展开。
8
+ *
9
+ * 图只做「谁依赖谁」与「谁覆盖谁」两种边;节点上的数量与状态由视图从快照补,
10
+ * 不在模型里重复存一份。
11
+ * @module dsh-plugin-console/client-impact-tree
12
+ */
13
+
14
+ window.__ModuleLoader__.load({
15
+ id: '@cheemsup/dsh-plugin-console',
16
+ chunk: 'client.impact-tree.js',
17
+ factory: () => {
18
+ /** 上游默认展示两层(目标 → 直接依赖 → 再下一层);下游按 host 闭包完整展开。 */
19
+ const DEFAULT_DEPTH = 2
20
+
21
+ /** entryId / rowId 双向索引。 */
22
+ function indexEntries(entries) {
23
+ const byEntryId = new Map()
24
+ const byRowId = new Map()
25
+ for (const entry of entries) {
26
+ byEntryId.set(entry.entryId, entry)
27
+ const list = byRowId.get(entry.rowId) ?? []
28
+ list.push(entry)
29
+ byRowId.set(entry.rowId, list)
30
+ }
31
+ return { byEntryId, byRowId }
32
+ }
33
+
34
+ /** 节点展示名;快照里找不到条目时退回原始 id。 */
35
+ function titleOf(entry, fallback) {
36
+ if (entry === undefined) return String(fallback)
37
+ return entry.title || entry.packageName || entry.moduleName || entry.entryId || String(fallback)
38
+ }
39
+
40
+ /** 树的最大深度(两侧各算一次)。 */
41
+ function maxDepthOf(nodes) {
42
+ let depth = 0
43
+ for (const node of nodes) {
44
+ depth = Math.max(depth, node.depth, maxDepthOf(node.children ?? []))
45
+ }
46
+ return depth
47
+ }
48
+
49
+ /**
50
+ * 建关系树。
51
+ *
52
+ * @param {object} snapshot - 当前快照。
53
+ * @param {object} target - `data.target`(至少含 rowId / entryId)。
54
+ * @param {object} [options] - `{ depth, maxNodes, full, serviceOnly }`;`full` 表示上下游都递归到底。
55
+ * @returns {{root: object | null, upstream: Array<object>, downstream: Array<object>, truncated: boolean, notes: string[]}} 关系树。
56
+ */
57
+ function buildRelationTree(snapshot, target, options = {}) {
58
+ const full = options.full === true
59
+ const depthLimit = full ? Infinity : Math.min(4, Math.max(1, Number.isInteger(options.depth) ? options.depth : DEFAULT_DEPTH))
60
+ // 不传 maxNodes 表示不设总预算:下游必须能完整画出闭包里的每一个插件。
61
+ // 显式传入时仍按旧口径截断,供需要的调用方保留概览模式。
62
+ const maxNodes = Number.isInteger(options.maxNodes) ? Math.max(8, options.maxNodes) : Infinity
63
+ const entries = Array.isArray(snapshot?.entries) ? snapshot.entries : []
64
+ const services = snapshot?.services ?? {}
65
+ const index = indexEntries(entries)
66
+ const rootEntry = target?.entryId === undefined ? undefined : index.byEntryId.get(target.entryId)
67
+ if (rootEntry === undefined && (target?.rowId === undefined || target?.rowId === null)) {
68
+ return { root: null, upstream: [], downstream: [], truncated: false, notes: ['找不到目标条目'] }
69
+ }
70
+ const rootId = target.rowId ?? rootEntry?.rowId
71
+ const root = {
72
+ key: 'root',
73
+ rowId: rootId,
74
+ entryId: target.entryId ?? rootEntry?.entryId,
75
+ title: target.title ?? titleOf(rootEntry, rootId),
76
+ moduleName: target.moduleName ?? rootEntry?.moduleName,
77
+ side: 'root',
78
+ depth: 0,
79
+ edgeKind: null,
80
+ edgeLabel: null,
81
+ children: [],
82
+ }
83
+ const notes = []
84
+ let count = 1
85
+ let truncated = false
86
+ let sequence = 0
87
+
88
+ /** 新建节点;`again` 是「已经在上方出现过」的叶子。 */
89
+ const makeNode = (entry, side, depth, edgeKind, edgeLabel, fallback, again) => {
90
+ sequence++
91
+ return {
92
+ key: `${side}#${sequence}`,
93
+ rowId: entry?.rowId ?? fallback,
94
+ entryId: entry?.entryId ?? fallback,
95
+ title: titleOf(entry, fallback),
96
+ moduleName: entry?.moduleName ?? null,
97
+ side,
98
+ depth,
99
+ edgeKind,
100
+ edgeLabel,
101
+ children: [],
102
+ again: again === true,
103
+ }
104
+ }
105
+ const canAdd = () => {
106
+ if (count < maxNodes) return true
107
+ truncated = true
108
+ return false
109
+ }
110
+
111
+ /** 两侧各自去重:同一个行只画一次,避免 DAG 被摊成重复节点。 */
112
+ const seenUp = new Set([rootId])
113
+ const seenDown = new Set([rootId])
114
+
115
+ /** 上游:目标需要的服务由谁提供,再顺着提供者的需求往上走。 */
116
+ const walkUp = (entry, depth, ancestors) => {
117
+ const children = []
118
+ for (const service of entry?.requires ?? []) {
119
+ for (const providerId of services[service]?.providers ?? []) {
120
+ if (!canAdd()) return children
121
+ const provider = index.byEntryId.get(providerId)
122
+ const rowId = provider?.rowId ?? providerId
123
+ if (ancestors.has(rowId)) {
124
+ children.push(makeNode(provider, 'upstream', depth, 'service', service, rowId, true))
125
+ count++
126
+ continue
127
+ }
128
+ if (seenUp.has(rowId)) continue
129
+ const node = makeNode(provider, 'upstream', depth, 'service', service, rowId, false)
130
+ seenUp.add(rowId)
131
+ count++
132
+ children.push(node)
133
+ if (depth < depthLimit) {
134
+ node.children = walkUp(provider ?? { requires: [] }, depth + 1, new Set([...ancestors, rowId]))
135
+ }
136
+ }
137
+ }
138
+ return children
139
+ }
140
+
141
+ /** 下游:目标提供的服务被谁消费,再顺着消费者的提供项往下走。 */
142
+ const walkDown = (entry, depth, ancestors) => {
143
+ const children = []
144
+ for (const service of entry?.provides ?? []) {
145
+ for (const consumerId of services[service]?.consumers ?? []) {
146
+ if (!canAdd()) return children
147
+ const consumer = index.byEntryId.get(consumerId)
148
+ const rowId = consumer?.rowId ?? consumerId
149
+ if (ancestors.has(rowId)) {
150
+ children.push(makeNode(consumer, 'downstream', depth, 'service', service, rowId, true))
151
+ count++
152
+ continue
153
+ }
154
+ if (seenDown.has(rowId)) continue
155
+ const node = makeNode(consumer, 'downstream', depth, 'service', service, rowId, false)
156
+ seenDown.add(rowId)
157
+ count++
158
+ children.push(node)
159
+ if (depth < depthLimit) {
160
+ node.children = walkDown(consumer ?? { provides: [] }, depth + 1, new Set([...ancestors, rowId]))
161
+ }
162
+ }
163
+ }
164
+ return children
165
+ }
166
+
167
+ const upstreamRoots = walkUp(rootEntry ?? { requires: target.requires ?? [] }, 1, new Set([rootId]))
168
+ if (!full && upstreamRoots.length > 0) notes.push(`影响图聚焦与选定插件最相邻的插件以及下游插件`)
169
+ const chainRows = full ? [] : (Array.isArray(options.chain?.blocked) ? options.chain.blocked : [])
170
+ // 不传 chainDepth 表示下游不截断:用户要看到这次禁用波及的全部插件。
171
+ const graphChainDepth = Number.isInteger(options.chainDepth) ? options.chainDepth : Infinity
172
+ let downstreamRoots
173
+
174
+ if (chainRows.length > 0) {
175
+ // 完整依赖链模式:下游只画「真的会不可用」的条目,层级与路径都来自 host
176
+ // 的闭包结果。分组子行是距离 0 的起点,先放进来,后续链路可以挂在它们下面。
177
+ downstreamRoots = []
178
+ const nodesById = new Map()
179
+ for (const child of options.groupChildren ?? []) {
180
+ if (!canAdd()) break
181
+ const entry = index.byEntryId.get(child.entryId)
182
+ const node = makeNode(
183
+ entry ?? { rowId: child.rowId, entryId: child.entryId, title: child.title, moduleName: null },
184
+ 'downstream', 1, 'group-child', '同组子行', child.rowId, false,
185
+ )
186
+ node.entryId = child.entryId
187
+ node.distance = 0
188
+ count++
189
+ downstreamRoots.push(node)
190
+ nodesById.set(child.entryId, node)
191
+ }
192
+ let depthCut = false
193
+ for (const row of chainRows) {
194
+ if (row.distance > graphChainDepth) {
195
+ depthCut = true
196
+ break
197
+ }
198
+ if (!canAdd()) break
199
+ const entry = index.byEntryId.get(row.entryId)
200
+ const node = makeNode(
201
+ entry ?? { rowId: row.rowId, entryId: row.entryId, title: row.title, moduleName: row.moduleName },
202
+ 'downstream', row.distance, 'blocked', row.causeService ?? '同组', row.rowId, false,
203
+ )
204
+ node.entryId = row.entryId
205
+ node.blocked = true
206
+ node.distance = row.distance
207
+ node.missingServices = Array.isArray(row.missingServices) ? row.missingServices : []
208
+ count++
209
+ const parent = typeof row.viaEntryId === 'string' && row.viaEntryId !== root.entryId
210
+ ? nodesById.get(row.viaEntryId)
211
+ : undefined
212
+ if (parent !== undefined) parent.children.push(node)
213
+ else downstreamRoots.push(node)
214
+ nodesById.set(row.entryId, node)
215
+ }
216
+ if (depthCut) notes.push(`链条较深:图只画到第 ${graphChainDepth} 层,完整链路见「影响链路」。`)
217
+ } else {
218
+ downstreamRoots = walkDown(rootEntry ?? { provides: target.provides ?? [] }, 1, new Set([rootId]))
219
+
220
+ if (options.serviceOnly !== true) {
221
+ // 配置引用:config 值里**完全等于**目标 id / 模块名 / 包名的行。
222
+ // 不做子串匹配——那会把 `dsh-tool-a-extra` 误算成 `dsh-tool-a` 的引用。
223
+ const identifiers = new Set(
224
+ [target.rowId, target.entryId, target.moduleName, target.packageName].filter((name) => typeof name === 'string' && name !== ''),
225
+ )
226
+ for (const entry of entries) {
227
+ if (entry.entryId === root.entryId) continue
228
+ if (seenDown.has(entry.rowId)) continue
229
+ const hit = (entry.configEntries ?? []).find((row) => identifiers.has(row.value))
230
+ if (hit === undefined) continue
231
+ if (!canAdd()) break
232
+ count++
233
+ seenDown.add(entry.rowId)
234
+ downstreamRoots.push(makeNode(entry, 'downstream', 1, 'config-reference', hit.key, entry.rowId, false))
235
+ }
236
+
237
+ // 同组子行:按 Loader id 前缀推断;条件禁用与动态挂载可能不同,界面会写明。
238
+ if (typeof root.entryId === 'string') {
239
+ for (const entry of entries) {
240
+ if (!entry.entryId.startsWith(root.entryId + ':')) continue
241
+ if (seenDown.has(entry.rowId)) continue
242
+ if (!canAdd()) break
243
+ count++
244
+ seenDown.add(entry.rowId)
245
+ downstreamRoots.push(makeNode(entry, 'downstream', 1, 'group-child', '同组子行', entry.rowId, false))
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ if (full) notes.push('完整链路按 provides/requires 声明展开')
252
+ if (truncated) notes.push(`关系图最多展示 ${maxNodes} 个节点,其余上下游已省略。`)
253
+ return { root, upstream: upstreamRoots, downstream: downstreamRoots, truncated, notes }
254
+ }
255
+
256
+ /**
257
+ * 以选中节点为中心,递归展开完整的上下游依赖链。
258
+ *
259
+ * 与 {@link buildRelationTree} 的区别:不按受影响状态筛选下游,也不只看上游 2 层;
260
+ * 两侧都沿 `provides` / `requires` 声明走到没有更多提供者或消费者为止。
261
+ * @param {object} snapshot - 当前快照。
262
+ * @param {object} target - `data.target`。
263
+ * @param {object} [options] - 透传的选项。
264
+ * @returns {object} 同 `buildRelationTree` 的树。
265
+ */
266
+ function buildFullChain(snapshot, target, options = {}) {
267
+ return buildRelationTree(snapshot, target, { ...options, full: true, serviceOnly: true })
268
+ }
269
+
270
+ /**
271
+ * 一条边:父节点在靠近目标的一侧,子节点在更外侧。
272
+ *
273
+ * 箭头统一表示「提供者 → 消费者」:下游是目标(或上游提供者)指向下游消费者;
274
+ * 上游是更外侧的提供者指向靠近目标、需要该服务的消费者,所以上游箭头落在
275
+ * 父节点一端,而不是继续朝外。
276
+ */
277
+ function edgeBetween(parent, child) {
278
+ const upstream = child.side === 'upstream'
279
+ const fromNode = upstream ? child : parent
280
+ const toNode = upstream ? parent : child
281
+ const fromX = fromNode.x + fromNode.width
282
+ const toX = toNode.x
283
+ const y1 = fromNode.y + fromNode.height / 2
284
+ const y2 = toNode.y + toNode.height / 2
285
+ const direction = Math.sign(toX - fromX) || 1
286
+ const span = Math.max(20, Math.abs(toX - fromX) / 2)
287
+ return {
288
+ key: fromNode.key + '>' + toNode.key,
289
+ fromKey: fromNode.key,
290
+ toKey: toNode.key,
291
+ kind: child.edgeKind,
292
+ label: child.edgeLabel,
293
+ d: `M${fromX} ${y1} C${fromX + direction * span} ${y1} ${toX - direction * span} ${y2} ${toX} ${y2}`,
294
+ arrow: `${toX},${y2} ${toX - direction * 6},${y2 - 3.5} ${toX - direction * 6},${y2 + 3.5}`,
295
+ labelX: (fromX + toX) / 2,
296
+ labelY: (y1 + y2) / 2 - 5,
297
+ }
298
+ }
299
+
300
+ /**
301
+ * 估算一个字符占几格:汉字/全角按 2,其余按 1。
302
+ * SVG 没有自动换行,只能按近似宽度自己折行。
303
+ */
304
+ function charWidth(char) {
305
+ return /[⺀-鿿豈-﫿＀-￯]/.test(char) ? 2 : 1
306
+ }
307
+
308
+ /**
309
+ * 按节点宽度折行,最多 `maxLines` 行,再长才省略。
310
+ * 节点左右各留 10px;12px 字号下一个西文字符约 6.6px,约合 1 格。
311
+ * @param {string} title - 插件名。
312
+ * @param {number} maxLines - 最多显示几行。
313
+ * @param {number} width - 节点宽度(px)。
314
+ * @returns {string[]} 每行的文字。
315
+ */
316
+ function wrapGraphTitle(title, maxLines, width) {
317
+ const perLine = Math.max(8, Math.floor((width - 20) / 6.6))
318
+ const lines = []
319
+ let line = ''
320
+ let units = 0
321
+ for (const char of String(title ?? '')) {
322
+ const size = charWidth(char)
323
+ if (line !== '' && units + size > perLine) {
324
+ lines.push(line)
325
+ line = ''
326
+ units = 0
327
+ }
328
+ line += char
329
+ units += size
330
+ }
331
+ if (line !== '') lines.push(line)
332
+ if (lines.length <= maxLines) return lines
333
+ // 超出最后一行的部分省略:给「…」留一格。
334
+ let kept = ''
335
+ let used = 0
336
+ for (const char of lines[maxLines - 1]) {
337
+ const size = charWidth(char)
338
+ if (used + size > perLine - 2) break
339
+ kept += char
340
+ used += size
341
+ }
342
+ return [...lines.slice(0, maxLines - 1), kept + '…']
343
+ }
344
+
345
+ /**
346
+ * 固定几何的树布局。
347
+ *
348
+ * 目标居中,上游向左侧按深度分列,下游向右侧分列;每侧按后序给叶子排 y,
349
+ * 父节点取首末子节点的中点。没有力导向、没有随机数——同一份数据永远得到
350
+ * 同一张图,便于眼动定位与自检。
351
+ * @param {object} tree - `buildRelationTree()` 的结果。
352
+ * @param {object} [options] - `{ nodeWidth, nodeHeight, gapX, gapY, padding }`。
353
+ * @returns {{nodes: Array<object>, edges: Array<object>, width: number, height: number}} 布局。
354
+ */
355
+ function layoutRelationTree(tree, options = {}) {
356
+ // 方块只放插件名(状态收进悬浮提示),所以把空间都给文字:两行名称、
357
+ // 更宽的行宽。放大查看交给视图层的缩放,这里仍保持固定几何。
358
+ const nodeWidth = options.nodeWidth ?? 240
359
+ const nodeHeight = options.nodeHeight ?? 64
360
+ const gapX = options.gapX ?? 96
361
+ const gapY = options.gapY ?? 14
362
+ const padding = options.padding ?? 8
363
+ if (tree?.root === null || tree?.root === undefined) {
364
+ return { nodes: [], edges: [], width: 0, height: 0 }
365
+ }
366
+
367
+ const upDepth = maxDepthOf(tree.upstream ?? [])
368
+ const downDepth = maxDepthOf(tree.downstream ?? [])
369
+ const rootX = padding + upDepth * (nodeWidth + gapX)
370
+ const nodes = []
371
+ const edges = []
372
+
373
+ /** 递归排一侧;`cursor` 是对象,保证同一个引用在整棵树里累加。 */
374
+ const assign = (node, side, cursor) => {
375
+ const childLayouts = (node.children ?? []).map((child) => assign(child, side, cursor))
376
+ let y
377
+ if (childLayouts.length > 0) {
378
+ y = (childLayouts[0].y + childLayouts[childLayouts.length - 1].y) / 2
379
+ } else {
380
+ y = padding + cursor.value * (nodeHeight + gapY)
381
+ cursor.value++
382
+ }
383
+ const layout = {
384
+ key: node.key,
385
+ rowId: node.rowId,
386
+ title: node.title,
387
+ moduleName: node.moduleName,
388
+ side,
389
+ depth: node.depth,
390
+ x: side === 'upstream' ? rootX - node.depth * (nodeWidth + gapX) : rootX + node.depth * (nodeWidth + gapX),
391
+ y,
392
+ width: nodeWidth,
393
+ height: nodeHeight,
394
+ edgeKind: node.edgeKind,
395
+ edgeLabel: node.edgeLabel,
396
+ again: node.again === true,
397
+ blocked: node.blocked === true,
398
+ missingServices: node.missingServices ?? [],
399
+ distance: node.distance ?? node.depth,
400
+ hasChildren: childLayouts.length > 0,
401
+ }
402
+ nodes.push(layout)
403
+ for (const child of childLayouts) edges.push(edgeBetween(layout, child))
404
+ return layout
405
+ }
406
+
407
+ const upCursor = { value: 0 }
408
+ const downCursor = { value: 0 }
409
+ const upstreamLayouts = (tree.upstream ?? []).map((node) => assign(node, 'upstream', upCursor))
410
+ const downstreamLayouts = (tree.downstream ?? []).map((node) => assign(node, 'downstream', downCursor))
411
+
412
+ const lowest = nodes.reduce((value, node) => Math.max(value, node.y), 0)
413
+ const rootY = lowest === 0 ? padding : padding + (lowest - padding) / 2
414
+ const root = {
415
+ key: 'root',
416
+ rowId: tree.root.rowId,
417
+ title: tree.root.title,
418
+ moduleName: tree.root.moduleName,
419
+ side: 'root',
420
+ depth: 0,
421
+ x: rootX,
422
+ y: rootY,
423
+ width: nodeWidth,
424
+ height: nodeHeight,
425
+ edgeKind: null,
426
+ edgeLabel: null,
427
+ again: false,
428
+ hasChildren: upstreamLayouts.length + downstreamLayouts.length > 0,
429
+ }
430
+ for (const layout of [...upstreamLayouts, ...downstreamLayouts]) edges.push(edgeBetween(root, layout))
431
+ nodes.push(root)
432
+
433
+ return {
434
+ nodes,
435
+ edges,
436
+ width: rootX + downDepth * (nodeWidth + gapX) + nodeWidth + padding,
437
+ height: Math.max(lowest, rootY) + nodeHeight + padding,
438
+ }
439
+ }
440
+
441
+ /**
442
+ * 摊平成节点列表;视图用它统计上下游客数与受阻节点数。
443
+ * @param {object} tree - `buildRelationTree()` 的结果。
444
+ * @returns {Array<object>} 深度优先的节点列表。
445
+ */
446
+ function flattenRelationTree(tree) {
447
+ const rows = []
448
+ if (tree?.root === null || tree?.root === undefined) return rows
449
+ rows.push({
450
+ key: 'root',
451
+ rowId: tree.root.rowId,
452
+ title: tree.root.title,
453
+ side: 'root',
454
+ depth: 0,
455
+ edgeKind: null,
456
+ edgeLabel: null,
457
+ again: false,
458
+ blocked: false,
459
+ missingServices: [],
460
+ distance: 0,
461
+ hasChildren: (tree.upstream?.length ?? 0) + (tree.downstream?.length ?? 0) > 0,
462
+ })
463
+ const walk = (node) => {
464
+ rows.push({
465
+ key: node.key,
466
+ rowId: node.rowId,
467
+ title: node.title,
468
+ side: node.side,
469
+ depth: node.depth,
470
+ edgeKind: node.edgeKind,
471
+ edgeLabel: node.edgeLabel,
472
+ again: node.again === true,
473
+ blocked: node.blocked === true,
474
+ missingServices: node.missingServices ?? [],
475
+ distance: node.distance ?? node.depth,
476
+ hasChildren: (node.children?.length ?? 0) > 0,
477
+ })
478
+ for (const child of node.children ?? []) walk(child)
479
+ }
480
+ for (const node of tree.upstream ?? []) walk(node)
481
+ for (const node of tree.downstream ?? []) walk(node)
482
+ return rows
483
+ }
484
+
485
+ return { buildRelationTree, buildFullChain, layoutRelationTree, flattenRelationTree, wrapGraphTitle }
486
+ },
487
+ })
package/lib/client.js CHANGED
@@ -28,22 +28,44 @@ window.__ModuleLoader__.load({
28
28
  */
29
29
  let runtimeCtx = null
30
30
 
31
- /** 侧边栏图标:一棵两层节点的小树。 */
31
+ /**
32
+ * 侧边栏图标:`icon.svg` 的等比例单色版。
33
+ *
34
+ * 完整路径原样保留,`currentColor` 与右侧插件名同色;16–18px 下细连接臂
35
+ * 会自然变淡,但螺母、卡扣、机械臂与插头仍能读出来。
36
+ *
37
+ * client 半没有打包器,不能运行时读包内 SVG;改 `icon.svg` 后要同步这里的
38
+ * 路径数据(缩放系数也在最后一条 path 的 transform 里)。
39
+ */
40
+ const ICON_PATHS = [
41
+ { d: 'M 971 967 Q 969 970 969 987 Q 969 1004 971 1007 Q 973 1012 978 1012 L 1058 1012 Q 1075 1012 1075 986 Q 1075 976 1073 973 Q 1070 962 1021 962 L 978 962 Q 973 964 971 967 Z' },
42
+ { d: 'M 972 866 Q 969 870 969 888 Q 969 906 970 908 Q 971 913 1018 913 L 1061 913 Q 1075 913 1075 888 Q 1075 876 1073 873 Q 1070 863 1019 863 L 976 863 Z' },
43
+ { d: 'M 285 812 Q 283 815 283 829 Q 283 843 285 847 L 468 1027 Q 473 1030 483 1033 L 785 1033 Q 786 1046 788 1051 Q 794 1067 868 1067 Q 928 1067 934 1065 Q 950 1060 951 944 L 951 841 Q 950 826 944 823 Q 936 812 865 812 Q 809 813 803 816 Q 790 823 788 834 Q 784 863 695 863 L 602 863 L 501 763 Q 497 760 480 772 L 462 782 Q 456 787 461 793 L 584 913 Q 590 915 664 915 L 738 915 Q 740 919 740 939 L 740 959 Q 736 963 654 963 L 570 963 Q 568 962 558 952 L 415 811 Q 411 810 394 820 Q 377 829 369 832 Q 361 834 354 834 Q 346 834 339 832 Q 331 830 313 820 L 291 810 Q 287 810 285 812 Z' },
44
+ { d: 'M 355 447 Q 349 447 343 450 L 202 529 Q 195 535 193 540 Q 191 544 191 625 Q 191 705 193 710 Q 195 714 199 718 L 340 799 Q 352 803 355 803 Q 357 803 363 802 L 510 717 Q 517 713 519 709 Q 521 704 521 625 Q 521 545 518 539 Q 515 533 510 529 L 367 450 Q 361 447 355 447 Z M 355 545 A 79.5 79.5 0 1 0 355 704 A 79.5 79.5 0 1 0 355 545 Z', fillRule: 'evenodd' },
45
+ { d: 'M 450 457 Q 449 460 451 462 L 484 481 Q 488 483 492 480 L 544 432 L 590 382 Q 596 381 696 381 L 796 381 Q 804 378 805 374 Q 805 371 798 359 L 788 340 Q 785 333 781 330 Q 777 328 678 328 L 579 328 Q 574 329 512 393 L 450 454 Q 449 455 450 457 Z' },
46
+ { d: 'M 302 419 Q 302 434 303 435 Q 307 438 325 429 Q 339 421 349 420 Q 358 418 367 420 Q 375 422 387 429 Q 399 435 403 435 Q 407 435 481 362 L 558 287 Q 562 285 670 285 L 782 285 Q 786 282 788 270 Q 790 261 798 246 Q 805 231 805 228 Q 805 225 803 223 Q 801 220 799 219 L 646 219 L 494 219 Q 488 221 483 224 L 392 312 L 304 400 Q 302 404 302 419 Z' },
47
+ { d: 'M 892 180 Q 888 181 882 185 Q 875 188 855 208 Q 835 227 827 240 Q 819 253 816 261 Q 809 280 809 300 Q 809 310 812 322 Q 814 334 819 344 Q 823 354 829 363 Q 835 372 854 390 L 876 411 Q 879 413 886 416 Q 892 418 928 418 L 963 418 Q 971 416 977 413 Q 983 409 1008 385 Q 1033 360 1036 355 Q 1038 349 1038 347 Q 1038 344 1037 342 Q 1036 340 1033 339 Q 1029 337 1005 334 Q 980 330 978 331 Q 975 332 968 338 Q 954 350 944 350 Q 922 352 917 350 Q 896 344 889 331 Q 877 316 877 301 Q 877 285 882 279 Q 890 261 903 257 Q 916 249 932 249 Q 947 249 959 256 Q 969 262 979 269 Q 984 270 1009 266 Q 1033 262 1035 261 Q 1038 258 1038 256 Q 1038 247 1033 241 Q 1029 234 1008 213 L 981 188 Q 976 184 969 182 Q 962 179 929 179 Q 895 179 892 180 Z', transform: 'translate(923.5 298.5) scale(1.15) translate(-923.5 -298.5)' },
48
+ ]
49
+
32
50
  function PluginConsoleIcon({ size = 16 }) {
33
51
  return h(
34
52
  'svg',
35
53
  {
36
54
  width: size,
37
55
  height: size,
38
- viewBox: '0 0 16 16',
39
- fill: 'none',
56
+ viewBox: '0 0 1254 1254',
57
+ fill: 'currentColor',
40
58
  'aria-hidden': 'true',
41
59
  focusable: 'false',
42
60
  },
43
- h('rect', { x: 1.25, y: 1.25, width: 4.5, height: 3.5, rx: 1, stroke: 'currentColor', strokeWidth: 1.1 }),
44
- h('rect', { x: 1.25, y: 10.25, width: 4.5, height: 3.5, rx: 1, stroke: 'currentColor', strokeWidth: 1.1 }),
45
- h('rect', { x: 10.25, y: 6.25, width: 4.5, height: 3.5, rx: 1, stroke: 'currentColor', strokeWidth: 1.1 }),
46
- h('path', { d: 'M5.75 3H8.5v5.5M5.75 12H8.5V8.5', stroke: 'currentColor', strokeWidth: 1.1, strokeLinecap: 'round' }),
61
+ ICON_PATHS.map((path, index) =>
62
+ h('path', {
63
+ key: index,
64
+ d: path.d,
65
+ fillRule: path.fillRule,
66
+ transform: path.transform,
67
+ }),
68
+ ),
47
69
  )
48
70
  }
49
71
 
@@ -55,7 +77,7 @@ window.__ModuleLoader__.load({
55
77
  * @returns {Promise<Function>} 页面组件。
56
78
  */
57
79
  async function loadPanel() {
58
- const [styles, shared, workspacePickerChunk, searchChunk, previewRawChunk, plugins, pluginFiltersChunk, sessions, tools, preview, previewStoreChunk, previewMessagesChunk, previewToolsChunk, editorChunk, applyChain, store, draftChunk, dialogChunk, templateCardChunk, cleanupChunk, influenceChunk, activityChunk, changesChunk, controlChunk, effectsChunk, sessionDetailChunk, editorStoreChunk, editorMessagesChunk, schemaChunk] = await Promise.all([
80
+ const [styles, shared, workspacePickerChunk, searchChunk, previewRawChunk, plugins, pluginFiltersChunk, sessions, tools, preview, previewStoreChunk, previewMessagesChunk, previewToolsChunk, editorChunk, applyChain, store, draftChunk, dialogChunk, templateCardChunk, cleanupChunk, influenceChunk, activityChunk, changesChunk, controlChunk, effectsChunk, sessionDetailChunk, editorStoreChunk, editorMessagesChunk, schemaChunk, impactTreeChunk, relationGraphChunk, disablePreviewChunk] = await Promise.all([
59
81
  require.async('./client.styles.js'),
60
82
  require.async('./client.shared.js'),
61
83
  require.async('./client.workspace-picker.js'),
@@ -85,6 +107,9 @@ window.__ModuleLoader__.load({
85
107
  require.async('./client.editor-store.js'),
86
108
  require.async('./client.editor-messages.js'),
87
109
  require.async('./client.schema.js'),
110
+ require.async('./client.impact-tree.js'),
111
+ require.async('./client.relation-graph.js'),
112
+ require.async('./client.disable-preview.js'),
88
113
  ])
89
114
 
90
115
  // 样式先注入,再挂面板:骨架屏也依赖这些类名。
@@ -114,6 +139,10 @@ window.__ModuleLoader__.load({
114
139
  const control = controlChunk(helpers)
115
140
  const effects = effectsChunk()
116
141
  const sessionDetail = sessionDetailChunk({ ...helpers, influence })
142
+ // 关系树是纯模型;关系图画布负责视口与缩放,禁用预演视图再组装两者。
143
+ const impactTree = impactTreeChunk
144
+ const relationGraph = relationGraphChunk({ ...helpers, impactTree })
145
+ const disablePreview = disablePreviewChunk({ ...helpers, search, relationGraph })
117
146
  const createPage = await require.async('./client.page.js')
118
147
  return createPage({
119
148
  runtimeCtx,
@@ -136,6 +165,7 @@ window.__ModuleLoader__.load({
136
165
  previewStore: previewStoreChunk({ shared: helpers }),
137
166
  editor,
138
167
  editorStore,
168
+ disablePreview,
139
169
  search,
140
170
  })
141
171
  }