@formily-design/formily-antd 1.0.0 → 1.0.2
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/package.json +8 -8
- package/.umirc.js +0 -44
- package/copy.ts +0 -6
- package/playground/components/AsyncSelect/AsyncSelect.tsx +0 -38
- package/playground/components/AsyncSelect/index.tsx +0 -1
- package/playground/components/AsyncSelect/preview.tsx +0 -36
- package/playground/components/ClickEventSetter/ActionConfigModal.tsx +0 -173
- package/playground/components/ClickEventSetter/ActionList.tsx +0 -67
- package/playground/components/ClickEventSetter/DownloadPanel.tsx +0 -24
- package/playground/components/ClickEventSetter/NavigationPanel.tsx +0 -42
- package/playground/components/ClickEventSetter/RequestPanel.tsx +0 -190
- package/playground/components/ClickEventSetter/index.tsx +0 -90
- package/playground/components/ClickEventSetter/styles.less +0 -89
- package/playground/components/ClickEventSetter/types.ts +0 -43
- package/playground/components/FormButton/FormButton.tsx +0 -189
- package/playground/components/FormButton/hooks/useEventActionExecutor.ts +0 -65
- package/playground/components/FormButton/index.ts +0 -1
- package/playground/components/FormButton/preview.tsx +0 -60
- package/playground/components/FormButton/utils/actionExecutors.ts +0 -96
- package/playground/components/FormButtonGroup/FormButtonGroup.tsx +0 -21
- package/playground/components/FormButtonGroup/index.ts +0 -1
- package/playground/components/FormButtonGroup/preview.tsx +0 -66
- package/playground/components/FormList/FormList.tsx +0 -164
- package/playground/components/FormList/index.tsx +0 -1
- package/playground/components/FormList/preview.tsx +0 -429
- package/playground/components/LocationPicker/LocationModal.tsx +0 -328
- package/playground/components/LocationPicker/LocationPicker.tsx +0 -163
- package/playground/components/LocationPicker/SearchBox.tsx +0 -122
- package/playground/components/LocationPicker/api.ts +0 -77
- package/playground/components/LocationPicker/constants.ts +0 -2
- package/playground/components/LocationPicker/index.tsx +0 -44
- package/playground/components/LocationPicker/types.ts +0 -160
- package/playground/components/LocationPicker/utils.ts +0 -46
- package/playground/components/ResourceIcon/index.module.less +0 -10
- package/playground/components/ResourceIcon/index.tsx +0 -10
- package/playground/designerLocales/en-US.ts +0 -38
- package/playground/designerLocales/index.ts +0 -6
- package/playground/designerLocales/ko-KR.ts +0 -10
- package/playground/designerLocales/zh-CN.ts +0 -38
- package/playground/locales/FormButton.ts +0 -38
- package/playground/locales/FormButtonGroup.ts +0 -29
- package/playground/locales/LocationPicker.ts +0 -30
- package/playground/locales/all.ts +0 -3
- package/playground/locales/index.ts +0 -3
- package/playground/main.tsx +0 -222
- package/playground/react-app-env.d.ts +0 -4
- package/playground/request.ts +0 -123
- package/playground/schemas/FormButton.ts +0 -42
- package/playground/schemas/FormButtonGroup.ts +0 -24
- package/playground/schemas/LocationPicker.ts +0 -14
- package/playground/schemas/all.ts +0 -3
- package/playground/schemas/index.ts +0 -3
- package/playground/service/index.ts +0 -1
- package/playground/service/schema.ts +0 -22
- package/playground/template.ejs +0 -20
- package/playground/utils.ts +0 -744
- package/playground/webpack.base.ts +0 -123
- package/playground/webpack.dev.ts +0 -64
- package/playground/webpack.prod.ts +0 -46
- package/playground/widgets/ActionsWidget.tsx +0 -58
- package/playground/widgets/LogoWidget.tsx +0 -20
- package/playground/widgets/MarkupSchemaWidget.tsx +0 -164
- package/playground/widgets/PreviewWidget.tsx +0 -188
- package/playground/widgets/SchemaEditorWidget.tsx +0 -27
- package/playground/widgets/index.ts +0 -5
- package/tsconfig.build.json +0 -12
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { FormButtonGroup as FormilyButtonGroup } from '@formily/antd-v5'
|
|
3
|
-
import { createBehavior, createResource } from '@formily-design/core'
|
|
4
|
-
import { DnFC } from '@formily-design/react'
|
|
5
|
-
import { CustomSchemas } from '../../schemas'
|
|
6
|
-
import { CustomLocales } from '../../locales'
|
|
7
|
-
|
|
8
|
-
export const FormButtonGroup: DnFC<
|
|
9
|
-
React.ComponentProps<typeof FormilyButtonGroup>
|
|
10
|
-
> = FormilyButtonGroup
|
|
11
|
-
|
|
12
|
-
FormButtonGroup.Behavior = createBehavior({
|
|
13
|
-
name: 'FormButtonGroup',
|
|
14
|
-
extends: ['Field'],
|
|
15
|
-
selector: (node) => node.props?.['x-component'] === 'FormButtonGroup',
|
|
16
|
-
designerProps: {
|
|
17
|
-
droppable: true,
|
|
18
|
-
propsSchema: {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
'x-component-props': CustomSchemas.FormButtonGroup,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
designerLocales: CustomLocales.FormButtonGroup,
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
FormButtonGroup.Resource = createResource({
|
|
29
|
-
icon: 'SelectSource',
|
|
30
|
-
elements: [
|
|
31
|
-
{
|
|
32
|
-
componentName: 'Field',
|
|
33
|
-
props: {
|
|
34
|
-
type: 'void',
|
|
35
|
-
title: 'FormButtonGroup',
|
|
36
|
-
'x-decorator': 'FormButtonGroup.FormItem',
|
|
37
|
-
'x-component': 'FormButtonGroup',
|
|
38
|
-
},
|
|
39
|
-
children: [
|
|
40
|
-
{
|
|
41
|
-
componentName: 'Field',
|
|
42
|
-
props: {
|
|
43
|
-
type: 'void',
|
|
44
|
-
'x-component': 'FormButton',
|
|
45
|
-
'x-component-props': {
|
|
46
|
-
title: '重置',
|
|
47
|
-
htmlType: 'reset',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
componentName: 'Field',
|
|
53
|
-
props: {
|
|
54
|
-
type: 'void',
|
|
55
|
-
'x-component': 'FormButton',
|
|
56
|
-
'x-component-props': {
|
|
57
|
-
title: '提交',
|
|
58
|
-
type: 'primary',
|
|
59
|
-
htmlType: 'submit',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
})
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Empty, Flex } from 'antd'
|
|
3
|
-
import { ArrayField } from '@formily/core'
|
|
4
|
-
import {
|
|
5
|
-
useField,
|
|
6
|
-
observer,
|
|
7
|
-
useFieldSchema,
|
|
8
|
-
RecursionField,
|
|
9
|
-
} from '@formily/react'
|
|
10
|
-
import cls from 'classnames'
|
|
11
|
-
import { ISchema } from '@formily/json-schema'
|
|
12
|
-
import { ArrayBase } from '@formily/antd-v5'
|
|
13
|
-
|
|
14
|
-
export interface FormListProps {
|
|
15
|
-
title?: string
|
|
16
|
-
className?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type ComposedFormList = React.FC<React.PropsWithChildren<FormListProps>>
|
|
20
|
-
|
|
21
|
-
const isAdditionComponent = (schema: ISchema) => {
|
|
22
|
-
return schema['x-component']?.indexOf('Addition') > -1
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const isIndexComponent = (schema: ISchema) => {
|
|
26
|
-
return schema['x-component']?.indexOf?.('Index') > -1
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const isRemoveComponent = (schema: ISchema) => {
|
|
30
|
-
return schema['x-component']?.indexOf?.('Remove') > -1
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const isCopyComponent = (schema: ISchema) => {
|
|
34
|
-
return schema['x-component']?.indexOf?.('Copy') > -1
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isMoveUpComponent = (schema: ISchema) => {
|
|
38
|
-
return schema['x-component']?.indexOf?.('MoveUp') > -1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const isMoveDownComponent = (schema: ISchema) => {
|
|
42
|
-
return schema['x-component']?.indexOf?.('MoveDown') > -1
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const isOperationComponent = (schema: ISchema) => {
|
|
46
|
-
return (
|
|
47
|
-
isAdditionComponent(schema) ||
|
|
48
|
-
isRemoveComponent(schema) ||
|
|
49
|
-
isCopyComponent(schema) ||
|
|
50
|
-
isMoveDownComponent(schema) ||
|
|
51
|
-
isMoveUpComponent(schema)
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const InternalFormList: ComposedFormList = observer((props) => {
|
|
56
|
-
const field = useField<ArrayField>()
|
|
57
|
-
const schema = useFieldSchema()
|
|
58
|
-
const dataSource = Array.isArray(field.value) ? field.value : []
|
|
59
|
-
const prefixCls = 'formily-array-cards'
|
|
60
|
-
|
|
61
|
-
if (!schema) throw new Error('can not found schema object')
|
|
62
|
-
|
|
63
|
-
const renderItems = () => {
|
|
64
|
-
return dataSource?.map((item, index) => {
|
|
65
|
-
const items = Array.isArray(schema.items)
|
|
66
|
-
? schema.items[index] || schema.items[0]
|
|
67
|
-
: schema.items
|
|
68
|
-
// const title = (
|
|
69
|
-
// <span>
|
|
70
|
-
// <RecursionField
|
|
71
|
-
// schema={items}
|
|
72
|
-
// name={index}
|
|
73
|
-
// filterProperties={(schema) => {
|
|
74
|
-
// if (!isIndexComponent(schema)) return false
|
|
75
|
-
// return true
|
|
76
|
-
// }}
|
|
77
|
-
// onlyRenderProperties
|
|
78
|
-
// />
|
|
79
|
-
// {props.title || field.title}
|
|
80
|
-
// </span>
|
|
81
|
-
// )
|
|
82
|
-
// const extra = (
|
|
83
|
-
// <span>
|
|
84
|
-
// <RecursionField
|
|
85
|
-
// schema={items}
|
|
86
|
-
// name={index}
|
|
87
|
-
// filterProperties={(schema) => {
|
|
88
|
-
// if (!isOperationComponent(schema)) return false
|
|
89
|
-
// return true
|
|
90
|
-
// }}
|
|
91
|
-
// onlyRenderProperties
|
|
92
|
-
// />
|
|
93
|
-
// {props.extra}
|
|
94
|
-
// </span>
|
|
95
|
-
// )
|
|
96
|
-
const content = items ? (
|
|
97
|
-
<RecursionField
|
|
98
|
-
schema={items}
|
|
99
|
-
name={index}
|
|
100
|
-
filterProperties={(schema) => {
|
|
101
|
-
if (isIndexComponent(schema)) return false
|
|
102
|
-
if (isOperationComponent(schema)) return false
|
|
103
|
-
return true
|
|
104
|
-
}}
|
|
105
|
-
/>
|
|
106
|
-
) : null
|
|
107
|
-
const operations = items ? (
|
|
108
|
-
<RecursionField
|
|
109
|
-
schema={items}
|
|
110
|
-
name={index}
|
|
111
|
-
filterProperties={(schema) => {
|
|
112
|
-
if (!isOperationComponent(schema)) return false
|
|
113
|
-
return true
|
|
114
|
-
}}
|
|
115
|
-
onlyRenderProperties
|
|
116
|
-
/>
|
|
117
|
-
) : null
|
|
118
|
-
return (
|
|
119
|
-
<ArrayBase.Item
|
|
120
|
-
key={index}
|
|
121
|
-
index={index}
|
|
122
|
-
record={() => field.value?.[index]}
|
|
123
|
-
>
|
|
124
|
-
<Flex gap={8}>
|
|
125
|
-
<div style={{ flex: 1 }}>{content}</div>
|
|
126
|
-
<div>{operations}</div>
|
|
127
|
-
</Flex>
|
|
128
|
-
</ArrayBase.Item>
|
|
129
|
-
)
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const renderAddition = () => {
|
|
134
|
-
return schema.reduceProperties((addition, schema, key) => {
|
|
135
|
-
if (isAdditionComponent(schema)) {
|
|
136
|
-
return <RecursionField schema={schema} name={key} />
|
|
137
|
-
}
|
|
138
|
-
return addition
|
|
139
|
-
}, null)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const renderEmpty = () => {
|
|
143
|
-
if (dataSource?.length) return
|
|
144
|
-
return (
|
|
145
|
-
<div className={cls(`${prefixCls}-item`, props.className)}>
|
|
146
|
-
<Empty />
|
|
147
|
-
</div>
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<ArrayBase>
|
|
153
|
-
{renderEmpty()}
|
|
154
|
-
{renderItems()}
|
|
155
|
-
{renderAddition()}
|
|
156
|
-
</ArrayBase>
|
|
157
|
-
)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
InternalFormList.displayName = 'FormList'
|
|
161
|
-
|
|
162
|
-
export const FormList = ArrayBase.mixin(InternalFormList)
|
|
163
|
-
|
|
164
|
-
export default FormList
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { FormList } from './preview'
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Flex } from 'antd'
|
|
3
|
-
import {
|
|
4
|
-
ITreeNode,
|
|
5
|
-
TreeNode,
|
|
6
|
-
createBehavior,
|
|
7
|
-
createResource,
|
|
8
|
-
} from '@formily-design/core'
|
|
9
|
-
import {
|
|
10
|
-
useTreeNode,
|
|
11
|
-
TreeNodeWidget,
|
|
12
|
-
DroppableWidget,
|
|
13
|
-
useNodeIdProps,
|
|
14
|
-
DnFC,
|
|
15
|
-
} from '@formily-design/react'
|
|
16
|
-
import { ArrayBase } from '@formily/antd-v5'
|
|
17
|
-
import { ISchema, observer } from '@formily/react'
|
|
18
|
-
import cls from 'classnames'
|
|
19
|
-
import {
|
|
20
|
-
createEnsureTypeItemsNode,
|
|
21
|
-
createNodeId,
|
|
22
|
-
findNodeByComponentPath,
|
|
23
|
-
queryNodesByComponentPath,
|
|
24
|
-
} from '../../../src/shared'
|
|
25
|
-
import { useDropTemplate } from '../../../src/hooks'
|
|
26
|
-
import { LoadTemplate } from '../../../src/common/LoadTemplate'
|
|
27
|
-
import {
|
|
28
|
-
AllLocales,
|
|
29
|
-
createFieldSchema,
|
|
30
|
-
createVoidFieldSchema,
|
|
31
|
-
} from '@formily-design/formily-antd'
|
|
32
|
-
import { FormListProps } from './FormList'
|
|
33
|
-
|
|
34
|
-
const ensureObjectItemsNode = createEnsureTypeItemsNode('object')
|
|
35
|
-
|
|
36
|
-
const isFormListOperation = (name: string) =>
|
|
37
|
-
name === 'FormList.Remove' ||
|
|
38
|
-
name === 'FormList.MoveDown' ||
|
|
39
|
-
name === 'FormList.MoveUp'
|
|
40
|
-
|
|
41
|
-
// const isOperationsComponent = (schema: Schema) => {
|
|
42
|
-
// return schema['x-component']?.indexOf('Operations') > -1
|
|
43
|
-
// }
|
|
44
|
-
|
|
45
|
-
// const isAdditionComponent = (schema: Schema) => {
|
|
46
|
-
// return schema['x-component']?.indexOf('Addition') > -1
|
|
47
|
-
// }
|
|
48
|
-
// const useAddition = () => {
|
|
49
|
-
// const schema = useFieldSchema()
|
|
50
|
-
// return schema?.reduceProperties((addition, schema, key) => {
|
|
51
|
-
// if (isAdditionComponent(schema)) {
|
|
52
|
-
// return <RecursionField schema={schema} name={key} />
|
|
53
|
-
// }
|
|
54
|
-
// return addition
|
|
55
|
-
// }, null)
|
|
56
|
-
// }
|
|
57
|
-
|
|
58
|
-
const FormListSchemas: ISchema & { Addition: ISchema } = {
|
|
59
|
-
type: 'array',
|
|
60
|
-
properties: {
|
|
61
|
-
size: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
enum: ['large', 'small', 'middle'],
|
|
64
|
-
'x-decorator': 'FormItem',
|
|
65
|
-
'x-component': 'Select',
|
|
66
|
-
'x-component-props': {
|
|
67
|
-
defaultValue: 'small',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
Addition: {
|
|
72
|
-
type: 'object',
|
|
73
|
-
properties: {
|
|
74
|
-
method: {
|
|
75
|
-
type: 'string',
|
|
76
|
-
enum: ['push', 'unshift'],
|
|
77
|
-
'x-decorator': 'FormItem',
|
|
78
|
-
'x-component': 'Radio.Group',
|
|
79
|
-
'x-component-props': {
|
|
80
|
-
defaultValue: 'push',
|
|
81
|
-
optionType: 'button',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
defaultValue: {
|
|
85
|
-
type: 'string',
|
|
86
|
-
'x-decorator': 'FormItem',
|
|
87
|
-
'x-component': 'ValueInput',
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
const FormListLocales = {
|
|
93
|
-
'zh-CN': {
|
|
94
|
-
title: '自增表单列表',
|
|
95
|
-
addIndex: '添加索引',
|
|
96
|
-
addOperation: '添加操作',
|
|
97
|
-
settings: {
|
|
98
|
-
'x-component-props': {
|
|
99
|
-
size: '大小',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
'en-US': {
|
|
104
|
-
title: 'Form List',
|
|
105
|
-
addIndex: 'Add Index',
|
|
106
|
-
addOperation: 'Add Operation',
|
|
107
|
-
settings: {
|
|
108
|
-
'x-component-props': {
|
|
109
|
-
size: 'Size',
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
}
|
|
114
|
-
const createArrayBehavior = (name: string) => {
|
|
115
|
-
return createBehavior(
|
|
116
|
-
{
|
|
117
|
-
name,
|
|
118
|
-
extends: ['Field'],
|
|
119
|
-
selector: (node) => node.props?.['x-component'] === name,
|
|
120
|
-
designerProps: {
|
|
121
|
-
droppable: true,
|
|
122
|
-
propsSchema: createFieldSchema(FormListSchemas),
|
|
123
|
-
},
|
|
124
|
-
designerLocales: FormListLocales,
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: `${name}.Addition`,
|
|
128
|
-
extends: ['Field'],
|
|
129
|
-
selector: (node) => node.props?.['x-component'] === `${name}.Addition`,
|
|
130
|
-
designerProps: {
|
|
131
|
-
allowDrop(parent) {
|
|
132
|
-
return parent.props?.['x-component'] === name
|
|
133
|
-
},
|
|
134
|
-
/** 不允许拖拽 */
|
|
135
|
-
draggable: false,
|
|
136
|
-
propsSchema: createVoidFieldSchema(FormListSchemas.Addition),
|
|
137
|
-
},
|
|
138
|
-
designerLocales: AllLocales.ArrayAddition,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: `${name}.Remove`,
|
|
142
|
-
extends: ['Field'],
|
|
143
|
-
selector: (node) => node.props?.['x-component'] === `${name}.Remove`,
|
|
144
|
-
designerProps: {
|
|
145
|
-
allowDrop(parent) {
|
|
146
|
-
return parent.props?.['x-component'] === name
|
|
147
|
-
},
|
|
148
|
-
draggable: false,
|
|
149
|
-
propsSchema: createVoidFieldSchema(),
|
|
150
|
-
},
|
|
151
|
-
designerLocales: AllLocales.ArrayRemove,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
name: `${name}.Index`,
|
|
155
|
-
extends: ['Field'],
|
|
156
|
-
selector: (node) => node.props?.['x-component'] === `${name}.Index`,
|
|
157
|
-
designerProps: {
|
|
158
|
-
allowDrop(parent) {
|
|
159
|
-
return parent.props?.['x-component'] === name
|
|
160
|
-
},
|
|
161
|
-
propsSchema: createVoidFieldSchema(),
|
|
162
|
-
},
|
|
163
|
-
designerLocales: AllLocales.ArrayIndex,
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: `${name}.MoveUp`,
|
|
167
|
-
extends: ['Field'],
|
|
168
|
-
selector: (node) => node.props?.['x-component'] === `${name}.MoveUp`,
|
|
169
|
-
designerProps: {
|
|
170
|
-
allowDrop(parent) {
|
|
171
|
-
return parent.props?.['x-component'] === name
|
|
172
|
-
},
|
|
173
|
-
draggable: false,
|
|
174
|
-
propsSchema: createVoidFieldSchema(),
|
|
175
|
-
},
|
|
176
|
-
designerLocales: AllLocales.ArrayMoveUp,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
name: `${name}.MoveDown`,
|
|
180
|
-
extends: ['Field'],
|
|
181
|
-
selector: (node) => node.props?.['x-component'] === `${name}.MoveDown`,
|
|
182
|
-
designerProps: {
|
|
183
|
-
allowDrop(parent) {
|
|
184
|
-
return parent.props?.['x-component'] === 'ArrayCards'
|
|
185
|
-
},
|
|
186
|
-
draggable: false,
|
|
187
|
-
propsSchema: createVoidFieldSchema(),
|
|
188
|
-
},
|
|
189
|
-
designerLocales: AllLocales.ArrayMoveDown,
|
|
190
|
-
}
|
|
191
|
-
)
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** 创建添加节点 */
|
|
195
|
-
function createAdditionNode(node: ITreeNode) {
|
|
196
|
-
return new TreeNode({
|
|
197
|
-
componentName: node.componentName,
|
|
198
|
-
props: {
|
|
199
|
-
type: 'void',
|
|
200
|
-
title: '新增一项',
|
|
201
|
-
'x-component': 'FormList.Addition',
|
|
202
|
-
},
|
|
203
|
-
})
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export const FormList: DnFC<FormListProps> = observer(({ title, ...props }) => {
|
|
207
|
-
const node = useTreeNode()
|
|
208
|
-
const nodeId = useNodeIdProps()
|
|
209
|
-
const designer = useDropTemplate('FormList', (source) => {
|
|
210
|
-
const indexNode = new TreeNode({
|
|
211
|
-
componentName: node.componentName,
|
|
212
|
-
props: {
|
|
213
|
-
type: 'void',
|
|
214
|
-
'x-component': 'FormList.Index',
|
|
215
|
-
},
|
|
216
|
-
})
|
|
217
|
-
const additionNode = createAdditionNode(node)
|
|
218
|
-
const removeNode = new TreeNode({
|
|
219
|
-
componentName: node.componentName,
|
|
220
|
-
props: {
|
|
221
|
-
type: 'void',
|
|
222
|
-
// title: 'Addition',
|
|
223
|
-
'x-component': 'FormList.Remove',
|
|
224
|
-
},
|
|
225
|
-
})
|
|
226
|
-
const moveDownNode = new TreeNode({
|
|
227
|
-
componentName: node.componentName,
|
|
228
|
-
props: {
|
|
229
|
-
type: 'void',
|
|
230
|
-
// title: 'Addition',
|
|
231
|
-
'x-component': 'FormList.MoveDown',
|
|
232
|
-
},
|
|
233
|
-
})
|
|
234
|
-
const moveUpNode = new TreeNode({
|
|
235
|
-
componentName: node.componentName,
|
|
236
|
-
props: {
|
|
237
|
-
type: 'void',
|
|
238
|
-
// title: 'Addition',
|
|
239
|
-
'x-component': 'FormList.MoveUp',
|
|
240
|
-
},
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
const objectNode = new TreeNode({
|
|
244
|
-
componentName: node.componentName,
|
|
245
|
-
props: {
|
|
246
|
-
type: 'object',
|
|
247
|
-
},
|
|
248
|
-
children: [indexNode, ...source, removeNode, moveDownNode, moveUpNode],
|
|
249
|
-
})
|
|
250
|
-
return [objectNode, additionNode]
|
|
251
|
-
})
|
|
252
|
-
const renderFormList = () => {
|
|
253
|
-
if (node.children.length === 0) return <DroppableWidget />
|
|
254
|
-
const additions = queryNodesByComponentPath(node, [
|
|
255
|
-
'FormList',
|
|
256
|
-
'FormList.Addition',
|
|
257
|
-
])
|
|
258
|
-
// const indexes = queryNodesByComponentPath(node, [
|
|
259
|
-
// 'FormList',
|
|
260
|
-
// '*',
|
|
261
|
-
// 'FormList.Index',
|
|
262
|
-
// ])
|
|
263
|
-
const operations = queryNodesByComponentPath(node, [
|
|
264
|
-
'FormList',
|
|
265
|
-
'*',
|
|
266
|
-
isFormListOperation,
|
|
267
|
-
])
|
|
268
|
-
const children = queryNodesByComponentPath(node, [
|
|
269
|
-
'FormList',
|
|
270
|
-
'*',
|
|
271
|
-
(name) => !name.includes('FormList.'),
|
|
272
|
-
])
|
|
273
|
-
return (
|
|
274
|
-
<ArrayBase disabled>
|
|
275
|
-
<ArrayBase.Item index={0} record={{}}>
|
|
276
|
-
<div
|
|
277
|
-
{...props}
|
|
278
|
-
className={cls('ant-formily-array-form-list-item', props.className)}
|
|
279
|
-
>
|
|
280
|
-
<div>
|
|
281
|
-
<span data-content-editable="x-component-props.title">
|
|
282
|
-
{title}
|
|
283
|
-
</span>
|
|
284
|
-
</div>
|
|
285
|
-
<div {...createNodeId(designer, ensureObjectItemsNode(node).id)}>
|
|
286
|
-
{children.length ? (
|
|
287
|
-
children.map((node) => (
|
|
288
|
-
<Flex gap={8} key={node.id}>
|
|
289
|
-
<div style={{ flex: 1 }}>
|
|
290
|
-
<TreeNodeWidget key={node.id} node={node} />
|
|
291
|
-
</div>
|
|
292
|
-
<div>
|
|
293
|
-
{operations.map((node) => (
|
|
294
|
-
<TreeNodeWidget key={node.id} node={node} />
|
|
295
|
-
))}
|
|
296
|
-
</div>
|
|
297
|
-
</Flex>
|
|
298
|
-
))
|
|
299
|
-
) : (
|
|
300
|
-
<DroppableWidget hasChildren={false} />
|
|
301
|
-
)}
|
|
302
|
-
</div>
|
|
303
|
-
</div>
|
|
304
|
-
</ArrayBase.Item>
|
|
305
|
-
{additions.map((node) => (
|
|
306
|
-
<TreeNodeWidget key={node.id} node={node} />
|
|
307
|
-
))}
|
|
308
|
-
</ArrayBase>
|
|
309
|
-
)
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return (
|
|
313
|
-
<div {...nodeId} className="dn-array-form-list">
|
|
314
|
-
{renderFormList()}
|
|
315
|
-
<LoadTemplate
|
|
316
|
-
actions={[
|
|
317
|
-
/** 添加索引 */
|
|
318
|
-
// {
|
|
319
|
-
// title: node.getMessage('addIndex'),
|
|
320
|
-
// icon: 'AddIndex',
|
|
321
|
-
// onClick: () => {
|
|
322
|
-
// if (
|
|
323
|
-
// hasNodeByComponentPath(node, [
|
|
324
|
-
// 'FormList',
|
|
325
|
-
// '*',
|
|
326
|
-
// 'FormList.Index',
|
|
327
|
-
// ])
|
|
328
|
-
// )
|
|
329
|
-
// return
|
|
330
|
-
// const indexNode = new TreeNode({
|
|
331
|
-
// componentName: node.componentName,
|
|
332
|
-
// props: {
|
|
333
|
-
// type: 'void',
|
|
334
|
-
// 'x-component': 'FormList.Index',
|
|
335
|
-
// },
|
|
336
|
-
// })
|
|
337
|
-
// ensureObjectItemsNode(node).append(indexNode)
|
|
338
|
-
// },
|
|
339
|
-
// },
|
|
340
|
-
/** 添加操作 */
|
|
341
|
-
{
|
|
342
|
-
title: node.getMessage('addOperation'),
|
|
343
|
-
icon: 'AddOperation',
|
|
344
|
-
onClick: () => {
|
|
345
|
-
const oldAdditionNode = findNodeByComponentPath(node, [
|
|
346
|
-
'FormList',
|
|
347
|
-
'FormList.Addition',
|
|
348
|
-
])
|
|
349
|
-
/** 不存在,才添加 */
|
|
350
|
-
if (!oldAdditionNode) {
|
|
351
|
-
const additionNode = createAdditionNode(node)
|
|
352
|
-
ensureObjectItemsNode(node).insertAfter(additionNode)
|
|
353
|
-
}
|
|
354
|
-
const oldRemoveNode = findNodeByComponentPath(node, [
|
|
355
|
-
'FormList',
|
|
356
|
-
'*',
|
|
357
|
-
'FormList.Remove',
|
|
358
|
-
])
|
|
359
|
-
const oldMoveDownNode = findNodeByComponentPath(node, [
|
|
360
|
-
'FormList',
|
|
361
|
-
'*',
|
|
362
|
-
'FormList.MoveDown',
|
|
363
|
-
])
|
|
364
|
-
const oldMoveUpNode = findNodeByComponentPath(node, [
|
|
365
|
-
'FormList',
|
|
366
|
-
'*',
|
|
367
|
-
'FormList.MoveUp',
|
|
368
|
-
])
|
|
369
|
-
if (!oldRemoveNode) {
|
|
370
|
-
ensureObjectItemsNode(node).append(
|
|
371
|
-
new TreeNode({
|
|
372
|
-
componentName: node.componentName,
|
|
373
|
-
props: {
|
|
374
|
-
type: 'void',
|
|
375
|
-
'x-component': 'FormList.Remove',
|
|
376
|
-
},
|
|
377
|
-
})
|
|
378
|
-
)
|
|
379
|
-
}
|
|
380
|
-
if (!oldMoveDownNode) {
|
|
381
|
-
ensureObjectItemsNode(node).append(
|
|
382
|
-
new TreeNode({
|
|
383
|
-
componentName: node.componentName,
|
|
384
|
-
props: {
|
|
385
|
-
type: 'void',
|
|
386
|
-
'x-component': 'FormList.MoveDown',
|
|
387
|
-
},
|
|
388
|
-
})
|
|
389
|
-
)
|
|
390
|
-
}
|
|
391
|
-
if (!oldMoveUpNode) {
|
|
392
|
-
ensureObjectItemsNode(node).append(
|
|
393
|
-
new TreeNode({
|
|
394
|
-
componentName: node.componentName,
|
|
395
|
-
props: {
|
|
396
|
-
type: 'void',
|
|
397
|
-
'x-component': 'FormList.MoveUp',
|
|
398
|
-
},
|
|
399
|
-
})
|
|
400
|
-
)
|
|
401
|
-
}
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
]}
|
|
405
|
-
/>
|
|
406
|
-
</div>
|
|
407
|
-
)
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
ArrayBase.mixin(FormList)
|
|
411
|
-
|
|
412
|
-
FormList.Behavior = createArrayBehavior('FormList')
|
|
413
|
-
|
|
414
|
-
FormList.Resource = createResource({
|
|
415
|
-
icon: 'ArrayCardsSource',
|
|
416
|
-
elements: [
|
|
417
|
-
{
|
|
418
|
-
componentName: 'Field',
|
|
419
|
-
props: {
|
|
420
|
-
type: 'array',
|
|
421
|
-
'x-decorator': 'FormItem',
|
|
422
|
-
'x-component': 'FormList',
|
|
423
|
-
'x-component-props': {
|
|
424
|
-
title: `Title`,
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
],
|
|
429
|
-
})
|