react-kggraph 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.es3.js CHANGED
@@ -1,32 +1,31 @@
1
1
  import { jsx as y, jsxs as G } from "react/jsx-runtime";
2
2
  import { useRef as E, useState as m, useEffect as q } from "react";
3
3
  import x from "cytoscape";
4
- import ue from "cytoscape-cose-bilkent";
5
- import ye from "cytoscape-cise";
6
- import fe from "cytoscape-fcose";
7
- import me from "storm-layout";
8
- import he from "./index.es6.js";
4
+ import fe from "cytoscape-cose-bilkent";
5
+ import me from "cytoscape-cise";
6
+ import he from "cytoscape-fcose";
7
+ import ve from "storm-layout";
8
+ import be from "./index.es6.js";
9
9
  /* empty css */
10
- import { stepNext as ve } from "./index.es7.js";
11
- import { handleCalcPath as be, resDetailData as A } from "./index.es8.js";
12
- import { fixNodesToEdges as xe, coseBilkentLayout as ee } from "./index.es9.js";
13
- import { edgeNodeStyles as Ne } from "./index.es10.js";
14
- import ke from "cytoscape-layout-utilities";
10
+ import { handleCalcPath as xe, resDetailData as A } from "./index.es7.js";
11
+ import { fixNodesToEdges as Ne, coseBilkentLayout as ee } from "./index.es8.js";
12
+ import { edgeNodeStyles as ke } from "./index.es9.js";
13
+ import Ce from "cytoscape-layout-utilities";
15
14
  import { message as O } from "antd";
16
- import { menuItemsConfig as Ce } from "./index.es11.js";
17
- import { jsonStringify as w } from "./index.es12.js";
18
- import ze from "./index.es13.js";
19
- import Ee from "./index.es14.js";
20
- import { GraphProvider as we } from "./index.es15.js";
21
- import Le from "./index.es16.js";
22
- x.use(ke);
23
- x.use(ye);
24
- x.use(fe);
15
+ import { menuItemsConfig as ze } from "./index.es10.js";
16
+ import { jsonStringify as w } from "./index.es11.js";
17
+ import Ee from "./index.es12.js";
18
+ import we from "./index.es13.js";
19
+ import { GraphProvider as Le } from "./index.es14.js";
20
+ import Te from "./index.es15.js";
21
+ x.use(Ce);
25
22
  x.use(me);
