mirror of https://github.com/msgbyte/tailchat
style: remove old meta-form code
parent
79bb323dbe
commit
bfc9853e74
@ -1 +0,0 @@
|
||||
lib
|
@ -1,2 +0,0 @@
|
||||
# https://npmmirror.com/
|
||||
registry = https://registry.npmmirror.com
|
@ -1,8 +0,0 @@
|
||||
基于Meta信息快速构建Form表单
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install react meta-form
|
||||
```
|
@ -1,44 +0,0 @@
|
||||
{
|
||||
"name": "meta-form",
|
||||
"version": "1.0.0",
|
||||
"description": "基于Meta信息快速构建Form表单",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"prepare": "tsc",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/msgbyte/tailchat.git"
|
||||
},
|
||||
"keywords": [
|
||||
"meta",
|
||||
"form",
|
||||
"react",
|
||||
"formik"
|
||||
],
|
||||
"author": "moonrailgun <moonrailgun@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/msgbyte/tailchat/issues"
|
||||
},
|
||||
"homepage": "https://github.com/msgbyte/tailchat#readme",
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.170",
|
||||
"@types/react": "^17.0.39",
|
||||
"react": "17.0.2",
|
||||
"typescript": "^4.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"formik": "^2.2.9",
|
||||
"lodash": "^4.17.21",
|
||||
"yup": "^0.32.9"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "17.0.2"
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import React from 'react';
|
||||
import type { MetaFormFieldComponent, MetaFormFieldProps } from './field';
|
||||
|
||||
export const CustomField: MetaFormFieldComponent<{
|
||||
render: (props: MetaFormFieldProps) => React.ReactNode;
|
||||
}> = React.memo((props) => {
|
||||
const { render, ...others } = props;
|
||||
|
||||
return <>{render(others)}</>;
|
||||
});
|
||||
CustomField.displayName = 'CustomField';
|
@ -1,29 +0,0 @@
|
||||
import type { ComponentType } from 'react';
|
||||
|
||||
/**
|
||||
* 容器配置
|
||||
*/
|
||||
export interface MetaFormContainerProps {
|
||||
loading: boolean;
|
||||
submitLabel?: string;
|
||||
|
||||
layout?: 'horizontal' | 'vertical';
|
||||
|
||||
/**
|
||||
* 是否允许提交
|
||||
*/
|
||||
canSubmit?: boolean;
|
||||
handleSubmit: () => void;
|
||||
}
|
||||
export type MetaFormContainerComponent =
|
||||
React.ComponentType<MetaFormContainerProps>;
|
||||
let MetaFormContainer: MetaFormContainerComponent;
|
||||
export function regFormContainer(component: MetaFormContainerComponent) {
|
||||
MetaFormContainer = component;
|
||||
}
|
||||
|
||||
export function getFormContainer():
|
||||
| ComponentType<MetaFormContainerProps>
|
||||
| undefined {
|
||||
return MetaFormContainer;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import React, { useContext } from 'react';
|
||||
import type { useFormik } from 'formik';
|
||||
|
||||
type MetaFormContextType = ReturnType<typeof useFormik>;
|
||||
|
||||
export const MetaFormContext = React.createContext<MetaFormContextType | null>(
|
||||
null
|
||||
);
|
||||
MetaFormContext.displayName = 'MetaFormContext';
|
||||
|
||||
export function useMetaFormContext(): MetaFormContextType | null {
|
||||
return useContext(MetaFormContext);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
import { CustomField } from './CustomField';
|
||||
|
||||
/**
|
||||
* 字段通用信息
|
||||
*/
|
||||
interface MetaFormFieldCommon {
|
||||
name: string; // 字段名
|
||||
label?: string; // 字段标签
|
||||
defaultValue?: any; // 默认值
|
||||
[other: string]: any; // 其他字段
|
||||
}
|
||||
|
||||
export interface MetaFormFieldProps extends MetaFormFieldCommon {
|
||||
value: any;
|
||||
error: string | undefined;
|
||||
onChange: (val: any) => void; // 修改数据的回调函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段组件
|
||||
*/
|
||||
export type MetaFormFieldComponent<T = Record<string, unknown>> =
|
||||
React.ComponentType<MetaFormFieldProps & T>;
|
||||
|
||||
const fieldMap = new Map<string, MetaFormFieldComponent>();
|
||||
|
||||
/**
|
||||
* 注册组件
|
||||
*/
|
||||
export function regField(type: string, component: MetaFormFieldComponent<any>) {
|
||||
fieldMap.set(type, component);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组件
|
||||
*/
|
||||
export function getField(
|
||||
type: string
|
||||
): MetaFormFieldComponent<any> | undefined {
|
||||
return fieldMap.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段配置
|
||||
*/
|
||||
export interface MetaFormFieldMeta extends MetaFormFieldCommon {
|
||||
type: string; // 字段类型
|
||||
}
|
||||
|
||||
// 内建字段
|
||||
regField('custom', CustomField);
|
@ -1,17 +0,0 @@
|
||||
/* eslint-disable id-blacklist */
|
||||
import { string, object, ref } from 'yup';
|
||||
import type { ObjectShape } from 'yup/lib/object';
|
||||
|
||||
/**
|
||||
* 创建MetaForm的Schema
|
||||
*
|
||||
*
|
||||
*/
|
||||
export function createMetaFormSchema(fieldMap: ObjectShape) {
|
||||
return object().shape(fieldMap);
|
||||
}
|
||||
|
||||
export const fieldSchema = {
|
||||
string,
|
||||
ref,
|
||||
};
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"lib": ["DOM", "ES2015"],
|
||||
"jsx": "react",
|
||||
"outDir": "./lib",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"isolatedModules": true,
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"importsNotUsedAsValues": "error",
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue