@react-typed-forms/schemas 11.0.0 → 11.0.2
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/controlRender.d.ts +1 -1
- package/lib/index.js +33 -8
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ export interface ControlRenderOptions extends FormContextOptions {
|
|
|
155
155
|
}
|
|
156
156
|
export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
|
|
157
157
|
export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField[] | undefined;
|
|
158
|
-
export declare function getControlData(fieldPath: SchemaField[] | undefined, parentContext: ControlDataContext, elementIndex: number | undefined): [Control<any
|
|
158
|
+
export declare function getControlData(fieldPath: SchemaField[] | undefined, parentContext: ControlDataContext, elementIndex: number | undefined): [Control<any>, Control<any> | undefined, ControlDataContext];
|
|
159
159
|
export declare function ControlRenderer({ definition, fields, renderer, options, control, parentPath, }: {
|
|
160
160
|
definition: ControlDefinition;
|
|
161
161
|
fields: SchemaField[];
|
package/lib/index.js
CHANGED
|
@@ -1077,14 +1077,15 @@ function useJsonataExpression(jExpr, dataContext, bindings, coerce) {
|
|
|
1077
1077
|
}, [fullExpr]);
|
|
1078
1078
|
var control = core.useControl();
|
|
1079
1079
|
var listenerRef = React.useRef();
|
|
1080
|
+
var updateRef = React.useRef(0);
|
|
1080
1081
|
var _useRefState = core.useRefState(function () {
|
|
1081
1082
|
return core.makeChangeTracker(function () {
|
|
1082
1083
|
var l = listenerRef.current;
|
|
1083
1084
|
if (l) {
|
|
1084
1085
|
listenerRef.current = undefined;
|
|
1085
1086
|
core.addAfterChangesCallback(function () {
|
|
1086
|
-
l();
|
|
1087
1087
|
listenerRef.current = l;
|
|
1088
|
+
l();
|
|
1088
1089
|
});
|
|
1089
1090
|
}
|
|
1090
1091
|
});
|
|
@@ -1097,13 +1098,14 @@ function useJsonataExpression(jExpr, dataContext, bindings, coerce) {
|
|
|
1097
1098
|
collect = _ref$current[0],
|
|
1098
1099
|
updateSubscriptions = _ref$current[1];
|
|
1099
1100
|
var _temp = _finallyRethrows(function () {
|
|
1101
|
+
updateRef.current++;
|
|
1100
1102
|
var bindingData = bindings ? core.collectChanges(collect, bindings) : undefined;
|
|
1101
1103
|
var _coerce = coerce;
|
|
1102
1104
|
return Promise.resolve(compiledExpr.evaluate(core.trackedValue(dataContext.data, collect), bindingData)).then(function (_compiledExpr$evaluat) {
|
|
1103
1105
|
control.value = _coerce(_compiledExpr$evaluat);
|
|
1104
1106
|
});
|
|
1105
1107
|
}, function (_wasThrown, _result) {
|
|
1106
|
-
updateSubscriptions();
|
|
1108
|
+
if (! --updateRef.current) updateSubscriptions();
|
|
1107
1109
|
if (_wasThrown) throw _result;
|
|
1108
1110
|
return _result;
|
|
1109
1111
|
});
|
|
@@ -1366,7 +1368,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1366
1368
|
control = _getControlData[1],
|
|
1367
1369
|
controlDataContext = _getControlData[2];
|
|
1368
1370
|
core.useControlEffect(function () {
|
|
1369
|
-
return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl
|
|
1371
|
+
return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl.isNull, _options.hidden];
|
|
1370
1372
|
}, function (_ref2) {
|
|
1371
1373
|
var vc = _ref2[0],
|
|
1372
1374
|
dv = _ref2[1],
|
|
@@ -1383,8 +1385,10 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1383
1385
|
cd.value = dv;
|
|
1384
1386
|
}
|
|
1385
1387
|
}
|
|
1386
|
-
if (parentNull
|
|
1387
|
-
parentControl.
|
|
1388
|
+
if (parentNull) {
|
|
1389
|
+
parentControl.setValue(function (x) {
|
|
1390
|
+
return x != null ? x : {};
|
|
1391
|
+
});
|
|
1388
1392
|
}
|
|
1389
1393
|
}, true);
|
|
1390
1394
|
var myOptions = core.useCalculatedControl(function () {
|
|
@@ -1402,7 +1406,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1402
1406
|
React.useEffect(function () {
|
|
1403
1407
|
if (control && typeof myOptions.disabled === "boolean") control.disabled = myOptions.disabled;
|
|
1404
1408
|
}, [control, myOptions.disabled]);
|
|
1405
|
-
if (parentControl
|
|
1409
|
+
if (parentControl.isNull) return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
1406
1410
|
var adornments = (_definition$adornment = (_definition$adornment2 = definition.adornments) == null ? void 0 : _definition$adornment2.map(function (x) {
|
|
1407
1411
|
return renderer.renderAdornment({
|
|
1408
1412
|
adornment: x
|
|
@@ -1472,14 +1476,35 @@ function getControlData(fieldPath, parentContext, elementIndex) {
|
|
|
1472
1476
|
})) != null ? _fieldPath$slice$map : [];
|
|
1473
1477
|
var path = [].concat(pp, extraPath);
|
|
1474
1478
|
var schemaField = fieldPath == null ? void 0 : fieldPath.at(-1);
|
|
1475
|
-
var
|
|
1479
|
+
var _lookupControl = lookupControl(data, path),
|
|
1480
|
+
parentControl = _lookupControl[0],
|
|
1481
|
+
found = _lookupControl[1];
|
|
1476
1482
|
var childPath = schemaField ? elementIndex != null ? [].concat(path, [schemaField.field, elementIndex]) : [].concat(path, [schemaField.field]) : path;
|
|
1477
|
-
var childControl = schemaField &&
|
|
1483
|
+
var childControl = schemaField && found ? (_parentControl$fields = parentControl.fields) == null ? void 0 : _parentControl$fields[schemaField.field] : undefined;
|
|
1478
1484
|
return [parentControl, childControl && elementIndex != null ? (_childControl$element = childControl.elements) == null ? void 0 : _childControl$element[elementIndex] : childControl, schemaField ? _extends({}, parentContext, {
|
|
1479
1485
|
path: childPath,
|
|
1480
1486
|
fields: isCompoundField(schemaField) ? schemaField.children : parentContext.fields
|
|
1481
1487
|
}) : parentContext];
|
|
1482
1488
|
}
|
|
1489
|
+
function lookupControl(control, path) {
|
|
1490
|
+
var _base;
|
|
1491
|
+
var base = control;
|
|
1492
|
+
var index = 0;
|
|
1493
|
+
while (index < path.length && base) {
|
|
1494
|
+
control = base;
|
|
1495
|
+
var childId = path[index];
|
|
1496
|
+
var c = base.current;
|
|
1497
|
+
if (typeof childId === "string") {
|
|
1498
|
+
var _c$fields;
|
|
1499
|
+
base = (_c$fields = c.fields) == null ? void 0 : _c$fields[childId];
|
|
1500
|
+
} else {
|
|
1501
|
+
var _c$elements;
|
|
1502
|
+
base = (_c$elements = c.elements) == null ? void 0 : _c$elements[childId];
|
|
1503
|
+
}
|
|
1504
|
+
index++;
|
|
1505
|
+
}
|
|
1506
|
+
return [(_base = base) != null ? _base : control, !!base];
|
|
1507
|
+
}
|
|
1483
1508
|
function ControlRenderer(_ref3) {
|
|
1484
1509
|
var _effect = core.useComponentTracking();
|
|
1485
1510
|
try {
|