@rjsf/core 6.8.0 → 6.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.umd.js +183 -152
- package/dist/index.cjs +179 -190
- package/dist/index.cjs.map +3 -3
- package/dist/index.esm.js +209 -198
- package/dist/index.esm.js.map +3 -3
- package/lib/components/Form.d.ts +3 -2
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +62 -45
- package/lib/components/Form.js.map +1 -0
- package/lib/components/RichDescription.js +1 -0
- package/lib/components/RichDescription.js.map +1 -0
- package/lib/components/RichHelp.js +1 -0
- package/lib/components/RichHelp.js.map +1 -0
- package/lib/components/SchemaExamples.js +1 -0
- package/lib/components/SchemaExamples.js.map +1 -0
- package/lib/components/constants.js +1 -0
- package/lib/components/constants.js.map +1 -0
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +16 -17
- package/lib/components/fields/ArrayField.js.map +1 -0
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +2 -2
- package/lib/components/fields/BooleanField.js.map +1 -0
- package/lib/components/fields/CyclicSchemaField.js +1 -0
- package/lib/components/fields/CyclicSchemaField.js.map +1 -0
- package/lib/components/fields/FallbackField.js +1 -0
- package/lib/components/fields/FallbackField.js.map +1 -0
- package/lib/components/fields/LayoutGridField.d.ts +61 -1
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +50 -63
- package/lib/components/fields/LayoutGridField.js.map +1 -0
- package/lib/components/fields/LayoutHeaderField.js +1 -0
- package/lib/components/fields/LayoutHeaderField.js.map +1 -0
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +14 -18
- package/lib/components/fields/LayoutMultiSchemaField.js.map +1 -0
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +6 -7
- package/lib/components/fields/MultiSchemaField.js.map +1 -0
- package/lib/components/fields/NullField.js +1 -0
- package/lib/components/fields/NullField.js.map +1 -0
- package/lib/components/fields/NumberField.js +1 -0
- package/lib/components/fields/NumberField.js.map +1 -0
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +20 -25
- package/lib/components/fields/ObjectField.js.map +1 -0
- package/lib/components/fields/OptionalDataControlsField.js +1 -0
- package/lib/components/fields/OptionalDataControlsField.js.map +1 -0
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +5 -5
- package/lib/components/fields/SchemaField.js.map +1 -0
- package/lib/components/fields/StringField.js +1 -0
- package/lib/components/fields/StringField.js.map +1 -0
- package/lib/components/fields/index.js +15 -14
- package/lib/components/fields/index.js.map +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +1 -0
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +1 -0
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -0
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTemplate.js +1 -0
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js +1 -0
- package/lib/components/templates/ArrayFieldTitleTemplate.js.map +1 -0
- package/lib/components/templates/BaseInputTemplate.js +3 -2
- package/lib/components/templates/BaseInputTemplate.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/AddButton.js +2 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js +1 -0
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +1 -0
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -0
- package/lib/components/templates/ButtonTemplates/index.js +4 -3
- package/lib/components/templates/ButtonTemplates/index.js.map +1 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.js +1 -0
- package/lib/components/templates/CyclicSchemaExpandTemplate.js.map +1 -0
- package/lib/components/templates/DescriptionField.js +2 -1
- package/lib/components/templates/DescriptionField.js.map +1 -0
- package/lib/components/templates/ErrorList.js +1 -0
- package/lib/components/templates/ErrorList.js.map +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js +1 -0
- package/lib/components/templates/FallbackFieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldErrorTemplate.js +1 -0
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -0
- package/lib/components/templates/FieldHelpTemplate.js +2 -1
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +2 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -0
- package/lib/components/templates/FieldTemplate/Label.js +1 -0
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -0
- package/lib/components/templates/FieldTemplate/index.d.ts +1 -1
- package/lib/components/templates/FieldTemplate/index.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/index.js +2 -1
- package/lib/components/templates/FieldTemplate/index.js.map +1 -0
- package/lib/components/templates/GridTemplate.js +1 -0
- package/lib/components/templates/GridTemplate.js.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js.map +1 -0
- package/lib/components/templates/ObjectFieldTemplate.js +1 -0
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -0
- package/lib/components/templates/OptionalDataControlsTemplate.js +2 -1
- package/lib/components/templates/OptionalDataControlsTemplate.js.map +1 -0
- package/lib/components/templates/TitleField.js +1 -0
- package/lib/components/templates/TitleField.js.map +1 -0
- package/lib/components/templates/UnsupportedField.js +1 -0
- package/lib/components/templates/UnsupportedField.js.map +1 -0
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -0
- package/lib/components/templates/index.js +22 -21
- package/lib/components/templates/index.js.map +1 -0
- package/lib/components/widgets/AltDateTimeWidget.js +1 -0
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -0
- package/lib/components/widgets/AltDateWidget.js +1 -0
- package/lib/components/widgets/AltDateWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +4 -3
- package/lib/components/widgets/CheckboxWidget.js.map +1 -0
- package/lib/components/widgets/CheckboxesWidget.js +1 -0
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -0
- package/lib/components/widgets/ColorWidget.js +1 -0
- package/lib/components/widgets/ColorWidget.js.map +1 -0
- package/lib/components/widgets/DateTimeWidget.js +1 -0
- package/lib/components/widgets/DateTimeWidget.js.map +1 -0
- package/lib/components/widgets/DateWidget.js +1 -0
- package/lib/components/widgets/DateWidget.js.map +1 -0
- package/lib/components/widgets/EmailWidget.js +1 -0
- package/lib/components/widgets/EmailWidget.js.map +1 -0
- package/lib/components/widgets/FileWidget.js +1 -0
- package/lib/components/widgets/FileWidget.js.map +1 -0
- package/lib/components/widgets/HiddenWidget.js +1 -0
- package/lib/components/widgets/HiddenWidget.js.map +1 -0
- package/lib/components/widgets/PasswordWidget.js +1 -0
- package/lib/components/widgets/PasswordWidget.js.map +1 -0
- package/lib/components/widgets/RadioWidget.js +1 -0
- package/lib/components/widgets/RadioWidget.js.map +1 -0
- package/lib/components/widgets/RangeWidget.js +1 -0
- package/lib/components/widgets/RangeWidget.js.map +1 -0
- package/lib/components/widgets/RatingWidget.d.ts +1 -1
- package/lib/components/widgets/RatingWidget.d.ts.map +1 -1
- package/lib/components/widgets/RatingWidget.js +2 -1
- package/lib/components/widgets/RatingWidget.js.map +1 -0
- package/lib/components/widgets/SelectWidget.js +1 -0
- package/lib/components/widgets/SelectWidget.js.map +1 -0
- package/lib/components/widgets/TextWidget.js +1 -0
- package/lib/components/widgets/TextWidget.js.map +1 -0
- package/lib/components/widgets/TextareaWidget.js +1 -0
- package/lib/components/widgets/TextareaWidget.js.map +1 -0
- package/lib/components/widgets/TimeWidget.js +1 -0
- package/lib/components/widgets/TimeWidget.js.map +1 -0
- package/lib/components/widgets/URLWidget.js +1 -0
- package/lib/components/widgets/URLWidget.js.map +1 -0
- package/lib/components/widgets/UpDownWidget.js +1 -0
- package/lib/components/widgets/UpDownWidget.js.map +1 -0
- package/lib/components/widgets/index.js +21 -20
- package/lib/components/widgets/index.js.map +1 -0
- package/lib/getDefaultRegistry.js +4 -3
- package/lib/getDefaultRegistry.js.map +1 -0
- package/lib/getTestRegistry.js +2 -1
- package/lib/getTestRegistry.js.map +1 -0
- package/lib/index.d.ts +12 -12
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -7
- package/lib/index.js.map +1 -0
- package/lib/withTheme.d.ts +1 -1
- package/lib/withTheme.d.ts.map +1 -1
- package/lib/withTheme.js +2 -1
- package/lib/withTheme.js.map +1 -0
- package/package.json +13 -18
- package/src/components/Form.tsx +68 -47
- package/src/components/fields/ArrayField.tsx +17 -19
- package/src/components/fields/BooleanField.tsx +1 -2
- package/src/components/fields/LayoutGridField.tsx +57 -65
- package/src/components/fields/LayoutMultiSchemaField.tsx +18 -18
- package/src/components/fields/MultiSchemaField.tsx +6 -8
- package/src/components/fields/ObjectField.tsx +26 -27
- package/src/components/fields/SchemaField.tsx +13 -4
- package/src/components/fields/index.ts +14 -14
- package/src/components/templates/BaseInputTemplate.tsx +2 -2
- package/src/components/templates/ButtonTemplates/AddButton.tsx +1 -1
- package/src/components/templates/ButtonTemplates/index.ts +3 -3
- package/src/components/templates/DescriptionField.tsx +1 -1
- package/src/components/templates/FieldHelpTemplate.tsx +1 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +1 -1
- package/src/components/templates/FieldTemplate/index.ts +1 -1
- package/src/components/templates/OptionalDataControlsTemplate.tsx +1 -1
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +21 -21
- package/src/components/widgets/CheckboxWidget.tsx +9 -2
- package/src/components/widgets/RatingWidget.tsx +0 -1
- package/src/components/widgets/index.ts +20 -20
- package/src/getDefaultRegistry.ts +3 -3
- package/src/getTestRegistry.tsx +1 -1
- package/src/index.ts +12 -12
- package/src/withTheme.tsx +2 -2
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/tsconfig.json +0 -30
package/dist/core.umd.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.
|
|
5
|
-
})(this, (function (exports, react, utils,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@rjsf/utils'), require('react/jsx-runtime'), require('markdown-to-jsx/react'), require('@rjsf/validator-ajv8')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', '@rjsf/utils', 'react/jsx-runtime', 'markdown-to-jsx/react', '@rjsf/validator-ajv8'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSONSchemaForm = {}, global.react, global.utils, global.jsxRuntime, global.react$1, global.validator));
|
|
5
|
+
})(this, (function (exports, react, utils, jsxRuntime, react$1, validator) { 'use strict';
|
|
6
6
|
|
|
7
7
|
// src/components/Form.tsx
|
|
8
|
+
var rowIdCounter = 0;
|
|
8
9
|
function generateRowId() {
|
|
9
|
-
|
|
10
|
+
rowIdCounter += 1;
|
|
11
|
+
return `rjsf-array-item-${rowIdCounter}`;
|
|
10
12
|
}
|
|
11
13
|
function generateKeyedFormData(formData) {
|
|
12
14
|
return !Array.isArray(formData) ? [] : formData.map((item) => ({
|
|
@@ -269,14 +271,14 @@
|
|
|
269
271
|
const { description } = utils.getUiOptions(itemUiSchema);
|
|
270
272
|
const hasDescription = !!description || !!itemSchema.description;
|
|
271
273
|
const { orderable = true, removable = true, copyable = false } = uiOptions;
|
|
272
|
-
const
|
|
274
|
+
const has = {
|
|
273
275
|
moveUp: orderable && canMoveUp,
|
|
274
276
|
moveDown: orderable && canMoveDown,
|
|
275
277
|
copy: copyable && canAdd,
|
|
276
278
|
remove: removable && canRemove,
|
|
277
279
|
toolbar: false
|
|
278
280
|
};
|
|
279
|
-
|
|
281
|
+
has.toolbar = Object.keys(has).some((key) => has[key]);
|
|
280
282
|
const onAddItem = react.useCallback(
|
|
281
283
|
(event) => {
|
|
282
284
|
handleAddItem(event, index + 1);
|
|
@@ -336,10 +338,10 @@
|
|
|
336
338
|
disabled,
|
|
337
339
|
readonly,
|
|
338
340
|
canAdd,
|
|
339
|
-
hasCopy:
|
|
340
|
-
hasMoveUp:
|
|
341
|
-
hasMoveDown:
|
|
342
|
-
hasRemove:
|
|
341
|
+
hasCopy: has.copy,
|
|
342
|
+
hasMoveUp: has.moveUp,
|
|
343
|
+
hasMoveDown: has.moveDown,
|
|
344
|
+
hasRemove: has.remove,
|
|
343
345
|
index,
|
|
344
346
|
totalItems,
|
|
345
347
|
onAddItem,
|
|
@@ -354,7 +356,7 @@
|
|
|
354
356
|
itemKey,
|
|
355
357
|
className: "rjsf-array-item",
|
|
356
358
|
disabled,
|
|
357
|
-
hasToolbar:
|
|
359
|
+
hasToolbar: has.toolbar,
|
|
358
360
|
index,
|
|
359
361
|
totalItems,
|
|
360
362
|
readonly,
|
|
@@ -397,7 +399,7 @@
|
|
|
397
399
|
const { schemaUtils, fields: fields2, formContext, globalUiOptions } = registry;
|
|
398
400
|
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
399
401
|
const uiOptions = react.useMemo(() => utils.getUiOptions(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
|
|
400
|
-
const schemaItems = react.useMemo(() => isObject(schema.items) ? schema.items : {}, [schema.items]);
|
|
402
|
+
const schemaItems = react.useMemo(() => utils.isObject(schema.items) ? schema.items : {}, [schema.items]);
|
|
401
403
|
const itemsSchema = react.useMemo(() => schemaUtils.retrieveSchema(schemaItems), [schemaUtils, schemaItems]);
|
|
402
404
|
const formData = react.useMemo(() => keyedToPlainFormData(keyedFormData), [keyedFormData]);
|
|
403
405
|
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
@@ -499,11 +501,8 @@
|
|
|
499
501
|
const { OptionalDataControlsField: OptionalDataControlsField2 } = fields2;
|
|
500
502
|
const renderOptionalField = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
501
503
|
const hasFormData = utils.isFormDataAvailable(formData);
|
|
502
|
-
const schemaItems = react.useMemo(
|
|
503
|
-
|
|
504
|
-
[schema.items]
|
|
505
|
-
);
|
|
506
|
-
const hasAdditionalItems = isObject(schema.additionalItems);
|
|
504
|
+
const schemaItems = react.useMemo(() => Array.isArray(schema.items) ? schema.items : [], [schema.items]);
|
|
505
|
+
const hasAdditionalItems = utils.isObject(schema.additionalItems);
|
|
507
506
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
508
507
|
if (items.length < schemaItems.length) {
|
|
509
508
|
items = items.concat(new Array(schemaItems.length - items.length));
|
|
@@ -522,7 +521,7 @@
|
|
|
522
521
|
const { key, item } = keyedItem;
|
|
523
522
|
const itemCast = item;
|
|
524
523
|
const additional = index >= schemaItems.length;
|
|
525
|
-
const rawItemSchema = (additional && isObject(schema.additionalItems) ? schema.additionalItems : schemaItems[index]) || {};
|
|
524
|
+
const rawItemSchema = (additional && utils.isObject(schema.additionalItems) ? schema.additionalItems : schemaItems[index]) || {};
|
|
526
525
|
let itemUiSchema;
|
|
527
526
|
if (additional) {
|
|
528
527
|
itemUiSchema = uiSchema.additionalItems;
|
|
@@ -625,9 +624,9 @@
|
|
|
625
624
|
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
626
625
|
const i = parseInt(idx, 10);
|
|
627
626
|
if (index === void 0 || i < index) {
|
|
628
|
-
|
|
627
|
+
utils.setByPath(newErrorSchema, i, errorSchemaRef.current[i]);
|
|
629
628
|
} else if (i >= index) {
|
|
630
|
-
|
|
629
|
+
utils.setByPath(newErrorSchema, i + 1, errorSchemaRef.current[i]);
|
|
631
630
|
}
|
|
632
631
|
}
|
|
633
632
|
}
|
|
@@ -656,15 +655,15 @@
|
|
|
656
655
|
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
657
656
|
const i = parseInt(idx, 10);
|
|
658
657
|
if (i <= index) {
|
|
659
|
-
|
|
658
|
+
utils.setByPath(newErrorSchema, i, errorSchemaRef.current[i]);
|
|
660
659
|
} else if (i > index) {
|
|
661
|
-
|
|
660
|
+
utils.setByPath(newErrorSchema, i + 1, errorSchemaRef.current[i]);
|
|
662
661
|
}
|
|
663
662
|
}
|
|
664
663
|
}
|
|
665
664
|
const newKeyedFormDataRow = {
|
|
666
665
|
key: generateRowId(),
|
|
667
|
-
item:
|
|
666
|
+
item: structuredClone(keyedFormDataRef.current[index].item)
|
|
668
667
|
};
|
|
669
668
|
const newKeyedFormData = [...keyedFormDataRef.current];
|
|
670
669
|
if (index !== void 0) {
|
|
@@ -687,9 +686,9 @@
|
|
|
687
686
|
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
688
687
|
const i = parseInt(idx, 10);
|
|
689
688
|
if (i < index) {
|
|
690
|
-
|
|
689
|
+
utils.setByPath(newErrorSchema, i, errorSchemaRef.current[i]);
|
|
691
690
|
} else if (i > index) {
|
|
692
|
-
|
|
691
|
+
utils.setByPath(newErrorSchema, i - 1, errorSchemaRef.current[i]);
|
|
693
692
|
}
|
|
694
693
|
}
|
|
695
694
|
}
|
|
@@ -710,11 +709,11 @@
|
|
|
710
709
|
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
711
710
|
const i = parseInt(idx, 10);
|
|
712
711
|
if (i === index) {
|
|
713
|
-
|
|
712
|
+
utils.setByPath(newErrorSchema, newIndex, errorSchemaRef.current[index]);
|
|
714
713
|
} else if (i === newIndex) {
|
|
715
|
-
|
|
714
|
+
utils.setByPath(newErrorSchema, index, errorSchemaRef.current[newIndex]);
|
|
716
715
|
} else {
|
|
717
|
-
|
|
716
|
+
utils.setByPath(newErrorSchema, idx, errorSchemaRef.current[i]);
|
|
718
717
|
}
|
|
719
718
|
}
|
|
720
719
|
}
|
|
@@ -839,7 +838,7 @@
|
|
|
839
838
|
enumOptions = utils.optionsList(
|
|
840
839
|
{
|
|
841
840
|
oneOf: schema.oneOf.map((option) => {
|
|
842
|
-
if (isObject(option)) {
|
|
841
|
+
if (utils.isObject(option)) {
|
|
843
842
|
return {
|
|
844
843
|
...option,
|
|
845
844
|
title: option.title || (option.const === true ? yes : no)
|
|
@@ -1051,37 +1050,38 @@
|
|
|
1051
1050
|
}
|
|
1052
1051
|
var LAYOUT_GRID_FIELD_TEST_IDS = utils.getTestIds();
|
|
1053
1052
|
function computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
|
|
1054
|
-
const globalUiOptions =
|
|
1055
|
-
const localUiSchema =
|
|
1056
|
-
const localUiOptions = { ...
|
|
1053
|
+
const globalUiOptions = uiSchema?.[utils.UI_GLOBAL_OPTIONS_KEY] ?? {};
|
|
1054
|
+
const localUiSchema = utils.getByPath(uiSchema, utils.toPath(field));
|
|
1055
|
+
const localUiOptions = { ...localUiSchema?.[utils.UI_OPTIONS_KEY] ?? {}, ...uiProps, ...globalUiOptions };
|
|
1057
1056
|
const fieldUiSchema = { ...localUiSchema };
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1057
|
+
if (Object.keys(localUiOptions).length > 0) {
|
|
1058
|
+
fieldUiSchema[utils.UI_OPTIONS_KEY] = localUiOptions;
|
|
1060
1059
|
}
|
|
1061
|
-
if (
|
|
1062
|
-
|
|
1060
|
+
if (Object.keys(globalUiOptions).length > 0) {
|
|
1061
|
+
fieldUiSchema[utils.UI_GLOBAL_OPTIONS_KEY] = globalUiOptions;
|
|
1063
1062
|
}
|
|
1064
1063
|
let { readonly: uiReadonly } = utils.getUiOptions(fieldUiSchema);
|
|
1065
|
-
if (forceReadonly === true ||
|
|
1064
|
+
if (forceReadonly === true || uiReadonly === void 0 && schemaReadonly === true) {
|
|
1066
1065
|
uiReadonly = true;
|
|
1067
|
-
|
|
1068
|
-
|
|
1066
|
+
const fieldUiOptions = fieldUiSchema[utils.UI_OPTIONS_KEY];
|
|
1067
|
+
if (fieldUiOptions && utils.READONLY_KEY in fieldUiOptions) {
|
|
1068
|
+
fieldUiOptions[utils.READONLY_KEY] = true;
|
|
1069
1069
|
} else {
|
|
1070
|
-
|
|
1070
|
+
fieldUiSchema[`ui:${utils.READONLY_KEY}`] = true;
|
|
1071
1071
|
}
|
|
1072
1072
|
}
|
|
1073
1073
|
return { fieldUiSchema, uiReadonly };
|
|
1074
1074
|
}
|
|
1075
1075
|
function conditionMatches(operator, datum, value = "$0m3tH1nG Un3xP3cT3d") {
|
|
1076
|
-
const data =
|
|
1077
|
-
const values =
|
|
1076
|
+
const data = [datum].flat().sort();
|
|
1077
|
+
const values = [value].flat().sort();
|
|
1078
1078
|
switch (operator) {
|
|
1079
1079
|
case "all" /* ALL */:
|
|
1080
|
-
return
|
|
1080
|
+
return utils.deepEquals(data, values);
|
|
1081
1081
|
case "some" /* SOME */:
|
|
1082
|
-
return
|
|
1082
|
+
return data.some((entry) => values.includes(entry));
|
|
1083
1083
|
case "none" /* NONE */:
|
|
1084
|
-
return
|
|
1084
|
+
return !data.some((entry) => values.includes(entry));
|
|
1085
1085
|
default:
|
|
1086
1086
|
return false;
|
|
1087
1087
|
}
|
|
@@ -1089,7 +1089,7 @@
|
|
|
1089
1089
|
function findChildrenAndProps(layoutGridSchema, schemaKey, registry) {
|
|
1090
1090
|
let gridProps = {};
|
|
1091
1091
|
let children = layoutGridSchema[schemaKey];
|
|
1092
|
-
if (isPlainObject(children)) {
|
|
1092
|
+
if (utils.isPlainObject(children)) {
|
|
1093
1093
|
const { children: elements, className: toMapClassNames, ...otherProps } = children;
|
|
1094
1094
|
children = elements;
|
|
1095
1095
|
if (toMapClassNames) {
|
|
@@ -1108,12 +1108,12 @@
|
|
|
1108
1108
|
function computeArraySchemasIfPresent(schema, fieldPathId, potentialIndex) {
|
|
1109
1109
|
let rawSchema;
|
|
1110
1110
|
let resultPathId = fieldPathId;
|
|
1111
|
-
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" &&
|
|
1111
|
+
if (isNumericIndex(potentialIndex) && schema && schema?.type === "array" && utils.ITEMS_KEY in schema) {
|
|
1112
1112
|
const index = Number(potentialIndex);
|
|
1113
1113
|
const items = schema[utils.ITEMS_KEY];
|
|
1114
1114
|
if (Array.isArray(items)) {
|
|
1115
1115
|
if (index > items.length) {
|
|
1116
|
-
rawSchema =
|
|
1116
|
+
rawSchema = items.at(-1);
|
|
1117
1117
|
} else {
|
|
1118
1118
|
rawSchema = items[index];
|
|
1119
1119
|
}
|
|
@@ -1138,44 +1138,45 @@
|
|
|
1138
1138
|
let isReadonly = schema.readOnly;
|
|
1139
1139
|
parts.forEach((part) => {
|
|
1140
1140
|
fieldPathId = utils.toFieldPathId(part, globalFormOptions, fieldPathId);
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1141
|
+
const schemaProperties = schema?.[utils.PROPERTIES_KEY];
|
|
1142
|
+
if (schemaProperties) {
|
|
1143
|
+
rawSchema = schemaProperties[part] ?? {};
|
|
1144
|
+
} else if (schema && (utils.ONE_OF_KEY in schema || utils.ANY_OF_KEY in schema)) {
|
|
1145
|
+
const xxx = utils.ONE_OF_KEY in schema ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1145
1146
|
const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
|
|
1146
|
-
rawSchema =
|
|
1147
|
+
rawSchema = utils.getPropertySchema(selectedSchema, part);
|
|
1147
1148
|
} else {
|
|
1148
1149
|
const result = computeArraySchemasIfPresent(schema, fieldPathId, part);
|
|
1149
1150
|
rawSchema = result.rawSchema ?? {};
|
|
1150
1151
|
fieldPathId = result.fieldPathId;
|
|
1151
1152
|
}
|
|
1152
|
-
innerData =
|
|
1153
|
+
innerData = utils.getByPath(innerData, part, {});
|
|
1153
1154
|
schema = schemaUtils.retrieveSchema(rawSchema, innerData);
|
|
1154
1155
|
isReadonly = getNonNullishValue(schema.readOnly, isReadonly);
|
|
1155
1156
|
});
|
|
1156
1157
|
let optionsInfo;
|
|
1157
1158
|
let isRequired2 = false;
|
|
1158
|
-
if (
|
|
1159
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
1159
1160
|
schema = void 0;
|
|
1160
1161
|
}
|
|
1161
1162
|
if (schema && leafPath) {
|
|
1162
|
-
if (schema && (
|
|
1163
|
-
const xxx =
|
|
1163
|
+
if (schema && (utils.ONE_OF_KEY in schema || utils.ANY_OF_KEY in schema)) {
|
|
1164
|
+
const xxx = utils.ONE_OF_KEY in schema ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1164
1165
|
schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
|
|
1165
1166
|
}
|
|
1166
1167
|
fieldPathId = utils.toFieldPathId(leafPath, globalFormOptions, fieldPathId);
|
|
1167
|
-
isRequired2 = schema !== void 0 && Array.isArray(schema.required) &&
|
|
1168
|
+
isRequired2 = schema !== void 0 && Array.isArray(schema.required) && schema.required.includes(leafPath);
|
|
1168
1169
|
const result = computeArraySchemasIfPresent(schema, fieldPathId, leafPath);
|
|
1169
1170
|
if (result.rawSchema) {
|
|
1170
1171
|
schema = result.rawSchema;
|
|
1171
1172
|
fieldPathId = result.fieldPathId;
|
|
1172
1173
|
} else {
|
|
1173
|
-
schema =
|
|
1174
|
+
schema = schema?.[utils.PROPERTIES_KEY]?.[leafPath];
|
|
1174
1175
|
schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
|
|
1175
1176
|
}
|
|
1176
1177
|
isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
|
|
1177
|
-
if (schema && (
|
|
1178
|
-
const xxx =
|
|
1178
|
+
if (schema && (utils.ONE_OF_KEY in schema || utils.ANY_OF_KEY in schema)) {
|
|
1179
|
+
const xxx = utils.ONE_OF_KEY in schema ? utils.ONE_OF_KEY : utils.ANY_OF_KEY;
|
|
1179
1180
|
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1180
1181
|
optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
|
|
1181
1182
|
}
|
|
@@ -1184,10 +1185,10 @@
|
|
|
1184
1185
|
}
|
|
1185
1186
|
function getCustomRenderComponent(render, registry) {
|
|
1186
1187
|
let customRenderer = render;
|
|
1187
|
-
if (
|
|
1188
|
+
if (typeof customRenderer === "string") {
|
|
1188
1189
|
customRenderer = utils.lookupFromFormContext(registry, customRenderer);
|
|
1189
1190
|
}
|
|
1190
|
-
if (
|
|
1191
|
+
if (typeof customRenderer === "function") {
|
|
1191
1192
|
return customRenderer;
|
|
1192
1193
|
}
|
|
1193
1194
|
return null;
|
|
@@ -1197,23 +1198,21 @@
|
|
|
1197
1198
|
let UIComponent = null;
|
|
1198
1199
|
let uiProps = {};
|
|
1199
1200
|
let rendered;
|
|
1200
|
-
if (
|
|
1201
|
+
if (typeof gridSchema === "string" || gridSchema === void 0) {
|
|
1201
1202
|
name = gridSchema ?? "";
|
|
1202
1203
|
} else {
|
|
1203
1204
|
const { name: innerName = "", render, ...innerProps } = gridSchema;
|
|
1204
1205
|
name = innerName;
|
|
1205
1206
|
uiProps = innerProps;
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
uiProps[key] = utils.lookupFromFormContext(registry, lookupName, lookupName);
|
|
1213
|
-
}
|
|
1207
|
+
Object.entries(uiProps).forEach(([key, prop]) => {
|
|
1208
|
+
if (typeof prop === "string") {
|
|
1209
|
+
const match = LOOKUP_REGEX.exec(prop);
|
|
1210
|
+
if (Array.isArray(match) && match.length > 1) {
|
|
1211
|
+
const lookupName = match[1];
|
|
1212
|
+
uiProps[key] = utils.lookupFromFormContext(registry, lookupName, lookupName);
|
|
1214
1213
|
}
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1217
1216
|
UIComponent = getCustomRenderComponent(render, registry);
|
|
1218
1217
|
if (!innerName && UIComponent) {
|
|
1219
1218
|
rendered = /* @__PURE__ */ jsxRuntime.jsx(UIComponent, { ...innerProps, "data-testid": LAYOUT_GRID_FIELD_TEST_IDS.uiComponent });
|
|
@@ -1241,7 +1240,7 @@
|
|
|
1241
1240
|
const { formData, registry } = layoutGridFieldProps;
|
|
1242
1241
|
const { children, gridProps } = findChildrenAndProps(layoutGridSchema, "ui:condition" /* CONDITION */, registry);
|
|
1243
1242
|
const { operator, field = "", value } = gridProps;
|
|
1244
|
-
const fieldData =
|
|
1243
|
+
const fieldData = utils.getByPath(formData, utils.toPath(field), null);
|
|
1245
1244
|
if (conditionMatches(operator, fieldData, value)) {
|
|
1246
1245
|
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridFieldChildren, { ...layoutGridFieldProps, childrenLayoutGridSchemaId: children });
|
|
1247
1246
|
}
|
|
@@ -1315,6 +1314,7 @@
|
|
|
1315
1314
|
if (schema) {
|
|
1316
1315
|
const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField2 : SchemaField2;
|
|
1317
1316
|
const { fieldUiSchema, uiReadonly } = computeFieldUiSchema(name, uiProps, uiSchema, isReadonly, readonly);
|
|
1317
|
+
const namePath = utils.toPath(name);
|
|
1318
1318
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1319
1319
|
Field,
|
|
1320
1320
|
{
|
|
@@ -1325,9 +1325,9 @@
|
|
|
1325
1325
|
readonly: uiReadonly,
|
|
1326
1326
|
schema,
|
|
1327
1327
|
uiSchema: fieldUiSchema,
|
|
1328
|
-
errorSchema:
|
|
1328
|
+
errorSchema: utils.getByPath(errorSchema, namePath),
|
|
1329
1329
|
fieldPathId: memoFieldPathId,
|
|
1330
|
-
formData:
|
|
1330
|
+
formData: utils.getByPath(formData, namePath),
|
|
1331
1331
|
onChange,
|
|
1332
1332
|
onBlur,
|
|
1333
1333
|
onFocus,
|
|
@@ -1363,10 +1363,10 @@
|
|
|
1363
1363
|
const { uiSchema } = props;
|
|
1364
1364
|
let { layoutGridSchema } = props;
|
|
1365
1365
|
const uiOptions = utils.getUiOptions(uiSchema);
|
|
1366
|
-
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1366
|
+
if (!layoutGridSchema && LAYOUT_GRID_UI_OPTION in uiOptions && utils.isObject(uiOptions[LAYOUT_GRID_UI_OPTION])) {
|
|
1367
1367
|
layoutGridSchema = uiOptions[LAYOUT_GRID_UI_OPTION];
|
|
1368
1368
|
}
|
|
1369
|
-
if (isObject(layoutGridSchema)) {
|
|
1369
|
+
if (utils.isObject(layoutGridSchema)) {
|
|
1370
1370
|
if ("ui:row" /* ROW */ in layoutGridSchema) {
|
|
1371
1371
|
return /* @__PURE__ */ jsxRuntime.jsx(LayoutGridRow, { ...props, layoutGridSchema });
|
|
1372
1372
|
}
|
|
@@ -1413,17 +1413,17 @@
|
|
|
1413
1413
|
const defaultValue = "!@#!@$@#$!@$#";
|
|
1414
1414
|
const schemaOptions = options.map(({ schema }) => schema);
|
|
1415
1415
|
return schemaOptions.find((option) => {
|
|
1416
|
-
const selector =
|
|
1417
|
-
const result =
|
|
1416
|
+
const selector = option[utils.PROPERTIES_KEY]?.[selectorField];
|
|
1417
|
+
const result = utils.getByPath(selector, utils.DEFAULT_KEY, utils.getByPath(selector, utils.CONST_KEY, defaultValue));
|
|
1418
1418
|
return result === value;
|
|
1419
1419
|
});
|
|
1420
1420
|
}
|
|
1421
1421
|
function computeEnumOptions(schema, options, schemaUtils, uiSchema, formData) {
|
|
1422
1422
|
const realOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
|
|
1423
1423
|
let tempSchema = schema;
|
|
1424
|
-
if (
|
|
1424
|
+
if (utils.ONE_OF_KEY in schema) {
|
|
1425
1425
|
tempSchema = { ...schema, [utils.ONE_OF_KEY]: realOptions };
|
|
1426
|
-
} else if (
|
|
1426
|
+
} else if (utils.ANY_OF_KEY in schema) {
|
|
1427
1427
|
tempSchema = { ...schema, [utils.ANY_OF_KEY]: realOptions };
|
|
1428
1428
|
}
|
|
1429
1429
|
const enumOptions = utils.optionsList(tempSchema, uiSchema);
|
|
@@ -1454,7 +1454,7 @@
|
|
|
1454
1454
|
} = props;
|
|
1455
1455
|
const { widgets: widgets2, schemaUtils, globalUiOptions } = registry;
|
|
1456
1456
|
const [enumOptions, setEnumOptions] = react.useState(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
|
|
1457
|
-
const id =
|
|
1457
|
+
const id = fieldPathId[utils.ID_KEY];
|
|
1458
1458
|
const discriminator = utils.getDiscriminatorFieldFromSchema(schema);
|
|
1459
1459
|
const FieldErrorTemplate2 = utils.getTemplate("FieldErrorTemplate", registry, options);
|
|
1460
1460
|
const FieldTemplate2 = utils.getTemplate("FieldTemplate", registry, options);
|
|
@@ -1476,14 +1476,15 @@
|
|
|
1476
1476
|
if (!selectorField) {
|
|
1477
1477
|
throw new Error("No selector field provided for the LayoutMultiSchemaField");
|
|
1478
1478
|
}
|
|
1479
|
-
const selectedOption =
|
|
1480
|
-
let optionSchema =
|
|
1479
|
+
const selectedOption = utils.getByPath(formData, selectorField);
|
|
1480
|
+
let optionSchema = utils.getPropertySchema(enumOptions[0]?.schema, selectorField);
|
|
1481
1481
|
const option = getSelectedOption(enumOptions, selectorField, selectedOption);
|
|
1482
1482
|
optionSchema = optionSchema?.type ? optionSchema : { ...optionSchema, type: option?.type || baseType };
|
|
1483
1483
|
const Widget = utils.getWidget(optionSchema, widget, widgets2);
|
|
1484
1484
|
const hideFieldError = uiSchemaHideError === void 0 ? hideError : Boolean(uiSchemaHideError);
|
|
1485
|
-
const rawErrors =
|
|
1486
|
-
const fieldErrorSchema =
|
|
1485
|
+
const rawErrors = errorSchema?.[utils.ERRORS_KEY] ?? [];
|
|
1486
|
+
const fieldErrorSchema = { ...errorSchema };
|
|
1487
|
+
delete fieldErrorSchema[utils.ERRORS_KEY];
|
|
1487
1488
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1488
1489
|
const onOptionChange = (opt) => {
|
|
1489
1490
|
if (disabled || readonly) {
|
|
@@ -1496,7 +1497,7 @@
|
|
|
1496
1497
|
newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, "excludeObjectChildren");
|
|
1497
1498
|
}
|
|
1498
1499
|
if (newFormData) {
|
|
1499
|
-
|
|
1500
|
+
utils.setByPath(newFormData, selectorField, opt);
|
|
1500
1501
|
}
|
|
1501
1502
|
onChange(newFormData, fieldPathId.path, void 0, id);
|
|
1502
1503
|
};
|
|
@@ -1509,7 +1510,7 @@
|
|
|
1509
1510
|
id,
|
|
1510
1511
|
schema,
|
|
1511
1512
|
label: (title || schema.title) ?? "",
|
|
1512
|
-
disabled: disabled || Array.isArray(enumOptions) &&
|
|
1513
|
+
disabled: disabled || Array.isArray(enumOptions) && enumOptions.length === 0,
|
|
1513
1514
|
uiSchema,
|
|
1514
1515
|
required,
|
|
1515
1516
|
readonly: !!readonly,
|
|
@@ -1517,9 +1518,9 @@
|
|
|
1517
1518
|
displayLabel,
|
|
1518
1519
|
errors,
|
|
1519
1520
|
onChange,
|
|
1520
|
-
onKeyRename: noop,
|
|
1521
|
-
onKeyRenameBlur: noop,
|
|
1522
|
-
onRemoveProperty: noop,
|
|
1521
|
+
onKeyRename: utils.noop,
|
|
1522
|
+
onKeyRenameBlur: utils.noop,
|
|
1523
|
+
onRemoveProperty: utils.noop,
|
|
1523
1524
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1524
1525
|
Widget,
|
|
1525
1526
|
{
|
|
@@ -1527,7 +1528,7 @@
|
|
|
1527
1528
|
name,
|
|
1528
1529
|
schema,
|
|
1529
1530
|
label: (title || schema.title) ?? "",
|
|
1530
|
-
disabled: disabled || Array.isArray(enumOptions) &&
|
|
1531
|
+
disabled: disabled || Array.isArray(enumOptions) && enumOptions.length === 0,
|
|
1531
1532
|
uiSchema,
|
|
1532
1533
|
autofocus,
|
|
1533
1534
|
readonly,
|
|
@@ -1554,7 +1555,7 @@
|
|
|
1554
1555
|
const {
|
|
1555
1556
|
name,
|
|
1556
1557
|
disabled = false,
|
|
1557
|
-
errorSchema
|
|
1558
|
+
errorSchema,
|
|
1558
1559
|
formData,
|
|
1559
1560
|
fieldPathId,
|
|
1560
1561
|
onBlur,
|
|
@@ -1644,8 +1645,9 @@
|
|
|
1644
1645
|
...uiOptions
|
|
1645
1646
|
} = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1646
1647
|
const Widget = utils.getWidget({ type: "number" }, widget, widgets2);
|
|
1647
|
-
const rawErrors =
|
|
1648
|
-
const fieldErrorSchema =
|
|
1648
|
+
const rawErrors = errorSchema?.[utils.ERRORS_KEY] ?? [];
|
|
1649
|
+
const fieldErrorSchema = { ...errorSchema };
|
|
1650
|
+
delete fieldErrorSchema[utils.ERRORS_KEY];
|
|
1649
1651
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
1650
1652
|
const option = selectedOption >= 0 ? retrievedOptions[selectedOption] || null : null;
|
|
1651
1653
|
let optionSchema;
|
|
@@ -1696,7 +1698,7 @@
|
|
|
1696
1698
|
onChange: onOptionChange,
|
|
1697
1699
|
onBlur,
|
|
1698
1700
|
onFocus,
|
|
1699
|
-
disabled: disabled ||
|
|
1701
|
+
disabled: disabled || enumOptions.length === 0,
|
|
1700
1702
|
multiple: false,
|
|
1701
1703
|
rawErrors,
|
|
1702
1704
|
errorSchema: fieldErrorSchema,
|
|
@@ -1832,12 +1834,12 @@
|
|
|
1832
1834
|
const onPropertyChange = react.useCallback(
|
|
1833
1835
|
(value, path, newErrorSchema, id) => {
|
|
1834
1836
|
let normalizedValue = value;
|
|
1835
|
-
if (value === void 0 && addedByAdditionalProperties) {
|
|
1837
|
+
if (value === void 0 && addedByAdditionalProperties && utils.deepEquals(path, innerFieldIdPathId.path)) {
|
|
1836
1838
|
normalizedValue = "";
|
|
1837
1839
|
}
|
|
1838
1840
|
onChange(normalizedValue, path, newErrorSchema, id);
|
|
1839
1841
|
},
|
|
1840
|
-
[onChange, addedByAdditionalProperties]
|
|
1842
|
+
[onChange, addedByAdditionalProperties, innerFieldIdPathId]
|
|
1841
1843
|
);
|
|
1842
1844
|
const onKeyRename = react.useCallback(
|
|
1843
1845
|
(value) => {
|
|
@@ -1932,7 +1934,7 @@
|
|
|
1932
1934
|
const { duplicateKeySuffixSeparator = "-" } = utils.getUiOptions(uiSchema, globalUiOptions);
|
|
1933
1935
|
let index = 0;
|
|
1934
1936
|
let newKey = preferredKey;
|
|
1935
|
-
while (
|
|
1937
|
+
while (utils.hasByPath(existingFormData, newKey)) {
|
|
1936
1938
|
index += 1;
|
|
1937
1939
|
newKey = `${preferredKey}${duplicateKeySuffixSeparator}${index}`;
|
|
1938
1940
|
}
|
|
@@ -1947,12 +1949,12 @@
|
|
|
1947
1949
|
const newFormData = { ...formData };
|
|
1948
1950
|
const newKey = getAvailableKey("newKey", newFormData);
|
|
1949
1951
|
if (schema.patternProperties) {
|
|
1950
|
-
|
|
1952
|
+
utils.setByPath(newFormData, newKey, null);
|
|
1951
1953
|
} else {
|
|
1952
1954
|
let type = void 0;
|
|
1953
1955
|
let constValue = void 0;
|
|
1954
1956
|
let defaultValue = void 0;
|
|
1955
|
-
if (isObject(schema.additionalProperties)) {
|
|
1957
|
+
if (utils.isObject(schema.additionalProperties)) {
|
|
1956
1958
|
type = schema.additionalProperties.type;
|
|
1957
1959
|
constValue = schema.additionalProperties.const;
|
|
1958
1960
|
defaultValue = schema.additionalProperties.default;
|
|
@@ -1968,7 +1970,7 @@
|
|
|
1968
1970
|
}
|
|
1969
1971
|
}
|
|
1970
1972
|
const newValue = constValue ?? defaultValue ?? getDefaultValue(translateString, type);
|
|
1971
|
-
|
|
1973
|
+
utils.setByPath(newFormData, newKey, newValue);
|
|
1972
1974
|
}
|
|
1973
1975
|
if (lastRenamedProperty.current.previousKey === newKey) {
|
|
1974
1976
|
lastRenamedProperty.current.currentKey = newKey;
|
|
@@ -2044,11 +2046,11 @@
|
|
|
2044
2046
|
{
|
|
2045
2047
|
propertyName,
|
|
2046
2048
|
required: isRequired(schema, propertyName),
|
|
2047
|
-
schema:
|
|
2049
|
+
schema: utils.getPropertySchema(schema, propertyName),
|
|
2048
2050
|
uiSchema: fieldUiSchema,
|
|
2049
|
-
errorSchema:
|
|
2051
|
+
errorSchema: utils.getByPath(errorSchema, propertyName),
|
|
2050
2052
|
fieldPathId: childFieldPathId,
|
|
2051
|
-
formData:
|
|
2053
|
+
formData: utils.getByPath(formData, propertyName),
|
|
2052
2054
|
handleKeyRename,
|
|
2053
2055
|
handleRemoveProperty,
|
|
2054
2056
|
addedByAdditionalProperties,
|
|
@@ -2232,12 +2234,12 @@
|
|
|
2232
2234
|
if (schema[utils.ANY_OF_KEY]) {
|
|
2233
2235
|
XxxOfField = _AnyOfField;
|
|
2234
2236
|
XxxOfOptions = schema[utils.ANY_OF_KEY].map(
|
|
2235
|
-
(xxxOfSchema) => schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? xxxOfSchema : {}, formData)
|
|
2237
|
+
(xxxOfSchema) => schemaUtils.retrieveSchema(utils.isObject(xxxOfSchema) ? xxxOfSchema : {}, formData)
|
|
2236
2238
|
);
|
|
2237
2239
|
} else if (schema[utils.ONE_OF_KEY]) {
|
|
2238
2240
|
XxxOfField = _OneOfField;
|
|
2239
2241
|
XxxOfOptions = schema[utils.ONE_OF_KEY].map(
|
|
2240
|
-
(xxxOfSchema) => schemaUtils.retrieveSchema(isObject(xxxOfSchema) ? xxxOfSchema : {}, formData)
|
|
2242
|
+
(xxxOfSchema) => schemaUtils.retrieveSchema(utils.isObject(xxxOfSchema) ? xxxOfSchema : {}, formData)
|
|
2241
2243
|
);
|
|
2242
2244
|
}
|
|
2243
2245
|
const isOptionalRender = utils.shouldRenderOptionalField(registry, schema, required, uiSchema);
|
|
@@ -2251,9 +2253,19 @@
|
|
|
2251
2253
|
};
|
|
2252
2254
|
}
|
|
2253
2255
|
const { __errors, ...fieldErrorSchema } = errorSchema || {};
|
|
2254
|
-
const
|
|
2256
|
+
const {
|
|
2257
|
+
"ui:classNames": consumedUiClassNames,
|
|
2258
|
+
classNames: consumedClassNames,
|
|
2259
|
+
"ui:style": consumedUiStyle,
|
|
2260
|
+
...fieldUiSchema
|
|
2261
|
+
} = uiSchema;
|
|
2255
2262
|
if (utils.UI_OPTIONS_KEY in fieldUiSchema) {
|
|
2256
|
-
|
|
2263
|
+
const {
|
|
2264
|
+
classNames: consumedOptionClassNames,
|
|
2265
|
+
style: consumedOptionStyle,
|
|
2266
|
+
...fieldUiOptions
|
|
2267
|
+
} = fieldUiSchema[utils.UI_OPTIONS_KEY];
|
|
2268
|
+
fieldUiSchema[utils.UI_OPTIONS_KEY] = fieldUiOptions;
|
|
2257
2269
|
}
|
|
2258
2270
|
const field = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2259
2271
|
FieldComponent,
|
|
@@ -2738,7 +2750,7 @@
|
|
|
2738
2750
|
(e) => {
|
|
2739
2751
|
e.preventDefault();
|
|
2740
2752
|
e.stopPropagation();
|
|
2741
|
-
onChange(options.emptyValue
|
|
2753
|
+
onChange(options.emptyValue);
|
|
2742
2754
|
},
|
|
2743
2755
|
[onChange, options.emptyValue]
|
|
2744
2756
|
);
|
|
@@ -3346,14 +3358,15 @@
|
|
|
3346
3358
|
onFocus,
|
|
3347
3359
|
onChange,
|
|
3348
3360
|
registry,
|
|
3349
|
-
htmlName
|
|
3361
|
+
htmlName,
|
|
3362
|
+
required
|
|
3350
3363
|
}) {
|
|
3351
3364
|
const DescriptionFieldTemplate = utils.getTemplate(
|
|
3352
3365
|
"DescriptionFieldTemplate",
|
|
3353
3366
|
registry,
|
|
3354
3367
|
options
|
|
3355
3368
|
);
|
|
3356
|
-
const
|
|
3369
|
+
const trueValueRequired = utils.schemaRequiresTrueValue(schema) && required;
|
|
3357
3370
|
const handleChange = react.useCallback(
|
|
3358
3371
|
(event) => onChange(event.target.checked),
|
|
3359
3372
|
[onChange]
|
|
@@ -3397,7 +3410,13 @@
|
|
|
3397
3410
|
"aria-describedby": utils.ariaDescribedByIds(id)
|
|
3398
3411
|
}
|
|
3399
3412
|
),
|
|
3400
|
-
utils.labelValue(
|
|
3413
|
+
utils.labelValue(
|
|
3414
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
3415
|
+
label,
|
|
3416
|
+
trueValueRequired && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "required", children: "*" })
|
|
3417
|
+
] }),
|
|
3418
|
+
hideLabel
|
|
3419
|
+
)
|
|
3401
3420
|
] })
|
|
3402
3421
|
] });
|
|
3403
3422
|
}
|
|
@@ -3592,7 +3611,6 @@
|
|
|
3592
3611
|
required,
|
|
3593
3612
|
disabled,
|
|
3594
3613
|
readonly,
|
|
3595
|
-
autofocus,
|
|
3596
3614
|
onChange,
|
|
3597
3615
|
onFocus,
|
|
3598
3616
|
onBlur,
|
|
@@ -3911,8 +3929,16 @@
|
|
|
3911
3929
|
};
|
|
3912
3930
|
}
|
|
3913
3931
|
function toIChangeEvent(state, status) {
|
|
3932
|
+
const { schema, uiSchema, fieldPathId, schemaUtils, formData, edit, errors, errorSchema } = state;
|
|
3914
3933
|
return {
|
|
3915
|
-
|
|
3934
|
+
schema,
|
|
3935
|
+
uiSchema,
|
|
3936
|
+
fieldPathId,
|
|
3937
|
+
schemaUtils,
|
|
3938
|
+
formData,
|
|
3939
|
+
edit,
|
|
3940
|
+
errors,
|
|
3941
|
+
errorSchema,
|
|
3916
3942
|
...status !== void 0 && { status }
|
|
3917
3943
|
};
|
|
3918
3944
|
}
|
|
@@ -4011,7 +4037,9 @@
|
|
|
4011
4037
|
// match one of the subSchemas, the retrieved schema must be updated.
|
|
4012
4038
|
isSchemaChanged || isFormDataChanged ? void 0 : this.state.retrievedSchema,
|
|
4013
4039
|
isSchemaChanged,
|
|
4014
|
-
|
|
4040
|
+
// Only the error clearing needs the path of each changed field, and it runs only when live validation does
|
|
4041
|
+
// not, so the walk that produces them is left for `getStateFromProps` to ask for
|
|
4042
|
+
() => utils.getChangedFields(this.props.formData, prevProps.formData, true),
|
|
4015
4043
|
// Skip live validation for this request if no form data has changed from the last state
|
|
4016
4044
|
!isStateDataChanged
|
|
4017
4045
|
);
|
|
@@ -4055,12 +4083,13 @@
|
|
|
4055
4083
|
* @param inputFormData - The new or current data for the `Form`
|
|
4056
4084
|
* @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
|
|
4057
4085
|
* @param [isSchemaChanged=false] - A flag indicating whether the schema has changed.
|
|
4058
|
-
* @param [
|
|
4086
|
+
* @param [getFormDataChangedFields=() => []] - Optional function returning the path of each `formData` field that
|
|
4087
|
+
* changed, only called when those paths are needed, which is when live validation is not going to run
|
|
4059
4088
|
* @param [skipLiveValidate=false] - Optional flag, if true, means that we are not running live validation
|
|
4060
4089
|
* @param [shouldSanitize=false] - Optional flag, if true, means that we should attempt to sanitize formData
|
|
4061
4090
|
* @returns - The new state for the `Form`
|
|
4062
4091
|
*/
|
|
4063
|
-
getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false,
|
|
4092
|
+
getStateFromProps(props, inputFormData, retrievedSchema, isSchemaChanged = false, getFormDataChangedFields = () => [], skipLiveValidate = false, shouldSanitize = false) {
|
|
4064
4093
|
const state = this.state || {};
|
|
4065
4094
|
const schema = "schema" in props ? props.schema : this.props.schema;
|
|
4066
4095
|
const validator2 = "validator" in props ? props.validator : this.props.validator;
|
|
@@ -4165,17 +4194,23 @@
|
|
|
4165
4194
|
const currentErrors = getCurrentErrors();
|
|
4166
4195
|
errors = currentErrors.errors;
|
|
4167
4196
|
errorSchema = currentErrors.errorSchema;
|
|
4168
|
-
if (
|
|
4169
|
-
const
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4197
|
+
if (!mustValidate) {
|
|
4198
|
+
const formDataChangedFields = getFormDataChangedFields();
|
|
4199
|
+
if (formDataChangedFields.length > 0) {
|
|
4200
|
+
const newErrorSchema = formDataChangedFields.reduce((acc, path) => {
|
|
4201
|
+
const pathOfField = utils.toPath(path);
|
|
4202
|
+
for (let i = 1; i < pathOfField.length; i++) {
|
|
4203
|
+
utils.setByPath(acc, [...pathOfField.slice(0, i), utils.ERRORS_KEY], void 0, true);
|
|
4204
|
+
}
|
|
4205
|
+
return utils.setByPath(acc, pathOfField, void 0, true);
|
|
4206
|
+
}, {});
|
|
4207
|
+
schemaValidationErrorSchema = utils.mergeObjects(
|
|
4208
|
+
currentErrors.errorSchema,
|
|
4209
|
+
newErrorSchema,
|
|
4210
|
+
"preventDuplicates"
|
|
4211
|
+
);
|
|
4212
|
+
errorSchema = schemaValidationErrorSchema;
|
|
4213
|
+
}
|
|
4179
4214
|
}
|
|
4180
4215
|
const mergedErrors = _Form.mergeErrors({ errorSchema, errors }, props.extraErrors, state.customErrors);
|
|
4181
4216
|
errors = mergedErrors.errors;
|
|
@@ -4373,14 +4408,14 @@
|
|
|
4373
4408
|
let mergeBaseErrorSchema = schemaValidationErrorSchema;
|
|
4374
4409
|
const rootPathId = fieldPathId.path[0] || "";
|
|
4375
4410
|
const isRootPath = !path || path.length === 0 || path.length === 1 && path[0] === rootPathId;
|
|
4376
|
-
let formData = isRootPath ? newValue :
|
|
4411
|
+
let formData = isRootPath ? newValue : structuredClone(oldFormData);
|
|
4377
4412
|
const hasOnlyUndefinedValues = utils.isObject(formData) && Object.keys(formData).length > 0 && Object.values(formData).every((v) => v === void 0);
|
|
4378
4413
|
const wasPreviouslyNull = oldFormData === null || oldFormData === void 0;
|
|
4379
4414
|
const inputForDefaults = hasOnlyUndefinedValues && wasPreviouslyNull ? void 0 : formData;
|
|
4380
4415
|
if (utils.isObject(formData) || Array.isArray(formData)) {
|
|
4381
4416
|
let plainLeafWasCleared = false;
|
|
4382
4417
|
if (newValue === ADDITIONAL_PROPERTY_KEY_REMOVE) {
|
|
4383
|
-
|
|
4418
|
+
utils.unsetByPath(formData, path);
|
|
4384
4419
|
} else if (!isRootPath) {
|
|
4385
4420
|
let valueForPath = newValue;
|
|
4386
4421
|
if (newValue === void 0) {
|
|
@@ -4397,9 +4432,9 @@
|
|
|
4397
4432
|
}
|
|
4398
4433
|
}
|
|
4399
4434
|
if (plainLeafWasCleared) {
|
|
4400
|
-
|
|
4435
|
+
utils.setByPath(formData, path, void 0);
|
|
4401
4436
|
} else {
|
|
4402
|
-
|
|
4437
|
+
utils.setByPath(formData, path, valueForPath);
|
|
4403
4438
|
}
|
|
4404
4439
|
}
|
|
4405
4440
|
const shouldSanitize = retrievedSchema && !isRootPath && !utils.isObject(newValue) && !Array.isArray(newValue) && !disabled && !readonly;
|
|
@@ -4415,7 +4450,7 @@
|
|
|
4415
4450
|
formData = newState.formData;
|
|
4416
4451
|
retrievedSchema = newState.retrievedSchema;
|
|
4417
4452
|
if (plainLeafWasCleared && formData) {
|
|
4418
|
-
|
|
4453
|
+
utils.setByPath(formData, path, void 0);
|
|
4419
4454
|
}
|
|
4420
4455
|
}
|
|
4421
4456
|
const mustValidate = !noValidate && (liveValidate === true || liveValidate === "onChange");
|
|
@@ -4426,11 +4461,11 @@
|
|
|
4426
4461
|
state = { ...state, formData: newFormData };
|
|
4427
4462
|
}
|
|
4428
4463
|
if (newErrorSchema) {
|
|
4429
|
-
const oldValidationError = !isRootPath ?
|
|
4430
|
-
if (
|
|
4464
|
+
const oldValidationError = !isRootPath ? utils.getByPath(schemaValidationErrorSchema, path) : schemaValidationErrorSchema;
|
|
4465
|
+
if (oldValidationError && Object.keys(oldValidationError).length > 0) {
|
|
4431
4466
|
if (!isRootPath) {
|
|
4432
|
-
mergeBaseErrorSchema =
|
|
4433
|
-
|
|
4467
|
+
mergeBaseErrorSchema = structuredClone(schemaValidationErrorSchema);
|
|
4468
|
+
utils.setByPath(mergeBaseErrorSchema, path, newErrorSchema, true);
|
|
4434
4469
|
} else {
|
|
4435
4470
|
mergeBaseErrorSchema = newErrorSchema;
|
|
4436
4471
|
}
|
|
@@ -4439,15 +4474,15 @@
|
|
|
4439
4474
|
customErrors = new utils.ErrorSchemaBuilder();
|
|
4440
4475
|
}
|
|
4441
4476
|
if (isRootPath) {
|
|
4442
|
-
const pathErrors =
|
|
4477
|
+
const pathErrors = newErrorSchema[utils.ERRORS_KEY];
|
|
4443
4478
|
if (pathErrors) {
|
|
4444
4479
|
customErrors.setErrors(pathErrors);
|
|
4445
4480
|
}
|
|
4446
4481
|
} else {
|
|
4447
|
-
|
|
4482
|
+
utils.setByPath(customErrors.ErrorSchema, path, newErrorSchema, true);
|
|
4448
4483
|
}
|
|
4449
4484
|
}
|
|
4450
|
-
} else if (customErrors &&
|
|
4485
|
+
} else if (customErrors && utils.getByPath(customErrors.ErrorSchema, [...path, utils.ERRORS_KEY])) {
|
|
4451
4486
|
customErrors.clearErrors(path);
|
|
4452
4487
|
}
|
|
4453
4488
|
if (mustValidate && this.pendingChanges.length === 1) {
|
|
@@ -4553,8 +4588,8 @@
|
|
|
4553
4588
|
state = { formData: newFormData, ...liveValidation, customErrors };
|
|
4554
4589
|
}
|
|
4555
4590
|
const hasChanges = Object.keys(state).filter((key) => !key.startsWith("schemaValidation")).some((key) => {
|
|
4556
|
-
const oldData =
|
|
4557
|
-
const newData =
|
|
4591
|
+
const oldData = this.state[key];
|
|
4592
|
+
const newData = state[key];
|
|
4558
4593
|
return !utils.deepEquals(oldData, newData);
|
|
4559
4594
|
});
|
|
4560
4595
|
this.setState(state, () => {
|
|
@@ -4682,12 +4717,8 @@
|
|
|
4682
4717
|
focusOnError(error) {
|
|
4683
4718
|
const { idPrefix = "root", idSeparator = "_" } = this.props;
|
|
4684
4719
|
const { property } = error;
|
|
4685
|
-
const path =
|
|
4686
|
-
|
|
4687
|
-
path[0] = idPrefix;
|
|
4688
|
-
} else {
|
|
4689
|
-
path.unshift(idPrefix);
|
|
4690
|
-
}
|
|
4720
|
+
const path = utils.toPath(property ?? "");
|
|
4721
|
+
path.unshift(idPrefix);
|
|
4691
4722
|
const elementId = path.join(idSeparator);
|
|
4692
4723
|
let field = this.formElement.current.elements[elementId];
|
|
4693
4724
|
if (!field) {
|