Skip to content

Commit

Permalink
Bump version 2.8.3 and update dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
bhch committed Jul 24, 2023
1 parent 8c9bc68 commit 689ac76
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
33 changes: 31 additions & 2 deletions dist/react-json-form.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ function getKey(obj, key, default_value) {
let val = obj[key];
return typeof val !== 'undefined' ? val : default_value;
}
function valueInChoices(schema, value) {
/* Checks whether the given value is in schema choices or not.
If schema doesn't have choices, returns true.
*/
let choices = getKeyword(schema, 'choices', 'enum');
if (!choices) return true;
let found = choices.find(choice => {
if (typeof choice == 'object') choice = choice.value;
return value == choice;
});
return found !== undefined ? true : false;
}
/* Set operations */

function isEqualset(a, b) {
Expand Down Expand Up @@ -323,6 +335,9 @@ function getSyncedArray(data, schema, getRef) {
if (item === FILLER) item = {};
newData[i] = getSyncedObject(item, schema.items, getRef);
} else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schema.items, newData[i])) item = FILLER;

if (item === FILLER) {
if (type === 'integer' || type === 'number') newData[i] = schema.items.default === 0 ? 0 : schema.items.default || null;else if (type === 'boolean') newData[i] = schema.items.default === false ? false : schema.items.default || null;else newData[i] = schema.items.default || '';
}
Expand Down Expand Up @@ -358,8 +373,11 @@ function getSyncedObject(data, schema, getRef) {
if (type === 'array') newData[key] = getSyncedArray([], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject({}, schemaValue, getRef);else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
if (type === 'array') newData[key] = getSyncedArray(data[key], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject(data[key], schemaValue, getRef);else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schemaValue, data[key])) data[key] = '';

if (data[key] === '') {
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
newData[key] = data[key];
}
Expand Down Expand Up @@ -964,7 +982,7 @@ function FormSelectInput(_ref4) {
}, props), /*#__PURE__*/React__default["default"].createElement("option", {
disabled: true,
value: "",
key: '__placehlder'
key: '__placeholder'
}, "Select..."), options.map((option, i) => {
let title, inputValue;

Expand Down Expand Up @@ -3906,6 +3924,12 @@ function DataValidator(schema) {
return;
if (schema.minLength && data.length < parseInt(schema.minLength)) this.addError(coords, 'This value must be at least ' + schema.minLength + ' characters long.');
if ((schema.maxLength || schema.maxLength == 0) && data.length > parseInt(schema.maxLength)) this.addError(coords, 'This value may not be longer than ' + schema.maxLength + ' characters.');

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}

let format = normalizeKeyword(schema.format);
let format_validator;

Expand Down Expand Up @@ -3981,6 +4005,11 @@ function DataValidator(schema) {
if ((schema.exclusiveMinimum || schema.exclusiveMinimum === 0) && data <= schema.exclusiveMinimum) this.addError(coords, 'This value must be greater than ' + schema.exclusiveMinimum);
if ((schema.exclusiveMaximum || schema.exclusiveMaximum === 0) && data >= schema.exclusiveMaximum) this.addError(coords, 'This value must be less than ' + schema.exclusiveMaximum);
if ((schema.multipleOf || schema.multipleOf === 0) && data * 100 % (schema.multipleOf * 100) / 100) this.addError(coords, 'This value must be a multiple of ' + schema.multipleOf);

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}
};

this.validateEmail = function (schema, data, coords) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-json-form.js

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions dist/react-json-form.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ function getKey(obj, key, default_value) {
let val = obj[key];
return typeof val !== 'undefined' ? val : default_value;
}
function valueInChoices(schema, value) {
/* Checks whether the given value is in schema choices or not.
If schema doesn't have choices, returns true.
*/
let choices = getKeyword(schema, 'choices', 'enum');
if (!choices) return true;
let found = choices.find(choice => {
if (typeof choice == 'object') choice = choice.value;
return value == choice;
});
return found !== undefined ? true : false;
}
/* Set operations */

function isEqualset(a, b) {
Expand Down Expand Up @@ -317,6 +329,9 @@ function getSyncedArray(data, schema, getRef) {
if (item === FILLER) item = {};
newData[i] = getSyncedObject(item, schema.items, getRef);
} else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schema.items, newData[i])) item = FILLER;

