@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.
Files changed (37) hide show
  1. package/README.md +9 -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-node.factory.js +669 -0
  9. package/dist/esm/headless/control-tree.js +106 -0
  10. package/dist/esm/headless/index.js +11 -0
  11. package/dist/esm/headless/locale.js +159 -0
  12. package/dist/esm/headless/model-bindings.js +265 -0
  13. package/dist/esm/headless/page-compiler.js +47 -0
  14. package/dist/esm/headless/page-template.factory.js +134 -0
  15. package/dist/esm/headless/permissions.js +334 -0
  16. package/dist/esm/headless/saved-model.encoder.js +135 -0
  17. package/dist/esm/headless/session.js +71 -0
  18. package/dist/esm/headless/types.js +149 -0
  19. package/dist/esm/headless/validator.js +140 -0
  20. package/dist/esm/utils.js +15 -16
  21. package/dist/headless/index.js +1 -0
  22. package/dist/headless/index.mjs +1 -0
  23. package/dist/index.umd.js +11 -3
  24. package/dist/types/headless/build-info.d.ts +5 -0
  25. package/dist/types/headless/control-node.factory.d.ts +3 -0
  26. package/dist/types/headless/control-tree.d.ts +9 -0
  27. package/dist/types/headless/index.d.ts +11 -0
  28. package/dist/types/headless/locale.d.ts +26 -0
  29. package/dist/types/headless/model-bindings.d.ts +3 -0
  30. package/dist/types/headless/page-compiler.d.ts +5 -0
  31. package/dist/types/headless/page-template.factory.d.ts +2 -0
  32. package/dist/types/headless/permissions.d.ts +5 -0
  33. package/dist/types/headless/saved-model.encoder.d.ts +5 -0
  34. package/dist/types/headless/session.d.ts +11 -0
  35. package/dist/types/headless/types.d.ts +36 -0
  36. package/dist/types/headless/validator.d.ts +9 -0
  37. package/package.json +29 -7
