@remoteoss/json-schema-form 0.4.4-dev.20230829101351 → 0.4.4-dev.20230829191632
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 +62 -489
- package/dist/index.js +62 -489
- package/dist/standalone.js +62 -867
- package/package.json +1 -2
- package/src/tests/const.test.js +86 -0
- package/src/tests/helpers.custom.js +0 -1
- package/src/tests/jsonLogic.test.js +0 -814
- package/src/tests/jsonLogicFixtures.js +0 -1489
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2023 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.
|
|
5
|
-
Generated: Tue, 29 Aug 2023
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230829191632
|
|
5
|
+
Generated: Tue, 29 Aug 2023 19:17:06 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -5648,384 +5648,6 @@ var require_isEmpty = __commonJS({
|
|
|
5648
5648
|
}
|
|
5649
5649
|
});
|
|
5650
5650
|
|
|
5651
|
-
// node_modules/json-logic-js/logic.js
|
|
5652
|
-
var require_logic = __commonJS({
|
|
5653
|
-
"node_modules/json-logic-js/logic.js"(exports2, module2) {
|
|
5654
|
-
(function(root2, factory) {
|
|
5655
|
-
if (typeof define === "function" && define.amd) {
|
|
5656
|
-
define(factory);
|
|
5657
|
-
} else if (typeof exports2 === "object") {
|
|
5658
|
-
module2.exports = factory();
|
|
5659
|
-
} else {
|
|
5660
|
-
root2.jsonLogic = factory();
|
|
5661
|
-
}
|
|
5662
|
-
})(exports2, function() {
|
|
5663
|
-
"use strict";
|
|
5664
|
-
if (!Array.isArray) {
|
|
5665
|
-
Array.isArray = function(arg) {
|
|
5666
|
-
return Object.prototype.toString.call(arg) === "[object Array]";
|
|
5667
|
-
};
|
|
5668
|
-
}
|
|
5669
|
-
function arrayUnique(array2) {
|
|
5670
|
-
var a = [];
|
|
5671
|
-
for (var i = 0, l = array2.length; i < l; i++) {
|
|
5672
|
-
if (a.indexOf(array2[i]) === -1) {
|
|
5673
|
-
a.push(array2[i]);
|
|
5674
|
-
}
|
|
5675
|
-
}
|
|
5676
|
-
return a;
|
|
5677
|
-
}
|
|
5678
|
-
var jsonLogic2 = {};
|
|
5679
|
-
var operations = {
|
|
5680
|
-
"==": function(a, b) {
|
|
5681
|
-
return a == b;
|
|
5682
|
-
},
|
|
5683
|
-
"===": function(a, b) {
|
|
5684
|
-
return a === b;
|
|
5685
|
-
},
|
|
5686
|
-
"!=": function(a, b) {
|
|
5687
|
-
return a != b;
|
|
5688
|
-
},
|
|
5689
|
-
"!==": function(a, b) {
|
|
5690
|
-
return a !== b;
|
|
5691
|
-
},
|
|
5692
|
-
">": function(a, b) {
|
|
5693
|
-
return a > b;
|
|
5694
|
-
},
|
|
5695
|
-
">=": function(a, b) {
|
|
5696
|
-
return a >= b;
|
|
5697
|
-
},
|
|
5698
|
-
"<": function(a, b, c) {
|
|
5699
|
-
return c === void 0 ? a < b : a < b && b < c;
|
|
5700
|
-
},
|
|
5701
|
-
"<=": function(a, b, c) {
|
|
5702
|
-
return c === void 0 ? a <= b : a <= b && b <= c;
|
|
5703
|
-
},
|
|
5704
|
-
"!!": function(a) {
|
|
5705
|
-
return jsonLogic2.truthy(a);
|
|
5706
|
-
},
|
|
5707
|
-
"!": function(a) {
|
|
5708
|
-
return !jsonLogic2.truthy(a);
|
|
5709
|
-
},
|
|
5710
|
-
"%": function(a, b) {
|
|
5711
|
-
return a % b;
|
|
5712
|
-
},
|
|
5713
|
-
"log": function(a) {
|
|
5714
|
-
console.log(a);
|
|
5715
|
-
return a;
|
|
5716
|
-
},
|
|
5717
|
-
"in": function(a, b) {
|
|
5718
|
-
if (!b || typeof b.indexOf === "undefined")
|
|
5719
|
-
return false;
|
|
5720
|
-
return b.indexOf(a) !== -1;
|
|
5721
|
-
},
|
|
5722
|
-
"cat": function() {
|
|
5723
|
-
return Array.prototype.join.call(arguments, "");
|
|
5724
|
-
},
|
|
5725
|
-
"substr": function(source, start, end) {
|
|
5726
|
-
if (end < 0) {
|
|
5727
|
-
var temp = String(source).substr(start);
|
|
5728
|
-
return temp.substr(0, temp.length + end);
|
|
5729
|
-
}
|
|
5730
|
-
return String(source).substr(start, end);
|
|
5731
|
-
},
|
|
5732
|
-
"+": function() {
|
|
5733
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5734
|
-
return parseFloat(a, 10) + parseFloat(b, 10);
|
|
5735
|
-
}, 0);
|
|
5736
|
-
},
|
|
5737
|
-
"*": function() {
|
|
5738
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5739
|
-
return parseFloat(a, 10) * parseFloat(b, 10);
|
|
5740
|
-
});
|
|
5741
|
-
},
|
|
5742
|
-
"-": function(a, b) {
|
|
5743
|
-
if (b === void 0) {
|
|
5744
|
-
return -a;
|
|
5745
|
-
} else {
|
|
5746
|
-
return a - b;
|
|
5747
|
-
}
|
|
5748
|
-
},
|
|
5749
|
-
"/": function(a, b) {
|
|
5750
|
-
return a / b;
|
|
5751
|
-
},
|
|
5752
|
-
"min": function() {
|
|
5753
|
-
return Math.min.apply(this, arguments);
|
|
5754
|
-
},
|
|
5755
|
-
"max": function() {
|
|
5756
|
-
return Math.max.apply(this, arguments);
|
|
5757
|
-
},
|
|
5758
|
-
"merge": function() {
|
|
5759
|
-
return Array.prototype.reduce.call(arguments, function(a, b) {
|
|
5760
|
-
return a.concat(b);
|
|
5761
|
-
}, []);
|
|
5762
|
-
},
|
|
5763
|
-
"var": function(a, b) {
|
|
5764
|
-
var not_found = b === void 0 ? null : b;
|
|
5765
|
-
var data = this;
|
|
5766
|
-
if (typeof a === "undefined" || a === "" || a === null) {
|
|
5767
|
-
return data;
|
|
5768
|
-
}
|
|
5769
|
-
var sub_props = String(a).split(".");
|
|
5770
|
-
for (var i = 0; i < sub_props.length; i++) {
|
|
5771
|
-
if (data === null || data === void 0) {
|
|
5772
|
-
return not_found;
|
|
5773
|
-
}
|
|
5774
|
-
data = data[sub_props[i]];
|
|
5775
|
-
if (data === void 0) {
|
|
5776
|
-
return not_found;
|
|
5777
|
-
}
|
|
5778
|
-
}
|
|
5779
|
-
return data;
|
|
5780
|
-
},
|
|
5781
|
-
"missing": function() {
|
|
5782
|
-
var missing = [];
|
|
5783
|
-
var keys2 = Array.isArray(arguments[0]) ? arguments[0] : arguments;
|
|
5784
|
-
for (var i = 0; i < keys2.length; i++) {
|
|
5785
|
-
var key = keys2[i];
|
|
5786
|
-
var value = jsonLogic2.apply({ "var": key }, this);
|
|
5787
|
-
if (value === null || value === "") {
|
|
5788
|
-
missing.push(key);
|
|
5789
|
-
}
|
|
5790
|
-
}
|
|
5791
|
-
return missing;
|
|
5792
|
-
},
|
|
5793
|
-
"missing_some": function(need_count, options) {
|
|
5794
|
-
var are_missing = jsonLogic2.apply({ "missing": options }, this);
|
|
5795
|
-
if (options.length - are_missing.length >= need_count) {
|
|
5796
|
-
return [];
|
|
5797
|
-
} else {
|
|
5798
|
-
return are_missing;
|
|
5799
|
-
}
|
|
5800
|
-
}
|
|
5801
|
-
};
|
|
5802
|
-
jsonLogic2.is_logic = function(logic) {
|
|
5803
|
-
return typeof logic === "object" && // An object
|
|
5804
|
-
logic !== null && // but not null
|
|
5805
|
-
!Array.isArray(logic) && // and not an array
|
|
5806
|
-
Object.keys(logic).length === 1;
|
|
5807
|
-
};
|
|
5808
|
-
jsonLogic2.truthy = function(value) {
|
|
5809
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
5810
|
-
return false;
|
|
5811
|
-
}
|
|
5812
|
-
return !!value;
|
|
5813
|
-
};
|
|
5814
|
-
jsonLogic2.get_operator = function(logic) {
|
|
5815
|
-
return Object.keys(logic)[0];
|
|
5816
|
-
};
|
|
5817
|
-
jsonLogic2.get_values = function(logic) {
|
|
5818
|
-
return logic[jsonLogic2.get_operator(logic)];
|
|
5819
|
-
};
|
|
5820
|
-
jsonLogic2.apply = function(logic, data) {
|
|
5821
|
-
if (Array.isArray(logic)) {
|
|
5822
|
-
return logic.map(function(l) {
|
|
5823
|
-
return jsonLogic2.apply(l, data);
|
|
5824
|
-
});
|
|
5825
|
-
}
|
|
5826
|
-
if (!jsonLogic2.is_logic(logic)) {
|
|
5827
|
-
return logic;
|
|
5828
|
-
}
|
|
5829
|
-
var op = jsonLogic2.get_operator(logic);
|
|
5830
|
-
var values2 = logic[op];
|
|
5831
|
-
var i;
|
|
5832
|
-
var current;
|
|
5833
|
-
var scopedLogic;
|
|
5834
|
-
var scopedData;
|
|
5835
|
-
var initial;
|
|
5836
|
-
if (!Array.isArray(values2)) {
|
|
5837
|
-
values2 = [values2];
|
|
5838
|
-
}
|
|
5839
|
-
if (op === "if" || op == "?:") {
|
|
5840
|
-
for (i = 0; i < values2.length - 1; i += 2) {
|
|
5841
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(values2[i], data))) {
|
|
5842
|
-
return jsonLogic2.apply(values2[i + 1], data);
|
|
5843
|
-
}
|
|
5844
|
-
}
|
|
5845
|
-
if (values2.length === i + 1) {
|
|
5846
|
-
return jsonLogic2.apply(values2[i], data);
|
|
5847
|
-
}
|
|
5848
|
-
return null;
|
|
5849
|
-
} else if (op === "and") {
|
|
5850
|
-
for (i = 0; i < values2.length; i += 1) {
|
|
5851
|
-
current = jsonLogic2.apply(values2[i], data);
|
|
5852
|
-
if (!jsonLogic2.truthy(current)) {
|
|
5853
|
-
return current;
|
|
5854
|
-
}
|
|
5855
|
-
}
|
|
5856
|
-
return current;
|
|
5857
|
-
} else if (op === "or") {
|
|
5858
|
-
for (i = 0; i < values2.length; i += 1) {
|
|
5859
|
-
current = jsonLogic2.apply(values2[i], data);
|
|
5860
|
-
if (jsonLogic2.truthy(current)) {
|
|
5861
|
-
return current;
|
|
5862
|
-
}
|
|
5863
|
-
}
|
|
5864
|
-
return current;
|
|
5865
|
-
} else if (op === "filter") {
|
|
5866
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5867
|
-
scopedLogic = values2[1];
|
|
5868
|
-
if (!Array.isArray(scopedData)) {
|
|
5869
|
-
return [];
|
|
5870
|
-
}
|
|
5871
|
-
return scopedData.filter(function(datum) {
|
|
5872
|
-
return jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, datum));
|
|
5873
|
-
});
|
|
5874
|
-
} else if (op === "map") {
|
|
5875
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5876
|
-
scopedLogic = values2[1];
|
|
5877
|
-
if (!Array.isArray(scopedData)) {
|
|
5878
|
-
return [];
|
|
5879
|
-
}
|
|
5880
|
-
return scopedData.map(function(datum) {
|
|
5881
|
-
return jsonLogic2.apply(scopedLogic, datum);
|
|
5882
|
-
});
|
|
5883
|
-
} else if (op === "reduce") {
|
|
5884
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5885
|
-
scopedLogic = values2[1];
|
|
5886
|
-
initial = typeof values2[2] !== "undefined" ? values2[2] : null;
|
|
5887
|
-
if (!Array.isArray(scopedData)) {
|
|
5888
|
-
return initial;
|
|
5889
|
-
}
|
|
5890
|
-
return scopedData.reduce(
|
|
5891
|
-
function(accumulator, current2) {
|
|
5892
|
-
return jsonLogic2.apply(
|
|
5893
|
-
scopedLogic,
|
|
5894
|
-
{ current: current2, accumulator }
|
|
5895
|
-
);
|
|
5896
|
-
},
|
|
5897
|
-
initial
|
|
5898
|
-
);
|
|
5899
|
-
} else if (op === "all") {
|
|
5900
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5901
|
-
scopedLogic = values2[1];
|
|
5902
|
-
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5903
|
-
return false;
|
|
5904
|
-
}
|
|
5905
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
5906
|
-
if (!jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5907
|
-
return false;
|
|
5908
|
-
}
|
|
5909
|
-
}
|
|
5910
|
-
return true;
|
|
5911
|
-
} else if (op === "none") {
|
|
5912
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5913
|
-
scopedLogic = values2[1];
|
|
5914
|
-
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5915
|
-
return true;
|
|
5916
|
-
}
|
|
5917
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
5918
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5919
|
-
return false;
|
|
5920
|
-
}
|
|
5921
|
-
}
|
|
5922
|
-
return true;
|
|
5923
|
-
} else if (op === "some") {
|
|
5924
|
-
scopedData = jsonLogic2.apply(values2[0], data);
|
|
5925
|
-
scopedLogic = values2[1];
|
|
5926
|
-
if (!Array.isArray(scopedData) || !scopedData.length) {
|
|
5927
|
-
return false;
|
|
5928
|
-
}
|
|
5929
|
-
for (i = 0; i < scopedData.length; i += 1) {
|
|
5930
|
-
if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
|
|
5931
|
-
return true;
|
|
5932
|
-
}
|
|
5933
|
-
}
|
|
5934
|
-
return false;
|
|
5935
|
-
}
|
|
5936
|
-
values2 = values2.map(function(val) {
|
|
5937
|
-
return jsonLogic2.apply(val, data);
|
|
5938
|
-
});
|
|
5939
|
-
if (operations.hasOwnProperty(op) && typeof operations[op] === "function") {
|
|
5940
|
-
return operations[op].apply(data, values2);
|
|
5941
|
-
} else if (op.indexOf(".") > 0) {
|
|
5942
|
-
var sub_ops = String(op).split(".");
|
|
5943
|
-
var operation = operations;
|
|
5944
|
-
for (i = 0; i < sub_ops.length; i++) {
|
|
5945
|
-
if (!operation.hasOwnProperty(sub_ops[i])) {
|
|
5946
|
-
throw new Error("Unrecognized operation " + op + " (failed at " + sub_ops.slice(0, i + 1).join(".") + ")");
|
|
5947
|
-
}
|
|
5948
|
-
operation = operation[sub_ops[i]];
|
|
5949
|
-
}
|
|
5950
|
-
return operation.apply(data, values2);
|
|
5951
|
-
}
|
|
5952
|
-
throw new Error("Unrecognized operation " + op);
|
|
5953
|
-
};
|
|
5954
|
-
jsonLogic2.uses_data = function(logic) {
|
|
5955
|
-
var collection = [];
|
|
5956
|
-
if (jsonLogic2.is_logic(logic)) {
|
|
5957
|
-
var op = jsonLogic2.get_operator(logic);
|
|
5958
|
-
var values2 = logic[op];
|
|
5959
|
-
if (!Array.isArray(values2)) {
|
|
5960
|
-
values2 = [values2];
|
|
5961
|
-
}
|
|
5962
|
-
if (op === "var") {
|
|
5963
|
-
collection.push(values2[0]);
|
|
5964
|
-
} else {
|
|
5965
|
-
values2.forEach(function(val) {
|
|
5966
|
-
collection.push.apply(collection, jsonLogic2.uses_data(val));
|
|
5967
|
-
});
|
|
5968
|
-
}
|
|
5969
|
-
}
|
|
5970
|
-
return arrayUnique(collection);
|
|
5971
|
-
};
|
|
5972
|
-
jsonLogic2.add_operation = function(name, code) {
|
|
5973
|
-
operations[name] = code;
|
|
5974
|
-
};
|
|
5975
|
-
jsonLogic2.rm_operation = function(name) {
|
|
5976
|
-
delete operations[name];
|
|
5977
|
-
};
|
|
5978
|
-
jsonLogic2.rule_like = function(rule, pattern) {
|
|
5979
|
-
if (pattern === rule) {
|
|
5980
|
-
return true;
|
|
5981
|
-
}
|
|
5982
|
-
if (pattern === "@") {
|
|
5983
|
-
return true;
|
|
5984
|
-
}
|
|
5985
|
-
if (pattern === "number") {
|
|
5986
|
-
return typeof rule === "number";
|
|
5987
|
-
}
|
|
5988
|
-
if (pattern === "string") {
|
|
5989
|
-
return typeof rule === "string";
|
|
5990
|
-
}
|
|
5991
|
-
if (pattern === "array") {
|
|
5992
|
-
return Array.isArray(rule) && !jsonLogic2.is_logic(rule);
|
|
5993
|
-
}
|
|
5994
|
-
if (jsonLogic2.is_logic(pattern)) {
|
|
5995
|
-
if (jsonLogic2.is_logic(rule)) {
|
|
5996
|
-
var pattern_op = jsonLogic2.get_operator(pattern);
|
|
5997
|
-
var rule_op = jsonLogic2.get_operator(rule);
|
|
5998
|
-
if (pattern_op === "@" || pattern_op === rule_op) {
|
|
5999
|
-
return jsonLogic2.rule_like(
|
|
6000
|
-
jsonLogic2.get_values(rule, false),
|
|
6001
|
-
jsonLogic2.get_values(pattern, false)
|
|
6002
|
-
);
|
|
6003
|
-
}
|
|
6004
|
-
}
|
|
6005
|
-
return false;
|
|
6006
|
-
}
|
|
6007
|
-
if (Array.isArray(pattern)) {
|
|
6008
|
-
if (Array.isArray(rule)) {
|
|
6009
|
-
if (pattern.length !== rule.length) {
|
|
6010
|
-
return false;
|
|
6011
|
-
}
|
|
6012
|
-
for (var i = 0; i < pattern.length; i += 1) {
|
|
6013
|
-
if (!jsonLogic2.rule_like(rule[i], pattern[i])) {
|
|
6014
|
-
return false;
|
|
6015
|
-
}
|
|
6016
|
-
}
|
|
6017
|
-
return true;
|
|
6018
|
-
} else {
|
|
6019
|
-
return false;
|
|
6020
|
-
}
|
|
6021
|
-
}
|
|
6022
|
-
return false;
|
|
6023
|
-
};
|
|
6024
|
-
return jsonLogic2;
|
|
6025
|
-
});
|
|
6026
|
-
}
|
|
6027
|
-
});
|
|
6028
|
-
|
|
6029
5651
|
// node_modules/lodash/_createFlow.js
|
|
6030
5652
|
var require_createFlow = __commonJS({
|
|
6031
5653
|
"node_modules/lodash/_createFlow.js"(exports2, module2) {
|
|
@@ -11422,8 +11044,8 @@ function hasProperty(object2, propertyName) {
|
|
|
11422
11044
|
}
|
|
11423
11045
|
|
|
11424
11046
|
// src/checkIfConditionMatches.js
|
|
11425
|
-
function checkIfConditionMatches(node, formValues, formFields
|
|
11426
|
-
return Object.keys(node.if.properties
|
|
11047
|
+
function checkIfConditionMatches(node, formValues, formFields) {
|
|
11048
|
+
return Object.keys(node.if.properties).every((name) => {
|
|
11427
11049
|
const currentProperty = node.if.properties[name];
|
|
11428
11050
|
const value = formValues[name];
|
|
11429
11051
|
const hasEmptyValue = typeof value === "undefined" || // NOTE: This is a "Remote API" dependency, as empty fields are sent as "null".
|
|
@@ -11449,8 +11071,7 @@ function checkIfConditionMatches(node, formValues, formFields, validations) {
|
|
|
11449
11071
|
return checkIfConditionMatches(
|
|
11450
11072
|
{ if: currentProperty },
|
|
11451
11073
|
formValues[name],
|
|
11452
|
-
getField(name, formFields).fields
|
|
11453
|
-
validations
|
|
11074
|
+
getField(name, formFields).fields
|
|
11454
11075
|
);
|
|
11455
11076
|
}
|
|
11456
11077
|
const field = getField(name, formFields);
|
|
@@ -11466,23 +11087,6 @@ function checkIfConditionMatches(node, formValues, formFields, validations) {
|
|
|
11466
11087
|
);
|
|
11467
11088
|
});
|
|
11468
11089
|
}
|
|
11469
|
-
function checkIfMatchesValidationsAndComputedValues(node, formValues, validations, parentID) {
|
|
11470
|
-
const validationsMatch = Object.entries(node.if.validations ?? {}).every(([name, property2]) => {
|
|
11471
|
-
const currentValue = validations.getScope(parentID).evaluateValidationRuleInCondition(name, formValues);
|
|
11472
|
-
if (Object.hasOwn(property2, "const") && currentValue === property2.const)
|
|
11473
|
-
return true;
|
|
11474
|
-
return false;
|
|
11475
|
-
});
|
|
11476
|
-
const computedValuesMatch = Object.entries(node.if.computedValues ?? {}).every(
|
|
11477
|
-
([name, property2]) => {
|
|
11478
|
-
const currentValue = validations.getScope(parentID).evaluateComputedValueRuleInCondition(name, formValues);
|
|
11479
|
-
if (Object.hasOwn(property2, "const") && currentValue === property2.const)
|
|
11480
|
-
return true;
|
|
11481
|
-
return false;
|
|
11482
|
-
}
|
|
11483
|
-
);
|
|
11484
|
-
return computedValuesMatch && validationsMatch;
|
|
11485
|
-
}
|
|
11486
11090
|
|
|
11487
11091
|
// src/internals/helpers.js
|
|
11488
11092
|
var import_merge = __toESM(require_merge2());
|
|
@@ -11743,9 +11347,6 @@ function _composeFieldCustomClosure(defaultComposeFn) {
|
|
|
11743
11347
|
};
|
|
11744
11348
|
}
|
|
11745
11349
|
|
|
11746
|
-
// src/jsonLogic.js
|
|
11747
|
-
var import_json_logic_js = __toESM(require_logic());
|
|
11748
|
-
|
|
11749
11350
|
// src/yupSchema.js
|
|
11750
11351
|
var import_flow = __toESM(require_flow());
|
|
11751
11352
|
var import_noop = __toESM(require_noop());
|
|
@@ -11872,7 +11473,7 @@ var getYupSchema = ({ inputType, ...field }) => {
|
|
|
11872
11473
|
}
|
|
11873
11474
|
return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
|
|
11874
11475
|
};
|
|
11875
|
-
function buildYupSchema(field, config
|
|
11476
|
+
function buildYupSchema(field, config) {
|
|
11876
11477
|
const { inputType, jsonType: jsonTypeValue, errorMessage = {}, ...propertyFields } = field;
|
|
11877
11478
|
const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
|
|
11878
11479
|
let baseSchema;
|
|
@@ -11972,8 +11573,7 @@ function buildYupSchema(field, config, validations) {
|
|
|
11972
11573
|
...fieldSetfield,
|
|
11973
11574
|
inputType: fieldSetfield.type
|
|
11974
11575
|
},
|
|
11975
|
-
|
|
11976
|
-
validations
|
|
11576
|
+
config
|
|
11977
11577
|
)();
|
|
11978
11578
|
}
|
|
11979
11579
|
});
|
|
@@ -11984,11 +11584,7 @@ function buildYupSchema(field, config, validations) {
|
|
|
11984
11584
|
propertyFields.nthFieldGroup.fields().reduce(
|
|
11985
11585
|
(schema, groupArrayField) => ({
|
|
11986
11586
|
...schema,
|
|
11987
|
-
[groupArrayField.name]: buildYupSchema(
|
|
11988
|
-
groupArrayField,
|
|
11989
|
-
{ ...config, parentID: `${propertyFields.nthFieldGroup.name}[]` },
|
|
11990
|
-
validations
|
|
11991
|
-
)()
|
|
11587
|
+
[groupArrayField.name]: buildYupSchema(groupArrayField, config)()
|
|
11992
11588
|
}),
|
|
11993
11589
|
{}
|
|
11994
11590
|
)
|
|
@@ -12027,11 +11623,6 @@ function buildYupSchema(field, config, validations) {
|
|
|
12027
11623
|
if (propertyFields.const) {
|
|
12028
11624
|
validators.push(withConst);
|
|
12029
11625
|
}
|
|
12030
|
-
if (propertyFields.requiredValidations) {
|
|
12031
|
-
propertyFields.requiredValidations.forEach(
|
|
12032
|
-
(id) => validators.push(yupSchemaWithCustomJSONLogic({ field, id, validations, config }))
|
|
12033
|
-
);
|
|
12034
|
-
}
|
|
12035
11626
|
return (0, import_flow.default)(validators);
|
|
12036
11627
|
}
|
|
12037
11628
|
function getNoSortEdges(fields = []) {
|
|
@@ -12042,322 +11633,26 @@ function getNoSortEdges(fields = []) {
|
|
|
12042
11633
|
return list;
|
|
12043
11634
|
}, []);
|
|
12044
11635
|
}
|
|
12045
|
-
function getSchema(fields = [], config
|
|
11636
|
+
function getSchema(fields = [], config) {
|
|
12046
11637
|
const newSchema = {};
|
|
12047
11638
|
fields.forEach((field) => {
|
|
12048
11639
|
if (field.schema) {
|
|
12049
11640
|
if (field.name) {
|
|
12050
11641
|
if (field.inputType === supportedTypes.FIELDSET) {
|
|
12051
|
-
const fieldsetSchema = buildYupSchema(
|
|
12052
|
-
field,
|
|
12053
|
-
{ ...config, parentID: field.name },
|
|
12054
|
-
validations
|
|
12055
|
-
)();
|
|
11642
|
+
const fieldsetSchema = buildYupSchema(field, config)();
|
|
12056
11643
|
newSchema[field.name] = fieldsetSchema;
|
|
12057
11644
|
} else {
|
|
12058
11645
|
newSchema[field.name] = field.schema;
|
|
12059
11646
|
}
|
|
12060
11647
|
} else {
|
|
12061
|
-
Object.assign(newSchema, getSchema(field.fields, config
|
|
11648
|
+
Object.assign(newSchema, getSchema(field.fields, config));
|
|
12062
11649
|
}
|
|
12063
11650
|
}
|
|
12064
11651
|
});
|
|
12065
11652
|
return newSchema;
|
|
12066
11653
|
}
|
|
12067
|
-
function buildCompleteYupSchema(fields, config
|
|
12068
|
-
return ObjectSchema().shape(getSchema(fields, config
|
|
12069
|
-
}
|
|
12070
|
-
|
|
12071
|
-
// src/jsonLogic.js
|
|
12072
|
-
function createValidationChecker(schema) {
|
|
12073
|
-
const scopes = /* @__PURE__ */ new Map();
|
|
12074
|
-
function createScopes(jsonSchema, key = "root") {
|
|
12075
|
-
const sampleEmptyObject = buildSampleEmptyObject(schema);
|
|
12076
|
-
scopes.set(key, createValidationsScope(jsonSchema));
|
|
12077
|
-
Object.entries(jsonSchema?.properties ?? {}).filter(([, property2]) => property2.type === "object" || property2.type === "array").forEach(([key2, property2]) => {
|
|
12078
|
-
if (property2.type === "array") {
|
|
12079
|
-
createScopes(property2.items, `${key2}[]`);
|
|
12080
|
-
}
|
|
12081
|
-
createScopes(property2, key2);
|
|
12082
|
-
});
|
|
12083
|
-
validateInlineRules(jsonSchema, sampleEmptyObject);
|
|
12084
|
-
}
|
|
12085
|
-
createScopes(schema);
|
|
12086
|
-
return {
|
|
12087
|
-
scopes,
|
|
12088
|
-
getScope(name = "root") {
|
|
12089
|
-
return scopes.get(name);
|
|
12090
|
-
}
|
|
12091
|
-
};
|
|
12092
|
-
}
|
|
12093
|
-
function createValidationsScope(schema) {
|
|
12094
|
-
const validationMap = /* @__PURE__ */ new Map();
|
|
12095
|
-
const computedValuesMap = /* @__PURE__ */ new Map();
|
|
12096
|
-
const logic = schema?.["x-jsf-logic"] ?? {
|
|
12097
|
-
validations: {},
|
|
12098
|
-
computedValues: {}
|
|
12099
|
-
};
|
|
12100
|
-
const validations = Object.entries(logic.validations ?? {});
|
|
12101
|
-
const computedValues = Object.entries(logic.computedValues ?? {});
|
|
12102
|
-
const sampleEmptyObject = buildSampleEmptyObject(schema);
|
|
12103
|
-
validations.forEach(([id, validation]) => {
|
|
12104
|
-
if (!validation.rule) {
|
|
12105
|
-
throw Error(`Missing rule for validation with id of: "${id}".`);
|
|
12106
|
-
}
|
|
12107
|
-
checkRuleIntegrity(validation.rule, id, sampleEmptyObject);
|
|
12108
|
-
validationMap.set(id, validation);
|
|
12109
|
-
});
|
|
12110
|
-
computedValues.forEach(([id, computedValue]) => {
|
|
12111
|
-
if (!computedValue.rule) {
|
|
12112
|
-
throw Error(`Missing rule for computedValue with id of: "${id}".`);
|
|
12113
|
-
}
|
|
12114
|
-
checkRuleIntegrity(computedValue.rule, id, sampleEmptyObject);
|
|
12115
|
-
computedValuesMap.set(id, computedValue);
|
|
12116
|
-
});
|
|
12117
|
-
function evaluateValidation(rule, values2) {
|
|
12118
|
-
return import_json_logic_js.default.apply(rule, clean(values2));
|
|
12119
|
-
}
|
|
12120
|
-
return {
|
|
12121
|
-
validationMap,
|
|
12122
|
-
computedValuesMap,
|
|
12123
|
-
evaluateValidation,
|
|
12124
|
-
evaluateValidationRuleInCondition(id, values2) {
|
|
12125
|
-
const validation = validationMap.get(id);
|
|
12126
|
-
if (validation === void 0)
|
|
12127
|
-
throw Error(`"${id}" validation in if condition doesn't exist.`);
|
|
12128
|
-
return evaluateValidation(validation.rule, values2);
|
|
12129
|
-
},
|
|
12130
|
-
evaluateComputedValueRuleForField(id, values2, fieldName) {
|
|
12131
|
-
const validation = computedValuesMap.get(id);
|
|
12132
|
-
if (validation === void 0)
|
|
12133
|
-
throw Error(`"${id}" computedValue in field "${fieldName}" doesn't exist.`);
|
|
12134
|
-
return evaluateValidation(validation.rule, values2);
|
|
12135
|
-
},
|
|
12136
|
-
evaluateComputedValueRuleInCondition(id, values2) {
|
|
12137
|
-
const validation = computedValuesMap.get(id);
|
|
12138
|
-
if (validation === void 0)
|
|
12139
|
-
throw Error(`"${id}" computedValue in if condition doesn't exist.`);
|
|
12140
|
-
return evaluateValidation(validation.rule, values2);
|
|
12141
|
-
}
|
|
12142
|
-
};
|
|
12143
|
-
}
|
|
12144
|
-
function clean(values2 = {}) {
|
|
12145
|
-
return Object.entries(values2).reduce((prev, [key, value]) => {
|
|
12146
|
-
return { ...prev, [key]: value === void 0 ? null : value };
|
|
12147
|
-
}, {});
|
|
12148
|
-
}
|
|
12149
|
-
function yupSchemaWithCustomJSONLogic({ field, validations, config, id }) {
|
|
12150
|
-
const { parentID = "root" } = config;
|
|
12151
|
-
const validation = validations.getScope(parentID).validationMap.get(id);
|
|
12152
|
-
if (validation === void 0) {
|
|
12153
|
-
throw Error(`Validation "${id}" required for "${field.name}" doesn't exist.`);
|
|
12154
|
-
}
|
|
12155
|
-
return (yupSchema) => yupSchema.test(
|
|
12156
|
-
`${field.name}-validation-${id}`,
|
|
12157
|
-
validation?.errorMessage ?? "This field is invalid.",
|
|
12158
|
-
(value, { parent }) => {
|
|
12159
|
-
if (value === void 0 && !field.required)
|
|
12160
|
-
return true;
|
|
12161
|
-
return import_json_logic_js.default.apply(validation.rule, parent);
|
|
12162
|
-
}
|
|
12163
|
-
);
|
|
12164
|
-
}
|
|
12165
|
-
function replaceHandlebarsTemplates({
|
|
12166
|
-
value: toReplace,
|
|
12167
|
-
validations,
|
|
12168
|
-
formValues,
|
|
12169
|
-
parentID,
|
|
12170
|
-
name: fieldName
|
|
12171
|
-
}) {
|
|
12172
|
-
if (typeof toReplace === "string") {
|
|
12173
|
-
return toReplace.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
12174
|
-
return validations.getScope(parentID).evaluateComputedValueRuleForField(key.trim(), formValues, fieldName);
|
|
12175
|
-
});
|
|
12176
|
-
} else if (typeof toReplace === "object") {
|
|
12177
|
-
const { value, ...rules } = toReplace;
|
|
12178
|
-
if (Object.keys(rules).length > 1 && !value)
|
|
12179
|
-
throw Error("Cannot define multiple rules without a template string with key `value`.");
|
|
12180
|
-
const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
|
|
12181
|
-
const computedValue = validations.getScope(parentID).evaluateValidation(rule, formValues);
|
|
12182
|
-
return prev.replaceAll(`{{${key}}}`, computedValue);
|
|
12183
|
-
}, value);
|
|
12184
|
-
return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
|
|
12185
|
-
return validations.getScope(parentID).evaluateComputedValueRuleForField(key.trim(), formValues, fieldName);
|
|
12186
|
-
});
|
|
12187
|
-
}
|
|
12188
|
-
}
|
|
12189
|
-
function calculateComputedAttributes(fieldParams, { parentID = "root" } = {}) {
|
|
12190
|
-
return ({ validations, isRequired, config, formValues }) => {
|
|
12191
|
-
const { name, computedAttributes } = fieldParams;
|
|
12192
|
-
const attributes = Object.fromEntries(
|
|
12193
|
-
Object.entries(computedAttributes).map(handleComputedAttribute(validations, formValues, parentID, name)).filter(([, value]) => value !== null)
|
|
12194
|
-
);
|
|
12195
|
-
return {
|
|
12196
|
-
...attributes,
|
|
12197
|
-
schema: buildYupSchema(
|
|
12198
|
-
{ ...fieldParams, ...attributes, required: isRequired },
|
|
12199
|
-
config,
|
|
12200
|
-
validations
|
|
12201
|
-
)
|
|
12202
|
-
};
|
|
12203
|
-
};
|
|
12204
|
-
}
|
|
12205
|
-
function handleComputedAttribute(validations, formValues, parentID, name) {
|
|
12206
|
-
return ([key, value]) => {
|
|
12207
|
-
if (key === "description")
|
|
12208
|
-
return [key, replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })];
|
|
12209
|
-
if (key === "title") {
|
|
12210
|
-
return [
|
|
12211
|
-
"label",
|
|
12212
|
-
replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })
|
|
12213
|
-
];
|
|
12214
|
-
}
|
|
12215
|
-
if (key === "const")
|
|
12216
|
-
return [
|
|
12217
|
-
key,
|
|
12218
|
-
validations.getScope(parentID).evaluateComputedValueRuleForField(value, formValues, name)
|
|
12219
|
-
];
|
|
12220
|
-
if (key === "x-jsf-errorMessage") {
|
|
12221
|
-
return [
|
|
12222
|
-
"errorMessage",
|
|
12223
|
-
handleNestedObjectForComputedValues(value, formValues, parentID, validations, name)
|
|
12224
|
-
];
|
|
12225
|
-
}
|
|
12226
|
-
if (typeof value === "string") {
|
|
12227
|
-
return [
|
|
12228
|
-
key,
|
|
12229
|
-
validations.getScope(parentID).evaluateComputedValueRuleForField(value, formValues, name)
|
|
12230
|
-
];
|
|
12231
|
-
}
|
|
12232
|
-
if (key === "x-jsf-presentation" && value.statement) {
|
|
12233
|
-
return [
|
|
12234
|
-
"statement",
|
|
12235
|
-
handleNestedObjectForComputedValues(
|
|
12236
|
-
value.statement,
|
|
12237
|
-
formValues,
|
|
12238
|
-
parentID,
|
|
12239
|
-
validations,
|
|
12240
|
-
name
|
|
12241
|
-
)
|
|
12242
|
-
];
|
|
12243
|
-
}
|
|
12244
|
-
if (typeof value === "object" && value.rule) {
|
|
12245
|
-
return [key, validations.getScope(parentID).evaluateValidation(value.rule, formValues)];
|
|
12246
|
-
}
|
|
12247
|
-
};
|
|
12248
|
-
}
|
|
12249
|
-
function handleNestedObjectForComputedValues(values2, formValues, parentID, validations, name) {
|
|
12250
|
-
return Object.fromEntries(
|
|
12251
|
-
Object.entries(values2).map(([key, value]) => {
|
|
12252
|
-
return [key, replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })];
|
|
12253
|
-
})
|
|
12254
|
-
);
|
|
12255
|
-
}
|
|
12256
|
-
function processJSONLogicNode({
|
|
12257
|
-
node,
|
|
12258
|
-
formFields,
|
|
12259
|
-
formValues,
|
|
12260
|
-
accRequired,
|
|
12261
|
-
parentID,
|
|
12262
|
-
validations
|
|
12263
|
-
}) {
|
|
12264
|
-
const requiredFields = new Set(accRequired);
|
|
12265
|
-
if (node.allOf) {
|
|
12266
|
-
node.allOf.map(
|
|
12267
|
-
(allOfNode) => processJSONLogicNode({ node: allOfNode, formValues, formFields, validations, parentID })
|
|
12268
|
-
).forEach(({ required: allOfItemRequired }) => {
|
|
12269
|
-
allOfItemRequired.forEach(requiredFields.add, requiredFields);
|
|
12270
|
-
});
|
|
12271
|
-
}
|
|
12272
|
-
if (node.if) {
|
|
12273
|
-
const matchesPropertyCondition = checkIfConditionMatches(
|
|
12274
|
-
node,
|
|
12275
|
-
formValues,
|
|
12276
|
-
formFields,
|
|
12277
|
-
validations
|
|
12278
|
-
);
|
|
12279
|
-
const matchesValidationsAndComputedValues = checkIfMatchesValidationsAndComputedValues(
|
|
12280
|
-
node,
|
|
12281
|
-
formValues,
|
|
12282
|
-
validations,
|
|
12283
|
-
parentID
|
|
12284
|
-
);
|
|
12285
|
-
const isConditionMatch = matchesPropertyCondition && matchesValidationsAndComputedValues;
|
|
12286
|
-
if (isConditionMatch && node.then) {
|
|
12287
|
-
const { required: branchRequired } = processNode({
|
|
12288
|
-
node: node.then,
|
|
12289
|
-
formValues,
|
|
12290
|
-
formFields,
|
|
12291
|
-
accRequired,
|
|
12292
|
-
validations
|
|
12293
|
-
});
|
|
12294
|
-
branchRequired.forEach((field) => requiredFields.add(field));
|
|
12295
|
-
}
|
|
12296
|
-
if (!isConditionMatch && node.else) {
|
|
12297
|
-
const { required: branchRequired } = processNode({
|
|
12298
|
-
node: node.else,
|
|
12299
|
-
formValues,
|
|
12300
|
-
formFields,
|
|
12301
|
-
accRequired: requiredFields,
|
|
12302
|
-
validations
|
|
12303
|
-
});
|
|
12304
|
-
branchRequired.forEach((field) => requiredFields.add(field));
|
|
12305
|
-
}
|
|
12306
|
-
}
|
|
12307
|
-
return { required: requiredFields };
|
|
12308
|
-
}
|
|
12309
|
-
function buildSampleEmptyObject(schema = {}) {
|
|
12310
|
-
const sample = {};
|
|
12311
|
-
if (typeof schema !== "object" || !schema.properties) {
|
|
12312
|
-
return schema;
|
|
12313
|
-
}
|
|
12314
|
-
for (const key in schema.properties) {
|
|
12315
|
-
if (schema.properties[key].type === "object") {
|
|
12316
|
-
sample[key] = buildSampleEmptyObject(schema.properties[key]);
|
|
12317
|
-
} else if (schema.properties[key].type === "array") {
|
|
12318
|
-
const itemSchema = schema.properties[key].items;
|
|
12319
|
-
sample[key] = buildSampleEmptyObject(itemSchema);
|
|
12320
|
-
} else {
|
|
12321
|
-
sample[key] = true;
|
|
12322
|
-
}
|
|
12323
|
-
}
|
|
12324
|
-
return sample;
|
|
12325
|
-
}
|
|
12326
|
-
function validateInlineRules(jsonSchema, sampleEmptyObject) {
|
|
12327
|
-
const properties = (jsonSchema?.properties || jsonSchema?.items?.properties) ?? {};
|
|
12328
|
-
Object.entries(properties).filter(([, property2]) => property2["x-jsf-logic-computedAttrs"] !== void 0).forEach(([fieldName, property2]) => {
|
|
12329
|
-
Object.entries(property2["x-jsf-logic-computedAttrs"]).filter(([, value]) => typeof value === "object").forEach(([key, item]) => {
|
|
12330
|
-
Object.values(item).forEach((rule) => {
|
|
12331
|
-
checkRuleIntegrity(
|
|
12332
|
-
rule,
|
|
12333
|
-
fieldName,
|
|
12334
|
-
sampleEmptyObject,
|
|
12335
|
-
(item2) => `"${item2.var}" in inline rule in property "${fieldName}.x-jsf-logic-computedAttrs.${key}" does not exist as a JSON schema property.`
|
|
12336
|
-
);
|
|
12337
|
-
});
|
|
12338
|
-
});
|
|
12339
|
-
});
|
|
12340
|
-
}
|
|
12341
|
-
function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `"${item.var}" in rule "${id}" does not exist as a JSON schema property.`) {
|
|
12342
|
-
Object.values(rule ?? {}).map((subRule) => {
|
|
12343
|
-
if (!Array.isArray(subRule) && subRule !== null && subRule !== void 0)
|
|
12344
|
-
return;
|
|
12345
|
-
subRule.map((item) => {
|
|
12346
|
-
const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
|
|
12347
|
-
if (isVar) {
|
|
12348
|
-
const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
|
|
12349
|
-
if (exists === null) {
|
|
12350
|
-
throw Error(errorMessage(item));
|
|
12351
|
-
}
|
|
12352
|
-
} else {
|
|
12353
|
-
checkRuleIntegrity(item, id, data);
|
|
12354
|
-
}
|
|
12355
|
-
});
|
|
12356
|
-
});
|
|
12357
|
-
}
|
|
12358
|
-
function removeIndicesFromPath(path) {
|
|
12359
|
-
const intermediatePath = path.replace(/\.\d+\./g, ".");
|
|
12360
|
-
return intermediatePath.replace(/\.\d+$/, "");
|
|
11654
|
+
function buildCompleteYupSchema(fields, config) {
|
|
11655
|
+
return ObjectSchema().shape(getSchema(fields, config), getNoSortEdges(fields));
|
|
12361
11656
|
}
|
|
12362
11657
|
|
|
12363
11658
|
// src/helpers.js
|
|
@@ -12367,8 +11662,8 @@ function hasType(type, typeName) {
|
|
|
12367
11662
|
function getField(fieldName, fields) {
|
|
12368
11663
|
return fields.find(({ name }) => name === fieldName);
|
|
12369
11664
|
}
|
|
12370
|
-
function validateFieldSchema(field, value
|
|
12371
|
-
const validator = buildYupSchema(field
|
|
11665
|
+
function validateFieldSchema(field, value) {
|
|
11666
|
+
const validator = buildYupSchema(field);
|
|
12372
11667
|
return validator().isValidSync(value);
|
|
12373
11668
|
}
|
|
12374
11669
|
function compareFormValueWithSchemaValue(formValue, schemaValue) {
|
|
@@ -12433,7 +11728,7 @@ function getPrefillValues(fields, initialValues = {}) {
|
|
|
12433
11728
|
});
|
|
12434
11729
|
return initialValues;
|
|
12435
11730
|
}
|
|
12436
|
-
function updateField(field, requiredFields, node, formValues
|
|
11731
|
+
function updateField(field, requiredFields, node, formValues) {
|
|
12437
11732
|
if (!field) {
|
|
12438
11733
|
return;
|
|
12439
11734
|
}
|
|
@@ -12455,25 +11750,8 @@ function updateField(field, requiredFields, node, formValues, validations, confi
|
|
|
12455
11750
|
}
|
|
12456
11751
|
}
|
|
12457
11752
|
});
|
|
12458
|
-
if (field.getComputedAttributes) {
|
|
12459
|
-
const computedFieldValues = field.getComputedAttributes({
|
|
12460
|
-
field,
|
|
12461
|
-
isRequired: fieldIsRequired,
|
|
12462
|
-
node,
|
|
12463
|
-
formValues,
|
|
12464
|
-
config,
|
|
12465
|
-
validations
|
|
12466
|
-
});
|
|
12467
|
-
updateValues(computedFieldValues);
|
|
12468
|
-
}
|
|
12469
11753
|
if (field.calculateConditionalProperties) {
|
|
12470
|
-
const newFieldValues = field.calculateConditionalProperties(
|
|
12471
|
-
fieldIsRequired,
|
|
12472
|
-
node,
|
|
12473
|
-
validations,
|
|
12474
|
-
config,
|
|
12475
|
-
formValues
|
|
12476
|
-
);
|
|
11754
|
+
const newFieldValues = field.calculateConditionalProperties(fieldIsRequired, node);
|
|
12477
11755
|
updateValues(newFieldValues);
|
|
12478
11756
|
}
|
|
12479
11757
|
if (field.calculateCustomValidationProperties) {
|
|
@@ -12485,46 +11763,33 @@ function updateField(field, requiredFields, node, formValues, validations, confi
|
|
|
12485
11763
|
updateValues(newFieldValues);
|
|
12486
11764
|
}
|
|
12487
11765
|
}
|
|
12488
|
-
function processNode({
|
|
12489
|
-
node,
|
|
12490
|
-
formValues,
|
|
12491
|
-
formFields,
|
|
12492
|
-
accRequired = /* @__PURE__ */ new Set(),
|
|
12493
|
-
parentID = "root",
|
|
12494
|
-
validations
|
|
12495
|
-
}) {
|
|
11766
|
+
function processNode(node, formValues, formFields, accRequired = /* @__PURE__ */ new Set()) {
|
|
12496
11767
|
const requiredFields = new Set(accRequired);
|
|
12497
11768
|
Object.keys(node.properties ?? []).forEach((fieldName) => {
|
|
12498
11769
|
const field = getField(fieldName, formFields);
|
|
12499
|
-
updateField(field, requiredFields, node, formValues
|
|
11770
|
+
updateField(field, requiredFields, node, formValues);
|
|
12500
11771
|
});
|
|
12501
11772
|
node.required?.forEach((fieldName) => {
|
|
12502
11773
|
requiredFields.add(fieldName);
|
|
12503
|
-
updateField(getField(fieldName, formFields), requiredFields, node, formValues
|
|
12504
|
-
parentID
|
|
12505
|
-
});
|
|
11774
|
+
updateField(getField(fieldName, formFields), requiredFields, node, formValues);
|
|
12506
11775
|
});
|
|
12507
11776
|
if (node.if) {
|
|
12508
|
-
const matchesCondition = checkIfConditionMatches(node, formValues, formFields
|
|
11777
|
+
const matchesCondition = checkIfConditionMatches(node, formValues, formFields);
|
|
12509
11778
|
if (matchesCondition && node.then) {
|
|
12510
|
-
const { required: branchRequired } = processNode(
|
|
12511
|
-
node
|
|
11779
|
+
const { required: branchRequired } = processNode(
|
|
11780
|
+
node.then,
|
|
12512
11781
|
formValues,
|
|
12513
11782
|
formFields,
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
validations
|
|
12517
|
-
});
|
|
11783
|
+
requiredFields
|
|
11784
|
+
);
|
|
12518
11785
|
branchRequired.forEach((field) => requiredFields.add(field));
|
|
12519
11786
|
} else if (node.else) {
|
|
12520
|
-
const { required: branchRequired } = processNode(
|
|
12521
|
-
node
|
|
11787
|
+
const { required: branchRequired } = processNode(
|
|
11788
|
+
node.else,
|
|
12522
11789
|
formValues,
|
|
12523
11790
|
formFields,
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
validations
|
|
12527
|
-
});
|
|
11791
|
+
requiredFields
|
|
11792
|
+
);
|
|
12528
11793
|
branchRequired.forEach((field) => requiredFields.add(field));
|
|
12529
11794
|
}
|
|
12530
11795
|
}
|
|
@@ -12536,21 +11801,12 @@ function processNode({
|
|
|
12536
11801
|
node.anyOf.forEach(({ required: required2 = [] }) => {
|
|
12537
11802
|
required2.forEach((fieldName) => {
|
|
12538
11803
|
const field = getField(fieldName, formFields);
|
|
12539
|
-
updateField(field, requiredFields, node, formValues
|
|
11804
|
+
updateField(field, requiredFields, node, formValues);
|
|
12540
11805
|
});
|
|
12541
11806
|
});
|
|
12542
11807
|
}
|
|
12543
11808
|
if (node.allOf) {
|
|
12544
|
-
node.allOf.map(
|
|
12545
|
-
(allOfNode) => processNode({
|
|
12546
|
-
node: allOfNode,
|
|
12547
|
-
formValues,
|
|
12548
|
-
formFields,
|
|
12549
|
-
accRequired: requiredFields,
|
|
12550
|
-
parentID,
|
|
12551
|
-
validations
|
|
12552
|
-
})
|
|
12553
|
-
).forEach(({ required: allOfItemRequired }) => {
|
|
11809
|
+
node.allOf.map((allOfNode) => processNode(allOfNode, formValues, formFields, requiredFields)).forEach(({ required: allOfItemRequired }) => {
|
|
12554
11810
|
allOfItemRequired.forEach(requiredFields.add, requiredFields);
|
|
12555
11811
|
});
|
|
12556
11812
|
}
|
|
@@ -12558,27 +11814,10 @@ function processNode({
|
|
|
12558
11814
|
Object.entries(node.properties).forEach(([name, nestedNode]) => {
|
|
12559
11815
|
const inputType = getInputType(nestedNode);
|
|
12560
11816
|
if (inputType === supportedTypes.FIELDSET) {
|
|
12561
|
-
processNode({
|
|
12562
|
-
node: nestedNode,
|
|
12563
|
-
formValues: formValues[name] || {},
|
|
12564
|
-
formFields: getField(name, formFields).fields,
|
|
12565
|
-
validations,
|
|
12566
|
-
parentID: name
|
|
12567
|
-
});
|
|
11817
|
+
processNode(nestedNode, formValues[name] || {}, getField(name, formFields).fields);
|
|
12568
11818
|
}
|
|
12569
11819
|
});
|
|
12570
11820
|
}
|
|
12571
|
-
if (node["x-jsf-logic"]) {
|
|
12572
|
-
const { required: requiredFromLogic } = processJSONLogicNode({
|
|
12573
|
-
node: node["x-jsf-logic"],
|
|
12574
|
-
formValues,
|
|
12575
|
-
formFields,
|
|
12576
|
-
accRequired: requiredFields,
|
|
12577
|
-
parentID,
|
|
12578
|
-
validations
|
|
12579
|
-
});
|
|
12580
|
-
requiredFromLogic.forEach((field) => requiredFields.add(field));
|
|
12581
|
-
}
|
|
12582
11821
|
return {
|
|
12583
11822
|
required: requiredFields
|
|
12584
11823
|
};
|
|
@@ -12593,11 +11832,11 @@ function clearValuesIfNotVisible(fields, formValues) {
|
|
|
12593
11832
|
}
|
|
12594
11833
|
});
|
|
12595
11834
|
}
|
|
12596
|
-
function updateFieldsProperties(fields, formValues, jsonSchema
|
|
11835
|
+
function updateFieldsProperties(fields, formValues, jsonSchema) {
|
|
12597
11836
|
if (!jsonSchema?.properties) {
|
|
12598
11837
|
return;
|
|
12599
11838
|
}
|
|
12600
|
-
processNode(
|
|
11839
|
+
processNode(jsonSchema, formValues, fields);
|
|
12601
11840
|
clearValuesIfNotVisible(fields, formValues);
|
|
12602
11841
|
}
|
|
12603
11842
|
var notNullOption = (opt) => opt.const !== null;
|
|
@@ -12640,20 +11879,12 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12640
11879
|
}
|
|
12641
11880
|
const presentation = pickXKey(schemaNode, "presentation") ?? {};
|
|
12642
11881
|
const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
|
|
12643
|
-
const requiredValidations = schemaNode["x-jsf-logic-validations"];
|
|
12644
|
-
const computedAttributes = schemaNode["x-jsf-logic-computedAttrs"];
|
|
12645
|
-
const decoratedComputedAttributes = {
|
|
12646
|
-
...computedAttributes ?? {},
|
|
12647
|
-
...computedAttributes?.const && computedAttributes?.default ? { value: computedAttributes.const } : {}
|
|
12648
|
-
};
|
|
12649
11882
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12650
11883
|
const description = presentation?.description || node.description;
|
|
12651
11884
|
const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
|
|
12652
11885
|
return (0, import_omitBy.default)(
|
|
12653
11886
|
{
|
|
12654
11887
|
const: node.const,
|
|
12655
|
-
// This is a "forced value" when both const and default are present.
|
|
12656
|
-
...node.const && node.default ? { value: node.const } : {},
|
|
12657
11888
|
label: node.title,
|
|
12658
11889
|
readOnly: node.readOnly,
|
|
12659
11890
|
...node.deprecated && {
|
|
@@ -12688,8 +11919,6 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12688
11919
|
},
|
|
12689
11920
|
// Handle [name].presentation
|
|
12690
11921
|
...presentation,
|
|
12691
|
-
requiredValidations,
|
|
12692
|
-
computedAttributes: decoratedComputedAttributes,
|
|
12693
11922
|
description: containsHTML(description) ? wrapWithSpan(description, {
|
|
12694
11923
|
class: "jsf-description"
|
|
12695
11924
|
}) : description,
|
|
@@ -12726,9 +11955,9 @@ function yupToFormErrors(yupError) {
|
|
|
12726
11955
|
}
|
|
12727
11956
|
return errors;
|
|
12728
11957
|
}
|
|
12729
|
-
var handleValuesChange = (fields, jsonSchema, config
|
|
12730
|
-
updateFieldsProperties(fields, values2, jsonSchema
|
|
12731
|
-
const lazySchema = lazy(() => buildCompleteYupSchema(fields, config
|
|
11958
|
+
var handleValuesChange = (fields, jsonSchema, config) => (values2) => {
|
|
11959
|
+
updateFieldsProperties(fields, values2, jsonSchema);
|
|
11960
|
+
const lazySchema = lazy(() => buildCompleteYupSchema(fields, config));
|
|
12732
11961
|
let errors;
|
|
12733
11962
|
try {
|
|
12734
11963
|
lazySchema.validateSync(values2, {
|
|
@@ -12782,8 +12011,8 @@ function rebuildFieldset(fields, property2) {
|
|
|
12782
12011
|
required: isFieldRequired(property2, field)
|
|
12783
12012
|
}));
|
|
12784
12013
|
}
|
|
12785
|
-
function calculateConditionalProperties(fieldParams, customProperties
|
|
12786
|
-
return (isRequired, conditionBranch
|
|
12014
|
+
function calculateConditionalProperties(fieldParams, customProperties) {
|
|
12015
|
+
return (isRequired, conditionBranch) => {
|
|
12787
12016
|
const conditionalProperty = conditionBranch?.properties?.[fieldParams.name];
|
|
12788
12017
|
if (conditionalProperty) {
|
|
12789
12018
|
const presentation = pickXKey(conditionalProperty, "presentation") ?? {};
|
|
@@ -12797,31 +12026,17 @@ function calculateConditionalProperties(fieldParams, customProperties, validatio
|
|
|
12797
12026
|
fieldSetFields = rebuildFieldset(fieldParams.fields, conditionalProperty);
|
|
12798
12027
|
newFieldParams.fields = fieldSetFields;
|
|
12799
12028
|
}
|
|
12800
|
-
const { computedAttributes, ...restNewFieldParams } = newFieldParams;
|
|
12801
|
-
const calculatedComputedAttributes = computedAttributes ? calculateComputedAttributes(newFieldParams, config)({ validations, formValues }) : {};
|
|
12802
|
-
const requiredValidations = [
|
|
12803
|
-
...fieldParams.requiredValidations ?? [],
|
|
12804
|
-
...restNewFieldParams.requiredValidations ?? []
|
|
12805
|
-
];
|
|
12806
12029
|
const base = {
|
|
12807
12030
|
isVisible: true,
|
|
12808
12031
|
required: isRequired,
|
|
12809
12032
|
...presentation?.inputType && { type: presentation.inputType },
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
requiredValidations,
|
|
12818
|
-
// If there are inner fields (case of fieldset) they need to be updated based on the condition
|
|
12819
|
-
fields: fieldSetFields,
|
|
12820
|
-
required: isRequired
|
|
12821
|
-
},
|
|
12822
|
-
config,
|
|
12823
|
-
validations
|
|
12824
|
-
)
|
|
12033
|
+
schema: buildYupSchema({
|
|
12034
|
+
...fieldParams,
|
|
12035
|
+
...newFieldParams,
|
|
12036
|
+
// If there are inner fields (case of fieldset) they need to be updated based on the condition
|
|
12037
|
+
fields: fieldSetFields,
|
|
12038
|
+
required: isRequired
|
|
12039
|
+
})
|
|
12825
12040
|
};
|
|
12826
12041
|
return (0, import_omit2.default)((0, import_merge2.default)(base, presentation, newFieldParams), ["inputType"]);
|
|
12827
12042
|
}
|
|
@@ -12915,19 +12130,14 @@ function sortByOrderOrPosition(a, b, order) {
|
|
|
12915
12130
|
function removeInvalidAttributes(fields) {
|
|
12916
12131
|
return (0, import_omit3.default)(fields, ["items", "maxFileSize", "isDynamic"]);
|
|
12917
12132
|
}
|
|
12918
|
-
function buildFieldParameters(name, fieldProperties, required2 = [], config = {}
|
|
12133
|
+
function buildFieldParameters(name, fieldProperties, required2 = [], config = {}) {
|
|
12919
12134
|
const { position } = pickXKey(fieldProperties, "presentation") ?? {};
|
|
12920
12135
|
let fields;
|
|
12921
12136
|
const inputType = getInputType(fieldProperties, config.strictInputType, name);
|
|
12922
12137
|
if (inputType === supportedTypes.FIELDSET) {
|
|
12923
|
-
fields = getFieldsFromJSONSchema(
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
customProperties: (0, import_get4.default)(config, `customProperties.${name}`, {}),
|
|
12927
|
-
parentID: name
|
|
12928
|
-
},
|
|
12929
|
-
validations
|
|
12930
|
-
);
|
|
12138
|
+
fields = getFieldsFromJSONSchema(fieldProperties, {
|
|
12139
|
+
customProperties: (0, import_get4.default)(config, `customProperties.${name}`, {})
|
|
12140
|
+
});
|
|
12931
12141
|
}
|
|
12932
12142
|
const result = {
|
|
12933
12143
|
name,
|
|
@@ -12942,9 +12152,9 @@ function buildFieldParameters(name, fieldProperties, required2 = [], config = {}
|
|
|
12942
12152
|
};
|
|
12943
12153
|
return (0, import_omitBy2.default)(result, import_isNil3.default);
|
|
12944
12154
|
}
|
|
12945
|
-
function convertJSONSchemaPropertiesToFieldParameters({ properties, required: required2, "x-jsf-order": order }, config = {}
|
|
12155
|
+
function convertJSONSchemaPropertiesToFieldParameters({ properties, required: required2, "x-jsf-order": order }, config = {}) {
|
|
12946
12156
|
const sortFields2 = (a, b) => sortByOrderOrPosition(a, b, order);
|
|
12947
|
-
return Object.entries(properties).filter(([, value]) => typeof value === "object").map(([key, value]) => buildFieldParameters(key, value, required2, config
|
|
12157
|
+
return Object.entries(properties).filter(([, value]) => typeof value === "object").map(([key, value]) => buildFieldParameters(key, value, required2, config)).sort(sortFields2).map(({ position, ...fieldParams }) => fieldParams);
|
|
12948
12158
|
}
|
|
12949
12159
|
function applyFieldsDependencies(fieldsParameters, node) {
|
|
12950
12160
|
if (node?.then) {
|
|
@@ -12966,9 +12176,6 @@ function applyFieldsDependencies(fieldsParameters, node) {
|
|
|
12966
12176
|
applyFieldsDependencies(fieldsParameters, condition);
|
|
12967
12177
|
});
|
|
12968
12178
|
}
|
|
12969
|
-
if (node?.["x-jsf-logic"]) {
|
|
12970
|
-
applyFieldsDependencies(fieldsParameters, node["x-jsf-logic"]);
|
|
12971
|
-
}
|
|
12972
12179
|
}
|
|
12973
12180
|
function getCustomPropertiesForField(fieldParams, config) {
|
|
12974
12181
|
return config?.customProperties?.[fieldParams.name];
|
|
@@ -12980,16 +12187,15 @@ function getComposeFunctionForField(fieldParams, hasCustomizations) {
|
|
|
12980
12187
|
}
|
|
12981
12188
|
return composeFn;
|
|
12982
12189
|
}
|
|
12983
|
-
function buildField(fieldParams, config, scopedJsonSchema
|
|
12190
|
+
function buildField(fieldParams, config, scopedJsonSchema) {
|
|
12984
12191
|
const customProperties = getCustomPropertiesForField(fieldParams, config);
|
|
12985
12192
|
const composeFn = getComposeFunctionForField(fieldParams, !!customProperties);
|
|
12986
|
-
const yupSchema = buildYupSchema(fieldParams, config
|
|
12987
|
-
const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties
|
|
12193
|
+
const yupSchema = buildYupSchema(fieldParams, config);
|
|
12194
|
+
const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties);
|
|
12988
12195
|
const calculateCustomValidationPropertiesClosure = calculateCustomValidationProperties(
|
|
12989
12196
|
fieldParams,
|
|
12990
12197
|
customProperties
|
|
12991
12198
|
);
|
|
12992
|
-
const getComputedAttributes = Object.keys(fieldParams.computedAttributes).length > 0 && calculateComputedAttributes(fieldParams, config);
|
|
12993
12199
|
const hasCustomValidations = !!customProperties && (0, import_size.default)((0, import_pick2.default)(customProperties, SUPPORTED_CUSTOM_VALIDATION_FIELD_PARAMS)) > 0;
|
|
12994
12200
|
const finalFieldParams = {
|
|
12995
12201
|
// invalid attribute cleanup
|
|
@@ -13002,7 +12208,6 @@ function buildField(fieldParams, config, scopedJsonSchema, validations) {
|
|
|
13002
12208
|
...hasCustomValidations && {
|
|
13003
12209
|
calculateCustomValidationProperties: calculateCustomValidationPropertiesClosure
|
|
13004
12210
|
},
|
|
13005
|
-
...getComputedAttributes && { getComputedAttributes },
|
|
13006
12211
|
// field customization properties
|
|
13007
12212
|
...customProperties && { fieldCustomization: customProperties },
|
|
13008
12213
|
// base schema
|
|
@@ -13011,15 +12216,11 @@ function buildField(fieldParams, config, scopedJsonSchema, validations) {
|
|
|
13011
12216
|
};
|
|
13012
12217
|
return composeFn(finalFieldParams);
|
|
13013
12218
|
}
|
|
13014
|
-
function getFieldsFromJSONSchema(scopedJsonSchema, config
|
|
12219
|
+
function getFieldsFromJSONSchema(scopedJsonSchema, config) {
|
|
13015
12220
|
if (!scopedJsonSchema) {
|
|
13016
12221
|
return [];
|
|
13017
12222
|
}
|
|
13018
|
-
const fieldParamsList = convertJSONSchemaPropertiesToFieldParameters(
|
|
13019
|
-
scopedJsonSchema,
|
|
13020
|
-
config,
|
|
13021
|
-
validations
|
|
13022
|
-
);
|
|
12223
|
+
const fieldParamsList = convertJSONSchemaPropertiesToFieldParameters(scopedJsonSchema, config);
|
|
13023
12224
|
applyFieldsDependencies(fieldParamsList, scopedJsonSchema);
|
|
13024
12225
|
const fields = [];
|
|
13025
12226
|
fieldParamsList.forEach((fieldParams) => {
|
|
@@ -13039,11 +12240,11 @@ function getFieldsFromJSONSchema(scopedJsonSchema, config, validations) {
|
|
|
13039
12240
|
fields: () => groupArrayFields,
|
|
13040
12241
|
addFieldText: fieldParams.addFieldText
|
|
13041
12242
|
};
|
|
13042
|
-
buildField(fieldParams, config, scopedJsonSchema
|
|
12243
|
+
buildField(fieldParams, config, scopedJsonSchema).forEach((groupField) => {
|
|
13043
12244
|
fields.push(groupField);
|
|
13044
12245
|
});
|
|
13045
12246
|
} else {
|
|
13046
|
-
fields.push(buildField(fieldParams, config, scopedJsonSchema
|
|
12247
|
+
fields.push(buildField(fieldParams, config, scopedJsonSchema));
|
|
13047
12248
|
}
|
|
13048
12249
|
});
|
|
13049
12250
|
return fields;
|
|
@@ -13054,15 +12255,9 @@ function createHeadlessForm(jsonSchema, customConfig = {}) {
|
|
|
13054
12255
|
...customConfig
|
|
13055
12256
|
};
|
|
13056
12257
|
try {
|
|
13057
|
-
const
|
|
13058
|
-
const
|
|
13059
|
-
|
|
13060
|
-
updateFieldsProperties(
|
|
13061
|
-
fields,
|
|
13062
|
-
getPrefillValues(fields, config.initialValues),
|
|
13063
|
-
jsonSchema,
|
|
13064
|
-
validations
|
|
13065
|
-
);
|
|
12258
|
+
const fields = getFieldsFromJSONSchema(jsonSchema, config);
|
|
12259
|
+
const handleValidation = handleValuesChange(fields, jsonSchema, config);
|
|
12260
|
+
updateFieldsProperties(fields, getPrefillValues(fields, config.initialValues), jsonSchema);
|
|
13066
12261
|
return {
|
|
13067
12262
|
fields,
|
|
13068
12263
|
handleValidation,
|