import * as _angular_core from '@angular/core'; import { InjectionToken, OnDestroy, OnInit, AfterViewInit, TemplateRef, Type, Provider, ModuleWithProviders } from '@angular/core'; import { Dictionary } from 'ngx-tethys/types'; import * as i2 from '@angular/forms'; import { AbstractControl, FormControlName, NgForm, FormGroupDirective, NgControl, AsyncValidator, ValidationErrors, Validator, ValidatorFn } from '@angular/forms'; import * as i1$1 from '@angular/common'; import * as i3 from 'ngx-tethys/input'; import * as i4 from 'ngx-tethys/alert'; import * as i5 from 'ngx-tethys/icon'; import * as i6 from 'ngx-tethys/tooltip'; import * as i1 from 'ngx-tethys/util'; import { Observable } from 'rxjs'; import { ThyFormControlSize } from 'ngx-tethys/core'; import { ValidationError, Field, FieldTree } from '@angular/forms/signals'; import { ThySelectOptionModel } from 'ngx-tethys/select'; import { ThySwitchColor } from 'ngx-tethys/switch'; import * as ngx_tethys_form from 'ngx-tethys/form'; type ThyFormLayout = 'horizontal' | 'vertical' | 'inline'; type ThyFormGroupFooterAlign = 'left' | 'right' | 'center'; declare type ThyValidateOn = 'submit' | 'blur' | 'change'; declare type ThyFormValidationMessages = Dictionary>; /** * @order 20 */ interface ThyFormValidatorConfig { /** * 当值为 true 或不传时,执行默认逻辑,当为 false 时,不显示错误;值为 function 时,执行自定义函数处理逻辑,需要注入 THY_VALIDATOR_CONFIG 来使配置生效。 */ showElementError?: boolean | ((element: HTMLElement, errorMessages: string[]) => void); /** * 移除错误,一般和 showElementError 匹配使用;当值为 true 或不传时,执行默认逻辑,当为 false 时,不显示错误提示;值为 function 时,执行自定义函数处理逻辑,需要注入 THY_VALIDATOR_CONFIG 来使配置生效。 */ removeElementError?: boolean | ((element: HTMLElement) => void); /** * 每个字段的验证提示信息配置, validationMessages: {external_url: {required: '应用地址不能为空'}} */ validationMessages?: ThyFormValidationMessages; /** * 表单验证触发方式; 支持change、submit、blur三种方式触发。默认submit。 */ validateOn?: ThyValidateOn; } interface ThyFormValidatorGlobalConfig extends ThyFormValidatorConfig { globalValidationMessages?: Dictionary; } interface ThyFormConfig { layout?: ThyFormLayout; footerAlign?: ThyFormGroupFooterAlign; } interface ThyControlValidationResult { valid: boolean; control: AbstractControl | FormControlName; element: HTMLElement; } interface ThyValidateResult { valid: boolean; invalidControls?: ThyControlValidationResult[]; validControls?: ThyControlValidationResult[]; } declare const THY_VALIDATOR_CONFIG: InjectionToken; declare const THY_FORM_CONFIG: InjectionToken; declare const THY_FORM_CONFIG_PROVIDER: { provide: InjectionToken; useValue: { layout: string; footerAlign: string; }; }; /** * @private */ declare class ThyFormValidatorService implements OnDestroy { private thyFormValidateLoader; private _ngForm; private _formElement; private _config; errors: string[]; private _controls; validations: Dictionary<{ hasError?: boolean; errorMessages?: string[]; }>; private _destroy$; private _getElement; private _clearElementError; private _tryGetValidation; private _addError; private _clearErrors; private _setControlValidateByChange; private _setControlValidateByBlur; private _initializeFormControlValidation; private _formatValidationMessage; private _getValidationMessage; private _getValidationMessages; private _setControlValidationError; private _getValidateOn; initialize(ngForm: NgForm | FormGroupDirective, formElement: HTMLFormElement): void; initializeFormControlsValidation(controls: NgControl[]): void; setValidatorConfig(config: ThyFormValidatorConfig): void; private _getControls; private _getControlByName; validateControl(name: string): { valid: boolean | null; control: AbstractControl | FormControlName; element: HTMLElement; }; validateControls(): { valid: boolean | null; control: AbstractControl | FormControlName; element: HTMLElement; }[]; addError(message: string): void; validate($event?: Event): boolean; validateWithDetail($event: Event): ThyValidateResult; reset(): void; setElementErrorMessage(name: string, message: string): void; ngOnDestroy(): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵprov: _angular_core.ɵɵInjectableDeclaration; } declare enum ThyEnterKeyMode { submit = "submit", alwaysSubmit = "alwaysSubmit", forbidSubmit = "forbidSubmit" } /** * 表单 * @name thyForm,[thy-form] * @order 10 */ declare class ThyFormDirective implements OnInit, AfterViewInit, OnDestroy { private ngForm; private elementRef; private renderer; private ngZone; readonly validator: ThyFormValidatorService; private config; private hostRenderer; /** * 布局,默认水平居中 horizontal,其他2种布局待开发 * @type horizontal | vertical | inline * @default horizontal */ readonly thyLayout: _angular_core.InputSignal; get isHorizontal(): boolean; private get layout(); /** * Enter 键提交模式。`submit`: Textarea 需要 Ctrl | Command + Enter 提交,其他元素直接 Enter 提交; `alwaysSubmit`: 不管是什么元素 Enter 都提交; `forbidSubmit`: Enter 不提交 * @type submit | alwaysSubmit | forbidSubmit * @default submit */ readonly thyEnterKeyMode: _angular_core.InputSignal; /** * 表单验证规则配置项 (更多内容查看:thyFormValidatorConfig) */ readonly thyFormValidatorConfig: _angular_core.InputSignal; wasValidated: boolean; onSubmitSuccess: ($event: any) => void; private _unsubscribe; readonly controls: _angular_core.Signal; private controlsInitialized; constructor(); ngOnInit(): void; ngAfterViewInit(): void; submit($event: Event): void; updateClasses(): void; submitRunInZone($event: any): void; onKeydown($event: KeyboardEvent): void; ngOnDestroy(): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } type TipsMode = 'default' | 'label'; /** * 表单分组组件 * @name thy-form-group * @order 40 */ declare class ThyFormGroup { private thyParentForm; private thyTranslate; protected isHorizontalSignal: _angular_core.WritableSignal; /** * Label 文本 */ readonly thyLabelText: _angular_core.InputSignal; /** * Label 文本多语言 Key */ readonly thyLabelTextTranslateKey: _angular_core.InputSignal; protected labelTextSignal: _angular_core.Signal; /** * Label 是否显示必填项样式 */ readonly thyLabelRequired: _angular_core.InputSignalWithTransform; /** * 清楚 Label padding 间距 */ readonly thyLabelPaddingTopClear: _angular_core.InputSignalWithTransform; /** * 反馈图标,比如日期输入框显示日期的图标,常用输入 date 表示时间 wtf wtf-schedule-o */ thyFeedbackIcon: _angular_core.InputSignalWithTransform; /** * 提示文字的显示模式,`label`模式表示在 label 后通过图标+Tooltip 提示, `default`模式在 Form Control 下方直接显示 * @type default | label * @default default */ thyTipsMode: _angular_core.InputSignal; /** * 提示文案 */ readonly thyTips: _angular_core.InputSignal; /** * 提示文案的多语言 Key */ readonly thyTipsTranslateKey: _angular_core.InputSignal; protected readonly tipsSignal: _angular_core.Signal; /** * 是否填充整行, 没有 Label 文本,只有输入框 * @default false */ readonly thyRowFill: _angular_core.InputSignalWithTransform; /** * 已废弃 * @deprecated please use content because formGroup is same name with angular formGroup directive */ readonly contentTemplateRef: _angular_core.Signal | undefined>; /** * 内容自定义模板,`` */ readonly contentTemplate: _angular_core.Signal | undefined>; constructor(); static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵcmp: _angular_core.ɵɵComponentDeclaration; } /** * @name thyFormGroupLabel * @order 45 */ declare class ThyFormGroupLabelDirective { private thyTranslate; labelText: string; labelRequired: boolean; _isFormGroupLabel: boolean; set thyLabelText(value: string); set thyLabelTranslateKey(translateKey: string); set thyLabelRequired(value: boolean); static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; static ngAcceptInputType_thyLabelRequired: i1.ThyBooleanInput; } /** * 表单提交指令 * @name thyFormSubmit,[thy-form-submit] * @order 15 */ declare class ThyFormSubmitDirective implements OnInit { private thyFormDirective; /** * Form 验证通过的提交函数 */ readonly thyFormSubmit: _angular_core.OutputEmitterRef; ngOnInit(): void; onSubmit($event: Event): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } /** * 表单组底部组件 * @name thy-form-group-footer * @order 55 */ declare class ThyFormGroupFooter { private thyParentForm; private defaultConfig; _isFormGroup: boolean; isHorizontal: boolean; readonly description: _angular_core.Signal | undefined>; /** * 对齐方式 * @type left | right | center * @default left */ readonly thyAlign: _angular_core.InputSignal; footerClassMap: {}; private get align(); constructor(); setFooterClassMap(): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵcmp: _angular_core.ɵɵComponentDeclaration; } /** * 用于校验表单控件的输入值是否已经存在 * @name thyUniqueCheck * @order 20 */ declare class ThyUniqueCheckValidator implements AsyncValidator { private elementRef; private thyForm; readonly thyUniqueCheck: _angular_core.InputSignal<((value: any) => Observable) | undefined>; validate(ctrl: AbstractControl): Promise | Observable; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } /** * @name thy-form-group-error * @order 50 */ declare class ThyFormGroupError implements OnInit { private thyParentForm; errors: string[]; readonly thyShowFirst: _angular_core.InputSignalWithTransform; /** * @type string[] */ set thyErrors(errors: string[]); get thyErrors(): string[]; get _isFormGroup(): boolean; isHorizontal: boolean; ngOnInit(): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵcmp: _angular_core.ɵɵComponentDeclaration; } /** * @name min * @order 35 */ declare class ThyMinDirective implements Validator { private _validator; set min(value: string); validate(control: AbstractControl): { [key: string]: any; } | null; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } /** * @name max * @order 30 */ declare class ThyMaxDirective implements Validator { private _validator; set max(value: string); validate(control: AbstractControl): { [key: string]: any; } | null; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } declare function confirmValidator(value: string): ValidatorFn; /** * confirm validator,用于确认两次输入是否一致 * @name confirm * @order 25 */ declare class ThyConfirmValidatorDirective implements Validator { /** * 表单控件的校验值 */ readonly confirm: _angular_core.InputSignal; validate(control: AbstractControl): i2.ValidationErrors | null; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵdir: _angular_core.ɵɵDirectiveDeclaration; } type ThyDynamicFormValue = Record; type ThyFormTextareaResize = 'none' | 'vertical' | 'horizontal' | 'both'; type ThyFormFieldValidator = (ctx: { value: unknown; formValue: ThyDynamicFormValue; }) => ValidationError | ValidationError[] | null; type ThyFormFieldAsyncValidator = (ctx: { value: unknown; formValue: ThyDynamicFormValue; }) => Promise; interface ThyDynamicFormStatus { readonly valid: boolean; readonly invalid: boolean; readonly submitting: boolean; } interface ThyFormFieldValueChange { key: string; value: unknown; } interface ThyFormFieldBaseProps { label?: string; placeholder?: string; required?: boolean; readonly?: boolean; disabled?: boolean; multiple?: boolean; } interface ThyFormFieldBaseSchema { key: string; kind: TKind; props?: TProps; /** * 外层栅格占位(1–12),默认 12;`inline` 下忽略。 */ col?: number; defaultValue?: unknown; errorMessages?: Partial>; /** * 控件值写入表单模型前的延迟。未设置时立即更新,`blur` 表示失焦后更新。 */ debounce?: number | 'blur'; validators?: ThyFormFieldValidator[]; asyncValidators?: ThyFormFieldAsyncValidator[]; } interface ThyFormInputFieldProps extends ThyFormFieldBaseProps { type?: string; minlength?: number; maxlength?: number; pattern?: string; } interface ThyFormNumberFieldProps extends ThyFormFieldBaseProps { min?: number | string; max?: number | string; step?: number | string; suffix?: string; } interface ThyFormTextareaFieldProps extends ThyFormFieldBaseProps { minlength?: number; maxlength?: number; rows?: number; resize?: ThyFormTextareaResize; pattern?: string; } interface ThyFormSelectFieldProps extends ThyFormFieldBaseProps { options?: ThySelectOptionModel[]; searchable?: boolean; clearable?: boolean; emptyText?: string; searchEmptyText?: string; } interface ThyFormRadioFieldProps extends ThyFormFieldBaseProps { options?: { value: string; label: string; }[]; /** * 是否同一行展示 */ inline?: boolean; /** * @deprecated please use inline, will be removed in v23 */ layout?: 'flex'; button?: boolean; } interface ThyFormSwitchFieldProps extends ThyFormFieldBaseProps { color?: ThySwitchColor; } interface ThyFormTimeFieldProps extends ThyFormFieldBaseProps { format?: string; allowClear?: boolean; showSelectNow?: boolean; } interface ThyFormDateFieldProps extends ThyFormFieldBaseProps { format?: string; min?: Date | number; max?: Date | number; allowClear?: boolean; showTime?: boolean; disabledDate?: (date: Date) => boolean; } interface ThyFormDateRangeFieldProps extends Omit { placeholder?: string | string[]; } interface ThyFormInputFieldSchema extends ThyFormFieldBaseSchema<'input', ThyFormInputFieldProps> { } interface ThyFormNumberFieldSchema extends ThyFormFieldBaseSchema<'number', ThyFormNumberFieldProps> { } interface ThyFormTextareaFieldSchema extends ThyFormFieldBaseSchema<'textarea', ThyFormTextareaFieldProps> { } interface ThyFormSelectFieldSchema extends ThyFormFieldBaseSchema<'select', ThyFormSelectFieldProps> { } interface ThyFormCheckboxFieldSchema extends ThyFormFieldBaseSchema<'checkbox', ThyFormFieldBaseProps> { } interface ThyFormRadioFieldSchema extends ThyFormFieldBaseSchema<'radio', ThyFormRadioFieldProps> { } interface ThyFormSwitchFieldSchema extends ThyFormFieldBaseSchema<'switch', ThyFormSwitchFieldProps> { } interface ThyFormTimeFieldSchema extends ThyFormFieldBaseSchema<'time', ThyFormTimeFieldProps> { } interface ThyFormDateFieldSchema extends ThyFormFieldBaseSchema<'date', ThyFormDateFieldProps> { } interface ThyFormDateRangeFieldSchema extends ThyFormFieldBaseSchema<'dateRange', ThyFormDateRangeFieldProps> { } type ThyFormFieldSchema = ThyFormInputFieldSchema | ThyFormTextareaFieldSchema | ThyFormNumberFieldSchema | ThyFormSelectFieldSchema | ThyFormCheckboxFieldSchema | ThyFormRadioFieldSchema | ThyFormSwitchFieldSchema | ThyFormTimeFieldSchema | ThyFormDateFieldSchema | ThyFormDateRangeFieldSchema; type ThyFormFieldSchemaWith = ThyFormFieldSchema | TCustom; type ThyDynamicFormFieldSchema = ThyFormFieldSchemaWith; interface ThyDynamicFormFieldOutletContext { field: Field; fieldSchema: ThyDynamicFormFieldSchema; size: ThyFormControlSize; invalid: boolean; } interface ThyDynamicFormFieldType { kind: string; component: Type; } declare const THY_DYNAMIC_FORM_FIELD_TYPES: InjectionToken; /** 注册动态表单字段类型。同名 kind 后注册覆盖先注册。 */ declare function provideThyDynamicFormFieldTypes(fieldTypes: ThyDynamicFormFieldType | ThyDynamicFormFieldType[]): Provider[]; /** * 动态表单 * @name thy-dynamic-form * @order 25 */ declare class ThyDynamicForm { /** * 字段配置。内置见 `ThyFormFieldSchema`;自定义用 `ThyFormFieldSchemaWith` 扩展。 * @type ThyDynamicFormFieldSchema[] * @default [] */ readonly thyFields: _angular_core.InputSignal; /** 表单值。支持双向绑定;不传时用各字段的 defaultValue */ readonly thyValue: _angular_core.ModelSignal; /** * 表单布局,与 `thyForm` 一致。`horizontal` 左右布局;`vertical` 上下布局;`inline` 行内布局。 * 未传入时回落 `THY_FORM_CONFIG.layout`(默认 `horizontal`)。 * @type horizontal | vertical | inline * @default horizontal */ readonly thyLayout: _angular_core.InputSignal; /** * 表单控件大小 * @type xs | sm | md | lg * @default md */ readonly thySize: _angular_core.InputSignalWithTransform; /** * Horizontal 下 label 固定宽度,默认 `120px`;`vertical` / `inline` 不生效。 */ readonly thyLabelWidth: _angular_core.InputSignal; private readonly config; protected readonly layout: _angular_core.Signal; get isHorizontal(): boolean; private readonly injectedFieldTypes; protected readonly fieldTypeMap: _angular_core.Signal>; /** 组件内部修改单个字段时触发。 */ readonly thyFieldValueChange: _angular_core.OutputEmitterRef; /** Signal Forms 状态变化时触发。 */ readonly thyStatusChange: _angular_core.OutputEmitterRef; /** 表单通过校验并提交时触发。 */ readonly thySubmit: _angular_core.OutputEmitterRef; private readonly injector; private readonly validatorLoader; protected readonly fields: _angular_core.Signal; private readonly fieldTreeRebuildDependencies; private readonly fieldTreeSignal; private previousFieldValue; get fieldTree(): FieldTree; readonly status: _angular_core.Signal; constructor(); protected resolveFieldType(kind: string): ThyDynamicFormFieldType | undefined; private createFieldTree; reset(value?: ThyDynamicFormValue): void; protected handleReset(event: Event): void; getField(key: string): Field; protected errorMessage(field: ThyDynamicFormFieldSchema, error: ValidationError | undefined): string | null; private emitFieldValueChanges; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵcmp: _angular_core.ɵɵComponentDeclaration; } declare class ThyFormModule { static forRoot(config: ThyFormValidatorGlobalConfig): ModuleWithProviders; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵmod: _angular_core.ɵɵNgModuleDeclaration; static ɵinj: _angular_core.ɵɵInjectorDeclaration; } declare const ERROR_VALUE_REPLACE_REGEX: RegExp; /** * @private */ declare class ThyFormValidatorLoader { private config; private locale; private get globalValidationMessages(); private getDefaultValidationMessage; constructor(); get validationMessages(): ThyFormValidationMessages; get validateOn(): ngx_tethys_form.ThyValidateOn | undefined; isElementInInputGroup(element: HTMLElement): boolean; getErrorMessage(name: string, key: string): string; getErrorMessages(name: string, validationErrors: ValidationErrors): string[]; defaultShowError(element: HTMLElement, errorMessages: string[]): void; defaultRemoveError(element: HTMLElement): void; removeError(element: HTMLElement): void; showError(element: HTMLElement, errorMessages: string[]): void; addValidationMessages(messages: ThyFormValidationMessages): void; setGlobalValidationMessages(validationMessages: Dictionary): void; static ɵfac: _angular_core.ɵɵFactoryDeclaration; static ɵprov: _angular_core.ɵɵInjectableDeclaration; } export { ERROR_VALUE_REPLACE_REGEX, THY_DYNAMIC_FORM_FIELD_TYPES, THY_FORM_CONFIG, THY_FORM_CONFIG_PROVIDER, THY_VALIDATOR_CONFIG, ThyConfirmValidatorDirective, ThyDynamicForm, ThyEnterKeyMode, ThyFormDirective, ThyFormGroup, ThyFormGroupError, ThyFormGroupFooter, ThyFormGroupLabelDirective, ThyFormModule, ThyFormSubmitDirective, ThyFormValidatorLoader, ThyFormValidatorService, ThyMaxDirective, ThyMinDirective, ThyUniqueCheckValidator, confirmValidator, provideThyDynamicFormFieldTypes }; export type { ThyControlValidationResult, ThyDynamicFormFieldOutletContext, ThyDynamicFormFieldSchema, ThyDynamicFormFieldType, ThyDynamicFormStatus, ThyDynamicFormValue, ThyFormCheckboxFieldSchema, ThyFormConfig, ThyFormDateFieldProps, ThyFormDateFieldSchema, ThyFormDateRangeFieldProps, ThyFormDateRangeFieldSchema, ThyFormFieldAsyncValidator, ThyFormFieldBaseProps, ThyFormFieldBaseSchema, ThyFormFieldSchema, ThyFormFieldSchemaWith, ThyFormFieldValidator, ThyFormFieldValueChange, ThyFormGroupFooterAlign, ThyFormInputFieldProps, ThyFormInputFieldSchema, ThyFormLayout, ThyFormNumberFieldProps, ThyFormNumberFieldSchema, ThyFormRadioFieldProps, ThyFormRadioFieldSchema, ThyFormSelectFieldProps, ThyFormSelectFieldSchema, ThyFormSwitchFieldProps, ThyFormSwitchFieldSchema, ThyFormTextareaFieldProps, ThyFormTextareaFieldSchema, ThyFormTextareaResize, ThyFormTimeFieldProps, ThyFormTimeFieldSchema, ThyFormValidationMessages, ThyFormValidatorConfig, ThyFormValidatorGlobalConfig, ThyValidateOn, ThyValidateResult };