refactor: 解耦fastform -> metaform

pull/81/head
moonrailgun 3 years ago
parent e1d55be242
commit 87d4952fcc

@ -1,27 +1,27 @@
import React, { useMemo } from 'react'; import React, { useMemo } from 'react';
import { import {
FastForm, MetaForm,
regField, regField,
FastFormContainerComponent, MetaFormContainerComponent,
regFormContainer, regFormContainer,
} from 'tailchat-shared'; } from 'meta-form';
import { Form, Button } from 'antd'; import { Form, Button } from 'antd';
import { FastFormText } from './types/Text'; import { MetaFormText } from './types/Text';
import { FastFormTextArea } from './types/TextArea'; import { MetaFormTextArea } from './types/TextArea';
import { FastFormPassword } from './types/Password'; import { MetaFormPassword } from './types/Password';
import { FastFormSelect } from './types/Select'; import { MetaFormSelect } from './types/Select';
import { FastFormCheckbox } from './types/Checkbox'; import { MetaFormCheckbox } from './types/Checkbox';
import { FastFormCustom } from './types/Custom'; import { MetaFormCustom } from './types/Custom';
regField('text', FastFormText); regField('text', MetaFormText);
regField('textarea', FastFormTextArea); regField('textarea', MetaFormTextArea);
regField('password', FastFormPassword); regField('password', MetaFormPassword);
regField('select', FastFormSelect); regField('select', MetaFormSelect);
regField('checkbox', FastFormCheckbox); regField('checkbox', MetaFormCheckbox);
regField('custom', FastFormCustom); regField('custom', MetaFormCustom);
const WebFastFormContainer: FastFormContainerComponent = React.memo((props) => { const WebMetaFormContainer: MetaFormContainerComponent = React.memo((props) => {
const layout = props.layout; const layout = props.layout;
const submitButtonRender = useMemo(() => { const submitButtonRender = useMemo(() => {
return ( return (
@ -64,8 +64,8 @@ const WebFastFormContainer: FastFormContainerComponent = React.memo((props) => {
</Form> </Form>
); );
}); });
WebFastFormContainer.displayName = 'WebFastFormContainer'; WebMetaFormContainer.displayName = 'WebMetaFormContainer';
regFormContainer(WebFastFormContainer); regFormContainer(WebMetaFormContainer);
export const WebFastForm = FastForm; export const WebMetaForm = MetaForm;
WebFastForm.displayName = 'WebFastForm'; WebMetaForm.displayName = 'WebMetaForm';

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Form, Checkbox } from 'antd'; import { Form, Checkbox } from 'antd';
import type { FastFormFieldComponent } from 'tailchat-shared'; import type { MetaFormFieldComponent } from 'meta-form';
import { getValidateStatus } from '../utils'; import { getValidateStatus } from '../utils';
export const FastFormCheckbox: FastFormFieldComponent = React.memo((props) => { export const MetaFormCheckbox: MetaFormFieldComponent = React.memo((props) => {
const { name, label, value, onChange, error } = props; const { name, label, value, onChange, error } = props;
return ( return (
@ -22,4 +22,4 @@ export const FastFormCheckbox: FastFormFieldComponent = React.memo((props) => {
</Form.Item> </Form.Item>
); );
}); });
FastFormCheckbox.displayName = 'FastFormCheckbox'; MetaFormCheckbox.displayName = 'MetaFormCheckbox';

@ -0,0 +1,17 @@
import React from 'react';
import { Form } from 'antd';
import type { MetaFormFieldComponent, MetaFormFieldProps } from 'meta-form';
import { CustomField } from 'meta-form';
export const MetaFormCustom: MetaFormFieldComponent<{
render: (props: MetaFormFieldProps) => React.ReactNode;
}> = React.memo((props) => {
const { label } = props;
return (
<Form.Item label={label}>
<CustomField {...props} />
</Form.Item>
);
});
MetaFormCustom.displayName = 'MetaFormCustom';

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Input, Form } from 'antd'; import { Input, Form } from 'antd';
import type { FastFormFieldComponent } from 'tailchat-shared'; import type { MetaFormFieldComponent } from 'meta-form';
import { getValidateStatus } from '../utils'; import { getValidateStatus } from '../utils';
export const FastFormPassword: FastFormFieldComponent = React.memo((props) => { export const MetaFormPassword: MetaFormFieldComponent = React.memo((props) => {
const { name, label, value, onChange, error, maxLength, placeholder } = props; const { name, label, value, onChange, error, maxLength, placeholder } = props;
return ( return (
@ -24,4 +24,4 @@ export const FastFormPassword: FastFormFieldComponent = React.memo((props) => {
</Form.Item> </Form.Item>
); );
}); });
FastFormPassword.displayName = 'FastFormPassword'; MetaFormPassword.displayName = 'MetaFormPassword';

@ -2,17 +2,17 @@ import React, { useEffect } from 'react';
import { Select, Form } from 'antd'; import { Select, Form } from 'antd';
import _get from 'lodash/get'; import _get from 'lodash/get';
import _isNil from 'lodash/isNil'; import _isNil from 'lodash/isNil';
import type { FastFormFieldComponent } from 'tailchat-shared'; import type { MetaFormFieldComponent } from 'meta-form';
const Option = Select.Option; const Option = Select.Option;
interface FastFormSelectOptionsItem { interface MetaFormSelectOptionsItem {
label: string; label: string;
value: string; value: string;
} }
export const FastFormSelect: FastFormFieldComponent<{ export const MetaFormSelect: MetaFormFieldComponent<{
options: FastFormSelectOptionsItem[]; options: MetaFormSelectOptionsItem[];
}> = React.memo((props) => { }> = React.memo((props) => {
const { name, label, value, onChange, options } = props; const { name, label, value, onChange, options } = props;
@ -35,4 +35,4 @@ export const FastFormSelect: FastFormFieldComponent<{
</Form.Item> </Form.Item>
); );
}); });
FastFormSelect.displayName = 'FastFormSelect'; MetaFormSelect.displayName = 'MetaFormSelect';

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Input, Form } from 'antd'; import { Input, Form } from 'antd';
import type { FastFormFieldComponent } from 'tailchat-shared'; import type { MetaFormFieldComponent } from 'meta-form';
import { getValidateStatus } from '../utils'; import { getValidateStatus } from '../utils';
export const FastFormText: FastFormFieldComponent = React.memo((props) => { export const MetaFormText: MetaFormFieldComponent = React.memo((props) => {
const { name, label, value, onChange, error, maxLength, placeholder } = props; const { name, label, value, onChange, error, maxLength, placeholder } = props;
return ( return (
@ -23,4 +23,4 @@ export const FastFormText: FastFormFieldComponent = React.memo((props) => {
</Form.Item> </Form.Item>
); );
}); });
FastFormText.displayName = 'FastFormText'; MetaFormText.displayName = 'MetaFormText';

@ -1,9 +1,9 @@
import React from 'react'; import React from 'react';
import { Input, Form } from 'antd'; import { Input, Form } from 'antd';
import type { FastFormFieldComponent } from 'tailchat-shared'; import type { MetaFormFieldComponent } from 'meta-form';
import { getValidateStatus } from '../utils'; import { getValidateStatus } from '../utils';
export const FastFormTextArea: FastFormFieldComponent = React.memo((props) => { export const MetaFormTextArea: MetaFormFieldComponent = React.memo((props) => {
const { name, label, value, onChange, error, maxLength, placeholder } = props; const { name, label, value, onChange, error, maxLength, placeholder } = props;
return ( return (
@ -23,4 +23,4 @@ export const FastFormTextArea: FastFormFieldComponent = React.memo((props) => {
</Form.Item> </Form.Item>
); );
}); });
FastFormTextArea.displayName = 'FastFormTextArea'; MetaFormTextArea.displayName = 'MetaFormTextArea';

@ -1,2 +1,10 @@
export { Icon } from './Icon'; export { Icon } from './Icon';
export { Image } from './Image'; export { Image } from './Image';
export { WebMetaForm } from './WebMetaForm';
export {
createMetaFormSchema,
fieldSchema as metaFormFieldSchema,
useMetaFormContext,
} from 'meta-form';
export type { MetaFormFieldMeta } from 'meta-form';

@ -21,6 +21,15 @@
"homepage": "https://github.com/msgbyte/tailchat#readme", "homepage": "https://github.com/msgbyte/tailchat#readme",
"dependencies": { "dependencies": {
"@iconify/react": "^3.2.1", "@iconify/react": "^3.2.1",
"antd": "^4.19.5" "antd": "^4.19.5",
"meta-form": "workspace:^1.0.0"
},
"devDependencies": {
"react": "17.0.2",
"react-dom": "17.0.2"
},
"peerDependencies": {
"react": "17.0.2",
"react-dom": "17.0.2"
} }
} }

@ -0,0 +1,2 @@
# https://npmmirror.com/
registry = https://registry.npmmirror.com

@ -0,0 +1,8 @@
基于Meta信息快速构建Form表单
## Install
```bash
npm install react meta-form
```

@ -0,0 +1,39 @@
{
"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": {
"react": "17.0.2",
"typescript": "^4.5.2"
},
"dependencies": {
"formik": "^2.2.9",
"yup": "^0.32.9"
},
"peerDependencies": {
"react": "17.0.2"
}
}

@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import type { FastFormFieldComponent, FastFormFieldProps } from './field'; import type { MetaFormFieldComponent, MetaFormFieldProps } from './field';
export const CustomField: FastFormFieldComponent<{ export const CustomField: MetaFormFieldComponent<{
render: (props: FastFormFieldProps) => React.ReactNode; render: (props: MetaFormFieldProps) => React.ReactNode;
}> = React.memo((props) => { }> = React.memo((props) => {
const { render, ...others } = props; const { render, ...others } = props;

@ -0,0 +1,29 @@
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;
}

@ -0,0 +1,13 @@
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);
}

@ -3,14 +3,14 @@ import { CustomField } from './CustomField';
/** /**
* *
*/ */
interface FastFormFieldCommon { interface MetaFormFieldCommon {
name: string; // 字段名 name: string; // 字段名
label?: string; // 字段标签 label?: string; // 字段标签
defaultValue?: any; // 默认值 defaultValue?: any; // 默认值
[other: string]: any; // 其他字段 [other: string]: any; // 其他字段
} }
export interface FastFormFieldProps extends FastFormFieldCommon { export interface MetaFormFieldProps extends MetaFormFieldCommon {
value: any; value: any;
error: string | undefined; error: string | undefined;
onChange: (val: any) => void; // 修改数据的回调函数 onChange: (val: any) => void; // 修改数据的回调函数
@ -19,15 +19,15 @@ export interface FastFormFieldProps extends FastFormFieldCommon {
/** /**
* *
*/ */
export type FastFormFieldComponent<T = Record<string, unknown>> = export type MetaFormFieldComponent<T = Record<string, unknown>> =
React.ComponentType<FastFormFieldProps & T>; React.ComponentType<MetaFormFieldProps & T>;
const fieldMap = new Map<string, FastFormFieldComponent>(); const fieldMap = new Map<string, MetaFormFieldComponent>();
/** /**
* *
*/ */
export function regField(type: string, component: FastFormFieldComponent<any>) { export function regField(type: string, component: MetaFormFieldComponent<any>) {
fieldMap.set(type, component); fieldMap.set(type, component);
} }
@ -36,14 +36,14 @@ export function regField(type: string, component: FastFormFieldComponent<any>) {
*/ */
export function getField( export function getField(
type: string type: string
): FastFormFieldComponent<any> | undefined { ): MetaFormFieldComponent<any> | undefined {
return fieldMap.get(type); return fieldMap.get(type);
} }
/** /**
* *
*/ */
export interface FastFormFieldMeta extends FastFormFieldCommon { export interface MetaFormFieldMeta extends MetaFormFieldCommon {
type: string; // 字段类型 type: string; // 字段类型
} }

@ -5,20 +5,20 @@ import _fromPairs from 'lodash/fromPairs';
import _isFunction from 'lodash/isFunction'; import _isFunction from 'lodash/isFunction';
import _isEmpty from 'lodash/isEmpty'; import _isEmpty from 'lodash/isEmpty';
import type { ObjectSchema } from 'yup'; import type { ObjectSchema } from 'yup';
import { FastFormContext } from './context'; import { MetaFormContext } from './context';
import { getField, regField } from './field'; import { getField, regField } from './field';
import type { import type {
FastFormFieldComponent, MetaFormFieldComponent,
FastFormFieldProps, MetaFormFieldProps,
FastFormFieldMeta, MetaFormFieldMeta,
} from './field'; } from './field';
import { getFormContainer } from './container'; import { getFormContainer } from './container';
/** /**
* *
*/ */
export interface FastFormProps { export interface MetaFormProps {
fields: FastFormFieldMeta[]; // 字段详情 fields: MetaFormFieldMeta[]; // 字段详情
schema?: ObjectSchema<any>; // yup schame object 用于表单校验 schema?: ObjectSchema<any>; // yup schame object 用于表单校验
layout?: 'horizontal' | 'vertical'; // 布局方式(默认水平) layout?: 'horizontal' | 'vertical'; // 布局方式(默认水平)
submitLabel?: string; // 提交按钮的标签名 submitLabel?: string; // 提交按钮的标签名
@ -31,7 +31,7 @@ export interface FastFormProps {
* *
* *
*/ */
export const FastForm: React.FC<FastFormProps> = React.memo((props) => { export const MetaForm: React.FC<MetaFormProps> = React.memo((props) => {
const initialValues = useMemo(() => { const initialValues = useMemo(() => {
return { return {
..._fromPairs( ..._fromPairs(
@ -65,10 +65,10 @@ export const FastForm: React.FC<FastFormProps> = React.memo((props) => {
}); });
const { handleSubmit, setFieldValue, values, errors } = formik; const { handleSubmit, setFieldValue, values, errors } = formik;
const FastFormContainer = getFormContainer(); const MetaFormContainer = getFormContainer();
if (_isNil(FastFormContainer)) { if (_isNil(MetaFormContainer)) {
console.warn('FastFormContainer 没有被注册'); console.warn('MetaFormContainer 没有被注册');
return null; return null;
} }
@ -96,8 +96,8 @@ export const FastForm: React.FC<FastFormProps> = React.memo((props) => {
}, [props.fields, values, errors, setFieldValue]); }, [props.fields, values, errors, setFieldValue]);
return ( return (
<FastFormContext.Provider value={formik}> <MetaFormContext.Provider value={formik}>
<FastFormContainer <MetaFormContainer
loading={loading} loading={loading}
layout={props.layout ?? 'horizontal'} layout={props.layout ?? 'horizontal'}
submitLabel={props.submitLabel} submitLabel={props.submitLabel}
@ -105,17 +105,19 @@ export const FastForm: React.FC<FastFormProps> = React.memo((props) => {
canSubmit={_isEmpty(errors)} canSubmit={_isEmpty(errors)}
> >
{fieldsRender} {fieldsRender}
</FastFormContainer> </MetaFormContainer>
</FastFormContext.Provider> </MetaFormContext.Provider>
); );
}); });
FastForm.displayName = 'FastForm'; MetaForm.displayName = 'MetaForm';
FastForm.defaultProps = { MetaForm.defaultProps = {
submitLabel: '提交', submitLabel: '提交',
}; };
export { CustomField } from './CustomField'; export { CustomField } from './CustomField';
export type { FastFormFieldComponent, FastFormFieldProps, FastFormFieldMeta }; export type { MetaFormFieldComponent, MetaFormFieldProps, MetaFormFieldMeta };
export { regField }; export { regField };
export { regFormContainer } from './container'; export { regFormContainer } from './container';
export type { FastFormContainerComponent } from './container'; export type { MetaFormContainerComponent } from './container';
export { createMetaFormSchema, fieldSchema } from './schema';
export { useMetaFormContext } from './context';

@ -3,11 +3,11 @@ import { string, object, ref } from 'yup';
import type { ObjectShape } from 'yup/lib/object'; import type { ObjectShape } from 'yup/lib/object';
/** /**
* FastFormSchema * MetaFormSchema
* *
* *
*/ */
export function createFastFormSchema(fieldMap: ObjectShape) { export function createMetaFormSchema(fieldMap: ObjectShape) {
return object().shape(fieldMap); return object().shape(fieldMap);
} }

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES5",
"lib": ["DOM"],
"jsx": "react",
"outDir": "./lib",
"declaration": true,
"esModuleInterop": true,
"isolatedModules": true,
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"importsNotUsedAsValues": "error",
}
}

File diff suppressed because it is too large Load Diff

@ -1,29 +0,0 @@
import type { ComponentType } from 'react';
/**
*
*/
export interface FastFormContainerProps {
loading: boolean;
submitLabel?: string;
layout?: 'horizontal' | 'vertical';
/**
*
*/
canSubmit?: boolean;
handleSubmit: () => void;
}
export type FastFormContainerComponent =
React.ComponentType<FastFormContainerProps>;
let FastFormContainer: FastFormContainerComponent;
export function regFormContainer(component: FastFormContainerComponent) {
FastFormContainer = component;
}
export function getFormContainer():
| ComponentType<FastFormContainerProps>
| undefined {
return FastFormContainer;
}

@ -1,13 +0,0 @@
import React, { useContext } from 'react';
import type { useFormik } from 'formik';
type FastFormContextType = ReturnType<typeof useFormik>;
export const FastFormContext = React.createContext<FastFormContextType | null>(
null
);
FastFormContext.displayName = 'FastFormContext';
export function useFastFormContext(): FastFormContextType | null {
return useContext(FastFormContext);
}

@ -15,23 +15,6 @@ export {
export { useCachedUserInfo, useCachedOnlineStatus } from './cache/useCache'; export { useCachedUserInfo, useCachedOnlineStatus } from './cache/useCache';
// components // components
export {
FastForm,
CustomField,
regField,
regFormContainer,
} from './components/FastForm/index';
export type {
FastFormFieldComponent,
FastFormFieldProps,
FastFormFieldMeta,
FastFormContainerComponent,
} from './components/FastForm/index';
export {
createFastFormSchema,
fieldSchema,
} from './components/FastForm/schema';
export { useFastFormContext } from './components/FastForm/context';
export { buildPortal, DefaultEventEmitter } from './components/Portal'; export { buildPortal, DefaultEventEmitter } from './components/Portal';
export { TcProvider } from './components/Provider'; export { TcProvider } from './components/Provider';

@ -1,22 +0,0 @@
import React from 'react';
import { Form } from 'antd';
import _get from 'lodash/get';
import _isNil from 'lodash/isNil';
import type {
FastFormFieldComponent,
FastFormFieldProps,
} from 'tailchat-shared';
import { CustomField } from 'tailchat-shared';
export const FastFormCustom: FastFormFieldComponent<{
render: (props: FastFormFieldProps) => React.ReactNode;
}> = React.memo((props) => {
const { label } = props;
return (
<Form.Item label={label}>
<CustomField {...props} />
</Form.Item>
);
});
FastFormCustom.displayName = 'FastFormCustom';

@ -3,16 +3,18 @@ import { setGlobalUserLoginInfo } from '@/utils/user-helper';
import React from 'react'; import React from 'react';
import { import {
claimTemporaryUser, claimTemporaryUser,
createFastFormSchema,
FastFormFieldMeta,
fieldSchema,
t, t,
useAppDispatch, useAppDispatch,
useAsyncRequest, useAsyncRequest,
userActions, userActions,
} from 'tailchat-shared'; } from 'tailchat-shared';
import {
createMetaFormSchema,
MetaFormFieldMeta,
metaFormFieldSchema,
WebMetaForm,
} from 'tailchat-design';
import { ModalWrapper } from '../Modal'; import { ModalWrapper } from '../Modal';
import { WebFastForm } from '../WebFastForm';
interface Values { interface Values {
email: string; email: string;
@ -20,7 +22,7 @@ interface Values {
[key: string]: unknown; [key: string]: unknown;
} }
const fields: FastFormFieldMeta[] = [ const fields: MetaFormFieldMeta[] = [
{ type: 'text', name: 'email', label: t('邮箱') }, { type: 'text', name: 'email', label: t('邮箱') },
{ {
type: 'password', type: 'password',
@ -29,12 +31,12 @@ const fields: FastFormFieldMeta[] = [
}, },
]; ];
const schema = createFastFormSchema({ const schema = createMetaFormSchema({
email: fieldSchema email: metaFormFieldSchema
.string() .string()
.required(t('邮箱不能为空')) .required(t('邮箱不能为空'))
.email(t('邮箱格式不正确')), .email(t('邮箱格式不正确')),
password: fieldSchema password: metaFormFieldSchema
.string() .string()
.min(6, t('密码不能低于6位')) .min(6, t('密码不能低于6位'))
.required(t('密码不能为空')), .required(t('密码不能为空')),
@ -68,7 +70,7 @@ export const ClaimTemporaryUser: React.FC<ClaimTemporaryUserProps> = React.memo(
return ( return (
<ModalWrapper title={t('认领账号')}> <ModalWrapper title={t('认领账号')}>
<WebFastForm schema={schema} fields={fields} onSubmit={handleClaim} /> <WebMetaForm schema={schema} fields={fields} onSubmit={handleClaim} />
</ModalWrapper> </ModalWrapper>
); );
} }

@ -1,26 +1,26 @@
import { findPluginPanelInfoByName } from '@/utils/plugin-helper';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { import {
GroupPanelType,
t, t,
useAsyncRequest, useAsyncRequest,
createGroupPanel, createGroupPanel,
createFastFormSchema,
fieldSchema,
showToasts, showToasts,
} from 'tailchat-shared'; } from 'tailchat-shared';
import {
createMetaFormSchema,
metaFormFieldSchema,
WebMetaForm,
} from 'tailchat-design';
import { ModalWrapper } from '../../Modal'; import { ModalWrapper } from '../../Modal';
import { WebFastForm } from '../../WebFastForm';
import { buildDataFromValues } from './helper'; import { buildDataFromValues } from './helper';
import type { GroupPanelValues } from './types'; import type { GroupPanelValues } from './types';
import { useGroupPanelFields } from './useGroupPanelFields'; import { useGroupPanelFields } from './useGroupPanelFields';
const schema = createFastFormSchema({ const schema = createMetaFormSchema({
name: fieldSchema name: metaFormFieldSchema
.string() .string()
.required(t('面板名不能为空')) .required(t('面板名不能为空'))
.max(20, t('面板名过长')), .max(20, t('面板名过长')),
type: fieldSchema.string().required(t('面板类型不能为空')), type: metaFormFieldSchema.string().required(t('面板类型不能为空')),
}); });
/** /**
@ -45,7 +45,7 @@ export const ModalCreateGroupPanel: React.FC<{
return ( return (
<ModalWrapper title={t('创建群组面板')} style={{ maxWidth: 440 }}> <ModalWrapper title={t('创建群组面板')} style={{ maxWidth: 440 }}>
<WebFastForm <WebMetaForm
schema={schema} schema={schema}
fields={fields} fields={fields}
onChange={setValues} onChange={setValues}

@ -4,24 +4,26 @@ import {
t, t,
useAsyncRequest, useAsyncRequest,
modifyGroupPanel, modifyGroupPanel,
createFastFormSchema,
fieldSchema,
showToasts, showToasts,
useGroupPanelInfo, useGroupPanelInfo,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { ModalWrapper } from '../../Modal'; import { ModalWrapper } from '../../Modal';
import { WebFastForm } from '../../WebFastForm'; import {
createMetaFormSchema,
metaFormFieldSchema,
WebMetaForm,
} from 'tailchat-design';
import { buildDataFromValues, pickValuesFromGroupPanelInfo } from './helper'; import { buildDataFromValues, pickValuesFromGroupPanelInfo } from './helper';
import type { GroupPanelValues } from './types'; import type { GroupPanelValues } from './types';
import { useGroupPanelFields } from './useGroupPanelFields'; import { useGroupPanelFields } from './useGroupPanelFields';
import _omit from 'lodash/omit'; import _omit from 'lodash/omit';
const schema = createFastFormSchema({ const schema = createMetaFormSchema({
name: fieldSchema name: metaFormFieldSchema
.string() .string()
.required(t('面板名不能为空')) .required(t('面板名不能为空'))
.max(20, t('面板名过长')), .max(20, t('面板名过长')),
type: fieldSchema.string().required(t('面板类型不能为空')), type: metaFormFieldSchema.string().required(t('面板类型不能为空')),
}); });
/** /**
@ -56,7 +58,7 @@ export const ModalModifyGroupPanel: React.FC<{
return ( return (
<ModalWrapper title={t('编辑群组面板')} style={{ maxWidth: 440 }}> <ModalWrapper title={t('编辑群组面板')} style={{ maxWidth: 440 }}>
<WebFastForm <WebMetaForm
schema={schema} schema={schema}
fields={fields.filter((f) => f.type !== 'type')} // 变更时不显示类型 fields={fields.filter((f) => f.type !== 'type')} // 变更时不显示类型
initialValues={pickValuesFromGroupPanelInfo(groupPanelInfo)} initialValues={pickValuesFromGroupPanelInfo(groupPanelInfo)}

@ -2,19 +2,18 @@ import { UserSelector } from '@/components/UserSelector';
import React from 'react'; import React from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { import {
FastFormFieldMeta,
GroupPanelType, GroupPanelType,
isDevelopment, isDevelopment,
t, t,
useFastFormContext,
useGroupMemberIds, useGroupMemberIds,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { MetaFormFieldMeta, useMetaFormContext } from 'tailchat-design';
import type { GroupPanelValues } from './types'; import type { GroupPanelValues } from './types';
import _compact from 'lodash/compact'; import _compact from 'lodash/compact';
import { pluginGroupPanel } from '@/plugin/common'; import { pluginGroupPanel } from '@/plugin/common';
import { findPluginPanelInfoByName } from '@/utils/plugin-helper'; import { findPluginPanelInfoByName } from '@/utils/plugin-helper';
const baseFields: FastFormFieldMeta[] = [ const baseFields: MetaFormFieldMeta[] = [
{ type: 'text', name: 'name', label: t('面板名') }, { type: 'text', name: 'name', label: t('面板名') },
{ {
type: 'select', type: 'select',
@ -44,7 +43,7 @@ export function useGroupPanelFields(
const disableSendMessageWithoutRender = useMemo(() => { const disableSendMessageWithoutRender = useMemo(() => {
const DisableSendMessageWithoutComponent: React.FC = () => { const DisableSendMessageWithoutComponent: React.FC = () => {
const groupMemberUUIDs = useGroupMemberIds(groupId); const groupMemberUUIDs = useGroupMemberIds(groupId);
const context = useFastFormContext(); const context = useMetaFormContext();
return ( return (
<UserSelector <UserSelector
@ -80,7 +79,7 @@ export function useGroupPanelFields(
label: t('仅允许指定用户发言'), label: t('仅允许指定用户发言'),
render: disableSendMessageWithoutRender, render: disableSendMessageWithoutRender,
}, },
]) as FastFormFieldMeta[]; ]) as MetaFormFieldMeta[];
} }
if (typeof currentValues.type === 'string') { if (typeof currentValues.type === 'string') {

@ -1,15 +1,17 @@
import React from 'react'; import React from 'react';
import { import {
createFastFormSchema,
FastFormFieldMeta,
fieldSchema,
modifyUserPassword, modifyUserPassword,
showToasts, showToasts,
t, t,
useAsyncRequest, useAsyncRequest,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { ModalWrapper } from '../Modal'; import { ModalWrapper } from '../Modal';
import { WebFastForm } from '../WebFastForm'; import {
createMetaFormSchema,
MetaFormFieldMeta,
metaFormFieldSchema,
WebMetaForm,
} from 'tailchat-design';
interface Values { interface Values {
oldPassword: string; oldPassword: string;
@ -17,7 +19,7 @@ interface Values {
newPasswordRepeat: string; newPasswordRepeat: string;
} }
const fields: FastFormFieldMeta[] = [ const fields: MetaFormFieldMeta[] = [
{ {
type: 'password', type: 'password',
name: 'oldPassword', name: 'oldPassword',
@ -35,16 +37,16 @@ const fields: FastFormFieldMeta[] = [
}, },
]; ];
const schema = createFastFormSchema({ const schema = createMetaFormSchema({
oldPassword: fieldSchema oldPassword: metaFormFieldSchema
.string() .string()
.min(6, t('密码不能低于6位')) .min(6, t('密码不能低于6位'))
.required(t('密码不能为空')), .required(t('密码不能为空')),
newPassword: fieldSchema newPassword: metaFormFieldSchema
.string() .string()
.min(6, t('密码不能低于6位')) .min(6, t('密码不能低于6位'))
.required(t('密码不能为空')), .required(t('密码不能为空')),
newPasswordRepeat: fieldSchema newPasswordRepeat: metaFormFieldSchema
.string() .string()
.min(6, t('密码不能低于6位')) .min(6, t('密码不能低于6位'))
.required(t('密码不能为空')), .required(t('密码不能为空')),
@ -72,7 +74,7 @@ export const ModifyPassword: React.FC<ModifyPasswordProps> = React.memo(
return ( return (
<ModalWrapper title={t('修改密码')}> <ModalWrapper title={t('修改密码')}>
<WebFastForm <WebMetaForm
schema={schema} schema={schema}
fields={fields} fields={fields}
onSubmit={handleModifyPassword} onSubmit={handleModifyPassword}

@ -36,14 +36,24 @@ export {
uploadFile, uploadFile,
showToasts, showToasts,
showErrorToasts, showErrorToasts,
createFastFormSchema,
fieldSchema,
fetchAvailableServices, fetchAvailableServices,
isValidStr, isValidStr,
useGroupPanelInfo, useGroupPanelInfo,
} from 'tailchat-shared'; } from 'tailchat-shared';
export { useLocation, useHistory } from 'react-router'; export { useLocation, useHistory } from 'react-router';
export {
/**
* @deprecated please use createMetaFormSchema
*/
createMetaFormSchema as createFastFormSchema,
/**
* @deprecated please use metaFormFieldSchema
*/
metaFormFieldSchema as fieldSchema,
} from 'tailchat-design';
/** /**
* axiosrequest config * axiosrequest config
* *

@ -3,10 +3,10 @@ import {
buildRegFn, buildRegFn,
buildRegList, buildRegList,
ChatMessage, ChatMessage,
FastFormFieldMeta,
GroupPanel, GroupPanel,
regSocketEventListener, regSocketEventListener,
} from 'tailchat-shared'; } from 'tailchat-shared';
import type { MetaFormFieldMeta } from 'tailchat-design';
/** /**
* *
@ -68,7 +68,7 @@ export interface PluginGroupPanel {
/** /**
* , 使 * , 使
*/ */
extraFormMeta: FastFormFieldMeta[]; extraFormMeta: MetaFormFieldMeta[];
/** /**
* *

@ -15,7 +15,15 @@ export { Image } from '@/components/Image';
export { Icon } from '@/components/Icon'; export { Icon } from '@/components/Icon';
export { PillTabs, PillTabPane } from '@/components/PillTabs'; export { PillTabs, PillTabPane } from '@/components/PillTabs';
export { LoadingSpinner } from '@/components/LoadingSpinner'; export { LoadingSpinner } from '@/components/LoadingSpinner';
export { WebFastForm } from '@/components/WebFastForm'; export {
/**
* @deprecated please use WebMetaForm
*/
WebMetaForm as WebFastForm,
WebMetaForm,
createMetaFormSchema,
metaFormFieldSchema,
} from 'tailchat-design';
export { export {
FullModalField, FullModalField,
DefaultFullModalInputEditorRender, DefaultFullModalInputEditorRender,

Loading…
Cancel
Save