@react-typed-forms/schemas 10.2.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +98 -43
- package/lib/index.js.map +1 -1
- package/lib/util.d.ts +8 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -313,49 +313,100 @@ function defaultControlForField(sf) {
|
|
|
313
313
|
}
|
|
314
314
|
throw "Unknown schema field";
|
|
315
315
|
}
|
|
316
|
-
function
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
316
|
+
function findControlsForCompound(compound, definition) {
|
|
317
|
+
if (isDataControlDefinition(definition) && compound.field === definition.field) {
|
|
318
|
+
return [definition];
|
|
319
|
+
}
|
|
320
|
+
if (isGroupControlsDefinition(definition)) {
|
|
321
|
+
var _definition$children$, _definition$children;
|
|
322
|
+
if (definition.compoundField === compound.field) return [definition];
|
|
323
|
+
return (_definition$children$ = (_definition$children = definition.children) == null ? void 0 : _definition$children.flatMap(function (d) {
|
|
324
|
+
return findControlsForCompound(compound, d);
|
|
325
|
+
})) != null ? _definition$children$ : [];
|
|
326
|
+
}
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
function findCompoundGroups(fields, controls) {
|
|
330
|
+
return Object.fromEntries(fields.filter(isCompoundField).map(function (cf) {
|
|
331
|
+
var groups = controls.flatMap(function (x) {
|
|
332
|
+
return findControlsForCompound(cf, x);
|
|
333
|
+
});
|
|
334
|
+
return [cf.field, {
|
|
335
|
+
groups: groups.concat(findNonDataGroups(groups.flatMap(function (x) {
|
|
336
|
+
var _x$children;
|
|
337
|
+
return (_x$children = x.children) != null ? _x$children : [];
|
|
338
|
+
}))),
|
|
339
|
+
children: findCompoundGroups(cf.children, groups.flatMap(function (x) {
|
|
340
|
+
var _x$children2;
|
|
341
|
+
return (_x$children2 = x.children) != null ? _x$children2 : [];
|
|
342
|
+
}))
|
|
343
|
+
}];
|
|
344
|
+
}));
|
|
324
345
|
}
|
|
325
|
-
function
|
|
326
|
-
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
346
|
+
function existsInGroups(field, lookup) {
|
|
347
|
+
var itself = lookup.groups.find(function (c) {
|
|
348
|
+
var _c$children;
|
|
349
|
+
return (_c$children = c.children) == null ? void 0 : _c$children.find(function (x) {
|
|
350
|
+
return isDataControlDefinition(x) && x.field === field.field || isGroupControlsDefinition(x) && x.compoundField === field.field;
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
if (!itself) return [[field, lookup]];
|
|
354
|
+
if (isCompoundField(field)) {
|
|
355
|
+
var childLookup = lookup.children[field.field];
|
|
356
|
+
if (!childLookup) return [[field, lookup]];
|
|
357
|
+
return field.children.flatMap(function (c) {
|
|
358
|
+
return existsInGroups(c, childLookup);
|
|
359
|
+
});
|
|
330
360
|
}
|
|
331
|
-
return
|
|
361
|
+
return [];
|
|
362
|
+
}
|
|
363
|
+
function findNonDataGroups(controls) {
|
|
364
|
+
return controls.flatMap(function (control) {
|
|
365
|
+
var _control$children2;
|
|
366
|
+
return isGroupControlsDefinition(control) && !control.compoundField ? [control].concat(findNonDataGroups((_control$children2 = control.children) != null ? _control$children2 : [])) : [];
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function cloneChildren(c) {
|
|
370
|
+
var _c$children2;
|
|
371
|
+
if (c.children) return _extends({}, c, {
|
|
372
|
+
children: (_c$children2 = c.children) == null ? void 0 : _c$children2.map(cloneChildren)
|
|
373
|
+
});
|
|
374
|
+
return c;
|
|
332
375
|
}
|
|
333
376
|
function addMissingControls(fields, controls) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
377
|
+
controls = controls.map(cloneChildren);
|
|
378
|
+
var rootMapping = findCompoundGroups(fields, controls);
|
|
379
|
+
var rootGroups = findNonDataGroups([{
|
|
380
|
+
type: exports.ControlDefinitionType.Group,
|
|
381
|
+
children: controls
|
|
382
|
+
}]);
|
|
383
|
+
var rootLookup = {
|
|
384
|
+
children: rootMapping,
|
|
385
|
+
groups: rootGroups
|
|
386
|
+
};
|
|
387
|
+
var missingFields = fields.filter(function (x) {
|
|
388
|
+
return !fieldHasTag(x, "_NoControl");
|
|
389
|
+
}).flatMap(function (x) {
|
|
390
|
+
return existsInGroups(x, rootLookup);
|
|
342
391
|
});
|
|
343
|
-
|
|
344
|
-
var
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
var cf = x;
|
|
350
|
-
return _extends({}, cf, {
|
|
351
|
-
children: addMissingControls(ex.field.children, (_cf$children = cf.children) != null ? _cf$children : [])
|
|
392
|
+
missingFields.forEach(function (_ref) {
|
|
393
|
+
var _f$tags, _insertGroup;
|
|
394
|
+
var f = _ref[0],
|
|
395
|
+
lookup = _ref[1];
|
|
396
|
+
var groupToAdd = (_f$tags = f.tags) == null ? void 0 : _f$tags.find(function (x) {
|
|
397
|
+
return x.startsWith("_ControlGroup:");
|
|
352
398
|
});
|
|
399
|
+
var insertGroup = undefined;
|
|
400
|
+
if (groupToAdd) {
|
|
401
|
+
var groupName = groupToAdd.substring(14);
|
|
402
|
+
insertGroup = lookup.groups.find(function (x) {
|
|
403
|
+
return x.title === groupName;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (!insertGroup) insertGroup = lookup.groups[0];
|
|
407
|
+
(_insertGroup = insertGroup) == null || (_insertGroup = _insertGroup.children) == null || _insertGroup.push(defaultControlForField(f));
|
|
353
408
|
});
|
|
354
|
-
return
|
|
355
|
-
return !x.existing;
|
|
356
|
-
}).map(function (x) {
|
|
357
|
-
return defaultControlForField(x.field);
|
|
358
|
-
}));
|
|
409
|
+
return controls;
|
|
359
410
|
}
|
|
360
411
|
function useUpdatedRef(a) {
|
|
361
412
|
var r = React.useRef(a);
|
|
@@ -472,8 +523,8 @@ function cleanDataForSchema(v, fields) {
|
|
|
472
523
|
return out;
|
|
473
524
|
}
|
|
474
525
|
function getAllReferencedClasses(c, collectExtra) {
|
|
475
|
-
var _c$
|
|
476
|
-
var childClasses = (_c$
|
|
526
|
+
var _c$children3, _collectExtra;
|
|
527
|
+
var childClasses = (_c$children3 = c.children) == null ? void 0 : _c$children3.flatMap(function (x) {
|
|
477
528
|
return getAllReferencedClasses(x, collectExtra);
|
|
478
529
|
});
|
|
479
530
|
var tc = clsx__default["default"]([c.styleClass, c.layoutClass, c.labelClass].concat((_collectExtra = collectExtra == null ? void 0 : collectExtra(c)) != null ? _collectExtra : []).map(getOverrideClass));
|
|
@@ -543,8 +594,8 @@ function makeHook(runHook, state, deps) {
|
|
|
543
594
|
}
|
|
544
595
|
function useDynamicHooks(hooks) {
|
|
545
596
|
var hookEntries = Object.entries(hooks);
|
|
546
|
-
var deps = hookEntries.map(function (
|
|
547
|
-
var x =
|
|
597
|
+
var deps = hookEntries.map(function (_ref2) {
|
|
598
|
+
var x = _ref2[1];
|
|
548
599
|
return toDepString(x.deps);
|
|
549
600
|
}).join(",");
|
|
550
601
|
var ref = React.useRef({});
|
|
@@ -553,9 +604,9 @@ function useDynamicHooks(hooks) {
|
|
|
553
604
|
return s[x[0]] = x[1].state;
|
|
554
605
|
});
|
|
555
606
|
return React.useCallback(function (p) {
|
|
556
|
-
return Object.fromEntries(hookEntries.map(function (
|
|
557
|
-
var f =
|
|
558
|
-
hg =
|
|
607
|
+
return Object.fromEntries(hookEntries.map(function (_ref3) {
|
|
608
|
+
var f = _ref3[0],
|
|
609
|
+
hg = _ref3[1];
|
|
559
610
|
return [f, hg.runHook(p, ref.current[f])];
|
|
560
611
|
}));
|
|
561
612
|
}, [deps]);
|
|
@@ -2670,12 +2721,16 @@ exports.dynamicReadonly = dynamicReadonly;
|
|
|
2670
2721
|
exports.dynamicVisibility = dynamicVisibility;
|
|
2671
2722
|
exports.elementValueForField = elementValueForField;
|
|
2672
2723
|
exports.emptyGroupDefinition = emptyGroupDefinition;
|
|
2724
|
+
exports.existsInGroups = existsInGroups;
|
|
2673
2725
|
exports.fieldDisplayName = fieldDisplayName;
|
|
2674
2726
|
exports.fieldEqExpr = fieldEqExpr;
|
|
2675
2727
|
exports.fieldHasTag = fieldHasTag;
|
|
2676
2728
|
exports.findChildDefinition = findChildDefinition;
|
|
2677
2729
|
exports.findCompoundField = findCompoundField;
|
|
2730
|
+
exports.findCompoundGroups = findCompoundGroups;
|
|
2731
|
+
exports.findControlsForCompound = findControlsForCompound;
|
|
2678
2732
|
exports.findField = findField;
|
|
2733
|
+
exports.findNonDataGroups = findNonDataGroups;
|
|
2679
2734
|
exports.findScalarField = findScalarField;
|
|
2680
2735
|
exports.getAllReferencedClasses = getAllReferencedClasses;
|
|
2681
2736
|
exports.getControlData = getControlData;
|