@rjsf/utils 6.0.0-beta.2 → 6.0.0-beta.20
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/{index.js → index.cjs} +241 -205
- package/dist/index.cjs.map +7 -0
- package/dist/utils.esm.js +240 -204
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +235 -200
- package/lib/canExpand.d.ts +1 -1
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +3 -0
- package/lib/constants.js.map +1 -1
- package/lib/createSchemaUtils.js +19 -14
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/enums.d.ts +3 -3
- package/lib/enums.js +3 -3
- package/lib/findSchemaDefinition.d.ts +7 -1
- package/lib/findSchemaDefinition.js +48 -6
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getTestIds.js +2 -2
- package/lib/getTestIds.js.map +1 -1
- package/lib/getUiOptions.js +4 -0
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/idGenerators.d.ts +15 -15
- package/lib/idGenerators.js +8 -8
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.js +14 -2
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findFieldInSchema.js +1 -1
- package/lib/schema/getDefaultFormState.d.ts +11 -2
- package/lib/schema/getDefaultFormState.js +59 -22
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.js +2 -2
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/index.d.ts +1 -2
- package/lib/schema/index.js +1 -2
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +1 -1
- package/lib/schema/retrieveSchema.js +6 -6
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/shallowEquals.d.ts +8 -0
- package/lib/shallowEquals.js +36 -0
- package/lib/shallowEquals.js.map +1 -0
- package/lib/shouldRender.d.ts +8 -2
- package/lib/shouldRender.js +17 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/toFieldPathId.d.ts +12 -0
- package/lib/toFieldPathId.js +19 -0
- package/lib/toFieldPathId.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +97 -66
- package/package.json +13 -14
- package/src/constants.ts +3 -0
- package/src/createSchemaUtils.ts +19 -25
- package/src/enums.ts +3 -3
- package/src/findSchemaDefinition.ts +55 -6
- package/src/getTestIds.ts +2 -2
- package/src/getUiOptions.ts +4 -0
- package/src/getWidget.tsx +3 -3
- package/src/idGenerators.ts +25 -25
- package/src/index.ts +6 -0
- package/src/mergeDefaultsWithFormData.ts +16 -2
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/getDefaultFormState.ts +76 -32
- package/src/schema/getDisplayLabel.ts +2 -2
- package/src/schema/index.ts +0 -2
- package/src/schema/retrieveSchema.ts +7 -5
- package/src/shallowEquals.ts +41 -0
- package/src/shouldRender.ts +27 -2
- package/src/toFieldPathId.ts +24 -0
- package/src/types.ts +107 -70
- package/dist/index.js.map +0 -7
- package/lib/schema/toIdSchema.d.ts +0 -14
- package/lib/schema/toIdSchema.js +0 -62
- package/lib/schema/toIdSchema.js.map +0 -1
- package/src/schema/toIdSchema.ts +0 -131
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Implements a shallow equals comparison that uses Object.is() for comparing values.
|
|
2
|
+
* This function compares objects by checking if all keys and their values are equal using Object.is().
|
|
3
|
+
*
|
|
4
|
+
* @param a - The first element to compare
|
|
5
|
+
* @param b - The second element to compare
|
|
6
|
+
* @returns - True if the `a` and `b` are shallow equal, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export default function shallowEquals(a: any, b: any): boolean {
|
|
9
|
+
// If they're the same reference, they're equal
|
|
10
|
+
if (Object.is(a, b)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// If either is null or undefined, they're not equal (since we know they're not the same reference)
|
|
15
|
+
if (a == null || b == null) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// If they're not objects, they're not equal (since Object.is already checked)
|
|
20
|
+
if (typeof a !== 'object' || typeof b !== 'object') {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const keysA = Object.keys(a);
|
|
25
|
+
const keysB = Object.keys(b);
|
|
26
|
+
|
|
27
|
+
// Different number of keys means not equal
|
|
28
|
+
if (keysA.length !== keysB.length) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Check if all keys and values are equal
|
|
33
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
34
|
+
const key = keysA[i];
|
|
35
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
package/src/shouldRender.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import deepEquals from './deepEquals';
|
|
4
|
+
import shallowEquals from './shallowEquals';
|
|
5
|
+
|
|
6
|
+
/** The supported component update strategies */
|
|
7
|
+
export type ComponentUpdateStrategy = 'customDeep' | 'shallow' | 'always';
|
|
4
8
|
|
|
5
9
|
/** Determines whether the given `component` should be rerendered by comparing its current set of props and state
|
|
6
|
-
* against the next set.
|
|
10
|
+
* against the next set. The comparison strategy can be controlled via the `updateStrategy` parameter.
|
|
7
11
|
*
|
|
8
12
|
* @param component - A React component being checked
|
|
9
13
|
* @param nextProps - The next set of props against which to check
|
|
10
14
|
* @param nextState - The next set of state against which to check
|
|
15
|
+
* @param updateStrategy - The strategy to use for comparison:
|
|
16
|
+
* - 'customDeep': Uses RJSF's custom deep equality checks (default)
|
|
17
|
+
* - 'shallow': Uses shallow comparison of props and state
|
|
18
|
+
* - 'always': Always returns true (React's default behavior)
|
|
11
19
|
* @returns - True if the component should be re-rendered, false otherwise
|
|
12
20
|
*/
|
|
13
|
-
export default function shouldRender(
|
|
21
|
+
export default function shouldRender(
|
|
22
|
+
component: React.Component,
|
|
23
|
+
nextProps: any,
|
|
24
|
+
nextState: any,
|
|
25
|
+
updateStrategy: ComponentUpdateStrategy = 'customDeep',
|
|
26
|
+
) {
|
|
27
|
+
if (updateStrategy === 'always') {
|
|
28
|
+
// Use React's default behavior: always update if state or props change (no shouldComponentUpdate optimization)
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (updateStrategy === 'shallow') {
|
|
33
|
+
// Use shallow comparison for props and state
|
|
34
|
+
const { props, state } = component;
|
|
35
|
+
return !shallowEquals(props, nextProps) || !shallowEquals(state, nextState);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Use custom deep equality checks (default 'customDeep' strategy)
|
|
14
39
|
const { props, state } = component;
|
|
15
40
|
return !deepEquals(props, nextProps) || !deepEquals(state, nextState);
|
|
16
41
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ID_KEY } from './constants';
|
|
2
|
+
import { FieldPathId, FieldPathList, GlobalFormOptions } from './types';
|
|
3
|
+
|
|
4
|
+
/** Constructs the `FieldPathId` for `fieldPath`. If `parentPathId` is provided, the `fieldPath` is appended to the end
|
|
5
|
+
* of the parent path. Then the `ID_KEY` of the resulting `FieldPathId` is constructed from the `idPrefix` and
|
|
6
|
+
* `idSeparator` contained within the `globalFormOptions`. If `fieldPath` is passed as an empty string, it will simply
|
|
7
|
+
* generate the path from the `parentPath` (if provided) and the `idPrefix` and `idSeparator`
|
|
8
|
+
*
|
|
9
|
+
* @param fieldPath - The property name or array index of the current field element
|
|
10
|
+
* @param globalFormOptions - The `GlobalFormOptions` used to get the `idPrefix` and `idSeparator`
|
|
11
|
+
* @param [parentPath] - The optional `FieldPathId` or `FieldPathList` of the parent element for this field element
|
|
12
|
+
* @returns - The `FieldPathId` for the given `fieldPath` and the optional `parentPathId`
|
|
13
|
+
*/
|
|
14
|
+
export default function toFieldPathId(
|
|
15
|
+
fieldPath: string | number,
|
|
16
|
+
globalFormOptions: GlobalFormOptions,
|
|
17
|
+
parentPath?: FieldPathId | FieldPathList,
|
|
18
|
+
): FieldPathId {
|
|
19
|
+
const basePath = Array.isArray(parentPath) ? parentPath : parentPath?.path;
|
|
20
|
+
const childPath = fieldPath === '' ? [] : [fieldPath];
|
|
21
|
+
const path = basePath ? basePath.concat(...childPath) : childPath;
|
|
22
|
+
const id = [globalFormOptions.idPrefix, ...path].join(globalFormOptions.idSeparator);
|
|
23
|
+
return { path, [ID_KEY]: id };
|
|
24
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -158,20 +158,25 @@ export type InputPropsType = Omit<RangeSpecType, 'step'> & {
|
|
|
158
158
|
accept?: HTMLInputElement['accept'];
|
|
159
159
|
};
|
|
160
160
|
|
|
161
|
-
/**
|
|
162
|
-
|
|
161
|
+
/** The list of path elements that represents where in the schema a field is located. When the item in the field list is
|
|
162
|
+
* a string, then it represents the name of the property within an object. When it is a number, then it represents the
|
|
163
|
+
* index within an array.
|
|
164
|
+
*
|
|
165
|
+
* For example:
|
|
166
|
+
* `[]` represents the root object of the schema
|
|
167
|
+
* `['foo', 'bar']` represents the `bar` element contained within the `foo` element of the schema
|
|
168
|
+
* `['baz', 1]` represents the second element in the list `baz` of the schema
|
|
169
|
+
*/
|
|
170
|
+
export type FieldPathList = (string | number)[];
|
|
171
|
+
|
|
172
|
+
/** Type describing an id and path used for a field */
|
|
173
|
+
export type FieldPathId = {
|
|
163
174
|
/** The id for a field */
|
|
164
175
|
$id: string;
|
|
176
|
+
/** The path for a field */
|
|
177
|
+
path: FieldPathList;
|
|
165
178
|
};
|
|
166
179
|
|
|
167
|
-
/** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
|
|
168
|
-
export type IdSchema<T = any> = T extends GenericObjectType
|
|
169
|
-
? FieldId & {
|
|
170
|
-
/** The set of ids for fields in the recursive object structure */
|
|
171
|
-
[key in keyof T]?: IdSchema<T[key]>;
|
|
172
|
-
}
|
|
173
|
-
: FieldId;
|
|
174
|
-
|
|
175
180
|
/** Type describing a name used for a field in the `PathSchema` */
|
|
176
181
|
export type FieldPath = {
|
|
177
182
|
/** The name of a field */
|
|
@@ -212,6 +217,8 @@ export type RJSFValidationError = {
|
|
|
212
217
|
schemaPath?: string;
|
|
213
218
|
/** Full error name, for example ".name is a required property" */
|
|
214
219
|
stack: string;
|
|
220
|
+
/** The title property for the failing field*/
|
|
221
|
+
title?: string;
|
|
215
222
|
};
|
|
216
223
|
|
|
217
224
|
/** The type that describes an error in a field */
|
|
@@ -261,8 +268,6 @@ export type ErrorListProps<
|
|
|
261
268
|
errorSchema: ErrorSchema<T>;
|
|
262
269
|
/** An array of the errors */
|
|
263
270
|
errors: RJSFValidationError[];
|
|
264
|
-
/** The `formContext` object that was passed to `Form` */
|
|
265
|
-
formContext?: F;
|
|
266
271
|
};
|
|
267
272
|
|
|
268
273
|
/** The properties that are passed to an `FieldErrorTemplate` implementation */
|
|
@@ -275,8 +280,8 @@ export type FieldErrorProps<
|
|
|
275
280
|
errorSchema?: ErrorSchema<T>;
|
|
276
281
|
/** An array of the errors */
|
|
277
282
|
errors?: Array<string | ReactElement>;
|
|
278
|
-
/** The
|
|
279
|
-
|
|
283
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
284
|
+
fieldPathId: FieldPathId;
|
|
280
285
|
};
|
|
281
286
|
|
|
282
287
|
/** The properties that are passed to an `FieldHelpTemplate` implementation */
|
|
@@ -287,8 +292,8 @@ export type FieldHelpProps<
|
|
|
287
292
|
> = RJSFBaseProps<T, S, F> & {
|
|
288
293
|
/** The help information to be rendered */
|
|
289
294
|
help?: string | ReactElement;
|
|
290
|
-
/** The
|
|
291
|
-
|
|
295
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
296
|
+
fieldPathId: FieldPathId;
|
|
292
297
|
/** Flag indicating whether there are errors associated with this field */
|
|
293
298
|
hasErrors?: boolean;
|
|
294
299
|
};
|
|
@@ -341,6 +346,8 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
341
346
|
FieldTemplate: ComponentType<FieldTemplateProps<T, S, F>>;
|
|
342
347
|
/** The template to use to render a Grid element */
|
|
343
348
|
GridTemplate: ComponentType<GridTemplateProps>;
|
|
349
|
+
/** The template to use while rendering a multi-schema field (i.e. anyOf, oneOf) */
|
|
350
|
+
MultiSchemaFieldTemplate: ComponentType<MultiSchemaFieldTemplateProps<T, S, F>>;
|
|
344
351
|
/** The template to use while rendering an object */
|
|
345
352
|
ObjectFieldTemplate: ComponentType<ObjectFieldTemplateProps<T, S, F>>;
|
|
346
353
|
/** The template to use for rendering the title of a field */
|
|
@@ -370,9 +377,10 @@ export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
370
377
|
};
|
|
371
378
|
|
|
372
379
|
/** The set of UiSchema options that can be set globally and used as fallbacks at an individual template, field or
|
|
373
|
-
* widget level when no field-level value of the option is provided.
|
|
380
|
+
* widget level when no field-level value of the option is provided. Extends GenericObjectType to support allowing users
|
|
381
|
+
* to provide any value they need for their customizations.
|
|
374
382
|
*/
|
|
375
|
-
export type GlobalUISchemaOptions = {
|
|
383
|
+
export type GlobalUISchemaOptions = GenericObjectType & {
|
|
376
384
|
/** Flag, if set to `false`, new items cannot be added to array fields, unless overridden (defaults to true) */
|
|
377
385
|
addable?: boolean;
|
|
378
386
|
/** Flag, if set to `true`, array items can be copied (defaults to false) */
|
|
@@ -392,6 +400,22 @@ export type GlobalUISchemaOptions = {
|
|
|
392
400
|
enableMarkdownInDescription?: boolean;
|
|
393
401
|
};
|
|
394
402
|
|
|
403
|
+
/** The set of options from the `Form` that will be available on the `Registry` for use in everywhere the `registry` is
|
|
404
|
+
* available.
|
|
405
|
+
*/
|
|
406
|
+
export type GlobalFormOptions = {
|
|
407
|
+
/** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
|
|
408
|
+
* Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
|
|
409
|
+
*/
|
|
410
|
+
readonly idPrefix: string;
|
|
411
|
+
/** To avoid using a path separator that is present in field names, it is possible to change the separator used for
|
|
412
|
+
* ids; Default is `_`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
|
|
413
|
+
*/
|
|
414
|
+
readonly idSeparator: string;
|
|
415
|
+
/** The component update strategy used by the Form and its fields for performance optimization */
|
|
416
|
+
readonly experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
|
|
417
|
+
};
|
|
418
|
+
|
|
395
419
|
/** The object containing the registered core, theme and custom fields and widgets as well as the root schema, form
|
|
396
420
|
* context, schema utils and templates.
|
|
397
421
|
*/
|
|
@@ -400,7 +424,7 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
400
424
|
* registered fields
|
|
401
425
|
*/
|
|
402
426
|
fields: RegistryFieldsType<T, S, F>;
|
|
403
|
-
/** The set of templates used by the `Form`. Includes templates from `core`, theme-specific
|
|
427
|
+
/** The set of templates used by the `Form`. Includes templates from `core`, theme-specific templates and any custom
|
|
404
428
|
* registered templates
|
|
405
429
|
*/
|
|
406
430
|
templates: TemplatesType<T, S, F>;
|
|
@@ -418,29 +442,31 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
|
|
|
418
442
|
schemaUtils: SchemaUtilsType<T, S>;
|
|
419
443
|
/** The string translation function to use when displaying any of the RJSF strings in templates, fields or widgets */
|
|
420
444
|
translateString: (stringKey: TranslatableString, params?: string[]) => string;
|
|
445
|
+
/** The global Form Options that are available for all templates, fields and widgets to access */
|
|
446
|
+
readonly globalFormOptions: GlobalFormOptions;
|
|
421
447
|
/** The optional global UI Options that are available for all templates, fields and widgets to access */
|
|
422
448
|
globalUiOptions?: GlobalUISchemaOptions;
|
|
423
449
|
}
|
|
424
450
|
|
|
425
|
-
/** The properties that are passed to a Field implementation */
|
|
451
|
+
/** The properties that are passed to a `Field` implementation */
|
|
426
452
|
export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
|
|
427
453
|
extends GenericObjectType,
|
|
428
454
|
RJSFBaseProps<T, S, F>,
|
|
429
455
|
Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
|
|
430
|
-
/** The
|
|
431
|
-
|
|
456
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
457
|
+
fieldPathId: FieldPathId;
|
|
432
458
|
/** The data for this field */
|
|
433
459
|
formData?: T;
|
|
434
460
|
/** The tree of errors for this field and its children */
|
|
435
461
|
errorSchema?: ErrorSchema<T>;
|
|
436
|
-
/** The field change event handler; called with the updated
|
|
437
|
-
|
|
462
|
+
/** The field change event handler; called with the updated field value, the change path for the value
|
|
463
|
+
* (defaults to an empty array), an optional ErrorSchema and the optional id of the field being changed
|
|
464
|
+
*/
|
|
465
|
+
onChange: (newValue: T | undefined, path: FieldPathList, es?: ErrorSchema<T>, id?: string) => void;
|
|
438
466
|
/** The input blur event handler; call it with the field id and value */
|
|
439
467
|
onBlur: (id: string, value: any) => void;
|
|
440
468
|
/** The input focus event handler; call it with the field id and value */
|
|
441
469
|
onFocus: (id: string, value: any) => void;
|
|
442
|
-
/** The `formContext` object that you passed to `Form` */
|
|
443
|
-
formContext?: F;
|
|
444
470
|
/** A boolean value stating if the field should autofocus */
|
|
445
471
|
autofocus?: boolean;
|
|
446
472
|
/** A boolean value stating if the field is disabled */
|
|
@@ -453,14 +479,6 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
453
479
|
required?: boolean;
|
|
454
480
|
/** The unique name of the field, usually derived from the name of the property in the JSONSchema */
|
|
455
481
|
name: string;
|
|
456
|
-
/** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
|
|
457
|
-
* Default is `root`
|
|
458
|
-
*/
|
|
459
|
-
idPrefix?: string;
|
|
460
|
-
/** To avoid using a path separator that is present in field names, it is possible to change the separator used for
|
|
461
|
-
* ids (Default is `_`)
|
|
462
|
-
*/
|
|
463
|
-
idSeparator?: string;
|
|
464
482
|
/** An array of strings listing all generated error messages from encountered errors for this field */
|
|
465
483
|
rawErrors?: string[];
|
|
466
484
|
}
|
|
@@ -468,9 +486,12 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
468
486
|
/** The definition of a React-based Field component */
|
|
469
487
|
export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = ComponentType<
|
|
470
488
|
FieldProps<T, S, F>
|
|
471
|
-
|
|
489
|
+
> & {
|
|
490
|
+
/** The optional TEST_IDS block that some fields contain, exported for testing purposes */
|
|
491
|
+
TEST_IDS?: TestIdShape;
|
|
492
|
+
};
|
|
472
493
|
|
|
473
|
-
/** The properties that are passed to a FieldTemplate implementation */
|
|
494
|
+
/** The properties that are passed to a `FieldTemplate` implementation */
|
|
474
495
|
export type FieldTemplateProps<
|
|
475
496
|
T = any,
|
|
476
497
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -516,8 +537,6 @@ export type FieldTemplateProps<
|
|
|
516
537
|
* you don't want to clutter the UI
|
|
517
538
|
*/
|
|
518
539
|
displayLabel?: boolean;
|
|
519
|
-
/** The `formContext` object that was passed to `Form` */
|
|
520
|
-
formContext?: F;
|
|
521
540
|
/** The formData for this field */
|
|
522
541
|
formData?: T;
|
|
523
542
|
/** The value change event handler; Can be called with a new value to change the value for this field */
|
|
@@ -534,8 +553,8 @@ export type UnsupportedFieldProps<
|
|
|
534
553
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
535
554
|
F extends FormContextType = any,
|
|
536
555
|
> = RJSFBaseProps<T, S, F> & {
|
|
537
|
-
/** The
|
|
538
|
-
|
|
556
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
557
|
+
fieldPathId: FieldPathId;
|
|
539
558
|
/** The reason why the schema field has an unsupported type */
|
|
540
559
|
reason: string;
|
|
541
560
|
};
|
|
@@ -574,8 +593,8 @@ export type ArrayFieldTitleProps<
|
|
|
574
593
|
> = Omit<TitleFieldProps<T, S, F>, 'id' | 'title'> & {
|
|
575
594
|
/** The title for the field being rendered */
|
|
576
595
|
title?: string;
|
|
577
|
-
/** The
|
|
578
|
-
|
|
596
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
597
|
+
fieldPathId: FieldPathId;
|
|
579
598
|
};
|
|
580
599
|
|
|
581
600
|
/** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
|
|
@@ -586,8 +605,8 @@ export type ArrayFieldDescriptionProps<
|
|
|
586
605
|
> = Omit<DescriptionFieldProps<T, S, F>, 'id' | 'description'> & {
|
|
587
606
|
/** The description of the field being rendered */
|
|
588
607
|
description?: string | ReactElement;
|
|
589
|
-
/**
|
|
590
|
-
|
|
608
|
+
/** An object containing the id and path for this field */
|
|
609
|
+
fieldPathId: FieldPathId;
|
|
591
610
|
};
|
|
592
611
|
|
|
593
612
|
/** The properties of the buttons to render for each element in the ArrayFieldTemplateProps.items array */
|
|
@@ -596,8 +615,8 @@ export type ArrayFieldItemButtonsTemplateType<
|
|
|
596
615
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
597
616
|
F extends FormContextType = any,
|
|
598
617
|
> = RJSFBaseProps<T, S, F> & {
|
|
599
|
-
/** The
|
|
600
|
-
|
|
618
|
+
/** The FieldPathId of the item for which buttons are being rendered */
|
|
619
|
+
fieldPathId: FieldPathId;
|
|
601
620
|
/** The className string */
|
|
602
621
|
className?: string;
|
|
603
622
|
/** Any optional style attributes */
|
|
@@ -665,7 +684,7 @@ export type ArrayFieldTemplateItemType<
|
|
|
665
684
|
F extends FormContextType = any,
|
|
666
685
|
> = ArrayFieldItemTemplateType<T, S, F>;
|
|
667
686
|
|
|
668
|
-
/** The properties that are passed to an ArrayFieldTemplate implementation */
|
|
687
|
+
/** The properties that are passed to an `ArrayFieldTemplate` implementation */
|
|
669
688
|
export type ArrayFieldTemplateProps<
|
|
670
689
|
T = any,
|
|
671
690
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
@@ -677,8 +696,8 @@ export type ArrayFieldTemplateProps<
|
|
|
677
696
|
className?: string;
|
|
678
697
|
/** A boolean value stating if the array is disabled */
|
|
679
698
|
disabled?: boolean;
|
|
680
|
-
/**
|
|
681
|
-
|
|
699
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
700
|
+
fieldPathId: FieldPathId;
|
|
682
701
|
/** An array of objects representing the items in the array */
|
|
683
702
|
items: ArrayFieldItemTemplateType<T, S, F>[];
|
|
684
703
|
/** A function that adds a new item to the array */
|
|
@@ -691,8 +710,6 @@ export type ArrayFieldTemplateProps<
|
|
|
691
710
|
hideError?: boolean;
|
|
692
711
|
/** A string value containing the title for the array */
|
|
693
712
|
title: string;
|
|
694
|
-
/** The `formContext` object that was passed to Form */
|
|
695
|
-
formContext?: F;
|
|
696
713
|
/** The formData for this array */
|
|
697
714
|
formData?: T;
|
|
698
715
|
/** The tree of errors for this field and its children */
|
|
@@ -737,14 +754,12 @@ export type ObjectFieldTemplateProps<
|
|
|
737
754
|
required?: boolean;
|
|
738
755
|
/** A boolean value stating if the field is hiding its errors */
|
|
739
756
|
hideError?: boolean;
|
|
740
|
-
/**
|
|
741
|
-
|
|
757
|
+
/** The FieldPathId of the field in the hierarchy */
|
|
758
|
+
fieldPathId: FieldPathId;
|
|
742
759
|
/** The optional validation errors in the form of an `ErrorSchema` */
|
|
743
760
|
errorSchema?: ErrorSchema<T>;
|
|
744
761
|
/** The form data for the object */
|
|
745
762
|
formData?: T;
|
|
746
|
-
/** The `formContext` object that was passed to Form */
|
|
747
|
-
formContext?: F;
|
|
748
763
|
};
|
|
749
764
|
|
|
750
765
|
/** The properties that are passed to a WrapIfAdditionalTemplate implementation */
|
|
@@ -773,11 +788,23 @@ export type WrapIfAdditionalTemplateProps<
|
|
|
773
788
|
| 'registry'
|
|
774
789
|
>;
|
|
775
790
|
|
|
776
|
-
/** The properties that are passed to a
|
|
791
|
+
/** The properties that are passed to a MultiSchemaFieldTemplate implementation */
|
|
792
|
+
export interface MultiSchemaFieldTemplateProps<
|
|
793
|
+
T = any,
|
|
794
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
795
|
+
F extends FormContextType = any,
|
|
796
|
+
> extends RJSFBaseProps<T, S, F> {
|
|
797
|
+
/** The rendered widget used to select a schema option */
|
|
798
|
+
selector: ReactNode;
|
|
799
|
+
/** The rendered SchemaField for the selected schema option */
|
|
800
|
+
optionSchemaField: ReactNode;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** The properties that are passed to a `Widget` implementation */
|
|
777
804
|
export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
|
|
778
805
|
extends GenericObjectType,
|
|
779
806
|
RJSFBaseProps<T, S, F>,
|
|
780
|
-
Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus'>> {
|
|
807
|
+
Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
|
|
781
808
|
/** The generated id for this widget, used to provide unique `name`s and `id`s for the HTML field elements rendered by
|
|
782
809
|
* widgets
|
|
783
810
|
*/
|
|
@@ -807,8 +834,6 @@ export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
807
834
|
/** The enum options list for a type that supports them */
|
|
808
835
|
enumOptions?: EnumOptionsType<S>[];
|
|
809
836
|
};
|
|
810
|
-
/** The `formContext` object that you passed to `Form` */
|
|
811
|
-
formContext?: F;
|
|
812
837
|
/** The input blur event handler; call it with the widget id and value */
|
|
813
838
|
onBlur: (id: string, value: any) => void;
|
|
814
839
|
/** The value change event handler; call it with the new value every time it changes */
|
|
@@ -985,6 +1010,13 @@ export type UIOptionsType<
|
|
|
985
1010
|
[key: string]: boolean | number | string | object | any[] | null | undefined;
|
|
986
1011
|
};
|
|
987
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* A utility type that extracts the element type from an array type.
|
|
1015
|
+
* If the type is not an array, it returns the type itself as a safe fallback.
|
|
1016
|
+
* Handles both standard arrays and readonly arrays.
|
|
1017
|
+
*/
|
|
1018
|
+
export type ArrayElement<A> = A extends readonly (infer E)[] ? E : A;
|
|
1019
|
+
|
|
988
1020
|
/** Type describing the well-known properties of the `UiSchema` while also supporting all user defined properties,
|
|
989
1021
|
* starting with `ui:`.
|
|
990
1022
|
*/
|
|
@@ -998,7 +1030,10 @@ export type UiSchema<
|
|
|
998
1030
|
* Registry for use everywhere.
|
|
999
1031
|
*/
|
|
1000
1032
|
'ui:globalOptions'?: GlobalUISchemaOptions;
|
|
1001
|
-
/** Allows the form to generate a unique prefix for the `Form`'s root prefix
|
|
1033
|
+
/** Allows the form to generate a unique prefix for the `Form`'s root prefix
|
|
1034
|
+
*
|
|
1035
|
+
* @deprecated - use `Form.idPrefix` instead, will be removed in a future major version
|
|
1036
|
+
*/
|
|
1002
1037
|
'ui:rootFieldId'?: string;
|
|
1003
1038
|
/** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
|
|
1004
1039
|
* `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
|
|
@@ -1010,6 +1045,13 @@ export type UiSchema<
|
|
|
1010
1045
|
'ui:fieldReplacesAnyOrOneOf'?: boolean;
|
|
1011
1046
|
/** An object that contains all the potential UI options in a single object */
|
|
1012
1047
|
'ui:options'?: UIOptionsType<T, S, F>;
|
|
1048
|
+
/** The uiSchema for items in an array. Can be an object for a uniform uiSchema across all items (current behavior),
|
|
1049
|
+
* or a function that returns a dynamic uiSchema based on the item's data and index.
|
|
1050
|
+
* When using a function, it receives the item data, index, and optionally the form context as parameters.
|
|
1051
|
+
*/
|
|
1052
|
+
items?:
|
|
1053
|
+
| UiSchema<ArrayElement<T>, S, F>
|
|
1054
|
+
| ((itemData: ArrayElement<T>, index: number, formContext?: F) => UiSchema<ArrayElement<T>, S, F>);
|
|
1013
1055
|
};
|
|
1014
1056
|
|
|
1015
1057
|
/** A `CustomValidator` function takes in a `formData`, `errors` and `uiSchema` objects and returns the given `errors`
|
|
@@ -1096,6 +1138,11 @@ export interface FoundFieldType<S extends StrictRJSFSchema = RJSFSchema> {
|
|
|
1096
1138
|
* set of APIs to the `@rjsf/core` components and the various themes as well.
|
|
1097
1139
|
*/
|
|
1098
1140
|
export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
1141
|
+
/** Returns the `rootSchema` in the `SchemaUtilsType`
|
|
1142
|
+
*
|
|
1143
|
+
* @returns - The rootSchema
|
|
1144
|
+
*/
|
|
1145
|
+
getRootSchema(): S;
|
|
1099
1146
|
/** Returns the `ValidatorType` in the `SchemaUtilsType`
|
|
1100
1147
|
*
|
|
1101
1148
|
* @returns - The `ValidatorType`
|
|
@@ -1243,16 +1290,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
|
|
|
1243
1290
|
* to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
|
|
1244
1291
|
*/
|
|
1245
1292
|
sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
|
|
1246
|
-
/** Generates an `IdSchema` object for the `schema`, recursively
|
|
1247
|
-
*
|
|
1248
|
-
* @param schema - The schema for which the display label flag is desired
|
|
1249
|
-
* @param [id] - The base id for the schema
|
|
1250
|
-
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
1251
|
-
* @param [idPrefix='root'] - The prefix to use for the id
|
|
1252
|
-
* @param [idSeparator='_'] - The separator to use for the path segments in the id
|
|
1253
|
-
* @returns - The `IdSchema` object for the `schema`
|
|
1254
|
-
*/
|
|
1255
|
-
toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
|
|
1256
1293
|
/** Generates an `PathSchema` object for the `schema`, recursively
|
|
1257
1294
|
*
|
|
1258
1295
|
* @param schema - The schema for which the display label flag is desired
|