react-jsonschema-form
Advanced tools
Comparing version 0.50.0 to 0.50.1
@@ -19,2 +19,6 @@ "use strict"; | ||
var _UnsupportedField = require("./UnsupportedField"); | ||
var _UnsupportedField2 = _interopRequireDefault(_UnsupportedField); | ||
var _utils = require("../../utils"); | ||
@@ -140,6 +144,6 @@ | ||
idSchema: props.idSchema, | ||
title: props.title, | ||
title: props.uiSchema["ui:title"] || props.title, | ||
required: props.required | ||
}), | ||
props.schema.description && _react2.default.createElement( | ||
(props.uiSchema["ui:description"] || props.schema.description) && _react2.default.createElement( | ||
"div", | ||
@@ -149,3 +153,3 @@ { | ||
key: "field-description-" + props.idSchema.$id }, | ||
props.schema.description | ||
props.uiSchema["ui:description"] || props.schema.description | ||
), | ||
@@ -174,10 +178,10 @@ _react2.default.createElement( | ||
idSchema: props.idSchema, | ||
title: props.title, | ||
title: props.uiSchema["ui:title"] || props.title, | ||
required: props.required | ||
}), | ||
props.schema.description && _react2.default.createElement(ArrayFieldDescription, { | ||
(props.uiSchema["ui:description"] || props.schema.description) && _react2.default.createElement(ArrayFieldDescription, { | ||
key: "array-field-description-" + props.idSchema.$id, | ||
DescriptionField: props.DescriptionField, | ||
idSchema: props.idSchema, | ||
description: props.schema.description | ||
description: props.uiSchema["ui:description"] || props.schema.description | ||
}), | ||
@@ -293,4 +297,4 @@ _react2.default.createElement( | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
key: "canAddItem", | ||
value: function canAddItem(formItems) { | ||
var _props = this.props, | ||
@@ -300,9 +304,41 @@ schema = _props.schema, | ||
if ((0, _utils.isFilesArray)(schema, uiSchema)) { | ||
return this.renderFiles(); | ||
var _getUiOptions = (0, _utils.getUiOptions)(uiSchema), | ||
addable = _getUiOptions.addable; | ||
if (addable !== false) { | ||
// if ui:options.addable was not explicitly set to false, we can add | ||
// another item if we have not exceeded maxItems yet | ||
if (schema.maxItems !== undefined) { | ||
addable = formItems.length < schema.maxItems; | ||
} else { | ||
addable = true; | ||
} | ||
} | ||
return addable; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _props2 = this.props, | ||
schema = _props2.schema, | ||
uiSchema = _props2.uiSchema, | ||
idSchema = _props2.idSchema, | ||
_props2$registry = _props2.registry, | ||
registry = _props2$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props2$registry; | ||
var definitions = registry.definitions; | ||
if (!schema.hasOwnProperty("items")) { | ||
return _react2.default.createElement(_UnsupportedField2.default, { | ||
schema: schema, | ||
idSchema: idSchema, | ||
reason: "Missing items definition" | ||
}); | ||
} | ||
if ((0, _utils.isFixedItems)(schema)) { | ||
return this.renderFixedArray(); | ||
} | ||
if ((0, _utils.isMultiSelect)(schema)) { | ||
if ((0, _utils.isFilesArray)(schema, uiSchema, definitions)) { | ||
return this.renderFiles(); | ||
} | ||
if ((0, _utils.isMultiSelect)(schema, definitions)) { | ||
return this.renderMultiSelect(); | ||
@@ -317,17 +353,18 @@ } | ||
var _props2 = this.props, | ||
schema = _props2.schema, | ||
uiSchema = _props2.uiSchema, | ||
formData = _props2.formData, | ||
errorSchema = _props2.errorSchema, | ||
idSchema = _props2.idSchema, | ||
name = _props2.name, | ||
required = _props2.required, | ||
disabled = _props2.disabled, | ||
readonly = _props2.readonly, | ||
autofocus = _props2.autofocus, | ||
_props2$registry = _props2.registry, | ||
registry = _props2$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props2$registry, | ||
formContext = _props2.formContext, | ||
onBlur = _props2.onBlur; | ||
var _props3 = this.props, | ||
schema = _props3.schema, | ||
uiSchema = _props3.uiSchema, | ||
formData = _props3.formData, | ||
errorSchema = _props3.errorSchema, | ||
idSchema = _props3.idSchema, | ||
name = _props3.name, | ||
required = _props3.required, | ||
disabled = _props3.disabled, | ||
readonly = _props3.readonly, | ||
autofocus = _props3.autofocus, | ||
_props3$registry = _props3.registry, | ||
registry = _props3$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props3$registry, | ||
formContext = _props3.formContext, | ||
onBlur = _props3.onBlur, | ||
onFocus = _props3.onFocus; | ||
@@ -342,9 +379,4 @@ var title = schema.title === undefined ? name : schema.title; | ||
var itemsSchema = (0, _utils.retrieveSchema)(schema.items, definitions); | ||
var _getUiOptions = (0, _utils.getUiOptions)(uiSchema), | ||
_getUiOptions$addable = _getUiOptions.addable, | ||
addable = _getUiOptions$addable === undefined ? true : _getUiOptions$addable; | ||
var arrayProps = { | ||
canAdd: addable, | ||
canAdd: this.canAddItem(formData), | ||
items: formData.map(function (item, index) { | ||
@@ -364,3 +396,4 @@ var itemErrorSchema = errorSchema ? errorSchema[index] : undefined; | ||
autofocus: autofocus && index === 0, | ||
onBlur: onBlur | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}); | ||
@@ -379,3 +412,4 @@ }), | ||
TitleField: TitleField, | ||
formContext: formContext | ||
formContext: formContext, | ||
formData: formData | ||
}; | ||
@@ -390,12 +424,13 @@ | ||
value: function renderMultiSelect() { | ||
var _props3 = this.props, | ||
schema = _props3.schema, | ||
idSchema = _props3.idSchema, | ||
uiSchema = _props3.uiSchema, | ||
disabled = _props3.disabled, | ||
readonly = _props3.readonly, | ||
autofocus = _props3.autofocus, | ||
onBlur = _props3.onBlur, | ||
_props3$registry = _props3.registry, | ||
registry = _props3$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props3$registry; | ||
var _props4 = this.props, | ||
schema = _props4.schema, | ||
idSchema = _props4.idSchema, | ||
uiSchema = _props4.uiSchema, | ||
disabled = _props4.disabled, | ||
readonly = _props4.readonly, | ||
autofocus = _props4.autofocus, | ||
onBlur = _props4.onBlur, | ||
onFocus = _props4.onFocus, | ||
_props4$registry = _props4.registry, | ||
registry = _props4$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props4$registry; | ||
@@ -423,2 +458,3 @@ var items = this.props.formData; | ||
onBlur: onBlur, | ||
onFocus: onFocus, | ||
options: options, | ||
@@ -436,13 +472,14 @@ schema: schema, | ||
value: function renderFiles() { | ||
var _props4 = this.props, | ||
schema = _props4.schema, | ||
uiSchema = _props4.uiSchema, | ||
idSchema = _props4.idSchema, | ||
name = _props4.name, | ||
disabled = _props4.disabled, | ||
readonly = _props4.readonly, | ||
autofocus = _props4.autofocus, | ||
onBlur = _props4.onBlur, | ||
_props4$registry = _props4.registry, | ||
registry = _props4$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props4$registry; | ||
var _props5 = this.props, | ||
schema = _props5.schema, | ||
uiSchema = _props5.uiSchema, | ||
idSchema = _props5.idSchema, | ||
name = _props5.name, | ||
disabled = _props5.disabled, | ||
readonly = _props5.readonly, | ||
autofocus = _props5.autofocus, | ||
onBlur = _props5.onBlur, | ||
onFocus = _props5.onFocus, | ||
_props5$registry = _props5.registry, | ||
registry = _props5$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props5$registry; | ||
@@ -466,2 +503,3 @@ var title = schema.title || name; | ||
onBlur: onBlur, | ||
onFocus: onFocus, | ||
schema: schema, | ||
@@ -481,15 +519,16 @@ title: title, | ||
var _props5 = this.props, | ||
schema = _props5.schema, | ||
uiSchema = _props5.uiSchema, | ||
errorSchema = _props5.errorSchema, | ||
idSchema = _props5.idSchema, | ||
name = _props5.name, | ||
required = _props5.required, | ||
disabled = _props5.disabled, | ||
readonly = _props5.readonly, | ||
autofocus = _props5.autofocus, | ||
_props5$registry = _props5.registry, | ||
registry = _props5$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props5$registry, | ||
onBlur = _props5.onBlur; | ||
var _props6 = this.props, | ||
schema = _props6.schema, | ||
uiSchema = _props6.uiSchema, | ||
errorSchema = _props6.errorSchema, | ||
idSchema = _props6.idSchema, | ||
name = _props6.name, | ||
required = _props6.required, | ||
disabled = _props6.disabled, | ||
readonly = _props6.readonly, | ||
autofocus = _props6.autofocus, | ||
_props6$registry = _props6.registry, | ||
registry = _props6$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props6$registry, | ||
onBlur = _props6.onBlur, | ||
onFocus = _props6.onFocus; | ||
@@ -508,8 +547,2 @@ var title = schema.title || name; | ||
var _getUiOptions3 = (0, _utils.getUiOptions)(uiSchema), | ||
_getUiOptions3$addabl = _getUiOptions3.addable, | ||
addable = _getUiOptions3$addabl === undefined ? true : _getUiOptions3$addabl; | ||
var canAdd = addable && additionalSchema; | ||
if (!items || items.length < itemSchemas.length) { | ||
@@ -523,3 +556,3 @@ // to make sure at least all fixed items are generated | ||
var arrayProps = { | ||
canAdd: canAdd, | ||
canAdd: this.canAddItem(items) && additionalSchema, | ||
className: "field field-array field-array-fixed-items", | ||
@@ -547,3 +580,4 @@ disabled: disabled, | ||
autofocus: autofocus && index === 0, | ||
onBlur: onBlur | ||
onBlur: onBlur, | ||
onFocus: onFocus | ||
}); | ||
@@ -580,9 +614,10 @@ }), | ||
autofocus = props.autofocus, | ||
onBlur = props.onBlur; | ||
var _props6 = this.props, | ||
disabled = _props6.disabled, | ||
readonly = _props6.readonly, | ||
uiSchema = _props6.uiSchema, | ||
_props6$registry = _props6.registry, | ||
registry = _props6$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props6$registry; | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus; | ||
var _props7 = this.props, | ||
disabled = _props7.disabled, | ||
readonly = _props7.readonly, | ||
uiSchema = _props7.uiSchema, | ||
_props7$registry = _props7.registry, | ||
registry = _props7$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props7$registry; | ||
var SchemaField = registry.fields.SchemaField; | ||
@@ -616,2 +651,3 @@ | ||
onBlur: onBlur, | ||
onFocus: onFocus, | ||
registry: this.props.registry, | ||
@@ -693,2 +729,3 @@ disabled: this.props.disabled, | ||
onBlur: _propTypes2.default.func, | ||
onFocus: _propTypes2.default.func, | ||
formData: _propTypes2.default.array, | ||
@@ -695,0 +732,0 @@ required: _propTypes2.default.bool, |
@@ -74,2 +74,3 @@ "use strict"; | ||
onBlur = _props.onBlur, | ||
onFocus = _props.onFocus, | ||
_props$registry = _props.registry, | ||
@@ -117,11 +118,11 @@ registry = _props$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props$registry; | ||
null, | ||
title && _react2.default.createElement(TitleField, { | ||
(uiSchema["ui:title"] || title) && _react2.default.createElement(TitleField, { | ||
id: idSchema.$id + "__title", | ||
title: title, | ||
title: uiSchema["ui:title"] || title, | ||
required: required, | ||
formContext: formContext | ||
}), | ||
schema.description && _react2.default.createElement(DescriptionField, { | ||
(uiSchema["ui:description"] || schema.description) && _react2.default.createElement(DescriptionField, { | ||
id: idSchema.$id + "__description", | ||
description: schema.description, | ||
description: uiSchema["ui:description"] || schema.description, | ||
formContext: formContext | ||
@@ -141,2 +142,3 @@ }), | ||
onBlur: onBlur, | ||
onFocus: onFocus, | ||
registry: registry, | ||
@@ -143,0 +145,0 @@ disabled: disabled, |
@@ -45,3 +45,3 @@ "use strict"; | ||
function getFieldComponent(schema, uiSchema, fields) { | ||
function getFieldComponent(schema, uiSchema, idSchema, fields) { | ||
var field = uiSchema["ui:field"]; | ||
@@ -55,3 +55,9 @@ if (typeof field === "function") { | ||
var componentName = COMPONENT_TYPES[schema.type]; | ||
return componentName in fields ? fields[componentName] : _UnsupportedField2.default; | ||
return componentName in fields ? fields[componentName] : function () { | ||
return _react2.default.createElement(_UnsupportedField2.default, { | ||
schema: schema, | ||
idSchema: idSchema, | ||
reason: "Unknown field type " + schema.type | ||
}); | ||
}; | ||
} | ||
@@ -191,3 +197,3 @@ | ||
var schema = (0, _utils.retrieveSchema)(props.schema, definitions); | ||
var FieldComponent = getFieldComponent(schema, uiSchema, fields); | ||
var FieldComponent = getFieldComponent(schema, uiSchema, idSchema, fields); | ||
var DescriptionField = fields.DescriptionField; | ||
@@ -209,3 +215,3 @@ | ||
if (schema.type === "array") { | ||
displayLabel = (0, _utils.isMultiSelect)(schema) || (0, _utils.isFilesArray)(schema, uiSchema); | ||
displayLabel = (0, _utils.isMultiSelect)(schema, definitions) || (0, _utils.isFilesArray)(schema, uiSchema, definitions); | ||
} | ||
@@ -241,4 +247,4 @@ if (schema.type === "object") { | ||
var id = idSchema.$id; | ||
var label = props.schema.title || schema.title || name; | ||
var description = props.schema.description || schema.description; | ||
var label = uiSchema["ui:title"] || props.schema.title || schema.title || name; | ||
var description = uiSchema["ui:description"] || props.schema.description || schema.description; | ||
var errors = __errors; | ||
@@ -245,0 +251,0 @@ var help = uiSchema["ui:help"]; |
@@ -35,2 +35,3 @@ "use strict"; | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
_props$registry = props.registry, | ||
@@ -43,3 +44,3 @@ registry = _props$registry === undefined ? (0, _utils.getDefaultRegistry)() : _props$registry; | ||
var enumOptions = Array.isArray(schema.enum) && (0, _utils.optionsList)(schema); | ||
var enumOptions = (0, _utils.isSelect)(schema) && (0, _utils.optionsList)(schema); | ||
var defaultWidget = format || (enumOptions ? "select" : "text"); | ||
@@ -64,2 +65,3 @@ | ||
onBlur: onBlur, | ||
onFocus: onFocus, | ||
required: required, | ||
@@ -82,2 +84,3 @@ disabled: disabled, | ||
onBlur: _propTypes2.default.func, | ||
onFocus: _propTypes2.default.func, | ||
formData: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]), | ||
@@ -84,0 +87,0 @@ registry: _propTypes2.default.shape({ |
@@ -6,3 +6,2 @@ "use strict"; | ||
}); | ||
exports.default = UnsupportedField; | ||
@@ -13,15 +12,55 @@ var _react = require("react"); | ||
var _propTypes = require("prop-types"); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function UnsupportedField(_ref) { | ||
var schema = _ref.schema; | ||
var schema = _ref.schema, | ||
idSchema = _ref.idSchema, | ||
reason = _ref.reason; | ||
// XXX render json as string so dev can inspect faulty subschema | ||
return _react2.default.createElement( | ||
"div", | ||
{ className: "unsupported-field" }, | ||
"Unsupported field schema ", | ||
JSON.stringify(schema, null, 2), | ||
"." | ||
_react2.default.createElement( | ||
"p", | ||
null, | ||
"Unsupported field schema", | ||
idSchema && idSchema.$id && _react2.default.createElement( | ||
"span", | ||
null, | ||
" for", | ||
" field ", | ||
_react2.default.createElement( | ||
"code", | ||
null, | ||
idSchema.$id | ||
) | ||
), | ||
reason && _react2.default.createElement( | ||
"em", | ||
null, | ||
": ", | ||
reason | ||
), | ||
"." | ||
), | ||
schema && _react2.default.createElement( | ||
"pre", | ||
null, | ||
JSON.stringify(schema, null, 2) | ||
) | ||
); | ||
} | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
UnsupportedField.propTypes = { | ||
schema: _propTypes2.default.object.isRequired, | ||
idSchema: _propTypes2.default.object, | ||
reason: _propTypes2.default.string | ||
}; | ||
} | ||
exports.default = UnsupportedField; |
@@ -51,3 +51,3 @@ "use strict"; | ||
var mustValidate = !_this.props.noValidate && (_this.props.liveValidate || options.validate); | ||
var state = { status: "editing", formData: formData }; | ||
var state = { formData: formData }; | ||
if (mustValidate) { | ||
@@ -75,5 +75,12 @@ var _this$validate = _this.validate(formData), | ||
_this.onFocus = function () { | ||
if (_this.props.onFocus) { | ||
var _this$props2; | ||
(_this$props2 = _this.props).onFocus.apply(_this$props2, arguments); | ||
} | ||
}; | ||
_this.onSubmit = function (event) { | ||
event.preventDefault(); | ||
_this.setState({ status: "submitted" }); | ||
@@ -104,5 +111,5 @@ if (!_this.props.noValidate) { | ||
if (_this.props.onSubmit) { | ||
_this.props.onSubmit(_this.state); | ||
_this.props.onSubmit(_extends({}, _this.state, { status: "submitted" })); | ||
} | ||
_this.setState({ status: "initial", errors: [], errorSchema: {} }); | ||
_this.setState({ errors: [], errorSchema: {} }); | ||
}; | ||
@@ -141,3 +148,2 @@ | ||
return { | ||
status: "initial", | ||
schema: schema, | ||
@@ -170,11 +176,20 @@ uiSchema: uiSchema, | ||
var _state = this.state, | ||
status = _state.status, | ||
errors = _state.errors; | ||
errors = _state.errors, | ||
errorSchema = _state.errorSchema, | ||
schema = _state.schema, | ||
uiSchema = _state.uiSchema; | ||
var _props2 = this.props, | ||
ErrorList = _props2.ErrorList, | ||
showErrorList = _props2.showErrorList; | ||
showErrorList = _props2.showErrorList, | ||
formContext = _props2.formContext; | ||
if (status !== "editing" && errors.length && showErrorList != false) { | ||
return _react2.default.createElement(ErrorList, { errors: errors }); | ||
if (errors.length && showErrorList != false) { | ||
return _react2.default.createElement(ErrorList, { | ||
errors: errors, | ||
errorSchema: errorSchema, | ||
schema: schema, | ||
uiSchema: uiSchema, | ||
formContext: formContext | ||
}); | ||
} | ||
@@ -250,2 +265,3 @@ return null; | ||
onBlur: this.onBlur, | ||
onFocus: this.onFocus, | ||
registry: registry, | ||
@@ -252,0 +268,0 @@ safeRenderCompletion: safeRenderCompletion |
@@ -29,2 +29,3 @@ "use strict"; | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
options = props.options, | ||
@@ -34,3 +35,3 @@ schema = props.schema, | ||
registry = props.registry, | ||
inputProps = _objectWithoutProperties(props, ["value", "readonly", "disabled", "autofocus", "onBlur", "options", "schema", "formContext", "registry"]); | ||
inputProps = _objectWithoutProperties(props, ["value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "options", "schema", "formContext", "registry"]); | ||
@@ -53,2 +54,5 @@ inputProps.type = options.inputType || inputProps.type || "text"; | ||
return onBlur(inputProps.id, event.target.value); | ||
}, | ||
onFocus: onFocus && function (event) { | ||
return onFocus(inputProps.id, event.target.value); | ||
} | ||
@@ -76,3 +80,4 @@ })); | ||
onChange: _propTypes2.default.func, | ||
onBlur: _propTypes2.default.func | ||
onBlur: _propTypes2.default.func, | ||
onFocus: _propTypes2.default.func | ||
}; | ||
@@ -79,0 +84,0 @@ } |
@@ -63,2 +63,3 @@ "use strict"; | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus, | ||
placeholder = props.placeholder; | ||
@@ -82,2 +83,6 @@ var enumOptions = options.enumOptions; | ||
}, | ||
onFocus: onFocus && function (event) { | ||
var newValue = getValue(event, multiple); | ||
onFocus(id, processValue(schema, newValue)); | ||
}, | ||
onChange: function onChange(event) { | ||
@@ -123,3 +128,4 @@ var newValue = getValue(event, multiple); | ||
onChange: _propTypes2.default.func, | ||
onBlur: _propTypes2.default.func | ||
onBlur: _propTypes2.default.func, | ||
onFocus: _propTypes2.default.func | ||
}; | ||
@@ -126,0 +132,0 @@ } |
@@ -27,3 +27,4 @@ "use strict"; | ||
onChange = props.onChange, | ||
onBlur = props.onBlur; | ||
onBlur = props.onBlur, | ||
onFocus = props.onFocus; | ||
@@ -48,2 +49,5 @@ var _onChange = function _onChange(_ref) { | ||
}, | ||
onFocus: onFocus && function (event) { | ||
return onFocus(id, event.target.value); | ||
}, | ||
onChange: _onChange | ||
@@ -72,3 +76,4 @@ }); | ||
onChange: _propTypes2.default.func, | ||
onBlur: _propTypes2.default.func | ||
onBlur: _propTypes2.default.func, | ||
onFocus: _propTypes2.default.func | ||
}; | ||
@@ -75,0 +80,0 @@ } |
@@ -19,2 +19,5 @@ "use strict"; | ||
exports.orderProperties = orderProperties; | ||
exports.isConstant = isConstant; | ||
exports.toConstant = toConstant; | ||
exports.isSelect = isSelect; | ||
exports.isMultiSelect = isMultiSelect; | ||
@@ -186,3 +189,3 @@ exports.isFilesArray = isFilesArray; | ||
case "object": | ||
return Object.keys(schema.properties).reduce(function (acc, key) { | ||
return Object.keys(schema.properties || {}).reduce(function (acc, key) { | ||
// Compute the defaults for this node, with the parent defaults we might | ||
@@ -196,3 +199,15 @@ // have from a previous run: defaults[key]. | ||
if (schema.minItems) { | ||
return new Array(schema.minItems).fill(computeDefaults(schema.items, defaults, definitions)); | ||
if (!isMultiSelect(schema, definitions)) { | ||
var defaultsLength = defaults ? defaults.length : 0; | ||
if (schema.minItems > defaultsLength) { | ||
var defaultEntries = defaults || []; | ||
// populate the array with the defaults | ||
var fillerEntries = new Array(schema.minItems - defaultsLength).fill(computeDefaults(schema.items, schema.items.defaults, definitions)); | ||
// then fill up the rest with either the item default or empty, up to minItems | ||
return defaultEntries.concat(fillerEntries); | ||
} | ||
} else { | ||
return []; | ||
} | ||
} | ||
@@ -332,8 +347,54 @@ } | ||
/** | ||
* This function checks if the given schema matches a single | ||
* constant value. | ||
*/ | ||
function isConstant(schema) { | ||
return Array.isArray(schema.enum) && schema.enum.length === 1 || schema.hasOwnProperty("const"); | ||
} | ||
function toConstant(schema) { | ||
if (Array.isArray(schema.enum) && schema.enum.length === 1) { | ||
return schema.enum[0]; | ||
} else if (schema.hasOwnProperty("const")) { | ||
return schema.const; | ||
} else { | ||
throw new Error("schema cannot be inferred as a constant"); | ||
} | ||
} | ||
function isSelect(_schema) { | ||
var definitions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var schema = retrieveSchema(_schema, definitions); | ||
var altSchemas = schema.oneOf || schema.anyOf; | ||
if (Array.isArray(schema.enum)) { | ||
return true; | ||
} else if (Array.isArray(altSchemas)) { | ||
return altSchemas.every(function (altSchemas) { | ||
return isConstant(altSchemas); | ||
}); | ||
} | ||
return false; | ||
} | ||
function isMultiSelect(schema) { | ||
return Array.isArray(schema.items.enum) && schema.uniqueItems; | ||
var definitions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!schema.uniqueItems || !schema.items) { | ||
return false; | ||
} | ||
return isSelect(schema.items, definitions); | ||
} | ||
function isFilesArray(schema, uiSchema) { | ||
return schema.items.type === "string" && schema.items.format === "data-url" || uiSchema["ui:widget"] === "files"; | ||
var definitions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (uiSchema["ui:widget"] === "files") { | ||
return true; | ||
} else if (schema.items) { | ||
var itemsSchema = retrieveSchema(schema.items, definitions); | ||
return itemsSchema.type === "string" && itemsSchema.format === "data-url"; | ||
} | ||
return false; | ||
} | ||
@@ -355,6 +416,15 @@ | ||
function optionsList(schema) { | ||
return schema.enum.map(function (value, i) { | ||
var label = schema.enumNames && schema.enumNames[i] || String(value); | ||
return { label: label, value: value }; | ||
}); | ||
if (schema.enum) { | ||
return schema.enum.map(function (value, i) { | ||
var label = schema.enumNames && schema.enumNames[i] || String(value); | ||
return { label: label, value: value }; | ||
}); | ||
} else { | ||
var altSchemas = schema.oneOf || schema.anyOf; | ||
return altSchemas.map(function (schema, i) { | ||
var value = toConstant(schema); | ||
var label = schema.title || String(value); | ||
return { label: label, value: value }; | ||
}); | ||
} | ||
} | ||
@@ -361,0 +431,0 @@ |
{ | ||
"name": "react-jsonschema-form", | ||
"version": "0.50.0", | ||
"version": "0.50.1", | ||
"description": "A simple React component capable of building HTML forms out of a JSON schema.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1015443
4139
30