@byteluck-fe/model-driven-engine 2.9.0-alpha.9 → 2.9.0-beta.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.
@@ -237,9 +237,10 @@ export var ActionManager = /*#__PURE__*/ function() {
237
237
  e = _state.sent();
238
238
  // 执行的时候不使用throw error,而是使用console.error,避免阻塞内置代码的执行
239
239
  logerror("".concat(action.id, " Exception during calling action: ").concat(e));
240
+ //尤其是在表单提交前事件异常,不能默认允许它通过。
240
241
  return [
241
- 3,
242
- 4
242
+ 2,
243
+ false
243
244
  ];
244
245
  case 4:
245
246
  return [
@@ -348,6 +348,7 @@ import { findItem, proxyState } from "./proxyState";
348
348
  import { ActionManager } from "./ActionManager";
349
349
  import { DataManager } from "./DataManager";
350
350
  import { checkerSubtableValue, checkerValue } from "./checkerValue";
351
+ import { buildUUID } from "../utils/runtimeUtils";
351
352
  if (typeof window !== "undefined") {
352
353
  // @ts-ignore
353
354
  window.engines = {};
@@ -467,7 +468,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
467
468
  {
468
469
  key: "_proxyStateBeforeSetCallback",
469
470
  value: function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
470
- var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
471
+ var _findItem = findItem(key, this), instance = _findItem.instance, rowIndex = _findItem.rowIndex;
471
472
  // 找不到控件说明不是改动控件上的字段,直接通过
472
473
  if (!instance) {
473
474
  return newValue;
@@ -517,7 +518,9 @@ var Engine = /*#__PURE__*/ function(Watcher) {
517
518
  key: "_handlerArrayUpdate",
518
519
  value: function _handlerArrayUpdate(state, key, type, args, result) {
519
520
  var _this = this;
520
- var subtable = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
521
+ var instanceItem = findItem(key, this);
522
+ var subtable = instanceItem.instance;
523
+ debugger;
521
524
  // if (!(subtable instanceof RuntimeListControl)) return
522
525
  if (!((subtable === null || subtable === void 0 ? void 0 : subtable.controlType) === CONTROL_BASE_TYPE.LIST)) return;
523
526
  // 新增多行方法
@@ -602,14 +605,16 @@ var Engine = /*#__PURE__*/ function(Watcher) {
602
605
  result
603
606
  ];
604
607
  }
608
+ var subtableData = this.getState(subtable.id);
609
+ this._handlerSubtableUpdateUid(subtableData);
605
610
  this.emit("list-change", {
606
611
  instance: subtable,
607
- value: this.getState(subtable.id),
612
+ value: subtableData,
608
613
  options: Object.assign({}, options, {
609
614
  changed: createdNewRows,
610
615
  data: createdNewRowsData,
611
616
  deleted: deleted !== null && deleted !== void 0 ? deleted : [],
612
- jsonValue: JSON.stringify(this.getState(subtable.id)),
617
+ jsonValue: JSON.stringify(subtableData),
613
618
  isDeleteLastOne: isDeleteLastOne,
614
619
  type: type,
615
620
  args: args
@@ -620,14 +625,26 @@ var Engine = /*#__PURE__*/ function(Watcher) {
620
625
  }
621
626
  }
622
627
  },
628
+ {
629
+ key: "_handlerSubtableUpdateUid",
630
+ value: function _handlerSubtableUpdateUid(subtableData) {
631
+ subtableData.forEach(function(item) {
632
+ if (!item.uid) {
633
+ Object.assign(item, {
634
+ uid: "new:" + buildUUID("uid")
635
+ });
636
+ }
637
+ });
638
+ }
639
+ },
623
640
  {
624
641
  key: "_handlerObjectUpdate",
625
642
  value: function _handlerObjectUpdate(state, key, value, oldValue) {
626
- var instance = findItem(this.runtime.flatInstances, key, this.runtime.instanceMap);
643
+ var _findItem = findItem(key, this), instance = _findItem.instance, rowIndex = _findItem.rowIndex;
627
644
  if (!instance) {
628
645
  return;
629
646
  }
630
- var index = this.getInstanceRowIndex(instance);
647
+ var index = rowIndex;
631
648
  var options = eventOptionsTemp || {};
632
649
  // if (instance instanceof RuntimeListControl) {
633
650
  if (instance.controlType === CONTROL_BASE_TYPE.LIST && instance.type === CONTROL_TYPE.SUBTABLE) {
@@ -652,6 +669,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
652
669
  if ((options === null || options === void 0 ? void 0 : options.setData) === true) {
653
670
  deleted = [];
654
671
  }
672
+ this._handlerSubtableUpdateUid(newValue);
655
673
  this.emit("list-change", {
656
674
  instance: instance,
657
675
  value: value,
@@ -661,7 +679,8 @@ var Engine = /*#__PURE__*/ function(Watcher) {
661
679
  data: newValue,
662
680
  deleted: deleted,
663
681
  // deleted: oldValue ?? [],
664
- type: "push"
682
+ type: "push",
683
+ jsonValue: JSON.stringify(newValue)
665
684
  })
666
685
  });
667
686
  } else {
@@ -77,9 +77,20 @@ var Store = /*#__PURE__*/ function() {
77
77
  value: function setState(controlId, value, rowIndex) {
78
78
  var _this = this;
79
79
  var controlInfo = this.controlIdMapping[controlId];
80
+ var noProxyValue = JSONCopy(value);
80
81
  if (controlInfo !== undefined) {
82
+ //明细表
83
+ if (controlInfo.children) {
84
+ value.forEach(function(item) {
85
+ if (!item.uid) {
86
+ Object.assign(item, {
87
+ uid: "new:" + buildUUID("uid")
88
+ });
89
+ }
90
+ });
91
+ }
81
92
  //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
82
- this.state[controlInfo.dataView][controlId] = value;
93
+ this.state[controlInfo.dataView][controlId] = noProxyValue;
83
94
  // if (
84
95
  // controlInfo.dataBind instanceof ObjectDataBind &&
85
96
  // isPlainObject(value)
@@ -98,7 +109,7 @@ var Store = /*#__PURE__*/ function() {
98
109
  Object.keys(children).map(function(childControlId) {
99
110
  if (childControlId === controlId) {
100
111
  if (_this.state[dataView][subtableId][rowIndex]) {
101
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
112
+ _this.state[dataView][subtableId][rowIndex][controlId] = noProxyValue;
102
113
  }
103
114
  }
104
115
  });
@@ -106,7 +117,7 @@ var Store = /*#__PURE__*/ function() {
106
117
  });
107
118
  } else {
108
119
  //不存在的 controlId,直接被挂载到外部key
109
- this.state[controlId] = value;
120
+ this.state[controlId] = noProxyValue;
110
121
  }
111
122
  }
112
123
  }
@@ -364,6 +375,13 @@ item) {
364
375
  });
365
376
  });
366
377
  } else {
378
+ if (data[item.props.dataBind.dataCode] === undefined) {
379
+ data[item.props.dataBind.dataCode] = {
380
+ controlId: dataViewId,
381
+ fields: [],
382
+ dataViewId: dataViewId
383
+ };
384
+ }
367
385
  data[item.props.dataBind.dataCode].fields.push({
368
386
  fieldCode: item.props.dataBind.fieldCode,
369
387
  controlId: item.id,
@@ -24,7 +24,7 @@ function _unsupported_iterable_to_array(o, minLen) {
24
24
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
25
25
  }
26
26
  var cc = console;
27
- import { CONTROL_BASE_TYPE, error, logerror } from "@byteluck-fe/model-driven-shared";
27
+ import { error, logerror, JSONCopy } from "@byteluck-fe/model-driven-shared";
28
28
  var proxyArrayApi = [
29
29
  "splice",
30
30
  "push",
@@ -125,7 +125,7 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
125
125
  return Reflect.get(target, propertyKey, receiver);
126
126
  },
127
127
  set: function set(target, propertyKey, value, receiver) {
128
- var newValue = value;
128
+ var newValue = JSONCopy(value);
129
129
  // @ts-ignore
130
130
  var oldValue = target[propertyKey];
131
131
  var concatKey = thisKey === "" ? propertyKey : thisKey + "." + propertyKey;
@@ -142,14 +142,14 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
142
142
  }
143
143
  }
144
144
  var _reProxyState;
145
- newValue = (_reProxyState = reProxyState(value)) !== null && _reProxyState !== void 0 ? _reProxyState : newValue;
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, value, 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,7 +171,7 @@ 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, value, oldValue);
174
+ callback.call(null, target, concatKey, newValue, oldValue);
175
175
  }
176
176
  // 不返回falsy 值(即 false、0、null、undefined、空字符串等)
177
177
  //fix: TypeError: Proxy object's 'set' trap returned falsy value for property 'length'
@@ -216,40 +216,33 @@ function flatInstanceForChildren(controls) {
216
216
  * 在flatInstance中通过key查找出对应的instance
217
217
  * @param flatInstance 拍平的instance数组
218
218
  * @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
219
- * */ export function findItem(flatInstance, key, instanceMap) {
220
- if (key === "") return undefined;
219
+ * */ export function findItem(key, engine) {
220
+ if (key === "") return {
221
+ instance: undefined,
222
+ rowIndex: undefined
223
+ };
221
224
  var keys = key.split(".");
222
- if (keys.length === 0) return undefined;
223
- var oneKey = keys[0];
224
- var otherKeys = keys.slice(1);
225
- // 3.4.1 优化速度,读取instanceMap
226
- // cc.time('findItem flatInstance find')
227
- // const initInstance = flatInstance.find((item) => item.id === oneKey)
228
- // cc.log('🏠 findItem flatInstance find result', initInstance)
229
- // cc.timeEnd('findItem flatInstance find')
230
- // cc.time('findItem instanceMap match')
231
- var initInstance = instanceMap[oneKey] ? instanceMap[oneKey][0] : undefined;
232
- // cc.log('🏠 findItem instanceMap match result', initInstance)
233
- // cc.timeEnd('findItem instanceMap match')
234
- if (otherKeys.length === 0) return initInstance;
235
- // @ts-ignore
236
- return otherKeys.reduce(function(prevItem, key) {
237
- var index = Number(key);
238
- var isNotIndex = Number.isNaN(index);
239
- if (isNotIndex && prevItem) {
240
- var flatChildren = (prevItem === null || prevItem === void 0 ? void 0 : prevItem.children) ? flatInstanceForChildren(prevItem.children) : undefined;
241
- var findEndItem = flatChildren === null || flatChildren === void 0 ? void 0 : flatChildren.find(function(item) {
242
- return item.id === key;
243
- });
244
- // 最后一个key可能是值对象上边的key,比如金额的amount和currency,计算公式的result和unit,所以需要判断前一个控件是不是一个表单控件,是的话就返回最后一个表单控件
245
- return findEndItem ? findEndItem : prevItem.controlType === CONTROL_BASE_TYPE.FORM ? prevItem : undefined;
246
- } else {
247
- var _prevItem_children;
248
- var _prevItem_children_index;
249
- // 如果有children,则取children中对应的下标,没有的话一直返回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;
251
- }
252
- }, initInstance);
225
+ if (keys.length === 0) return {
226
+ instance: undefined,
227
+ rowIndex: undefined
228
+ };
229
+ var instanceIndex = keys.filter(function(item) {
230
+ return !isNaN(item);
231
+ }).at(-1);
232
+ var findKeyIndex = instanceIndex ? keys.lastIndexOf(instanceIndex) : -1;
233
+ var rowIndex;
234
+ var controlId;
235
+ if (findKeyIndex > -1) {
236
+ rowIndex = Number(keys[findKeyIndex]);
237
+ controlId = keys === null || keys === void 0 ? void 0 : keys[findKeyIndex + 1];
238
+ } else {
239
+ controlId = keys[1];
240
+ }
241
+ var proxyInstance = engine.getInstance(controlId, rowIndex);
242
+ return {
243
+ instance: proxyInstance,
244
+ rowIndex: rowIndex
245
+ };
253
246
  }
254
247
  function getArrayNewValue(type, args) {
255
248
  if ([
@@ -213,7 +213,7 @@ export var ControlsEventPlugin = /*#__PURE__*/ function() {
213
213
  switch(_state.label){
214
214
  case 0:
215
215
  // 初始化state的时候不触发change事件,必须在engine mounted以后才触发
216
- if (eventKey === "change" && !_this.engine.isMounted) {
216
+ if ((eventKey === "change" || eventKey === "list-change") && !_this.engine.isMounted) {
217
217
  return [
218
218
  2
219
219
  ];
@@ -201,6 +201,7 @@ function _ts_generator(thisArg, body) {
201
201
  }
202
202
  }
203
203
  var LifecycleEventKeyMap = {
204
+ "engine-initialized": "did_init",
204
205
  "engine-mounted": "did_mount",
205
206
  "engine-submit": "will_submit",
206
207
  "engine-submit-params": "do_submit",
@@ -1,4 +1,10 @@
1
- function _class_call_check(instance, Constructor) {
1
+ /*
2
+ * @Author: zhaoxiaoyang zhaoxiaoyang@byteluck.com
3
+ * @Date: 2022-04-15 14:06:03
4
+ * @LastEditors: zhaoxiaoyang zhaoxiaoyang@byteluck.com
5
+ * @LastEditTime: 2023-11-30 16:38:47
6
+ * @FilePath: /model-driven/packages/engine/src/plugins/StylePlugin.ts
7
+ */ function _class_call_check(instance, Constructor) {
2
8
  if (!(instance instanceof Constructor)) {
3
9
  throw new TypeError("Cannot call a class as a function");
4
10
  }
@@ -1,6 +1,6 @@
1
1
  import { CONTROL_BASE_TYPE, CONTROL_TYPE } from "@byteluck-fe/model-driven-shared";
2
2
  export function hasChildrenControl(instance) {
3
- return instance.controlType === CONTROL_BASE_TYPE.LAYOUT || instance.controlType === CONTROL_BASE_TYPE.WRAP || instance.controlType === CONTROL_BASE_TYPE.LIST || instance.controlType === CONTROL_BASE_TYPE.SEARCH;
3
+ return instance.controlType === CONTROL_BASE_TYPE.LAYOUT || instance.controlType === CONTROL_BASE_TYPE.WRAP || instance.controlType === CONTROL_BASE_TYPE.LIST || instance.controlType === CONTROL_BASE_TYPE.SEARCH || instance.controlType === CONTROL_BASE_TYPE.COLUMN && instance.type !== CONTROL_TYPE.OPERATION_COLUMN;
4
4
  }
5
5
  export function loopFormControl(control, callback) {
6
6
  if (Array.isArray(control)) {