@formily-design/formily-setters 1.0.0

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 (108) hide show
  1. package/.umirc.js +44 -0
  2. package/LICENSE.md +20 -0
  3. package/README.md +7 -0
  4. package/copy.ts +6 -0
  5. package/esm/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
  6. package/esm/components/DataSourceSetter/DataSettingPanel.js +66 -0
  7. package/esm/components/DataSourceSetter/Header.d.ts +7 -0
  8. package/esm/components/DataSourceSetter/Header.js +10 -0
  9. package/esm/components/DataSourceSetter/Title.d.ts +7 -0
  10. package/esm/components/DataSourceSetter/Title.js +50 -0
  11. package/esm/components/DataSourceSetter/TreePanel.d.ts +12 -0
  12. package/esm/components/DataSourceSetter/TreePanel.js +98 -0
  13. package/esm/components/DataSourceSetter/index.d.ts +18 -0
  14. package/esm/components/DataSourceSetter/index.js +34 -0
  15. package/esm/components/DataSourceSetter/shared.d.ts +9 -0
  16. package/esm/components/DataSourceSetter/shared.js +47 -0
  17. package/esm/components/DataSourceSetter/styles.less +80 -0
  18. package/esm/components/DataSourceSetter/types.d.ts +18 -0
  19. package/esm/components/DataSourceSetter/types.js +1 -0
  20. package/esm/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
  21. package/esm/components/ReactionsSetter/FieldPropertySetter.js +83 -0
  22. package/esm/components/ReactionsSetter/PathSelector.d.ts +10 -0
  23. package/esm/components/ReactionsSetter/PathSelector.js +107 -0
  24. package/esm/components/ReactionsSetter/declarations.d.ts +5 -0
  25. package/esm/components/ReactionsSetter/declarations.js +51 -0
  26. package/esm/components/ReactionsSetter/helpers.d.ts +10 -0
  27. package/esm/components/ReactionsSetter/helpers.js +384 -0
  28. package/esm/components/ReactionsSetter/index.d.ts +8 -0
  29. package/esm/components/ReactionsSetter/index.js +282 -0
  30. package/esm/components/ReactionsSetter/properties.d.ts +11 -0
  31. package/esm/components/ReactionsSetter/properties.js +41 -0
  32. package/esm/components/ReactionsSetter/styles.less +103 -0
  33. package/esm/components/ReactionsSetter/types.d.ts +13 -0
  34. package/esm/components/ReactionsSetter/types.js +1 -0
  35. package/esm/components/RemoteDataSourceSetter/RemoteDataSourcePanel.d.ts +8 -0
  36. package/esm/components/RemoteDataSourceSetter/RemoteDataSourcePanel.js +103 -0
  37. package/esm/components/RemoteDataSourceSetter/index.d.ts +17 -0
  38. package/esm/components/RemoteDataSourceSetter/index.js +25 -0
  39. package/esm/components/RemoteDataSourceSetter/styles.less +33 -0
  40. package/esm/components/RemoteDataSourceSetter/types.d.ts +8 -0
  41. package/esm/components/RemoteDataSourceSetter/types.js +1 -0
  42. package/esm/components/ValidatorSetter/index.d.ts +6 -0
  43. package/esm/components/ValidatorSetter/index.js +140 -0
  44. package/esm/components/index.d.ts +4 -0
  45. package/esm/components/index.js +4 -0
  46. package/esm/index.d.ts +2 -0
  47. package/esm/index.js +2 -0
  48. package/esm/locales/en-US.d.ts +110 -0
  49. package/esm/locales/en-US.js +115 -0
  50. package/esm/locales/index.d.ts +1 -0
  51. package/esm/locales/index.js +5 -0
  52. package/esm/locales/ko-KR.d.ts +110 -0
  53. package/esm/locales/ko-KR.js +115 -0
  54. package/esm/locales/zh-CN.d.ts +110 -0
  55. package/esm/locales/zh-CN.js +115 -0
  56. package/lib/components/DataSourceSetter/DataSettingPanel.d.ts +10 -0
  57. package/lib/components/DataSourceSetter/DataSettingPanel.js +102 -0
  58. package/lib/components/DataSourceSetter/Header.d.ts +7 -0
  59. package/lib/components/DataSourceSetter/Header.js +16 -0
  60. package/lib/components/DataSourceSetter/Title.d.ts +7 -0
  61. package/lib/components/DataSourceSetter/Title.js +56 -0
  62. package/lib/components/DataSourceSetter/TreePanel.d.ts +12 -0
  63. package/lib/components/DataSourceSetter/TreePanel.js +134 -0
  64. package/lib/components/DataSourceSetter/index.d.ts +18 -0
  65. package/lib/components/DataSourceSetter/index.js +73 -0
  66. package/lib/components/DataSourceSetter/shared.d.ts +9 -0
  67. package/lib/components/DataSourceSetter/shared.js +53 -0
  68. package/lib/components/DataSourceSetter/styles.less +80 -0
  69. package/lib/components/DataSourceSetter/types.d.ts +18 -0
  70. package/lib/components/DataSourceSetter/types.js +2 -0
  71. package/lib/components/ReactionsSetter/FieldPropertySetter.d.ts +10 -0
  72. package/lib/components/ReactionsSetter/FieldPropertySetter.js +120 -0
  73. package/lib/components/ReactionsSetter/PathSelector.d.ts +10 -0
  74. package/lib/components/ReactionsSetter/PathSelector.js +114 -0
  75. package/lib/components/ReactionsSetter/declarations.d.ts +5 -0
  76. package/lib/components/ReactionsSetter/declarations.js +55 -0
  77. package/lib/components/ReactionsSetter/helpers.d.ts +10 -0
  78. package/lib/components/ReactionsSetter/helpers.js +387 -0
  79. package/lib/components/ReactionsSetter/index.d.ts +8 -0
  80. package/lib/components/ReactionsSetter/index.js +319 -0
  81. package/lib/components/ReactionsSetter/properties.d.ts +11 -0
  82. package/lib/components/ReactionsSetter/properties.js +44 -0
  83. package/lib/components/ReactionsSetter/styles.less +103 -0
  84. package/lib/components/ReactionsSetter/types.d.ts +13 -0
  85. package/lib/components/ReactionsSetter/types.js +2 -0
  86. package/lib/components/RemoteDataSourceSetter/RemoteDataSourcePanel.d.ts +8 -0
  87. package/lib/components/RemoteDataSourceSetter/RemoteDataSourcePanel.js +140 -0
  88. package/lib/components/RemoteDataSourceSetter/index.d.ts +17 -0
  89. package/lib/components/RemoteDataSourceSetter/index.js +64 -0
  90. package/lib/components/RemoteDataSourceSetter/styles.less +33 -0
  91. package/lib/components/RemoteDataSourceSetter/types.d.ts +8 -0
  92. package/lib/components/RemoteDataSourceSetter/types.js +2 -0
  93. package/lib/components/ValidatorSetter/index.d.ts +6 -0
  94. package/lib/components/ValidatorSetter/index.js +146 -0
  95. package/lib/components/index.d.ts +4 -0
  96. package/lib/components/index.js +20 -0
  97. package/lib/index.d.ts +2 -0
  98. package/lib/index.js +18 -0
  99. package/lib/locales/en-US.d.ts +110 -0
  100. package/lib/locales/en-US.js +117 -0
  101. package/lib/locales/index.d.ts +1 -0
  102. package/lib/locales/index.js +10 -0
  103. package/lib/locales/ko-KR.d.ts +110 -0
  104. package/lib/locales/ko-KR.js +117 -0
  105. package/lib/locales/zh-CN.d.ts +110 -0
  106. package/lib/locales/zh-CN.js +117 -0
  107. package/package.json +53 -0
  108. package/tsconfig.build.json +10 -0
