@react-typed-forms/schemas 10.4.0 → 11.0.1
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 +2 -2
- package/lib/hooks.d.ts +9 -8
- package/lib/index.js +143 -93
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +0 -3
- package/lib/util.d.ts +5 -2
- package/package.json +2 -2
package/lib/controlRender.d.ts
CHANGED
|
@@ -154,8 +154,8 @@ export interface ControlRenderOptions extends FormContextOptions {
|
|
|
154
154
|
elementIndex?: number;
|
|
155
155
|
}
|
|
156
156
|
export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
|
|
157
|
-
export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField | undefined;
|
|
158
|
-
export declare function getControlData(
|
|
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>, 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/hooks.d.ts
CHANGED
|
@@ -3,20 +3,21 @@ import React from "react";
|
|
|
3
3
|
import { Control } from "@react-typed-forms/core";
|
|
4
4
|
import { ControlDataContext, DataContext, DynamicHookGenerator } from "./util";
|
|
5
5
|
export type EvalExpressionHook<A = any> = DynamicHookGenerator<Control<A | undefined>, ControlDataContext>;
|
|
6
|
-
export type UseEvalExpressionHook = (expr: EntityExpression | undefined) => DynamicHookGenerator<Control<any> | undefined, ControlDataContext>;
|
|
7
|
-
export declare function useEvalVisibilityHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition,
|
|
6
|
+
export type UseEvalExpressionHook = (expr: EntityExpression | undefined, coerce: (v: any) => any) => DynamicHookGenerator<Control<any> | undefined, ControlDataContext>;
|
|
7
|
+
export declare function useEvalVisibilityHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition, fieldPath?: SchemaField[]): EvalExpressionHook<boolean>;
|
|
8
8
|
export declare function useEvalReadonlyHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<boolean>;
|
|
9
9
|
export declare function useEvalStyleHook(useEvalExpressionHook: UseEvalExpressionHook, property: DynamicPropertyType, definition: ControlDefinition): EvalExpressionHook<React.CSSProperties>;
|
|
10
10
|
export declare function useEvalAllowedOptionsHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<any[]>;
|
|
11
11
|
export declare function useEvalDisabledHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<boolean>;
|
|
12
12
|
export declare function useEvalDisplayHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): DynamicHookGenerator<Control<string | undefined> | undefined, ControlDataContext>;
|
|
13
13
|
export declare function useEvalDefaultValueHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition, schemaField: SchemaField | undefined, element: boolean): EvalExpressionHook;
|
|
14
|
-
export declare function defaultEvalHooks(expr: EntityExpression, context: ControlDataContext): Control<any>;
|
|
14
|
+
export declare function defaultEvalHooks(expr: EntityExpression, context: ControlDataContext, coerce: (v: any) => any): Control<any>;
|
|
15
15
|
export declare const defaultUseEvalExpressionHook: UseEvalExpressionHook;
|
|
16
|
-
export declare function makeEvalExpressionHook(f: (expr: EntityExpression, context: ControlDataContext) => Control<any>): UseEvalExpressionHook;
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function
|
|
19
|
-
export declare function
|
|
20
|
-
export declare function
|
|
16
|
+
export declare function makeEvalExpressionHook(f: (expr: EntityExpression, context: ControlDataContext, coerce: (v: any) => any) => Control<any>): UseEvalExpressionHook;
|
|
17
|
+
export declare function useEvalDynamicBoolHook(definition: ControlDefinition, type: DynamicPropertyType, useEvalExpressionHook: UseEvalExpressionHook): DynamicHookGenerator<Control<any> | undefined, ControlDataContext>;
|
|
18
|
+
export declare function useEvalDynamicHook(definition: ControlDefinition, type: DynamicPropertyType, useEvalExpressionHook: UseEvalExpressionHook, coerce?: (v: any) => any): DynamicHookGenerator<Control<any> | undefined, ControlDataContext>;
|
|
19
|
+
export declare function matchesType(context: ControlDataContext, fieldPath?: SchemaField[]): boolean | undefined;
|
|
20
|
+
export declare function hideDisplayOnly(context: ControlDataContext, fieldPath: SchemaField[], definition: ControlDefinition, schemaInterface: SchemaInterface): boolean | undefined;
|
|
21
|
+
export declare function useJsonataExpression(jExpr: string, dataContext: DataContext, bindings?: () => Record<string, any>, coerce?: (v: any) => any): Control<any>;
|
|
21
22
|
export declare function useEvalActionHook(useExpr: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<string | null>;
|
|
22
23
|
export declare function useEvalLabelText(useExpr: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<string | null>;
|
package/lib/index.js
CHANGED
|
@@ -420,11 +420,13 @@ function isControlReadonly(c) {
|
|
|
420
420
|
function getDisplayOnlyOptions(d) {
|
|
421
421
|
return isDataControlDefinition(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
|
|
422
422
|
}
|
|
423
|
-
function getTypeField(context) {
|
|
424
|
-
var
|
|
423
|
+
function getTypeField(context, fieldPath) {
|
|
424
|
+
var withoutLast = fieldPath.slice(0, -1);
|
|
425
|
+
var fieldList = withoutLast.length > 0 ? withoutLast.at(-1).children : context.fields;
|
|
426
|
+
var typeSchemaField = fieldList.find(function (x) {
|
|
425
427
|
return x.isTypeField;
|
|
426
428
|
});
|
|
427
|
-
return typeSchemaField ? lookupChildControl(context, typeSchemaField
|
|
429
|
+
return typeSchemaField ? lookupChildControl(context, [].concat(withoutLast, [typeSchemaField])) : undefined;
|
|
428
430
|
}
|
|
429
431
|
function visitControlDataArray(controls, context, cb) {
|
|
430
432
|
if (!controls) return undefined;
|
|
@@ -479,8 +481,13 @@ function visitControlData(definition, ctx, cb) {
|
|
|
479
481
|
}
|
|
480
482
|
}
|
|
481
483
|
}
|
|
482
|
-
function lookupChildControl(data,
|
|
483
|
-
|
|
484
|
+
function lookupChildControl(data, path) {
|
|
485
|
+
return lookupChildControlPath(data, path.map(function (x) {
|
|
486
|
+
return x.field;
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
function lookupChildControlPath(data, jsonPath) {
|
|
490
|
+
var childPath = [].concat(data.path, jsonPath);
|
|
484
491
|
return watchControlLookup(data.data, childPath);
|
|
485
492
|
}
|
|
486
493
|
function cleanDataForSchema(v, fields) {
|
|
@@ -625,6 +632,21 @@ function appendElementIndex(dataContext, elementIndex) {
|
|
|
625
632
|
function applyLengthRestrictions(length, min, max, minValue, maxValue) {
|
|
626
633
|
return [min == null || length > min ? minValue : undefined, max == null || length < max ? maxValue : undefined];
|
|
627
634
|
}
|
|
635
|
+
function findFieldPath(fields, fieldPath) {
|
|
636
|
+
var fieldNames = fieldPath.split("/");
|
|
637
|
+
var foundFields = [];
|
|
638
|
+
var i = 0;
|
|
639
|
+
var currentFields = fields;
|
|
640
|
+
while (i < fieldNames.length && currentFields) {
|
|
641
|
+
var cf = fieldNames[i];
|
|
642
|
+
var nextField = findField(currentFields, cf);
|
|
643
|
+
if (!nextField) return undefined;
|
|
644
|
+
foundFields.push(nextField);
|
|
645
|
+
currentFields = isCompoundField(nextField) && !nextField.collection ? nextField.children : undefined;
|
|
646
|
+
i++;
|
|
647
|
+
}
|
|
648
|
+
return foundFields.length === fieldNames.length ? foundFields : undefined;
|
|
649
|
+
}
|
|
628
650
|
|
|
629
651
|
function buildSchema(def) {
|
|
630
652
|
return Object.entries(def).map(function (x) {
|
|
@@ -885,43 +907,6 @@ function applyExtensionsToSchema(schemaMap, extensions) {
|
|
|
885
907
|
return resolveSchemas(extensions.reduce(applyExtensionToSchema, schemaMap));
|
|
886
908
|
}
|
|
887
909
|
|
|
888
|
-
function useCalculatedControl(calculate) {
|
|
889
|
-
var c = core.useControl(calculate);
|
|
890
|
-
core.useControlEffect(calculate, function (v) {
|
|
891
|
-
return c.value = v;
|
|
892
|
-
});
|
|
893
|
-
return c;
|
|
894
|
-
}
|
|
895
|
-
function cc(n) {
|
|
896
|
-
return n ? n : undefined;
|
|
897
|
-
}
|
|
898
|
-
function trackedStructure(c, tracker) {
|
|
899
|
-
var cc = c.current;
|
|
900
|
-
var cv = cc.value;
|
|
901
|
-
if (cv == null) {
|
|
902
|
-
tracker(c, core.ControlChange.Structure);
|
|
903
|
-
return cv;
|
|
904
|
-
}
|
|
905
|
-
if (typeof cv !== "object") {
|
|
906
|
-
tracker(c, core.ControlChange.Value);
|
|
907
|
-
return cv;
|
|
908
|
-
}
|
|
909
|
-
return new Proxy(cv, {
|
|
910
|
-
get: function get(target, p, receiver) {
|
|
911
|
-
if (Array.isArray(cv)) {
|
|
912
|
-
tracker(c, core.ControlChange.Structure);
|
|
913
|
-
if (typeof p === "symbol" || p[0] >= "9" || p[0] < "0") return Reflect.get(cv, p);
|
|
914
|
-
var nc = cc.elements[p];
|
|
915
|
-
if (typeof nc === "function") return nc;
|
|
916
|
-
if (nc == null) return null;
|
|
917
|
-
return trackedStructure(nc, tracker);
|
|
918
|
-
}
|
|
919
|
-
if (p in cc.fields || p in cv) return trackedStructure(cc.fields[p], tracker);
|
|
920
|
-
return undefined;
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
|
|
925
910
|
function _finallyRethrows(body, finalizer) {
|
|
926
911
|
try {
|
|
927
912
|
var result = body();
|
|
@@ -933,24 +918,24 @@ function _finallyRethrows(body, finalizer) {
|
|
|
933
918
|
}
|
|
934
919
|
return finalizer(false, result);
|
|
935
920
|
}
|
|
936
|
-
function useEvalVisibilityHook(useEvalExpressionHook, definition,
|
|
937
|
-
var dynamicVisibility =
|
|
921
|
+
function useEvalVisibilityHook(useEvalExpressionHook, definition, fieldPath) {
|
|
922
|
+
var dynamicVisibility = useEvalDynamicBoolHook(definition, exports.DynamicPropertyType.Visible, useEvalExpressionHook);
|
|
938
923
|
return makeDynamicPropertyHook(dynamicVisibility, function (ctx, _ref) {
|
|
939
|
-
var
|
|
924
|
+
var fieldPath = _ref.fieldPath,
|
|
940
925
|
definition = _ref.definition;
|
|
941
926
|
return core.useComputed(function () {
|
|
942
|
-
return matchesType(ctx,
|
|
927
|
+
return matchesType(ctx, fieldPath) && (!fieldPath || !hideDisplayOnly(ctx, fieldPath, definition, ctx.schemaInterface));
|
|
943
928
|
});
|
|
944
929
|
}, {
|
|
945
|
-
|
|
930
|
+
fieldPath: fieldPath,
|
|
946
931
|
definition: definition
|
|
947
932
|
});
|
|
948
933
|
}
|
|
949
934
|
function useEvalReadonlyHook(useEvalExpressionHook, definition) {
|
|
950
|
-
var dynamicReadonly =
|
|
935
|
+
var dynamicReadonly = useEvalDynamicBoolHook(definition, exports.DynamicPropertyType.Readonly, useEvalExpressionHook);
|
|
951
936
|
return makeDynamicPropertyHook(dynamicReadonly, function (ctx, _ref2) {
|
|
952
937
|
var definition = _ref2.definition;
|
|
953
|
-
return useCalculatedControl(function () {
|
|
938
|
+
return core.useCalculatedControl(function () {
|
|
954
939
|
return isControlReadonly(definition);
|
|
955
940
|
});
|
|
956
941
|
}, {
|
|
@@ -970,7 +955,7 @@ function useEvalAllowedOptionsHook(useEvalExpressionHook, definition) {
|
|
|
970
955
|
}, undefined);
|
|
971
956
|
}
|
|
972
957
|
function useEvalDisabledHook(useEvalExpressionHook, definition) {
|
|
973
|
-
var dynamicDisabled =
|
|
958
|
+
var dynamicDisabled = useEvalDynamicBoolHook(definition, exports.DynamicPropertyType.Disabled, useEvalExpressionHook);
|
|
974
959
|
return makeDynamicPropertyHook(dynamicDisabled, function () {
|
|
975
960
|
return core.useControl(false);
|
|
976
961
|
}, undefined);
|
|
@@ -995,63 +980,89 @@ function useEvalDefaultValueHook(useEvalExpressionHook, definition, schemaField,
|
|
|
995
980
|
schemaField: schemaField
|
|
996
981
|
});
|
|
997
982
|
}
|
|
998
|
-
function useDataExpression(fvExpr, fields, data) {
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
983
|
+
function useDataExpression(fvExpr, fields, data, coerce) {
|
|
984
|
+
if (coerce === void 0) {
|
|
985
|
+
coerce = function coerce(x) {
|
|
986
|
+
return x;
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
var refField = findFieldPath(fields, fvExpr.field);
|
|
990
|
+
var otherField = refField ? lookupChildControl(data, refField) : undefined;
|
|
991
|
+
return core.useCalculatedControl(function () {
|
|
992
|
+
return coerce(otherField == null ? void 0 : otherField.value);
|
|
1003
993
|
});
|
|
1004
994
|
}
|
|
1005
|
-
function useDataMatchExpression(fvExpr, fields, data) {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
995
|
+
function useDataMatchExpression(fvExpr, fields, data, coerce) {
|
|
996
|
+
if (coerce === void 0) {
|
|
997
|
+
coerce = function coerce(x) {
|
|
998
|
+
return x;
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
var refField = findFieldPath(fields, fvExpr.field);
|
|
1002
|
+
var otherField = refField ? lookupChildControl(data, refField) : undefined;
|
|
1003
|
+
return core.useCalculatedControl(function () {
|
|
1009
1004
|
var fv = otherField == null ? void 0 : otherField.value;
|
|
1010
|
-
return Array.isArray(fv) ? fv.includes(fvExpr.value) : fv === fvExpr.value;
|
|
1005
|
+
return coerce(Array.isArray(fv) ? fv.includes(fvExpr.value) : fv === fvExpr.value);
|
|
1011
1006
|
});
|
|
1012
1007
|
}
|
|
1013
|
-
function defaultEvalHooks(expr, context) {
|
|
1008
|
+
function defaultEvalHooks(expr, context, coerce) {
|
|
1014
1009
|
switch (expr.type) {
|
|
1015
1010
|
case exports.ExpressionType.Jsonata:
|
|
1016
|
-
return useJsonataExpression(expr.expression, context);
|
|
1011
|
+
return useJsonataExpression(expr.expression, context, undefined, coerce);
|
|
1017
1012
|
case exports.ExpressionType.Data:
|
|
1018
|
-
return useDataExpression(expr, context.fields, context);
|
|
1013
|
+
return useDataExpression(expr, context.fields, context, coerce);
|
|
1019
1014
|
case exports.ExpressionType.DataMatch:
|
|
1020
|
-
return useDataMatchExpression(expr, context.fields, context);
|
|
1015
|
+
return useDataMatchExpression(expr, context.fields, context, coerce);
|
|
1021
1016
|
default:
|
|
1022
1017
|
return core.useControl(undefined);
|
|
1023
1018
|
}
|
|
1024
1019
|
}
|
|
1025
1020
|
var defaultUseEvalExpressionHook = makeEvalExpressionHook(defaultEvalHooks);
|
|
1026
1021
|
function makeEvalExpressionHook(f) {
|
|
1027
|
-
return function (expr) {
|
|
1022
|
+
return function (expr, coerce) {
|
|
1028
1023
|
return {
|
|
1029
1024
|
deps: expr == null ? void 0 : expr.type,
|
|
1030
1025
|
state: expr,
|
|
1031
1026
|
runHook: function runHook(ctx, state) {
|
|
1032
|
-
return state ? f(state, ctx) : undefined;
|
|
1027
|
+
return state ? f(state, ctx, coerce) : undefined;
|
|
1033
1028
|
}
|
|
1034
1029
|
};
|
|
1035
1030
|
};
|
|
1036
1031
|
}
|
|
1037
|
-
function
|
|
1032
|
+
function useEvalDynamicBoolHook(definition, type, useEvalExpressionHook) {
|
|
1033
|
+
return useEvalDynamicHook(definition, type, useEvalExpressionHook, function (x) {
|
|
1034
|
+
return Boolean(x);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function useEvalDynamicHook(definition, type, useEvalExpressionHook, coerce) {
|
|
1038
1038
|
var _definition$dynamic;
|
|
1039
|
+
if (coerce === void 0) {
|
|
1040
|
+
coerce = function coerce(x) {
|
|
1041
|
+
return x;
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1039
1044
|
var expression = (_definition$dynamic = definition.dynamic) == null ? void 0 : _definition$dynamic.find(function (x) {
|
|
1040
1045
|
return x.type === type;
|
|
1041
1046
|
});
|
|
1042
|
-
return useEvalExpressionHook(expression == null ? void 0 : expression.expr);
|
|
1047
|
+
return useEvalExpressionHook(expression == null ? void 0 : expression.expr, coerce);
|
|
1043
1048
|
}
|
|
1044
|
-
function matchesType(context,
|
|
1049
|
+
function matchesType(context, fieldPath) {
|
|
1050
|
+
var types = fieldPath ? fieldPath[fieldPath.length - 1].onlyForTypes : undefined;
|
|
1045
1051
|
if (types == null || types.length === 0) return true;
|
|
1046
|
-
var typeField = getTypeField(context);
|
|
1052
|
+
var typeField = getTypeField(context, fieldPath);
|
|
1047
1053
|
return typeField && types.includes(typeField.value);
|
|
1048
1054
|
}
|
|
1049
|
-
function hideDisplayOnly(context,
|
|
1055
|
+
function hideDisplayOnly(context, fieldPath, definition, schemaInterface) {
|
|
1050
1056
|
var _lookupChildControl;
|
|
1051
1057
|
var displayOptions = getDisplayOnlyOptions(definition);
|
|
1052
|
-
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(
|
|
1058
|
+
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(fieldPath.at(-1), (_lookupChildControl = lookupChildControl(context, fieldPath)) == null ? void 0 : _lookupChildControl.value);
|
|
1053
1059
|
}
|
|
1054
|
-
function useJsonataExpression(jExpr, dataContext, bindings) {
|
|
1060
|
+
function useJsonataExpression(jExpr, dataContext, bindings, coerce) {
|
|
1061
|
+
if (coerce === void 0) {
|
|
1062
|
+
coerce = function coerce(x) {
|
|
1063
|
+
return x;
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1055
1066
|
var pathString = jsonPathString(dataContext.path, function (x) {
|
|
1056
1067
|
return "#$i[" + x + "]";
|
|
1057
1068
|
});
|
|
@@ -1087,8 +1098,9 @@ function useJsonataExpression(jExpr, dataContext, bindings) {
|
|
|
1087
1098
|
updateSubscriptions = _ref$current[1];
|
|
1088
1099
|
var _temp = _finallyRethrows(function () {
|
|
1089
1100
|
var bindingData = bindings ? core.collectChanges(collect, bindings) : undefined;
|
|
1090
|
-
|
|
1091
|
-
|
|
1101
|
+
var _coerce = coerce;
|
|
1102
|
+
return Promise.resolve(compiledExpr.evaluate(core.trackedValue(dataContext.data, collect), bindingData)).then(function (_compiledExpr$evaluat) {
|
|
1103
|
+
control.value = _coerce(_compiledExpr$evaluat);
|
|
1092
1104
|
});
|
|
1093
1105
|
}, function (_wasThrown, _result) {
|
|
1094
1106
|
updateSubscriptions();
|
|
@@ -1150,8 +1162,8 @@ function useValidationHook(definition, field) {
|
|
|
1150
1162
|
return control.setError("default", "");
|
|
1151
1163
|
});
|
|
1152
1164
|
core.useValidator(control, function (v) {
|
|
1153
|
-
return !hidden && dd.required &&
|
|
1154
|
-
}, "required");
|
|
1165
|
+
return !hidden && dd.required && field && schemaInterface.isEmptyValue(field, v) ? "Please enter a value" : null;
|
|
1166
|
+
}, "required", undefined, [hidden, dd.required, !!field]);
|
|
1155
1167
|
((_dd$validators = dd.validators) != null ? _dd$validators : []).forEach(function (x, i) {
|
|
1156
1168
|
switch (x.type) {
|
|
1157
1169
|
case exports.ValidatorType.Length:
|
|
@@ -1224,6 +1236,10 @@ function useDateValidator(control, dv, i) {
|
|
|
1224
1236
|
}, "date" + i);
|
|
1225
1237
|
}
|
|
1226
1238
|
|
|
1239
|
+
function cc(n) {
|
|
1240
|
+
return n ? n : undefined;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1227
1243
|
var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
1228
1244
|
function DefaultSchemaInterface() {}
|
|
1229
1245
|
var _proto = DefaultSchemaInterface.prototype;
|
|
@@ -1275,10 +1291,11 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1275
1291
|
var elementIndex = options.elementIndex;
|
|
1276
1292
|
var schemaInterface = (_options$schemaInterf = options.schemaInterface) != null ? _options$schemaInterf : defaultSchemaInterface;
|
|
1277
1293
|
var useExpr = (_options$useEvalExpre = options.useEvalExpressionHook) != null ? _options$useEvalExpre : defaultUseEvalExpressionHook;
|
|
1278
|
-
var
|
|
1294
|
+
var fieldPath = lookupSchemaField(definition, fields);
|
|
1295
|
+
var schemaField = fieldPath == null ? void 0 : fieldPath.at(-1);
|
|
1279
1296
|
var dynamicHooks = useDynamicHooks({
|
|
1280
1297
|
defaultValueControl: useEvalDefaultValueHook(useExpr, definition, schemaField, elementIndex != null),
|
|
1281
|
-
visibleControl: useEvalVisibilityHook(useExpr, definition,
|
|
1298
|
+
visibleControl: useEvalVisibilityHook(useExpr, definition, fieldPath),
|
|
1282
1299
|
readonlyControl: useEvalReadonlyHook(useExpr, definition),
|
|
1283
1300
|
disabledControl: useEvalDisabledHook(useExpr, definition),
|
|
1284
1301
|
allowedOptions: useEvalAllowedOptionsHook(useExpr, definition),
|
|
@@ -1293,7 +1310,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1293
1310
|
options: options,
|
|
1294
1311
|
definition: definition,
|
|
1295
1312
|
fields: fields,
|
|
1296
|
-
|
|
1313
|
+
fieldPath: fieldPath,
|
|
1297
1314
|
elementIndex: elementIndex
|
|
1298
1315
|
});
|
|
1299
1316
|
var Component = React.useCallback(function (_ref) {
|
|
@@ -1307,8 +1324,9 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1307
1324
|
c = _r$current.definition,
|
|
1308
1325
|
_options = _r$current.options,
|
|
1309
1326
|
_fields = _r$current.fields,
|
|
1310
|
-
|
|
1327
|
+
_fieldPath = _r$current.fieldPath,
|
|
1311
1328
|
_elementIndex = _r$current.elementIndex;
|
|
1329
|
+
var _schemaField = _fieldPath == null ? void 0 : _fieldPath.at(-1);
|
|
1312
1330
|
var parentDataContext = {
|
|
1313
1331
|
fields: _fields,
|
|
1314
1332
|
schemaInterface: schemaInterface,
|
|
@@ -1343,12 +1361,12 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1343
1361
|
};
|
|
1344
1362
|
});
|
|
1345
1363
|
});
|
|
1346
|
-
var _getControlData = getControlData(
|
|
1364
|
+
var _getControlData = getControlData(_fieldPath, parentDataContext, _elementIndex),
|
|
1347
1365
|
parentControl = _getControlData[0],
|
|
1348
1366
|
control = _getControlData[1],
|
|
1349
1367
|
controlDataContext = _getControlData[2];
|
|
1350
1368
|
core.useControlEffect(function () {
|
|
1351
|
-
return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl
|
|
1369
|
+
return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl.isNull, _options.hidden];
|
|
1352
1370
|
}, function (_ref2) {
|
|
1353
1371
|
var vc = _ref2[0],
|
|
1354
1372
|
dv = _ref2[1],
|
|
@@ -1365,11 +1383,13 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1365
1383
|
cd.value = dv;
|
|
1366
1384
|
}
|
|
1367
1385
|
}
|
|
1368
|
-
if (parentNull
|
|
1369
|
-
parentControl.
|
|
1386
|
+
if (parentNull) {
|
|
1387
|
+
parentControl.setValue(function (x) {
|
|
1388
|
+
return x != null ? x : {};
|
|
1389
|
+
});
|
|
1370
1390
|
}
|
|
1371
1391
|
}, true);
|
|
1372
|
-
var myOptions = useCalculatedControl(function () {
|
|
1392
|
+
var myOptions = core.useCalculatedControl(function () {
|
|
1373
1393
|
var _visibility$fields;
|
|
1374
1394
|
return {
|
|
1375
1395
|
hidden: _options.hidden || !((_visibility$fields = visibility.fields) != null && _visibility$fields.showing.value),
|
|
@@ -1384,7 +1404,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1384
1404
|
React.useEffect(function () {
|
|
1385
1405
|
if (control && typeof myOptions.disabled === "boolean") control.disabled = myOptions.disabled;
|
|
1386
1406
|
}, [control, myOptions.disabled]);
|
|
1387
|
-
if (parentControl
|
|
1407
|
+
if (parentControl.isNull) return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
1388
1408
|
var adornments = (_definition$adornment = (_definition$adornment2 = definition.adornments) == null ? void 0 : _definition$adornment2.map(function (x) {
|
|
1389
1409
|
return renderer.renderAdornment({
|
|
1390
1410
|
adornment: x
|
|
@@ -1443,20 +1463,46 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1443
1463
|
}
|
|
1444
1464
|
function lookupSchemaField(c, fields) {
|
|
1445
1465
|
var fieldName = isGroupControlsDefinition(c) ? c.compoundField : isDataControlDefinition(c) ? c.field : undefined;
|
|
1446
|
-
return fieldName ?
|
|
1466
|
+
return fieldName ? findFieldPath(fields, fieldName) : undefined;
|
|
1447
1467
|
}
|
|
1448
|
-
function getControlData(
|
|
1449
|
-
var _parentControl$fields, _childControl$element;
|
|
1468
|
+
function getControlData(fieldPath, parentContext, elementIndex) {
|
|
1469
|
+
var _fieldPath$slice$map, _parentControl$fields, _childControl$element;
|
|
1450
1470
|
var data = parentContext.data,
|
|
1451
|
-
|
|
1452
|
-
var
|
|
1471
|
+
pp = parentContext.path;
|
|
1472
|
+
var extraPath = (_fieldPath$slice$map = fieldPath == null ? void 0 : fieldPath.slice(0, -1).map(function (x) {
|
|
1473
|
+
return x.field;
|
|
1474
|
+
})) != null ? _fieldPath$slice$map : [];
|
|
1475
|
+
var path = [].concat(pp, extraPath);
|
|
1476
|
+
var schemaField = fieldPath == null ? void 0 : fieldPath.at(-1);
|
|
1477
|
+
var _lookupControl = lookupControl(data, path),
|
|
1478
|
+
parentControl = _lookupControl[0],
|
|
1479
|
+
found = _lookupControl[1];
|
|
1453
1480
|
var childPath = schemaField ? elementIndex != null ? [].concat(path, [schemaField.field, elementIndex]) : [].concat(path, [schemaField.field]) : path;
|
|
1454
|
-
var childControl = schemaField &&
|
|
1481
|
+
var childControl = schemaField && found ? (_parentControl$fields = parentControl.fields) == null ? void 0 : _parentControl$fields[schemaField.field] : undefined;
|
|
1455
1482
|
return [parentControl, childControl && elementIndex != null ? (_childControl$element = childControl.elements) == null ? void 0 : _childControl$element[elementIndex] : childControl, schemaField ? _extends({}, parentContext, {
|
|
1456
1483
|
path: childPath,
|
|
1457
1484
|
fields: isCompoundField(schemaField) ? schemaField.children : parentContext.fields
|
|
1458
1485
|
}) : parentContext];
|
|
1459
1486
|
}
|
|
1487
|
+
function lookupControl(control, path) {
|
|
1488
|
+
var _base;
|
|
1489
|
+
var base = control;
|
|
1490
|
+
var index = 0;
|
|
1491
|
+
while (index < path.length && base) {
|
|
1492
|
+
control = base;
|
|
1493
|
+
var childId = path[index];
|
|
1494
|
+
var c = base.current;
|
|
1495
|
+
if (typeof childId === "string") {
|
|
1496
|
+
var _c$fields;
|
|
1497
|
+
base = (_c$fields = c.fields) == null ? void 0 : _c$fields[childId];
|
|
1498
|
+
} else {
|
|
1499
|
+
var _c$elements;
|
|
1500
|
+
base = (_c$elements = c.elements) == null ? void 0 : _c$elements[childId];
|
|
1501
|
+
}
|
|
1502
|
+
index++;
|
|
1503
|
+
}
|
|
1504
|
+
return [(_base = base) != null ? _base : control, !!base];
|
|
1505
|
+
}
|
|
1460
1506
|
function ControlRenderer(_ref3) {
|
|
1461
1507
|
var _effect = core.useComponentTracking();
|
|
1462
1508
|
try {
|
|
@@ -2743,6 +2789,7 @@ exports.findCompoundField = findCompoundField;
|
|
|
2743
2789
|
exports.findCompoundGroups = findCompoundGroups;
|
|
2744
2790
|
exports.findControlsForCompound = findControlsForCompound;
|
|
2745
2791
|
exports.findField = findField;
|
|
2792
|
+
exports.findFieldPath = findFieldPath;
|
|
2746
2793
|
exports.findNonDataGroups = findNonDataGroups;
|
|
2747
2794
|
exports.findScalarField = findScalarField;
|
|
2748
2795
|
exports.getAllReferencedClasses = getAllReferencedClasses;
|
|
@@ -2774,6 +2821,7 @@ exports.jsonPathString = jsonPathString;
|
|
|
2774
2821
|
exports.jsonataExpr = jsonataExpr;
|
|
2775
2822
|
exports.layoutKeyForPlacement = layoutKeyForPlacement;
|
|
2776
2823
|
exports.lookupChildControl = lookupChildControl;
|
|
2824
|
+
exports.lookupChildControlPath = lookupChildControlPath;
|
|
2777
2825
|
exports.lookupSchemaField = lookupSchemaField;
|
|
2778
2826
|
exports.makeCompoundField = makeCompoundField;
|
|
2779
2827
|
exports.makeEvalExpressionHook = makeEvalExpressionHook;
|
|
@@ -2799,6 +2847,7 @@ exports.useEvalAllowedOptionsHook = useEvalAllowedOptionsHook;
|
|
|
2799
2847
|
exports.useEvalDefaultValueHook = useEvalDefaultValueHook;
|
|
2800
2848
|
exports.useEvalDisabledHook = useEvalDisabledHook;
|
|
2801
2849
|
exports.useEvalDisplayHook = useEvalDisplayHook;
|
|
2850
|
+
exports.useEvalDynamicBoolHook = useEvalDynamicBoolHook;
|
|
2802
2851
|
exports.useEvalDynamicHook = useEvalDynamicHook;
|
|
2803
2852
|
exports.useEvalLabelText = useEvalLabelText;
|
|
2804
2853
|
exports.useEvalReadonlyHook = useEvalReadonlyHook;
|
|
@@ -2810,6 +2859,7 @@ exports.useValidationHook = useValidationHook;
|
|
|
2810
2859
|
exports.visitControlData = visitControlData;
|
|
2811
2860
|
exports.visitControlDataArray = visitControlDataArray;
|
|
2812
2861
|
exports.visitControlDefinition = visitControlDefinition;
|
|
2862
|
+
exports.watchControlLookup = watchControlLookup;
|
|
2813
2863
|
exports.withScalarOptions = withScalarOptions;
|
|
2814
2864
|
exports.wrapMarkup = wrapMarkup;
|
|
2815
2865
|
exports.wrapMarkupAt = wrapMarkupAt;
|