Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function isBoundsAwareMoveable(element: SModelElement): element is SModelElement & Locateable & BoundsAware {
return isMoveable(element) && isBoundsAware(element);
}
mouseDown(target: SModelElement, event: MouseEvent): Action[] {
this.isMouseDown = true;
const currentChild = findParentByFeature(target, isConfigurableNode);
if (currentChild && currentChild.reparentable && isBoundsAware(currentChild.parent)) {
this.child = currentChild;
this.parentBounds = currentChild.parent.bounds;
}
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`;
}
function drawFeedbackEdgeSource(context: CommandExecutionContext, targetId: string, elementTypeId: string) {
const root = context.root;
const targetChild = root.index.getById(targetId);
if (!targetChild) {
return;
}
const target = findParentByFeature(targetChild, isConnectable);
if (!target || !isBoundsAware(target)) {
return;
}
const edgeEnd = new FeedbackEdgeEnd(target.id, elementTypeId);
edgeEnd.id = feedbackEdgeEndId(root);
edgeEnd.position = { x: target.bounds.x, y: target.bounds.y };
const feedbackEdgeSchema = {
type: 'edge',
id: feedbackEdgeId(root),
sourceId: edgeEnd.id,
targetId: target.id,
opacity: 0.3
};
const feedbackEdge = context.modelFactory.createElement(feedbackEdgeSchema);
function drawFeedbackEdge(context: CommandExecutionContext, sourceId: string, elementTypeId: string) {
const root = context.root;
const sourceChild = root.index.getById(sourceId);
if (!sourceChild) {
return;
}
const source = findParentByFeature(sourceChild, isConnectable);
if (!source || !isBoundsAware(source)) {
return;
}
const edgeEnd = new FeedbackEdgeEnd(source.id, elementTypeId);
edgeEnd.id = feedbackEdgeEndId(root);
edgeEnd.position = { x: source.bounds.x, y: source.bounds.y };
const feedbackEdgeSchema = {
type: 'edge',
id: feedbackEdgeId(root),
sourceId: source.id,
targetId: edgeEnd.id,
opacity: 0.3
};
const feedbackEdge = context.modelFactory.createElement(feedbackEdgeSchema);
mouseMove(target: SModelElement, event: MouseEvent): Action[] {
const root = target.root;
const edgeEnd = root.index.getById(feedbackEdgeEndId(root));
if (!(edgeEnd instanceof FeedbackEdgeEnd) || !edgeEnd.feedbackEdge) {
return [];
}
const edge = edgeEnd.feedbackEdge;
const position = getAbsolutePosition(edgeEnd, event);
const endAtMousePosition = findChildrenAtPosition(target.root, position)
.find(e => isConnectable(e) && e.canConnect(edge, 'target'));
if (endAtMousePosition instanceof SConnectableElement && edge.source && isBoundsAware(edge.source)) {
const anchorComputer = this.anchorRegistry.get(PolylineEdgeRouter.KIND, endAtMousePosition.anchorKind);
const anchor = anchorComputer.getAnchor(endAtMousePosition, center(edge.source.bounds));
if (euclideanDistance(anchor, edgeEnd.position) > 1) {
return [new MoveAction([{ elementId: edgeEnd.id, toPosition: anchor }], false)];
}
} else {
return [new MoveAction([{ elementId: edgeEnd.id, toPosition: position }], false)];
}
return [];
}
}
export function isNonRoutableSelectedBoundsAware(element: SModelElement): element is SelectableBoundsAware {
return isBoundsAware(element) && isSelected(element) && !isRoutable(element);
}