@teamix/pro 1.3.14 → 1.3.15

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.
@@ -37,4 +37,11 @@ declare const mapSchemaName: (obj: any) => any;
37
37
  * @returns 合并数组或合并其他值
38
38
  */
39
39
  declare const mergeArrayValue: (arr: any[], v?: any) => any[];
40
- export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName, };
40
+ /**
41
+ * 初始化请求配置为表达式
42
+ * @param config 请求配置
43
+ * @param suffix scope名称后缀
44
+ * @returns 表达式和scope上下文
45
+ */
46
+ declare const initializeRequestExpression: (config?: any, mode?: string | undefined, suffix?: string | undefined) => any;
47
+ export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName, initializeRequestExpression, };
package/es/form/utils.js CHANGED
@@ -1,3 +1,9 @@
1
+ var _excluded = ["customRequest"];
2
+
3
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
+
5
+ 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; }
6
+
1
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
8
 
3
9
  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."); }
@@ -26,7 +32,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
26
32
 
27
33
  import { isVoidField } from '@formily/core';
28
34
  import { useFormLayout, useFormShallowLayout } from '@teamix/formily';
29
- import { isArr, isObj, getValueByValue } from '@teamix/utils';
35
+ import { isArr, isObj, getValueByValue, isPlainObj, isFn } from '@teamix/utils';
30
36
  import schemaNameMap from './schemaNameMap';
31
37
  /**
32
38
  * 映射字段size,主要是default转medium
@@ -177,5 +183,42 @@ var mergeArrayValue = function mergeArrayValue(arr, v) {
177
183
 
178
184
  return [].concat(_toConsumableArray(arr), [v]);
179
185
  };
186
+ /**
187
+ * 初始化请求配置为表达式
188
+ * @param config 请求配置
189
+ * @param suffix scope名称后缀
190
+ * @returns 表达式和scope上下文
191
+ */
192
+
193
+
194
+ var initializeRequestExpression = function initializeRequestExpression(config, mode, suffix) {
195
+ var schema = {};
196
+
197
+ if (isPlainObj(config)) {
198
+ var customRequest = config.customRequest,
199
+ requestConfig = _objectWithoutProperties(config, _excluded);
200
+
201
+ var requestConfigName = "$requestConfig_".concat(suffix);
202
+
203
+ if (isFn(customRequest)) {
204
+ var _scope;
205
+
206
+ // 自定义请求方法 customRequest
207
+ var customRequestName = "$customRequest_".concat(suffix);
208
+ schema = {
209
+ expression: "{{".concat(mode, "(").concat(customRequestName, ",context,").concat(requestConfigName, ")}}"),
210
+ scope: (_scope = {}, _defineProperty(_scope, customRequestName, customRequest), _defineProperty(_scope, requestConfigName, requestConfig), _scope)
211
+ };
212
+ } else {
213
+ // pro 通用数据请求 $request
214
+ schema = {
215
+ expression: "{{".concat(mode, "($request,context,").concat(requestConfigName, ")}}"),
216
+ scope: _defineProperty({}, requestConfigName, requestConfig)
217
+ };
218
+ }
219
+ }
220
+
221
+ return schema;
222
+ };
180
223
 
181
- export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName };
224
+ export { mapSize, mapStatus, mapDataSource, mapMode, mergeArrayValue, getFieldName, mapSchemaName, initializeRequestExpression };
package/es/index.d.ts CHANGED
@@ -26,5 +26,5 @@ export * from './table';
26
26
  export * from './sidebar';
27
27
  export * from './utils';
28
28
  export * from './timeline';
29
- declare const version = "1.3.14";
29
+ declare const version = "1.3.15";
30
30
  export { version, ProAction, ProCard, ProField, ProForm, ProInfo, ProPageContainer, ProPageHeader, ProSkeleton, ProTable, ProSidebar, ProTimeline, hooks, nocode, templates, utils, };
package/es/index.js CHANGED
@@ -31,6 +31,6 @@ export * from './sidebar';
31
31
  export * from './utils'; // export * from './sidebar';
32
32
 
33
33
  export * from './timeline';
