@makehq/forman-schema 1.9.2 → 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 +32 -1
- package/dist/index.js +32 -1
- package/package.json +1 -1
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
|
-
|
|
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,11 @@ 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
|
+
}
|
|
1035
1051
|
var FORMAN_TYPE_MAP2 = {
|
|
1036
1052
|
account: "number",
|
|
1037
1053
|
hook: "number",
|
|
@@ -1187,6 +1203,9 @@ async function validateFormanValue(value, field, context) {
|
|
|
1187
1203
|
};
|
|
1188
1204
|
}
|
|
1189
1205
|
if (value == null) {
|
|
1206
|
+
if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
|
|
1207
|
+
return handleSelectType(value, normalizedField, context);
|
|
1208
|
+
}
|
|
1190
1209
|
return {
|
|
1191
1210
|
valid: true,
|
|
1192
1211
|
errors: []
|
|
@@ -1659,6 +1678,18 @@ async function handleSelectType(value, field, context) {
|
|
|
1659
1678
|
});
|
|
1660
1679
|
}
|
|
1661
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;
|
|
1662
1693
|
} else {
|
|
1663
1694
|
const item = findValueInSelectOptions(field, value, optionsOrGroups);
|
|
1664
1695
|
if (!item) {
|
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
|
-
|
|
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,11 @@ 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
|
+
}
|
|
1006
1022
|
var FORMAN_TYPE_MAP2 = {
|
|
1007
1023
|
account: "number",
|
|
1008
1024
|
hook: "number",
|
|
@@ -1158,6 +1174,9 @@ async function validateFormanValue(value, field, context) {
|
|
|
1158
1174
|
};
|
|
1159
1175
|
}
|
|
1160
1176
|
if (value == null) {
|
|
1177
|
+
if (normalizedField.type === "select" && hasPlaceholderNested(normalizedField)) {
|
|
1178
|
+
return handleSelectType(value, normalizedField, context);
|
|
1179
|
+
}
|
|
1161
1180
|
return {
|
|
1162
1181
|
valid: true,
|
|
1163
1182
|
errors: []
|
|
@@ -1630,6 +1649,18 @@ async function handleSelectType(value, field, context) {
|
|
|
1630
1649
|
});
|
|
1631
1650
|
}
|
|
1632
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;
|
|
1633
1664
|
} else {
|
|
1634
1665
|
const item = findValueInSelectOptions(field, value, optionsOrGroups);
|
|
1635
1666
|
if (!item) {
|