UNPKG

@ibyar/core

Version:

Ibyar core, Implements Aurora's core functionality, low-level services, and utilities

175 lines 7.77 kB
import type { MetadataClass } from '@ibyar/decorators'; import type { Type } from '../utils/typeof.js'; import { TemplateRef } from './template-ref.js'; import { EmbeddedViewRef, ViewRef } from './view-ref.js'; import { HTMLComponent } from '../component/custom-element.js'; interface IndexOptions { /** * the index to insert the */ index?: number; /** * the default value is true */ insert?: boolean; } export interface ViewContainerOptions<C> extends IndexOptions { context?: C; } export interface ViewContainerComponentOptions extends IndexOptions { selector?: string; } export interface HTMLElementOptions extends ElementCreationOptions, IndexOptions { } export declare abstract class ViewContainerRef { /** * Anchor element that specifies the location of this container in the containing view. * Each view container can have only one anchor element, and each anchor element * can have only a single view container. * * Root elements of views attached to this container become siblings of the anchor element in * the rendered view. * * Access the `ViewContainerRef` of an element by placing a `Directive` injected * with `ViewContainerRef` on the element, or use a `ViewChild` query. * */ abstract get anchorElement(): Element; /** * Destroys all views in this container. */ abstract clear(): void; /** * Retrieves a view from this container. * @param index The 0-based index of the view to retrieve. * @returns The `ViewRef` instance, or null if the index is out of range. */ abstract get(index: number): ViewRef | undefined; /** * Reports how many views are currently attached to this container. * @returns The number of views. */ abstract get length(): number; /** * Instantiates an embedded view and inserts it * into this container. * @param templateRef The HTML template that defines the view. * @param context The data-binding context of the embedded view, as declared * in the `<ng-template>` usage. * @param index The 0-based index at which to insert the new view into this container. * If not specified, appends the new view as the last entry. * * @returns The `ViewRef` instance for the newly created view. */ abstract createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>; /** * create component by tag name `selector`. * @param selector the tag name for the aurora custom-element * @param options */ abstract createComponent<C extends {}>(selector: string, options?: IndexOptions): C; /** * create component by the aurora custom-element `View` Class * @param viewClass the generated aurora view class * @param options */ abstract createComponent<C extends {}>(viewClass: Type<HTMLComponent<C>>, options?: IndexOptions): C; /** * Instantiates a single component and inserts its host view into this container. * * @param componentType Component Type to use. * @param options An object that contains extra parameters: * * index: the index at which to insert the new component's host view into this container. * If not specified, appends the new view as the last entry. * * selector: the tag name of the new create component that attached with this model class. * Any Model class can have many views with different selectors. * * @returns The new `HTMLComponent` which contains the component instance and the host view. */ abstract createComponent<C extends {}>(componentType: Type<C>, options?: ViewContainerComponentOptions): C; /** * create an HTMLElement by tag name `selector`. * @param selector the tag name for the aurora custom-element * @param options */ abstract createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K]; abstract createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K]; /** * create HTMLElement by View Class reference * @param viewClass the generated aurora view class * @param options */ abstract createElement<C extends HTMLElement>(htmlElementClass: Type<C>, options?: HTMLElementOptions): C; /** * create a text node and insert to the view * @param data * @param options */ abstract createTextNode(data: string, options?: IndexOptions): Text; /** * Inserts a view into this container. * @param viewRef The view to insert. * @param index The 0-based index at which to insert the view. * If not specified, appends the new view as the last entry. * @returns The inserted `ViewRef` instance. * */ abstract insert(viewRef: ViewRef, index?: number): ViewRef; /** * Moves a view to a new location in this container. * @param viewRef The view to move. * @param newIndex The 0-based index of the new location. * @returns The moved `ViewRef` instance. */ abstract move(viewRef: ViewRef, newIndex: number): ViewRef; /** * Returns the index of a view within the current container. * @param viewRef The view to query. * @returns The 0-based index of the view's position in this container, * or `-1` if this container doesn't contain the view. */ abstract indexOf(viewRef: ViewRef): number; /** * Destroys a view attached to this container * @param index The 0-based index of the view to destroy. * If not specified, the last view in the container is removed. */ abstract remove(index?: number): void; /** * Detaches a view from this container without destroying it. * Use along with `insert()` to move a view within the current container. * @param index The 0-based index of the view to detach. * If not specified, the last view in the container is detached. */ abstract detach(index?: number): ViewRef | undefined; /** * set the current views from this * @param views the new `ViewRef` list */ abstract updateViews(views: ViewRef[]): void; } export declare class ViewContainerRefImpl extends ViewContainerRef { private _parent; private _firstComment; private _views; constructor(parent: Element, firstComment: Comment); get anchorElement(): Element; get length(): number; clear(): void; get(index: number): ViewRef | undefined; detach(index?: number): ViewRef | undefined; indexOf(viewRef: EmbeddedViewRef<any>): number; remove(index?: number): void; insert(viewRef: EmbeddedViewRef<any>, index?: number): ViewRef; move(viewRef: EmbeddedViewRef<any>, newIndex: number): ViewRef; createEmbeddedView<C extends {}>(templateRef: TemplateRef, options?: ViewContainerOptions<C>): EmbeddedViewRef<C>; createComponent<C extends {}>(selector: string, options?: IndexOptions): C; createComponent<C extends {}>(viewClass: MetadataClass<HTMLComponent<C>>, options?: IndexOptions): C; createComponent<C extends {}>(componentType: MetadataClass<C>, options?: ViewContainerComponentOptions): C; createElement<K extends keyof HTMLElementTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementTagNameMap[K]; createElement<K extends keyof HTMLElementDeprecatedTagNameMap>(selector: K, options?: HTMLElementOptions): HTMLElementDeprecatedTagNameMap[K]; createTextNode(data: string, options?: IndexOptions): Text; updateViews(views: ViewRef[]): void; } export {}; //# sourceMappingURL=view-container-ref.d.ts.map