@remoteoss/json-schema-form 0.5.0-dev.20230810172154 → 0.5.0-dev.20230901130231

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.
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2023 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230810172154
5
- Generated: Thu, 10 Aug 2023 17:22:35 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.5.0-dev.20230901130231
5
+ Generated: Fri, 01 Sep 2023 13:03:04 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -6421,6 +6421,384 @@ var require_randexp = __commonJS({
6421
6421
  }
6422
6422
  });
6423
6423
 
6424
+ // node_modules/json-logic-js/logic.js
6425
+ var require_logic = __commonJS({
6426
+ "node_modules/json-logic-js/logic.js"(exports2, module2) {
6427
+ (function(root2, factory) {
6428
+ if (typeof define === "function" && define.amd) {
6429
+ define(factory);
6430
+ } else if (typeof exports2 === "object") {
6431
+ module2.exports = factory();
6432
+ } else {
6433
+ root2.jsonLogic = factory();
6434
+ }
6435
+ })(exports2, function() {
6436
+ "use strict";
6437
+ if (!Array.isArray) {
6438
+ Array.isArray = function(arg) {
6439
+ return Object.prototype.toString.call(arg) === "[object Array]";
6440
+ };
6441
+ }
6442
+ function arrayUnique(array2) {
6443
+ var a = [];
6444
+ for (var i = 0, l = array2.length; i < l; i++) {
6445
+ if (a.indexOf(array2[i]) === -1) {
6446
+ a.push(array2[i]);
6447
+ }
6448
+ }
6449
+ return a;
6450
+ }
6451
+ var jsonLogic2 = {};
6452
+ var operations = {
6453
+ "==": function(a, b) {
6454
+ return a == b;
6455
+ },
6456
+ "===": function(a, b) {
6457
+ return a === b;
6458
+ },
6459
+ "!=": function(a, b) {
6460
+ return a != b;
6461
+ },
6462
+ "!==": function(a, b) {
6463
+ return a !== b;
6464
+ },
6465
+ ">": function(a, b) {
6466
+ return a > b;
6467
+ },
6468
+ ">=": function(a, b) {
6469
+ return a >= b;
6470
+ },
6471
+ "<": function(a, b, c) {
6472
+ return c === void 0 ? a < b : a < b && b < c;
6473
+ },
6474
+ "<=": function(a, b, c) {
6475
+ return c === void 0 ? a <= b : a <= b && b <= c;
6476
+ },
6477
+ "!!": function(a) {
6478
+ return jsonLogic2.truthy(a);
6479
+ },
6480
+ "!": function(a) {
6481
+ return !jsonLogic2.truthy(a);
6482
+ },
6483
+ "%": function(a, b) {
6484
+ return a % b;
6485
+ },
6486
+ "log": function(a) {
6487
+ console.log(a);
6488
+ return a;
6489
+ },
6490
+ "in": function(a, b) {
6491
+ if (!b || typeof b.indexOf === "undefined")
6492
+ return false;
6493
+ return b.indexOf(a) !== -1;
6494
+ },
6495
+ "cat": function() {
6496
+ return Array.prototype.join.call(arguments, "");
6497
+ },
6498
+ "substr": function(source, start, end) {
6499
+ if (end < 0) {
6500
+ var temp = String(source).substr(start);
6501
+ return temp.substr(0, temp.length + end);
6502
+ }
6503
+ return String(source).substr(start, end);
6504
+ },
6505
+ "+": function() {
6506
+ return Array.prototype.reduce.call(arguments, function(a, b) {
6507
+ return parseFloat(a, 10) + parseFloat(b, 10);
6508
+ }, 0);
6509
+ },
6510
+ "*": function() {
6511
+ return Array.prototype.reduce.call(arguments, function(a, b) {
6512
+ return parseFloat(a, 10) * parseFloat(b, 10);
6513
+ });
6514
+ },
6515
+ "-": function(a, b) {
6516
+ if (b === void 0) {
6517
+ return -a;
6518
+ } else {
6519
+ return a - b;
6520
+ }
6521
+ },
6522
+ "/": function(a, b) {
6523
+ return a / b;
6524
+ },
6525
+ "min": function() {
6526
+ return Math.min.apply(this, arguments);
6527
+ },
6528
+ "max": function() {
6529
+ return Math.max.apply(this, arguments);
6530
+ },
6531
+ "merge": function() {
6532
+ return Array.prototype.reduce.call(arguments, function(a, b) {
6533
+ return a.concat(b);
6534
+ }, []);
6535
+ },
6536
+ "var": function(a, b) {
6537
+ var not_found = b === void 0 ? null : b;
6538
+ var data = this;
6539
+ if (typeof a === "undefined" || a === "" || a === null) {
6540
+ return data;
6541
+ }
6542
+ var sub_props = String(a).split(".");
6543
+ for (var i = 0; i < sub_props.length; i++) {
6544
+ if (data === null || data === void 0) {
6545
+ return not_found;
6546
+ }
6547
+ data = data[sub_props[i]];
6548
+ if (data === void 0) {
6549
+ return not_found;
6550
+ }
6551
+ }
6552
+ return data;
6553
+ },
6554
+ "missing": function() {
6555
+ var missing = [];
6556
+ var keys2 = Array.isArray(arguments[0]) ? arguments[0] : arguments;
6557
+ for (var i = 0; i < keys2.length; i++) {
6558
+ var key = keys2[i];
6559
+ var value = jsonLogic2.apply({ "var": key }, this);
6560
+ if (value === null || value === "") {
6561
+ missing.push(key);
6562
+ }
6563
+ }
6564
+ return missing;
6565
+ },
6566
+ "missing_some": function(need_count, options) {
6567
+ var are_missing = jsonLogic2.apply({ "missing": options }, this);
6568
+ if (options.length - are_missing.length >= need_count) {
6569
+ return [];
6570
+ } else {
6571
+ return are_missing;
6572
+ }
6573
+ }
6574
+ };
6575
+ jsonLogic2.is_logic = function(logic) {
6576
+ return typeof logic === "object" && // An object
6577
+ logic !== null && // but not null
6578
+ !Array.isArray(logic) && // and not an array
6579
+ Object.keys(logic).length === 1;
6580
+ };
6581
+ jsonLogic2.truthy = function(value) {
6582
+ if (Array.isArray(value) && value.length === 0) {
6583
+ return false;
6584
+ }
6585
+ return !!value;
6586
+ };
6587
+ jsonLogic2.get_operator = function(logic) {
6588
+ return Object.keys(logic)[0];
6589
+ };
6590
+ jsonLogic2.get_values = function(logic) {
6591
+ return logic[jsonLogic2.get_operator(logic)];
6592
+ };
6593
+ jsonLogic2.apply = function(logic, data) {
6594
+ if (Array.isArray(logic)) {
6595
+ return logic.map(function(l) {
6596
+ return jsonLogic2.apply(l, data);
6597
+ });
6598
+ }
6599
+ if (!jsonLogic2.is_logic(logic)) {
6600
+ return logic;
6601
+ }
6602
+ var op = jsonLogic2.get_operator(logic);
6603
+ var values2 = logic[op];
6604
+ var i;
6605
+ var current;
6606
+ var scopedLogic;
6607
+ var scopedData;
6608
+ var initial;
6609
+ if (!Array.isArray(values2)) {
6610
+ values2 = [values2];
6611
+ }
6612
+ if (op === "if" || op == "?:") {
6613
+ for (i = 0; i < values2.length - 1; i += 2) {
6614
+ if (jsonLogic2.truthy(jsonLogic2.apply(values2[i], data))) {
6615
+ return jsonLogic2.apply(values2[i + 1], data);
6616
+ }
6617
+ }
6618
+ if (values2.length === i + 1) {
6619
+ return jsonLogic2.apply(values2[i], data);
6620
+ }
6621
+ return null;
6622
+ } else if (op === "and") {
6623
+ for (i = 0; i < values2.length; i += 1) {
6624
+ current = jsonLogic2.apply(values2[i], data);
6625
+ if (!jsonLogic2.truthy(current)) {
6626
+ return current;
6627
+ }
6628
+ }
6629
+ return current;
6630
+ } else if (op === "or") {
6631
+ for (i = 0; i < values2.length; i += 1) {
6632
+ current = jsonLogic2.apply(values2[i], data);
6633
+ if (jsonLogic2.truthy(current)) {
6634
+ return current;
6635
+ }
6636
+ }
6637
+ return current;
6638
+ } else if (op === "filter") {
6639
+ scopedData = jsonLogic2.apply(values2[0], data);
6640
+ scopedLogic = values2[1];
6641
+ if (!Array.isArray(scopedData)) {
6642
+ return [];
6643
+ }
6644
+ return scopedData.filter(function(datum) {
6645
+ return jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, datum));
6646
+ });
6647
+ } else if (op === "map") {
6648
+ scopedData = jsonLogic2.apply(values2[0], data);
6649
+ scopedLogic = values2[1];
6650
+ if (!Array.isArray(scopedData)) {
6651
+ return [];
6652
+ }
6653
+ return scopedData.map(function(datum) {
6654
+ return jsonLogic2.apply(scopedLogic, datum);
6655
+ });
6656
+ } else if (op === "reduce") {
6657
+ scopedData = jsonLogic2.apply(values2[0], data);
6658
+ scopedLogic = values2[1];
6659
+ initial = typeof values2[2] !== "undefined" ? values2[2] : null;
6660
+ if (!Array.isArray(scopedData)) {
6661
+ return initial;
6662
+ }
6663
+ return scopedData.reduce(
6664
+ function(accumulator, current2) {
6665
+ return jsonLogic2.apply(
6666
+ scopedLogic,
6667
+ { current: current2, accumulator }
6668
+ );
6669
+ },
6670
+ initial
6671
+ );
6672
+ } else if (op === "all") {
6673
+ scopedData = jsonLogic2.apply(values2[0], data);
6674
+ scopedLogic = values2[1];
6675
+ if (!Array.isArray(scopedData) || !scopedData.length) {
6676
+ return false;
6677
+ }
6678
+ for (i = 0; i < scopedData.length; i += 1) {
6679
+ if (!jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
6680
+ return false;
6681
+ }
6682
+ }
6683
+ return true;
6684
+ } else if (op === "none") {
6685
+ scopedData = jsonLogic2.apply(values2[0], data);
6686
+ scopedLogic = values2[1];
6687
+ if (!Array.isArray(scopedData) || !scopedData.length) {
6688
+ return true;
6689
+ }
6690
+ for (i = 0; i < scopedData.length; i += 1) {
6691
+ if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
6692
+ return false;
6693
+ }
6694
+ }
6695
+ return true;
6696
+ } else if (op === "some") {
6697
+ scopedData = jsonLogic2.apply(values2[0], data);
6698
+ scopedLogic = values2[1];
6699
+ if (!Array.isArray(scopedData) || !scopedData.length) {
6700
+ return false;
6701
+ }
6702
+ for (i = 0; i < scopedData.length; i += 1) {
6703
+ if (jsonLogic2.truthy(jsonLogic2.apply(scopedLogic, scopedData[i]))) {
6704
+ return true;
6705
+ }
6706
+ }
6707
+ return false;
6708
+ }
6709
+ values2 = values2.map(function(val) {
6710
+ return jsonLogic2.apply(val, data);
6711
+ });
6712
+ if (operations.hasOwnProperty(op) && typeof operations[op] === "function") {
6713
+ return operations[op].apply(data, values2);
6714
+ } else if (op.indexOf(".") > 0) {
6715
+ var sub_ops = String(op).split(".");
6716
+ var operation = operations;
6717
+ for (i = 0; i < sub_ops.length; i++) {
6718
+ if (!operation.hasOwnProperty(sub_ops[i])) {
6719
+ throw new Error("Unrecognized operation " + op + " (failed at " + sub_ops.slice(0, i + 1).join(".") + ")");
6720
+ }
6721
+ operation = operation[sub_ops[i]];
6722
+ }
6723
+ return operation.apply(data, values2);
6724
+ }
6725
+ throw new Error("Unrecognized operation " + op);
6726
+ };
6727
+ jsonLogic2.uses_data = function(logic) {
6728
+ var collection = [];
6729
+ if (jsonLogic2.is_logic(logic)) {
6730
+ var op = jsonLogic2.get_operator(logic);
6731
+ var values2 = logic[op];
6732
+ if (!Array.isArray(values2)) {
6733
+ values2 = [values2];
6734
+ }
6735
+ if (op === "var") {
6736
+ collection.push(values2[0]);
6737
+ } else {
6738
+ values2.forEach(function(val) {
6739
+ collection.push.apply(collection, jsonLogic2.uses_data(val));
6740
+ });
6741
+ }
6742
+ }
6743
+ return arrayUnique(collection);
6744
+ };
6745
+ jsonLogic2.add_operation = function(name, code) {
6746
+ operations[name] = code;
6747
+ };
6748
+ jsonLogic2.rm_operation = function(name) {
6749
+ delete operations[name];
6750
+ };
6751
+ jsonLogic2.rule_like = function(rule, pattern) {
6752
+ if (pattern === rule) {
6753
+ return true;
6754
+ }
6755
+ if (pattern === "@") {
6756
+ return true;
6757
+ }
6758
+ if (pattern === "number") {
6759
+ return typeof rule === "number";
6760
+ }
6761
+ if (pattern === "string") {
6762
+ return typeof rule === "string";
6763
+ }
6764
+ if (pattern === "array") {
6765
+ return Array.isArray(rule) && !jsonLogic2.is_logic(rule);
6766
+ }
6767
+ if (jsonLogic2.is_logic(pattern)) {
6768
+ if (jsonLogic2.is_logic(rule)) {
6769
+ var pattern_op = jsonLogic2.get_operator(pattern);
6770
+ var rule_op = jsonLogic2.get_operator(rule);
6771
+ if (pattern_op === "@" || pattern_op === rule_op) {
6772
+ return jsonLogic2.rule_like(
6773
+ jsonLogic2.get_values(rule, false),
6774
+ jsonLogic2.get_values(pattern, false)
6775
+ );
6776
+ }
6777
+ }
6778
+ return false;
6779
+ }
6780
+ if (Array.isArray(pattern)) {
6781
+ if (Array.isArray(rule)) {
6782
+ if (pattern.length !== rule.length) {
6783
+ return false;
6784
+ }
6785
+ for (var i = 0; i < pattern.length; i += 1) {
6786
+ if (!jsonLogic2.rule_like(rule[i], pattern[i])) {
6787
+ return false;
6788
+ }
6789
+ }
6790
+ return true;
6791
+ } else {
6792
+ return false;
6793
+ }
6794
+ }
6795
+ return false;
6796
+ };
6797
+ return jsonLogic2;
6798
+ });
6799
+ }
6800
+ });
6801
+
6424
6802
  // node_modules/lodash/_baseInRange.js