34
- var version = '1.3.14';
34
+ var version = '1.3.15';
35
35
  export { version, ProAction, ProCard, ProField, ProForm, ProInfo, // ProLayout,
36
36
  ProPageContainer, ProPageHeader, ProSkeleton, ProTable, ProSidebar, ProTimeline, hooks, nocode, templates, utils };
@@ -121,3 +121,16 @@
121
121
  }
122
122
  }
123
123
  }
124
+
125
+ // 针对弹层内的 table 在暗色模式下适配
126
+ .next-dialog-body {
127
+ .teamix-pro-table, .next-table-empty {
128
+ background: var(--dialog-bg);
129
+ }
130
+ }
131
+
132
+ .next-drawer-body {
133
+ .teamix-pro-table, .next-table-empty {
134
+ background: var(--drawer-bg);
135
+ }
136
+ }
@@ -150,24 +150,21 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
150
150
  }); // 等待mounted + 字段loading结束 + initialRequest结束 => 表单默认值初始化完成
151
151
 
152
152
  if (!(form.mounted && !loadingField.length && !form.loading)) {
153
- _context.next = 10;
153
+ _context.next = 9;
154
154
  break;
155
155
  }
156
156
 
157
- onFormInit = function onFormInit() {}; // init后销毁 isFormInit 方法
158
-
159
-
160
- filterEnable.current = 'filter';
157
+ onFormInit = undefined; // init后销毁 isFormInit 方法
161
158
 
162
159
  if (!onInit) {
163
- _context.next = 10;
160
+ _context.next = 9;
164
161
  break;
165
162
  }
166
163
 
167
- _context.next = 8;
164
+ _context.next = 7;
168
165
  return form.validate();
169
166
 
170
- case 8:
167
+ case 7:
171
168
  onInit === null || onInit === void 0 ? void 0 : onInit((0, _reactive.toJS)(form.values)); // 设置Tag
172
169
 
173
170
  if (mode === 'panel') {
@@ -175,7 +172,7 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
175
172
  !panelVisible && configTag();
176
173
  }
177
174
 
178
- case 10:
175
+ case 9:
179
176
  case "end":
180
177
  return _context.stop();
181
178
  }
@@ -194,13 +191,105 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
194
191
 
195
192
  if (formRef) {
196
193
  var form = formMap[formName];
197
- formRef.current = form;
194
+ formRef.current = form; // 自定义updateTags方法
198
195
 
199
196
  if (!formRef.current.updateTags) {
200
197
  formRef.current.updateTags = function () {
201
- configFilterItem(form);
202
- configTag();
198
+ updateTags(form);
203
199
  };
200
+ } // 自定义setAsyncValues方法
201
+
202
+
203
+ if (!formRef.current.setAsyncValues) {
204
+ formRef.current.setAsyncValues = /*#__PURE__*/function () {
205
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(values) {
206
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
207
+ while (1) {
208
+ switch (_context2.prev = _context2.next) {
209
+ case 0:
210
+ form.setValues(values);
211
+
212
+ if (!(filterEnable.current === 'filter' && formName === 'advanced')) {
213
+ _context2.next = 6;
214
+ break;
215
+ }
216
+
217
+ _context2.next = 4;
218
+ return form.validate();
219
+
220
+ case 4:
221
+ onFilter === null || onFilter === void 0 ? void 0 : onFilter((0, _reactive.toJS)(form.values));
222
+ updateTags(form);
223
+
224
+ case 6:
225
+ case "end":
226
+ return _context2.stop();
227
+ }
228
+ }
229
+ }, _callee2);
230
+ }));
231
+
232
+ return function (_x2) {
233
+ return _ref2.apply(this, arguments);
234
+ };
235
+ }();
236
+ } // 自定义triggerFilter方法
237
+
238
+
239
+ if (!formRef.current.triggerFilter) {
240
+ formRef.current.triggerFilter = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
241
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
242
+ while (1) {
243
+ switch (_context3.prev = _context3.next) {
244
+ case 0:
245
+ _context3.next = 2;
246
+ return form.validate();
247
+
248
+ case 2:
249
+ onFilter === null || onFilter === void 0 ? void 0 : onFilter((0, _reactive.toJS)(form.values));
250
+
251
+ if (formName === 'advanced') {
252
+ updateTags(form);
253
+ }
254
+
255
+ case 4:
256
+ case "end":
257
+ return _context3.stop();
258
+ }
259
+ }
260
+ }, _callee3);
261
+ }));
262
+ } // 自定义triggerReset方法
263
+
264
+
265
+ if (!formRef.current.triggerReset) {
266
+ formRef.current.triggerReset = /*#__PURE__*/function () {
267
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(config) {
268
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
269
+ while (1) {
270
+ switch (_context4.prev = _context4.next) {
271
+ case 0:
272
+ simpleForm.reset('*', config);
273
+ lightForm.reset('*', config);
274
+ advancedForm.reset('*', config);
275
+
276
+ if (formName === 'advanced') {
277
+ onReset === null || onReset === void 0 ? void 0 : onReset((0, _reactive.toJS)(advancedForm.values));
278
+ updateTags(form);
279
+ }
280
+
281
+ case 4:
282
+ case "end":
283
+ return _context4.stop();
284
+ }
285
+ }
286
+ }, _callee4);
287
+ }));
288
+
289
+ return function (_x3) {
290
+ return _ref4.apply(this, arguments);
291
+ };
292
+ }();
204
293
  }
