get more code from old version of rjsf
This commit is contained in:
parent
b6f50a65f3
commit
384c28c1c3
|
@ -2,8 +2,89 @@ import { Select, SelectItem } from '@carbon/react';
|
|||
import { WidgetProps } from '@rjsf/utils';
|
||||
import { getCommonAttributes } from '../../helpers';
|
||||
|
||||
// this processSelectValue code is pulled from rjsf/utils version 5.0.0-beta.20
|
||||
// this guessType, asNumber, and processSelectValue code is pulled from rjsf/utils version 5.0.0-beta.20
|
||||
// the function was removed.
|
||||
/** Given a specific `value` attempts to guess the type of a schema element. In the case where we have to implicitly
|
||||
* create a schema, it is useful to know what type to use based on the data we are defining.
|
||||
*
|
||||
* @param value - The value from which to guess the type
|
||||
* @returns - The best guess for the object type
|
||||
*/
|
||||
function guessType(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return 'array';
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return 'string';
|
||||
}
|
||||
if (value == null) {
|
||||
return 'null';
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return 'boolean';
|
||||
}
|
||||
if (!isNaN(value)) {
|
||||
return 'number';
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
return 'object';
|
||||
}
|
||||
// Default to string if we can't figure it out
|
||||
return 'string';
|
||||
}
|
||||
|
||||
/** Attempts to convert the string into a number. If an empty string is provided, then `undefined` is returned. If a
|
||||
* `null` is provided, it is returned. If the string ends in a `.` then the string is returned because the user may be
|
||||
* in the middle of typing a float number. If a number ends in a pattern like `.0`, `.20`, `.030`, string is returned
|
||||
* because the user may be typing number that will end in a non-zero digit. Otherwise, the string is wrapped by
|
||||
* `Number()` and if that result is not `NaN`, that number will be returned, otherwise the string `value` will be.
|
||||
*
|
||||
* @param value - The string or null value to convert to a number
|
||||
* @returns - The `value` converted to a number when appropriate, otherwise the `value`
|
||||
*/
|
||||
function asNumber(value) {
|
||||
if (value === '') {
|
||||
return undefined;
|
||||
}
|
||||
if (value === null) {
|
||||
return null;
|
||||
}
|
||||
if (/\.$/.test(value)) {
|
||||
// '3.' can't really be considered a number even if it parses in js. The
|
||||
// user is most likely entering a float.
|
||||
return value;
|
||||
}
|
||||
if (/\.0$/.test(value)) {
|
||||
// we need to return this as a string here, to allow for input like 3.07
|
||||
return value;
|
||||
}
|
||||
if (/\.\d*0$/.test(value)) {
|
||||
// It's a number, that's cool - but we need it as a string so it doesn't screw
|
||||
// with the user when entering dollar amounts or other values (such as those with
|
||||
// specific precision or number of significant digits)
|
||||
return value;
|
||||
}
|
||||
var n = Number(value);
|
||||
var valid = typeof n === 'number' && !Number.isNaN(n);
|
||||
return valid ? n : value;
|
||||
}
|
||||
|
||||
function get(object, path) {
|
||||
// Split the path into an array of keys
|
||||
const keys = Array.isArray(path) ? path : path.split('.');
|
||||
|
||||
// Traverse the object along the keys
|
||||
let result = object;
|
||||
for (let key of keys) {
|
||||
if (result == null) {
|
||||
return undefined; // If the path does not exist, return undefined
|
||||
}
|
||||
result = result[key];
|
||||
}
|
||||
|
||||
return result; // Return the found value or undefined if not found
|
||||
}
|
||||
|
||||
var nums = /*#__PURE__*/ new Set(['number', 'integer']);
|
||||
/** Returns the real value for a select widget due to a silly limitation in the DOM which causes option change event
|
||||
* values to always be retrieved as strings. Uses the `schema` to help determine the value's true type. If the value is
|
||||
|
|
Loading…
Reference in New Issue