react-kggraph 0.0.20 → 0.0.22

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.
Files changed (2) hide show
  1. package/lib/index.es3.js +100 -100
  2. package/package.json +1 -1
package/lib/index.es3.js CHANGED
@@ -1,72 +1,72 @@
1
- import { jsx as c, jsxs as te } from "react/jsx-runtime";
2
- import { useRef as N, useState as h, useEffect as S } from "react";
1
+ import { jsx as m, jsxs as oe } from "react/jsx-runtime";
2
+ import { useRef as N, useState as v, useEffect as S } from "react";
3
3
  import k from "cytoscape";
4
4
  import Ne from "cytoscape-cose-bilkent";
5
5
  import Ce from "cytoscape-cise";
6
6
  import ke from "cytoscape-fcose";
7
- import Ee from "storm-layout";
8
- import ze from "./index.es7.js";
7
+ import ze from "storm-layout";
8
+ import Ee from "./index.es7.js";
9
9
  /* empty css */
10
10
  import { handleCalcPath as we, resDetailData as F } from "./index.es8.js";
11
- import { fixNodesToEdges as Le, coseBilkentLayout as oe } from "./index.es9.js";
12
- import { edgeNodeStyles as Re, defaultColors as ne } from "./index.es10.js";
11
+ import { fixNodesToEdges as Le, coseBilkentLayout as ne } from "./index.es9.js";
12
+ import { edgeNodeStyles as Re, defaultColors as se } from "./index.es10.js";
13
13
  import je from "cytoscape-layout-utilities";
14
- import { Row as Te, Empty as $e, message as C } from "antd";
15
- import { menuItemsConfig as De } from "./index.es11.js";
14
+ import { message as C } from "antd";
15
+ import { menuItemsConfig as Te } from "./index.es11.js";
16
16
  import { jsonStringify as R } from "./index.es12.js";
17
- import Oe from "./index.es13.js";
18
- import Se from "./index.es14.js";
19
- import { GraphProvider as Ie } from "./index.es15.js";
20
- import Pe from "./index.es16.js";
17
+ import $e from "./index.es13.js";
18
+ import De from "./index.es14.js";
19
+ import { GraphProvider as Oe } from "./index.es15.js";
20
+ import Se from "./index.es16.js";
21
21
  k.use(je);
22
22
  k.use(Ce);
23
23
  k.use(ke);
24
- k.use(Ee);
24
+ k.use(ze);
25
25
  k.use(Ne);
