How to use the sprotty/lib.isBoundsAware function in sprotty

To help you get started, we’ve selected a few sprotty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / change-bounds / model.ts View on Github external
export function isBoundsAwareMoveable(element: SModelElement): element is SModelElement & Locateable & BoundsAware {
    return isMoveable(element) && isBoundsAware(element);
}
github eclipsesource / graphical-lsp / client / packages / glsp-sprotty / src / features / tools / change-container.tool.ts View on Github external
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 [];
    }
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / command-palette / command-palette.ts View on Github external
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`;
    }
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / tool-feedback / edge-edit-tool-feedback.ts View on Github external
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);
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / tool-feedback / creation-tool-feedback.ts View on Github external
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);
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / features / tool-feedback / creation-tool-feedback.ts View on Github external
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 [];
    }
}
github eclipsesource / graphical-lsp / client / packages / sprotty-client / src / utils / smodel-util.ts View on Github external
export function isNonRoutableSelectedBoundsAware(element: SModelElement): element is SelectableBoundsAware {
    return isBoundsAware(element) && isSelected(element) && !isRoutable(element);
}