Skip to content

Commit

Permalink
框选功能支持手机端的触摸事件。
Browse files Browse the repository at this point in the history
The box selection function supports touch events on the phone.
  • Loading branch information
little-snow-fox committed Feb 6, 2025
1 parent 4b92521 commit 10e5bed
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/x6-plugin-selection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,26 @@ export class Selection

protected startListening() {
this.graph.on('blank:mousedown', this.onBlankMouseDown, this)
this.graph.on('blank:touchstart', this.onBlankMouseDown, this)
this.graph.on('blank:click', this.onBlankClick, this)
this.graph.on('cell:mousemove', this.onCellMouseMove, this)
this.graph.on('cell:touchmove', this.onCellMouseMove, this)
this.graph.on('cell:mouseup', this.onCellMouseUp, this)
this.graph.on('cell:touchend', this.onCellMouseUp, this)
this.selectionImpl.on('box:mousedown', this.onBoxMouseDown, this)
this.selectionImpl.on('blank:touchstart', this.onBoxMouseDown, this)
}

protected stopListening() {
this.graph.off('blank:mousedown', this.onBlankMouseDown, this)
this.graph.off('blank:touchstart', this.onBlankMouseDown, this)
this.graph.off('blank:click', this.onBlankClick, this)
this.graph.off('cell:mousemove', this.onCellMouseMove, this)
this.graph.off('cell:touchmove', this.onCellMouseMove, this)
this.graph.off('cell:mouseup', this.onCellMouseUp, this)
this.graph.off('cell:touchend', this.onCellMouseUp, this)
this.selectionImpl.off('box:mousedown', this.onBoxMouseDown, this)
this.selectionImpl.off('blank:touchstart', this.onBoxMouseDown, this)
}

protected onBlankMouseDown({ e }: EventArgs['blank:mousedown']) {
Expand All @@ -335,10 +343,11 @@ export class Selection
}
}

protected allowBlankMouseDown(e: Dom.MouseDownEvent) {
protected allowBlankMouseDown(e: Dom.MouseDownEvent | Dom.TouchStartEvent) {
const eventTypes = this.options.eventTypes
return (
(eventTypes?.includes('leftMouseDown') && e.button === 0) ||
(eventTypes?.includes('leftMouseDown') &&
(e.button === 0 || e.touches?.length === 1)) ||
(eventTypes?.includes('mouseWheelDown') && e.button === 1)
)
}
Expand Down

0 comments on commit 10e5bed

Please sign in to comment.