/** * 将 schema 转化为 react form 组件 */ import React from 'react'; import type { SchemaType } from '../core/normalize'; import type { FormInstance } from '@amazebird/form'; type StoreValue = any; export type Type = 'object' | 'array' | 'string' | 'number'; type Store = Record; type NamePath = string | number | (string | number)[]; /** Only return partial when type is not any */ declare type ValidateMessage = string | (() => string); interface ValidateMessages { default?: ValidateMessage; required?: ValidateMessage; enum?: ValidateMessage; whitespace?: ValidateMessage; date?: { format?: ValidateMessage; parse?: ValidateMessage; invalid?: ValidateMessage; }; types?: { string?: ValidateMessage; method?: ValidateMessage; array?: ValidateMessage; object?: ValidateMessage; number?: ValidateMessage; date?: ValidateMessage; boolean?: ValidateMessage; integer?: ValidateMessage; float?: ValidateMessage; regexp?: ValidateMessage; email?: ValidateMessage; url?: ValidateMessage; hex?: ValidateMessage; }; string?: { len?: ValidateMessage; min?: ValidateMessage; max?: ValidateMessage; range?: ValidateMessage; }; number?: { len?: ValidateMessage; min?: ValidateMessage; max?: ValidateMessage; range?: ValidateMessage; }; array?: { len?: ValidateMessage; min?: ValidateMessage; max?: ValidateMessage; range?: ValidateMessage; }; pattern?: { mismatch?: ValidateMessage; }; } interface FieldData { name: NamePath; touched?: boolean; validating?: boolean; errors?: string[]; warnings?: string[]; value?: StoreValue; } type BaseFormProps = Omit, 'onSubmit' | 'children'>; type RenderProps = (values: Store, form: FormInstance) => JSX.Element | React.ReactNode; interface FormProps extends BaseFormProps { form?: FormInstance; children?: RenderProps | React.ReactNode; onFieldsChange?: (changedFields: FieldData[], allFields: FieldData[]) => void; onValuesChange?: (changeValues: any, allValues: any) => void; validateMessages?: ValidateMessages; initialState?: any; component?: React.ComponentType | false; preserve?: boolean; } declare function useForm(form?: FormInstance): [FormInstance]; interface FormInterface { (props: FormProps & { children?: React.ReactNode; } & { ref?: React.Ref> | undefined; }): React.ReactElement; useForm: typeof useForm; } export interface SchemaFormProps extends FormProps { /** * 配置缓存的策略 * key: 配置缓存时存储的 key * type: 配置缓存数据存储位置,如果想刷新后保持,需要设为 localStorage */ cache?: { key: string; /** * 设置缓存的位置,默认 indexedDB */ type?: 'localStorage' | 'indexedDB' | 'sessionStorage'; /** * 指定命名空间(可选)。优先级高于全局命名空间; * 未指定时,将使用全局命名空间;两者皆无则使用组件默认命名空间。 */ namespace?: string; /** * 设置缓存的优先级,用于垃圾回收时的清理策略 * very_important: 最高优先级,最后被清理 * important: 高优先级 * normal: 普通优先级,默认值 */ priority?: 'very_important' | 'important' | 'normal'; onReady?: (initialValues: any) => void; }; schema: SchemaType | (() => Promise); mode?: 'add' | 'modify' | 'detail' | string; listMode?: 'card' | 'default'; initialState?: Store; initialValues?: Store | (() => Promise); formatInitail?: boolean; observer?: { watch: NamePath | NamePath[]; action: (value: any) => void; }; form?: FormInstance; detailStyle?: boolean; scope?: string; labelCol?: any; wrapperCol?: any; requiredMark?: boolean; } export interface SchemaFormInterface { (props: SchemaFormProps & { children?: React.ReactNode; }): React.ReactElement; createForm: () => NonNullable; clearCache: any; } export default function SchemaFormWrapper(Form: FormInterface, Loading: any, EnhanceDecorator?: any): SchemaFormInterface; export {};