@@ -0,0 +1,669 @@
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 { getControlDefinition } from '@byteluck-fe/model-driven-controls/catalog';
115
+ import { UnknownControlPropertyError, UnknownControlTypeError, UnsupportedControlPropertyInputError } from './types';
116
+ import { directNestedControlNodes } from './control-tree';
117
+ import { normalizeHeadlessLocale, resolveHeadlessMessage } from './locale';
118
+ export function createSequentialIdFactory() {
119
+ var prefix = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'md';
120
+ var sequence = 0;
121
+ return function() {
122
+ sequence += 1;
123
+ return "".concat(prefix, "_").concat(sequence.toString(36).padStart(8, '0'));
124
+ };
125
+ }
126
+ function clone(value) {
127
+ if (Array.isArray(value)) {
128
+ return value.map(function(item) {
129
+ return clone(item);
130
+ });
131
+ }
132
+ if (!value || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object') return value;
133
+ return Object.fromEntries(Object.entries(value).map(function(param) {
134
+ var _param = _sliced_to_array(param, 2), key = _param[0], item = _param[1];
135
+ return [
136
+ key,
137
+ clone(item)
138
+ ];
139
+ }));
140
+ }
141
+ function isRecord(value) {
142
+ return (typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && value !== null && !Array.isArray(value);
143
+ }
144
+ function mergeObjects(base, override) {
145
+ if (!override) return clone(base);
146
+ var result = clone(base);
147
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
148
+ try {
149
+ for(var _iterator = Object.entries(override)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
150
+ var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
151
+ var current = result[key];
152
+ result[key] = isRecord(current) && isRecord(value) ? mergeObjects(current, value) : clone(value);
153
+ }
154
+ } catch (err) {
155
+ _didIteratorError = true;
156
+ _iteratorError = err;
157
+ } finally{
158
+ try {
159
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
160
+ _iterator.return();
161
+ }
162
+ } finally{
163
+ if (_didIteratorError) {
164
+ throw _iteratorError;
165
+ }
166
+ }
167
+ }
168
+ return result;
169
+ }
170
+ function setPath(target, path, value) {
171
+ var current = target;
172
+ for(var index = 0; index < path.length - 1; index += 1){
173
+ var key = path[index];
174
+ if (!isRecord(current) && !Array.isArray(current)) {
175
+ throw new Error("Catalog locale default path is unreachable: ".concat(path.join('.')));
176
+ }
177
+ current = current[key];
178
+ }
179
+ if (!isRecord(current) && !Array.isArray(current)) {
180
+ throw new Error("Catalog locale default path is unreachable: ".concat(path.join('.')));
181
+ }
182
+ var last = path[path.length - 1];
183
+ current[last] = value;
184
+ }
185
+ function canReachPath(target, path) {
186
+ var current = target;
187
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
188
+ try {
189
+ for(var _iterator = path[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
190
+ var key = _step.value;
191
+ if (!isRecord(current) && !Array.isArray(current)) return false;
192
+ if (!Object.prototype.hasOwnProperty.call(current, key)) return false;
193
+ current = current[key];
194
+ }
195
+ } catch (err) {
196
+ _didIteratorError = true;
197
+ _iteratorError = err;
198
+ } finally{
199
+ try {
200
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
201
+ _iterator.return();
202
+ }
203
+ } finally{
204
+ if (_didIteratorError) {
205
+ throw _iteratorError;
206
+ }
207
+ }
208
+ }
209
+ return true;
210
+ }
211
+ function applyLocaleJsonDefault(template, propertyKey, jsonPath, value, space) {
212
+ var source = template.props[propertyKey];
213
+ if (typeof source !== 'string') {
214
+ throw new Error("Catalog locale JSON default is not a string: ".concat(propertyKey));
215
+ }
216
+ var parsed;
217
+ try {
218
+ parsed = JSON.parse(source);
219
+ } catch (_error) {
220
+ throw new Error("Catalog locale JSON default cannot be parsed: ".concat(propertyKey));
221
+ }
222
+ if (!canReachPath(parsed, jsonPath)) {
223
+ throw new Error("Catalog locale JSON default path is unreachable: ".concat(propertyKey, ":").concat(jsonPath.join('.')));
224
+ }
225
+ setPath(parsed, jsonPath, value);
226
+ template.props[propertyKey] = JSON.stringify(parsed, null, space);
227
+ }
228
+ function hasInputProperty(input, propertyKey) {
229
+ return Boolean(input.props && Object.prototype.hasOwnProperty.call(input.props, propertyKey));
230
+ }
231
+ function assertKnownInputProperties(definition, input) {
232
+ if (!input.props) return;
233
+ var knownProperties = new Set(_to_consumable_array(Object.keys(definition.defaultSchema.props)).concat(_to_consumable_array(Object.keys(definition.propertyNameMap))));
234
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
235
+ try {
236
+ for(var _iterator = Object.keys(input.props)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
237
+ var propertyKey = _step.value;
238
+ if (!knownProperties.has(propertyKey)) {
239
+ throw new UnknownControlPropertyError(definition.type, propertyKey);
240
+ }
241
+ if (definition.unsupportedExplicitProps.includes(propertyKey)) {
242
+ throw new UnsupportedControlPropertyInputError(definition.type, propertyKey);
243
+ }
244
+ }
245
+ } catch (err) {
246
+ _didIteratorError = true;
247
+ _iteratorError = err;
248
+ } finally{
249
+ try {
250
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
251
+ _iterator.return();
252
+ }
253
+ } finally{
254
+ if (_didIteratorError) {
255
+ throw _iteratorError;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ function selectExplicitTemplates(definition, template, input) {
261
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
262
+ try {
263
+ var _loop = function() {
264
+ var _step_value = _sliced_to_array(_step.value, 2), propertyKey = _step_value[0], inputValue = _step_value[1];
265
+ if (isRecord(inputValue) && definition.explicitObjectDefaults[propertyKey]) {
266
+ template.props[propertyKey] = clone(definition.explicitObjectDefaults[propertyKey]);
267
+ return "continue";
268
+ }
269
+ var itemTemplate = definition.explicitArrayItemDefaults[propertyKey];
270
+ if (Array.isArray(inputValue) && itemTemplate) {
271
+ template.props[propertyKey] = inputValue.map(function(item) {
272
+ return isRecord(item) ? clone(itemTemplate) : clone(item);
273
+ });
274
+ }
275
+ };
276
+ for(var _iterator = Object.entries(input.props || {})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
277
+ } catch (err) {
278
+ _didIteratorError = true;
279
+ _iteratorError = err;
280
+ } finally{
281
+ try {
282
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
283
+ _iterator.return();
284
+ }
285
+ } finally{
286
+ if (_didIteratorError) {
287
+ throw _iteratorError;
288
+ }
289
+ }
290
+ }
291
+ }
292
+ function materializeExplicitGeneratedIds(definition, template, input, context) {
293
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
294
+ try {
295
+ for(var _iterator = Object.entries(definition.explicitObjectGeneratedIdPaths)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
296
+ var _step_value = _sliced_to_array(_step.value, 2), propertyKey = _step_value[0], paths = _step_value[1];
297
+ if (!hasInputProperty(input, propertyKey)) continue;
298
+ var target = template.props[propertyKey];
299
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
300
+ try {
301
+ for(var _iterator1 = paths[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
302
+ var path = _step1.value;
303
+ setPath(target, path, context.idFactory());
304
+ }
305
+ } catch (err) {
306
+ _didIteratorError1 = true;
307
+ _iteratorError1 = err;
308
+ } finally{
309
+ try {
310
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
311
+ _iterator1.return();
312
+ }
313
+ } finally{
314
+ if (_didIteratorError1) {
315
+ throw _iteratorError1;
316
+ }
317
+ }
318
+ }
319
+ }
320
+ } catch (err) {
321
+ _didIteratorError = true;
322
+ _iteratorError = err;
323
+ } finally{
324
+ try {
325
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
326
+ _iterator.return();
327
+ }
328
+ } finally{
329
+ if (_didIteratorError) {
330
+ throw _iteratorError;
331
+ }
332
+ }
333
+ }
334
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
335
+ try {
336
+ for(var _iterator2 = Object.entries(definition.explicitArrayItemGeneratedIdPaths)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
337
+ var _step_value1 = _sliced_to_array(_step2.value, 2), propertyKey1 = _step_value1[0], paths1 = _step_value1[1];
338
+ if (!hasInputProperty(input, propertyKey1)) continue;
339
+ var target1 = template.props[propertyKey1];
340
+ if (!Array.isArray(target1)) continue;
341
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
342
+ try {
343
+ for(var _iterator3 = target1[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
344
+ var item = _step3.value;
345
+ var _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined;
346
+ try {
347
+ for(var _iterator4 = paths1[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true){
348
+ var path1 = _step4.value;
349
+ setPath(item, path1, context.idFactory());
350
+ }
351
+ } catch (err) {
352
+ _didIteratorError4 = true;
353
+ _iteratorError4 = err;
354
+ } finally{
355
+ try {
356
+ if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
357
+ _iterator4.return();
358
+ }
359
+ } finally{
360
+ if (_didIteratorError4) {
361
+ throw _iteratorError4;
362
+ }
363
+ }
364
+ }
365
+ }
366
+ } catch (err) {
367
+ _didIteratorError3 = true;
368
+ _iteratorError3 = err;
369
+ } finally{
370
+ try {
371
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
372
+ _iterator3.return();
373
+ }
374
+ } finally{
375
+ if (_didIteratorError3) {
376
+ throw _iteratorError3;
377
+ }
378
+ }
379
+ }
380
+ }
381
+ } catch (err) {
382
+ _didIteratorError2 = true;
383
+ _iteratorError2 = err;
384
+ } finally{
385
+ try {
386
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
387
+ _iterator2.return();
388
+ }
389
+ } finally{
390
+ if (_didIteratorError2) {
391
+ throw _iteratorError2;
392
+ }
393
+ }
394
+ }
395
+ }
396
+ function hydrateTemplateDynamicDefaults(definition, template, input, context) {
397
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
398
+ try {
399
+ for(var _iterator = definition.dynamicDefaults[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
400
+ var dynamicDefault = _step.value;
401
+ if (dynamicDefault.kind === 'locale-json-text') {
402
+ if (hasInputProperty(input, dynamicDefault.propertyKey)) continue;
403
+ var value = resolveHeadlessMessage({
404
+ key: dynamicDefault.messageKey,
405
+ fallback: dynamicDefault.fallback,
406
+ values: dynamicDefault.values
407
+ }, context);
408
+ applyLocaleJsonDefault(template, dynamicDefault.propertyKey, dynamicDefault.jsonPath, value, dynamicDefault.space);
409
+ continue;
410
+ }
411
+ if (dynamicDefault.kind === 'locale-text') {
412
+ var isExplicit = hasInputProperty(input, dynamicDefault.propertyKey);
413
+ if (isExplicit && dynamicDefault.applyToExplicit !== true) continue;
414
+ if (!canReachPath(template.props, dynamicDefault.path)) {
415
+ if (isExplicit) continue;
416
+ throw new Error("Catalog locale default path is unreachable: ".concat(dynamicDefault.path.join('.')));
417
+ }
418
+ var value1 = resolveHeadlessMessage({
419
+ key: dynamicDefault.messageKey,
420
+ fallback: dynamicDefault.fallback,
421
+ values: dynamicDefault.values
422
+ }, context);
423
+ setPath(template.props, dynamicDefault.path, value1);
424
+ continue;
425
+ }
426
+ if (dynamicDefault.kind === 'generated-id') {
427
+ var propertyKey = dynamicDefault.path[0] === 'props' && typeof dynamicDefault.path[1] === 'string' ? dynamicDefault.path[1] : undefined;
428
+ if (propertyKey && hasInputProperty(input, propertyKey)) continue;
429
+ setPath(template, dynamicDefault.path, context.idFactory());
430
+ continue;
431
+ }
432
+ }
433
+ } catch (err) {
434
+ _didIteratorError = true;
435
+ _iteratorError = err;
436
+ } finally{
437
+ try {
438
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
439
+ _iterator.return();
440
+ }
441
+ } finally{
442
+ if (_didIteratorError) {
443
+ throw _iteratorError;
444
+ }
445
+ }
446
+ }
447
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
448
+ try {
449
+ // 父模板的 generated-id 已覆盖整棵快照;嵌套控件只按自身 definition
450
+ // 递归物化 locale,避免重复分配 id 导致序列漂移。
451
+ for(var _iterator1 = directNestedControlNodes(template)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
452
+ var _step_value = _step1.value, child = _step_value.node;
453
+ var childDefinition = getControlDefinition(child.type);
454
+ if (!childDefinition) throw new UnknownControlTypeError(child.type);
455
+ hydrateNestedLocaleDefaults(childDefinition, child, context);
456
+ }
457
+ } catch (err) {
458
+ _didIteratorError1 = true;
459
+ _iteratorError1 = err;
460
+ } finally{
461
+ try {
462
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
463
+ _iterator1.return();
464
+ }
465
+ } finally{
466
+ if (_didIteratorError1) {
467
+ throw _iteratorError1;
468
+ }
469
+ }
470
+ }
471
+ materializeExplicitGeneratedIds(definition, template, input, context);
472
+ }
473
+ function hydrateNestedLocaleDefaults(definition, node, context) {
474
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
475
+ try {
476
+ for(var _iterator = definition.dynamicDefaults[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
477
+ var dynamicDefault = _step.value;
478
+ if (dynamicDefault.kind === 'locale-json-text') {
479
+ var value = resolveHeadlessMessage({
480
+ key: dynamicDefault.messageKey,
481
+ fallback: dynamicDefault.fallback,
482
+ values: dynamicDefault.values
483
+ }, context);
484
+ applyLocaleJsonDefault(node, dynamicDefault.propertyKey, dynamicDefault.jsonPath, value, dynamicDefault.space);
485
+ continue;
486
+ }
487
+ if (dynamicDefault.kind !== 'locale-text') continue;
488
+ var value1 = resolveHeadlessMessage({
489
+ key: dynamicDefault.messageKey,
490
+ fallback: dynamicDefault.fallback,
491
+ values: dynamicDefault.values
492
+ }, context);
493
+ setPath(node.props, dynamicDefault.path, value1);
494
+ }
495
+ } catch (err) {
496
+ _didIteratorError = true;
497
+ _iteratorError = err;
498
+ } finally{
499
+ try {
500
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
501
+ _iterator.return();
502
+ }
503
+ } finally{
504
+ if (_didIteratorError) {
505
+ throw _iteratorError;
506
+ }
507
+ }
508
+ }
509
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
510
+ try {
511
+ for(var _iterator1 = directNestedControlNodes(node)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
512
+ var _step_value = _step1.value, child = _step_value.node;
513
+ var childDefinition = getControlDefinition(child.type);
514
+ if (!childDefinition) throw new UnknownControlTypeError(child.type);
515
+ hydrateNestedLocaleDefaults(childDefinition, child, context);
516
+ }
517
+ } catch (err) {
518
+ _didIteratorError1 = true;
519
+ _iteratorError1 = err;
520
+ } finally{
521
+ try {
522
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
523
+ _iterator1.return();
524
+ }
525
+ } finally{
526
+ if (_didIteratorError1) {
527
+ throw _iteratorError1;
528
+ }
529
+ }
530
+ }
531
+ }
532
+ function applyInputSensitiveDefaults(definition, node, input, context) {
533
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
534
+ try {
535
+ var _loop = function() {
536
+ var dynamicDefault = _step.value;
537
+ if (dynamicDefault.kind === 'option-item-ids') {
538
+ var _input_props;
539
+ var value = node.props[dynamicDefault.propertyKey];
540
+ if (!Array.isArray(value)) return "continue";
541
+ var inputItems = (_input_props = input.props) === null || _input_props === void 0 ? void 0 : _input_props[dynamicDefault.propertyKey];
542
+ node.props[dynamicDefault.propertyKey] = value.map(function(item, index) {
543
+ var _item_label, _ref, _ref1, _explicitItem_label;
544
+ if (!isRecord(item)) return item;
545
+ var inputItem = Array.isArray(inputItems) ? inputItems[index] : undefined;
546
+ var explicitItem = isRecord(inputItem) ? inputItem : {};
547
+ return _object_spread_props(_object_spread({}, item), {
548
+ id: typeof item.id === 'string' && item.id ? item.id : context.idFactory(),
549
+ value: Object.prototype.hasOwnProperty.call(explicitItem, 'value') ? explicitItem.value : dynamicDefault.valueFromLabel ? (_item_label = item.label) !== null && _item_label !== void 0 ? _item_label : '' : (_ref = (_ref1 = (_explicitItem_label = explicitItem.label) !== null && _explicitItem_label !== void 0 ? _explicitItem_label : item.value) !== null && _ref1 !== void 0 ? _ref1 : item.label) !== null && _ref !== void 0 ? _ref : '',
550
+ color: typeof item.color === 'string' ? item.color : ''
551
+ });
552
+ });
553
+ return "continue";
554
+ }
555
+ if (dynamicDefault.kind !== 'score-explain') return "continue";
556
+ var countValue = node.props[dynamicDefault.countPropertyKey];
557
+ var count = typeof countValue === 'number' && Number.isFinite(countValue) ? Math.max(0, Math.floor(countValue)) : 0;
558
+ var provided = node.props[dynamicDefault.propertyKey];
559
+ var countWasExplicit = hasInputProperty(input, dynamicDefault.countPropertyKey);
560
+ var collectionWasExplicit = hasInputProperty(input, dynamicDefault.propertyKey);
561
+ var source = collectionWasExplicit && Array.isArray(provided) ? provided : countWasExplicit ? Array.from({
562
+ length: count
563
+ }, function() {
564
+ return {};
565
+ }) : Array.isArray(provided) ? provided : Array.from({
566
+ length: count
567
+ }, function() {
568
+ return {};
569
+ });
570
+ node.props[dynamicDefault.propertyKey] = source.map(function(item) {
571
+ var record = isRecord(item) ? item : {};
572
+ return {
573
+ id: typeof record.id === 'string' && record.id ? record.id : context.idFactory(),
574
+ text: typeof record.text === 'string' ? record.text : '',
575
+ color: typeof record.color === 'string' ? record.color : ''
576
+ };
577
+ });
578
+ };
579
+ for(var _iterator = definition.dynamicDefaults[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
580
+ } catch (err) {
581
+ _didIteratorError = true;
582
+ _iteratorError = err;
583
+ } finally{
584
+ try {
585
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
586
+ _iterator.return();
587
+ }
588
+ } finally{
589
+ if (_didIteratorError) {
590
+ throw _iteratorError;
591
+ }
592
+ }
593
+ }
594
+ }
595
+ function mergePreparedProps(definition, templateProps, inputProps) {
596
+ if (!inputProps) return clone(templateProps);
597
+ var result = clone(templateProps);
598
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
599
+ try {
600
+ var _loop = function() {
601
+ var _step_value = _sliced_to_array(_step.value, 2), propertyKey = _step_value[0], inputValue = _step_value[1];
602
+ var templateValue = result[propertyKey];
603
+ if (definition.explicitObjectDefaults[propertyKey] && isRecord(templateValue) && isRecord(inputValue)) {
604
+ result[propertyKey] = mergeObjects(templateValue, inputValue);
605
+ return "continue";
606
+ }
607
+ if (definition.explicitArrayItemDefaults[propertyKey] && Array.isArray(templateValue) && Array.isArray(inputValue)) {
608
+ result[propertyKey] = inputValue.map(function(item, index) {
609
+ var preparedItem = templateValue[index];
610
+ return isRecord(preparedItem) && isRecord(item) ? mergeObjects(preparedItem, item) : clone(item);
611
+ });
612
+ return "continue";
613
+ }
614
+ result[propertyKey] = clone(inputValue);
615
+ };
616
+ for(var _iterator = Object.entries(inputProps)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
617
+ } catch (err) {
618
+ _didIteratorError = true;
619
+ _iteratorError = err;
620
+ } finally{
621
+ try {
622
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
623
+ _iterator.return();
624
+ }
625
+ } finally{
626
+ if (_didIteratorError) {
627
+ throw _iteratorError;
628
+ }
629
+ }
630
+ }
631
+ return result;
632
+ }
633
+ function createWithContext(input, context) {
634
+ var _input_fieldType;
635
+ var definition = getControlDefinition(input.type);
636
+ if (!definition) throw new UnknownControlTypeError(input.type);
637
+ assertKnownInputProperties(definition, input);
638
+ var template = clone(definition.defaultSchema);
639
+ // 先选择真实嵌套构造器的显式输入模板,再物化 locale/id,最后合并用户叶子值。
640
+ selectExplicitTemplates(definition, template, input);
641
+ hydrateTemplateDynamicDefaults(definition, template, input, context);
642
+ var node = {
643
+ id: input.id || context.idFactory(),
644
+ type: input.type,
645
+ controlType: template.controlType,
646
+ props: mergePreparedProps(definition, template.props, input.props),
647
+ fieldType: (_input_fieldType = input.fieldType) !== null && _input_fieldType !== void 0 ? _input_fieldType : template.fieldType
648
+ };
649
+ if (input.children !== undefined) {
650
+ node.children = clone(input.children);
651
+ } else if (template.children !== undefined) {
652
+ node.children = clone(template.children);
653
+ }
654
+ applyInputSensitiveDefaults(definition, node, input, context);
655
+ return node;
656
+ }
657
+ export function createControlNode(input) {
658
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
659
+ var normalizedInput = typeof input === 'string' ? {
660
+ type: input
661
+ } : input;
662
+ return createWithContext(normalizedInput, {
663
+ // 单次调用建立独立序列;构造多节点树时调用方应复用同一个 idFactory。
664
+ idFactory: options.idFactory || createSequentialIdFactory(),
665
+ locale: normalizeHeadlessLocale(options.locale),
666
+ localeMessages: options.localeMessages,
667
+ resolveLocaleMessage: options.resolveLocaleMessage
668
+ });
669
+ }