Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): 修复笔记本触摸板点击边事件失效 #1940

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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