205
294
  }
206
295
  }; // 创建简单筛选表单实例
@@ -212,7 +301,11 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
212
301
  effects: function effects() {
213
302
  (0, _core.onFormReact)(function (form) {
214
303
  if (mode === 'inline') {
215
- onFormInit(form);
304
+ var _onFormInit;
305
+
306
+ (_onFormInit = onFormInit) === null || _onFormInit === void 0 ? void 0 : _onFormInit(form).finally(function () {
307
+ return filterEnable.current = 'filter';
308
+ });
216
309
  }
217
310
  });
218
311
  }
@@ -236,7 +329,11 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
236
329
  effects: function effects() {
237
330
  (0, _core.onFormReact)(function (form) {
238
331
  if (mode === 'panel') {
239
- onFormInit(form);
332
+ var _onFormInit2;
333
+
334
+ (_onFormInit2 = onFormInit) === null || _onFormInit2 === void 0 ? void 0 : _onFormInit2(form).finally(function () {
335
+ return filterEnable.current = 'filter';
336
+ });
240
337
  }
241
338
  });
242
339
  (0, _core.onFormInputChange)(function (form) {
@@ -255,12 +352,12 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
255
352
  var displayValues = (0, _useFormDisplayValues.getFormDisplayValues)(form);
256
353
  var originalData = Object.entries(displayValues);
257
354
  var filterData = [];
258
- originalData.forEach(function (_ref2) {
355
+ originalData.forEach(function (_ref5) {
259
356
  var _data$displayValue;
260
357
 
261
- var _ref3 = _slicedToArray(_ref2, 2),
262
- key = _ref3[0],
263
- data = _ref3[1];
358
+ var _ref6 = _slicedToArray(_ref5, 2),
359
+ key = _ref6[0],
360
+ data = _ref6[1];
264
361
 
265
362
  var value = (_data$displayValue = data.displayValue) !== null && _data$displayValue !== void 0 ? _data$displayValue : data.value;
266
363
  var component = data.component;
@@ -295,6 +392,11 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
295
392
 
296
393
  var configTag = (0, _react.useCallback)(function () {
297
394
  setTagDataSource(filterItem.current);
395
+ }, []); // 更新标签数据
396
+
397
+ var updateTags = (0, _react.useCallback)(function (form) {
398
+ configFilterItem(form);
399
+ configTag();
298
400
  }, []); // 展开收起高级筛选
299
401
 
300
402
  var toggleAdvancedFilter = (0, _react.useCallback)(function () {
@@ -317,12 +419,12 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
317
419
  }, [panelVisible, configTag]); // 简单搜索Filter
318
420
 
319
421
  var onSimpleFilter = (0, _react.useCallback)( /*#__PURE__*/function () {
320
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(values) {
321
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
422
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(values) {
423
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
322
424
  while (1) {
323
- switch (_context2.prev = _context2.next) {
425
+ switch (_context5.prev = _context5.next) {
324
426
  case 0:
325
- _context2.next = 2;
427
+ _context5.next = 2;
326
428
  return simpleForm.validate();
327
429
 
328
430
  case 2:
@@ -330,14 +432,14 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
330
432
 
331
433
  case 3:
332
434
  case "end":
333
- return _context2.stop();
435
+ return _context5.stop();
334
436
  }
335
437
  }
336
- }, _callee2);
438
+ }, _callee5);
337
439
  }));
338
440
 
339
- return function (_x2) {
340
- return _ref4.apply(this, arguments);
441
+ return function (_x4) {
442
+ return _ref7.apply(this, arguments);
341
443
  };
342
444
  }(), [onFilter]); // 简单搜索Change
343
445
 
@@ -360,10 +462,8 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
360
462
  (_Object$keys = Object.keys(advancedForm.values)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.forEach(function (key) {
361
463
  clearKeys[key] = undefined;
362
464
  });
363
- advancedForm.setValues(clearKeys); // 配置Tag
364
-
365
- configFilterItem(advancedForm);
366
- configTag();
465
+ advancedForm.setValues(clearKeys);
466
+ updateTags(advancedForm);
367
467
  }, [onFilter]); // 轻量搜索Change
368
468
 
369
469
  var onLightChange = (0, _react.useCallback)(function (values, fieldValue, fieldName) {
@@ -411,8 +511,7 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
411
511
  }
412
512
 
413
513
  advancedForm.setValuesIn(key, newValue);
414
- configFilterItem(advancedForm);
415
- configTag();
514
+ updateTags(advancedForm);
416
515
  onFilter === null || onFilter === void 0 ? void 0 : onFilter((0, _reactive.toJS)(advancedForm.values));
417
516
  }, [onFilter]); // initialRequest 的回调
418
517
 
@@ -456,12 +555,12 @@ var QueryFilter = /*#__PURE__*/(0, _react.memo)(function (props) {
456
555
  onReset: onAdvancedReset,
457
556
  onInitialComplete: onInitialComplete
458
557
  })) : null
459
- }, mode === 'panel' && !panelVisible ? /*#__PURE__*/_react.default.createElement(_components.Tag.Group, null, tagDataSource.map(function (_ref5) {
460
- var key = _ref5.key,
461
- label = _ref5.label,
462
- value = _ref5.value,
463
- type = _ref5.type,
464
- index = _ref5.index;
558
+ }, mode === 'panel' && !panelVisible ? /*#__PURE__*/_react.default.createElement(_components.Tag.Group, null, tagDataSource.map(function (_ref8) {
559
+ var key = _ref8.key,
560
+ label = _ref8.label,
561
+ value = _ref8.value,
562
+ type = _ref8.type,
563
+ index = _ref8.index;
465
564
  return /*#__PURE__*/_react.default.createElement(_components.Tag.Closeable, {
466
565
  key: (0, _utils.isNum)(index) ? key + label : key,
467
566
  afterClose: function afterClose() {
@@ -1,6 +1,5 @@
1
- import type { ProFormRequestConfig } from '../typing';
2
1
  interface IInitializeDataSource {
3
- (requestConfig?: ProFormRequestConfig | any, suffix?: string): {
2
+ (requestConfig: any, suffix: string): {
4
3
  dataSource?: any[];
5
4
  reactions: any[];
6
5
  scope: {
@@ -5,30 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _utils = require("@teamix/utils");
9
-
10
- 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; }
8
+ var _utils = require("../utils");
11
9
 
12
10
  var initializeDataSource = function initializeDataSource(dataSource, suffix) {
13
- if ((0, _utils.isPlainObj)(dataSource)) {
14
- var _requestConfig$extraC;
11
+ var _dataSource$extraConf;
15
12
 
16
- var requestConfig = dataSource;
17
- var requestConfigName = "$requestConfig_".concat(suffix);
18
- return {
19
- reactions: ["{{$dataSource($request,".concat(requestConfigName, ",context)}}")],
20
- scope: _defineProperty({}, requestConfigName, requestConfig),
21
- // dataSource请求时,默认配置字段为只读
22
- data: {
23
- readOnlyOnLoading: (requestConfig === null || requestConfig === void 0 ? void 0 : (_requestConfig$extraC = requestConfig.extraConfig) === null || _requestConfig$extraC === void 0 ? void 0 : _requestConfig$extraC.readOnly) !== false
24
- }
25
- };
26
- }
13
+ var _initializeRequestExp = (0, _utils.initializeRequestExpression)(dataSource, '$dataSource', suffix),
14
+ expression = _initializeRequestExp.expression,
15
+ scope = _initializeRequestExp.scope;
27
16
 
28
- return {
29
- dataSource: dataSource,
17
+ return expression ? {
18
+ reactions: [expression],
19
+ scope: scope,
20
+ data: {
21
+ readOnlyOnLoading: (dataSource === null || dataSource === void 0 ? void 0 : (_dataSource$extraConf = dataSource.extraConfig) === null || _dataSource$extraConf === void 0 ? void 0 : _dataSource$extraConf.readOnly) !== false
22
+ }
23
+ } : {
30
24
  reactions: [],
31
- scope: {}
25
+ scope: {},
26
+ dataSource: dataSource
32
27
  };
33
28
  };
34
29
 
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("@teamix/utils");
9
9
 
10
+ var _utils2 = require("../utils");
11
+
10
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
13
 
12
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -25,37 +27,35 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
25
27
 
26
28
  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; }
27
29
 
28
- var initializeRequest = function initializeRequest(requestConfig, suffix) {
29
- if (requestConfig) {
30
- if ((0, _utils.isArr)(requestConfig)) {
31
- var reactionsMap = [];
32
- var scopeMap = {};
33
- requestConfig.forEach(function (item, index) {
34
- var _initializeRequest = initializeRequest(item, "".concat(suffix).concat(index)),
35
- reactions = _initializeRequest.reactions,
36
- scope = _initializeRequest.scope;
37
-
38
- reactionsMap = [].concat(_toConsumableArray(reactionsMap), _toConsumableArray(reactions));
39
- scopeMap = _objectSpread(_objectSpread({}, scopeMap), scope);
40
- });
41
- return {
42
- reactions: reactionsMap,
43
- scope: scopeMap
44
- };
45
- } else {
46
- var requestConfigName = "$requestConfig_".concat(suffix);
47
- return {
48
- reactions: ["{{$common($request,".concat(requestConfigName, ",context)}}")],
49
- scope: _defineProperty({}, requestConfigName, requestConfig)
50
- };
51
- }
52
- }
30
+ var initializeItem = function initializeItem(request, suffix) {
31
+ var _initializeRequestExp = (0, _utils2.initializeRequestExpression)(request, '$common', suffix),
32
+ expression = _initializeRequestExp.expression,
33
+ scope = _initializeRequestExp.scope;
53
34
 
54
- return {
35
+ return expression ? {
36
+ reactions: [expression],
37
+ scope: scope
38
+ } : {
55
39
  reactions: [],
56
40
  scope: {}
57
41
  };
58
42
  };
59
43
 
44
+ var initializeRequest = function initializeRequest(request, suffix) {
45
+ if ((0, _utils.isArr)(request)) {
46
+ return request.reduce(function (prev, current, index) {
47
+ var result = initializeItem(current, "".concat(suffix, "_").concat(index));
48
+ prev.reactions = [].concat(_toConsumableArray(prev.reactions), _toConsumableArray(result.reactions));
49
+ prev.scope = _objectSpread(_objectSpread({}, prev.scope), result.scope);
50
+ return prev;
51
+ }, {
52
+ reactions: [],
53
+ scope: {}
54
+ });
55
+ }
56
+
57
+ return initializeItem(request, suffix);
58
+ };
59
+
60
60
  var _default = initializeRequest;
61
61
  exports.default = _default;
@@ -1,7 +1,7 @@
1
1
  interface IInitializeRules {
2
- (rules?: any, suffix?: string): {
2
+ (rules: any, suffix: string): {
3
3
  rules?: any;
4
- reactions: any[];
4
+ reactions?: any[];
5
5
  scope: {
6
6
  [x: string]: any;
7
7
  };
@@ -7,6 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _utils = require("@teamix/utils");
9
9
 
10
+ var _utils2 = require("../utils");
11
+
12
+ var _excluded = ["validator"];
13
+
10
14
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
15
 
12
16
  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,30 +29,34 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
29
 
26
30
  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; }
27
31
 
28
- var initializeRules = function initializeRules(rules, suffix) {
29
- var initializeValidator = function initializeValidator(rule) {
30
- var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
31
-
32
- if ((0, _utils.isPlainObj)(rule === null || rule === void 0 ? void 0 : rule.validator)) {
33
- var requestConfig = rule.validator;
34
- var requestConfigName = "$requestConfig_".concat(suffix).concat(index);
35
- return {
36
- rules: _objectSpread(_objectSpread({}, rule), {}, {
37
- validator: "{{$validator($request,".concat(requestConfigName, ",context)}}")
38
- }),
39
- scope: _defineProperty({}, requestConfigName, requestConfig)
40
- };
41
- }
42
-
43
- return {
44
- rules: rule,
45
- scope: {}
46
- };
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+
34
+ 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; }
35
+
36
+ var initializeRule = function initializeRule(rule, suffix) {
37
+ var _ref = rule || {},
38
+ validator = _ref.validator,
39
+ rest = _objectWithoutProperties(_ref, _excluded);
40
+
41
+ var _initializeRequestExp = (0, _utils2.initializeRequestExpression)(validator, '$validator', suffix),
42
+ expression = _initializeRequestExp.expression,
43
+ scope = _initializeRequestExp.scope;
44
+
45
+ return expression ? {
46
+ scope: scope,
47
+ rules: _objectSpread({
48
+ validator: expression
49
+ }, rest)
50
+ } : {
51
+ scope: {},
52
+ rules: rule
47
53
  };
54
+ };
48
55
 
56
+ var initializeRules = function initializeRules(rules, suffix) {
49
57
  if ((0, _utils.isArr)(rules)) {
50
- return rules.reduce(function (prev, current, subIndex) {
51
- var result = initializeValidator(current, subIndex);
58
+ return rules.reduce(function (prev, current, index) {
59
+ var result = initializeRule(current, "".concat(suffix, "_").concat(index));
52
60
  prev.rules = [].concat(_toConsumableArray(prev.rules), [result.rules]);
53
61
  prev.scope = _objectSpread(_objectSpread({}, prev.scope), result.scope);
54
62
  return prev;
@@ -58,7 +66,7 @@ var initializeRules = function initializeRules(rules, suffix) {
58
66
  });
59
67
  }
60
68
 
61
- return initializeValidator(rules);
69
+ return initializeRule(rules, suffix);
62
70
  };
63
71
 
64
72
  var _default = initializeRules;
@@ -1,6 +1,6 @@
1
1
  import type { ProFormRequestConfig } from '../typing';
2
- declare const $request: (field: any, { extraConfig, ...requestConfig }: ProFormRequestConfig, context: any, type: 'request' | 'validator' | 'dataSource') => Promise<unknown>;
3
- declare const $common: (services: any, requestConfig: ProFormRequestConfig, context: any) => (field: any) => any;
4
- declare const $validator: (services: any, requestConfig: ProFormRequestConfig, context: any) => (value: any, rules: any, { field }: any) => any;
5
- declare const $dataSource: (services: any, requestConfig: ProFormRequestConfig, context: any) => (field: any) => any;
2
+ declare const $request: (field: any, context: any, { extraConfig, onComplete, ...rest }: ProFormRequestConfig, type: 'request' | 'validator' | 'dataSource') => Promise<unknown>;
3
+ declare const $common: (services: any, context: any, requestConfig: ProFormRequestConfig) => (field: any) => any;
4
+ declare const $validator: (services: any, context: any, requestConfig: ProFormRequestConfig) => (value: any, rules: any, { field }: any) => any;
5
+ declare const $dataSource: (services: any, context: any, requestConfig: ProFormRequestConfig) => (field: any) => any;
6
6
  export { $request, $common, $dataSource, $validator };