@rjsf/core 6.6.1 → 6.6.2
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 +454 -373
- package/dist/index.cjs +416 -334
- package/dist/index.cjs.map +3 -3
- package/dist/index.esm.js +418 -415
- package/dist/index.esm.js.map +3 -3
- package/lib/components/Form.d.ts +14 -11
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +97 -62
- package/lib/components/RichDescription.d.ts +2 -2
- package/lib/components/RichDescription.d.ts.map +1 -1
- package/lib/components/RichDescription.js +1 -1
- package/lib/components/RichHelp.d.ts +2 -2
- package/lib/components/RichHelp.d.ts.map +1 -1
- package/lib/components/RichHelp.js +1 -1
- package/lib/components/SchemaExamples.d.ts +1 -1
- package/lib/components/SchemaExamples.d.ts.map +1 -1
- package/lib/components/SchemaExamples.js +1 -3
- package/lib/components/fields/ArrayField.d.ts +1 -1
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +87 -88
- package/lib/components/fields/BooleanField.d.ts +1 -1
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +2 -5
- package/lib/components/fields/FallbackField.d.ts +1 -1
- package/lib/components/fields/FallbackField.d.ts.map +1 -1
- package/lib/components/fields/FallbackField.js +2 -2
- package/lib/components/fields/LayoutGridField.d.ts +7 -9
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +5 -4
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.d.ts.map +1 -1
- package/lib/components/fields/LayoutHeaderField.js +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.d.ts +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/LayoutMultiSchemaField.js +4 -1
- package/lib/components/fields/MultiSchemaField.d.ts +9 -3
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +27 -9
- package/lib/components/fields/NullField.d.ts +1 -1
- package/lib/components/fields/NullField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.d.ts +1 -1
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +7 -9
- package/lib/components/fields/ObjectField.d.ts +1 -1
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +27 -25
- package/lib/components/fields/OptionalDataControlsField.d.ts +1 -1
- package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.d.ts +1 -1
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +7 -7
- package/lib/components/fields/StringField.d.ts +1 -1
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +2 -5
- package/lib/components/fields/index.d.ts +1 -1
- package/lib/components/fields/index.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +1 -1
- package/lib/components/templates/BaseInputTemplate.d.ts +1 -1
- package/lib/components/templates/BaseInputTemplate.d.ts.map +1 -1
- package/lib/components/templates/BaseInputTemplate.js +7 -6
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts +14 -7
- package/lib/components/templates/ButtonTemplates/IconButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js +14 -6
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/SubmitButton.d.ts.map +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts +1 -1
- package/lib/components/templates/ButtonTemplates/index.d.ts.map +1 -1
- package/lib/components/templates/DescriptionField.d.ts +1 -1
- package/lib/components/templates/DescriptionField.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.d.ts +1 -1
- package/lib/components/templates/ErrorList.d.ts.map +1 -1
- package/lib/components/templates/ErrorList.js +2 -4
- package/lib/components/templates/FallbackFieldTemplate.d.ts +1 -1
- package/lib/components/templates/FallbackFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.d.ts +1 -1
- package/lib/components/templates/FieldErrorTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.js +1 -3
- package/lib/components/templates/FieldHelpTemplate.d.ts +1 -1
- package/lib/components/templates/FieldHelpTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +1 -1
- package/lib/components/templates/FieldTemplate/Label.d.ts +2 -2
- package/lib/components/templates/FieldTemplate/Label.d.ts.map +1 -1
- package/lib/components/templates/GridTemplate.d.ts +1 -1
- package/lib/components/templates/GridTemplate.d.ts.map +1 -1
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +1 -1
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.d.ts +1 -1
- package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -1
- package/lib/components/templates/OptionalDataControlsTemplate.js +1 -1
- package/lib/components/templates/TitleField.d.ts +1 -1
- package/lib/components/templates/TitleField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.d.ts +1 -1
- package/lib/components/templates/UnsupportedField.d.ts.map +1 -1
- package/lib/components/templates/UnsupportedField.js +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.d.ts.map +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js +1 -1
- package/lib/components/templates/index.d.ts +1 -1
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/widgets/AltDateTimeWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts +1 -1
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -2
- package/lib/components/widgets/CheckboxWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts +1 -1
- package/lib/components/widgets/CheckboxesWidget.d.ts.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/components/widgets/ColorWidget.d.ts +1 -1
- package/lib/components/widgets/ColorWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.d.ts +1 -1
- package/lib/components/widgets/DateTimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/DateTimeWidget.js +2 -2
- package/lib/components/widgets/DateWidget.d.ts +1 -1
- package/lib/components/widgets/DateWidget.d.ts.map +1 -1
- package/lib/components/widgets/EmailWidget.d.ts +1 -1
- package/lib/components/widgets/EmailWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.d.ts +1 -1
- package/lib/components/widgets/FileWidget.d.ts.map +1 -1
- package/lib/components/widgets/FileWidget.js +6 -4
- package/lib/components/widgets/HiddenWidget.d.ts +1 -1
- package/lib/components/widgets/HiddenWidget.d.ts.map +1 -1
- package/lib/components/widgets/PasswordWidget.d.ts +1 -1
- package/lib/components/widgets/PasswordWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.d.ts +1 -1
- package/lib/components/widgets/RadioWidget.d.ts.map +1 -1
- package/lib/components/widgets/RadioWidget.js +2 -2
- package/lib/components/widgets/RangeWidget.d.ts +1 -1
- package/lib/components/widgets/RangeWidget.d.ts.map +1 -1
- 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 +15 -15
- package/lib/components/widgets/SelectWidget.d.ts +1 -1
- package/lib/components/widgets/SelectWidget.d.ts.map +1 -1
- package/lib/components/widgets/SelectWidget.js +4 -4
- package/lib/components/widgets/TextWidget.d.ts +1 -1
- package/lib/components/widgets/TextWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts +1 -1
- package/lib/components/widgets/TextareaWidget.d.ts.map +1 -1
- package/lib/components/widgets/TextareaWidget.js +2 -2
- package/lib/components/widgets/TimeWidget.d.ts +1 -1
- package/lib/components/widgets/TimeWidget.d.ts.map +1 -1
- package/lib/components/widgets/URLWidget.d.ts +1 -1
- package/lib/components/widgets/URLWidget.d.ts.map +1 -1
- package/lib/components/widgets/UpDownWidget.d.ts +1 -1
- package/lib/components/widgets/UpDownWidget.d.ts.map +1 -1
- package/lib/components/widgets/index.d.ts +1 -1
- package/lib/components/widgets/index.d.ts.map +1 -1
- package/lib/getDefaultRegistry.d.ts +1 -1
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +1 -1
- package/lib/getTestRegistry.d.ts +1 -1
- package/lib/getTestRegistry.d.ts.map +1 -1
- package/lib/getTestRegistry.js +1 -1
- package/lib/index.d.ts +10 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.d.ts +3 -3
- package/lib/withTheme.d.ts.map +1 -1
- package/lib/withTheme.js +6 -6
- package/package.json +5 -6
- package/src/components/Form.tsx +164 -97
- package/src/components/RichDescription.tsx +3 -10
- package/src/components/RichHelp.tsx +3 -10
- package/src/components/SchemaExamples.tsx +6 -4
- package/src/components/fields/ArrayField.tsx +122 -108
- package/src/components/fields/BooleanField.tsx +4 -9
- package/src/components/fields/FallbackField.tsx +4 -8
- package/src/components/fields/LayoutGridField.tsx +21 -19
- package/src/components/fields/LayoutHeaderField.tsx +2 -10
- package/src/components/fields/LayoutMultiSchemaField.tsx +15 -10
- package/src/components/fields/MultiSchemaField.tsx +29 -16
- package/src/components/fields/NullField.tsx +1 -1
- package/src/components/fields/NumberField.tsx +8 -10
- package/src/components/fields/ObjectField.tsx +48 -39
- package/src/components/fields/OptionalDataControlsField.tsx +6 -4
- package/src/components/fields/SchemaField.tsx +22 -19
- package/src/components/fields/StringField.tsx +4 -15
- package/src/components/fields/index.ts +1 -1
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +2 -7
- package/src/components/templates/ArrayFieldItemTemplate.tsx +3 -9
- package/src/components/templates/ArrayFieldTemplate.tsx +2 -9
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +2 -10
- package/src/components/templates/BaseInputTemplate.tsx +15 -19
- package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/IconButton.tsx +16 -7
- package/src/components/templates/ButtonTemplates/SubmitButton.tsx +2 -1
- package/src/components/templates/ButtonTemplates/index.ts +1 -1
- package/src/components/templates/DescriptionField.tsx +1 -1
- package/src/components/templates/ErrorList.tsx +8 -15
- package/src/components/templates/FallbackFieldTemplate.tsx +2 -1
- package/src/components/templates/FieldErrorTemplate.tsx +8 -8
- package/src/components/templates/FieldHelpTemplate.tsx +2 -1
- package/src/components/templates/FieldTemplate/FieldTemplate.tsx +2 -8
- package/src/components/templates/FieldTemplate/Label.tsx +2 -2
- package/src/components/templates/GridTemplate.tsx +1 -1
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +1 -1
- package/src/components/templates/ObjectFieldTemplate.tsx +2 -7
- package/src/components/templates/OptionalDataControlsTemplate.tsx +3 -2
- package/src/components/templates/TitleField.tsx +1 -1
- package/src/components/templates/UnsupportedField.tsx +3 -2
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +2 -9
- package/src/components/templates/index.ts +1 -1
- package/src/components/widgets/AltDateTimeWidget.tsx +1 -1
- package/src/components/widgets/AltDateWidget.tsx +7 -13
- package/src/components/widgets/CheckboxWidget.tsx +3 -5
- package/src/components/widgets/CheckboxesWidget.tsx +6 -8
- package/src/components/widgets/ColorWidget.tsx +2 -1
- package/src/components/widgets/DateTimeWidget.tsx +3 -10
- package/src/components/widgets/DateWidget.tsx +2 -1
- package/src/components/widgets/EmailWidget.tsx +2 -1
- package/src/components/widgets/FileWidget.tsx +9 -8
- package/src/components/widgets/HiddenWidget.tsx +1 -1
- package/src/components/widgets/PasswordWidget.tsx +2 -1
- package/src/components/widgets/RadioWidget.tsx +6 -8
- package/src/components/widgets/RangeWidget.tsx +1 -1
- package/src/components/widgets/RatingWidget.tsx +48 -47
- package/src/components/widgets/SelectWidget.tsx +12 -10
- package/src/components/widgets/TextWidget.tsx +2 -1
- package/src/components/widgets/TextareaWidget.tsx +7 -4
- package/src/components/widgets/TimeWidget.tsx +2 -1
- package/src/components/widgets/URLWidget.tsx +2 -1
- package/src/components/widgets/UpDownWidget.tsx +2 -1
- package/src/components/widgets/index.ts +1 -1
- package/src/getDefaultRegistry.ts +2 -9
- package/src/getTestRegistry.tsx +2 -7
- package/src/index.ts +10 -5
- package/src/withTheme.tsx +14 -9
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
|
+
import { examplesId } from '@rjsf/utils';
|
|
2
3
|
|
|
3
4
|
export interface SchemaExamplesProps<S extends StrictRJSFSchema = RJSFSchema> {
|
|
4
5
|
/** The id of the input element this datalist is for */
|
|
@@ -28,9 +29,10 @@ export default function SchemaExamples<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
28
29
|
? ([schemaDefault] as string[])
|
|
29
30
|
: [],
|
|
30
31
|
)
|
|
31
|
-
.map((example: any) =>
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
.map((example: any) => (
|
|
33
|
+
// oxlint-disable-next-line jsx-a11y/control-has-associated-label
|
|
34
|
+
<option key={String(example)} value={example} />
|
|
35
|
+
))}
|
|
34
36
|
</datalist>
|
|
35
37
|
);
|
|
36
38
|
}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import { MouseEvent
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
import { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import type {
|
|
4
|
+
ArrayFieldTemplateProps,
|
|
5
|
+
ErrorSchema,
|
|
6
|
+
FieldPathId,
|
|
7
|
+
FieldPathList,
|
|
8
|
+
FieldProps,
|
|
9
|
+
FormContextType,
|
|
10
|
+
Registry,
|
|
11
|
+
RJSFSchema,
|
|
12
|
+
StrictRJSFSchema,
|
|
13
|
+
UiSchema,
|
|
14
|
+
UIOptionsType,
|
|
15
|
+
} from '@rjsf/utils';
|
|
2
16
|
import {
|
|
3
17
|
allowAdditionalItems,
|
|
4
18
|
getTemplate,
|
|
@@ -14,18 +28,7 @@ import {
|
|
|
14
28
|
useDeepCompareMemo,
|
|
15
29
|
ITEMS_KEY,
|
|
16
30
|
ID_KEY,
|
|
17
|
-
ArrayFieldTemplateProps,
|
|
18
|
-
ErrorSchema,
|
|
19
|
-
FieldPathId,
|
|
20
|
-
FieldPathList,
|
|
21
|
-
FieldProps,
|
|
22
|
-
FormContextType,
|
|
23
|
-
Registry,
|
|
24
|
-
RJSFSchema,
|
|
25
|
-
StrictRJSFSchema,
|
|
26
31
|
TranslatableString,
|
|
27
|
-
UiSchema,
|
|
28
|
-
UIOptionsType,
|
|
29
32
|
} from '@rjsf/utils';
|
|
30
33
|
import cloneDeep from 'lodash/cloneDeep';
|
|
31
34
|
import isObject from 'lodash/isObject';
|
|
@@ -33,7 +36,10 @@ import set from 'lodash/set';
|
|
|
33
36
|
import uniqueId from 'lodash/uniqueId';
|
|
34
37
|
|
|
35
38
|
/** Type used to represent the keyed form data used in the state */
|
|
36
|
-
|
|
39
|
+
interface KeyedFormDataType<T> {
|
|
40
|
+
key: string;
|
|
41
|
+
item: T;
|
|
42
|
+
}
|
|
37
43
|
|
|
38
44
|
/** Used to generate a unique ID for an element in a row */
|
|
39
45
|
function generateRowId() {
|
|
@@ -48,12 +54,10 @@ function generateRowId() {
|
|
|
48
54
|
function generateKeyedFormData<T>(formData?: T[]): KeyedFormDataType<T>[] {
|
|
49
55
|
return !Array.isArray(formData)
|
|
50
56
|
? []
|
|
51
|
-
: formData.map((item) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
+
: formData.map((item) => ({
|
|
58
|
+
key: generateRowId(),
|
|
59
|
+
item,
|
|
60
|
+
}));
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
/** Converts `KeyedFormDataType` data into the inner `formData`
|
|
@@ -136,6 +140,7 @@ function computeItemUiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
136
140
|
// Only use the result if it's truthy
|
|
137
141
|
return result as UiSchema<T[], S, F>;
|
|
138
142
|
} catch (e) {
|
|
143
|
+
// oxlint-disable-next-line no-console
|
|
139
144
|
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
140
145
|
// Fall back to undefined to allow the field to still render
|
|
141
146
|
return undefined;
|
|
@@ -348,7 +353,7 @@ function ArrayAsFiles<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
348
353
|
/** Renders the individual array item using a `SchemaField` along with the additional properties that are needed to
|
|
349
354
|
* render the whole of the `ArrayFieldItemTemplate`.
|
|
350
355
|
*/
|
|
351
|
-
function
|
|
356
|
+
function ArrayFieldItemInner<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: {
|
|
352
357
|
itemKey: string;
|
|
353
358
|
index: number;
|
|
354
359
|
name: string;
|
|
@@ -364,10 +369,10 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
364
369
|
canRemove?: boolean;
|
|
365
370
|
canMoveUp: boolean;
|
|
366
371
|
canMoveDown: boolean;
|
|
367
|
-
|
|
372
|
+
rawItemSchema: S;
|
|
368
373
|
itemData: T[];
|
|
369
374
|
itemUiSchema: UiSchema<T[], S, F> | undefined;
|
|
370
|
-
|
|
375
|
+
parentFieldPathId: FieldPathId;
|
|
371
376
|
itemErrorSchema?: ErrorSchema<T[]>;
|
|
372
377
|
autofocus?: boolean;
|
|
373
378
|
onBlur: FieldProps<T[], S, F>['onBlur'];
|
|
@@ -394,10 +399,10 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
394
399
|
canRemove = true,
|
|
395
400
|
canMoveUp,
|
|
396
401
|
canMoveDown,
|
|
397
|
-
|
|
402
|
+
rawItemSchema,
|
|
398
403
|
itemData,
|
|
399
404
|
itemUiSchema,
|
|
400
|
-
|
|
405
|
+
parentFieldPathId,
|
|
401
406
|
itemErrorSchema,
|
|
402
407
|
autofocus,
|
|
403
408
|
onBlur,
|
|
@@ -415,8 +420,18 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
415
420
|
schemaUtils,
|
|
416
421
|
fields: { ArraySchemaField, SchemaField },
|
|
417
422
|
globalUiOptions,
|
|
423
|
+
globalFormOptions,
|
|
418
424
|
} = registry;
|
|
419
|
-
const
|
|
425
|
+
const itemSchema = useMemo(
|
|
426
|
+
() => schemaUtils.retrieveSchema(rawItemSchema, itemData),
|
|
427
|
+
[schemaUtils, rawItemSchema, itemData],
|
|
428
|
+
);
|
|
429
|
+
// parentFieldPathId is the same stable reference for all items; index is a stable number.
|
|
430
|
+
// useMemo avoids creating a new FieldPathId object on every render, letting React.memo bail out.
|
|
431
|
+
const fieldPathId = useMemo(
|
|
432
|
+
() => toFieldPathId(index, globalFormOptions, parentFieldPathId),
|
|
433
|
+
[index, globalFormOptions, parentFieldPathId],
|
|
434
|
+
);
|
|
420
435
|
const ItemSchemaField = ArraySchemaField || SchemaField;
|
|
421
436
|
const ArrayFieldItemTemplate = getTemplate<'ArrayFieldItemTemplate', T[], S, F>(
|
|
422
437
|
'ArrayFieldItemTemplate',
|
|
@@ -427,7 +442,7 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
427
442
|
const { description } = getUiOptions(itemUiSchema);
|
|
428
443
|
const hasDescription = !!description || !!itemSchema.description;
|
|
429
444
|
const { orderable = true, removable = true, copyable = false } = uiOptions;
|
|
430
|
-
const has:
|
|
445
|
+
const has: Record<string, boolean> = {
|
|
431
446
|
moveUp: orderable && canMoveUp,
|
|
432
447
|
moveDown: orderable && canMoveDown,
|
|
433
448
|
copy: copyable && canAdd,
|
|
@@ -499,7 +514,7 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
499
514
|
hasMoveUp: has.moveUp,
|
|
500
515
|
hasMoveDown: has.moveDown,
|
|
501
516
|
hasRemove: has.remove,
|
|
502
|
-
index
|
|
517
|
+
index,
|
|
503
518
|
totalItems,
|
|
504
519
|
onAddItem,
|
|
505
520
|
onCopyItem,
|
|
@@ -526,6 +541,7 @@ function ArrayFieldItem<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
|
|
|
526
541
|
};
|
|
527
542
|
return <ArrayFieldItemTemplate {...templateProps} />;
|
|
528
543
|
}
|
|
544
|
+
const ArrayFieldItem = memo(ArrayFieldItemInner) as typeof ArrayFieldItemInner;
|
|
529
545
|
|
|
530
546
|
/** The properties required by the stateless components that render the items using the `ArrayFieldItem` */
|
|
531
547
|
interface InternalArrayFieldProps<
|
|
@@ -575,15 +591,19 @@ function NormalArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
575
591
|
handleReorderItems,
|
|
576
592
|
} = props;
|
|
577
593
|
const fieldTitle = schema.title || title || name;
|
|
578
|
-
const { schemaUtils, fields, formContext,
|
|
594
|
+
const { schemaUtils, fields, formContext, globalUiOptions } = registry;
|
|
579
595
|
const { OptionalDataControlsField } = fields;
|
|
580
|
-
const uiOptions = getUiOptions<T[], S, F>(uiSchema, globalUiOptions);
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
const
|
|
596
|
+
const uiOptions = useMemo(() => getUiOptions<T[], S, F>(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
|
|
597
|
+
// Memoize schemaItems to avoid a new `{}` object identity on every render (which would bust retrieveSchema cache)
|
|
598
|
+
const schemaItems: S = useMemo(() => (isObject(schema.items) ? (schema.items as S) : ({} as S)), [schema.items]);
|
|
599
|
+
const itemsSchema: S = useMemo(() => schemaUtils.retrieveSchema(schemaItems), [schemaUtils, schemaItems]);
|
|
600
|
+
const formData = useMemo(() => keyedToPlainFormData<T>(keyedFormData), [keyedFormData]);
|
|
584
601
|
const renderOptionalField = shouldRenderOptionalField<T[], S, F>(registry, schema, required, uiSchema);
|
|
585
602
|
const hasFormData = isFormDataAvailable<T[]>(formDataFromProps);
|
|
586
|
-
const canAdd =
|
|
603
|
+
const canAdd = useMemo(
|
|
604
|
+
() => canAddItem<T, S, F>(registry, schema, formData, uiSchema) && (!renderOptionalField || hasFormData),
|
|
605
|
+
[registry, schema, formData, uiSchema, renderOptionalField, hasFormData],
|
|
606
|
+
);
|
|
587
607
|
const actualFormData = hasFormData ? keyedFormData : [];
|
|
588
608
|
const extraClass = renderOptionalField ? ' rjsf-optional-array-field' : '';
|
|
589
609
|
// All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
|
|
@@ -597,9 +617,7 @@ function NormalArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
597
617
|
const { key, item } = keyedItem;
|
|
598
618
|
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
599
619
|
const itemCast = item as unknown as T[];
|
|
600
|
-
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
601
620
|
const itemErrorSchema = errorSchema ? (errorSchema[index] as ErrorSchema<T[]>) : undefined;
|
|
602
|
-
const itemFieldPathId = toFieldPathId(index, globalFormOptions, childFieldPathId);
|
|
603
621
|
|
|
604
622
|
// Compute the item UI schema using the helper method
|
|
605
623
|
const itemUiSchema = computeItemUiSchema<T, S, F>(uiSchema, item, index, formContext);
|
|
@@ -619,8 +637,8 @@ function NormalArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
619
637
|
canAdd,
|
|
620
638
|
canMoveUp: index > 0,
|
|
621
639
|
canMoveDown: index < formData.length - 1,
|
|
622
|
-
|
|
623
|
-
|
|
640
|
+
rawItemSchema: schemaItems,
|
|
641
|
+
parentFieldPathId: childFieldPathId,
|
|
624
642
|
itemErrorSchema,
|
|
625
643
|
itemData: itemCast,
|
|
626
644
|
itemUiSchema,
|
|
@@ -687,24 +705,22 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
687
705
|
} = props;
|
|
688
706
|
let { formData: items = [] } = props;
|
|
689
707
|
const fieldTitle = schema.title || title || name;
|
|
690
|
-
const {
|
|
691
|
-
const uiOptions = getUiOptions<T[], S, F>(uiSchema, globalUiOptions);
|
|
708
|
+
const { fields, formContext, globalUiOptions } = registry;
|
|
709
|
+
const uiOptions = useMemo(() => getUiOptions<T[], S, F>(uiSchema, globalUiOptions), [uiSchema, globalUiOptions]);
|
|
692
710
|
const { OptionalDataControlsField } = fields;
|
|
693
711
|
const renderOptionalField = shouldRenderOptionalField<T[], S, F>(registry, schema, required, uiSchema);
|
|
694
712
|
const hasFormData = isFormDataAvailable<T[]>(formData);
|
|
695
|
-
const
|
|
696
|
-
|
|
697
|
-
|
|
713
|
+
const schemaItems: S[] = useMemo(
|
|
714
|
+
() => (isObject(schema.items) ? (schema.items as S[]) : ([] as S[])),
|
|
715
|
+
[schema.items],
|
|
698
716
|
);
|
|
699
|
-
const
|
|
700
|
-
? schemaUtils.retrieveSchema(schema.additionalItems as S, formData)
|
|
701
|
-
: null;
|
|
717
|
+
const hasAdditionalItems = isObject(schema.additionalItems);
|
|
702
718
|
// All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
|
|
703
719
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
704
720
|
|
|
705
|
-
if (items.length <
|
|
721
|
+
if (items.length < schemaItems.length) {
|
|
706
722
|
// to make sure at least all fixed items are generated
|
|
707
|
-
items = items.concat(new Array(
|
|
723
|
+
items = items.concat(new Array(schemaItems.length - items.length));
|
|
708
724
|
}
|
|
709
725
|
const actualFormData = hasFormData ? keyedFormData : [];
|
|
710
726
|
const extraClass = renderOptionalField ? ' rjsf-optional-array-field' : '';
|
|
@@ -715,7 +731,7 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
715
731
|
// These are the props passed into the render function
|
|
716
732
|
const canAdd =
|
|
717
733
|
canAddItem<T, S, F>(registry, schema, items, uiSchema) &&
|
|
718
|
-
|
|
734
|
+
hasAdditionalItems &&
|
|
719
735
|
(!renderOptionalField || hasFormData);
|
|
720
736
|
const arrayProps: ArrayFieldTemplateProps<T[], S, F> = {
|
|
721
737
|
canAdd,
|
|
@@ -727,25 +743,21 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
727
743
|
const { key, item } = keyedItem;
|
|
728
744
|
// While we are actually dealing with a single item of type T, the types require a T[], so cast
|
|
729
745
|
const itemCast = item as unknown as T[];
|
|
730
|
-
const additional = index >=
|
|
731
|
-
const
|
|
732
|
-
(additional && isObject(schema.additionalItems)
|
|
733
|
-
|
|
734
|
-
: itemSchemas[index]) || {};
|
|
735
|
-
const itemFieldPathId = toFieldPathId(index, globalFormOptions, childFieldPathId);
|
|
746
|
+
const additional = index >= schemaItems.length;
|
|
747
|
+
const rawItemSchema =
|
|
748
|
+
(additional && isObject(schema.additionalItems) ? (schema.additionalItems as S) : schemaItems[index]) ||
|
|
749
|
+
({} as S);
|
|
736
750
|
// Compute the item UI schema - handle both static and dynamic cases
|
|
737
751
|
let itemUiSchema: UiSchema<T[], S, F> | undefined;
|
|
738
752
|
if (additional) {
|
|
739
753
|
// For additional items, use additionalItems uiSchema
|
|
740
754
|
itemUiSchema = uiSchema.additionalItems as UiSchema<T[], S, F>;
|
|
741
|
-
} else {
|
|
755
|
+
} else if (Array.isArray(uiSchema.items)) {
|
|
742
756
|
// For fixed items, uiSchema.items can be an array, a function, or a single object
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
itemUiSchema = computeItemUiSchema<T, S, F>(uiSchema, item, index, formContext);
|
|
748
|
-
}
|
|
757
|
+
itemUiSchema = uiSchema.items[index] as UiSchema<T[], S, F>;
|
|
758
|
+
} else {
|
|
759
|
+
// Use the helper method for function or static object cases
|
|
760
|
+
itemUiSchema = computeItemUiSchema<T, S, F>(uiSchema, item, index, formContext);
|
|
749
761
|
}
|
|
750
762
|
const itemErrorSchema = errorSchema ? (errorSchema[index] as ErrorSchema<T[]>) : undefined;
|
|
751
763
|
|
|
@@ -763,12 +775,12 @@ function FixedArray<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
763
775
|
title: fieldTitle ? `${fieldTitle}-${index + 1}` : undefined,
|
|
764
776
|
canAdd,
|
|
765
777
|
canRemove: additional,
|
|
766
|
-
canMoveUp: index >=
|
|
778
|
+
canMoveUp: index >= schemaItems.length + 1,
|
|
767
779
|
canMoveDown: additional && index < items.length - 1,
|
|
768
|
-
|
|
780
|
+
rawItemSchema,
|
|
769
781
|
itemData: itemCast,
|
|
770
782
|
itemUiSchema,
|
|
771
|
-
|
|
783
|
+
parentFieldPathId: childFieldPathId,
|
|
772
784
|
itemErrorSchema,
|
|
773
785
|
autofocus: autofocus && index === 0,
|
|
774
786
|
onBlur,
|
|
@@ -807,12 +819,12 @@ interface KeyedFormDataState<T = any> {
|
|
|
807
819
|
}
|
|
808
820
|
|
|
809
821
|
/** Type used for the state of the `ArrayField` component */
|
|
810
|
-
|
|
822
|
+
interface ArrayFieldState<T> {
|
|
811
823
|
/** The hash of the last formData passed in */
|
|
812
824
|
formDataHash: string;
|
|
813
825
|
/** The keyed form data elements */
|
|
814
826
|
keyedFormData: KeyedFormDataType<T>[];
|
|
815
|
-
}
|
|
827
|
+
}
|
|
816
828
|
|
|
817
829
|
/** A custom hook that handles the updating of the keyedFormData from an external `formData` change as well as
|
|
818
830
|
* internally by the `ArrayField`. If there was an external `formData` change, then the `keyedFormData` is recomputed
|
|
@@ -846,8 +858,8 @@ function useKeyedFormData<T = any>(formData: T[] = []): KeyedFormDataState<T> {
|
|
|
846
858
|
|
|
847
859
|
const updateKeyedFormData = useCallback((newData: KeyedFormDataType<T>[]) => {
|
|
848
860
|
const plainFormData = keyedToPlainFormData(newData);
|
|
849
|
-
const
|
|
850
|
-
setState({ formDataHash:
|
|
861
|
+
const updatedHash = hashObject(plainFormData);
|
|
862
|
+
setState({ formDataHash: updatedHash, keyedFormData: newData });
|
|
851
863
|
return plainFormData;
|
|
852
864
|
}, []);
|
|
853
865
|
|
|
@@ -863,6 +875,12 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
863
875
|
const { schema, uiSchema, errorSchema, fieldPathId, registry, formData, onChange } = props;
|
|
864
876
|
const { globalFormOptions, schemaUtils, translateString } = registry;
|
|
865
877
|
const { keyedFormData, updateKeyedFormData } = useKeyedFormData<T>(formData);
|
|
878
|
+
// Refs keep the latest values accessible inside stable useCallback closures without being in the dep array,
|
|
879
|
+
// so the four mutation handlers don't get new references on every keyedFormData / errorSchema change.
|
|
880
|
+
const keyedFormDataRef = useRef(keyedFormData);
|
|
881
|
+
keyedFormDataRef.current = keyedFormData;
|
|
882
|
+
const errorSchemaRef = useRef(errorSchema);
|
|
883
|
+
errorSchemaRef.current = errorSchema;
|
|
866
884
|
// All the children will use childFieldPathId if present in the props, falling back to the fieldPathId
|
|
867
885
|
const childFieldPathId = props.childFieldPathId ?? fieldPathId;
|
|
868
886
|
|
|
@@ -880,14 +898,14 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
880
898
|
}
|
|
881
899
|
|
|
882
900
|
let newErrorSchema: ErrorSchema<T> | undefined;
|
|
883
|
-
if (
|
|
901
|
+
if (errorSchemaRef.current) {
|
|
884
902
|
newErrorSchema = {};
|
|
885
|
-
for (const idx
|
|
886
|
-
const i = parseInt(idx);
|
|
903
|
+
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
904
|
+
const i = parseInt(idx, 10);
|
|
887
905
|
if (index === undefined || i < index) {
|
|
888
|
-
set(newErrorSchema, [i],
|
|
906
|
+
set(newErrorSchema, [i], errorSchemaRef.current[i]);
|
|
889
907
|
} else if (i >= index) {
|
|
890
|
-
set(newErrorSchema, [i + 1],
|
|
908
|
+
set(newErrorSchema, [i + 1], errorSchemaRef.current[i]);
|
|
891
909
|
}
|
|
892
910
|
}
|
|
893
911
|
}
|
|
@@ -896,7 +914,7 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
896
914
|
key: generateRowId(),
|
|
897
915
|
item: getNewFormDataRow<T, S, F>(registry, schema),
|
|
898
916
|
};
|
|
899
|
-
const newKeyedFormData = [...
|
|
917
|
+
const newKeyedFormData = [...keyedFormDataRef.current];
|
|
900
918
|
if (index !== undefined) {
|
|
901
919
|
newKeyedFormData.splice(index, 0, newKeyedFormDataRow);
|
|
902
920
|
} else {
|
|
@@ -904,7 +922,7 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
904
922
|
}
|
|
905
923
|
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema as ErrorSchema<T[]>);
|
|
906
924
|
},
|
|
907
|
-
[
|
|
925
|
+
[registry, schema, onChange, updateKeyedFormData, childFieldPathId],
|
|
908
926
|
);
|
|
909
927
|
|
|
910
928
|
/** Callback handler for when the user clicks on the copy button on an existing array element. Clones the row of
|
|
@@ -920,23 +938,23 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
920
938
|
}
|
|
921
939
|
|
|
922
940
|
let newErrorSchema: ErrorSchema<T> | undefined;
|
|
923
|
-
if (
|
|
941
|
+
if (errorSchemaRef.current) {
|
|
924
942
|
newErrorSchema = {};
|
|
925
|
-
for (const idx
|
|
926
|
-
const i = parseInt(idx);
|
|
943
|
+
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
944
|
+
const i = parseInt(idx, 10);
|
|
927
945
|
if (i <= index) {
|
|
928
|
-
set(newErrorSchema, [i],
|
|
946
|
+
set(newErrorSchema, [i], errorSchemaRef.current[i]);
|
|
929
947
|
} else if (i > index) {
|
|
930
|
-
set(newErrorSchema, [i + 1],
|
|
948
|
+
set(newErrorSchema, [i + 1], errorSchemaRef.current[i]);
|
|
931
949
|
}
|
|
932
950
|
}
|
|
933
951
|
}
|
|
934
952
|
|
|
935
953
|
const newKeyedFormDataRow: KeyedFormDataType<T> = {
|
|
936
954
|
key: generateRowId(),
|
|
937
|
-
item: cloneDeep(
|
|
955
|
+
item: cloneDeep(keyedFormDataRef.current[index].item),
|
|
938
956
|
};
|
|
939
|
-
const newKeyedFormData = [...
|
|
957
|
+
const newKeyedFormData = [...keyedFormDataRef.current];
|
|
940
958
|
if (index !== undefined) {
|
|
941
959
|
newKeyedFormData.splice(index + 1, 0, newKeyedFormDataRow);
|
|
942
960
|
} else {
|
|
@@ -944,7 +962,7 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
944
962
|
}
|
|
945
963
|
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema as ErrorSchema<T[]>);
|
|
946
964
|
},
|
|
947
|
-
[
|
|
965
|
+
[onChange, updateKeyedFormData, childFieldPathId],
|
|
948
966
|
);
|
|
949
967
|
|
|
950
968
|
/** Callback handler for when the user clicks on the remove button on an existing array element. Removes the row of
|
|
@@ -960,21 +978,21 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
960
978
|
}
|
|
961
979
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
962
980
|
let newErrorSchema: ErrorSchema<T> | undefined;
|
|
963
|
-
if (
|
|
981
|
+
if (errorSchemaRef.current) {
|
|
964
982
|
newErrorSchema = {};
|
|
965
|
-
for (const idx
|
|
966
|
-
const i = parseInt(idx);
|
|
983
|
+
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
984
|
+
const i = parseInt(idx, 10);
|
|
967
985
|
if (i < index) {
|
|
968
|
-
set(newErrorSchema, [i],
|
|
986
|
+
set(newErrorSchema, [i], errorSchemaRef.current[i]);
|
|
969
987
|
} else if (i > index) {
|
|
970
|
-
set(newErrorSchema, [i - 1],
|
|
988
|
+
set(newErrorSchema, [i - 1], errorSchemaRef.current[i]);
|
|
971
989
|
}
|
|
972
990
|
}
|
|
973
991
|
}
|
|
974
|
-
const newKeyedFormData =
|
|
992
|
+
const newKeyedFormData = keyedFormDataRef.current.filter((_, i) => i !== index);
|
|
975
993
|
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema as ErrorSchema<T[]>);
|
|
976
994
|
},
|
|
977
|
-
[
|
|
995
|
+
[onChange, updateKeyedFormData, childFieldPathId],
|
|
978
996
|
);
|
|
979
997
|
|
|
980
998
|
/** Callback handler for when the user clicks on one of the move item buttons on an existing array element. Moves the
|
|
@@ -991,34 +1009,30 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
991
1009
|
event.currentTarget.blur();
|
|
992
1010
|
}
|
|
993
1011
|
let newErrorSchema: ErrorSchema<T> | undefined;
|
|
994
|
-
if (
|
|
1012
|
+
if (errorSchemaRef.current) {
|
|
995
1013
|
newErrorSchema = {};
|
|
996
|
-
for (const idx
|
|
997
|
-
const i = parseInt(idx);
|
|
998
|
-
if (i
|
|
999
|
-
set(newErrorSchema, [newIndex],
|
|
1000
|
-
} else if (i
|
|
1001
|
-
set(newErrorSchema, [index],
|
|
1014
|
+
for (const idx of Object.keys(errorSchemaRef.current)) {
|
|
1015
|
+
const i = parseInt(idx, 10);
|
|
1016
|
+
if (i === index) {
|
|
1017
|
+
set(newErrorSchema, [newIndex], errorSchemaRef.current[index]);
|
|
1018
|
+
} else if (i === newIndex) {
|
|
1019
|
+
set(newErrorSchema, [index], errorSchemaRef.current[newIndex]);
|
|
1002
1020
|
} else {
|
|
1003
|
-
set(newErrorSchema, [idx],
|
|
1021
|
+
set(newErrorSchema, [idx], errorSchemaRef.current[i]);
|
|
1004
1022
|
}
|
|
1005
1023
|
}
|
|
1006
1024
|
}
|
|
1007
1025
|
|
|
1008
1026
|
function reOrderArray() {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
_newKeyedFormData.splice(index, 1);
|
|
1014
|
-
_newKeyedFormData.splice(newIndex, 0, keyedFormData[index]);
|
|
1015
|
-
|
|
1016
|
-
return _newKeyedFormData;
|
|
1027
|
+
const newKeyedFormData = keyedFormDataRef.current.slice();
|
|
1028
|
+
newKeyedFormData.splice(index, 1);
|
|
1029
|
+
newKeyedFormData.splice(newIndex, 0, keyedFormDataRef.current[index]);
|
|
1030
|
+
return newKeyedFormData;
|
|
1017
1031
|
}
|
|
1018
1032
|
const newKeyedFormData = reOrderArray();
|
|
1019
1033
|
onChange(updateKeyedFormData(newKeyedFormData), childFieldPathId.path, newErrorSchema as ErrorSchema<T[]>);
|
|
1020
1034
|
},
|
|
1021
|
-
[
|
|
1035
|
+
[onChange, updateKeyedFormData, childFieldPathId],
|
|
1022
1036
|
);
|
|
1023
1037
|
|
|
1024
1038
|
/** Callback handler used to deal with changing the value of the data in the array at the `index`. Calls the
|
|
@@ -1054,7 +1068,7 @@ export default function ArrayField<T = any, S extends StrictRJSFSchema = RJSFSch
|
|
|
1054
1068
|
...props,
|
|
1055
1069
|
formData,
|
|
1056
1070
|
fieldPathId: childFieldPathId,
|
|
1057
|
-
onSelectChange
|
|
1071
|
+
onSelectChange,
|
|
1058
1072
|
};
|
|
1059
1073
|
const arrayProps: InternalArrayFieldProps<T, S, F> = {
|
|
1060
1074
|
...props,
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
getWidget,
|
|
4
|
-
getUiOptions,
|
|
5
|
-
optionsList,
|
|
2
|
+
import type {
|
|
6
3
|
FieldProps,
|
|
7
4
|
FormContextType,
|
|
8
5
|
EnumOptionsType,
|
|
9
6
|
ErrorSchema,
|
|
10
7
|
RJSFSchema,
|
|
11
8
|
StrictRJSFSchema,
|
|
12
|
-
TranslatableString,
|
|
13
9
|
} from '@rjsf/utils';
|
|
10
|
+
import { getWidget, getUiOptions, optionsList, TranslatableString } from '@rjsf/utils';
|
|
14
11
|
import isObject from 'lodash/isObject';
|
|
15
12
|
|
|
16
13
|
/** The `BooleanField` component is used to render a field in the schema is boolean. It constructs `enumOptions` for the
|
|
@@ -89,10 +86,8 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
const onWidgetChange = useCallback(
|
|
92
|
-
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) =>
|
|
93
|
-
|
|
94
|
-
return onChange(value, fieldPathId.path, errorSchema, id);
|
|
95
|
-
},
|
|
89
|
+
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) =>
|
|
90
|
+
onChange(value, fieldPathId.path, errorSchema, id),
|
|
96
91
|
[onChange, fieldPathId],
|
|
97
92
|
);
|
|
98
93
|
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
|
+
import type { FallbackFieldProps, FieldPathId, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
|
|
2
3
|
import {
|
|
3
|
-
FallbackFieldProps,
|
|
4
|
-
FieldPathId,
|
|
5
|
-
FormContextType,
|
|
6
4
|
getTemplate,
|
|
7
5
|
getUiOptions,
|
|
8
6
|
hashObject,
|
|
9
|
-
RJSFSchema,
|
|
10
|
-
StrictRJSFSchema,
|
|
11
7
|
toFieldPathId,
|
|
12
8
|
TranslatableString,
|
|
13
9
|
useDeepCompareMemo,
|
|
14
10
|
} from '@rjsf/utils';
|
|
15
|
-
import { JSONSchema7TypeName } from 'json-schema';
|
|
11
|
+
import type { JSONSchema7TypeName } from 'json-schema';
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
14
|
* Get the schema for the type selection component.
|
|
@@ -23,7 +19,7 @@ function getFallbackTypeSelectionSchema(title: string): RJSFSchema {
|
|
|
23
19
|
type: 'string',
|
|
24
20
|
enum: ['string', 'number', 'boolean', 'object', 'array'],
|
|
25
21
|
default: 'string',
|
|
26
|
-
title
|
|
22
|
+
title,
|
|
27
23
|
};
|
|
28
24
|
}
|
|
29
25
|
|
|
@@ -54,7 +50,7 @@ function castToNewType<T = any>(formData: T, newType: JSONSchema7TypeName): T {
|
|
|
54
50
|
return String(formData) as T;
|
|
55
51
|
case 'number': {
|
|
56
52
|
const castedNumber = Number(formData);
|
|
57
|
-
return (isNaN(castedNumber) ? 0 : castedNumber) as T;
|
|
53
|
+
return (Number.isNaN(castedNumber) ? 0 : castedNumber) as T;
|
|
58
54
|
}
|
|
59
55
|
case 'boolean':
|
|
60
56
|
return Boolean(formData) as T;
|