swoop-common 2.0.3 → 2.0.5
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.
|
@@ -9,7 +9,7 @@ export const generateJsonSchema = (formSchema, stage, onlyEditableFields) => {
|
|
|
9
9
|
properties: {},
|
|
10
10
|
required: [],
|
|
11
11
|
};
|
|
12
|
-
formSchema.forEach(s => {
|
|
12
|
+
formSchema.forEach((s) => {
|
|
13
13
|
if (stage < s.existsFrom)
|
|
14
14
|
return;
|
|
15
15
|
if (onlyEditableFields && !s.editableIn.includes(stage))
|
|
@@ -32,12 +32,17 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
|
|
|
32
32
|
field.fieldType = (_a = field.fieldType) !== null && _a !== void 0 ? _a : "string";
|
|
33
33
|
let schema = getType(field.fieldType);
|
|
34
34
|
if (!schema)
|
|
35
|
-
throw new Error("tried to generate schema from unknown type: " +
|
|
35
|
+
throw new Error("tried to generate schema from unknown type: " +
|
|
36
|
+
field.fieldType +
|
|
37
|
+
"\nFull object: " +
|
|
38
|
+
JSON.stringify(field, null, 2));
|
|
36
39
|
const requiredFields = [];
|
|
37
40
|
if (field.required)
|
|
38
41
|
requiredFields.push(field.name);
|
|
39
42
|
// Specific for array
|
|
40
|
-
let arrayItems = field.fieldType === "array"
|
|
43
|
+
let arrayItems = field.fieldType === "array"
|
|
44
|
+
? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true)
|
|
45
|
+
: undefined;
|
|
41
46
|
// Obj childs
|
|
42
47
|
const properties = {};
|
|
43
48
|
for (const child of (_d = (_c = field.objectOptions) === null || _c === void 0 ? void 0 : _c.properties) !== null && _d !== void 0 ? _d : []) {
|
|
@@ -46,16 +51,20 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
|
|
|
46
51
|
if (child.required)
|
|
47
52
|
requiredFields.push(fieldId);
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
enumOptions.
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
let enumOpts = field.fieldType === "enum" || field.fieldType === "stagedEnum"
|
|
55
|
+
? (() => {
|
|
56
|
+
var _a;
|
|
57
|
+
let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) ||
|
|
58
|
+
[]);
|
|
59
|
+
if (enumOptions.length === 0)
|
|
60
|
+
enumOptions.push("");
|
|
61
|
+
return enumOptions;
|
|
62
|
+
})()
|
|
63
|
+
: undefined;
|
|
57
64
|
// Component (probably should change this)
|
|
58
|
-
let templates = field.fieldType === "componentPicker"
|
|
65
|
+
let templates = field.fieldType === "componentPicker"
|
|
66
|
+
? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds }
|
|
67
|
+
: {};
|
|
59
68
|
let title = omitTitle ? undefined : field.name;
|
|
60
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (
|
|
69
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (!isChild && !field.editableIn.includes(stage) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
|
|
61
70
|
};
|
|
@@ -40,6 +40,20 @@ registerType("enum", "Dropdown", { type: "string" }, {
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
}, true);
|
|
43
|
+
registerType("stagedEnum", "Staged Dropdown", {
|
|
44
|
+
type: "array",
|
|
45
|
+
items: { type: "string" },
|
|
46
|
+
}, {
|
|
47
|
+
type: "object",
|
|
48
|
+
title: "Dropdown Options",
|
|
49
|
+
properties: {
|
|
50
|
+
enumValues: {
|
|
51
|
+
title: "Dropdown Values",
|
|
52
|
+
type: "array",
|
|
53
|
+
items: { type: "string" },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
}, true);
|
|
43
57
|
registerType("array", "List", { type: "array" }, {
|
|
44
58
|
type: "object",
|
|
45
59
|
title: "List Options",
|