react-kggraph 0.0.21 → 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 +85 -85
  2. package/package.json +1 -1
package/lib/index.es3.js CHANGED
@@ -1,46 +1,46 @@
1
- import { jsx as c, jsxs as oe } from "react/jsx-runtime";
2
- import { useRef as N, useState as v, useEffect as D } 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
- import Ce from "cytoscape-cose-bilkent";
5
- import ke from "cytoscape-cise";
6
- import Ee from "cytoscape-fcose";
4
+ import Ne from "cytoscape-cose-bilkent";
5
+ import Ce from "cytoscape-cise";
6
+ import ke from "cytoscape-fcose";
7
7
  import ze from "storm-layout";
8
- import we from "./index.es7.js";
8
+ import Ee from "./index.es7.js";
9
9
  /* empty css */
10
- import { handleCalcPath as Le, resDetailData as F } from "./index.es8.js";
11
- import { fixNodesToEdges as Re, coseBilkentLayout as ne } from "./index.es9.js";
12
- import { edgeNodeStyles as je, defaultColors as se } from "./index.es10.js";
13
- import Te from "cytoscape-layout-utilities";
14
- import { Row as $e, Empty as Oe, message as C } from "antd";
15
- import { menuItemsConfig as Se } from "./index.es11.js";
10
+ import { handleCalcPath as we, resDetailData as F } from "./index.es8.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
+ import je from "cytoscape-layout-utilities";
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 De from "./index.es13.js";
18
- import Ie from "./index.es14.js";
19
- import { GraphProvider as Pe } from "./index.es15.js";
20
- import Be from "./index.es16.js";
21
- k.use(Te);
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
+ k.use(je);
22
+ k.use(Ce);
22
23
  k.use(ke);
23
- k.use(Ee);
24
24
  k.use(ze);