6425
6803
  var require_baseInRange = __commonJS({
6426
6804
  "node_modules/lodash/_baseInRange.js"(exports2, module2) {
@@ -11032,6 +11410,13 @@ function convertDiskSizeFromTo(from2, to) {
11032
11410
  return value * Math.pow(1024, units.indexOf(from2.toLowerCase())) / Math.pow(1024, units.indexOf(to.toLowerCase()));
11033
11411
  };
11034
11412
  }
11413
+ function containsHTML(str = "") {
11414
+ return /<[a-z][\s\S]*>/i.test(str);
11415
+ }
11416
+ function wrapWithSpan(html, properties = {}) {
11417
+ const attributes = Object.entries(properties).reduce((acc, [key, value]) => `${acc}${key}="${value}" `, "").trim();
11418
+ return `<span ${attributes}>${html}</span>`;
11419
+ }
11035
11420
  function hasProperty(object2, propertyName) {
11036
11421
  return Object.prototype.hasOwnProperty.call(object2, propertyName);
11037
11422
  }
@@ -11344,6 +11729,103 @@ function _composeFieldCustomClosure(defaultComposeFn) {
11344
11729
  var import_flow = __toESM(require_flow());
11345
11730
  var import_noop = __toESM(require_noop());
11346
11731
  var import_randexp = __toESM(require_randexp());
11732
+
11733
+ // src/jsonLogic.js
11734
+ var import_json_logic_js = __toESM(require_logic());
11735
+ function createValidationChecker(schema) {
11736
+ const scopes = /* @__PURE__ */ new Map();
11737
+ function createScopes(jsonSchema, key = "root") {
11738
+ scopes.set(key, createValidationsScope(jsonSchema));
11739
+ Object.entries(jsonSchema?.properties ?? {}).filter(([, property2]) => property2.type === "object" || property2.type === "array").forEach(([key2, property2]) => {
11740
+ if (property2.type === "array") {
11741
+ createScopes(property2.items, `${key2}[]`);
11742
+ } else {
11743
+ createScopes(property2, key2);
11744
+ }
11745
+ });
11746
+ }
11747
+ createScopes(schema);
11748
+ return {
11749
+ scopes,
11750
+ getScope(name = "root") {
11751
+ return scopes.get(name);
11752
+ }
11753
+ };
11754
+ }
11755
+ function createValidationsScope(schema) {
11756
+ const validationMap = /* @__PURE__ */ new Map();
11757
+ const computedValuesMap = /* @__PURE__ */ new Map();
11758
+ const logic = schema?.["x-jsf-logic"] ?? {
11759
+ validations: {},
11760
+ computedValues: {}
11761
+ };
11762
+ const validations = Object.entries(logic.validations ?? {});
11763
+ const computedValues = Object.entries(logic.computedValues ?? {});
11764
+ validations.forEach(([id, validation]) => {
11765
+ validationMap.set(id, validation);
11766
+ });
11767
+ computedValues.forEach(([id, computedValue]) => {
11768
+ computedValuesMap.set(id, computedValue);
11769
+ });
11770
+ function validate2(rule, values2) {
11771
+ return import_json_logic_js.default.apply(rule, replaceUndefinedValuesWithNulls(values2));
11772
+ }
11773
+ return {
11774
+ validationMap,
11775
+ computedValuesMap,
11776
+ validate: validate2,
11777
+ applyValidationRuleInCondition(id, values2) {
11778
+ const validation = validationMap.get(id);
11779
+ return validate2(validation.rule, values2);
11780
+ },
11781
+ applyComputedValueInField(id, values2) {
11782
+ const validation = computedValuesMap.get(id);
11783
+ return validate2(validation.rule, values2);
11784
+ },
11785
+ applyComputedValueRuleInCondition(id, values2) {
11786
+ const validation = computedValuesMap.get(id);
11787
+ return validate2(validation.rule, values2);
11788
+ }
11789
+ };
11790
+ }
11791
+ function replaceUndefinedValuesWithNulls(values2 = {}) {
11792
+ return Object.entries(values2).reduce((prev, [key, value]) => {
11793
+ return { ...prev, [key]: value === void 0 ? null : value };
11794
+ }, {});
11795
+ }
11796
+ function yupSchemaWithCustomJSONLogic({ field, logic, config, id }) {
11797
+ const { parentID = "root" } = config;
11798
+ const validation = logic.getScope(parentID).validationMap.get(id);
11799
+ return (yupSchema) => yupSchema.test(
11800
+ `${field.name}-validation-${id}`,
11801
+ validation?.errorMessage ?? "This field is invalid.",
11802
+ (value, { parent }) => {
11803
+ if (value === void 0 && !field.required)
11804
+ return true;
11805
+ return import_json_logic_js.default.apply(validation.rule, parent);
11806
+ }
11807
+ );
11808
+ }
11809
+ function calculateComputedAttributes(fieldParams, { parentID = "root" } = {}) {
11810
+ return ({ logic, formValues }) => {
11811
+ const { computedAttributes } = fieldParams;
11812
+ const attributes = Object.fromEntries(
11813
+ Object.entries(computedAttributes).map(handleComputedAttribute(logic, formValues, parentID)).filter(([, value]) => value !== null)
11814
+ );
11815
+ return attributes;
11816
+ };
11817
+ }
11818
+ function handleComputedAttribute(logic, formValues, parentID) {
11819
+ return ([key, value]) => {
11820
+ if (key === "const")
11821
+ return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues)];
11822
+ if (typeof value === "string") {
11823
+ return [key, logic.getScope(parentID).applyComputedValueInField(value, formValues)];
11824
+ }
11825
+ };
11826
+ }
11827
+
11828
+ // src/yupSchema.js
11347
11829
  var DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
11348
11830
  var baseString = StringSchema().trim();
11349
11831
  var todayDateHint = (/* @__PURE__ */ new Date()).toISOString().substring(0, 10);
@@ -11466,7 +11948,7 @@ var getYupSchema = ({ inputType, ...field }) => {
11466
11948
  }
11467
11949
  return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
11468
11950
  };
