Skip to content

Commit a98e97d

Browse files
authored
fix: add getGraph provide (#3072)
1 parent 30c2ed2 commit a98e97d

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/x6-react-shape/src/view.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ export class ReactShapeView extends NodeView<ReactShape> {
2626
const node = this.cell
2727

2828
if (container) {
29-
const graph = node.model ? node.model.graph : null
30-
// Actually in the dnd plugin, this graph is empty,
31-
// in order to make the external perception type of graph is a graph, rather than graph | null, so hack this.
32-
const elem = React.createElement(Wrap, { node, graph: graph! })
29+
const elem = React.createElement(Wrap, { node, graph: this.graph })
3330
if (Portal.isActive()) {
3431
const portal = createPortal(elem, container) as ReactPortal
3532
Portal.connect(this.cell.id, portal)

packages/x6-vue-shape/src/teleport.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineComponent, h, reactive, isVue3, Vue } from 'vue-demi'
2+
import { Graph } from '@antv/x6'
23
import { VueShape } from './node'
34

45
let active = false
@@ -9,6 +10,7 @@ export function connect(
910
component: any,
1011
container: HTMLDivElement,
1112
node: VueShape,
13+
graph: Graph,
1214
) {
1315
if (active) {
1416
const { Teleport, markRaw } = Vue as any
@@ -17,6 +19,7 @@ export function connect(
1719
render: () => h(Teleport, { to: container } as any, [h(component)]),
1820
provide: () => ({
1921
getNode: () => node,
22+
getGraph: () => graph,
2023
}),
2124
}),
2225
)

packages/x6-vue-shape/src/view.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ export class VueShapeView extends NodeView<VueShape> {
4040
provide() {
4141
return {
4242
getNode: () => node,
43+
getGraph: () => this.graph,
4344
}
4445
},
4546
})
4647
} else if (isVue3) {
4748
if (isActive()) {
48-
connect(this.targetId(), component, root, node)
49+
connect(this.targetId(), component, root, node, this.graph)
4950
} else {
5051
this.vm = createApp({
5152
render() {
@@ -54,6 +55,7 @@ export class VueShapeView extends NodeView<VueShape> {
5455
provide() {
5556
return {
5657
getNode: () => node,
58+
getGraph: () => this.graph,
5759
}
5860
},
5961
})

0 commit comments

Comments
 (0)