@simpleform/render 2.0.8 → 3.0.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 +194 -218
- package/README_CN.md +196 -219
- package/lib/components/grid.d.ts +2 -2
- package/lib/hooks.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/store.d.ts +15 -26
- package/lib/types.d.ts +20 -30
- package/lib/utils/object.d.ts +0 -1
- package/lib/utils/utils.d.ts +9 -23
- package/package.json +2 -2
package/README_CN.md
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.md) | 中文说明
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@simpleform/render)
|
|
6
6
|
|
|
7
7
|
> 轻量级动态表单引擎,实现动态渲染表单很简单.
|
|
8
8
|
|
|
9
9
|
* Break Change: 建议使用3.x以上版本,提供了更好的语义化`JSON`结构。
|
|
10
|
+
- 废弃 ~`properties`~ : 由`widgetList`代替.
|
|
11
|
+
- 废弃 ~`onPropertiesChange`~ : 由`onRenderChange`代替.
|
|
12
|
+
- `useSimpleFormRender()`的方法全部变更使用方式.
|
|
10
13
|
|
|
11
14
|
## 介绍
|
|
12
|
-
- 组件注册: 在`@simpleform/render`中使用的表单控件必须是具有`value`和`onChange
|
|
13
|
-
- 组件描述:`
|
|
15
|
+
- 组件注册: 在`@simpleform/render`中使用的表单控件必须是具有`value`和`onChange`两个`props`的受控组件.
|
|
16
|
+
- 组件描述:`widgetList`数组列表描述当前的表单结构.
|
|
14
17
|
- 组件渲染:`Form`组件处理表单的值, `FormChildren`组件处理表单的渲染, 一个`Form`组件可以支持多个`FormChildren`组件在内部渲染.
|
|
15
|
-
- 组件联动:表单属性均可以支持字符串表达式描述联动条件(`
|
|
18
|
+
- 组件联动:表单属性均可以支持字符串表达式描述联动条件(`widgetList`属性除外).
|
|
16
19
|
|
|
17
20
|
## 安装
|
|
18
21
|
- [Node.js](https://nodejs.org/en/) Version >= 14.0.0
|
|
@@ -118,105 +121,104 @@ export default function Demo5(props) {
|
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
children:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
124
|
+
const widgetList = [
|
|
125
|
+
{
|
|
126
|
+
label: "readonly",
|
|
127
|
+
name: 'name1',
|
|
128
|
+
readOnly: true,
|
|
129
|
+
readOnlyRender: "readonly component",
|
|
130
|
+
initialValue: 1111,
|
|
131
|
+
hidden: '{{formvalues && formvalues.name6 == true}}',
|
|
132
|
+
type: 'Input',
|
|
133
|
+
props: {}
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
label: "input",
|
|
137
|
+
name: 'name2',
|
|
138
|
+
rules: [{ required: true, message: 'input empty' }],
|
|
139
|
+
initialValue: 1,
|
|
140
|
+
hidden: '{{formvalues && formvalues.name6 == true}}',
|
|
141
|
+
type: 'Input',
|
|
142
|
+
props: {}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
label: 'list[0]',
|
|
146
|
+
name: 'list[0]',
|
|
147
|
+
rules: [{ required: true, message: 'list[0] empty' }],
|
|
148
|
+
initialValue: { label: 'option1', value: '1', key: '1' },
|
|
149
|
+
type: 'Select',
|
|
150
|
+
props: {
|
|
151
|
+
labelInValue: true,
|
|
152
|
+
style: { width: '100%' },
|
|
153
|
+
children: [
|
|
154
|
+
{ type: 'Select.Option', props: { key: 1, value: '1', children: 'option1' } },
|
|
155
|
+
{ type: 'Select.Option', props: { key: 2, value: '2', children: 'option2' } }
|
|
156
|
+
]
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
label: 'list[1]',
|
|
161
|
+
name: 'list[1]',
|
|
162
|
+
rules: [{ required: true, message: 'list[1] empty' }],
|
|
163
|
+
type: 'Select',
|
|
164
|
+
props: {
|
|
165
|
+
labelInValue: true,
|
|
166
|
+
style: { width: '100%' },
|
|
167
|
+
children: [
|
|
168
|
+
{ type: 'Select.Option', props: { key: 1, value: '1', children: 'option1' } },
|
|
169
|
+
{ type: 'Select.Option', props: { key: 2, value: '2', children: 'option2' } }
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
label: 'first',
|
|
175
|
+
name: 'name4.first',
|
|
176
|
+
rules: [{ required: true, message: 'first empty' }],
|
|
177
|
+
type: 'Select',
|
|
178
|
+
props: {
|
|
179
|
+
style: { width: '100%' },
|
|
180
|
+
children: [{ type: 'Select.Option', props: { key: 1, value: '1', children: 'option1' } }]
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
label: 'second',
|
|
185
|
+
name: 'name4.second',
|
|
186
|
+
rules: [{ required: true, message: 'second empty' }],
|
|
187
|
+
type: 'Select',
|
|
188
|
+
props: {
|
|
189
|
+
style: { width: '100%' },
|
|
190
|
+
children: [{ type: 'Select.Option', props: { key: 1, value: '1', children: 'option1' } }]
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
label: 'name5',
|
|
195
|
+
name: 'name5',
|
|
196
|
+
initialValue: { span: 12 },
|
|
197
|
+
valueSetter: "{{(value)=> (value && value['span'])}}",
|
|
198
|
+
valueGetter: "{{(value) => ({span: value})}}",
|
|
199
|
+
type: 'Select',
|
|
200
|
+
props: {
|
|
201
|
+
style: { width: '100%' },
|
|
202
|
+
children: [
|
|
203
|
+
{ type: 'Select.Option', props: { key: 1, value: 12, children: 'option1' } },
|
|
204
|
+
{ type: 'Select.Option', props: { key: 2, value: 6, children: 'option2' } },
|
|
205
|
+
{ type: 'Select.Option', props: { key: 3, value: 4, children: 'option3' } }
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
label: 'checkbox',
|
|
211
|
+
name: 'name6',
|
|
212
|
+
valueProp: 'checked',
|
|
213
|
+
initialValue: true,
|
|
214
|
+
rules: [{ required: true, message: 'checkbox empty' }],
|
|
215
|
+
type: 'Checkbox',
|
|
216
|
+
props: {
|
|
217
|
+
style: { width: '100%' },
|
|
218
|
+
children: 'option'
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
]
|
|
220
222
|
|
|
221
223
|
const form = useSimpleForm();
|
|
222
224
|
// const formrender = useSimpleFormRender();
|
|
@@ -232,7 +234,7 @@ export default function Demo5(props) {
|
|
|
232
234
|
<FormRender
|
|
233
235
|
form={form}
|
|
234
236
|
// formrender={formrender}
|
|
235
|
-
|
|
237
|
+
widgetList={widgetList}
|
|
236
238
|
watch={watch} />
|
|
237
239
|
<div style={{ marginLeft: '120px' }}>
|
|
238
240
|
<Button onClick={onSubmit}>submit</Button>
|
|
@@ -252,25 +254,23 @@ import { FormChildren, Form, useSimpleForm } from './form-render';
|
|
|
252
254
|
import { Button } from 'antd';
|
|
253
255
|
export default function Demo(props) {
|
|
254
256
|
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
},
|
|
273
|
-
}
|
|
257
|
+
const widgetList1 = [{
|
|
258
|
+
label: "part1input",
|
|
259
|
+
name: 'part1',
|
|
260
|
+
rules: [{ required: true, message: 'part1 empty' }],
|
|
261
|
+
initialValue: 1,
|
|
262
|
+
type: 'Input',
|
|
263
|
+
props: {}
|
|
264
|
+
}]
|
|
265
|
+
|
|
266
|
+
const widgetList2 = [{
|
|
267
|
+
label: "part2input",
|
|
268
|
+
name: 'part2',
|
|
269
|
+
rules: [{ required: true, message: 'part2 empty' }],
|
|
270
|
+
initialValue: 1,
|
|
271
|
+
type: 'Input',
|
|
272
|
+
props: {}
|
|
273
|
+
}]
|
|
274
274
|
|
|
275
275
|
const form = useSimpleForm();
|
|
276
276
|
// const formrender1 = useSimpleFormRender()
|
|
@@ -289,14 +289,14 @@ export default function Demo(props) {
|
|
|
289
289
|
<p>part1</p>
|
|
290
290
|
<FormChildren
|
|
291
291
|
// formrender={formrender1}
|
|
292
|
-
|
|
292
|
+
widgetList={widgetList1}
|
|
293
293
|
/>
|
|
294
294
|
</div>
|
|
295
295
|
<div>
|
|
296
296
|
<p>part2</p>
|
|
297
297
|
<FormChildren
|
|
298
298
|
// formrender={formrender2}
|
|
299
|
-
|
|
299
|
+
widgetList={widgetList2}
|
|
300
300
|
/>
|
|
301
301
|
</div>
|
|
302
302
|
</Form>
|
|
@@ -315,32 +315,36 @@ import FormRender, { useSimpleForm } from './form-render';
|
|
|
315
315
|
import { Button } from 'antd';
|
|
316
316
|
export default function Demo(props) {
|
|
317
317
|
const form = useSimpleForm();
|
|
318
|
-
const
|
|
318
|
+
const widgetList =
|
|
319
319
|
[
|
|
320
320
|
{
|
|
321
321
|
label: "list-0",
|
|
322
|
-
|
|
322
|
+
name: 'list[0]',
|
|
323
|
+
rules: [{ required: true, message: 'list[0] empty' }],
|
|
323
324
|
initialValue: 1,
|
|
324
325
|
type: 'Input',
|
|
325
326
|
props: {}
|
|
326
327
|
},
|
|
327
328
|
{
|
|
328
329
|
label: "list-1",
|
|
329
|
-
|
|
330
|
+
name: 'list[1]',
|
|
331
|
+
rules: [{ required: true, message: 'list[1] empty' }],
|
|
330
332
|
initialValue: 2,
|
|
331
333
|
type: 'Input',
|
|
332
334
|
props: {}
|
|
333
335
|
},
|
|
334
336
|
{
|
|
335
337
|
label: "list-2",
|
|
336
|
-
|
|
338
|
+
name: 'list[2]',
|
|
339
|
+
rules: [{ required: true, message: 'list[2] empty' }],
|
|
337
340
|
initialValue: 3,
|
|
338
341
|
type: 'Input',
|
|
339
342
|
props: {}
|
|
340
343
|
},
|
|
341
344
|
{
|
|
342
345
|
label: "list-3",
|
|
343
|
-
|
|
346
|
+
name: 'list[3]',
|
|
347
|
+
rules: [{ required: true, message: 'list[3] empty' }],
|
|
344
348
|
initialValue: 4,
|
|
345
349
|
type: 'Input',
|
|
346
350
|
props: {}
|
|
@@ -357,7 +361,7 @@ export default function Demo(props) {
|
|
|
357
361
|
<div style={{ padding: '0 8px' }}>
|
|
358
362
|
<FormRender
|
|
359
363
|
form={form}
|
|
360
|
-
|
|
364
|
+
widgetList={widgetList}
|
|
361
365
|
/>
|
|
362
366
|
<div style={{ marginLeft: '120px' }}>
|
|
363
367
|
<Button onClick={onSubmit}>submit</Button>
|
|
@@ -373,26 +377,25 @@ export default function Demo(props) {
|
|
|
373
377
|
来源于[@simpleform/form](../form);
|
|
374
378
|
|
|
375
379
|
### FormChildren's props
|
|
376
|
-
- `
|
|
380
|
+
- `widgetList`: `WidgetItem[]` 渲染表单的DSL形式的json数据
|
|
377
381
|
- `components`:注册表单中的所有组件;
|
|
378
382
|
- `plugins`:表单中需要引入的外来库;
|
|
379
383
|
- `options`: `GenerateFormNodeProps | ((field: GenerateFormNodeProps) => any)` 传递给表单节点组件的参数信息. 优先级比表单节点自身的参数要低
|
|
380
384
|
- `renderList`:提供自定义渲染列表的函数.
|
|
381
385
|
- `renderItem`:提供自定义渲染节点的函数.
|
|
382
|
-
- `
|
|
386
|
+
- `onRenderChange`: `(newValue: WidgetList) => void;` `widgetList`更改时回调函数
|
|
383
387
|
- `formrender`: 负责渲染的表单类。通过`useSimpleFormRender()`创建,选填.
|
|
384
388
|
- `form`: 负责表单的值的类。通过`useSimpleForm()`创建,选填.
|
|
385
389
|
- `uneval`: 不执行表单中的字符串表达式.
|
|
386
390
|
|
|
387
391
|
### SimpleFormRender's Methods
|
|
388
|
-
- `updateItemByPath`: `(data?: any, path?: string
|
|
389
|
-
- `setItemByPath`: `(data?: any, path?: string
|
|
390
|
-
- `
|
|
391
|
-
- `
|
|
392
|
-
- `
|
|
393
|
-
- `getItemByPath`: `(path?: string, attributeName?: string) => void` 获取路径`path`对应的节点,如果是节点中的具体属性则需要`attributeName`参数
|
|
392
|
+
- `updateItemByPath`: `(data?: any, path?: string) => void` 根据`path`获取对应的节点
|
|
393
|
+
- `setItemByPath`: `(data?: any, path?: string) => void` 根据`path`设置对应的节点
|
|
394
|
+
- `delItemByPath`: `(path?: string) => void` 删除路径`path`对应的节点
|
|
395
|
+
- `insertItemByIndex`: `(data: WidgetItem | WidgetItem[], index?: number, parent?: string) => void` 根据序号和父节点路径添加节点
|
|
396
|
+
- `getItemByPath`: `(path?: string) => void` 获取路径`path`对应的节点
|
|
394
397
|
- `moveItemByPath`: `(from: { parent?: string, index: number }, to: { parent?: string, index?: number })` 把树中的选项从一个位置调换到另外一个位置
|
|
395
|
-
- `
|
|
398
|
+
- `setWidgetList`: `(data?: WidgetList) => void` 设置表单的`widgetList`属性;
|
|
396
399
|
|
|
397
400
|
### Hooks
|
|
398
401
|
- `useSimpleFormRender()`: 创建 `new SimpleFormRender()`.
|
|
@@ -400,66 +403,40 @@ export default function Demo(props) {
|
|
|
400
403
|
|
|
401
404
|
## 其他
|
|
402
405
|
|
|
403
|
-
###
|
|
404
|
-
`
|
|
405
|
-
-
|
|
406
|
-
|
|
407
|
-
- 控件节点:
|
|
408
|
-
无`properties`属性的节点,默认携带表单域组件(`Form.Item`)。
|
|
406
|
+
### widgetList结构说明
|
|
407
|
+
`widgetList`列表中每一项均为一个渲染节点, 分为表单控件节点和非控件节点
|
|
408
|
+
- 表单控件节点:
|
|
409
|
+
具有`name`属性的节点为表单控件节点,默认携带表单域组件(`Form.Item`),举例:
|
|
409
410
|
```javascript
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
label: 'first',
|
|
419
|
-
rules: [{ required: true, message: 'first empty' }],
|
|
420
|
-
type: 'Select',
|
|
421
|
-
props: {
|
|
422
|
-
style: { width: '100%' },
|
|
423
|
-
children: [{ type: 'Select.Option', props: { key: 1, value: '1', children: 'option1' } }]
|
|
424
|
-
}
|
|
425
|
-
},
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
}
|
|
411
|
+
const widgetList = [{
|
|
412
|
+
label: "part2input",
|
|
413
|
+
name: 'part2',
|
|
414
|
+
rules: [{ required: true, message: 'part2 empty' }],
|
|
415
|
+
initialValue: 1,
|
|
416
|
+
type: 'Input',
|
|
417
|
+
props: {}
|
|
418
|
+
}]
|
|
429
419
|
```
|
|
430
|
-
-
|
|
420
|
+
- 普通组件节点:
|
|
421
|
+
无`name`属性的节点。举例:
|
|
431
422
|
```javascript
|
|
432
|
-
|
|
433
|
-
type
|
|
434
|
-
props
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// 表单上的组件联合类型
|
|
444
|
-
export type CustomUnionType = FormComponent | Array<FormComponent> | UnionComponent<any> | Function | ReactNode
|
|
445
|
-
// 表单对象
|
|
446
|
-
export type PropertiesData = { [name: string]: FormNodeProps } | FormNodeProps[]
|
|
447
|
-
// 表单域(字符串表达式编译后)
|
|
448
|
-
export type GenerateFormNodeProps<T = {}> = FormComponent & FormItemProps & T & {
|
|
449
|
-
ignore?: boolean; // 标记当前节点为非表单节点
|
|
450
|
-
inside?: CustomUnionType; // 节点内层嵌套组件
|
|
451
|
-
outside?: CustomUnionType; // 节点外层嵌套组件
|
|
423
|
+
const widgetList = [{
|
|
424
|
+
type: 'CustomCard',
|
|
425
|
+
props: {}
|
|
426
|
+
}]
|
|
427
|
+
```
|
|
428
|
+
- 节点的属性
|
|
429
|
+
```javascript
|
|
430
|
+
export type GenerateWidgetItem<T extends Record<string, any> = {}> = FormItemProps & T & {
|
|
431
|
+
inside?: CustomUnionType; // 节点的内层
|
|
432
|
+
outside?: CustomUnionType; // 节点的外层
|
|
452
433
|
readOnly?: boolean; // 只读模式
|
|
453
|
-
readOnlyRender?: CustomUnionType; //
|
|
454
|
-
typeRender?: CustomUnionType; //
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
//
|
|
459
|
-
export type FormNodeProps = {
|
|
460
|
-
[key in keyof GenerateFormNodeProps]: key extends 'rules' ?
|
|
461
|
-
(string | Array<{ [key in keyof FormRule]: FormRule[key] | string }> | GenerateFormNodeProps[key])
|
|
462
|
-
: (key extends 'properties' ? GenerateFormNodeProps[key] : (string | GenerateFormNodeProps[key]))
|
|
434
|
+
readOnlyRender?: CustomUnionType; // 只读模式下的组件
|
|
435
|
+
typeRender?: CustomUnionType; // 自定义渲染实例
|
|
436
|
+
hidden?: boolean; // 隐藏节点
|
|
437
|
+
type?: string; // 注册组件
|
|
438
|
+
props?: Record<string, any> & { children?: any | Array<CustomWidget> }; // 注册组件的props
|
|
439
|
+
widgetList?: WidgetList; // 嵌套的子节点(会覆盖props.children)
|
|
463
440
|
}
|
|
464
441
|
```
|
|
465
442
|
|
|
@@ -482,10 +459,8 @@ export type FormNodeProps = {
|
|
|
482
459
|
表单中的注册组件会接收到上下文参数
|
|
483
460
|
```javascript
|
|
484
461
|
export interface GenerateParams<T = {}> {
|
|
485
|
-
name?: string;
|
|
486
462
|
path?: string;
|
|
487
|
-
|
|
488
|
-
parent?: { name?: string; path?: string, field?: GenerateFormNodeProps<T>; };
|
|
463
|
+
widgetItem?: GenerateWidgetItem<T>;
|
|
489
464
|
formrender?: SimpleFormRender;
|
|
490
465
|
form?: SimpleForm;
|
|
491
466
|
};
|
|
@@ -499,14 +474,15 @@ export interface GenerateParams<T = {}> {
|
|
|
499
474
|
- `a[0].b`表示数组a下面的第一个选项的b属性
|
|
500
475
|
|
|
501
476
|
### 字符串表达式用法
|
|
502
|
-
表单节点中属性字段除`
|
|
477
|
+
表单节点中属性字段除`widgetList`外均可以支持字符串表达式来进行联动
|
|
503
478
|
1. 快速使用:用`{{`和`}}`包裹目标属性值的计算表达式
|
|
504
479
|
```javascript
|
|
505
480
|
...
|
|
506
481
|
|
|
507
|
-
const
|
|
508
|
-
|
|
482
|
+
const widgetList = [
|
|
483
|
+
{
|
|
509
484
|
label: 'name1',
|
|
485
|
+
name: 'name1',
|
|
510
486
|
valueProp: 'checked',
|
|
511
487
|
initialValue: true,
|
|
512
488
|
type: 'Checkbox',
|
|
@@ -514,20 +490,22 @@ export interface GenerateParams<T = {}> {
|
|
|
514
490
|
children: 'option'
|
|
515
491
|
}
|
|
516
492
|
},
|
|
517
|
-
|
|
493
|
+
{
|
|
518
494
|
label: "name2",
|
|
495
|
+
name: 'name2',
|
|
519
496
|
rules: '{{[{ required: formvalues && formvalues.name1 === true, message: "name2 empty" }]}}',
|
|
520
497
|
initialValue: 1,
|
|
521
498
|
type: 'Input',
|
|
522
499
|
props: {}
|
|
523
|
-
}
|
|
524
|
-
|
|
500
|
+
}
|
|
501
|
+
]
|
|
525
502
|
|
|
526
503
|
// OR
|
|
527
504
|
|
|
528
|
-
const
|
|
529
|
-
|
|
505
|
+
const widgetList = [
|
|
506
|
+
{
|
|
530
507
|
label: 'name1',
|
|
508
|
+
name: 'name1',
|
|
531
509
|
valueProp: 'checked',
|
|
532
510
|
initialValue: true,
|
|
533
511
|
type: 'Checkbox',
|
|
@@ -535,14 +513,15 @@ export interface GenerateParams<T = {}> {
|
|
|
535
513
|
children: 'option'
|
|
536
514
|
}
|
|
537
515
|
},
|
|
538
|
-
|
|
516
|
+
{
|
|
539
517
|
label: "name2",
|
|
518
|
+
name: 'name2',
|
|
540
519
|
hidden: '{{formvalues && formvalues.name1 === true}}',
|
|
541
520
|
initialValue: 1,
|
|
542
521
|
type: 'Input',
|
|
543
522
|
props: {}
|
|
544
523
|
},
|
|
545
|
-
|
|
524
|
+
]
|
|
546
525
|
```
|
|
547
526
|
2. 字符串表达式的使用规则
|
|
548
527
|
- 一个字符串有且只能有一对`{{`和`}}`.
|
|
@@ -551,14 +530,12 @@ export interface GenerateParams<T = {}> {
|
|
|
551
530
|
import dayjs from 'dayjs';
|
|
552
531
|
import FormRender from "./form-render";
|
|
553
532
|
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
},
|
|
561
|
-
}
|
|
533
|
+
const widgetList = [{
|
|
534
|
+
label: "name3",
|
|
535
|
+
initialValue: "{{dayjs().format('YYYY-MM-DD')}}",
|
|
536
|
+
type: 'Input',
|
|
537
|
+
props: {}
|
|
538
|
+
}]
|
|
562
539
|
|
|
563
|
-
<FormRender
|
|
564
|
-
```
|
|
540
|
+
<FormRender widgetList={widgetList} plugins={{ dayjs }} />
|
|
541
|
+
```
|
package/lib/components/grid.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ColProps, RowProps } from "antd";
|
|
|
3
3
|
import { GenerateParams } from '../types';
|
|
4
4
|
import './grid.less';
|
|
5
5
|
export declare const getColProps: (props: ColProps, inline?: boolean) => {
|
|
6
|
-
flex?: (number | import("antd/es/_util/type").LiteralUnion<"
|
|
6
|
+
flex?: (number | import("antd/es/_util/type").LiteralUnion<"auto" | "none">) | undefined;
|
|
7
7
|
order?: (string | number) | undefined;
|
|
8
8
|
offset?: (string | number) | undefined;
|
|
9
9
|
push?: (string | number) | undefined;
|
|
@@ -18,7 +18,7 @@ export declare const getColProps: (props: ColProps, inline?: boolean) => {
|
|
|
18
18
|
accessKey?: string | undefined;
|
|
19
19
|
autoFocus?: boolean | undefined;
|
|
20
20
|
className?: string | undefined;
|
|
21
|
-
contentEditable?: (boolean | "true" | "false") | "
|
|
21
|
+
contentEditable?: "inherit" | (boolean | "true" | "false") | "plaintext-only" | undefined;
|
|
22
22
|
contextMenu?: string | undefined;
|
|
23
23
|
dir?: string | undefined;
|
|
24
24
|
draggable?: (boolean | "true" | "false") | undefined;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { SimpleFormRender } from './store';
|
|
3
|
-
import {
|
|
3
|
+
import { WidgetList } from './types';
|
|
4
4
|
export declare function useSimpleFormRender(): SimpleFormRender;
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function useWidgetList(formrender: SimpleFormRender): (WidgetList | import("react").Dispatch<import("react").SetStateAction<WidgetList | undefined>> | undefined)[];
|