vue-x6 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +42 -4
- package/dist/Graph.d.ts +21 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +208 -122
- package/dist/render.d.ts +1 -2
- package/package.json +4 -2
package/README.md
CHANGED
@@ -39,10 +39,40 @@ const toggle = () => visible.value = !visible.value
|
|
39
39
|
<button @click="toggle">显示/隐藏node2</button>
|
40
40
|
<Graph grid>
|
41
41
|
<SnaplinePlugin key="Snapline" />
|
42
|
-
<Node id="1" label="node1" :x="100" :y="100" :width="80" :height="40" @click="click"
|
42
|
+
<Node id="1" label="node1" :x="100" :y="100" :width="80" :height="40" @click="click" >
|
43
|
+
</Node>
|
43
44
|
<Node id="2" label="node2" :x="200" :y="200" :width="80" :height="40" @click="click" v-if="visible" />
|
44
45
|
<Node id="3" label="node3" :x="200" :y="100" :width="80" :height="40" parent="1" @click="click" />
|
45
|
-
<Edge source="1" target="2" @click="click"
|
46
|
+
<Edge v-if="visible" source="1" target="2" @click="click">
|
47
|
+
<EdgeTool name="button-remove" :args='{ x: 10, y: 10 }' />
|
48
|
+
<Label :attrs='{text: {text: "Hello Label1"}}' :position='{distance: 0.3}' />
|
49
|
+
<Label :attrs='{text: {text: "Hello Label3"}}' :position='{distance: 0.5}' />
|
50
|
+
<Label :attrs='{text: {text: "Hello Label2"}}' :position='{distance: 0.7}' />
|
51
|
+
<SourceMarker name="diamond" />
|
52
|
+
<TargetMarker name="ellipse" />
|
53
|
+
</Edge>
|
54
|
+
</Graph>
|
55
|
+
</template>
|
56
|
+
```
|
57
|
+
|
58
|
+
### x6-vue-shape demo
|
59
|
+
```
|
60
|
+
import { register, getTeleport } from "@antv/x6-vue-shape";
|
61
|
+
import ProgressNode from "./ProgressNode.vue";
|
62
|
+
|
63
|
+
register({
|
64
|
+
shape: "custom-vue-node",
|
65
|
+
width: 100,
|
66
|
+
height: 100,
|
67
|
+
component: ProgressNode,
|
68
|
+
});
|
69
|
+
|
70
|
+
const TeleportContainer = getTeleport();
|
71
|
+
|
72
|
+
<template>
|
73
|
+
<TeleportContainer />
|
74
|
+
<Graph grid>
|
75
|
+
<Node shape="custom-vue-node" :x="400" :y="100" />
|
46
76
|
</Graph>
|
47
77
|
</template>
|
48
78
|
```
|
@@ -52,6 +82,14 @@ const toggle = () => visible.value = !visible.value
|
|
52
82
|
- [x] Graph组件
|
53
83
|
- [x] Node/Edge组件
|
54
84
|
- [x] ElementOfPlugin函数方便封装官方plugin
|
55
|
-
- [
|
56
|
-
- [
|
85
|
+
- [x] Label(Edge)
|
86
|
+
- [x] NodePort
|
87
|
+
- [x] NodeTool/EdgeTool
|
88
|
+
- [x] SourceMarker/TargetMarker
|
89
|
+
|
90
|
+
|
91
|
+
## TIP
|
92
|
+
1. vue createRenderer中的createElement也通过包装一层传递root(graph)进去
|
93
|
+
2. vue createRenderer传递patchProp,这里通过包装一个patchProps一次性更新整个props
|
94
|
+
3. 这里patchProps中有延时逻辑,所以增加`updated:props`事件监听
|
57
95
|
|
package/dist/Graph.d.ts
CHANGED
@@ -13,5 +13,26 @@ export declare const Node: DefineComponent<unknown, {
|
|
13
13
|
export declare const Edge: DefineComponent<unknown, {
|
14
14
|
[key: string]: any;
|
15
15
|
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
16
|
+
export declare const SourceMarker: DefineComponent<unknown, {
|
17
|
+
[key: string]: any;
|
18
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
19
|
+
export declare const TargetMarker: DefineComponent<unknown, {
|
20
|
+
[key: string]: any;
|
21
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
22
|
+
export declare const PortGroup: DefineComponent<unknown, {
|
23
|
+
[key: string]: any;
|
24
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
25
|
+
export declare const Label: DefineComponent<unknown, {
|
26
|
+
[key: string]: any;
|
27
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
28
|
+
export declare const Port: DefineComponent<unknown, {
|
29
|
+
[key: string]: any;
|
30
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
31
|
+
export declare const EdgeTool: DefineComponent<unknown, {
|
32
|
+
[key: string]: any;
|
33
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
34
|
+
export declare const NodeTool: DefineComponent<unknown, {
|
35
|
+
[key: string]: any;
|
36
|
+
}, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>;
|
16
37
|
export declare function ElementOfPlugin(name: string, type: any): any;
|
17
38
|
export {};
|
package/dist/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("vue"),v=require("@antv/x6"),B=require("@vue/runtime-core"),G=new Map;function p(s,c){return G.set(s,c),s}const S=s=>{let c;const n=new Map,r=(e,o,t,i)=>{if(!e)return;const a=n.get(e.id)||{};c&&clearTimeout(c),a[o]=i,n.set(e.id,{...a,[o]:i}),c=setTimeout(()=>{e._update(n.get(e.id)||{}),n.set(e.id,{})},1)};return B.createRenderer({patchProp:r,insert:(e,o)=>e._insert&&e._insert(o),remove:e=>e&&e._remove(),createElement:(e,o,t,i)=>{const a=G.get(e);return a&&a(i,s)},createText:e=>{const o={text:e,_insert:t=>o.parentNode=t};return o},createComment:e=>{console.log("createComment",e)},setText:()=>null,setElementText:()=>null,parentNode:e=>e.parentNode,nextSibling(e){}},s)},T=s=>Object.entries(s).reduce((c,[n,r])=>(n.startsWith("on")?c.events[n.substr(2).toLowerCase()]=r:c.props[n]=r===""?!0:r,c),{props:{},events:{}}),M=(s,c,n)=>{const r=Object.entries(c).map(([e,o])=>{const t=i=>{const{cell:a}=i;s&&a.id===s.id&&o(i)};return n.on(`cell:${e}`,t),()=>n.off(`cell:${e}`,t)});return()=>r.forEach(e=>e())},I=d.defineComponent({inheritAttrs:!1,name:"Graph",setup(s,{attrs:c,slots:n,expose:r}){const{container:e}=s,{props:o={},events:t={}}=T(c),{width:i=800,height:a=600,...f}=o,g=d.ref(e),l=d.shallowReactive({graph:null}),m=d.ref([]),N=d.ref(new Map),k=(E,b="")=>E.filter(P=>P.props).map(P=>{const{props:$={},type:_,children:O=[]}=P,{id:u}=$,x=v.StringExt.hashcode(JSON.stringify($));let h=u&&`${b}:${_}:${u}`||u&&N.value.get(`${b}:${_}:${u}`)||N.value.get(`${b}:${x}`);return h||(h=v.StringExt.uuid(),!u&&_!=="Edge"&&N.value.set(u?`${b}:${u}`:`${b}:${x}`,h)),d.h(_,{...$,id:u||h,key:h},O&&k(O,h))}).filter(P=>P.key);return r(l),d.onMounted(()=>{if(g.value){l.graph=new v.Graph({container:g.value,width:i,height:a,...f}),M(null,t,l.graph);const{render:E}=S(l.graph);E(d.h(()=>m.value),l.graph)}}),d.onUnmounted(()=>{l.graph&&l.graph.dispose()}),()=>{const E=n.default&&n.default()||[];return d.nextTick(()=>m.value=k(E)),d.createVNode("div",{style:{width:"100%",height:"100%",position:"relative"}},[!e&&d.createVNode("div",{ref:g},null)])}}}),y=(s,c,n,r)=>{const{props:e={},events:o={}}=T(n),t=s(n);if(t._remove=()=>{t._removeEvent(),r.model.removeCell(t)},t._update=i=>{const{props:a={},events:f={}}=T(i),l=s({shape:t.shape,...a,parent:void 0}).getProp();v.ObjectExt.isEqual(t.getProp(),l)||Object.keys(l).forEach(m=>{["id","parent","shape"].indexOf(m)===-1&&t.setProp(m,l[m])}),t._removeEvent(),t._removeEvent=M(t,f,r),r.trigger("updated:props",{cell:t})},r.model.addCell(t),t.parentNode=r,e.parent){const i=r.getCellById(e.parent);i&&i.addChild(t)}return t._removeEvent=M(t,o,r),d.nextTick(()=>t._update(e)),t},R=(s,c,n)=>{const{props:r={},events:e={}}=T(c),o=new s({enabled:!0,...r});return o._remove=()=>o.dispose(),o._update=()=>null,n.use(o),M(null,e,o),o},C=(s,c,n,r)=>{const{id:e}=n,o={id:e,cell:{id:""},props:n,_update:i=>o.props=i,_insert:i=>o.cell=i,_remove:()=>{o._update(null),r.off("updated:props",t)}},t=({cell:i})=>{if(o.cell.id==i.id){const a=s(i),f=a.findIndex(l=>l.id===e),g=f===-1?a.length:f;o.props?a.splice(g,1,o.props):a.splice(g,1),c(i,a)}};return r.on("updated:props",t),o},q=(s,c)=>C(n=>n.getLabels(),(n,r)=>n.setLabels([...r]),s,c),L=(s,c,n,r)=>{const{id:e,name:o}=n,t={id:e,name:o,props:n,cell:{id:""},_update:a=>t.props=a,_insert:a=>t.cell=a,_remove:()=>{t._update(),r.off("updated:props",i)}},i=({cell:a})=>{t.cell.id==a.id&&c(t,a,t.props)};return r.on("updated:props",i),t},w=(s,c,n)=>L(s,(r,e,o)=>{const t=e.attr("line");e.attr("line",{...t,[s]:o})},c,n),V=(s,c,n)=>L(s,(r,e,o)=>{const{port:t}=e,i=e.getPropByPath("ports/groups")||{};o?i[r.name]=t.parseGroup(o):delete i[r.name],e.setPropByPath("ports/groups",{...i})},c,n),A=(s,c)=>C(n=>n.getPorts(),(n,r)=>{n.setPropByPath("ports/items",r)},s,c),j=(s,c)=>C(n=>{const r=n.getTools();return r&&r.items?r.items:r||[]},(n,r)=>n.setTools(r),s,c),z=p("Node",y.bind(null,v.Node.create,"rect")),J=p("Edge",y.bind(null,v.Edge.create,"edge")),U=p("SourceMarker",w.bind(null,"sourceMarker")),W=p("TargetMarker",w.bind(null,"targetMarker")),D=p("PortGroup",V.bind(null,"group")),F=p("Label",q),H=p("Port",A),K=p("EdgeTool",j),Q=p("NodeTool",j);function X(s,c){return p(s,R.bind(null,c))}exports.Edge=J;exports.EdgeTool=K;exports.ElementOf=p;exports.ElementOfPlugin=X;exports.Graph=I;exports.Label=F;exports.Node=z;exports.NodeTool=Q;exports.Port=H;exports.PortGroup=D;exports.SourceMarker=U;exports.TargetMarker=W;exports.getRender=S;
|
package/dist/index.js
CHANGED
@@ -1,158 +1,244 @@
|
|
1
|
-
import { defineComponent as
|
2
|
-
import { Node as
|
3
|
-
import { createRenderer as
|
4
|
-
const
|
5
|
-
function
|
6
|
-
return
|
1
|
+
import { defineComponent as R, ref as N, shallowReactive as A, onMounted as V, h as x, onUnmounted as q, nextTick as L, createVNode as O } from "vue";
|
2
|
+
import { Node as z, Edge as J, Graph as U, ObjectExt as W, StringExt as w } from "@antv/x6";
|
3
|
+
import { createRenderer as D } from "@vue/runtime-core";
|
4
|
+
const y = /* @__PURE__ */ new Map();
|
5
|
+
function l(s, c) {
|
6
|
+
return y.set(s, c), s;
|
7
7
|
}
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
8
|
+
const F = (s) => {
|
9
|
+
let c;
|
10
|
+
const n = /* @__PURE__ */ new Map();
|
11
|
+
return D({
|
12
|
+
patchProp: (e, r, t, a) => {
|
13
|
+
if (!e)
|
14
|
+
return;
|
15
|
+
const i = n.get(e.id) || {};
|
16
|
+
c && clearTimeout(c), i[r] = a, n.set(e.id, { ...i, [r]: a }), c = setTimeout(() => {
|
17
|
+
e._update(n.get(e.id) || {}), n.set(e.id, {});
|
18
|
+
}, 1);
|
19
|
+
},
|
20
|
+
insert: (e, r) => e._insert && e._insert(r),
|
21
|
+
remove: (e) => e && e._remove(),
|
22
|
+
createElement: (e, r, t, a) => {
|
23
|
+
const i = y.get(e);
|
24
|
+
return i && i(a, s);
|
25
|
+
},
|
26
|
+
createText: (e) => {
|
27
|
+
const r = { text: e, _insert: (t) => r.parentNode = t };
|
28
|
+
return r;
|
29
|
+
},
|
30
|
+
createComment: (e) => {
|
31
|
+
console.log("createComment", e);
|
32
|
+
},
|
33
|
+
setText: () => null,
|
34
|
+
setElementText: () => null,
|
35
|
+
parentNode: (e) => e.parentNode,
|
36
|
+
nextSibling(e) {
|
37
|
+
}
|
38
|
+
// optional, DOM-specific
|
39
|
+
// querySelector,
|
40
|
+
// setScopeId,
|
41
|
+
// cloneNode,
|
42
|
+
// insertStaticContent,
|
43
|
+
}, s);
|
44
|
+
}, b = (s) => Object.entries(s).reduce((c, [n, o]) => (n.startsWith("on") ? c.events[n.substr(2).toLowerCase()] = o : c.props[n] = o === "" ? !0 : o, c), {
|
32
45
|
props: {},
|
33
46
|
events: {}
|
34
|
-
}),
|
35
|
-
const
|
36
|
-
const t = (
|
47
|
+
}), P = (s, c, n) => {
|
48
|
+
const o = Object.entries(c).map(([e, r]) => {
|
49
|
+
const t = (a) => {
|
37
50
|
const {
|
38
|
-
cell:
|
39
|
-
} =
|
40
|
-
|
51
|
+
cell: i
|
52
|
+
} = a;
|
53
|
+
s && i.id === s.id && r(a);
|
41
54
|
};
|
42
|
-
return
|
55
|
+
return n.on(`cell:${e}`, t), () => n.off(`cell:${e}`, t);
|
43
56
|
});
|
44
|
-
return () =>
|
45
|
-
},
|
57
|
+
return () => o.forEach((e) => e());
|
58
|
+
}, te = /* @__PURE__ */ R({
|
46
59
|
inheritAttrs: !1,
|
47
60
|
name: "Graph",
|
48
|
-
setup(
|
49
|
-
attrs:
|
50
|
-
slots:
|
51
|
-
expose:
|
61
|
+
setup(s, {
|
62
|
+
attrs: c,
|
63
|
+
slots: n,
|
64
|
+
expose: o
|
52
65
|
}) {
|
53
66
|
const {
|
54
|
-
container:
|
55
|
-
} =
|
56
|
-
props:
|
67
|
+
container: e
|
68
|
+
} = s, {
|
69
|
+
props: r = {},
|
57
70
|
events: t = {}
|
58
|
-
} =
|
59
|
-
width:
|
60
|
-
height:
|
61
|
-
...
|
62
|
-
} =
|
71
|
+
} = b(c), {
|
72
|
+
width: a = 800,
|
73
|
+
height: i = 600,
|
74
|
+
...m
|
75
|
+
} = r, u = N(e), p = A({
|
63
76
|
graph: null
|
64
|
-
}),
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
}),
|
87
|
-
|
77
|
+
}), f = N([]), $ = N(/* @__PURE__ */ new Map()), C = (h, v = "") => h.filter((E) => E.props).map((E) => {
|
78
|
+
const {
|
79
|
+
props: T = {},
|
80
|
+
type: _,
|
81
|
+
children: G = []
|
82
|
+
} = E, {
|
83
|
+
id: d
|
84
|
+
} = T, k = w.hashcode(JSON.stringify(T));
|
85
|
+
let g = d && `${v}:${_}:${d}` || d && $.value.get(`${v}:${_}:${d}`) || $.value.get(`${v}:${k}`);
|
86
|
+
return g || (g = w.uuid(), !d && _ !== "Edge" && $.value.set(d ? `${v}:${d}` : `${v}:${k}`, g)), x(_, {
|
87
|
+
...T,
|
88
|
+
id: d || g,
|
89
|
+
key: g
|
90
|
+
}, G && C(G, g));
|
91
|
+
}).filter((E) => E.key);
|
92
|
+
return o(p), V(() => {
|
93
|
+
if (u.value) {
|
94
|
+
p.graph = new U({
|
95
|
+
container: u.value,
|
96
|
+
width: a,
|
97
|
+
height: i,
|
98
|
+
...m
|
99
|
+
}), P(null, t, p.graph);
|
100
|
+
const {
|
101
|
+
render: h
|
102
|
+
} = F(p.graph);
|
103
|
+
h(x(() => f.value), p.graph);
|
88
104
|
}
|
89
|
-
}),
|
90
|
-
|
105
|
+
}), q(() => {
|
106
|
+
p.graph && p.graph.dispose();
|
91
107
|
}), () => {
|
92
|
-
const
|
93
|
-
return
|
108
|
+
const h = n.default && n.default() || [];
|
109
|
+
return L(() => f.value = C(h)), O("div", {
|
94
110
|
style: {
|
95
111
|
width: "100%",
|
96
112
|
height: "100%",
|
97
113
|
position: "relative"
|
98
114
|
}
|
99
|
-
}, [!
|
100
|
-
ref:
|
115
|
+
}, [!e && O("div", {
|
116
|
+
ref: u
|
101
117
|
}, null)]);
|
102
118
|
};
|
103
119
|
}
|
104
|
-
}),
|
120
|
+
}), S = (s, c, n, o) => {
|
105
121
|
const {
|
106
|
-
props:
|
122
|
+
props: e = {},
|
107
123
|
events: r = {}
|
108
|
-
} =
|
109
|
-
|
110
|
-
|
111
|
-
t.
|
112
|
-
t._removeEvent(), p.model.removeCell(t);
|
113
|
-
}, t._insert = (i) => {
|
114
|
-
if (p = i.addCell(t), t._removeEvent = g(t, r, p), t.parentNode = i, s.parent) {
|
115
|
-
const c = p.getCellById(s.parent);
|
116
|
-
c && c.addChild(t);
|
117
|
-
}
|
118
|
-
};
|
119
|
-
let l, h = {};
|
120
|
-
return t._update = (i, c, a) => {
|
121
|
-
l && clearTimeout(l), h[i] = a, l = setTimeout(() => t._update_props(h), 1);
|
122
|
-
}, t._update_props = (i) => {
|
124
|
+
} = b(n), t = s(n);
|
125
|
+
if (t._remove = () => {
|
126
|
+
t._removeEvent(), o.model.removeCell(t);
|
127
|
+
}, t._update = (a) => {
|
123
128
|
const {
|
124
|
-
props:
|
125
|
-
events:
|
126
|
-
} =
|
129
|
+
props: i = {},
|
130
|
+
events: m = {}
|
131
|
+
} = b(a), p = s({
|
127
132
|
shape: t.shape,
|
128
|
-
...
|
133
|
+
...i,
|
129
134
|
parent: void 0
|
130
135
|
}).getProp();
|
131
|
-
|
132
|
-
["id", "parent", "shape"].indexOf(
|
133
|
-
}), t._removeEvent(), t._removeEvent =
|
134
|
-
|
135
|
-
}
|
136
|
+
W.isEqual(t.getProp(), p) || Object.keys(p).forEach((f) => {
|
137
|
+
["id", "parent", "shape"].indexOf(f) === -1 && t.setProp(f, p[f]);
|
138
|
+
}), t._removeEvent(), t._removeEvent = P(t, m, o), o.trigger("updated:props", {
|
139
|
+
cell: t
|
140
|
+
});
|
141
|
+
}, o.model.addCell(t), t.parentNode = o, e.parent) {
|
142
|
+
const a = o.getCellById(e.parent);
|
143
|
+
a && a.addChild(t);
|
144
|
+
}
|
145
|
+
return t._removeEvent = P(t, r, o), L(() => t._update(e)), t;
|
146
|
+
}, H = (s, c, n) => {
|
136
147
|
const {
|
137
148
|
props: o = {},
|
138
|
-
events:
|
139
|
-
} =
|
149
|
+
events: e = {}
|
150
|
+
} = b(c), r = new s({
|
140
151
|
enabled: !0,
|
141
152
|
...o
|
142
153
|
});
|
143
|
-
return r.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
154
|
+
return r._remove = () => r.dispose(), r._update = () => null, n.use(r), P(null, e, r), r;
|
155
|
+
}, M = (s, c, n, o) => {
|
156
|
+
const {
|
157
|
+
id: e
|
158
|
+
} = n, r = {
|
159
|
+
id: e,
|
160
|
+
cell: {
|
161
|
+
id: ""
|
162
|
+
},
|
163
|
+
props: n,
|
164
|
+
// update只是将newProps存起来,实际执行逻辑在updated:props里面执行
|
165
|
+
_update: (a) => r.props = a,
|
166
|
+
_insert: (a) => r.cell = a,
|
167
|
+
_remove: () => {
|
168
|
+
r._update(null), o.off("updated:props", t);
|
169
|
+
}
|
170
|
+
}, t = ({
|
171
|
+
cell: a
|
172
|
+
}) => {
|
173
|
+
if (r.cell.id == a.id) {
|
174
|
+
const i = s(a), m = i.findIndex((p) => p.id === e), u = m === -1 ? i.length : m;
|
175
|
+
r.props ? i.splice(u, 1, r.props) : i.splice(u, 1), c(a, i);
|
176
|
+
}
|
177
|
+
};
|
178
|
+
return o.on("updated:props", t), r;
|
179
|
+
}, K = (s, c) => M((n) => n.getLabels(), (n, o) => n.setLabels([...o]), s, c), B = (s, c, n, o) => {
|
180
|
+
const {
|
181
|
+
id: e,
|
182
|
+
name: r
|
183
|
+
} = n, t = {
|
184
|
+
id: e,
|
185
|
+
name: r,
|
186
|
+
props: n,
|
187
|
+
cell: {
|
188
|
+
id: ""
|
189
|
+
},
|
190
|
+
// @ts-ignore
|
191
|
+
_update: (i) => t.props = i,
|
192
|
+
_insert: (i) => t.cell = i,
|
193
|
+
_remove: () => {
|
194
|
+
t._update(), o.off("updated:props", a);
|
195
|
+
}
|
196
|
+
}, a = ({
|
197
|
+
cell: i
|
198
|
+
}) => {
|
199
|
+
t.cell.id == i.id && c(t, i, t.props);
|
200
|
+
};
|
201
|
+
return o.on("updated:props", a), t;
|
202
|
+
}, I = (s, c, n) => B(s, (o, e, r) => {
|
203
|
+
const t = e.attr("line");
|
204
|
+
e.attr("line", {
|
205
|
+
...t,
|
206
|
+
[s]: r
|
207
|
+
});
|
208
|
+
}, c, n), Q = (s, c, n) => B(s, (o, e, r) => {
|
209
|
+
const {
|
210
|
+
port: t
|
211
|
+
} = e, a = e.getPropByPath("ports/groups") || {};
|
212
|
+
r ? a[o.name] = t.parseGroup(r) : delete a[o.name], e.setPropByPath("ports/groups", {
|
213
|
+
...a
|
214
|
+
});
|
215
|
+
}, c, n), X = (s, c) => M(
|
216
|
+
(n) => n.getPorts(),
|
217
|
+
// getPorts return ObjectExt.cloneDeep
|
218
|
+
(n, o) => {
|
219
|
+
n.setPropByPath("ports/items", o);
|
220
|
+
},
|
221
|
+
s,
|
222
|
+
c
|
223
|
+
), j = (s, c) => M((n) => {
|
224
|
+
const o = n.getTools();
|
225
|
+
return o && o.items ? o.items : o || [];
|
226
|
+
}, (n, o) => n.setTools(o), s, c), ne = l("Node", S.bind(null, z.create, "rect")), oe = l("Edge", S.bind(null, J.create, "edge")), re = l("SourceMarker", I.bind(null, "sourceMarker")), se = l("TargetMarker", I.bind(null, "targetMarker")), ce = l("PortGroup", Q.bind(null, "group")), ae = l("Label", K), ie = l("Port", X), pe = l("EdgeTool", j), le = l("NodeTool", j);
|
227
|
+
function de(s, c) {
|
228
|
+
return l(s, H.bind(null, c));
|
149
229
|
}
|
150
230
|
export {
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
231
|
+
oe as Edge,
|
232
|
+
pe as EdgeTool,
|
233
|
+
l as ElementOf,
|
234
|
+
de as ElementOfPlugin,
|
235
|
+
te as Graph,
|
236
|
+
ae as Label,
|
237
|
+
ne as Node,
|
238
|
+
le as NodeTool,
|
239
|
+
ie as Port,
|
240
|
+
ce as PortGroup,
|
241
|
+
re as SourceMarker,
|
242
|
+
se as TargetMarker,
|
243
|
+
F as getRender
|
158
244
|
};
|
package/dist/render.d.ts
CHANGED
@@ -2,5 +2,4 @@ import type { DefineComponent } from 'vue';
|
|
2
2
|
export declare function ElementOf<Element, T extends string>(type: T, Ctor: () => any): DefineComponent<Element, {
|
3
3
|
[key: string]: any;
|
4
4
|
}>;
|
5
|
-
declare const
|
6
|
-
export { render, createApp };
|
5
|
+
export declare const getRender: (graph: any) => import("vue").Renderer<any>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "vue-x6",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.5",
|
4
4
|
"type": "module",
|
5
5
|
"scripts": {
|
6
6
|
"dev": "vite",
|
@@ -36,10 +36,12 @@
|
|
36
36
|
"vue": "^3.2.45"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@antv/x6": "^2.5.
|
39
|
+
"@antv/x6": "^2.5.2",
|
40
40
|
"@antv/x6-plugin-snapline": "^2.1.6",
|
41
|
+
"@antv/x6-vue-shape": "^2.0.10",
|
41
42
|
"@vitejs/plugin-vue": "^4.0.0",
|
42
43
|
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
44
|
+
"element-plus": "^2.3.0",
|
43
45
|
"npm-run-all": "^4.1.5",
|
44
46
|
"typescript": "^4.9.3",
|
45
47
|
"vite": "^4.1.0",
|