@teamix/pro 1.1.29 → 1.1.33
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/dist/pro.css +1 -1
- package/dist/pro.js +1329 -892
- package/dist/pro.min.css +1 -1
- package/dist/pro.min.js +1 -1
- package/es/actions/dialog-form.js +3 -1
- package/es/actions/dialog.d.ts +0 -2
- package/es/actions/dialog.js +16 -23
- package/es/actions/index.js +13 -8
- package/es/actions/link.d.ts +2 -8
- package/es/actions/link.js +2 -22
- package/es/actions/request.d.ts +1 -1
- package/es/actions/request.js +6 -3
- package/es/form/Components/FormGroup/index.scss +1 -1
- package/es/form/Components/ProField/index.d.ts +4 -0
- package/es/form/Components/Query/index.scss +1 -6
- package/es/form/Components/Text/index.scss +4 -2
- package/es/form/ProForm/index.js +3 -16
- package/es/form/ProForm/index.scss +4 -11
- package/es/form/ProForm/useAutoSubmit.js +3 -1
- package/es/form/ProForm/useFormDisplayValues.d.ts +6 -0
- package/es/form/ProForm/useFormDisplayValues.js +65 -0
- package/es/form/SchemaForm/adapterType.js +2 -1
- package/es/form/SchemaForm/index.js +5 -15
- package/es/form/SchemaForm/initializeProField.js +1 -0
- package/es/form/SchemaForm/initializeReactions.d.ts +2 -0
- package/es/form/SchemaForm/initializeReactions.js +89 -0
- package/es/form/SchemaForm/reactions.js +10 -2
- package/es/form/global.scss +12 -0
- package/es/form/index.d.ts +3 -3
- package/es/form/index.js +3 -3
- package/es/form/typing.d.ts +2 -2
- package/es/form/utils.d.ts +31 -8
- package/es/form/utils.js +27 -44
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/info/components/ProInfoItem/index.js +4 -2
- package/es/table/components/Filter/index.js +6 -2
- package/es/table/index.js +15 -3
- package/es/table/typing.d.ts +8 -4
- package/es/table/utils/columnRender.js +38 -11
- package/lib/actions/dialog-form.js +4 -1
- package/lib/actions/dialog.d.ts +0 -2
- package/lib/actions/dialog.js +15 -23
- package/lib/actions/index.js +12 -7
- package/lib/actions/link.d.ts +2 -8
- package/lib/actions/link.js +2 -25
- package/lib/actions/request.d.ts +1 -1
- package/lib/actions/request.js +7 -3
- package/lib/form/Components/FormGroup/index.scss +1 -1
- package/lib/form/Components/ProField/index.d.ts +4 -0
- package/lib/form/Components/Query/index.scss +1 -6
- package/lib/form/Components/Text/index.scss +4 -2
- package/lib/form/ProForm/index.js +2 -15
- package/lib/form/ProForm/index.scss +4 -11
- package/lib/form/ProForm/useAutoSubmit.js +4 -1
- package/lib/form/ProForm/useFormDisplayValues.d.ts +6 -0
- package/lib/form/ProForm/useFormDisplayValues.js +74 -0
- package/lib/form/SchemaForm/adapterType.js +2 -1
- package/lib/form/SchemaForm/index.js +5 -14
- package/lib/form/SchemaForm/initializeProField.js +1 -0
- package/lib/form/SchemaForm/initializeReactions.d.ts +2 -0
- package/lib/form/SchemaForm/initializeReactions.js +101 -0
- package/lib/form/SchemaForm/reactions.js +10 -2
- package/lib/form/global.scss +12 -0
- package/lib/form/index.d.ts +3 -3
- package/lib/form/index.js +15 -8
- package/lib/form/typing.d.ts +2 -2
- package/lib/form/utils.d.ts +31 -8
- package/lib/form/utils.js +28 -54
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/info/components/ProInfoItem/index.js +3 -1
- package/lib/table/components/Filter/index.js +6 -2
- package/lib/table/index.js +15 -3
- package/lib/table/typing.d.ts +8 -4
- package/lib/table/utils/columnRender.js +38 -11
- package/package.json +4 -4
package/lib/actions/dialog.js
CHANGED
@@ -18,8 +18,6 @@ var _utils = require("@teamix/utils");
|
|
18
18
|
|
19
19
|
var _base = require("./base");
|
20
20
|
|
21
|
-
var _link = require("./link");
|
22
|
-
|
23
21
|
var _request = require("./request");
|
24
22
|
|
25
23
|
var _excluded = ["url", "method", "params", "data", "extendParams", "successMsg", "errorMsg", "formatParams", "formatResult", "onSuccess", "onError"],
|
@@ -115,50 +113,44 @@ function useDialogAction(action, context) {
|
|
115
113
|
while (1) {
|
116
114
|
switch (_context.prev = _context.next) {
|
117
115
|
case 0:
|
118
|
-
if (
|
116
|
+
if (url) {
|
119
117
|
_context.next = 5;
|
120
118
|
break;
|
121
119
|
}
|
122
120
|
|
123
|
-
|
124
|
-
|
125
|
-
resolve(true);
|
126
|
-
return _context.abrupt("return");
|
127
|
-
|
128
|
-
case 5:
|
129
|
-
if (url) {
|
130
|
-
_context.next = 9;
|
131
|
-
break;
|
121
|
+
if (link) {
|
122
|
+
(0, _utils.goToLink)(link, history);
|
132
123
|
}
|
133
124
|
|
134
125
|
onFinish && onFinish();
|
135
126
|
resolve(true);
|
136
127
|
return _context.abrupt("return");
|
137
128
|
|
138
|
-
case
|
129
|
+
case 5:
|
139
130
|
setLoading(true);
|
140
|
-
_context.prev =
|
141
|
-
_context.next =
|
142
|
-
return (0, _request.doRequest)(action, context);
|
131
|
+
_context.prev = 6;
|
132
|
+
_context.next = 9;
|
133
|
+
return (0, _request.doRequest)(action, context, history);
|
143
134
|
|
144
|
-
case
|
135
|
+
case 9:
|
145
136
|
onFinish && onFinish();
|
146
137
|
resolve(true);
|
147
|
-
_context.next =
|
138
|
+
_context.next = 18;
|
148
139
|
break;
|
149
140
|
|
150
|
-
case
|
151
|
-
_context.prev =
|
152
|
-
_context.t0 = _context["catch"](
|
141
|
+
case 13:
|
142
|
+
_context.prev = 13;
|
143
|
+
_context.t0 = _context["catch"](6);
|
153
144
|
setLoading(false);
|
154
145
|
resolve(false);
|
146
|
+
return _context.abrupt("return");
|
155
147
|
|
156
|
-
case
|
148
|
+
case 18:
|
157
149
|
case "end":
|
158
150
|
return _context.stop();
|
159
151
|
}
|
160
152
|
}
|
161
|
-
}, _callee, null, [[
|
153
|
+
}, _callee, null, [[6, 13]]);
|
162
154
|
}));
|
163
155
|
|
164
156
|
return function (_x) {
|
package/lib/actions/index.js
CHANGED
@@ -156,16 +156,18 @@ var useAction = function useAction(config, context) {
|
|
156
156
|
|
157
157
|
exports.useAction = useAction;
|
158
158
|
|
159
|
-
var buttonContent = function buttonContent(content, iconType, iconSize) {
|
159
|
+
var buttonContent = function buttonContent(content, iconType, iconSize, context) {
|
160
|
+
var renderedContent = typeof content === 'function' ? content(context) : content;
|
161
|
+
|
160
162
|
if (!iconType) {
|
161
|
-
return
|
163
|
+
return renderedContent;
|
162
164
|
}
|
163
165
|
|
164
166
|
return [/*#__PURE__*/_react.default.createElement(_icon.default, {
|
165
167
|
type: iconType,
|
166
168
|
size: iconSize,
|
167
169
|
key: "teamix-button-icon"
|
168
|
-
}),
|
170
|
+
}), renderedContent];
|
169
171
|
};
|
170
172
|
|
171
173
|
var ActionButton = function ActionButton(props) {
|
@@ -189,7 +191,7 @@ var ActionButton = function ActionButton(props) {
|
|
189
191
|
}) : _objectSpread(_objectSpread({}, actionProps), others);
|
190
192
|
return /*#__PURE__*/_react.default.createElement(_components.Button, _objectSpread({
|
191
193
|
type: type
|
192
|
-
}, buttonProps), buttonContent(children, icon, iconSize));
|
194
|
+
}, buttonProps), buttonContent(children, icon, iconSize, context));
|
193
195
|
};
|
194
196
|
|
195
197
|
exports.ActionButton = ActionButton;
|
@@ -210,7 +212,7 @@ function renderMenuButtonItem(item, key, context) {
|
|
210
212
|
}) : _objectSpread({}, menuItemProps);
|
211
213
|
return /*#__PURE__*/_react.default.createElement(_components.MenuButton.Item, _objectSpread({
|
212
214
|
key: key
|
213
|
-
}, buttonProps), buttonContent(item.children, item.icon));
|
215
|
+
}, buttonProps), buttonContent(item.children, item.icon, undefined, context));
|
214
216
|
}
|
215
217
|
|
216
218
|
function renderCommonActionButtonMenuItem(action, key, context) {
|
@@ -246,8 +248,11 @@ var ActionMenuButton = function ActionMenuButton(props) {
|
|
246
248
|
mode: 'popup',
|
247
249
|
triggerType: 'hover'
|
248
250
|
},
|
251
|
+
popupProps: {
|
252
|
+
shouldUpdatePosition: true
|
253
|
+
},
|
249
254
|
type: type,
|
250
|
-
label: buttonContent(label || children, icon, iconSize)
|
255
|
+
label: buttonContent(label || children, icon, iconSize, context)
|
251
256
|
}, others), actions.map(function (action, i) {
|
252
257
|
return renderCommonActionButtonMenuItem(action, i, context);
|
253
258
|
}));
|
@@ -295,7 +300,7 @@ function renderCommonActionButton(button, context, isTypeText) {
|
|
295
300
|
function getDefaultMoreButton(type, moreText) {
|
296
301
|
if (type === 'button') {
|
297
302
|
return {
|
298
|
-
label: moreText || '
|
303
|
+
label: moreText || (0, _utils.getMessage)('more')
|
299
304
|
};
|
300
305
|
}
|
301
306
|
|
package/lib/actions/link.d.ts
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
+
import { LocationHistory } from '@teamix/utils';
|
1
2
|
import { BaseAction } from './base';
|
2
|
-
export interface
|
3
|
-
to: string;
|
4
|
-
search?: string;
|
5
|
-
hash?: string;
|
6
|
-
blank?: boolean;
|
3
|
+
export interface LinkAction extends BaseAction, LocationHistory {
|
7
4
|
}
|
8
|
-
export interface LinkAction extends BaseAction, LinkBase {
|
9
|
-
}
|
10
|
-
export declare function goToLink(link: LinkBase, history: any): void;
|
11
5
|
export declare function useLinkAction(action: LinkAction, context?: any): {
|
12
6
|
[x: string]: (e: import("react").MouseEvent<HTMLElement, MouseEvent>) => void;
|
13
7
|
};
|
package/lib/actions/link.js
CHANGED
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
exports.goToLink = goToLink;
|
8
7
|
exports.useLinkAction = useLinkAction;
|
9
8
|
|
10
|
-
var _reactRouterDom = require("react-router-dom");
|
11
|
-
|
12
9
|
var _utils = require("@teamix/utils");
|
13
10
|
|
14
11
|
var _base = require("./base");
|
@@ -19,27 +16,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
19
16
|
|
20
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
21
18
|
|
22
|
-
function goToLink(link, history) {
|
23
|
-
var to = link.to,
|
24
|
-
search = link.search,
|
25
|
-
hash = link.hash,
|
26
|
-
blank = link.blank;
|
27
|
-
|
28
|
-
if (blank) {
|
29
|
-
window.open("".concat(to).concat(search ? "?".concat(search) : '').concat(hash ? "#".concat(hash) : ''));
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
|
33
|
-
history.push({
|
34
|
-
pathname: to,
|
35
|
-
search: search,
|
36
|
-
hash: hash
|
37
|
-
});
|
38
|
-
}
|
39
|
-
|
40
19
|
function useLinkAction(action, context) {
|
41
|
-
var history = (0, _reactRouterDom.useHistory)();
|
42
|
-
|
43
20
|
var _getTargetValue = (0, _utils.getTargetValue)(action, context),
|
44
21
|
to = _getTargetValue.to,
|
45
22
|
search = _getTargetValue.search,
|
@@ -47,12 +24,12 @@ function useLinkAction(action, context) {
|
|
47
24
|
blank = _getTargetValue.blank;
|
48
25
|
|
49
26
|
return _objectSpread({}, (0, _base.eventHandler)(action, function () {
|
50
|
-
goToLink({
|
27
|
+
(0, _utils.goToLink)({
|
51
28
|
to: to,
|
52
29
|
search: search,
|
53
30
|
hash: hash,
|
54
31
|
blank: blank
|
55
|
-
}
|
32
|
+
});
|
56
33
|
}));
|
57
34
|
}
|
58
35
|
|
package/lib/actions/request.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { CommonRequestConfig } from '@teamix/utils';
|
|
2
2
|
import { BaseAction } from './base';
|
3
3
|
export interface RequestAction extends CommonRequestConfig, BaseAction {
|
4
4
|
}
|
5
|
-
export declare function doRequest(action: RequestAction, context?: any): Promise<unknown>;
|
5
|
+
export declare function doRequest(action: RequestAction, context?: any, history?: any): Promise<unknown>;
|
6
6
|
export declare function useRequestAction(action: RequestAction, context?: any): {
|
7
7
|
loading: boolean;
|
8
8
|
};
|
package/lib/actions/request.js
CHANGED
@@ -9,6 +9,8 @@ exports.useRequestAction = useRequestAction;
|
|
9
9
|
|
10
10
|
var _react = require("react");
|
11
11
|
|
12
|
+
var _reactRouterDom = require("react-router-dom");
|
13
|
+
|
12
14
|
var _utils = require("@teamix/utils");
|
13
15
|
|
14
16
|
var _base = require("./base");
|
@@ -39,14 +41,14 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
39
41
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
40
42
|
|
41
43
|
// action 里的数据请求都默认是 post 类型
|
42
|
-
function doRequest(action, context) {
|
44
|
+
function doRequest(action, context, history) {
|
43
45
|
var _action$method = action.method,
|
44
46
|
method = _action$method === void 0 ? 'post' : _action$method,
|
45
47
|
others = _objectWithoutProperties(action, _excluded);
|
46
48
|
|
47
49
|
return (0, _utils.doCommonRequest)(_objectSpread({
|
48
50
|
method: method
|
49
|
-
}, others), context);
|
51
|
+
}, others), context, history);
|
50
52
|
}
|
51
53
|
|
52
54
|
function useRequestAction(action, context) {
|
@@ -55,12 +57,14 @@ function useRequestAction(action, context) {
|
|
55
57
|
loading = _useState2[0],
|
56
58
|
setLoading = _useState2[1];
|
57
59
|
|
60
|
+
var history = (0, _reactRouterDom.useHistory)();
|
61
|
+
|
58
62
|
var onFinish = action.onFinish,
|
59
63
|
others = _objectWithoutProperties(action, _excluded2);
|
60
64
|
|
61
65
|
return _objectSpread(_objectSpread({}, (0, _base.eventHandler)(action, function () {
|
62
66
|
setLoading(true);
|
63
|
-
doRequest(_objectSpread({}, others), context).then(function () {
|
67
|
+
doRequest(_objectSpread({}, others), context, history).then(function () {
|
64
68
|
setLoading(false);
|
65
69
|
onFinish && onFinish();
|
66
70
|
}).catch(function () {
|
@@ -143,6 +143,10 @@ declare const _default: React.ForwardRefExoticComponent<(Partial<import("@teamix
|
|
143
143
|
type: "tagFilter";
|
144
144
|
} & {
|
145
145
|
children?: React.ReactNode;
|
146
|
+
}> | Partial<import("@teamix/pro-field/lib/components/FieldTagFilter").IProFieldMultipleTagFilter & {
|
147
|
+
type: "multipleTagPicker";
|
148
|
+
} & {
|
149
|
+
children?: React.ReactNode;
|
146
150
|
}> | Partial<import("@teamix/pro-field/lib/components/FieldMenuSelect").IProFieldMenuSelect & {
|
147
151
|
type: "menuSelect";
|
148
152
|
} & {
|
@@ -1,9 +1,4 @@
|
|
1
|
-
@import '
|
2
|
-
|
3
|
-
$form-item-cls: #{$css-prefix}formily-item;
|
4
|
-
$noborder-font-weight-medium: calc(
|
5
|
-
var(--form-element-medium-height, 32px) - var(--input-border-width, 1px) * 2
|
6
|
-
);
|
1
|
+
@import '../../global.scss';
|
7
2
|
|
8
3
|
// Query样式
|
9
4
|
.#{$css-prefix}filter {
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
@import '../../global.scss';
|
2
2
|
|
3
|
-
|
3
|
+
$teamix-pro-form-text: #{$teamix-pro-form}-text;
|
4
|
+
|
5
|
+
.#{$teamix-pro-form-text} {
|
4
6
|
line-height: var(--form-element-medium-height, 32px);
|
5
7
|
color: var(--color-fill1-6, #848484);
|
6
8
|
}
|
@@ -98,7 +98,7 @@ var ProForm = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
98
98
|
form.addEffects('onChange', function () {
|
99
99
|
(0, _core.onFormValuesChange)(function (form) {
|
100
100
|
if (onChange) {
|
101
|
-
onChange((0, _reactive.toJS)(form.values)
|
101
|
+
onChange((0, _reactive.toJS)(form.values));
|
102
102
|
}
|
103
103
|
});
|
104
104
|
});
|
@@ -112,20 +112,7 @@ var ProForm = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
112
112
|
form.setInitialValues(values);
|
113
113
|
});
|
114
114
|
}
|
115
|
-
}, []);
|
116
|
-
// <Form
|
117
|
-
// className={cls(prefixCls, className)}
|
118
|
-
// {...otherProps}
|
119
|
-
// {...getTeamixLayout}
|
120
|
-
// form={form}
|
121
|
-
// onAutoSubmit={onAutoSubmit}
|
122
|
-
// onAutoSubmitFailed={onSubmitFailed}
|
123
|
-
// >
|
124
|
-
// <SchemaForm schema={schema} scope={scope} components={components} />
|
125
|
-
// {children}
|
126
|
-
// </Form>
|
127
|
-
// );
|
128
|
-
|
115
|
+
}, []);
|
129
116
|
return outerForm === false ?
|
130
117
|
/*#__PURE__*/
|
131
118
|
// 特殊表单,无需渲染form实例,例如FormDialog等
|
@@ -1,14 +1,11 @@
|
|
1
|
-
@import '
|
2
|
-
|
3
|
-
$form-item-cls: #{$css-prefix}formily-item;
|
4
|
-
$teamix-pro-form: teamix-pro-form;
|
1
|
+
@import '../global.scss';
|
5
2
|
|
6
3
|
// FormItem 样式重写
|
7
4
|
.#{$form-item-cls} {
|
8
5
|
// 标签加粗 主题颜色
|
9
6
|
.#{$form-item-cls}-label label {
|
10
7
|
color: var(--form-label-color, #333333);
|
11
|
-
font-weight:
|
8
|
+
font-weight: var(--font-weight-medium, 500);
|
12
9
|
}
|
13
10
|
|
14
11
|
// 溢出label样式
|
@@ -126,10 +123,6 @@ $teamix-pro-form: teamix-pro-form;
|
|
126
123
|
}
|
127
124
|
}
|
128
125
|
|
129
|
-
// 内嵌模式
|
130
|
-
$inset-font-weight-medium: calc(
|
131
|
-
var(--form-element-medium-height, 32px) - var(--input-border-width, 1px) * 2
|
132
|
-
);
|
133
126
|
// 内嵌模式 - 行高
|
134
127
|
.#{$form-item-cls}-inset {
|
135
128
|
line-height: $inset-font-weight-medium;
|
@@ -155,7 +148,7 @@ $inset-font-weight-medium: calc(
|
|
155
148
|
.#{$form-item-cls}-label-content {
|
156
149
|
label {
|
157
150
|
color: var(--color-text1-8, #848484);
|
158
|
-
font-weight:
|
151
|
+
font-weight: normal;
|
159
152
|
}
|
160
153
|
}
|
161
154
|
.#{$form-item-cls}-colon {
|
@@ -193,7 +186,7 @@ $inset-font-weight-medium: calc(
|
|
193
186
|
|
194
187
|
// Editable预览态行高
|
195
188
|
.#{$css-prefix}formily-editable-content {
|
196
|
-
line-height:
|
189
|
+
line-height: var(--form-element-medium-height, 32px);
|
197
190
|
}
|
198
191
|
|
199
192
|
// 折叠面板
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
7
|
|
8
|
+
var _reactRouterDom = require("react-router-dom");
|
9
|
+
|
8
10
|
var _utils = require("@teamix/utils");
|
9
11
|
|
10
12
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
@@ -15,6 +17,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
15
17
|
|
16
18
|
var useAutoSubmit = function useAutoSubmit(onSubmit) {
|
17
19
|
if ((0, _utils.isObj)(onSubmit)) {
|
20
|
+
var history = (0, _reactRouterDom.useHistory)();
|
18
21
|
var submitConfig = onSubmit;
|
19
22
|
return function (values) {
|
20
23
|
return (0, _utils.doCommonRequest)(_objectSpread(_objectSpread({
|
@@ -23,7 +26,7 @@ var useAutoSubmit = function useAutoSubmit(onSubmit) {
|
|
23
26
|
params: _objectSpread(_objectSpread({}, values), submitConfig.params || {})
|
24
27
|
}), {
|
25
28
|
fields: values
|
26
|
-
});
|
29
|
+
}, history);
|
27
30
|
};
|
28
31
|
}
|
29
32
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("@formily/react");
|
9
|
+
|
10
|
+
var _utils = require("@teamix/utils");
|
11
|
+
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
13
|
+
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
15
|
+
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
17
|
+
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
19
|
+
|
20
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
21
|
+
|
22
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
23
|
+
|
24
|
+
/**
|
25
|
+
* 获取表单值的可显示值
|
26
|
+
* @returns 如果某字段有dataSource,则返回value对应label
|
27
|
+
*/
|
28
|
+
var useFormDisplayValues = function useFormDisplayValues() {
|
29
|
+
var form = (0, _react.useForm)();
|
30
|
+
var values = form.values; // 判断值的类型,递归获取每个值在该结构中的完整路径
|
31
|
+
|
32
|
+
var getDisplayValues = function getDisplayValues(values) {
|
33
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
34
|
+
var displayValues;
|
35
|
+
|
36
|
+
if ((0, _utils.isPlainObj)(values)) {
|
37
|
+
displayValues = {};
|
38
|
+
Object.entries(values).forEach(function (_ref) {
|
39
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
40
|
+
key = _ref2[0],
|
41
|
+
value = _ref2[1];
|
42
|
+
|
43
|
+
var path = prefix ? "".concat(prefix, ".").concat(key) : "".concat(key);
|
44
|
+
displayValues[key] = getDisplayValues(value, path);
|
45
|
+
});
|
46
|
+
} else if ((0, _utils.isArr)(values)) {
|
47
|
+
displayValues = [];
|
48
|
+
values.map(function (value, index) {
|
49
|
+
var path = prefix ? "".concat(prefix, ".").concat(index) : "".concat(index);
|
50
|
+
displayValues[index] = getDisplayValues(value, path);
|
51
|
+
});
|
52
|
+
} else {
|
53
|
+
// 通过值的完整路径获取字段address(从form实例的indexes中),然后获取该字段的value在该字段dataSource中对应的label
|
54
|
+
var address = form.indexes[prefix];
|
55
|
+
var field = form.query(address).take();
|
56
|
+
displayValues = (0, _utils.getValueByValue)(field === null || field === void 0 ? void 0 : field.dataSource, values) || values;
|
57
|
+
}
|
58
|
+
|
59
|
+
return displayValues;
|
60
|
+
}; // 测试样例
|
61
|
+
// const example = {
|
62
|
+
// a: [
|
63
|
+
// [{ b: 'a.0.0.b', c: 'a.0.0.c' }, { d: 'a.0.1.d' }],
|
64
|
+
// { e: [{ f: { g: [{ h: 'a.1.e.0.f.g.0.h' }] } }, 'a.1.e.1'] },
|
65
|
+
// ],
|
66
|
+
// };
|
67
|
+
// console.log(getDisplayValues(example));
|
68
|
+
|
69
|
+
|
70
|
+
return getDisplayValues(values);
|
71
|
+
};
|
72
|
+
|
73
|
+
var _default = useFormDisplayValues;
|
74
|
+
exports.default = _default;
|
@@ -35,6 +35,8 @@ var _adapterDecorator = _interopRequireDefault(require("./adapterDecorator"));
|
|
35
35
|
|
36
36
|
var _initializeRequest2 = _interopRequireDefault(require("./initializeRequest"));
|
37
37
|
|
38
|
+
var _initializeReactions = _interopRequireDefault(require("./initializeReactions"));
|
39
|
+
|
38
40
|
var _initializeDataSource2 = _interopRequireDefault(require("./initializeDataSource"));
|
39
41
|
|
40
42
|
var _initializeRules2 = _interopRequireDefault(require("./initializeRules"));
|
@@ -255,21 +257,10 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
255
257
|
|
256
258
|
var _initializeRules = (0, _initializeRules2.default)(rules),
|
257
259
|
defaultRules = _initializeRules.rules,
|
258
|
-
rulesScope = _initializeRules.scope; // 合并reactions
|
259
|
-
|
260
|
-
|
261
|
-
var mergedReactions = function () {
|
262
|
-
var innerReactions = [].concat(_toConsumableArray(requestReactions), _toConsumableArray(dataSourceReactions));
|
263
|
-
|
264
|
-
if (reactions && innerReactions.length) {
|
265
|
-
return (0, _utils.mergeArrayValue)(innerReactions, reactions);
|
266
|
-
} else if (innerReactions.length) {
|
267
|
-
return innerReactions;
|
268
|
-
}
|
260
|
+
rulesScope = _initializeRules.scope; // 合并reactions,初始化reactions
|
269
261
|
|
270
|
-
return reactions;
|
271
|
-
}(); // 合并scope
|
272
262
|
|
263
|
+
var defaultReactions = (0, _initializeReactions.default)(reactions, [].concat(_toConsumableArray(requestReactions), _toConsumableArray(dataSourceReactions))); // 合并scope
|
273
264
|
|
274
265
|
Object.entries(_objectSpread(_objectSpread(_objectSpread({}, requestScope), dataSourceScope), rulesScope)).map(function (_ref2) {
|
275
266
|
var _ref3 = _slicedToArray(_ref2, 2),
|
@@ -284,7 +275,7 @@ var _default = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
284
275
|
decorator: defaultDecorator,
|
285
276
|
decoratorProps: defaultDecoratorProps,
|
286
277
|
rules: defaultRules,
|
287
|
-
reactions:
|
278
|
+
reactions: defaultReactions,
|
288
279
|
dataSource: defaultDataSource
|
289
280
|
})); // 递归子组件
|
290
281
|
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@teamix/utils");
|
9
|
+
|
10
|
+
var _utils2 = require("../utils");
|
11
|
+
|
12
|
+
var _schemaNameMap = _interopRequireDefault(require("../schemaNameMap"));
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19
|
+
|
20
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
21
|
+
|
22
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
23
|
+
|
24
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
25
|
+
|
26
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
27
|
+
|
28
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
29
|
+
|
30
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
31
|
+
|
32
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
33
|
+
|
34
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
35
|
+
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
37
|
+
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
39
|
+
|
40
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
41
|
+
|
42
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
43
|
+
|
44
|
+
var mapSchemaName = function mapSchemaName(schema) {
|
45
|
+
if ((0, _utils.isPlainObj)(schema)) {
|
46
|
+
var newSchema = {};
|
47
|
+
Object.entries(schema).forEach(function (_ref) {
|
48
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
49
|
+
key = _ref2[0],
|
50
|
+
value = _ref2[1];
|
51
|
+
|
52
|
+
var _key$split = key.split('.'),
|
53
|
+
_key$split2 = _toArray(_key$split),
|
54
|
+
firstKey = _key$split2[0],
|
55
|
+
otherKey = _key$split2.slice(1);
|
56
|
+
|
57
|
+
var newFirstKey = (0, _utils.getValueByValue)(_schemaNameMap.default, firstKey, {
|
58
|
+
inputKey: 'proForm',
|
59
|
+
outputKey: 'formily'
|
60
|
+
}) || firstKey;
|
61
|
+
var newKey = [newFirstKey].concat(_toConsumableArray(otherKey)).join('.');
|
62
|
+
newSchema[newKey] = value;
|
63
|
+
});
|
64
|
+
return newSchema;
|
65
|
+
}
|
66
|
+
|
67
|
+
return schema;
|
68
|
+
};
|
69
|
+
|
70
|
+
var initializeReactions = function initializeReactions(reactions, innerReactions) {
|
71
|
+
var temp = innerReactions; // 合并reactions
|
72
|
+
|
73
|
+
if (reactions) {
|
74
|
+
temp = (0, _utils2.mergeArrayValue)(innerReactions, reactions);
|
75
|
+
} // schema名称映射,由ProFormSchema映射为formilySchema
|
76
|
+
|
77
|
+
|
78
|
+
temp = temp.map(function (item) {
|
79
|
+
var _item$fulfill, _item$otherwise;
|
80
|
+
|
81
|
+
var fulfillSchema = mapSchemaName(item === null || item === void 0 ? void 0 : (_item$fulfill = item.fulfill) === null || _item$fulfill === void 0 ? void 0 : _item$fulfill.schema);
|
82
|
+
var otherwiseSchema = mapSchemaName(item === null || item === void 0 ? void 0 : (_item$otherwise = item.otherwise) === null || _item$otherwise === void 0 ? void 0 : _item$otherwise.schema);
|
83
|
+
|
84
|
+
if (fulfillSchema || otherwiseSchema) {
|
85
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
86
|
+
fulfill: _objectSpread(_objectSpread({}, item === null || item === void 0 ? void 0 : item.fulfill), {}, {
|
87
|
+
schema: fulfillSchema
|
88
|
+
}),
|
89
|
+
otherwise: _objectSpread(_objectSpread({}, item === null || item === void 0 ? void 0 : item.otherwise), {}, {
|
90
|
+
schema: otherwiseSchema
|
91
|
+
})
|
92
|
+
});
|
93
|
+
}
|
94
|
+
|
95
|
+
return item;
|
96
|
+
});
|
97
|
+
return temp;
|
98
|
+
};
|
99
|
+
|
100
|
+
var _default = initializeReactions;
|
101
|
+
exports.default = _default;
|