import { VNode } from 'snabbdom/vnode'; import { PartialObserver, Subscription, Observable, Subject } from 'rxjs'; import { Type, Injector, ProviderArg } from '../di'; import { EventBus, BusEvent } from '../events'; import { RenderableArg, ContextType } from '../common'; import { RenderableArea } from './RenderableArea'; import { Renderer } from './Renderer'; import { RenderableConfig } from './common'; import { BaseSerializerArg } from '../serialization'; export interface BaseModificationArgs { /** * Whether to invoke the render cycle. This is useful for * delaying the render cycle to a later time. * @type {boolean} */ render?: boolean; } /** * Args used when removing a child renderable. * @export * @interface RemoveChildArgs * @extends {BaseModificationArgs} */ export interface RemoveChildArgs extends BaseModificationArgs { /** * Whether to destroy the child being removed. * @type {boolean} */ destroy?: boolean; /** * The context the child is being destroyed. * @type {ContextType} */ context?: ContextType; } /** * Args used when adding a child renderable. * @export * @interface AddChildArgs * @extends {BaseModificationArgs} */ export interface AddChildArgs extends BaseModificationArgs { /** * What index to add the child renderable to. If not provided then * it will be pushed. * @type {number} */ index?: number; /** * Whether to invoke a resize of this renderable. * @type {boolean} */ resize?: boolean; } /** * Contains data about the destruction of a view. * @export * @interface RenderableDestroyContext */ export interface RenderableDestroyContext { type: ContextType; } /** * Contains data about the destruction of a renderable. * @export * @interface RenderableDestroyedContext * @template T */ export interface RenderableDestroyedContext { context: ContextType; renderable: T; } /** * The base renderable that all other renderables extend from. * @export * @abstract * @class Renderable */ export declare abstract class Renderable { /** * Notifies when this renderable is destroyed. * @type {Observable} */ destroyed: Observable>; /** * Notifies when the container of this renderable changes. * @type {(Observable)} */ containerChange: Observable; tags: Set; protected _eventBus: EventBus; protected _width: number; protected _height: number; protected _isDestroyed: boolean; protected _uid: number; protected _container: Renderable | null; protected _destroyed: Subject>; protected _containerChange: Subject; protected _contentItems: Renderable[]; protected _renderer: Renderer; protected _injector: Injector; protected _config: C | null; constructor(); /** * This renderables container or null if none. * @readonly * @type {(Renderable|null)} */ readonly container: Renderable | null; /** * This renderables width in pixels. * @readonly * @type {number} */ readonly width: number; /** * This renderables height in pixels. * @readonly * @type {number} */ readonly height: number; /** * This renderables page offset x. * @readonly * @type {number} */ readonly offsetX: number; /** * This renderables page offset y. * @readonly * @type {number} */ readonly offsetY: number; /** * Whether this renderable is destroyed. * @readonly * @type {boolean} */ readonly isDestroyed: boolean; /** * A unique identifier for this renderable. * @readonly * @type {number} */ readonly uid: number; /** * The amount of content items belonging to this renderable. * @readonly * @type {number} */ readonly length: number; /** * The injector used to create this renderable. * @readonly * @type {Injector} */ readonly injector: Injector; /** * Creates this renderables VNode for diffing against the previous VNode state. * @abstract * @returns {VNode} */ abstract render(): VNode; /** * Invoked when the Injector has been assigned and ready for use. */ initialize(): void; /** * Sets this components size and triggers it's childrens sizing. */ resize(): void; /** * Returns this renderables children renderables. This differs * from content items as children should contain all renderables * we want as part of the render cycle. * @returns {Renderable[]} */ getChildren(): Renderable[]; /** * Determines whether this renderable is visible. * @returns {boolean} */ isVisible(): boolean; /** * Destroys this renderable and all it's children. * @returns {void} */ destroy(context: RenderableDestroyContext): void; /** * Gets this renderables parent or any parent that is * an instance of the passed in constructor. If non is found * then null is returned. * @template T The constructor type. * @param {Type} [Ctor] * @returns {(T|null)} */ getParent(Ctor?: Type | Type[]): T | null; /** * Creates an Observable that emits when the parent matching renderable changes. * @template T * @param {Type} Ctor * @returns {(Observable)} */ queryParent(Ctor: Type | Type[]): Observable; /** * Gets this renderables parents or any parents that are * an instance of the passed in constructor. * @template T The constructor type. * @param {Type} [Ctor] * @returns {(T|null)} */ getParents(Ctor?: Type | Type[]): T[]; /** * Sets the container of this renderable. * @param {(Renderable|null)} container */ setContainer(container: Renderable | null): void; /** * Subscribes to a BusEvent. * @template T The event type. * @param {Type} Event * @param {PartialObserver|function(event: T)} observer * @returns {Subscription} */ subscribe>(Event: Type, observer: PartialObserver | ((event: T) => void)): Subscription; /** * Emits a BusEvent on this renderable. * @template T The event type. * @param {T} event */ emit>(event: T): void; /** * Emits a BusEvent down to all descendants recursively. * Propagation can be stopped by any descending renderable. * @template T The event type. * @param {T} event */ emitDown>(event: T): void; /** * Emits a BusEvent up to all parents recursively. * Propagation can be stopped by any parent renderable. * @template T The event type. * @param {T} event */ emitUp>(event: T): void; /** * Gets all descendants of this renderable recursively. * @returns {Renderable[]} */ getDescendants(): Renderable[]; /** * Replaces a content item on this renderable with another content item. * @param {Renderable} item * @param {Renderable} withItem * @param {RemoveChildArgs} [options={}] */ replaceChild(item: Renderable, withItem: Renderable, options?: RemoveChildArgs): void; /** * Adds a child item to this renderable. * @param {Renderable} item * @param {AddChildArgs} [options={}] */ addChild(item: Renderable, options?: AddChildArgs): void; /** * Removes a content item from this renderable. * @param {Renderable} item * @param {RemoveChildArgs} [options={}] */ removeChild(item: Renderable, options?: RemoveChildArgs): void; /** * Removes this item from it's parent. If there is no * parent then this renderable will just be destroyed. */ remove(context?: ContextType): void; /** * Gets the index of a content renderable. * @param {Renderable} item * @returns {number} */ getIndexOf(item: Renderable): number; /** * Gets a content renderable at an index. * @param {number} index * @returns {(Renderable|null)} */ getAtIndex(index: number): Renderable | null; /** * Creates an Observable scoped to a specific event type. * @template T The event type. * @param {Type} Event * @returns {Observable} */ scope>(Event: Type): Observable; /** * Whether a renderable is a descendant of this renderable. * @param {Renderable} item * @returns {boolean} */ contains(item: Renderable): boolean; /** * Whether this renderable is a descendant of another renderable. * @param {Renderable} item * @returns {boolean} */ isContainedWithin(item: Renderable): boolean; /** * Gets the renderable area of this renderable. * @returns {RenderableArea} */ getArea(): RenderableArea; /** * Creates a child renderable using this renderable as it's container. * @template T * @param {RenderableArg} renderable * @param {ProviderArg[]} [providers=[]] * @returns {T} */ createChild(renderable: RenderableArg, providers?: ProviderArg[]): T; /** * Handles any cleanup from a drop. */ handleDropCleanup(): void; getMinimizedSize(): number; getRenderableChildren(): Renderable[]; /** * Returns the active leaf nodes of the render tree from this node. Basically * the node at the end of the tree. * @returns {Renderable} */ getLeafNodes(): Renderable[]; /** * Returns a serializer, serializer class or a configured serializer specifically for this renderable. * @returns {(BaseSerializerArg | null)} */ getSerializer(): BaseSerializerArg | null; /** * Whether this renderable can be dropped on. * @param {Renderable} target * @returns {boolean} */ isDroppable(target: Renderable): boolean; getHeightForChild(): number; getWidthForChild(): number; isRenderable(): boolean; getActiveWindow(): Window | null; protected _matchesRenderable(instance: T, query: Type | Type[]): boolean; }