@react-typed-forms/schemas 16.2.2 → 17.0.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/FORM_EXTENSIONS_GUIDE.md +781 -0
- package/lib/RenderForm.d.ts +22 -5
- package/lib/controlBuilder.d.ts +4 -47
- package/lib/controlRender.d.ts +49 -24
- package/lib/index.cjs +310 -332
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +270 -272
- package/lib/index.js.map +1 -1
- package/lib/renderer/elementSelected.d.ts +8 -0
- package/lib/renderers.d.ts +6 -2
- package/lib/types.d.ts +10 -5
- package/lib/util.d.ts +3 -2
- package/package.json +5 -5
- package/src/RenderForm.tsx +130 -64
- package/src/controlBuilder.ts +6 -193
- package/src/controlRender.tsx +127 -81
- package/src/createFormRenderer.tsx +52 -19
- package/src/index.ts +1 -0
- package/src/renderer/elementSelected.ts +48 -0
- package/src/renderers.tsx +8 -1
- package/src/types.ts +15 -5
- package/src/util.ts +13 -1
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { isCompoundField, findField, getTagParam, SchemaTags, ControlDefinitionType, isScalarField, DataRenderType, isDataControl, isGroupControl, createSchemaTree, relativePath, isCompoundNode, fieldPathForDefinition, schemaForFieldPath, isCheckEntryClasses, isGridRenderer, isAutoCompleteClasses, getGroupRendererOptions,
|
|
1
|
+
import { isCompoundField, findField, getTagParam, SchemaTags, ControlDefinitionType, isScalarField, DataRenderType, isDataControl, isGroupControl, createSchemaTree, relativePath, isCompoundNode, fieldPathForDefinition, schemaForFieldPath, isCheckEntryClasses, isGridRenderer, isAutoCompleteClasses, getGroupRendererOptions, emptyGroupDefinition, mergeOption, mergeFields, resolveSchemas, dataControl, isActionControl, ActionStyle, isDisplayControl, DisplayDataType, AdornmentPlacement, ValidatorType, lookupDataNode, defaultSchemaInterface, ControlDisableType, ControlAdornmentType, defaultResolveChildNodes, defaultEvaluators, createFormStateNode, legacyFormNode, createSchemaDataNode } from '@astroapps/forms-core';
|
|
2
2
|
export * from '@astroapps/forms-core';
|
|
3
|
-
import { useRef, useMemo,
|
|
3
|
+
import { useRef, useMemo, useEffect, useCallback } from 'react';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
|
-
import { getElementIndex, ensureMetaValue, newControl, ControlChange, useControl, createScopedEffect, removeElement,
|
|
6
|
-
import {
|
|
5
|
+
import { getElementIndex, ensureMetaValue, newControl, ControlChange, useControl, createScopedEffect, removeElement, addElement, useComponentTracking, useComputed, useControlEffect } from '@react-typed-forms/core';
|
|
6
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
7
7
|
|
|
8
8
|
function _extends() {
|
|
9
9
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
@@ -18,7 +18,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
18
18
|
if (null == r) return {};
|
|
19
19
|
var t = {};
|
|
20
20
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
21
|
-
if (e.
|
|
21
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
22
22
|
t[n] = r[n];
|
|
23
23
|
}
|
|
24
24
|
return t;
|
|
@@ -726,131 +726,17 @@ function useExpression(defaultValue, runExpression, expression, coerce, bindings
|
|
|
726
726
|
}, value);
|
|
727
727
|
return value;
|
|
728
728
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
return o => _extends({
|
|
739
|
-
type
|
|
740
|
-
}, o);
|
|
741
|
-
}
|
|
742
|
-
function adornmentOptions(type) {
|
|
743
|
-
return o => _extends({
|
|
744
|
-
type
|
|
745
|
-
}, o);
|
|
746
|
-
}
|
|
747
|
-
function renderOptionsFor(type) {
|
|
748
|
-
return o => ({
|
|
749
|
-
renderOptions: _extends({
|
|
750
|
-
type
|
|
751
|
-
}, o)
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
const autocompleteOptions = renderOptionsFor(DataRenderType.Autocomplete);
|
|
755
|
-
const checkListOptions = renderOptionsFor(DataRenderType.CheckList);
|
|
756
|
-
const radioButtonOptions = renderOptionsFor(DataRenderType.Radio);
|
|
757
|
-
const lengthValidatorOptions = validatorOptions(ValidatorType.Length);
|
|
758
|
-
const jsonataValidatorOptions = validatorOptions(ValidatorType.Jsonata);
|
|
759
|
-
const dateValidatorOptions = validatorOptions(ValidatorType.Date);
|
|
760
|
-
const accordionOptions = adornmentOptions(ControlAdornmentType.Accordion);
|
|
761
|
-
const textfieldOptions = renderOptionsFor(DataRenderType.Textfield);
|
|
762
|
-
const displayOnlyOptions = renderOptionsFor(DataRenderType.DisplayOnly);
|
|
763
|
-
const jsonataOptions = renderOptionsFor(DataRenderType.Jsonata);
|
|
764
|
-
function textDisplayControl(text, options) {
|
|
765
|
-
return _extends({
|
|
766
|
-
type: ControlDefinitionType.Display,
|
|
767
|
-
displayData: {
|
|
768
|
-
type: DisplayDataType.Text,
|
|
769
|
-
text
|
|
770
|
-
}
|
|
771
|
-
}, options);
|
|
772
|
-
}
|
|
773
|
-
function htmlDisplayControl(html, options) {
|
|
774
|
-
return _extends({
|
|
775
|
-
type: ControlDefinitionType.Display,
|
|
776
|
-
displayData: {
|
|
777
|
-
type: DisplayDataType.Html,
|
|
778
|
-
html
|
|
779
|
-
}
|
|
780
|
-
}, options);
|
|
781
|
-
}
|
|
782
|
-
function dynamicDefaultValue(expr) {
|
|
783
|
-
return {
|
|
784
|
-
type: DynamicPropertyType.DefaultValue,
|
|
785
|
-
expr
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
function dynamicReadonly(expr) {
|
|
789
|
-
return {
|
|
790
|
-
type: DynamicPropertyType.Readonly,
|
|
791
|
-
expr
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function dynamicVisibility(expr) {
|
|
795
|
-
return {
|
|
796
|
-
type: DynamicPropertyType.Visible,
|
|
797
|
-
expr
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
function dynamicDisabled(expr) {
|
|
801
|
-
return {
|
|
802
|
-
type: DynamicPropertyType.Disabled,
|
|
803
|
-
expr
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
function fieldExpr(field) {
|
|
807
|
-
return {
|
|
808
|
-
type: ExpressionType.Data,
|
|
809
|
-
field
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
function fieldEqExpr(field, value) {
|
|
813
|
-
return {
|
|
814
|
-
type: ExpressionType.DataMatch,
|
|
815
|
-
field,
|
|
816
|
-
value
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
function jsonataExpr(expression) {
|
|
820
|
-
return {
|
|
821
|
-
type: ExpressionType.Jsonata,
|
|
822
|
-
expression
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
function groupedControl(children, title, options) {
|
|
826
|
-
return _extends({
|
|
827
|
-
type: ControlDefinitionType.Group,
|
|
828
|
-
children,
|
|
829
|
-
title,
|
|
830
|
-
groupOptions: {
|
|
831
|
-
type: "Standard",
|
|
832
|
-
hideTitle: !title
|
|
833
|
-
}
|
|
834
|
-
}, options);
|
|
835
|
-
}
|
|
836
|
-
function compoundControl(field, title, children, options) {
|
|
837
|
-
return _extends({
|
|
838
|
-
type: ControlDefinitionType.Data,
|
|
839
|
-
field,
|
|
840
|
-
children,
|
|
841
|
-
title,
|
|
842
|
-
renderOptions: {
|
|
843
|
-
type: "Standard"
|
|
844
|
-
}
|
|
845
|
-
}, options);
|
|
846
|
-
}
|
|
847
|
-
function actionControl(actionText, actionId, options) {
|
|
848
|
-
return _extends({
|
|
849
|
-
type: ControlDefinitionType.Action,
|
|
850
|
-
title: actionText,
|
|
851
|
-
actionId
|
|
852
|
-
}, options);
|
|
729
|
+
function setIncluded(array, elem, included) {
|
|
730
|
+
const already = array.includes(elem);
|
|
731
|
+
if (included === already) {
|
|
732
|
+
return array;
|
|
733
|
+
}
|
|
734
|
+
if (included) {
|
|
735
|
+
return [...array, elem];
|
|
736
|
+
}
|
|
737
|
+
return array.filter(e => e !== elem);
|
|
853
738
|
}
|
|
739
|
+
|
|
854
740
|
function createAction(actionId, onClick, actionText, options) {
|
|
855
741
|
return _extends({
|
|
856
742
|
actionId,
|
|
@@ -858,14 +744,6 @@ function createAction(actionId, onClick, actionText, options) {
|
|
|
858
744
|
actionText: actionText != null ? actionText : actionId
|
|
859
745
|
}, options);
|
|
860
746
|
}
|
|
861
|
-
const emptyGroupDefinition = {
|
|
862
|
-
type: ControlDefinitionType.Group,
|
|
863
|
-
children: [],
|
|
864
|
-
groupOptions: {
|
|
865
|
-
type: GroupRenderType.Standard,
|
|
866
|
-
hideTitle: true
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
747
|
function useControlDefinitionForSchema(sf, definition = emptyGroupDefinition) {
|
|
870
748
|
return useMemo(() => {
|
|
871
749
|
var _definition$children;
|
|
@@ -897,7 +775,7 @@ function createIconLibraryExtension(name, value) {
|
|
|
897
775
|
};
|
|
898
776
|
}
|
|
899
777
|
|
|
900
|
-
const _excluded$1 = ["
|
|
778
|
+
const _excluded$1 = ["formNode", "style", "schemaInterface", "styleClass", "textClass", "displayOnly", "inline"];
|
|
901
779
|
const AppendAdornmentPriority = 0;
|
|
902
780
|
const WrapAdornmentPriority = 1000;
|
|
903
781
|
/**
|
|
@@ -921,9 +799,8 @@ var LabelType;
|
|
|
921
799
|
function defaultDataProps(_ref, definition, control) {
|
|
922
800
|
var _definition$renderOpt;
|
|
923
801
|
let {
|
|
924
|
-
|
|
802
|
+
formNode,
|
|
925
803
|
style,
|
|
926
|
-
allowedOptions,
|
|
927
804
|
schemaInterface = defaultSchemaInterface,
|
|
928
805
|
styleClass,
|
|
929
806
|
textClass: tc,
|
|
@@ -936,30 +813,24 @@ function defaultDataProps(_ref, definition, control) {
|
|
|
936
813
|
const className = rendererClass(styleClass, definition.styleClass);
|
|
937
814
|
const textClass = rendererClass(tc, definition.textClass);
|
|
938
815
|
const required = !!definition.required && !displayOnly;
|
|
939
|
-
const
|
|
940
|
-
const _allowed = allowedOptions != null ? allowedOptions : [];
|
|
941
|
-
const allowed = Array.isArray(_allowed) ? _allowed : [_allowed];
|
|
816
|
+
const id = "c" + control.uniqueId;
|
|
942
817
|
return _extends({
|
|
943
818
|
dataNode,
|
|
819
|
+
formNode,
|
|
944
820
|
definition,
|
|
945
821
|
control,
|
|
946
822
|
field,
|
|
947
|
-
id
|
|
823
|
+
id,
|
|
824
|
+
errorId: "err_" + id,
|
|
948
825
|
inline: !!inline,
|
|
949
|
-
options:
|
|
950
|
-
|
|
951
|
-
return typeof x === "object" ? x : (_fieldOptions$find = fieldOptions == null ? void 0 : fieldOptions.find(y => y.value == x)) != null ? _fieldOptions$find : {
|
|
952
|
-
name: x.toString(),
|
|
953
|
-
value: x
|
|
954
|
-
};
|
|
955
|
-
}).filter(x => x != null) : fieldOptions,
|
|
956
|
-
readonly: !!formOptions.readonly,
|
|
826
|
+
options: formNode.resolved.fieldOptions,
|
|
827
|
+
readonly: formNode.readonly,
|
|
957
828
|
displayOnly: !!displayOnly,
|
|
958
829
|
renderOptions: (_definition$renderOpt = definition.renderOptions) != null ? _definition$renderOpt : {
|
|
959
830
|
type: "Standard"
|
|
960
831
|
},
|
|
961
832
|
required,
|
|
962
|
-
hidden:
|
|
833
|
+
hidden: !formNode.visible,
|
|
963
834
|
className,
|
|
964
835
|
textClass,
|
|
965
836
|
style
|
|
@@ -981,14 +852,11 @@ function renderControlLayout(props) {
|
|
|
981
852
|
styleClass,
|
|
982
853
|
textClass,
|
|
983
854
|
formNode,
|
|
984
|
-
formOptions,
|
|
985
855
|
actionOnClick,
|
|
986
|
-
state,
|
|
987
|
-
getChildState,
|
|
988
856
|
inline,
|
|
989
857
|
displayOnly
|
|
990
858
|
} = props;
|
|
991
|
-
const c =
|
|
859
|
+
const c = formNode.definition;
|
|
992
860
|
if (isDataControl(c)) {
|
|
993
861
|
return renderData(c);
|
|
994
862
|
}
|
|
@@ -1005,7 +873,6 @@ function renderControlLayout(props) {
|
|
|
1005
873
|
inline,
|
|
1006
874
|
processLayout: renderer.renderGroup({
|
|
1007
875
|
formNode,
|
|
1008
|
-
state,
|
|
1009
876
|
definition: c,
|
|
1010
877
|
renderChild,
|
|
1011
878
|
runExpression,
|
|
@@ -1017,8 +884,7 @@ function renderControlLayout(props) {
|
|
|
1017
884
|
textClass: rendererClass(textClass, c.textClass),
|
|
1018
885
|
style,
|
|
1019
886
|
designMode,
|
|
1020
|
-
actionOnClick
|
|
1021
|
-
getChildState
|
|
887
|
+
actionOnClick
|
|
1022
888
|
}),
|
|
1023
889
|
label: {
|
|
1024
890
|
label: c.title,
|
|
@@ -1030,10 +896,11 @@ function renderControlLayout(props) {
|
|
|
1030
896
|
};
|
|
1031
897
|
}
|
|
1032
898
|
if (isActionControl(c)) {
|
|
1033
|
-
var _c$actionStyle, _c$title
|
|
899
|
+
var _c$actionStyle, _c$title;
|
|
1034
900
|
const actionData = c.actionData;
|
|
1035
901
|
const actionStyle = (_c$actionStyle = c.actionStyle) != null ? _c$actionStyle : ActionStyle.Button;
|
|
1036
902
|
const actionContent = actionStyle == ActionStyle.Group ? renderActionGroup() : undefined;
|
|
903
|
+
const handler = props.actionOnClick == null ? void 0 : props.actionOnClick(c.actionId, actionData, dataContext);
|
|
1037
904
|
return {
|
|
1038
905
|
inline,
|
|
1039
906
|
children: renderer.renderAction({
|
|
@@ -1046,24 +913,41 @@ function renderControlLayout(props) {
|
|
|
1046
913
|
iconPlacement: c.iconPlacement,
|
|
1047
914
|
icon: c.icon,
|
|
1048
915
|
inline,
|
|
1049
|
-
disabled:
|
|
1050
|
-
onClick:
|
|
916
|
+
disabled: formNode.disabled,
|
|
917
|
+
onClick: handler ? () => {
|
|
918
|
+
var _c$disableType;
|
|
919
|
+
let disableType = (_c$disableType = c.disableType) != null ? _c$disableType : ControlDisableType.Self;
|
|
920
|
+
const actionContext = {
|
|
921
|
+
disableForm(type) {
|
|
922
|
+
disableType = type;
|
|
923
|
+
},
|
|
924
|
+
runAction(actionId, actionData) {
|
|
925
|
+
const h = props.actionOnClick == null ? void 0 : props.actionOnClick(actionId, actionData, dataContext);
|
|
926
|
+
if (h) {
|
|
927
|
+
h(actionContext);
|
|
928
|
+
}
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
const r = handler(actionContext);
|
|
933
|
+
if (r instanceof Promise) {
|
|
934
|
+
const cleanup = formNode.ui.getDisabler(disableType)();
|
|
935
|
+
formNode.setBusy(true);
|
|
936
|
+
r.then(() => {
|
|
937
|
+
cleanup();
|
|
938
|
+
formNode.setBusy(false);
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
} : () => {},
|
|
1051
942
|
className: rendererClass(styleClass, c.styleClass),
|
|
1052
|
-
style
|
|
943
|
+
style,
|
|
944
|
+
busy: formNode.busy
|
|
1053
945
|
})
|
|
1054
946
|
};
|
|
1055
947
|
function renderActionGroup() {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
groupOptions: {
|
|
1060
|
-
type: GroupRenderType.Contents,
|
|
1061
|
-
hideTitle: true
|
|
1062
|
-
},
|
|
1063
|
-
children: childDefs
|
|
1064
|
-
};
|
|
1065
|
-
const childNode = formNode.createChildNode("child", childDef);
|
|
1066
|
-
return renderChild("child", childNode, {});
|
|
948
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
949
|
+
children: formNode.children.map(x => renderChild(x))
|
|
950
|
+
});
|
|
1067
951
|
}
|
|
1068
952
|
}
|
|
1069
953
|
if (isDisplayControl(c)) {
|
|
@@ -1108,7 +992,8 @@ function renderControlLayout(props) {
|
|
|
1108
992
|
className: rendererClass(labelClass, c.labelClass),
|
|
1109
993
|
textClass: rendererClass(labelTextClass, c.labelTextClass)
|
|
1110
994
|
},
|
|
1111
|
-
errorControl: control
|
|
995
|
+
errorControl: control,
|
|
996
|
+
errorId: rendererProps.errorId
|
|
1112
997
|
};
|
|
1113
998
|
}
|
|
1114
999
|
}
|
|
@@ -1153,7 +1038,8 @@ function renderLayoutParts(props, renderer) {
|
|
|
1153
1038
|
errorControl,
|
|
1154
1039
|
label,
|
|
1155
1040
|
adornments,
|
|
1156
|
-
inline
|
|
1041
|
+
inline,
|
|
1042
|
+
errorId
|
|
1157
1043
|
} = (_props$processLayout = props.processLayout == null ? void 0 : props.processLayout(props)) != null ? _props$processLayout : props;
|
|
1158
1044
|
const layout = {
|
|
1159
1045
|
children,
|
|
@@ -1161,6 +1047,7 @@ function renderLayoutParts(props, renderer) {
|
|
|
1161
1047
|
style,
|
|
1162
1048
|
className: className,
|
|
1163
1049
|
inline,
|
|
1050
|
+
errorId,
|
|
1164
1051
|
wrapLayout: x => x
|
|
1165
1052
|
};
|
|
1166
1053
|
(adornments != null ? adornments : []).sort((a, b) => a.priority - b.priority).forEach(x => x.apply(layout));
|
|
@@ -1178,7 +1065,7 @@ function getLengthRestrictions(definition) {
|
|
|
1178
1065
|
max: lengthVal == null ? void 0 : lengthVal.max
|
|
1179
1066
|
};
|
|
1180
1067
|
}
|
|
1181
|
-
function createArrayActions(control, field, options) {
|
|
1068
|
+
function createArrayActions(control, getElementCount, field, options) {
|
|
1182
1069
|
var _field$displayName;
|
|
1183
1070
|
const noun = (_field$displayName = field.displayName) != null ? _field$displayName : field.field;
|
|
1184
1071
|
const {
|
|
@@ -1197,6 +1084,7 @@ function createArrayActions(control, field, options) {
|
|
|
1197
1084
|
} = options != null ? options : {};
|
|
1198
1085
|
return {
|
|
1199
1086
|
arrayControl: control,
|
|
1087
|
+
getElementCount,
|
|
1200
1088
|
addAction: !readonly && !noAdd ? makeAdd(() => {
|
|
1201
1089
|
if (!designMode) {
|
|
1202
1090
|
const newValue = elementValueForField(field);
|
|
@@ -1267,7 +1155,7 @@ function createArrayActions(control, field, options) {
|
|
|
1267
1155
|
}
|
|
1268
1156
|
}
|
|
1269
1157
|
function applyArrayLengthRestrictions({
|
|
1270
|
-
|
|
1158
|
+
getElementCount,
|
|
1271
1159
|
min,
|
|
1272
1160
|
max,
|
|
1273
1161
|
editAction,
|
|
@@ -1275,8 +1163,7 @@ function applyArrayLengthRestrictions({
|
|
|
1275
1163
|
removeAction: ra,
|
|
1276
1164
|
required
|
|
1277
1165
|
}, disable) {
|
|
1278
|
-
|
|
1279
|
-
const [removeAllowed, addAllowed] = applyLengthRestrictions((_arrayControl$element = (_arrayControl$element2 = arrayControl.elements) == null ? void 0 : _arrayControl$element2.length) != null ? _arrayControl$element : 0, min == null && required ? 1 : min, max, true, true);
|
|
1166
|
+
const [removeAllowed, addAllowed] = applyLengthRestrictions(getElementCount(), min == null && required ? 1 : min, max, true, true);
|
|
1280
1167
|
return {
|
|
1281
1168
|
addAction: disable || addAllowed ? aa : undefined,
|
|
1282
1169
|
removeAction: disable || removeAllowed ? ra : undefined,
|
|
@@ -1286,19 +1173,11 @@ function applyArrayLengthRestrictions({
|
|
|
1286
1173
|
};
|
|
1287
1174
|
}
|
|
1288
1175
|
function fieldOptionAdornment(p) {
|
|
1289
|
-
return (o, fieldIndex, selected) =>
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
variables: {
|
|
1295
|
-
formData: {
|
|
1296
|
-
option: o,
|
|
1297
|
-
optionSelected: selected
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
})
|
|
1301
|
-
});
|
|
1176
|
+
return (o, fieldIndex, selected) => {
|
|
1177
|
+
const fieldChild = p.formNode.children.find(x => x.meta["fieldOptionValue"] === o.value);
|
|
1178
|
+
if (fieldChild) return p.renderChild(fieldChild);
|
|
1179
|
+
return undefined;
|
|
1180
|
+
};
|
|
1302
1181
|
}
|
|
1303
1182
|
function lookupChildDataContext(dataContext, c) {
|
|
1304
1183
|
var _dataContext$dataNode;
|
|
@@ -1402,7 +1281,19 @@ function createFormRenderer(customRenderers = [], defaultRenderers) {
|
|
|
1402
1281
|
renderLayout,
|
|
1403
1282
|
renderVisibility,
|
|
1404
1283
|
renderLabelText,
|
|
1405
|
-
html: defaultRenderers.html
|
|
1284
|
+
html: defaultRenderers.html,
|
|
1285
|
+
resolveChildren(c) {
|
|
1286
|
+
const def = c.definition;
|
|
1287
|
+
if (isDataControl(def)) {
|
|
1288
|
+
var _def$renderOptions;
|
|
1289
|
+
if (!c.dataNode) return [];
|
|
1290
|
+
const matching = matchData(c, (_def$renderOptions = def.renderOptions) != null ? _def$renderOptions : {
|
|
1291
|
+
type: DataRenderType.Standard
|
|
1292
|
+
}, c.dataNode);
|
|
1293
|
+
if (matching != null && matching.resolveChildren) return matching.resolveChildren(c);
|
|
1294
|
+
}
|
|
1295
|
+
return defaultResolveChildNodes(c);
|
|
1296
|
+
}
|
|
1406
1297
|
};
|
|
1407
1298
|
function renderVisibility(props) {
|
|
1408
1299
|
return visibilityRenderer.render(props, formRenderers);
|
|
@@ -1432,29 +1323,31 @@ function createFormRenderer(customRenderers = [], defaultRenderers) {
|
|
|
1432
1323
|
const renderer = (_labelRenderers$find = labelRenderers.find(x => isOneOf(x.labelType, props.type))) != null ? _labelRenderers$find : defaultRenderers.label;
|
|
1433
1324
|
return renderer.render(props, labelStart, labelEnd, formRenderers);
|
|
1434
1325
|
}
|
|
1435
|
-
function
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
} = props;
|
|
1440
|
-
const options = hasOptions(props);
|
|
1326
|
+
function matchData(formState, renderOptions, dataNode) {
|
|
1327
|
+
var _formState$resolved$f, _formState$resolved$f2;
|
|
1328
|
+
const field = dataNode.schema.field;
|
|
1329
|
+
const options = ((_formState$resolved$f = (_formState$resolved$f2 = formState.resolved.fieldOptions) == null ? void 0 : _formState$resolved$f2.length) != null ? _formState$resolved$f : 0) > 0;
|
|
1441
1330
|
const renderType = renderOptions.type;
|
|
1442
|
-
|
|
1443
|
-
const result = (renderer != null ? renderer : defaultRenderers.data).render(props, formRenderers);
|
|
1444
|
-
if (typeof result === "function") return result;
|
|
1445
|
-
return l => _extends({}, l, {
|
|
1446
|
-
children: result
|
|
1447
|
-
});
|
|
1331
|
+
return dataRegistrations.find(matchesRenderer);
|
|
1448
1332
|
function matchesRenderer(x) {
|
|
1449
1333
|
var _x$collection, _field$collection, _x$options;
|
|
1450
|
-
const noMatch = x.match ? !x.match(
|
|
1334
|
+
const noMatch = x.match ? !x.match(formState, renderOptions) : undefined;
|
|
1451
1335
|
if (noMatch === true) return false;
|
|
1452
|
-
const matchCollection = ((_x$collection = x.collection) != null ? _x$collection : false) === (
|
|
1336
|
+
const matchCollection = ((_x$collection = x.collection) != null ? _x$collection : false) === (dataNode.elementIndex == null && ((_field$collection = field.collection) != null ? _field$collection : false));
|
|
1453
1337
|
const isSchemaAllowed = !!x.schemaType && renderType == DataRenderType.Standard ? isOneOf(x.schemaType, field.type) : undefined;
|
|
1454
1338
|
const isRendererAllowed = !!x.renderType && isOneOf(x.renderType, renderType);
|
|
1455
|
-
|
|
1339
|
+
const optionsMatch = isRendererAllowed || ((_x$options = x.options) != null ? _x$options : false) === options;
|
|
1340
|
+
return matchCollection && optionsMatch && (isSchemaAllowed || isRendererAllowed || !x.renderType && !x.schemaType && noMatch === false);
|
|
1456
1341
|
}
|
|
1457
1342
|
}
|
|
1343
|
+
function renderData(props) {
|
|
1344
|
+
const renderer = matchData(props.formNode, props.renderOptions, props.dataNode);
|
|
1345
|
+
const result = (renderer != null ? renderer : defaultRenderers.data).render(props, formRenderers);
|
|
1346
|
+
if (typeof result === "function") return result;
|
|
1347
|
+
return l => _extends({}, l, {
|
|
1348
|
+
children: result
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1458
1351
|
function renderGroup(props) {
|
|
1459
1352
|
var _groupRegistrations$f;
|
|
1460
1353
|
const renderType = props.renderOptions.type;
|
|
@@ -1510,48 +1403,101 @@ function isArrayRegistration(x) {
|
|
|
1510
1403
|
}
|
|
1511
1404
|
|
|
1512
1405
|
const _excluded = ["styleClass", "labelClass", "layoutClass", "labelTextClass", "textClass"],
|
|
1513
|
-
_excluded2 = ["
|
|
1406
|
+
_excluded2 = ["actionOnClick"];
|
|
1514
1407
|
function RenderForm({
|
|
1515
1408
|
data,
|
|
1516
1409
|
form,
|
|
1517
1410
|
renderer,
|
|
1518
|
-
options = {}
|
|
1411
|
+
options = {},
|
|
1412
|
+
stateRef
|
|
1519
1413
|
}) {
|
|
1520
1414
|
var _effect = useComponentTracking();
|
|
1521
1415
|
try {
|
|
1522
|
-
var _options$schemaInterf
|
|
1416
|
+
var _options$schemaInterf;
|
|
1417
|
+
const {
|
|
1418
|
+
readonly,
|
|
1419
|
+
disabled,
|
|
1420
|
+
displayOnly,
|
|
1421
|
+
hidden,
|
|
1422
|
+
variables,
|
|
1423
|
+
clearHidden
|
|
1424
|
+
} = options;
|
|
1523
1425
|
const schemaInterface = (_options$schemaInterf = options.schemaInterface) != null ? _options$schemaInterf : defaultSchemaInterface;
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1426
|
+
const {
|
|
1427
|
+
runAsync
|
|
1428
|
+
} = useAsyncRunner();
|
|
1429
|
+
const globals = {
|
|
1430
|
+
runAsync,
|
|
1431
|
+
schemaInterface,
|
|
1432
|
+
evalExpression: (e, ctx) => {
|
|
1433
|
+
var _defaultEvaluators$e$;
|
|
1434
|
+
return (_defaultEvaluators$e$ = defaultEvaluators[e.type]) == null ? void 0 : _defaultEvaluators$e$.call(defaultEvaluators, e, ctx);
|
|
1435
|
+
},
|
|
1436
|
+
resolveChildren: renderer.resolveChildren,
|
|
1437
|
+
clearHidden: !!clearHidden
|
|
1531
1438
|
};
|
|
1532
|
-
const state =
|
|
1439
|
+
const state = useMemo(() => createFormStateNode(form, data, globals, {
|
|
1440
|
+
forceReadonly: !!readonly,
|
|
1441
|
+
forceDisabled: !!disabled,
|
|
1442
|
+
variables,
|
|
1443
|
+
forceHidden: !!hidden
|
|
1444
|
+
}), [form.id]);
|
|
1445
|
+
state.globals.value = globals;
|
|
1446
|
+
state.options.setValue(x => ({
|
|
1447
|
+
variables,
|
|
1448
|
+
forceHidden: hidden != null ? hidden : x.forceHidden,
|
|
1449
|
+
forceDisabled: disabled != null ? disabled : x.forceDisabled,
|
|
1450
|
+
forceReadonly: readonly != null ? readonly : x.forceReadonly
|
|
1451
|
+
}));
|
|
1452
|
+
if (stateRef) stateRef.current = state;
|
|
1533
1453
|
useEffect(() => {
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
}
|
|
1537
|
-
}, [
|
|
1454
|
+
return () => {
|
|
1455
|
+
state.cleanup();
|
|
1456
|
+
};
|
|
1457
|
+
}, [state]);
|
|
1458
|
+
return /*#__PURE__*/jsx(RenderFormNode, {
|
|
1459
|
+
node: state,
|
|
1460
|
+
renderer: renderer,
|
|
1461
|
+
options: options
|
|
1462
|
+
});
|
|
1463
|
+
} finally {
|
|
1464
|
+
_effect();
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
/* @trackControls */
|
|
1468
|
+
function RenderFormNode({
|
|
1469
|
+
node: state,
|
|
1470
|
+
renderer,
|
|
1471
|
+
options = {}
|
|
1472
|
+
}) {
|
|
1473
|
+
var _effect2 = useComponentTracking();
|
|
1474
|
+
try {
|
|
1475
|
+
var _definition$adornment, _definition$adornment2, _dataContext$dataNode, _options$adjustLayout;
|
|
1476
|
+
useEffect(() => {
|
|
1477
|
+
state.attachUi(new DefaultFormNodeUi(state));
|
|
1478
|
+
}, [state]);
|
|
1479
|
+
const {
|
|
1480
|
+
runAsync
|
|
1481
|
+
} = useAsyncRunner();
|
|
1482
|
+
const schemaInterface = state.schemaInterface;
|
|
1538
1483
|
const definition = state.definition;
|
|
1539
|
-
const visible =
|
|
1484
|
+
const visible = state.visible;
|
|
1540
1485
|
const visibility = useControl(() => visible != null ? {
|
|
1541
1486
|
visible,
|
|
1542
1487
|
showing: visible
|
|
1543
1488
|
} : undefined);
|
|
1544
|
-
|
|
1489
|
+
if (visible != null) {
|
|
1490
|
+
visibility.fields.visible.value = visible;
|
|
1491
|
+
}
|
|
1545
1492
|
const dataContext = {
|
|
1546
1493
|
schemaInterface: state.schemaInterface,
|
|
1547
1494
|
dataNode: state.dataNode,
|
|
1548
|
-
parentNode:
|
|
1549
|
-
variables: state.variables
|
|
1495
|
+
parentNode: state.parent
|
|
1550
1496
|
};
|
|
1551
1497
|
const adornments = (_definition$adornment = (_definition$adornment2 = definition.adornments) == null ? void 0 : _definition$adornment2.map(x => renderer.renderAdornment({
|
|
1552
1498
|
adornment: x,
|
|
1553
1499
|
dataContext,
|
|
1554
|
-
|
|
1500
|
+
formNode: state
|
|
1555
1501
|
}))) != null ? _definition$adornment : [];
|
|
1556
1502
|
const {
|
|
1557
1503
|
styleClass,
|
|
@@ -1562,7 +1508,7 @@ function RenderForm({
|
|
|
1562
1508
|
inheritableOptions = _objectWithoutPropertiesLoose(options, _excluded);
|
|
1563
1509
|
const {
|
|
1564
1510
|
readonly,
|
|
1565
|
-
|
|
1511
|
+
visible: vis,
|
|
1566
1512
|
disabled,
|
|
1567
1513
|
variables
|
|
1568
1514
|
} = state;
|
|
@@ -1570,60 +1516,46 @@ function RenderForm({
|
|
|
1570
1516
|
readonly,
|
|
1571
1517
|
disabled,
|
|
1572
1518
|
variables,
|
|
1573
|
-
|
|
1574
|
-
hidden
|
|
1519
|
+
hidden: vis === false
|
|
1575
1520
|
});
|
|
1576
1521
|
const labelAndChildren = renderControlLayout({
|
|
1577
|
-
formNode:
|
|
1522
|
+
formNode: state,
|
|
1578
1523
|
renderer,
|
|
1579
|
-
|
|
1580
|
-
renderChild: (k, child, options) => {
|
|
1581
|
-
var _ref2;
|
|
1524
|
+
renderChild: (child, options) => {
|
|
1582
1525
|
const overrideClasses = getGroupClassOverrides(definition);
|
|
1583
1526
|
const _ref = options != null ? options : {},
|
|
1584
1527
|
{
|
|
1585
|
-
|
|
1586
|
-
actionOnClick,
|
|
1587
|
-
variables
|
|
1528
|
+
actionOnClick
|
|
1588
1529
|
} = _ref,
|
|
1589
1530
|
renderOptions = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
1590
|
-
const dContext = (_ref2 = parentDataNode != null ? parentDataNode : dataContext.dataNode) != null ? _ref2 : data;
|
|
1591
1531
|
const allChildOptions = _extends({}, childOptions, overrideClasses, renderOptions, {
|
|
1592
|
-
variables: _extends({}, childOptions.variables, variables),
|
|
1593
1532
|
actionOnClick: actionHandlers(actionOnClick, childOptions.actionOnClick)
|
|
1594
1533
|
});
|
|
1595
|
-
return /*#__PURE__*/jsx(
|
|
1596
|
-
|
|
1534
|
+
return /*#__PURE__*/jsx(RenderFormNode, {
|
|
1535
|
+
node: child,
|
|
1597
1536
|
renderer: renderer,
|
|
1598
|
-
data: dContext,
|
|
1599
1537
|
options: allChildOptions
|
|
1600
|
-
},
|
|
1538
|
+
}, child.childKey);
|
|
1601
1539
|
},
|
|
1602
1540
|
inline: options == null ? void 0 : options.inline,
|
|
1603
1541
|
displayOnly: options == null ? void 0 : options.displayOnly,
|
|
1604
1542
|
createDataProps: defaultDataProps,
|
|
1605
|
-
formOptions: state,
|
|
1606
1543
|
dataContext,
|
|
1607
1544
|
control: (_dataContext$dataNode = dataContext.dataNode) == null ? void 0 : _dataContext$dataNode.control,
|
|
1608
1545
|
schemaInterface,
|
|
1609
|
-
style: state.style,
|
|
1610
|
-
allowedOptions: state.allowedOptions,
|
|
1546
|
+
style: state.resolved.style,
|
|
1611
1547
|
customDisplay: options.customDisplay,
|
|
1612
1548
|
actionOnClick: options.actionOnClick,
|
|
1613
1549
|
styleClass: styleClass,
|
|
1614
1550
|
labelClass: labelClass,
|
|
1615
1551
|
labelTextClass: labelTextClass,
|
|
1616
1552
|
textClass: textClass,
|
|
1617
|
-
getChildState(child, parent) {
|
|
1618
|
-
var _ref3;
|
|
1619
|
-
return formState.getControlState((_ref3 = parent != null ? parent : state.dataNode) != null ? _ref3 : data, child, childOptions, runAsync);
|
|
1620
|
-
},
|
|
1621
1553
|
runExpression: (scope, expr, returnResult) => {
|
|
1622
1554
|
if (expr != null && expr.type) {
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
dataNode: data,
|
|
1555
|
+
defaultEvaluators[expr.type](expr, {
|
|
1556
|
+
dataNode: state.parent,
|
|
1626
1557
|
schemaInterface,
|
|
1558
|
+
scope,
|
|
1627
1559
|
returnResult,
|
|
1628
1560
|
runAsync
|
|
1629
1561
|
});
|
|
@@ -1633,22 +1565,14 @@ function RenderForm({
|
|
|
1633
1565
|
const layoutProps = _extends({}, labelAndChildren, {
|
|
1634
1566
|
adornments,
|
|
1635
1567
|
className: rendererClass(options.layoutClass, definition.layoutClass),
|
|
1636
|
-
style: state.layoutStyle
|
|
1568
|
+
style: state.resolved.layoutStyle
|
|
1637
1569
|
});
|
|
1638
1570
|
const renderedControl = renderer.renderLayout((_options$adjustLayout = options.adjustLayout == null ? void 0 : options.adjustLayout(dataContext, layoutProps)) != null ? _options$adjustLayout : layoutProps);
|
|
1639
|
-
|
|
1571
|
+
return renderer.renderVisibility(_extends({
|
|
1640
1572
|
visibility
|
|
1641
1573
|
}, renderedControl));
|
|
1642
|
-
useEffect(() => {
|
|
1643
|
-
if (effects) {
|
|
1644
|
-
const toRun = effects;
|
|
1645
|
-
effects = undefined;
|
|
1646
|
-
toRun.forEach(cb => cb());
|
|
1647
|
-
}
|
|
1648
|
-
}, [effects]);
|
|
1649
|
-
return rendered;
|
|
1650
1574
|
} finally {
|
|
1651
|
-
|
|
1575
|
+
_effect2();
|
|
1652
1576
|
}
|
|
1653
1577
|
}
|
|
1654
1578
|
/**
|
|
@@ -1688,13 +1612,13 @@ function ControlRenderer({
|
|
|
1688
1612
|
control,
|
|
1689
1613
|
parentPath
|
|
1690
1614
|
}) {
|
|
1691
|
-
var
|
|
1615
|
+
var _effect3 = useComponentTracking();
|
|
1692
1616
|
try {
|
|
1693
1617
|
const schemaDataNode = createSchemaDataNode(createSchemaTree(fields).rootNode, control);
|
|
1694
1618
|
const Render = useControlRendererComponent(definition, renderer, options, schemaDataNode);
|
|
1695
1619
|
return /*#__PURE__*/jsx(Render, {});
|
|
1696
1620
|
} finally {
|
|
1697
|
-
|
|
1621
|
+
_effect3();
|
|
1698
1622
|
}
|
|
1699
1623
|
}
|
|
1700
1624
|
/**
|
|
@@ -1706,12 +1630,12 @@ function NewControlRenderer({
|
|
|
1706
1630
|
options,
|
|
1707
1631
|
parentDataNode
|
|
1708
1632
|
}) {
|
|
1709
|
-
var
|
|
1633
|
+
var _effect4 = useComponentTracking();
|
|
1710
1634
|
try {
|
|
1711
1635
|
const Render = useControlRendererComponent(definition, renderer, options, parentDataNode);
|
|
1712
1636
|
return /*#__PURE__*/jsx(Render, {});
|
|
1713
1637
|
} finally {
|
|
1714
|
-
|
|
1638
|
+
_effect4();
|
|
1715
1639
|
}
|
|
1716
1640
|
}
|
|
1717
1641
|
/**
|
|
@@ -1734,6 +1658,80 @@ function useControlRenderer(definition, fields, renderer, options = {}) {
|
|
|
1734
1658
|
}));
|
|
1735
1659
|
}, [r]);
|
|
1736
1660
|
}
|
|
1661
|
+
function useAsyncRunner() {
|
|
1662
|
+
let effects = [];
|
|
1663
|
+
const runAsync = cb => {
|
|
1664
|
+
if (effects) effects.push(cb);else cb();
|
|
1665
|
+
};
|
|
1666
|
+
useEffect(() => {
|
|
1667
|
+
if (effects) {
|
|
1668
|
+
const toRun = effects;
|
|
1669
|
+
effects = undefined;
|
|
1670
|
+
toRun.forEach(cb => cb());
|
|
1671
|
+
}
|
|
1672
|
+
}, [effects]);
|
|
1673
|
+
return {
|
|
1674
|
+
runAsync
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
class DefaultFormNodeUi {
|
|
1678
|
+
constructor(node) {
|
|
1679
|
+
this.node = void 0;
|
|
1680
|
+
this.node = node;
|
|
1681
|
+
}
|
|
1682
|
+
ensureVisible() {
|
|
1683
|
+
var _this$node$parentNode;
|
|
1684
|
+
(_this$node$parentNode = this.node.parentNode) == null || _this$node$parentNode.ui.ensureChildVisible(this.node.childIndex);
|
|
1685
|
+
}
|
|
1686
|
+
ensureChildVisible(childIndex) {
|
|
1687
|
+
this.ensureVisible();
|
|
1688
|
+
}
|
|
1689
|
+
getDisabler(type) {
|
|
1690
|
+
if (type === ControlDisableType.Self) {
|
|
1691
|
+
return () => {
|
|
1692
|
+
const old = !!this.node.forceDisabled;
|
|
1693
|
+
this.node.setForceDisabled(true);
|
|
1694
|
+
return () => {
|
|
1695
|
+
this.node.setForceDisabled(old);
|
|
1696
|
+
};
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
if (type === ControlDisableType.Global) {
|
|
1700
|
+
let topLevel = this.node;
|
|
1701
|
+
while (topLevel.parentNode) {
|
|
1702
|
+
topLevel = topLevel.parentNode;
|
|
1703
|
+
}
|
|
1704
|
+
return topLevel.ui.getDisabler(ControlDisableType.Self);
|
|
1705
|
+
}
|
|
1706
|
+
return () => () => {};
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const NoOpControlActionContext = {
|
|
1711
|
+
disableForm(disable) {},
|
|
1712
|
+
runAction(actionId, actionData) {}
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
function useElementSelectedRenderer({
|
|
1716
|
+
runExpression,
|
|
1717
|
+
renderOptions,
|
|
1718
|
+
control
|
|
1719
|
+
}) {
|
|
1720
|
+
const elementValue = useControl();
|
|
1721
|
+
useEffect(() => {
|
|
1722
|
+
runExpression(elementValue, renderOptions.elementExpression, v => elementValue.value = v);
|
|
1723
|
+
}, []);
|
|
1724
|
+
const isSelected = useComputed(() => {
|
|
1725
|
+
var _control$as$value$inc, _control$as$value;
|
|
1726
|
+
return (_control$as$value$inc = (_control$as$value = control.as().value) == null ? void 0 : _control$as$value.includes(elementValue.value)) != null ? _control$as$value$inc : false;
|
|
1727
|
+
});
|
|
1728
|
+
const selControl = useControl(() => isSelected.current.value);
|
|
1729
|
+
selControl.value = isSelected.value;
|
|
1730
|
+
useControlEffect(() => selControl.value, v => {
|
|
1731
|
+
control.as().setValue(x => setIncluded(x != null ? x : [], elementValue.value, v));
|
|
1732
|
+
});
|
|
1733
|
+
return selControl;
|
|
1734
|
+
}
|
|
1737
1735
|
|
|
1738
|
-
export { AppendAdornmentPriority, ControlRenderer, LabelType, NewControlRenderer,
|
|
1736
|
+
export { AppendAdornmentPriority, ControlRenderer, DefaultFormNodeUi, LabelType, NewControlRenderer, NoOpControlActionContext, RenderForm, RenderFormNode, WrapAdornmentPriority, actionHandlers, addMissingControls, addMissingControlsForSchema, appendMarkup, appendMarkupAt, applyArrayLengthRestrictions, applyDefaultForField, applyDefaultValues, applyExtensionToSchema, applyExtensionsToSchema, applyLengthRestrictions, applyValues, cleanDataForSchema, clearMultiValues, coerceToString, collectDifferences, controlTitle, createAction, createActionRenderer, createAdornmentRenderer, createArrayActions, createArrayRenderer, createDataRenderer, createDisplayRenderer, createFormRenderer, createGroupRenderer, createIconLibraryExtension, createLabelRenderer, createLayoutRenderer, createVisibilityRenderer, deepMerge, defaultControlForField, defaultDataProps, defaultValueForField, defaultValueForFields, elementValueForField, fieldDisplayName, fieldHasTag, fieldOptionAdornment, findChildDefinition, findCompoundField, findControlsForCompound, findFieldPath, findNonDataGroups, findScalarField, getAllReferencedClasses, getAllValues, getDiffObject, getExternalEditData, getGroupClassOverrides, getIsEditing, getLastDefinedValue, getLengthRestrictions, getNullToggler, getOverrideClass, hasOptions, isAccordionAdornment, isIconAdornment, isOptionalAdornment, isSetFieldAdornment, layoutKeyForPlacement, lookupChildDataContext, mergeObjects, renderControlLayout, renderLayoutParts, rendererClass, setIncluded, useAsyncRunner, useControlDefinitionForSchema, useControlRenderer, useControlRendererComponent, useElementSelectedRenderer, useExpression, useUpdatedRef, validationVisitor, wrapLayout, wrapMarkup, wrapMarkupAt };
|
|
1739
1737
|
//# sourceMappingURL=index.js.map
|