From 98c1ce354f8549dac2c481db1f61c3f1fc517265 Mon Sep 17 00:00:00 2001 From: yuyang Date: Thu, 30 Nov 2023 18:36:03 +0800 Subject: [PATCH 1/2] feat: selection's pointerEvents support function type --- packages/x6-plugin-selection/src/selection.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/x6-plugin-selection/src/selection.ts b/packages/x6-plugin-selection/src/selection.ts index 243b604e422..0b6bf8a7f6a 100644 --- a/packages/x6-plugin-selection/src/selection.ts +++ b/packages/x6-plugin-selection/src/selection.ts @@ -126,7 +126,10 @@ export class SelectionImpl extends View { const { ui, selection, translateBy, snapped } = options const allowTranslating = - (showNodeSelectionBox !== true || pointerEvents === 'none') && + (showNodeSelectionBox !== true || + (typeof pointerEvents === 'string' + ? pointerEvents + : pointerEvents?.(this.cells)) === 'none') && !this.translating && !selection @@ -819,6 +822,7 @@ export class SelectionImpl extends View { 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) @@ -828,7 +832,11 @@ export class SelectionImpl extends View { 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() @@ -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[] From 02218b115530959c19e922161bee885049973245 Mon Sep 17 00:00:00 2001 From: yuyang Date: Wed, 17 Jan 2024 14:47:25 +0800 Subject: [PATCH 2/2] fix: extracting function getPointerEventsValue --- packages/x6-plugin-selection/src/selection.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/x6-plugin-selection/src/selection.ts b/packages/x6-plugin-selection/src/selection.ts index 0b6bf8a7f6a..349e846509a 100644 --- a/packages/x6-plugin-selection/src/selection.ts +++ b/packages/x6-plugin-selection/src/selection.ts @@ -126,10 +126,7 @@ export class SelectionImpl extends View { const { ui, selection, translateBy, snapped } = options const allowTranslating = - (showNodeSelectionBox !== true || - (typeof pointerEvents === 'string' - ? pointerEvents - : pointerEvents?.(this.cells)) === 'none') && + (showNodeSelectionBox !== true || (pointerEvents && this.getPointerEventsValue(pointerEvents) === 'none')) && !this.translating && !selection @@ -810,6 +807,12 @@ export class SelectionImpl extends View { ) } + protected getPointerEventsValue(pointerEvents: 'none' | 'auto' | ((cells: Cell[]) => 'none' | 'auto')) { + return typeof pointerEvents === 'string' + ? pointerEvents + : pointerEvents(this.cells) + } + protected createSelectionBox(cell: Cell) { this.addCellSelectedClassName(cell) @@ -833,9 +836,7 @@ export class SelectionImpl extends View { width: bbox.width, height: bbox.height, pointerEvents: pointerEvents - ? typeof pointerEvents === 'string' - ? pointerEvents - : pointerEvents(this.cells) + ? this.getPointerEventsValue(pointerEvents) : 'auto', }) Dom.appendTo(box, this.container)