@makehq/forman-schema 1.9.1 → 1.9.3

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
@@ -45,6 +45,10 @@ var FORMAN_REFERENCE_TYPES = [
45
45
  function isReferenceType(type) {
46
46
  return FORMAN_REFERENCE_TYPES.includes(type);
47
47
  }
48
+ var EDITABLE_TYPES = ["select", "file", "folder", "boolean"];
49
+ function isEditableType(type) {
50
+ return EDITABLE_TYPES.includes(type);
51
+ }
48
52
  function noEmpty(text) {
49
53
  return text?.trim() || void 0;
50
54
  }
@@ -869,7 +873,7 @@ function handleSelectOrPathType(field, result, context) {
869
873
  value: appendQueryString(optionsOrGroups, context.domain, context.tail)
870
874
  });
871
875
  } else {
872
- const options = optionsOrGroups?.flatMap((optionOrGroup) => {
876
+ let options = optionsOrGroups?.flatMap((optionOrGroup) => {
873
877
  if (isOptionGroup(optionOrGroup)) {
874
878
  return optionOrGroup.options.map((option) => ({
875
879
  ...option,
@@ -878,6 +882,17 @@ function handleSelectOrPathType(field, result, context) {
878
882
  }
879
883
  return optionOrGroup;
880
884
  });
885
+ if (field.type === "select" && !field.required && isObject(field.options)) {
886
+ const placeholder = field.options.placeholder;
887
+ if (isObject(placeholder) && placeholder.nested) {
888
+ (options ||= []).push({
889
+ value: null,
890
+ label: placeholder.label,
891
+ nested: placeholder.nested
892
+ });
893
+ result.type = [result.type, "null"];
894
+ }
895
+ }
881
896
  if (options?.some((option) => {
882
897
  if (isOptionGroup(option)) return option.options.some((option2) => option2.label || option2.nested);
883
898
  return option.label || option.nested;
@@ -1028,6 +1043,11 @@ function processNestedDirective(field, nested, domain, result, context) {
1028
1043
  }
1029
1044
 
1030
1045
  // src/validator.ts
1046
+ function hasPlaceholderNested(field) {
1047
+ if (!isObject(field.options)) return false;
1048
+ const placeholder = field.options.placeholder;
1049
+ return isObject(placeholder) && placeholder.nested != null;
1050
+ }
1031
1051
  var FORMAN_TYPE_MAP2 = {
1032
1052
  account: "number",
1033
1053
  hook: "number",
@@ -1183,6 +1203,9 @@ async function validateFormanValue(value, field, context) {
1183
1203
  };
1184
1204
  }
1185
1205
  if (value == null) {
1206
+ if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1207
+ return handleSelectType(value, normalizedField, context);
1208
+ }
1186
1209
  return {
1187
1210
  valid: true,
1188
1211
  errors: []
@@ -1216,6 +1239,12 @@ async function validateFormanValue(value, field, context) {
1216
1239
  ]
1217
1240
  };
1218
1241
  }
1242
+ if (isEditableType(normalizedField.type)) {
1243
+ context.roots[context.domain].fieldStates.push({
1244
+ path: [...context.path],
1245
+ state: { mode: "edit" }
1246
+ });
1247
+ }
1219
1248
  return {
1220
1249
  valid: true,
1221
1250
  errors: []
@@ -1649,6 +1678,18 @@ async function handleSelectType(value, field, context) {
1649
1678
  });
1650
1679
  }
1651
1680
  }
1681
+ } else if (value == null && hasPlaceholderNested(field)) {
1682
+ const placeholder = field.options.placeholder;
1683
+ if (placeholder.label) {
1684
+ context.roots[context.domain].fieldStates.push({
1685
+ path: context.path,
1686
+ state: {
1687
+ mode: "chose",
1688
+ label: placeholder.label
1689
+ }
1690
+ });
1691
+ }
1692
+ if (placeholder.nested) nested = placeholder.nested;
1652
1693
  } else {
1653
1694
  const item = findValueInSelectOptions(field, value, optionsOrGroups);
1654
1695
  if (!item) {
package/dist/index.js CHANGED
@@ -16,6 +16,10 @@ var FORMAN_REFERENCE_TYPES = [
16
16
  function isReferenceType(type) {
17
17
  return FORMAN_REFERENCE_TYPES.includes(type);
18
18
  }
19
+ var EDITABLE_TYPES = ["select", "file", "folder", "boolean"];
20
+ function isEditableType(type) {
21
+ return EDITABLE_TYPES.includes(type);
22
+ }
19
23
  function noEmpty(text) {
20
24
  return text?.trim() || void 0;
21
25
  }
@@ -840,7 +844,7 @@ function handleSelectOrPathType(field, result, context) {
840
844
  value: appendQueryString(optionsOrGroups, context.domain, context.tail)
841
845
  });
842
846
  } else {
843
- const options = optionsOrGroups?.flatMap((optionOrGroup) => {
847
+ let options = optionsOrGroups?.flatMap((optionOrGroup) => {
844
848
  if (isOptionGroup(optionOrGroup)) {
845
849
  return optionOrGroup.options.map((option) => ({
846
850
  ...option,
@@ -849,6 +853,17 @@ function handleSelectOrPathType(field, result, context) {
849
853
  }
850
854
  return optionOrGroup;
851
855
  });
856
+ if (field.type === "select" && !field.required && isObject(field.options)) {
857
+ const placeholder = field.options.placeholder;
858
+ if (isObject(placeholder) && placeholder.nested) {
859
+ (options ||= []).push({
860
+ value: null,
861
+ label: placeholder.label,
862
+ nested: placeholder.nested
863
+ });
864
+ result.type = [result.type, "null"];
865
+ }
866
+ }
852
867
  if (options?.some((option) => {
853
868
  if (isOptionGroup(option)) return option.options.some((option2) => option2.label || option2.nested);
854
869
  return option.label || option.nested;
@@ -999,6 +1014,11 @@ function processNestedDirective(field, nested, domain, result, context) {
999
1014
  }
1000
1015
 
1001
1016
  // src/validator.ts
1017
+ function hasPlaceholderNested(field) {
1018
+ if (!isObject(field.options)) return false;
1019
+ const placeholder = field.options.placeholder;
1020
+ return isObject(placeholder) && placeholder.nested != null;
1021
+ }
1002
1022
  var FORMAN_TYPE_MAP2 = {
1003
1023
  account: "number",
1004
1024
  hook: "number",
@@ -1154,6 +1174,9 @@ async function validateFormanValue(value, field, context) {
1154
1174
  };
1155
1175
  }
1156
1176
  if (value == null) {
1177
+ if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1178
+ return handleSelectType(value, normalizedField, context);
1179
+ }
1157
1180
  return {
1158
1181
  valid: true,
1159
1182
  errors: []
@@ -1187,6 +1210,12 @@ async function validateFormanValue(value, field, context) {
1187
1210
  ]
1188
1211
  };
1189
1212
  }
1213
+ if (isEditableType(normalizedField.type)) {
1214
+ context.roots[context.domain].fieldStates.push({
1215
+ path: [...context.path],
1216
+ state: { mode: "edit" }
1217
+ });
1218
+ }
1190
1219
  return {
1191
1220
  valid: true,
1192
1221
  errors: []
@@ -1620,6 +1649,18 @@ async function handleSelectType(value, field, context) {
1620
1649
  });
1621
1650
  }
1622
1651
  }
1652
+ } else if (value == null && hasPlaceholderNested(field)) {
1653
+ const placeholder = field.options.placeholder;
1654
+ if (placeholder.label) {
1655
+ context.roots[context.domain].fieldStates.push({
1656
+ path: context.path,
1657
+ state: {
1658
+ mode: "chose",
1659
+ label: placeholder.label
1660
+ }
1661
+ });
1662
+ }
1663
+ if (placeholder.nested) nested = placeholder.nested;
1623
1664
  } else {
1624
1665
  const item = findValueInSelectOptions(field, value, optionsOrGroups);
1625
1666
  if (!item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makehq/forman-schema",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "Forman Schema Tools",
5
5
  "license": "MIT",
6
6
  "author": "Make",