@byteluck-fe/model-driven-engine 2.5.0-beta.9 → 2.5.1

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.
@@ -65,7 +65,7 @@ function _inherits(subClass, superClass) {
65
65
  }
66
66
  function _instanceof(left, right) {
67
67
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
68
- return right[Symbol.hasInstance](left);
68
+ return !!right[Symbol.hasInstance](left);
69
69
  } else {
70
70
  return left instanceof right;
71
71
  }
@@ -164,9 +164,9 @@ function _createSuper(Derived) {
164
164
  return _possibleConstructorReturn(this, result);
165
165
  };
166
166
  }
167
- import { isArray, isFunction, isString, isJSONArray, isJSONObject, isNumber, isNumberAndEmptyStringArray, isPlainObject, isStringArray, FieldTypes, isObject } from '@byteluck-fe/model-driven-shared';
168
- import { AddressValue, AmountValue, CalcValue, RangeDateValue } from '@byteluck-fe/model-driven-core';
169
- import { camelizeKeys } from 'humps';
167
+ import { isArray, isFunction, isString, isJSONArray, isJSONObject, isNumber, isNumberAndEmptyStringArray, isPlainObject, isStringArray, FieldTypes, isObject } from "@byteluck-fe/model-driven-shared";
168
+ import { AddressValue, AmountValue, CalcValue, RangeDateValue } from "@byteluck-fe/model-driven-core";
169
+ import { camelizeKeys } from "humps";
170
170
  var ValueChecker = function ValueChecker() {
171
171
  "use strict";
172
172
  _classCallCheck(this, ValueChecker);
@@ -190,7 +190,7 @@ var StringValueChecker = /*#__PURE__*/ function(ValueChecker) {
190
190
  key: "transform",
191
191
  value: function transform(value) {
192
192
  if (value === null || value === undefined) {
193
- return '';
193
+ return "";
194
194
  }
195
195
  if (!isPlainObject(value) && !isFunction(value)) {
196
196
  return String(value);
@@ -217,14 +217,14 @@ var NumberValueChecker = /*#__PURE__*/ function(ValueChecker) {
217
217
  // 数字类型允许是空字符串,用于置空数据
218
218
  key: "validate",
219
219
  value: function validate(value) {
220
- return isNumber(value) || value === '';
220
+ return isNumber(value) || value === "";
221
221
  }
222
222
  },
223
223
  {
224
224
  key: "transform",
225
225
  value: function transform(value) {
226
226
  if (value === null || value === undefined) {
227
- return '';
227
+ return "";
228
228
  }
229
229
  var newValue = !isPlainObject(value) && !isFunction(value) ? Number(value) : undefined;
230
230
  if (!Number.isNaN(newValue) && newValue !== undefined) {
@@ -253,28 +253,28 @@ var StringArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
253
253
  },
254
254
  {
255
255
  key: "transform",
256
- value: function transform(value1) {
256
+ value: function transform(value) {
257
257
  var getStringValueArray = function getStringValueArray(value) {
258
258
  return value.map(function(item) {
259
- return !item ? '' : String(item);
259
+ return !item ? "" : String(item);
260
260
  });
261
261
  };
262
- if (value1 === undefined || value1 === null) {
262
+ if (value === undefined || value === null) {
263
263
  return [];
264
264
  }
265
- if (isArray(value1)) {
266
- return getStringValueArray(value1);
265
+ if (isArray(value)) {
266
+ return getStringValueArray(value);
267
267
  }
268
- if (isString(value1) && isJSONArray(value1)) {
268
+ if (isString(value) && isJSONArray(value)) {
269
269
  try {
270
- var newValue = JSON.parse(value1);
270
+ var newValue = JSON.parse(value);
271
271
  if (Array.isArray(newValue)) {
272
272
  return getStringValueArray(newValue);
273
273
  }
274
274
  } catch (e) {}
275
275
  }
276
276
  return [
277
- String(value1)
277
+ String(value)
278
278
  ];
279
279
  }
280
280
  }
@@ -298,31 +298,31 @@ var NumberArrayValueChecker = /*#__PURE__*/ function(ValueChecker) {
298
298
  },
299
299
  {
300
300
  key: "transform",
301
- value: function transform(value2) {
301
+ value: function transform(value) {
302
302
  var getNumberValueArray = function getNumberValueArray(value) {
303
303
  return value.map(function(item) {
304
- return !item && item !== 0 ? '' : Number(item);
304
+ return !item && item !== 0 ? "" : Number(item);
305
305
  }).filter(function(item) {
306
- return item === '' || !Number.isNaN(item);
306
+ return item === "" || !Number.isNaN(item);
307
307
  });
308
308
  };
309
- if (value2 === undefined || value2 === null) {
309
+ if (value === undefined || value === null) {
310
310
  return [];
311
311
  }
312
- if (isArray(value2)) {
313
- return getNumberValueArray(value2);
312
+ if (isArray(value)) {
313
+ return getNumberValueArray(value);
314
314
  }
315
- if (isString(value2) && isJSONArray(value2)) {
315
+ if (isString(value) && isJSONArray(value)) {
316
316
  try {
317
- var newValue = JSON.parse(value2);
317
+ var newValue = JSON.parse(value);
318
318
  if (isArray(newValue)) {
319
319
  return getNumberValueArray(newValue);
320
320
  }
321
321
  } catch (e) {}
322
322
  }
323
- var newValue1 = Number(value2);
323
+ var newValue1 = Number(value);
324
324
  if (Number.isNaN(newValue1)) {
325
- throw "".concat(value2, " is not a number array");
325
+ throw "".concat(value, " is not a number array");
326
326
  }
327
327
  return [
328
328
  newValue1
@@ -344,13 +344,13 @@ var MoneyValueChecker = /*#__PURE__*/ function(ValueChecker) {
344
344
  {
345
345
  key: "validate",
346
346
  value: function validate(value) {
347
- return _instanceof(value, AmountValue) || isPlainObject(value) && 'amount' in value && isNumber(value.amount) && 'currency' in value && isString(value.currency);
347
+ return _instanceof(value, AmountValue) || isPlainObject(value) && "amount" in value && isNumber(value.amount) && "currency" in value && isString(value.currency);
348
348
  }
349
349
  },
350
350
  {
351
351
  key: "transform",
352
352
  value: function transform(value, oldValue) {
353
- if (value === undefined || value === null || value === '') {
353
+ if (value === undefined || value === null || value === "") {
354
354
  return new AmountValue({
355
355
  currency: oldValue === null || oldValue === void 0 ? void 0 : oldValue.currency
356
356
  });
@@ -394,13 +394,13 @@ var TimeScopeValueChecker = /*#__PURE__*/ function(ValueChecker) {
394
394
  {
395
395
  key: "validate",
396
396
  value: function validate(value) {
397
- return _instanceof(value, RangeDateValue) || isPlainObject(value) && 'min' in value && isString(value.min) && 'max' in value && isString(value.max);
397
+ return _instanceof(value, RangeDateValue) || isPlainObject(value) && "min" in value && isString(value.min) && "max" in value && isString(value.max);
398
398
  }
399
399
  },
400
400
  {
401
401
  key: "transform",
402
402
  value: function transform(value, oldValue) {
403
- if (value === undefined || value === null || value === '') {
403
+ if (value === undefined || value === null || value === "") {
404
404
  return new RangeDateValue();
405
405
  }
406
406
  var result;
@@ -441,13 +441,13 @@ var CalcValueChecker = /*#__PURE__*/ function(ValueChecker) {
441
441
  {
442
442
  key: "validate",
443
443
  value: function validate(value) {
444
- return _instanceof(value, CalcValue) || isPlainObject(value) && 'result' in value && isNumber(value.result) && 'unit' in value && isString(value.unit);
444
+ return _instanceof(value, CalcValue) || isPlainObject(value) && "result" in value && isNumber(value.result) && "unit" in value && isString(value.unit);
445
445
  }
446
446
  },
447
447
  {
448
448
  key: "transform",
449
449
  value: function transform(value, oldValue) {
450
- if (value === undefined || value === null || value === '') {
450
+ if (value === undefined || value === null || value === "") {
451
451
  return new CalcValue({
452
452
  unit: oldValue === null || oldValue === void 0 ? void 0 : oldValue.unit
453
453
  });
@@ -497,7 +497,7 @@ var AddressValueChecker = /*#__PURE__*/ function(ValueChecker) {
497
497
  {
498
498
  key: "transform",
499
499
  value: function transform(value, oldValue) {
500
- if (value === undefined || value === null || value === '') {
500
+ if (value === undefined || value === null || value === "") {
501
501
  return new AddressValue();
502
502
  }
503
503
  var result;
@@ -581,22 +581,22 @@ var ValueCheckerFactory = /*#__PURE__*/ function() {
581
581
  }();
582
582
  function getFieldTypeFromKey(key) {
583
583
  if ([
584
- 'min',
585
- 'max',
586
- 'currency',
587
- 'unit'
584
+ "min",
585
+ "max",
586
+ "currency",
587
+ "unit"
588
588
  ].includes(key)) {
589
589
  return FieldTypes.VARCHAR;
590
590
  } else if ([
591
- 'result',
592
- 'amount'
591
+ "result",
592
+ "amount"
593
593
  ].includes(key)) {
594
594
  return FieldTypes.DECIMAL;
595
595
  }
596
596
  }
597
597
  export function checkerValue(fieldType, key, value, oldValue) {
598
- var ref;
599
- var getCheckerFieldType = (ref = getFieldTypeFromKey(key)) !== null && ref !== void 0 ? ref : fieldType;
598
+ var _getFieldTypeFromKey;
599
+ var getCheckerFieldType = (_getFieldTypeFromKey = getFieldTypeFromKey(key)) !== null && _getFieldTypeFromKey !== void 0 ? _getFieldTypeFromKey : fieldType;
600
600
  var checker = ValueCheckerFactory.getValueChecker(getCheckerFieldType);
601
601
  if (!checker || checker.validate(value)) {
602
602
  return value;
@@ -1,2 +1,2 @@
1
- export * from './Engine';
2
- export * from './Plugin';
1
+ export * from "./Engine";
2
+ export * from "./Plugin";
@@ -23,22 +23,22 @@ function _unsupportedIterableToArray(o, minLen) {
23
23
  if (n === "Map" || n === "Set") return Array.from(n);
24
24
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
25
25
  }
26
- import { CONTROL_BASE_TYPE, error, logerror } from '@byteluck-fe/model-driven-shared';
27
26
  var cc = console;
27
+ import { CONTROL_BASE_TYPE, error, logerror, JSONCopy } from "@byteluck-fe/model-driven-shared";
28
28
  var proxyArrayApi = [
29
- 'splice',
30
- 'push',
31
- 'shift',
32
- 'pop',
33
- 'unshift',
34
- 'reverse',
29
+ "splice",
30
+ "push",
31
+ "shift",
32
+ "pop",
33
+ "unshift",
34
+ "reverse"
35
35
  ];
36
- export var engineProxyFlag = Symbol('__engineProxy__');
37
- export var engineTargetKey = Symbol('__engineTarget__');
38
- export var engineArrayBeforeSetCallbackFlag = Symbol('__engineArrayBeforeSetCallbackFlag__');
39
- export var engineProxyThisKey = Symbol('__engineProxyThisKey__');
36
+ export var engineProxyFlag = Symbol("__engineProxy__");
37
+ export var engineTargetKey = Symbol("__engineTarget__");
38
+ export var engineArrayBeforeSetCallbackFlag = Symbol("__engineArrayBeforeSetCallbackFlag__");
39
+ export var engineProxyThisKey = Symbol("__engineProxyThisKey__");
40
40
  var currentHandlerState = {
41
- type: '',
41
+ type: "",
42
42
  args: [],
43
43
  callback: emptyFn
44
44
  };
@@ -55,16 +55,16 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
55
55
  // 操作下标
56
56
  // Number(propertyKey) > target.length 说明当前操作的下标已经超过了安全范围(数组的运行长度,比如[1,2,3],它的长度为3,可操作的下标为0,1,2,3,如果操作4将会产生一个empty index)
57
57
  if (index > target.length) {
58
- error("Wrong array operations may cause unknown errors. It is recommended to use APIs such as ".concat(proxyArrayApi.join(','), " for array operations"));
58
+ error("Wrong array operations may cause unknown errors. It is recommended to use APIs such as ".concat(proxyArrayApi.join(","), " for array operations"));
59
59
  return;
60
60
  }
61
61
  // 不是操作下标,而是直接操作length或者自定义属性等
62
62
  var isNotHandlerIndex = Number.isNaN(index);
63
- if (isNotHandlerIndex && propertyKey !== 'length') {
63
+ if (isNotHandlerIndex && propertyKey !== "length") {
64
64
  return;
65
65
  }
66
66
  // 直接操作length
67
- if (propertyKey === 'length') {
67
+ if (propertyKey === "length") {
68
68
  var newLength = value;
69
69
  var oldLength = target.length;
70
70
  if (newLength > target.length) {
@@ -76,9 +76,9 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
76
76
  }
77
77
  // 通过操作length删除旧的行
78
78
  return function() {
79
- return callback.call(null, target, thisKey, 'splice', [
79
+ return callback.call(null, target, thisKey, "splice", [
80
80
  newLength,
81
- oldLength - newLength,
81
+ oldLength - newLength
82
82
  ]);
83
83
  };
84
84
  // 直接操作下标
@@ -86,13 +86,13 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
86
86
  // 正常操作
87
87
  if (index === target.length) {
88
88
  return function() {
89
- return callback.call(null, target, thisKey, 'push', [
89
+ return callback.call(null, target, thisKey, "push", [
90
90
  value
91
91
  ]);
92
92
  };
93
93
  } else {
94
94
  return function() {
95
- return callback.call(null, target, thisKey, 'splice', [
95
+ return callback.call(null, target, thisKey, "splice", [
96
96
  index,
97
97
  1,
98
98
  value
@@ -124,9 +124,9 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
124
124
  }
125
125
  return Reflect.get(target, propertyKey, receiver);
126
126
  },
127
- set: function set(target, propertyKey, value1, receiver) {
127
+ set: function set(target, propertyKey, value, receiver) {
128
128
  var reProxyState = function reProxyState(value) {
129
- if (typeof value === 'object' && value !== null) {
129
+ if (typeof value === "object" && value !== null) {
130
130
  // @ts-ignore
131
131
  if (value[engineProxyFlag] !== true) {
132
132
  return proxyState(value, callback, beforeSetCallback, concatKey);
@@ -137,19 +137,19 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
137
137
  }
138
138
  }
139
139
  };
140
- var newValue = value1;
140
+ var newValue = JSONCopy(value);
141
141
  // @ts-ignore
142
142
  var oldValue = target[propertyKey];
143
- var concatKey = thisKey === '' ? propertyKey : thisKey + '.' + propertyKey;
144
- var ref;
145
- newValue = (ref = reProxyState(value1)) !== null && ref !== void 0 ? ref : newValue;
143
+ var concatKey = thisKey === "" ? propertyKey : thisKey + "." + propertyKey;
144
+ var _reProxyState;
145
+ newValue = (_reProxyState = reProxyState(newValue)) !== null && _reProxyState !== void 0 ? _reProxyState : newValue;
146
146
  // 先设置值,然后再进行触发回调,确保回调内拿到的是最新的值
147
147
  var setResult;
148
148
  // TODO 数组拦截操作需要重构,优化现有逻辑
149
149
  // TODO 直接操作下标改动明细表时,没有对行数据进行checker
150
150
  if (Array.isArray(target)) {
151
151
  // 操作数组的时候,不需要使用拼接的thisKey,先判断执行的是否是违规操作,违规操作的话会报错,不允许继续执行,正常操作的话,返回一个回调函数,用于在值修改完之后触发
152
- var nextHandler = ArrayHandler(target, propertyKey, value1, thisKey, callback);
152
+ var nextHandler = ArrayHandler(target, propertyKey, newValue, thisKey, callback);
153
153
  setResult = Reflect.set(target, propertyKey, newValue, receiver);
154
154
  if (nextHandler) {
155
155
  nextHandler();
@@ -171,9 +171,11 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
171
171
  return true;
172
172
  }
173
173
  setResult = Reflect.set(target, propertyKey, newValue, receiver);
174
- callback.call(null, target, concatKey, value1, oldValue);
174
+ callback.call(null, target, concatKey, newValue, oldValue);
175
175
  }
176
- return setResult;
176
+ // 不返回falsy 值(即 false、0、null、undefined、空字符串等)
177
+ //fix: TypeError: Proxy object's 'set' trap returned falsy value for property 'length'
178
+ return setResult ? setResult : true;
177
179
  }
178
180
  };
179
181
  }
@@ -184,15 +186,15 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
184
186
  * @param beforeSetCallback
185
187
  * @param prevKey 递归对象的key
186
188
  * */ export function proxyState(state, callback, beforeSetCallback) {
187
- var prevKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
189
+ var prevKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "";
188
190
  // 冻结的对象不需要再执行proxy,否则会报错
189
191
  if (Object.isFrozen(state)) {
190
192
  return state;
191
193
  }
192
194
  for(var key in state){
193
- var concatKey = prevKey === '' ? key : prevKey + '.' + key;
195
+ var concatKey = prevKey === "" ? key : prevKey + "." + key;
194
196
  var obj = state[key];
195
- if (typeof obj === 'object' && obj !== null) {
197
+ if (typeof obj === "object" && obj !== null) {
196
198
  // @ts-ignore
197
199
  state[key] = proxyState(obj, callback, beforeSetCallback, concatKey);
198
200
  }
@@ -203,7 +205,7 @@ function flatInstanceForChildren(controls) {
203
205
  var result = [];
204
206
  controls.forEach(function(item) {
205
207
  result.push(item);
206
- if (item.controlType === 'layout') {
208
+ if (item.controlType === "layout") {
207
209
  var _result;
208
210
  (_result = result).push.apply(_result, _toConsumableArray(flatInstanceForChildren(item.children)));
209
211
  }
@@ -214,9 +216,9 @@ function flatInstanceForChildren(controls) {
214
216
  * 在flatInstance中通过key查找出对应的instance
215
217
  * @param flatInstance 拍平的instance数组
216
218
  * @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
217
- * */ export function findItem(flatInstance, key1, instanceMap) {
218
- if (key1 === '') return undefined;
219
- var keys = key1.split('.');
219
+ * */ export function findItem(flatInstance, key, instanceMap) {
220
+ if (key === "") return undefined;
221
+ var keys = key.split(".");
220
222
  if (keys.length === 0) return undefined;
221
223
  var oneKey = keys[0];
222
224
  var otherKeys = keys.slice(1);
@@ -242,31 +244,31 @@ function flatInstanceForChildren(controls) {
242
244
  // 最后一个key可能是值对象上边的key,比如金额的amount和currency,计算公式的result和unit,所以需要判断前一个控件是不是一个表单控件,是的话就返回最后一个表单控件
243
245
  return findEndItem ? findEndItem : prevItem.controlType === CONTROL_BASE_TYPE.FORM ? prevItem : undefined;
244
246
  } else {
245
- var ref;
246
- var ref1;
247
+ var _prevItem_children;
248
+ var _prevItem_children_index;
247
249
  // 如果有children,则取children中对应的下标,没有的话一直返回prevItem
248
- return (ref1 = prevItem === null || prevItem === void 0 ? void 0 : (ref = prevItem.children) === null || ref === void 0 ? void 0 : ref[index]) !== null && ref1 !== void 0 ? ref1 : prevItem;
250
+ return (_prevItem_children_index = prevItem === null || prevItem === void 0 ? void 0 : (_prevItem_children = prevItem.children) === null || _prevItem_children === void 0 ? void 0 : _prevItem_children[index]) !== null && _prevItem_children_index !== void 0 ? _prevItem_children_index : prevItem;
249
251
  }
250
252
  }, initInstance);
251
253
  }
252
254
  function getArrayNewValue(type, args) {
253
255
  if ([
254
- 'push',
255
- 'unshift'
256
+ "push",
257
+ "unshift"
256
258
  ].includes(type)) {
257
259
  return args;
258
- } else if (type === 'splice') {
260
+ } else if (type === "splice") {
259
261
  return args.slice(2);
260
262
  }
261
263
  return [];
262
264
  }
263
265
  function getArrayNewArgs(type, args, value) {
264
266
  if ([
265
- 'push',
266
- 'unshift'
267
+ "push",
268
+ "unshift"
267
269
  ].includes(type)) {
268
270
  return value;
269
- } else if (type === 'splice') {
271
+ } else if (type === "splice") {
270
272
  return args.slice(0, 2).concat(value);
271
273
  }
272
274
  }
@@ -285,9 +287,9 @@ function getArrayNewArgs(type, args, value) {
285
287
  var result;
286
288
  var addValue = getArrayNewValue(key, args);
287
289
  if (addValue.length) {
288
- var _obj, ref;
290
+ var _this, _this_engineArrayBeforeSetCallbackFlag;
289
291
  // @ts-ignore
290
- var newValue = (ref = (_obj = this)[engineArrayBeforeSetCallbackFlag]) === null || ref === void 0 ? void 0 : ref.call(_obj, // @ts-ignore
292
+ var newValue = (_this_engineArrayBeforeSetCallbackFlag = (_this = this)[engineArrayBeforeSetCallbackFlag]) === null || _this_engineArrayBeforeSetCallbackFlag === void 0 ? void 0 : _this_engineArrayBeforeSetCallbackFlag.call(_this, // @ts-ignore
291
293
  this[engineTargetKey], // @ts-ignore
292
294
  this[engineProxyThisKey], addValue);
293
295
  var newArgs = getArrayNewArgs(key, args, newValue);
@@ -301,8 +303,8 @@ function getArrayNewArgs(type, args, value) {
301
303
  // @ts-ignore
302
304
  result = oldApiHandler.apply(this, args);
303
305
  }
304
- typeof currentHandlerState.callback === 'function' && currentHandlerState.callback(key, args, result);
305
- currentHandlerState.type = '';
306
+ typeof currentHandlerState.callback === "function" && currentHandlerState.callback(key, args, result);
307
+ currentHandlerState.type = "";
306
308
  currentHandlerState.args = [];
307
309
  currentHandlerState.callback = emptyFn;
308
310
  return result;
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './common';
2
- export * from './plugins';
3
- export * from './utils';
1
+ export * from "./common";
2
+ export * from "./plugins";
3
+ export * from "./utils";