Skip to content

Commit

Permalink
fix(core): 修复笔记本触摸板点击边事件失效
Browse files Browse the repository at this point in the history
  • Loading branch information
wuchenguang1998 authored and boyongjiong committed Oct 29, 2024
1 parent d66f35a commit 9b5f3f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/feature-examples/src/pages/graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export default function BasicNode() {
lf.on('blank:drop', (data) => {
console.log('blank:drop', data)
})

lf.on('edge:click', (data) => {
console.log('edge:click', data)
})
}

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/model/edge/BaseEdgeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class BaseEdgeModel<P extends PropertiesType = PropertiesType>
// 边特有属性,动画及调整点
@observable isAnimation = false
@observable isShowAdjustPoint = false // 是否显示边两端的调整点
isDragging?: boolean
// 引用属性
graphModel: GraphModel
@observable zIndex: number = 0
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/view/edge/BaseEdge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export abstract class BaseEdge<P extends IProps> extends Component<
> {
static isObserved: boolean = false
static extendsKey?: string
mouseUpDrag?: boolean

startTime?: number
contextMenuTime?: number
Expand Down Expand Up @@ -385,13 +386,16 @@ export abstract class BaseEdge<P extends IProps> extends Component<
e.stopPropagation()
this.startTime = new Date().getTime()
}
handleMouseUp = () => {
const { model } = this.props
this.mouseUpDrag = model.isDragging
}
/**
* 不支持重写
*/
handleMouseUp = (e: MouseEvent) => {
handleClick = (e: MouseEvent) => {
if (!this.startTime) return
const time = new Date().getTime() - this.startTime
if (time > 200) return // 事件大于200ms,认为是拖拽。
if (this.mouseUpDrag) return // 如果是拖拽,不触发click事件。
const isRightClick = e.button === 2
if (isRightClick) return
// 这里 IE 11不能正确显示
Expand Down Expand Up @@ -490,6 +494,7 @@ export abstract class BaseEdge<P extends IProps> extends Component<
.join(' ')}
onMouseDown={this.handleMouseDown}
onMouseUp={this.handleMouseUp}
onClick={this.handleClick}
onContextMenu={this.handleContextMenu}
onMouseOver={this.setHoverOn}
onMouseEnter={this.setHoverOn}
Expand Down

0 comments on commit 9b5f3f5

Please sign in to comment.