@byteluck-fe/model-driven-driven 7.0.0-props.99 → 7.1.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.
Files changed (45) hide show
  1. package/README.md +13 -0
  2. package/dist/esm/Builder.js +2 -6
  3. package/dist/esm/Designer.js +31 -42
  4. package/dist/esm/Driven.js +20 -29
  5. package/dist/esm/Plugin.js +1 -3
  6. package/dist/esm/Store.js +7 -9
  7. package/dist/esm/headless/build-info.js +58 -0
  8. package/dist/esm/headless/control-id.js +73 -0
  9. package/dist/esm/headless/control-node.factory.js +669 -0
  10. package/dist/esm/headless/control-tree.js +106 -0
  11. package/dist/esm/headless/index.js +15 -0
  12. package/dist/esm/headless/locale.js +159 -0
  13. package/dist/esm/headless/model-bindings.js +265 -0
  14. package/dist/esm/headless/page-change-validator.js +202 -0
  15. package/dist/esm/headless/page-compiler.js +36 -0
  16. package/dist/esm/headless/page-template.factory.js +134 -0
  17. package/dist/esm/headless/permissions.js +334 -0
  18. package/dist/esm/headless/reserved-control-ids.js +258 -0
  19. package/dist/esm/headless/saved-model.decoder.js +171 -0
  20. package/dist/esm/headless/saved-model.encoder.js +135 -0
  21. package/dist/esm/headless/session.js +71 -0
  22. package/dist/esm/headless/types.js +149 -0
  23. package/dist/esm/headless/validator.js +146 -0
  24. package/dist/esm/utils.js +15 -16
  25. package/dist/headless/index.js +1 -0
  26. package/dist/headless/index.mjs +1 -0
  27. package/dist/index.umd.js +11 -3
  28. package/dist/types/headless/build-info.d.ts +5 -0
  29. package/dist/types/headless/control-id.d.ts +29 -0
  30. package/dist/types/headless/control-node.factory.d.ts +3 -0
  31. package/dist/types/headless/control-tree.d.ts +9 -0
  32. package/dist/types/headless/index.d.ts +15 -0
  33. package/dist/types/headless/locale.d.ts +26 -0
  34. package/dist/types/headless/model-bindings.d.ts +3 -0
  35. package/dist/types/headless/page-change-validator.d.ts +9 -0
  36. package/dist/types/headless/page-compiler.d.ts +5 -0
  37. package/dist/types/headless/page-template.factory.d.ts +2 -0
  38. package/dist/types/headless/permissions.d.ts +5 -0
  39. package/dist/types/headless/reserved-control-ids.d.ts +15 -0
  40. package/dist/types/headless/saved-model.decoder.d.ts +12 -0
  41. package/dist/types/headless/saved-model.encoder.d.ts +5 -0
  42. package/dist/types/headless/session.d.ts +11 -0
  43. package/dist/types/headless/types.d.ts +36 -0
  44. package/dist/types/headless/validator.d.ts +10 -0
  45. package/package.json +29 -7
