@thienvu18/designable-formily-setters 2.0.1 → 2.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/esm/components/DataSourceSetter/DataSettingPanel.d.ts +8 -8
- package/esm/components/DataSourceSetter/DataSettingPanel.js +124 -52
- package/esm/components/DataSourceSetter/Header.d.ts +5 -5
- package/esm/components/DataSourceSetter/Header.js +16 -7
- package/esm/components/DataSourceSetter/Title.d.ts +5 -5
- package/esm/components/DataSourceSetter/Title.js +57 -44
- package/esm/components/DataSourceSetter/TreePanel.d.ts +10 -10
- package/esm/components/DataSourceSetter/TreePanel.js +129 -89
- package/esm/components/DataSourceSetter/index.d.ts +16 -16
- package/esm/components/DataSourceSetter/index.js +81 -24
- package/esm/components/DataSourceSetter/shared.d.ts +14 -7
- package/esm/components/DataSourceSetter/shared.js +39 -41
- package/esm/components/DataSourceSetter/styles.less +4 -3
- package/esm/components/DataSourceSetter/types.d.ts +12 -12
- package/esm/components/DataSourceSetter/types.js +1 -1
- package/esm/components/ReactionsSetter/FieldPropertySetter.d.ts +6 -6
- package/esm/components/ReactionsSetter/FieldPropertySetter.js +140 -63
- package/esm/components/ReactionsSetter/PathSelector.d.ts +10 -9
- package/esm/components/ReactionsSetter/PathSelector.js +97 -100
- package/esm/components/ReactionsSetter/declarations.d.ts +3 -3
- package/esm/components/ReactionsSetter/declarations.js +31 -18
- package/esm/components/ReactionsSetter/helpers.d.ts +20 -10
- package/esm/components/ReactionsSetter/helpers.js +10 -10
- package/esm/components/ReactionsSetter/index.d.ts +6 -6
- package/esm/components/ReactionsSetter/index.js +412 -230
- package/esm/components/ReactionsSetter/properties.d.ts +14 -11
- package/esm/components/ReactionsSetter/properties.js +49 -40
- package/esm/components/ReactionsSetter/styles.less +2 -2
- package/esm/components/ReactionsSetter/types.d.ts +11 -11
- package/esm/components/ReactionsSetter/types.js +1 -1
- package/esm/components/ValidatorSetter/index.d.ts +4 -4
- package/esm/components/ValidatorSetter/index.js +148 -125
- package/esm/components/index.d.ts +3 -3
- package/esm/components/index.js +3 -3
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/locales/en-US.d.ts +92 -92
- package/esm/locales/en-US.js +96 -93
- package/esm/locales/index.d.ts +1 -1
- package/esm/locales/index.js +5 -5
- package/esm/locales/ko-KR.d.ts +92 -92
- package/esm/locales/ko-KR.js +94 -93
- package/esm/locales/zh-CN.d.ts +92 -92
- package/esm/locales/zh-CN.js +94 -93
- package/lib/components/DataSourceSetter/DataSettingPanel.d.ts +8 -8
- package/lib/components/DataSourceSetter/DataSettingPanel.js +129 -55
- package/lib/components/DataSourceSetter/Header.d.ts +5 -5
- package/lib/components/DataSourceSetter/Header.js +19 -10
- package/lib/components/DataSourceSetter/Title.d.ts +5 -5
- package/lib/components/DataSourceSetter/Title.js +70 -47
- package/lib/components/DataSourceSetter/TreePanel.d.ts +10 -10
- package/lib/components/DataSourceSetter/TreePanel.js +134 -92
- package/lib/components/DataSourceSetter/index.d.ts +16 -16
- package/lib/components/DataSourceSetter/index.js +94 -30
- package/lib/components/DataSourceSetter/shared.d.ts +14 -7
- package/lib/components/DataSourceSetter/shared.js +48 -47
- package/lib/components/DataSourceSetter/styles.less +4 -3
- package/lib/components/DataSourceSetter/types.d.ts +12 -12
- package/lib/components/DataSourceSetter/types.js +2 -2
- package/lib/components/ReactionsSetter/FieldPropertySetter.d.ts +6 -6
- package/lib/components/ReactionsSetter/FieldPropertySetter.js +150 -67
- package/lib/components/ReactionsSetter/PathSelector.d.ts +10 -9
- package/lib/components/ReactionsSetter/PathSelector.js +101 -104
- package/lib/components/ReactionsSetter/declarations.d.ts +3 -3
- package/lib/components/ReactionsSetter/declarations.js +35 -22
- package/lib/components/ReactionsSetter/helpers.d.ts +20 -10
- package/lib/components/ReactionsSetter/helpers.js +23 -13
- package/lib/components/ReactionsSetter/index.d.ts +6 -6
- package/lib/components/ReactionsSetter/index.js +434 -234
- package/lib/components/ReactionsSetter/properties.d.ts +14 -11
- package/lib/components/ReactionsSetter/properties.js +43 -43
- package/lib/components/ReactionsSetter/styles.less +2 -2
- package/lib/components/ReactionsSetter/types.d.ts +11 -11
- package/lib/components/ReactionsSetter/types.js +2 -2
- package/lib/components/ValidatorSetter/index.d.ts +4 -4
- package/lib/components/ValidatorSetter/index.js +151 -128
- package/lib/components/index.d.ts +3 -3
- package/lib/components/index.js +35 -19
- package/lib/index.d.ts +2 -2
- package/lib/index.js +34 -18
- package/lib/locales/en-US.d.ts +92 -92
- package/lib/locales/en-US.js +98 -95
- package/lib/locales/index.d.ts +1 -1
- package/lib/locales/index.js +16 -10
- package/lib/locales/ko-KR.d.ts +92 -92
- package/lib/locales/ko-KR.js +96 -95
- package/lib/locales/zh-CN.d.ts +92 -92
- package/lib/locales/zh-CN.js +96 -95
- package/package.json +5 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import './
|
|
1
|
+
import { Form as FormCore } from '@formily/core'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import './styles.less'
|
|
4
|
+
import { ITreeDataSource } from './types'
|
|
5
5
|
export interface IDataSettingPanelProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
treeDataSource: ITreeDataSource
|
|
7
|
+
allowExtendOption?: boolean
|
|
8
|
+
effects?: (form: FormCore<any>) => void
|
|
9
9
|
}
|
|
10
|
-
export declare const DataSettingPanel: React.FC<IDataSettingPanelProps
|
|
10
|
+
export declare const DataSettingPanel: React.FC<IDataSettingPanelProps>
|
|
@@ -1,54 +1,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { Header } from './Header'
|
|
12
|
-
import { traverseTree } from './shared'
|
|
13
|
-
import './styles.less'
|
|
1
|
+
import { PlusOutlined } from '@ant-design/icons'
|
|
2
|
+
import { createForm } from '@formily/core'
|
|
3
|
+
import { createSchemaField } from '@formily/react'
|
|
4
|
+
import { observer } from '@formily/reactive-react'
|
|
5
|
+
import { TextWidget, usePrefix } from '@thienvu18/designable-react'
|
|
6
|
+
import { ValueInput } from '@thienvu18/designable-react-settings-form'
|
|
7
|
+
import { ArrayItems, Form, FormItem, Input } from '@thienvu18/formily-antd-v6'
|
|
8
|
+
import { Button } from 'antd'
|
|
9
|
+
import { Fragment, useMemo } from 'react'
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime'
|
|
11
|
+
import { Header } from './Header'
|
|
12
|
+
import { traverseTree } from './shared'
|
|
13
|
+
import './styles.less'
|
|
14
14
|
const SchemaField = createSchemaField({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
15
|
+
components: {
|
|
16
|
+
FormItem,
|
|
17
|
+
Input,
|
|
18
|
+
ArrayItems,
|
|
19
|
+
ValueInput,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
22
|
export const DataSettingPanel = observer((props) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
23
|
+
const { allowExtendOption, effects } = props
|
|
24
|
+
const prefix = usePrefix('data-source-setter')
|
|
25
|
+
const form = useMemo(() => {
|
|
26
|
+
let values
|
|
27
|
+
traverseTree(props.treeDataSource.dataSource, (dataItem) => {
|
|
28
|
+
if (dataItem.key === props.treeDataSource.selectedKey) {
|
|
29
|
+
values = dataItem
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
return createForm({
|
|
33
|
+
values,
|
|
34
|
+
effects: effects,
|
|
35
|
+
})
|
|
36
|
+
}, [props.treeDataSource.selectedKey, props.treeDataSource.dataSource.length])
|
|
37
|
+
if (!props.treeDataSource.selectedKey)
|
|
38
|
+
return _jsxs(Fragment, {
|
|
39
|
+
children: [
|
|
40
|
+
_jsx(Header, {
|
|
41
|
+
title: _jsx(TextWidget, {
|
|
42
|
+
token: 'SettingComponents.DataSourceSetter.nodeProperty',
|
|
43
|
+
}),
|
|
44
|
+
extra: null,
|
|
45
|
+
}),
|
|
46
|
+
_jsx('div', {
|
|
47
|
+
className: `${prefix + '-layout-item-content'}`,
|
|
48
|
+
children: _jsx(TextWidget, {
|
|
49
|
+
token: 'SettingComponents.DataSourceSetter.pleaseSelectNode',
|
|
50
|
+
}),
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
return _jsxs(Fragment, {
|
|
55
|
+
children: [
|
|
56
|
+
_jsx(Header, {
|
|
57
|
+
title: _jsx(TextWidget, {
|
|
58
|
+
token: 'SettingComponents.DataSourceSetter.nodeProperty',
|
|
59
|
+
}),
|
|
60
|
+
extra: allowExtendOption
|
|
61
|
+
? _jsx(Button, {
|
|
62
|
+
type: 'text',
|
|
63
|
+
onClick: () => {
|
|
64
|
+
form.setFieldState('map', (state) => {
|
|
65
|
+
state.value.push({})
|
|
66
|
+
})
|
|
67
|
+
},
|
|
68
|
+
icon: _jsx(PlusOutlined, {}),
|
|
69
|
+
children: _jsx(TextWidget, {
|
|
70
|
+
token: 'SettingComponents.DataSourceSetter.addKeyValuePair',
|
|
71
|
+
}),
|
|
72
|
+
})
|
|
73
|
+
: null,
|
|
74
|
+
}),
|
|
75
|
+
_jsx('div', {
|
|
76
|
+
className: `${prefix + '-layout-item-content'}`,
|
|
77
|
+
children: _jsx(Form, {
|
|
78
|
+
form: form,
|
|
79
|
+
labelWidth: 60,
|
|
80
|
+
wrapperWidth: 160,
|
|
81
|
+
children: _jsx(SchemaField, {
|
|
82
|
+
children: _jsx(SchemaField.Array, {
|
|
83
|
+
name: 'map',
|
|
84
|
+
'x-component': 'ArrayItems',
|
|
85
|
+
children: _jsxs(SchemaField.Object, {
|
|
86
|
+
'x-decorator': 'ArrayItems.Item',
|
|
87
|
+
'x-decorator-props': { type: 'divide' },
|
|
88
|
+
children: [
|
|
89
|
+
_jsx(SchemaField.String, {
|
|
90
|
+
title: _jsx(TextWidget, {
|
|
91
|
+
token: 'SettingComponents.DataSourceSetter.label',
|
|
92
|
+
}),
|
|
93
|
+
'x-decorator': 'FormItem',
|
|
94
|
+
'x-disabled': !allowExtendOption,
|
|
95
|
+
name: 'label',
|
|
96
|
+
'x-component': 'Input',
|
|
97
|
+
}),
|
|
98
|
+
_jsx(SchemaField.String, {
|
|
99
|
+
title: _jsx(TextWidget, {
|
|
100
|
+
token: 'SettingComponents.DataSourceSetter.value',
|
|
101
|
+
}),
|
|
102
|
+
'x-decorator': 'FormItem',
|
|
103
|
+
name: 'value',
|
|
104
|
+
'x-component': 'ValueInput',
|
|
105
|
+
}),
|
|
106
|
+
_jsx(SchemaField.Void, {
|
|
107
|
+
'x-component': 'ArrayItems.Remove',
|
|
108
|
+
'x-visible': allowExtendOption,
|
|
109
|
+
'x-component-props': {
|
|
110
|
+
style: {
|
|
111
|
+
margin: 5,
|
|
112
|
+
display: 'flex',
|
|
113
|
+
justifyContent: 'center',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
}),
|
|
122
|
+
}),
|
|
123
|
+
}),
|
|
124
|
+
],
|
|
125
|
+
})
|
|
126
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react'
|
|
2
|
-
import './styles.less'
|
|
1
|
+
import React, { ReactNode } from 'react'
|
|
2
|
+
import './styles.less'
|
|
3
3
|
export interface IHeaderProps {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
extra: ReactNode | null
|
|
5
|
+
title: ReactNode | string
|
|
6
6
|
}
|
|
7
|
-
export declare const Header: React.FC<IHeaderProps
|
|
7
|
+
export declare const Header: React.FC<IHeaderProps>
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import './styles.less'
|
|
1
|
+
import { observer } from '@formily/reactive-react'
|
|
2
|
+
import { usePrefix } from '@thienvu18/designable-react'
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime'
|
|
4
|
+
import './styles.less'
|
|
5
5
|
export const Header = observer(({ extra, title }) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
const prefix = usePrefix('data-source-setter')
|
|
7
|
+
return _jsxs('div', {
|
|
8
|
+
className: `${prefix + '-layout-item-header'}`,
|
|
9
|
+
children: [
|
|
10
|
+
_jsx('div', {
|
|
11
|
+
className: `${prefix + '-layout-item-title'}`,
|
|
12
|
+
children: title,
|
|
13
|
+
}),
|
|
14
|
+
extra,
|
|
15
|
+
],
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import
|
|
3
|
-
import './
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import './styles.less'
|
|
3
|
+
import { INodeItem, ITreeDataSource } from './types'
|
|
4
4
|
export interface ITitleProps extends INodeItem {
|
|
5
|
-
|
|
5
|
+
treeDataSource: ITreeDataSource
|
|
6
6
|
}
|
|
7
|
-
export declare const Title: React.FC<ITitleProps
|
|
7
|
+
export declare const Title: React.FC<ITitleProps>
|
|
@@ -1,46 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { clone, toArr } from '@formily/shared'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { traverseTree } from './shared'
|
|
6
|
-
import './styles.less'
|
|
1
|
+
import { observer } from '@formily/reactive-react'
|
|
2
|
+
import { clone, toArr } from '@formily/shared'
|
|
3
|
+
import { IconWidget, TextWidget, usePrefix } from '@thienvu18/designable-react'
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime'
|
|
5
|
+
import { traverseTree } from './shared'
|
|
6
|
+
import './styles.less'
|
|
7
7
|
export const Title = observer((props) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
});
|
|
8
|
+
const prefix = usePrefix('data-source-setter-node-title')
|
|
9
|
+
const getTitleValue = (dataSource) => {
|
|
10
|
+
const optionalKeys = ['label', 'title', 'header']
|
|
11
|
+
let nodeTitle
|
|
12
|
+
optionalKeys.some((key) => {
|
|
13
|
+
const title = toArr(dataSource).find((item) => item.label === key)?.value
|
|
14
|
+
if (title !== undefined) {
|
|
15
|
+
nodeTitle = title
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
return false
|
|
19
|
+
})
|
|
20
|
+
if (nodeTitle === undefined) {
|
|
21
|
+
toArr(dataSource || []).some((item) => {
|
|
22
|
+
if (item.value && typeof item.value === 'string') {
|
|
23
|
+
nodeTitle = item.value
|
|
24
|
+
return true
|
|
28
25
|
}
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
26
|
+
return false
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
return nodeTitle
|
|
30
|
+
}
|
|
31
|
+
const renderTitle = (dataSource) => {
|
|
32
|
+
const nodeTitle = getTitleValue(dataSource)
|
|
33
|
+
if (nodeTitle === undefined)
|
|
34
|
+
return _jsx(TextWidget, {
|
|
35
|
+
token: 'SettingComponents.DataSourceSetter.defaultTitle',
|
|
36
|
+
})
|
|
37
|
+
else return nodeTitle + ''
|
|
38
|
+
}
|
|
39
|
+
return _jsxs('div', {
|
|
40
|
+
className: prefix,
|
|
41
|
+
children: [
|
|
42
|
+
_jsx('span', {
|
|
43
|
+
style: { marginRight: '5px' },
|
|
44
|
+
children: renderTitle(props?.map || []),
|
|
45
|
+
}),
|
|
46
|
+
_jsx(IconWidget, {
|
|
47
|
+
className: prefix + '-icon',
|
|
48
|
+
infer: 'Remove',
|
|
49
|
+
onClick: () => {
|
|
50
|
+
const newDataSource = clone(props?.treeDataSource?.dataSource)
|
|
51
|
+
traverseTree(newDataSource || [], (dataItem, i, data) => {
|
|
52
|
+
if (data[i].key === props.duplicateKey) toArr(data).splice(i, 1)
|
|
53
|
+
})
|
|
54
|
+
props.treeDataSource.dataSource = newDataSource
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
})
|
|
59
|
+
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import
|
|
3
|
-
import './
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import './styles.less'
|
|
3
|
+
import { ITreeDataSource } from './types'
|
|
4
4
|
export interface ITreePanelProps {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
treeDataSource: ITreeDataSource
|
|
6
|
+
allowTree: boolean
|
|
7
|
+
defaultOptionValue: {
|
|
8
|
+
label: string
|
|
9
|
+
value: any
|
|
10
|
+
}[]
|
|
11
11
|
}
|
|
12
|
-
export declare const TreePanel: React.FC<ITreePanelProps
|
|
12
|
+
export declare const TreePanel: React.FC<ITreePanelProps>
|
|
@@ -1,94 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Header } from './Header'
|
|
9
|
-
import {
|
|
10
|
-
import './
|
|
11
|
-
import
|
|
1
|
+
import { observer } from '@formily/reactive-react'
|
|
2
|
+
import { uid } from '@formily/shared'
|
|
3
|
+
import { GlobalRegistry } from '@thienvu18/designable-core'
|
|
4
|
+
import { IconWidget, TextWidget, usePrefix } from '@thienvu18/designable-react'
|
|
5
|
+
import { Button, Tree } from 'antd'
|
|
6
|
+
import { Fragment } from 'react'
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from 'react/jsx-runtime'
|
|
8
|
+
import { Header } from './Header'
|
|
9
|
+
import { Title } from './Title'
|
|
10
|
+
import { traverseTree } from './shared'
|
|
11
|
+
import './styles.less'
|
|
12
12
|
const limitTreeDrag = ({ dropPosition }) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
13
|
+
if (dropPosition === 0) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
18
|
export const TreePanel = observer((props) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
});
|
|
19
|
+
const prefix = usePrefix('data-source-setter')
|
|
20
|
+
const dropHandler = (info) => {
|
|
21
|
+
const dropKey = info.node?.key
|
|
22
|
+
const dragKey = info.dragNode?.key
|
|
23
|
+
const dropPos = info.node.pos.split('-')
|
|
24
|
+
const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1])
|
|
25
|
+
const data = [...props.treeDataSource.dataSource]
|
|
26
|
+
// Find dragObject
|
|
27
|
+
let dragObj
|
|
28
|
+
traverseTree(data, (item, index, arr) => {
|
|
29
|
+
if (arr[index].key === dragKey) {
|
|
30
|
+
arr.splice(index, 1)
|
|
31
|
+
dragObj = item
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
if (!info.dropToGap) {
|
|
35
|
+
traverseTree(data, (item) => {
|
|
36
|
+
if (item.key === dropKey) {
|
|
37
|
+
item.children = item.children || []
|
|
38
|
+
item.children.unshift(dragObj)
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
})
|
|
41
|
+
} else if (
|
|
42
|
+
(info.node.children || []).length > 0 &&
|
|
43
|
+
info.node.expanded &&
|
|
44
|
+
dropPosition === 1
|
|
45
|
+
) {
|
|
46
|
+
traverseTree(data, (item) => {
|
|
47
|
+
if (item.key === dropKey) {
|
|
48
|
+
item.children = item.children || []
|
|
49
|
+
item.children.unshift(dragObj)
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
});
|
|
61
|
-
if (dropPosition === -1) {
|
|
62
|
-
ar.splice(i, 0, dragObj);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
ar.splice(i + 1, 0, dragObj);
|
|
66
|
-
}
|
|
51
|
+
})
|
|
52
|
+
} else {
|
|
53
|
+
let ar
|
|
54
|
+
let i
|
|
55
|
+
traverseTree(data, (item, index, arr) => {
|
|
56
|
+
if (item.key === dropKey) {
|
|
57
|
+
ar = arr
|
|
58
|
+
i = index
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
60
|
+
})
|
|
61
|
+
if (dropPosition === -1) {
|
|
62
|
+
ar.splice(i, 0, dragObj)
|
|
63
|
+
} else {
|
|
64
|
+
ar.splice(i + 1, 0, dragObj)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
props.treeDataSource.dataSource = data
|
|
68
|
+
}
|
|
69
|
+
return _jsxs(Fragment, {
|
|
70
|
+
children: [
|
|
71
|
+
_jsx(Header, {
|
|
72
|
+
title: _jsx(TextWidget, {
|
|
73
|
+
token: 'SettingComponents.DataSourceSetter.dataSourceTree',
|
|
74
|
+
}),
|
|
75
|
+
extra: _jsx(Button, {
|
|
76
|
+
type: 'text',
|
|
77
|
+
onClick: () => {
|
|
78
|
+
const uuid = uid()
|
|
79
|
+
const dataSource = props.treeDataSource.dataSource
|
|
80
|
+
const initialKeyValuePairs = props.defaultOptionValue?.map(
|
|
81
|
+
(item) => ({ ...item })
|
|
82
|
+
) || [
|
|
83
|
+
{
|
|
84
|
+
label: 'label',
|
|
85
|
+
value: `${GlobalRegistry.getDesignerMessage(
|
|
86
|
+
`SettingComponents.DataSourceSetter.item`
|
|
87
|
+
)} ${dataSource.length + 1}`,
|
|
88
|
+
},
|
|
89
|
+
{ label: 'value', value: uuid },
|
|
90
|
+
]
|
|
91
|
+
props.treeDataSource.dataSource = dataSource.concat({
|
|
92
|
+
key: uuid,
|
|
93
|
+
duplicateKey: uuid,
|
|
94
|
+
map: initialKeyValuePairs,
|
|
95
|
+
children: [],
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
icon: _jsx(IconWidget, { infer: 'Add' }),
|
|
99
|
+
children: _jsx(TextWidget, {
|
|
100
|
+
token: 'SettingComponents.DataSourceSetter.addNode',
|
|
101
|
+
}),
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
_jsx('div', {
|
|
105
|
+
className: `${prefix + '-layout-item-content'}`,
|
|
106
|
+
children: _jsx(Tree, {
|
|
107
|
+
blockNode: true,
|
|
108
|
+
draggable: true,
|
|
109
|
+
allowDrop: props.allowTree ? () => true : limitTreeDrag,
|
|
110
|
+
defaultExpandAll: true,
|
|
111
|
+
defaultExpandParent: true,
|
|
112
|
+
autoExpandParent: true,
|
|
113
|
+
showLine: { showLeafIcon: false },
|
|
114
|
+
treeData: props.treeDataSource.dataSource,
|
|
115
|
+
onDragEnter: () => {},
|
|
116
|
+
onDrop: dropHandler,
|
|
117
|
+
titleRender: (titleProps) => {
|
|
118
|
+
const { key, ...rest } = titleProps
|
|
119
|
+
return _jsx(
|
|
120
|
+
Title,
|
|
121
|
+
{ ...rest, treeDataSource: props.treeDataSource },
|
|
122
|
+
key
|
|
123
|
+
)
|
|
124
|
+
},
|
|
125
|
+
onSelect: (selectedKeys) => {
|
|
126
|
+
if (selectedKeys[0]) {
|
|
127
|
+
props.treeDataSource.selectedKey = selectedKeys[0].toString()
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
}),
|
|
132
|
+
],
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import './
|
|
1
|
+
import { Form } from '@formily/core'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import './styles.less'
|
|
4
|
+
import { IDataSourceItem } from './types'
|
|
5
5
|
export interface IDataSourceSetterProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
className?: string
|
|
7
|
+
style?: React.CSSProperties
|
|
8
|
+
onChange: (dataSource: IDataSourceItem[]) => void
|
|
9
|
+
value: IDataSourceItem[]
|
|
10
|
+
allowTree?: boolean
|
|
11
|
+
allowExtendOption?: boolean
|
|
12
|
+
defaultOptionValue?: {
|
|
13
|
+
label: string
|
|
14
|
+
value: any
|
|
15
|
+
}[]
|
|
16
|
+
effects?: (form: Form<any>) => void
|
|
17
17
|
}
|
|
18
|
-
export declare const DataSourceSetter: React.FC<IDataSourceSetterProps
|
|
18
|
+
export declare const DataSourceSetter: React.FC<IDataSourceSetterProps>
|