UNPKG

nz-json-schema-form

Version:

Schema form for JSON schema

365 lines (344 loc) 13.6 kB
import * as i0 from '@angular/core'; import { OnChanges, SimpleChanges, InjectionToken, OnInit, AfterViewInit, OnDestroy, ChangeDetectorRef, TemplateRef, Type } from '@angular/core'; import { UntypedFormGroup, AbstractControl, UntypedFormControl, UntypedFormArray } from '@angular/forms'; import { Subject } from 'rxjs'; import { NgClassType, NgStyleInterface } from 'ng-zorro-antd/core/types'; import { NzCascaderOption } from 'ng-zorro-antd/cascader'; declare enum JSONSchemaTypes { STRING = "string", NUMBER = "number", INTEGER = "integer", BOOLEAN = "boolean", OBJECT = "object", ARRAY = "array", NULL = "null" } type JSONSchemaTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null'; type JSONSchemaType = JSONSchemaArray[] | boolean | number | null | object | string; interface JSONSchemaArray extends Array<JSONSchemaType> { } type JSONSchemaVersion = string; type JSONSchemaDefinition = JSONSchema; interface JSONSchema { $id?: string; $ref?: string; $schema?: JSONSchemaVersion; $comment?: string; type?: JSONSchemaTypeName; enum?: JSONSchemaType[]; const?: JSONSchemaType; multipleOf?: number; maximum?: number; exclusiveMaximum?: number; minimum?: number; exclusiveMinimum?: number; maxLength?: number; minLength?: number; pattern?: string; items?: JSONSchemaDefinition | JSONSchemaDefinition[]; additionalItems?: JSONSchemaDefinition; maxItems?: number; minItems?: number; uniqueItems?: boolean; contains?: JSONSchema; maxProperties?: number; minProperties?: number; required?: string[]; properties?: { [key: string]: JSONSchemaDefinition; }; patternProperties?: { [key: string]: JSONSchemaDefinition; }; additionalProperties?: JSONSchemaDefinition; dependencies?: { [key: string]: JSONSchemaDefinition | string[]; }; propertyNames?: JSONSchemaDefinition; if?: JSONSchemaDefinition; then?: JSONSchemaDefinition; else?: JSONSchemaDefinition; allOf?: JSONSchemaDefinition[]; anyOf?: JSONSchemaDefinition[]; oneOf?: JSONSchemaDefinition[]; not?: JSONSchemaDefinition; format?: string; contentMediaType?: string; contentEncoding?: string; definitions?: { [key: string]: JSONSchemaDefinition; }; title?: string; description?: string; default?: JSONSchemaType; readOnly?: boolean; writeOnly?: boolean; examples?: JSONSchemaType; } interface UISchema<T extends Record<string, unknown> = { [p: string]: any; }> { widget?: string; messages?: Record<string, unknown>; placeholder?: string; disabled?: boolean; size?: 'large' | 'default' | 'small'; klass?: NgClassType; style?: NgStyleInterface | null; type?: string; widgetData?: any; options?: T; } type NZSchemaDefinition = NzSchema; interface NzSchema extends JSONSchema { ui?: UISchema; items?: NZSchemaDefinition | NZSchemaDefinition[]; additionalItems?: NZSchemaDefinition; properties?: { [key: string]: NZSchemaDefinition; }; patternProperties?: { [key: string]: NZSchemaDefinition; }; additionalProperties?: NZSchemaDefinition; dependencies?: { [key: string]: NZSchemaDefinition | string[]; }; propertyNames?: NZSchemaDefinition; if?: NZSchemaDefinition; then?: NZSchemaDefinition; else?: NZSchemaDefinition; allOf?: NZSchemaDefinition[]; anyOf?: NZSchemaDefinition[]; oneOf?: NZSchemaDefinition[]; not?: NZSchemaDefinition; definitions?: { [key: string]: NZSchemaDefinition; }; } declare class SchemaContext { schema: NzSchema; parent: NzSchema; root: NzSchema; name: string | number; constructor(schema: NzSchema); child(schema: NzSchema, name: string | number): SchemaContext; } declare class SchemaFormBuilder { build(schema: NzSchema, value?: any): SchemaFormGroup; object(context: SchemaContext, value?: any): SchemaFormGroup; array(context: SchemaContext, value?: any[]): SchemaFormArray; control(context: SchemaContext, value?: any): SchemaFormControl; createControl(context: SchemaContext, value?: any): AbstractSchemaControl; private reduceControls; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormBuilder, never>; static ɵprov: i0.ɵɵInjectableDeclaration<SchemaFormBuilder>; } type UpdateSchemaFun = (schema: NzSchema) => NzSchema; declare abstract class AbstractSchemaControl extends AbstractControl { schemaContext: SchemaContext; onUpdateSchema$: Subject<NzSchema>; abstract updateSchema(schemaOrFun: NzSchema | UpdateSchemaFun): void; } declare class SchemaFormControl extends UntypedFormControl implements AbstractSchemaControl { schemaContext: SchemaContext; onUpdateSchema$: Subject<NzSchema>; get updateSchema(): (schemaOrFun: NzSchema | UpdateSchemaFun) => void; get(path: Array<string | number> | string): AbstractSchemaControl | null; setValue(value: any, options?: { onlySelf?: boolean; emitEvent?: boolean; emitModelToViewChange?: boolean; emitViewToModelChange?: boolean; }): void; } declare class SchemaFormGroup extends UntypedFormGroup implements AbstractSchemaControl { schemaContext: SchemaContext; controls: { [key: string]: AbstractSchemaControl; }; onUpdateSchema$: Subject<NzSchema>; get updateSchema(): (schemaOrFun: NzSchema | UpdateSchemaFun) => void; get(path: Array<string | number> | string): AbstractSchemaControl | null; } declare class SchemaFormArray extends UntypedFormArray implements AbstractSchemaControl { schemaContext: SchemaContext; controls: AbstractSchemaControl[]; onUpdateSchema$: Subject<NzSchema>; onControlsChange: Subject<void>; _builder: SchemaFormBuilder; get updateSchema(): (schemaOrFun: NzSchema | UpdateSchemaFun) => void; get(path: Array<string | number> | string): AbstractSchemaControl | null; setValue(value: any[], options?: { onlySelf?: boolean; emitEvent?: boolean; }): void; } declare class NzSchemaComponent implements OnChanges { nzSchema: NzSchema; nzFormValue: any; form: SchemaFormGroup; private schemaFormBuilder; ngOnChanges(changes: SimpleChanges): void; private buildForm; private setFormValue; static ɵfac: i0.ɵɵFactoryDeclaration<NzSchemaComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<NzSchemaComponent, "nz-schema", never, { "nzSchema": { "alias": "nzSchema"; "required": false; }; "nzFormValue": { "alias": "nzFormValue"; "required": false; }; }, {}, never, never, true, never>; } declare class NzSchemaErrorMessageService { private errorMessages; getErrorMessage(form: AbstractSchemaControl): string | null; static ɵfac: i0.ɵɵFactoryDeclaration<NzSchemaErrorMessageService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NzSchemaErrorMessageService>; } declare const SCHEMA: InjectionToken<NzSchema>; declare const SCHEMA_FORM: InjectionToken<AbstractSchemaControl>; declare abstract class BaseField<T extends AbstractSchemaControl = SchemaFormControl> implements OnInit, AfterViewInit, OnDestroy { abstract schemaForm: T; required: boolean | undefined; errorMessage?: string; inputElement: any; protected errorMessageService: NzSchemaErrorMessageService; protected cdr: ChangeDetectorRef; get schema(): NzSchema; get userInterfaceSchema(): UISchema; get widgetOptions(): { [p: string]: any; }; get ngClass(): NgClassType; get ngStyle(): NgStyleInterface; get size(): 'large' | 'default' | 'small'; get placeholder(): string; get type(): string | undefined; get widgetData(): any; get disabled(): boolean | undefined; get enum(): JSONSchemaType[]; get label(): string; get description(): string; init(): void; setInputElementOptions(firstChange?: boolean): void; ngAfterViewInit(): void; ngOnInit(): void; ngOnDestroy(): void; static ɵfac: i0.ɵɵFactoryDeclaration<BaseField<any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<BaseField<any>, never, never, {}, {}, never, never, true, never>; } interface AutocompleteOptions { backfill?: boolean; defaultActiveFirstOption?: boolean; width?: number; overlayClassName?: string; overlayStyle?: { [p: string]: string; }; } declare class SchemaFormAutocompleteComponent extends BaseField implements OnInit { get widgetOptions(): AutocompleteOptions; schemaForm: SchemaFormControl; options: Array<{ label: string; value: any; }>; setOption(): void; ngOnInit(): void; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormAutocompleteComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormAutocompleteComponent, "nz-schema-form-autocomplete", never, {}, {}, never, never, true, never>; } interface CascaderOptions { allowClear?: boolean; changeOnSelect?: boolean; showArrow?: boolean; showInput?: boolean; showSearch?: boolean; changeOn?: (option: NzCascaderOption, index: number) => boolean; columnClassName?: string; expandTrigger?: 'click' | 'hover'; menuClassName?: string; menuStyle?: object; notFoundContent?: string | TemplateRef<void>; labelProperty?: string; valueProperty?: string; labelRender?: TemplateRef<any>; loadData?: (option: any, index?: number) => PromiseLike<any>; visibleChange?(e: boolean, form: SchemaFormControl): void; selectionChange?(e: NzCascaderOption[], form: SchemaFormControl): void; } declare class SchemaFormCascaderComponent extends BaseField { get widgetData(): NzCascaderOption[]; get widgetOptions(): CascaderOptions; schemaForm: SchemaFormControl; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormCascaderComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormCascaderComponent, "nz-schema-form-cascader", never, {}, {}, never, never, true, never>; } declare class SchemaFormCheckboxComponent extends BaseField { schemaForm: SchemaFormControl; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormCheckboxComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormCheckboxComponent, "nz-schema-form-checkbox", never, {}, {}, never, never, true, never>; } declare class SchemaFormDatePickerComponent extends BaseField { schemaForm: SchemaFormControl; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormDatePickerComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormDatePickerComponent, "nz-schema-form-date-picker", never, {}, {}, never, never, true, never>; } declare class SchemaFormMentionComponent extends BaseField { schemaForm: SchemaFormControl; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormMentionComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormMentionComponent, "nz-schema-form-mention", never, {}, {}, never, never, true, never>; } declare class SchemaFormSelectComponent extends BaseField implements OnInit { options: Array<{ label: string; value: any; }>; schemaForm: SchemaFormControl; setOption(): void; ngOnInit(): void; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormSelectComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormSelectComponent, "nz-schema-form-select", never, {}, {}, never, never, true, never>; } interface TextareaOptions { autosize?: boolean | { minRows: number; maxRows: number; }; rows?: string; size?: 'large' | 'small' | 'default'; } declare class SchemaFormTextareaComponent extends BaseField { get widgetOptions(): TextareaOptions; schemaForm: SchemaFormControl; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaFormTextareaComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<SchemaFormTextareaComponent, "nz-schema-form-textarea", never, {}, {}, never, never, true, never>; } declare class SchemaWidgetRegistryService { widgetMap: { array: { select: typeof SchemaFormSelectComponent; cascader: typeof SchemaFormCascaderComponent; }; boolean: { checkbox: typeof SchemaFormCheckboxComponent; select: typeof SchemaFormSelectComponent; }; number: { select: typeof SchemaFormSelectComponent; 'date-picker': typeof SchemaFormDatePickerComponent; }; object: {}; string: { select: typeof SchemaFormSelectComponent; autocomplete: typeof SchemaFormAutocompleteComponent; textarea: typeof SchemaFormTextareaComponent; 'date-picker': typeof SchemaFormDatePickerComponent; mention: typeof SchemaFormMentionComponent; }; null: {}; integer: {}; }; getWidget(schema: NzSchema): Type<any> | null; setWidget(type: JSONSchemaTypes, widgetName: string, widgetComponent: Type<any>): void; static ɵfac: i0.ɵɵFactoryDeclaration<SchemaWidgetRegistryService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<SchemaWidgetRegistryService>; } export { BaseField, JSONSchemaTypes, NzSchemaComponent, SCHEMA, SCHEMA_FORM, SchemaFormArray, SchemaFormControl, SchemaFormGroup, SchemaWidgetRegistryService }; export type { JSONSchema, JSONSchemaArray, JSONSchemaDefinition, JSONSchemaType, JSONSchemaTypeName, JSONSchemaVersion, NZSchemaDefinition, NzSchema, UISchema };