11469
- function buildYupSchema(field, config) {
11951
+ function buildYupSchema(field, config, logic) {
11470
11952
  const { inputType, jsonType: jsonTypeValue, errorMessage = {}, ...propertyFields } = field;
11471
11953
  const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
11472
11954
  let baseSchema;
@@ -11539,6 +12021,13 @@ function buildYupSchema(field, config) {
11539
12021
  }) : true
11540
12022
  );
11541
12023
  }
12024
+ function withConst(yupSchema) {
12025
+ return yupSchema.test(
12026
+ "isConst",
12027
+ errorMessage.const ?? errorMessageFromConfig.const ?? `The only accepted value is ${propertyFields.const}.`,
12028
+ (value) => propertyFields.required === false && value === void 0 || value === null || value === propertyFields.const
12029
+ );
12030
+ }
11542
12031
  function withBaseSchema() {
11543
12032
  const customErrorMsg = errorMessage.type || errorMessageFromConfig.type;
11544
12033
  if (customErrorMsg) {
@@ -11606,6 +12095,14 @@ function buildYupSchema(field, config) {
11606
12095
  if (propertyFields.accept) {
11607
12096
  validators.push(withFileFormat);
11608
12097
  }
12098
+ if (propertyFields.const) {
12099
+ validators.push(withConst);
12100
+ }
12101
+ if (propertyFields.requiredValidations) {
12102
+ propertyFields.requiredValidations.forEach(
12103
+ (id) => validators.push(yupSchemaWithCustomJSONLogic({ field, id, logic, config }))
12104
+ );
12105
+ }
11609
12106
  return (0, import_flow.default)(validators);
11610
12107
  }
11611
12108
  function getNoSortEdges(fields = []) {
@@ -11645,8 +12142,8 @@ function hasType(type, typeName) {
11645
12142
  function getField(fieldName, fields) {
11646
12143
  return fields.find(({ name }) => name === fieldName);
11647
12144
  }
11648
- function validateFieldSchema(field, value) {
11649
- const validator = buildYupSchema(field);
12145
+ function validateFieldSchema(field, value, logic) {
12146
+ const validator = buildYupSchema(field, {}, logic);
11650
12147
  return validator().isValidSync(value);
11651
12148
  }
11652
12149
  function compareFormValueWithSchemaValue(formValue, schemaValue) {
@@ -11682,7 +12179,16 @@ function getPrefillSubFieldValues(field, defaultValues, parentFieldKeyPath) {
11682
12179
  initialValue[field.name] = subFieldValues;
11683
12180
  }
11684
12181
  } else {
11685
- initialValue = getPrefillValues([field], initialValue);
12182
+ if (typeof initialValue !== "object") {
12183
+ console.warn(
12184
+ `Field "${parentFieldKeyPath}"'s value is "${initialValue}", but should be type object.`
12185
+ );
12186
+ initialValue = getPrefillValues([field], {
12187
+ // TODO nested fieldsets are not handled
12188
+ });
12189
+ } else {
12190
+ initialValue = getPrefillValues([field], initialValue);
12191
+ }
11686
12192
  }
11687
12193
  return initialValue;
11688
12194
  }
@@ -11711,7 +12217,7 @@ function getPrefillValues(fields, initialValues = {}) {
11711
12217
  });
11712
12218
  return initialValues;
11713
12219
  }
11714
- function updateField(field, requiredFields, node, formValues) {
12220
+ function updateField(field, requiredFields, node, formValues, logic, config) {
11715
12221
  if (!field) {
11716
12222
  return;
11717
12223
  }
@@ -11733,6 +12239,17 @@ function updateField(field, requiredFields, node, formValues) {
11733
12239
  }
11734
12240
  }
11735
12241
  });
12242
+ if (field.getComputedAttributes) {
12243
+ const computedFieldValues = field.getComputedAttributes({
12244
+ field,
12245
+ isRequired: fieldIsRequired,
12246
+ node,
12247
+ formValues,
12248
+ config,
12249
+ logic
12250
+ });
12251
+ updateValues(computedFieldValues);
12252
+ }
11736
12253
  if (field.calculateConditionalProperties) {
11737
12254
  const newFieldValues = field.calculateConditionalProperties(fieldIsRequired, node);
11738
12255
  updateValues(newFieldValues);
@@ -11746,33 +12263,46 @@ function updateField(field, requiredFields, node, formValues) {
11746
12263
  updateValues(newFieldValues);
11747
12264
  }
11748
12265
  }
11749
- function processNode(node, formValues, formFields, accRequired = /* @__PURE__ */ new Set()) {
12266
+ function processNode({
12267
+ node,
12268
+ formValues,
12269
+ formFields,
12270
+ accRequired = /* @__PURE__ */ new Set(),
12271
+ parentID = "root",
12272
+ logic
12273
+ }) {
11750
12274
  const requiredFields = new Set(accRequired);
11751
12275
  Object.keys(node.properties ?? []).forEach((fieldName) => {
11752
12276
  const field = getField(fieldName, formFields);
11753
- updateField(field, requiredFields, node, formValues);
12277
+ updateField(field, requiredFields, node, formValues, logic, { parentID });
11754
12278
  });
11755
12279
  node.required?.forEach((fieldName) => {
11756
12280
  requiredFields.add(fieldName);
11757
- updateField(getField(fieldName, formFields), requiredFields, node, formValues);
12281
+ updateField(getField(fieldName, formFields), requiredFields, node, formValues, logic, {
12282
+ parentID
12283
+ });
11758
12284
  });
11759
12285
  if (node.if) {
11760
- const matchesCondition = checkIfConditionMatches(node, formValues, formFields);
12286
+ const matchesCondition = checkIfConditionMatches(node, formValues, formFields, logic);
11761
12287
  if (matchesCondition && node.then) {
11762
- const { required: branchRequired } = processNode(
11763
- node.then,
12288
+ const { required: branchRequired } = processNode({
12289
+ node: node.then,
11764
12290
  formValues,
11765
12291
  formFields,
11766
- requiredFields
11767
- );
12292
+ accRequired: requiredFields,
12293
+ parentID,
12294
+ logic
12295
+ });
11768
12296
  branchRequired.forEach((field) => requiredFields.add(field));
11769
12297
  } else if (node.else) {
11770
- const { required: branchRequired } = processNode(
11771
- node.else,
12298
+ const { required: branchRequired } = processNode({
12299
+ node: node.else,
11772
12300
  formValues,
11773
12301
  formFields,
11774
- requiredFields
11775
- );
12302
+ accRequired: requiredFields,
12303
+ parentID,
12304
+ logic
12305
+ });
11776
12306
  branchRequired.forEach((field) => requiredFields.add(field));
11777
12307
  }
11778
12308
  }
@@ -11784,12 +12314,21 @@ function processNode(node, formValues, formFields, accRequired = /* @__PURE__ */
11784
12314
  node.anyOf.forEach(({ required: required2 = [] }) => {
11785
12315
  required2.forEach((fieldName) => {
11786
12316
  const field = getField(fieldName, formFields);
11787
- updateField(field, requiredFields, node, formValues);
12317
+ updateField(field, requiredFields, node, formValues, logic, { parentID });
11788
12318
  });
11789
12319
  });
11790
12320
  }
11791
12321
  if (node.allOf) {
11792
- node.allOf.map((allOfNode) => processNode(allOfNode, formValues, formFields, requiredFields)).forEach(({ required: allOfItemRequired }) => {
12322
+ node.allOf.map(
12323
+ (allOfNode) => processNode({
12324
+ node: allOfNode,
12325
+ formValues,
12326
+ formFields,
12327
+ accRequired: requiredFields,
12328
+ parentID,
12329
+ logic
12330
+ })
12331
+ ).forEach(({ required: allOfItemRequired }) => {
11793
12332
  allOfItemRequired.forEach(requiredFields.add, requiredFields);
11794
12333
  });
11795
12334
  }
@@ -11797,7 +12336,13 @@ function processNode(node, formValues, formFields, accRequired = /* @__PURE__ */
11797
12336
  Object.entries(node.properties).forEach(([name, nestedNode]) => {
11798
12337
  const inputType = getInputType(nestedNode);
11799
12338
  if (inputType === supportedTypes.FIELDSET) {
11800
- processNode(nestedNode, formValues[name] || {}, getField(name, formFields).fields);
12339
+ processNode({
12340
+ node: nestedNode,
12341
+ formValues: formValues[name] || {},
12342
+ formFields: getField(name, formFields).fields,
12343
+ parentID: name,
12344
+ logic
12345
+ });
11801
12346
  }
11802
12347
  });
11803
12348
  }
@@ -11815,11 +12360,11 @@ function clearValuesIfNotVisible(fields, formValues) {
11815
12360
  }
11816
12361
  });
11817
12362
  }
11818
- function updateFieldsProperties(fields, formValues, jsonSchema) {
12363
+ function updateFieldsProperties(fields, formValues, jsonSchema, logic) {
11819
12364
  if (!jsonSchema?.properties) {
11820
12365
  return;
11821
12366
  }
11822
- processNode(jsonSchema, formValues, fields);
12367
+ processNode({ node: jsonSchema, formValues, formFields: fields, logic });
11823
12368
  clearValuesIfNotVisible(fields, formValues);
11824
12369
  }
11825
12370
  var notNullOption = (opt) => opt.const !== null;
@@ -11862,11 +12407,15 @@ function extractParametersFromNode(schemaNode) {
11862
12407
  }
11863
12408
  const presentation = pickXKey(schemaNode, "presentation") ?? {};
11864
12409
  const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
12410
+ const requiredValidations = schemaNode["x-jsf-logic-validations"];
12411
+ const computedAttributes = schemaNode["x-jsf-logic-computedAttrs"];
12412
+ const decoratedComputedAttributes = getDecoratedComputedAttributes(computedAttributes);
11865
12413
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
11866
12414
  const description = presentation?.description || node.description;
11867
- const statementDescription = presentation.statement?.description;
12415
+ const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
11868
12416
  return (0, import_omitBy.default)(
11869
12417
  {
12418
+ const: node.const,
11870
12419
  label: node.title,
11871
12420
  readOnly: node.readOnly,
11872
12421
  ...node.deprecated && {
@@ -11901,8 +12450,12 @@ function extractParametersFromNode(schemaNode) {
11901
12450
  },
11902
12451
  // Handle [name].presentation
11903
12452
  ...presentation,
11904
- description,
11905
- extra: presentation.extra,
12453
+ requiredValidations,
12454
+ computedAttributes: decoratedComputedAttributes,
12455
+ description: containsHTML(description) ? wrapWithSpan(description, {
12456
+ class: "jsf-description"
12457
+ }) : description,
12458
+ extra: containsHTML(presentation.extra) ? wrapWithSpan(presentation.extra, { class: "jsf-extra" }) : presentation.extra,
11906
12459
  statement: presentation.statement && {
11907
12460
  ...presentation.statement,
11908
12461
  description: statementDescription
@@ -11935,8 +12488,8 @@ function yupToFormErrors(yupError) {
11935
12488
  }
11936
12489
  return errors;
11937
12490
  }
11938
- var handleValuesChange = (fields, jsonSchema, config) => (values2) => {
11939
- updateFieldsProperties(fields, values2, jsonSchema);
12491
+ var handleValuesChange = (fields, jsonSchema, config, logic) => (values2) => {
12492
+ updateFieldsProperties(fields, values2, jsonSchema, logic);
11940
12493
  const lazySchema = lazy(() => buildCompleteYupSchema(fields, config));
11941
12494
  let errors;
11942
12495
  try {
@@ -11955,6 +12508,12 @@ var handleValuesChange = (fields, jsonSchema, config) => (values2) => {
11955
12508
  formErrors: yupToFormErrors(errors)
11956
12509
  };
11957
12510
  };
12511
+ function getDecoratedComputedAttributes(computedAttributes) {
12512
+ return {
12513
+ ...computedAttributes ?? {},
12514
+ ...computedAttributes?.const && computedAttributes?.default ? { value: computedAttributes.const } : {}
12515
+ };
12516
+ }
11958
12517
 
11959
12518
  // src/calculateConditionalProperties.js
11960
12519
  function isFieldRequired(node, field) {
@@ -12156,6 +12715,9 @@ function applyFieldsDependencies(fieldsParameters, node) {
12156
12715
  applyFieldsDependencies(fieldsParameters, condition);
12157
12716
  });
12158
12717
  }
12718
+ if (node?.["x-jsf-logic"]) {
12719
+ applyFieldsDependencies(fieldsParameters, node["x-jsf-logic"]);
12720
+ }
12159
12721
  }
12160
12722
  function getCustomPropertiesForField(fieldParams, config) {
12161
12723
  return config?.customProperties?.[fieldParams.name];
@@ -12167,15 +12729,16 @@ function getComposeFunctionForField(fieldParams, hasCustomizations) {
12167
12729
  }
12168
12730
  return composeFn;
12169
12731
  }
12170
- function buildField(fieldParams, config, scopedJsonSchema) {
12732
+ function buildField(fieldParams, config, scopedJsonSchema, logic) {
12171
12733
  const customProperties = getCustomPropertiesForField(fieldParams, config);
12172
12734
  const composeFn = getComposeFunctionForField(fieldParams, !!customProperties);
12173
- const yupSchema = buildYupSchema(fieldParams, config);
12735
+ const yupSchema = buildYupSchema(fieldParams, config, logic);
12174
12736
  const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties);
12175
12737
  const calculateCustomValidationPropertiesClosure = calculateCustomValidationProperties(
12176
12738
  fieldParams,
12177
12739
  customProperties
12178
12740
  );
12741
+ const getComputedAttributes = Object.keys(fieldParams.computedAttributes).length > 0 && calculateComputedAttributes(fieldParams, config);
12179
12742
  const hasCustomValidations = !!customProperties && (0, import_size.default)((0, import_pick2.default)(customProperties, SUPPORTED_CUSTOM_VALIDATION_FIELD_PARAMS)) > 0;
12180
12743
  const finalFieldParams = {
12181
12744
  // invalid attribute cleanup
@@ -12188,6 +12751,7 @@ function buildField(fieldParams, config, scopedJsonSchema) {
12188
12751
  ...hasCustomValidations && {
12189
12752
  calculateCustomValidationProperties: calculateCustomValidationPropertiesClosure
12190
12753
  },
12754
+ ...getComputedAttributes && { getComputedAttributes },
12191
12755
  // field customization properties
12192
12756
  ...customProperties && { fieldCustomization: customProperties },
12193
12757
  // base schema
@@ -12196,7 +12760,7 @@ function buildField(fieldParams, config, scopedJsonSchema) {
12196
12760
  };
12197
12761
  return composeFn(finalFieldParams);
12198
12762
  }
12199
- function getFieldsFromJSONSchema(scopedJsonSchema, config) {
12763
+ function getFieldsFromJSONSchema(scopedJsonSchema, config, logic) {
12200
12764
  if (!scopedJsonSchema) {
12201
12765
  return [];
12202
12766
  }
@@ -12220,11 +12784,11 @@ function getFieldsFromJSONSchema(scopedJsonSchema, config) {
12220
12784
  fields: () => groupArrayFields,
12221
12785
  addFieldText: fieldParams.addFieldText
12222
12786
  };
12223
- buildField(fieldParams, config, scopedJsonSchema).forEach((groupField) => {
12787
+ buildField(fieldParams, config, scopedJsonSchema, logic).forEach((groupField) => {
12224
12788
  fields.push(groupField);
12225
12789
  });
12226
12790
  } else {
12227
- fields.push(buildField(fieldParams, config, scopedJsonSchema));
12791
+ fields.push(buildField(fieldParams, config, scopedJsonSchema, logic));
12228
12792
  }
12229
12793
  });
12230
12794
  return fields;
@@ -12235,9 +12799,15 @@ function createHeadlessForm(jsonSchema, customConfig = {}) {
12235
12799
  ...customConfig
12236
12800
  };
12237
12801
  try {
12238
- const fields = getFieldsFromJSONSchema(jsonSchema, config);
12239
- const handleValidation = handleValuesChange(fields, jsonSchema, config);
12240
- updateFieldsProperties(fields, getPrefillValues(fields, config.initialValues), jsonSchema);
12802
+ const logic = createValidationChecker(jsonSchema);
12803
+ const fields = getFieldsFromJSONSchema(jsonSchema, config, logic);
12804
+ const handleValidation = handleValuesChange(fields, jsonSchema, config, logic);
12805
+ updateFieldsProperties(
12806
+ fields,
12807
+ getPrefillValues(fields, config.initialValues),
12808
+ jsonSchema,
12809
+ logic
12810
+ );
12241
12811
  return {
12242
12812
  fields,
12243
12813
  handleValidation,