@cheemsup/dsh-plugin-console 0.0.0-stage → 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.
- package/LICENSE +23 -0
- package/README.md +95 -3
- package/cordis.patch.yml +5 -0
- package/icon.svg +203 -0
- package/lib/client.activity.js +222 -0
- package/lib/client.apply.js +171 -0
- package/lib/client.changes.js +206 -0
- package/lib/client.cleanup.js +270 -0
- package/lib/client.control.js +247 -0
- package/lib/client.dialog.js +77 -0
- package/lib/client.disable-preview.js +904 -0
- package/lib/client.draft.js +280 -0
- package/lib/client.editor-messages.js +421 -0
- package/lib/client.editor-store.js +266 -0
- package/lib/client.editor.js +433 -0
- package/lib/client.effects.js +115 -0
- package/lib/client.impact-tree.js +487 -0
- package/lib/client.influence.js +361 -0
- package/lib/client.js +246 -0
- package/lib/client.page.js +646 -0
- package/lib/client.plugin-filters.js +62 -0
- package/lib/client.plugins.js +506 -0
- package/lib/client.preview-messages.js +506 -0
- package/lib/client.preview-raw.js +132 -0
- package/lib/client.preview-store.js +128 -0
- package/lib/client.preview-tools.js +194 -0
- package/lib/client.preview.js +448 -0
- package/lib/client.relation-graph.js +364 -0
- package/lib/client.schema.js +327 -0
- package/lib/client.search.js +409 -0
- package/lib/client.session-detail.js +503 -0
- package/lib/client.sessions.js +495 -0
- package/lib/client.shared.js +562 -0
- package/lib/client.store.js +452 -0
- package/lib/client.styles.js +589 -0
- package/lib/client.template-card.js +240 -0
- package/lib/client.tools.js +366 -0
- package/lib/client.workspace-picker.js +204 -0
- package/lib/host/activity.js +252 -0
- package/lib/host/assembly-preview.js +244 -0
- package/lib/host/attribution.js +341 -0
- package/lib/host/catalog.js +133 -0
- package/lib/host/categorize.js +40 -0
- package/lib/host/config-layers.js +589 -0
- package/lib/host/constants.js +69 -0
- package/lib/host/control.js +159 -0
- package/lib/host/disable-preview.js +651 -0
- package/lib/host/entries.js +289 -0
- package/lib/host/fiber.js +86 -0
- package/lib/host/fs.js +99 -0
- package/lib/host/health.js +178 -0
- package/lib/host/http.js +65 -0
- package/lib/host/impact.js +138 -0
- package/lib/host/injection-owners.js +60 -0
- package/lib/host/layers.js +132 -0
- package/lib/host/masks.js +145 -0
- package/lib/host/modes.js +96 -0
- package/lib/host/names.js +44 -0
- package/lib/host/patch-config.js +554 -0
- package/lib/host/patch-scan.js +103 -0
- package/lib/host/preview-conditions.js +281 -0
- package/lib/host/preview-contexts.js +174 -0
- package/lib/host/preview-envelope.js +31 -0
- package/lib/host/preview-instructions.js +450 -0
- package/lib/host/preview-messages.js +284 -0
- package/lib/host/preview-modules.js +233 -0
- package/lib/host/preview-skills.js +200 -0
- package/lib/host/prompt.js +213 -0
- package/lib/host/recipe-overlay.js +209 -0
- package/lib/host/request-preview.js +114 -0
- package/lib/host/routes/activation.js +96 -0
- package/lib/host/routes/activity.js +22 -0
- package/lib/host/routes/apply.js +93 -0
- package/lib/host/routes/cleanup.js +62 -0
- package/lib/host/routes/control.js +22 -0
- package/lib/host/routes/disable-preview.js +19 -0
- package/lib/host/routes/impact.js +19 -0
- package/lib/host/routes/operations.js +22 -0
- package/lib/host/routes/preview.js +58 -0
- package/lib/host/routes/session-influence.js +23 -0
- package/lib/host/routes/snapshot.js +21 -0
- package/lib/host/routes/template.js +54 -0
- package/lib/host/routes/templates.js +28 -0
- package/lib/host/scope-impact.js +125 -0
- package/lib/host/session-events.js +39 -0
- package/lib/host/session-influence.js +467 -0
- package/lib/host/sessions.js +293 -0
- package/lib/host/snapshot.js +218 -0
- package/lib/host/source-scan.js +225 -0
- package/lib/host/templates/cleanup.js +219 -0
- package/lib/host/templates/inheritance.js +144 -0
- package/lib/host/templates/materialize.js +317 -0
- package/lib/host/templates/message-overlay.js +184 -0
- package/lib/host/templates/repository.js +323 -0
- package/lib/host/templates/store.js +131 -0
- package/lib/host/tool-set.js +150 -0
- package/lib/host/tools.js +129 -0
- package/lib/index.js +106 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +124 -6
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「插件禁用预演」里的关系图画布:固定视口 + 缩放/拖拽。
|
|
3
|
+
*
|
|
4
|
+
* 单独成一个 chunk:图不是 React 状态驱动的——拖拽与滚轮每秒几十次,直接改
|
|
5
|
+
* 画布的 transform 才不会把整页重渲染;固定视口让图像地图一样在内部任意移动。
|
|
6
|
+
* 数据与几何仍由 `client.impact-tree.js` 纯计算,这里只负责挂上去。
|
|
7
|
+
* @module dsh-plugin-console/client-relation-graph
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
window.__ModuleLoader__.load({
|
|
11
|
+
id: '@cheemsup/dsh-plugin-console',
|
|
12
|
+
chunk: 'client.relation-graph.js',
|
|
13
|
+
factory: (require) => {
|
|
14
|
+
const React = require('react')
|
|
15
|
+
const { createElement: h } = React
|
|
16
|
+
|
|
17
|
+
return function create(deps) {
|
|
18
|
+
const { activateOnKey, impactTree, textButton } = deps
|
|
19
|
+
|
|
20
|
+
/** 关系图缩放:按钮与滚轮共用同一组边界与步长;100% 表示整图适配视口。 */
|
|
21
|
+
const GRAPH_ZOOM_MIN = 0.4
|
|
22
|
+
const GRAPH_ZOOM_MAX = 4
|
|
23
|
+
const GRAPH_ZOOM_STEP = 0.2
|
|
24
|
+
|
|
25
|
+
/** 视口高度:clamp(最小, 视口占比, 最大);CSS 里同步了一份。 */
|
|
26
|
+
const GRAPH_VIEWPORT_HEIGHT = 'clamp(360px,65vh,640px)'
|
|
27
|
+
const GRAPH_VIEWPORT_MIN_HEIGHT = '360px'
|
|
28
|
+
|
|
29
|
+
/** 把任意输入夹到缩放范围内;非数字回到 100%。 */
|
|
30
|
+
function clampZoom(value) {
|
|
31
|
+
const number = Number(value)
|
|
32
|
+
if (!Number.isFinite(number)) return 1
|
|
33
|
+
return Number(Math.min(GRAPH_ZOOM_MAX, Math.max(GRAPH_ZOOM_MIN, number)).toFixed(2))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 图表/节点里的定长截断;不改变数据,只影响文本节点。 */
|
|
37
|
+
function clip(text, limit) {
|
|
38
|
+
const value = typeof text === 'string' ? text : String(text ?? '')
|
|
39
|
+
return value.length > limit ? value.slice(0, limit - 1) + '…' : value
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 节点的一句话说明,只出现在悬浮提示与读屏标签里。
|
|
44
|
+
*
|
|
45
|
+
* 方块本身只放插件名:状态、层级与服务边都收进这里,避免挤掉名称。
|
|
46
|
+
* 下游页面另有「受影响的下游插件」逐行给出同样的因果路径。
|
|
47
|
+
*/
|
|
48
|
+
function nodeTooltip(node, data) {
|
|
49
|
+
if (node.side === 'root') {
|
|
50
|
+
return `目标插件 · 工具 ${data.tools.owned.length} · 段 ${data.prompt.sections.owned.length} · 服务 ${data.target.provides.length}`
|
|
51
|
+
}
|
|
52
|
+
if (node.blocked === true) {
|
|
53
|
+
const missing = (node.missingServices ?? []).join('、')
|
|
54
|
+
return `失去 ${missing || node.edgeLabel || '必需服务'}${node.distance ? ` · 第 ${node.distance} 层` : ''}`
|
|
55
|
+
}
|
|
56
|
+
if (node.edgeKind === 'config-reference') return `config.${node.edgeLabel} 引用了它`
|
|
57
|
+
if (node.edgeKind === 'group-child') return '同组子行'
|
|
58
|
+
const relation = node.side === 'upstream' ? `上游:提供 ${node.edgeLabel}` : `下游:需要 ${node.edgeLabel}`
|
|
59
|
+
return node.again === true ? `已在上方 · ${relation}` : relation
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 视口的缩放/平移状态。
|
|
64
|
+
*
|
|
65
|
+
* 直接改画布的 transform,不重渲染:拖拽和滚轮每秒会触发很多次,用 React
|
|
66
|
+
* state 会卡;画布固定在视口内,超出部分裁掉,像地图一样任意移动。
|
|
67
|
+
*/
|
|
68
|
+
const graphView = { x: 0, y: 0, scale: 1, key: null }
|
|
69
|
+
const graphZoomControl = { zoom: 1, set: undefined }
|
|
70
|
+
const graphPan = { active: false, moved: false, x: 0, y: 0 }
|
|
71
|
+
/** 适配比例与画布/视口尺寸;100% 表示整张图刚好放进视口。 */
|
|
72
|
+
const graphFit = { scale: 1, width: 0, height: 0, boxWidth: 0, boxHeight: 0 }
|
|
73
|
+
let graphViewportElement = null
|
|
74
|
+
let graphStageElement = null
|
|
75
|
+
let graphWheelListener = null
|
|
76
|
+
|
|
77
|
+
/** 量视口与画布尺寸并重算适配比例;返回视口尺寸是否变了。 */
|
|
78
|
+
function measureGraph() {
|
|
79
|
+
const viewport = graphViewportElement
|
|
80
|
+
if (viewport === null) return false
|
|
81
|
+
const boxWidth = viewport.clientWidth
|
|
82
|
+
const boxHeight = viewport.clientHeight
|
|
83
|
+
if (!(boxWidth > 0) || !(boxHeight > 0)) return false
|
|
84
|
+
const resized = graphFit.boxWidth !== boxWidth || graphFit.boxHeight !== boxHeight
|
|
85
|
+
graphFit.boxWidth = boxWidth
|
|
86
|
+
graphFit.boxHeight = boxHeight
|
|
87
|
+
if (graphFit.width > 0 && graphFit.height > 0) {
|
|
88
|
+
graphFit.scale = Math.min(1, (boxWidth - 32) / graphFit.width, (boxHeight - 32) / graphFit.height)
|
|
89
|
+
}
|
|
90
|
+
return resized
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 把整张图放到视口中央;画布左上角为原点。 */
|
|
94
|
+
function centerGraph() {
|
|
95
|
+
if (!(graphFit.boxWidth > 0) || !(graphFit.boxHeight > 0)) return
|
|
96
|
+
graphView.x = (graphFit.boxWidth - graphFit.width * graphView.scale) / 2
|
|
97
|
+
graphView.y = (graphFit.boxHeight - graphFit.height * graphView.scale) / 2
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 画布变换:左上角原点 + 平移/缩放;视口负责裁切。 */
|
|
101
|
+
function graphTransform(view, scale) {
|
|
102
|
+
// 两位小数足够,避免浮点尾数把 style 字符串写得又长又难比对。
|
|
103
|
+
const x = Math.round(view.x * 100) / 100
|
|
104
|
+
const y = Math.round(view.y * 100) / 100
|
|
105
|
+
return `translate(${x}px,${y}px) scale(${scale})`
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 只改画布 transform,供拖拽/滚轮这类高频操作直接调用。 */
|
|
109
|
+
function applyGraphView() {
|
|
110
|
+
if (graphStageElement !== null) graphStageElement.style.transform = graphTransform(graphView, graphView.scale)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function setGraphStage(element) {
|
|
114
|
+
graphStageElement = element
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 视口 ref。
|
|
119
|
+
*
|
|
120
|
+
* 滚轮必须用原生监听并 `passive:false`:React 的 onWheel 是 passive 的,
|
|
121
|
+
* preventDefault 拦不住浏览器把整页滚走。普通滚轮仍归页面,Ctrl + 滚轮
|
|
122
|
+
* 才缩放——与常见制图软件一致。
|
|
123
|
+
*/
|
|
124
|
+
function setGraphViewport(element) {
|
|
125
|
+
if (graphWheelListener !== null) graphViewportElement?.removeEventListener('wheel', graphWheelListener)
|
|
126
|
+
graphViewportElement = element
|
|
127
|
+
graphWheelListener = element === null
|
|
128
|
+
? null
|
|
129
|
+
: (event) => {
|
|
130
|
+
if (event.ctrlKey !== true) return
|
|
131
|
+
if (typeof graphZoomControl.set !== 'function') return
|
|
132
|
+
event.preventDefault()
|
|
133
|
+
zoomGraph(element, event.clientX, event.clientY, event.deltaY < 0 ? 1 : -1)
|
|
134
|
+
}
|
|
135
|
+
if (graphWheelListener !== null) element.addEventListener('wheel', graphWheelListener, { passive: false })
|
|
136
|
+
// 视口尺寸只有挂载后才知道:第一次拿到就按「整张图放进视口」定初始比例。
|
|
137
|
+
measureGraph()
|
|
138
|
+
graphView.scale = graphFit.scale * graphZoomControl.zoom
|
|
139
|
+
centerGraph()
|
|
140
|
+
applyGraphView()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 以视口内某点为锚缩放;按钮不传坐标时绕视口中心。 */
|
|
144
|
+
function zoomGraph(viewport, clientX, clientY, direction) {
|
|
145
|
+
const current = graphZoomControl.zoom
|
|
146
|
+
if (typeof graphZoomControl.set !== 'function') return
|
|
147
|
+
const next = clampZoom(current + direction * GRAPH_ZOOM_STEP)
|
|
148
|
+
if (next === current) return
|
|
149
|
+
const rect = viewport?.getBoundingClientRect?.()
|
|
150
|
+
const previous = graphFit.scale * current
|
|
151
|
+
const scale = graphFit.scale * next
|
|
152
|
+
if (rect !== undefined && previous > 0) {
|
|
153
|
+
// 缩放前后保持光标下的那一点不动:先把屏幕点换算成画布坐标再回推。
|
|
154
|
+
const px = Number.isFinite(clientX) ? clientX - rect.left : rect.width / 2
|
|
155
|
+
const py = Number.isFinite(clientY) ? clientY - rect.top : rect.height / 2
|
|
156
|
+
graphView.x = px - ((px - graphView.x) / previous) * scale
|
|
157
|
+
graphView.y = py - ((py - graphView.y) / previous) * scale
|
|
158
|
+
}
|
|
159
|
+
graphView.scale = scale
|
|
160
|
+
applyGraphView()
|
|
161
|
+
graphZoomControl.set(next)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** 任意位置按下都先记起点,但只有移动超过阈值才算拖拽,点击节点仍然可用。 */
|
|
165
|
+
function startGraphPan(event) {
|
|
166
|
+
if (event.button !== 0) return
|
|
167
|
+
graphPan.active = true
|
|
168
|
+
graphPan.moved = false
|
|
169
|
+
graphPan.x = event.clientX
|
|
170
|
+
graphPan.y = event.clientY
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** 拖拽时增量平移画布;超过阈值才捕获指针。 */
|
|
174
|
+
function moveGraphPan(event) {
|
|
175
|
+
if (!graphPan.active) return
|
|
176
|
+
const dx = event.clientX - graphPan.x
|
|
177
|
+
const dy = event.clientY - graphPan.y
|
|
178
|
+
if (!graphPan.moved) {
|
|
179
|
+
if (Math.abs(dx) + Math.abs(dy) <= 4) return
|
|
180
|
+
graphPan.moved = true
|
|
181
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
182
|
+
event.currentTarget.dataset.panning = 'true'
|
|
183
|
+
}
|
|
184
|
+
graphPan.x = event.clientX
|
|
185
|
+
graphPan.y = event.clientY
|
|
186
|
+
graphView.x += dx
|
|
187
|
+
graphView.y += dy
|
|
188
|
+
applyGraphView()
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 结束平移;指针抬起或取消都要收尾,避免下次渲染还停在拖拽态。 */
|
|
192
|
+
function endGraphPan(event) {
|
|
193
|
+
if (!graphPan.active) return
|
|
194
|
+
graphPan.active = false
|
|
195
|
+
const viewport = event.currentTarget
|
|
196
|
+
delete viewport.dataset.panning
|
|
197
|
+
if (viewport.hasPointerCapture?.(event.pointerId) === true) viewport.releasePointerCapture(event.pointerId)
|
|
198
|
+
// click 在 pointerup 之后才派发;等它过去再清掉「刚拖过」,避免误开插件。
|
|
199
|
+
if (graphPan.moved) globalThis.setTimeout?.(() => { graphPan.moved = false }, 0)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** 上下游树状图;右上角缩放,并可切换「影响图 / 完整链路」。 */
|
|
203
|
+
function renderRelations(vc, data) {
|
|
204
|
+
const graphMode = vc.disablePreview?.graphMode === 'full' ? 'full' : 'impact'
|
|
205
|
+
const setGraphMode = typeof vc.disablePreview?.setGraphMode === 'function' ? vc.disablePreview.setGraphMode : undefined
|
|
206
|
+
const graphZoom = clampZoom(vc.disablePreview?.graphZoom ?? 1)
|
|
207
|
+
const setGraphZoom = typeof vc.disablePreview?.setGraphZoom === 'function' ? vc.disablePreview.setGraphZoom : undefined
|
|
208
|
+
// 两张图必须共用本次预演的快照;页面级快照可能早于或晚于这次采集。
|
|
209
|
+
const graphSnapshot = data.graph ?? vc.snapshot
|
|
210
|
+
const impactGraph = impactTree.buildRelationTree(graphSnapshot, data.target, {
|
|
211
|
+
depth: 2,
|
|
212
|
+
chain: data.chain,
|
|
213
|
+
groupChildren: data.descendants,
|
|
214
|
+
})
|
|
215
|
+
const fullGraph = impactTree.buildFullChain(graphSnapshot, data.target)
|
|
216
|
+
const tree = graphMode === 'full' ? fullGraph : impactGraph
|
|
217
|
+
const layout = impactTree.layoutRelationTree(tree)
|
|
218
|
+
const rows = impactTree.flattenRelationTree(tree)
|
|
219
|
+
const pending = new Set((data.services?.pending ?? []).map((row) => row.rowId))
|
|
220
|
+
const blockedCount = rows.filter((row) => row.blocked === true).length
|
|
221
|
+
const upstreamCount = rows.filter((row) => row.side === 'upstream').length
|
|
222
|
+
const downstreamCount = rows.filter((row) => row.side === 'downstream').length
|
|
223
|
+
const hasGraph = tree.root !== null && layout.nodes.length > 1
|
|
224
|
+
const openPlugin = typeof vc.gotoPlugin === 'function' ? vc.gotoPlugin : () => {}
|
|
225
|
+
// 换目标或换视图时回到居中;同一张图内的缩放与平移保留。
|
|
226
|
+
const viewKey = `${graphMode}|${data.target?.rowId ?? ''}|${layout.width}x${layout.height}`
|
|
227
|
+
// 图换了就按新尺寸重算适配比例;视口尺寸变了也在每次渲染时跟上。
|
|
228
|
+
if (graphFit.width !== layout.width || graphFit.height !== layout.height) {
|
|
229
|
+
graphFit.width = layout.width
|
|
230
|
+
graphFit.height = layout.height
|
|
231
|
+
}
|
|
232
|
+
const resized = measureGraph()
|
|
233
|
+
graphView.scale = graphFit.scale * graphZoom
|
|
234
|
+
graphZoomControl.zoom = graphZoom
|
|
235
|
+
graphZoomControl.set = setGraphZoom
|
|
236
|
+
if (graphView.key !== viewKey || resized) {
|
|
237
|
+
graphView.key = viewKey
|
|
238
|
+
centerGraph()
|
|
239
|
+
}
|
|
240
|
+
const resetGraphView = () => {
|
|
241
|
+
graphView.scale = graphFit.scale
|
|
242
|
+
centerGraph()
|
|
243
|
+
applyGraphView()
|
|
244
|
+
if (setGraphZoom !== undefined) setGraphZoom(1)
|
|
245
|
+
}
|
|
246
|
+
const zoomControls = setGraphZoom === undefined ? null : h(
|
|
247
|
+
'span',
|
|
248
|
+
{ className: 'ptGraphZoom' },
|
|
249
|
+
textButton('−', () => zoomGraph(graphViewportElement, undefined, undefined, -1), { disabled: graphZoom <= GRAPH_ZOOM_MIN, title: '缩小关系图(也可以按住 Ctrl 滚动滚轮)' }),
|
|
250
|
+
h('span', { className: 'ptGraphZoomValue', title: '当前缩放比例;100% 表示整图适配视口,Ctrl + 滚轮可直接缩放' }, `${Math.round(graphZoom * 100)}%`),
|
|
251
|
+
textButton('+', () => zoomGraph(graphViewportElement, undefined, undefined, 1), { disabled: graphZoom >= GRAPH_ZOOM_MAX, title: '放大关系图(也可以按住 Ctrl 滚动滚轮)' }),
|
|
252
|
+
textButton('重置', resetGraphView, { title: '回到整图适配并居中' }),
|
|
253
|
+
)
|
|
254
|
+
const toggle = setGraphMode === undefined ? null : textButton(
|
|
255
|
+
graphMode === 'full' ? '切换到影响图' : '切换到完整链路图',
|
|
256
|
+
() => setGraphMode(graphMode === 'full' ? 'impact' : 'full'),
|
|
257
|
+
)
|
|
258
|
+
const actions = zoomControls === null && toggle === null ? null : h('span', { className: 'ptActions' }, zoomControls, toggle)
|
|
259
|
+
const graphLabel = graphMode === 'full'
|
|
260
|
+
? `插件完整依赖链:目标 ${data.target.title},上游 ${upstreamCount} 个,下游 ${downstreamCount} 个。`
|
|
261
|
+
: `插件关系图:目标 ${data.target.title},上游 ${upstreamCount} 个,下游 ${downstreamCount} 个${blockedCount > 0 ? `(其中受阻 ${blockedCount} 个)` : ''}。`
|
|
262
|
+
return h(
|
|
263
|
+
'div',
|
|
264
|
+
{ className: 'ptSection' },
|
|
265
|
+
h(
|
|
266
|
+
'div',
|
|
267
|
+
{ className: 'ptSectionHead' },
|
|
268
|
+
h('p', { className: 'ptSectionTitle' }, '依赖关系图'),
|
|
269
|
+
actions,
|
|
270
|
+
),
|
|
271
|
+
hasGraph
|
|
272
|
+
? h(
|
|
273
|
+
'div',
|
|
274
|
+
{
|
|
275
|
+
className: 'ptGraphViewport',
|
|
276
|
+
ref: setGraphViewport,
|
|
277
|
+
title: '按住 Ctrl 滚动滚轮缩放,按住拖拽平移',
|
|
278
|
+
// 关键布局也写在行内:即使宿主还挂着旧样式,图也不会跑出固定区域。
|
|
279
|
+
style: { position: 'relative', overflow: 'hidden', flex: 'none', height: GRAPH_VIEWPORT_HEIGHT, minHeight: GRAPH_VIEWPORT_MIN_HEIGHT },
|
|
280
|
+
onPointerDown: startGraphPan,
|
|
281
|
+
onPointerMove: moveGraphPan,
|
|
282
|
+
onPointerUp: endGraphPan,
|
|
283
|
+
onPointerLeave: () => { if (graphPan.moved !== true) graphPan.active = false },
|
|
284
|
+
onPointerCancel: endGraphPan,
|
|
285
|
+
},
|
|
286
|
+
h(
|
|
287
|
+
'div',
|
|
288
|
+
{
|
|
289
|
+
className: 'ptGraphStage',
|
|
290
|
+
ref: setGraphStage,
|
|
291
|
+
style: {
|
|
292
|
+
position: 'absolute',
|
|
293
|
+
top: 0,
|
|
294
|
+
left: 0,
|
|
295
|
+
width: `${layout.width}px`,
|
|
296
|
+
height: `${layout.height}px`,
|
|
297
|
+
transformOrigin: '0 0',
|
|
298
|
+
transform: graphTransform(graphView, graphView.scale),
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
h(
|
|
302
|
+
'svg',
|
|
303
|
+
{
|
|
304
|
+
className: 'ptGraph',
|
|
305
|
+
viewBox: `0 0 ${layout.width} ${layout.height}`,
|
|
306
|
+
role: 'group',
|
|
307
|
+
'aria-label': graphLabel,
|
|
308
|
+
},
|
|
309
|
+
layout.edges.map((edge) => h(
|
|
310
|
+
'g',
|
|
311
|
+
{ key: edge.key },
|
|
312
|
+
h('path', { className: 'ptGraphEdge', 'data-kind': edge.kind, d: edge.d }),
|
|
313
|
+
h('polygon', { className: 'ptGraphArrow', points: edge.arrow }),
|
|
314
|
+
edge.label
|
|
315
|
+
? h('text', { className: 'ptGraphEdgeLabel', x: edge.labelX, y: edge.labelY, textAnchor: 'middle' }, clip(edge.label, 18))
|
|
316
|
+
: null,
|
|
317
|
+
)),
|
|
318
|
+
layout.nodes.map((node) => {
|
|
319
|
+
// 方块里只有插件名;状态、层级与服务边都收进悬浮提示。
|
|
320
|
+
const tooltip = nodeTooltip(node, data)
|
|
321
|
+
const titleLines = impactTree.wrapGraphTitle(node.title, 2, node.width)
|
|
322
|
+
const labelY = titleLines.length > 1 ? 28 : 36
|
|
323
|
+
return h(
|
|
324
|
+
'g',
|
|
325
|
+
{
|
|
326
|
+
key: node.key,
|
|
327
|
+
className: 'ptGraphNode',
|
|
328
|
+
'data-tone': node.side === 'root' ? 'target' : node.blocked === true || pending.has(node.rowId) ? 'pending' : undefined,
|
|
329
|
+
role: 'button',
|
|
330
|
+
tabIndex: 0,
|
|
331
|
+
'aria-label': `${node.title}:${tooltip},点击在插件页打开`,
|
|
332
|
+
onClick: () => {
|
|
333
|
+
if (graphPan.moved === true) return
|
|
334
|
+
openPlugin(node.rowId)
|
|
335
|
+
},
|
|
336
|
+
onKeyDown: (event) => activateOnKey(event, () => openPlugin(node.rowId)),
|
|
337
|
+
},
|
|
338
|
+
h('title', null, `${node.title} · ${tooltip}`),
|
|
339
|
+
h('rect', { x: node.x, y: node.y, width: node.width, height: node.height, rx: 8 }),
|
|
340
|
+
h(
|
|
341
|
+
'text',
|
|
342
|
+
{ className: 'ptGraphLabel', x: node.x + 10, y: node.y + labelY },
|
|
343
|
+
titleLines.map((line, index) => h(
|
|
344
|
+
'tspan',
|
|
345
|
+
{ key: index, x: node.x + 10, dy: index === 0 ? 0 : 16 },
|
|
346
|
+
line,
|
|
347
|
+
)),
|
|
348
|
+
),
|
|
349
|
+
)
|
|
350
|
+
}),
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
)
|
|
354
|
+
: h('p', { className: 'ptEmpty' }, '没有可绘制的上下游关系'),
|
|
355
|
+
tree.notes.length > 0
|
|
356
|
+
? h('div', null, tree.notes.map((note) => h('p', { key: note, className: 'ptHint', style: { margin: 0 } }, note)))
|
|
357
|
+
: null,
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return { renderRelations }
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
})
|