@jswork/react-ant-form-schema 1.0.6 → 1.0.8
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/README.md +8 -0
- package/dist/main.cjs.js +1 -1
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.d.mts +0 -5
- package/dist/main.d.ts +0 -5
- package/dist/main.esm.js +1 -1
- package/dist/main.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +26 -30
- package/src/utils.ts +4 -3
package/README.md
CHANGED
|
@@ -5,3 +5,11 @@
|
|
|
5
5
|
```shell
|
|
6
6
|
yarn add @jswork/react-ant-form-schema
|
|
7
7
|
```
|
|
8
|
+
|
|
9
|
+
## setup
|
|
10
|
+
```ts
|
|
11
|
+
import { config as niceFormConfig } from '@ebay/nice-form-react';
|
|
12
|
+
import antdAdapter from '@ebay/nice-form-react/adapters/antdAdapter';
|
|
13
|
+
|
|
14
|
+
niceFormConfig.addAdapter(antdAdapter);
|
|
15
|
+
```
|
package/dist/main.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var d=Object.defineProperty;var n=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var i=(t,e,r)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e)=>{for(var r in e||(e={}))A.call(e,r)&&i(t,r,e[r]);if(n)for(var r of n(e))N.call(e,r)&&i(t,r,e[r]);return t};var h=(t,e)=>d(t,"name",{value:e,configurable:!0});var y=(t,e)=>{var r={};for(var o in t)A.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(t!=null&&n)for(var o of n(t))e.indexOf(o)<0&&N.call(t,o)&&(r[o]=t[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);function c(t,e){let r=a({},t);for(let o in e)e[o]&&typeof e[o]=="object"&&!Array.isArray(e[o])?r[o]=c(r[o]||{},e[o]):r[o]=e[o];return r}h(c,"deepMerge");var E="react-ant-form-schema",P={layout:"vertical",wrapperProps:{labelCol:{span:4}}},L={header:null,actionsClassName:""},T=_react2.default.forwardRef((t,e)=>{var p,f;let l=a(a({},L),t),{className:r,meta:o,header:u,children:w,actionsClassName:x}=l,M=y(l,["className","meta","header","children","actionsClassName"]),R=w,m=c(P,o),S=((f=(p=m==null?void 0:m.wrapperProps)==null?void 0:p.labelCol)==null?void 0:f.span)||4;return _react2.default.createElement(_antd.Form,a({"data-component":E,className:_classnames2.default.call(void 0, E,r),ref:e},M),u,_react2.default.createElement(_niceformreact2.default,{meta:m}),_react2.default.createElement(_antd.Form.Item,{wrapperCol:{offset:S},className:x,style:{marginBottom:0}},R))}),F=T;var H=F;exports.default = H;
|
|
2
2
|
|
|
3
3
|
module.exports = exports.default;
|
|
4
4
|
//# sourceMappingURL=main.cjs.js.map
|
package/dist/main.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/ap7/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","layout","wrapperProps","labelCol","span","defaultProps","
|
|
1
|
+
{"version":3,"sources":["/Users/ap7/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","layout","wrapperProps","labelCol","span","defaultProps","header","actionsClassName","ReactAntdFormSchema","React","forwardRef","props","ref","_b","_c","_a","className","meta","children","rest","footerNode","_meta","_offset","Form","data-component","cx","NiceForm","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,GAAA,CAAA,IAAA,EAAA,GAAA,CAAA,CAAA,CAAA,CAAoB,CAAC,CAAA,CAAA,IAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA,CAAE,CAAA,CAAE,CAAA,CAAA,CAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAI,CAAA,CAAA,CAAA,IAAU,CAAC,CAAC,CAAC,CAAC,CAAA,CAAA,CAAA,EA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AAAA,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA,CAAqBlB,QAAAA,CAAAA,EAArBkB,IAAAA,CAAAA,KAAAA,CAAAA,CAAAA,CAAAA,CAA+BjB,IAAAA,CAAAA,EAAQ,CAAA,CAEvD,OACEK,eAAAA,CAAA,aAAA,CAACc,UAAAA,CAAAA,CAAAA,CAAAA,CAAKC,gBAAAA,CAAgBzB,CAAAA,CAAYiB,SAAAA,CAAWS,kCAAAA,CAAG1B,CAAYiB,CAAAA,CAAAA,CAAYJ,GAAAA,CAAKA,CAAAA,CAAAA,CAASO,CAAAA,CAAAA,CACnFb,CAAAA,CACDG,eAAAA,CAAA,aAAA,CAACiB,uBAAAA,CAAAA,CAAST,IAAAA,CAAMI,CAAAA,CAAAA,CAAAA,CAChBZ,eAAAA,CAAA,aAAA,CAACc,UAAAA,CAAKI,IAAAA,CAAI,CACRC,UAAAA,CAAY,CAAEC,MAAAA,CAAQP,CAAQ,CAAA,CAC9BN,SAAAA,CAAWT,CAAAA,CACXuB,KAAAA,CAAO,CAAEC,YAAAA,CAAc,CAAE,CAAA,CAAA,CACxBX,CAAAA,CAAAA,CAIT,CAAA,CAAA,CAGFY,CAAAA,CAAexB,CAAAA,CE1Df,IAAAyB,CAAAA,CAAezB,CAAAA,CAAAA,oBAAAA","file":"/Users/ap7/github/react-ant-form-schema/packages/lib/dist/main.cjs.js","sourcesContent":[null,"import cx from 'classnames';\nimport React, { FC, ReactNode, RefObject } from 'react';\nimport { Form, FormInstance, FormProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { deepMerge } from './utils';\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n layout: 'vertical',\n wrapperProps: {\n labelCol: {\n span: 4,\n },\n },\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The form schema meta data.\n */\n meta: NiceFormMeta;\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 actionsClassName: '',\n};\n\nconst ReactAntdFormSchema: FC<ReactAntdFormSchemaProps> = React.forwardRef(\n (props, ref: RefObject<FormInstance>) => {\n const { className, meta, header, children, actionsClassName, ...rest } = {\n ...defaultProps,\n ...props,\n };\n const footerNode = children as ReactNode;\n const _meta = deepMerge(DEFAULT_META, meta) as NiceFormMeta;\n const _offset = _meta?.wrapperProps?.labelCol?.span || 4;\n\n return (\n <Form data-component={CLASS_NAME} className={cx(CLASS_NAME, className)} ref={ref} {...rest}>\n {header}\n <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"]}
|
package/dist/main.d.mts
CHANGED
|
@@ -3,11 +3,6 @@ import { FormProps } from 'antd';
|
|
|
3
3
|
import { NiceFormMeta } from '@ebay/nice-form-react';
|
|
4
4
|
|
|
5
5
|
type ReactAntdFormSchemaProps = {
|
|
6
|
-
/**
|
|
7
|
-
* The extended className for component.
|
|
8
|
-
* @default ''
|
|
9
|
-
*/
|
|
10
|
-
className?: string;
|
|
11
6
|
/**
|
|
12
7
|
* The form schema meta data.
|
|
13
8
|
*/
|
package/dist/main.d.ts
CHANGED
|
@@ -3,11 +3,6 @@ import { FormProps } from 'antd';
|
|
|
3
3
|
import { NiceFormMeta } from '@ebay/nice-form-react';
|
|
4
4
|
|
|
5
5
|
type ReactAntdFormSchemaProps = {
|
|
6
|
-
/**
|
|
7
|
-
* The extended className for component.
|
|
8
|
-
* @default ''
|
|
9
|
-
*/
|
|
10
|
-
className?: string;
|
|
11
6
|
/**
|
|
12
7
|
* The form schema meta data.
|
|
13
8
|
*/
|
package/dist/main.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var d=Object.defineProperty;var n=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var i=(t,e,r)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e)=>{for(var r in e||(e={}))A.call(e,r)&&i(t,r,e[r]);if(n)for(var r of n(e))N.call(e,r)&&i(t,r,e[r]);return t};var h=(t,e)=>d(t,"name",{value:e,configurable:!0});var y=(t,e)=>{var r={};for(var o in t)A.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(t!=null&&n)for(var o of n(t))e.indexOf(o)<0&&N.call(t,o)&&(r[o]=t[o]);return r};import b from"classnames";import s from"react";import{Form as C}from"antd";import g from"@ebay/nice-form-react";function c(t,e){let r=a({},t);for(let o in e)e[o]&&typeof e[o]=="object"&&!Array.isArray(e[o])?r[o]=c(r[o]||{},e[o]):r[o]=e[o];return r}h(c,"deepMerge");var E="react-ant-form-schema",P={layout:"vertical",wrapperProps:{labelCol:{span:4}}},L={header:null,actionsClassName:""},T=s.forwardRef((t,e)=>{var p,f;let l=a(a({},L),t),{className:r,meta:o,header:u,children:w,actionsClassName:x}=l,M=y(l,["className","meta","header","children","actionsClassName"]),R=w,m=c(P,o),S=((f=(p=m==null?void 0:m.wrapperProps)==null?void 0:p.labelCol)==null?void 0:f.span)||4;return s.createElement(C,a({"data-component":E,className:b(E,r),ref:e},M),u,s.createElement(g,{meta:m}),s.createElement(C.Item,{wrapperCol:{offset:S},className:x,style:{marginBottom:0}},R))}),F=T;var H=F;export{H 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/utils.ts","../src/main.tsx"],"sourcesContent":["import cx from 'classnames';\nimport React, { FC, ReactNode } from 'react';\nimport { Form, FormProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { deepMerge } from './utils';\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n layout: 'vertical',\n wrapperProps: {\n labelCol: {\n span: 4,\n },\n },\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx","../src/utils.ts","../src/main.tsx"],"sourcesContent":["import cx from 'classnames';\nimport React, { FC, ReactNode, RefObject } from 'react';\nimport { Form, FormInstance, FormProps } from 'antd';\nimport NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';\nimport { deepMerge } from './utils';\n\nconst CLASS_NAME = 'react-ant-form-schema';\nconst DEFAULT_META = {\n layout: 'vertical',\n wrapperProps: {\n labelCol: {\n span: 4,\n },\n },\n};\n\nexport type ReactAntdFormSchemaProps = {\n /**\n * The form schema meta data.\n */\n meta: NiceFormMeta;\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 actionsClassName: '',\n};\n\nconst ReactAntdFormSchema: FC<ReactAntdFormSchemaProps> = React.forwardRef(\n (props, ref: RefObject<FormInstance>) => {\n const { className, meta, header, children, actionsClassName, ...rest } = {\n ...defaultProps,\n ...props,\n };\n const footerNode = children as ReactNode;\n const _meta = deepMerge(DEFAULT_META, meta) as NiceFormMeta;\n const _offset = _meta?.wrapperProps?.labelCol?.span || 4;\n\n return (\n <Form data-component={CLASS_NAME} className={cx(CLASS_NAME, className)} ref={ref} {...rest}>\n {header}\n <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"],"mappings":"8iBAAA,OAAOA,MAAQ,aACf,OAAOC,MAAyC,QAChD,OAASC,QAAAA,MAAqC,OAC9C,OAAOC,MAAgC,wBCMhC,SAASC,EAAUC,EAAmBC,EAAiB,CAC5D,IAAMC,EAASC,EAAA,GAAKH,GACpB,QAAWI,KAAOH,EACZA,EAAOG,CAAAA,GAAQ,OAAOH,EAAOG,CAAAA,GAAS,UAAY,CAACC,MAAMC,QAAQL,EAAOG,CAAAA,CAAI,EAC9EF,EAAOE,CAAAA,EAAOL,EAAUG,EAAOE,CAAAA,GAAQ,CAAC,EAAGH,EAAOG,CAAAA,CAAI,EAEtDF,EAAOE,CAAAA,EAAOH,EAAOG,CAAAA,EAGzB,OAAOF,CACT,CAVgBH,EAAAA,EAAAA,aDHhB,IAAMQ,EAAa,wBACbC,EAAe,CACnBC,OAAQ,WACRC,aAAc,CACZC,SAAU,CACRC,KAAM,CACR,CACF,CACF,EAiBMC,EAAkD,CACtDC,OAAQ,KACRC,iBAAkB,EACpB,EAEMC,EAAoDC,EAAMC,WAC9D,CAACC,EAAOC,IAAAA,CArCV,IAAAC,EAAAC,EAsCI,IAAyEC,EAAAC,IAAA,GACpEX,GACAM,GAFGM,WAAAA,EAAWC,KAAAA,EAAMZ,OAAAA,EAAQa,SAAAA,EAAUZ,iBAAAA,CAtC/C,EAsC6EQ,EAATK,EAAAA,EAASL,EAATK,CAAxDH,YAAWC,OAAMZ,SAAQa,WAAUZ,qBAIrCc,EAAaF,EACbG,EAAQC,EAAUvB,EAAckB,CAAAA,EAChCM,IAAUF,GAAAA,EAAAA,GAAAA,YAAAA,EAAOpB,eAAPoB,YAAAA,EAAqBnB,WAArBmB,YAAAA,EAA+BlB,OAAQ,EAEvD,OACEK,EAAA,cAACgB,EAAAA,EAAAA,CAAKC,iBAAgB3B,EAAYkB,UAAWU,EAAG5B,EAAYkB,CAAAA,EAAYL,IAAKA,GAASQ,GACnFd,EACDG,EAAA,cAACmB,EAAAA,CAASV,KAAMI,IAChBb,EAAA,cAACgB,EAAKI,KAAI,CACRC,WAAY,CAAEC,OAAQP,CAAQ,EAC9BP,UAAWV,EACXyB,MAAO,CAAEC,aAAc,CAAE,GACxBZ,CAAAA,CAAAA,CAIT,CAAA,EAGFa,EAAe1B,EE1Df,IAAA2B,EAAeC","names":["cx","React","Form","NiceForm","deepMerge","target","source","result","__spreadValues","key","Array","isArray","CLASS_NAME","DEFAULT_META","layout","wrapperProps","labelCol","span","defaultProps","header","actionsClassName","ReactAntdFormSchema","React","forwardRef","props","ref","_b","_c","_a","__spreadValues","className","meta","children","rest","footerNode","_meta","deepMerge","_offset","Form","data-component","cx","NiceForm","Item","wrapperCol","offset","style","marginBottom","index_default","main_default","ReactAntdFormSchema"]}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cx from 'classnames';
|
|
2
|
-
import React, { FC, ReactNode } from 'react';
|
|
3
|
-
import { Form, FormProps } from 'antd';
|
|
2
|
+
import React, { FC, ReactNode, RefObject } from 'react';
|
|
3
|
+
import { Form, FormInstance, FormProps } from 'antd';
|
|
4
4
|
import NiceForm, { NiceFormMeta } from '@ebay/nice-form-react';
|
|
5
5
|
import { deepMerge } from './utils';
|
|
6
6
|
|
|
@@ -15,11 +15,6 @@ const DEFAULT_META = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export type ReactAntdFormSchemaProps = {
|
|
18
|
-
/**
|
|
19
|
-
* The extended className for component.
|
|
20
|
-
* @default ''
|
|
21
|
-
*/
|
|
22
|
-
className?: string;
|
|
23
18
|
/**
|
|
24
19
|
* The form schema meta data.
|
|
25
20
|
*/
|
|
@@ -34,33 +29,34 @@ export type ReactAntdFormSchemaProps = {
|
|
|
34
29
|
actionsClassName?: string;
|
|
35
30
|
} & FormProps;
|
|
36
31
|
|
|
37
|
-
const defaultProps = {
|
|
38
|
-
className: '',
|
|
32
|
+
const defaultProps: Partial<ReactAntdFormSchemaProps> = {
|
|
39
33
|
header: null,
|
|
40
34
|
actionsClassName: '',
|
|
41
35
|
};
|
|
42
36
|
|
|
43
|
-
const ReactAntdFormSchema: FC<ReactAntdFormSchemaProps> = (
|
|
44
|
-
|
|
45
|
-
...
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
const ReactAntdFormSchema: FC<ReactAntdFormSchemaProps> = React.forwardRef(
|
|
38
|
+
(props, ref: RefObject<FormInstance>) => {
|
|
39
|
+
const { className, meta, header, children, actionsClassName, ...rest } = {
|
|
40
|
+
...defaultProps,
|
|
41
|
+
...props,
|
|
42
|
+
};
|
|
43
|
+
const footerNode = children as ReactNode;
|
|
44
|
+
const _meta = deepMerge(DEFAULT_META, meta) as NiceFormMeta;
|
|
45
|
+
const _offset = _meta?.wrapperProps?.labelCol?.span || 4;
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
47
|
+
return (
|
|
48
|
+
<Form data-component={CLASS_NAME} className={cx(CLASS_NAME, className)} ref={ref} {...rest}>
|
|
49
|
+
{header}
|
|
50
|
+
<NiceForm meta={_meta} />
|
|
51
|
+
<Form.Item
|
|
52
|
+
wrapperCol={{ offset: _offset }}
|
|
53
|
+
className={actionsClassName}
|
|
54
|
+
style={{ marginBottom: 0 }}>
|
|
55
|
+
{footerNode}
|
|
56
|
+
</Form.Item>
|
|
57
|
+
</Form>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
65
61
|
|
|
66
62
|
export default ReactAntdFormSchema;
|
package/src/utils.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* @Author: aric 1290657123@qq.com
|
|
3
3
|
* @Date: 2025-10-18 21:20:55
|
|
4
4
|
* @LastEditors: aric 1290657123@qq.com
|
|
5
|
-
* @LastEditTime: 2025-10-
|
|
5
|
+
* @LastEditTime: 2025-10-22 08:55:52
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
type AnyObject = { [key: string]: any };
|
|
9
|
+
|
|
10
|
+
export function deepMerge(target: AnyObject, source: AnyObject) {
|
|
9
11
|
const result = { ...target };
|
|
10
12
|
for (const key in source) {
|
|
11
13
|
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
@@ -16,4 +18,3 @@ export function deepMerge(target, source) {
|
|
|
16
18
|
}
|
|
17
19
|
return result;
|
|
18
20
|
}
|
|
19
|
-
|