@react-typed-forms/schemas 7.1.0 → 7.2.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/.rush/temp/shrinkwrap-deps.json +229 -215
- package/lib/controlRender.d.ts +1 -0
- package/lib/hooks.d.ts +1 -1
- package/lib/index.js +23 -19
- package/lib/index.js.map +1 -1
- package/lib/schemaBuilder.d.ts +1 -1
- package/lib/util.d.ts +1 -0
- package/package.json +48 -48
- package/src/controlRender.tsx +4 -1
- package/src/hooks.tsx +16 -14
- package/src/schemaBuilder.ts +20 -20
- package/src/util.ts +2 -1
- package/src/validators.ts +5 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -141,6 +141,7 @@ export interface ControlRenderOptions extends FormContextOptions {
|
|
|
141
141
|
useEvalExpressionHook?: UseEvalExpressionHook;
|
|
142
142
|
clearHidden?: boolean;
|
|
143
143
|
schemaInterface?: SchemaInterface;
|
|
144
|
+
dataRoot?: Control<any>;
|
|
144
145
|
}
|
|
145
146
|
export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
|
|
146
147
|
export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField | undefined;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -17,4 +17,4 @@ export declare function makeEvalExpressionHook(f: (expr: EntityExpression, conte
|
|
|
17
17
|
export declare function useEvalDynamicHook(definition: ControlDefinition, type: DynamicPropertyType, useEvalExpressionHook: (expr: EntityExpression | undefined) => EvalExpressionHook | undefined): EvalExpressionHook | undefined;
|
|
18
18
|
export declare function matchesType(context: ControlDataContext, types?: string[] | null): boolean | undefined;
|
|
19
19
|
export declare function hideDisplayOnly(context: ControlDataContext, field: SchemaField, definition: ControlDefinition, schemaInterface: SchemaInterface): boolean | undefined;
|
|
20
|
-
export declare function useJsonataExpression(jExpr: string, data: Control<any>): Control<any>;
|
|
20
|
+
export declare function useJsonataExpression(jExpr: string, data: Control<any>, root: Control<any>): Control<any>;
|
package/lib/index.js
CHANGED
|
@@ -479,11 +479,10 @@ function visitControlData(definition, ctx, cb) {
|
|
|
479
479
|
var elemResult = def ? cb(def, fieldData, c, true) : undefined;
|
|
480
480
|
if (elemResult !== undefined) return elemResult;
|
|
481
481
|
if (isCompoundField(fieldData)) {
|
|
482
|
-
var cfResult = visitControlDataArray(children, {
|
|
482
|
+
var cfResult = visitControlDataArray(children, _extends({}, ctx, {
|
|
483
483
|
fields: fieldData.children,
|
|
484
|
-
groupControl: c
|
|
485
|
-
|
|
486
|
-
}, cb);
|
|
484
|
+
groupControl: c
|
|
485
|
+
}), cb);
|
|
487
486
|
if (cfResult !== undefined) return cfResult;
|
|
488
487
|
}
|
|
489
488
|
}
|
|
@@ -528,7 +527,6 @@ function cleanDataForSchema(v, fields) {
|
|
|
528
527
|
;
|
|
529
528
|
}
|
|
530
529
|
});
|
|
531
|
-
|
|
532
530
|
return out;
|
|
533
531
|
}
|
|
534
532
|
function getAllReferencedClasses(c) {
|
|
@@ -754,7 +752,7 @@ function useDataMatchExpression(fvExpr, fields, data) {
|
|
|
754
752
|
function defaultEvalHooks(expr, context) {
|
|
755
753
|
switch (expr.type) {
|
|
756
754
|
case exports.ExpressionType.Jsonata:
|
|
757
|
-
return useJsonataExpression(expr.expression, context.groupControl);
|
|
755
|
+
return useJsonataExpression(expr.expression, context.groupControl, context.root);
|
|
758
756
|
case exports.ExpressionType.Data:
|
|
759
757
|
return useDataExpression(expr, context.fields, context.groupControl);
|
|
760
758
|
case exports.ExpressionType.DataMatch:
|
|
@@ -790,21 +788,25 @@ function hideDisplayOnly(context, field, definition, schemaInterface) {
|
|
|
790
788
|
var displayOptions = getDisplayOnlyOptions(definition);
|
|
791
789
|
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(field, context.groupControl.fields[field.field].value);
|
|
792
790
|
}
|
|
793
|
-
function useJsonataExpression(jExpr, data) {
|
|
791
|
+
function useJsonataExpression(jExpr, data, root) {
|
|
794
792
|
var compiledExpr = React.useMemo(function () {
|
|
795
793
|
try {
|
|
796
794
|
return jsonata__default["default"](jExpr);
|
|
797
795
|
} catch (e) {
|
|
798
796
|
console.error(e);
|
|
799
|
-
return jsonata__default["default"]("");
|
|
797
|
+
return jsonata__default["default"]("null");
|
|
800
798
|
}
|
|
801
799
|
}, [jExpr]);
|
|
802
800
|
var control = core.useControl();
|
|
803
801
|
core.useControlEffect(function () {
|
|
804
|
-
return data.value;
|
|
805
|
-
}, function (
|
|
802
|
+
return [data.value, root.value];
|
|
803
|
+
}, function (_ref2) {
|
|
804
|
+
var v = _ref2[0],
|
|
805
|
+
rv = _ref2[1];
|
|
806
806
|
try {
|
|
807
|
-
return Promise.resolve(compiledExpr.evaluate(v
|
|
807
|
+
return Promise.resolve(compiledExpr.evaluate(v, {
|
|
808
|
+
root: rv
|
|
809
|
+
})).then(function (_compiledExpr$evaluat) {
|
|
808
810
|
control.value = _compiledExpr$evaluat;
|
|
809
811
|
});
|
|
810
812
|
} catch (e) {
|
|
@@ -841,7 +843,7 @@ function useValidationHook(definition) {
|
|
|
841
843
|
}, validatorTypes ? validatorTypes : [null]);
|
|
842
844
|
}
|
|
843
845
|
function useJsonataValidator(control, context, expr, hidden, i) {
|
|
844
|
-
var errorMsg = useJsonataExpression(expr.expression, context.groupControl);
|
|
846
|
+
var errorMsg = useJsonataExpression(expr.expression, context.groupControl, context.root);
|
|
845
847
|
core.useControlEffect(function () {
|
|
846
848
|
return [hidden, errorMsg.value];
|
|
847
849
|
}, function (_ref) {
|
|
@@ -933,7 +935,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
933
935
|
var parentControl = _ref.control;
|
|
934
936
|
var stopTracking = core.useComponentTracking();
|
|
935
937
|
try {
|
|
936
|
-
var _c$children$map, _c$children, _definition$adornment, _definition$adornment2;
|
|
938
|
+
var _options$dataRoot, _c$children$map, _c$children, _definition$adornment, _definition$adornment2;
|
|
937
939
|
var _r$current = r.current,
|
|
938
940
|
c = _r$current.definition,
|
|
939
941
|
_options = _r$current.options,
|
|
@@ -942,7 +944,8 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
942
944
|
var dataContext = {
|
|
943
945
|
groupControl: parentControl,
|
|
944
946
|
fields: _fields,
|
|
945
|
-
schemaInterface: schemaInterface
|
|
947
|
+
schemaInterface: schemaInterface,
|
|
948
|
+
root: (_options$dataRoot = _options.dataRoot) != null ? _options$dataRoot : parentControl
|
|
946
949
|
};
|
|
947
950
|
var readonlyControl = useIsReadonly(dataContext);
|
|
948
951
|
var disabledControl = useIsDisabled(dataContext);
|
|
@@ -1001,7 +1004,9 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1001
1004
|
}).value;
|
|
1002
1005
|
useValidation(control, !!myOptions.hidden, dataContext);
|
|
1003
1006
|
var childRenderers = (_c$children$map = (_c$children = c.children) == null ? void 0 : _c$children.map(function (cd) {
|
|
1004
|
-
return useControlRenderer(cd, childContext.fields, renderer, _extends({}, _options, myOptions
|
|
1007
|
+
return useControlRenderer(cd, childContext.fields, renderer, _extends({}, _options, myOptions, {
|
|
1008
|
+
dataRoot: dataContext.root
|
|
1009
|
+
}));
|
|
1005
1010
|
})) != null ? _c$children$map : [];
|
|
1006
1011
|
React.useEffect(function () {
|
|
1007
1012
|
if (control && typeof myOptions.disabled === "boolean") control.disabled = myOptions.disabled;
|
|
@@ -1053,11 +1058,10 @@ function lookupSchemaField(c, fields) {
|
|
|
1053
1058
|
function getControlData(schemaField, parentContext) {
|
|
1054
1059
|
var _parentContext$groupC, _parentContext$groupC2;
|
|
1055
1060
|
var childControl = schemaField ? (_parentContext$groupC = (_parentContext$groupC2 = parentContext.groupControl.fields) == null ? void 0 : _parentContext$groupC2[schemaField.field]) != null ? _parentContext$groupC : core.newControl({}) : undefined;
|
|
1056
|
-
return [childControl, schemaField && isCompoundField(schemaField) ? {
|
|
1061
|
+
return [childControl, schemaField && isCompoundField(schemaField) ? _extends({}, parentContext, {
|
|
1057
1062
|
groupControl: childControl,
|
|
1058
|
-
fields: schemaField.children
|
|
1059
|
-
|
|
1060
|
-
} : parentContext];
|
|
1063
|
+
fields: schemaField.children
|
|
1064
|
+
}) : parentContext];
|
|
1061
1065
|
}
|
|
1062
1066
|
function groupProps(renderOptions, childCount, _renderChild, control, className, style) {
|
|
1063
1067
|
if (renderOptions === void 0) {
|