diff --git a/packages/antd/README.md b/packages/antd/README.md index 214e80abcdd..6d92d2912ca 100644 --- a/packages/antd/README.md +++ b/packages/antd/README.md @@ -75,6 +75,11 @@ npm install --save @uform/antd - [`ISchemaFieldComponent`](#ISchemaFieldComponent) - [`ISchemaVirtualFieldComponent`](#ISchemaVirtualFieldComponent) - [`ISchemaFormRegistry`](#ISchemaFormRegistry) + - [`InternalFormats`](#InternalFormats) + - [`CustomValidator`](#CustomValidator) + - [`ValidateDescription`](#ValidateDescription) + - [`ValidateArrayRules`](#ValidateArrayRules) + - [`ValidatePatternRules`](#ValidatePatternRules) - [`INextSchemaFieldProps`](#INextSchemaFieldProps) - [`IPreviewTextProps`](#IPreviewTextProps) - [`IMutators`](#IMutators) @@ -3394,6 +3399,88 @@ interface ISchemaFormRegistry { } ``` +#### InternalFormats + +```typescript +type InternalFormats = + | 'url' + | 'email' + | 'ipv6' + | 'ipv4' + | 'idcard' + | 'taodomain' + | 'qq' + | 'phone' + | 'money' + | 'zh' + | 'date' + | 'zip' + | string +``` + +#### CustomValidator + +```typescript +declare type CustomValidator = ( + value: any, + rescription?: ValidateDescription +) => ValidateResponse +``` + +#### ValidateDescription + +```typescript +interface ValidateDescription { + // built-in rules,ref: string rules + format?: InternalFormats + // custom validation + validator?: CustomValidator + // required + required?: boolean + // pattern + pattern?: RegExp | string + // max length + max?: number + // maximum + maximum?: number + // exclusiveMaximum + exclusiveMaximum?: number + // exclusiveMinimum + exclusiveMinimum?: number + // minimum + minimum?: number + // min + min?: number + // length + len?: number + // whitespace + whitespace?: boolean + // enum + enum?: any[] + // error message + message?: string + [key: string]: any +} +``` + +#### ValidateArrayRules + +```typescript +declare type ValidateArrayRules = Array< + InternalFormats | CustomValidator | ValidateDescription +> +``` + +#### ValidatePatternRules + +```typescript +declare type ValidatePatternRules = + | InternalFormats + | CustomValidator + | ValidateDescription + | ValidateArrayRules +``` + #### INextSchemaFieldProps ```typescript diff --git a/packages/antd/README.zh-cn.md b/packages/antd/README.zh-cn.md index 13cb66ebfc2..545ce40de77 100644 --- a/packages/antd/README.zh-cn.md +++ b/packages/antd/README.zh-cn.md @@ -76,6 +76,11 @@ npm install --save @uform/antd - [`ISchemaFieldComponent`](#ISchemaFieldComponent) - [`ISchemaVirtualFieldComponent`](#ISchemaVirtualFieldComponent) - [`ISchemaFormRegistry`](#ISchemaFormRegistry) + - [`InternalFormats`](#InternalFormats) + - [`CustomValidator`](#CustomValidator) + - [`ValidateDescription`](#ValidateDescription) + - [`ValidateArrayRules`](#ValidateArrayRules) + - [`ValidatePatternRules`](#ValidatePatternRules) - [`INextSchemaFieldProps`](#INextSchemaFieldProps) - [`IPreviewTextProps`](#IPreviewTextProps) - [`IMutators`](#IMutators) @@ -3509,6 +3514,89 @@ interface ISchemaFormRegistry { } ``` + +#### InternalFormats + +```typescript +type InternalFormats = + | 'url' + | 'email' + | 'ipv6' + | 'ipv4' + | 'idcard' + | 'taodomain' + | 'qq' + | 'phone' + | 'money' + | 'zh' + | 'date' + | 'zip' + | string +``` + +#### CustomValidator + +```typescript +declare type CustomValidator = ( + value: any, + rescription?: ValidateDescription +) => ValidateResponse +``` + +#### ValidateDescription + +```typescript +interface ValidateDescription { + // 内置校验规则,参考string内置校验规则 + format?: InternalFormats + // 自定义校验规则 + validator?: CustomValidator + // 是否必填 + required?: boolean + // 匹配规则 + pattern?: RegExp | string + // 最大长度 + max?: number + // 最大值(大于) + maximum?: number + // 最大值(大于等于) + exclusiveMaximum?: number + // 最小值(小于等于) + exclusiveMinimum?: number + // 最小值(小于) + minimum?: number + // 最小长度 + min?: number + // 长度 + len?: number + // 空格 + whitespace?: boolean + // 是否包含在枚举列表中 + enum?: any[] + // 错误信息 + message?: string + [key: string]: any +} +``` + +#### ValidateArrayRules + +```typescript +declare type ValidateArrayRules = Array< + InternalFormats | CustomValidator | ValidateDescription +> +``` + +#### ValidatePatternRules + +```typescript +declare type ValidatePatternRules = + | InternalFormats + | CustomValidator + | ValidateDescription + | ValidateArrayRules +``` + #### INextSchemaFieldProps ```typescript diff --git a/packages/antd/src/types.ts b/packages/antd/src/types.ts index acba0dfaa09..dfcd849f5c8 100644 --- a/packages/antd/src/types.ts +++ b/packages/antd/src/types.ts @@ -15,7 +15,7 @@ import { StyledComponent } from 'styled-components' type ColSpanType = number | string -export type IAntdSchemaFormProps = Omit & +export type IAntdSchemaFormProps = Omit & IFormItemTopProps & PreviewTextConfigProps & ISchemaFormProps diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 61b46f105f9..5d581d13666 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -712,10 +712,7 @@ export function createForm( return arr }, validate(opts?: IFormExtendedValidateFieldOptions) { - return validate( - field.getSourceState(state => state.path), - opts - ) + return validate(field.getSourceState(state => state.path), opts) } } } diff --git a/packages/next/README.md b/packages/next/README.md index 6f667c32193..246bac925d0 100644 --- a/packages/next/README.md +++ b/packages/next/README.md @@ -75,6 +75,11 @@ npm install --save @uform/next - [`ISchemaFieldComponent`](#ISchemaFieldComponent) - [`ISchemaVirtualFieldComponent`](#ISchemaVirtualFieldComponent) - [`ISchemaFormRegistry`](#ISchemaFormRegistry) + - [`InternalFormats`](#InternalFormats) + - [`CustomValidator`](#CustomValidator) + - [`ValidateDescription`](#ValidateDescription) + - [`ValidateArrayRules`](#ValidateArrayRules) + - [`ValidatePatternRules`](#ValidatePatternRules) - [`INextSchemaFieldProps`](#INextSchemaFieldProps) - [`IPreviewTextProps`](#IPreviewTextProps) - [`IMutators`](#IMutators) @@ -3405,6 +3410,88 @@ interface ISchemaFormRegistry { } ``` +#### InternalFormats + +```typescript +type InternalFormats = + | 'url' + | 'email' + | 'ipv6' + | 'ipv4' + | 'idcard' + | 'taodomain' + | 'qq' + | 'phone' + | 'money' + | 'zh' + | 'date' + | 'zip' + | string +``` + +#### CustomValidator + +```typescript +declare type CustomValidator = ( + value: any, + rescription?: ValidateDescription +) => ValidateResponse +``` + +#### ValidateDescription + +```typescript +interface ValidateDescription { + // built-in rules,ref: string rules + format?: InternalFormats + // custom validation + validator?: CustomValidator + // required + required?: boolean + // pattern + pattern?: RegExp | string + // max length + max?: number + // maximum + maximum?: number + // exclusiveMaximum + exclusiveMaximum?: number + // exclusiveMinimum + exclusiveMinimum?: number + // minimum + minimum?: number + // min + min?: number + // length + len?: number + // whitespace + whitespace?: boolean + // enum + enum?: any[] + // error message + message?: string + [key: string]: any +} +``` + +#### ValidateArrayRules + +```typescript +declare type ValidateArrayRules = Array< + InternalFormats | CustomValidator | ValidateDescription +> +``` + +#### ValidatePatternRules + +```typescript +declare type ValidatePatternRules = + | InternalFormats + | CustomValidator + | ValidateDescription + | ValidateArrayRules +``` + #### INextSchemaFieldProps ```typescript diff --git a/packages/next/README.zh-cn.md b/packages/next/README.zh-cn.md index d293251864c..7ae06f0d622 100644 --- a/packages/next/README.zh-cn.md +++ b/packages/next/README.zh-cn.md @@ -76,6 +76,11 @@ npm install --save @uform/next - [`ISchemaFieldComponent`](#ISchemaFieldComponent) - [`ISchemaVirtualFieldComponent`](#ISchemaVirtualFieldComponent) - [`ISchemaFormRegistry`](#ISchemaFormRegistry) + - [`InternalFormats`](#InternalFormats) + - [`CustomValidator`](#CustomValidator) + - [`ValidateDescription`](#ValidateDescription) + - [`ValidateArrayRules`](#ValidateArrayRules) + - [`ValidatePatternRules`](#ValidatePatternRules) - [`INextSchemaFieldProps`](#INextSchemaFieldProps) - [`IPreviewTextProps`](#IPreviewTextProps) - [`IMutators`](#IMutators) @@ -3435,6 +3440,89 @@ interface ISchemaFormRegistry { } ``` + +#### InternalFormats + +```typescript +type InternalFormats = + | 'url' + | 'email' + | 'ipv6' + | 'ipv4' + | 'idcard' + | 'taodomain' + | 'qq' + | 'phone' + | 'money' + | 'zh' + | 'date' + | 'zip' + | string +``` + +#### CustomValidator + +```typescript +declare type CustomValidator = ( + value: any, + rescription?: ValidateDescription +) => ValidateResponse +``` + +#### ValidateDescription + +```typescript +interface ValidateDescription { + // 内置校验规则,参考string内置校验规则 + format?: InternalFormats + // 自定义校验规则 + validator?: CustomValidator + // 是否必填 + required?: boolean + // 匹配规则 + pattern?: RegExp | string + // 最大长度 + max?: number + // 最大值(大于) + maximum?: number + // 最大值(大于等于) + exclusiveMaximum?: number + // 最小值(小于等于) + exclusiveMinimum?: number + // 最小值(小于) + minimum?: number + // 最小长度 + min?: number + // 长度 + len?: number + // 空格 + whitespace?: boolean + // 是否包含在枚举列表中 + enum?: any[] + // 错误信息 + message?: string + [key: string]: any +} +``` + +#### ValidateArrayRules + +```typescript +declare type ValidateArrayRules = Array< + InternalFormats | CustomValidator | ValidateDescription +> +``` + +#### ValidatePatternRules + +```typescript +declare type ValidatePatternRules = + | InternalFormats + | CustomValidator + | ValidateDescription + | ValidateArrayRules +``` + #### INextSchemaFieldProps ```typescript diff --git a/packages/next/src/types.ts b/packages/next/src/types.ts index c2865b05e90..2cf50049145 100644 --- a/packages/next/src/types.ts +++ b/packages/next/src/types.ts @@ -12,10 +12,11 @@ import { StyledComponent } from 'styled-components' type ColSpanType = number | string -export type INextSchemaFormProps = Omit & +export type INextSchemaFormProps = Omit & IFormItemTopProps & PreviewTextConfigProps & ISchemaFormProps + export type INextSchemaFieldProps = IMarkupSchemaFieldProps diff --git a/packages/react-schema-renderer/src/shared/schema.ts b/packages/react-schema-renderer/src/shared/schema.ts index cf52cfce865..a88e985f832 100644 --- a/packages/react-schema-renderer/src/shared/schema.ts +++ b/packages/react-schema-renderer/src/shared/schema.ts @@ -14,7 +14,8 @@ import { isBool, isValid, FormPathPattern, - FormPath + FormPath, + deprecate } from '@uform/shared' import { SchemaMessage, ISchema } from '../types' @@ -311,7 +312,7 @@ export class Schema implements ISchema { return this['x-component'] } getExtendsRenderer() { - return this['x-render'] + return deprecate(this['x-render'], 'x-render is deprecate in future, Please do not use it.') } getExtendsEffect() { return this['x-effect']