clearai-dsh 0.5.6 → 0.5.7
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 +14 -0
- package/README.md +4 -4
- package/README.zh-CN.md +4 -4
- package/lib/client.js +141 -51
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are recorded here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
4
4
|
|
|
5
|
+
## [0.5.7] — 2026-10-24
|
|
6
|
+
|
|
7
|
+
**暗色模式下本体图的缩放控件看得清了;会话在跑时图上的关系文字不再闪。**
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **暗色下的缩放/适配控件看不清**:React Flow 的 Controls 默认走它自己的浅色主题——按钮底色 `#fefefe`,而按钮颜色是 `inherit`;暗色宿主把文字色设成近白,图标于是成了白底上的白图标(对比度 1.04:1),整块控件在暗色画布上还是一块刺眼的白框。现在把控件用到的那几个库变量(`--xy-controls-button-*`)接到宿主主题令牌上,深浅色都跟着宿主走,不写死色值。
|
|
12
|
+
- **会话运行时本体图「字会闪」**:中栏会跟着会话更新高频重渲染,而图带每次渲染都新造 nodes / edges;React Flow 按对象身份判断节点是否变化,于是每次都重新 adopt(`measured` 归零)、边被卸载重挂,边标签(要等 `useEffect` 里的 `getBBox` 才量出尺寸)先画成 hidden 再变 visible——看起来就是关系文字在闪。现在用 `useMemo` 把「同一份投影 + 同一个选中态」钉成同一组 nodes / edges,并按签名缓存节点对象(选中一个点只换那一个);父级重渲染不再动图的数据模型。
|
|
13
|
+
|
|
14
|
+
### Tests
|
|
15
|
+
|
|
16
|
+
- 客户端套件新增:父级重渲染时 nodes / edges 对象身份不变;选中一个点只换它自己;缩放控件接到宿主主题令牌。
|
|
17
|
+
- 另做了修前 / 修后对照:同一份投影重渲染 90 次,修前边被卸载重挂 2047 次、控件对比度 1.04:1;修后 0 次、15:1,且没有 hidden 的边标签。
|
|
18
|
+
|
|
5
19
|
## [0.5.6] — 2026-10-19
|
|
6
20
|
|
|
7
21
|
**适配 DSH 0.2.1:独立评估者在新宿主上重新派得出去,且仍然只读(issue #38);交给评估者的材料有了体积闸门(issue #36),复跑副本能被认出是副本(issue #35);另补上递归删除闸门的几处绕过。**
|
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@ ClearAI is an **ontology discovery and exploration platform**, built on two core
|
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
24
|
# Install (npm package, prebuilt — no build step, no allowBuilds prompt)
|
|
25
|
-
dsh plugin --profile web add clearai-dsh@0.5.
|
|
26
|
-
# or in the app: Plugins → Add plugin → clearai-dsh@0.5.
|
|
25
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
26
|
+
# or in the app: Plugins → Add plugin → clearai-dsh@0.5.7
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Restart `dsh web`, then pick **ClearAI** in the preset picker at the top of a new session. That is the whole setup. [Full install notes ↓](#install-and-use)
|
|
@@ -86,12 +86,12 @@ ClearAI does **not** claim recursive self-improvement. It provides the epistemic
|
|
|
86
86
|
|
|
87
87
|
**Recommended — install it in the app, with the version pinned:**
|
|
88
88
|
|
|
89
|
-
In the sidebar open **Plugins → Add plugin**, enter `clearai-dsh@0.5.
|
|
89
|
+
In the sidebar open **Plugins → Add plugin**, enter `clearai-dsh@0.5.7`, and install. That is DSH's own plugin manager: it hands what you type to pnpm, checks that the package declares a bundle and is compatible with this host, and applies it live. (The Settings page **插件列表 / Plugins** is the read-only inventory — installing happens on the sidebar's Plugins page.)
|
|
90
90
|
|
|
91
91
|
**Or from a terminal — the same install:**
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
|
-
dsh plugin --profile web add clearai-dsh@0.5.
|
|
94
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
This installs the prebuilt package from the npm registry. Nothing is compiled on your machine, so there is no `allowBuilds` grant to approve — the plugin is ready the moment the command returns.
|
package/README.zh-CN.md
CHANGED
|
@@ -22,8 +22,8 @@ ClearAI 是一个**本体发现与探索平台**,核心由两个概念支撑
|
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
24
|
# 安装(npm 包,预构建——无需构建步骤,不会触发 allowBuilds 授权)
|
|
25
|
-
dsh plugin --profile web add clearai-dsh@0.5.
|
|
26
|
-
# 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.
|
|
25
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
26
|
+
# 或在应用里:侧栏「插件」→ 添加插件 → clearai-dsh@0.5.7
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
重启 `dsh web`,在新建会话顶部的模式选择器里选 **ClearAI** 即可。这就是全部步骤。[完整安装说明 ↓](#安装与使用)
|
|
@@ -86,12 +86,12 @@ ClearAI **不**声称递归自我改进。它提供的是自我改进系统所
|
|
|
86
86
|
|
|
87
87
|
**推荐——在应用里装,并把版本钉住:**
|
|
88
88
|
|
|
89
|
-
侧栏打开**「插件」→ 添加插件**,填 `clearai-dsh@0.5.
|
|
89
|
+
侧栏打开**「插件」→ 添加插件**,填 `clearai-dsh@0.5.7`,安装。这就是 DSH 自己的插件管理器:它把你填的东西交给 pnpm,校验这个包声明了组合包、与当前宿主兼容,然后当场生效。(设置里的**插件列表**是**只读清单**;安装入口在侧栏那个「插件」页。)
|
|
90
90
|
|
|
91
91
|
**或者开终端——同一次安装:**
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
|
-
dsh plugin --profile web add clearai-dsh@0.5.
|
|
94
|
+
dsh plugin --profile web add clearai-dsh@0.5.7
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
从 npm registry 装预构建产物。本机不跑任何编译,因此不需要批准 `allowBuilds` 授权——命令返回时插件就已经可用。
|
package/lib/client.js
CHANGED
|
@@ -313,6 +313,15 @@ window.__ModuleLoader__.load({
|
|
|
313
313
|
.clearai-graph[data-full="1"] .clearai-graph-body{flex:1 1 auto}
|
|
314
314
|
.clearai-graph-body[data-side="1"]{flex-direction:row}
|
|
315
315
|
.clearai-graph-canvas{height:340px;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;overflow:hidden;background:var(--dsw-alias-bg-base)}
|
|
316
|
+
/**
|
|
317
|
+
* **缩放/适配控件跟着宿主主题走**(暗色下原来白底白图标,对比度 1.04:1)。
|
|
318
|
+
*
|
|
319
|
+
* React Flow 的 Controls 默认是它自己的浅色主题:按钮底色 #fefefe,而按钮颜色是 inherit ——
|
|
320
|
+
* 暗色宿主把文字色设成近白,图标就继承成近白,于是白底上的白图标看不见。
|
|
321
|
+
* 这里不传 colorMode(那会把整张图切到库自带的暗色板,和宿主令牌未必同色),
|
|
322
|
+
* 只把控件用到的那几个库变量接到宿主令牌上:深浅色都跟着宿主走,不写死色值。
|
|
323
|
+
*/
|
|
324
|
+
.clearai-graph-canvas .react-flow{--xy-controls-button-background-color:var(--dsw-alias-bg-layer-1);--xy-controls-button-background-color-hover:var(--dsw-alias-interactive-bg-hover);--xy-controls-button-color:var(--dsw-alias-label-primary);--xy-controls-button-color-hover:var(--dsw-alias-label-primary);--xy-controls-button-border-color:var(--dsw-alias-border-l2)}
|
|
316
325
|
.clearai-graph[data-full="1"] .clearai-graph-canvas{height:auto;flex:1 1 auto;min-width:0}
|
|
317
326
|
/**
|
|
318
327
|
* 全屏是自画的覆盖层(fixed / inset:0 / z-index:40),画布与右下角抽屉都长在它里面。
|
|
@@ -2469,16 +2478,24 @@ window.__ModuleLoader__.load({
|
|
|
2469
2478
|
* · **点击语义**:点节点 / 边 = 打开小卡;「只看相关」是卡上的显式动作。
|
|
2470
2479
|
* · **全屏**:position: fixed 的真 overlay,打开时自动适配。
|
|
2471
2480
|
*/
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2481
|
+
/** 空投影:常量,免得每次渲染造一个新对象。 */
|
|
2482
|
+
const EMPTY_GRAPH = { nodes: [], edges: [], bounds: { width: 0, height: 0 } }
|
|
2483
|
+
|
|
2484
|
+
/**
|
|
2485
|
+
* 投影 → React Flow 的 nodes / edges(纯计算;GraphBand 用 useMemo 把它钉住)。
|
|
2486
|
+
*
|
|
2487
|
+
* 为什么必须稳定:会话在跑时中栏会跟着高频重渲染。每次重渲染都新造 node/edge 对象的话,
|
|
2488
|
+
* React Flow 会把它们当成新节点重新 adopt:`measured` 归零 → 边被卸载重挂 →
|
|
2489
|
+
* 边标签(要等 useEffect 里的 getBBox 才量出尺寸)先 hidden 再 visible,肉眼就是「字在闪」。
|
|
2490
|
+
* 同一份投影 + 同一个选中态 = 同一组对象;选中一个点也只换那一个节点对象(按签名缓存)。
|
|
2491
|
+
*/
|
|
2492
|
+
function graphViewOf({ lexicon, layer, toggled, dragged, selectedId, entityKnowledge, nodeCache, setToggled }) {
|
|
2493
|
+
const graph = lexicon?.graph ?? EMPTY_GRAPH
|
|
2476
2494
|
const conflicts = Array.isArray(lexicon?.conflicts) ? lexicon.conflicts : []
|
|
2477
2495
|
const conflicted = new Set(conflicts.flatMap((item) => item.sides.map((side) => side.fact)).filter((id) => typeof id === 'string'))
|
|
2478
2496
|
const layerNodes = graph.nodes.filter((node) => node.layer === layer)
|
|
2479
2497
|
const layerEdges = graph.edges.filter((edge) => edge.layer === layer && typeof edge.from === 'string' && typeof edge.to === 'string')
|
|
2480
2498
|
const nodeById = new Map(layerNodes.map((node) => [node.id, node]))
|
|
2481
|
-
const problems = Array.isArray(lexicon?.problems) ? lexicon.problems : []
|
|
2482
2499
|
|
|
2483
2500
|
/**
|
|
2484
2501
|
* **目录嵌套就是子图**:概念的父是 `node.parent`(is_a),实体的父是 `node.container`(组成)。
|
|
@@ -2501,10 +2518,6 @@ window.__ModuleLoader__.load({
|
|
|
2501
2518
|
}
|
|
2502
2519
|
return depth
|
|
2503
2520
|
}
|
|
2504
|
-
const [toggled, setToggled] = React.useState({})
|
|
2505
|
-
React.useEffect(() => {
|
|
2506
|
-
setToggled({})
|
|
2507
|
-
}, [layer])
|
|
2508
2521
|
const crowded = layerNodes.length > 40
|
|
2509
2522
|
const isCollapsed = (id) => (childCount.get(id) ?? 0) > 0 && (toggled[id] ?? (crowded && depthOfNode(id) >= 1))
|
|
2510
2523
|
/** 往上找第一个没被收起的祖先挡住的点:自己可见就是自己。 */
|
|
@@ -2541,7 +2554,14 @@ window.__ModuleLoader__.load({
|
|
|
2541
2554
|
}
|
|
2542
2555
|
return out
|
|
2543
2556
|
})()
|
|
2544
|
-
|
|
2557
|
+
/**
|
|
2558
|
+
* 收起/展开用**函数式更新**读当下的 `toggled`:节点对象会被缓存复用,
|
|
2559
|
+
* 闭包里存旧状态的话,复用节点的折叠按钮会按上一帧的状态去翻。
|
|
2560
|
+
*/
|
|
2561
|
+
const toggle = (id) => setToggled((current) => {
|
|
2562
|
+
const collapsed = (childCount.get(id) ?? 0) > 0 && (current[id] ?? (crowded && depthOfNode(id) >= 1))
|
|
2563
|
+
return { ...current, [id]: !collapsed }
|
|
2564
|
+
})
|
|
2545
2565
|
const countOf = (name) => graph.nodes.filter((node) => node.layer === name).length
|
|
2546
2566
|
const entityNames = new Map(graph.nodes.filter((node) => node.kind === 'instance' && typeof node.ref === 'string' && node.ref !== '' && node.label !== node.ref).map((node) => [String(node.ref), String(node.label)]))
|
|
2547
2567
|
|
|
@@ -2550,28 +2570,6 @@ window.__ModuleLoader__.load({
|
|
|
2550
2570
|
const value = String(text ?? '')
|
|
2551
2571
|
return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`
|
|
2552
2572
|
}
|
|
2553
|
-
|
|
2554
|
-
/**
|
|
2555
|
-
* **节点位置是受控的,所以必须自己接住拖动**:不给 `onNodesChange`,
|
|
2556
|
-
* React Flow 内部的拖动没有地方落地,节点根本拖不动。位置是界面状态,换层或图变了就清掉。
|
|
2557
|
-
*/
|
|
2558
|
-
const [dragged, setDragged] = React.useState({})
|
|
2559
|
-
const graphKey = `${layer}|${layerNodes.length}|${layerEdges.length}`
|
|
2560
|
-
React.useEffect(() => {
|
|
2561
|
-
setDragged({})
|
|
2562
|
-
}, [graphKey])
|
|
2563
|
-
const onNodesChange = React.useCallback((changes) => {
|
|
2564
|
-
setDragged((current) => {
|
|
2565
|
-
let next = current
|
|
2566
|
-
for (const change of changes) {
|
|
2567
|
-
if (change?.type !== 'position' || change.position === undefined) continue
|
|
2568
|
-
if (next === current) next = { ...current }
|
|
2569
|
-
next[change.id] = change.position
|
|
2570
|
-
}
|
|
2571
|
-
return next
|
|
2572
|
-
})
|
|
2573
|
-
}, [])
|
|
2574
|
-
|
|
2575
2573
|
/** 一个点的状态:矛盾 > 废止 > 待核验(只登记、没有写进长期知识的事实)> 平常。 */
|
|
2576
2574
|
const nodeState = (node) => {
|
|
2577
2575
|
if (Array.isArray(node.facts) && node.facts.some((id) => conflicted.has(id))) return 'conflict'
|
|
@@ -2579,12 +2577,7 @@ window.__ModuleLoader__.load({
|
|
|
2579
2577
|
if (node.kind !== 'concept' && node.kind !== 'value_type' && node.source === 'asserted' && (node.facts ?? []).length === 0) return 'pending'
|
|
2580
2578
|
return 'on'
|
|
2581
2579
|
}
|
|
2582
|
-
const selectedId = picked?.kind === 'node' ? picked.node.id : (focus ?? null)
|
|
2583
2580
|
|
|
2584
|
-
/**
|
|
2585
|
-
* 投影节点 → React Flow 节点。坐标 = 力导向松弛过的投影坐标(起点确定 ⇒ 同一份账本同一张图)。
|
|
2586
|
-
* 尺寸显式给:只写在 style 里的话,React Flow 要等测量完成才知道它多大。
|
|
2587
|
-
*/
|
|
2588
2581
|
/**
|
|
2589
2582
|
* 小图(十来个点)不跑力导向:几个点、几条边时它常常把点排成一条线。
|
|
2590
2583
|
* 改成一圈:连得最多的那个点居中(它是这张图的主语),其余按投影顺序绕一圈——确定、好读。
|
|
@@ -2609,43 +2602,84 @@ window.__ModuleLoader__.load({
|
|
|
2609
2602
|
})
|
|
2610
2603
|
return out
|
|
2611
2604
|
})()
|
|
2612
|
-
const
|
|
2613
|
-
|
|
2614
|
-
|
|
2605
|
+
const basePosition = (node) => dragged[node.id] ?? ring?.get(node.id) ?? { x: node.x ?? 0, y: node.y ?? 0 }
|
|
2606
|
+
/**
|
|
2607
|
+
* 坐标 = 力导向松弛过的投影坐标(起点确定 ⇒ 同一份账本同一张图)。
|
|
2608
|
+
* 力导向会把它收到的节点整个换成新对象,所以**先算坐标、后建节点对象**;
|
|
2609
|
+
* 反过来的话缓存下来的节点身份会在布局那一步丢掉。
|
|
2610
|
+
*/
|
|
2611
|
+
const positions = small
|
|
2612
|
+
? new Map(allNodes.map((node) => [node.id, basePosition(node)]))
|
|
2613
|
+
: (() => {
|
|
2614
|
+
const laidOut = forceLayout(
|
|
2615
|
+
allNodes.map((node) => ({ id: node.id, position: basePosition(node) })),
|
|
2616
|
+
allEdges.map((edge) => ({ source: edge.from, target: edge.to })),
|
|
2617
|
+
)
|
|
2618
|
+
const out = new Map(allNodes.map((node) => [node.id, basePosition(node)]))
|
|
2619
|
+
for (const node of laidOut) {
|
|
2620
|
+
const x = node?.position?.x
|
|
2621
|
+
const y = node?.position?.y
|
|
2622
|
+
if (Number.isFinite(x) && Number.isFinite(y)) out.set(node.id, { x, y })
|
|
2623
|
+
}
|
|
2624
|
+
return out
|
|
2625
|
+
})()
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* 投影节点 → React Flow 节点。坐标 = 上面算好的位置。
|
|
2629
|
+
* 尺寸显式给:只写在 style 里的话,React Flow 要等测量完成才知道它多大。
|
|
2630
|
+
* 对象身份按**签名**守:内容没变就复用上一次那个对象,内容真变了才重建。
|
|
2631
|
+
*/
|
|
2632
|
+
const cache = nodeCache.current ?? new Map()
|
|
2633
|
+
const rfNodes = allNodes.map((node) => {
|
|
2634
|
+
const position = positions.get(node.id) ?? { x: 0, y: 0 }
|
|
2635
|
+
const state = nodeState(node)
|
|
2636
|
+
const selected = node.id === selectedId
|
|
2637
|
+
const labelText = trimLabel(node.kind === 'value_type' ? (FORM_WORD[node.ref] ?? node.label ?? node.ref) : (node.label ?? node.ref ?? node.id), 16)
|
|
2638
|
+
const counts = node.layer === 'entity' ? entityKnowledge?.[node.id]?.counts : undefined
|
|
2639
|
+
const children = childCount.get(node.id) ?? 0
|
|
2640
|
+
const collapsed = children > 0 ? isCollapsed(node.id) : false
|
|
2641
|
+
const foldText = children > 0 ? (collapsed ? `+${hiddenUnder.get(node.id) ?? 0}` : '−') : ''
|
|
2642
|
+
const signature = [node.id, node.kind, node.ref ?? '', position.x, position.y, selected ? 1 : 0, state, labelText, foldText, counts === undefined ? '' : JSON.stringify(counts)].join('\u0001')
|
|
2643
|
+
const cached = cache.get(node.id)
|
|
2644
|
+
if (cached !== undefined && cached.signature === signature) return cached.node
|
|
2645
|
+
const rfNode = {
|
|
2615
2646
|
id: node.id,
|
|
2616
2647
|
type: 'default',
|
|
2617
|
-
position
|
|
2648
|
+
position,
|
|
2618
2649
|
initialWidth: 120,
|
|
2619
2650
|
initialHeight: 26,
|
|
2620
|
-
selected
|
|
2651
|
+
selected,
|
|
2621
2652
|
data: {
|
|
2622
2653
|
label: h(
|
|
2623
2654
|
'span',
|
|
2624
|
-
{ className: 'clearai-star', 'data-kind': node.kind, 'data-state':
|
|
2655
|
+
{ className: 'clearai-star', 'data-kind': node.kind, 'data-state': state, 'data-sel': selected ? '1' : '0' },
|
|
2625
2656
|
h('i', null),
|
|
2626
|
-
h('span', null,
|
|
2627
|
-
node.layer === 'entity' ? h(CountMarks, { counts
|
|
2628
|
-
|
|
2657
|
+
h('span', null, labelText),
|
|
2658
|
+
node.layer === 'entity' ? h(CountMarks, { counts }) : null,
|
|
2659
|
+
children > 0
|
|
2629
2660
|
? h(
|
|
2630
2661
|
'b',
|
|
2631
2662
|
{
|
|
2632
2663
|
className: 'clearai-fold',
|
|
2633
|
-
title:
|
|
2664
|
+
title: collapsed ? t('展开下一层') : t('收起下一层'),
|
|
2634
2665
|
onClick: (event) => {
|
|
2635
2666
|
event.stopPropagation()
|
|
2636
2667
|
toggle(node.id)
|
|
2637
2668
|
},
|
|
2638
2669
|
},
|
|
2639
|
-
|
|
2670
|
+
foldText,
|
|
2640
2671
|
)
|
|
2641
2672
|
: null,
|
|
2642
2673
|
),
|
|
2643
2674
|
},
|
|
2644
2675
|
className: 'clearai-star-node',
|
|
2645
2676
|
style: { background: 'transparent', border: 0, padding: 0, width: 'auto', boxShadow: 'none' },
|
|
2646
|
-
}
|
|
2647
|
-
|
|
2648
|
-
|
|
2677
|
+
}
|
|
2678
|
+
cache.set(node.id, { signature, node: rfNode })
|
|
2679
|
+
return rfNode
|
|
2680
|
+
})
|
|
2681
|
+
/** 塌掉/移除的分支不在图上了:缓存里只留当前层还认识的点。 */
|
|
2682
|
+
for (const id of [...cache.keys()]) if (!nodeById.has(id)) cache.delete(id)
|
|
2649
2683
|
|
|
2650
2684
|
/** 投影边 → React Flow 边:实线已验证、虚线待核验、淡线上下位、告警色是矛盾。 */
|
|
2651
2685
|
const edgeTone = (edge) => {
|
|
@@ -2667,6 +2701,62 @@ window.__ModuleLoader__.load({
|
|
|
2667
2701
|
style: edgeTone(edge),
|
|
2668
2702
|
}))
|
|
2669
2703
|
|
|
2704
|
+
return {
|
|
2705
|
+
rfNodes,
|
|
2706
|
+
rfEdges,
|
|
2707
|
+
allNodes,
|
|
2708
|
+
allEdges,
|
|
2709
|
+
nodeById,
|
|
2710
|
+
entityNames,
|
|
2711
|
+
countOf,
|
|
2712
|
+
conflicts,
|
|
2713
|
+
graphKey: `${layer}|${layerNodes.length}|${layerEdges.length}`,
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
const GraphBand = ({ lexicon, data, send, layer, onLayer, fullscreen, onToggleFullscreen, onFilter, sessionId, unlanded, focus }) => {
|
|
2718
|
+
const [picked, setPicked] = React.useState(null)
|
|
2719
|
+
const [asked, setAsked] = React.useState({})
|
|
2720
|
+
const [toggled, setToggled] = React.useState({})
|
|
2721
|
+
const [dragged, setDragged] = React.useState({})
|
|
2722
|
+
/** 节点对象缓存:见 graphViewOf。父级重渲染一个都不换,选中只换选中那个。 */
|
|
2723
|
+
const nodeCache = React.useRef(new Map())
|
|
2724
|
+
const selectedId = picked?.kind === 'node' ? picked.node.id : (focus ?? null)
|
|
2725
|
+
React.useEffect(() => {
|
|
2726
|
+
setToggled({})
|
|
2727
|
+
}, [layer])
|
|
2728
|
+
|
|
2729
|
+
/**
|
|
2730
|
+
* **同一份投影只产出一组 nodes/edges**。会话在跑时中栏会被高频重渲染;
|
|
2731
|
+
* 每次重造对象会让 React Flow 重新 adopt、边被卸载重挂,边标签因此闪。
|
|
2732
|
+
*/
|
|
2733
|
+
const view = React.useMemo(
|
|
2734
|
+
() => graphViewOf({ lexicon, layer, toggled, dragged, selectedId, entityKnowledge: data?.entityKnowledge, nodeCache, setToggled }),
|
|
2735
|
+
[lexicon, layer, toggled, dragged, selectedId, data?.entityKnowledge],
|
|
2736
|
+
)
|
|
2737
|
+
const { rfNodes, rfEdges, allNodes, allEdges, nodeById, entityNames, countOf, conflicts, graphKey } = view
|
|
2738
|
+
/** 读时的跨文件检查只标不拦:有问题的那一份不进图,这里说清是哪个文件、哪里不对。 */
|
|
2739
|
+
const problems = Array.isArray(lexicon?.problems) ? lexicon.problems : []
|
|
2740
|
+
|
|
2741
|
+
/**
|
|
2742
|
+
* **节点位置是受控的,所以必须自己接住拖动**:不给 `onNodesChange`,
|
|
2743
|
+
* React Flow 内部的拖动没有地方落地,节点根本拖不动。位置是界面状态,换层或图变了就清掉。
|
|
2744
|
+
*/
|
|
2745
|
+
React.useEffect(() => {
|
|
2746
|
+
setDragged({})
|
|
2747
|
+
}, [graphKey])
|
|
2748
|
+
const onNodesChange = React.useCallback((changes) => {
|
|
2749
|
+
setDragged((current) => {
|
|
2750
|
+
let next = current
|
|
2751
|
+
for (const change of changes) {
|
|
2752
|
+
if (change?.type !== 'position' || change.position === undefined) continue
|
|
2753
|
+
if (next === current) next = { ...current }
|
|
2754
|
+
next[change.id] = change.position
|
|
2755
|
+
}
|
|
2756
|
+
return next
|
|
2757
|
+
})
|
|
2758
|
+
}, [])
|
|
2759
|
+
|
|
2670
2760
|
const onNodeClick = (_event, node) => {
|
|
2671
2761
|
const original = nodeById.get(node.id)
|
|
2672
2762
|
if (original !== undefined) setPicked({ kind: 'node', node: original })
|