@bpmn-io/form-js-viewer 1.21.0 → 1.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +139 -135
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +139 -135
- package/dist/index.es.js.map +1 -1
- package/dist/types/render/context/FormRenderContext.d.ts +1 -0
- package/dist/types/render/hooks/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist/types/render/hooks/useCondition.d.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -640,6 +640,110 @@ function prefixId(id, formId, indexes) {
|
|
|
640
640
|
return result;
|
|
641
641
|
}
|
|
642
642
|
|
|
643
|
+
/**
|
|
644
|
+
* Returns the options data for the provided if they can be simply determined, ignoring expression defined options.
|
|
645
|
+
*
|
|
646
|
+
* @param {object} formField
|
|
647
|
+
* @param {object} formData
|
|
648
|
+
*/
|
|
649
|
+
function getSimpleOptionsData(formField, formData) {
|
|
650
|
+
const {
|
|
651
|
+
valuesExpression: optionsExpression,
|
|
652
|
+
valuesKey: optionsKey,
|
|
653
|
+
values: staticOptions
|
|
654
|
+
} = formField;
|
|
655
|
+
if (optionsExpression) {
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
return optionsKey ? minDash.get(formData, [optionsKey]) : staticOptions;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Normalizes the provided options data to a format that can be used by the select components.
|
|
663
|
+
* If the options data is not valid, it is filtered out.
|
|
664
|
+
*
|
|
665
|
+
* @param {any[]} optionsData
|
|
666
|
+
*
|
|
667
|
+
* @returns {object[]}
|
|
668
|
+
*/
|
|
669
|
+
function normalizeOptionsData(optionsData) {
|
|
670
|
+
return optionsData.filter(_isAllowedValue).map(_normalizeOption).filter(o => !minDash.isNil(o));
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Creates an options object with default values if no options are provided.
|
|
675
|
+
*
|
|
676
|
+
* @param {object} options
|
|
677
|
+
*
|
|
678
|
+
* @returns {object}
|
|
679
|
+
*/
|
|
680
|
+
function createEmptyOptions(options = {}) {
|
|
681
|
+
const defaults = {};
|
|
682
|
+
|
|
683
|
+
// provide default options if valuesKey and valuesExpression are not set
|
|
684
|
+
if (!options.valuesKey && !options.valuesExpression) {
|
|
685
|
+
defaults.values = [{
|
|
686
|
+
label: 'Value',
|
|
687
|
+
value: 'value'
|
|
688
|
+
}];
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
...defaults,
|
|
692
|
+
...options
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Converts the provided option to a normalized format.
|
|
698
|
+
* If the option is not valid, null is returned.
|
|
699
|
+
*
|
|
700
|
+
* @param {object} option
|
|
701
|
+
* @param {string} option.label
|
|
702
|
+
* @param {*} option.value
|
|
703
|
+
*
|
|
704
|
+
* @returns
|
|
705
|
+
*/
|
|
706
|
+
function _normalizeOption(option) {
|
|
707
|
+
// (1) simple primitive case, use it as both label and value
|
|
708
|
+
if (_isAllowedPrimitive(option)) {
|
|
709
|
+
return {
|
|
710
|
+
value: option,
|
|
711
|
+
label: `${option}`
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
if (minDash.isObject(option)) {
|
|
715
|
+
const isValidLabel = _isValidLabel(option.label);
|
|
716
|
+
|
|
717
|
+
// (2) no label provided, but value is a simple primitive, use it as label and value
|
|
718
|
+
if (!isValidLabel && _isAllowedPrimitive(option.value)) {
|
|
719
|
+
return {
|
|
720
|
+
value: option.value,
|
|
721
|
+
label: `${option.value}`
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// (3) both label and value are provided, use them as is
|
|
726
|
+
if (isValidLabel && _isAllowedValue(option.value)) {
|
|
727
|
+
return option;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
function _isAllowedPrimitive(value) {
|
|
733
|
+
const isAllowedPrimitiveType = ['number', 'string', 'boolean'].includes(typeof value);
|
|
734
|
+
const isValid = value || value === 0 || value === false;
|
|
735
|
+
return isAllowedPrimitiveType && isValid;
|
|
736
|
+
}
|
|
737
|
+
function _isValidLabel(label) {
|
|
738
|
+
return label && minDash.isString(label);
|
|
739
|
+
}
|
|
740
|
+
function _isAllowedValue(value) {
|
|
741
|
+
if (minDash.isObject(value)) {
|
|
742
|
+
return Object.keys(value).length > 0;
|
|
743
|
+
}
|
|
744
|
+
return _isAllowedPrimitive(value);
|
|
745
|
+
}
|
|
746
|
+
|
|
643
747
|
const FormRenderContext = preact.createContext({
|
|
644
748
|
Empty: props => {
|
|
645
749
|
return null;
|
|
@@ -680,7 +784,8 @@ const FormRenderContext = preact.createContext({
|
|
|
680
784
|
},
|
|
681
785
|
hoverInfo: {
|
|
682
786
|
cleanup: () => {}
|
|
683
|
-
}
|
|
787
|
+
},
|
|
788
|
+
applyVisibilityConditions: true
|
|
684
789
|
});
|
|
685
790
|
|
|
686
791
|
const LocalExpressionContext = preact.createContext({
|
|
@@ -813,134 +918,6 @@ function runUnaryTestEvaluation(expressionLanguage, value, expressionContextInfo
|
|
|
813
918
|
return expressionLanguage.evaluateUnaryTest(value, buildExpressionContext(expressionContextInfo));
|
|
814
919
|
}
|
|
815
920
|
|
|
816
|
-
/**
|
|
817
|
-
* Evaluate a unary test expression reactively. Returns null for invalid/missing expressions.
|
|
818
|
-
* The function is memoized to minimize re-renders.
|
|
819
|
-
*
|
|
820
|
-
* @param {string | undefined} value - A unary test expression to evaluate.
|
|
821
|
-
* @returns {boolean | null} - Evaluated result, or null if expression is invalid/missing.
|
|
822
|
-
*/
|
|
823
|
-
function useUnaryTestEvaluation(value) {
|
|
824
|
-
const expressionLanguage = useService('expressionLanguage');
|
|
825
|
-
const expressionContextInfo = hooks.useContext(LocalExpressionContext);
|
|
826
|
-
return hooks.useMemo(() => runUnaryTestEvaluation(expressionLanguage, value, expressionContextInfo), [expressionLanguage, expressionContextInfo, value]);
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Evaluate if condition is met reactively based on the expression language and form data.
|
|
831
|
-
*
|
|
832
|
-
* @param {string | undefined} condition
|
|
833
|
-
*
|
|
834
|
-
* @returns {boolean | null} true if condition is met, false if not, null if no condition or expression language
|
|
835
|
-
*/
|
|
836
|
-
function useCondition(condition) {
|
|
837
|
-
return useUnaryTestEvaluation(condition);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
/**
|
|
841
|
-
* Returns the options data for the provided if they can be simply determined, ignoring expression defined options.
|
|
842
|
-
*
|
|
843
|
-
* @param {object} formField
|
|
844
|
-
* @param {object} formData
|
|
845
|
-
*/
|
|
846
|
-
function getSimpleOptionsData(formField, formData) {
|
|
847
|
-
const {
|
|
848
|
-
valuesExpression: optionsExpression,
|
|
849
|
-
valuesKey: optionsKey,
|
|
850
|
-
values: staticOptions
|
|
851
|
-
} = formField;
|
|
852
|
-
if (optionsExpression) {
|
|
853
|
-
return null;
|
|
854
|
-
}
|
|
855
|
-
return optionsKey ? minDash.get(formData, [optionsKey]) : staticOptions;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
/**
|
|
859
|
-
* Normalizes the provided options data to a format that can be used by the select components.
|
|
860
|
-
* If the options data is not valid, it is filtered out.
|
|
861
|
-
*
|
|
862
|
-
* @param {any[]} optionsData
|
|
863
|
-
*
|
|
864
|
-
* @returns {object[]}
|
|
865
|
-
*/
|
|
866
|
-
function normalizeOptionsData(optionsData) {
|
|
867
|
-
return optionsData.filter(_isAllowedValue).map(_normalizeOption).filter(o => !minDash.isNil(o));
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
* Creates an options object with default values if no options are provided.
|
|
872
|
-
*
|
|
873
|
-
* @param {object} options
|
|
874
|
-
*
|
|
875
|
-
* @returns {object}
|
|
876
|
-
*/
|
|
877
|
-
function createEmptyOptions(options = {}) {
|
|
878
|
-
const defaults = {};
|
|
879
|
-
|
|
880
|
-
// provide default options if valuesKey and valuesExpression are not set
|
|
881
|
-
if (!options.valuesKey && !options.valuesExpression) {
|
|
882
|
-
defaults.values = [{
|
|
883
|
-
label: 'Value',
|
|
884
|
-
value: 'value'
|
|
885
|
-
}];
|
|
886
|
-
}
|
|
887
|
-
return {
|
|
888
|
-
...defaults,
|
|
889
|
-
...options
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
/**
|
|
894
|
-
* Converts the provided option to a normalized format.
|
|
895
|
-
* If the option is not valid, null is returned.
|
|
896
|
-
*
|
|
897
|
-
* @param {object} option
|
|
898
|
-
* @param {string} option.label
|
|
899
|
-
* @param {*} option.value
|
|
900
|
-
*
|
|
901
|
-
* @returns
|
|
902
|
-
*/
|
|
903
|
-
function _normalizeOption(option) {
|
|
904
|
-
// (1) simple primitive case, use it as both label and value
|
|
905
|
-
if (_isAllowedPrimitive(option)) {
|
|
906
|
-
return {
|
|
907
|
-
value: option,
|
|
908
|
-
label: `${option}`
|
|
909
|
-
};
|
|
910
|
-
}
|
|
911
|
-
if (minDash.isObject(option)) {
|
|
912
|
-
const isValidLabel = _isValidLabel(option.label);
|
|
913
|
-
|
|
914
|
-
// (2) no label provided, but value is a simple primitive, use it as label and value
|
|
915
|
-
if (!isValidLabel && _isAllowedPrimitive(option.value)) {
|
|
916
|
-
return {
|
|
917
|
-
value: option.value,
|
|
918
|
-
label: `${option.value}`
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
// (3) both label and value are provided, use them as is
|
|
923
|
-
if (isValidLabel && _isAllowedValue(option.value)) {
|
|
924
|
-
return option;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
return null;
|
|
928
|
-
}
|
|
929
|
-
function _isAllowedPrimitive(value) {
|
|
930
|
-
const isAllowedPrimitiveType = ['number', 'string', 'boolean'].includes(typeof value);
|
|
931
|
-
const isValid = value || value === 0 || value === false;
|
|
932
|
-
return isAllowedPrimitiveType && isValid;
|
|
933
|
-
}
|
|
934
|
-
function _isValidLabel(label) {
|
|
935
|
-
return label && minDash.isString(label);
|
|
936
|
-
}
|
|
937
|
-
function _isAllowedValue(value) {
|
|
938
|
-
if (minDash.isObject(value)) {
|
|
939
|
-
return Object.keys(value).length > 0;
|
|
940
|
-
}
|
|
941
|
-
return _isAllowedPrimitive(value);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
921
|
/**
|
|
945
922
|
* If the value is a valid expression, it is evaluated and returned. Otherwise, it is returned as-is.
|
|
946
923
|
* The function is memoized to minimize re-renders.
|
|
@@ -1272,6 +1249,19 @@ function useBooleanExpressionEvaluation(value) {
|
|
|
1272
1249
|
}, [expressionLanguage, expressionContextInfo, value]);
|
|
1273
1250
|
}
|
|
1274
1251
|
|
|
1252
|
+
/**
|
|
1253
|
+
* Evaluate a unary test expression reactively. Returns null for invalid/missing expressions.
|
|
1254
|
+
* The function is memoized to minimize re-renders.
|
|
1255
|
+
*
|
|
1256
|
+
* @param {string | undefined} value - A unary test expression to evaluate.
|
|
1257
|
+
* @returns {boolean | null} - Evaluated result, or null if expression is invalid/missing.
|
|
1258
|
+
*/
|
|
1259
|
+
function useUnaryTestEvaluation(value) {
|
|
1260
|
+
const expressionLanguage = useService('expressionLanguage');
|
|
1261
|
+
const expressionContextInfo = hooks.useContext(LocalExpressionContext);
|
|
1262
|
+
return hooks.useMemo(() => runUnaryTestEvaluation(expressionLanguage, value, expressionContextInfo), [expressionLanguage, expressionContextInfo, value]);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1275
1265
|
/**
|
|
1276
1266
|
* Returns the conditionally filtered data of a form reactively.
|
|
1277
1267
|
* Memoised to minimize re-renders
|
|
@@ -2083,7 +2073,8 @@ function FormField(props) {
|
|
|
2083
2073
|
const {
|
|
2084
2074
|
Element,
|
|
2085
2075
|
Hidden,
|
|
2086
|
-
Column
|
|
2076
|
+
Column,
|
|
2077
|
+
applyVisibilityConditions
|
|
2087
2078
|
} = hooks.useContext(FormRenderContext);
|
|
2088
2079
|
const {
|
|
2089
2080
|
formId
|
|
@@ -2107,7 +2098,8 @@ function FormField(props) {
|
|
|
2107
2098
|
|
|
2108
2099
|
// add precedence: global readonly > form field disabled
|
|
2109
2100
|
const disabled = !properties.readOnly && (properties.disabled || field.disabled || false);
|
|
2110
|
-
const
|
|
2101
|
+
const conditionResult = useUnaryTestEvaluation(field.conditional && field.conditional.hide || null);
|
|
2102
|
+
const hidden = applyVisibilityConditions ? conditionResult : null;
|
|
2111
2103
|
const instanceId = hooks.useMemo(() => {
|
|
2112
2104
|
if (!formFieldInstanceRegistry) {
|
|
2113
2105
|
return null;
|
|
@@ -8507,11 +8499,23 @@ function runPresetValidation(field, validation, value) {
|
|
|
8507
8499
|
errors.push('Field is required.');
|
|
8508
8500
|
}
|
|
8509
8501
|
}
|
|
8510
|
-
if ('min' in validation && (value || value === 0)
|
|
8511
|
-
|
|
8502
|
+
if ('min' in validation && (value || value === 0)) {
|
|
8503
|
+
try {
|
|
8504
|
+
if (Big(value).lt(Big(validation.min))) {
|
|
8505
|
+
errors.push(`Field must have minimum value of ${validation.min}.`);
|
|
8506
|
+
}
|
|
8507
|
+
} catch {
|
|
8508
|
+
errors.push('Min validation value is not a valid number.');
|
|
8509
|
+
}
|
|
8512
8510
|
}
|
|
8513
|
-
if ('max' in validation && (value || value === 0)
|
|
8514
|
-
|
|
8511
|
+
if ('max' in validation && (value || value === 0)) {
|
|
8512
|
+
try {
|
|
8513
|
+
if (Big(value).gt(Big(validation.max))) {
|
|
8514
|
+
errors.push(`Field must have maximum value of ${validation.max}.`);
|
|
8515
|
+
}
|
|
8516
|
+
} catch {
|
|
8517
|
+
errors.push('Max validation value is not a valid number.');
|
|
8518
|
+
}
|
|
8515
8519
|
}
|
|
8516
8520
|
if ('minLength' in validation && value && value.trim().length < validation.minLength) {
|
|
8517
8521
|
errors.push(`Field must have minimum length of ${validation.minLength}.`);
|