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 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
15 changes: 12 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,7 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {
const { ui, selection, translateBy, snapped } = options

const allowTranslating =
(showNodeSelectionBox !== true || pointerEvents === 'none') &&
(showNodeSelectionBox !== true || (pointerEvents && this.getPointerEventsValue(pointerEvents) === 'none')) &&
!this.translating &&
!selection

Expand Down Expand Up @@ -807,6 +807,12 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {
)
}

protected getPointerEventsValue(pointerEvents: 'none' | 'auto' | ((cells: Cell[]) => 'none' | 'auto')) {
return typeof pointerEvents === 'string'
? pointerEvents
: pointerEvents(this.cells)
}

protected createSelectionBox(cell: Cell) {
this.addCellSelectedClassName(cell)

Expand All @@ -819,6 +825,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 +835,9 @@ export class SelectionImpl extends View<SelectionImpl.EventArgs> {
top: bbox.y,
width: bbox.width,
height: bbox.height,
pointerEvents: this.options.pointerEvents || 'auto',
pointerEvents: pointerEvents
? this.getPointerEventsValue(pointerEvents)
: 'auto',
})
Dom.appendTo(box, this.container)
this.showSelected()
Expand Down Expand Up @@ -978,7 +987,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