ronds-metadata 1.1.88 → 1.1.90

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 (30) hide show
  1. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +3 -2
  2. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.d.ts +2 -0
  3. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +17 -0
  4. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +45 -3
  5. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +5 -2
  6. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.d.ts +2 -0
  7. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +22 -0
  8. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +47 -3
  9. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +4 -2
  10. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +5 -2
  11. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +122 -2
  12. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +6 -2
  13. package/es/comps/FormGenerator/comps/Canvas/core/index.js +53 -11
  14. package/es/comps/FormGenerator/comps/Canvas/core/index.less +0 -1
  15. package/es/comps/FormGenerator/comps/Settings/index.js +1 -1
  16. package/es/comps/FormGenerator/comps/Sidebar/index.js +1 -1
  17. package/es/comps/FormGenerator/settings/index.d.ts +83 -70
  18. package/es/comps/FormGenerator/settings/index.js +22 -15
  19. package/es/comps/FormGenerator/settings/ruleConfig.d.ts +32 -2
  20. package/es/comps/FormGenerator/settings/ruleConfig.js +201 -7
  21. package/es/comps/FormGenerator/transformer.js +2 -2
  22. package/es/comps/MetadataForm/DataCell/Array.js +18 -4
  23. package/es/comps/MetadataForm/DataCell/Select.js +38 -11
  24. package/es/comps/MetadataForm/DataCell/layout/TableArray.d.ts +1 -1
  25. package/es/comps/MetadataForm/DataCell/layout/TableArray.js +75 -28
  26. package/es/comps/MetadataForm/utils.d.ts +1 -0
  27. package/es/comps/MetadataForm/utils.js +13 -1
  28. package/es/utils.d.ts +3 -0
  29. package/es/utils.js +28 -2
  30. package/package.json +1 -1
@@ -27,7 +27,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
27
27
  /*
28
28
  * @Author:wangxian
29
29
  * @Date: 2021-09-18 14:15:04
30
- * @LastEditTime: 2023-02-10 08:23:34
30
+ * @LastEditTime: 2023-02-14 08:54:35
31
31
  */
32
32
  import React from 'react';
33
33
  import { MetadataFormContext, MetadataRefContext } from '../interface';
@@ -83,33 +83,60 @@ function Index(props) {
83
83
  // 判断是否有 watch的扩展属性
84
84
  var _watch = extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$http = extraInfo.http) === null || _extraInfo$http === void 0 ? void 0 : _extraInfo$http.watch;
85
85
 
