UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

231 lines 13.9 kB
/******************************************************************************** * Copyright (c) 2019-2024 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { BoundsAware, EdgeRouterRegistry, ElementAndBounds, ElementAndRoutingPoints, FluentIterable, GModelElement, GModelElementSchema, GParentElement, GRoutableElement, GRoutingHandle, Locateable, ModelIndexImpl, Point, RoutedPoint, Selectable, TypeGuard } from '@eclipse-glsp/sprotty'; import { ResizeHandleLocation } from '../features/change-bounds/model'; /** * Helper type to represent a filter predicate for {@link GModelElement}s. This is used to retrieve * elements from the {@link ModelIndexImpl} that also conform to a second type `T`. Its mainly used for * retrieving elements that also implement a certain model features (e.g. selectable) */ export type ModelFilterPredicate<T> = (modelElement: GModelElement) => modelElement is GModelElement & T; /** * Retrieves all elements from the given {@link ModelIndexImpl} that match the given {@link ModelFilterPredicate} * @param index The {@link ModelIndexImpl}. * @param predicate The {@link ModelFilterPredicate} that should be used. * @returns A {@link FluentIterable} of all indexed element that match the predicate * (correctly casted to also include the additional type of the predicate). */ export declare function filter<T>(index: ModelIndexImpl, predicate: ModelFilterPredicate<T>): FluentIterable<GModelElement & T>; /** * Retrieves all elements from the given {@link ModelIndexImpl} that match the given {@link ModelFilterPredicate} and executes * the given runnable for each element of the result set. * @param index The {@link ModelIndexImpl}. * @param predicate The {@link ModelFilterPredicate} that should be used. * @param runnable The runnable that should be executed for each matching element. */ export declare function forEachElement<T>(index: ModelIndexImpl, predicate: ModelFilterPredicate<T>, runnable: (modelElement: GModelElement & T) => void): void; /** * Retrieves an array of all elements that match the given {@link ModelFilterPredicate} from the given {@link ModelIndexImpl}. * @param index The {@link ModelIndexImpl}. * @param predicate The {@link ModelFilterPredicate} that should be used. * @returns An array of all indexed element that match the predicate * (correctly casted to also include the additional type of the predicate). */ export declare function getMatchingElements<T>(index: ModelIndexImpl, predicate: ModelFilterPredicate<T>): (GModelElement & T)[]; /** * Invokes the given model index to retrieve the corresponding model elements for the given set of ids. Ids that * have no corresponding element in the index will be ignored. * @param index THe model index. * @param elementsIDs The element ids. * @param guard Optional typeguard. If defined only elements that match the guard will be returned. * @returns An array of the model elements that correspond to the given ids and filter predicate. */ export declare function getElements<S extends GModelElement>(index: ModelIndexImpl, elementsIDs: string[], guard?: TypeGuard<S>): S[]; /** * Retrieves the amount of currently selected elements in the given {@link ModelIndexImpl}. * @param index The {@link ModelIndexImpl}. * @returns The amount of selected elements. */ export declare function getSelectedElementCount(index: ModelIndexImpl): number; /** * Helper function to check wether an any element is selected in the given {@link ModelIndexImpl}. * @param index The {@link ModelIndexImpl}. * @returns `true` if at least one element is selected, `false` otherwise. */ export declare function hasSelectedElements(index: ModelIndexImpl): boolean; /** * Helper function to check wether an element is defined. Can be used as {@link ModelFilterPredicate}. * @param element The element that should be checked. * @returns the type predicate for `T` */ export declare function isNotUndefined<T>(element: T | undefined): element is T; /** * Adds a set of css classes to the given {@link GModelElement}. * @param element The element to which the css classes should be added. * @param cssClasses The set of css classes as string array. */ export declare function addCssClasses(element: GModelElement, cssClasses: string[]): void; export declare function addCssClasses(element: GModelElement, ...cssClasses: string[]): void; /** * Removes a set of css classes from the given {@link GModelElement}. * @param element The element from which the css classes should be removed. * @param cssClasses The set of css classes as string array. */ export declare function removeCssClasses(element: GModelElement, cssClasses: string[]): void; export declare function removeCssClasses(element: GModelElement, ...cssClasses: string[]): void; /** * Adds a css classs to a set of {@link GModelElement}s. * * @param elements The elements to which the css class should be added. * @param cssClass The css class to add. */ export declare function addCssClassToElements(elements: GModelElement[], ...cssClasses: string[]): void; /** * Removes a css class from a set of {@link GModelElement}s. * @param elements The elements from which the css class should be removed. * @param cssClass The css class to remove. */ export declare function removeCssClassOfElements(elements: GModelElement[], ...cssClasses: string[]): void; /** * Toggles a css class on a {@link GModelElement} based on the given toggle flag. */ export declare function toggleCssClass(element: GModelElement, cssClass: string, toggle: boolean): void; export declare function isNonRoutableSelectedMovableBoundsAware(element: GModelElement): element is SelectableBoundsAware; export declare function isNonRoutableMovableBoundsAware(element: GModelElement): element is BoundsAwareModelElement; /** * A typeguard function to check wether a given {@link GModelElement} implements the {@link BoundsAware} model feature, * the {@link Selectable} model feature and is actually selected. In addition, the element must not be a {@link GRoutableElement}. * @param element The element to check. * @returns A type predicate indicating wether the element is of type {@link SelectableBoundsAware}. */ export declare function isNonRoutableSelectedBoundsAware(element: GModelElement): element is SelectableBoundsAware; /** * A typeguard function to check wether a given {@link GModelElement} implements the {@link BoundsAware} model feature. * In addition, the element must not be a {@link GRoutableElement}. * @param element The element to check. * @returns A type predicate indicating wether the element is of type {@link BoundsAwareModelElement}. */ export declare function isNonRoutableBoundsAware(element: GModelElement): element is BoundsAwareModelElement; /** * A type guard function to check wether a given {@link GModelElement} is a {@link GRoutableElement}. * @param element The element to check. * @returns A type predicate indicating wether the element is a {@link GRoutableElement}. */ export declare function isRoutable<T extends GModelElement>(element: T): element is T & GRoutableElement; /** * A typeguard function to check wether a given {@link GModelElement} is a {@link SRoutingHandle}. * @param element The element to check. * @returns A type predicate indicating wether the element is a {@link SRoutingHandle} */ export declare function isRoutingHandle(element: GModelElement | undefined): element is GRoutingHandle; /** * A typeguard function to check wether a given {@link GModelElement} implements the {@link Selectable} model feature and * the {@link BoundsAware} model feature. * @returns A type predicate indicating wether the element is of type {@link SelectableBoundsAware}. */ export declare function isSelectableAndBoundsAware(element: GModelElement): element is SelectableBoundsAware; /** * Union type to describe {@link GModelElement}s that implement the {@link Selectable} feature. */ export type SelectableElement = GModelElement & Selectable; /** * Union type to describe {@link GModelElement}s that implement the {@link Selectable} and {@link BoundsAware} feature. */ export type SelectableBoundsAware = SelectableElement & BoundsAware; /** * Union type to describe {@link GModelElement}s that implement the {@link BoundsAware} feature. */ export type BoundsAwareModelElement = GModelElement & BoundsAware; /** * Union type to describe {@link GModelElement}s that implement the {@link Locateable} feature. */ export type MoveableElement = GModelElement & Locateable; export interface Resizable extends BoundsAware, Selectable { } export interface ResizableModelElement extends GParentElement, Resizable { resizeLocations?: ResizeHandleLocation[]; } /** * Helper function to translate a given {@link GModelElement} into its corresponding {@link ElementAndBounds} representation. * @param element The element to translate. * @returns The corresponding {@link ElementAndBounds} for the given element. */ export declare function toElementAndBounds(element: BoundsAwareModelElement): ElementAndBounds; /** * Helper function to translate a given {@link GRoutableElement} into its corresponding * {@link ElementAndRoutingPoints} representation. * @param element The element to translate. * @returns The corresponding {@link ElementAndRoutingPoints} for the given element. */ export declare function toElementAndRoutingPoints(element: GRoutableElement): ElementAndRoutingPoints; /** All routing points. */ export declare const ALL_ROUTING_POINTS: undefined; /** Pure routing point data kinds. */ export declare const ROUTING_POINT_KINDS: string[]; /** Pure route data kinds. */ export declare const ROUTE_KINDS: string[]; /** * Helper function to calculate the {@link ElementAndRoutingPoints} for a given {@link GRoutableElement}. * If client layout is activated, i.e., the edge routing registry is given and has a router for the element, then the routing * points from the calculated route are used, otherwise we use the already specified routing points of the {@link GRoutableElement}. * @param element The element to translate. * @param routerRegistry the edge router registry. * @returns The corresponding {@link ElementAndRoutingPoints} for the given element. */ export declare function calcElementAndRoutingPoints(element: GRoutableElement, routerRegistry?: EdgeRouterRegistry): ElementAndRoutingPoints; /** * Helper function to calculate the route for a given {@link GRoutableElement}. * If client layout is activated, i.e., the edge routing registry is given and has a router for the element, then the points * from the calculated route are used, otherwise we use the already specified routing points of the {@link GRoutableElement}. * @param element The element to translate. * @param routerRegistry the edge router registry. * @returns The corresponding route for the given element. */ export declare function calcElementAndRoute(element: GRoutableElement, routerRegistry?: EdgeRouterRegistry): ElementAndRoutingPoints; /** * Helper function to calculate the route for a given {@link GRoutableElement} by filtering duplicate points. * @param element The element to translate. * @param routerRegistry the edge router registry. * @param pointKinds the routing point kinds that should be considered. * @param tolerance the tolerance applied to a point's coordinates to determine duplicates. * @returns The corresponding route for the given element. */ export declare function calcRoute(element: GRoutableElement, routerRegistry: EdgeRouterRegistry, pointKinds?: string[] | undefined, tolerance?: number): RoutedPoint[] | undefined; /** * Convenience function to retrieve the model element type from a given input. The input * can either be a {@link GModelElement}, {@link GModelElementSchema} or a string. * @param input The type input. * @returns The corresponding model type as string. */ export declare function getElementTypeId(input: GModelElement | GModelElementSchema | string): string; export declare function findTopLevelElementByFeature<T>(element: GModelElement, predicate: (t: GModelElement) => t is GModelElement & T, skip?: (t: GModelElement) => boolean): (GModelElement & T) | undefined; export declare function calculateDeltaBetweenPoints(target: Point, source: Point, element: GModelElement): Point; export declare function isVisibleOnCanvas(model: BoundsAwareModelElement): boolean; export declare function getDescendantIds(element?: GModelElement, skip?: (t: GModelElement) => boolean): string[]; /** * Returns a filter function that checks if the given element is not a descendant of any of the given elements. * * @param elements The elements that the element should not be a descendant of. * @returns the filter function */ export declare function isNotDescendantOfAnyElement<T extends GModelElement>(elements: FluentIterable<T>): (element: T) => boolean; /** * Removes any descendants of the given elements from the given elements. * @param elements The elements to filter. * @returns the filtered elements */ export declare function removeDescendants<T extends GModelElement>(elements: FluentIterable<T>): FluentIterable<T>; //# sourceMappingURL=gmodel-util.d.ts.map