@fluent-form/core
Version:
An Angular dynamic forms library powered by Fluent API and JSON.
49 lines (48 loc) • 2.13 kB
TypeScript
import type { AbstractControlOptions, AsyncValidatorFn, ValidatorFn } from '@angular/forms';
import type { SafeAny } from '@ngify/core';
import type { AbstractSchema } from './abstract.schema';
import type { MaybeSchemaReactiveFn, SchemaReactiveFn } from './interfaces';
import type { ControlEventListenerHolder, EventListenerHolder } from './listeners';
import type { ControlValueMapper } from './mapper';
import type { ControlEventObserverHolder, EventObserverHolder } from './observers';
import type { PropertyHolder } from './properties';
import type { SchemaKey, SingleSchemaKey } from './types';
/**
* Abstract representation of a real (concrete) control schema.
*/
export interface AbstractControlSchema<Key extends SchemaKey = SchemaKey, Val = SafeAny> extends AbstractSchema<Key> {
id?: string;
/** I/O mapper for control */
mapper?: ControlValueMapper<Val>;
/** Linkage control values */
value?: SchemaReactiveFn<AbstractControlSchema, Val>;
defaultValue?: SafeAny | Val;
/** Is it a required control */
required?: MaybeSchemaReactiveFn<AbstractControlSchema<SchemaKey, Val>, boolean>;
/** Whether to disable control */
disabled?: MaybeSchemaReactiveFn<AbstractControlSchema<SchemaKey, Val>, boolean>;
/** Validator for the control */
validators?: ValidatorFn[];
/** Async validators for control */
asyncValidators?: AsyncValidatorFn[];
config?: ControlSchemaConfig;
}
export interface ControlSchemaConfig {
/** The event name for control to update upon. */
updateOn?: AbstractControlOptions['updateOn'];
/** How values are read/collected from the form. 'raw' includes disabled (like getRawValue) */
valueCollectionStrategy?: 'value' | 'raw';
}
/**
* @public
*/
export interface HeadlessControlSchema<Key extends SingleSchemaKey = SingleSchemaKey> extends AbstractControlSchema<Key>, ControlEventObserverHolder, ControlEventListenerHolder {
kind: 'headless';
}
/**
* @public
*/
export interface AbstractHeadfulControlSchema extends PropertyHolder, EventListenerHolder, EventObserverHolder {
kind: 'headful';
template: string;
}