Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected setActiveResizeElement(target: SModelElement): boolean {
// check if we have a selected, moveable element (multi-selection allowed)
const moveableElement = findParentByFeature(target, isBoundsAwareMoveable);
if (isSelected(moveableElement)) {
// only allow one element to have the element resize handles
this.activeResizeElementId = moveableElement.id;
this.tool.dispatchFeedback([new ShowChangeBoundsToolResizeFeedbackAction(this.activeResizeElementId)]);
return true;
}
return false;
}
mouseUp(target: SModelElement, event: MouseEvent): Action[] {
super.mouseUp(target, event);
if (!this.hasPositionDelta()) {
this.resetPosition();
return [];
}
// no further bound changing, simply send the latest data to the server using a single change bounds action for all relevant elements
const actions: Action[] = [];
if (this.activeResizeHandle) {
// An action. Resize, not move.
const resizeElement = findParentByFeature(this.activeResizeHandle, isResizable);
if (this.isActiveResizeElement(resizeElement)) {
createChangeBoundsAction(resizeElement).forEach(action => actions.push(action));
}
} else {
// Bounds... Change Bounds.
const newBounds: ElementAndBounds[] = [];
forEachElement(target, isNonRoutableSelectedBoundsAware, element =>
createElementAndBounds(element).forEach(bounds => newBounds.push(bounds)));
if (newBounds.length > 0) {
actions.push(new ChangeBoundsOperationAction(newBounds));
}
}
this.resetPosition();
return actions;
}
mouseOver(target: SModelElement, event: MouseEvent): Action[] {
if (this.child && !this.inBounds(event)) {
const currentContainer = findParentByFeature(target, isConfigurableNode);
if (!this.container || currentContainer !== this.container) {
this.container = currentContainer;
const feedback = this.reparentAllowed()
? new ApplyCursorCSSFeedbackAction(CursorCSS.CHANGE_CONTAINER) :
new ApplyCursorCSSFeedbackAction(CursorCSS.OPERATION_NOT_ALLOWED);
this.tool.dispatchFeedback([feedback]);
}
}
return [];
}
private inBounds(event: MouseEvent): boolean {
protected updatePosition(target: SModelElement, event: MouseEvent): boolean {
if (this.lastDragPosition) {
const viewport = findParentByFeature(target, isViewport);
const zoom = viewport ? viewport.zoom : 1;
const dx = (event.pageX - this.lastDragPosition.x) / zoom;
const dy = (event.pageY - this.lastDragPosition.y) / zoom;
this.positionDelta = { x: dx, y: dy };
this.lastDragPosition = { x: event.pageX, y: event.pageY };
return true;
}
return false;
}
mouseDown(target: SModelElement, event: MouseEvent): Action[] {
const result: Action[] = [];
if (event.button === 0) {
const routingHandle = findParentByFeature(target, isRoutingHandle);
if (routingHandle !== undefined) {
result.push(new SwitchRoutingModeAction([target.id], []));
this.lastDragPosition = { x: event.pageX, y: event.pageY };
} else {
this.lastDragPosition = undefined;
}
this.hasDragged = false;
}
return result;
}
private updatePosition(target: SModelElement, event: MouseEvent) {
if (this.lastDragPosition) {
const viewport = findParentByFeature(target, isViewport);
const zoom = viewport ? viewport.zoom : 1;
const dx = (event.pageX - this.lastDragPosition.x) / zoom;
const dy = (event.pageY - this.lastDragPosition.y) / zoom;
this.positionDelta = { x: this.positionDelta.x + dx, y: this.positionDelta.y + dy };
this.lastDragPosition = { x: event.pageX, y: event.pageY };
}
}
mouseDown(target: SModelElement, event: MouseEvent): (Action | Promise)[] {
if (event.button === 2 && this.contextMenuService && this.menuProvider) {
const mousePosition = { x: event.x, y: event.y };
let isTargetSelected = false;
const selectableTarget = findParentByFeature(target, isSelectable);
if (selectableTarget) {
isTargetSelected = selectableTarget.selected;
selectableTarget.selected = true;
}
const restoreSelection = () => { if (selectableTarget) selectableTarget.selected = isTargetSelected; };
Promise.all([this.contextMenuService(), this.menuProvider.getItems(target.root, mousePosition)])
.then(([menuService, menuItems]) => menuService.show(menuItems, mousePosition, restoreSelection));
}
return [];
}
}
protected updatePosition(selectedElements: SModelElement[]) {
let x = this.xOffset;
let y = this.yOffset;
if (selectedElements.length === 1) {
const firstElement = selectedElements[0];
if (isBoundsAware(firstElement)) {
const viewport = findParentByFeature(firstElement, isViewport);
if (viewport) {
x += (firstElement.bounds.x - viewport.scroll.x) * viewport.zoom;
y += (firstElement.bounds.y - viewport.scroll.y) * viewport.zoom;
} else {
x += firstElement.bounds.x;
y += firstElement.bounds.y;
}
}
}
this.containerElement.style.left = `${x}px`;
this.containerElement.style.top = `${y}px`;
this.containerElement.style.width = `${this.defaultWidth}px`;
}