UNPKG

@tsed/schema-formio

Version:

Transform Ts.ED Schema & JsonSchema to a valid Formio schema

29 lines (28 loc) 955 B
import { cleanObject } from "@tsed/core"; import { execMapper, registerFormioMapper } from "../registries/FormioMappersContainer.js"; export function enumToComponent(schema, options) { const component = execMapper("default", schema, options); const values = schema.enum.map((value) => { return { label: value, value }; }); if (component.type === "select") { return cleanObject({ ...component, data: { json: component.data?.json || JSON.stringify(values) }, dataSrc: "json", idPath: "value", valueProperty: "value", template: component.template || "<span>{{ item.label }}</span>" }); } return cleanObject({ ...component, values: schema["x-values"] || values.map((value) => ({ ...value, shortcut: "" })) }); } registerFormioMapper("enum", enumToComponent);