@byteluck-fe/model-driven-driven 1.3.0-beta.25 → 1.5.0-beta.10
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/esm/Builder.js +96 -0
- package/dist/esm/Designer.js +232 -0
- package/dist/esm/Driven.js +631 -0
- package/dist/esm/EventLogic.js +2 -0
- package/dist/esm/Plugin.js +10 -0
- package/dist/esm/Store.js +295 -0
- package/dist/esm/constants.js +33 -0
- package/dist/esm/designerUtils.js +34 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/utils.js +429 -0
- package/dist/index.umd.js +3 -0
- package/dist/types/Builder.d.ts +8 -0
- package/dist/types/Designer.d.ts +36 -0
- package/dist/types/Driven.d.ts +108 -0
- package/dist/types/EventLogic.d.ts +2 -0
- package/dist/types/Plugin.d.ts +6 -0
- package/dist/types/Store.d.ts +82 -0
- package/dist/types/constants.d.ts +6 -0
- package/dist/types/designerUtils.d.ts +4 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/utils.d.ts +55 -0
- package/package.json +7 -7
- package/src/index.ts +0 -8
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _arrayWithoutHoles(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
+
}
|
|
12
|
+
function _classCallCheck(instance, Constructor) {
|
|
13
|
+
if (!(instance instanceof Constructor)) {
|
|
14
|
+
throw new TypeError("Cannot call a class as a function");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _defineProperties(target, props) {
|
|
18
|
+
for(var i = 0; i < props.length; i++){
|
|
19
|
+
var descriptor = props[i];
|
|
20
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
21
|
+
descriptor.configurable = true;
|
|
22
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
23
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
27
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
28
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
29
|
+
return Constructor;
|
|
30
|
+
}
|
|
31
|
+
function _instanceof(left, right) {
|
|
32
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
33
|
+
return !!right[Symbol.hasInstance](left);
|
|
34
|
+
} else {
|
|
35
|
+
return left instanceof right;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function _iterableToArray(iter) {
|
|
39
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
40
|
+
}
|
|
41
|
+
function _iterableToArrayLimit(arr, i) {
|
|
42
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
43
|
+
if (_i == null) return;
|
|
44
|
+
var _arr = [];
|
|
45
|
+
var _n = true;
|
|
46
|
+
var _d = false;
|
|
47
|
+
var _s, _e;
|
|
48
|
+
try {
|
|
49
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
50
|
+
_arr.push(_s.value);
|
|
51
|
+
if (i && _arr.length === i) break;
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_d = true;
|
|
55
|
+
_e = err;
|
|
56
|
+
} finally{
|
|
57
|
+
try {
|
|
58
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
59
|
+
} finally{
|
|
60
|
+
if (_d) throw _e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return _arr;
|
|
64
|
+
}
|
|
65
|
+
function _nonIterableRest() {
|
|
66
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
67
|
+
}
|
|
68
|
+
function _nonIterableSpread() {
|
|
69
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
|
+
}
|
|
71
|
+
function _slicedToArray(arr, i) {
|
|
72
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
73
|
+
}
|
|
74
|
+
function _toConsumableArray(arr) {
|
|
75
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
76
|
+
}
|
|
77
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
78
|
+
if (!o) return;
|
|
79
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
80
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
81
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
82
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
83
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
84
|
+
}
|
|
85
|
+
import { DesignerFormControl, DataBind } from "@byteluck-fe/model-driven-core";
|
|
86
|
+
import { hasChildrenControl, hasHeaderControl } from "./designerUtils";
|
|
87
|
+
import { Group } from "@byteluck-fe/model-driven-settings";
|
|
88
|
+
import { CONTROL_TYPE } from "@byteluck-fe/model-driven-shared";
|
|
89
|
+
// 维护当前selected,。。 selectedControlSetting
|
|
90
|
+
export var Store = /*#__PURE__*/ function() {
|
|
91
|
+
"use strict";
|
|
92
|
+
function Store(options) {
|
|
93
|
+
_classCallCheck(this, Store);
|
|
94
|
+
/**
|
|
95
|
+
* 当前选中的控件
|
|
96
|
+
* */ this.selected = null;
|
|
97
|
+
/**
|
|
98
|
+
* 当前选中的数据作用域控件
|
|
99
|
+
* */ this.selectedInstanceDataScopeParent = null;
|
|
100
|
+
this.selectedDataScopeFlatInstances = [];
|
|
101
|
+
/**
|
|
102
|
+
* 当前选中控件的setting
|
|
103
|
+
* */ this.selectedInstanceSetting = [];
|
|
104
|
+
this.selectedInstanceSettingItems = [];
|
|
105
|
+
/**
|
|
106
|
+
* 当前选中控件的数据模型
|
|
107
|
+
* */ this.selectedFieldItem = null;
|
|
108
|
+
/**
|
|
109
|
+
* 扩展字段,比如appId,dataCode等
|
|
110
|
+
* */ this.external = {};
|
|
111
|
+
this.movingInstance = null;
|
|
112
|
+
this.movingInstanceOldParent = null;
|
|
113
|
+
this.movingInstanceOldDataScopeParent = null;
|
|
114
|
+
var _getParentBeforeInstanceMove;
|
|
115
|
+
this.getParentBeforeInstanceMove = (_getParentBeforeInstanceMove = options.getParentBeforeInstanceMove) !== null && _getParentBeforeInstanceMove !== void 0 ? _getParentBeforeInstanceMove : function(instance) {
|
|
116
|
+
return instance.parent;
|
|
117
|
+
};
|
|
118
|
+
this.instance = options.instance;
|
|
119
|
+
this.getFlatInstances();
|
|
120
|
+
}
|
|
121
|
+
var _proto = Store.prototype;
|
|
122
|
+
_proto.setInstances = function setInstances(instances) {
|
|
123
|
+
this.instance = instances;
|
|
124
|
+
this.getFlatInstances();
|
|
125
|
+
};
|
|
126
|
+
_proto.setSelectInstance = function setSelectInstance(instance) {
|
|
127
|
+
this.selected = instance;
|
|
128
|
+
this.selectedInstanceDataScopeParent = instance ? findInstanceDataScopeParent(instance) : null;
|
|
129
|
+
this.selectedDataScopeFlatInstances = this.selectedInstanceDataScopeParent ? getDataScopeFlatInstances(this.selectedInstanceDataScopeParent) : [];
|
|
130
|
+
};
|
|
131
|
+
_proto.setSelectInstanceSettings = function setSelectInstanceSettings(settings) {
|
|
132
|
+
var _this = this;
|
|
133
|
+
this.selectedInstanceSetting = settings;
|
|
134
|
+
this.selectedInstanceSettingItems = [];
|
|
135
|
+
this.selectedInstanceSetting.forEach(function(group) {
|
|
136
|
+
var _selectedInstanceSettingItems;
|
|
137
|
+
(_selectedInstanceSettingItems = _this.selectedInstanceSettingItems).push.apply(_selectedInstanceSettingItems, _toConsumableArray(_this.getSettingItems(group)));
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
_proto.getSettingItems = function getSettingItems(group) {
|
|
141
|
+
return _instanceof(group, Group) ? group.items : group.items.reduce(function(result, curr) {
|
|
142
|
+
var _result;
|
|
143
|
+
(_result = result).push.apply(_result, _toConsumableArray(curr.items));
|
|
144
|
+
return result;
|
|
145
|
+
}, []);
|
|
146
|
+
};
|
|
147
|
+
_proto.setSelectedFieldItem = function setSelectedFieldItem(fieldItem) {
|
|
148
|
+
this.selectedFieldItem = fieldItem;
|
|
149
|
+
};
|
|
150
|
+
_proto.setMovingInstance = function setMovingInstance(instance) {
|
|
151
|
+
this.movingInstance = instance;
|
|
152
|
+
this.movingInstanceOldParent = instance ? this.getParentBeforeInstanceMove(instance) : null;
|
|
153
|
+
this.movingInstanceOldDataScopeParent = findInstanceDataScopeParent(instance);
|
|
154
|
+
};
|
|
155
|
+
_proto.updateDataFieldCodeMap = function updateDataFieldCodeMap(instance) {
|
|
156
|
+
var scopeParent = findInstanceDataScopeParent(instance);
|
|
157
|
+
if (!scopeParent) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
var map = this.dataFieldCodeMap.get(scopeParent.props.datasourceBind.dataCode);
|
|
161
|
+
if (!map) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
165
|
+
try {
|
|
166
|
+
for(var _iterator = map.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
167
|
+
var _value = _slicedToArray(_step.value, 2), key = _value[0], value = _value[1];
|
|
168
|
+
if (value.id === instance.id) {
|
|
169
|
+
map.delete(key);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
_didIteratorError = true;
|
|
175
|
+
_iteratorError = err;
|
|
176
|
+
} finally{
|
|
177
|
+
try {
|
|
178
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
179
|
+
_iterator.return();
|
|
180
|
+
}
|
|
181
|
+
} finally{
|
|
182
|
+
if (_didIteratorError) {
|
|
183
|
+
throw _iteratorError;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
setInstanceInDataFieldCodeMap(instance, this.dataFieldCodeMap);
|
|
188
|
+
};
|
|
189
|
+
_proto.getFlatInstances = function getFlatInstances() {
|
|
190
|
+
var instances = [];
|
|
191
|
+
var instanceIdMap = new Map();
|
|
192
|
+
var dataFieldCodeMap = new Map();
|
|
193
|
+
loop(this.instance, function(instance) {
|
|
194
|
+
instances.push(instance);
|
|
195
|
+
instanceIdMap.set(instance.id, instance);
|
|
196
|
+
setInstanceInDataFieldCodeMap(instance, dataFieldCodeMap);
|
|
197
|
+
});
|
|
198
|
+
this.flatInstances = instances;
|
|
199
|
+
this.instanceIdMap = instanceIdMap;
|
|
200
|
+
this.dataFieldCodeMap = dataFieldCodeMap;
|
|
201
|
+
};
|
|
202
|
+
_createClass(Store, [
|
|
203
|
+
{
|
|
204
|
+
key: "selectedRules",
|
|
205
|
+
get: /**
|
|
206
|
+
* 当前选中控件的rules
|
|
207
|
+
* */ function get() {
|
|
208
|
+
if (!this.selected) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return this.selected.rules;
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
key: "selectedAntdRules",
|
|
216
|
+
get: /**
|
|
217
|
+
* 当前选中控件的antd rules
|
|
218
|
+
* */ function get() {
|
|
219
|
+
var rules = this.selectedRules;
|
|
220
|
+
if (!rules) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
// TODO 转换Antd rules
|
|
224
|
+
return rules;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
]);
|
|
228
|
+
return Store;
|
|
229
|
+
}();
|
|
230
|
+
function setDataFieldCodeMap(dataFieldCodeMap, dataBind, instance) {
|
|
231
|
+
var dataCode = dataBind.dataCode, fieldCode = dataBind.fieldCode;
|
|
232
|
+
if (dataCode && fieldCode) {
|
|
233
|
+
if (!dataFieldCodeMap.has(dataCode)) {
|
|
234
|
+
dataFieldCodeMap.set(dataCode, new Map());
|
|
235
|
+
}
|
|
236
|
+
dataFieldCodeMap.get(dataCode).set(fieldCode, instance);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function setInstanceInDataFieldCodeMap(instance, dataFieldCodeMap) {
|
|
240
|
+
if (_instanceof(instance, DesignerFormControl)) {
|
|
241
|
+
var dataBind = instance.props.dataBind;
|
|
242
|
+
if (_instanceof(dataBind, DataBind)) {
|
|
243
|
+
setDataFieldCodeMap(dataFieldCodeMap, dataBind, instance);
|
|
244
|
+
} else {
|
|
245
|
+
Object.values(dataBind).forEach(function(subDataBind) {
|
|
246
|
+
setDataFieldCodeMap(dataFieldCodeMap, subDataBind, instance);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
export function loop(instances, callback) {
|
|
252
|
+
var _instances = Array.isArray(instances) ? instances : [
|
|
253
|
+
instances
|
|
254
|
+
];
|
|
255
|
+
_instances.forEach(function(item) {
|
|
256
|
+
callback(item);
|
|
257
|
+
if (hasChildrenControl(item)) {
|
|
258
|
+
loop(item.children, callback);
|
|
259
|
+
}
|
|
260
|
+
if (hasHeaderControl(item)) {
|
|
261
|
+
loop(item.props.headers, callback);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
export function isDataScopeInstance(instance) {
|
|
266
|
+
return [
|
|
267
|
+
CONTROL_TYPE.SUBTABLE,
|
|
268
|
+
CONTROL_TYPE.DATA_VIEW,
|
|
269
|
+
CONTROL_TYPE.LIST_VIEW,
|
|
270
|
+
].includes(instance.type);
|
|
271
|
+
}
|
|
272
|
+
export function findInstanceDataScopeParent(instance) {
|
|
273
|
+
var parent = instance ? instance.parent : null;
|
|
274
|
+
if (!parent) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
while(parent && !isDataScopeInstance(parent)){
|
|
278
|
+
parent = parent.parent;
|
|
279
|
+
}
|
|
280
|
+
return parent;
|
|
281
|
+
}
|
|
282
|
+
export function getDataScopeFlatInstances(dataScopeInstance) {
|
|
283
|
+
var result = [
|
|
284
|
+
dataScopeInstance
|
|
285
|
+
];
|
|
286
|
+
loop(dataScopeInstance, function(instance) {
|
|
287
|
+
if (instance === dataScopeInstance) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (result.includes(instance.parent) && !isDataScopeInstance(instance)) {
|
|
291
|
+
result.push(instance);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CONTROL_TYPE, FieldTypes } from "@byteluck-fe/model-driven-shared";
|
|
2
|
+
// 使用ObjectDataBind的控件
|
|
3
|
+
export var objectDataBindControlTypes = [
|
|
4
|
+
CONTROL_TYPE.AMOUNT,
|
|
5
|
+
CONTROL_TYPE.CALC,
|
|
6
|
+
CONTROL_TYPE.DATE_RANGE,
|
|
7
|
+
];
|
|
8
|
+
export var objectDataBindKeyToFieldType = {
|
|
9
|
+
amount: {
|
|
10
|
+
caption: "金额",
|
|
11
|
+
fieldType: FieldTypes.DECIMAL
|
|
12
|
+
},
|
|
13
|
+
currency: {
|
|
14
|
+
caption: "币种",
|
|
15
|
+
fieldType: FieldTypes.VARCHAR
|
|
16
|
+
},
|
|
17
|
+
result: {
|
|
18
|
+
caption: "结果",
|
|
19
|
+
fieldType: FieldTypes.DECIMAL
|
|
20
|
+
},
|
|
21
|
+
unit: {
|
|
22
|
+
caption: "单位",
|
|
23
|
+
fieldType: FieldTypes.VARCHAR
|
|
24
|
+
},
|
|
25
|
+
min: {
|
|
26
|
+
caption: "开始时间",
|
|
27
|
+
fieldType: FieldTypes.TIMESTAMP
|
|
28
|
+
},
|
|
29
|
+
max: {
|
|
30
|
+
caption: "结束时间",
|
|
31
|
+
fieldType: FieldTypes.TIMESTAMP
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function _instanceof(left, right) {
|
|
2
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
3
|
+
return !!right[Symbol.hasInstance](left);
|
|
4
|
+
} else {
|
|
5
|
+
return left instanceof right;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
import { DesignerFormControl } from "@byteluck-fe/model-driven-core";
|
|
9
|
+
import { CONTROL_TYPE, isArray } from "@byteluck-fe/model-driven-shared";
|
|
10
|
+
export function hasChildrenControl(instance) {
|
|
11
|
+
return "children" in instance && isArray(instance.children);
|
|
12
|
+
}
|
|
13
|
+
export function hasHeaderControl(instance) {
|
|
14
|
+
return "headers" in instance.props && isArray(instance.props.headers);
|
|
15
|
+
}
|
|
16
|
+
export function loopFormControl(control, callback) {
|
|
17
|
+
if (Array.isArray(control)) {
|
|
18
|
+
control.map(function(item) {
|
|
19
|
+
//TODO 此处需要再抽象一层 datagrid/datalist
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
if (item.type === CONTROL_TYPE.SUBTABLE) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
loopFormControl(item.props.headers, callback);
|
|
24
|
+
} else if (hasChildrenControl(item)) {
|
|
25
|
+
var // @ts-ignore
|
|
26
|
+
ref;
|
|
27
|
+
loopFormControl((ref = (item)) === null || ref === void 0 ? void 0 : ref.children, callback);
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
} else if (_instanceof(item, DesignerFormControl)) {
|
|
30
|
+
callback(item);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|