Skip to content

Commit

Permalink
fix: bind dragstart after add group (#4131)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Jan 2, 2024
1 parent 928c008 commit 8030621
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"prepare": "is-ci || run-p setup:husky build:dev",
"start:demo": "cd ./examples/x6-example-features && pnpm start",
"start:site": "cd ./sites/x6-sites && pnpm start",
"release": "pnpm publish --no-git-checks -r --filter @antv/x6"
"release": "pnpm publish --no-git-checks -r --filter @antv/x6"
},
"rss": {
"clean:turbo": "rimraf .turbo",
Expand Down
21 changes: 12 additions & 9 deletions packages/x6-plugin-stencil/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class Stencil extends View implements Graph.Plugin {
)
groupNames.forEach((groupName) => {
const graph = this.graphs[groupName]
this.unregisterGraphEvents(graph)
graph.dispose()
delete this.graphs[groupName]

Expand Down Expand Up @@ -249,6 +250,8 @@ export class Stencil extends View implements Graph.Plugin {
preventDefaultBlankAction: false,
})

this.registerGraphEvents(graph)

Dom.append(content, graph.container)
Dom.append(groupElem, [title, content])
Dom.appendTo(groupElem, this.content)
Expand Down Expand Up @@ -339,19 +342,18 @@ export class Stencil extends View implements Graph.Plugin {
[`focusin .${searchText}`]: 'onSearchFocusIn',
[`focusout .${searchText}`]: 'onSearchFocusOut',
})

Object.keys(this.graphs).forEach((groupName) => {
const graph = this.graphs[groupName]
graph.on('cell:mousedown', this.onDragStart, this)
})
}

protected stopListening() {
this.undelegateEvents()
Object.keys(this.graphs).forEach((groupName) => {
const graph = this.graphs[groupName]
graph.off('cell:mousedown', this.onDragStart, this)
})
}

protected registerGraphEvents(graph: Graph) {
graph.on('cell:mousedown', this.onDragStart, this)
}

protected unregisterGraphEvents(graph: Graph) {
graph.off('cell:mousedown', this.onDragStart, this)
}

protected loadGroup(
Expand Down Expand Up @@ -571,6 +573,7 @@ export class Stencil extends View implements Graph.Plugin {
protected clearGroups() {
Object.keys(this.graphs).forEach((groupName) => {
const graph = this.graphs[groupName]
this.unregisterGraphEvents(graph)
graph.dispose()
})
Object.keys(this.groups).forEach((groupName) => {
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8030621

Please sign in to comment.