26
- x.use(ue);
27
- const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N = [], graphInfo: f }) => {
23
+ x.use(he);
24
+ x.use(ve);
25
+ x.use(fe);
26
+ const Ze = ({ data: te, getAllGraphData: S, searchType: je, highPathAnalysis: N = [], graphInfo: f, stepNextApi: oe, knowledgeCardApi: ne }) => {
28
27
  var Y, Z;
29
- const L = E(null), [v, D] = m([]), p = E(null), F = E(null), H = 1, [je, K] = m(!1), [k, I] = m({}), [T, P] = m({}), [oe, ne] = m("cose-bilkent"), X = E(null), J = E(null), [se, Q] = m(["", ""]), [c, C] = m({
28
+ const L = E(null), [v, D] = m([]), p = E(null), F = E(null), H = 1, [Re, K] = m(!1), [k, I] = m({}), [T, P] = m({}), [se, de] = m("cose-bilkent"), X = E(null), J = E(null), [ae, Q] = m(["", ""]), [c, C] = m({
30
29
  visible: !1,
31
30
  x: 0,
32
31
  y: 0,
@@ -37,13 +36,13 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
37
36
  x: 0,
38
37
  y: 0,
39
38
  content: ""
40
- }), de = Ce({ cyRef: p, setContextMenu: C, onPathAnalysis: (Y = F.current) == null ? void 0 : Y.onPathAnalysis, setPathNodes: Q });
39
+ }), re = ze({ cyRef: p, setContextMenu: C, onPathAnalysis: (Y = F.current) == null ? void 0 : Y.onPathAnalysis, setPathNodes: Q });
41
40
  q(() => {
42
- (N == null ? void 0 : N.length) > 1 && be(p, { pathNodes: N, isGrayed: !1 });
41
+ (N == null ? void 0 : N.length) > 1 && xe(p, { pathNodes: N, isGrayed: !1 });
43
42
  }, [w(N), w(v)]), q(() => {
44
43
  S == null || S({ graphData: v, nodeStatic: k, relationStatic: T });
45
44
  }, [w(v), w(k), w(T)]), q(() => {
46
- var r;
45
+ var a;
47
46
  if (!L.current || p.current) return;
48
47
  const { elements: o, typeListObj: d, relationListObj: z } = A(te, { typeObj: k, graphInfo: f });
49
48
  I(d), D(o), P(z), document.addEventListener("contextmenu", function(t) {
@@ -52,7 +51,7 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
52
51
  const e = x({
53
52
  container: L.current,
54
53
  elements: o,
55
- style: Ne({ elements: o }),
54
+ style: ke({ elements: o }),
56
55
  autounselectify: !1,
57
56
  autolock: !1,
58
57
  layout: {
@@ -60,8 +59,8 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
60
59
  // 使用预设布局,完全依赖 position
61
60
  }
62
61
  });
63
- if (p.current = e, ((r = f == null ? void 0 : f.searchNodes) == null ? void 0 : r.length) === 2)
64
- xe(
62
+ if (p.current = e, ((a = f == null ? void 0 : f.searchNodes) == null ? void 0 : a.length) === 2)
63
+ Ne(
65
64
  e,
66
65
  f.searchNodes[0],
67
66
  f.searchNodes[1]
@@ -88,12 +87,12 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
88
87
  const s = t.target;
89
88
  s.hasClass("selected") || s.addClass("hover");
90
89
  }), e.on("mouseover", "node", (t) => {
91
- const s = t.target, n = s.renderedPosition(), a = s.data("name") || "";
90
+ const s = t.target, n = s.renderedPosition(), r = s.data("name") || "";
92
91
  s.addClass("hover"), V({
93
92
  visible: !0,
94
93
  x: n.x,
95
94
  y: n.y - 60,
96
- content: a
95
+ content: r
97
96
  });
98
97
  }), e.on("mouseout", "node", (t) => {
99
98
  t.target.removeClass("hover"), V((n) => ({ ...n, visible: !1 }));
@@ -110,27 +109,27 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
110
109
  }), p.current = e, e.on("click", "node", (t) => {
111
110
  const s = t.target;
112
111
  e.nodes().removeClass("selected grayed highlighted"), e.edges().removeClass("selected grayed highlighted"), s.addClass("selected");
113
- const a = s.neighborhood().nodes().add(s), b = a.edgesWith(a);
114
- console.log("cy.nodes().not(relatedNodes):::", a), e.nodes().not(a).addClass("grayed"), e.edges().not(b).addClass("grayed"), a.addClass("highlighted"), b.addClass("highlighted");
112
+ const r = s.neighborhood().nodes().add(s), b = r.edgesWith(r);
113
+ console.log("cy.nodes().not(relatedNodes):::", r), e.nodes().not(r).addClass("grayed"), e.edges().not(b).addClass("grayed"), r.addClass("highlighted"), b.addClass("highlighted");
115
114
  }), e.on("tap", (t) => {
116
115
  t.target === e && (C((s) => ({ ...s, visible: !1 })), e.nodes().removeClass("grayed highlighted highlight selected correlationStyle path-node level-highlight level-selected level-grayed"), e.edges().removeClass("grayed highlighted highlight selected correlationStyle path-edge level-highlightedge level-grayed"));
117
116
  }), () => {
118
117
  p.current && (p.current.destroy(), p.current = null);
119
118
  };
120
119
  }, []);
121
- const re = async (o) => {
120
+ const ie = async (o) => {
122
121
  const { id: d, kgId: z } = o, e = p.current;
123
122
  if (!e) return;
124
- const r = e.$(`#${d}`);
125
- if (!r || r.length === 0) {
123
+ const a = e.$(`#${d}`);
124
+ if (!a || a.length === 0) {
126
125
  console.error("当前节点不存在");
127
126
  return;
128
127
  }
129
128
  const t = e.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === d || n.data("idLabel") === `${d}-${n.data("name")}`) && n.data("zktype") === o.zktype : !1);
130
129
  if (t.length > 0) {
131
- const n = t.map((l) => l.id()), a = t.connectedEdges(), b = e.edges().filter(
130
+ const n = t.map((l) => l.id()), r = t.connectedEdges(), b = e.edges().filter(
132
131
  (l) => l.data("source") === d && n.includes(l.data("target"))
133
- ), R = e.edges().filter((l) => l.data("appendedBy") === d), B = a.merge(b).merge(R).filter((l) => l.data().zktype === o.zktype);
132
+ ), R = e.edges().filter((l) => l.data("appendedBy") === d), B = r.merge(b).merge(R).filter((l) => l.data().zktype === o.zktype);
134
133
  t.animate({
135
134
  style: { opacity: 0 }
136
135
  }, {
@@ -143,19 +142,19 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
143
142
  if (u.group === "nodes" && n.includes((h = u.data) == null ? void 0 : h.id) && i && i === o.zktype)
144
143
  return !1;
145
144
  if (u.group === "edges" && i && i === o.zktype) {
146
- const le = Array.from(R).map((ge) => {
147
- const U = ge.data();
145
+ const pe = Array.from(R).map((ye) => {
146
+ const U = ye.data();
148
147
  return `${U.source}-${U.target}-${U.label}`;
149
- }), M = u.data, ce = le.includes(`${M.source}-${M.target}-${M.label}`), pe = ((_ = u.data) == null ? void 0 : _.appendedBy) === d;
150
- return !ce && !pe;
148
+ }), M = u.data, ge = pe.includes(`${M.source}-${M.target}-${M.label}`), ue = ((_ = u.data) == null ? void 0 : _.appendedBy) === d;
149
+ return !ge && !ue;
151
150
  }
152
151
  return !0;
153
152
  }), { typeListObj: g, relationListObj: W } = A({}, { graphData: $, typeObj: {} });
154
153
  return I(g), P(W), $;
155
- }), r.data("appendedNodes", []), r.data("isExpanded", !1);
154
+ }), a.data("appendedNodes", []), a.data("isExpanded", !1);
156
155
  }
157
156
  }), setTimeout(() => {
158
- r.removed() || (r.style("border-width", ""), r.style("border-color", ""));
157
+ a.removed() || (a.style("border-width", ""), a.style("border-color", ""));
159
158
  }, 300);