@@ -0,0 +1,171 @@
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 _type_of(obj) {
66
+ "@swc/helpers - typeof";
67
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
68
+ }
69
+ function _unsupported_iterable_to_array(o, minLen) {
70
+ if (!o) return;
71
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
72
+ var n = Object.prototype.toString.call(o).slice(8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return Array.from(n);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
76
+ }
77
+ import { getControlDefinition } from '@byteluck-fe/model-driven-controls/catalog';
78
+ function isRecord(value) {
79
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
80
+ }
81
+ function parsedModel(value) {
82
+ if (typeof value !== 'string') return value;
83
+ try {
84
+ return JSON.parse(value);
85
+ } catch (_error) {
86
+ return undefined;
87
+ }
88
+ }
89
+ function isPotentialControlNode(value) {
90
+ if (!isRecord(value) || typeof value.type !== 'string' || !isRecord(value.props)) {
91
+ return false;
92
+ }
93
+ return Object.prototype.hasOwnProperty.call(value, 'id') || Object.prototype.hasOwnProperty.call(value, 'control_type') || Object.prototype.hasOwnProperty.call(value, 'controlType') || Boolean(getControlDefinition(value.type));
94
+ }
95
+ function isRootControlNode(value) {
96
+ if (!isRecord(value) || typeof value.type !== 'string') return false;
97
+ return Object.prototype.hasOwnProperty.call(value, 'id') || Object.prototype.hasOwnProperty.call(value, 'control_type') || Object.prototype.hasOwnProperty.call(value, 'controlType') || Boolean(getControlDefinition(value.type));
98
+ }
99
+ function isChildControlNode(value) {
100
+ return isRecord(value) && typeof value.type === 'string';
101
+ }
102
+ function decodeValue(value) {
103
+ if (Array.isArray(value)) return value.map(function(item) {
104
+ return decodeValue(item);
105
+ });
106
+ if (isPotentialControlNode(value)) return decodeControlNode(value);
107
+ if (!isRecord(value)) return value;
108
+ return Object.fromEntries(Object.entries(value).map(function(param) {
109
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
110
+ return [
111
+ key,
112
+ decodeValue(item)
113
+ ];
114
+ }));
115
+ }
116
+ /**
117
+ * 只规范化控件结构字段,props 内的业务 key 保持原样;这样既能识别 snake_case
118
+ * 保存模型中的嵌套控件,也不会误改租户自定义对象字段。
119
+ */ export function decodeControlNode(value) {
120
+ var _value_controlType, _value_fieldType;
121
+ var children = Array.isArray(value.children) ? value.children// children 是页面 schema 的控件槽;即使历史节点同时缺少 id/control_type,
122
+ // 也要保留下来交给结构校验诊断,不能在解码阶段静默丢弃。
123
+ .filter(isChildControlNode).map(function(child) {
124
+ return decodeControlNode(child);
125
+ }) : undefined;
126
+ var controlType = (_value_controlType = value.controlType) !== null && _value_controlType !== void 0 ? _value_controlType : value.control_type;
127
+ var fieldType = (_value_fieldType = value.fieldType) !== null && _value_fieldType !== void 0 ? _value_fieldType : value.field_type;
128
+ return _object_spread({
129
+ id: typeof value.id === 'string' ? value.id : '',
130
+ type: typeof value.type === 'string' ? value.type : '',
131
+ controlType: typeof controlType === 'string' ? controlType : '',
132
+ // 历史保存模型可能省略空 props;按空对象参与差分,避免 Patch 仅创建 props
133
+ // 容器时把同一批既有 control_type 缺失问题误判为新增。
134
+ props: isRecord(value.props) ? decodeValue(value.props) : {}
135
+ }, typeof fieldType === 'string' ? {
136
+ fieldType: fieldType
137
+ } : {}, children ? {
138
+ children: children
139
+ } : {});
140
+ }
141
+ /** 保存模型必须是仅含一个页面根控件的数组;错误只返回短诊断,不回显原始 JSON。 */ export function decodeSavedPageModel(value) {
142
+ var model = parsedModel(value);
143
+ if (!Array.isArray(model) || model.length !== 1 || !isRecord(model[0])) {
144
+ return {
145
+ diagnostics: [
146
+ {
147
+ code: 'MODEL_DRIVEN_PAGE_MODEL_INVALID',
148
+ message: 'Saved page model must contain exactly one root control',
149
+ severity: 'error',
150
+ path: 'model'
151
+ }
152
+ ]
153
+ };
154
+ }
155
+ if (!isRootControlNode(model[0])) {
156
+ return {
157
+ diagnostics: [
158
+ {
159
+ code: 'MODEL_DRIVEN_PAGE_MODEL_INVALID',
160
+ message: 'Saved page model root is not a control node',
161
+ severity: 'error',
162
+ path: 'model[0]'
163
+ }
164
+ ]
165
+ };
166
+ }
167
+ return {
168
+ diagnostics: [],
169
+ root: decodeControlNode(model[0])
170
+ };
171
+ }
@@ -0,0 +1,135 @@
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 _type_of(obj) {
66
+ "@swc/helpers - typeof";
67
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
68
+ }
69
+ function _unsupported_iterable_to_array(o, minLen) {
70
+ if (!o) return;
71
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
72
+ var n = Object.prototype.toString.call(o).slice(8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return Array.from(n);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
76
+ }
77
+ function isRecord(value) {
78
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
79
+ }
80
+ function isControlNode(value) {
81
+ return Boolean(isRecord(value) && typeof value.id === 'string' && typeof value.type === 'string' && typeof value.controlType === 'string' && isRecord(value.props));
82
+ }
83
+ function encodeValue(value) {
84
+ if (Array.isArray(value)) return value.map(function(item) {
85
+ return encodeValue(item);
86
+ });
87
+ if (isControlNode(value)) return encodeControlNode(value);
88
+ if (!isRecord(value)) return value;
89
+ return Object.fromEntries(Object.entries(value).map(function(param) {
90
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
91
+ return [
92
+ key,
93
+ encodeValue(item)
94
+ ];
95
+ }));
96
+ }
97
+ export function encodeControlNode(node) {
98
+ return _object_spread({
99
+ id: node.id,
100
+ type: node.type,
101
+ props: encodeValue(node.props),
102
+ // 与旧 toSchema 保持一致:即使值为 undefined,也保留 fieldType 自有 key。
103
+ fieldType: node.fieldType,
104
+ controlType: node.controlType
105
+ }, Array.isArray(node.children) ? {
106
+ children: node.children.map(function(child) {
107
+ return encodeControlNode(child);
108
+ })
109
+ } : {});
110
+ }
111
+ export function encodeSavedModel(nodes) {
112
+ return Array.isArray(nodes) ? nodes.map(function(node) {
113
+ return encodeControlNode(node);
114
+ }) : encodeControlNode(nodes);
115
+ }
116
+ function decamelizeKey(key) {
117
+ return key.replace(/[A-Z]/g, function(letter) {
118
+ return "_".concat(letter.toLowerCase());
119
+ });
120
+ }
121
+ /** 纯递归 key 转换;不依赖 shared 中会读取浏览器状态的根入口。 */ export function decamelizeKeys(value) {
122
+ if (Array.isArray(value)) {
123
+ return value.map(function(item) {
124
+ return decamelizeKeys(item);
125
+ });
126
+ }
127
+ if (!isRecord(value)) return value;
128
+ return Object.fromEntries(Object.entries(value).map(function(param) {
129
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
130
+ return [
131
+ decamelizeKey(key),
132
+ decamelizeKeys(item)
133
+ ];
134
+ }));
135
+ }
@@ -0,0 +1,71 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else obj[key] = value;
10
+ return obj;
11
+ }
12
+ function _object_spread(target) {
13
+ for(var i = 1; i < arguments.length; i++){
14
+ var source = arguments[i] != null ? arguments[i] : {};
15
+ var ownKeys = Object.keys(source);
16
+ if (typeof Object.getOwnPropertySymbols === "function") {
17
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
18
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
19
+ }));
20
+ }
21
+ ownKeys.forEach(function(key) {
22
+ _define_property(target, key, source[key]);
23
+ });
24
+ }
25
+ return target;
26
+ }
27
+ function ownKeys(object, enumerableOnly) {
28
+ var keys = Object.keys(object);
29
+ if (Object.getOwnPropertySymbols) {
30
+ var symbols = Object.getOwnPropertySymbols(object);
31
+ if (enumerableOnly) {
32
+ symbols = symbols.filter(function(sym) {
33
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
34
+ });
35
+ }
36
+ keys.push.apply(keys, symbols);
37
+ }
38
+ return keys;
39
+ }
40
+ function _object_spread_props(target, source) {
41
+ source = source != null ? source : {};
42
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
43
+ else {
44
+ ownKeys(Object(source)).forEach(function(key) {
45
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
46
+ });
47
+ }
48
+ return target;
49
+ }
50
+ import { createControlNode, createSequentialIdFactory } from './control-node.factory';
51
+ import { createPageRoot } from './page-template.factory';
52
+ import { generatePermissions } from './permissions';
53
+ /**
54
+ * 一次页面构建共享一个 idFactory;不同 session 相互隔离,既避免重复 id,也不引入进程全局状态。
55
+ */ export function createHeadlessSession() {
56
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
57
+ var scopedOptions = _object_spread_props(_object_spread({}, options), {
58
+ idFactory: options.idFactory || createSequentialIdFactory()
59
+ });
60
+ return Object.freeze({
61
+ createControlNode: function createControlNode1(input) {
62
+ return createControlNode(input, scopedOptions);
63
+ },
64
+ createPageRoot: function createPageRoot1(kind) {
65
+ return createPageRoot(kind, scopedOptions);
66
+ },
67
+ generatePermissions: function generatePermissions1(controls) {
68
+ return generatePermissions(controls, scopedOptions);
69
+ }
70
+ });
71
+ }
@@ -0,0 +1,149 @@
1
+ function _assert_this_initialized(self) {
2
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3
+ return self;
4
+ }
5
+ function _call_super(_this, derived, args) {
6
+ derived = _get_prototype_of(derived);
7
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
8
+ }
9
+ function _class_call_check(instance, Constructor) {
10
+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
11
+ }
12
+ function _construct(Parent, args, Class) {
13
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
14
+ else {
15
+ _construct = function construct(Parent, args, Class) {
16
+ var a = [
17
+ null
18
+ ];
19
+ a.push.apply(a, args);
20
+ var Constructor = Function.bind.apply(Parent, a);
21
+ var instance = new Constructor();
22
+ if (Class) _set_prototype_of(instance, Class.prototype);
23
+ return instance;
24
+ };
25
+ }
26
+ return _construct.apply(null, arguments);
27
+ }
28
+ function _define_property(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else obj[key] = value;
37
+ return obj;
38
+ }
39
+ function _get_prototype_of(o) {
40
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
41
+ return o.__proto__ || Object.getPrototypeOf(o);
42
+ };
43
+ return _get_prototype_of(o);
44
+ }
45
+ function _inherits(subClass, superClass) {
46
+ if (typeof superClass !== "function" && superClass !== null) {
47
+ throw new TypeError("Super expression must either be null or a function");
48
+ }
49
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
50
+ constructor: {
51
+ value: subClass,
52
+ writable: true,
53
+ configurable: true
54
+ }
55
+ });
56
+ if (superClass) _set_prototype_of(subClass, superClass);
57
+ }
58
+ function _is_native_function(fn) {
59
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
60
+ }
61
+ function _is_native_reflect_construct() {
62
+ try {
63
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
64
+ } catch (_) {}
65
+ return (_is_native_reflect_construct = function() {
66
+ return !!result;
67
+ })();
68
+ }
69
+ function _possible_constructor_return(self, call) {
70
+ if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
71
+ return _assert_this_initialized(self);
72
+ }
73
+ function _set_prototype_of(o, p) {
74
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
75
+ o.__proto__ = p;
76
+ return o;
77
+ };
78
+ return _set_prototype_of(o, p);
79
+ }
80
+ function _type_of(obj) {
81
+ "@swc/helpers - typeof";
82
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
83
+ }
84
+ function _wrap_native_super(Class) {
85
+ var _cache = typeof Map === "function" ? new Map() : undefined;
86
+ _wrap_native_super = function(Class) {
87
+ if (Class === null || !_is_native_function(Class)) return Class;
88
+ if (typeof Class !== "function") throw new TypeError("Super expression must either be null or a function");
89
+ if (typeof _cache !== "undefined") {
90
+ if (_cache.has(Class)) return _cache.get(Class);
91
+ _cache.set(Class, Wrapper);
92
+ }
93
+ function Wrapper() {
94
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
95
+ }
96
+ Wrapper.prototype = Object.create(Class.prototype, {
97
+ constructor: {
98
+ value: Wrapper,
99
+ enumerable: false,
100
+ writable: true,
101
+ configurable: true
102
+ }
103
+ });
104
+ return _set_prototype_of(Wrapper, Class);
105
+ };
106
+ return _wrap_native_super(Class);
107
+ }
108
+ export var UnknownControlTypeError = /*#__PURE__*/ function(Error1) {
109
+ "use strict";
110
+ _inherits(UnknownControlTypeError, Error1);
111
+ function UnknownControlTypeError(controlType) {
112
+ _class_call_check(this, UnknownControlTypeError);
113
+ var _this;
114
+ _this = _call_super(this, UnknownControlTypeError, [
115
+ "Unknown model-driven control type: ".concat(controlType)
116
+ ]), _define_property(_this, "controlType", void 0), _define_property(_this, "code", void 0), _this.controlType = controlType, _this.code = 'MODEL_DRIVEN_UNKNOWN_CONTROL_TYPE';
117
+ _this.name = 'UnknownControlTypeError';
118
+ return _this;
119
+ }
120
+ return UnknownControlTypeError;
121
+ }(_wrap_native_super(Error));
122
+ export var UnknownControlPropertyError = /*#__PURE__*/ function(Error1) {
123
+ "use strict";
124
+ _inherits(UnknownControlPropertyError, Error1);
125
+ function UnknownControlPropertyError(controlType, propertyKey) {
126
+ _class_call_check(this, UnknownControlPropertyError);
127
+ var _this;
128
+ _this = _call_super(this, UnknownControlPropertyError, [
129
+ "Unknown property ".concat(propertyKey, " for model-driven control ").concat(controlType)
130
+ ]), _define_property(_this, "controlType", void 0), _define_property(_this, "propertyKey", void 0), _define_property(_this, "code", void 0), _this.controlType = controlType, _this.propertyKey = propertyKey, _this.code = 'MODEL_DRIVEN_UNKNOWN_CONTROL_PROPERTY';
131
+ _this.name = 'UnknownControlPropertyError';
132
+ return _this;
133
+ }
134
+ return UnknownControlPropertyError;
135
+ }(_wrap_native_super(Error));
136
+ export var UnsupportedControlPropertyInputError = /*#__PURE__*/ function(Error1) {
137
+ "use strict";
138
+ _inherits(UnsupportedControlPropertyInputError, Error1);
139
+ function UnsupportedControlPropertyInputError(controlType, propertyKey) {
140
+ _class_call_check(this, UnsupportedControlPropertyInputError);
141
+ var _this;
142
+ _this = _call_super(this, UnsupportedControlPropertyInputError, [
143
+ "Headless construction does not support explicit property ".concat(propertyKey, " for control ").concat(controlType)
144
+ ]), _define_property(_this, "controlType", void 0), _define_property(_this, "propertyKey", void 0), _define_property(_this, "code", void 0), _this.controlType = controlType, _this.propertyKey = propertyKey, _this.code = 'MODEL_DRIVEN_UNSUPPORTED_CONTROL_PROPERTY_INPUT';
145
+ _this.name = 'UnsupportedControlPropertyInputError';
146
+ return _this;
147
+ }
148
+ return UnsupportedControlPropertyInputError;
149
+ }(_wrap_native_super(Error));
@@ -0,0 +1,146 @@
1
+ import { getControlDefinition } from '@byteluck-fe/model-driven-controls/catalog';
2
+ import { getHeadlessBuildInfo } from './build-info';
3
+ import { directNestedControlNodes } from './control-tree';
4
+ function validateVersions(expected, diagnostics) {
5
+ if (!expected) return;
6
+ var actual = getHeadlessBuildInfo();
7
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
8
+ try {
9
+ for(var _iterator = Object.keys(expected)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10
+ var key = _step.value;
11
+ if (expected[key] === undefined || expected[key] === actual[key]) continue;
12
+ diagnostics.push({
13
+ code: 'MODEL_DRIVEN_VERSION_MISMATCH',
14
+ severity: 'error',
15
+ blockingPolicy: 'always',
16
+ message: "Model-driven ".concat(key, " mismatch: expected ").concat(String(expected[key]), ", actual ").concat(String(actual[key])),
17
+ path: "buildInfo.".concat(key)
18
+ });
19
+ }
20
+ } catch (err) {
21
+ _didIteratorError = true;
22
+ _iteratorError = err;
23
+ } finally{
24
+ try {
25
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
26
+ _iterator.return();
27
+ }
28
+ } finally{
29
+ if (_didIteratorError) {
30
+ throw _iteratorError;
31
+ }
32
+ }
33
+ }
34
+ }
35
+ /**
36
+ * 纯结构校验:遍历 children 及 props 中任意嵌套控件,不加载任何 UI 实例。
37
+ */ export function validateControlTree(root) {
38
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
39
+ var diagnostics = [];
40
+ var ids = new Set();
41
+ validateVersions(options.expectedBuildInfo, diagnostics);
42
+ var visit = function visit1(node, path) {
43
+ var _options_controlTypeAliases;
44
+ var catalogType = ((_options_controlTypeAliases = options.controlTypeAliases) === null || _options_controlTypeAliases === void 0 ? void 0 : _options_controlTypeAliases[node.type]) || node.type;
45
+ var definition = getControlDefinition(catalogType);
46
+ if (!definition) {
47
+ diagnostics.push({
48
+ code: 'MODEL_DRIVEN_UNKNOWN_CONTROL_TYPE',
49
+ severity: 'error',
50
+ message: "Unknown model-driven control type: ".concat(node.type),
51
+ path: path,
52
+ controlId: node.id,
53
+ controlType: node.type
54
+ });
55
+ }
56
+ if (!node.id) {
57
+ diagnostics.push({
58
+ code: 'MODEL_DRIVEN_CONTROL_ID_REQUIRED',
59
+ severity: 'error',
60
+ message: "Control ".concat(node.type, " requires a non-empty id"),
61
+ path: "".concat(path, ".id"),
62
+ controlType: node.type
63
+ });
64
+ } else if (ids.has(node.id)) {
65
+ diagnostics.push({
66
+ code: 'MODEL_DRIVEN_DUPLICATE_CONTROL_ID',
67
+ severity: 'error',
68
+ message: "Duplicate control id: ".concat(node.id),
69
+ path: "".concat(path, ".id"),
70
+ controlId: node.id,
71
+ controlType: node.type
72
+ });
73
+ } else {
74
+ ids.add(node.id);
75
+ }
76
+ if (definition && node.controlType !== definition.baseType) {
77
+ diagnostics.push({
78
+ code: 'MODEL_DRIVEN_CONTROL_BASE_TYPE_MISMATCH',
79
+ severity: 'error',
80
+ message: "Control ".concat(node.type, " expects ").concat(definition.baseType, ", received ").concat(node.controlType),
81
+ path: "".concat(path, ".controlType"),
82
+ controlId: node.id,
83
+ controlType: node.type
84
+ });
85
+ }
86
+ var nestedControls = directNestedControlNodes(node);
87
+ // Designer 的 drop policy 只约束实例 children;List headers 及 props 内嵌套控件
88
+ // 仍递归校验 id/type,但不计入 childrenMaxLength/excludes。
89
+ var policyChildren = node.children || [];
90
+ if (definition && !definition.children.allowed && policyChildren.length > 0) {
91
+ diagnostics.push({
92
+ code: 'MODEL_DRIVEN_CHILDREN_NOT_ALLOWED',
93
+ severity: 'error',
94
+ message: "Control ".concat(node.type, " does not allow child controls"),
95
+ path: path,
96
+ controlId: node.id,
97
+ controlType: node.type
98
+ });
99
+ }
100
+ if (definition && definition.children.max !== undefined && policyChildren.length > definition.children.max) {
101
+ diagnostics.push({
102
+ code: 'MODEL_DRIVEN_CHILDREN_LIMIT_EXCEEDED',
103
+ severity: 'error',
104
+ message: "Control ".concat(node.type, " allows at most ").concat(definition.children.max, " children"),
105
+ path: path,
106
+ controlId: node.id,
107
+ controlType: node.type
108
+ });
109
+ }
110
+ var excludes = definition === null || definition === void 0 ? void 0 : definition.children.excludes;
111
+ nestedControls.forEach(function(param) {
112
+ var child = param.node, childPath = param.path;
113
+ var _options_controlTypeAliases;
114
+ var childPathText = childPath.map(function(part) {
115
+ return typeof part === 'number' ? "[".concat(part, "]") : part;
116
+ }).join('.');
117
+ var nestedPath = "".concat(path, ".").concat(childPathText);
118
+ var isPolicyChild = childPath[0] === 'children';
119
+ if (isPolicyChild && Array.isArray(excludes) && excludes.includes(((_options_controlTypeAliases = options.controlTypeAliases) === null || _options_controlTypeAliases === void 0 ? void 0 : _options_controlTypeAliases[child.type]) || child.type)) {
120
+ diagnostics.push({
121
+ code: 'MODEL_DRIVEN_CHILD_TYPE_EXCLUDED',
122
+ severity: 'error',
123
+ message: "Control ".concat(node.type, " excludes child type ").concat(child.type),
124
+ path: nestedPath,
125
+ controlId: child.id,
126
+ controlType: child.type,
127
+ scopeControlId: node.id
128
+ });
129
+ }
130
+ // 未登记的历史父控件仍继续递归其子树;否则修复父类型时才暴露的旧问题
131
+ // 会被差分校验误认为是本次 Patch 新增。
132
+ visit(child, nestedPath);
133
+ });
134
+ };
135
+ (Array.isArray(root) ? root : [
136
+ root
137
+ ]).forEach(function(node, index) {
138
+ return visit(node, "root[".concat(index, "]"));
139
+ });
140
+ return {
141
+ ok: diagnostics.every(function(diagnostic) {
142
+ return diagnostic.severity !== 'error';
143
+ }),
144
+ diagnostics: diagnostics
145
+ };
146
+ }