@byteluck-fe/model-driven-controls 7.1.0-beta.2 → 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.
@@ -9,6 +9,17 @@ function _array_with_holes(arr) {
9
9
  function _array_without_holes(arr) {
10
10
  if (Array.isArray(arr)) return _array_like_to_array(arr);
11
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
+ }
12
23
  function _iterable_to_array(iter) {
13
24
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
14
25
  return Array.from(iter);
@@ -44,12 +55,54 @@ function _non_iterable_rest() {
44
55
  function _non_iterable_spread() {
45
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.");
46
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
+ }
47
96
  function _sliced_to_array(arr, i) {
48
97
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
49
98
  }
50
99
  function _to_consumable_array(arr) {
51
100
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
52
101
  }
102
+ function _type_of(obj) {
103
+ "@swc/helpers - typeof";
104
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
105
+ }
53
106
  function _unsupported_iterable_to_array(o, minLen) {
54
107
  if (!o) return;
55
108
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -100,6 +153,7 @@ export function getControlSettingFacts(type) {
100
153
  * propsSchema 可能声明了工厂默认模型未实际物化的可选属性,因此必须同时命中
101
154
  * propertyNameMap 与 defaultProps,才能作为控件切换时的能力证据。
102
155
  */ export function getControlSavedPropertyFact(type, savedPropertyKey) {
156
+ var _definition_absentRuntimeDefaults;
103
157
  var definition = definitionsByType.get(type);
104
158
  if (!definition) return undefined;
105
159
  var propertyEntry = Object.entries(definition.propertyNameMap).find(function(param) {
@@ -114,12 +168,212 @@ export function getControlSettingFacts(type) {
114
168
  var defaultValue = definition.defaultProps[propertyKey];
115
169
  // generated JSON 不允许 undefined;若产物被破坏则窄查询继续失败关闭。
116
170
  if (defaultValue === undefined) return undefined;
117
- return clone({
171
+ var hasAbsentRuntimeValue = Object.prototype.hasOwnProperty.call(definition.absentRuntimeDefaults || {}, propertyKey);
172
+ var absentRuntimeValue = (_definition_absentRuntimeDefaults = definition.absentRuntimeDefaults) === null || _definition_absentRuntimeDefaults === void 0 ? void 0 : _definition_absentRuntimeDefaults[propertyKey];
173
+ // 声明为已登记却出现 undefined 说明生成物损坏,不能对外返回不完整事实。
174
+ if (hasAbsentRuntimeValue && absentRuntimeValue === undefined) return undefined;
175
+ return clone(_object_spread_props(_object_spread({
118
176
  controlType: definition.type,
119
- defaultValue: defaultValue,
177
+ defaultValue: defaultValue
178
+ }, hasAbsentRuntimeValue ? {
179
+ absentRuntimeValue: absentRuntimeValue
180
+ } : {}), {
120
181
  propertyKey: propertyKey,
121
182
  savedPropertyKey: savedPropertyKey
183
+ }));
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';
122
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
+ }
308
+ /**
309
+ * 解析一个保存属性的有效值,仅在 catalog 已登记历史缺失语义时补值。
310
+ *
311
+ * `null` 是显式 JSON 值,不能与缺失/undefined 混为一谈。调用方可传 camelCase
312
+ * 构造态或 snake_case 保存态 props,返回值始终指出公共构造属性名。
313
+ */ export function resolveControlSavedPropertyValue(input) {
314
+ var fact = getControlSavedPropertyFact(input.controlType, input.savedPropertyKey);
315
+ if (!fact) return undefined;
316
+ for(var _i = 0, _iter = [
317
+ fact.propertyKey,
318
+ fact.savedPropertyKey
319
+ ]; _i < _iter.length; _i++){
320
+ var key = _iter[_i];
321
+ var value = input.props[key];
322
+ if (Object.prototype.hasOwnProperty.call(input.props, key) && value !== undefined) {
323
+ return {
324
+ propertyKey: fact.propertyKey,
325
+ savedPropertyKey: fact.savedPropertyKey,
326
+ value: clone(value),
327
+ source: 'explicit'
328
+ };
329
+ }
330
+ }
331
+ if (fact.absentRuntimeValue === undefined) return undefined;
332
+ return {
333
+ propertyKey: fact.propertyKey,
334
+ savedPropertyKey: fact.savedPropertyKey,
335
+ value: clone(fact.absentRuntimeValue),
336
+ source: 'absent_runtime_value'
337
+ };
338
+ }
339
+ /**
340
+ * 为 Designer 等构造态消费者补齐 Runtime 已核实的历史缺失语义。
341
+ *
342
+ * 未命中时保留原对象引用;命中时只浅拷贝 props 并写入公共属性名,不修改保存态原对象。
343
+ */ export function applyControlRuntimeAbsentDefaults(controlType, props) {
344
+ var definition = definitionsByType.get(controlType);
345
+ if (!definition) return props;
346
+ var result = props;
347
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
348
+ try {
349
+ for(var _iterator = Object.entries(definition.absentRuntimeDefaults || {})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
350
+ var _step_value = _sliced_to_array(_step.value, 2), propertyKey = _step_value[0], absentRuntimeValue = _step_value[1];
351
+ var savedPropertyKey = definition.propertyNameMap[propertyKey];
352
+ if (!savedPropertyKey) continue;
353
+ var resolved = resolveControlSavedPropertyValue({
354
+ controlType: controlType,
355
+ savedPropertyKey: savedPropertyKey,
356
+ props: props
357
+ });
358
+ if (!resolved || resolved.source !== 'absent_runtime_value') continue;
359
+ if (result === props) result = _object_spread({}, props);
360
+ result[propertyKey] = clone(absentRuntimeValue);
361
+ }
362
+ } catch (err) {
363
+ _didIteratorError = true;
364
+ _iteratorError = err;
365
+ } finally{
366
+ try {
367
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
368
+ _iterator.return();
369
+ }
370
+ } finally{
371
+ if (_didIteratorError) {
372
+ throw _iteratorError;
373
+ }
374
+ }
375
+ }
376
+ return result;
123
377
  }
124
378
  /** headless 按稳定 key 窄查消息事实,避免复制整份 catalog。 */ export function getControlLocaleMessageFact(key) {
125
379
  var fact = catalog.localeMessages[key];
@@ -362,6 +362,12 @@ var SubTableControlProperty = /*#__PURE__*/ function(ListControlProperty) {
362
362
  return SubTableControlProperty;
363
363
  }(ListControlProperty);
364
364
  _define_property(SubTableControlProperty, "Rules", SubTableControlPropertyRules);
365
+ /**
366
+ * 历史页面未保存 label_position 时,Runtime 一直按左右布局解释。
367
+ * 新建控件仍使用构造器中的 top;catalog 将两类语义分开发布,供 Designer 对齐历史运行态。
368
+ */ _define_property(SubTableControlProperty, "catalogAbsentRuntimeDefaults", {
369
+ labelPosition: 'left'
370
+ });
365
371
  _define_property(SubTableControlProperty, "RuntimeRules", SubtableControlRuntimeRules);
366
372
  export default SubTableControlProperty;
367
373
  export { SubTableControlProperty, SubTableControlPropertyRules, SubtableControlRuntimeRules, };