@remoteoss/json-schema-form 0.4.4-dev.20230829101351 → 0.4.4-dev.20230829102031

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 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.20230829101351
5
- Generated: Tue, 29 Aug 2023 10:14:13 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.4.4-dev.20230829102031
5
+ Generated: Tue, 29 Aug 2023 10:20:47 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -103,8 +103,8 @@ function hasProperty(object2, propertyName) {
103
103
  }
104
104
 
105
105
  // src/checkIfConditionMatches.js
106
- function checkIfConditionMatches(node, formValues, formFields, validations) {
107
- return Object.keys(node.if.properties ?? {}).every((name) => {
106
+ function checkIfConditionMatches(node, formValues, formFields) {
107
+ return Object.keys(node.if.properties).every((name) => {
108
108
  const currentProperty = node.if.properties[name];
109
109
  const value = formValues[name];
110
110
  const hasEmptyValue = typeof value === "undefined" || // NOTE: This is a "Remote API" dependency, as empty fields are sent as "null".
@@ -130,8 +130,7 @@ function checkIfConditionMatches(node, formValues, formFields, validations) {
130
130
  return checkIfConditionMatches(
131
131
  { if: currentProperty },
132
132
  formValues[name],
133
- getField(name, formFields).fields,
134
- validations
133
+ getField(name, formFields).fields
135
134
  );
136
135
  }
137
136
  const field = getField(name, formFields);
@@ -147,23 +146,6 @@ function checkIfConditionMatches(node, formValues, formFields, validations) {
147
146
  );
148
147
  });
149
148
  }
150
- function checkIfMatchesValidationsAndComputedValues(node, formValues, validations, parentID) {
151
- const validationsMatch = Object.entries(node.if.validations ?? {}).every(([name, property]) => {
152
- const currentValue = validations.getScope(parentID).evaluateValidationRuleInCondition(name, formValues);
153
- if (Object.hasOwn(property, "const") && currentValue === property.const)
154
- return true;
155
- return false;
156
- });
157
- const computedValuesMatch = Object.entries(node.if.computedValues ?? {}).every(
158
- ([name, property]) => {
159
- const currentValue = validations.getScope(parentID).evaluateComputedValueRuleInCondition(name, formValues);
160
- if (Object.hasOwn(property, "const") && currentValue === property.const)
161
- return true;
162
- return false;
163
- }
164
- );
165
- return computedValuesMatch && validationsMatch;
166
- }
167
149
 
168
150
  // src/internals/helpers.js
169
151
  var import_merge = __toESM(require("lodash/fp/merge"));
@@ -424,9 +406,6 @@ function _composeFieldCustomClosure(defaultComposeFn) {
424
406
  };
425
407
  }
426
408
 
427
- // src/jsonLogic.js
428
- var import_json_logic_js = __toESM(require("json-logic-js"));
429
-
430
409
  // src/yupSchema.js
431
410
  var import_flow = __toESM(require("lodash/flow"));
432
411
  var import_noop = __toESM(require("lodash/noop"));
@@ -554,7 +533,7 @@ var getYupSchema = ({ inputType, ...field }) => {
554
533
  }
555
534
  return yupSchemas[inputType] || yupSchemasToJsonTypes[jsonType];
556
535
  };
557
- function buildYupSchema(field, config, validations) {
536
+ function buildYupSchema(field, config) {
558
537
  const { inputType, jsonType: jsonTypeValue, errorMessage = {}, ...propertyFields } = field;
559
538
  const isCheckboxBoolean = typeof propertyFields.checkboxValue === "boolean";
560
539
  let baseSchema;
@@ -654,8 +633,7 @@ function buildYupSchema(field, config, validations) {
654
633
  ...fieldSetfield,
655
634
  inputType: fieldSetfield.type
656
635
  },
657
- { ...config, parentID: field.name },
658
- validations
636
+ config
659
637
  )();
660
638
  }
661
639
  });
@@ -666,11 +644,7 @@ function buildYupSchema(field, config, validations) {
666
644
  propertyFields.nthFieldGroup.fields().reduce(
667
645
  (schema, groupArrayField) => ({
668
646
  ...schema,
669
- [groupArrayField.name]: buildYupSchema(
670
- groupArrayField,
671
- { ...config, parentID: `${propertyFields.nthFieldGroup.name}[]` },
672
- validations
673
- )()
647
+ [groupArrayField.name]: buildYupSchema(groupArrayField, config)()
674
648
  }),
675
649
  {}
676
650
  )
@@ -709,11 +683,6 @@ function buildYupSchema(field, config, validations) {
709
683
  if (propertyFields.const) {
710
684
  validators.push(withConst);
711
685
  }
712
- if (propertyFields.requiredValidations) {
713
- propertyFields.requiredValidations.forEach(
714
- (id) => validators.push(yupSchemaWithCustomJSONLogic({ field, id, validations, config }))
715
- );
716
- }
717
686
  return (0, import_flow.default)(validators);
718
687
  }
719
688
  function getNoSortEdges(fields = []) {
@@ -724,322 +693,26 @@ function getNoSortEdges(fields = []) {
724
693
  return list;
725
694
  }, []);
726
695
  }
