@makehq/forman-schema 1.9.2 → 1.9.4

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
@@ -873,7 +873,7 @@ function handleSelectOrPathType(field, result, context) {
873
873
  value: appendQueryString(optionsOrGroups, context.domain, context.tail)
874
874
  });
875
875
  } else {
876
- const options = optionsOrGroups?.flatMap((optionOrGroup) => {
876
+ let options = optionsOrGroups?.flatMap((optionOrGroup) => {
877
877
  if (isOptionGroup(optionOrGroup)) {
878
878
  return optionOrGroup.options.map((option) => ({
879
879
  ...option,
@@ -882,6 +882,17 @@ function handleSelectOrPathType(field, result, context) {
882
882
  }
883
883
  return optionOrGroup;
884
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
+ }
885
896
  if (options?.some((option) => {
886
897
  if (isOptionGroup(option)) return option.options.some((option2) => option2.label || option2.nested);
887
898
  return option.label || option.nested;
@@ -1032,6 +1043,16 @@ function processNestedDirective(field, nested, domain, result, context) {
1032
1043
  }
1033
1044
 
1034
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
+ }
1051
+ function extractNestedFromField(field) {
1052
+ if (field.nested) return field.nested;
1053
+ if (isObject(field.options) && field.options.nested) return field.options.nested;
1054
+ return void 0;
1055
+ }
1035
1056
  var FORMAN_TYPE_MAP2 = {
1036
1057
  account: "number",
1037
1058
  hook: "number",
@@ -1187,6 +1208,9 @@ async function validateFormanValue(value, field, context) {
1187
1208
  };
1188
1209
  }
1189
1210
  if (value == null) {
1211
+ if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1212
+ return handleSelectType(value, normalizedField, context);
1213
+ }
1190
1214
  return {
1191
1215
  valid: true,
1192
1216
  errors: []
@@ -1226,6 +1250,10 @@ async function validateFormanValue(value, field, context) {
1226
1250
  state: { mode: "edit" }
1227
1251
  });
1228
1252
  }
1253
+ const nested = extractNestedFromField(normalizedField);
1254
+ if (nested) {
1255
+ return handleNestedFields(nested, value, normalizedField, context);
1256
+ }
1229
1257
  return {
1230
1258
  valid: true,
1231
1259
  errors: []
@@ -1583,7 +1611,7 @@ async function handlePathType(value, field, context) {
1583
1611
  async function handleSelectType(value, field, context) {
1584
1612
  const errors = [];
1585
1613
  let optionsOrGroups = isObject(field.options) ? field.options.store : field.options;
1586
- let nested = field.nested ? field.nested : isObject(field.options) ? field.options.nested : void 0;
1614
+ let nested = extractNestedFromField(field);
1587
1615
  if (typeof optionsOrGroups === "string") {
1588
1616
  try {
1589
1617
  const resolved = await context.resolveRemote(optionsOrGroups, context);
@@ -1659,6 +1687,18 @@ async function handleSelectType(value, field, context) {
1659
1687
  });
1660
1688
  }
1661
1689
  }
1690
+ } else if (value == null && hasPlaceholderNested(field)) {
1691
+ const placeholder = field.options.placeholder;
1692
+ if (placeholder.label) {
1693
+ context.roots[context.domain].fieldStates.push({
1694
+ path: context.path,
1695
+ state: {
1696
+ mode: "chose",
1697
+ label: placeholder.label
1698
+ }
1699
+ });
1700
+ }
1701
+ if (placeholder.nested) nested = placeholder.nested;
1662
1702
  } else {
1663
1703
  const item = findValueInSelectOptions(field, value, optionsOrGroups);
1664
1704
  if (!item) {
@@ -1805,8 +1845,9 @@ async function handlePrimitiveType2(value, field, context) {
1805
1845
  }
1806
1846
  }
1807
1847
  }
1808
- if (field.nested) {
1809
- const result = await handleNestedFields(field.nested, value, field, context);
1848
+ const nested = extractNestedFromField(field);
1849
+ if (nested) {
1850
+ const result = await handleNestedFields(nested, value, field, context);
1810
1851
  errors.push(...result.errors);
1811
1852
  }
1812
1853
  return {
package/dist/index.js CHANGED
@@ -844,7 +844,7 @@ function handleSelectOrPathType(field, result, context) {
844
844
  value: appendQueryString(optionsOrGroups, context.domain, context.tail)
845
845
  });
846
846
  } else {
847
- const options = optionsOrGroups?.flatMap((optionOrGroup) => {
847
+ let options = optionsOrGroups?.flatMap((optionOrGroup) => {
848
848
  if (isOptionGroup(optionOrGroup)) {
849
849
  return optionOrGroup.options.map((option) => ({
850
850
  ...option,
@@ -853,6 +853,17 @@ function handleSelectOrPathType(field, result, context) {
853
853
  }
854
854
  return optionOrGroup;
855
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
+ }
856
867
  if (options?.some((option) => {
857
868
  if (isOptionGroup(option)) return option.options.some((option2) => option2.label || option2.nested);
858
869
  return option.label || option.nested;
@@ -1003,6 +1014,16 @@ function processNestedDirective(field, nested, domain, result, context) {
1003
1014
  }
1004
1015
 
1005
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
+ }
1022
+ function extractNestedFromField(field) {
1023
+ if (field.nested) return field.nested;
1024
+ if (isObject(field.options) && field.options.nested) return field.options.nested;
1025
+ return void 0;
1026
+ }
1006
1027
  var FORMAN_TYPE_MAP2 = {
1007
1028
  account: "number",
1008
1029
  hook: "number",
@@ -1158,6 +1179,9 @@ async function validateFormanValue(value, field, context) {
1158
1179
  };
1159
1180
  }
1160
1181
  if (value == null) {
1182
+ if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
1183
+ return handleSelectType(value, normalizedField, context);
1184
+ }
1161
1185
  return {
1162
1186
  valid: true,
1163
1187
  errors: []
@@ -1197,6 +1221,10 @@ async function validateFormanValue(value, field, context) {
1197
1221
  state: { mode: "edit" }
1198
1222
  });
1199
1223
  }
1224
+ const nested = extractNestedFromField(normalizedField);
1225
+ if (nested) {
1226
+ return handleNestedFields(nested, value, normalizedField, context);
1227
+ }
1200
1228
  return {
1201
1229
  valid: true,
1202
1230
  errors: []
@@ -1554,7 +1582,7 @@ async function handlePathType(value, field, context) {
1554
1582
  async function handleSelectType(value, field, context) {
1555
1583
  const errors = [];
1556
1584
  let optionsOrGroups = isObject(field.options) ? field.options.store : field.options;
1557
- let nested = field.nested ? field.nested : isObject(field.options) ? field.options.nested : void 0;
1585
+ let nested = extractNestedFromField(field);
1558
1586
  if (typeof optionsOrGroups === "string") {
1559
1587
  try {
1560
1588
  const resolved = await context.resolveRemote(optionsOrGroups, context);
@@ -1630,6 +1658,18 @@ async function handleSelectType(value, field, context) {
1630
1658
  });
1631
1659
  }
1632
1660
  }
1661
+ } else if (value == null && hasPlaceholderNested(field)) {
1662
+ const placeholder = field.options.placeholder;
1663
+ if (placeholder.label) {
1664
+ context.roots[context.domain].fieldStates.push({
1665
+ path: context.path,
1666
+ state: {
1667
+ mode: "chose",
1668
+ label: placeholder.label
1669
+ }
1670
+ });
1671
+ }
1672
+ if (placeholder.nested) nested = placeholder.nested;
1633
1673
  } else {
1634
1674
  const item = findValueInSelectOptions(field, value, optionsOrGroups);
1635
1675
  if (!item) {
@@ -1776,8 +1816,9 @@ async function handlePrimitiveType2(value, field, context) {
1776
1816
  }
1777
1817
  }
1778
1818
  }
1779
- if (field.nested) {
1780
- const result = await handleNestedFields(field.nested, value, field, context);
1819
+ const nested = extractNestedFromField(field);
1820
+ if (nested) {
1821
+ const result = await handleNestedFields(nested, value, field, context);
1781
1822
  errors.push(...result.errors);
1782
1823
  }
1783
1824
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makehq/forman-schema",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
4
4
  "description": "Forman Schema Tools",
5
5
  "license": "MIT",
6
6
  "author": "Make",