@byteluck-fe/model-driven-controls 7.1.0-beta.3 → 7.1.0-beta.4

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,373 @@
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 _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else obj[key] = value;
21
+ return obj;
22
+ }
23
+ function _iterable_to_array(iter) {
24
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
25
+ return Array.from(iter);
26
+ }
27
+ }
28
+ function _iterable_to_array_limit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
49
+ }
50
+ return _arr;
51
+ }
52
+ function _non_iterable_rest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _non_iterable_spread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _object_spread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _define_property(target, key, source[key]);
69
+ });
70
+ }
71
+ return target;
72
+ }
73
+ function ownKeys(object, enumerableOnly) {
74
+ var keys = Object.keys(object);
75
+ if (Object.getOwnPropertySymbols) {
76
+ var symbols = Object.getOwnPropertySymbols(object);
77
+ if (enumerableOnly) {
78
+ symbols = symbols.filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
80
+ });
81
+ }
82
+ keys.push.apply(keys, symbols);
83
+ }
84
+ return keys;
85
+ }
86
+ function _object_spread_props(target, source) {
87
+ source = source != null ? source : {};
88
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
+ else {
90
+ ownKeys(Object(source)).forEach(function(key) {
91
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
+ });
93
+ }
94
+ return target;
95
+ }
96
+ function _sliced_to_array(arr, i) {
97
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
98
+ }
99
+ function _to_consumable_array(arr) {
100
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
101
+ }
102
+ function _type_of(obj) {
103
+ "@swc/helpers - typeof";
104
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
105
+ }
106
+ function _unsupported_iterable_to_array(o, minLen) {
107
+ if (!o) return;
108
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
109
+ var n = Object.prototype.toString.call(o).slice(8, -1);
110
+ if (n === "Object" && o.constructor) n = o.constructor.name;
111
+ if (n === "Map" || n === "Set") return Array.from(n);
112
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
113
+ }
114
+ import { applyControlRuntimeAbsentDefaults } from './query';
115
+ /** 公共入口接受 unknown,因此对非 JSON 构造态对象也设置有界递归。 */ var MAX_CONTROL_TREE_DEPTH = 64;
116
+ /**
117
+ * 当前公共模型中已确认的 props 嵌套控件槽位。footers 仍存在于历史列表 Schema。
118
+ */ export var CONTROL_TREE_NESTED_PROP_KEYS = [
119
+ 'headers',
120
+ 'footers'
121
+ ];
122
+ function isRecord(value) {
123
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
124
+ }
125
+ /**
126
+ * 只要求保存态与构造态共有字段;不要求 id/controlType,兼容待诊断的历史节点。
127
+ */ export function isControlTreeNode(value) {
128
+ return Boolean(isRecord(value) && typeof value.type === 'string' && isRecord(value.props));
129
+ }
130
+ function nestedPropKeys(options) {
131
+ return Array.from(new Set(_to_consumable_array(CONTROL_TREE_NESTED_PROP_KEYS).concat(_to_consumable_array(options.additionalNestedPropKeys || []))));
132
+ }
133
+ function visitNestedValue(value, path, parent, nestedPropKey, propKeys, visitor, ancestors, depth) {
134
+ if (depth > MAX_CONTROL_TREE_DEPTH) return;
135
+ if (isControlTreeNode(value)) {
136
+ visitNode(value, path, parent, 'nested-prop', nestedPropKey, propKeys, visitor, ancestors, depth);
137
+ return;
138
+ }
139
+ if (!Array.isArray(value) && !isRecord(value)) return;
140
+ if (ancestors.has(value)) return;
141
+ ancestors.add(value);
142
+ try {
143
+ if (Array.isArray(value)) {
144
+ value.forEach(function(item, index) {
145
+ return visitNestedValue(item, _to_consumable_array(path).concat([
146
+ index
147
+ ]), parent, nestedPropKey, propKeys, visitor, ancestors, depth + 1);
148
+ });
149
+ return;
150
+ }
151
+ Object.entries(value).forEach(function(param) {
152
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
153
+ return visitNestedValue(item, _to_consumable_array(path).concat([
154
+ key
155
+ ]), parent, nestedPropKey, propKeys, visitor, ancestors, depth + 1);
156
+ });
157
+ } finally{
158
+ ancestors.delete(value);
159
+ }
160
+ }
161
+ function visitNode(node, path, parent, source, nestedPropKey, propKeys, visitor, ancestors, depth) {
162
+ if (depth > MAX_CONTROL_TREE_DEPTH || ancestors.has(node)) return;
163
+ ancestors.add(node);
164
+ try {
165
+ // visitor 获得独立路径,即使 JavaScript 调用方强制修改也不污染后续遍历。
166
+ visitor({
167
+ node: node,
168
+ path: _to_consumable_array(path),
169
+ parent: parent,
170
+ source: source,
171
+ nestedPropKey: nestedPropKey
172
+ });
173
+ if (Array.isArray(node.children) && !ancestors.has(node.children)) {
174
+ ancestors.add(node.children);
175
+ try {
176
+ node.children.forEach(function(child, index) {
177
+ if (!isControlTreeNode(child)) return;
178
+ visitNode(child, _to_consumable_array(path).concat([
179
+ 'children',
180
+ index
181
+ ]), node, 'children', undefined, propKeys, visitor, ancestors, depth + 1);
182
+ });
183
+ } finally{
184
+ ancestors.delete(node.children);
185
+ }
186
+ }
187
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
188
+ try {
189
+ for(var _iterator = propKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
190
+ var propKey = _step.value;
191
+ if (!Object.prototype.hasOwnProperty.call(node.props, propKey)) continue;
192
+ visitNestedValue(node.props[propKey], _to_consumable_array(path).concat([
193
+ 'props',
194
+ propKey
195
+ ]), node, propKey, propKeys, visitor, ancestors, depth + 1);
196
+ }
197
+ } catch (err) {
198
+ _didIteratorError = true;
199
+ _iteratorError = err;
200
+ } finally{
201
+ try {
202
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
203
+ _iterator.return();
204
+ }
205
+ } finally{
206
+ if (_didIteratorError) {
207
+ throw _iteratorError;
208
+ }
209
+ }
210
+ }
211
+ } finally{
212
+ ancestors.delete(node);
213
+ }
214
+ }
215
+ /**
216
+ * 以前序稳定顺序遍历一个控件或控件数组。visitor 只接收只读视图,本函数不修改输入。
217
+ */ export function visitControlTree(value, visitor) {
218
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
219
+ var propKeys = nestedPropKeys(options);
220
+ var ancestors = new Set();
221
+ if (isControlTreeNode(value)) {
222
+ visitNode(value, [], undefined, 'root', undefined, propKeys, visitor, ancestors, 0);
223
+ return;
224
+ }
225
+ if (!Array.isArray(value)) return;
226
+ ancestors.add(value);
227
+ try {
228
+ value.forEach(function(item, index) {
229
+ if (!isControlTreeNode(item)) return;
230
+ visitNode(item, [
231
+ index
232
+ ], undefined, 'root', undefined, propKeys, visitor, ancestors, 0);
233
+ });
234
+ } finally{
235
+ ancestors.delete(value);
236
+ }
237
+ }
238
+ /** 返回稳定顺序的节点与路径,不复制页面 JSON 或 props。 */ export function collectControlTreeNodes(value) {
239
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
240
+ var result = [];
241
+ visitControlTree(value, function(visit) {
242
+ return result.push(visit);
243
+ }, options);
244
+ return result;
245
+ }
246
+ function mapNestedValue(value, propKeys, ancestors, depth) {
247
+ if (depth > MAX_CONTROL_TREE_DEPTH) return value;
248
+ if (isControlTreeNode(value)) {
249
+ return mapNode(value, propKeys, ancestors, depth);
250
+ }
251
+ if (!Array.isArray(value) && !isRecord(value)) return value;
252
+ if (ancestors.has(value)) return value;
253
+ ancestors.add(value);
254
+ try {
255
+ if (Array.isArray(value)) {
256
+ var result = value;
257
+ value.forEach(function(item, index) {
258
+ var next = mapNestedValue(item, propKeys, ancestors, depth + 1);
259
+ if (next === item) return;
260
+ if (result === value) result = _to_consumable_array(value);
261
+ result[index] = next;
262
+ });
263
+ return result;
264
+ }
265
+ var result1 = value;
266
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
267
+ try {
268
+ for(var _iterator = Object.entries(value)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
269
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], item = _step_value[1];
270
+ var next = mapNestedValue(item, propKeys, ancestors, depth + 1);
271
+ if (next === item) continue;
272
+ if (result1 === value) result1 = _object_spread({}, value);
273
+ result1[key] = next;
274
+ }
275
+ } catch (err) {
276
+ _didIteratorError = true;
277
+ _iteratorError = err;
278
+ } finally{
279
+ try {
280
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
281
+ _iterator.return();
282
+ }
283
+ } finally{
284
+ if (_didIteratorError) {
285
+ throw _iteratorError;
286
+ }
287
+ }
288
+ }
289
+ return result1;
290
+ } finally{
291
+ ancestors.delete(value);
292
+ }
293
+ }
294
+ function mapNode(input, propKeys, ancestors, depth) {
295
+ if (depth > MAX_CONTROL_TREE_DEPTH || ancestors.has(input)) return input;
296
+ ancestors.add(input);
297
+ try {
298
+ var node = input;
299
+ if (Array.isArray(input.children)) {
300
+ var children = mapNestedValue(input.children, propKeys, ancestors, depth + 1);
301
+ if (children !== input.children) node = _object_spread_props(_object_spread({}, node), {
302
+ children: children
303
+ });
304
+ }
305
+ var props = node.props;
306
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
307
+ try {
308
+ for(var _iterator = propKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
309
+ var propKey = _step.value;
310
+ if (!Object.prototype.hasOwnProperty.call(props, propKey)) continue;
311
+ var current = props[propKey];
312
+ var next = mapNestedValue(current, propKeys, ancestors, depth + 1);
313
+ if (next === current) continue;
314
+ if (props === node.props) props = _object_spread({}, props);
315
+ props[propKey] = next;
316
+ }
317
+ } catch (err) {
318
+ _didIteratorError = true;
319
+ _iteratorError = err;
320
+ } finally{
321
+ try {
322
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
323
+ _iterator.return();
324
+ }
325
+ } finally{
326
+ if (_didIteratorError) {
327
+ throw _iteratorError;
328
+ }
329
+ }
330
+ }
331
+ if (props !== node.props) node = _object_spread_props(_object_spread({}, node), {
332
+ props: props
333
+ });
334
+ var normalizedProps = applyControlRuntimeAbsentDefaults(node.type, node.props);
335
+ if (normalizedProps !== node.props) {
336
+ node = _object_spread_props(_object_spread({}, node), {
337
+ props: normalizedProps
338
+ });
339
+ }
340
+ return node;
341
+ } finally{
342
+ ancestors.delete(input);
343
+ }
344
+ }
345
+ function mapRootValue(value, propKeys) {
346
+ var ancestors = new Set();
347
+ if (isControlTreeNode(value)) return mapNode(value, propKeys, ancestors, 0);
348
+ if (!Array.isArray(value)) return value;
349
+ var result = value;
350
+ ancestors.add(value);
351
+ try {
352
+ value.forEach(function(item, index) {
353
+ if (!isControlTreeNode(item)) return;
354
+ var next = mapNode(item, propKeys, ancestors, 0);
355
+ if (next === item) return;
356
+ if (result === value) result = _to_consumable_array(value);
357
+ result[index] = next;
358
+ });
359
+ } finally{
360
+ ancestors.delete(value);
361
+ }
362
+ return result;
363
+ }
364
+ /**
365
+ * 为整棵树补齐 catalog 已核实的 Runtime 缺失属性语义。
366
+ *
367
+ * - 缺失与 own-property `undefined` 使用 absent Runtime 值;`null` 和其它显式值保留。
368
+ * - 结果使用 catalog 公共构造属性名,适合实例化兼容,不是持久化 Schema 升级。
369
+ * - 未变化时保留原引用;变化时只复制命中节点及其祖先,不修改输入对象。
370
+ */ export function applyRuntimeAbsentDefaultsToControlTree(value) {
371
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
372
+ return mapRootValue(value, nestedPropKeys(options));
373
+ }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": "model-driven.control-catalog.v1",
3
- "packageVersion": "7.1.0-beta.3",
4
- "sourceRevision": "sha256:5699432a72e9369aeccc3083c2479d8c12e506bb74ae068a21c89ba77f6937dc",
5
- "revision": "sha256:f352354ca2e86d563cfd767830aa9c5aeab204de26401d3517824f8a45f54bdb",
3
+ "packageVersion": "7.1.0-beta.4",
4
+ "sourceRevision": "sha256:29da8bd3ec3de616fe213143170f79a1dce326ec77d5ce6398747100cd1229d1",
5
+ "revision": "sha256:ad4745a37643c80842d3a5a8fa9dd4a8cb13d12f61e35df972c9ef63097faddd",
6
6
  "localeMessages": {
7
7
  "CMD.approvedDocuments": {
8
8
  "key": "CMD.approvedDocuments",
@@ -1,2 +1,3 @@
1
1
  export * from './types';
2
2
  export * from './query';
3
+ export * from './control-tree';
@@ -99,6 +99,10 @@ function _sliced_to_array(arr, i) {
99
99
  function _to_consumable_array(arr) {
100
100
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
101
101
  }
102
+ function _type_of(obj) {
103
+ "@swc/helpers - typeof";
104
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
105
+ }
102
106
  function _unsupported_iterable_to_array(o, minLen) {
103
107
  if (!o) return;
104
108
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -178,6 +182,129 @@ export function getControlSettingFacts(type) {
178
182
  savedPropertyKey: savedPropertyKey
179
183
  }));
180
184
  }
185
+ var CATALOG_VALUE_TYPES = new Set([
186
+ 'array',
187
+ 'boolean',
188
+ 'integer',
189
+ 'null',
190
+ 'number',
191
+ 'object',
192
+ 'string'
193
+ ]);
194
+ function isRecord(value) {
195
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
196
+ }
197
+ function schemaValueTypes(value) {
198
+ if (!isRecord(value)) return [];
199
+ var result = new Set();
200
+ var addType = function addType(type) {
201
+ if (typeof type === 'string' && CATALOG_VALUE_TYPES.has(type)) {
202
+ result.add(type);
203
+ }
204
+ };
205
+ if (Array.isArray(value.type)) value.type.forEach(addType);
206
+ else addType(value.type);
207
+ if (Array.isArray(value.anyOf)) {
208
+ value.anyOf.forEach(function(item) {
209
+ return schemaValueTypes(item).forEach(function(type) {
210
+ return result.add(type);
211
+ });
212
+ });
213
+ }
214
+ return _to_consumable_array(result).sort();
215
+ }
216
+ function jsonValues(value) {
217
+ if (!Array.isArray(value)) return undefined;
218
+ // generated catalog 已是 JSON;仍复制一份,避免查询结果污染共享文档。
219
+ return clone(value);
220
+ }
221
+ function numberValue(value) {
222
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
223
+ }
224
+ function valueTypeForDefault(value) {
225
+ if (value === null) return 'null';
226
+ if (Array.isArray(value)) return 'array';
227
+ if (typeof value === 'boolean') return 'boolean';
228
+ if (typeof value === 'number') {
229
+ return Number.isInteger(value) ? 'integer' : 'number';
230
+ }
231
+ if (typeof value === 'string') return 'string';
232
+ return 'object';
233
+ }
234
+ /**
235
+ * 按保存键返回单个紧凑 authoring 事实;不存在或未被真实默认模型物化时失败关闭。
236
+ */ export function getControlAuthoringPropertyFact(type, savedPropertyKey) {
237
+ var _ref, _ref1, _ref2, _ref3;
238
+ var definition = definitionsByType.get(type);
239
+ var savedFact = getControlSavedPropertyFact(type, savedPropertyKey);
240
+ if (!definition || !savedFact) return undefined;
241
+ var settingFact = definition.settingFacts.find(function(fact) {
242
+ return fact.savedPropertyKey === savedPropertyKey;
243
+ });
244
+ var propertySchema = isRecord(definition.propsSchema.properties) ? definition.propsSchema.properties[savedFact.propertyKey] : undefined;
245
+ var schemaTypes = schemaValueTypes(propertySchema);
246
+ var schema = isRecord(propertySchema) ? propertySchema : undefined;
247
+ var defaultType = valueTypeForDefault(savedFact.defaultValue);
248
+ // schema 联合类型、setting 类型与真实创建默认值都是独立事实;不能用某一个默认值
249
+ // 反向缩窄整个合法值域,否则 integer|string 之类的历史合法值会被误拒绝。
250
+ var valueTypes = _to_consumable_array(new Set(_to_consumable_array(schemaTypes).concat(_to_consumable_array(settingFact ? [
251
+ settingFact.valueType
252
+ ] : []), [
253
+ defaultType
254
+ ]))).sort();
255
+ // setting options 与当前 schema enum 尚无“完整值域”发布事实,只能作为 authoring 提示。
256
+ var optionHints = (settingFact === null || settingFact === void 0 ? void 0 : settingFact.options) || jsonValues(schema === null || schema === void 0 ? void 0 : schema.enum);
257
+ var min = (_ref = (_ref1 = settingFact === null || settingFact === void 0 ? void 0 : settingFact.min) !== null && _ref1 !== void 0 ? _ref1 : numberValue(schema === null || schema === void 0 ? void 0 : schema.minimum)) !== null && _ref !== void 0 ? _ref : numberValue(schema === null || schema === void 0 ? void 0 : schema.min);
258
+ var max = (_ref2 = (_ref3 = settingFact === null || settingFact === void 0 ? void 0 : settingFact.max) !== null && _ref3 !== void 0 ? _ref3 : numberValue(schema === null || schema === void 0 ? void 0 : schema.maximum)) !== null && _ref2 !== void 0 ? _ref2 : numberValue(schema === null || schema === void 0 ? void 0 : schema.max);
259
+ var hasTopLevelOnly = valueTypes.some(function(valueType) {
260
+ return valueType === 'array' || valueType === 'object';
261
+ });
262
+ return clone(_object_spread_props(_object_spread({
263
+ controlType: type,
264
+ propertyKey: savedFact.propertyKey,
265
+ savedPropertyKey: savedPropertyKey,
266
+ createDefaultValue: savedFact.defaultValue,
267
+ absentRuntimeValue: savedFact.absentRuntimeValue !== undefined ? {
268
+ known: true,
269
+ value: savedFact.absentRuntimeValue
270
+ } : {
271
+ known: false
272
+ },
273
+ valueTypes: valueTypes
274
+ }, optionHints ? {
275
+ optionHints: optionHints
276
+ } : {}, min !== undefined ? {
277
+ min: min
278
+ } : {}, max !== undefined ? {
279
+ max: max
280
+ } : {}), {
281
+ constraintCompleteness: hasTopLevelOnly ? 'top-level' : 'complete',
282
+ settingExposed: Boolean(settingFact),
283
+ explicitConstructionSupported: !definition.unsupportedExplicitProps.includes(savedFact.propertyKey)
284
+ }));
285
+ }
286
+ /**
287
+ * 返回一个控件的紧凑 authoring 事实,属性按保存键稳定排序;不复制完整 catalog。
288
+ */ export function getControlAuthoringFacts(type) {
289
+ var definition = definitionsByType.get(type);
290
+ if (!definition) return undefined;
291
+ var properties = Object.values(definition.propertyNameMap).map(function(savedPropertyKey) {
292
+ return getControlAuthoringPropertyFact(type, savedPropertyKey);
293
+ }).filter(function(fact) {
294
+ return fact !== undefined;
295
+ }).sort(function(left, right) {
296
+ return left.savedPropertyKey.localeCompare(right.savedPropertyKey);
297
+ });
298
+ return clone(_object_spread_props(_object_spread({
299
+ controlType: type,
300
+ baseType: definition.baseType
301
+ }, definition.fieldType ? {
302
+ fieldType: definition.fieldType
303
+ } : {}), {
304
+ catalogRevision: catalog.revision,
305
+ properties: properties
306
+ }));
307
+ }
181
308
  /**
182
309
  * 解析一个保存属性的有效值,仅在 catalog 已登记历史缺失语义时补值。
183
310
  *
@@ -0,0 +1,49 @@
1
+ export type ControlTreePath = ReadonlyArray<string | number>;
2
+ /**
3
+ * 保存态与构造态控件共有的最小结构。
4
+ *
5
+ * 历史保存模型可能只有 `control_type`,构造态则通常使用 `controlType`;遍历只依赖
6
+ * `type` 与 `props`,避免为了读取纯 JSON 控件树加载 Designer、Vue 或 DOM。
7
+ */
8
+ export interface ControlTreeNode {
9
+ readonly type: string;
10
+ readonly props: Readonly<Record<string, unknown>>;
11
+ readonly children?: unknown;
12
+ readonly [key: string]: unknown;
13
+ }
14
+ export interface ControlTreeVisit {
15
+ node: ControlTreeNode;
16
+ path: ControlTreePath;
17
+ parent?: ControlTreeNode;
18
+ source: 'root' | 'children' | 'nested-prop';
19
+ nestedPropKey?: string;
20
+ }
21
+ export interface ControlTreeTraversalOptions {
22
+ /**
23
+ * 宿主额外确认会保存控件节点的 props 槽位。默认槽位始终保留,不能由调用方覆盖。
24
+ */
25
+ additionalNestedPropKeys?: readonly string[];
26
+ }
27
+ export type ControlTreeVisitor = (visit: ControlTreeVisit) => void;
28
+ /**
29
+ * 当前公共模型中已确认的 props 嵌套控件槽位。footers 仍存在于历史列表 Schema。
30
+ */
31
+ export declare const CONTROL_TREE_NESTED_PROP_KEYS: readonly ["headers", "footers"];
32
+ /**
33
+ * 只要求保存态与构造态共有字段;不要求 id/controlType,兼容待诊断的历史节点。
34
+ */
35
+ export declare function isControlTreeNode(value: unknown): value is ControlTreeNode;
36
+ /**
37
+ * 以前序稳定顺序遍历一个控件或控件数组。visitor 只接收只读视图,本函数不修改输入。
38
+ */
39
+ export declare function visitControlTree(value: unknown, visitor: ControlTreeVisitor, options?: ControlTreeTraversalOptions): void;
40
+ /** 返回稳定顺序的节点与路径,不复制页面 JSON 或 props。 */
41
+ export declare function collectControlTreeNodes(value: unknown, options?: ControlTreeTraversalOptions): ControlTreeVisit[];
42
+ /**
43
+ * 为整棵树补齐 catalog 已核实的 Runtime 缺失属性语义。
44
+ *
45
+ * - 缺失与 own-property `undefined` 使用 absent Runtime 值;`null` 和其它显式值保留。
46
+ * - 结果使用 catalog 公共构造属性名,适合实例化兼容,不是持久化 Schema 升级。
47
+ * - 未变化时保留原引用;变化时只复制命中节点及其祖先,不修改输入对象。
48
+ */
49
+ export declare function applyRuntimeAbsentDefaultsToControlTree<T>(value: T, options?: ControlTreeTraversalOptions): T;
@@ -1,2 +1,3 @@
1
1
  export * from './types';
2
2
  export * from './query';
3
+ export * from './control-tree';
@@ -1,4 +1,4 @@
1
- import { ControlCatalogInfo, ControlDefinition, ControlLocaleMessageFact, ResolvedControlSavedPropertyValue, ControlSavedPropertyFact, ControlSettingFact } from './types';
1
+ import { ControlAuthoringFacts, ControlAuthoringPropertyFact, ControlCatalogInfo, ControlDefinition, ControlLocaleMessageFact, ResolvedControlSavedPropertyValue, ControlSavedPropertyFact, ControlSettingFact } from './types';
2
2
  import { JsonObject } from '@byteluck-fe/model-driven-core/contracts';
3
3
  /** 返回独立副本,避免调用方污染进程内共享 catalog。 */
4
4
  export declare function getControlDefinition(type: string): ControlDefinition | undefined;
@@ -16,6 +16,14 @@ export declare function getControlSettingFacts(type: string): ControlSettingFact
16
16
  * propertyNameMap 与 defaultProps,才能作为控件切换时的能力证据。
17
17
  */
18
18
  export declare function getControlSavedPropertyFact(type: string, savedPropertyKey: string): ControlSavedPropertyFact | undefined;
19
+ /**
20
+ * 按保存键返回单个紧凑 authoring 事实;不存在或未被真实默认模型物化时失败关闭。
21
+ */
22
+ export declare function getControlAuthoringPropertyFact(type: string, savedPropertyKey: string): ControlAuthoringPropertyFact | undefined;
23
+ /**
24
+ * 返回一个控件的紧凑 authoring 事实,属性按保存键稳定排序;不复制完整 catalog。
25
+ */
26
+ export declare function getControlAuthoringFacts(type: string): ControlAuthoringFacts | undefined;
19
27
  /**
20
28
  * 解析一个保存属性的有效值,仅在 catalog 已登记历史缺失语义时补值。
21
29
  *
@@ -1,5 +1,5 @@
1
1
  import { ControlCatalogSchemaVersion, JsonObject, JsonValue, HeadlessControlNode, ModelDrivenBaseControlType } from '@byteluck-fe/model-driven-core/contracts';
2
- export type ControlCatalogValueType = 'array' | 'boolean' | 'integer' | 'number' | 'object' | 'string';
2
+ export type ControlCatalogValueType = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';
3
3
  export interface ControlSettingFact {
4
4
  controlType: string;
5
5
  propertyKey: string;
@@ -28,6 +28,44 @@ export interface ControlSavedPropertyFact {
28
28
  propertyKey: string;
29
29
  savedPropertyKey: string;
30
30
  }
31
+ export type ControlAuthoringConstraintCompleteness = 'complete' | 'top-level';
32
+ export type ControlAuthoringAbsentRuntimeValueFact = {
33
+ known: false;
34
+ } | {
35
+ known: true;
36
+ value: JsonValue;
37
+ };
38
+ /**
39
+ * 单个保存属性的紧凑 authoring 事实。
40
+ *
41
+ * 事实只证明目标控件真实物化了该保存属性;宿主仍必须通过自己的版本化策略准入写入。
42
+ * createDefaultValue 与 absentRuntimeValue 分别描述“新建”与“历史缺失”语义,不能互换。
43
+ */
44
+ export interface ControlAuthoringPropertyFact {
45
+ controlType: string;
46
+ propertyKey: string;
47
+ savedPropertyKey: string;
48
+ createDefaultValue: JsonValue;
49
+ absentRuntimeValue: ControlAuthoringAbsentRuntimeValueFact;
50
+ valueTypes?: ControlCatalogValueType[];
51
+ /** Designer setting/schema 提供的候选提示;未声明完整性,不能作为穷举值域拒绝输入。 */
52
+ optionHints?: JsonValue[];
53
+ min?: number;
54
+ max?: number;
55
+ constraintCompleteness?: ControlAuthoringConstraintCompleteness;
56
+ /** 该属性是否出现在当前 Designer setting 可见面;false 不等于禁止,由宿主策略决定。 */
57
+ settingExposed: boolean;
58
+ /** 显式构造是否能由 headless 工厂完整表达;保存态 Patch 不因此自动获得授权。 */
59
+ explicitConstructionSupported: boolean;
60
+ }
61
+ /** 单控件窄投影,不包含 defaultSchema、完整 propsSchema、settings 或组件实现。 */
62
+ export interface ControlAuthoringFacts {
63
+ controlType: string;
64
+ baseType: ModelDrivenBaseControlType;
65
+ fieldType?: string;
66
+ catalogRevision: string;
67
+ properties: ControlAuthoringPropertyFact[];
68
+ }
31
69
  export interface ResolvedControlSavedPropertyValue {
32
70
  propertyKey: string;
33
71
  savedPropertyKey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@byteluck-fe/model-driven-controls",
3
- "version": "7.1.0-beta.3",
3
+ "version": "7.1.0-beta.4",
4
4
  "description": "> TODO: description",
5
5
  "author": "郝晨光 <2293885211@qq.com>",
6
6
  "homepage": "",
@@ -49,10 +49,10 @@
49
49
  "postpublish": "node ../../scripts/postpublish.js"
50
50
  },
51
51
  "dependencies": {
52
- "@byteluck-fe/model-driven-core": "7.1.0-beta.3",
53
- "@byteluck-fe/model-driven-settings": "7.1.0-beta.3",
54
- "@byteluck-fe/model-driven-shared": "7.1.0-beta.3",
52
+ "@byteluck-fe/model-driven-core": "7.1.0-beta.4",
53
+ "@byteluck-fe/model-driven-settings": "7.1.0-beta.4",
54
+ "@byteluck-fe/model-driven-shared": "7.1.0-beta.4",
55
55
  "async-validator": "3.5.1"
56
56
  },
57
- "gitHead": "7adfb426676013d0daa1ece71a415ef840b8f92e"
57
+ "gitHead": "82847b31dd60becd6a77ed5d831c12f57b3dc7aa"
58
58
  }