package/.umirc.js ADDED
@@ -0,0 +1,44 @@
1
+ import { resolve } from 'path'
2
+ export default {
3
+ mode: 'site',
4
+ logo: '//img.alicdn.com/imgextra/i2/O1CN01Kq3OHU1fph6LGqjIz_!!6000000004056-55-tps-1141-150.svg',
5
+ title: 'Formily',
6
+ hash: true,
7
+ favicon:
8
+ '//img.alicdn.com/imgextra/i3/O1CN01XtT3Tv1Wd1b5hNVKy_!!6000000002810-55-tps-360-360.svg',
9
+ outputPath: './doc-site',
10
+ navs: [
11
+ {
12
+ title: 'Ant Design',
13
+ path: '/components',
14
+ },
15
+ {
16
+ title: '主站',
17
+ path: 'https://v2.formilyjs.org',
18
+ },
19
+ {
20
+ title: 'GITHUB',
21
+ path: 'https://github.com/alibaba/formily',
22
+ },
23
+ ],
24
+ styles: [
25
+ `.__dumi-default-navbar-logo{
26
+ height: 60px !important;
27
+ width: 150px !important;
28
+ padding-left:0 !important;
29
+ color: transparent !important;
30
+ }
31
+ .__dumi-default-navbar{
32
+ padding: 0 28px !important;
33
+ }
34
+ .__dumi-default-layout-hero{
35
+ background-image: url(//img.alicdn.com/imgextra/i4/O1CN01ZcvS4e26XMsdsCkf9_!!6000000007671-2-tps-6001-4001.png);
36
+ background-size: cover;
37
+ background-repeat: no-repeat;
38
+ }
39
+ nav a{
40
+ text-decoration: none !important;
41
+ }
42
+ `,
43
+ ],
44
+ }
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-present, Alibaba Group Holding Limited. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @formily/designable-antd
2
+
3
+ ### Install
4
+
5
+ ```bash
6
+ npm install --save @formily/designable-antd
7
+ ```
package/copy.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { runCopy } from '../../scripts/build-style'
2
+
3
+ runCopy({
4
+ esStr: 'antd/es/',
5
+ libStr: 'antd/lib/',
6
+ })
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { Form as FormCore } from '@formily/core';
3
+ import { ITreeDataSource } from './types';
4
+ import './styles.less';
5
+ export interface IDataSettingPanelProps {
6
+ treeDataSource: ITreeDataSource;
7
+ allowExtendOption?: boolean;
8
+ effects?: (form: FormCore<any>) => void;
9
+ }
10
+ export declare const DataSettingPanel: React.FC<IDataSettingPanelProps>;
@@ -0,0 +1,66 @@
1
+ import React, { useMemo, Fragment } from 'react';
2
+ import { Button } from 'antd';
3
+ import { PlusOutlined } from '@ant-design/icons';
4
+ import { ArrayItems, Form, Input, FormItem } from '@formily/antd-v5';
5
+ import { createForm } from '@formily/core';
6
+ import { observer } from '@formily/reactive-react';
7
+ import { createSchemaField } from '@formily/react';
8
+ import { ValueInput } from '@formily-design/react-settings-form';
9
+ import { usePrefix, TextWidget } from '@formily-design/react';
10
+ import { Header } from './Header';
11
+ import { traverseTree } from './shared';
12
+ import './styles.less';
13
+ const SchemaField = createSchemaField({
14
+ components: {
15
+ FormItem,
16
+ Input,
17
+ ArrayItems,
18
+ ValueInput,
19
+ },
20
+ });
21
+ export const DataSettingPanel = observer((props) => {
22
+ const { allowExtendOption, effects } = props;
23
+ const prefix = usePrefix('data-source-setter');
24
+ const form = useMemo(() => {
25
+ let values;
26
+ traverseTree(props.treeDataSource.dataSource, (dataItem) => {
27
+ if (dataItem.key === props.treeDataSource.selectedKey) {
28
+ values = dataItem;
29
+ }
30
+ });
31
+ return createForm({
32
+ values,
33
+ effects: effects,
34
+ });
35
+ }, [
36
+ props.treeDataSource.selectedKey,
37
+ props.treeDataSource.dataSource.length,
38
+ ]);
39
+ if (!props.treeDataSource.selectedKey)
40
+ return (React.createElement(Fragment, null,
41
+ React.createElement(Header, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.nodeProperty" }), extra: null }),
42
+ React.createElement("div", { className: `${prefix + '-layout-item-content'}` },
43
+ React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.pleaseSelectNode" }))));
44
+ return (React.createElement(Fragment, null,
45
+ React.createElement(Header, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.nodeProperty" }), extra: allowExtendOption ? (React.createElement(Button, { type: "text", onClick: () => {
46
+ form.setFieldState('map', (state) => {
47
+ state.value.push({});
48
+ });
49
+ }, icon: React.createElement(PlusOutlined, null) },
50
+ React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.addKeyValuePair" }))) : null }),
51
+ React.createElement("div", { className: `${prefix + '-layout-item-content'}` },
52
+ React.createElement(Form, { form: form, labelWidth: 60, wrapperWidth: 160 },
53
+ React.createElement(SchemaField, null,
54
+ React.createElement(SchemaField.Array, { name: "map", "x-component": "ArrayItems" },
55
+ React.createElement(SchemaField.Object, { "x-decorator": "ArrayItems.Item", "x-decorator-props": { type: 'divide' } },
56
+ React.createElement(SchemaField.String, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.label" }), "x-decorator": "FormItem", "x-disabled": !allowExtendOption, name: "label", "x-component": "Input" }),
57
+ React.createElement(SchemaField.String, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.value" }), "x-decorator": "FormItem", name: "value", "x-component": "ValueInput" }),
58
+ React.createElement(SchemaField.Void, { "x-component": "ArrayItems.Remove", "x-visible": allowExtendOption, "x-component-props": {
59
+ style: {
60
+ margin: 5,
61
+ display: 'flex',
62
+ justifyContent: 'center',
63
+ alignItems: 'center',
64
+ },
65
+ } }))))))));
66
+ });
@@ -0,0 +1,7 @@
1
+ import React, { ReactNode } from 'react';
2
+ import './styles.less';
3
+ export interface IHeaderProps {
4
+ extra: ReactNode | null;
5
+ title: ReactNode | string;
6
+ }
7
+ export declare const Header: React.FC<IHeaderProps>;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { observer } from '@formily/reactive-react';
3
+ import { usePrefix } from '@formily-design/react';
4
+ import './styles.less';
5
+ export const Header = observer(({ extra, title }) => {
6
+ const prefix = usePrefix('data-source-setter');
7
+ return (React.createElement("div", { className: `${prefix + '-layout-item-header'}` },
8
+ React.createElement("div", { className: `${prefix + '-layout-item-title'}` }, title),
9
+ extra));
10
+ });
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { INodeItem, ITreeDataSource } from './types';
3
+ import './styles.less';
4
+ export interface ITitleProps extends INodeItem {
5
+ treeDataSource: ITreeDataSource;
6
+ }
7
+ export declare const Title: React.FC<ITitleProps>;
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import { clone, toArr } from '@formily/shared';
3
+ import { observer } from '@formily/reactive-react';
4
+ import { IconWidget, TextWidget, usePrefix } from '@formily-design/react';
5
+ import { traverseTree } from './shared';
6
+ import './styles.less';
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
+ var _a;
14
+ const title = (_a = toArr(dataSource).find((item) => item.label === key)) === null || _a === void 0 ? void 0 : _a.value;
15
+ if (title !== undefined) {
16
+ nodeTitle = title;
17
+ return true;
18
+ }
19
+ return false;
20
+ });
21
+ if (nodeTitle === undefined) {
22
+ toArr(dataSource || []).some((item) => {
23
+ if (item.value && typeof item.value === 'string') {
24
+ nodeTitle = item.value;
25
+ return true;
26
+ }
27
+ return false;
28
+ });
29
+ }
30
+ return nodeTitle;
31
+ };
32
+ const renderTitle = (dataSource) => {
33
+ const nodeTitle = getTitleValue(dataSource);
34
+ if (nodeTitle === undefined)
35
+ return (React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.defaultTitle" }));
36
+ else
37
+ return nodeTitle + '';
38
+ };
39
+ return (React.createElement("div", { className: prefix },
40
+ React.createElement("span", { style: { marginRight: '5px' } }, renderTitle((props === null || props === void 0 ? void 0 : props.map) || [])),
41
+ React.createElement(IconWidget, { className: prefix + '-icon', infer: "Remove", onClick: () => {
42
+ var _a;
43
+ const newDataSource = clone((_a = props === null || props === void 0 ? void 0 : props.treeDataSource) === null || _a === void 0 ? void 0 : _a.dataSource);
44
+ traverseTree(newDataSource || [], (dataItem, i, data) => {
45
+ if (data[i].key === props.duplicateKey)
46
+ toArr(data).splice(i, 1);
47
+ });
48
+ props.treeDataSource.dataSource = newDataSource;
49
+ } })));
50
+ });
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ITreeDataSource } from './types';
3
+ import './styles.less';
4
+ export interface ITreePanelProps {
5
+ treeDataSource: ITreeDataSource;
6
+ allowTree: boolean;
7
+ defaultOptionValue: {
8
+ label: string;
9
+ value: any;
10
+ }[];
11
+ }
12
+ export declare const TreePanel: React.FC<ITreePanelProps>;
@@ -0,0 +1,98 @@
1
+ import React, { Fragment } from 'react';
2
+ import { Tree, Button } from 'antd';
3
+ import { uid } from '@formily/shared';
4
+ import { observer } from '@formily/reactive-react';
5
+ import { usePrefix, TextWidget, IconWidget } from '@formily-design/react';
6
+ import { Title } from './Title';
7
+ import { Header } from './Header';
8
+ import { traverseTree } from './shared';
9
+ import './styles.less';
10
+ import { GlobalRegistry } from '@formily-design/core';
11
+ const limitTreeDrag = ({ dropPosition }) => {
12
+ if (dropPosition === 0) {
13
+ return false;
14
+ }
15
+ return true;
16
+ };
17
+ export const TreePanel = observer((props) => {
18
+ const prefix = usePrefix('data-source-setter');
19
+ const dropHandler = (info) => {
20
+ var _a, _b;
21
+ const dropKey = (_a = info.node) === null || _a === void 0 ? void 0 : _a.key;
22
+ const dragKey = (_b = info.dragNode) === null || _b === void 0 ? void 0 : _b.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
+ });
41
+ }
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
+ });
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;
59
+ }
60
+ });
61
+ if (dropPosition === -1) {
62
+ ar.splice(i, 0, dragObj);
63
+ }
64
+ else {
65
+ ar.splice(i + 1, 0, dragObj);
66
+ }
67
+ }
68
+ props.treeDataSource.dataSource = data;
69
+ };
70
+ return (React.createElement(Fragment, null,
71
+ React.createElement(Header, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.dataSourceTree" }), extra: React.createElement(Button, { type: "text", onClick: () => {
72
+ var _a;
73
+ const uuid = uid();
74
+ const dataSource = props.treeDataSource.dataSource;
75
+ const initialKeyValuePairs = ((_a = props.defaultOptionValue) === null || _a === void 0 ? void 0 : _a.map((item) => ({ ...item }))) || [
76
+ {
77
+ label: 'label',
78
+ value: `${GlobalRegistry.getDesignerMessage(`SettingComponents.DataSourceSetter.item`)} ${dataSource.length + 1}`,
79
+ },
80
+ { label: 'value', value: uuid },
81
+ ];
82
+ props.treeDataSource.dataSource = dataSource.concat({
83
+ key: uuid,
84
+ duplicateKey: uuid,
85
+ map: initialKeyValuePairs,
86
+ children: [],
87
+ });
88
+ }, icon: React.createElement(IconWidget, { infer: "Add" }) },
89
+ React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.addNode" })) }),
90
+ React.createElement("div", { className: `${prefix + '-layout-item-content'}` },
91
+ React.createElement(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) => {
92
+ return (React.createElement(Title, { ...titleProps, treeDataSource: props.treeDataSource }));
93
+ }, onSelect: (selectedKeys) => {
94
+ if (selectedKeys[0]) {
95
+ props.treeDataSource.selectedKey = selectedKeys[0].toString();
96
+ }
97
+ } }))));
98
+ });
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { Form } from '@formily/core';
3
+ import { IDataSourceItem } from './types';
4
+ import './styles.less';
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;
17
+ }
18
+ export declare const DataSourceSetter: React.FC<IDataSourceSetterProps>;
@@ -0,0 +1,34 @@
1
+ import React, { Fragment, useMemo, useState } from 'react';
2
+ import cls from 'classnames';
3
+ import { Modal, Button } from 'antd';
4
+ import { observable } from '@formily/reactive';
5
+ import { observer } from '@formily/reactive-react';
6
+ import { usePrefix, useTheme, TextWidget } from '@formily-design/react';
7
+ import { DataSettingPanel } from './DataSettingPanel';
8
+ import { TreePanel } from './TreePanel';
9
+ import { transformDataToValue, transformValueToData } from './shared';
10
+ import './styles.less';
11
+ export const DataSourceSetter = observer((props) => {
12
+ const { className, value = [], onChange, allowTree = true, allowExtendOption = true, defaultOptionValue, effects = () => { }, } = props;
13
+ const theme = useTheme();
14
+ const prefix = usePrefix('data-source-setter');
15
+ const [modalVisible, setModalVisible] = useState(false);
16
+ const treeDataSource = useMemo(() => observable({
17
+ dataSource: transformValueToData(value),
18
+ selectedKey: '',
19
+ }), [value, modalVisible]);
20
+ const openModal = () => setModalVisible(true);
21
+ const closeModal = () => setModalVisible(false);
22
+ return (React.createElement(Fragment, null,
23
+ React.createElement(Button, { block: true, onClick: openModal },
24
+ React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" })),
25
+ React.createElement(Modal, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.configureDataSource" }), width: "65%", bodyStyle: { padding: 10 }, transitionName: "", maskTransitionName: "", visible: modalVisible, onCancel: closeModal, onOk: () => {
26
+ onChange(transformDataToValue(treeDataSource.dataSource));
27
+ closeModal();
28
+ } },
29
+ React.createElement("div", { className: `${cls(prefix, className)} ${prefix + '-' + theme} ${prefix + '-layout'}` },
30
+ React.createElement("div", { className: `${prefix + '-layout-item left'}` },
31
+ React.createElement(TreePanel, { defaultOptionValue: defaultOptionValue, allowTree: allowTree, treeDataSource: treeDataSource })),
32
+ React.createElement("div", { className: `${prefix + '-layout-item right'}` },
33
+ React.createElement(DataSettingPanel, { allowExtendOption: allowExtendOption, treeDataSource: treeDataSource, effects: effects }))))));
34
+ });
@@ -0,0 +1,9 @@
1
+ import { IDataSourceItem, INodeItem } from './types';
2
+ export interface INode {
3
+ key?: string;
4
+ map?: any;
5
+ children?: INode[];
6
+ }
7
+ export declare const traverseTree: <T extends INode>(data: T[], callback: (dataItem: T, i: number, data: T[]) => any) => void;
8
+ export declare const transformValueToData: (value: IDataSourceItem[]) => INodeItem[];
9
+ export declare const transformDataToValue: (data: INodeItem[]) => IDataSourceItem[];
@@ -0,0 +1,47 @@
1
+ import { uid, clone, toArr } from '@formily/shared';
2
+ export const traverseTree = (data, callback) => {
3
+ var _a, _b;
4
+ for (let i = 0; i < data.length; i++) {
5
+ callback(data[i], i, data);
6
+ if ((_a = data[i]) === null || _a === void 0 ? void 0 : _a.children) {
7
+ traverseTree((_b = data[i]) === null || _b === void 0 ? void 0 : _b.children, callback);
8
+ }
9
+ }
10
+ };
11
+ export const transformValueToData = (value) => {
12
+ const data = clone(value);
13
+ traverseTree(data, (item, i, dataSource) => {
14
+ const dataItem = {
15
+ key: '',
16
+ duplicateKey: '',
17
+ map: [],
18
+ children: [],
19
+ };
20
+ for (const [key, value] of Object.entries(dataSource[i] || {})) {
21
+ if (key !== 'children')
22
+ dataItem.map.push({ label: key, value: value });
23
+ }
24
+ const uuid = uid();
25
+ dataItem.key = uuid;
26
+ dataItem.duplicateKey = uuid;
27
+ dataItem.children = dataSource[i].children || [];
28
+ dataSource[i] = dataItem;
29
+ });
30
+ return data;
31
+ };
32
+ export const transformDataToValue = (data) => {
33
+ const value = clone(data);
34
+ traverseTree(value, (item, i, dataSource) => {
35
+ var _a;
36
+ const valueItem = {
37
+ children: [],
38
+ };
39
+ toArr(dataSource[i].map).forEach((item) => {
40
+ if (item.label)
41
+ valueItem[item.label] = item.value;
42
+ });
43
+ valueItem.children = ((_a = dataSource[i]) === null || _a === void 0 ? void 0 : _a.children) || [];
44
+ dataSource[i] = valueItem;
45
+ });
46
+ return value;
47
+ };
@@ -0,0 +1,80 @@
1
+ @root-entry-name: 'default';
2
+
3
+ .dn-data-source-setter {
4
+ ::-webkit-scrollbar {
5
+ width: 5px;
6
+ height: 5px;
7
+ }
8
+
9
+ ::-webkit-scrollbar-thumb {
10
+ background-color: rgba(0, 0, 0, 0.2);
11
+ border-radius: 0;
12
+ transition: all 0.25s ease-in-out;
13
+ }
14
+
15
+ ::-webkit-scrollbar-thumb:hover {
16
+ background-color: rgba(0, 0, 0, 0.3);
17
+ }
18
+ &-node-title {
19
+ display: flex;
20
+ justify-content: space-between;
21
+ align-items: center;
22
+
23
+ &-icon {
24
+ transition: all 0.15s ease-in-out;
25
+ opacity: 0;
26
+
27
+ &:hover {
28
+ }
29
+ }
30
+ }
31
+
32
+ &-layout {
33
+ display: flex;
34
+ justify-content: space-around;
35
+ border: 1px solid #d9d9d9;
36
+ border-radius: 3px;
37
+
38
+ .ant-tree-treenode {
39
+ padding-right: 10px;
40
+ white-space: nowrap;
41
+
42
+ &:hover {
43
+ .dn-data-source-setter-node-title-icon {
44
+ opacity: 1;
45
+ }
46
+ }
47
+ }
48
+
49
+ &-item {
50
+ position: relative;
51
+
52
+ &.left {
53
+ width: 40%;
54
+ border-right: 1px solid #d9d9d9;
55
+ }
56
+
57
+ &.right {
58
+ width: 60%;
59
+ }
60
+
61
+ &-header {
62
+ display: flex;
63
+ flex: none;
64
+ align-items: center;
65
+ justify-content: space-between;
66
+ height: 40px;
67
+ padding: 8px 12px 9px;
68
+ border-bottom: 1px solid #d9d9d9;
69
+ border-radius: 2px 2px 0 0;
70
+ }
71
+
72
+ &-content {
73
+ padding: 2%;
74
+ height: 300px;
75
+ max-height: 300px;
76
+ overflow: scroll;
77
+ }
78
+ }
79
+ }
80
+ }
@@ -0,0 +1,18 @@
1
+ export interface IDataSourceItem {
2
+ label?: '';
3
+ value?: any;
4
+ children?: any[];
5
+ }
6
+ export interface INodeItem {
7
+ key: string;
8
+ duplicateKey?: string;
9
+ map?: {
10
+ label: string;
11
+ value: any;
12
+ }[];
13
+ children?: INodeItem[];
14
+ }
15
+ export interface ITreeDataSource {
16
+ dataSource: INodeItem[];
17
+ selectedKey: string;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export interface IFieldProperty {
3
+ [key: string]: string;
4
+ }
5
+ export interface IFieldPropertySetterProps {
6
+ extraLib?: string;
7
+ value?: IFieldProperty;
8
+ onChange?: (value: IFieldProperty) => void;
9
+ }
10
+ export declare const FieldPropertySetter: React.FC<IFieldPropertySetterProps>;
@@ -0,0 +1,83 @@
1
+ import React, { useState } from 'react';
2
+ import { TextWidget, usePrefix } from '@formily-design/react';
3
+ import { Menu } from 'antd';
4
+ import { MonacoInput } from '@formily-design/react-settings-form';
5
+ import { isPlainObj, reduce } from '@formily/shared';
6
+ import { FieldProperties } from './properties';
7
+ const template = (code) => {
8
+ if (!code)
9
+ return;
10
+ return code.trim();
11
+ };
12
+ export const FieldPropertySetter = (props) => {
13
+ const [selectKeys, setSelectKeys] = useState(['visible']);
14
+ const prefix = usePrefix('field-property-setter');
15
+ const value = { ...props.value };
16
+ const parseExpression = (expression) => {
17
+ var _a;
18
+ if (!expression)
19
+ return '';
20
+ return ((_a = String(expression).match(/^\{\{([\s\S]*)\}\}$/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
21
+ };
22
+ const filterEmpty = (value) => {
23
+ return reduce(value, (buf, value, key) => {
24
+ if (!value || value === '{{}}')
25
+ return buf;
26
+ buf[key] = value;
27
+ return buf;
28
+ }, {});
29
+ };
30
+ const currentProperty = FieldProperties.find((item) => item.key === selectKeys[0]);
31
+ return (React.createElement("div", { className: prefix },
32
+ React.createElement(Menu, { mode: "vertical", style: {
33
+ width: 200,
34
+ height: 300,
35
+ paddingRight: 4,
36
+ overflowY: 'auto',
37
+ overflowX: 'hidden',
38
+ }, defaultSelectedKeys: selectKeys, selectedKeys: selectKeys, onSelect: ({ selectedKeys }) => {
39
+ setSelectKeys(selectedKeys);
40
+ } }, FieldProperties.map((key) => {
41
+ if (isPlainObj(key)) {
42
+ return (React.createElement(Menu.Item, { key: key.key },
43
+ React.createElement(TextWidget, { token: `SettingComponents.ReactionsSetter.${key.token || key.key}` })));
44
+ }
45
+ return (React.createElement(Menu.Item, { key: key },
46
+ React.createElement(TextWidget, { token: `SettingComponents.ReactionsSetter.${key}` })));
47
+ })),
48
+ React.createElement("div", { className: prefix + '-coder-wrapper' },
49
+ React.createElement("div", { className: prefix + '-coder-start' },
50
+ `$self.${selectKeys[0]} = (`,
51
+ React.createElement("span", { style: {
52
+ fontSize: 14,
53
+ marginLeft: 10,
54
+ color: '#888',
55
+ fontWeight: 'normal',
56
+ } },
57
+ '//',
58
+ ' ',
59
+ React.createElement(TextWidget, { token: "SettingComponents.ReactionsSetter.expressionValueTypeIs" }),
60
+ ' ',
61
+ '`', currentProperty === null || currentProperty === void 0 ? void 0 :
62
+ currentProperty.type,
63
+ '`')),
64
+ React.createElement("div", { className: prefix + '-coder' },
65
+ React.createElement(MonacoInput, { key: selectKeys[0], language: "javascript.expression", extraLib: props.extraLib, helpCode: template(currentProperty === null || currentProperty === void 0 ? void 0 : currentProperty.helpCode), value: parseExpression(value[selectKeys[0]]), options: {
66
+ lineNumbers: 'off',
67
+ wordWrap: 'on',
68
+ glyphMargin: false,
69
+ folding: false,
70
+ lineDecorationsWidth: 0,
71
+ lineNumbersMinChars: 0,
72
+ minimap: {
73
+ enabled: false,
74
+ },
75
+ }, onChange: (expression) => {
76
+ var _a;
77
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, filterEmpty({
78
+ ...value,
79
+ [selectKeys[0]]: `{{${expression}}}`,
80
+ }));
81
+ } })),
82
+ React.createElement("div", { className: prefix + '-coder-end' }, `)`))));
83
+ };