@rjsf/core
Version:
A simple React component capable of building HTML forms out of a JSON schema.
1,572 lines (1,565 loc) • 178 kB
JavaScript
// src/components/Form.tsx
import { Component as Component3, createRef } from "react";
import {
createSchemaUtils,
deepEquals as deepEquals2,
ErrorSchemaBuilder,
expandUiSchemaDefinitions,
getChangedFields,
getTemplate as getTemplate28,
getUiOptions as getUiOptions21,
isObject as isObject6,
mergeObjects,
shouldRender as shouldRender2,
SUBMIT_BTN_OPTIONS_KEY,
toErrorList,
toFieldPathId as toFieldPathId6,
UI_DEFINITIONS_KEY,
UI_GLOBAL_OPTIONS_KEY as UI_GLOBAL_OPTIONS_KEY2,
UI_OPTIONS_KEY as UI_OPTIONS_KEY3,
validationDataMerge,
DEFAULT_ID_SEPARATOR as DEFAULT_ID_SEPARATOR2,
DEFAULT_ID_PREFIX as DEFAULT_ID_PREFIX2,
ERRORS_KEY as ERRORS_KEY3,
ID_KEY as ID_KEY5,
getUsedFormData,
getFieldNames
} from "@rjsf/utils";
import _cloneDeep from "lodash/cloneDeep";
import _get from "lodash/get";
import _isEmpty from "lodash/isEmpty";
import _pick from "lodash/pick";
import _set from "lodash/set";
import _toPath from "lodash/toPath";
import _unset from "lodash/unset";
// src/getDefaultRegistry.ts
import {
DEFAULT_ID_PREFIX,
DEFAULT_ID_SEPARATOR,
englishStringTranslator
} from "@rjsf/utils";
// src/components/fields/ArrayField.tsx
import { useCallback, useMemo, useState } from "react";
import {
allowAdditionalItems,
getTemplate,
getUiOptions,
getWidget,
hashObject,
isCustomWidget,
isFixedItems,
isFormDataAvailable,
optionsList,
shouldRenderOptionalField,
toFieldPathId,
useDeepCompareMemo,
ITEMS_KEY,
ID_KEY,
TranslatableString
} from "@rjsf/utils";
import cloneDeep from "lodash/cloneDeep";
import isObject from "lodash/isObject";
import set from "lodash/set";
import uniqueId from "lodash/uniqueId";
import { jsx } from "react/jsx-runtime";
function generateRowId() {
return uniqueId("rjsf-array-item-");
}
function generateKeyedFormData(formData) {
return !Array.isArray(formData) ? [] : formData.map((item) => {
return {
key: generateRowId(),
item
};
});
}
function keyedToPlainFormData(keyedFormData) {
if (Array.isArray(keyedFormData)) {
return keyedFormData.map((keyedItem) => keyedItem.item);
}
return [];
}
function isItemRequired(itemSchema) {
if (Array.isArray(itemSchema.type)) {
return !itemSchema.type.includes("null");
}
return itemSchema.type !== "null";
}
function canAddItem(registry, schema, formItems, uiSchema) {
let { addable } = getUiOptions(uiSchema, registry.globalUiOptions);
if (addable !== false) {
if (schema.maxItems !== void 0) {
addable = formItems.length < schema.maxItems;
} else {
addable = true;
}
}
return addable;
}
function computeItemUiSchema(uiSchema, item, index, formContext) {
if (typeof uiSchema.items === "function") {
try {
const result = uiSchema.items(item, index, formContext);
return result;
} catch (e) {
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
return void 0;
}
} else {
return uiSchema.items;
}
}
function getNewFormDataRow(registry, schema) {
const { schemaUtils, globalFormOptions } = registry;
let itemSchema = schema.items;
if (globalFormOptions.useFallbackUiForUnsupportedType && !itemSchema) {
itemSchema = {};
} else if (isFixedItems(schema) && allowAdditionalItems(schema)) {
itemSchema = schema.additionalItems;
}
return schemaUtils.getDefaultFormState(itemSchema);
}
function ArrayAsMultiSelect(props) {
const {
schema,
fieldPathId,
uiSchema,
formData: items = [],
disabled = false,
readonly = false,
autofocus = false,
required = false,
placeholder,
onBlur,
onFocus,
registry,
rawErrors,
name,
onSelectChange
} = props;
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
const itemsSchema = schemaUtils.retrieveSchema(schema.items, items);
const enumOptions = optionsList(itemsSchema, uiSchema);
const { widget = "select", title: uiTitle, ...options } = getUiOptions(uiSchema, globalUiOptions);
const Widget = getWidget(schema, widget, widgets2);
const label = uiTitle ?? schema.title ?? name;
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
const multiValueFieldPathId = useDeepCompareMemo(toFieldPathId("", globalFormOptions, fieldPathId, true));
return /* @__PURE__ */ jsx(
Widget,
{
id: multiValueFieldPathId[ID_KEY],
name,
multiple: true,
onChange: onSelectChange,
onBlur,
onFocus,
options: { ...options, enumOptions },
schema,
uiSchema,
registry,
value: items,
disabled,
readonly,
required,
label,
hideLabel: !displayLabel,
placeholder,
autofocus,
rawErrors,
htmlName: multiValueFieldPathId.name
}
);
}
function ArrayAsCustomWidget(props) {
const {
schema,
fieldPathId,
uiSchema,
disabled = false,
readonly = false,
autofocus = false,
required = false,
hideError,
placeholder,
onBlur,
onFocus,
formData: items = [],
registry,
rawErrors,
name,
onSelectChange
} = props;
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
const { widget, title: uiTitle, ...options } = getUiOptions(uiSchema, globalUiOptions);
const Widget = getWidget(schema, widget, widgets2);
const label = uiTitle ?? schema.title ?? name;
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
const multiValueFieldPathId = useDeepCompareMemo(toFieldPathId("", globalFormOptions, fieldPathId, true));
return /* @__PURE__ */ jsx(
Widget,
{
id: multiValueFieldPathId[ID_KEY],
name,
multiple: true,
onChange: onSelectChange,
onBlur,
onFocus,
options,
schema,
uiSchema,
registry,
value: items,
disabled,
readonly,
hideError,
required,
label,
hideLabel: !displayLabel,
placeholder,
autofocus,
rawErrors,
htmlName: multiValueFieldPathId.name
}
);
}
function ArrayAsFiles(props) {
const {
schema,
uiSchema,
fieldPathId,
name,
disabled = false,
readonly = false,
autofocus = false,
required = false,
onBlur,
onFocus,
registry,
formData: items = [],
rawErrors,
onSelectChange
} = props;
const { widgets: widgets2, schemaUtils, globalFormOptions, globalUiOptions } = registry;
const { widget = "files", title: uiTitle, ...options } = getUiOptions(uiSchema, globalUiOptions);
const Widget = getWidget(schema, widget, widgets2);
const label = uiTitle ?? schema.title ?? name;
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
const multiValueFieldPathId = useDeepCompareMemo(toFieldPathId("", globalFormOptions, fieldPathId, true));
return /* @__PURE__ */ jsx(
Widget,
{
options,
id: multiValueFieldPathId[ID_KEY],
name,
multiple: true,
onChange: onSelectChange,
onBlur,
onFocus,
schema,
uiSchema,
value: items,
disabled,
readonly,
required,
registry,
autofocus,
rawErrors,
label,
hideLabel: !displayLabel,
htmlName: multiValueFieldPathId.name
}
);
}
function ArrayFieldItem(props) {
const {
itemKey,
index,
name,
disabled,
hideError,
readonly,
registry,
uiOptions,
parentUiSchema,
canAdd,
canRemove = true,
canMoveUp,
canMoveDown,
itemSchema,
itemData,
itemUiSchema,
itemFieldPathId,
itemErrorSchema,
autofocus,
onBlur,
onFocus,
onChange,
rawErrors,
totalItems,
title,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems
} = props;
const {
schemaUtils,
fields: { ArraySchemaField, SchemaField: SchemaField2 },
globalUiOptions
} = registry;
const fieldPathId = useDeepCompareMemo(itemFieldPathId);
const ItemSchemaField = ArraySchemaField || SchemaField2;
const ArrayFieldItemTemplate2 = getTemplate(
"ArrayFieldItemTemplate",
registry,
uiOptions
);
const displayLabel = schemaUtils.getDisplayLabel(itemSchema, itemUiSchema, globalUiOptions);
const { description } = getUiOptions(itemUiSchema);
const hasDescription = !!description || !!itemSchema.description;
const { orderable = true, removable = true, copyable = false } = uiOptions;
const has4 = {
moveUp: orderable && canMoveUp,
moveDown: orderable && canMoveDown,
copy: copyable && canAdd,
remove: removable && canRemove,
toolbar: false
};
has4.toolbar = Object.keys(has4).some((key) => has4[key]);
const onAddItem = useCallback(
(event) => {
handleAddItem(event, index + 1);
},
[handleAddItem, index]
);
const onCopyItem = useCallback(
(event) => {
handleCopyItem(event, index);
},
[handleCopyItem, index]
);
const onRemoveItem = useCallback(
(event) => {
handleRemoveItem(event, index);
},
[handleRemoveItem, index]
);
const onMoveUpItem = useCallback(
(event) => {
handleReorderItems(event, index, index - 1);
},
[handleReorderItems, index]
);
const onMoveDownItem = useCallback(
(event) => {
handleReorderItems(event, index, index + 1);
},
[handleReorderItems, index]
);
const templateProps = {
children: /* @__PURE__ */ jsx(
ItemSchemaField,
{
name,
title,
index,
schema: itemSchema,
uiSchema: itemUiSchema,
formData: itemData,
errorSchema: itemErrorSchema,
fieldPathId,
required: isItemRequired(itemSchema),
onChange,
onBlur,
onFocus,
registry,
disabled,
readonly,
hideError,
autofocus,
rawErrors
}
),
buttonsProps: {
fieldPathId,
disabled,
readonly,
canAdd,
hasCopy: has4.copy,
hasMoveUp: has4.moveUp,
hasMoveDown: has4.moveDown,
hasRemove: has4.remove,
index,
totalItems,
onAddItem,
onCopyItem,
onRemoveItem,
onMoveUpItem,
onMoveDownItem,
registry,
schema: itemSchema,
uiSchema: itemUiSchema
},
itemKey,
className: "rjsf-array-item",
disabled,
hasToolbar: has4.toolbar,
index,
totalItems,
readonly,
registry,
schema: itemSchema,
uiSchema: itemUiSchema,
parentUiSchema,
displayLabel,
hasDescription
};
return /* @__PURE__ */ jsx(ArrayFieldItemTemplate2, { ...templateProps });
}
function NormalArray(props) {
const {
schema,
uiSchema = {},
errorSchema,
fieldPathId,
formData: formDataFromProps,
name,
title,
disabled = false,
readonly = false,
autofocus = false,
required = false,
hideError = false,
registry,
onBlur,
onFocus,
rawErrors,
onChange,
keyedFormData,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems
} = props;
const fieldTitle = schema.title || title || name;
const { schemaUtils, fields: fields2, formContext, globalFormOptions, globalUiOptions } = registry;
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
const uiOptions = getUiOptions(uiSchema, globalUiOptions);
const _schemaItems = isObject(schema.items) ? schema.items : {};
const itemsSchema = schemaUtils.retrieveSchema(_schemaItems);
const formData = keyedToPlainFormData(keyedFormData);
const renderOptionalField = shouldRenderOptionalField(registry, schema, required, uiSchema);
const hasFormData = isFormDataAvailable(formDataFromProps);
const canAdd = canAddItem(registry, schema, formData, uiSchema) && (!renderOptionalField || hasFormData);
const actualFormData = hasFormData ? keyedFormData : [];
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsx(OptionalDataControlsField2, { ...props, fieldPathId: childFieldPathId }) : void 0;
const arrayProps = {
canAdd,
items: actualFormData.map((keyedItem, index) => {
const { key, item } = keyedItem;
const itemCast = item;
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
const itemFieldPathId = toFieldPathId(index, globalFormOptions, childFieldPathId);
const itemUiSchema = computeItemUiSchema(uiSchema, item, index, formContext);
const itemProps = {
itemKey: key,
index,
name: name && `${name}-${index}`,
registry,
uiOptions,
hideError,
readonly,
disabled,
required,
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
canAdd,
canMoveUp: index > 0,
canMoveDown: index < formData.length - 1,
itemSchema,
itemFieldPathId,
itemErrorSchema,
itemData: itemCast,
itemUiSchema,
autofocus: autofocus && index === 0,
onBlur,
onFocus,
rawErrors,
totalItems: keyedFormData.length,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems,
onChange
};
return /* @__PURE__ */ jsx(ArrayFieldItem, { ...itemProps }, key);
}),
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}${extraClass}`,
disabled,
fieldPathId,
uiSchema,
onAddClick: handleAddItem,
readonly,
required,
schema,
title: fieldTitle,
formData,
rawErrors,
registry,
optionalDataControl
};
const Template = getTemplate("ArrayFieldTemplate", registry, uiOptions);
return /* @__PURE__ */ jsx(Template, { ...arrayProps });
}
function FixedArray(props) {
const {
schema,
uiSchema = {},
formData,
errorSchema,
fieldPathId,
name,
title,
disabled = false,
readonly = false,
autofocus = false,
required = false,
hideError = false,
registry,
onBlur,
onFocus,
rawErrors,
keyedFormData,
onChange,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems
} = props;
let { formData: items = [] } = props;
const fieldTitle = schema.title || title || name;
const { schemaUtils, fields: fields2, formContext, globalFormOptions, globalUiOptions } = registry;
const uiOptions = getUiOptions(uiSchema, globalUiOptions);
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
const renderOptionalField = shouldRenderOptionalField(registry, schema, required, uiSchema);
const hasFormData = isFormDataAvailable(formData);
const _schemaItems = isObject(schema.items) ? schema.items : [];
const itemSchemas = _schemaItems.map(
(item, index) => schemaUtils.retrieveSchema(item, items[index])
);
const additionalSchema = isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, formData) : null;
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
if (items.length < itemSchemas.length) {
items = items.concat(new Array(itemSchemas.length - items.length));
}
const actualFormData = hasFormData ? keyedFormData : [];
const extraClass = renderOptionalField ? " rjsf-optional-array-field" : "";
const optionalDataControl = renderOptionalField ? /* @__PURE__ */ jsx(OptionalDataControlsField2, { ...props, fieldPathId: childFieldPathId }) : void 0;
const canAdd = canAddItem(registry, schema, items, uiSchema) && !!additionalSchema && (!renderOptionalField || hasFormData);
const arrayProps = {
canAdd,
className: `rjsf-field rjsf-field-array rjsf-field-array-fixed-items${extraClass}`,
disabled,
fieldPathId,
formData,
items: actualFormData.map((keyedItem, index) => {
const { key, item } = keyedItem;
const itemCast = item;
const additional = index >= itemSchemas.length;
const itemSchema = (additional && isObject(schema.additionalItems) ? schemaUtils.retrieveSchema(schema.additionalItems, itemCast) : itemSchemas[index]) || {};
const itemFieldPathId = toFieldPathId(index, globalFormOptions, childFieldPathId);
let itemUiSchema;
if (additional) {
itemUiSchema = uiSchema.additionalItems;
} else {
if (Array.isArray(uiSchema.items)) {
itemUiSchema = uiSchema.items[index];
} else {
itemUiSchema = computeItemUiSchema(uiSchema, item, index, formContext);
}
}
const itemErrorSchema = errorSchema ? errorSchema[index] : void 0;
const itemProps = {
index,
itemKey: key,
name: name && `${name}-${index}`,
registry,
uiOptions,
hideError,
readonly,
disabled,
required,
title: fieldTitle ? `${fieldTitle}-${index + 1}` : void 0,
canAdd,
canRemove: additional,
canMoveUp: index >= itemSchemas.length + 1,
canMoveDown: additional && index < items.length - 1,
itemSchema,
itemData: itemCast,
itemUiSchema,
itemFieldPathId,
itemErrorSchema,
autofocus: autofocus && index === 0,
onBlur,
onFocus,
rawErrors,
totalItems: keyedFormData.length,
onChange,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems
};
return /* @__PURE__ */ jsx(ArrayFieldItem, { ...itemProps }, key);
}),
onAddClick: handleAddItem,
readonly,
required,
registry,
schema,
uiSchema,
title: fieldTitle,
errorSchema,
rawErrors,
optionalDataControl
};
const Template = getTemplate("ArrayFieldTemplate", registry, uiOptions);
return /* @__PURE__ */ jsx(Template, { ...arrayProps });
}
function useKeyedFormData(formData = []) {
const newHash = useMemo(() => hashObject(formData), [formData]);
const [state, setState] = useState(() => ({
formDataHash: newHash,
keyedFormData: generateKeyedFormData(formData)
}));
let { keyedFormData, formDataHash } = state;
if (newHash !== formDataHash) {
const nextFormData = Array.isArray(formData) ? formData : [];
const previousKeyedFormData = keyedFormData || [];
keyedFormData = nextFormData.length === previousKeyedFormData.length ? previousKeyedFormData.map((previousKeyedFormDatum, index) => ({
key: previousKeyedFormDatum.key,
item: nextFormData[index]
})) : generateKeyedFormData(nextFormData);
formDataHash = newHash;
setState({ formDataHash, keyedFormData });
}
const updateKeyedFormData = useCallback((newData) => {
const plainFormData = keyedToPlainFormData(newData);
const newHash2 = hashObject(plainFormData);
setState({ formDataHash: newHash2, keyedFormData: newData });
return plainFormData;
}, []);
return { keyedFormData, updateKeyedFormData };
}
function ArrayField(props) {
const { schema, uiSchema, errorSchema, fieldPathId, registry, formData, onChange } = props;
const { globalFormOptions, schemaUtils, translateString } = registry;
const { keyedFormData, updateKeyedFormData } = useKeyedFormData(formData);
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
const handleAddItem = useCallback(
(event, index) => {
if (event) {
event.preventDefault();
}
let newErrorSchema;
if (errorSchema) {
newErrorSchema = {};
for (const idx in errorSchema) {
const i = parseInt(idx);
if (index === void 0 || i < index) {
set(newErrorSchema, [i], errorSchema[idx]);
} else if (i >= index) {
set(newErrorSchema, [i + 1], errorSchema[idx]);
}
}
}
const newKeyedFormDataRow = {
key: generateRowId(),
item: getNewFormDataRow(registry, schema)
};
const newKeyedFormData = [...keyedFormData];
if (index !== void 0) {
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
} else {
newKeyedFormData.push(newKeyedFormDataRow);
}
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema);
},
[keyedFormData, registry, schema, onChange, updateKeyedFormData, errorSchema, childFieldPathId]
);
const handleCopyItem = useCallback(
(event, index) => {
if (event) {
event.preventDefault();
}
let newErrorSchema;
if (errorSchema) {
newErrorSchema = {};
for (const idx in errorSchema) {
const i = parseInt(idx);
if (i <= index) {
set(newErrorSchema, [i], errorSchema[idx]);
} else if (i > index) {
set(newErrorSchema, [i + 1], errorSchema[idx]);
}
}
}
const newKeyedFormDataRow = {
key: generateRowId(),
item: cloneDeep(keyedFormData[index].item)
};
const newKeyedFormData = [...keyedFormData];
if (index !== void 0) {
newKeyedFormData.splice(index + 1, 0, newKeyedFormDataRow);
} else {
newKeyedFormData.push(newKeyedFormDataRow);
}
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema);
},
[keyedFormData, onChange, updateKeyedFormData, errorSchema, childFieldPathId]
);
const handleRemoveItem = useCallback(
(event, index) => {
if (event) {
event.preventDefault();
}
let newErrorSchema;
if (errorSchema) {
newErrorSchema = {};
for (const idx in errorSchema) {
const i = parseInt(idx);
if (i < index) {
set(newErrorSchema, [i], errorSchema[idx]);
} else if (i > index) {
set(newErrorSchema, [i - 1], errorSchema[idx]);
}
}
}
const newKeyedFormData = keyedFormData.filter((_, i) => i !== index);
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema);
},
[keyedFormData, onChange, updateKeyedFormData, errorSchema, childFieldPathId]
);
const handleReorderItems = useCallback(
(event, index, newIndex) => {
if (event) {
event.preventDefault();
event.currentTarget.blur();
}
let newErrorSchema;
if (errorSchema) {
newErrorSchema = {};
for (const idx in errorSchema) {
const i = parseInt(idx);
if (i == index) {
set(newErrorSchema, [newIndex], errorSchema[index]);
} else if (i == newIndex) {
set(newErrorSchema, [index], errorSchema[newIndex]);
} else {
set(newErrorSchema, [idx], errorSchema[i]);
}
}
}
function reOrderArray() {
const _newKeyedFormData = keyedFormData.slice();
_newKeyedFormData.splice(index, 1);
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
return _newKeyedFormData;
}
const newKeyedFormData = reOrderArray();
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema);
},
[keyedFormData, onChange, updateKeyedFormData, errorSchema, childFieldPathId]
);
const handleChange = useCallback(
(value, path, newErrorSchema, id) => {
onChange(
// We need to treat undefined items as nulls to have validation.
// See https://github.com/tdegrunt/jsonschema/issues/206
value === void 0 ? null : value,
path,
newErrorSchema,
id
);
},
[onChange]
);
const onSelectChange = useCallback(
(value) => {
onChange(value, childFieldPathId.path, void 0, childFieldPathId?.[ID_KEY]);
},
[onChange, childFieldPathId]
);
const arrayAsMultiProps = {
...props,
formData,
fieldPathId: childFieldPathId,
onSelectChange
};
const arrayProps = {
...props,
handleAddItem,
handleCopyItem,
handleRemoveItem,
handleReorderItems,
keyedFormData,
onChange: handleChange
};
if (!(ITEMS_KEY in schema)) {
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
const uiOptions = getUiOptions(uiSchema);
const UnsupportedFieldTemplate = getTemplate(
"UnsupportedFieldTemplate",
registry,
uiOptions
);
return /* @__PURE__ */ jsx(
UnsupportedFieldTemplate,
{
schema,
fieldPathId,
reason: translateString(TranslatableString.MissingItems),
registry
}
);
}
const fallbackSchema = { ...schema, [ITEMS_KEY]: { type: void 0 } };
arrayAsMultiProps.schema = fallbackSchema;
arrayProps.schema = fallbackSchema;
}
if (schemaUtils.isMultiSelect(arrayAsMultiProps.schema)) {
return /* @__PURE__ */ jsx(ArrayAsMultiSelect, { ...arrayAsMultiProps });
}
if (isCustomWidget(uiSchema)) {
return /* @__PURE__ */ jsx(ArrayAsCustomWidget, { ...arrayAsMultiProps });
}
if (isFixedItems(arrayAsMultiProps.schema)) {
return /* @__PURE__ */ jsx(FixedArray, { ...arrayProps });
}
if (schemaUtils.isFilesArray(arrayAsMultiProps.schema, uiSchema)) {
return /* @__PURE__ */ jsx(ArrayAsFiles, { ...arrayAsMultiProps });
}
return /* @__PURE__ */ jsx(NormalArray, { ...arrayProps });
}
// src/components/fields/BooleanField.tsx
import { useCallback as useCallback2 } from "react";
import {
getWidget as getWidget2,
getUiOptions as getUiOptions2,
optionsList as optionsList2,
TranslatableString as TranslatableString2
} from "@rjsf/utils";
import isObject2 from "lodash/isObject";
import { jsx as jsx2 } from "react/jsx-runtime";
function BooleanField(props) {
const {
schema,
name,
uiSchema,
fieldPathId,
formData,
registry,
required,
disabled,
readonly,
hideError,
autofocus,
title,
onChange,
onFocus,
onBlur,
rawErrors
} = props;
const { title: schemaTitle } = schema;
const { widgets: widgets2, translateString, globalUiOptions } = registry;
const {
widget = "checkbox",
title: uiTitle,
// Unlike the other fields, don't use `getDisplayLabel()` since it always returns false for the boolean type
label: displayLabel = true,
enumNames,
...options
} = getUiOptions2(uiSchema, globalUiOptions);
const Widget = getWidget2(schema, widget, widgets2);
const yes = translateString(TranslatableString2.YesLabel);
const no = translateString(TranslatableString2.NoLabel);
let enumOptions;
const label = uiTitle ?? schemaTitle ?? title ?? name;
if (Array.isArray(schema.oneOf)) {
enumOptions = optionsList2(
{
oneOf: schema.oneOf.map((option) => {
if (isObject2(option)) {
return {
...option,
title: option.title || (option.const === true ? yes : no)
};
}
return void 0;
}).filter((o) => o)
// cast away the error that typescript can't grok is fixed
},
uiSchema
);
} else {
const enums = schema.enum ?? [true, false];
if (!enumNames && enums.length === 2 && enums.every((v) => typeof v === "boolean")) {
enumOptions = [
{
value: enums[0],
label: enums[0] ? yes : no
},
{
value: enums[1],
label: enums[1] ? yes : no
}
];
} else {
enumOptions = optionsList2({ enum: enums }, uiSchema);
}
}
const onWidgetChange = useCallback2(
(value, errorSchema, id) => {
return onChange(value, fieldPathId.path, errorSchema, id);
},
[onChange, fieldPathId]
);
return /* @__PURE__ */ jsx2(
Widget,
{
options: { ...options, enumOptions },
schema,
uiSchema,
id: fieldPathId.$id,
name,
onChange: onWidgetChange,
onFocus,
onBlur,
label,
hideLabel: !displayLabel,
value: formData,
required,
disabled,
readonly,
hideError,
registry,
autofocus,
rawErrors,
htmlName: fieldPathId.name
}
);
}
var BooleanField_default = BooleanField;
// src/components/fields/FallbackField.tsx
import {
getTemplate as getTemplate2,
getUiOptions as getUiOptions3,
hashObject as hashObject2,
toFieldPathId as toFieldPathId2,
TranslatableString as TranslatableString3,
useDeepCompareMemo as useDeepCompareMemo2
} from "@rjsf/utils";
import { useMemo as useMemo2, useState as useState2 } from "react";
import { jsx as jsx3 } from "react/jsx-runtime";
function getFallbackTypeSelectionSchema(title) {
return {
type: "string",
enum: ["string", "number", "boolean", "object", "array"],
default: "string",
title
};
}
function getTypeOfFormData(formData) {
const dataType = typeof formData;
if (dataType === "string" || dataType === "number" || dataType === "boolean") {
return dataType;
}
if (dataType === "object") {
return Array.isArray(formData) ? "array" : "object";
}
return "string";
}
function castToNewType(formData, newType) {
switch (newType) {
case "string":
return String(formData);
case "number": {
const castedNumber = Number(formData);
return isNaN(castedNumber) ? 0 : castedNumber;
}
case "boolean":
return Boolean(formData);
default:
return formData;
}
}
function FallbackField(props) {
const {
id,
formData,
displayLabel = true,
schema,
name,
uiSchema,
required,
disabled = false,
readonly = false,
onBlur,
onFocus,
registry,
fieldPathId,
onChange,
errorSchema
} = props;
const { translateString, fields: fields2, globalFormOptions } = registry;
const [type, setType] = useState2(getTypeOfFormData(formData));
const uiOptions = getUiOptions3(uiSchema);
const typeSelectorInnerFieldPathId = useDeepCompareMemo2(
toFieldPathId2("__internal_type_selector", globalFormOptions, fieldPathId)
);
const schemaTitle = translateString(TranslatableString3.Type);
const typesOptionSchema = useMemo2(() => getFallbackTypeSelectionSchema(schemaTitle), [schemaTitle]);
const onTypeChange = (newType) => {
if (newType != null) {
setType(newType);
onChange(castToNewType(formData, newType), fieldPathId.path, errorSchema, id);
}
};
if (!globalFormOptions.useFallbackUiForUnsupportedType) {
const { reason = translateString(TranslatableString3.UnknownFieldType, [String(schema.type)]) } = props;
const UnsupportedFieldTemplate = getTemplate2(
"UnsupportedFieldTemplate",
registry,
uiOptions
);
return /* @__PURE__ */ jsx3(UnsupportedFieldTemplate, { schema, fieldPathId, reason, registry });
}
const FallbackFieldTemplate2 = getTemplate2(
"FallbackFieldTemplate",
registry,
uiOptions
);
const { SchemaField: SchemaField2 } = fields2;
return /* @__PURE__ */ jsx3(
FallbackFieldTemplate2,
{
schema,
registry,
typeSelector: /* @__PURE__ */ jsx3(
SchemaField2,
{
fieldPathId: typeSelectorInnerFieldPathId,
name: `${name}__fallback_type`,
schema: typesOptionSchema,
formData: type,
onChange: onTypeChange,
onBlur,
onFocus,
registry,
hideLabel: !displayLabel,
disabled,
readonly,
required
},
formData ? hashObject2(formData) : "__empty__"
),
schemaField: /* @__PURE__ */ jsx3(
SchemaField2,
{
...props,
schema: {
type,
title: translateString(TranslatableString3.Value),
...type === "object" && { additionalProperties: true }
}
}
)
}
);
}
// src/components/fields/LayoutGridField.tsx
import {
ANY_OF_KEY,
getDiscriminatorFieldFromSchema,
getTemplate as getTemplate3,
getTestIds,
getUiOptions as getUiOptions4,
hashObject as hashObject3,
ID_KEY as ID_KEY2,
lookupFromFormContext,
ONE_OF_KEY,
PROPERTIES_KEY,
READONLY_KEY,
toFieldPathId as toFieldPathId3,
UI_OPTIONS_KEY,
UI_GLOBAL_OPTIONS_KEY,
ITEMS_KEY as ITEMS_KEY2,
useDeepCompareMemo as useDeepCompareMemo3
} from "@rjsf/utils";
import each from "lodash/each";
import flatten from "lodash/flatten";
import get from "lodash/get";
import has from "lodash/has";
import includes from "lodash/includes";
import intersection from "lodash/intersection";
import isEmpty from "lodash/isEmpty";
import isFunction from "lodash/isFunction";
import isEqual from "lodash/isEqual";
import isObject3 from "lodash/isObject";
import isPlainObject from "lodash/isPlainObject";
import isString from "lodash/isString";
import isUndefined from "lodash/isUndefined";
import last from "lodash/last";
import set2 from "lodash/set";
import { jsx as jsx4 } from "react/jsx-runtime";
import { createElement } from "react";
var LOOKUP_REGEX = /^\$lookup=(.+)/;
var LAYOUT_GRID_UI_OPTION = "layoutGrid";
var LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
function getNonNullishValue(value, fallback) {
return value ?? fallback;
}
function isNumericIndex(str) {
return /^\d+?$/.test(str);
}
var LAYOUT_GRID_FIELD_TEST_IDS = getTestIds();
function computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS_KEY], {});
const localUiSchema = get(uiSchema, field);
const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
const fieldUiSchema = { ...localUiSchema };
if (!isEmpty(localUiOptions)) {
set2(fieldUiSchema, [UI_OPTIONS_KEY], localUiOptions);
}
if (!isEmpty(globalUiOptions)) {
set2(fieldUiSchema, [UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
}
let { readonly: uiReadonly } = getUiOptions4(fieldUiSchema);
if (forceReadonly === true || isUndefined(uiReadonly) && schemaReadonly === true) {
uiReadonly = true;
if (has(localUiOptions, READONLY_KEY)) {
set2(fieldUiSchema, [UI_OPTIONS_KEY, READONLY_KEY], true);
} else {
set2(fieldUiSchema, `ui:${READONLY_KEY}`, true);
}
}
return { fieldUiSchema, uiReadonly };
}
function conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
const data = flatten([datum]).sort();
const values = flatten([value]).sort();
switch (operator) {
case "all" /* ALL */:
return isEqual(data, values);
case "some" /* SOME */:
return intersection(data, values).length > 0;
case "none" /* NONE */:
return intersection(data, values).length === 0;
default:
return false;
}
}
function findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
let gridProps = {};
let children = layoutGridSchema[schemaKey];
if (isPlainObject(children)) {
const { children: elements, className: toMapClassNames, ...otherProps } = children;
children = elements;
if (toMapClassNames) {
const classes = toMapClassNames.split(" ");
const className = classes.map((ele) => lookupFromFormContext(registry, ele, ele)).join(" ");
gridProps = { ...otherProps, className };
} else {
gridProps = otherProps;
}
}
if (!Array.isArray(children)) {
throw new TypeError(`Expected array for "${schemaKey}" in ${JSON.stringify(layoutGridSchema)}`);
}
return { children, gridProps };
}
function computeArraySchemasIfPresent(schema, fieldPathId, potentialIndex) {
let rawSchema;
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" && has(schema, ITEMS_KEY2)) {
const index = Number(potentialIndex);
const items = schema[ITEMS_KEY2];
if (Array.isArray(items)) {
if (index > items.length) {
rawSchema = last(items);
} else {
rawSchema = items[index];
}
} else {
rawSchema = items;
}
fieldPathId = {
[ID_KEY2]: fieldPathId[ID_KEY2],
path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index]
};
}
return { rawSchema, fieldPathId };
}
function getSchemaDetailsForField(registry, dottedPath, initialSchema, formData, initialFieldIdPath) {
const { schemaUtils, globalFormOptions } = registry;
let rawSchema = initialSchema;
let fieldPathId = initialFieldIdPath;
const parts = dottedPath.split(".");
const leafPath = parts.pop();
let schema = schemaUtils.retrieveSchema(rawSchema, formData);
let innerData = formData;
let isReadonly = schema.readOnly;
parts.forEach((part) => {
fieldPathId = toFieldPathId3(part, globalFormOptions, fieldPathId);
if (has(schema, PROPERTIES_KEY)) {
rawSchema = get(schema, [PROPERTIES_KEY, part], {});
} else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {});
} else {
const result = computeArraySchemasIfPresent(schema, fieldPathId, part);
rawSchema = result.rawSchema ?? {};
fieldPathId = result.fieldPathId;
}
innerData = get(innerData, part, {});
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
});
let optionsInfo;
let isRequired2 = false;
if (isEmpty(schema)) {
schema = void 0;
}
if (schema && leafPath) {
if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
}
fieldPathId = toFieldPathId3(leafPath, globalFormOptions, fieldPathId);
isRequired2 = schema !== void 0 && Array.isArray(schema.required) && includes(schema.required, leafPath);
const result = computeArraySchemasIfPresent(schema, fieldPathId, leafPath);
if (result.rawSchema) {
schema = result.rawSchema;
fieldPathId = result.fieldPathId;
} else {
schema = get(schema, [PROPERTIES_KEY, leafPath]);
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
}
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
const discriminator = getDiscriminatorFieldFromSchema(schema);
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
}
}
return { schema, isRequired: isRequired2, isReadonly, optionsInfo, fieldPathId };
}
function getCustomRenderComponent(render, registry) {
let customRenderer = render;
if (isString(customRenderer)) {
customRenderer = lookupFromFormContext(registry, customRenderer);
}
if (isFunction(customRenderer)) {
return customRenderer;
}
return null;
}
function computeUIComponentPropsFromGridSchema(registry, gridSchema) {
let name;
let UIComponent = null;
let uiProps = {};
let rendered;
if (isString(gridSchema) || isUndefined(gridSchema)) {
name = gridSchema ?? "";
} else {
const { name: innerName = "", render, ...innerProps } = gridSchema;
name = innerName;
uiProps = innerProps;
if (!isEmpty(uiProps)) {
each(uiProps, (prop, key) => {
if (isString(prop)) {
const match = LOOKUP_REGEX.exec(prop);
if (Array.isArray(match) && match.length > 1) {
const name2 = match[1];
uiProps[key] = lookupFromFormContext(registry, name2, name2);
}
}
});
}
UIComponent = getCustomRenderComponent(render, registry);
if (!innerName && UIComponent) {
rendered = /* @__PURE__ */ jsx4(UIComponent, { ...innerProps, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.uiComponent });
}
}
return { name, UIComponent, uiProps, rendered };
}
function LayoutGridFieldChildren(props) {
const { childrenLayoutGridSchemaId, ...layoutGridFieldProps } = props;
const { registry, schema: rawSchema, formData } = layoutGridFieldProps;
const { schemaUtils } = registry;
const schema = schemaUtils.retrieveSchema(rawSchema, formData);
return childrenLayoutGridSchemaId.map((layoutGridSchema) => /* @__PURE__ */ createElement(
LayoutGridField,
{
...layoutGridFieldProps,
key: `layoutGrid-${hashObject3(layoutGridSchema)}`,
schema,
layoutGridSchema
}
));
}
function LayoutGridCondition(props) {
const { layoutGridSchema, ...layoutGridFieldProps } = props;
const { formData, registry } = layoutGridFieldProps;
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:condition" /* CONDITION */, registry);
const { operator, field = "", value } = gridProps;
const fieldData = get(formData, field, null);
if (conditionMatches(operator, fieldData, value)) {
return /* @__PURE__ */ jsx4(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children });
}
return null;
}
function LayoutGridCol(props) {
const { layoutGridSchema, ...layoutGridFieldProps } = props;
const { registry, uiSchema } = layoutGridFieldProps;
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:col" /* COLUMN */, registry);
const uiOptions = getUiOptions4(uiSchema);
const GridTemplate2 = getTemplate3("GridTemplate", registry, uiOptions);
return /* @__PURE__ */ jsx4(GridTemplate2, { column: true, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.col, ...gridProps, children: /* @__PURE__ */ jsx4(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children }) });
}
function LayoutGridColumns(props) {
const { layoutGridSchema, ...layoutGridFieldProps } = props;
const { registry, uiSchema } = layoutGridFieldProps;
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:columns" /* COLUMNS */, registry);
const uiOptions = getUiOptions4(uiSchema);
const GridTemplate2 = getTemplate3("GridTemplate", registry, uiOptions);
return children.map((child) => /* @__PURE__ */ jsx4(
GridTemplate2,
{
column: true,
"data-testid": LAYOUT_GRID_FIELD_TEST_IDS.col,
...gridProps,
children: /* @__PURE__ */ jsx4(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: [child] })
},
`column-${hashObject3(child)}`
));
}
function LayoutGridRow(props) {
const { layoutGridSchema, ...layoutGridFieldProps } = props;
const { registry, uiSchema } = layoutGridFieldProps;
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:row" /* ROW */, registry);
const uiOptions = getUiOptions4(uiSchema);
const GridTemplate2 = getTemplate3("GridTemplate", registry, uiOptions);
return /* @__PURE__ */ jsx4(GridTemplate2, { ...gridProps, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.row, children: /* @__PURE__ */ jsx4(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children }) });
}
function LayoutGridFieldComponent(props) {
const {
gridSchema,
schema: initialSchema,
uiSchema,
errorSchema,
fieldPathId,
onBlur,
onFocus,
formData,
readonly,
registry,
layoutGridSchema,
// Used to pull this out of otherProps since we don't want to pass it through
...otherProps
} = props;
const { onChange } = otherProps;
const { fields: fields2 } = registry;
const { SchemaField: SchemaField2, LayoutMultiSchemaField: LayoutMultiSchemaField2 } = fields2;
const uiComponentProps = computeUIComponentPropsFromGridSchema(registry, gridSchema);
const { name, UIComponent, uiProps } = uiComponentProps;
const {
schema,
isRequired: isRequired2,
isReadonly,
optionsInfo,
fieldPathId: fieldIdSchema
} = getSchemaDetailsForField(registry, name, initialSchema, formData, fieldPathId);
const memoFieldPathId = useDeepCompareMemo3(fieldIdSchema);
if (uiComponentProps.rendered) {
return uiComponentProps.rendered;
}
if (schema) {
const Field2 = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
const { fieldUiSchema, uiReadonly } = computeFieldUiSchema(name, uiProps, uiSchema, isReadonly, readonly);
return /* @__PURE__ */ jsx4(
Field2,
{
"data-testid": optionsInfo?.hasDiscriminator ? LAYOUT_GRID_FIELD_TEST_IDS.layoutMultiSchemaField : LAYOUT_GRID_FIELD_TEST_IDS.field,
...otherProps,
name,
required: isRequired2,
readonly: uiReadonly,
schema,
uiSchema: fieldUiSchema,
errorSchema: get(errorSchema, name),
fieldPathId: memoFieldPathId,
formData: get(formData, name),
onChange,
onBlur,
onFocus,
options: optionsInfo?.options,
registry
}
);
}
if (UIComponent) {
return /* @__PURE__ */ jsx4(
UIComponent,
{
"data-testid": LAYOUT_GRID_FIELD_TEST_IDS.uiComponent,
...otherProps,
name,
required: isRequired2,
formData,
readOnly: !!isReadonly || readonly,
errorSchema,
uiSchema,
schema: initialSchema,
fieldPathId,
onBlur,
onFocus,
registry,
...uiProps
}
);
}
return null;
}
function LayoutGridField(props) {
const { uiSchema } = props;
let { layoutGridSchema } = props;
const uiOptions = getUiOptions4(uiSchema);
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject3(uiOptions[LAYOUT_GRID_UI_OPTION])) {
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
}
if (isObject3(layoutGridSchema)) {
if ("ui:row" /* ROW */ in layoutGridSchema) {
return /* @__PURE__ */ jsx4(LayoutGridRow, { ...props, layoutGridSchema });
}
if ("ui:col" /* COLUMN */ in layoutGridSchema) {
return /* @__PURE__ */ jsx4(LayoutGridCol, { ...props, layoutGridSchema });
}
if ("ui:columns" /* COLUMNS */ in layoutGridSchema) {
return /* @__PURE__ */ jsx4(LayoutGridColumns, { ...props, layoutGridSchema });
}
if ("ui:condition" /* CONDITION */ in layoutGridSchema) {
return /* @__PURE__ */ jsx4(LayoutGridCondition, { ...props, layoutGridSchema });
}
}
return /* @__PURE__ */ jsx4(LayoutGridFieldComponent, { ...props, gridSchema: layoutGridSchema });
}
LayoutGridField.TEST_IDS = LAYOUT_GRID_FIELD_TEST_IDS;
// src/components/fields/LayoutHeaderField.tsx
import {
getTemplate as getTemplate4,
getUiOptions as getUiOptions5,
titleId
} from "@rjsf/utils";
import { jsx as jsx5 } from "react/jsx-runtime";
function LayoutHeaderField(props) {
const { fieldPathId, title, schema, uiSchema, required, registry, name } = props;
const options = getUiOptions5(uiSchema, registry.globalUiOptions);
const { title: uiTitle } = options;
const { title: schemaTitle } = schema;
const fieldTitle = uiTitle || title || schemaTitle || name;
if (!fieldTitle) {
return null;
}
const TitleFieldTemplate = getTemplate4(
"TitleFieldTemplate",
registry,
options
);
return /* @__PURE__ */ jsx5(
TitleFieldTemplate,
{
id: titleId(fieldPathId),
title: fieldTitle,
required,
schema,
uiSchema,
registry
}
);
}
// src/components/fields/LayoutMultiSchemaField.tsx
import { useState as useState3, useEffect } from "react";
import {
ANY_OF_KEY as ANY_OF_KEY2,
CONST_KEY,
DEFAULT_KEY,
ERRORS_KEY,
getDiscriminatorFieldFromSchema as getDiscriminatorFieldFromSchema2,
hashObject as hashObject4,
ID_KEY as ID_KEY3,
ONE_OF_KEY as ONE_OF_KEY2,
optionsList as optionsList3,
PROPERTIES_KEY as PROPERTIES_KEY2,
getTemplate as getTemplate5,
getUiOptions as getUiOptions6,
getWidget as getWidget3
} from "@rjsf/utils";
import get2 from "lodash/get";
import has2 from "lodash/has";
import isEmpty2 from "lodash/isEmpty";
import noop from "lodash/noop";
import omit from "lodash/omit";
import set3 from "lodash/set";
import { jsx as jsx6 } from "react/jsx-runtime";
function getSelectedOption(options, selectorField, value) {
const defaultValue = "!@#!@$@#$!@$#";
const schemaOptions = options.map(({ schema }) => schema);
return schemaOptions.find((option) => {
const selector = get2(option, [PROPERTIES_KEY2, selectorField]);
const result = get2(selector, DEFAULT_KEY, get2(selector, CONST_KEY, defaultValue));
return result === value;
});
}
function computeEnumOptions(schema, options, schemaUtils, uiSchema, formData) {
const realOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
let tempSchema = schema;
if (has2(schema, ONE_OF_KEY2)) {
tempSchema = { ...schema, [ONE_OF_KEY2]: realOptions };
} else if (has2(schema, ANY_OF_KEY2)) {
tempSchema = { ...schema, [ANY_OF_KEY2]: realOptions };
}
const enumOptions = optionsList3(tempSchema, uiSchema);
if (!enumOptions) {
throw new Error(`No enumOptions were computed from the schema ${JSON.stringify(tempSchema)}`);
}
return enumOptions;
}
function LayoutMultiSchemaField(props) {
const {
name,
baseType,
disabled = false,
formData,
fieldPathId,
onBlur,
onChange,
options,
onFocus,
registry,
uiSchema,
schema,
autofocus,
readonly,
required,
errorSchema,
hideError = false
} = props;
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
const [enumOptions, setEnumOptions] = useState3(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
const id = get2(fieldPathId, ID_KEY3);
const discriminator = getDiscriminatorFieldFromSchema2(schema);
const FieldErrorTemplate2 = getTemplate5("FieldErrorT