@yuku123/z-cognition-component 1.0.1 → 1.0.3

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.
@@ -0,0 +1,128 @@
1
+ import { jsx as e, jsxs as r } from "react/jsx-runtime";
2
+ import { useState as i, useEffect as j } from "react";
3
+ import { useSearchParams as E } from "react-router-dom";
4
+ import { Alert as N, Spin as P, Card as I, Space as m, Select as S, Input as p, Button as T, Descriptions as a, Tag as z, message as x } from "antd";
5
+ import { DatabaseOutlined as $ } from "@ant-design/icons";
6
+ import { o as h, f as n } from "./api-BVrIcAFp.js";
7
+ import { parseSnapshot as F } from "./OntologyValidatePage-WX4sAfzY.js";
8
+ const { TextArea: L } = p;
9
+ function U() {
10
+ var w;
11
+ const [C] = E(), o = C.get("id") || "", [s, k] = i("source"), [d, A] = i("default"), [c, g] = i(""), [f, B] = i(`{
12
+ "individuals": [],
13
+ "statements": []
14
+ }`), [D, v] = i([]), [l, u] = i(null), [R, y] = i(!1);
15
+ j(() => {
16
+ o && h.listSources().then(v).catch(() => v([]));
17
+ }, [o]);
18
+ const M = async () => {
19
+ y(!0), u(null);
20
+ try {
21
+ if (s === "source") {
22
+ if (!c.trim()) {
23
+ x.warning("按来源物化需要指定 source");
24
+ return;
25
+ }
26
+ u(await h.materialize(o, c.trim(), d));
27
+ } else
28
+ u(await h.materializeInline(o, F(f), d));
29
+ } catch (t) {
30
+ x.error(t.message);
31
+ } finally {
32
+ y(!1);
33
+ }
34
+ };
35
+ if (!o)
36
+ return /* @__PURE__ */ e(N, { type: "warning", message: "缺少本体 ID(?id=xxx)" });
37
+ const b = ((w = l == null ? void 0 : l.validation) == null ? void 0 : w.issues) || [];
38
+ return /* @__PURE__ */ r(P, { spinning: R, children: [
39
+ /* @__PURE__ */ e(I, { size: "small", title: "物化输入", style: { marginBottom: 16 }, children: /* @__PURE__ */ r(m, { direction: "vertical", style: { width: "100%" }, size: 12, children: [
40
+ /* @__PURE__ */ r(m, { wrap: !0, children: [
41
+ /* @__PURE__ */ e(
42
+ S,
43
+ {
44
+ style: { width: 200 },
45
+ value: s,
46
+ onChange: k,
47
+ options: [
48
+ { value: "source", label: "按来源物化" },
49
+ { value: "inline", label: "内联快照物化" }
50
+ ]
51
+ }
52
+ ),
53
+ /* @__PURE__ */ e(
54
+ p,
55
+ {
56
+ style: { width: 220 },
57
+ placeholder: "工作空间",
58
+ value: d,
59
+ onChange: (t) => A(t.target.value)
60
+ }
61
+ ),
62
+ s === "source" ? /* @__PURE__ */ e(
63
+ S,
64
+ {
65
+ style: { width: 280 },
66
+ placeholder: "选择数据源",
67
+ value: c || void 0,
68
+ onChange: g,
69
+ showSearch: !0,
70
+ options: D.map((t) => ({ value: t.id, label: t.description ? `${t.id} — ${t.description}` : t.id })),
71
+ notFoundContent: null
72
+ }
73
+ ) : null,
74
+ /* @__PURE__ */ e(T, { type: "primary", icon: /* @__PURE__ */ e($, {}), onClick: M, children: "执行物化" })
75
+ ] }),
76
+ s === "source" ? /* @__PURE__ */ e(
77
+ p,
78
+ {
79
+ style: { width: 420 },
80
+ placeholder: "source ID(可直接输入)",
81
+ value: c,
82
+ onChange: (t) => g(t.target.value)
83
+ }
84
+ ) : /* @__PURE__ */ e(
85
+ L,
86
+ {
87
+ rows: 10,
88
+ value: f,
89
+ onChange: (t) => B(t.target.value),
90
+ placeholder: '{"individuals": [], "statements": []}'
91
+ }
92
+ )
93
+ ] }) }),
94
+ l ? /* @__PURE__ */ r(I, { size: "small", title: "物化报告", children: [
95
+ /* @__PURE__ */ r(a, { bordered: !0, size: "small", column: 2, style: { marginBottom: 12 }, children: [
96
+ /* @__PURE__ */ e(a.Item, { label: "本体", children: n(l, "ontologyId") }),
97
+ /* @__PURE__ */ e(a.Item, { label: "工作空间", children: n(l, "workspace") }),
98
+ /* @__PURE__ */ e(a.Item, { label: "来源", children: n(l, "sourceId") || "(内联)" }),
99
+ /* @__PURE__ */ r(a.Item, { label: "耗时", children: [
100
+ n(l, "durationMs"),
101
+ " ms"
102
+ ] }),
103
+ /* @__PURE__ */ e(a.Item, { label: "类节点", children: n(l, "classNodes") }),
104
+ /* @__PURE__ */ e(a.Item, { label: "实例节点", children: n(l, "individualNodes") }),
105
+ /* @__PURE__ */ e(a.Item, { label: "边", children: n(l, "edges") }),
106
+ /* @__PURE__ */ e(a.Item, { label: "物化时间", children: n(l, "materializedAt") || "—" })
107
+ ] }),
108
+ /* @__PURE__ */ r(m, { size: "large", wrap: !0, style: { marginBottom: 8 }, children: [
109
+ /* @__PURE__ */ r("span", { children: [
110
+ "显式陈述 ",
111
+ /* @__PURE__ */ e("b", { children: n(l, "explicitStatements") })
112
+ ] }),
113
+ /* @__PURE__ */ r("span", { children: [
114
+ "推理陈述 ",
115
+ /* @__PURE__ */ e("b", { children: n(l, "inferredStatements") })
116
+ ] })
117
+ ] }),
118
+ b.length ? /* @__PURE__ */ e("div", { children: b.map((t, O) => /* @__PURE__ */ r(z, { color: t.severity === "ERROR" ? "red" : "orange", children: [
119
+ t.code,
120
+ " ",
121
+ t.message
122
+ ] }, O)) }) : /* @__PURE__ */ e(z, { color: "green", children: "物化通过,无校验问题" })
123
+ ] }) : null
124
+ ] });
125
+ }
126
+ export {
127
+ U as default
128
+ };
@@ -0,0 +1,270 @@
1
+ import { jsx as o, jsxs as c, Fragment as J } from "react/jsx-runtime";
2
+ import { useState as f, useMemo as Q, useRef as de, useCallback as m, useEffect as ue } from "react";
3
+ import { useSearchParams as pe } from "react-router-dom";
4
+ import { message as G, Empty as U, Tag as T, Input as ye, Button as b, Spin as fe, Drawer as he, Descriptions as C } from "antd";
5
+ import { ApartmentOutlined as X, ReloadOutlined as me, RollbackOutlined as ge, ExpandOutlined as Y, ArrowsAltOutlined as Z } from "@ant-design/icons";
6
+ import { o as A } from "./api-BVrIcAFp.js";
7
+ import { b as ke, t as ve, u as be } from "./use-g6-graph-2-Pr4oTs.js";
8
+ import "d3-force";
9
+ import "@antv/g6";
10
+ const se = "class", te = "instance";
11
+ function Ce() {
12
+ return ke([
13
+ { categoryCode: se },
14
+ { categoryCode: te }
15
+ ]);
16
+ }
17
+ function E(a) {
18
+ return (a.labels || []).includes("OntologyClass");
19
+ }
20
+ function ee(a) {
21
+ return (a.labels || []).includes("OntologyIndividual");
22
+ }
23
+ function _(a) {
24
+ const r = a.properties && a.properties.name;
25
+ return r != null && String(r).trim() ? String(r) : a.key;
26
+ }
27
+ function Ne(a, r) {
28
+ const d = (a.nodes || []).map((t) => ({
29
+ id: t.key,
30
+ code: t.key,
31
+ name: _(t),
32
+ fullName: t.key,
33
+ categoryCode: E(t) ? se : te,
34
+ objectCode: t.key,
35
+ objectName: _(t),
36
+ labels: t.labels || [],
37
+ props: t.properties || {}
38
+ })), g = (a.edges || []).map((t) => ({
39
+ source: t.from_key,
40
+ target: t.to_key,
41
+ code: t.type,
42
+ value: t.type,
43
+ displayName: t.type,
44
+ edgeKey: t.key,
45
+ isSelfAssoc: t.from_key === t.to_key
46
+ }));
47
+ return ve({ data: d, links: g }, void 0, void 0, r);
48
+ }
49
+ function Se(a, r) {
50
+ const d = new Map((a.nodes || []).map((t) => [t.key, t])), g = new Map((a.edges || []).map((t) => [t.key || `${t.from_key}|${t.type}|${t.to_key}`, t]));
51
+ return (r.nodes || []).forEach((t) => d.set(t.key, t)), (r.edges || []).forEach((t) => g.set(t.key || `${t.from_key}|${t.type}|${t.to_key}`, t)), { nodes: [...d.values()], edges: [...g.values()] };
52
+ }
53
+ function ze() {
54
+ const [a] = pe(), r = a.get("id") || "", [d, g] = f("default"), [t, M] = f("structure"), [ne, P] = f(""), [N, R] = f([]), [y, I] = f({ nodes: [], edges: [] }), [F, $] = f(!1), [i, S] = f(null), [w, k] = f([]), [B, L] = f(!1), H = Q(() => Ce(), []), p = de(0), K = m(
55
+ (e) => (y.nodes || []).find((s) => s.key === e) || null,
56
+ [y.nodes]
57
+ ), j = m(() => (y.nodes || []).map((e) => e.key), [y.nodes]), { containerRef: oe, setData: W, setViewState: O, ready: re } = be({
58
+ onNodeClick: (e) => {
59
+ var l, u;
60
+ const s = ((l = e.data) == null ? void 0 : l.code) || ((u = e.data) == null ? void 0 : u.id);
61
+ if (!s) return;
62
+ const n = K(s);
63
+ S(n || { key: s, labels: [], properties: {} }), k([s]), O([s], [], j().filter((h) => h !== s));
64
+ },
65
+ onNodeDoubleClick: (e) => {
66
+ var l, u;
67
+ const s = ((l = e.data) == null ? void 0 : l.code) || ((u = e.data) == null ? void 0 : u.id), n = K(s);
68
+ n && E(n) && z(n.key);
69
+ },
70
+ onCanvasClick: () => {
71
+ S(null), k([]), O([], [], []);
72
+ },
73
+ tooltipFormatter: (e, s) => {
74
+ if (s !== "node") return "";
75
+ const n = Array.isArray(e.labels) ? e.labels.join(" / ") : "";
76
+ return `<div><b>${D(e.name || e.code || "")}</b>${n ? `<div style="color:#888;font-size:12px">${D(n)}</div>` : ""}<div style="color:#999;font-size:12px">${D(e.code || "")}</div></div>`;
77
+ }
78
+ }), v = m(
79
+ (e, s = {}) => {
80
+ const n = Ne(e, H);
81
+ W(n, { fit: s.fit !== !1, keepPositions: !!s.keepPositions });
82
+ },
83
+ [W, H]
84
+ ), x = m(
85
+ async (e = d) => {
86
+ if (!r) return;
87
+ const s = ++p.current;
88
+ $(!0);
89
+ try {
90
+ const n = await A.listClasses(r, e);
91
+ if (s !== p.current) return;
92
+ R(n || []);
93
+ const l = (n || []).map((h) => h.key), u = await A.subgraph(r, l, 1, e);
94
+ if (s !== p.current) return;
95
+ I(u || { nodes: [], edges: [] }), M("structure"), P(""), S(null), k([]), v(u || { nodes: [], edges: [] });
96
+ } catch (n) {
97
+ s === p.current && (G.error(`图谱取数失败:${n.message}`), I({ nodes: [], edges: [] }), R([]));
98
+ } finally {
99
+ s === p.current && $(!1);
100
+ }
101
+ },
102
+ [r, d, v]
103
+ );
104
+ ue(() => (r && x("default"), () => {
105
+ p.current += 1;
106
+ }), [r]);
107
+ const z = m(
108
+ async (e) => {
109
+ if (!r) return;
110
+ const s = ++p.current;
111
+ $(!0);
112
+ try {
113
+ const n = await A.subgraph(r, [e], 1, d);
114
+ if (s !== p.current) return;
115
+ I(n || { nodes: [], edges: [] }), M("instance"), P(e), S(null), k([]), v(n || { nodes: [], edges: [] });
116
+ } catch (n) {
117
+ s === p.current && G.error(`实例图取数失败:${n.message}`);
118
+ } finally {
119
+ s === p.current && $(!1);
120
+ }
121
+ },
122
+ [r, d, v]
123
+ ), le = m(() => x(), [x]), q = m(
124
+ async (e) => {
125
+ const s = e || i;
126
+ if (!(!s || !r)) {
127
+ L(!0);
128
+ try {
129
+ const n = await A.listNeighbors(r, s.key, 1, d), l = { nodes: [], edges: [] };
130
+ (n || []).forEach((h) => {
131
+ h.node && l.nodes.push(h.node), h.edge && l.edges.push(h.edge);
132
+ });
133
+ const u = Se(y, l);
134
+ I(u), v(u, { keepPositions: !0 });
135
+ } catch (n) {
136
+ G.error(`邻居展开失败:${n.message}`);
137
+ } finally {
138
+ L(!1);
139
+ }
140
+ }
141
+ },
142
+ [i, r, d, y, v]
143
+ ), ie = m(
144
+ (e) => {
145
+ const s = w.includes(e) ? w.filter((n) => n !== e) : [...w, e];
146
+ k(s), O(s, [], s.length ? j().filter((n) => !s.includes(n)) : []);
147
+ },
148
+ [w, O, j]
149
+ ), ae = Q(() => {
150
+ const e = {}, s = new Set((N || []).map((n) => n.key));
151
+ return (y.nodes || []).forEach((n) => {
152
+ s.has(n.key) ? e[n.key] = e[n.key] || { instances: 0 } : ee(n) && (n.labels || []).filter((l) => s.has(l)).forEach((l) => {
153
+ e[l] = e[l] || { instances: 0 }, e[l].instances += 1;
154
+ });
155
+ }), e;
156
+ }, [N, y.nodes]);
157
+ if (!r)
158
+ return /* @__PURE__ */ o(U, { description: "缺少本体 ID(?id=xxx)", style: { padding: 48 } });
159
+ const V = t === "structure", ce = !!(y.nodes || []).length;
160
+ return /* @__PURE__ */ c("div", { className: "view", children: [
161
+ /* @__PURE__ */ c("div", { className: "view-bar", children: [
162
+ /* @__PURE__ */ c(T, { icon: /* @__PURE__ */ o(X, {}), color: "purple", children: [
163
+ "本体 ",
164
+ r
165
+ ] }),
166
+ /* @__PURE__ */ o(
167
+ ye.Search,
168
+ {
169
+ style: { width: 200 },
170
+ placeholder: "工作空间(默认 default)",
171
+ value: d,
172
+ onChange: (e) => g(e.target.value),
173
+ onSearch: () => x()
174
+ }
175
+ ),
176
+ V ? /* @__PURE__ */ o(b, { icon: /* @__PURE__ */ o(me, {}), onClick: () => x(), children: "刷新" }) : /* @__PURE__ */ c(J, { children: [
177
+ /* @__PURE__ */ o(b, { icon: /* @__PURE__ */ o(ge, {}), onClick: le, children: "返回结构层" }),
178
+ /* @__PURE__ */ c(T, { color: "blue", children: [
179
+ "实例层:",
180
+ ne
181
+ ] })
182
+ ] }),
183
+ i ? /* @__PURE__ */ o(b, { icon: /* @__PURE__ */ o(Y, {}), loading: B, onClick: () => q(i), children: "展开邻居" }) : null,
184
+ /* @__PURE__ */ o("span", { className: "spacer hint", children: "双击类节点进入实例层 · 点击节点查看详情 · 空白点击取消" })
185
+ ] }),
186
+ /* @__PURE__ */ c("div", { style: { display: "flex", gap: 12, alignItems: "stretch", height: "calc(100vh - 220px)" }, children: [
187
+ /* @__PURE__ */ c("div", { className: "side-rail", children: [
188
+ /* @__PURE__ */ c("div", { className: "rail-head", children: [
189
+ "类型(",
190
+ N.length,
191
+ ")"
192
+ ] }),
193
+ N.length ? /* @__PURE__ */ o("ul", { className: "rail-list", children: N.map((e) => {
194
+ const s = ae[e.key] || { instances: 0 }, n = w.includes(e.key);
195
+ return /* @__PURE__ */ c(
196
+ "li",
197
+ {
198
+ className: `rail-item${n ? " active" : ""}`,
199
+ onClick: () => ie(e.key),
200
+ title: "点击高亮该类型",
201
+ children: [
202
+ /* @__PURE__ */ o(X, { style: { color: "#722ed1" } }),
203
+ /* @__PURE__ */ o("span", { style: { flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: _(e) }),
204
+ /* @__PURE__ */ c(T, { style: { fontSize: 11 }, children: [
205
+ s.instances,
206
+ " 实例"
207
+ ] }),
208
+ /* @__PURE__ */ o(
209
+ b,
210
+ {
211
+ type: "link",
212
+ size: "small",
213
+ style: { padding: 0 },
214
+ icon: /* @__PURE__ */ o(Z, {}),
215
+ title: "进入实例层",
216
+ onClick: (l) => {
217
+ l.stopPropagation(), z(e.key);
218
+ }
219
+ }
220
+ )
221
+ ]
222
+ },
223
+ e.key
224
+ );
225
+ }) }) : /* @__PURE__ */ o("div", { className: "empty-note", children: "暂无类定义(可先登记 schema 或物化)" })
226
+ ] }),
227
+ /* @__PURE__ */ c("div", { ref: oe, className: "graph-canvas", children: [
228
+ F ? /* @__PURE__ */ o("div", { className: "canvas-overlay", children: /* @__PURE__ */ o(fe, { tip: "图谱加载中", children: /* @__PURE__ */ o("div", { style: { width: 80, height: 80 } }) }) }) : null,
229
+ !F && re && !ce ? /* @__PURE__ */ o("div", { className: "canvas-overlay", children: /* @__PURE__ */ o(U, { description: V ? "本体内无物化图数据" : "该类型暂无实例" }) }) : null
230
+ ] })
231
+ ] }),
232
+ /* @__PURE__ */ o(
233
+ he,
234
+ {
235
+ open: !!i,
236
+ width: 380,
237
+ title: i ? _(i) : "",
238
+ onClose: () => {
239
+ S(null), k([]);
240
+ },
241
+ destroyOnHidden: !0,
242
+ children: i ? /* @__PURE__ */ c(J, { children: [
243
+ /* @__PURE__ */ c(C, { column: 1, size: "small", bordered: !0, children: [
244
+ /* @__PURE__ */ o(C.Item, { label: "key", children: i.key }),
245
+ /* @__PURE__ */ o(C.Item, { label: "类型", children: E(i) ? "类" : ee(i) ? "实例" : (i.labels || []).join(" / ") || "节点" }),
246
+ /* @__PURE__ */ o(C.Item, { label: "标签", children: (i.labels || []).join(" / ") || "-" })
247
+ ] }),
248
+ /* @__PURE__ */ o("div", { style: { marginTop: 16, fontWeight: 600, marginBottom: 8 }, children: "属性" }),
249
+ Object.keys(i.properties || {}).length ? /* @__PURE__ */ o(C, { column: 1, size: "small", children: Object.entries(i.properties).map(([e, s]) => /* @__PURE__ */ o(C.Item, { label: e, children: String(s) }, e)) }) : /* @__PURE__ */ o("div", { style: { color: "#999", fontSize: 12 }, children: "(无属性)" }),
250
+ /* @__PURE__ */ c("div", { style: { marginTop: 16, display: "flex", gap: 8 }, children: [
251
+ /* @__PURE__ */ o(b, { icon: /* @__PURE__ */ o(Y, {}), loading: B, onClick: () => q(i), children: "展开 1 跳邻居" }),
252
+ E(i) ? /* @__PURE__ */ o(b, { type: "primary", icon: /* @__PURE__ */ o(Z, {}), onClick: () => z(i.key), children: "查看实例" }) : null
253
+ ] })
254
+ ] }) : null
255
+ }
256
+ )
257
+ ] });
258
+ }
259
+ function D(a) {
260
+ return String(a).replace(/[&<>"']/g, (r) => ({
261
+ "&": "&amp;",
262
+ "<": "&lt;",
263
+ ">": "&gt;",
264
+ '"': "&quot;",
265
+ "'": "&#39;"
266
+ })[r]);
267
+ }
268
+ export {
269
+ ze as default
270
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),se=require("react-router-dom"),l=require("antd"),f=require("@ant-design/icons"),A=require("./api-D5Hgcud4.cjs"),q=require("./use-g6-graph-B9K6IPJe.cjs");require("d3-force");require("@antv/g6");const W="class",V="instance";function te(){return q.buildCategoryColorMap([{categoryCode:W},{categoryCode:V}])}function O(d){return(d.labels||[]).includes("OntologyClass")}function K(d){return(d.labels||[]).includes("OntologyIndividual")}function I(d){const r=d.properties&&d.properties.name;return r!=null&&String(r).trim()?String(r):d.key}function ne(d,r){const u=(d.nodes||[]).map(n=>({id:n.key,code:n.key,name:I(n),fullName:n.key,categoryCode:O(n)?W:V,objectCode:n.key,objectName:I(n),labels:n.labels||[],props:n.properties||{}})),m=(d.edges||[]).map(n=>({source:n.from_key,target:n.to_key,code:n.type,value:n.type,displayName:n.type,edgeKey:n.key,isSelfAssoc:n.from_key===n.to_key}));return q.toG6Data({data:u,links:m},void 0,void 0,r)}function oe(d,r){const u=new Map((d.nodes||[]).map(n=>[n.key,n])),m=new Map((d.edges||[]).map(n=>[n.key||`${n.from_key}|${n.type}|${n.to_key}`,n]));return(r.nodes||[]).forEach(n=>u.set(n.key,n)),(r.edges||[]).forEach(n=>m.set(n.key||`${n.from_key}|${n.type}|${n.to_key}`,n)),{nodes:[...u.values()],edges:[...m.values()]}}function re(){const[d]=se.useSearchParams(),r=d.get("id")||"",[u,m]=i.useState("default"),[n,T]=i.useState("structure"),[J,_]=i.useState(""),[j,G]=i.useState([]),[g,S]=i.useState({nodes:[],edges:[]}),[R,N]=i.useState(!1),[c,b]=i.useState(null),[v,x]=i.useState([]),[B,M]=i.useState(!1),z=i.useMemo(()=>te(),[]),y=i.useRef(0),P=i.useCallback(s=>(g.nodes||[]).find(t=>t.key===s)||null,[g.nodes]),$=i.useCallback(()=>(g.nodes||[]).map(s=>s.key),[g.nodes]),{containerRef:Q,setData:F,setViewState:w,ready:U}=q.useG6Graph({onNodeClick:s=>{var a,p;const t=((a=s.data)==null?void 0:a.code)||((p=s.data)==null?void 0:p.id);if(!t)return;const o=P(t);b(o||{key:t,labels:[],properties:{}}),x([t]),w([t],[],$().filter(h=>h!==t))},onNodeDoubleClick:s=>{var a,p;const t=((a=s.data)==null?void 0:a.code)||((p=s.data)==null?void 0:p.id),o=P(t);o&&O(o)&&D(o.key)},onCanvasClick:()=>{b(null),x([]),w([],[],[])},tooltipFormatter:(s,t)=>{if(t!=="node")return"";const o=Array.isArray(s.labels)?s.labels.join(" / "):"";return`<div><b>${E(s.name||s.code||"")}</b>${o?`<div style="color:#888;font-size:12px">${E(o)}</div>`:""}<div style="color:#999;font-size:12px">${E(s.code||"")}</div></div>`}}),k=i.useCallback((s,t={})=>{const o=ne(s,z);F(o,{fit:t.fit!==!1,keepPositions:!!t.keepPositions})},[F,z]),C=i.useCallback(async(s=u)=>{if(!r)return;const t=++y.current;N(!0);try{const o=await A.ontologyApi.listClasses(r,s);if(t!==y.current)return;G(o||[]);const a=(o||[]).map(h=>h.key),p=await A.ontologyApi.subgraph(r,a,1,s);if(t!==y.current)return;S(p||{nodes:[],edges:[]}),T("structure"),_(""),b(null),x([]),k(p||{nodes:[],edges:[]})}catch(o){t===y.current&&(l.message.error(`图谱取数失败:${o.message}`),S({nodes:[],edges:[]}),G([]))}finally{t===y.current&&N(!1)}},[r,u,k]);i.useEffect(()=>(r&&C("default"),()=>{y.current+=1}),[r]);const D=i.useCallback(async s=>{if(!r)return;const t=++y.current;N(!0);try{const o=await A.ontologyApi.subgraph(r,[s],1,u);if(t!==y.current)return;S(o||{nodes:[],edges:[]}),T("instance"),_(s),b(null),x([]),k(o||{nodes:[],edges:[]})}catch(o){t===y.current&&l.message.error(`实例图取数失败:${o.message}`)}finally{t===y.current&&N(!1)}},[r,u,k]),X=i.useCallback(()=>C(),[C]),L=i.useCallback(async s=>{const t=s||c;if(!(!t||!r)){M(!0);try{const o=await A.ontologyApi.listNeighbors(r,t.key,1,u),a={nodes:[],edges:[]};(o||[]).forEach(h=>{h.node&&a.nodes.push(h.node),h.edge&&a.edges.push(h.edge)});const p=oe(g,a);S(p),k(p,{keepPositions:!0})}catch(o){l.message.error(`邻居展开失败:${o.message}`)}finally{M(!1)}}},[c,r,u,g,k]),Y=i.useCallback(s=>{const t=v.includes(s)?v.filter(o=>o!==s):[...v,s];x(t),w(t,[],t.length?$().filter(o=>!t.includes(o)):[])},[v,w,$]),Z=i.useMemo(()=>{const s={},t=new Set((j||[]).map(o=>o.key));return(g.nodes||[]).forEach(o=>{t.has(o.key)?s[o.key]=s[o.key]||{instances:0}:K(o)&&(o.labels||[]).filter(a=>t.has(a)).forEach(a=>{s[a]=s[a]||{instances:0},s[a].instances+=1})}),s},[j,g.nodes]);if(!r)return e.jsx(l.Empty,{description:"缺少本体 ID(?id=xxx)",style:{padding:48}});const H=n==="structure",ee=!!(g.nodes||[]).length;return e.jsxs("div",{className:"view",children:[e.jsxs("div",{className:"view-bar",children:[e.jsxs(l.Tag,{icon:e.jsx(f.ApartmentOutlined,{}),color:"purple",children:["本体 ",r]}),e.jsx(l.Input.Search,{style:{width:200},placeholder:"工作空间(默认 default)",value:u,onChange:s=>m(s.target.value),onSearch:()=>C()}),H?e.jsx(l.Button,{icon:e.jsx(f.ReloadOutlined,{}),onClick:()=>C(),children:"刷新"}):e.jsxs(e.Fragment,{children:[e.jsx(l.Button,{icon:e.jsx(f.RollbackOutlined,{}),onClick:X,children:"返回结构层"}),e.jsxs(l.Tag,{color:"blue",children:["实例层:",J]})]}),c?e.jsx(l.Button,{icon:e.jsx(f.ExpandOutlined,{}),loading:B,onClick:()=>L(c),children:"展开邻居"}):null,e.jsx("span",{className:"spacer hint",children:"双击类节点进入实例层 · 点击节点查看详情 · 空白点击取消"})]}),e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"stretch",height:"calc(100vh - 220px)"},children:[e.jsxs("div",{className:"side-rail",children:[e.jsxs("div",{className:"rail-head",children:["类型(",j.length,")"]}),j.length?e.jsx("ul",{className:"rail-list",children:j.map(s=>{const t=Z[s.key]||{instances:0},o=v.includes(s.key);return e.jsxs("li",{className:`rail-item${o?" active":""}`,onClick:()=>Y(s.key),title:"点击高亮该类型",children:[e.jsx(f.ApartmentOutlined,{style:{color:"#722ed1"}}),e.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I(s)}),e.jsxs(l.Tag,{style:{fontSize:11},children:[t.instances," 实例"]}),e.jsx(l.Button,{type:"link",size:"small",style:{padding:0},icon:e.jsx(f.ArrowsAltOutlined,{}),title:"进入实例层",onClick:a=>{a.stopPropagation(),D(s.key)}})]},s.key)})}):e.jsx("div",{className:"empty-note",children:"暂无类定义(可先登记 schema 或物化)"})]}),e.jsxs("div",{ref:Q,className:"graph-canvas",children:[R?e.jsx("div",{className:"canvas-overlay",children:e.jsx(l.Spin,{tip:"图谱加载中",children:e.jsx("div",{style:{width:80,height:80}})})}):null,!R&&U&&!ee?e.jsx("div",{className:"canvas-overlay",children:e.jsx(l.Empty,{description:H?"本体内无物化图数据":"该类型暂无实例"})}):null]})]}),e.jsx(l.Drawer,{open:!!c,width:380,title:c?I(c):"",onClose:()=>{b(null),x([])},destroyOnHidden:!0,children:c?e.jsxs(e.Fragment,{children:[e.jsxs(l.Descriptions,{column:1,size:"small",bordered:!0,children:[e.jsx(l.Descriptions.Item,{label:"key",children:c.key}),e.jsx(l.Descriptions.Item,{label:"类型",children:O(c)?"类":K(c)?"实例":(c.labels||[]).join(" / ")||"节点"}),e.jsx(l.Descriptions.Item,{label:"标签",children:(c.labels||[]).join(" / ")||"-"})]}),e.jsx("div",{style:{marginTop:16,fontWeight:600,marginBottom:8},children:"属性"}),Object.keys(c.properties||{}).length?e.jsx(l.Descriptions,{column:1,size:"small",children:Object.entries(c.properties).map(([s,t])=>e.jsx(l.Descriptions.Item,{label:s,children:String(t)},s))}):e.jsx("div",{style:{color:"#999",fontSize:12},children:"(无属性)"}),e.jsxs("div",{style:{marginTop:16,display:"flex",gap:8},children:[e.jsx(l.Button,{icon:e.jsx(f.ExpandOutlined,{}),loading:B,onClick:()=>L(c),children:"展开 1 跳邻居"}),O(c)?e.jsx(l.Button,{type:"primary",icon:e.jsx(f.ArrowsAltOutlined,{}),onClick:()=>D(c.key),children:"查看实例"}):null]})]}):null})]})}function E(d){return String(d).replace(/[&<>"']/g,r=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[r])}exports.default=re;
@@ -0,0 +1,4 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),R=require("react-router-dom"),s=require("antd"),k=require("@ant-design/icons"),o=require("./api-D5Hgcud4.cjs"),{TextArea:O}=s.Input,A={ERROR:"red",WARNING:"orange",INFO:"blue"};function q(){const[u]=R.useSearchParams(),a=u.get("id")||"",[i,S]=n.useState("source"),[h,j]=n.useState("default"),[l,p]=n.useState(""),[g,w]=n.useState(`{
2
+ "individuals": [],
3
+ "statements": []
4
+ }`),[f,x]=n.useState([]),[r,d]=n.useState(null),[v,y]=n.useState(!1);n.useEffect(()=>{a&&o.ontologyApi.listSources().then(x).catch(()=>x([]))},[a]);const C=async()=>{y(!0),d(null);try{if(i==="source"){if(!l.trim()){s.message.warning("按来源校验需要指定 source");return}d(await o.ontologyApi.validateSource(a,l.trim(),h))}else d(await o.ontologyApi.validate(a,m(g)))}catch(t){s.message.error(t.message)}finally{y(!1)}},I=[{title:"级别",dataIndex:"severity",key:"severity",width:90,render:t=>e.jsx(s.Tag,{color:A[t]||"default",children:t})},{title:"编码",dataIndex:"code",key:"code",width:160},{title:"主体",dataIndex:"subject",key:"subject",width:160},{title:"谓词",dataIndex:"predicate",key:"predicate",width:140},{title:"说明",dataIndex:"message",key:"message"}];if(!a)return e.jsx(s.Alert,{type:"warning",message:"缺少本体 ID(?id=xxx)"});const c=(r==null?void 0:r.issues)||[];return e.jsxs(s.Spin,{spinning:v,children:[e.jsx(s.Card,{size:"small",style:{marginBottom:16},children:e.jsxs(s.Space,{direction:"vertical",style:{width:"100%"},size:12,children:[e.jsxs(s.Space,{wrap:!0,children:[e.jsx(s.Select,{style:{width:180},value:i,onChange:S,options:[{value:"source",label:"按来源校验"},{value:"inline",label:"内联快照校验"}]}),e.jsx(s.Input,{style:{width:220},placeholder:"工作空间",value:h,onChange:t=>j(t.target.value)}),i==="source"?e.jsx(s.Select,{style:{width:280},placeholder:"选择或输入数据源",value:l||void 0,onChange:p,showSearch:!0,options:f.map(t=>({value:t.id,label:t.description?`${t.id} — ${t.description}`:t.id})),notFoundContent:null}):null,e.jsx(s.Button,{type:"primary",icon:e.jsx(k.CheckCircleOutlined,{}),onClick:C,children:"执行校验"})]}),i==="source"?e.jsx(s.Input,{style:{width:420},placeholder:"source ID(可直接输入)",value:l,onChange:t=>p(t.target.value)}):e.jsx(O,{rows:10,value:g,onChange:t=>w(t.target.value),placeholder:'{"individuals": [], "statements": []}'})]})}),r?e.jsxs(s.Card,{size:"small",title:`校验结果(${c.length} 条问题)`,children:[e.jsxs(s.Space,{size:"large",wrap:!0,style:{marginBottom:c.length?12:0},children:[e.jsxs("span",{children:["错误 ",e.jsx("b",{children:o.field(r,"errorCount","error_count")})]}),e.jsxs("span",{children:["警告 ",e.jsx("b",{children:o.field(r,"warningCount","warning_count")})]}),e.jsxs("span",{children:["提示 ",e.jsx("b",{children:o.field(r,"infoCount","info_count")})]})]}),c.length===0?e.jsx(s.Alert,{type:"success",message:"校验通过,未发现问题"}):e.jsx(s.Table,{rowKey:(t,b)=>`${t.code}-${b}`,size:"small",columns:I,dataSource:c,pagination:!1})]}):null]})}function m(u){try{return JSON.parse(u)}catch(a){throw new Error(`快照不是合法 JSON:${a.message}`)}}exports.default=q;exports.parseSnapshot=m;
@@ -0,0 +1,136 @@
1
+ import { jsx as t, jsxs as n } from "react/jsx-runtime";
2
+ import { useState as s, useEffect as j } from "react";
3
+ import { useSearchParams as A } from "react-router-dom";
4
+ import { Alert as S, Spin as T, Card as C, Space as u, Select as x, Input as g, Button as _, Table as B, message as I, Tag as D } from "antd";
5
+ import { CheckCircleOutlined as F } from "@ant-design/icons";
6
+ import { o as h, f as p } from "./api-BVrIcAFp.js";
7
+ const { TextArea: J } = g, L = { ERROR: "red", WARNING: "orange", INFO: "blue" };
8
+ function q() {
9
+ const [c] = A(), a = c.get("id") || "", [o, b] = s("source"), [m, k] = s("default"), [i, y] = s(""), [f, O] = s(`{
10
+ "individuals": [],
11
+ "statements": []
12
+ }`), [R, w] = s([]), [r, d] = s(null), [$, v] = s(!1);
13
+ j(() => {
14
+ a && h.listSources().then(w).catch(() => w([]));
15
+ }, [a]);
16
+ const z = async () => {
17
+ v(!0), d(null);
18
+ try {
19
+ if (o === "source") {
20
+ if (!i.trim()) {
21
+ I.warning("按来源校验需要指定 source");
22
+ return;
23
+ }
24
+ d(await h.validateSource(a, i.trim(), m));
25
+ } else
26
+ d(await h.validate(a, P(f)));
27
+ } catch (e) {
28
+ I.error(e.message);
29
+ } finally {
30
+ v(!1);
31
+ }
32
+ }, E = [
33
+ { title: "级别", dataIndex: "severity", key: "severity", width: 90, render: (e) => /* @__PURE__ */ t(D, { color: L[e] || "default", children: e }) },
34
+ { title: "编码", dataIndex: "code", key: "code", width: 160 },
35
+ { title: "主体", dataIndex: "subject", key: "subject", width: 160 },
36
+ { title: "谓词", dataIndex: "predicate", key: "predicate", width: 140 },
37
+ { title: "说明", dataIndex: "message", key: "message" }
38
+ ];
39
+ if (!a)
40
+ return /* @__PURE__ */ t(S, { type: "warning", message: "缺少本体 ID(?id=xxx)" });
41
+ const l = (r == null ? void 0 : r.issues) || [];
42
+ return /* @__PURE__ */ n(T, { spinning: $, children: [
43
+ /* @__PURE__ */ t(C, { size: "small", style: { marginBottom: 16 }, children: /* @__PURE__ */ n(u, { direction: "vertical", style: { width: "100%" }, size: 12, children: [
44
+ /* @__PURE__ */ n(u, { wrap: !0, children: [
45
+ /* @__PURE__ */ t(
46
+ x,
47
+ {
48
+ style: { width: 180 },
49
+ value: o,
50
+ onChange: b,
51
+ options: [
52
+ { value: "source", label: "按来源校验" },
53
+ { value: "inline", label: "内联快照校验" }
54
+ ]
55
+ }
56
+ ),
57
+ /* @__PURE__ */ t(
58
+ g,
59
+ {
60
+ style: { width: 220 },
61
+ placeholder: "工作空间",
62
+ value: m,
63
+ onChange: (e) => k(e.target.value)
64
+ }
65
+ ),
66
+ o === "source" ? /* @__PURE__ */ t(
67
+ x,
68
+ {
69
+ style: { width: 280 },
70
+ placeholder: "选择或输入数据源",
71
+ value: i || void 0,
72
+ onChange: y,
73
+ showSearch: !0,
74
+ options: R.map((e) => ({ value: e.id, label: e.description ? `${e.id} — ${e.description}` : e.id })),
75
+ notFoundContent: null
76
+ }
77
+ ) : null,
78
+ /* @__PURE__ */ t(_, { type: "primary", icon: /* @__PURE__ */ t(F, {}), onClick: z, children: "执行校验" })
79
+ ] }),
80
+ o === "source" ? /* @__PURE__ */ t(
81
+ g,
82
+ {
83
+ style: { width: 420 },
84
+ placeholder: "source ID(可直接输入)",
85
+ value: i,
86
+ onChange: (e) => y(e.target.value)
87
+ }
88
+ ) : /* @__PURE__ */ t(
89
+ J,
90
+ {
91
+ rows: 10,
92
+ value: f,
93
+ onChange: (e) => O(e.target.value),
94
+ placeholder: '{"individuals": [], "statements": []}'
95
+ }
96
+ )
97
+ ] }) }),
98
+ r ? /* @__PURE__ */ n(C, { size: "small", title: `校验结果(${l.length} 条问题)`, children: [
99
+ /* @__PURE__ */ n(u, { size: "large", wrap: !0, style: { marginBottom: l.length ? 12 : 0 }, children: [
100
+ /* @__PURE__ */ n("span", { children: [
101
+ "错误 ",
102
+ /* @__PURE__ */ t("b", { children: p(r, "errorCount", "error_count") })
103
+ ] }),
104
+ /* @__PURE__ */ n("span", { children: [
105
+ "警告 ",
106
+ /* @__PURE__ */ t("b", { children: p(r, "warningCount", "warning_count") })
107
+ ] }),
108
+ /* @__PURE__ */ n("span", { children: [
109
+ "提示 ",
110
+ /* @__PURE__ */ t("b", { children: p(r, "infoCount", "info_count") })
111
+ ] })
112
+ ] }),
113
+ l.length === 0 ? /* @__PURE__ */ t(S, { type: "success", message: "校验通过,未发现问题" }) : /* @__PURE__ */ t(
114
+ B,
115
+ {
116
+ rowKey: (e, N) => `${e.code}-${N}`,
117
+ size: "small",
118
+ columns: E,
119
+ dataSource: l,
120
+ pagination: !1
121
+ }
122
+ )
123
+ ] }) : null
124
+ ] });
125
+ }
126
+ function P(c) {
127
+ try {
128
+ return JSON.parse(c);
129
+ } catch (a) {
130
+ throw new Error(`快照不是合法 JSON:${a.message}`);
131
+ }
132
+ }
133
+ export {
134
+ q as default,
135
+ P as parseSnapshot
136
+ };