if (item === FILLER) {
if (type === 'integer' || type === 'number') newData[i] = schema.items.default === 0 ? 0 : schema.items.default || null;else if (type === 'boolean') newData[i] = schema.items.default === false ? false : schema.items.default || null;else newData[i] = schema.items.default || '';
}
Expand Down Expand Up @@ -352,8 +367,11 @@ function getSyncedObject(data, schema, getRef) {
if (type === 'array') newData[key] = getSyncedArray([], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject({}, schemaValue, getRef);else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
if (type === 'array') newData[key] = getSyncedArray(data[key], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject(data[key], schemaValue, getRef);else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schemaValue, data[key])) data[key] = '';

if (data[key] === '') {
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
newData[key] = data[key];
}
Expand Down Expand Up @@ -958,7 +976,7 @@ function FormSelectInput(_ref4) {
}, props), /*#__PURE__*/React$1.createElement("option", {
disabled: true,
value: "",
key: '__placehlder'
key: '__placeholder'
}, "Select..."), options.map((option, i) => {
let title, inputValue;

Expand Down Expand Up @@ -3900,6 +3918,12 @@ function DataValidator(schema) {
return;
if (schema.minLength && data.length < parseInt(schema.minLength)) this.addError(coords, 'This value must be at least ' + schema.minLength + ' characters long.');
if ((schema.maxLength || schema.maxLength == 0) && data.length > parseInt(schema.maxLength)) this.addError(coords, 'This value may not be longer than ' + schema.maxLength + ' characters.');

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}

let format = normalizeKeyword(schema.format);
let format_validator;

Expand Down Expand Up @@ -3975,6 +3999,11 @@ function DataValidator(schema) {
if ((schema.exclusiveMinimum || schema.exclusiveMinimum === 0) && data <= schema.exclusiveMinimum) this.addError(coords, 'This value must be greater than ' + schema.exclusiveMinimum);
if ((schema.exclusiveMaximum || schema.exclusiveMaximum === 0) && data >= schema.exclusiveMaximum) this.addError(coords, 'This value must be less than ' + schema.exclusiveMaximum);
if ((schema.multipleOf || schema.multipleOf === 0) && data * 100 % (schema.multipleOf * 100) / 100) this.addError(coords, 'This value must be a multiple of ' + schema.multipleOf);

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}
};

this.validateEmail = function (schema, data, coords) {
Expand Down
33 changes: 31 additions & 2 deletions dist/react-json-form.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ function getKey(obj, key, default_value) {
let val = obj[key];
return typeof val !== 'undefined' ? val : default_value;
}
function valueInChoices(schema, value) {
/* Checks whether the given value is in schema choices or not.
If schema doesn't have choices, returns true.
*/
let choices = getKeyword(schema, 'choices', 'enum');
if (!choices) return true;
let found = choices.find(choice => {
if (typeof choice == 'object') choice = choice.value;
return value == choice;
});
return found !== undefined ? true : false;
}
/* Set operations */

function isEqualset(a, b) {
Expand Down Expand Up @@ -317,6 +329,9 @@ function getSyncedArray(data, schema, getRef) {
if (item === FILLER) item = {};
newData[i] = getSyncedObject(item, schema.items, getRef);
} else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schema.items, newData[i])) item = FILLER;

if (item === FILLER) {
if (type === 'integer' || type === 'number') newData[i] = schema.items.default === 0 ? 0 : schema.items.default || null;else if (type === 'boolean') newData[i] = schema.items.default === false ? false : schema.items.default || null;else newData[i] = schema.items.default || '';
}
Expand Down Expand Up @@ -352,8 +367,11 @@ function getSyncedObject(data, schema, getRef) {
if (type === 'array') newData[key] = getSyncedArray([], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject({}, schemaValue, getRef);else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
if (type === 'array') newData[key] = getSyncedArray(data[key], schemaValue, getRef);else if (type === 'object') newData[key] = getSyncedObject(data[key], schemaValue, getRef);else {
// if the current value is not in choices, we reset to blank
if (!valueInChoices(schemaValue, data[key])) data[key] = '';

if (data[key] === '') {
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;
if (type === 'integer' || type === 'number') newData[key] = schemaValue.default === 0 ? 0 : schemaValue.default || null;else if (type === 'boolean') newData[key] = schemaValue.default === false ? false : schemaValue.default || null;else newData[key] = schemaValue.default || '';
} else {
newData[key] = data[key];
}
Expand Down Expand Up @@ -958,7 +976,7 @@ function FormSelectInput(_ref4) {
}, props), /*#__PURE__*/React$1.createElement("option", {
disabled: true,
value: "",
key: '__placehlder'
key: '__placeholder'
}, "Select..."), options.map((option, i) => {
let title, inputValue;

Expand Down Expand Up @@ -3900,6 +3918,12 @@ function DataValidator(schema) {
return;
if (schema.minLength && data.length < parseInt(schema.minLength)) this.addError(coords, 'This value must be at least ' + schema.minLength + ' characters long.');
if ((schema.maxLength || schema.maxLength == 0) && data.length > parseInt(schema.maxLength)) this.addError(coords, 'This value may not be longer than ' + schema.maxLength + ' characters.');

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}

let format = normalizeKeyword(schema.format);
let format_validator;

Expand Down Expand Up @@ -3975,6 +3999,11 @@ function DataValidator(schema) {
if ((schema.exclusiveMinimum || schema.exclusiveMinimum === 0) && data <= schema.exclusiveMinimum) this.addError(coords, 'This value must be greater than ' + schema.exclusiveMinimum);
if ((schema.exclusiveMaximum || schema.exclusiveMaximum === 0) && data >= schema.exclusiveMaximum) this.addError(coords, 'This value must be less than ' + schema.exclusiveMaximum);
if ((schema.multipleOf || schema.multipleOf === 0) && data * 100 % (schema.multipleOf * 100) / 100) this.addError(coords, 'This value must be a multiple of ' + schema.multipleOf);

if (!valueInChoices(schema, data)) {
this.addError(coords, 'Invalid choice "' + data + '"');
return;
}
};

this.validateEmail = function (schema, data, coords) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bhch/react-json-form",
"version": "2.8.2",
"version": "2.8.3",
"description": "Create forms using JSON Schema",
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 689ac76

Please sign in to comment.