UNPKG

sprotty

Version:

A next-gen framework for graphical views

112 lines 4.62 kB
/******************************************************************************** * Copyright (c) 2017-2024 TypeFox 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 { interfaces } from 'inversify'; import { VNode } from 'snabbdom'; import { InstanceRegistry } from '../../utils/registry'; import { SModelElementImpl, SModelRootImpl, SParentElementImpl } from '../model/smodel'; import { CustomFeatures } from '../model/smodel-factory'; import { Point } from 'sprotty-protocol'; import { ILogger } from '../../utils/logging'; /** * Arguments for `IView` rendering. */ export interface IViewArgs { parentArgs?: IViewArgs; [key: string]: any; } /** * Searches for the property specified in `key` in the specified `args`, * including its direct or indirect `IRenderingArgs#parentArgs`. * * @param arg the rendering arguments. * @param key the key to search for. * @returns the found value or `undefined. */ export declare function findArgValue<T>(arg: IViewArgs | undefined, key: string): T | undefined; /** * Base interface for the components that turn GModelElements into virtual DOM elements. */ export interface IView<A extends IViewArgs = {}> { render(model: Readonly<SModelElementImpl>, context: RenderingContext, args?: A): VNode | undefined; } /** * Indicates the target of the view rendering. `main` is the actually visible diagram, * `popup` is the mouse hover popup, and `hidden` is for computing element bounds prior * to the main rendering. */ export type RenderingTargetKind = 'main' | 'popup' | 'hidden'; /** * Bundles additional data that is passed to views for VNode creation. */ export interface RenderingContext { readonly viewRegistry: ViewRegistry; readonly targetKind: RenderingTargetKind; readonly parentArgs?: IViewArgs; decorate(vnode: VNode, element: Readonly<SModelElementImpl>): VNode; renderElement(element: Readonly<SModelElementImpl>): VNode | undefined; renderChildren(element: Readonly<SParentElementImpl>, args?: IViewArgs): VNode[]; } /** * Used to bind a model element type to a view factory in the ViewRegistry. */ export interface ViewRegistration { type: string; factory: () => IView; isOverride?: boolean; } export type ViewRegistrationFactory = () => ViewRegistration; /** * Allows to look up the IView for a given SModelElement based on its type. */ export declare class ViewRegistry extends InstanceRegistry<IView> { protected logger: ILogger; constructor(registrations: ViewRegistration[]); protected registerDefaults(): void; missing(key: string): IView; } /** * Combines `registerModelElement` and `configureView`. */ export declare function configureModelElement(context: { bind: interfaces.Bind; isBound: interfaces.IsBound; }, type: string, modelConstr: new () => SModelElementImpl, viewConstr: interfaces.ServiceIdentifier<IView>, features?: CustomFeatures): void; export declare function overrideModelElement(context: { bind: interfaces.Bind; isBound: interfaces.IsBound; }, type: string, modelConstr: new () => SModelElementImpl, viewConstr: interfaces.ServiceIdentifier<IView>, features?: CustomFeatures): void; /** * Utility function to register a view for a model element type. */ export declare function configureView(context: { bind: interfaces.Bind; isBound: interfaces.IsBound; }, type: string, constr: interfaces.ServiceIdentifier<IView>, isOverride?: boolean): void; /** * This view is used when the model is the EMPTY_ROOT. */ export declare class EmptyView implements IView { render(model: SModelRootImpl, context: RenderingContext): VNode; } /** * This view is used when no view has been registered for a model element type. */ export declare class MissingView implements IView { private static positionMap; render(model: Readonly<SModelElementImpl>, context: RenderingContext): VNode; getPostion(type: string): Point; } //# sourceMappingURL=view.d.ts.map