uniforms-bridge-json-schema
Advanced tools
Comparing version 4.0.0-alpha.3 to 4.0.0-alpha.4
@@ -227,15 +227,14 @@ "use strict"; | ||
} | ||
const options = props.options; | ||
let options = props.options; | ||
if (options) { | ||
if (Array.isArray(options)) { | ||
props.allowedValues = options.map(option => option.value); | ||
props.transform = (value) => options.find(option => option.value === value).label; | ||
if (!Array.isArray(options)) { | ||
options = Object.entries(options).map(([key, value]) => ({ | ||
key, | ||
label: key, | ||
value, | ||
})); | ||
} | ||
else { | ||
props.allowedValues = Object.keys(options); | ||
props.transform = (value) => options[value]; | ||
} | ||
} | ||
else if (props.enum) { | ||
props.allowedValues = props.enum; | ||
options = Object.values(props.enum).map(value => ({ value })); | ||
} | ||
@@ -253,3 +252,3 @@ propsToRename.forEach(([key, newKey]) => { | ||
}); | ||
return props; | ||
return Object.assign(props, { options }); | ||
} | ||
@@ -256,0 +255,0 @@ getSubfields(name = '') { |
@@ -225,15 +225,14 @@ import { __rest } from "tslib"; | ||
} | ||
const options = props.options; | ||
let options = props.options; | ||
if (options) { | ||
if (Array.isArray(options)) { | ||
props.allowedValues = options.map(option => option.value); | ||
props.transform = (value) => options.find(option => option.value === value).label; | ||
if (!Array.isArray(options)) { | ||
options = Object.entries(options).map(([key, value]) => ({ | ||
key, | ||
label: key, | ||
value, | ||
})); | ||
} | ||
else { | ||
props.allowedValues = Object.keys(options); | ||
props.transform = (value) => options[value]; | ||
} | ||
} | ||
else if (props.enum) { | ||
props.allowedValues = props.enum; | ||
options = Object.values(props.enum).map(value => ({ value })); | ||
} | ||
@@ -251,3 +250,3 @@ propsToRename.forEach(([key, newKey]) => { | ||
}); | ||
return props; | ||
return Object.assign(props, { options }); | ||
} | ||
@@ -254,0 +253,0 @@ getSubfields(name = '') { |
{ | ||
"name": "uniforms-bridge-json-schema", | ||
"version": "4.0.0-alpha.3", | ||
"version": "4.0.0-alpha.4", | ||
"license": "MIT", | ||
@@ -39,5 +39,5 @@ "main": "./cjs/index.js", | ||
"tslib": "^2.2.0", | ||
"uniforms": "^4.0.0-alpha.3" | ||
"uniforms": "^4.0.0-alpha.4" | ||
}, | ||
"gitHead": "1353ab3a541d279a50e2dadfbc8e7684fd1a4fab" | ||
"gitHead": "e046d871f3514c8f7e2d45cf957495444507b848" | ||
} |
@@ -89,2 +89,10 @@ import invariant from 'invariant'; | ||
/** Option type used in SelectField or RadioField */ | ||
type Option<Value> = { | ||
disabled?: boolean; | ||
label?: string; | ||
key?: string; | ||
value: Value; | ||
}; | ||
type FieldError = { | ||
@@ -310,17 +318,17 @@ instancePath?: string; | ||
type OptionDict = Record<string, string>; | ||
type OptionList = { label: string; value: unknown }[]; | ||
type Options = OptionDict | OptionList; | ||
const options: Options = props.options; | ||
type OptionList = Option<unknown>[]; | ||
type OptionDict = Record<string, unknown>; | ||
type Options = OptionList | OptionDict; | ||
let options: Options | undefined = props.options; | ||
if (options) { | ||
if (Array.isArray(options)) { | ||
props.allowedValues = options.map(option => option.value); | ||
props.transform = (value: unknown) => | ||
options.find(option => option.value === value)!.label; | ||
} else { | ||
props.allowedValues = Object.keys(options); | ||
props.transform = (value: string) => options[value]; | ||
if (!Array.isArray(options)) { | ||
options = Object.entries(options).map(([key, value]) => ({ | ||
key, | ||
label: key, | ||
value, | ||
})); | ||
} | ||
} else if (props.enum) { | ||
props.allowedValues = props.enum; | ||
options = Object.values(props.enum).map(value => ({ value })); | ||
} | ||
@@ -341,3 +349,3 @@ | ||
return props; | ||
return Object.assign(props, { options }); | ||
} | ||
@@ -344,0 +352,0 @@ |
40655
18
1021
Updateduniforms@^4.0.0-alpha.4