Skip to content

Commit 8030621

Browse files
authored
fix: bind dragstart after add group (#4131)
1 parent 928c008 commit 8030621

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"prepare": "is-ci || run-p setup:husky build:dev",
2424
"start:demo": "cd ./examples/x6-example-features && pnpm start",
2525
"start:site": "cd ./sites/x6-sites && pnpm start",
26-
"release": "pnpm publish --no-git-checks -r --filter @antv/x6"
26+
"release": "pnpm publish --no-git-checks -r --filter @antv/x6"
2727
},
2828
"rss": {
2929
"clean:turbo": "rimraf .turbo",

packages/x6-plugin-stencil/src/index.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export class Stencil extends View implements Graph.Plugin {
180180
)
181181
groupNames.forEach((groupName) => {
182182
const graph = this.graphs[groupName]
183+
this.unregisterGraphEvents(graph)
183184
graph.dispose()
184185
delete this.graphs[groupName]
185186

@@ -249,6 +250,8 @@ export class Stencil extends View implements Graph.Plugin {
249250
preventDefaultBlankAction: false,
250251
})
251252

253+
this.registerGraphEvents(graph)
254+
252255
Dom.append(content, graph.container)
253256
Dom.append(groupElem, [title, content])
254257
Dom.appendTo(groupElem, this.content)
@@ -339,19 +342,18 @@ export class Stencil extends View implements Graph.Plugin {
339342
[`focusin .${searchText}`]: 'onSearchFocusIn',
340343
[`focusout .${searchText}`]: 'onSearchFocusOut',
341344
})
342-
343-
Object.keys(this.graphs).forEach((groupName) => {
344-
const graph = this.graphs[groupName]
345-
graph.on('cell:mousedown', this.onDragStart, this)
346-
})
347345
}
348346

349347
protected stopListening() {
350348
this.undelegateEvents()
351-
Object.keys(this.graphs).forEach((groupName) => {
352-
const graph = this.graphs[groupName]
353-
graph.off('cell:mousedown', this.onDragStart, this)
354-
})
349+
}
350+
351+
protected registerGraphEvents(graph: Graph) {
352+
graph.on('cell:mousedown', this.onDragStart, this)
353+
}
354+
355+
protected unregisterGraphEvents(graph: Graph) {
356+
graph.off('cell:mousedown', this.onDragStart, this)
355357
}
356358

357359
protected loadGroup(
@@ -571,6 +573,7 @@ export class Stencil extends View implements Graph.Plugin {
571573
protected clearGroups() {
572574
Object.keys(this.graphs).forEach((groupName) => {
573575
const graph = this.graphs[groupName]
576+
this.unregisterGraphEvents(graph)
574577
graph.dispose()
575578
})
576579
Object.keys(this.groups).forEach((groupName) => {

pnpm-lock.yaml

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)