@jswork/react-ant-form-schema 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.cjs.js +1 -3
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.d.mts +17 -16
- package/dist/main.d.ts +17 -16
- package/dist/main.esm.js +1 -1
- package/dist/main.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/default-form.tsx +12 -0
- package/src/components/fieldset-groups.tsx +26 -0
- package/src/components/tabs-groups.tsx +31 -0
- package/src/index.tsx +19 -86
- package/src/main.tsx +2 -2
- package/src/types.ts +58 -0
- package/src/utils.ts +0 -20
package/dist/main.cjs.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
2
|
-
|
|
3
|
-
module.exports = exports.default;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var E=Object.defineProperty;var n=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var h=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t)=>{for(var r in t||(t={}))b.call(t,r)&&h(e,r,t[r]);if(n)for(var r of n(t))F.call(t,r)&&h(e,r,t[r]);return e};var m=(e,t)=>E(e,"name",{value:t,configurable:!0});var N=(e,t)=>{var r={};for(var o in e)b.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&n)for(var o of n(e))t.indexOf(o)<0&&F.call(e,o)&&(r[o]=e[o]);return r};var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames);var _react = require('react'); var _react2 = _interopRequireDefault(_react);var _antd = require('antd');var _niceformreact = require('@ebay/nice-form-react'); var _niceformreact2 = _interopRequireDefault(_niceformreact);var k=m(({meta:e})=>_react2.default.createElement(_niceformreact2.default,{meta:e}),"DefaultForm"),g=k;var I=m(({groups:e,defaultMeta:t})=>_react2.default.createElement("div",{className:"react-ant-form-schema-groups"},e.map((r,o)=>{let s=a(a({},t),r.meta);return _react2.default.createElement("fieldset",{key:o,className:"react-ant-form-schema-fieldset"},_react2.default.createElement("legend",{className:"react-ant-form-schema-legend"},r.title),_react2.default.createElement(_niceformreact2.default,{meta:s}))})),"FieldsetGroups"),M=I;var B=m(({groups:e,defaultMeta:t,tabProps:r})=>{let o=e.map(s=>{let f=a(a({},t),s.meta);return{key:s.title,label:s.title,children:_react2.default.createElement(_niceformreact2.default,{meta:f})}});return _react2.default.createElement(_antd.Tabs,a({items:o,className:"react-ant-form-schema-tabs"},r))},"TabsGroups"),R=B;var p=(function(e){return e.Fieldset="fieldset",e.Tabs="tabs",e})({});var y="react-ant-form-schema",j={vertical:{labelWidth:24},horizontal:{labelWidth:4}},q={header:null,layout:"horizontal"},H=_react2.default.forwardRef((e,t)=>{let d=a(a({},q),e),{className:r,meta:o,header:s,children:f,actionsClassName:G,layout:u}=d,C=N(d,["className","meta","header","children","actionsClassName","layout"]),S=f,c=j[u],v=o.groups&&o.groups.length>0,z=o.groupsMode||p.Fieldset,D=m(()=>v?z===p.Tabs?_react2.default.createElement(R,{groups:o.groups,defaultMeta:c,tabProps:o.tabProps}):_react2.default.createElement(M,{groups:o.groups,defaultMeta:c}):_react2.default.createElement(g,{meta:a(a({},c),o)}),"renderContent");return _react2.default.createElement(_antd.Form,a({"data-component":y,className:_classnames2.default.call(void 0, y,r),layout:u,ref:t},C),s,D(),_react2.default.createElement(_antd.Form.Item,{wrapperCol:{offset:u==="horizontal"?c==null?void 0:c.labelWidth:0},className:G,style:{marginBottom:0}},S))}),A=H;var Ee=A;exports.GroupsMode = p; exports.default = Ee;
|
|
4
2
|
//# sourceMappingURL=main.cjs.js.map
|
package/dist/main.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/feizheng/github/react-ant-form-schema/packages/lib/dist/main.cjs.js","../src/index.tsx","../src/utils.ts","../src/main.tsx"],"names":["deepMerge","target","source","result","__spreadValues","key","Array","isArray","CLASS_NAME","DEFAULT_META","vertical","labelWidth","horizontal","defaultProps","header","layout","ReactAntdFormSchema","React","forwardRef","props","ref","_a","className","meta","children","actionsClassName","rest","footerNode","_meta","_offset","isGroupsMode","groups","length","groupsMode","renderGroupsContent","__name","tabItems","map","group","index","groupMeta","String","label","title","NiceForm","Tabs","items","tabProps","div","fieldset","legend","Form","data-component","cx","Item","wrapperCol","offset","style","marginBottom","index_default","main_default"],"mappings":"AAAA,6KAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,qBAAA,CAAA,IAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,cAAA,CAAA,CAAA,CAAA,MAAA,CAAA,SAAA,CAAA,oBAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,GAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,UAAM,CAAM,CAAC,CAAA,CAAA,YAAc,CAAC,CAAA,CAAA,CAAA,QAAM,CAAM,CAAC,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqB,CAAC,CAAA,CAAA,CAAA,CAAI,EAAE,CAAA,GAAA,CAAA,IAAO,EAAA,GAAA,CAAA,EAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAc,CAAC,CAAC,CAAC,CAAA,EAAA,CAAA,CAAA,CAAM,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAU,CAAA,CAAA,CAAA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,SAAAA,CAAWG,CAAAA,CACXgC,KAAAA,CAAO,CAAEC,YAAAA,CAAc,CAAE,CAAA,CAAA,CACxB/B,CAAAA,CAAAA,CAIT,CAAA,CAAA,CAGFgC,CAAAA,CAAe3C,CAAAA,CEvIf,IAAA4C,CAAAA,CAAe5C,CAAAA,CAAAA,oBAAAA","file":"/Users/feizheng/github/react-ant-form-schema/packages/lib/dist/main.cjs.js","sourcesContent":[null,"import cx from 'classnames';\nimport React, { ReactNode } from 'react';\nimport { Form, FormInstance, FormProps, Tabs, TabsProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { deepMerge } from './utils';\n\nexport type GroupsMode = 'fieldset' | 'tabs';\n\nexport type NiceFormGroup = {\n /**\n * The group title displayed in legend.\n */\n title: string;\n /**\n * The form meta for this group.\n */\n meta: NiceFormMeta;\n};\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n vertical: {\n labelWidth: 24,\n },\n // 这个是 nice-form-react 默认的 meta 数据,其它设置不生效\n // wrapperProps.labelCol.span 这个属性是 deprecated 的,请使用 labelWidth\n horizontal: {\n labelWidth: 4,\n },\n};\n\nexport type ReactAntdFormSchemaMeta = NiceFormMeta & {\n /**\n * Form groups for grouped mode.\n * When groups is provided, fields will be rendered in groups.\n */\n groups?: NiceFormGroup[];\n /**\n * Display mode for groups.\n * - 'fieldset': Render groups as fieldset/legend elements\n * - 'tabs': Render groups as tabs\n */\n groupsMode?: GroupsMode;\n /**\n * Props to pass to Tabs component when groupsMode is 'tabs'.\n */\n tabProps?: TabsProps;\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The form schema meta data.\n */\n meta: ReactAntdFormSchemaMeta;\n /**\n * The header content.\n */\n header?: ReactNode;\n /**\n * The form actions className.\n */\n actionsClassName?: string;\n} & FormProps;\n\nconst defaultProps: Partial<ReactAntdFormSchemaProps> = {\n header: null,\n layout: 'horizontal',\n};\n\nconst ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaProps>(\n (props, ref) => {\n const { className, meta, header, children, actionsClassName, layout, ...rest } = {\n ...defaultProps,\n ...props,\n };\n const footerNode = children as ReactNode;\n const _meta = deepMerge(DEFAULT_META[layout!], meta) as NiceFormMeta;\n const _offset = layout === 'horizontal' ? _meta?.labelWidth : 0;\n\n // Check if groups mode is enabled\n const isGroupsMode = meta.groups && meta.groups.length > 0;\n const groupsMode = meta.groupsMode || 'fieldset';\n\n const renderGroupsContent = () => {\n if (groupsMode === 'tabs') {\n const tabItems = meta.groups!.map((group, index) => {\n const groupMeta = deepMerge(DEFAULT_META[layout!], group.meta) as NiceFormMeta;\n return {\n key: String(index),\n label: group.title,\n children: <NiceForm meta={groupMeta} />,\n };\n });\n return (\n <Tabs\n items={tabItems}\n className=\"react-ant-form-schema-tabs\"\n {...meta.tabProps}\n />\n );\n } else {\n // fieldset mode (default)\n return (\n <div className=\"react-ant-form-schema-groups\">\n {meta.groups?.map((group, index) => {\n const groupMeta = deepMerge(DEFAULT_META[layout!], group.meta) as NiceFormMeta;\n return (\n <fieldset key={index} className=\"react-ant-form-schema-fieldset\">\n <legend className=\"react-ant-form-schema-legend\">{group.title}</legend>\n <NiceForm meta={groupMeta} />\n </fieldset>\n );\n })}\n </div>\n );\n }\n };\n\n return (\n <Form\n data-component={CLASS_NAME}\n className={cx(CLASS_NAME, className)}\n layout={layout}\n ref={ref}\n {...rest}>\n {header}\n {isGroupsMode ? renderGroupsContent() : <NiceForm meta={_meta} />}\n <Form.Item\n wrapperCol={{ offset: _offset }}\n className={actionsClassName}\n style={{ marginBottom: 0 }}>\n {footerNode}\n </Form.Item>\n </Form>\n );\n },\n);\n\nexport default ReactAntdFormSchema;\n","/**\n * @Author: aric 1290657123@qq.com\n * @Date: 2025-10-18 21:20:55\n * @LastEditors: aric 1290657123@qq.com\n * @LastEditTime: 2025-10-22 08:55:52\n */\n\ntype AnyObject = { [key: string]: any };\n\nexport function deepMerge(target: AnyObject, source: AnyObject) {\n const result = { ...target };\n for (const key in source) {\n if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {\n result[key] = deepMerge(result[key] || {}, source[key]);\n } else {\n result[key] = source[key];\n }\n }\n return result;\n}\n","import ReactAntdFormSchema from '.';\nimport { ReactAntdFormSchemaProps } from '.';\n\nexport default ReactAntdFormSchema;\nexport type { ReactAntdFormSchemaProps };\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/feizheng/github/react-ant-form-schema/packages/lib/dist/main.cjs.js","../src/index.tsx","../src/components/default-form.tsx","../src/components/fieldset-groups.tsx","../src/components/tabs-groups.tsx","../src/types.ts","../src/main.tsx"],"names":["DefaultForm","__name","meta","React","NiceForm","default_form_default","FieldsetGroups","groups","defaultMeta","div","className","map","group","index","groupMeta","__spreadValues","fieldset","key","legend","title","fieldset_groups_default","TabsGroups","tabProps","tabItems","label","children","Tabs","items","tabs_groups_default","GroupsMode","CLASS_NAME","DEFAULT_META","vertical","labelWidth","horizontal","defaultProps","header","layout","ReactAntdFormSchema","forwardRef","props","ref","_a","actionsClassName","rest","footerNode","isGroupsMode","length","groupsMode","Fieldset","renderContent","Form","data-component","cx","Item","wrapperCol","offset","style","marginBottom","index_default","main_default"],"mappings":"AAAA,6KAAI,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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AAAA,CAAMa,CAAAA,CAAAA,CAAAA,CAAA,CAAA,CAAA,CAAKP,CAAAA,CAAAA,CAAgBN,CAAAA,CAAAA,CAAAA,CAAAA,CAT3B,eAAA,CAAA,CAYtB,OACEC,eAAAA,CAAA,aAAA,CAACgD,UAAAA,CAAAA,CAAAA,CAAAA,CACCC,gBAAAA,CAAgBtB,CAAAA,CAChBpB,SAAAA,CAAW2C,kCAAAA,CAAGvB,CAAYpB,CAAAA,CAAAA,CAC1B2B,MAAAA,CAAQA,CAAAA,CACRI,GAAAA,CAAKA,CAAAA,CAAAA,CACDG,CAAAA,CAAAA,CACHR,CAAAA,CACAc,CAAAA,CAAAA,CAAAA,CACD/C,eAAAA,CAAA,aAAA,CAACgD,UAAAA,CAAKG,IAAAA,CAAI,CACRC,UAAAA,CAAY,CAAEC,MAAAA,CAAQnB,CAAAA,GAAW,YAAA,CAAe7B,CAAAA,EAAAA,IAAAA,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA,CAAayB,UAAAA,CAAa,CAAE,CAAA,CAC5EvB,SAAAA,CAAWiC,CAAAA,CACXc,KAAAA,CAAO,CAAEC,YAAAA,CAAc,CAAE,CAAA,CAAA,CACxBb,CAAAA,CAAAA,CAIT,CAAA,CAAA,CAGFc,CAAAA,CAAerB,CAAAA,CKnEf,IAAAsB,EAAAA,CAAetB,CAAAA,CAAAA,6CAAAA","file":"/Users/feizheng/github/react-ant-form-schema/packages/lib/dist/main.cjs.js","sourcesContent":[null,"import cx from 'classnames';\nimport React, { type ReactNode } from 'react';\nimport { Form, type FormInstance } from 'antd';\nimport DefaultForm from './components/default-form';\nimport FieldsetGroups from './components/fieldset-groups';\nimport TabsGroups from './components/tabs-groups';\nimport { ReactAntdFormSchemaProps, GroupsMode } from './types';\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n vertical: {\n labelWidth: 24,\n },\n // 这个是 nice-form-react 默认的 meta 数据,其它设置不生效\n // wrapperProps.labelCol.span 这个属性是 deprecated 的,请使用 labelWidth\n horizontal: {\n labelWidth: 4,\n },\n};\n\nconst defaultProps: Partial<ReactAntdFormSchemaProps> = {\n header: null,\n layout: 'horizontal',\n};\n\nconst ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaProps>(\n (props, ref) => {\n const { className, meta, header, children, actionsClassName, layout, ...rest } = {\n ...defaultProps,\n ...props,\n };\n const footerNode = children as ReactNode;\n const defaultMeta = DEFAULT_META[layout!];\n\n // Check if groups mode is enabled\n const isGroupsMode = meta.groups && meta.groups.length > 0;\n const groupsMode = meta.groupsMode || GroupsMode.Fieldset;\n\n // Render form content based on mode\n const renderContent = () => {\n if (isGroupsMode) {\n if (groupsMode === GroupsMode.Tabs) {\n return <TabsGroups groups={meta.groups!} defaultMeta={defaultMeta} tabProps={meta.tabProps} />;\n }\n // fieldset mode (default)\n return <FieldsetGroups groups={meta.groups!} defaultMeta={defaultMeta} />;\n }\n // standard mode\n return <DefaultForm meta={{ ...defaultMeta, ...meta }} />;\n };\n\n return (\n <Form\n data-component={CLASS_NAME}\n className={cx(CLASS_NAME, className)}\n layout={layout}\n ref={ref}\n {...rest}>\n {header}\n {renderContent()}\n <Form.Item\n wrapperCol={{ offset: layout === 'horizontal' ? defaultMeta?.labelWidth : 0 }}\n className={actionsClassName}\n style={{ marginBottom: 0 }}>\n {footerNode}\n </Form.Item>\n </Form>\n );\n },\n);\n\nexport default ReactAntdFormSchema;\n","import React from 'react';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\n\nexport type DefaultFormProps = {\n meta: NiceFormMeta;\n};\n\nconst DefaultForm = ({ meta }: DefaultFormProps) => {\n return <NiceForm meta={meta} />;\n};\n\nexport default DefaultForm;\n","import React from 'react';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { NiceFormGroup } from '../types';\n\nexport type FieldsetGroupsProps = {\n groups: NiceFormGroup[];\n defaultMeta: Record<string, any>;\n};\n\nconst FieldsetGroups = ({ groups, defaultMeta }: FieldsetGroupsProps) => {\n return (\n <div className=\"react-ant-form-schema-groups\">\n {groups.map((group, index) => {\n const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;\n return (\n <fieldset key={index} className=\"react-ant-form-schema-fieldset\">\n <legend className=\"react-ant-form-schema-legend\">{group.title}</legend>\n <NiceForm meta={groupMeta} />\n </fieldset>\n );\n })}\n </div>\n );\n};\n\nexport default FieldsetGroups;\n","import React from 'react';\nimport { Tabs, TabsProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { NiceFormGroup } from '../types';\n\nexport type TabsGroupsProps = {\n groups: NiceFormGroup[];\n defaultMeta: Record<string, any>;\n tabProps?: TabsProps;\n};\n\nconst TabsGroups = ({ groups, defaultMeta, tabProps }: TabsGroupsProps) => {\n const tabItems = groups.map((group) => {\n const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;\n return {\n key: group.title,\n label: group.title,\n children: <NiceForm meta={groupMeta} />,\n };\n });\n\n return (\n <Tabs\n items={tabItems}\n className=\"react-ant-form-schema-tabs\"\n {...tabProps}\n />\n );\n};\n\nexport default TabsGroups;\n","import { TabsProps } from 'antd';\nimport { NiceFormMeta, NiceFormField } from '@ebay/nice-form-react';\nimport { ReactNode } from 'react';\nimport { FormProps } from 'antd';\n\nexport enum GroupsMode {\n Fieldset = 'fieldset',\n Tabs = 'tabs',\n}\n\nexport type NiceFormGroup = {\n /**\n * The group title displayed in legend or tab.\n */\n title: string;\n /**\n * The form meta for this group.\n */\n meta: NiceFormMeta;\n};\n\nexport type ReactAntdFormSchemaMeta = Omit<NiceFormMeta, 'fields'> & {\n /**\n * Form fields for standard mode.\n * Either fields or groups must be provided.\n */\n fields?: NiceFormField[];\n /**\n * Form groups for grouped mode.\n * When groups is provided, fields will be rendered in groups.\n */\n groups?: NiceFormGroup[];\n /**\n * Display mode for groups.\n * - 'fieldset': Render groups as fieldset/legend elements\n * - 'tabs': Render groups as tabs\n */\n groupsMode?: GroupsMode;\n /**\n * Props to pass to Tabs component when groupsMode is 'tabs'.\n */\n tabProps?: TabsProps;\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The form schema meta data.\n */\n meta: ReactAntdFormSchemaMeta;\n /**\n * The header content.\n */\n header?: ReactNode;\n /**\n * The form actions className.\n */\n actionsClassName?: string;\n} & FormProps;\n","import ReactAntdFormSchema from '.';\nexport type { ReactAntdFormSchemaProps, ReactAntdFormSchemaMeta } from './types';\nexport { GroupsMode } from './types';\n\nexport default ReactAntdFormSchema;\n"]}
|
package/dist/main.d.mts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as antd from 'antd';
|
|
2
2
|
import { TabsProps, FormProps, FormInstance } from 'antd';
|
|
3
|
-
import { NiceFormMeta } from '@ebay/nice-form-react';
|
|
3
|
+
import { NiceFormMeta, NiceFormField } from '@ebay/nice-form-react';
|
|
4
|
+
import React, { ReactNode } from 'react';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
declare enum GroupsMode {
|
|
7
|
+
Fieldset = "fieldset",
|
|
8
|
+
Tabs = "tabs"
|
|
9
|
+
}
|
|
6
10
|
type NiceFormGroup = {
|
|
7
11
|
/**
|
|
8
|
-
* The group title displayed in legend.
|
|
12
|
+
* The group title displayed in legend or tab.
|
|
9
13
|
*/
|
|
10
14
|
title: string;
|
|
11
15
|
/**
|
|
@@ -13,7 +17,12 @@ type NiceFormGroup = {
|
|
|
13
17
|
*/
|
|
14
18
|
meta: NiceFormMeta;
|
|
15
19
|
};
|
|
16
|
-
type ReactAntdFormSchemaMeta = NiceFormMeta & {
|
|
20
|
+
type ReactAntdFormSchemaMeta = Omit<NiceFormMeta, 'fields'> & {
|
|
21
|
+
/**
|
|
22
|
+
* Form fields for standard mode.
|
|
23
|
+
* Either fields or groups must be provided.
|
|
24
|
+
*/
|
|
25
|
+
fields?: NiceFormField[];
|
|
17
26
|
/**
|
|
18
27
|
* Form groups for grouped mode.
|
|
19
28
|
* When groups is provided, fields will be rendered in groups.
|
|
@@ -44,19 +53,11 @@ type ReactAntdFormSchemaProps = {
|
|
|
44
53
|
*/
|
|
45
54
|
actionsClassName?: string;
|
|
46
55
|
} & FormProps;
|
|
56
|
+
|
|
47
57
|
declare const ReactAntdFormSchema: React.ForwardRefExoticComponent<{
|
|
48
|
-
/**
|
|
49
|
-
* The form schema meta data.
|
|
50
|
-
*/
|
|
51
58
|
meta: ReactAntdFormSchemaMeta;
|
|
52
|
-
/**
|
|
53
|
-
* The header content.
|
|
54
|
-
*/
|
|
55
59
|
header?: ReactNode;
|
|
56
|
-
/**
|
|
57
|
-
* The form actions className.
|
|
58
|
-
*/
|
|
59
60
|
actionsClassName?: string;
|
|
60
|
-
} & FormProps<any> & React.RefAttributes<FormInstance<any>>>;
|
|
61
|
+
} & antd.FormProps<any> & React.RefAttributes<FormInstance<any>>>;
|
|
61
62
|
|
|
62
|
-
export { type ReactAntdFormSchemaProps, ReactAntdFormSchema as default };
|
|
63
|
+
export { GroupsMode, type ReactAntdFormSchemaMeta, type ReactAntdFormSchemaProps, ReactAntdFormSchema as default };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as antd from 'antd';
|
|
2
2
|
import { TabsProps, FormProps, FormInstance } from 'antd';
|
|
3
|
-
import { NiceFormMeta } from '@ebay/nice-form-react';
|
|
3
|
+
import { NiceFormMeta, NiceFormField } from '@ebay/nice-form-react';
|
|
4
|
+
import React, { ReactNode } from 'react';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
declare enum GroupsMode {
|
|
7
|
+
Fieldset = "fieldset",
|
|
8
|
+
Tabs = "tabs"
|
|
9
|
+
}
|
|
6
10
|
type NiceFormGroup = {
|
|
7
11
|
/**
|
|
8
|
-
* The group title displayed in legend.
|
|
12
|
+
* The group title displayed in legend or tab.
|
|
9
13
|
*/
|
|
10
14
|
title: string;
|
|
11
15
|
/**
|
|
@@ -13,7 +17,12 @@ type NiceFormGroup = {
|
|
|
13
17
|
*/
|
|
14
18
|
meta: NiceFormMeta;
|
|
15
19
|
};
|
|
16
|
-
type ReactAntdFormSchemaMeta = NiceFormMeta & {
|
|
20
|
+
type ReactAntdFormSchemaMeta = Omit<NiceFormMeta, 'fields'> & {
|
|
21
|
+
/**
|
|
22
|
+
* Form fields for standard mode.
|
|
23
|
+
* Either fields or groups must be provided.
|
|
24
|
+
*/
|
|
25
|
+
fields?: NiceFormField[];
|
|
17
26
|
/**
|
|
18
27
|
* Form groups for grouped mode.
|
|
19
28
|
* When groups is provided, fields will be rendered in groups.
|
|
@@ -44,21 +53,13 @@ type ReactAntdFormSchemaProps = {
|
|
|
44
53
|
*/
|
|
45
54
|
actionsClassName?: string;
|
|
46
55
|
} & FormProps;
|
|
56
|
+
|
|
47
57
|
declare const ReactAntdFormSchema: React.ForwardRefExoticComponent<{
|
|
48
|
-
/**
|
|
49
|
-
* The form schema meta data.
|
|
50
|
-
*/
|
|
51
58
|
meta: ReactAntdFormSchemaMeta;
|
|
52
|
-
/**
|
|
53
|
-
* The header content.
|
|
54
|
-
*/
|
|
55
59
|
header?: ReactNode;
|
|
56
|
-
/**
|
|
57
|
-
* The form actions className.
|
|
58
|
-
*/
|
|
59
60
|
actionsClassName?: string;
|
|
60
|
-
} & FormProps<any> & React.RefAttributes<FormInstance<any>>>;
|
|
61
|
+
} & antd.FormProps<any> & React.RefAttributes<FormInstance<any>>>;
|
|
61
62
|
|
|
62
63
|
// @ts-ignore
|
|
63
64
|
export = ReactAntdFormSchema;
|
|
64
|
-
export type
|
|
65
|
+
export { GroupsMode, type ReactAntdFormSchemaMeta, type ReactAntdFormSchemaProps };
|
package/dist/main.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E=Object.defineProperty;var n=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var h=(e,t,r)=>t in e?E(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,a=(e,t)=>{for(var r in t||(t={}))b.call(t,r)&&h(e,r,t[r]);if(n)for(var r of n(t))F.call(t,r)&&h(e,r,t[r]);return e};var m=(e,t)=>E(e,"name",{value:t,configurable:!0});var N=(e,t)=>{var r={};for(var o in e)b.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(e!=null&&n)for(var o of n(e))t.indexOf(o)<0&&F.call(e,o)&&(r[o]=e[o]);return r};import U from"classnames";import l from"react";import{Form as T}from"antd";import P from"react";import W from"@ebay/nice-form-react";var k=m(({meta:e})=>P.createElement(W,{meta:e}),"DefaultForm"),g=k;import i from"react";import w from"@ebay/nice-form-react";var I=m(({groups:e,defaultMeta:t})=>i.createElement("div",{className:"react-ant-form-schema-groups"},e.map((r,o)=>{let s=a(a({},t),r.meta);return i.createElement("fieldset",{key:o,className:"react-ant-form-schema-fieldset"},i.createElement("legend",{className:"react-ant-form-schema-legend"},r.title),i.createElement(w,{meta:s}))})),"FieldsetGroups"),M=I;import x from"react";import{Tabs as L}from"antd";import _ from"@ebay/nice-form-react";var B=m(({groups:e,defaultMeta:t,tabProps:r})=>{let o=e.map(s=>{let f=a(a({},t),s.meta);return{key:s.title,label:s.title,children:x.createElement(_,{meta:f})}});return x.createElement(L,a({items:o,className:"react-ant-form-schema-tabs"},r))},"TabsGroups"),R=B;var p=(function(e){return e.Fieldset="fieldset",e.Tabs="tabs",e})({});var y="react-ant-form-schema",j={vertical:{labelWidth:24},horizontal:{labelWidth:4}},q={header:null,layout:"horizontal"},H=l.forwardRef((e,t)=>{let d=a(a({},q),e),{className:r,meta:o,header:s,children:f,actionsClassName:G,layout:u}=d,C=N(d,["className","meta","header","children","actionsClassName","layout"]),S=f,c=j[u],v=o.groups&&o.groups.length>0,z=o.groupsMode||p.Fieldset,D=m(()=>v?z===p.Tabs?l.createElement(R,{groups:o.groups,defaultMeta:c,tabProps:o.tabProps}):l.createElement(M,{groups:o.groups,defaultMeta:c}):l.createElement(g,{meta:a(a({},c),o)}),"renderContent");return l.createElement(T,a({"data-component":y,className:U(y,r),layout:u,ref:t},C),s,D(),l.createElement(T.Item,{wrapperCol:{offset:u==="horizontal"?c==null?void 0:c.labelWidth:0},className:G,style:{marginBottom:0}},S))}),A=H;var Ee=A;export{p as GroupsMode,Ee as default};
|
|
2
2
|
//# sourceMappingURL=main.esm.js.map
|
package/dist/main.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx","../src/components/default-form.tsx","../src/components/fieldset-groups.tsx","../src/components/tabs-groups.tsx","../src/types.ts","../src/main.tsx"],"sourcesContent":["import cx from 'classnames';\nimport React, { type ReactNode } from 'react';\nimport { Form, type FormInstance } from 'antd';\nimport DefaultForm from './components/default-form';\nimport FieldsetGroups from './components/fieldset-groups';\nimport TabsGroups from './components/tabs-groups';\nimport { ReactAntdFormSchemaProps, GroupsMode } from './types';\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n vertical: {\n labelWidth: 24,\n },\n // 这个是 nice-form-react 默认的 meta 数据,其它设置不生效\n // wrapperProps.labelCol.span 这个属性是 deprecated 的,请使用 labelWidth\n horizontal: {\n labelWidth: 4,\n },\n};\n\nconst defaultProps: Partial<ReactAntdFormSchemaProps> = {\n header: null,\n layout: 'horizontal',\n};\n\nconst ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaProps>(\n (props, ref) => {\n const { className, meta, header, children, actionsClassName, layout, ...rest } = {\n ...defaultProps,\n ...props,\n };\n const footerNode = children as ReactNode;\n const defaultMeta = DEFAULT_META[layout!];\n\n // Check if groups mode is enabled\n const isGroupsMode = meta.groups && meta.groups.length > 0;\n const groupsMode = meta.groupsMode || GroupsMode.Fieldset;\n\n // Render form content based on mode\n const renderContent = () => {\n if (isGroupsMode) {\n if (groupsMode === GroupsMode.Tabs) {\n return <TabsGroups groups={meta.groups!} defaultMeta={defaultMeta} tabProps={meta.tabProps} />;\n }\n // fieldset mode (default)\n return <FieldsetGroups groups={meta.groups!} defaultMeta={defaultMeta} />;\n }\n // standard mode\n return <DefaultForm meta={{ ...defaultMeta, ...meta }} />;\n };\n\n return (\n <Form\n data-component={CLASS_NAME}\n className={cx(CLASS_NAME, className)}\n layout={layout}\n ref={ref}\n {...rest}>\n {header}\n {renderContent()}\n <Form.Item\n wrapperCol={{ offset: layout === 'horizontal' ? defaultMeta?.labelWidth : 0 }}\n className={actionsClassName}\n style={{ marginBottom: 0 }}>\n {footerNode}\n </Form.Item>\n </Form>\n );\n },\n);\n\nexport default ReactAntdFormSchema;\n","import React from 'react';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\n\nexport type DefaultFormProps = {\n meta: NiceFormMeta;\n};\n\nconst DefaultForm = ({ meta }: DefaultFormProps) => {\n return <NiceForm meta={meta} />;\n};\n\nexport default DefaultForm;\n","import React from 'react';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { NiceFormGroup } from '../types';\n\nexport type FieldsetGroupsProps = {\n groups: NiceFormGroup[];\n defaultMeta: Record<string, any>;\n};\n\nconst FieldsetGroups = ({ groups, defaultMeta }: FieldsetGroupsProps) => {\n return (\n <div className=\"react-ant-form-schema-groups\">\n {groups.map((group, index) => {\n const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;\n return (\n <fieldset key={index} className=\"react-ant-form-schema-fieldset\">\n <legend className=\"react-ant-form-schema-legend\">{group.title}</legend>\n <NiceForm meta={groupMeta} />\n </fieldset>\n );\n })}\n </div>\n );\n};\n\nexport default FieldsetGroups;\n","import React from 'react';\nimport { Tabs, TabsProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { NiceFormGroup } from '../types';\n\nexport type TabsGroupsProps = {\n groups: NiceFormGroup[];\n defaultMeta: Record<string, any>;\n tabProps?: TabsProps;\n};\n\nconst TabsGroups = ({ groups, defaultMeta, tabProps }: TabsGroupsProps) => {\n const tabItems = groups.map((group) => {\n const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;\n return {\n key: group.title,\n label: group.title,\n children: <NiceForm meta={groupMeta} />,\n };\n });\n\n return (\n <Tabs\n items={tabItems}\n className=\"react-ant-form-schema-tabs\"\n {...tabProps}\n />\n );\n};\n\nexport default TabsGroups;\n","import { TabsProps } from 'antd';\nimport { NiceFormMeta, NiceFormField } from '@ebay/nice-form-react';\nimport { ReactNode } from 'react';\nimport { FormProps } from 'antd';\n\nexport enum GroupsMode {\n Fieldset = 'fieldset',\n Tabs = 'tabs',\n}\n\nexport type NiceFormGroup = {\n /**\n * The group title displayed in legend or tab.\n */\n title: string;\n /**\n * The form meta for this group.\n */\n meta: NiceFormMeta;\n};\n\nexport type ReactAntdFormSchemaMeta = Omit<NiceFormMeta, 'fields'> & {\n /**\n * Form fields for standard mode.\n * Either fields or groups must be provided.\n */\n fields?: NiceFormField[];\n /**\n * Form groups for grouped mode.\n * When groups is provided, fields will be rendered in groups.\n */\n groups?: NiceFormGroup[];\n /**\n * Display mode for groups.\n * - 'fieldset': Render groups as fieldset/legend elements\n * - 'tabs': Render groups as tabs\n */\n groupsMode?: GroupsMode;\n /**\n * Props to pass to Tabs component when groupsMode is 'tabs'.\n */\n tabProps?: TabsProps;\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The form schema meta data.\n */\n meta: ReactAntdFormSchemaMeta;\n /**\n * The header content.\n */\n header?: ReactNode;\n /**\n * The form actions className.\n */\n actionsClassName?: string;\n} & FormProps;\n","import ReactAntdFormSchema from '.';\nexport type { ReactAntdFormSchemaProps, ReactAntdFormSchemaMeta } from './types';\nexport { GroupsMode } from './types';\n\nexport default ReactAntdFormSchema;\n"],"mappings":"8iBAAA,OAAOA,MAAQ,aACf,OAAOC,MAA+B,QACtC,OAASC,QAAAA,MAA+B,OCFxC,OAAOC,MAAW,QAClB,OAAOC,MAAgC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ACV,EAEMC,EAAsBC,EAAMC,WAChC,CAACC,EAAOC,IAAAA,CACN,IAAiFC,EAAAC,IAAA,GAC5ET,GACAM,GAFGI,WAAAA,EAAWC,KAAAA,EAAMV,OAAAA,EAAQW,SAAAA,EAAUC,iBAAAA,EAAkBX,OAAAA,CA3BjE,EA2BqFM,EAATM,EAAAA,EAASN,EAATM,CAAhEJ,YAAWC,OAAMV,SAAQW,WAAUC,mBAAkBX,WAIvDa,EAAaH,EACbI,EAAcpB,EAAaM,CAAAA,EAG3Be,EAAeN,EAAKO,QAAUP,EAAKO,OAAOC,OAAS,EACnDC,EAAaT,EAAKS,YAAcC,EAAWC,SAG3CC,EAAgBC,EAAA,IAChBP,EACEG,IAAeC,EAAWI,KACrBrB,EAAA,cAACsB,EAAAA,CAAWR,OAAQP,EAAKO,OAASF,YAAaA,EAAaW,SAAUhB,EAAKgB,WAG7EvB,EAAA,cAACwB,EAAAA,CAAeV,OAAQP,EAAKO,OAASF,YAAaA,IAGrDZ,EAAA,cAACyB,EAAAA,CAAYlB,KAAMF,IAAA,GAAKO,GAAgBL,KAT3B,iBAYtB,OACEP,EAAA,cAAC0B,EAAAA,EAAAA,CACCC,iBAAgBpC,EAChBe,UAAWsB,EAAGrC,EAAYe,CAAAA,EAC1BR,OAAQA,EACRK,IAAKA,GACDO,GACHb,EACAsB,EAAAA,EACDnB,EAAA,cAAC0B,EAAKG,KAAI,CACRC,WAAY,CAAEC,OAAQjC,IAAW,aAAec,GAAAA,YAAAA,EAAalB,WAAa,CAAE,EAC5EY,UAAWG,EACXuB,MAAO,CAAEC,aAAc,CAAE,GACxBtB,CAAAA,CAAAA,CAIT,CAAA,EAGFuB,EAAenC,EKnEf,IAAAoC,GAAeC","names":["cx","React","Form","React","NiceForm","DefaultForm","__name","meta","React","NiceForm","default_form_default","React","NiceForm","FieldsetGroups","__name","groups","defaultMeta","React","div","className","map","group","index","groupMeta","__spreadValues","meta","fieldset","key","legend","title","NiceForm","fieldset_groups_default","React","Tabs","NiceForm","TabsGroups","__name","groups","defaultMeta","tabProps","tabItems","map","group","groupMeta","__spreadValues","meta","key","title","label","children","React","NiceForm","Tabs","items","className","tabs_groups_default","GroupsMode","CLASS_NAME","DEFAULT_META","vertical","labelWidth","horizontal","defaultProps","header","layout","ReactAntdFormSchema","React","forwardRef","props","ref","_a","__spreadValues","className","meta","children","actionsClassName","rest","footerNode","defaultMeta","isGroupsMode","groups","length","groupsMode","GroupsMode","Fieldset","renderContent","__name","Tabs","TabsGroups","tabProps","FieldsetGroups","DefaultForm","Form","data-component","cx","Item","wrapperCol","offset","style","marginBottom","index_default","main_default","ReactAntdFormSchema"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';
|
|
3
|
+
|
|
4
|
+
export type DefaultFormProps = {
|
|
5
|
+
meta: NiceFormMeta;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const DefaultForm = ({ meta }: DefaultFormProps) => {
|
|
9
|
+
return <NiceForm meta={meta} />;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default DefaultForm;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';
|
|
3
|
+
import { NiceFormGroup } from '../types';
|
|
4
|
+
|
|
5
|
+
export type FieldsetGroupsProps = {
|
|
6
|
+
groups: NiceFormGroup[];
|
|
7
|
+
defaultMeta: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const FieldsetGroups = ({ groups, defaultMeta }: FieldsetGroupsProps) => {
|
|
11
|
+
return (
|
|
12
|
+
<div className="react-ant-form-schema-groups">
|
|
13
|
+
{groups.map((group, index) => {
|
|
14
|
+
const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;
|
|
15
|
+
return (
|
|
16
|
+
<fieldset key={index} className="react-ant-form-schema-fieldset">
|
|
17
|
+
<legend className="react-ant-form-schema-legend">{group.title}</legend>
|
|
18
|
+
<NiceForm meta={groupMeta} />
|
|
19
|
+
</fieldset>
|
|
20
|
+
);
|
|
21
|
+
})}
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default FieldsetGroups;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Tabs, TabsProps } from 'antd';
|
|
3
|
+
import NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';
|
|
4
|
+
import { NiceFormGroup } from '../types';
|
|
5
|
+
|
|
6
|
+
export type TabsGroupsProps = {
|
|
7
|
+
groups: NiceFormGroup[];
|
|
8
|
+
defaultMeta: Record<string, any>;
|
|
9
|
+
tabProps?: TabsProps;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const TabsGroups = ({ groups, defaultMeta, tabProps }: TabsGroupsProps) => {
|
|
13
|
+
const tabItems = groups.map((group) => {
|
|
14
|
+
const groupMeta = { ...defaultMeta, ...group.meta } as NiceFormMeta;
|
|
15
|
+
return {
|
|
16
|
+
key: group.title,
|
|
17
|
+
label: group.title,
|
|
18
|
+
children: <NiceForm meta={groupMeta} />,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Tabs
|
|
24
|
+
items={tabItems}
|
|
25
|
+
className="react-ant-form-schema-tabs"
|
|
26
|
+
{...tabProps}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default TabsGroups;
|
package/src/index.tsx
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import cx from 'classnames';
|
|
2
|
-
import React, { ReactNode } from 'react';
|
|
3
|
-
import { Form, FormInstance
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type NiceFormGroup = {
|
|
10
|
-
/**
|
|
11
|
-
* The group title displayed in legend.
|
|
12
|
-
*/
|
|
13
|
-
title: string;
|
|
14
|
-
/**
|
|
15
|
-
* The form meta for this group.
|
|
16
|
-
*/
|
|
17
|
-
meta: NiceFormMeta;
|
|
18
|
-
};
|
|
2
|
+
import React, { type ReactNode } from 'react';
|
|
3
|
+
import { Form, type FormInstance } from 'antd';
|
|
4
|
+
import DefaultForm from './components/default-form';
|
|
5
|
+
import FieldsetGroups from './components/fieldset-groups';
|
|
6
|
+
import TabsGroups from './components/tabs-groups';
|
|
7
|
+
import { ReactAntdFormSchemaProps, GroupsMode } from './types';
|
|
19
8
|
|
|
20
9
|
const CLASS_NAME = 'react-ant-form-schema';
|
|
21
10
|
const DEFAULT_META = {
|
|
@@ -29,39 +18,6 @@ const DEFAULT_META = {
|
|
|
29
18
|
},
|
|
30
19
|
};
|
|
31
20
|
|
|
32
|
-
export type ReactAntdFormSchemaMeta = NiceFormMeta & {
|
|
33
|
-
/**
|
|
34
|
-
* Form groups for grouped mode.
|
|
35
|
-
* When groups is provided, fields will be rendered in groups.
|
|
36
|
-
*/
|
|
37
|
-
groups?: NiceFormGroup[];
|
|
38
|
-
/**
|
|
39
|
-
* Display mode for groups.
|
|
40
|
-
* - 'fieldset': Render groups as fieldset/legend elements
|
|
41
|
-
* - 'tabs': Render groups as tabs
|
|
42
|
-
*/
|
|
43
|
-
groupsMode?: GroupsMode;
|
|
44
|
-
/**
|
|
45
|
-
* Props to pass to Tabs component when groupsMode is 'tabs'.
|
|
46
|
-
*/
|
|
47
|
-
tabProps?: TabsProps;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type ReactAntdFormSchemaProps = {
|
|
51
|
-
/**
|
|
52
|
-
* The form schema meta data.
|
|
53
|
-
*/
|
|
54
|
-
meta: ReactAntdFormSchemaMeta;
|
|
55
|
-
/**
|
|
56
|
-
* The header content.
|
|
57
|
-
*/
|
|
58
|
-
header?: ReactNode;
|
|
59
|
-
/**
|
|
60
|
-
* The form actions className.
|
|
61
|
-
*/
|
|
62
|
-
actionsClassName?: string;
|
|
63
|
-
} & FormProps;
|
|
64
|
-
|
|
65
21
|
const defaultProps: Partial<ReactAntdFormSchemaProps> = {
|
|
66
22
|
header: null,
|
|
67
23
|
layout: 'horizontal',
|
|
@@ -74,46 +30,23 @@ const ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaPr
|
|
|
74
30
|
...props,
|
|
75
31
|
};
|
|
76
32
|
const footerNode = children as ReactNode;
|
|
77
|
-
const
|
|
78
|
-
const _offset = layout === 'horizontal' ? _meta?.labelWidth : 0;
|
|
33
|
+
const defaultMeta = DEFAULT_META[layout!];
|
|
79
34
|
|
|
80
35
|
// Check if groups mode is enabled
|
|
81
36
|
const isGroupsMode = meta.groups && meta.groups.length > 0;
|
|
82
|
-
const groupsMode = meta.groupsMode ||
|
|
37
|
+
const groupsMode = meta.groupsMode || GroupsMode.Fieldset;
|
|
83
38
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
|
|
90
|
-
label: group.title,
|
|
91
|
-
children: <NiceForm meta={groupMeta} />,
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
return (
|
|
95
|
-
<Tabs
|
|
96
|
-
items={tabItems}
|
|
97
|
-
className="react-ant-form-schema-tabs"
|
|
98
|
-
{...meta.tabProps}
|
|
99
|
-
/>
|
|
100
|
-
);
|
|
101
|
-
} else {
|
|
39
|
+
// Render form content based on mode
|
|
40
|
+
const renderContent = () => {
|
|
41
|
+
if (isGroupsMode) {
|
|
42
|
+
if (groupsMode === GroupsMode.Tabs) {
|
|
43
|
+
return <TabsGroups groups={meta.groups!} defaultMeta={defaultMeta} tabProps={meta.tabProps} />;
|
|
44
|
+
}
|
|
102
45
|
// fieldset mode (default)
|
|
103
|
-
return
|
|
104
|
-
<div className="react-ant-form-schema-groups">
|
|
105
|
-
{meta.groups?.map((group, index) => {
|
|
106
|
-
const groupMeta = deepMerge(DEFAULT_META[layout!], group.meta) as NiceFormMeta;
|
|
107
|
-
return (
|
|
108
|
-
<fieldset key={index} className="react-ant-form-schema-fieldset">
|
|
109
|
-
<legend className="react-ant-form-schema-legend">{group.title}</legend>
|
|
110
|
-
<NiceForm meta={groupMeta} />
|
|
111
|
-
</fieldset>
|
|
112
|
-
);
|
|
113
|
-
})}
|
|
114
|
-
</div>
|
|
115
|
-
);
|
|
46
|
+
return <FieldsetGroups groups={meta.groups!} defaultMeta={defaultMeta} />;
|
|
116
47
|
}
|
|
48
|
+
// standard mode
|
|
49
|
+
return <DefaultForm meta={{ ...defaultMeta, ...meta }} />;
|
|
117
50
|
};
|
|
118
51
|
|
|
119
52
|
return (
|
|
@@ -124,9 +57,9 @@ const ReactAntdFormSchema = React.forwardRef<FormInstance, ReactAntdFormSchemaPr
|
|
|
124
57
|
ref={ref}
|
|
125
58
|
{...rest}>
|
|
126
59
|
{header}
|
|
127
|
-
{
|
|
60
|
+
{renderContent()}
|
|
128
61
|
<Form.Item
|
|
129
|
-
wrapperCol={{ offset:
|
|
62
|
+
wrapperCol={{ offset: layout === 'horizontal' ? defaultMeta?.labelWidth : 0 }}
|
|
130
63
|
className={actionsClassName}
|
|
131
64
|
style={{ marginBottom: 0 }}>
|
|
132
65
|
{footerNode}
|
package/src/main.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ReactAntdFormSchema from '.';
|
|
2
|
-
|
|
2
|
+
export type { ReactAntdFormSchemaProps, ReactAntdFormSchemaMeta } from './types';
|
|
3
|
+
export { GroupsMode } from './types';
|
|
3
4
|
|
|
4
5
|
export default ReactAntdFormSchema;
|
|
5
|
-
export type { ReactAntdFormSchemaProps };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { TabsProps } from 'antd';
|
|
2
|
+
import { NiceFormMeta, NiceFormField } from '@ebay/nice-form-react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { FormProps } from 'antd';
|
|
5
|
+
|
|
6
|
+
export enum GroupsMode {
|
|
7
|
+
Fieldset = 'fieldset',
|
|
8
|
+
Tabs = 'tabs',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type NiceFormGroup = {
|
|
12
|
+
/**
|
|
13
|
+
* The group title displayed in legend or tab.
|
|
14
|
+
*/
|
|
15
|
+
title: string;
|
|
16
|
+
/**
|
|
17
|
+
* The form meta for this group.
|
|
18
|
+
*/
|
|
19
|
+
meta: NiceFormMeta;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ReactAntdFormSchemaMeta = Omit<NiceFormMeta, 'fields'> & {
|
|
23
|
+
/**
|
|
24
|
+
* Form fields for standard mode.
|
|
25
|
+
* Either fields or groups must be provided.
|
|
26
|
+
*/
|
|
27
|
+
fields?: NiceFormField[];
|
|
28
|
+
/**
|
|
29
|
+
* Form groups for grouped mode.
|
|
30
|
+
* When groups is provided, fields will be rendered in groups.
|
|
31
|
+
*/
|
|
32
|
+
groups?: NiceFormGroup[];
|
|
33
|
+
/**
|
|
34
|
+
* Display mode for groups.
|
|
35
|
+
* - 'fieldset': Render groups as fieldset/legend elements
|
|
36
|
+
* - 'tabs': Render groups as tabs
|
|
37
|
+
*/
|
|
38
|
+
groupsMode?: GroupsMode;
|
|
39
|
+
/**
|
|
40
|
+
* Props to pass to Tabs component when groupsMode is 'tabs'.
|
|
41
|
+
*/
|
|
42
|
+
tabProps?: TabsProps;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type ReactAntdFormSchemaProps = {
|
|
46
|
+
/**
|
|
47
|
+
* The form schema meta data.
|
|
48
|
+
*/
|
|
49
|
+
meta: ReactAntdFormSchemaMeta;
|
|
50
|
+
/**
|
|
51
|
+
* The header content.
|
|
52
|
+
*/
|
|
53
|
+
header?: ReactNode;
|
|
54
|
+
/**
|
|
55
|
+
* The form actions className.
|
|
56
|
+
*/
|
|
57
|
+
actionsClassName?: string;
|
|
58
|
+
} & FormProps;
|
package/src/utils.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @Author: aric 1290657123@qq.com
|
|
3
|
-
* @Date: 2025-10-18 21:20:55
|
|
4
|
-
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
-
* @LastEditTime: 2025-10-22 08:55:52
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
type AnyObject = { [key: string]: any };
|
|
9
|
-
|
|
10
|
-
export function deepMerge(target: AnyObject, source: AnyObject) {
|
|
11
|
-
const result = { ...target };
|
|
12
|
-
for (const key in source) {
|
|
13
|
-
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
14
|
-
result[key] = deepMerge(result[key] || {}, source[key]);
|
|
15
|
-
} else {
|
|
16
|
-
result[key] = source[key];
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|