25
- k.use(Ce);
26
- const dt = ({
25
+ k.use(Ne);
26
+ const nt = ({
27
27
  data: de,
28
28
  getAllGraphData: I,
29
- highPathAnalysis: E = [],
29
+ highPathAnalysis: z = [],
30
30
  graphInfo: h,
31
31
  stepNextApi: re,
32
32
  knowledgeCardApi: ae,
33
- colors: z,
33
+ colors: E,
34
34
  actionBar: ie,
35
35
  actionCircle: le,
36
- noDataDesc: ce = "暂无数据"
36
+ noDataDesc: Ie = "暂无数据"
37
37
  }) => {
38
38
  var _, G, ee;
39
- const j = N(null), [u, P] = v([]), p = N(null), K = N(null), X = 1, [We, J] = v(!1), [w, B] = v({}), [T, W] = v({}), [pe, ue] = v("cose-bilkent"), Q = N(null), V = N(null), [ge, Y] = v(["", ""]), H = N(z);
40
- D(() => {
41
- H.current = z;
42
- }, [z]);
43
- const [g, L] = v({
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
+ S(() => {
41
+ H.current = E;
42
+ }, [E]);
43
+ const [u, L] = v({
44
44
  visible: !1,
45
45
  x: 0,
46
46
  y: 0,
@@ -51,22 +51,22 @@ const dt = ({
51
51
  x: 0,
52
52
  y: 0,
53
53
  content: ""
54
- }), ye = Se({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: le });
55
- D(() => {
56
- (E == null ? void 0 : E.length) > 1 && Le(p, { pathNodes: E, isGrayed: !1 });
57
- }, [R(E), R(u)]), D(() => {
58
- I == null || I({ graphData: u, nodeStatic: w, relationStatic: T });
59
- }, [R(u), R(w), R(T)]), D(() => {
54
+ }), ge = Te({ cyRef: p, setContextMenu: L, onPathAnalysis: (_ = K.current) == null ? void 0 : _.onPathAnalysis, setPathNodes: Y, actionCircle: le });
55
+ S(() => {
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
60
  var r;
61
61
  if (!j.current || p.current) return;
62
- const { elements: s, typeListObj: a, relationListObj: y } = F(de, { typeObj: w, graphInfo: h });
63
- B(a), P(s), W(y), 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
68
  elements: s,
69
- style: je({ elements: s, colors: z }),
69
+ style: Re({ elements: s, colors: E }),
70
70
  autounselectify: !1,
71
71
  autolock: !1,
72
72
  layout: {
@@ -75,7 +75,7 @@ const dt = ({
75
75
  }
76
76
  });
77
77
  if (p.current = e, ((r = h == null ? void 0 : h.searchNodes) == null ? void 0 : r.length) === 2)
78
- Re(
78
+ Le(
79
79
  e,
80
80
  h.searchNodes[0],
81
81
  h.searchNodes[1]
@@ -142,8 +142,8 @@ const dt = ({
142
142
  p.current && (p.current.destroy(), p.current = null);
143
143
  };
144
144
  }, []);
145
- const fe = async (s) => {
146
- const { id: a, kgId: y } = s, e = p.current;
145
+ const ye = async (s) => {
146
+ const { id: a, kgId: g } = s, e = p.current;
147
147
  if (!e) return;
148
148
  const r = e.$(`#${a}`);
149
149
  if (!r || r.length === 0) {
@@ -154,28 +154,28 @@ const dt = ({
154
154
  if (t.length > 0) {
155
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
- ), O = e.edges().filter((l) => l.data("appendedBy") === a), M = d.merge(x).merge(O).filter((l) => l.data().zktype === s.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
  }, {
161
161
  duration: 200,
162
162
  complete: () => {
163
163
  e.remove(t), e.remove(M), P((l) => {
164
- const S = l.filter((m) => {
164
+ const O = l.filter((f) => {
165
165
  var b, te;
166
- const i = m.data.zktype;
167
- if (m.group === "nodes" && n.includes((b = m.data) == null ? void 0 : b.id) && i && i === s.zktype)
166
+ const i = f.data.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 (m.group === "edges" && i && i === s.zktype) {
170
- const ve = Array.from(O).map((Ne) => {
171
- const A = Ne.data();
169
+ if (f.group === "edges" && i && i === s.zktype) {
170
+ const he = Array.from(D).map((xe) => {
171
+ const A = xe.data();
172
172
  return `${A.source}-${A.target}-${A.label}`;
173
- }), q = m.data, be = ve.includes(`${q.source}-${q.target}-${q.label}`), xe = ((te = m.data) == null ? void 0 : te.appendedBy) === a;
174
- return !be && !xe;
173
+ }), q = f.data, ve = he.includes(`${q.source}-${q.target}-${q.label}`), be = ((te = f.data) == null ? void 0 : te.appendedBy) === a;
174
+ return !ve && !be;
175
175
  }
176
176
  return !0;
177
- }), { typeListObj: f, relationListObj: U } = F({}, { graphData: S, typeObj: {} });
178
- return B(f), W(U), S;
177
+ }), { typeListObj: y, relationListObj: U } = F({}, { graphData: O, typeObj: {} });
178
+ return B(y), W(U), O;
179
179
  }), r.data("appendedNodes", []), r.data("isExpanded", !1);
180
180
  }
181
181
  }), setTimeout(() => {
@@ -188,8 +188,8 @@ const dt = ({
188
188
  content: "正在展开...",
189
189
  duration: 0
190
190
  });
191
- const n = await re({ uri: a, queryType: 1, kgId: y, zktype: s.zktype }), { elements: d, typeListObj: x, relationListObj: O } = F(n.data, { graphData: u, typeObj: w, relationObj: T, zktype: s.zktype });
192
- if (B(x), W(O), !((d == null ? void 0 : d.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);
@@ -235,12 +235,12 @@ const dt = ({
235
235
  zktype: s.zktype
236
236
  }
237
237
  };
238
- }), S = e.add(l);
239
- P([...u, ...l]);
240
- const f = S.filter(":node"), U = f.map((i) => i.id());
238
+ }), O = e.add(l);
239
+ P([...c, ...l]);
240
+ const y = O.filter(":node"), U = y.map((i) => i.id());
241
241
  r.data("appendedNodes", U), r.data("isExpanded", !0);
242
- const m = e.nodes().difference(f);
243
- m.forEach((i) => i.lock()), M.placeNewNodes(f), e.layout({
242
+ const f = e.nodes().difference(y);
243
+ f.forEach((i) => i.lock()), M.placeNewNodes(y), e.layout({
244
244
  name: "cose-bilkent",
245
245
  randomize: !1,
246
246
  // ⚠️ 这是关键!保持已有节点位置不变
@@ -256,8 +256,8 @@ const dt = ({
256
256
  // 可以适当减少,因为只需要微调
257
257
  gravity: 0.6
258
258
  }).run(), setTimeout(() => {
259
- m.forEach((i) => i.unlock());
260
- }, 2e3), f.animate({
259
+ f.forEach((i) => i.unlock());
260
+ }, 2e3), y.animate({
261
261
  style: {
262
262
  opacity: 1,
263
263
  width: 20,
@@ -267,7 +267,7 @@ const dt = ({
267
267
  duration: 400,
268
268
  easing: "ease-out",
269
269
  complete: () => {
270
- f.style("opacity", ""), f.style("width", ""), f.style("height", "");
270
+ y.style("opacity", ""), y.style("width", ""), y.style("height", "");
271
271
  }
272
272
  }), setTimeout(() => {
273
273
  r.removed() || (r.style("border-width", ""), r.style("border-color", ""), e.center(r), e.zoom(e.zoom()));
@@ -281,19 +281,19 @@ const dt = ({
281
281
  J(!1);
282
282
  }
283
283
  L({ visible: !1 });
284
- }, me = {
284
+ }, fe = {
285
285
  expanded: "typed-literal",
286
286
  contract: "uri"
287
- }, he = (s, a) => {
287
+ }, me = (s, a) => {
288
288
  var e;
289
289
  console.log("handleMenuAction:::", s, a);
290
- const y = a || g.targetNode;
291
- if (y) {
292
- const r = s.ids, t = y.data();
290
+ const g = a || u.targetNode;
291
+ if (g) {
292
+ const r = s.ids, t = g.data();
293
293
  if (["expanded", "contract"].includes(r))
294
- fe({ kgId: 3, ...t, zktype: me[r] });
294
+ ye({ kgId: 3, ...t, zktype: fe[r] });
295
295
  else if (r === "nodeInfo") {
296
- const o = y, n = {
296
+ const o = g, n = {
297
297
  id: o.id(),
298
298
  data: o.data(),
299
299
  position: o.position(),
@@ -304,14 +304,14 @@ const dt = ({
304
304
  style: o.style()
305
305
  };
306
306
  Q.current.open(n);
307
- } else r === "knowledgeCard" && V.current.open(y.data());
308
- (e = s.onClick) == null || e.call(s, y), 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 ((G = u == null ? void 0 : u.nodes) == null ? void 0 : G.length) > 0 ? /* @__PURE__ */ c(Pe, { value: { pathNodes: ge, setPathNodes: Y, graphInfo: h, graphData: u, layoutType: pe, setLayoutType: ue, knowledgeCardApi: ae }, children: /* @__PURE__ */ oe("div", { className: "cytoscape-container relative", children: [
312
- /* @__PURE__ */ c("div", { className: "btn-group" }),
313
- /* @__PURE__ */ c(
314
- we,
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,
@@ -320,19 +320,19 @@ const dt = ({
320
320
  cyContainerRef: j,
321
321
  typeObj: w,
322
322
  relationObj: T,
323
- colors: z,
323
+ colors: E,
324
324
  actionBar: ie
325
325
  }
326
326
  ),
327
327
  /* @__PURE__ */ oe("div", { className: "relative h-100", children: [
328
- /* @__PURE__ */ c("div", { ref: j, className: "cy-container" }),
329
- g.visible && g.targetNode && /* @__PURE__ */ c(
328
+ /* @__PURE__ */ m("div", { ref: j, className: "cy-container" }),
329
+ u.visible && u.targetNode && /* @__PURE__ */ m(
330
330
  "div",
331
331
  {
332
332
  style: {
333
333
  position: "absolute",
334
- left: `${g.x}px`,
335
- top: `${g.y}px`,
334
+ left: `${u.x}px`,
335
+ top: `${u.y}px`,
336
336
  // backgroundColor: 'white',
337
337
  // border: '1px solid #ccc',
338
338
  // borderRadius: '50%',
@@ -346,10 +346,10 @@ const dt = ({
346
346
  overflow: "hidden"
347
347
  },
348
348
  onClick: (s) => s.stopPropagation(),
349
- children: /* @__PURE__ */ c(De, { items: ye, centerImage: (ee = g == null ? void 0 : g.targetNode) == null ? void 0 : ee.data().image, targetNode: g.targetNode, onClick: (s, a) => he(s, a) })
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 dt = ({
373
373
  }
374
374
  )
375
375
  ] }),
376
- /* @__PURE__ */ c(Ie, { ref: Q }),
377
- /* @__PURE__ */ c(Be, { ref: V })
378
- ] }) }) : /* @__PURE__ */ c($e, { className: "h-100", align: "middle", justify: "center", children: /* @__PURE__ */ c(Oe, { description: ce }) });
376
+ /* @__PURE__ */ m(De, { ref: Q }),
377
+ /* @__PURE__ */ m(Se, { ref: V })
378
+ ] }) });
379
379
  };
380
380
  export {
381
- dt 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.21",
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",