@byteluck-fe/model-driven-driven 7.0.0-props.98 → 7.1.0-beta.0
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/README.md +9 -0
- package/dist/esm/Builder.js +2 -6
- package/dist/esm/Designer.js +31 -42
- package/dist/esm/Driven.js +20 -29
- package/dist/esm/Plugin.js +1 -3
- package/dist/esm/Store.js +7 -9
- package/dist/esm/headless/build-info.js +58 -0
- package/dist/esm/headless/control-node.factory.js +669 -0
- package/dist/esm/headless/control-tree.js +106 -0
- package/dist/esm/headless/index.js +11 -0
- package/dist/esm/headless/locale.js +159 -0
- package/dist/esm/headless/model-bindings.js +265 -0
- package/dist/esm/headless/page-compiler.js +47 -0
- package/dist/esm/headless/page-template.factory.js +134 -0
- package/dist/esm/headless/permissions.js +334 -0
- package/dist/esm/headless/saved-model.encoder.js +135 -0
- package/dist/esm/headless/session.js +71 -0
- package/dist/esm/headless/types.js +149 -0
- package/dist/esm/headless/validator.js +140 -0
- package/dist/esm/utils.js +15 -16
- package/dist/headless/index.js +1 -0
- package/dist/headless/index.mjs +1 -0
- package/dist/index.umd.js +11 -3
- package/dist/types/headless/build-info.d.ts +5 -0
- package/dist/types/headless/control-node.factory.d.ts +3 -0
- package/dist/types/headless/control-tree.d.ts +9 -0
- package/dist/types/headless/index.d.ts +11 -0
- package/dist/types/headless/locale.d.ts +26 -0
- package/dist/types/headless/model-bindings.d.ts +3 -0
- package/dist/types/headless/page-compiler.d.ts +5 -0
- package/dist/types/headless/page-template.factory.d.ts +2 -0
- package/dist/types/headless/permissions.d.ts +5 -0
- package/dist/types/headless/saved-model.encoder.d.ts +5 -0
- package/dist/types/headless/session.d.ts +11 -0
- package/dist/types/headless/types.d.ts +36 -0
- package/dist/types/headless/validator.d.ts +9 -0
- package/package.json +29 -7
|
@@ -0,0 +1,106 @@
|
|
|
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 _iterable_to_array(iter) {
|
|
13
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
14
|
+
return Array.from(iter);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _iterable_to_array_limit(arr, i) {
|
|
18
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
19
|
+
if (_i == null) return;
|
|
20
|
+
var _arr = [];
|
|
21
|
+
var _n = true;
|
|
22
|
+
var _d = false;
|
|
23
|
+
var _s, _e;
|
|
24
|
+
try {
|
|
25
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
26
|
+
_arr.push(_s.value);
|
|
27
|
+
if (i && _arr.length === i) break;
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
_d = true;
|
|
31
|
+
_e = err;
|
|
32
|
+
} finally{
|
|
33
|
+
try {
|
|
34
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
35
|
+
} finally{
|
|
36
|
+
if (_d) throw _e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return _arr;
|
|
40
|
+
}
|
|
41
|
+
function _non_iterable_rest() {
|
|
42
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
+
}
|
|
44
|
+
function _non_iterable_spread() {
|
|
45
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
46
|
+
}
|
|
47
|
+
function _sliced_to_array(arr, i) {
|
|
48
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
49
|
+
}
|
|
50
|
+
function _to_consumable_array(arr) {
|
|
51
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
52
|
+
}
|
|
53
|
+
function _type_of(obj) {
|
|
54
|
+
"@swc/helpers - typeof";
|
|
55
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
56
|
+
}
|
|
57
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
58
|
+
if (!o) return;
|
|
59
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
60
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
61
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
62
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
63
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
64
|
+
}
|
|
65
|
+
function isRecord(value) {
|
|
66
|
+
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
|
|
67
|
+
}
|
|
68
|
+
export function isHeadlessControlNode(value) {
|
|
69
|
+
return Boolean(isRecord(value) && typeof value.id === 'string' && typeof value.type === 'string' && typeof value.controlType === 'string' && isRecord(value.props));
|
|
70
|
+
}
|
|
71
|
+
/** 只收集当前值中最近的控件节点,子控件内部由调用方下一层继续遍历。 */ export function collectNestedControlNodes(value) {
|
|
72
|
+
var path = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
73
|
+
if (isHeadlessControlNode(value)) return [
|
|
74
|
+
{
|
|
75
|
+
node: value,
|
|
76
|
+
path: path
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
return value.flatMap(function(item, index) {
|
|
81
|
+
return collectNestedControlNodes(item, _to_consumable_array(path).concat([
|
|
82
|
+
index
|
|
83
|
+
]));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!isRecord(value)) return [];
|
|
87
|
+
return Object.entries(value).flatMap(function(param) {
|
|
88
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
|
|
89
|
+
return collectNestedControlNodes(item, _to_consumable_array(path).concat([
|
|
90
|
+
key
|
|
91
|
+
]));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export function directNestedControlNodes(node) {
|
|
95
|
+
return _to_consumable_array((node.children || []).map(function(child, index) {
|
|
96
|
+
return {
|
|
97
|
+
node: child,
|
|
98
|
+
path: [
|
|
99
|
+
'children',
|
|
100
|
+
index
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
})).concat(_to_consumable_array(collectNestedControlNodes(node.props, [
|
|
104
|
+
'props'
|
|
105
|
+
])));
|
|
106
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './build-info';
|
|
3
|
+
export * from './locale';
|
|
4
|
+
export * from './control-node.factory';
|
|
5
|
+
export * from './session';
|
|
6
|
+
export * from './page-template.factory';
|
|
7
|
+
export * from './saved-model.encoder';
|
|
8
|
+
export * from './model-bindings';
|
|
9
|
+
export * from './permissions';
|
|
10
|
+
export * from './validator';
|
|
11
|
+
export * from './page-compiler';
|
|
@@ -0,0 +1,159 @@
|
|
|
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 _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else obj[key] = value;
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
|
20
|
+
function _iterable_to_array_limit(arr, i) {
|
|
21
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
22
|
+
if (_i == null) return;
|
|
23
|
+
var _arr = [];
|
|
24
|
+
var _n = true;
|
|
25
|
+
var _d = false;
|
|
26
|
+
var _s, _e;
|
|
27
|
+
try {
|
|
28
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
29
|
+
_arr.push(_s.value);
|
|
30
|
+
if (i && _arr.length === i) break;
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
_d = true;
|
|
34
|
+
_e = err;
|
|
35
|
+
} finally{
|
|
36
|
+
try {
|
|
37
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
38
|
+
} finally{
|
|
39
|
+
if (_d) throw _e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return _arr;
|
|
43
|
+
}
|
|
44
|
+
function _non_iterable_rest() {
|
|
45
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
46
|
+
}
|
|
47
|
+
function _object_spread(target) {
|
|
48
|
+
for(var i = 1; i < arguments.length; i++){
|
|
49
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
50
|
+
var ownKeys = Object.keys(source);
|
|
51
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
52
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
53
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
ownKeys.forEach(function(key) {
|
|
57
|
+
_define_property(target, key, source[key]);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
function _sliced_to_array(arr, i) {
|
|
63
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
64
|
+
}
|
|
65
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
66
|
+
if (!o) return;
|
|
67
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
68
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
69
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
70
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
71
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
72
|
+
}
|
|
73
|
+
import { getControlLocaleMessageFact } from '@byteluck-fe/model-driven-controls/catalog';
|
|
74
|
+
export var DEFAULT_HEADLESS_LOCALE = 'zh-CN';
|
|
75
|
+
/** page/permission 使用稳定消息 key;调用方可为任意 locale 注入同名消息。 */ export var HEADLESS_MESSAGE_KEYS = {
|
|
76
|
+
approvedDocuments: 'CMD.approvedDocuments',
|
|
77
|
+
processStatus: 'CMD.processStatus',
|
|
78
|
+
permissionView: 'CMD.view',
|
|
79
|
+
permissionEdit: 'CMD.edit',
|
|
80
|
+
permissionDelete: 'CMD.delete'
|
|
81
|
+
};
|
|
82
|
+
var HEADLESS_MESSAGE_FACTS = {
|
|
83
|
+
approvedDocuments: {
|
|
84
|
+
key: HEADLESS_MESSAGE_KEYS.approvedDocuments,
|
|
85
|
+
fallback: '审批通过单据'
|
|
86
|
+
},
|
|
87
|
+
processStatus: {
|
|
88
|
+
key: HEADLESS_MESSAGE_KEYS.processStatus,
|
|
89
|
+
fallback: '流程状态'
|
|
90
|
+
},
|
|
91
|
+
permissionView: {
|
|
92
|
+
key: HEADLESS_MESSAGE_KEYS.permissionView,
|
|
93
|
+
fallback: '查看'
|
|
94
|
+
},
|
|
95
|
+
permissionEdit: {
|
|
96
|
+
key: HEADLESS_MESSAGE_KEYS.permissionEdit,
|
|
97
|
+
fallback: '编辑'
|
|
98
|
+
},
|
|
99
|
+
permissionDelete: {
|
|
100
|
+
key: HEADLESS_MESSAGE_KEYS.permissionDelete,
|
|
101
|
+
fallback: '删除'
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 只做通用 BCP 47 规范化,不维护语言枚举;未知但非空的 locale 保持原语义。
|
|
106
|
+
*/ export function normalizeHeadlessLocale(locale) {
|
|
107
|
+
if (typeof locale !== 'string' || !locale.trim()) {
|
|
108
|
+
return DEFAULT_HEADLESS_LOCALE;
|
|
109
|
+
}
|
|
110
|
+
var value = locale.trim().replace(/_/g, '-');
|
|
111
|
+
var canonicalize = Intl.getCanonicalLocales;
|
|
112
|
+
if (!canonicalize) return value;
|
|
113
|
+
try {
|
|
114
|
+
return canonicalize.call(Intl, value)[0] || value;
|
|
115
|
+
} catch (_error) {
|
|
116
|
+
// 自定义 locale 标识也允许透传,不能因为不在平台枚举内降级成中文。
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function getHeadlessMessageFact(key) {
|
|
121
|
+
return _object_spread({}, HEADLESS_MESSAGE_FACTS[key]);
|
|
122
|
+
}
|
|
123
|
+
function nonEmptyText(value) {
|
|
124
|
+
return typeof value === 'string' && value.length > 0;
|
|
125
|
+
}
|
|
126
|
+
function languageSubtag(locale) {
|
|
127
|
+
var normalized = normalizeHeadlessLocale(locale);
|
|
128
|
+
var match = /^([A-Za-z]{2,8})(?:-|$)/.exec(normalized);
|
|
129
|
+
return match === null || match === void 0 ? void 0 : match[1].toLowerCase();
|
|
130
|
+
}
|
|
131
|
+
/** exact 未命中时只采用唯一的同语言候选,多个地区变体时不猜测。 */ function catalogValueForLocale(values, locale) {
|
|
132
|
+
var exactValue = values[locale];
|
|
133
|
+
if (nonEmptyText(exactValue)) return exactValue;
|
|
134
|
+
var language = languageSubtag(locale);
|
|
135
|
+
if (!language) return undefined;
|
|
136
|
+
var candidates = Object.entries(values).filter(function(param) {
|
|
137
|
+
var _param = _sliced_to_array(param, 1), candidateLocale = _param[0];
|
|
138
|
+
return languageSubtag(candidateLocale) === language;
|
|
139
|
+
});
|
|
140
|
+
if (candidates.length !== 1) return undefined;
|
|
141
|
+
return nonEmptyText(candidates[0][1]) ? candidates[0][1] : undefined;
|
|
142
|
+
}
|
|
143
|
+
/** 调用方事实优先;未提供时才使用发布内事实与该消息自己的 fallback。 */ export function resolveHeadlessMessage(fact) {
|
|
144
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
145
|
+
var _catalogValueForLocale;
|
|
146
|
+
var _getControlLocaleMessageFact, _options_localeMessages, _options_resolveLocaleMessage;
|
|
147
|
+
var locale = normalizeHeadlessLocale(options.locale);
|
|
148
|
+
var values = fact.values || ((_getControlLocaleMessageFact = getControlLocaleMessageFact(fact.key)) === null || _getControlLocaleMessageFact === void 0 ? void 0 : _getControlLocaleMessageFact.values) || {};
|
|
149
|
+
var directValue = (_options_localeMessages = options.localeMessages) === null || _options_localeMessages === void 0 ? void 0 : _options_localeMessages[fact.key];
|
|
150
|
+
if (nonEmptyText(directValue)) return directValue;
|
|
151
|
+
var resolvedValue = (_options_resolveLocaleMessage = options.resolveLocaleMessage) === null || _options_resolveLocaleMessage === void 0 ? void 0 : _options_resolveLocaleMessage.call(options, {
|
|
152
|
+
key: fact.key,
|
|
153
|
+
locale: locale,
|
|
154
|
+
fallback: fact.fallback,
|
|
155
|
+
values: values
|
|
156
|
+
});
|
|
157
|
+
if (nonEmptyText(resolvedValue)) return resolvedValue;
|
|
158
|
+
return (_catalogValueForLocale = catalogValueForLocale(values, locale)) !== null && _catalogValueForLocale !== void 0 ? _catalogValueForLocale : fact.fallback;
|
|
159
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
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 _iterable_to_array(iter) {
|
|
13
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
14
|
+
return Array.from(iter);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _iterable_to_array_limit(arr, i) {
|
|
18
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
19
|
+
if (_i == null) return;
|
|
20
|
+
var _arr = [];
|
|
21
|
+
var _n = true;
|
|
22
|
+
var _d = false;
|
|
23
|
+
var _s, _e;
|
|
24
|
+
try {
|
|
25
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
26
|
+
_arr.push(_s.value);
|
|
27
|
+
if (i && _arr.length === i) break;
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
_d = true;
|
|
31
|
+
_e = err;
|
|
32
|
+
} finally{
|
|
33
|
+
try {
|
|
34
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
35
|
+
} finally{
|
|
36
|
+
if (_d) throw _e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return _arr;
|
|
40
|
+
}
|
|
41
|
+
function _non_iterable_rest() {
|
|
42
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
43
|
+
}
|
|
44
|
+
function _non_iterable_spread() {
|
|
45
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
46
|
+
}
|
|
47
|
+
function _sliced_to_array(arr, i) {
|
|
48
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
49
|
+
}
|
|
50
|
+
function _to_consumable_array(arr) {
|
|
51
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
52
|
+
}
|
|
53
|
+
function _type_of(obj) {
|
|
54
|
+
"@swc/helpers - typeof";
|
|
55
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
56
|
+
}
|
|
57
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
58
|
+
if (!o) return;
|
|
59
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
60
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
61
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
62
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
63
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
64
|
+
}
|
|
65
|
+
import { getControlDefinition } from '@byteluck-fe/model-driven-controls/catalog';
|
|
66
|
+
function clone(value) {
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
return value.map(function(item) {
|
|
69
|
+
return clone(item);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object') return value;
|
|
73
|
+
return Object.fromEntries(Object.entries(value).map(function(param) {
|
|
74
|
+
var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
|
|
75
|
+
return [
|
|
76
|
+
key,
|
|
77
|
+
clone(item)
|
|
78
|
+
];
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function isRecord(value) {
|
|
82
|
+
return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
function baseBinding(node, parentId) {
|
|
85
|
+
var dataBind = node.props.dataBind;
|
|
86
|
+
var datasourceBind = node.props.datasourceBind;
|
|
87
|
+
if (!node.fieldType && !dataBind && !datasourceBind) return undefined;
|
|
88
|
+
var props = {};
|
|
89
|
+
var binding = {
|
|
90
|
+
controlId: node.id,
|
|
91
|
+
// 旧 BaseControl 直接透传 caption,不在绑定投影阶段做文案兜底。
|
|
92
|
+
caption: node.props.caption,
|
|
93
|
+
type: node.type,
|
|
94
|
+
fieldType: node.fieldType,
|
|
95
|
+
parentId: parentId,
|
|
96
|
+
props: props
|
|
97
|
+
};
|
|
98
|
+
if (dataBind) binding.dataBind = clone(dataBind);
|
|
99
|
+
var optionConfig = node.props.optionConfig;
|
|
100
|
+
if (optionConfig === 'custom') {
|
|
101
|
+
props.options = clone(node.props.options);
|
|
102
|
+
} else if ((optionConfig === 'datasource' || optionConfig === undefined) && datasourceBind) {
|
|
103
|
+
binding.datasourceBind = clone(datasourceBind);
|
|
104
|
+
}
|
|
105
|
+
if (node.props.required !== undefined) {
|
|
106
|
+
binding.required = node.props.required;
|
|
107
|
+
}
|
|
108
|
+
if (node.props.maxLength !== undefined) {
|
|
109
|
+
binding.maxLength = node.props.maxLength;
|
|
110
|
+
}
|
|
111
|
+
if (node.props.encrypted !== undefined) {
|
|
112
|
+
binding.encrypted = node.props.encrypted;
|
|
113
|
+
}
|
|
114
|
+
if (node.props.encryptedMode !== undefined) {
|
|
115
|
+
binding.encryptedMode = node.props.encryptedMode;
|
|
116
|
+
}
|
|
117
|
+
return binding;
|
|
118
|
+
}
|
|
119
|
+
function copyProps() {
|
|
120
|
+
for(var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++){
|
|
121
|
+
keys[_key] = arguments[_key];
|
|
122
|
+
}
|
|
123
|
+
return function(node, binding) {
|
|
124
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
125
|
+
try {
|
|
126
|
+
for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
127
|
+
var key = _step.value;
|
|
128
|
+
var value = node.props[key];
|
|
129
|
+
// 旧 Designer 覆盖只跳过 undefined;空字符串也是调用方的有效显式值。
|
|
130
|
+
if (value !== undefined) binding.props[key] = clone(value);
|
|
131
|
+
}
|
|
132
|
+
} catch (err) {
|
|
133
|
+
_didIteratorError = true;
|
|
134
|
+
_iteratorError = err;
|
|
135
|
+
} finally{
|
|
136
|
+
try {
|
|
137
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
138
|
+
_iterator.return();
|
|
139
|
+
}
|
|
140
|
+
} finally{
|
|
141
|
+
if (_didIteratorError) {
|
|
142
|
+
throw _iteratorError;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
var precisionProjection = function precisionProjection(node, binding) {
|
|
149
|
+
if (node.props.precision !== '' && node.props.precision !== undefined) {
|
|
150
|
+
binding.props.precision = clone(node.props.precision);
|
|
151
|
+
}
|
|
152
|
+
if (typeof node.props.micrometer === 'boolean') {
|
|
153
|
+
binding.props.micrometer = node.props.micrometer;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* 这里逐项承接 controls 中真实存在的 toDataBindModel 覆盖,新增覆盖必须登记并做 parity,
|
|
158
|
+
* 通用投影器不得按控件名称猜测业务字段。
|
|
159
|
+
*/ var BINDING_PROJECTION_REGISTRY = {
|
|
160
|
+
amount: precisionProjection,
|
|
161
|
+
calc: precisionProjection,
|
|
162
|
+
number: precisionProjection,
|
|
163
|
+
'decimal-column': precisionProjection,
|
|
164
|
+
department: copyProps('displayLevel', 'showSubDept'),
|
|
165
|
+
department2: copyProps('displayLevel', 'showSubDept'),
|
|
166
|
+
'organization-selection': copyProps('displayLevel', 'showSubDept'),
|
|
167
|
+
'department-column': copyProps('displayLevel'),
|
|
168
|
+
'date-picker': copyProps('dateType', 'isInternational'),
|
|
169
|
+
'date-range': copyProps('dateType', 'isInternational'),
|
|
170
|
+
'timestamp-column': copyProps('dateType', 'isInternational'),
|
|
171
|
+
'timescope-column': copyProps('dateType', 'isInternational'),
|
|
172
|
+
'select-relation': copyProps('optionDisplayConfig'),
|
|
173
|
+
'custom-column': copyProps('fieldCodeList'),
|
|
174
|
+
'text-column': copyProps('escapeHTML'),
|
|
175
|
+
'operation-column': function(node, binding) {
|
|
176
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
177
|
+
try {
|
|
178
|
+
for(var _iterator = (node.children || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
179
|
+
var child = _step.value;
|
|
180
|
+
if (child.type !== 'operation-button') continue;
|
|
181
|
+
var command = child.props.command;
|
|
182
|
+
if (typeof command === 'string' && command) {
|
|
183
|
+
binding.props[command] = clone(child.props);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
_didIteratorError = true;
|
|
188
|
+
_iteratorError = err;
|
|
189
|
+
} finally{
|
|
190
|
+
try {
|
|
191
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
192
|
+
_iterator.return();
|
|
193
|
+
}
|
|
194
|
+
} finally{
|
|
195
|
+
if (_didIteratorError) {
|
|
196
|
+
throw _iteratorError;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/** 只登记真实 Designer 覆盖过的 parentId 语义,不按名称模糊推断。 */ var BINDING_PARENT_POLICY_REGISTRY = {
|
|
203
|
+
'operation-column': function() {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function projectNode(node, parentId) {
|
|
208
|
+
var _BINDING_PROJECTION_REGISTRY_node_type;
|
|
209
|
+
var definition = getControlDefinition(node.type);
|
|
210
|
+
if (!definition) return [];
|
|
211
|
+
var parentPolicy = BINDING_PARENT_POLICY_REGISTRY[node.type];
|
|
212
|
+
var effectiveParentId = parentPolicy ? parentPolicy(parentId) : parentId;
|
|
213
|
+
if (definition.baseType === 'list') {
|
|
214
|
+
var _BINDING_PROJECTION_REGISTRY_node_type1;
|
|
215
|
+
// 旧 ListControl 忽略外部 parentId,自身始终位于根权限层;headers 使用 list.id。
|
|
216
|
+
var own = baseBinding(node, null);
|
|
217
|
+
if (own) (_BINDING_PROJECTION_REGISTRY_node_type1 = BINDING_PROJECTION_REGISTRY[node.type]) === null || _BINDING_PROJECTION_REGISTRY_node_type1 === void 0 ? void 0 : _BINDING_PROJECTION_REGISTRY_node_type1.call(BINDING_PROJECTION_REGISTRY, node, own);
|
|
218
|
+
var headers = Array.isArray(node.props.headers) ? node.props.headers.filter(function(header) {
|
|
219
|
+
return isRecord(header) && typeof header.type === 'string';
|
|
220
|
+
}) : [];
|
|
221
|
+
return _to_consumable_array(own ? [
|
|
222
|
+
own
|
|
223
|
+
] : []).concat(_to_consumable_array(headers.flatMap(function(header) {
|
|
224
|
+
return projectNode(header, node.id);
|
|
225
|
+
})));
|
|
226
|
+
}
|
|
227
|
+
if ([
|
|
228
|
+
'layout',
|
|
229
|
+
'search',
|
|
230
|
+
'wrap'
|
|
231
|
+
].includes(definition.baseType)) {
|
|
232
|
+
var _BINDING_PROJECTION_REGISTRY_node_type2;
|
|
233
|
+
// LayoutControl 自身调用 super.toDataBindModel() 时不传 parentId;children 沿用传入值。
|
|
234
|
+
var own1 = baseBinding(node, null);
|
|
235
|
+
if (own1) (_BINDING_PROJECTION_REGISTRY_node_type2 = BINDING_PROJECTION_REGISTRY[node.type]) === null || _BINDING_PROJECTION_REGISTRY_node_type2 === void 0 ? void 0 : _BINDING_PROJECTION_REGISTRY_node_type2.call(BINDING_PROJECTION_REGISTRY, node, own1);
|
|
236
|
+
return _to_consumable_array(own1 ? [
|
|
237
|
+
own1
|
|
238
|
+
] : []).concat(_to_consumable_array((node.children || []).flatMap(function(child) {
|
|
239
|
+
return projectNode(child, parentId);
|
|
240
|
+
})));
|
|
241
|
+
}
|
|
242
|
+
var own2 = baseBinding(node, effectiveParentId);
|
|
243
|
+
if (!own2) return [];
|
|
244
|
+
(_BINDING_PROJECTION_REGISTRY_node_type = BINDING_PROJECTION_REGISTRY[node.type]) === null || _BINDING_PROJECTION_REGISTRY_node_type === void 0 ? void 0 : _BINDING_PROJECTION_REGISTRY_node_type.call(BINDING_PROJECTION_REGISTRY, node, own2);
|
|
245
|
+
return [
|
|
246
|
+
own2
|
|
247
|
+
];
|
|
248
|
+
}
|
|
249
|
+
export function getModelBindInfoList(node) {
|
|
250
|
+
if (Array.isArray(node)) return node.flatMap(function(item) {
|
|
251
|
+
return projectNode(item, null);
|
|
252
|
+
});
|
|
253
|
+
var result = projectNode(node, null);
|
|
254
|
+
var definition = getControlDefinition(node.type);
|
|
255
|
+
if (definition && [
|
|
256
|
+
'layout',
|
|
257
|
+
'list',
|
|
258
|
+
'search',
|
|
259
|
+
'wrap'
|
|
260
|
+
].includes(definition.baseType)) {
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
return result[0];
|
|
264
|
+
}
|
|
265
|
+
export var BINDING_PROJECTION_TYPES = Object.freeze(Object.keys(BINDING_PROJECTION_REGISTRY).sort());
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getHeadlessBuildInfo } from './build-info';
|
|
2
|
+
import { getModelBindInfoList } from './model-bindings';
|
|
3
|
+
import { encodeSavedModel } from './saved-model.encoder';
|
|
4
|
+
import { validateControlTree } from './validator';
|
|
5
|
+
function normalizeBindings(value) {
|
|
6
|
+
if (!value) return [];
|
|
7
|
+
return Array.isArray(value) ? value : [
|
|
8
|
+
value
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 编译只做校验、保存模型编码和绑定投影,不访问接口也不读取运行时全局状态。
|
|
13
|
+
*/ export function compilePageModel(input) {
|
|
14
|
+
var validation = validateControlTree(input.root, {
|
|
15
|
+
expectedBuildInfo: input.expectedBuildInfo
|
|
16
|
+
});
|
|
17
|
+
var expectedRootType = input.kind === 'form' ? 'data-view' : 'list-view';
|
|
18
|
+
if (input.root.type !== expectedRootType) {
|
|
19
|
+
validation.diagnostics.push({
|
|
20
|
+
code: 'MODEL_DRIVEN_PAGE_ROOT_TYPE_MISMATCH',
|
|
21
|
+
severity: 'error',
|
|
22
|
+
message: "".concat(input.kind, " page expects root type ").concat(expectedRootType, ", received ").concat(input.root.type),
|
|
23
|
+
path: 'root[0].type',
|
|
24
|
+
controlId: input.root.id,
|
|
25
|
+
controlType: input.root.type
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (validation.diagnostics.some(function(item) {
|
|
29
|
+
return item.severity === 'error';
|
|
30
|
+
})) {
|
|
31
|
+
return {
|
|
32
|
+
ok: false,
|
|
33
|
+
diagnostics: validation.diagnostics,
|
|
34
|
+
buildInfo: getHeadlessBuildInfo()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var model = encodeSavedModel(input.root);
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
model: [
|
|
41
|
+
model
|
|
42
|
+
],
|
|
43
|
+
modelBindInfoList: normalizeBindings(getModelBindInfoList(input.root)),
|
|
44
|
+
diagnostics: validation.diagnostics,
|
|
45
|
+
buildInfo: getHeadlessBuildInfo()
|
|
46
|
+
};
|
|
47
|
+
}
|