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 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
- - [ ] NodePort
56
- - [ ] NodeTool/EdgeTool
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 a=require("vue"),g=require("@antv/x6"),w=require("@vue/runtime-core"),C=new Map;function b(e,n){return C.set(e,n),e}const{render:P,createApp:M}=w.createRenderer({patchProp:(e,n,o,s)=>e._update(n,o,s),insert:(e,n)=>e&&e._insert(n),remove:e=>e&&e._remove(),createElement:(e,n,o,s)=>{const r=C.get(e);return r&&r(s)},createText:e=>{const n={text:e,_insert:o=>n.parentNode=o};return n},createComment:()=>null,setText:()=>null,setElementText:()=>null,parentNode:e=>e.parentNode,nextSibling(e){}}),E=e=>Object.entries(e).reduce((n,[o,s])=>(o.startsWith("on")?n.events[o.substr(2).toLowerCase()]=s:n.props[o]=s===""?!0:s,n),{props:{},events:{}}),_=(e,n,o)=>{const s=Object.entries(n).map(([r,i])=>{const t=u=>{const{cell:f}=u;e&&f.id===e.id&&i(u)};return o.on(`cell:${r}`,t),()=>o.off(`cell:${r}`,t)});return()=>s.forEach(r=>r())},j=a.defineComponent({inheritAttrs:!1,name:"Graph",setup(e,{attrs:n,slots:o,expose:s}){const{container:r}=e,{props:i={},events:t={}}=E(n),{width:u=800,height:f=600,...c}=i,l=a.ref(r),p=a.shallowReactive({graph:null}),x=a.ref(),d=a.ref(new Map);return s(p),a.onMounted(()=>{if(l.value){p.graph=new g.Graph({container:l.value,width:u,height:f,...c}),_(null,t,p.graph);const h=a.h(()=>(x.value||[]).filter(v=>v.props).map(v=>{const{key:S,props:N={},type:T}=v,{id:m}=N;if(!S){const O=g.StringExt.hashcode(JSON.stringify(N));v.key=m||d.value.get(m)||d.value.get(O)||g.StringExt.uuid(),!m&&T!=="Edge"&&d.value.set(m||O,v.key)}return v}),p);P(h,p.graph)}}),a.onUnmounted(()=>{p.graph&&p.graph.dispose()}),()=>{const h=o.default&&o.default()||[];return a.nextTick(()=>x.value=h),a.createVNode("div",{style:{width:"100%",height:"100%",position:"relative"}},[!r&&a.createVNode("div",{ref:l},null)])}}}),y=(e,n,o)=>{const{props:s={},events:r={}}=E(o);let i;const t=e(o);t._remove=()=>{t._removeEvent(),i.model.removeCell(t)},t._insert=c=>{if(i=c.addCell(t),t._removeEvent=_(t,r,i),t.parentNode=c,s.parent){const l=i.getCellById(s.parent);l&&l.addChild(t)}};let u,f={};return t._update=(c,l,p)=>{u&&clearTimeout(u),f[c]=p,u=setTimeout(()=>t._update_props(f),1)},t._update_props=c=>{const{props:l={},events:p={}}=E(c),d=e({shape:t.shape,...l,parent:void 0}).getProp();g.ObjectExt.isEqual(t.getProp(),d)||Object.keys(d).forEach(h=>{["id","parent","shape"].indexOf(h)===-1&&t.setProp(h,d[h])}),t._removeEvent(),t._removeEvent=_(t,p,i),c={}},t},G=(e,n)=>{const{props:o={},events:s={}}=E(n),r=new e({enabled:!0,...o});return r._insert=i=>{i.use(r),_(null,s,r)},r._remove=()=>r.dispose(),r._update=()=>null,r},q=b("Node",y.bind(null,g.Node.create,"rect")),V=b("Edge",y.bind(null,g.Edge.create,"edge"));function k(e,n){return b(e,G.bind(null,n))}exports.Edge=V;exports.ElementOf=b;exports.ElementOfPlugin=k;exports.Graph=j;exports.Node=q;exports.createApp=M;exports.render=P;
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 G, ref as _, shallowReactive as M, onMounted as $, h as j, onUnmounted as S, nextTick as k, createVNode as C } from "vue";
2
- import { Node as R, Edge as V, Graph as A, StringExt as O, ObjectExt as B } from "@antv/x6";
3
- import { createRenderer as I } from "@vue/runtime-core";
4
- const w = /* @__PURE__ */ new Map();
5
- function b(e, n) {
6
- return w.set(e, n), e;
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 { render: q, createApp: W } = I({
9
- patchProp: (e, n, o, s) => e._update(n, o, s),
10
- insert: (e, n) => e && e._insert(n),
11
- remove: (e) => e && e._remove(),
12
- createElement: (e, n, o, s) => {
13
- const r = w.get(e);
14
- return r && r(s);
15
- },
16
- createText: (e) => {
17
- const n = { text: e, _insert: (o) => n.parentNode = o };
18
- return n;
19
- },
20
- createComment: () => null,
21
- setText: () => null,
22
- setElementText: () => null,
23
- parentNode: (e) => e.parentNode,
24
- nextSibling(e) {
25
- }
26
- // optional, DOM-specific
27
- // querySelector,
28
- // setScopeId,
29
- // cloneNode,
30
- // insertStaticContent,
31
- }), m = (e) => Object.entries(e).reduce((n, [o, s]) => (o.startsWith("on") ? n.events[o.substr(2).toLowerCase()] = s : n.props[o] = s === "" ? !0 : s, n), {
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
- }), g = (e, n, o) => {
35
- const s = Object.entries(n).map(([r, p]) => {
36
- const t = (l) => {
47
+ }), P = (s, c, n) => {
48
+ const o = Object.entries(c).map(([e, r]) => {
49
+ const t = (a) => {
37
50
  const {
38
- cell: h
39
- } = l;
40
- e && h.id === e.id && p(l);
51
+ cell: i
52
+ } = a;
53
+ s && i.id === s.id && r(a);
41
54
  };
42
- return o.on(`cell:${r}`, t), () => o.off(`cell:${r}`, t);
55
+ return n.on(`cell:${e}`, t), () => n.off(`cell:${e}`, t);
43
56
  });
44
- return () => s.forEach((r) => r());
45
- }, D = /* @__PURE__ */ G({
57
+ return () => o.forEach((e) => e());
58
+ }, te = /* @__PURE__ */ R({
46
59
  inheritAttrs: !1,
47
60
  name: "Graph",
48
- setup(e, {
49
- attrs: n,
50
- slots: o,
51
- expose: s
61
+ setup(s, {
62
+ attrs: c,
63
+ slots: n,
64
+ expose: o
52
65
  }) {
53
66
  const {
54
- container: r
55
- } = e, {
56
- props: p = {},
67
+ container: e
68
+ } = s, {
69
+ props: r = {},
57
70
  events: t = {}
58
- } = m(n), {
59
- width: l = 800,
60
- height: h = 600,
61
- ...i
62
- } = p, c = _(r), a = M({
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
- }), E = _(), d = _(/* @__PURE__ */ new Map());
65
- return s(a), $(() => {
66
- if (c.value) {
67
- a.graph = new A({
68
- container: c.value,
69
- width: l,
70
- height: h,
71
- ...i
72
- }), g(null, t, a.graph);
73
- const u = j(() => (E.value || []).filter((f) => f.props).map((f) => {
74
- const {
75
- key: T,
76
- props: x = {},
77
- type: y
78
- } = f, {
79
- id: v
80
- } = x;
81
- if (!T) {
82
- const N = O.hashcode(JSON.stringify(x));
83
- f.key = v || d.value.get(v) || d.value.get(N) || O.uuid(), !v && y !== "Edge" && d.value.set(v || N, f.key);
84
- }
85
- return f;
86
- }), a);
87
- q(u, a.graph);
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
- }), S(() => {
90
- a.graph && a.graph.dispose();
105
+ }), q(() => {
106
+ p.graph && p.graph.dispose();
91
107
  }), () => {
92
- const u = o.default && o.default() || [];
93
- return k(() => E.value = u), C("div", {
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
- }, [!r && C("div", {
100
- ref: c
115
+ }, [!e && O("div", {
116
+ ref: u
101
117
  }, null)]);
102
118
  };
103
119
  }
104
- }), P = (e, n, o) => {
120
+ }), S = (s, c, n, o) => {
105
121
  const {
106
- props: s = {},
122
+ props: e = {},
107
123
  events: r = {}
108
- } = m(o);
109
- let p;
110
- const t = e(o);
111
- t._remove = () => {
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: c = {},
125
- events: a = {}
126
- } = m(i), d = e({
129
+ props: i = {},
130
+ events: m = {}
131
+ } = b(a), p = s({
127
132
  shape: t.shape,
128
- ...c,
133
+ ...i,
129
134
  parent: void 0
130
135
  }).getProp();
131
- B.isEqual(t.getProp(), d) || Object.keys(d).forEach((u) => {
132
- ["id", "parent", "shape"].indexOf(u) === -1 && t.setProp(u, d[u]);
133
- }), t._removeEvent(), t._removeEvent = g(t, a, p), i = {};
134
- }, t;
135
- }, z = (e, n) => {
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: s = {}
139
- } = m(n), r = new e({
149
+ events: e = {}
150
+ } = b(c), r = new s({
140
151
  enabled: !0,
141
152
  ...o
142
153
  });
143
- return r._insert = (p) => {
144
- p.use(r), g(null, s, r);
145
- }, r._remove = () => r.dispose(), r._update = () => null, r;
146
- }, F = b("Node", P.bind(null, R.create, "rect")), H = b("Edge", P.bind(null, V.create, "edge"));
147
- function K(e, n) {
148
- return b(e, z.bind(null, n));
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
- H as Edge,
152
- b as ElementOf,
153
- K as ElementOfPlugin,
154
- D as Graph,
155
- F as Node,
156
- W as createApp,
157
- q as render
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 render: import("vue").RootRenderFunction<import("vue").RendererElement>, createApp: import("vue").CreateAppFunction<import("vue").RendererElement>;
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",
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.1",
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",