import { ViewContainerRef, ComponentFactoryResolver, ComponentRef } from '@angular/core'; import { FormArray, FormGroup } from '@angular/forms'; import { Params } from '../../core/utils/helpers'; import { GetViewContainerDirective } from '../../core/utils/get-view-container.directive'; import { FormSection, FormFieldContent, FormFieldControl } from '../form-field.control'; /** * A base interface that represents the content of a `ContainerControl`. */ export interface ContainerContent extends FormFieldContent { /** * Returns an array of controls that represents the `ContainerControl`'s child controls that are * stored in the `content.formSection`; that is, `content.containerControlChildren` and `content.formSection` * have the same length. * It is always set internally. * By default, its value is `[]`. */ containerControlChildren?: any[]; /** * Returns the `FormSection` that tracks the value and validity state of the internal * child controls that contains this control. * Implementation notes: * - Represents the `FormGroup` or `FormArray` that contains the child controls. * - The `content.containerControlChildren` and `content.formSection` have the same length. * - It must be specified; otherwise, an exception is thrown. */ formSection?: FormSection; /** * Returns an array of contents that represents the `ContainerControl`'s child controls that are * stored in the `ViewContainer`; that is, `content.formSectionContent` and container's `ViewContainer` * have the same length. * Implementation notes: * - It must be specified, and must have at least one element; otherwise, an exception is thrown. * - If the `content.formSection` field represents a `FormArray`, then the `name` field * of all elements in the `content.formSectionContent` array represents the position * in the array like string. */ formSectionContent?: Params[]; /** * Returns true if the container control has a dynamic length, that is, the `content.formSection` field * represents a `FormArray` and its length is not fixed; otherwise, false. * This field has sense only when the `content.formSection` field represents a `FormArray`. * By default, its value is `true`. */ isDynamic?: boolean; } /** * Represents the base abstract class for a control that contains one or more controls. */ export declare abstract class ContainerControl extends FormFieldControl { /** * Returns a `FormGroup` by default. * Its value is empty object, and does not have validators. */ static getFormGroupByDefault(): FormGroup; /** * Returns a `FormArray` by default. * Its value is empty array, and does not have validators. */ static getFormArrayByDefault(): FormArray; /** * Input field that contains the content of this class. */ content: ContainerContent; /** * Returns the helper directive to mark valid insertion point in the `ContainerControl`'s template. */ protected _componentHost: GetViewContainerDirective; /** * Returns the view container of the element that will host the child components in the `ContainerControl`'s template. * This field can only be assigned in the `ContainerControl` class. * The `content.formSectionContent` and container's `_viewContainerRef` have the same length. */ protected _viewContainerRef: ViewContainerRef; /** * Returns the factory for a given component type. * This field can only be assigned in the `ContainerControl` class. */ protected _componentFactoryResolver: ComponentFactoryResolver; /** * Returns the component created by a `ComponentFactory`. * For only internal use by the `createChildComponent` method. */ protected _cr: ComponentRef; /** * Returns true if the container control is a `FormArray`, that is, the `content.formSection` field * represents a `FormArray`; otherwise, false. * By default, its value is `false`. */ private _isFormArray; /** * If the `content.formSection` represents a `FormArray`, then this field returns * a pattern content that is `content.formSectionContent` value; otherwise, returns `undefined`. * It is shared among controls. * It is used for adding a new element in the `content.formSectionContent`, that is, * for adding a new control in the `FormArray`. * By default, its value is `[]`. */ private _formArrayPatternContent; /** * If the `content.formSection` represents a `FormArray`, then this field returns * a pattern value that is a copy of one value that can contain the `content.value` array, and sets all * its properties/values of built-in type to `undefined`; otherwise, returns `undefined`. * It is used for adding a new element in the `content.formSectionContent`, that is, * for adding a new control in the `FormArray`. * By default, its value is `undefined`. */ private _formArrayPatternValue; /** * Returns the current `FormArray` length. * This field has sense only when the `content.formSection` field represents a `FormArray`. * By default, its value is `0`. */ private _formArrayLength; /** * Constructs a new instance of this class. */ constructor(); /** * Initializes the `content` input property. * @param label The default label to use. It is used if the `content.label` is not specified. * @param placeholder It is NOT used here. Fix that. */ protected init(label: string, placeholder?: string): void; /** * Initializes the `content.formSectionContent` array correctly depending on the `content.value`. * In this case, `content.value` is an array. For each element in the `content.value`, a cloning * is done to the `_formArrayPatternContent` array, and it is added in the `content.formSectionContent`; * therefore one element is added in the `content.formSection` `FormArray`. */ protected initFormSectionContentToFormArray(): void; /** * Sets the parent control to its children. */ protected setParentToChildren(): void; /** * Sets the parent control to one child. * @param ffc The child to set the parent control. */ protected setParentToChild(ffc: FormFieldContent): void; /** * Returns a new value that is created following the `_formArrayPatternContent` structure. * It also sets all its properties/values of built-in type to `undefined`. * It creates the value smartly depending on the type of content. * It creates in deep until the next `FormArray`, then the next `FormArray` creates in deep until the next `FormArray`, and so on. * It is the first time that the `_formArrayPatternContent` is travelled, therefore the `createValueToUndefined` method does verifications. */ protected createValueToUndefined(): any; private _createValueToUndefined; /** * Initializes and returns a clone of the `_formArrayPatternContent` array correctly * depending on the specified `value`. * This clone is also added in the `content.formSectionContent` array. * @param value The initial `value` field of each content representing a `FormControl`. */ private _initElemFormSectionContentToFormArray; /** * Returns a new content that represents the clone of the specified content target. * It also sets the initial `value` field of each content representing a `FormControl`. * It clones the content smartly depending on the type of property. * It clones in deep until the next `FormArray`, then the next `FormArray` clones in deep until the next `FormArray`, and so on. * @param target The content object to clone. * @param value The initial `value` field of each content representing a `FormControl`. * @param canClone It is true if the function can clone the `formSectionContent` field; otherwise, false. */ private _cloneContent; /** * Creates the child components. * @param componentsContent Components content array for creating the components. */ protected createChildComponents(componentsContent: Params[]): void; /** * Creates a child component. * @param componentContent Component content for creating the component. */ protected createChildComponent(componentContent: Params): void; /** * Initializes the control's value. It uses the `content.value` and it is already different of `undefined`. * It also checks if the specified `content.value` is correct. For internal use only. */ protected initValue(): void; /** * Returns this instance. */ readonly getInstance: ContainerControl; /** * Returns an array of controls that represents the `ContainerControl`'s child controls. * It is always set internally. */ readonly containerControlChildren: any[]; /** * If the `content.formSection` represents a `FormArray`, then this field returns * a pattern content that is `content.formSectionContent[0]` value; otherwise, returns `undefined`. * It is shared among controls. * It is used for adding a new element in the `content.formSectionContent`, that is, * for adding a new control in the `FormArray`. * By default, its value is `undefined`. */ readonly formArrayPatternContent: any; /** * If the `content.formSection` represents a `FormArray`, then this field returns * a pattern value that is a clone of the `content.value[0]` value, and sets all * its properties/values of built-in type to `undefined`; otherwise, returns `undefined`. * It is used for adding a new element in the `content.formSectionContent`. * By default, its value is `undefined`. */ readonly formArrayPatternValue: any; /** * Returns true if the container control has a dynamic length, that is, the `content.formSection` field * represents a `FormArray` and its length is not fixed; otherwise, false. * This property has sense only when the `content.formSection` field represents a `FormArray`. */ readonly isDynamic: boolean; /** * Returns true if the container control is a `FormArray`, that is, the `content.formSection` field * represents a `FormArray`; otherwise, false. */ readonly isFormArray: boolean; /** * Returns true if this container is empty; otherwise, false. */ readonly isEmpty: boolean; /** * Returns true if an element can be removed from the `content.formSection`; otherwise, false. * Use along with `removeFromFormArray` and `clearFormArray` methods. * The `content.formSection` must be an instance of `FormArray`. */ readonly canRemoveFromFormArray: boolean; /** * Adds an empty element at the end of the `content.formSectionContent`; therefore one element * is added at the end of the `content.formSection` `FormArray`. * The `content.formSection` must be an instance of `FormArray`. */ addToFormArray(): void; /** * Removes the element at the given `index` in the `content.formSectionContent`; therefore * the element at the given `index` is removed in the `content.formSection` `FormArray`. * The `content.formSection` must be an instance of `FormArray`. * @param index Index in the array to remove the element. */ removeFromFormArray(index: number): void; /** * Removes all elements in the `content.formSectionContent`; therefore * all elements are removed in the `content.formSection` `FormArray`. * The `content.formSection` must be an instance of `FormArray`. */ clearFormArray(): void; }