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