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

feat: selection's pointerEvents support function type #4067

Merged
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions packages/x6-plugin-selection/src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {
const { ui, selection, translateBy, snapped } = options

const allowTranslating =
(showNodeSelectionBox !== true || pointerEvents === 'none') &&
(showNodeSelectionBox !== true ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不好意思,这么久才来 review 代码,注意到两个地方都有相似的判断,可以提取成一个函数。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okk

(typeof pointerEvents === 'string'
? pointerEvents
: pointerEvents?.(this.cells)) === 'none') &&
!this.translating &&
!selection

Expand Down Expand Up @@ -819,6 +822,7 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {

const className = this.boxClassName
const box = document.createElement('div')
const pointerEvents = this.options.pointerEvents
Dom.addClass(box, className)
Dom.addClass(box, `${className}-${cell.isNode() ? 'node' : 'edge'}`)
Dom.attr(box, 'data-cell-id', cell.id)
Expand All @@ -828,7 +832,11 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {
top: bbox.y,
width: bbox.width,
height: bbox.height,
pointerEvents: this.options.pointerEvents || 'auto',
pointerEvents: pointerEvents
? typeof pointerEvents === 'string'
? pointerEvents
: pointerEvents(this.cells)
: 'auto',
})
Dom.appendTo(box, this.container)
this.showSelected()
Expand Down Expand Up @@ -978,7 +986,7 @@ export namespace SelectionImpl {
rubberEdge?: boolean

// Whether to respond event on the selectionBox
pointerEvents?: 'none' | 'auto'
pointerEvents?: 'none' | 'auto' | ((cells: Cell[]) => 'none' | 'auto')

// with which mouse button the selection can be started
eventTypes?: SelectionEventType[]
Expand Down
Loading