@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
@@ -0,0 +1,282 @@
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
+ import { clone, uid } from '@formily/shared';
3
+ import { createForm, isVoidField } from '@formily/core';
4
+ import { createSchemaField } from '@formily/react';
5
+ import { GlobalRegistry } from '@formily-design/core';
6
+ import { requestIdle } from '@formily-design/shared';
7
+ import { usePrefix, TextWidget } from '@formily-design/react';
8
+ import { MonacoInput } from '@formily-design/react-settings-form';
9
+ import { Form, ArrayTable, Input, Select, FormItem, FormCollapse, } from '@formily/antd-v5';
10
+ import { Modal, Card, Button, Tag, Tooltip } from 'antd';
11
+ import { PathSelector } from './PathSelector';
12
+ import { FieldPropertySetter } from './FieldPropertySetter';
13
+ import { FulfillRunHelper } from './helpers';
14
+ import { initDeclaration } from './declarations';
15
+ import './styles.less';
16
+ const TypeView = ({ value }) => {
17
+ const text = String(value);
18
+ if (text.length <= 26)
19
+ return React.createElement(Tag, null, text);
20
+ return (React.createElement(Tag, null,
21
+ React.createElement(Tooltip, { title: React.createElement("div", { style: { fontSize: 12 } },
22
+ React.createElement("code", null,
23
+ React.createElement("pre", { style: { whiteSpace: 'pre-wrap', padding: 0, margin: 0 } }, text))) },
24
+ text.substring(0, 24),
25
+ "...")));
26
+ };
27
+ const SchemaField = createSchemaField({
28
+ components: {
29
+ Card,
30
+ FormCollapse,
31
+ Input,
32
+ TypeView,
33
+ Select,
34
+ FormItem,
35
+ PathSelector,
36
+ FieldPropertySetter,
37
+ ArrayTable,
38
+ MonacoInput,
39
+ },
40
+ });
41
+ const FieldStateProperties = [
42
+ 'value',
43
+ 'initialValue',
44
+ 'inputValue',
45
+ 'inputValues',
46
+ 'modified',
47
+ 'initialized',
48
+ 'title',
49
+ 'description',
50
+ 'mounted',
51
+ 'unmounted',
52
+ 'active',
53
+ 'visited',
54
+ 'loading',
55
+ 'errors',
56
+ 'warnings',
57
+ 'successes',
58
+ 'feedbacks',
59
+ 'valid',
60
+ 'invalid',
61
+ 'pattern',
62
+ 'display',
63
+ 'disabled',
64
+ 'readOnly',
65
+ 'readPretty',
66
+ 'visible',
67
+ 'hidden',
68
+ 'editable',
69
+ 'validateStatus',
70
+ 'validating',
71
+ ];
72
+ const FieldStateValueTypes = {
73
+ modified: 'boolean',
74
+ initialized: 'boolean',
75
+ title: 'string',
76
+ description: 'string',
77
+ mounted: 'boolean',
78
+ unmounted: 'boolean',
79
+ active: 'boolean',
80
+ visited: 'boolean',
81
+ loading: 'boolean',
82
+ errors: 'string[]',
83
+ warnings: 'string[]',
84
+ successes: 'string[]',
85
+ feedbacks: `Array<
86
+ triggerType?: 'onInput' | 'onFocus' | 'onBlur'
87
+ type?: 'error' | 'success' | 'warning'
88
+ code?:
89
+ | 'ValidateError'
90
+ | 'ValidateSuccess'
91
+ | 'ValidateWarning'
92
+ | 'EffectError'
93
+ | 'EffectSuccess'
94
+ | 'EffectWarning'
95
+ messages?: string[]
96
+ >
97
+ `,
98
+ valid: 'boolean',
99
+ invalid: 'boolean',
100
+ pattern: "'editable' | 'disabled' | 'readOnly' | 'readPretty'",
101
+ display: "'visible' | 'hidden' | 'none'",
102
+ disabled: 'boolean',
103
+ readOnly: 'boolean',
104
+ readPretty: 'boolean',
105
+ visible: 'boolean',
106
+ hidden: 'boolean',
107
+ editable: 'boolean',
108
+ validateStatus: "'error' | 'warning' | 'success' | 'validating'",
109
+ validating: 'boolean',
110
+ };
111
+ export const ReactionsSetter = (props) => {
112
+ const [modalVisible, setModalVisible] = useState(false);
113
+ const [innerVisible, setInnerVisible] = useState(false);
114
+ const prefix = usePrefix('reactions-setter');
115
+ const form = useMemo(() => {
116
+ return createForm({
117
+ values: clone(props.value),
118
+ });
119
+ }, [modalVisible, props.value]);
120
+ const formCollapse = useMemo(() => FormCollapse.createFormCollapse(['deps', 'state']), [modalVisible]);
121
+ const openModal = () => setModalVisible(true);
122
+ const closeModal = () => setModalVisible(false);
123
+ useEffect(() => {
124
+ if (modalVisible) {
125
+ requestIdle(() => {
126
+ initDeclaration().then(() => {
127
+ setInnerVisible(true);
128
+ });
129
+ }, {
130
+ timeout: 400,
131
+ });
132
+ }
133
+ else {
134
+ setInnerVisible(false);
135
+ }
136
+ }, [modalVisible]);
137
+ return (React.createElement(React.Fragment, null,
138
+ React.createElement(Button, { block: true, onClick: openModal },
139
+ React.createElement(TextWidget, { token: "SettingComponents.ReactionsSetter.configureReactions" })),
140
+ React.createElement(Modal, { title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.configureReactions'), width: "70%", centered: true, bodyStyle: { padding: 10 }, transitionName: "", maskTransitionName: "", visible: modalVisible, onCancel: closeModal, destroyOnClose: true, onOk: () => {
141
+ form.submit((values) => {
142
+ var _a;
143
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, values);
144
+ });
145
+ closeModal();
146
+ } },
147
+ React.createElement("div", { className: prefix }, innerVisible && (React.createElement(Form, { form: form },
148
+ React.createElement(SchemaField, null,
149
+ React.createElement(SchemaField.Void, { "x-component": "FormCollapse", "x-component-props": {
150
+ formCollapse,
151
+ defaultActiveKey: ['deps', 'state'],
152
+ style: { marginBottom: 10 },
153
+ } },
154
+ React.createElement(SchemaField.Void, { "x-component": "FormCollapse.CollapsePanel", "x-component-props": {
155
+ key: 'deps',
156
+ header: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.relationsFields'),
157
+ } },
158
+ React.createElement(SchemaField.Array, { name: "dependencies", default: [{}], "x-component": "ArrayTable" },
159
+ React.createElement(SchemaField.Object, null,
160
+ React.createElement(SchemaField.Void, { "x-component": "ArrayTable.Column", "x-component-props": {
161
+ title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.sourceField'),
162
+ width: 240,
163
+ } },
164
+ React.createElement(SchemaField.String, { name: "source", "x-decorator": "FormItem", "x-component": "PathSelector", "x-component-props": {
165
+ placeholder: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.pleaseSelect'),
166
+ } })),
167
+ React.createElement(SchemaField.Void, { "x-component": "ArrayTable.Column", "x-component-props": {
168
+ title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.sourceProperty'),
169
+ width: 200,
170
+ } },
171
+ React.createElement(SchemaField.String, { name: "property", default: "value", "x-decorator": "FormItem", "x-component": "Select", "x-component-props": { showSearch: true }, enum: FieldStateProperties })),
172
+ React.createElement(SchemaField.Void, { "x-component": "ArrayTable.Column", "x-component-props": {
173
+ title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.variableName'),
174
+ width: 200,
175
+ } },
176
+ React.createElement(SchemaField.String, { name: "name", "x-decorator": "FormItem", "x-validator": {
177
+ pattern: /^[$_a-zA-Z]+[$_a-zA-Z0-9]*$/,
178
+ message: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.variableNameValidateMessage'),
179
+ }, "x-component": "Input", "x-component-props": {
180
+ addonBefore: '$deps.',
181
+ placeholder: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.pleaseInput'),
182
+ }, "x-reactions": (field) => {
183
+ if (isVoidField(field))
184
+ return;
185
+ field.query('.source').take((source) => {
186
+ var _a, _b;
187
+ if (isVoidField(source))
188
+ return;
189
+ if (source.value &&
190
+ !field.value &&
191
+ !field.modified) {
192
+ field.value =
193
+ ((_b = (_a = source.inputValues[1]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.name) ||
194
+ `v_${uid()}`;
195
+ }
196
+ });
197
+ } })),
198
+ React.createElement(SchemaField.Void, { "x-component": "ArrayTable.Column", "x-component-props": {
199
+ title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.variableType'),
200
+ ellipsis: {
201
+ showTitle: false,
202
+ },
203
+ width: 200,
204
+ align: 'center',
205
+ } },
206
+ React.createElement(SchemaField.String, { name: "type", default: "any", "x-decorator": "FormItem", "x-component": "TypeView", "x-reactions": (field) => {
207
+ if (isVoidField(field))
208
+ return;
209
+ const property = field
210
+ .query('.property')
211
+ .get('inputValues');
212
+ if (!property)
213
+ return;
214
+ property[0] = property[0] || 'value';
215
+ field.query('.source').take((source) => {
216
+ var _a, _b;
217
+ if (isVoidField(source))
218
+ return;
219
+ if (source.value) {
220
+ if (property[0] === 'value' ||
221
+ property[0] === 'initialValue' ||
222
+ property[0] === 'inputValue') {
223
+ field.value =
224
+ ((_b = (_a = source.inputValues[1]) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.type) ||
225
+ 'any';
226
+ }
227
+ else if (property[0] === 'inputValues') {
228
+ field.value = `any[]`;
229
+ }
230
+ else if (property[0]) {
231
+ field.value =
232
+ FieldStateValueTypes[property[0]];
233
+ }
234
+ else {
235
+ field.value = 'any';
236
+ }
237
+ }
238
+ });
239
+ } })),
240
+ React.createElement(SchemaField.Void, { "x-component": "ArrayTable.Column", "x-component-props": {
241
+ title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.operations'),
242
+ align: 'center',
243
+ width: 80,
244
+ } },
245
+ React.createElement(SchemaField.Markup, { type: "void", "x-component": "ArrayTable.Remove" }))),
246
+ React.createElement(SchemaField.Void, { title: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.addRelationField'), "x-component": "ArrayTable.Addition", "x-component-props": { style: { marginTop: 8 } } }))),
247
+ React.createElement(SchemaField.Void, { "x-component": "FormCollapse.CollapsePanel", "x-component-props": {
248
+ header: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.propertyReactions'),
249
+ key: 'state',
250
+ className: 'reaction-state',
251
+ } },
252
+ React.createElement(SchemaField.Markup, { name: "fulfill.state", "x-component": "FieldPropertySetter" })),
253
+ React.createElement(SchemaField.Void, { "x-component": "FormCollapse.CollapsePanel", "x-component-props": {
254
+ key: 'run',
255
+ header: GlobalRegistry.getDesignerMessage('SettingComponents.ReactionsSetter.actionReactions'),
256
+ className: 'reaction-runner',
257
+ } },
258
+ React.createElement(SchemaField.String, { name: "fulfill.run", "x-component": "MonacoInput", "x-component-props": {
259
+ width: '100%',
260
+ height: 400,
261
+ language: 'typescript',
262
+ helpCode: FulfillRunHelper,
263
+ options: {
264
+ minimap: {
265
+ enabled: false,
266
+ },
267
+ },
268
+ }, "x-reactions": (field) => {
269
+ const deps = field.query('dependencies').value();
270
+ if (Array.isArray(deps)) {
271
+ field.componentProps.extraLib = `
272
+ declare var $deps : {
273
+ ${deps.map(({ name, type }) => {
274
+ if (!name)
275
+ return '';
276
+ return `${name}?:${type || 'any'},`;
277
+ })}
278
+ }
279
+ `;
280
+ }
281
+ } }))))))))));
282
+ };
@@ -0,0 +1,11 @@
1
+ export declare const FieldProperties: ({
2
+ key: string;
3
+ type: string;
4
+ helpCode: string;
5
+ token?: undefined;
6
+ } | {
7
+ key: string;
8
+ token: string;
9
+ type: string;
10
+ helpCode: string;
11
+ })[];
@@ -0,0 +1,41 @@
1
+ import { BooleanHelper, PatternHelper, StringHelper, AnyHelper, DataSourceHelper, DecoratorPropsHelper, DisplayHelper, ComponentPropsHelper, } from './helpers';
2
+ export const FieldProperties = [
3
+ {
4
+ key: 'visible',
5
+ type: 'boolean',
6
+ helpCode: BooleanHelper,
7
+ },
8
+ { key: 'hidden', type: 'boolean', helpCode: BooleanHelper },
9
+ {
10
+ key: 'display',
11
+ type: '"visible" | "hidden" | "none"',
12
+ helpCode: DisplayHelper,
13
+ },
14
+ {
15
+ key: 'pattern',
16
+ type: '"editable" | "disabled" | "readOnly" | "readPretty"',
17
+ helpCode: PatternHelper,
18
+ },
19
+ { key: 'title', type: 'string', helpCode: StringHelper },
20
+ { key: 'description', type: 'string', helpCode: StringHelper },
21
+ { key: 'value', type: 'any', helpCode: AnyHelper },
22
+ { key: 'initialValue', type: 'any', helpCode: AnyHelper },
23
+ { key: 'required', type: 'boolean', helpCode: BooleanHelper },
24
+ {
25
+ key: 'dataSource',
26
+ type: 'Array<{label?:string,value?:any}>',
27
+ helpCode: DataSourceHelper,
28
+ },
29
+ {
30
+ key: 'componentProps',
31
+ token: 'componentProps',
32
+ type: 'object',
33
+ helpCode: ComponentPropsHelper,
34
+ },
35
+ {
36
+ key: 'decoratorProps',
37
+ token: 'decoratorProps',
38
+ type: 'object',
39
+ helpCode: DecoratorPropsHelper,
40
+ },
41
+ ];
@@ -0,0 +1,103 @@
1
+ .dn-reactions-setter {
2
+ width: 100%;
3
+ min-height: 623px;
4
+ overflow: hidden;
5
+
6
+ ::-webkit-scrollbar {
7
+ width: 5px;
8
+ height: 5px;
9
+ }
10
+
11
+ ::-webkit-scrollbar-thumb {
12
+ background-color: rgba(0, 0, 0, 0.2);
13
+ border-radius: 0;
14
+ transition: all 0.25s ease-in-out;
15
+ }
16
+
17
+ ::-webkit-scrollbar-thumb:hover {
18
+ background-color: rgba(0, 0, 0, 0.3);
19
+ }
20
+
21
+ .ant-collapse {
22
+ border: 1px solid #d9d9d9;
23
+
24
+ &-header {
25
+ padding: 8px 10px !important;
26
+
27
+ border-bottom: 1px solid #d9d9d9 !important;
28
+ font-weight: 500 !important;
29
+
30
+ .ant-collapse-arrow {
31
+ margin-right: 4px !important;
32
+ }
33
+ }
34
+
35
+ &-item {
36
+ border: none !important;
37
+ }
38
+
39
+ &-content {
40
+ border: none !important;
41
+ transition: none !important;
42
+ }
43
+
44
+ &-content-box {
45
+ padding: 12px !important;
46
+ }
47
+ }
48
+
49
+ .reaction-runner {
50
+ .ant-collapse-content-box {
51
+ padding: 12px 0 !important;
52
+ }
53
+ }
54
+
55
+ .reaction-state {
56
+ .ant-collapse-content-box {
57
+ padding: 12px 0 !important;
58
+ }
59
+ }
60
+
61
+ .dn-field-property-setter {
62
+ display: flex;
63
+ height: 300px;
64
+
65
+ &-coder-wrapper {
66
+ display: flex;
67
+ flex-grow: 2;
68
+ height: 100%;
69
+ padding-left: 10px;
70
+ position: relative;
71
+ flex-direction: column;
72
+ }
73
+
74
+ &-coder-start {
75
+ font-size: 18px;
76
+ line-height: 30px;
77
+ margin-bottom: 4px;
78
+
79
+ font-weight: 300;
80
+ flex-grow: 0;
81
+ opacity: 0.96;
82
+ height: 31px;
83
+ }
84
+
85
+ &-coder-end {
86
+ font-size: 18px;
87
+ height: 31px;
88
+
89
+ margin-top: 4px;
90
+ margin-bottom: 4px;
91
+ line-height: 30px;
92
+ font-weight: 300;
93
+ flex-grow: 0;
94
+ opacity: 0.96;
95
+ }
96
+
97
+ &-coder {
98
+ min-width: 0;
99
+ flex-grow: 2;
100
+ padding-left: 10px;
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,13 @@
1
+ export interface IReaction {
2
+ dependencies?: {
3
+ [key: string]: string;
4
+ };
5
+ fulfill?: {
6
+ state?: {
7
+ [key: string]: string;
8
+ };
9
+ schema?: {
10
+ [key: string]: string;
11
+ };
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import './styles.less';
3
+ import { IRemoteDataSource } from './types';
4
+ export interface IRemoteDataSourcePanelProps {
5
+ value?: IRemoteDataSource;
6
+ onChange: (value: IRemoteDataSource) => void;
7
+ }
8
+ export declare const RemoteDataSourcePanel: React.FC<IRemoteDataSourcePanelProps>;
@@ -0,0 +1,103 @@
1
+ import React, { useEffect } from 'react';
2
+ import { Form, Input, Select, Tabs, Button } from 'antd';
3
+ import { MonacoInput } from '@formily-design/react-settings-form';
4
+ import { usePrefix, TextWidget } from '@formily-design/react';
5
+ import './styles.less';
6
+ /** 转换配置数据为表单数据 */
7
+ function toFormValues(dataSourceConfig) {
8
+ return {
9
+ ...dataSourceConfig,
10
+ headers: Object.entries(dataSourceConfig.headers || {}).map(([key, value]) => ({ key, value })),
11
+ params: Object.entries(dataSourceConfig.params || {}).map(([key, value]) => ({ key, value })),
12
+ };
13
+ }
14
+ /** 转换表单数据为配置数据 */
15
+ function toDataSourceConfigData(values) {
16
+ var _a, _b;
17
+ return {
18
+ ...values,
19
+ headers: (_a = values.headers) === null || _a === void 0 ? void 0 : _a.reduce((pre, cur) => {
20
+ pre[cur.key] = cur.value;
21
+ return pre;
22
+ }, {}),
23
+ params: (_b = values.params) === null || _b === void 0 ? void 0 : _b.reduce((pre, cur) => {
24
+ pre[cur.key] = cur.value;
25
+ return pre;
26
+ }, {}),
27
+ };
28
+ }
29
+ export const RemoteDataSourcePanel = (props) => {
30
+ const prefix = usePrefix('remote-data-source-panel');
31
+ const { value, onChange } = props;
32
+ const [form] = Form.useForm();
33
+ useEffect(() => {
34
+ if (value) {
35
+ form.setFieldsValue(toFormValues(value));
36
+ }
37
+ }, [value]);
38
+ const handleValuesChange = () => {
39
+ onChange(toDataSourceConfigData(form.getFieldsValue()));
40
+ };
41
+ const tabsItems = [
42
+ {
43
+ key: 'basic',
44
+ label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.basic" }),
45
+ children: (React.createElement("div", { className: `${prefix}-section` },
46
+ React.createElement(Form, { form: form, layout: "vertical", onValuesChange: handleValuesChange },
47
+ React.createElement(Form.Item, { label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.url" }), name: "url" },
48
+ React.createElement(Input, { placeholder: "https://api.example.com/data" })),
49
+ React.createElement(Form.Item, { label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.method" }), name: "method" },
50
+ React.createElement(Select, { options: [
51
+ { label: 'GET', value: 'GET' },
52
+ { label: 'POST', value: 'POST' },
53
+ { label: 'PUT', value: 'PUT' },
54
+ { label: 'DELETE', value: 'DELETE' },
55
+ { label: 'PATCH', value: 'PATCH' },
56
+ ] }))))),
57
+ },
58
+ {
59
+ key: 'headers',
60
+ label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.headers" }),
61
+ children: (React.createElement("div", { className: `${prefix}-section` },
62
+ React.createElement(Form, { form: form, layout: "vertical", onValuesChange: handleValuesChange },
63
+ React.createElement(Form.List, { name: "headers" }, (fields, { add, remove }) => (React.createElement(React.Fragment, null,
64
+ fields.map((field) => (React.createElement("div", { key: field.key, className: `${prefix}-row` },
65
+ React.createElement(Form.Item, { ...field, label: "", style: { marginBottom: 0 }, name: [field.name, 'key'] },
66
+ React.createElement(Input, { placeholder: "Key", style: { width: '45%' } })),
67
+ React.createElement("span", { style: { margin: '0 8px' } }, "-"),
68
+ React.createElement(Form.Item, { style: { marginBottom: 0 }, name: [field.name, 'value'] },
69
+ React.createElement(Input, { placeholder: "Value", style: { width: '45%' } })),
70
+ React.createElement(Button, { type: "text", danger: true, onClick: () => remove(field.name), style: { marginLeft: 8 } }, "X")))),
71
+ React.createElement(Button, { type: "dashed", onClick: () => add({ key: '', value: '' }), block: true },
72
+ React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.addHeader" })))))))),
73
+ },
74
+ {
75
+ key: 'params',
76
+ label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.params" }),
77
+ children: (React.createElement("div", { className: `${prefix}-section` },
78
+ React.createElement(Form, { form: form, layout: "vertical", onValuesChange: handleValuesChange },
79
+ React.createElement(Form.List, { name: "params" }, (fields, { add, remove }) => (React.createElement(React.Fragment, null,
80
+ fields.map((field) => (React.createElement("div", { key: field.key, className: `${prefix}-row` },
81
+ React.createElement(Form.Item, { ...field, label: "", style: { marginBottom: 0 }, name: [field.name, 'key'] },
82
+ React.createElement(Input, { placeholder: "Key", style: { width: '45%' } })),
83
+ React.createElement("span", { style: { margin: '0 8px' } }, "-"),
84
+ React.createElement(Form.Item, { style: { marginBottom: 0 }, name: [field.name, 'value'] },
85
+ React.createElement(Input, { placeholder: "Value", style: { width: '45%' } })),
86
+ React.createElement(Button, { type: "text", danger: true, onClick: () => remove(field.name), style: { marginLeft: 8 } }, "X")))),
87
+ React.createElement(Button, { type: "dashed", onClick: () => add({ key: '', value: '' }), block: true },
88
+ React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.addParam" })))))))),
89
+ },
90
+ {
91
+ key: 'handlers',
92
+ label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.handlers" }),
93
+ children: (React.createElement("div", { className: `${prefix}-section` },
94
+ React.createElement(Form, { form: form, layout: "vertical", onValuesChange: handleValuesChange },
95
+ React.createElement(Form.Item, { label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.beforeRequest" }), name: "beforeRequest" },
96
+ React.createElement(MonacoInput, { language: "javascript.expression", height: 150, helpLink: false })),
97
+ React.createElement(Form.Item, { label: React.createElement(TextWidget, { token: "SettingComponents.RemoteDataSource.dataHandler" }), name: "dataHandler" },
98
+ React.createElement(MonacoInput, { language: "javascript.expression", height: 150, helpLink: false }))))),
99
+ },
100
+ ];
101
+ return (React.createElement("div", { className: prefix },
102
+ React.createElement(Tabs, { items: tabsItems, defaultActiveKey: "basic", size: "small" })));
103
+ };
@@ -0,0 +1,17 @@
1
+ import { Form } from '@formily/core';
2
+ import React from 'react';
3
+ import { IRemoteDataSource } from './types';
4
+ export interface IRemoteDataSourceSetterProps {
5
+ className?: string;
6
+ style?: React.CSSProperties;
7
+ onChange: (dataSource: IRemoteDataSource) => void;
8
+ value: IRemoteDataSource;
9
+ allowTree?: boolean;
10
+ allowExtendOption?: boolean;
11
+ defaultOptionValue?: {
12
+ label: string;
13
+ value: any;
14
+ }[];
15
+ effects?: (form: Form<any>) => void;
16
+ }
17
+ export declare const RemoteDataSourceSetter: React.FC<IRemoteDataSourceSetterProps>;
@@ -0,0 +1,25 @@
1
+ import React, { Fragment, useState } from 'react';
2
+ import { Button, Modal } from 'antd';
3
+ import { TextWidget, usePrefix, useTheme } from '@formily-design/react';
4
+ import { RemoteDataSourcePanel } from './RemoteDataSourcePanel';
5
+ import cls from 'classnames';
6
+ import { observer } from '@formily/react';
7
+ export const RemoteDataSourceSetter = observer((props) => {
8
+ const { onChange, value, className } = props;
9
+ const theme = useTheme();
10
+ const prefix = usePrefix('remote-data-source-setter');
11
+ const [modalVisible, setModalVisible] = useState(false);
12
+ const [currentRemoteData, setCurrentRemoteData] = useState(value);
13
+ const openModal = () => setModalVisible(true);
14
+ const closeModal = () => setModalVisible(false);
15
+ const handleOk = () => {
16
+ onChange(currentRemoteData);
17
+ closeModal();
18
+ };
19
+ return (React.createElement(Fragment, null,
20
+ React.createElement(Button, { block: true, onClick: openModal },
21
+ React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.editConfigure" })),
22
+ React.createElement(Modal, { title: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.editConfigure" }), width: "65%", styles: { body: { padding: 10 } }, transitionName: "", maskTransitionName: "", open: modalVisible, onCancel: closeModal, onOk: handleOk, okText: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.confirm" }), cancelText: React.createElement(TextWidget, { token: "SettingComponents.DataSourceSetter.cancel" }) },
23
+ React.createElement("div", { className: `${cls(prefix, className)} ${prefix + '-' + theme} ${prefix + '-layout'}` },
24
+ React.createElement(RemoteDataSourcePanel, { value: currentRemoteData, onChange: setCurrentRemoteData })))));
25
+ });
@@ -0,0 +1,33 @@
1
+ .dn-data-source-setter {
2
+ ::-webkit-scrollbar {
3
+ width: 5px;
4
+ height: 5px;
5
+ }
6
+
7
+ ::-webkit-scrollbar-thumb {
8
+ background-color: rgba(0, 0, 0, 0.2);
9
+ border-radius: 0;
10
+ transition: all 0.25s ease-in-out;
11
+ }
12
+
13
+ ::-webkit-scrollbar-thumb:hover {
14
+ background-color: rgba(0, 0, 0, 0.3);
15
+ }
16
+
17
+ &-tabs {
18
+ margin-bottom: 8px;
19
+ }
20
+ }
21
+
22
+ .dn-remote-data-source-panel {
23
+ &-section {
24
+ padding: 16px;
25
+ min-height: 300px;
26
+ }
27
+
28
+ &-row {
29
+ display: flex;
30
+ align-items: center;
31
+ margin-bottom: 8px;
32
+ }
33
+ }
@@ -0,0 +1,8 @@
1
+ export interface IRemoteDataSource {
2
+ url: string;
3
+ method: string;
4
+ headers?: Record<string, string>;
5
+ params?: Record<string, string>;
6
+ beforeRequest?: string;
7
+ dataHandler?: string;
8
+ }
@@ -0,0 +1 @@
1
+ export {};