26
- const rt = ({
27
- data: re,
26
+ const nt = ({
27
+ data: de,
28
28
  getAllGraphData: I,
29
- highPathAnalysis: E = [],
30
- graphInfo: m,
31
- stepNextApi: se,
32
- knowledgeCardApi: de,
33
- colors: z,
34
- actionBar: ae,
35
- actionCircle: ie,
36
- noDataDesc: le = "暂无数据"
29
+ highPathAnalysis: z = [],
30
+ graphInfo: h,
31
+ stepNextApi: re,
32
+ knowledgeCardApi: ae,
33
+ colors: E,
34
+ actionBar: ie,
35
+ actionCircle: le,
36
+ noDataDesc: Ie = "暂无数据"
37
37
  }) => {
38
- var _, G;
39
- const j = N(null), [v, P] = h([]), p = N(null), K = N(null), X = 1, [Be, J] = h(!1), [w, B] = h({}), [T, W] = h({}), [ce, pe] = h("cose-bilkent"), Q = N(null), V = N(null), [ue, Y] = h(["", ""]), H = N(z);
38
+ var _, G, ee;
39
+ const j = N(null), [c, P] = v([]), p = N(null), K = N(null), X = 1, [Pe, J] = v(!1), [w, B] = v({}), [T, W] = v({}), [ce, pe] = v("cose-bilkent"), Q = N(null), V = N(null), [ue, Y] = v(["", ""]), H = N(E);
40
40
  S(() => {
41
- H.current = z;
42
- }, [z]);
43
- const [u, L] = h({
41
+ H.current = E;
42
+ }, [E]);
43
+ const [u, L] = v({
44
44
  visible: !1,
45
45
  x: 0,
46
46
  y: 0,
47
47
  targetNode: null,
48
48
  bgColor: ""
49
- }), [$, Z] = h({
49
+ }), [$, Z] = v({
50
50
  visible: !1,
51
51
  x: 0,
52
52
  y: 0,
53
53
  content: ""
54
- }), ge = De({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: ie });
54
+ }), ge = Te({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: le });
55
55
  S(() => {
56
- (E == null ? void 0 : E.length) > 1 && we(p, { pathNodes: E, isGrayed: !1 });
57
- }, [R(E), R(v)]), S(() => {
58
- I == null || I({ graphData: v, nodeStatic: w, relationStatic: T });
59
- }, [R(v), R(w), R(T)]), S(() => {
60
- var d;
56
+ (z == null ? void 0 : z.length) > 1 && we(p, { pathNodes: z, isGrayed: !1 });
57
+ }, [R(z), R(c)]), S(() => {
58
+ I == null || I({ graphData: c, nodeStatic: w, relationStatic: T });
59
+ }, [R(c), R(w), R(T)]), S(() => {
60
+ var r;
61
61
  if (!j.current || p.current) return;
62
- const { elements: r, typeListObj: a, relationListObj: g } = F(re, { typeObj: w, graphInfo: m });
63
- B(a), P(r), W(g), document.addEventListener("contextmenu", function(t) {
62
+ const { elements: s, typeListObj: a, relationListObj: g } = F(de, { typeObj: w, graphInfo: h });
63
+ B(a), P(s), W(g), document.addEventListener("contextmenu", function(t) {
64
64
  t.preventDefault();
65
65
  });
66
66
  const e = k({
67
67
  container: j.current,
68
- elements: r,
69
- style: Re({ elements: r, colors: z }),
68
+ elements: s,
69
+ style: Re({ elements: s, colors: E }),
70
70
  autounselectify: !1,
71
71
  autolock: !1,
72
72
  layout: {
@@ -74,14 +74,14 @@ const rt = ({
74
74
  // 使用预设布局,完全依赖 position
75
75
  }
76
76
  });
77
- if (p.current = e, ((d = m == null ? void 0 : m.searchNodes) == null ? void 0 : d.length) === 2)
77
+ if (p.current = e, ((r = h == null ? void 0 : h.searchNodes) == null ? void 0 : r.length) === 2)
78
78
  Le(
79
79
  e,
80
- m.searchNodes[0],
81
- m.searchNodes[1]
80
+ h.searchNodes[0],
81
+ h.searchNodes[1]
82
82
  );
83
83
  else {
84
- const t = e.layout(oe());
84
+ const t = e.layout(ne());
85
85
  t.run(), t.on("layoutstop", () => {
86
86
  e.fit(void 0, 50), e.center();
87
87
  });
@@ -90,10 +90,10 @@ const rt = ({
90
90
  var n;
91
91
  const o = t.target;
92
92
  if (!o.hasClass("path-edge")) {
93
- const s = ((n = H.current) == null ? void 0 : n.edgeHoverColor) ?? ne.edgeHoverColor;
93
+ const d = ((n = H.current) == null ? void 0 : n.edgeHoverColor) ?? se.edgeHoverColor;
94
94
  o.style({
95
- "line-color": s,
96
- "target-arrow-color": s,
95
+ "line-color": d,
96
+ "target-arrow-color": d,
97
97
  opacity: 0.8
98
98
  });
99
99
  }
@@ -101,10 +101,10 @@ const rt = ({
101
101
  var n;
102
102
  const o = t.target;
103
103
  if (!o.hasClass("path-edge")) {
104
- const s = ((n = H.current) == null ? void 0 : n.edgeDefaultColor) ?? ne.edgeDefaultColor;
104
+ const d = ((n = H.current) == null ? void 0 : n.edgeDefaultColor) ?? se.edgeDefaultColor;
105
105
  o.style({
106
- "line-color": s,
107
- "target-arrow-color": s,
106
+ "line-color": d,
107
+ "target-arrow-color": d,
108
108
  opacity: 1
109
109
  });
110
110
  }
@@ -112,12 +112,12 @@ const rt = ({
112
112
  const o = t.target;
113
113
  o.hasClass("selected") || o.addClass("hover");
114
114
  }), e.on("mouseover", "node", (t) => {
115
- const o = t.target, n = o.renderedPosition(), s = o.data("name") || "";
115
+ const o = t.target, n = o.renderedPosition(), d = o.data("name") || "";
116
116
  o.addClass("hover"), Z({
117
117
  visible: !0,
118
118
  x: n.x,
119
119
  y: n.y - 60,
120
- content: s
120
+ content: d
121
121
  });
122
122
  }), e.on("mouseout", "node", (t) => {
123
123
  t.target.removeClass("hover"), Z((n) => ({ ...n, visible: !1 }));
@@ -134,27 +134,27 @@ const rt = ({
134
134
  }), p.current = e, e.on("click", "node", (t) => {
135
135
  const o = t.target;
136
136
  e.nodes().removeClass("selected grayed highlighted"), e.edges().removeClass("selected grayed highlighted"), o.addClass("selected");
137
- const s = o.neighborhood().nodes().add(o), x = s.edgesWith(s);
138
- console.log("cy.nodes().not(relatedNodes):::", s), e.nodes().not(s).addClass("grayed"), e.edges().not(x).addClass("grayed"), s.addClass("highlighted"), x.addClass("highlighted");
137
+ const d = o.neighborhood().nodes().add(o), x = d.edgesWith(d);
138
+ console.log("cy.nodes().not(relatedNodes):::", d), e.nodes().not(d).addClass("grayed"), e.edges().not(x).addClass("grayed"), d.addClass("highlighted"), x.addClass("highlighted");
139
139
  }), e.on("tap", (t) => {
140
140
  t.target === e && (L((o) => ({ ...o, 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"));
141
141
  }), () => {
142
142
  p.current && (p.current.destroy(), p.current = null);
143
143
  };
144
144
  }, []);
145
- const ye = async (r) => {
146
- const { id: a, kgId: g } = r, e = p.current;
145
+ const ye = async (s) => {
146
+ const { id: a, kgId: g } = s, e = p.current;
147
147
  if (!e) return;
148
- const d = e.$(`#${a}`);
149
- if (!d || d.length === 0) {
148
+ const r = e.$(`#${a}`);
149
+ if (!r || r.length === 0) {
150
150
  console.error("当前节点不存在");
151
151
  return;
152
152
  }
153
- const t = e.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === a || n.data("idLabel") === `${a}-${n.data("name")}`) && n.data("zktype") === r.zktype : !1);
153
+ const t = e.nodes().filter((n) => n.data("parentId") ? (n.data("parentId") === a || n.data("idLabel") === `${a}-${n.data("name")}`) && n.data("zktype") === s.zktype : !1);
154
154
  if (t.length > 0) {
155
- const n = t.map((l) => l.id()), s = t.connectedEdges(), x = e.edges().filter(
155
+ const n = t.map((l) => l.id()), d = t.connectedEdges(), x = e.edges().filter(
156
156
  (l) => l.data("source") === a && n.includes(l.data("target"))
157
- ), D = e.edges().filter((l) => l.data("appendedBy") === a), M = s.merge(x).merge(D).filter((l) => l.data().zktype === r.zktype);
157
+ ), D = e.edges().filter((l) => l.data("appendedBy") === a), M = d.merge(x).merge(D).filter((l) => l.data().zktype === s.zktype);
158
158
  t.animate({
159
159
  style: { opacity: 0 }
160
160
  }, {
@@ -162,24 +162,24 @@ const rt = ({
162
162
  complete: () => {
163
163
  e.remove(t), e.remove(M), P((l) => {
164
164
  const O = l.filter((f) => {
165
- var b, ee;
165
+ var b, te;
166
166
  const i = f.data.zktype;
167
- if (f.group === "nodes" && n.includes((b = f.data) == null ? void 0 : b.id) && i && i === r.zktype)
167
+ if (f.group === "nodes" && n.includes((b = f.data) == null ? void 0 : b.id) && i && i === s.zktype)
168
168
  return !1;
169
- if (f.group === "edges" && i && i === r.zktype) {
169
+ if (f.group === "edges" && i && i === s.zktype) {
170
170
  const he = Array.from(D).map((xe) => {
171
171
  const A = xe.data();
172
172
  return `${A.source}-${A.target}-${A.label}`;
173
- }), q = f.data, ve = he.includes(`${q.source}-${q.target}-${q.label}`), be = ((ee = f.data) == null ? void 0 : ee.appendedBy) === a;
173
+ }), q = f.data, ve = he.includes(`${q.source}-${q.target}-${q.label}`), be = ((te = f.data) == null ? void 0 : te.appendedBy) === a;
174
174
  return !ve && !be;
175
175
  }
176
176
  return !0;
177
177
  }), { typeListObj: y, relationListObj: U } = F({}, { graphData: O, typeObj: {} });
178
178
  return B(y), W(U), O;
179
- }), d.data("appendedNodes", []), d.data("isExpanded", !1);
179
+ }), r.data("appendedNodes", []), r.data("isExpanded", !1);
180
180
  }
181
181
  }), setTimeout(() => {
182
- d.removed() || (d.style("border-width", ""), d.style("border-color", ""));
182
+ r.removed() || (r.style("border-width", ""), r.style("border-color", ""));
183
183
  }, 300);
184
184
  } else {
185
185
  try {
@@ -188,21 +188,21 @@ const rt = ({
188
188
  content: "正在展开...",
189
189
  duration: 0
190
190
  });
191
- const n = await se({ uri: a, queryType: 1, kgId: g, zktype: r.zktype }), { elements: s, typeListObj: x, relationListObj: D } = F(n.data, { graphData: v, typeObj: w, relationObj: T, zktype: r.zktype });
192
- if (B(x), W(D), !((s == null ? void 0 : s.length) > 0)) {
191
+ const n = await re({ uri: a, queryType: 1, kgId: g, zktype: s.zktype }), { elements: d, typeListObj: x, relationListObj: D } = F(n.data, { graphData: c, typeObj: w, relationObj: T, zktype: s.zktype });
192
+ if (B(x), W(D), !((d == null ? void 0 : d.length) > 0)) {
193
193
  setTimeout(() => {
194
194
  C.destroy(), C.warning("暂无数据");
195
195
  }, 2e3);
196
196
  return;
197
197
  }
198
- if ((s == null ? void 0 : s.length) > 0) {
198
+ if ((d == null ? void 0 : d.length) > 0) {
199
199
  const M = e.layoutUtilities({
200
- ...oe(),
200
+ ...ne(),
201
201
  idealEdgeLength: 80,
202
202
  // 与你的期望边长匹配
203
203
  offset: 30
204
204
  // 随机偏移,避免完全重叠
205
- }), l = s.map((i) => {
205
+ }), l = d.map((i) => {
206
206
  if (i.group === "nodes") {
207
207
  const b = 80 * X;
208
208
  return {
@@ -219,7 +219,7 @@ const rt = ({
219
219
  appendedBy: a,
220
220
  // 标记由谁追加
221
221
  idLabel: a + "-" + i.data.label,
222
- zktype: r.zktype,
222
+ zktype: s.zktype,
223
223
  isAppended: !0,
224
224
  // 标记是追加节点
225
225
  baseWidth: b,
@@ -232,13 +232,13 @@ const rt = ({
232
232
  data: {
233
233
  ...i.data,
234
234
  appendedBy: a,
235
- zktype: r.zktype
235
+ zktype: s.zktype
236
236
  }
237
237
  };
238
238
  }), O = e.add(l);
239
- P([...v, ...l]);
239
+ P([...c, ...l]);
240
240
  const y = O.filter(":node"), U = y.map((i) => i.id());
241
- d.data("appendedNodes", U), d.data("isExpanded", !0);
241
+ r.data("appendedNodes", U), r.data("isExpanded", !0);
242
242
  const f = e.nodes().difference(y);
243
243
  f.forEach((i) => i.lock()), M.placeNewNodes(y), e.layout({
244
244
  name: "cose-bilkent",
@@ -270,7 +270,7 @@ const rt = ({
270
270
  y.style("opacity", ""), y.style("width", ""), y.style("height", "");
271
271
  }
272
272
  }), setTimeout(() => {
273
- d.removed() || (d.style("border-width", ""), d.style("border-color", ""), e.center(d), e.zoom(e.zoom()));
273
+ r.removed() || (r.style("border-width", ""), r.style("border-color", ""), e.center(r), e.zoom(e.zoom()));
274
274
  }, 600);
275
275
  } else
276
276
  console.log("没有找到相关节点数据");
@@ -284,15 +284,15 @@ const rt = ({
284
284
  }, fe = {
285
285
  expanded: "typed-literal",
286
286
  contract: "uri"
287
- }, me = (r, a) => {
287
+ }, me = (s, a) => {
288
288
  var e;
289
- console.log("handleMenuAction:::", r, a);
289
+ console.log("handleMenuAction:::", s, a);
290
290
  const g = a || u.targetNode;
291
291
  if (g) {
292
- const d = r.ids, t = g.data();
293
- if (["expanded", "contract"].includes(d))
294
- ye({ kgId: 3, ...t, zktype: fe[d] });
295
- else if (d === "nodeInfo") {
292
+ const r = s.ids, t = g.data();
293
+ if (["expanded", "contract"].includes(r))
294
+ ye({ kgId: 3, ...t, zktype: fe[r] });
295
+ else if (r === "nodeInfo") {
296
296
  const o = g, n = {
297
297
  id: o.id(),
298
298
  data: o.data(),
@@ -304,29 +304,29 @@ const rt = ({
304
304
  style: o.style()
305
305
  };
306
306
  Q.current.open(n);
307
- } else d === "knowledgeCard" && V.current.open(g.data());
308
- (e = r.onClick) == null || e.call(r, g), L({ visible: !1, x: 0, y: 0, targetNode: null });
307
+ } else r === "knowledgeCard" && V.current.open(g.data());
308
+ (e = s.onClick) == null || e.call(s, g), L({ visible: !1, x: 0, y: 0, targetNode: null });
309
309
  }
310
310
  };
311
- return v.length < 1 ? /* @__PURE__ */ c(Te, { className: "h-100", align: "middle", justify: "center", children: /* @__PURE__ */ c($e, { description: le }) }) : /* @__PURE__ */ c(Ie, { value: { pathNodes: ue, setPathNodes: Y, graphInfo: m, graphData: v, layoutType: ce, setLayoutType: pe, knowledgeCardApi: de }, children: /* @__PURE__ */ te("div", { className: "cytoscape-container relative", children: [
312
- /* @__PURE__ */ c("div", { className: "btn-group" }),
313
- /* @__PURE__ */ c(
314
- ze,
311
+ return console.log(111, !(((G = c == null ? void 0 : c.nodes) == null ? void 0 : G.length) > 0), c), /* @__PURE__ */ m(Oe, { value: { pathNodes: ue, setPathNodes: Y, graphInfo: h, graphData: c, layoutType: ce, setLayoutType: pe, knowledgeCardApi: ae }, children: /* @__PURE__ */ oe("div", { className: "cytoscape-container relative", children: [
312
+ /* @__PURE__ */ m("div", { className: "btn-group" }),
313
+ /* @__PURE__ */ m(
314
+ Ee,
315
315
  {
316
316
  ref: K,
317
317
  cyRef: p,
318
- graphInfo: m,
318
+ graphInfo: h,
319
319
  initNodeScale: X,
320
320
  cyContainerRef: j,
321
321
  typeObj: w,
322
322
  relationObj: T,
323
- colors: z,
324
- actionBar: ae
323
+ colors: E,
324
+ actionBar: ie
325
325
  }
326
326
  ),
327
- /* @__PURE__ */ te("div", { className: "relative h-100", children: [
328
- /* @__PURE__ */ c("div", { ref: j, className: "cy-container" }),
329
- u.visible && u.targetNode && /* @__PURE__ */ c(
327
+ /* @__PURE__ */ oe("div", { className: "relative h-100", children: [
328
+ /* @__PURE__ */ m("div", { ref: j, className: "cy-container" }),
329
+ u.visible && u.targetNode && /* @__PURE__ */ m(
330
330
  "div",
331
331
  {
332
332
  style: {
@@ -345,11 +345,11 @@ const rt = ({
345
345
  height: "200px",
346
346
  overflow: "hidden"
347
347
  },
348
- onClick: (r) => r.stopPropagation(),
349
- children: /* @__PURE__ */ c(Oe, { items: ge, centerImage: (G = u == null ? void 0 : u.targetNode) == null ? void 0 : G.data().image, targetNode: u.targetNode, onClick: (r, a) => me(r, a) })
348
+ onClick: (s) => s.stopPropagation(),
349
+ children: /* @__PURE__ */ m($e, { items: ge, centerImage: (ee = u == null ? void 0 : u.targetNode) == null ? void 0 : ee.data().image, targetNode: u.targetNode, onClick: (s, a) => me(s, a) })
350
350
  }
351
351
  ),
352
- $.visible && /* @__PURE__ */ c(
352
+ $.visible && /* @__PURE__ */ m(
353
353
  "div",
354
354
  {
355
355
  style: {
@@ -373,10 +373,10 @@ const rt = ({
373
373
  }
374
374
  )
375
375
  ] }),
376
- /* @__PURE__ */ c(Se, { ref: Q }),
377
- /* @__PURE__ */ c(Pe, { ref: V })
376
+ /* @__PURE__ */ m(De, { ref: Q }),
377
+ /* @__PURE__ */ m(Se, { ref: V })
378
378
  ] }) });
379
379
  };
380
380
  export {
381
- rt as default
381
+ nt as default
382
382
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-kggraph",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "A knowledge graph visualization component based on Cytoscape",
5
5
  "type": "module",
6
6
  "main": "./lib/index.es.js",