dynamicformdjx-react 0.0.5 → 0.1.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/README.md +269 -15
- package/dist/antd/AdDynamicForm.d.ts +18 -0
- package/dist/antd/hooks/renderForm.d.ts +5 -0
- package/dist/antd/index.cjs +1 -0
- package/dist/antd/index.d.ts +6 -0
- package/dist/antd/index.mjs +155 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/hooks/useDyForm.d.ts +26 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +477 -310
- package/dist/types/form.d.ts +65 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/utils/tools.d.ts +3 -1
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
基于 **React** 的动态表单输入组件。
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[Document](https://xczcdjx.github.io/dynamicFormDoc/react/install.html)
|
|
6
6
|
|
|
7
|
-
Vue3 版本
|
|
7
|
+
[Vue3 版本](https://www.npmjs.com/package/dynamicformdjx)
|
|
8
8
|
|
|
9
|
-
[Vue2 版本](https://www.npmjs.com/package/dynamicformdjx-vue2) (
|
|
9
|
+
[Vue2 版本](https://www.npmjs.com/package/dynamicformdjx-vue2) (后续适配)
|
|
10
10
|
|
|
11
|
+
## 概述
|
|
12
|
+
|
|
13
|
+
`DynamicForm` 一个灵活且动态的表单组件,使用数组,简化模版操作,提供多种hook快速操作表单等。
|
|
14
|
+
|
|
15
|
+
- 简化节点代码,快速处理表单
|
|
16
|
+
- 提供render2函数渲染表单项,使用函数渲染值或自定义Component函数
|
|
17
|
+
- 提供多种hooks函数,快速处理数据值
|
|
11
18
|
|
|
12
19
|
## 安装
|
|
13
20
|
|
|
@@ -20,22 +27,267 @@ yarn add dynamicformdjx-react
|
|
|
20
27
|
pnpm add dynamicformdjx-react
|
|
21
28
|
```
|
|
22
29
|
|
|
23
|
-
###
|
|
30
|
+
### 动态表单
|
|
31
|
+
|
|
32
|
+
#### 与Antd配合
|
|
33
|
+
|
|
34
|
+
> 需配合antd v5+ 版本以上
|
|
35
|
+
|
|
36
|
+
##### 简单表单
|
|
37
|
+
|
|
38
|
+
> 更多render函数请等待后续更新,可直接使用下方自定义渲染
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import {useRef, useState} from "react";
|
|
42
|
+
import {Button, Input, Radio} from "antd";
|
|
43
|
+
import {AdDynamicForm, type adDynamicFormRef, renderInput} from "dynamicformdjx-react/antd";
|
|
44
|
+
import {omitFormCommonKey, OmitValue, useDyForm, useReactiveForm} from "dynamicformdjx-react";
|
|
45
|
+
import type {PresetType} from "dynamicformdjx-react/types";
|
|
46
|
+
import type {Rule} from "antd/es/form";
|
|
47
|
+
|
|
48
|
+
type RowProps = {
|
|
49
|
+
username: string
|
|
50
|
+
password: string
|
|
51
|
+
desc: string
|
|
52
|
+
preset: string
|
|
53
|
+
}
|
|
54
|
+
const SimpleForm = () => {
|
|
55
|
+
const [presetType, setPresetType] = useState<PresetType>('fullRow')
|
|
56
|
+
const [formItems, setFormItems] = useReactiveForm<RowProps, Rule | Rule[]>([
|
|
57
|
+
{
|
|
58
|
+
key: "username",
|
|
59
|
+
label: "用户名",
|
|
60
|
+
value: "",
|
|
61
|
+
allowClear: true,
|
|
62
|
+
rule: [{required: true, message: 'Please input your username!', validateTrigger: 'onBlur'}],
|
|
63
|
+
render2: f => renderInput({}, f),
|
|
64
|
+
span: 12
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "password",
|
|
68
|
+
label: "密码",
|
|
69
|
+
required: true,
|
|
70
|
+
value: "",
|
|
71
|
+
render2: (f) => <Input.Password placeholder="请输入密码" {...OmitValue(f, omitFormCommonKey)}/>,
|
|
72
|
+
span: 8,
|
|
73
|
+
offset: 2,
|
|
74
|
+
sort: 0
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "preset",
|
|
78
|
+
label: "表格预设",
|
|
79
|
+
value: "fullRow",
|
|
80
|
+
render2: (f) => <Radio.Group
|
|
81
|
+
value={f.value}
|
|
82
|
+
options={[
|
|
83
|
+
{value: 'fullRow', label: 'row'},
|
|
84
|
+
{value: 'grid', label: 'grid'},
|
|
85
|
+
]}
|
|
86
|
+
onChange={(v) => {
|
|
87
|
+
setPresetType(v.target.value)
|
|
88
|
+
}}
|
|
89
|
+
/>,
|
|
90
|
+
}
|
|
91
|
+
])
|
|
92
|
+
const useForm = useDyForm([formItems, setFormItems])
|
|
93
|
+
const antdFormRef = useRef<adDynamicFormRef>(null)
|
|
94
|
+
const rules: Partial<Record<keyof RowProps, Rule | Rule[]>> = {
|
|
95
|
+
desc: [{required: true, message: '请输入详情'}]
|
|
96
|
+
}
|
|
97
|
+
return (
|
|
98
|
+
<div className='dynamicFormTest'>
|
|
99
|
+
<AdDynamicForm ref={antdFormRef} rules={rules} validateTrigger={null} items={formItems}
|
|
100
|
+
preset={presetType}/>
|
|
101
|
+
<div className="footer" style={{
|
|
102
|
+
display: 'flex',
|
|
103
|
+
gap: '5px'
|
|
104
|
+
}}>
|
|
105
|
+
<Button color={'green'} variant={'outlined'} onClick={() => {
|
|
106
|
+
// const res=antdFormRef.current?.getResult?.()
|
|
107
|
+
const res = useForm.getValues()
|
|
108
|
+
console.log(res)
|
|
109
|
+
}}>getData</Button>
|
|
110
|
+
<Button color={'orange'} variant={'outlined'} onClick={() => {
|
|
111
|
+
useForm.setValues({
|
|
112
|
+
username: 'antd',
|
|
113
|
+
password: 'I love you'
|
|
114
|
+
})
|
|
115
|
+
}}>setData</Button>
|
|
116
|
+
<Button color={'blue'} variant={'outlined'} onClick={() => {
|
|
117
|
+
antdFormRef.current?.validator().then(v => {
|
|
118
|
+
console.log(v)
|
|
119
|
+
}).catch(r => {
|
|
120
|
+
console.log(r)
|
|
121
|
+
})
|
|
122
|
+
}}>validator</Button>
|
|
123
|
+
<Button color={'red'} variant={'outlined'} onClick={() => {
|
|
124
|
+
useForm.onReset()
|
|
125
|
+
}}>reset</Button>
|
|
126
|
+
<Button variant={'outlined'} onClick={() => {
|
|
127
|
+
useForm.setDisabled(true)
|
|
128
|
+
}}>setDisabled</Button>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default SimpleForm;
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
##### 自定义表单
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
import {useRef} from "react";
|
|
142
|
+
import {Button, Input, Select} from "antd";
|
|
143
|
+
import {
|
|
144
|
+
DynamicInput,
|
|
145
|
+
type dynamicInputRef,
|
|
146
|
+
omitFormCommonKey,
|
|
147
|
+
OmitValue,
|
|
148
|
+
useDyForm,
|
|
149
|
+
useReactiveForm
|
|
150
|
+
} from "dynamicformdjx-react";
|
|
151
|
+
import {AdDynamicForm, type adDynamicFormRef} from "dynamicformdjx-react/antd";
|
|
152
|
+
import type {Rule} from "antd/es/form";
|
|
153
|
+
|
|
154
|
+
type RowProps = {
|
|
155
|
+
username: string
|
|
156
|
+
job: string
|
|
157
|
+
json: object
|
|
158
|
+
}
|
|
159
|
+
const CustomForm = () => {
|
|
160
|
+
const [formItems, setFormItems] = useReactiveForm<RowProps, Rule | Rule[]>([
|
|
161
|
+
{
|
|
162
|
+
key: "username",
|
|
163
|
+
label: "用户名",
|
|
164
|
+
value: "",
|
|
165
|
+
allowClear: true,
|
|
166
|
+
render2: (f) => <Input placeholder="请输入姓名" {...OmitValue(f, omitFormCommonKey)}/>,
|
|
167
|
+
rule: [
|
|
168
|
+
{
|
|
169
|
+
required: true,
|
|
170
|
+
message: 'Please confirm your username!',
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
validator: async (_, value) => {
|
|
174
|
+
if (!value) return; // 交给 required 处理
|
|
175
|
+
if (value.length < 3) {
|
|
176
|
+
throw new Error('至少 3 个字符');
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
key: "job",
|
|
184
|
+
label: "职位",
|
|
185
|
+
value: "",
|
|
186
|
+
required: true,
|
|
187
|
+
render2: (f) => <Select
|
|
188
|
+
style={{
|
|
189
|
+
width: '100%'
|
|
190
|
+
}}
|
|
191
|
+
options={[
|
|
192
|
+
{value: 'jack', label: 'Jack'},
|
|
193
|
+
{value: 'lucy', label: 'Lucy'},
|
|
194
|
+
{value: 'Yiminghe', label: 'yiminghe'},
|
|
195
|
+
{value: 'disabled', label: 'Disabled', disabled: true},
|
|
196
|
+
]}
|
|
197
|
+
/>,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: "json",
|
|
201
|
+
label: "Json",
|
|
202
|
+
value: {},
|
|
203
|
+
isCustom: true,
|
|
204
|
+
rule: [
|
|
205
|
+
{
|
|
206
|
+
required: true,
|
|
207
|
+
message: 'json 不能为空'
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
validator: async (_, value) => {
|
|
211
|
+
if (!value || Object.keys(value).length === 0) {
|
|
212
|
+
throw new Error('json 不能为空');
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
],
|
|
217
|
+
render2: f => {
|
|
218
|
+
return <DynamicInput ref={dynamicInputRef} value={f.value} onChange={(v: object) => {
|
|
219
|
+
f.value = v
|
|
220
|
+
}} isController/>
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
])
|
|
224
|
+
const useForm = useDyForm([formItems, setFormItems])
|
|
225
|
+
const antdFormRef = useRef<adDynamicFormRef>(null)
|
|
226
|
+
const dynamicInputRef = useRef<dynamicInputRef>(null)
|
|
227
|
+
return (
|
|
228
|
+
<div className='dynamicFormTest'>
|
|
229
|
+
<AdDynamicForm ref={antdFormRef} items={formItems}/>
|
|
230
|
+
<div className="footer" style={{
|
|
231
|
+
display: 'flex',
|
|
232
|
+
gap: '5px'
|
|
233
|
+
}}>
|
|
234
|
+
<Button color={'green'} variant={'outlined'} onClick={() => {
|
|
235
|
+
// const res=antdFormRef.current?.getResult?.()
|
|
236
|
+
const res = useForm.getValues()
|
|
237
|
+
console.log(res)
|
|
238
|
+
}}>getData</Button>
|
|
239
|
+
<Button color={'orange'} variant={'outlined'} onClick={() => {
|
|
240
|
+
useForm.setValues({
|
|
241
|
+
username: 'antd',
|
|
242
|
+
job: 'jack'
|
|
243
|
+
})
|
|
244
|
+
dynamicInputRef.current?.onSet?.({
|
|
245
|
+
a: 'Hello world',
|
|
246
|
+
b: 1314,
|
|
247
|
+
c: [5, 2, 0]
|
|
248
|
+
})
|
|
249
|
+
}}>setData</Button>
|
|
250
|
+
<Button color={'blue'} variant={'outlined'} onClick={() => {
|
|
251
|
+
antdFormRef.current?.validator().then(v => {
|
|
252
|
+
console.log(v)
|
|
253
|
+
}).catch(r => {
|
|
254
|
+
console.error(r)
|
|
255
|
+
})
|
|
256
|
+
}}>validator</Button>
|
|
257
|
+
<Button color={'red'} variant={'outlined'} onClick={() => {
|
|
258
|
+
useForm.onReset()
|
|
259
|
+
dynamicInputRef.current?.onSet?.({})
|
|
260
|
+
}}>reset</Button>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export default CustomForm;
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 动态录入
|
|
271
|
+
|
|
272
|
+
> 此录入无需组件库依赖
|
|
273
|
+
|
|
274
|
+
### 1.单组件
|
|
275
|
+
|
|
24
276
|
```tsx
|
|
25
277
|
import {useState} from "react";
|
|
26
|
-
import {DynamicInput,dynamicFormRef} from "dynamicformdjx-react";
|
|
278
|
+
import {DynamicInput, dynamicFormRef} from "dynamicformdjx-react";
|
|
27
279
|
|
|
28
280
|
function App() {
|
|
29
|
-
const [obj,setObj]=useState<Record<string, any>>({
|
|
281
|
+
const [obj, setObj] = useState<Record<string, any>>({
|
|
30
282
|
a: 'Hello world',
|
|
31
283
|
b: 1314,
|
|
32
284
|
c: [5, 2, 0]
|
|
33
285
|
});
|
|
34
|
-
const dynamicInputRef=useRef<dynamicFormRef>(null)
|
|
286
|
+
const dynamicInputRef = useRef<dynamicFormRef>(null)
|
|
35
287
|
return (<div>
|
|
36
288
|
<DynamicInput ref={dynamicInputRef} isController value={obj} onChange={(e) => setObj(e)}/>
|
|
37
289
|
<pre>
|
|
38
|
-
{JSON.stringify(obj,null, 2)}
|
|
290
|
+
{JSON.stringify(obj, null, 2)}
|
|
39
291
|
</pre>
|
|
40
292
|
<div>
|
|
41
293
|
<button onClick={() => {
|
|
@@ -51,12 +303,14 @@ function App() {
|
|
|
51
303
|
export default App
|
|
52
304
|
```
|
|
53
305
|
|
|
54
|
-
###
|
|
306
|
+
### 2.级联基本使用
|
|
307
|
+
|
|
55
308
|
```tsx
|
|
56
309
|
import {useState} from "react";
|
|
57
|
-
import {DynamicCascadeInput,dynamicCascadeInputRef} from "dynamicformdjx-react";
|
|
58
|
-
|
|
59
|
-
|
|
310
|
+
import {DynamicCascadeInput, dynamicCascadeInputRef} from "dynamicformdjx-react";
|
|
311
|
+
|
|
312
|
+
const App = () => {
|
|
313
|
+
const [obj, setObj] = useState<Record<string, any>>({
|
|
60
314
|
a: {
|
|
61
315
|
b: {
|
|
62
316
|
c: {
|
|
@@ -69,16 +323,16 @@ const App=()=>{
|
|
|
69
323
|
aa: [5, 2, 0],
|
|
70
324
|
aaa: 1314
|
|
71
325
|
});
|
|
72
|
-
const dynamicInputRef=useRef<dynamicCascadeInputRef>(null)
|
|
326
|
+
const dynamicInputRef = useRef<dynamicCascadeInputRef>(null)
|
|
73
327
|
return (<div>
|
|
74
328
|
<DynamicCascadeInput ref={dynamicInputRef} isController value={obj} onChange={(e) => setObj(e)}/>
|
|
75
329
|
<pre>
|
|
76
|
-
{JSON.stringify(obj,null, 2)}
|
|
330
|
+
{JSON.stringify(obj, null, 2)}
|
|
77
331
|
</pre>
|
|
78
332
|
<div>
|
|
79
333
|
<button onClick={() => {
|
|
80
334
|
dynamicInputRef.current?.onSet?.({
|
|
81
|
-
test:'hello world'
|
|
335
|
+
test: 'hello world'
|
|
82
336
|
})
|
|
83
337
|
}}>setData
|
|
84
338
|
</button>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { FormProps, RowProps } from 'antd';
|
|
3
|
+
import { Rule } from 'antd/es/form';
|
|
4
|
+
import { DyFormItem } from '../types/form';
|
|
5
|
+
import { ExposeDyFType, PresetType } from '../types';
|
|
6
|
+
type RulesMap = Record<string, Rule | Rule[]>;
|
|
7
|
+
type AdDynamicFormProps = {
|
|
8
|
+
header?: () => ReactNode;
|
|
9
|
+
footer?: () => ReactNode;
|
|
10
|
+
items: DyFormItem[];
|
|
11
|
+
preset?: PresetType;
|
|
12
|
+
formConfig?: FormProps;
|
|
13
|
+
gridConfig?: RowProps;
|
|
14
|
+
validateTrigger?: string | null;
|
|
15
|
+
rules?: RulesMap;
|
|
16
|
+
};
|
|
17
|
+
declare const AdDynamicForm: import('react').ForwardRefExoticComponent<AdDynamicFormProps & import('react').RefAttributes<ExposeDyFType>>;
|
|
18
|
+
export default AdDynamicForm;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DyFormItem } from '../../types/form';
|
|
2
|
+
import { PasswordProps, TextAreaProps, InputProps } from 'antd/es/input';
|
|
3
|
+
export declare function renderInput(optionProps: PasswordProps, rf?: DyFormItem): JSX.Element;
|
|
4
|
+
export declare function renderInput(optionProps: TextAreaProps, rf?: DyFormItem): JSX.Element;
|
|
5
|
+
export declare function renderInput(optionProps?: InputProps, rf?: DyFormItem): JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),b=require("react"),y=require("antd");function I(e){return Array.isArray(e)?e:typeof e=="string"&&e.includes(".")?e.split("."):e}function p(e){return Array.isArray(e)?e.join("."):String(e)}function E(e,l){return(Array.isArray(l)?l:[l]).reduce((a,c)=>a==null?a:a[c],e)}function B(e,l,s){const a=Array.isArray(l)?l:[l];let c=e;for(let m=0;m<a.length;m++){const d=a[m];m===a.length-1?c[d]=s:((c[d]==null||typeof c[d]!="object")&&(c[d]={}),c=c[d])}}function w(e){const l={};return e.forEach(s=>{const a=I(s?.path??s?.key);B(l,a,s?.value)}),l}const S=b.forwardRef((e,l)=>{const[s]=y.Form.useForm(),a=e.validateTrigger??"onBlur",c=e.validateTrigger===null?void 0:a,m=e.preset??"fullRow",[d,A]=b.useState({}),u=b.useMemo(()=>(e.items??[]).filter(r=>!r?.hidden),[e.items]),q=b.useMemo(()=>[...u].sort((r,t)=>{const o=r?.sort??1/0,f=t?.sort??1/0;return Number(o)-Number(f)}),[u]),P=b.useMemo(()=>{const r={};return u.forEach(t=>{const o=I(t?.path??t?.key),f=p(o);let i=t?.rule;if(t?.required&&!t?.rule){const n=typeof t?.label=="string"?t.label:"";i={required:!0,message:t?.requiredHint?.(n)??`${n||t?.key}不能为空`,validateTrigger:c}}if(i&&(r[f]=i,t.isCustom)){const n=Array.isArray(i)?i:[i];A(C=>({...C,[o]:{status:!1,help:n.map(h=>h.message).filter(Boolean).join(",")}}))}}),{...r,...e.rules??{}}},[u,e.rules]);b.useEffect(()=>{s.setFieldsValue(w(u))},[s,u]);const R=(r,t)=>{u.forEach(o=>{const f=I(o?.path??o?.key);o.value=E(t,f)})};b.useImperativeHandle(l,()=>({reset:(r=null)=>{u.forEach(t=>t.value=r),s.setFieldsValue(w(u))},validator:async()=>{const r=u.filter(n=>!n.isCustom).map(n=>I(n?.path??n?.key)),t=await s.validateFields(r);let o={};const f=u.filter(n=>n.isCustom),i=[];for(const n of f){const C=I(n?.path??n?.key),h=p(C),j=P[h],F=Array.isArray(j)?j:j?[j]:[];A(v=>({...v,[h]:{status:"validating",help:""}})),o={...o,[h]:n.value};try{await M(n.value,F),A(v=>({...v,[h]:{status:"success",help:""}}))}catch(v){const x=v?.message||F.map(k=>k.message).filter(Boolean).join(",");A(k=>({...k,[h]:{status:"error",help:x}})),i.push({name:h,errors:[x]})}}return i.length?Promise.reject({errorFields:i,outOfDate:!1}):{...t,...o}},getResult:(r="res")=>r==="ori"?u:w(u),form:s}));const T=(r,t)=>typeof r?.render2=="function"?r.render2.length>=2?r.render2(r,t):r.render2(r):null,N=r=>{const t=I(r?.path??r?.key),o=p(t),f=P[o],i=Array.isArray(f)?f:f?[f]:void 0;let n=i?.map(x=>x.validateTrigger)?.filter(Boolean)??[];c&&(n=n.concat(a));const C=r?.colProps??{span:r?.span??24,offset:r?.offset??0},h=r?.formItemProps??{},{status:j,help:F}=d[o]??{status:void 0,help:void 0},v=r.isCustom?g.jsx(y.Form.Item,{name:void 0,label:r?.label,required:!!r?.required||d[o],validateStatus:j,help:j==="error"?F:void 0,...h,children:T(r,s)},o):g.jsx(y.Form.Item,{name:t,label:r?.label,rules:i,validateTrigger:n,...h,children:T(r,s)},o);return m==="grid"?g.jsx(y.Col,{...C,children:v},o):v};return g.jsxs("div",{className:"dynamicForm",children:[e.header&&g.jsx("div",{className:"header",children:e.header()}),g.jsx(y.Form,{form:s,onValuesChange:R,...e.formConfig,children:m==="grid"?g.jsx(y.Row,{gutter:e.gridConfig?.gutter??10,...e.gridConfig,children:q.map(N)}):q.map(N)}),e.footer&&g.jsx("div",{className:"footer",children:e.footer()})]})});function V(e){return!!(e==null||e===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0)}async function M(e,l){for(const s of l){const a=s;if(a?.required&&V(e))throw new Error(a?.message||"必填");typeof a?.validator=="function"&&await a.validator(a,e)}}function O(e={},l){const{type:s="text",key:a,render2:c,...m}=l??{},d=A=>{l?.onChange?.(A.target.value,l),e?.onChange?.(A)};switch(s){case"password":return g.jsx(y.Input.Password,{...m,...e,onChange:d});case"textarea":return g.jsx(y.Input.TextArea,{...m,...e,onChange:d});default:return g.jsx(y.Input,{...m,...e,onChange:d})}}exports.AdDynamicForm=S;exports.renderInput=O;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { jsxs as B, jsx as g } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as V, useState as O, useMemo as p, useEffect as S, useImperativeHandle as D } from "react";
|
|
3
|
+
import { Form as F, Row as H, Col as M, Input as w } from "antd";
|
|
4
|
+
function b(e) {
|
|
5
|
+
return Array.isArray(e) ? e : typeof e == "string" && e.includes(".") ? e.split(".") : e;
|
|
6
|
+
}
|
|
7
|
+
function N(e) {
|
|
8
|
+
return Array.isArray(e) ? e.join(".") : String(e);
|
|
9
|
+
}
|
|
10
|
+
function K(e, l) {
|
|
11
|
+
return (Array.isArray(l) ? l : [l]).reduce((a, c) => a == null ? a : a[c], e);
|
|
12
|
+
}
|
|
13
|
+
function _(e, l, s) {
|
|
14
|
+
const a = Array.isArray(l) ? l : [l];
|
|
15
|
+
let c = e;
|
|
16
|
+
for (let m = 0; m < a.length; m++) {
|
|
17
|
+
const d = a[m];
|
|
18
|
+
m === a.length - 1 ? c[d] = s : ((c[d] == null || typeof c[d] != "object") && (c[d] = {}), c = c[d]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function P(e) {
|
|
22
|
+
const l = {};
|
|
23
|
+
return e.forEach((s) => {
|
|
24
|
+
const a = b(s?.path ?? s?.key);
|
|
25
|
+
_(l, a, s?.value);
|
|
26
|
+
}), l;
|
|
27
|
+
}
|
|
28
|
+
const Q = V((e, l) => {
|
|
29
|
+
const [s] = F.useForm(), a = e.validateTrigger ?? "onBlur", c = e.validateTrigger === null ? void 0 : a, m = e.preset ?? "fullRow", [d, v] = O({}), u = p(
|
|
30
|
+
() => (e.items ?? []).filter((r) => !r?.hidden),
|
|
31
|
+
[e.items]
|
|
32
|
+
), T = p(() => [...u].sort((r, t) => {
|
|
33
|
+
const o = r?.sort ?? 1 / 0, f = t?.sort ?? 1 / 0;
|
|
34
|
+
return Number(o) - Number(f);
|
|
35
|
+
}), [u]), E = p(() => {
|
|
36
|
+
const r = {};
|
|
37
|
+
return u.forEach((t) => {
|
|
38
|
+
const o = b(t?.path ?? t?.key), f = N(o);
|
|
39
|
+
let i = t?.rule;
|
|
40
|
+
if (t?.required && !t?.rule) {
|
|
41
|
+
const n = typeof t?.label == "string" ? t.label : "";
|
|
42
|
+
i = {
|
|
43
|
+
required: !0,
|
|
44
|
+
message: t?.requiredHint?.(n) ?? `${n || t?.key}不能为空`,
|
|
45
|
+
validateTrigger: c
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (i && (r[f] = i, t.isCustom)) {
|
|
49
|
+
const n = Array.isArray(i) ? i : [i];
|
|
50
|
+
v((C) => ({
|
|
51
|
+
...C,
|
|
52
|
+
[o]: {
|
|
53
|
+
status: !1,
|
|
54
|
+
help: n.map((h) => h.message).filter(Boolean).join(",")
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
}), { ...r, ...e.rules ?? {} };
|
|
59
|
+
}, [u, e.rules]);
|
|
60
|
+
S(() => {
|
|
61
|
+
s.setFieldsValue(P(u));
|
|
62
|
+
}, [s, u]);
|
|
63
|
+
const x = (r, t) => {
|
|
64
|
+
u.forEach((o) => {
|
|
65
|
+
const f = b(o?.path ?? o?.key);
|
|
66
|
+
o.value = K(t, f);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
D(l, () => ({
|
|
70
|
+
reset: (r = null) => {
|
|
71
|
+
u.forEach((t) => t.value = r), s.setFieldsValue(P(u));
|
|
72
|
+
},
|
|
73
|
+
validator: async () => {
|
|
74
|
+
const r = u.filter((n) => !n.isCustom).map((n) => b(n?.path ?? n?.key)), t = await s.validateFields(r);
|
|
75
|
+
let o = {};
|
|
76
|
+
const f = u.filter((n) => n.isCustom), i = [];
|
|
77
|
+
for (const n of f) {
|
|
78
|
+
const C = b(n?.path ?? n?.key), h = N(C), A = E[h], I = Array.isArray(A) ? A : A ? [A] : [];
|
|
79
|
+
v((y) => ({ ...y, [h]: { status: "validating", help: "" } })), o = { ...o, [h]: n.value };
|
|
80
|
+
try {
|
|
81
|
+
await z(n.value, I), v((y) => ({ ...y, [h]: { status: "success", help: "" } }));
|
|
82
|
+
} catch (y) {
|
|
83
|
+
const k = y?.message || I.map((j) => j.message).filter(Boolean).join(",");
|
|
84
|
+
v((j) => ({ ...j, [h]: { status: "error", help: k } })), i.push({ name: h, errors: [k] });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return i.length ? Promise.reject({ errorFields: i, outOfDate: !1 }) : { ...t, ...o };
|
|
88
|
+
},
|
|
89
|
+
getResult: (r = "res") => r === "ori" ? u : P(u),
|
|
90
|
+
form: s
|
|
91
|
+
}));
|
|
92
|
+
const R = (r, t) => typeof r?.render2 == "function" ? r.render2.length >= 2 ? r.render2(r, t) : r.render2(r) : null, q = (r) => {
|
|
93
|
+
const t = b(r?.path ?? r?.key), o = N(t), f = E[o], i = Array.isArray(f) ? f : f ? [f] : void 0;
|
|
94
|
+
let n = i?.map((k) => k.validateTrigger)?.filter(Boolean) ?? [];
|
|
95
|
+
c && (n = n.concat(a));
|
|
96
|
+
const C = r?.colProps ?? { span: r?.span ?? 24, offset: r?.offset ?? 0 }, h = r?.formItemProps ?? {}, { status: A, help: I } = d[o] ?? { status: void 0, help: void 0 }, y = r.isCustom ? /* @__PURE__ */ g(
|
|
97
|
+
F.Item,
|
|
98
|
+
{
|
|
99
|
+
name: void 0,
|
|
100
|
+
label: r?.label,
|
|
101
|
+
required: !!r?.required || d[o],
|
|
102
|
+
validateStatus: A,
|
|
103
|
+
help: A === "error" ? I : void 0,
|
|
104
|
+
...h,
|
|
105
|
+
children: R(r, s)
|
|
106
|
+
},
|
|
107
|
+
o
|
|
108
|
+
) : /* @__PURE__ */ g(
|
|
109
|
+
F.Item,
|
|
110
|
+
{
|
|
111
|
+
name: t,
|
|
112
|
+
label: r?.label,
|
|
113
|
+
rules: i,
|
|
114
|
+
validateTrigger: n,
|
|
115
|
+
...h,
|
|
116
|
+
children: R(r, s)
|
|
117
|
+
},
|
|
118
|
+
o
|
|
119
|
+
);
|
|
120
|
+
return m === "grid" ? /* @__PURE__ */ g(M, { ...C, children: y }, o) : y;
|
|
121
|
+
};
|
|
122
|
+
return /* @__PURE__ */ B("div", { className: "dynamicForm", children: [
|
|
123
|
+
e.header && /* @__PURE__ */ g("div", { className: "header", children: e.header() }),
|
|
124
|
+
/* @__PURE__ */ g(F, { form: s, onValuesChange: x, ...e.formConfig, children: m === "grid" ? /* @__PURE__ */ g(H, { gutter: e.gridConfig?.gutter ?? 10, ...e.gridConfig, children: T.map(q) }) : T.map(q) }),
|
|
125
|
+
e.footer && /* @__PURE__ */ g("div", { className: "footer", children: e.footer() })
|
|
126
|
+
] });
|
|
127
|
+
});
|
|
128
|
+
function $(e) {
|
|
129
|
+
return !!(e == null || e === "" || Array.isArray(e) && e.length === 0 || typeof e == "object" && !Array.isArray(e) && Object.keys(e).length === 0);
|
|
130
|
+
}
|
|
131
|
+
async function z(e, l) {
|
|
132
|
+
for (const s of l) {
|
|
133
|
+
const a = s;
|
|
134
|
+
if (a?.required && $(e))
|
|
135
|
+
throw new Error(a?.message || "必填");
|
|
136
|
+
typeof a?.validator == "function" && await a.validator(a, e);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function U(e = {}, l) {
|
|
140
|
+
const { type: s = "text", key: a, render2: c, ...m } = l ?? {}, d = (v) => {
|
|
141
|
+
l?.onChange?.(v.target.value, l), e?.onChange?.(v);
|
|
142
|
+
};
|
|
143
|
+
switch (s) {
|
|
144
|
+
case "password":
|
|
145
|
+
return /* @__PURE__ */ g(w.Password, { ...m, ...e, onChange: d });
|
|
146
|
+
case "textarea":
|
|
147
|
+
return /* @__PURE__ */ g(w.TextArea, { ...m, ...e, onChange: d });
|
|
148
|
+
default:
|
|
149
|
+
return /* @__PURE__ */ g(w, { ...m, ...e, onChange: d });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export {
|
|
153
|
+
Q as AdDynamicForm,
|
|
154
|
+
U as renderInput
|
|
155
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const omitFormCommonKey: readonly ["value", "key", "onChange", "render2"];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { DyFormItem } from '../types/form';
|
|
3
|
+
type Options = {
|
|
4
|
+
syncFromRaw?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function useReactiveForm<T extends Record<string, any>, U = any>(rawItems: DyFormItem<T, U>[], options?: Options): readonly [DyFormItem<T, U>[], Dispatch<SetStateAction<DyFormItem<T, U>[]>>];
|
|
7
|
+
type KeyOf<T> = Extract<keyof T, string>;
|
|
8
|
+
type ItemsState<Row extends Record<string, any>, RuleT = any> = readonly [
|
|
9
|
+
DyFormItem<Row, RuleT>[],
|
|
10
|
+
Dispatch<SetStateAction<DyFormItem<Row, RuleT>[]>>
|
|
11
|
+
];
|
|
12
|
+
export declare function useDyForm<Row extends Record<string, any>, RuleT = any>(itemsState: ItemsState<Row, RuleT>): {
|
|
13
|
+
items: DyFormItem<Row, RuleT>[];
|
|
14
|
+
setDisabled: (disabled: boolean, keys?: KeyOf<Row>[]) => void;
|
|
15
|
+
setHidden: (hidden: boolean, keys?: KeyOf<Row>[]) => void;
|
|
16
|
+
setValue: <K extends KeyOf<Row>>(key: K, value: Row[K]) => void;
|
|
17
|
+
setValues: (patch: Partial<{ [K in KeyOf<Row>]: Row[K]; }>) => void;
|
|
18
|
+
getValue: <K extends KeyOf<Row>>(key: K) => Row[K] | undefined;
|
|
19
|
+
getValues: <K extends KeyOf<Row>>(keys?: readonly K[]) => Partial<Pick<Row, K>> & Record<string, any>;
|
|
20
|
+
onReset: (value?: any) => void;
|
|
21
|
+
getItem: <K extends KeyOf<Row>>(key: K) => DyFormItem<Row, RuleT> | undefined;
|
|
22
|
+
setItem: <K extends KeyOf<Row>>(k: K, patchItem: Partial<Omit<DyFormItem<Row, RuleT>, "key">>) => void;
|
|
23
|
+
setItems: <K extends KeyOf<Row>>(patch: [K, Partial<Omit<DyFormItem<Row, RuleT>, "key">>][]) => void;
|
|
24
|
+
updateKeys: <K extends KeyOf<Row>>(patch: [K, string][]) => void;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const s=require("react/jsx-runtime"),b=require("react"),K=(u,d,t)=>Object.keys(u).map((n,m)=>{const h=u[n],p=Array.isArray(h),w=p?h.every(D=>typeof D=="number"):typeof h=="number";return{rId:d(m),key:n,value:p?h.join(t):h,isArray:p||void 0,isNumber:w||void 0}}),B=(u,d)=>u.reduce((t,n)=>(n.key.trim()&&(t[n.key]=_(n.value,n.isArray,n.isNumber,d)),t),{}),_=(u,d,t,n=",")=>{let m;return d?t?m=String(u).split(n).map(Number).filter(h=>!Number.isNaN(h)):m=String(u).split(n):t?m=parseFloat(u):m=u.toString(),m},W=(u,d,t=",")=>{const n=m=>{m=m.replace(/[^\d.-]/g,"");let h=!1;m.startsWith("-")&&(h=!0),m=m.replace(/-/g,"");const p=m.indexOf(".");return p!==-1&&(m=m.slice(0,p+1)+m.slice(p+1).replace(/\./g,"")),(h?"-":"")+m};return d?u.split(t).map(m=>n(m)).join(t):n(u)},G=u=>`hsl(${u*35%360}, 60%, 65%)`,J=(u,d)=>u[d-1]??G(d);function O(u,d,t){if(d.length===0)return t(u,-1);const[n,...m]=d,h=[...u];if(m.length===0)return t(h,n);const p=h[n];if(!Array.isArray(p.value))return h;const w=O(p.value,m,t);return w.length===0?h[n]={...p,value:"",isArray:void 0,isNumber:void 0}:h[n]={...p,value:w},h}function k(u){return u.filter(Boolean).join(" ")}function U(u,d){const t={...u};return delete t.value,d?.forEach(n=>{n!=="value"&&delete t[n]}),t}const X=b.forwardRef((u,d)=>{const{value:t={},size:n,dyCls:m,isController:h,configs:p,btnConfigs:w,dyListConfigs:D,randomFun:N=e=>`${Date.now()}_${e??0}`,onReset:L,onMerge:P,onChange:H}=u,M={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...w},R={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...p},x={arraySplitSymbol:",",...D},[r,a]=b.useState(()=>K(t,N,x.arraySplitSymbol)),c=b.useRef(null);return b.useImperativeHandle(d,()=>({getResult(e){return e==="ori"?r:B(r,x.arraySplitSymbol)},onSet(e){a(K(e??t,N,x.arraySplitSymbol))}})),b.useEffect(()=>{h&&H(B(r,x.arraySplitSymbol))},[r]),s.jsxs("div",{className:`dynamicInput ${n} ${m}`,children:[s.jsx("div",{className:`dyFormList ${r.length?"":"noList"}`,ref:c,style:{maxHeight:R.maxHeight},children:r.map((e,o,A)=>s.jsxs("div",{className:"dItem",children:[s.jsxs("div",{className:"input",children:[s.jsx("input",{value:e.key,className:"key nativeInput",onInput:f=>{const l=f.target.value;a(y=>{const j=[...y],i=j[o];return j[o]={...i,key:l},j})}}),":",s.jsxs("div",{className:"vInput",children:[s.jsxs("div",{className:"slot",children:[s.jsx("button",{className:k([e.isArray?"success":"default","small","bt"]),onClick:()=>{a(f=>{const l=[...f],y=l[o];return l[o]={...y,isArray:!y.isArray},l})},children:"Array"})," ",s.jsx("button",{className:k([e.isNumber?"success":"default","small","bt"]),onClick:()=>{a(f=>{const l=[...f],y=l[o];return l[o]={...y,isNumber:!y.isNumber},l})},children:"Number"})]}),s.jsx("input",{value:e.value,className:"value nativeV",onInput:f=>{const l=f.target.value;let y=l;e.isNumber&&R.allowFilter&&(y=W(l,e.isArray,x.arraySplitSymbol)),a(j=>{const i=[...j],V=i[o];return i[o]={...V,value:y},i})}})]})]}),s.jsxs("div",{className:"btn",children:[s.jsx("button",{className:k([n,"success","bt"]),disabled:o!==A.length-1,onClick:()=>{a(f=>[...f,{rId:N(),key:"",value:""}]),R.autoScroll&&setTimeout(()=>{const f=c.current;f?.scrollTo({top:f?.scrollHeight+20,behavior:"smooth"})})},children:"+"}),s.jsx("button",{className:k(["danger",n,"bt"]),onClick:()=>{a(f=>f.filter(l=>l.rId!==e.rId))},children:"-"})]})]},e.rId))}),s.jsxs("div",{className:`control ${r.length?"":"noList"}`,children:[!r.length&&s.jsx("button",{className:k(["success",n,"bt"]),onClick:()=>{a(e=>[...e,{rId:N(),key:"",value:""}])},children:M.newTxt}),!h&&s.jsxs(s.Fragment,{children:[!R.hideReset&&s.jsx("button",{className:k(["default",n,"bt"]),onClick:()=>{a(K(t,N,x.arraySplitSymbol)),L?.()},children:M.resetTxt}),s.jsx("button",{className:k(["info",n,"bt"]),onClick:()=>{[...r].sort((A,f)=>+A.rId-+f.rId);const o=B(r,x.arraySplitSymbol);H(o),P?.(o,r),a(K(o,N,x.arraySplitSymbol))},children:M.mergeTxt})]})]})]})}),Y=b.forwardRef((u,d)=>{const{depth:t=5,value:n,isController:m,dyCls:h,configs:p,btnConfigs:w,dyListConfigs:D,randomFun:N=l=>`${Date.now()}_${l??0}`,newChildTxt:L=l=>`添加 '${l.key}' 子项`,onReset:P,onMerge:H,onChange:M}=u,R={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...w},x={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...p},r={arraySplitSymbol:",",...D},a=l=>["string","number"].includes(l),[c,e]=b.useState(()=>o(n));b.useImperativeHandle(d,()=>({getResult(l){return l==="ori"?c:A(c)},onSet(l){e(o(l??n))}}));function o(l){return Object.keys(l).map((y,j)=>{let i=l[y];const V=Array.isArray(i),q=V?i.every(E=>typeof E=="number"):typeof i=="number",F=i===null;return a(typeof i)&&(i=l[y]),F&&(i=""),{rId:N(j),key:y,value:Object.prototype.toString.call(i)==="[object Object]"?o(l[y]):V?i.join(r.arraySplitSymbol):i,isArray:V||void 0,isNumber:q||void 0}})}const A=l=>l.reduce((y,j)=>{const i=j.value;return j.key.trim().length&&(y[j.key]=Array.isArray(i)?A(i):_(j.value,j.isArray,j.isNumber,r.arraySplitSymbol)),y},{}),f=(l,y=1,j=[])=>s.jsx("div",{className:k([`depth-${y}`,x.showBorder?"":"no-border",x.showPad?"":"no-pad"]),style:{"--depth":y,["--c"+[y]]:J(x.borderColors,y)},children:l.map((i,V,q)=>{const F=[...j,V],E=Array.isArray(i.value),Q=a(typeof i.value);return s.jsxs("div",{className:"dItem",style:{marginLeft:y>1?`${y*x.retractLen}px`:"0"},children:[s.jsxs("div",{className:"input",children:[!E&&s.jsxs(s.Fragment,{children:[s.jsx("input",{value:i.key,className:"key nativeInput",onInput:I=>{const S=I.target.value;e(g=>O(g,F,(v,C)=>{const T=[...v],$=T[C];return T[C]={...$,key:S},T}))}}),":"]}),s.jsxs("div",{className:"vInput",children:[s.jsx("div",{className:"slot",children:Array.isArray(i.value)?void 0:s.jsxs(s.Fragment,{children:[s.jsx("button",{className:k([i.isArray?"success":"default","small","bt"]),onClick:()=>{e(I=>O(I,F,(S,g)=>{const v=[...S],C=v[g];return v[g]={...C,isArray:!C.isArray},v}))},children:"Array"})," ",s.jsx("button",{className:k([i.isNumber?"success":"default","small","bt"]),onClick:()=>{e(I=>O(I,F,(S,g)=>{const v=[...S],C=v[g];return v[g]={...C,isNumber:!C.isNumber},v}))},children:"Number"})]})}),s.jsx("input",{className:`value nativeV ${E?"isKey":""}`,value:Q?i.value:i.key,onInput:I=>{const S=I.target.value;if(E){e(v=>O(v,F,(C,T)=>{const $=[...C],z=$[T];return $[T]={...z,key:S},$}));return}let g=S;x.allowFilter&&i.isNumber&&(g=W(S,i.isArray,r.arraySplitSymbol)),e(v=>O(v,F,(C,T)=>{const $=[...C],z=$[T];return $[T]={...z,value:g},$}))}}),s.jsx("div",{className:"surSlot",children:y<t?!E&&s.jsx("button",{className:k(["success","bt"]),onClick:()=>{e(I=>O(I,F,(S,g)=>{const v=[...S],C=v[g],$=[...Array.isArray(C.value)?C.value:[],{rId:N(),key:"",value:""}];return v[g]={...C,isArray:void 0,isNumber:void 0,value:$},v}))},children:L(i)}):null})]})]}),s.jsxs("div",{className:"btn",children:[s.jsx("button",{className:k(["success","bt"]),disabled:V!==q.length-1,onClick:()=>{e(I=>O(I,F,(S,g)=>{const v=[...S];return v.splice(g+1,0,{rId:N(),key:"",value:""}),v}))},children:"+"}),s.jsx("button",{className:k(["danger","bt"]),onClick:()=>{e(I=>O(I,F,(S,g)=>{const v=[...S];return v.splice(g,1),v}))},children:"-"})]}),Array.isArray(i.value)&&f(i.value,y+1,F)]},i.rId)})});return b.useEffect(()=>{m&&M(A(c))},[c]),s.jsxs("div",{className:`dynamicCascadeInput ${h}`,children:[s.jsx("div",{className:`dyFormList ${c.length?"":"noObj"}`,style:{maxHeight:x.maxHeight},children:f(c)}),s.jsxs("div",{className:`control ${c.length?"":"noObj"}`,children:[!c.length&&s.jsx("button",{className:k(["success","bt"]),onClick:()=>{e(l=>[...l,{rId:N(),key:"",value:""}])},children:R.newTxt}),!m&&s.jsxs(s.Fragment,{children:[!x.hideReset&&s.jsx("button",{className:k(["default","bt"]),onClick:()=>{e(o(n)),P?.()},children:R.resetTxt}),s.jsx("button",{className:k(["info","bt"]),onClick:()=>{const l=A(c);M(l),H?.(l,c),e(o(l))},children:R.mergeTxt})]})]})]})}),Z=["value","key","onChange","render2"];function ee(u,d={}){const[t,n]=b.useState(()=>u);return b.useEffect(()=>{d.syncFromRaw&&n(u)},[d.syncFromRaw,u]),[t,n]}function te(u){const[d,t]=u,n=b.useRef(d);b.useEffect(()=>{n.current=d},[d]);const m=b.useCallback(()=>n.current,[]),h=b.useCallback((r,a)=>{const c=a?.length?new Set(a):null;t(e=>e.map(o=>{const A=o.key;return!c||c.has(A)?{...o,disabled:r}:o}))},[t]),p=b.useCallback((r,a)=>{const c=a?.length?new Set(a):null;t(e=>e.map(o=>{const A=o.key;return!c||c.has(A)?{...o,hidden:r}:o}))},[t]),w=b.useCallback((r,a)=>{t(c=>c.map(e=>e.key===r?{...e,value:a}:e))},[t]),D=b.useCallback(r=>{t(a=>a.map(c=>{const e=c.key;return e in r?{...c,value:r[e]}:c}))},[t]),N=b.useCallback(r=>m().find(a=>a.key===r),[m]),L=b.useCallback(r=>{const a=N(r);return a?a.value:void 0},[N]),P=b.useCallback(r=>{const a=r?.length?new Set(r):null;return m().reduce((c,e)=>{const o=e.key;return(!a||a.has(o))&&(c[o]=e.value),c},{})},[m]),H=b.useCallback((r=null)=>{t(a=>a.map(c=>({...c,value:r})))},[t]),M=b.useCallback((r,a)=>{t(c=>c.map(e=>{if(e.key!==r)return e;const{key:o,...A}=a;return{...e,...A}}))},[t]),R=b.useCallback(r=>{const a=new Map(r);t(c=>c.map(e=>{const o=a.get(e.key);if(!o)return e;const{key:A,...f}=o;return{...e,...f}}))},[t]),x=b.useCallback(r=>{const a=new Map(r);t(c=>c.map(e=>{const o=a.get(e.key);return o?{...e,key:o}:e}))},[t]);return b.useMemo(()=>({items:d,setDisabled:h,setHidden:p,setValue:w,setValues:D,getValue:L,getValues:P,onReset:H,getItem:N,setItem:M,setItems:R,updateKeys:x}),[d,h,p,w,D,L,P,H,N,M,R,x])}exports.DynamicCascadeInput=Y;exports.DynamicInput=X;exports.OmitValue=U;exports.clsx=k;exports.formatNumberInput=W;exports.getDepthColor=G;exports.omitFormCommonKey=Z;exports.parseValue=_;exports.resetObj=B;exports.saferRepairColor=J;exports.tranArr=K;exports.updateArrayAtPath=O;exports.useDyForm=te;exports.useReactiveForm=ee;
|