@byteluck-fe/model-driven-driven 3.0.0-beta.6 → 3.0.0-beta.9

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.
@@ -0,0 +1,2 @@
1
+ import { EventLogic } from '@byteluck-fe/model-driven-shared';
2
+ export default EventLogic;
@@ -0,0 +1,10 @@
1
+ function _class_call_check(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ var Plugin = function Plugin() {
7
+ "use strict";
8
+ _class_call_check(this, Plugin);
9
+ };
10
+ export { Plugin };
@@ -0,0 +1,352 @@
1
+ function _array_like_to_array(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 _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _class_call_check(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 _create_class(Constructor, protoProps, staticProps) {
27
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
28
+ if (staticProps) _defineProperties(Constructor, staticProps);
29
+ return Constructor;
30
+ }
31
+ function _define_property(obj, key, value) {
32
+ if (key in obj) {
33
+ Object.defineProperty(obj, key, {
34
+ value: value,
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true
38
+ });
39
+ } else {
40
+ obj[key] = value;
41
+ }
42
+ return obj;
43
+ }
44
+ function _iterable_to_array(iter) {
45
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
46
+ }
47
+ function _iterable_to_array_limit(arr, i) {
48
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
49
+ if (_i == null) return;
50
+ var _arr = [];
51
+ var _n = true;
52
+ var _d = false;
53
+ var _s, _e;
54
+ try {
55
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
56
+ _arr.push(_s.value);
57
+ if (i && _arr.length === i) break;
58
+ }
59
+ } catch (err) {
60
+ _d = true;
61
+ _e = err;
62
+ } finally{
63
+ try {
64
+ if (!_n && _i["return"] != null) _i["return"]();
65
+ } finally{
66
+ if (_d) throw _e;
67
+ }
68
+ }
69
+ return _arr;
70
+ }
71
+ function _non_iterable_rest() {
72
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
+ }
74
+ function _non_iterable_spread() {
75
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
76
+ }
77
+ function _sliced_to_array(arr, i) {
78
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
79
+ }
80
+ function _to_consumable_array(arr) {
81
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
82
+ }
83
+ function _unsupported_iterable_to_array(o, minLen) {
84
+ if (!o) return;
85
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
86
+ var n = Object.prototype.toString.call(o).slice(8, -1);
87
+ if (n === "Object" && o.constructor) n = o.constructor.name;
88
+ if (n === "Map" || n === "Set") return Array.from(n);
89
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
90
+ }
91
+ import { isDataBind } from '@byteluck-fe/model-driven-core';
92
+ import { hasChildrenControl, hasHeaderControl } from './designerUtils';
93
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE } from '@byteluck-fe/model-driven-shared';
94
+ // 维护当前selected,。。 selectedControlSetting
95
+ export var Store = /*#__PURE__*/ function() {
96
+ "use strict";
97
+ function Store(options) {
98
+ _class_call_check(this, Store);
99
+ /**
100
+ * 页面控件实例树
101
+ * */ _define_property(this, "instance", void 0);
102
+ /**
103
+ * 拍平的控件数组
104
+ * */ _define_property(this, "flatInstances", void 0);
105
+ /**
106
+ * 控件id组成的map
107
+ * */ _define_property(this, "instanceIdMap", void 0);
108
+ /**
109
+ * dataCode和fieldCode组成的map
110
+ * {
111
+ * [主表dataCode]: {
112
+ * [fieldCode]: 控件
113
+ * },
114
+ * [子表dataCode]: {
115
+ * [fieldCode]: 控件
116
+ * }
117
+ * }
118
+ * */ _define_property(this, "dataFieldCodeMap", void 0);
119
+ /**
120
+ * 当前选中的控件
121
+ * */ _define_property(this, "selected", null);
122
+ /**
123
+ * 当前选中的数据作用域控件
124
+ * */ _define_property(this, "selectedInstanceDataScopeParent", null);
125
+ _define_property(this, "selectedDataScopeFlatInstances", []);
126
+ /**
127
+ * 当前选中控件的setting
128
+ * */ _define_property(this, "selectedInstanceSetting", []);
129
+ _define_property(this, "selectedInstanceSettingItems", []);
130
+ /**
131
+ * 当前选中控件的数据模型
132
+ * */ _define_property(this, "selectedFieldItem", null);
133
+ /**
134
+ * 扩展字段,比如appId,dataCode等
135
+ * */ _define_property(this, "external", {});
136
+ _define_property(this, "movingInstance", null);
137
+ _define_property(this, "movingInstanceOldParent", null);
138
+ _define_property(this, "movingInstanceOldDataScopeParent", null);
139
+ _define_property(this, "getParentBeforeInstanceMove", void 0);
140
+ var _options_getParentBeforeInstanceMove;
141
+ this.getParentBeforeInstanceMove = (_options_getParentBeforeInstanceMove = options.getParentBeforeInstanceMove) !== null && _options_getParentBeforeInstanceMove !== void 0 ? _options_getParentBeforeInstanceMove : function(instance) {
142
+ return instance.parent;
143
+ };
144
+ this.instance = options.instance;
145
+ this.getFlatInstances();
146
+ }
147
+ _create_class(Store, [
148
+ {
149
+ key: "selectedRules",
150
+ get: /**
151
+ * 当前选中控件的rules
152
+ * */ function get() {
153
+ if (!this.selected) {
154
+ return null;
155
+ }
156
+ return this.selected.rules;
157
+ }
158
+ },
159
+ {
160
+ key: "selectedAntdRules",
161
+ get: /**
162
+ * 当前选中控件的antd rules
163
+ * */ function get() {
164
+ var rules = this.selectedRules;
165
+ if (!rules) {
166
+ return null;
167
+ }
168
+ // TODO 转换Antd rules
169
+ return rules;
170
+ }
171
+ },
172
+ {
173
+ key: "setInstances",
174
+ value: function setInstances(instances) {
175
+ this.instance = instances;
176
+ this.getFlatInstances();
177
+ }
178
+ },
179
+ {
180
+ key: "setSelectInstance",
181
+ value: function setSelectInstance(instance) {
182
+ this.selected = instance;
183
+ this.selectedInstanceDataScopeParent = instance ? findInstanceDataScopeParent(instance) : null;
184
+ this.selectedDataScopeFlatInstances = this.selectedInstanceDataScopeParent ? getDataScopeFlatInstances(this.selectedInstanceDataScopeParent) : [];
185
+ }
186
+ },
187
+ {
188
+ key: "setSelectInstanceSettings",
189
+ value: function setSelectInstanceSettings(settings) {
190
+ var _this = this;
191
+ this.selectedInstanceSetting = settings;
192
+ this.selectedInstanceSettingItems = [];
193
+ this.selectedInstanceSetting.forEach(function(group) {
194
+ var _this_selectedInstanceSettingItems;
195
+ (_this_selectedInstanceSettingItems = _this.selectedInstanceSettingItems).push.apply(_this_selectedInstanceSettingItems, _to_consumable_array(_this.getSettingItems(group)));
196
+ });
197
+ }
198
+ },
199
+ {
200
+ key: "getSettingItems",
201
+ value: function getSettingItems(group) {
202
+ // return group instanceof Group
203
+ return group.type === 'group' ? group.items : group.items.reduce(function(result, curr) {
204
+ var _result;
205
+ (_result = result).push.apply(_result, _to_consumable_array(curr.items));
206
+ return result;
207
+ }, []);
208
+ }
209
+ },
210
+ {
211
+ key: "setSelectedFieldItem",
212
+ value: function setSelectedFieldItem(fieldItem) {
213
+ this.selectedFieldItem = fieldItem;
214
+ }
215
+ },
216
+ {
217
+ key: "setMovingInstance",
218
+ value: function setMovingInstance(instance) {
219
+ this.movingInstance = instance;
220
+ this.movingInstanceOldParent = instance ? this.getParentBeforeInstanceMove(instance) : null;
221
+ this.movingInstanceOldDataScopeParent = findInstanceDataScopeParent(instance);
222
+ }
223
+ },
224
+ {
225
+ key: "updateDataFieldCodeMap",
226
+ value: function updateDataFieldCodeMap(instance) {
227
+ var scopeParent = findInstanceDataScopeParent(instance);
228
+ if (!scopeParent) {
229
+ return;
230
+ }
231
+ var map = this.dataFieldCodeMap.get(scopeParent.props.datasourceBind.dataCode);
232
+ if (!map) {
233
+ return;
234
+ }
235
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
236
+ try {
237
+ for(var _iterator = map.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
238
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
239
+ if (value.id === instance.id) {
240
+ map.delete(key);
241
+ break;
242
+ }
243
+ }
244
+ } catch (err) {
245
+ _didIteratorError = true;
246
+ _iteratorError = err;
247
+ } finally{
248
+ try {
249
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
250
+ _iterator.return();
251
+ }
252
+ } finally{
253
+ if (_didIteratorError) {
254
+ throw _iteratorError;
255
+ }
256
+ }
257
+ }
258
+ setInstanceInDataFieldCodeMap(instance, this.dataFieldCodeMap);
259
+ }
260
+ },
261
+ {
262
+ key: "getFlatInstances",
263
+ value: function getFlatInstances() {
264
+ var instances = [];
265
+ var instanceIdMap = new Map();
266
+ var dataFieldCodeMap = new Map();
267
+ loop(this.instance, function(instance) {
268
+ instances.push(instance);
269
+ instanceIdMap.set(instance.id, instance);
270
+ setInstanceInDataFieldCodeMap(instance, dataFieldCodeMap);
271
+ });
272
+ this.flatInstances = instances;
273
+ this.instanceIdMap = instanceIdMap;
274
+ this.dataFieldCodeMap = dataFieldCodeMap;
275
+ }
276
+ }
277
+ ]);
278
+ return Store;
279
+ }();
280
+ function setDataFieldCodeMap(dataFieldCodeMap, dataBind, instance) {
281
+ var dataCode = dataBind.dataCode, fieldCode = dataBind.fieldCode;
282
+ if (dataCode && fieldCode) {
283
+ if (!dataFieldCodeMap.has(dataCode)) {
284
+ dataFieldCodeMap.set(dataCode, new Map());
285
+ }
286
+ dataFieldCodeMap.get(dataCode).set(fieldCode, instance);
287
+ }
288
+ }
289
+ function setInstanceInDataFieldCodeMap(instance, dataFieldCodeMap) {
290
+ // if (instance instanceof DesignerFormControl) {
291
+ if (instance.controlType === CONTROL_BASE_TYPE.FORM) {
292
+ var dataBind = instance.props.dataBind;
293
+ //if (dataBind instanceof DataBind) {
294
+ if (isDataBind(dataBind)) {
295
+ setDataFieldCodeMap(dataFieldCodeMap, dataBind, instance);
296
+ } else {
297
+ if (dataBind) {
298
+ Object.values(dataBind).forEach(function(subDataBind) {
299
+ setDataFieldCodeMap(dataFieldCodeMap, subDataBind, instance);
300
+ });
301
+ }
302
+ }
303
+ }
304
+ }
305
+ export function loop(instances, callback) {
306
+ var _instances = Array.isArray(instances) ? instances : [
307
+ instances
308
+ ];
309
+ _instances.forEach(function(item) {
310
+ callback(item);
311
+ if (hasChildrenControl(item)) {
312
+ loop(item.children, callback);
313
+ }
314
+ if (hasHeaderControl(item)) {
315
+ loop(item.props.headers, callback);
316
+ }
317
+ // if(item)) {
318
+ // loop(item.props?.footers ?? [], callback)
319
+ // }
320
+ });
321
+ }
322
+ export function isDataScopeInstance(instance) {
323
+ return [
324
+ CONTROL_TYPE.SUBTABLE,
325
+ CONTROL_TYPE.DATA_VIEW,
326
+ CONTROL_TYPE.LIST_VIEW
327
+ ].includes(instance.type);
328
+ }
329
+ export function findInstanceDataScopeParent(instance) {
330
+ var parent = instance ? instance.parent : null;
331
+ if (!parent) {
332
+ return null;
333
+ }
334
+ while(parent && !isDataScopeInstance(parent)){
335
+ parent = parent.parent;
336
+ }
337
+ return parent;
338
+ }
339
+ export function getDataScopeFlatInstances(dataScopeInstance) {
340
+ var result = [
341
+ dataScopeInstance
342
+ ];
343
+ loop(dataScopeInstance, function(instance) {
344
+ if (instance === dataScopeInstance) {
345
+ return;
346
+ }
347
+ if (result.includes(instance.parent) && !isDataScopeInstance(instance)) {
348
+ result.push(instance);
349
+ }
350
+ });
351
+ return result;
352
+ }
@@ -0,0 +1,34 @@
1
+ import { getLocaleText } from '@byteluck-fe/locale-message';
2
+ import { CONTROL_TYPE, FieldTypes } from '@byteluck-fe/model-driven-shared';
3
+ // 使用ObjectDataBind 的控件
4
+ export var objectDataBindControlTypes = [
5
+ CONTROL_TYPE.AMOUNT,
6
+ CONTROL_TYPE.CALC,
7
+ CONTROL_TYPE.DATE_RANGE
8
+ ];
9
+ export var objectDataBindKeyToFieldType = {
10
+ amount: {
11
+ caption: getLocaleText('CMD.amount', null, '金额'),
12
+ fieldType: FieldTypes.DECIMAL
13
+ },
14
+ currency: {
15
+ caption: getLocaleText('CMD.currency', null, '币种'),
16
+ fieldType: FieldTypes.VARCHAR
17
+ },
18
+ result: {
19
+ caption: getLocaleText('CMD.result', null, '结果'),
20
+ fieldType: FieldTypes.DECIMAL
21
+ },
22
+ unit: {
23
+ caption: getLocaleText('CMD.unit', null, '单位'),
24
+ fieldType: FieldTypes.VARCHAR
25
+ },
26
+ min: {
27
+ caption: getLocaleText('CMD.startTime', null, '开始时间'),
28
+ fieldType: FieldTypes.TIMESTAMP
29
+ },
30
+ max: {
31
+ caption: getLocaleText('CMD.endTime', null, '结束时间'),
32
+ fieldType: FieldTypes.TIMESTAMP
33
+ }
34
+ };
@@ -0,0 +1,34 @@
1
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, isArray } from '@byteluck-fe/model-driven-shared';
2
+ export function hasChildrenControl(instance) {
3
+ return 'children' in instance && isArray(instance.children);
4
+ }
5
+ export function hasHeaderControl(instance) {
6
+ return 'headers' in instance.props && isArray(instance.props.headers);
7
+ }
8
+ // export function hasFooterControl(
9
+ // instance: DesignerControl
10
+ // ): instance is DesignerListControl {
11
+ // return (
12
+ // 'footers' in instance.props &&
13
+ // isArray((instance as DesignerListControl).props.footers)
14
+ // )
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
+ loopFormControl(// @ts-ignore
26
+ item === null || item === void 0 ? void 0 : item.children, callback);
27
+ // @ts-ignore
28
+ // } else if (item instanceof DesignerFormControl) {
29
+ } else if (item.controlType === CONTROL_BASE_TYPE.FORM) {
30
+ callback(item);
31
+ }
32
+ });
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ import Designer from './Designer';
2
+ export { Designer };
3
+ export * from './utils';
4
+ export * from './Builder';
5
+ export * from './designerUtils';
6
+ export * from './Driven';
7
+ export * from './Store';