import { Observable } from 'rxjs'; import { Injector, Type } from '../di'; import { Renderable } from '../dom'; import { BeforeDestroyEvent } from '../events'; import { ContextType } from '../common'; import { View } from './View'; import { ViewFactory } from './ViewFactory'; import { ViewConfig } from './common'; import { ViewHookExecutor, SizeChanges } from './hooks'; import { ViewFailReason } from './ViewFailReason'; import { CacheStrategy } from './common'; export declare enum ViewContainerStatus { READY = 0, PENDING = 1, FAILED = 2 } export declare enum ViewContainerAttachedStatus { ATTACHED = 0, DETACHED = 1 } export declare const FAILED_RESOLVE: ViewFailReason; export interface ViewContainerReadyOptions { /** * Whether to initialize the component. * @type {boolean} */ init?: boolean; /** * Statuses that tell when the component is ready. * @type {ViewContainerStatus[]} */ when?: ViewContainerStatus[]; /** * When the view transitions to one of these statuses then it will stop listening for status * updates and the observable will complete without the component being emitted as ready. * @type {ViewContainerStatus[]} */ until?: ViewContainerStatus[]; } /** * A container that holds a 1 to 1 relationship with a component instance. This instance * is the main API for a component to interact with the layout framework. * @export * @class ViewContainer * @template T The component type. */ export declare class ViewContainer { /** * This element is the mount point that views can mount to. * The node created by the render method gets recreated when moved * somewhere else in the tree. This element is constant. * @private * @type {HTMLElement} */ private _element; private _component; private _container; private _status; private _destroyed; private _beforeDestroy; private _containerChange; private _containerSource; private _visibilityChanges; private _sizeChanges; private _windowChanges; private _attached; private _initialized; private _componentReady; private _componentInitialized; private _isInitialized; private _retry; private _statusInternal; private _failedReason; private _isAttached; protected _document: Document; protected _injector: Injector; protected _viewHookExecutor: ViewHookExecutor; protected _viewFactory: ViewFactory; protected _viewComponentConfig: any; protected _viewConfig: ViewConfig; /** * A unique identifier for this instance. * @type {number} */ readonly id: number; /** * Notifies that the view is being destroyed. This action is cancellable or can be halted until * an async action is complete. * @see Cancellable * @type {Observable>} */ readonly beforeDestroy: Observable>; /** * Notifies when the view is destroyed. * @type {Observable>} */ readonly destroyed: Observable>; /** * Notifies when the visibility of this view changes. * @type {Observable} */ readonly visibilityChanges: Observable; /** * Notifies when the containing window changes. * @type {Observable} */ readonly windowChanges: Observable; /** * Notifies when the dimensions of this views container has changed. * @type {Observable<{ width: number, height: number }>} */ readonly sizeChanges: Observable<{ width: number; height: number; }>; /** * Notifies when the status of this component changes. * @type {Observable} */ readonly status: Observable; /** * Contains the state of ths views initialized state. * @type {Observable} */ readonly initialized: Observable; /** * Notifies when this container has changed the {@link View} it is associated with. * @type {(Observable)} */ readonly containerChange: Observable; /** * Notifies when the view has become attached. * @type {Observable} */ readonly attached: Observable; /** * Notifies when the view has become detached. * @type {Observable} */ readonly detached: Observable; /** * Notifies when the component is assigned to the container and ready for access. * @type {Observable} */ readonly componentReady: Observable; /** * Notifies when the component is initialized. * @type {Observable} */ readonly componentInitialized: Observable; /** * Emits the current container upon subscription and any other changes. * @type {(Observable)} */ readonly container: Observable; readonly hasComponent: boolean; readonly failedReason: ViewFailReason | null; readonly viewComponentConfig: any; readonly config: ViewConfig; /** * Current width in pixels. * @readonly * @type {number} */ readonly width: number; /** * Current height in pixels. * @readonly * @type {number} */ readonly height: number; /** * The component instance associated with this container. * @readonly * @type {T|null} */ readonly component: T | null; readonly caching: CacheStrategy; /** * The HTML element for this container. * @readonly * @type {HTMLElement} */ readonly element: HTMLElement; readonly view: View | null; /** * Determines whether the view is attached to a Renderable or not. * @readonly * @type {boolean} */ readonly isAttached: boolean; init(): void; /** * Gets a token from this containers injector. Note, this should not be used to grab * parent renderables or any item that can be changed. * @template U The return type. * @param {*} token * @returns {(U|null)} */ get(token: any): U | null; /** * Destroys the container. */ destroy(): void; /** * Whether the container is cacheable. * @param {ContextType} context The current context * @returns {boolean} */ isCacheable(context?: ContextType): boolean; /** * Waits for the component to be ready. If the component is not initialized * it will be initialized. This is important when the view is lazy and hasn't * been shown yet but we need to interact with the component. * @async * @param {{ init?: boolean }} [options={}] * @returns {Promise>} */ ready(options?: ViewContainerReadyOptions): Observable>; /** * Initializes the component. This creates the component. */ initialize(): void; /** * Sets the containing {@link View} for this container. * @param {(View|null)} container * @returns {void} */ setView(container: View | null): 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): U | null; /** * 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): U[]; /** * Queries for a parent renderable for the view. * @template U * @param {(Type | Type[])} Ctor * @returns {(Observable<[ U | null, Observable ]>)} */ queryParent(Ctor: Type | Type[]): Observable; /** * Signals up the tree to make this {@link View} visible. */ makeVisible(): void; /** * Minimizes the view if applicable */ minimize(isMinimized?: boolean): void; /** * Determines whether this renderable is visible. * @returns {boolean} */ isVisible(): boolean; /** * Closes this view. * @param {{ silent?: boolean }} args */ close(args: { silent?: boolean; }): void; /** * Mounts this containers element to the given element. * @param {HTMLElement} element */ mountTo(element: HTMLElement): void; /** * Mounts an element to this containers element. * @param {HTMLElement} element */ mount(element: HTMLElement): void; /** * Sets all the content of this containers element to the given HTML string. * @param {string} html */ mountHTML(html: string): void; /** * Detaches this container. */ detach(): void; /** * Attaches this container. */ attach(): void; fail(reason: ViewFailReason, retry?: Function | null): void; retry(): void; /** * Resolves the container. Note, the component must be created or else an error will be thrown. * @throws Error * @param {{ fromCache?: boolean }} [options={}] * @returns {Promise} */ resolve(options?: { fromCache?: boolean; }): Promise; /** * Triggers a size change event. This doesn't resize the view. This is merely * to force a resize event to a component. This is useful for sizing a component * that has now view attached to it. * @param {SizeChanges} event */ triggerSizeChange(event: SizeChanges): void; /** * Triggers a visibility change event. This is merely * to force a visibility event to a component. * @param {SizeChanges} event */ triggerVisibilityChange(isVisible: boolean): void; /** * Resolves a config property by checking the config on the currently attached container first, * then the config the ViewContainer was created with, then the metadata defined for the component. * @template T * @param {string} path * @returns {(T | null)} */ resolveConfigProperty(path: string): T | null; /** * Invoked when the view renderable is destroyed. * @private */ private _onViewDestroy; /** * Executes a hook on the component. * @private * @param {string} name * @param {...any[]} args * @returns {*} */ private _executeHook; private _onCustomViewHook; /** * Invoked when the component is resolved from the initialization. * @private * @async * @param {T} component * @returns {Promise} */ private _onComponentReady; }