import { CSSProperties, Dispatch } from "react"; // 叶子节点类型 type TreeItem = { fieldKey: string; schema: TreeItem[]; collapsed?: boolean; }; // 树形结构 type TreeItems = TreeItem[]; // 扁平化结构类型 interface FlattenedItem extends TreeItem { parentFieldKey: null | string; depth: number; index: number; } type Map = { [key: string]: any; }; type ClosestEdge = "left" | "top" | "bottom" | "right" | "over"; /** * 生成fieldkey的正则 * 根据a.0.b 返回/a.(\d+|$container).b/正则 * @param arr 需要生成正则的数组 * @returns 返回正则 */ declare const generateReg: (arr: Array) => RegExp; /** * 用于删除、切换数组排序的arraykey * @param arr * @returns */ declare const generateArrayKeyReg: (arr: Array) => RegExp; /** * 基本数据类型检测 * @param {unknown} checkVar 待检测的变量 * @returns {string} 基本数据类型:Object | Array | String | Number | Boolean | Null | Undefined */ declare function typeCheck(checkVar: any): string; /** * 判断变量是否为空 * @param checkVar */ declare function isEmpty(checkVar: any): boolean; /** * 设置data.a.b.c = value * 若data没有a.b 则依次赋值空对象,最后再将a.b.c设为value * @param {string} keys a.b.c * @param {object} data data.a.b.c * @param {unknown} value data.a.b.c = value * @param {object} typeMap 确定a.0.b.1中的0和1的父级应该是对象还是数组形式 * @param parentKey */ declare const setDeepProp: (keys: string[], data: Map, value: unknown, typeMap?: Map | undefined, parentKey?: string[] | undefined) => void; /** * 删除data.a.b.c * 若data没有a.b.c,则不进行任何操作 * @param {string} keys [a,b,c] * @param {object} data 需要删除的对象 */ declare const deleteDeepProp: (keys: string[], data: Map) => void; /** * 判断对象是否有某一属性,如没有,则根据valueType为其创建 * 并返回最后一个key的校验生成后的value * @param {Map} source 源对象 * @param {'array' | 'object'} valueType 创建的类型 * @param {array} keys 对象的key值,支持...以拓展深层对象的创建 */ declare const judgeAndRegister: (source: Map, valueType: "array" | "object", ...keys: any[]) => Map; /** * 允许循环引用的深拷贝 * @param target * @param map */ declare function deepClone(target: any, map?: WeakMap): any; /** * 更新属性,并联动更新与其相关的子元素的对应属性 * @param items * @param fieldKey * @param property * @param setter */ declare function setProperty(items: TreeItems, fieldKey: string, property: T, setter: (value: TreeItem[T]) => TreeItem[T]): TreeItems; /** * 移除属性,并联动移除与其相关的子元素的对应属性 * @param schema * @param fieldKey */ declare function removeItem(schema: TreeItems, fieldKey: string): TreeItems; /** * 该方法用于快速向check的shcmea中注入vcontol。方便过滤已经设置的表单 * @param obj 待注入vontrol的uiSchema对象 */ declare function injectVcontrol(obj: Record): void; /** * 解析url中?后的参数,返回参数Map * @param url */ declare function parseHrefParam(url: string | undefined): Map; declare function randomString(length: number): string; declare function number2Chinese(num: number): string; // TODO 更新Read more文档 declare function upgradeTips(oldApiName: string, newApiName: string): void; // 转换数组 declare function toArray(param: string | Array): Array; // 处理容器宽度 declare const handleMargin: (style: CSSProperties) => void; /** * 根据uiSchema,获取当前schem相对的主题和组件类型 * @param uiSchema * @returns */ declare const getThemeAndType: (uiSchema: { type: string; theme?: string; } & Map) => string; /** * 将二进制流数据转成base64格式的数据 * * @param file */ declare function binaryData2Blob(file: File): Promise; /** * 将base64g格式的图片地址转成img图片对象 * * @param {string} imgBase64Url */ declare function getImgEl(imgBase64Url: string): Promise; // 尺寸限制 type ImgDimension = Partial<{ width: number; height: number; minWidth: number; minHeight: number; maxWidth: number; maxHeight: number; widthDivisor: number; heightDivisor: number; widthHeightEqual: boolean; }>; // 大小限制 type ImgSize = Partial<{ max: number; min: number; }>; declare function checkImg({ file, dimension, size }: { file: File; dimension?: ImgDimension; size?: ImgSize; }): Promise<{ isOk: boolean; errors: Array; }>; type Get = (fieldKey?: string) => { data: Map | undefined; dataSchema: DataSchema; uiSchema: UiSchema; }; type GetKey = (fieldKey: string, type: "uiSchema" | "dataSchema" | "data" | "unitedSchema") => string; type GetTypeKey = (fieldKey: string) => string | never; type State = { typePath: Record; uiSchema: UiSchema; dataSchema: DataSchema; // 表单数据 formData: Record; errors: Record; // ajv校验错误信息 ajvErrors: Record; // 用户自定义错误信息 customErrors: Record; // 是否正在校验 checking: boolean; // ajv是否已经将dataSchema中的默认值添加到formData中 hasDefault: boolean; // 当前可见的表单 visibleFieldKey: Array; // 当前正在变动的表单 changeKey: string; // 数组容器对应的react key映射 arrayKey: Record>; // 异步校验需要保留的错误key(用于防止异步校验的错误信息被ajv覆盖) ignoreErrKey: Array; }; // 即将废弃,请改用 ResetAction type ReloadAction = { type: "reload"; } & Omit; type ResetAction = { type: "reset"; action: { state: Omit; }; }; // 即将废弃,请改用 SetValidate type SetDataSchemaAction = { type: "setDataSchema"; dataSchema?: DataSchema; isDelete?: boolean; } & Map; type SetValidate = { type: "setValidate"; action: { deleteKeys?: Array | string; dataSchema?: DataSchema; set?: Map; }; }; // 即将废弃,请改用 SetUiAction type SetUiSchemaAction = { type: "setUiSchema"; uiSchema?: UiSchema; } & Map; // 即将废弃,请改用 SetUiAction type DeleteUiSchemaAction = { type: "deleteUiSchema"; key: string; }; type SetUiAction = { type: "setUi"; action: { deleteKeys?: Array | string; uiSchema?: UiSchema; set?: Map; }; }; // 即将废弃,请改用 SetDataAction type SetFormDataAction = { type: "setFormData"; formData?: Map; } & Map; // 即将废弃 改用 SetDataAction type DeleteFormDataAction = { type: "deleteFormData"; key: string; }; type SetDataAction = { type: "setData"; action: { deleteKeys?: string | Array; formData?: Map; set?: Map; }; }; type DeleteFieldAction = { type: "deleteField"; action: { fieldKey: string; get: Get; getKey: GetKey; getTypeKey: GetTypeKey; }; }; type AddFieldAction = { type: "addField"; action: { fieldKey: string; closestEdge: ClosestEdge; unitedSchema: UnitedSchema; overFieldKey: string; get: Get; getKey: GetKey; getTypeKey: GetTypeKey; shouldDelete: boolean; }; }; // 即将废弃 type SetErrType = { type: "setError"; action?: { ignore?: Array; }; } & Record; // 即将废弃 type SetErrsType = { type: "setError"; ignore?: Array; errors?: Record; }; // 即将废弃 请改用 SetErrAction type SetErrorAction = SetErrType | SetErrsType; // 即将废弃 请改用 SetErrAction type DeleteErrorAction = { type: "deleteError"; key: Array | string; }; // 设置自定义错误信息 type SetErrAction = { type: "setErr"; action: { deleteKeys?: Array | string; errors?: Record; set?: Record; }; }; // 设置ajv错误 type SetAjvErrorAction = { type: "setAjvErr"; action: { deleteKeys?: Array | string; errors?: Record; set?: Record; }; }; // 即将废弃 type OldSetCheckingAction = { type: "setChecking"; checking: boolean; }; type NewSetCheckingAction = { type: "setChecking"; action: { checking: boolean; }; }; type SetCheckingAction = OldSetCheckingAction | NewSetCheckingAction; type SetVisibleKeyAction = { type: "setVisibleKey"; action: { deleteKeys?: Array | string; fieldKey?: Array | string; }; }; type SetDefaultSuccessAction = { type: "setDefaultSuccess"; action: { hasDefault: boolean; }; }; // 数组容器设置映射的组件唯一key(避免删除导致的组件渲染问题) type SetArrayKey = { type: "setArrayKey"; action: { // 数组父级fieldKey fieldKey: string; // 添加或删除的位置 (order为undefiedn,则全量设置当前fieldKey的key) order?: number; // 是否删除 默认添加 isDelete?: boolean; // 切换数组的顺序 move?: [ number, number ]; }; }; type Action = ReloadAction | ResetAction | SetDataSchemaAction | SetValidate | SetUiSchemaAction | DeleteUiSchemaAction | SetUiAction | SetFormDataAction | DeleteFormDataAction | SetDataAction | DeleteFieldAction | AddFieldAction | SetErrorAction | SetErrAction | SetAjvErrorAction | DeleteErrorAction | SetCheckingAction | SetVisibleKeyAction | SetDefaultSuccessAction | SetArrayKey; /** * 在联合Schema中,某个节点的类型 */ type FieldAtomType = { fieldKey?: string | number; } & Map; type ContainerStyle = Partial<{ // 表单宽度 width: number | string; // 容器margin-top marginTop: number | string; // 容器margin-right marginRight: number | string; // 容器margin-bottom marginBottom: number | string; // 容器margin-left marginLeft: number | string; // 容器margin margin: string; // 容器padding padding: string; paddingTop: number | string; paddingBottom: number | string; paddingRigth: number | string; paddingLeft: number | string; }> | null; type Description = { type: "icon" | "text"; title: string; } | null; type TitlePlacement = "left" | "right" | "bottom" | "top"; type Theme = "antd" | "babel-ui" | "drip-design" | string; type TitleUi = Partial<{ // 标题宽度 width: number | string; // 标题margin-top marginTop: number | string; // 标题margin-right marginRight: number | string; // 标题margin-bottom marginBottom: number | string; // 标题margin-left marginLeft: number | string; // 标题margin margin: string; // 标题垂直对齐方式 verticalAlign: "center" | "top" | "bottom"; // 标题水平对齐方式 textAlign: "left" | "right" | "center"; // 是否展示必填*号 requiredIcon: boolean; placement: TitlePlacement; color: string; fontSize: number | string; showColon?: boolean; }> | null; type Properties = { [propName: string]: { type: string; title?: TitleUi; showTitle?: boolean; containerStyle?: ContainerStyle; theme?: Theme; description?: Description; [propName: string]: unknown; }; }; /** * @param {string} fieldKey 必填 表单change触发,更改formData的key值 * @param {function} onChange 可选 表单触发change事件后的回调 * @param {object} options 可选 表单字段特殊处理配置。注意:options中只能有一个字段的值是true。否则不会对特殊数据进行格式化 * @param {func} dispatch 操作context */ type OnChange = (({ val, dispatch, fieldKey, getKey, prevFieldData, // 注意目前只有select表单支持这个字段(看后续是否有场景其它表单也需要) fieldData }: { val: any; dispatch: Dispatch; getKey: GetKey; fieldKey: string; prevFieldData: any; // 注意目前只有select表单支持这个字段(看后续是否有场景其它表单也需要) fieldData: any; }) => void) | string; /** * UiSchema的最小原子 */ type UiSchema = { formMode?: "edit" | "view" | "generator"; mode: "add" | "normal" | "collapse" | "tuple" | "fixed"; theme: Theme; type: string; containerStyle?: ContainerStyle; properties: Properties; order: Array; title?: TitleUi; onChange?: OnChange; [propName: string]: unknown; }; /** * DataSchema的最小原子 */ type DataSchema = { type: string; validateTime: "submit" | "change"; requiredMode: "default" | "empty"; properties?: Map; items?: Array | Map; required?: Array; errorMessage?: { required: Map; properties?: Map; items?: Map; [propName: string]: unknown; }; } & Map; /** * 联合Schema格式 */ type UnitedSchema = { theme?: "antd" | "babel-ui" | "drip-design" | string; validateTime?: string; requiredMode?: "default" | "empty"; title?: string; ui?: Map; schema?: Array; items?: Array | Map; } & Map; /** * 解析联合Schema * @param unitedSchema */ declare const parseUnitedSchema: (unitedSchema: UnitedSchema) => { uiSchema: UiSchema; dataSchema: DataSchema; typePath: Map; customProps: string[]; }; type Options = Partial<{ // 是否开启$fieldKey值转换为fieldKey(默认不开启,generator中viewport区域需要开启) $fieldKey: boolean; }>; /** * 融合dataSchema和uiSchema为联合Schema */ declare function combine(dataSchema: DataSchema, uiSchema: UiSchema, options?: Options): UnitedSchema; /** * 树形结构扁平化 * @param items * @param parentFieldKey * @param depth */ declare function flatten(items?: TreeItems, parentFieldKey?: string | null, depth?: number): FlattenedItem[]; declare function flattenTree(items: TreeItems): FlattenedItem[]; /** * 排除在ids列表中的容器及其子表单项,获取已扁平化的待渲染列表 * @param items * @param ids */ declare function removeChildrenOf(items: FlattenedItem[], ids: string[]): FlattenedItem[]; /** * todo: 未知 * @param items * @param itemId */ declare function findItemDeep(items: TreeItems, itemId: string): TreeItem | undefined; /** * todo: 未知 * @param items * @param id */ declare function getChildCount(items: TreeItems, id: string): number; /** * * @param items * @param itemId */ declare function findItem(items: TreeItem[], itemId: string): TreeItem | undefined; /** * * @param flattenedItems */ declare function buildTree(flattenedItems: FlattenedItem[]): TreeItems; export { generateReg, generateArrayKeyReg, typeCheck, isEmpty, setDeepProp, deleteDeepProp, judgeAndRegister, deepClone, setProperty, removeItem, injectVcontrol, parseHrefParam, randomString, number2Chinese, upgradeTips, toArray, handleMargin, getThemeAndType, Map, ClosestEdge, binaryData2Blob, getImgEl, ImgDimension, ImgSize, checkImg, parseUnitedSchema, combine, FieldAtomType, ContainerStyle, Description, TitlePlacement, Theme, TitleUi, OnChange, UiSchema, DataSchema, UnitedSchema, flatten, flattenTree, removeChildrenOf, findItemDeep, getChildCount, findItem, buildTree, TreeItem, TreeItems, FlattenedItem, Get, GetKey, GetTypeKey, State, SetErrType, SetErrsType, Action };