@react-typed-forms/schemas 7.0.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 +5 -2
- package/lib/hooks.d.ts +2 -1
- package/lib/index.js +48 -25
- package/lib/index.js.map +1 -1
- package/lib/schemaBuilder.d.ts +1 -1
- package/lib/types.d.ts +2 -1
- package/lib/util.d.ts +1 -0
- package/package.json +48 -48
- package/src/controlRender.tsx +23 -4
- package/src/hooks.tsx +24 -4
- package/src/schemaBuilder.ts +20 -20
- package/src/types.ts +1 -0
- package/src/util.ts +2 -1
- package/src/validators.ts +5 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -132,6 +132,7 @@ export interface DataControlProps {
|
|
|
132
132
|
style: React.CSSProperties | undefined;
|
|
133
133
|
childCount: number;
|
|
134
134
|
renderChild: ChildRenderer;
|
|
135
|
+
allowedOptions?: Control<any[] | undefined>;
|
|
135
136
|
elementRenderer?: (elemProps: Control<any>) => ReactNode;
|
|
136
137
|
}
|
|
137
138
|
export type CreateDataProps = (controlProps: DataControlProps) => DataRendererProps;
|
|
@@ -140,11 +141,12 @@ export interface ControlRenderOptions extends FormContextOptions {
|
|
|
140
141
|
useEvalExpressionHook?: UseEvalExpressionHook;
|
|
141
142
|
clearHidden?: boolean;
|
|
142
143
|
schemaInterface?: SchemaInterface;
|
|
144
|
+
dataRoot?: Control<any>;
|
|
143
145
|
}
|
|
144
146
|
export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
|
|
145
147
|
export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField | undefined;
|
|
146
148
|
export declare function getControlData(schemaField: SchemaField | undefined, parentContext: ControlDataContext): [Control<any> | undefined, ControlDataContext];
|
|
147
|
-
export declare function defaultDataProps({ definition, field, control, options, elementRenderer, style, ...props }: DataControlProps): DataRendererProps;
|
|
149
|
+
export declare function defaultDataProps({ definition, field, control, options, elementRenderer, style, allowedOptions, ...props }: DataControlProps): DataRendererProps;
|
|
148
150
|
export declare function defaultArrayProps(arrayControl: Control<any[] | undefined | null>, field: SchemaField, required: boolean, style: CSSProperties | undefined, className: string | undefined, renderElement: (elemProps: Control<any>) => ReactNode): ArrayRendererProps;
|
|
149
151
|
export type ChildRenderer = (k: Key, childIndex: number, props: ControlRenderProps) => ReactNode;
|
|
150
152
|
export interface RenderControlProps {
|
|
@@ -159,8 +161,9 @@ export interface RenderControlProps {
|
|
|
159
161
|
schemaField?: SchemaField;
|
|
160
162
|
displayControl?: Control<string | undefined>;
|
|
161
163
|
style?: React.CSSProperties;
|
|
164
|
+
allowedOptions?: Control<any[] | undefined>;
|
|
162
165
|
}
|
|
163
|
-
export declare function renderControlLayout({ definition: c, renderer, childCount, renderChild: childRenderer, control: childControl, schemaField, dataContext, formOptions: dataOptions, createDataProps: dataProps, displayControl, style, }: RenderControlProps): ControlLayoutProps;
|
|
166
|
+
export declare function renderControlLayout({ definition: c, renderer, childCount, renderChild: childRenderer, control: childControl, schemaField, dataContext, formOptions: dataOptions, createDataProps: dataProps, displayControl, style, allowedOptions, }: RenderControlProps): ControlLayoutProps;
|
|
164
167
|
export declare function appendMarkup(k: keyof Omit<RenderedLayout, "errorControl" | "style" | "className">, markup: ReactNode): (layout: RenderedLayout) => void;
|
|
165
168
|
export declare function wrapMarkup(k: keyof Omit<RenderedLayout, "errorControl" | "style" | "className">, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
|
|
166
169
|
export declare function layoutKeyForPlacement(pos: AdornmentPlacement): keyof Omit<RenderedLayout, "errorControl" | "style" | "className">;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type UseEvalExpressionHook = (expr: EntityExpression | undefined) => Eval
|
|
|
6
6
|
export declare function useEvalVisibilityHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition, schemaField?: SchemaField): EvalExpressionHook<boolean>;
|
|
7
7
|
export declare function useEvalReadonlyHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<boolean>;
|
|
8
8
|
export declare function useEvalStyleHook(useEvalExpressionHook: UseEvalExpressionHook, property: DynamicPropertyType, definition: ControlDefinition): EvalExpressionHook<React.CSSProperties>;
|
|
9
|
+
export declare function useEvalAllowedOptionsHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<any[]>;
|
|
9
10
|
export declare function useEvalDisabledHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): EvalExpressionHook<boolean>;
|
|
10
11
|
export declare function useEvalDisplayHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition): (groupContext: ControlDataContext) => Control<string | undefined> | undefined;
|
|
11
12
|
export declare function useEvalDefaultValueHook(useEvalExpressionHook: UseEvalExpressionHook, definition: ControlDefinition, schemaField?: SchemaField): EvalExpressionHook;
|
|
@@ -16,4 +17,4 @@ export declare function makeEvalExpressionHook(f: (expr: EntityExpression, conte
|
|
|
16
17
|
export declare function useEvalDynamicHook(definition: ControlDefinition, type: DynamicPropertyType, useEvalExpressionHook: (expr: EntityExpression | undefined) => EvalExpressionHook | undefined): EvalExpressionHook | undefined;
|
|
17
18
|
export declare function matchesType(context: ControlDataContext, types?: string[] | null): boolean | undefined;
|
|
18
19
|
export declare function hideDisplayOnly(context: ControlDataContext, field: SchemaField, definition: ControlDefinition, schemaInterface: SchemaInterface): boolean | undefined;
|
|
19
|
-
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
|
@@ -39,6 +39,7 @@ exports.DynamicPropertyType = void 0;
|
|
|
39
39
|
DynamicPropertyType["Display"] = "Display";
|
|
40
40
|
DynamicPropertyType["Style"] = "Style";
|
|
41
41
|
DynamicPropertyType["LayoutStyle"] = "LayoutStyle";
|
|
42
|
+
DynamicPropertyType["AllowedOptions"] = "AllowedOptions";
|
|
42
43
|
})(exports.DynamicPropertyType || (exports.DynamicPropertyType = {}));
|
|
43
44
|
exports.ExpressionType = void 0;
|
|
44
45
|
(function (ExpressionType) {
|
|
@@ -478,11 +479,10 @@ function visitControlData(definition, ctx, cb) {
|
|
|
478
479
|
var elemResult = def ? cb(def, fieldData, c, true) : undefined;
|
|
479
480
|
if (elemResult !== undefined) return elemResult;
|
|
480
481
|
if (isCompoundField(fieldData)) {
|
|
481
|
-
var cfResult = visitControlDataArray(children, {
|
|
482
|
+
var cfResult = visitControlDataArray(children, _extends({}, ctx, {
|
|
482
483
|
fields: fieldData.children,
|
|
483
|
-
groupControl: c
|
|
484
|
-
|
|
485
|
-
}, cb);
|
|
484
|
+
groupControl: c
|
|
485
|
+
}), cb);
|
|
486
486
|
if (cfResult !== undefined) return cfResult;
|
|
487
487
|
}
|
|
488
488
|
}
|
|
@@ -527,7 +527,6 @@ function cleanDataForSchema(v, fields) {
|
|
|
527
527
|
;
|
|
528
528
|
}
|
|
529
529
|
});
|
|
530
|
-
|
|
531
530
|
return out;
|
|
532
531
|
}
|
|
533
532
|
function getAllReferencedClasses(c) {
|
|
@@ -695,6 +694,13 @@ function useEvalStyleHook(useEvalExpressionHook, property, definition) {
|
|
|
695
694
|
return core.useControl(undefined);
|
|
696
695
|
}, [dynamicStyle]);
|
|
697
696
|
}
|
|
697
|
+
function useEvalAllowedOptionsHook(useEvalExpressionHook, definition) {
|
|
698
|
+
var dynamicAllowed = useEvalDynamicHook(definition, exports.DynamicPropertyType.AllowedOptions, useEvalExpressionHook);
|
|
699
|
+
return React.useCallback(function (ctx) {
|
|
700
|
+
if (dynamicAllowed) return dynamicAllowed(ctx);
|
|
701
|
+
return core.useControl([]);
|
|
702
|
+
}, [dynamicAllowed]);
|
|
703
|
+
}
|
|
698
704
|
function useEvalDisabledHook(useEvalExpressionHook, definition) {
|
|
699
705
|
var dynamicDisabled = useEvalDynamicHook(definition, exports.DynamicPropertyType.Disabled, useEvalExpressionHook);
|
|
700
706
|
return React.useCallback(function (ctx) {
|
|
@@ -746,7 +752,7 @@ function useDataMatchExpression(fvExpr, fields, data) {
|
|
|
746
752
|
function defaultEvalHooks(expr, context) {
|
|
747
753
|
switch (expr.type) {
|
|
748
754
|
case exports.ExpressionType.Jsonata:
|
|
749
|
-
return useJsonataExpression(expr.expression, context.groupControl);
|
|
755
|
+
return useJsonataExpression(expr.expression, context.groupControl, context.root);
|
|
750
756
|
case exports.ExpressionType.Data:
|
|
751
757
|
return useDataExpression(expr, context.fields, context.groupControl);
|
|
752
758
|
case exports.ExpressionType.DataMatch:
|
|
@@ -782,21 +788,25 @@ function hideDisplayOnly(context, field, definition, schemaInterface) {
|
|
|
782
788
|
var displayOptions = getDisplayOnlyOptions(definition);
|
|
783
789
|
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(field, context.groupControl.fields[field.field].value);
|
|
784
790
|
}
|
|
785
|
-
function useJsonataExpression(jExpr, data) {
|
|
791
|
+
function useJsonataExpression(jExpr, data, root) {
|
|
786
792
|
var compiledExpr = React.useMemo(function () {
|
|
787
793
|
try {
|
|
788
794
|
return jsonata__default["default"](jExpr);
|
|
789
795
|
} catch (e) {
|
|
790
796
|
console.error(e);
|
|
791
|
-
return jsonata__default["default"]("");
|
|
797
|
+
return jsonata__default["default"]("null");
|
|
792
798
|
}
|
|
793
799
|
}, [jExpr]);
|
|
794
800
|
var control = core.useControl();
|
|
795
801
|
core.useControlEffect(function () {
|
|
796
|
-
return data.value;
|
|
797
|
-
}, function (
|
|
802
|
+
return [data.value, root.value];
|
|
803
|
+
}, function (_ref2) {
|
|
804
|
+
var v = _ref2[0],
|
|
805
|
+
rv = _ref2[1];
|
|
798
806
|
try {
|
|
799
|
-
return Promise.resolve(compiledExpr.evaluate(v
|
|
807
|
+
return Promise.resolve(compiledExpr.evaluate(v, {
|
|
808
|
+
root: rv
|
|
809
|
+
})).then(function (_compiledExpr$evaluat) {
|
|
800
810
|
control.value = _compiledExpr$evaluat;
|
|
801
811
|
});
|
|
802
812
|
} catch (e) {
|
|
@@ -833,7 +843,7 @@ function useValidationHook(definition) {
|
|
|
833
843
|
}, validatorTypes ? validatorTypes : [null]);
|
|
834
844
|
}
|
|
835
845
|
function useJsonataValidator(control, context, expr, hidden, i) {
|
|
836
|
-
var errorMsg = useJsonataExpression(expr.expression, context.groupControl);
|
|
846
|
+
var errorMsg = useJsonataExpression(expr.expression, context.groupControl, context.root);
|
|
837
847
|
core.useControlEffect(function () {
|
|
838
848
|
return [hidden, errorMsg.value];
|
|
839
849
|
}, function (_ref) {
|
|
@@ -889,7 +899,7 @@ function defaultTextValue(f, value) {
|
|
|
889
899
|
}
|
|
890
900
|
}
|
|
891
901
|
|
|
892
|
-
var _excluded$1 = ["definition", "field", "control", "options", "elementRenderer", "style"];
|
|
902
|
+
var _excluded$1 = ["definition", "field", "control", "options", "elementRenderer", "style", "allowedOptions"];
|
|
893
903
|
var AppendAdornmentPriority = 0;
|
|
894
904
|
var WrapAdornmentPriority = 1000;
|
|
895
905
|
exports.LabelType = void 0;
|
|
@@ -910,6 +920,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
910
920
|
var useIsVisible = useEvalVisibilityHook(useExpr, definition, schemaField);
|
|
911
921
|
var useIsReadonly = useEvalReadonlyHook(useExpr, definition);
|
|
912
922
|
var useIsDisabled = useEvalDisabledHook(useExpr, definition);
|
|
923
|
+
var useAllowedOptions = useEvalAllowedOptionsHook(useExpr, definition);
|
|
913
924
|
var useCustomStyle = useEvalStyleHook(useExpr, exports.DynamicPropertyType.Style, definition);
|
|
914
925
|
var useLayoutStyle = useEvalStyleHook(useExpr, exports.DynamicPropertyType.LayoutStyle, definition);
|
|
915
926
|
var useDynamicDisplay = useEvalDisplayHook(useExpr, definition);
|
|
@@ -924,7 +935,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
924
935
|
var parentControl = _ref.control;
|
|
925
936
|
var stopTracking = core.useComponentTracking();
|
|
926
937
|
try {
|
|
927
|
-
var _c$children$map, _c$children, _definition$adornment, _definition$adornment2;
|
|
938
|
+
var _options$dataRoot, _c$children$map, _c$children, _definition$adornment, _definition$adornment2;
|
|
928
939
|
var _r$current = r.current,
|
|
929
940
|
c = _r$current.definition,
|
|
930
941
|
_options = _r$current.options,
|
|
@@ -933,7 +944,8 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
933
944
|
var dataContext = {
|
|
934
945
|
groupControl: parentControl,
|
|
935
946
|
fields: _fields,
|
|
936
|
-
schemaInterface: schemaInterface
|
|
947
|
+
schemaInterface: schemaInterface,
|
|
948
|
+
root: (_options$dataRoot = _options.dataRoot) != null ? _options$dataRoot : parentControl
|
|
937
949
|
};
|
|
938
950
|
var readonlyControl = useIsReadonly(dataContext);
|
|
939
951
|
var disabledControl = useIsDisabled(dataContext);
|
|
@@ -958,6 +970,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
958
970
|
};
|
|
959
971
|
});
|
|
960
972
|
});
|
|
973
|
+
var allowedOptions = useAllowedOptions(dataContext);
|
|
961
974
|
var defaultValueControl = useDefaultValue(dataContext);
|
|
962
975
|
var _getControlData = getControlData(_schemaField, dataContext),
|
|
963
976
|
control = _getControlData[0],
|
|
@@ -991,7 +1004,9 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
991
1004
|
}).value;
|
|
992
1005
|
useValidation(control, !!myOptions.hidden, dataContext);
|
|
993
1006
|
var childRenderers = (_c$children$map = (_c$children = c.children) == null ? void 0 : _c$children.map(function (cd) {
|
|
994
|
-
return useControlRenderer(cd, childContext.fields, renderer, _extends({}, _options, myOptions
|
|
1007
|
+
return useControlRenderer(cd, childContext.fields, renderer, _extends({}, _options, myOptions, {
|
|
1008
|
+
dataRoot: dataContext.root
|
|
1009
|
+
}));
|
|
995
1010
|
})) != null ? _c$children$map : [];
|
|
996
1011
|
React.useEffect(function () {
|
|
997
1012
|
if (control && typeof myOptions.disabled === "boolean") control.disabled = myOptions.disabled;
|
|
@@ -1018,7 +1033,8 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1018
1033
|
control: displayControl != null ? displayControl : control,
|
|
1019
1034
|
schemaField: _schemaField,
|
|
1020
1035
|
displayControl: displayControl,
|
|
1021
|
-
style: customStyle
|
|
1036
|
+
style: customStyle,
|
|
1037
|
+
allowedOptions: allowedOptions
|
|
1022
1038
|
});
|
|
1023
1039
|
var renderedControl = renderer.renderLayout(_extends({}, labelAndChildren, {
|
|
1024
1040
|
adornments: adornments,
|
|
@@ -1031,7 +1047,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1031
1047
|
} finally {
|
|
1032
1048
|
stopTracking();
|
|
1033
1049
|
}
|
|
1034
|
-
}, [r, dataProps, useIsVisible, useDefaultValue, useIsReadonly, useIsDisabled, useCustomStyle, useLayoutStyle, useDynamicDisplay, useValidation, renderer, schemaInterface]);
|
|
1050
|
+
}, [r, dataProps, useIsVisible, useDefaultValue, useIsReadonly, useIsDisabled, useCustomStyle, useLayoutStyle, useAllowedOptions, useDynamicDisplay, useValidation, renderer, schemaInterface]);
|
|
1035
1051
|
Component.displayName = "RenderControl";
|
|
1036
1052
|
return Component;
|
|
1037
1053
|
}
|
|
@@ -1042,11 +1058,10 @@ function lookupSchemaField(c, fields) {
|
|
|
1042
1058
|
function getControlData(schemaField, parentContext) {
|
|
1043
1059
|
var _parentContext$groupC, _parentContext$groupC2;
|
|
1044
1060
|
var childControl = schemaField ? (_parentContext$groupC = (_parentContext$groupC2 = parentContext.groupControl.fields) == null ? void 0 : _parentContext$groupC2[schemaField.field]) != null ? _parentContext$groupC : core.newControl({}) : undefined;
|
|
1045
|
-
return [childControl, schemaField && isCompoundField(schemaField) ? {
|
|
1061
|
+
return [childControl, schemaField && isCompoundField(schemaField) ? _extends({}, parentContext, {
|
|
1046
1062
|
groupControl: childControl,
|
|
1047
|
-
fields: schemaField.children
|
|
1048
|
-
|
|
1049
|
-
} : parentContext];
|
|
1063
|
+
fields: schemaField.children
|
|
1064
|
+
}) : parentContext];
|
|
1050
1065
|
}
|
|
1051
1066
|
function groupProps(renderOptions, childCount, _renderChild, control, className, style) {
|
|
1052
1067
|
if (renderOptions === void 0) {
|
|
@@ -1067,21 +1082,26 @@ function groupProps(renderOptions, childCount, _renderChild, control, className,
|
|
|
1067
1082
|
};
|
|
1068
1083
|
}
|
|
1069
1084
|
function defaultDataProps(_ref3) {
|
|
1070
|
-
var _field$options$length, _field$options, _definition$renderOpt;
|
|
1085
|
+
var _field$options$length, _field$options, _allowedOptions$value, _definition$renderOpt;
|
|
1071
1086
|
var definition = _ref3.definition,
|
|
1072
1087
|
field = _ref3.field,
|
|
1073
1088
|
control = _ref3.control,
|
|
1074
1089
|
options = _ref3.options,
|
|
1075
1090
|
elementRenderer = _ref3.elementRenderer,
|
|
1076
1091
|
style = _ref3.style,
|
|
1092
|
+
allowedOptions = _ref3.allowedOptions,
|
|
1077
1093
|
props = _objectWithoutPropertiesLoose(_ref3, _excluded$1);
|
|
1078
1094
|
var className = cc(definition.styleClass);
|
|
1079
1095
|
var required = !!definition.required;
|
|
1096
|
+
var fieldOptions = ((_field$options$length = (_field$options = field.options) == null ? void 0 : _field$options.length) != null ? _field$options$length : 0) === 0 ? null : field.options;
|
|
1097
|
+
var allowed = (_allowedOptions$value = allowedOptions == null ? void 0 : allowedOptions.value) != null ? _allowedOptions$value : [];
|
|
1080
1098
|
return _extends({
|
|
1081
1099
|
control: control,
|
|
1082
1100
|
field: field,
|
|
1083
1101
|
id: "c" + control.uniqueId,
|
|
1084
|
-
options:
|
|
1102
|
+
options: fieldOptions && allowed.length > 0 ? fieldOptions.filter(function (x) {
|
|
1103
|
+
return allowed.includes(x.value);
|
|
1104
|
+
}) : fieldOptions,
|
|
1085
1105
|
readonly: !!options.readonly,
|
|
1086
1106
|
renderOptions: (_definition$renderOpt = definition.renderOptions) != null ? _definition$renderOpt : {
|
|
1087
1107
|
type: "Standard"
|
|
@@ -1141,7 +1161,8 @@ function renderControlLayout(_ref4) {
|
|
|
1141
1161
|
dataOptions = _ref4.formOptions,
|
|
1142
1162
|
dataProps = _ref4.createDataProps,
|
|
1143
1163
|
displayControl = _ref4.displayControl,
|
|
1144
|
-
style = _ref4.style
|
|
1164
|
+
style = _ref4.style,
|
|
1165
|
+
allowedOptions = _ref4.allowedOptions;
|
|
1145
1166
|
if (isDataControlDefinition(c)) {
|
|
1146
1167
|
return renderData(c);
|
|
1147
1168
|
}
|
|
@@ -1199,6 +1220,7 @@ function renderControlLayout(_ref4) {
|
|
|
1199
1220
|
options: dataOptions,
|
|
1200
1221
|
style: style,
|
|
1201
1222
|
childCount: childCount,
|
|
1223
|
+
allowedOptions: allowedOptions,
|
|
1202
1224
|
renderChild: childRenderer,
|
|
1203
1225
|
elementRenderer: elementControl == null && schemaField.collection ? function (element) {
|
|
1204
1226
|
return renderLayoutParts(renderData(c, element), renderer).children;
|
|
@@ -2143,6 +2165,7 @@ exports.stringOptionsField = stringOptionsField;
|
|
|
2143
2165
|
exports.textDisplayControl = textDisplayControl;
|
|
2144
2166
|
exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
|
|
2145
2167
|
exports.useControlRenderer = useControlRenderer;
|
|
2168
|
+
exports.useEvalAllowedOptionsHook = useEvalAllowedOptionsHook;
|
|
2146
2169
|
exports.useEvalDefaultValueHook = useEvalDefaultValueHook;
|
|
2147
2170
|
exports.useEvalDisabledHook = useEvalDisabledHook;
|
|
2148
2171
|
exports.useEvalDisplayHook = useEvalDisplayHook;
|