lu-lowcode-package-form 0.6.2 → 0.7.1
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/index.cjs.js +48 -48
- package/dist/index.es.js +355 -337
- package/package.json +2 -1
- package/src/components/form-container/index.jsx +28 -12
- package/src/components/index.jsx +2 -2
- package/vite.config.js +15 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lu-lowcode-package-form",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@ant-design/icons": "^5.3.7",
|
|
6
6
|
"@testing-library/jest-dom": "^5.17.0",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/core": "^7.24.7",
|
|
44
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
44
45
|
"@babel/preset-env": "^7.24.7",
|
|
45
46
|
"@babel/preset-react": "^7.24.7",
|
|
46
47
|
"@rollup/plugin-babel": "^6.0.4",
|
|
@@ -4,7 +4,7 @@ import { Form, Row, Col } from "antd";
|
|
|
4
4
|
|
|
5
5
|
function debounce(func, wait) {
|
|
6
6
|
let timeout;
|
|
7
|
-
return function(...args) {
|
|
7
|
+
return function (...args) {
|
|
8
8
|
clearTimeout(timeout);
|
|
9
9
|
timeout = setTimeout(() => func.apply(this, args), wait);
|
|
10
10
|
}
|
|
@@ -55,7 +55,7 @@ const FormContainer = forwardRef(({ cols, children }, ref) => {
|
|
|
55
55
|
}, [])
|
|
56
56
|
|
|
57
57
|
useEffect(() => {
|
|
58
|
-
},[form])
|
|
58
|
+
}, [form])
|
|
59
59
|
|
|
60
60
|
useEffect(() => {
|
|
61
61
|
initWithMap()
|
|
@@ -76,23 +76,23 @@ const FormContainer = forwardRef(({ cols, children }, ref) => {
|
|
|
76
76
|
show: true
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
initFieldsShow();
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
// 初始化字段的显示状态
|
|
85
85
|
const initFieldsShow = (reloadFields = false) => {
|
|
86
86
|
const fieldsValues = form.getFieldsValue();
|
|
87
87
|
withMap.current.keys().forEach(function (key) {
|
|
88
|
-
computeNeedShow(key,fieldsValues)
|
|
88
|
+
computeNeedShow(key, fieldsValues)
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
if (reloadFields)
|
|
91
|
+
if (reloadFields) setFormContent(getChildren())
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// 计算是否显示
|
|
95
|
-
const computeNeedShow = (name,fieldsValues) => {
|
|
95
|
+
const computeNeedShow = (name, fieldsValues) => {
|
|
96
96
|
let needRefresh = false;
|
|
97
97
|
if (withMap.current.has(name)) {
|
|
98
98
|
let withChildrens = withMap.current.get(name).children
|
|
@@ -113,21 +113,21 @@ const FormContainer = forwardRef(({ cols, children }, ref) => {
|
|
|
113
113
|
}
|
|
114
114
|
return needRefresh
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
const handleFieldsChange = debounce((changedFields, allFields) => {
|
|
118
118
|
// 获得所有字段值
|
|
119
119
|
const fieldsValues = form.getFieldsValue();
|
|
120
120
|
let needRefresh = false;
|
|
121
121
|
for (let index = 0; index < changedFields.length; index++) {
|
|
122
122
|
const element = changedFields[index];
|
|
123
|
-
if (element.name && element.name.length > 0
|
|
124
|
-
needRefresh = computeNeedShow(element.name[0],fieldsValues)
|
|
123
|
+
if (element.name && element.name.length > 0)
|
|
124
|
+
needRefresh = computeNeedShow(element.name[0], fieldsValues)
|
|
125
125
|
}
|
|
126
126
|
if (needRefresh) {
|
|
127
127
|
setFormContent(getChildren())
|
|
128
128
|
}
|
|
129
129
|
}, 100); // 字段变化时会调用三次此函数,使用 100 毫秒的防抖时间
|
|
130
|
-
|
|
130
|
+
|
|
131
131
|
const getChildren = () => {
|
|
132
132
|
let childrenArray = React.Children.toArray(children);
|
|
133
133
|
const newArray = groupArray(childrenArray.filter((item) => {
|
|
@@ -189,3 +189,19 @@ const FormContainer = forwardRef(({ cols, children }, ref) => {
|
|
|
189
189
|
|
|
190
190
|
export default FormContainer;
|
|
191
191
|
|
|
192
|
+
/**
|
|
193
|
+
* 简单包装,不做任何处理
|
|
194
|
+
* 部分组件ref比较特殊,包一层会解决这个问题
|
|
195
|
+
*/
|
|
196
|
+
export function withWrap(Comp) {
|
|
197
|
+
return forwardRef((props, ref) => {
|
|
198
|
+
return <Comp {...props} ref={ref} forwardedRef={ref} />;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const FormContainerClass = () => {
|
|
203
|
+
const { forwardedRef, ...otherProps } = this.props;
|
|
204
|
+
return <FormContainerWrapper {...otherProps} ref={forwardedRef} />
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export const FormContainerWrapper = withWrap(FormContainerClass);
|
package/src/components/index.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import { Input, TextArea, Password, Search ,CodeMachine} from './field/input/ind
|
|
|
2
2
|
import '../App.css';
|
|
3
3
|
import { TreeSelect, Select } from './field/select/index.jsx'
|
|
4
4
|
import Custom from './field/custom/index.jsx'
|
|
5
|
-
import { default as FormContainer } from './form-container/index.jsx'
|
|
5
|
+
import { default as FormContainer, FormContainerWrapper } from './form-container/index.jsx'
|
|
6
6
|
import { Checkbox ,CheckboxTree } from './field/checkbox/index.jsx'
|
|
7
7
|
import { default as RadioGrop } from './field/radio/index.jsx'
|
|
8
8
|
const Field = {
|
|
@@ -19,4 +19,4 @@ const Field = {
|
|
|
19
19
|
Custom,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export { FormContainer, Field }
|
|
22
|
+
export { FormContainer, Field ,FormContainerWrapper }
|
package/vite.config.js
CHANGED
|
@@ -19,7 +19,21 @@ export default defineConfig({
|
|
|
19
19
|
react: 'React',
|
|
20
20
|
'react-dom': 'ReactDOM'
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
|
+
plugins: [
|
|
24
|
+
babel({
|
|
25
|
+
babelHelpers: 'bundled',
|
|
26
|
+
exclude: 'node_modules/**',
|
|
27
|
+
presets: [
|
|
28
|
+
'@babel/preset-env',
|
|
29
|
+
'@babel/preset-react'
|
|
30
|
+
],
|
|
31
|
+
plugins: [
|
|
32
|
+
'@babel/plugin-proposal-nullish-coalescing-operator',
|
|
33
|
+
'@babel/plugin-proposal-optional-chaining'
|
|
34
|
+
]
|
|
35
|
+
})
|
|
36
|
+
]
|
|
23
37
|
}
|
|
24
38
|
},
|
|
25
39
|
css: {
|
|
@@ -32,11 +46,5 @@ export default defineConfig({
|
|
|
32
46
|
},
|
|
33
47
|
plugins: [
|
|
34
48
|
react(),
|
|
35
|
-
babel({
|
|
36
|
-
babelHelpers: 'bundled',
|
|
37
|
-
exclude: 'node_modules/**',
|
|
38
|
-
presets: ['@babel/preset-env', '@babel/preset-react'],
|
|
39
|
-
plugins: ['@babel/plugin-proposal-nullish-coalescing-operator'],
|
|
40
|
-
}),
|
|
41
49
|
],
|
|
42
50
|
});
|