86
- if (_watch && (p === null || p === void 0 ? void 0 : p.type) === 'onSelectChange') {
86
+ if (_watch && (p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
87
87
  var _watchArr = _watch.split(',');
88
88
 
89
89
  if (_watchArr.length === 1) {
90
- var _value = p === null || p === void 0 ? void 0 : p.payload[_watchArr[0]];
90
+ var _p$payload, _p$payload2;
91
+
92
+ var _value = p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.allVals[_watchArr[0]];
91
93
 
92
94
  if (_value) {
93
- setWatchValue(_value);
94
- watchValueRef.current = _value;
95
- formContext.form.setFieldsValue(_defineProperty({}, id, undefined));
95
+ if ((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.http.method) === 'post') {
96
+ var _wRef = watchValueRef.current || {};
97
+
98
+ _wRef[_watchArr[0]] = _value;
99
+ watchValueRef.current = _wRef;
100
+ setWatchValue(_value);
101
+ } else {
102
+ setWatchValue(_value.toString());
103
+ watchValueRef.current = _value;
104
+ }
105
+ }
106
+
107
+ if (p === null || p === void 0 ? void 0 : (_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.val[_watchArr[0]]) {
108
+ setTimeout(function () {
109
+ formContext.form.setFieldsValue(_defineProperty({}, id, undefined));
110
+ }, 100);
96
111
  }
97
112
  } else {
113
+ var b = false;
114
+
98
115
  for (var i = 0; i < _watchArr.length; i++) {
116
+ var _p$payload3;
117
+
99
118
  var w = _watchArr[i];
100
119
 
101
- var _value2 = p === null || p === void 0 ? void 0 : p.payload[w];
120
+ var _value2 = p === null || p === void 0 ? void 0 : (_p$payload3 = p.payload) === null || _p$payload3 === void 0 ? void 0 : _p$payload3.allVals[w];
102
121
 
103
122
  if (_value2) {
104
- var _wRef = watchValueRef.current || {};
123
+ var _p$payload4;
105
124
 
106
- _wRef[w] = _value2;
107
- watchValueRef.current = _wRef;
125
+ var _wRef2 = watchValueRef.current || {};
126
+
127
+ _wRef2[w] = _value2;
128
+ watchValueRef.current = _wRef2;
129
+ b = p === null || p === void 0 ? void 0 : (_p$payload4 = p.payload) === null || _p$payload4 === void 0 ? void 0 : _p$payload4.val[w];
108
130
  }
109
131
  }
110
132
 
111
- formContext.form.setFieldsValue(_defineProperty({}, id, undefined));
112
133
  setWatchValue(_objectSpread({}, watchValueRef.current));
134
+
135
+ if (b) {
136
+ setTimeout(function () {
137
+ formContext.form.setFieldsValue(_defineProperty({}, id, undefined));
138
+ }, 100);
139
+ }
113
140
  }
114
141
  }
115
142
  }, [formContext.stream$, extraInfo]);
@@ -1,6 +1,6 @@
1
1
  import { FormInstance } from 'antd';
2
2
  interface ITableArrayProps {
3
- name: string;
3
+ name: string | string[];
4
4
  form: FormInstance;
5
5
  refId: string;
6
6
  initEnumValue: any[];
@@ -12,7 +12,7 @@ import { JsonMetadataProvider } from '../../../../framework/metadata';
12
12
  import Editable from '../../../../comps/Editable';
13
13
  import useObservable from '../../../../framework/rxjs-hooks/useObservable';
14
14
  import { MetadataFormContext } from '../../interface';
15
- import { getLabelByProps } from '../../utils';
15
+ import { assign, getLabelByProps } from '../../utils';
16
16
  import { deepClone } from '../../../../utils';
17
17
  import { STREAM_EVENT_TYPE } from '../../constants';
18
18
 
@@ -55,27 +55,63 @@ var TableArray = function TableArray(props) {
55
55
  list = _React$useState10[0],
56
56
  setList = _React$useState10[1];
57
57
 
58
+ var listRef = React.useRef([]);
58
59
  useObservable(function (p) {
59
- if ((p === null || p === void 0 ? void 0 : p.type) === 'setFieldsValue' && p.payload[name]) {
60
- setList(_toConsumableArray(p.payload[name]));
60
+ if ((p === null || p === void 0 ? void 0 : p.type) === 'setFieldsValue') {
61
+ if (typeof name === 'string' && p.payload[name]) {
62
+ setList(_toConsumableArray(p.payload[name]));
63
+ listRef.current = p.payload[name];
64
+ } else if (p.payload[name[0]]) {
65
+ var evalString = 'p.payload';
66
+
67
+ for (var i = 0; i < name.length; i++) {
68
+ evalString = "".concat(evalString, "[name[").concat(i, "]]");
69
+ }
70
+
71
+ var _list = eval(evalString) || [];
72
+
73
+ setList(_toConsumableArray(_list));
74
+ listRef.current = _list;
75
+ }
61
76
  }
62
- }, [formContext.stream$]);
77
+ }, [formContext.stream$, name]);
63
78
  useObservable(function (p) {
64
79
  if ((p === null || p === void 0 ? void 0 : p.type) === 'onValuesChange') {
65
- var _p$payload;
66
-
67
- var val = _defineProperty({}, "".concat(name), _objectSpread({
68
- rowIdx: p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.rowIdx
69
- }, p.payload.values));
70
-
71
- var allVals = form.getFieldsValue();
72
- formContext.stream$.next({
73
- type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
74
- payload: {
75
- val: val,
76
- allVals: allVals
77
- }
78
- });
80
+ if (typeof name === 'string') {
81
+ var _p$payload;
82
+
83
+ var val = _defineProperty({}, "".concat(name), _objectSpread({
84
+ rowIdx: p === null || p === void 0 ? void 0 : (_p$payload = p.payload) === null || _p$payload === void 0 ? void 0 : _p$payload.rowIdx
85
+ }, p.payload.values));
86
+
87
+ var allVals = form.getFieldsValue();
88
+ allVals[name] = listRef.current;
89
+ formContext.stream$.next({
90
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
91
+ payload: {
92
+ val: val,
93
+ allVals: allVals
94
+ }
95
+ });
96
+ } else {
97
+ var _p$payload2;
98
+
99
+ var _val2 = {};
100
+
101
+ var _allVals = form.getFieldsValue();
102
+
103
+ assign(name, _objectSpread({
104
+ rowIdx: p === null || p === void 0 ? void 0 : (_p$payload2 = p.payload) === null || _p$payload2 === void 0 ? void 0 : _p$payload2.rowIdx
105
+ }, p.payload.values), _val2);
106
+ assign(name, _toConsumableArray(listRef.current), _allVals);
107
+ formContext.stream$.next({
108
+ type: STREAM_EVENT_TYPE.ON_VALUES_CHANGE,
109
+ payload: {
110
+ val: _val2,
111
+ allVals: _allVals
112
+ }
113
+ });
114
+ }
79
115
  }
80
116
  }, [tblStream]);
81
117
  var getSchemaByRefId = React.useCallback( /*#__PURE__*/function () {
@@ -149,7 +185,22 @@ var TableArray = function TableArray(props) {
149
185
  }, [refId]);
150
186
  React.useEffect(function () {
151
187
  if (initValue && firstLoadRef.current) {
152
- setList(_toConsumableArray(initValue[name]));
188
+ if (typeof name === 'string' && initValue[name]) {
189
+ setList(_toConsumableArray(initValue[name]));
190
+ listRef.current = initValue[name];
191
+ } else if (initValue[name[0]]) {
192
+ var evalString = 'initValue';
193
+
194
+ for (var i = 0; i < name.length; i++) {
195
+ evalString = "".concat(evalString, "[name[").concat(i, "]]");
196
+ }
197
+
198
+ var _list = eval(evalString);
199
+
200
+ setList(_toConsumableArray(_list));
201
+ listRef.current = _list;
202
+ }
203
+
153
204
  firstLoadRef.current = false;
154
205
  }
155
206
  }, [initValue, form]);
@@ -186,7 +237,7 @@ var TableArray = function TableArray(props) {
186
237
  var processColumnType = React.useCallback(function (data, _extraInfo) {
187
238
  var _extraInfo$text;
188
239
 
189
- if (data.type === 'text' && ((_extraInfo$text = _extraInfo.text) === null || _extraInfo$text === void 0 ? void 0 : _extraInfo$text.type)) {
240
+ if ((data === null || data === void 0 ? void 0 : data.type) === 'text' && (_extraInfo === null || _extraInfo === void 0 ? void 0 : (_extraInfo$text = _extraInfo.text) === null || _extraInfo$text === void 0 ? void 0 : _extraInfo$text.type)) {
190
241
  var _extraInfo$text2;
191
242
 
192
243
  return (_extraInfo$text2 = _extraInfo.text) === null || _extraInfo$text2 === void 0 ? void 0 : _extraInfo$text2.type;
@@ -206,8 +257,8 @@ var TableArray = function TableArray(props) {
206
257
  title: getLabelByProps(it),
207
258
  key: it.id,
208
259
  dataIndex: it.id,
209
- width: processColumnType(it, extraInfo) === 'buttonCell' ? 60 : 100,
210
- editable: !((_extraInfo$common = extraInfo.common) === null || _extraInfo$common === void 0 ? void 0 : _extraInfo$common.disabled),
260
+ width: processColumnType(it, extraInfo) === 'buttonCell' ? 25 : 50,
261
+ editable: !(extraInfo === null || extraInfo === void 0 ? void 0 : (_extraInfo$common = extraInfo.common) === null || _extraInfo$common === void 0 ? void 0 : _extraInfo$common.disabled),
211
262
  type: processColumnType(it, extraInfo),
212
263
  enum: it.type === 'enum' ? processEnumData(it, extraInfo) : undefined
213
264
  };
@@ -228,11 +279,7 @@ var TableArray = function TableArray(props) {
228
279
  }, [schema, processSchemaToColumns]);
229
280
 
230
281
  var onTableChange = function onTableChange(values) {
231
- form.setFieldsValue(_objectSpread({}, _defineProperty({}, "".concat(name), values)));
232
- formContext.stream$.next({
233
- type: 'onValuesChange',
234
- payload: _defineProperty({}, "".concat(name), _objectSpread({}, values))
235
- });
282
+ listRef.current = values;
236
283
  };
237
284
 
238
285
  var onButtonCellClick = function onButtonCellClick(record) {
@@ -272,7 +319,7 @@ var TableArray = function TableArray(props) {
272
319
  tableProps: {
273
320
  scroll: {
274
321
  x: '100%',
275
- y: "".concat(rowNumber * getCellHeight(readonly) + 45, "px")
322
+ y: addButtonHidden || readonly ? "".concat(rowNumber * getCellHeight(readonly) + 45, "px ") : "".concat(rowNumber * getCellHeight(readonly), "px ")
276
323
  }
277
324
  }
278
325
  })));
@@ -13,3 +13,4 @@ export declare function getDataCell(item: any, options: IFormOptions): JSX.Eleme
13
13
  */
14
14
  export declare function renderForm(schemaRef: any[], options: IFormOptions, colSpan?: number): JSX.Element;
15
15
  export declare function getLabelByProps(data: any): any;
16
+ export declare function assign(pathArr: string[], val: any, obj: any): void;
@@ -9,7 +9,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
9
9
  /*
10
10
  * @Author: wangxian
11
11
  * @Date: 2021-09-18 14:15:04
12
- * @LastEditTime: 2023-02-09 15:53:44
12
+ * @LastEditTime: 2023-02-10 17:03:48
13
13
  */
14
14
  import React from 'react';
15
15
  import Input from './DataCell/Input';
@@ -104,4 +104,16 @@ export function getLabelByProps(data) {
104
104
  }
105
105
 
106
106
  return data.id;
107
+ }
108
+ export function assign(pathArr, val, obj) {
109
+ var len = pathArr.length - 1;
110
+ pathArr.reduce(function (cur, key, index) {
111
+ if (index === len) {
112
+ cur[key] = val;
113
+ } else {
114
+ cur[key] = {};
115
+ }
116
+
117
+ return cur[key];
118
+ }, obj);
107
119
  }
package/es/utils.d.ts CHANGED
@@ -14,3 +14,6 @@ export declare function useThrottle(fn: Function, delay: number, dep?: Dependenc
14
14
  export declare function deepClone<T = any>(target: T): T;
15
15
  export declare function guid(): string;
16
16
  export declare const md5: (data: string, digest?: string) => any;
17
+ export declare function arrayMoveMutable(array: any[], fromIndex: number, toIndex: number): void;
18
+ export declare function arrayMoveImmutable(array: any[], fromIndex: number, toIndex: number): any[];
19
+ export declare function arrayInsert(array: any[], index: number, item: any): any[];
package/es/utils.js CHANGED
@@ -1,7 +1,10 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+
1
4
  /*
2
5
  * @Author: wangxian
3
6
  * @Date: 2021-09-18 14:15:04
4
- * @LastEditTime: 2022-08-11 09:42:43
7
+ * @LastEditTime: 2023-02-13 17:02:22
5
8
  */
6
9
  import { useCallback, useEffect, useRef } from 'react';
7
10
  /** 防抖 */
@@ -109,4 +112,27 @@ var crypto = require('crypto');
109
112
  export var md5 = function md5(data) {
110
113
  var digest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'hex';
111
114
  return crypto.createHash('md5').update(data).digest(digest || 'base64');
112
- };
115
+ };
116
+ export function arrayMoveMutable(array, fromIndex, toIndex) {
117
+ var startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;
118
+
119
+ if (startIndex >= 0 && startIndex < array.length) {
120
+ var endIndex = toIndex < 0 ? array.length + toIndex : toIndex;
121
+
122
+ var _array$splice = array.splice(fromIndex, 1),
123
+ _array$splice2 = _slicedToArray(_array$splice, 1),
124
+ item = _array$splice2[0];
125
+
126
+ array.splice(endIndex, 0, item);
127
+ }
128
+ }
129
+ export function arrayMoveImmutable(array, fromIndex, toIndex) {
130
+ var newArray = _toConsumableArray(array);
131
+
132
+ arrayMoveMutable(newArray, fromIndex, toIndex);
133
+ return newArray;
134
+ }
135
+ export function arrayInsert(array, index, item) {
136
+ array.splice(index, 0, item);
137
+ return array;
138
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.1.88",
4
+ "version": "1.1.90",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",