727
- function getSchema(fields = [], config, validations) {
696
+ function getSchema(fields = [], config) {
728
697
  const newSchema = {};
729
698
  fields.forEach((field) => {
730
699
  if (field.schema) {
731
700
  if (field.name) {
732
701
  if (field.inputType === supportedTypes.FIELDSET) {
733
- const fieldsetSchema = buildYupSchema(
734
- field,
735
- { ...config, parentID: field.name },
736
- validations
737
- )();
702
+ const fieldsetSchema = buildYupSchema(field, config)();
738
703
  newSchema[field.name] = fieldsetSchema;
739
704
  } else {
740
705
  newSchema[field.name] = field.schema;
741
706
  }
742
707
  } else {
743
- Object.assign(newSchema, getSchema(field.fields, config, validations));
708
+ Object.assign(newSchema, getSchema(field.fields, config));
744
709
  }
745
710
  }
746
711
  });
747
712
  return newSchema;
748
713
  }
749
- function buildCompleteYupSchema(fields, config, validations) {
750
- return (0, import_yup.object)().shape(getSchema(fields, config, validations), getNoSortEdges(fields));
751
- }
752
-
753
- // src/jsonLogic.js
754
- function createValidationChecker(schema) {
755
- const scopes = /* @__PURE__ */ new Map();
756
- function createScopes(jsonSchema, key = "root") {
757
- const sampleEmptyObject = buildSampleEmptyObject(schema);
758
- scopes.set(key, createValidationsScope(jsonSchema));
759
- Object.entries(jsonSchema?.properties ?? {}).filter(([, property]) => property.type === "object" || property.type === "array").forEach(([key2, property]) => {
760
- if (property.type === "array") {
761
- createScopes(property.items, `${key2}[]`);
762
- }
763
- createScopes(property, key2);
764
- });
765
- validateInlineRules(jsonSchema, sampleEmptyObject);
766
- }
767
- createScopes(schema);
768
- return {
769
- scopes,
770
- getScope(name = "root") {
771
- return scopes.get(name);
772
- }
773
- };
774
- }
775
- function createValidationsScope(schema) {
776
- const validationMap = /* @__PURE__ */ new Map();
777
- const computedValuesMap = /* @__PURE__ */ new Map();
778
- const logic = schema?.["x-jsf-logic"] ?? {
779
- validations: {},
780
- computedValues: {}
781
- };
782
- const validations = Object.entries(logic.validations ?? {});
783
- const computedValues = Object.entries(logic.computedValues ?? {});
784
- const sampleEmptyObject = buildSampleEmptyObject(schema);
785
- validations.forEach(([id, validation]) => {
786
- if (!validation.rule) {
787
- throw Error(`Missing rule for validation with id of: "${id}".`);
788
- }
789
- checkRuleIntegrity(validation.rule, id, sampleEmptyObject);
790
- validationMap.set(id, validation);
791
- });
792
- computedValues.forEach(([id, computedValue]) => {
793
- if (!computedValue.rule) {
794
- throw Error(`Missing rule for computedValue with id of: "${id}".`);
795
- }
796
- checkRuleIntegrity(computedValue.rule, id, sampleEmptyObject);
797
- computedValuesMap.set(id, computedValue);
798
- });
799
- function evaluateValidation(rule, values) {
800
- return import_json_logic_js.default.apply(rule, clean(values));
801
- }
802
- return {
803
- validationMap,
804
- computedValuesMap,
805
- evaluateValidation,
806
- evaluateValidationRuleInCondition(id, values) {
807
- const validation = validationMap.get(id);
808
- if (validation === void 0)
809
- throw Error(`"${id}" validation in if condition doesn't exist.`);
810
- return evaluateValidation(validation.rule, values);
811
- },
812
- evaluateComputedValueRuleForField(id, values, fieldName) {
813
- const validation = computedValuesMap.get(id);
814
- if (validation === void 0)
815
- throw Error(`"${id}" computedValue in field "${fieldName}" doesn't exist.`);
816
- return evaluateValidation(validation.rule, values);
817
- },
818
- evaluateComputedValueRuleInCondition(id, values) {
819
- const validation = computedValuesMap.get(id);
820
- if (validation === void 0)
821
- throw Error(`"${id}" computedValue in if condition doesn't exist.`);
822
- return evaluateValidation(validation.rule, values);
823
- }
824
- };
825
- }
826
- function clean(values = {}) {
827
- return Object.entries(values).reduce((prev, [key, value]) => {
828
- return { ...prev, [key]: value === void 0 ? null : value };
829
- }, {});
830
- }
831
- function yupSchemaWithCustomJSONLogic({ field, validations, config, id }) {
832
- const { parentID = "root" } = config;
833
- const validation = validations.getScope(parentID).validationMap.get(id);
834
- if (validation === void 0) {
835
- throw Error(`Validation "${id}" required for "${field.name}" doesn't exist.`);
836
- }
837
- return (yupSchema) => yupSchema.test(
838
- `${field.name}-validation-${id}`,
839
- validation?.errorMessage ?? "This field is invalid.",
840
- (value, { parent }) => {
841
- if (value === void 0 && !field.required)
842
- return true;
843
- return import_json_logic_js.default.apply(validation.rule, parent);
844
- }
845
- );
846
- }
847
- function replaceHandlebarsTemplates({
848
- value: toReplace,
849
- validations,
850
- formValues,
851
- parentID,
852
- name: fieldName
853
- }) {
854
- if (typeof toReplace === "string") {
855
- return toReplace.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
856
- return validations.getScope(parentID).evaluateComputedValueRuleForField(key.trim(), formValues, fieldName);
857
- });
858
- } else if (typeof toReplace === "object") {
859
- const { value, ...rules } = toReplace;
860
- if (Object.keys(rules).length > 1 && !value)
861
- throw Error("Cannot define multiple rules without a template string with key `value`.");
862
- const computedTemplateValue = Object.entries(rules).reduce((prev, [key, rule]) => {
863
- const computedValue = validations.getScope(parentID).evaluateValidation(rule, formValues);
864
- return prev.replaceAll(`{{${key}}}`, computedValue);
865
- }, value);
866
- return computedTemplateValue.replace(/\{\{([^{}]+)\}\}/g, (match, key) => {
867
- return validations.getScope(parentID).evaluateComputedValueRuleForField(key.trim(), formValues, fieldName);
868
- });
869
- }
870
- }
871
- function calculateComputedAttributes(fieldParams, { parentID = "root" } = {}) {
872
- return ({ validations, isRequired, config, formValues }) => {
873
- const { name, computedAttributes } = fieldParams;
874
- const attributes = Object.fromEntries(
875
- Object.entries(computedAttributes).map(handleComputedAttribute(validations, formValues, parentID, name)).filter(([, value]) => value !== null)
876
- );
877
- return {
878
- ...attributes,
879
- schema: buildYupSchema(
880
- { ...fieldParams, ...attributes, required: isRequired },
881
- config,
882
- validations
883
- )
884
- };
885
- };
886
- }
887
- function handleComputedAttribute(validations, formValues, parentID, name) {
888
- return ([key, value]) => {
889
- if (key === "description")
890
- return [key, replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })];
891
- if (key === "title") {
892
- return [
893
- "label",
894
- replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })
895
- ];
896
- }
897
- if (key === "const")
898
- return [
899
- key,
900
- validations.getScope(parentID).evaluateComputedValueRuleForField(value, formValues, name)
901
- ];
902
- if (key === "x-jsf-errorMessage") {
903
- return [
904
- "errorMessage",
905
- handleNestedObjectForComputedValues(value, formValues, parentID, validations, name)
906
- ];
907
- }
908
- if (typeof value === "string") {
909
- return [
910
- key,
911
- validations.getScope(parentID).evaluateComputedValueRuleForField(value, formValues, name)
912
- ];
913
- }
914
- if (key === "x-jsf-presentation" && value.statement) {
915
- return [
916
- "statement",
917
- handleNestedObjectForComputedValues(
918
- value.statement,
919
- formValues,
920
- parentID,
921
- validations,
922
- name
923
- )
924
- ];
925
- }
926
- if (typeof value === "object" && value.rule) {
927
- return [key, validations.getScope(parentID).evaluateValidation(value.rule, formValues)];
928
- }
929
- };
930
- }
931
- function handleNestedObjectForComputedValues(values, formValues, parentID, validations, name) {
932
- return Object.fromEntries(
933
- Object.entries(values).map(([key, value]) => {
934
- return [key, replaceHandlebarsTemplates({ value, validations, formValues, parentID, name })];
935
- })
936
- );
937
- }
938
- function processJSONLogicNode({
939
- node,
940
- formFields,
941
- formValues,
942
- accRequired,
943
- parentID,
944
- validations
945
- }) {
946
- const requiredFields = new Set(accRequired);
947
- if (node.allOf) {
948
- node.allOf.map(
949
- (allOfNode) => processJSONLogicNode({ node: allOfNode, formValues, formFields, validations, parentID })
950
- ).forEach(({ required: allOfItemRequired }) => {
951
- allOfItemRequired.forEach(requiredFields.add, requiredFields);
952
- });
953
- }
954
- if (node.if) {
955
- const matchesPropertyCondition = checkIfConditionMatches(
956
- node,
957
- formValues,
958
- formFields,
959
- validations
960
- );
961
- const matchesValidationsAndComputedValues = checkIfMatchesValidationsAndComputedValues(
962
- node,
963
- formValues,
964
- validations,
965
- parentID
966
- );
967
- const isConditionMatch = matchesPropertyCondition && matchesValidationsAndComputedValues;
968
- if (isConditionMatch && node.then) {
969
- const { required: branchRequired } = processNode({
970
- node: node.then,
971
- formValues,
972
- formFields,
973
- accRequired,
974
- validations
975
- });
976
- branchRequired.forEach((field) => requiredFields.add(field));
977
- }
978
- if (!isConditionMatch && node.else) {
979
- const { required: branchRequired } = processNode({
980
- node: node.else,
981
- formValues,
982
- formFields,
983
- accRequired: requiredFields,
984
- validations
985
- });
986
- branchRequired.forEach((field) => requiredFields.add(field));
987
- }
988
- }
989
- return { required: requiredFields };
990
- }
991
- function buildSampleEmptyObject(schema = {}) {
992
- const sample = {};
993
- if (typeof schema !== "object" || !schema.properties) {
994
- return schema;
995
- }
996
- for (const key in schema.properties) {
997
- if (schema.properties[key].type === "object") {
998
- sample[key] = buildSampleEmptyObject(schema.properties[key]);
999
- } else if (schema.properties[key].type === "array") {
1000
- const itemSchema = schema.properties[key].items;
1001
- sample[key] = buildSampleEmptyObject(itemSchema);
1002
- } else {
1003
- sample[key] = true;
1004
- }
1005
- }
1006
- return sample;
1007
- }
1008
- function validateInlineRules(jsonSchema, sampleEmptyObject) {
1009
- const properties = (jsonSchema?.properties || jsonSchema?.items?.properties) ?? {};
1010
- Object.entries(properties).filter(([, property]) => property["x-jsf-logic-computedAttrs"] !== void 0).forEach(([fieldName, property]) => {
1011
- Object.entries(property["x-jsf-logic-computedAttrs"]).filter(([, value]) => typeof value === "object").forEach(([key, item]) => {
1012
- Object.values(item).forEach((rule) => {
1013
- checkRuleIntegrity(
1014
- rule,
1015
- fieldName,
1016
- sampleEmptyObject,
1017
- (item2) => `"${item2.var}" in inline rule in property "${fieldName}.x-jsf-logic-computedAttrs.${key}" does not exist as a JSON schema property.`
1018
- );
1019
- });
1020
- });
1021
- });
1022
- }
1023
- function checkRuleIntegrity(rule, id, data, errorMessage = (item) => `"${item.var}" in rule "${id}" does not exist as a JSON schema property.`) {
1024
- Object.values(rule ?? {}).map((subRule) => {
1025
- if (!Array.isArray(subRule) && subRule !== null && subRule !== void 0)
1026
- return;
1027
- subRule.map((item) => {
1028
- const isVar = item !== null && typeof item === "object" && Object.hasOwn(item, "var");
1029
- if (isVar) {
1030
- const exists = import_json_logic_js.default.apply({ var: removeIndicesFromPath(item.var) }, data);
1031
- if (exists === null) {
1032
- throw Error(errorMessage(item));
1033
- }
1034
- } else {
1035
- checkRuleIntegrity(item, id, data);
1036
- }
1037
- });
1038
- });
1039
- }
1040
- function removeIndicesFromPath(path) {
1041
- const intermediatePath = path.replace(/\.\d+\./g, ".");
1042
- return intermediatePath.replace(/\.\d+$/, "");
714
+ function buildCompleteYupSchema(fields, config) {
715
+ return (0, import_yup.object)().shape(getSchema(fields, config), getNoSortEdges(fields));
1043
716
  }
1044
717
 
1045
718
  // src/helpers.js
@@ -1049,8 +722,8 @@ function hasType(type, typeName) {
1049
722
  function getField(fieldName, fields) {
1050
723
  return fields.find(({ name }) => name === fieldName);
1051
724
  }
1052
- function validateFieldSchema(field, value, validations) {
1053
- const validator = buildYupSchema(field, {}, validations);
725
+ function validateFieldSchema(field, value) {
726
+ const validator = buildYupSchema(field);
1054
727
  return validator().isValidSync(value);
1055
728
  }
1056
729
  function compareFormValueWithSchemaValue(formValue, schemaValue) {
@@ -1115,7 +788,7 @@ function getPrefillValues(fields, initialValues = {}) {
1115
788
  });
1116
789
  return initialValues;
1117
790
  }
1118
- function updateField(field, requiredFields, node, formValues, validations, config) {
791
+ function updateField(field, requiredFields, node, formValues) {
1119
792
  if (!field) {
1120
793
  return;
1121
794
  }
@@ -1137,25 +810,8 @@ function updateField(field, requiredFields, node, formValues, validations, confi
1137
810
  }
1138
811
  }
1139
812
  });
1140
- if (field.getComputedAttributes) {
1141
- const computedFieldValues = field.getComputedAttributes({
1142
- field,
1143
- isRequired: fieldIsRequired,
1144
- node,
1145
- formValues,
1146
- config,
1147
- validations
1148
- });
1149
- updateValues(computedFieldValues);
1150
- }
1151
813
  if (field.calculateConditionalProperties) {
1152
- const newFieldValues = field.calculateConditionalProperties(
1153
- fieldIsRequired,
1154
- node,
1155
- validations,
1156
- config,
1157
- formValues
1158
- );
814
+ const newFieldValues = field.calculateConditionalProperties(fieldIsRequired, node);
1159
815
  updateValues(newFieldValues);
1160
816
  }
1161
817
  if (field.calculateCustomValidationProperties) {
@@ -1167,46 +823,33 @@ function updateField(field, requiredFields, node, formValues, validations, confi
1167
823
  updateValues(newFieldValues);
1168
824
  }
1169
825
  }
1170
- function processNode({
1171
- node,
1172
- formValues,
1173
- formFields,
1174
- accRequired = /* @__PURE__ */ new Set(),
1175
- parentID = "root",
1176
- validations
1177
- }) {
826
+ function processNode(node, formValues, formFields, accRequired = /* @__PURE__ */ new Set()) {
1178
827
  const requiredFields = new Set(accRequired);
1179
828
  Object.keys(node.properties ?? []).forEach((fieldName) => {
1180
829
  const field = getField(fieldName, formFields);
1181
- updateField(field, requiredFields, node, formValues, validations, { parentID });
830
+ updateField(field, requiredFields, node, formValues);
1182
831
  });
1183
832
  node.required?.forEach((fieldName) => {
1184
833
  requiredFields.add(fieldName);
1185
- updateField(getField(fieldName, formFields), requiredFields, node, formValues, validations, {
1186
- parentID
1187
- });
834
+ updateField(getField(fieldName, formFields), requiredFields, node, formValues);
1188
835
  });
1189
836
  if (node.if) {
1190
- const matchesCondition = checkIfConditionMatches(node, formValues, formFields, validations);
837
+ const matchesCondition = checkIfConditionMatches(node, formValues, formFields);
1191
838
  if (matchesCondition && node.then) {
1192
- const { required: branchRequired } = processNode({
1193
- node: node.then,
839
+ const { required: branchRequired } = processNode(
840
+ node.then,
1194
841
  formValues,
1195
842
  formFields,
1196
- accRequired: requiredFields,
1197
- parentID,
1198
- validations
1199
- });
843
+ requiredFields
844
+ );
1200
845
  branchRequired.forEach((field) => requiredFields.add(field));
1201
846
  } else if (node.else) {
1202
- const { required: branchRequired } = processNode({
1203
- node: node.else,
847
+ const { required: branchRequired } = processNode(
848
+ node.else,
1204
849
  formValues,
1205
850
  formFields,
1206
- accRequired: requiredFields,
1207
- parentID,
1208
- validations
1209
- });
851
+ requiredFields
852
+ );
1210
853
  branchRequired.forEach((field) => requiredFields.add(field));
1211
854
  }
1212
855
  }
@@ -1218,21 +861,12 @@ function processNode({
1218
861
  node.anyOf.forEach(({ required = [] }) => {
1219
862
  required.forEach((fieldName) => {
1220
863
  const field = getField(fieldName, formFields);
1221
- updateField(field, requiredFields, node, formValues, validations, { parentID });
864
+ updateField(field, requiredFields, node, formValues);
1222
865
  });
1223
866
  });
1224
867
  }
1225
868
  if (node.allOf) {
1226
- node.allOf.map(
1227
- (allOfNode) => processNode({
1228
- node: allOfNode,
1229
- formValues,
1230
- formFields,
1231
- accRequired: requiredFields,
1232
- parentID,
1233
- validations
1234
- })
1235
- ).forEach(({ required: allOfItemRequired }) => {
869
+ node.allOf.map((allOfNode) => processNode(allOfNode, formValues, formFields, requiredFields)).forEach(({ required: allOfItemRequired }) => {
1236
870
  allOfItemRequired.forEach(requiredFields.add, requiredFields);
1237
871
  });
1238
872
  }
@@ -1240,27 +874,10 @@ function processNode({
1240
874
  Object.entries(node.properties).forEach(([name, nestedNode]) => {
1241
875
  const inputType = getInputType(nestedNode);
1242
876
  if (inputType === supportedTypes.FIELDSET) {
1243
- processNode({
1244
- node: nestedNode,
1245
- formValues: formValues[name] || {},
1246
- formFields: getField(name, formFields).fields,
1247
- validations,
1248
- parentID: name
1249
- });
877
+ processNode(nestedNode, formValues[name] || {}, getField(name, formFields).fields);
1250
878
  }
1251
879
  });
1252
880
  }
1253
- if (node["x-jsf-logic"]) {
1254
- const { required: requiredFromLogic } = processJSONLogicNode({
1255
- node: node["x-jsf-logic"],
1256
- formValues,
1257
- formFields,
1258
- accRequired: requiredFields,
1259
- parentID,
1260
- validations
1261
- });
1262
- requiredFromLogic.forEach((field) => requiredFields.add(field));
1263
- }
1264
881
  return {
1265
882
  required: requiredFields
1266
883
  };
@@ -1275,11 +892,11 @@ function clearValuesIfNotVisible(fields, formValues) {
1275
892
  }
1276
893
  });
1277
894
  }
1278
- function updateFieldsProperties(fields, formValues, jsonSchema, validations) {
895
+ function updateFieldsProperties(fields, formValues, jsonSchema) {
1279
896
  if (!jsonSchema?.properties) {
1280
897
  return;
1281
898
  }
1282
- processNode({ node: jsonSchema, formValues, formFields: fields, validations });
899
+ processNode(jsonSchema, formValues, fields);
1283
900
  clearValuesIfNotVisible(fields, formValues);
1284
901
  }
1285
902
  var notNullOption = (opt) => opt.const !== null;
@@ -1322,20 +939,12 @@ function extractParametersFromNode(schemaNode) {
1322
939
  }
1323
940
  const presentation = pickXKey(schemaNode, "presentation") ?? {};
1324
941
  const errorMessage = pickXKey(schemaNode, "errorMessage") ?? {};
1325
- const requiredValidations = schemaNode["x-jsf-logic-validations"];
1326
- const computedAttributes = schemaNode["x-jsf-logic-computedAttrs"];
1327
- const decoratedComputedAttributes = {
1328
- ...computedAttributes ?? {},
1329
- ...computedAttributes?.const && computedAttributes?.default ? { value: computedAttributes.const } : {}
1330
- };
1331
942
  const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
1332
943
  const description = presentation?.description || node.description;
1333
944
  const statementDescription = containsHTML(presentation.statement?.description) ? wrapWithSpan(presentation.statement.description, { class: "jsf-statement" }) : presentation.statement?.description;
1334
945
  return (0, import_omitBy.default)(
1335
946
  {
1336
947
  const: node.const,
1337
- // This is a "forced value" when both const and default are present.
1338
- ...node.const && node.default ? { value: node.const } : {},
1339
948
  label: node.title,
1340
949
  readOnly: node.readOnly,
1341
950
  ...node.deprecated && {
@@ -1370,8 +979,6 @@ function extractParametersFromNode(schemaNode) {
1370
979
  },
1371
980
  // Handle [name].presentation
1372
981
  ...presentation,
1373
- requiredValidations,
1374
- computedAttributes: decoratedComputedAttributes,
1375
982
  description: containsHTML(description) ? wrapWithSpan(description, {
1376
983
  class: "jsf-description"
1377
984
  }) : description,
@@ -1408,9 +1015,9 @@ function yupToFormErrors(yupError) {
1408
1015
  }
1409
1016
  return errors;
1410
1017
  }
1411
- var handleValuesChange = (fields, jsonSchema, config, validations) => (values) => {
1412
- updateFieldsProperties(fields, values, jsonSchema, validations);
1413
- const lazySchema = (0, import_yup2.lazy)(() => buildCompleteYupSchema(fields, config, validations));
1018
+ var handleValuesChange = (fields, jsonSchema, config) => (values) => {
1019
+ updateFieldsProperties(fields, values, jsonSchema);
1020
+ const lazySchema = (0, import_yup2.lazy)(() => buildCompleteYupSchema(fields, config));
1414
1021
  let errors;
1415
1022
  try {
1416
1023
  lazySchema.validateSync(values, {
@@ -1464,8 +1071,8 @@ function rebuildFieldset(fields, property) {
1464
1071
  required: isFieldRequired(property, field)
1465
1072
  }));
1466
1073
  }
1467
- function calculateConditionalProperties(fieldParams, customProperties, validations, config) {
1468
- return (isRequired, conditionBranch, __, _, formValues) => {
1074
+ function calculateConditionalProperties(fieldParams, customProperties) {
1075
+ return (isRequired, conditionBranch) => {
1469
1076
  const conditionalProperty = conditionBranch?.properties?.[fieldParams.name];
1470
1077
  if (conditionalProperty) {
1471
1078
  const presentation = pickXKey(conditionalProperty, "presentation") ?? {};
@@ -1479,31 +1086,17 @@ function calculateConditionalProperties(fieldParams, customProperties, validatio
1479
1086
  fieldSetFields = rebuildFieldset(fieldParams.fields, conditionalProperty);
1480
1087
  newFieldParams.fields = fieldSetFields;
1481
1088
  }
1482
- const { computedAttributes, ...restNewFieldParams } = newFieldParams;
1483
- const calculatedComputedAttributes = computedAttributes ? calculateComputedAttributes(newFieldParams, config)({ validations, formValues }) : {};
1484
- const requiredValidations = [
1485
- ...fieldParams.requiredValidations ?? [],
1486
- ...restNewFieldParams.requiredValidations ?? []
1487
- ];
1488
1089
  const base = {
1489
1090
  isVisible: true,
1490
1091
  required: isRequired,
1491
1092
  ...presentation?.inputType && { type: presentation.inputType },
1492
- ...calculatedComputedAttributes,
1493
- ...calculatedComputedAttributes.value ? { value: calculatedComputedAttributes.value } : { value: void 0 },
1494
- schema: buildYupSchema(
1495
- {
1496
- ...fieldParams,
1497
- ...restNewFieldParams,
1498
- ...calculatedComputedAttributes,
1499
- requiredValidations,
1500
- // If there are inner fields (case of fieldset) they need to be updated based on the condition
1501
- fields: fieldSetFields,
1502
- required: isRequired
1503
- },
1504
- config,
1505
- validations
1506
- )
1093
+ schema: buildYupSchema({
1094
+ ...fieldParams,
1095
+ ...newFieldParams,
1096
+ // If there are inner fields (case of fieldset) they need to be updated based on the condition
1097
+ fields: fieldSetFields,
1098
+ required: isRequired
1099
+ })
1507
1100
  };
1508
1101
  return (0, import_omit2.default)((0, import_merge2.default)(base, presentation, newFieldParams), ["inputType"]);
1509
1102
  }
@@ -1597,19 +1190,14 @@ function sortByOrderOrPosition(a, b, order) {
1597
1190
  function removeInvalidAttributes(fields) {
1598
1191
  return (0, import_omit3.default)(fields, ["items", "maxFileSize", "isDynamic"]);
1599
1192
  }
1600
- function buildFieldParameters(name, fieldProperties, required = [], config = {}, validations) {
1193
+ function buildFieldParameters(name, fieldProperties, required = [], config = {}) {
1601
1194
  const { position } = pickXKey(fieldProperties, "presentation") ?? {};
1602
1195
  let fields;
1603
1196
  const inputType = getInputType(fieldProperties, config.strictInputType, name);
1604
1197
  if (inputType === supportedTypes.FIELDSET) {
1605
- fields = getFieldsFromJSONSchema(
1606
- fieldProperties,
1607
- {
1608
- customProperties: (0, import_get3.default)(config, `customProperties.${name}`, {}),
1609
- parentID: name
1610
- },
1611
- validations
1612
- );
1198
+ fields = getFieldsFromJSONSchema(fieldProperties, {
1199
+ customProperties: (0, import_get3.default)(config, `customProperties.${name}`, {})
1200
+ });
1613
1201
  }
1614
1202
  const result = {
1615
1203
  name,
@@ -1624,9 +1212,9 @@ function buildFieldParameters(name, fieldProperties, required = [], config = {},
1624
1212
  };
1625
1213
  return (0, import_omitBy2.default)(result, import_isNil3.default);
1626
1214
  }
1627
- function convertJSONSchemaPropertiesToFieldParameters({ properties, required, "x-jsf-order": order }, config = {}, validations) {
1215
+ function convertJSONSchemaPropertiesToFieldParameters({ properties, required, "x-jsf-order": order }, config = {}) {
1628
1216
  const sortFields = (a, b) => sortByOrderOrPosition(a, b, order);
1629
- return Object.entries(properties).filter(([, value]) => typeof value === "object").map(([key, value]) => buildFieldParameters(key, value, required, config, validations)).sort(sortFields).map(({ position, ...fieldParams }) => fieldParams);
1217
+ return Object.entries(properties).filter(([, value]) => typeof value === "object").map(([key, value]) => buildFieldParameters(key, value, required, config)).sort(sortFields).map(({ position, ...fieldParams }) => fieldParams);
1630
1218
  }
1631
1219
  function applyFieldsDependencies(fieldsParameters, node) {
1632
1220
  if (node?.then) {
@@ -1648,9 +1236,6 @@ function applyFieldsDependencies(fieldsParameters, node) {
1648
1236
  applyFieldsDependencies(fieldsParameters, condition);
1649
1237
  });
1650
1238
  }
1651
- if (node?.["x-jsf-logic"]) {
1652
- applyFieldsDependencies(fieldsParameters, node["x-jsf-logic"]);
1653
- }
1654
1239
  }
1655
1240
  function getCustomPropertiesForField(fieldParams, config) {
1656
1241
  return config?.customProperties?.[fieldParams.name];
@@ -1662,16 +1247,15 @@ function getComposeFunctionForField(fieldParams, hasCustomizations) {
1662
1247
  }
1663
1248
  return composeFn;
1664
1249
  }
1665
- function buildField(fieldParams, config, scopedJsonSchema, validations) {
1250
+ function buildField(fieldParams, config, scopedJsonSchema) {
1666
1251
  const customProperties = getCustomPropertiesForField(fieldParams, config);
1667
1252
  const composeFn = getComposeFunctionForField(fieldParams, !!customProperties);
1668
- const yupSchema = buildYupSchema(fieldParams, config, validations);
1669
- const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties, validations, config);
1253
+ const yupSchema = buildYupSchema(fieldParams, config);
1254
+ const calculateConditionalFieldsClosure = fieldParams.isDynamic && calculateConditionalProperties(fieldParams, customProperties);
1670
1255
  const calculateCustomValidationPropertiesClosure = calculateCustomValidationProperties(
1671
1256
  fieldParams,
1672
1257
  customProperties
1673
1258
  );
1674
- const getComputedAttributes = Object.keys(fieldParams.computedAttributes).length > 0 && calculateComputedAttributes(fieldParams, config);
1675
1259
  const hasCustomValidations = !!customProperties && (0, import_size.default)((0, import_pick2.default)(customProperties, SUPPORTED_CUSTOM_VALIDATION_FIELD_PARAMS)) > 0;
1676
1260
  const finalFieldParams = {
1677
1261
  // invalid attribute cleanup
@@ -1684,7 +1268,6 @@ function buildField(fieldParams, config, scopedJsonSchema, validations) {
1684
1268
  ...hasCustomValidations && {
1685
1269
  calculateCustomValidationProperties: calculateCustomValidationPropertiesClosure
1686
1270
  },
1687
- ...getComputedAttributes && { getComputedAttributes },
1688
1271
  // field customization properties
1689
1272
  ...customProperties && { fieldCustomization: customProperties },
1690
1273
  // base schema
@@ -1693,15 +1276,11 @@ function buildField(fieldParams, config, scopedJsonSchema, validations) {
1693
1276
  };
1694
1277
  return composeFn(finalFieldParams);
1695
1278
  }
1696
- function getFieldsFromJSONSchema(scopedJsonSchema, config, validations) {
1279
+ function getFieldsFromJSONSchema(scopedJsonSchema, config) {
1697
1280
  if (!scopedJsonSchema) {
1698
1281
  return [];
1699
1282
  }
1700
- const fieldParamsList = convertJSONSchemaPropertiesToFieldParameters(
1701
- scopedJsonSchema,
1702
- config,
1703
- validations
1704
- );
1283
+ const fieldParamsList = convertJSONSchemaPropertiesToFieldParameters(scopedJsonSchema, config);
1705
1284
  applyFieldsDependencies(fieldParamsList, scopedJsonSchema);
1706
1285
  const fields = [];
1707
1286
  fieldParamsList.forEach((fieldParams) => {
@@ -1721,11 +1300,11 @@ function getFieldsFromJSONSchema(scopedJsonSchema, config, validations) {
1721
1300
  fields: () => groupArrayFields,
1722
1301
  addFieldText: fieldParams.addFieldText
1723
1302
  };
1724
- buildField(fieldParams, config, scopedJsonSchema, validations).forEach((groupField) => {
1303
+ buildField(fieldParams, config, scopedJsonSchema).forEach((groupField) => {
1725
1304
  fields.push(groupField);
1726
1305
  });
1727
1306
  } else {
1728
- fields.push(buildField(fieldParams, config, scopedJsonSchema, validations));
1307
+ fields.push(buildField(fieldParams, config, scopedJsonSchema));
1729
1308
  }
1730
1309
  });
1731
1310
  return fields;
@@ -1736,15 +1315,9 @@ function createHeadlessForm(jsonSchema, customConfig = {}) {
1736
1315
  ...customConfig
1737
1316
  };
1738
1317
  try {
1739
- const validations = createValidationChecker(jsonSchema);
1740
- const fields = getFieldsFromJSONSchema(jsonSchema, config, validations);
1741
- const handleValidation = handleValuesChange(fields, jsonSchema, config, validations);
1742
- updateFieldsProperties(
1743
- fields,
1744
- getPrefillValues(fields, config.initialValues),
1745
- jsonSchema,
1746
- validations
1747
- );
1318
+ const fields = getFieldsFromJSONSchema(jsonSchema, config);
1319
+ const handleValidation = handleValuesChange(fields, jsonSchema, config);
1320
+ updateFieldsProperties(fields, getPrefillValues(fields, config.initialValues), jsonSchema);
1748
1321
  return {
1749
1322
  fields,
1750
1323
  handleValidation,