160
159
  } else {
161
160
  try {
@@ -164,21 +163,21 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
164
163
  content: "正在展开...",
165
164
  duration: 0
166
165
  });
167
- const n = await ve({ uri: d, queryType: 1, kgId: z, zktype: o.zktype }), { elements: a, typeListObj: b, relationListObj: R } = A(n.data, { graphData: v, typeObj: k, relationObj: T, zktype: o.zktype });
168
- if (I(b), P(R), console.log(555e3, a), !((a == null ? void 0 : a.length) > 0)) {
166
+ const n = await oe({ uri: d, queryType: 1, kgId: z, zktype: o.zktype }), { elements: r, typeListObj: b, relationListObj: R } = A(n.data, { graphData: v, typeObj: k, relationObj: T, zktype: o.zktype });
167
+ if (I(b), P(R), console.log(555e3, r), !((r == null ? void 0 : r.length) > 0)) {
169
168
  O.warning("暂无数据"), setTimeout(() => {
170
169
  O.destroy();
171
170
  }, 2e3);
172
171
  return;
173
172
  }
174
- if ((a == null ? void 0 : a.length) > 0) {
173
+ if ((r == null ? void 0 : r.length) > 0) {
175
174
  const B = e.layoutUtilities({
176
175
  ...ee(),
177
176
  idealEdgeLength: 80,
178
177
  // 与你的期望边长匹配
179
178
  offset: 30
180
179
  // 随机偏移,避免完全重叠
181
- }), l = a.map((i) => {
180
+ }), l = r.map((i) => {
182
181
  if (i.group === "nodes") {
183
182
  const h = 80 * H;
184
183
  return {
@@ -214,7 +213,7 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
214
213
  }), $ = e.add(l);
215
214
  D([...v, ...l]);
216
215
  const g = $.filter(":node"), W = g.map((i) => i.id());
217
- r.data("appendedNodes", W), r.data("isExpanded", !0);
216
+ a.data("appendedNodes", W), a.data("isExpanded", !0);
218
217
  const u = e.nodes().difference(g);
219
218
  u.forEach((i) => i.lock()), B.placeNewNodes(g), e.layout({
220
219
  name: "cose-bilkent",
@@ -246,7 +245,7 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
246
245
  g.style("opacity", ""), g.style("width", ""), g.style("height", "");
247
246
  }
248
247
  }), setTimeout(() => {
249
- r.removed() || (r.style("border-width", ""), r.style("border-color", ""), e.center(r), e.zoom(e.zoom()));
248
+ a.removed() || (a.style("border-width", ""), a.style("border-color", ""), e.center(a), e.zoom(e.zoom()));
250
249
  }, 600);
251
250
  } else
252
251
  console.log("没有找到相关节点数据");
@@ -256,16 +255,16 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
256
255
  K(!1), O.destroy();
257
256
  }
258
257
  C({ visible: !1 });
259
- }, ae = {
258
+ }, le = {
260
259
  expanded: "typed-literal",
261
260
  contract: "uri"
262
- }, ie = (o) => {
261
+ }, ce = (o) => {
263
262
  if (console.log("handleMenuAction:::", o), c.targetNode) {
264
263
  const d = o.ids, z = c.targetNode.data();
265
264
  if (["expanded", "contract"].includes(d))
266
- re({ kgId: 3, ...z, zktype: ae[d] });
265
+ ie({ kgId: 3, ...z, zktype: le[d] });
267
266
  else if (d === "nodeInfo") {
268
- const e = c.targetNode, r = {
267
+ const e = c.targetNode, a = {
269
268
  id: e.id(),
270
269
  data: e.data(),
271
270
  position: e.position(),
@@ -276,7 +275,7 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
276
275
  // 样式信息
277
276
  style: e.style()
278
277
  };
279
- X.current.open(r);
278
+ X.current.open(a);
280
279
  } else if (d === "knowledgeCard") {
281
280
  const e = c.targetNode;
282
281
  J.current.open(e.data());
@@ -284,10 +283,10 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
284
283
  o.action(c.targetNode), C({ visible: !1, x: 0, y: 0, targetNode: null });
285
284
  }
286
285
  };
287
- return /* @__PURE__ */ y(we, { value: { pathNodes: se, setPathNodes: Q, graphInfo: f, graphData: v, layoutType: oe, setLayoutType: ne }, children: /* @__PURE__ */ G("div", { className: "cytoscape-container", style: { position: "relative" }, children: [
286
+ return /* @__PURE__ */ y(Le, { value: { pathNodes: ae, setPathNodes: Q, graphInfo: f, graphData: v, layoutType: se, setLayoutType: de, knowledgeCardApi: ne }, children: /* @__PURE__ */ G("div", { className: "cytoscape-container", style: { position: "relative" }, children: [
288
287
  /* @__PURE__ */ y("div", { className: "btn-group" }),
289
288
  /* @__PURE__ */ y(
290
- he,
289
+ be,
291
290
  {
292
291
  ref: F,
293
292
  cyRef: p,
@@ -320,7 +319,7 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
320
319
  overflow: "hidden"
321
320
  },
322
321
  onClick: (o) => o.stopPropagation(),
323
- children: /* @__PURE__ */ y(ze, { items: de, centerImage: (Z = c == null ? void 0 : c.targetNode) == null ? void 0 : Z.data().image, onClick: (o) => ie(o) })
322
+ children: /* @__PURE__ */ y(Ee, { items: re, centerImage: (Z = c == null ? void 0 : c.targetNode) == null ? void 0 : Z.data().image, onClick: (o) => ce(o) })
324
323
  }
325
324
  ),
326
325
  j.visible && /* @__PURE__ */ y(
@@ -347,8 +346,8 @@ const Ze = ({ data: te, getAllGraphData: S, searchType: Te, highPathAnalysis: N
347
346
  }
348
347
  )
349
348
  ] }),
350
- /* @__PURE__ */ y(Ee, { ref: X }),
351
- /* @__PURE__ */ y(Le, { ref: J })
349
+ /* @__PURE__ */ y(we, { ref: X }),
350
+ /* @__PURE__ */ y(Te, { ref: J })
352
351
  ] }) });
353
352
  };
354
353
  export {