Skip to content

Commit

Permalink
feat: selection's pointerEvents support function type (#4067)
Browse files Browse the repository at this point in the history
* feat: selection's pointerEvents support function type

* fix: extracting function getPointerEventsValue

---------

Co-authored-by: yuyang <[email protected]>
  • Loading branch information
damnright and yuyang authored Jan 24, 2024
1 parent a769284 commit 6decb75
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 6decb75

Please sign in to comment.