@rjsf/utils 6.0.0-beta.19 → 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/lib/types.d.ts CHANGED
@@ -133,15 +133,23 @@ export type InputPropsType = Omit<RangeSpecType, 'step'> & {
133
133
  /** Specifies a filter for what file types the user can upload. */
134
134
  accept?: HTMLInputElement['accept'];
135
135
  };
136
- /** Type describing an id used for a field in the `IdSchema` */
137
- export type FieldId = {
136
+ /** The list of path elements that represents where in the schema a field is located. When the item in the field list is
137
+ * a string, then it represents the name of the property within an object. When it is a number, then it represents the
138
+ * index within an array.
139
+ *
140
+ * For example:
141
+ * `[]` represents the root object of the schema
142
+ * `['foo', 'bar']` represents the `bar` element contained within the `foo` element of the schema
143
+ * `['baz', 1]` represents the second element in the list `baz` of the schema
144
+ */
145
+ export type FieldPathList = (string | number)[];
146
+ /** Type describing an id and path used for a field */
147
+ export type FieldPathId = {
138
148
  /** The id for a field */
139
149
  $id: string;
150
+ /** The path for a field */
151
+ path: FieldPathList;
140
152
  };
141
- /** Type describing a recursive structure of `FieldId`s for an object with a non-empty set of keys */
142
- export type IdSchema<T = any> = T extends GenericObjectType ? FieldId & {
143
- [key in keyof T]?: IdSchema<T[key]>;
144
- } : FieldId;
145
153
  /** Type describing a name used for a field in the `PathSchema` */
146
154
  export type FieldPath = {
147
155
  /** The name of a field */
@@ -219,15 +227,15 @@ export type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
219
227
  errorSchema?: ErrorSchema<T>;
220
228
  /** An array of the errors */
221
229
  errors?: Array<string | ReactElement>;
222
- /** The tree of unique ids for every child field */
223
- idSchema: IdSchema<T>;
230
+ /** The FieldPathId of the field in the hierarchy */
231
+ fieldPathId: FieldPathId;
224
232
  };
225
233
  /** The properties that are passed to an `FieldHelpTemplate` implementation */
226
234
  export type FieldHelpProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
227
235
  /** The help information to be rendered */
228
236
  help?: string | ReactElement;
229
- /** The tree of unique ids for every child field */
230
- idSchema: IdSchema<T>;
237
+ /** The FieldPathId of the field in the hierarchy */
238
+ fieldPathId: FieldPathId;
231
239
  /** Flag indicating whether there are errors associated with this field */
232
240
  hasErrors?: boolean;
233
241
  };
@@ -335,13 +343,13 @@ export type GlobalUISchemaOptions = GenericObjectType & {
335
343
  */
336
344
  export type GlobalFormOptions = {
337
345
  /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
338
- * Default is `root`. This prop is passed to the `toIdSchema()` function within the RJSF field implementations.
346
+ * Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
339
347
  */
340
- readonly idPrefix?: string;
348
+ readonly idPrefix: string;
341
349
  /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
342
- * ids; Default is `_`. This prop is passed to the `toIdSchema()` function within the RJSF field implementations.
350
+ * ids; Default is `_`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
343
351
  */
344
- readonly idSeparator?: string;
352
+ readonly idSeparator: string;
345
353
  /** The component update strategy used by the Form and its fields for performance optimization */
346
354
  readonly experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
347
355
  };
@@ -378,16 +386,16 @@ export interface Registry<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
378
386
  }
379
387
  /** The properties that are passed to a `Field` implementation */
380
388
  export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> extends GenericObjectType, RJSFBaseProps<T, S, F>, Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
381
- /** The tree of unique ids for every child field */
382
- idSchema: IdSchema<T>;
389
+ /** The FieldPathId of the field in the hierarchy */
390
+ fieldPathId: FieldPathId;
383
391
  /** The data for this field */
384
392
  formData?: T;
385
393
  /** The tree of errors for this field and its children */
386
394
  errorSchema?: ErrorSchema<T>;
387
- /** The field change event handler; called with the updated field value, the optional change path for the value
395
+ /** The field change event handler; called with the updated field value, the change path for the value
388
396
  * (defaults to an empty array), an optional ErrorSchema and the optional id of the field being changed
389
397
  */
390
- onChange: (newValue: T | undefined, path?: (number | string)[], es?: ErrorSchema<T>, id?: string) => void;
398
+ onChange: (newValue: T | undefined, path: FieldPathList, es?: ErrorSchema<T>, id?: string) => void;
391
399
  /** The input blur event handler; call it with the field id and value */
392
400
  onBlur: (id: string, value: any) => void;
393
401
  /** The input focus event handler; call it with the field id and value */
@@ -465,8 +473,8 @@ export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema,
465
473
  };
466
474
  /** The properties that are passed to the `UnsupportedFieldTemplate` implementation */
467
475
  export type UnsupportedFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
468
- /** The tree of unique ids for every child field */
469
- idSchema?: IdSchema<T>;
476
+ /** The FieldPathId of the field in the hierarchy */
477
+ fieldPathId: FieldPathId;
470
478
  /** The reason why the schema field has an unsupported type */
471
479
  reason: string;
472
480
  };
@@ -490,20 +498,20 @@ export type DescriptionFieldProps<T = any, S extends StrictRJSFSchema = RJSFSche
490
498
  export type ArrayFieldTitleProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<TitleFieldProps<T, S, F>, 'id' | 'title'> & {
491
499
  /** The title for the field being rendered */
492
500
  title?: string;
493
- /** The idSchema of the field in the hierarchy */
494
- idSchema: IdSchema<T>;
501
+ /** The FieldPathId of the field in the hierarchy */
502
+ fieldPathId: FieldPathId;
495
503
  };
496
504
  /** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
497
505
  export type ArrayFieldDescriptionProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = Omit<DescriptionFieldProps<T, S, F>, 'id' | 'description'> & {
498
506
  /** The description of the field being rendered */
499
507
  description?: string | ReactElement;
500
- /** The idSchema of the field in the hierarchy */
501
- idSchema: IdSchema<T>;
508
+ /** An object containing the id and path for this field */
509
+ fieldPathId: FieldPathId;
502
510
  };
503
511
  /** The properties of the buttons to render for each element in the ArrayFieldTemplateProps.items array */
504
512
  export type ArrayFieldItemButtonsTemplateType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = RJSFBaseProps<T, S, F> & {
505
- /** The idSchema of the item for which buttons are being rendered */
506
- idSchema: IdSchema<T>;
513
+ /** The FieldPathId of the item for which buttons are being rendered */
514
+ fieldPathId: FieldPathId;
507
515
  /** The className string */
508
516
  className?: string;
509
517
  /** Any optional style attributes */
@@ -568,8 +576,8 @@ export type ArrayFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSc
568
576
  className?: string;
569
577
  /** A boolean value stating if the array is disabled */
570
578
  disabled?: boolean;
571
- /** An object containing the id for this object & ids for its properties */
572
- idSchema: IdSchema<T>;
579
+ /** The FieldPathId of the field in the hierarchy */
580
+ fieldPathId: FieldPathId;
573
581
  /** An array of objects representing the items in the array */
574
582
  items: ArrayFieldItemTemplateType<T, S, F>[];
575
583
  /** A function that adds a new item to the array */
@@ -620,8 +628,8 @@ export type ObjectFieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFS
620
628
  required?: boolean;
621
629
  /** A boolean value stating if the field is hiding its errors */
622
630
  hideError?: boolean;
623
- /** An object containing the id for this object & ids for its properties */
624
- idSchema: IdSchema<T>;
631
+ /** The FieldPathId of the field in the hierarchy */
632
+ fieldPathId: FieldPathId;
625
633
  /** The optional validation errors in the form of an `ErrorSchema` */
626
634
  errorSchema?: ErrorSchema<T>;
627
635
  /** The form data for the object */
@@ -816,7 +824,10 @@ export type UiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
816
824
  * Registry for use everywhere.
817
825
  */
818
826
  'ui:globalOptions'?: GlobalUISchemaOptions;
819
- /** Allows the form to generate a unique prefix for the `Form`'s root prefix */
827
+ /** Allows the form to generate a unique prefix for the `Form`'s root prefix
828
+ *
829
+ * @deprecated - use `Form.idPrefix` instead, will be removed in a future major version
830
+ */
820
831
  'ui:rootFieldId'?: string;
821
832
  /** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
822
833
  * `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
@@ -1041,16 +1052,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1041
1052
  * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1042
1053
  */
1043
1054
  sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
1044
- /** Generates an `IdSchema` object for the `schema`, recursively
1045
- *
1046
- * @param schema - The schema for which the display label flag is desired
1047
- * @param [id] - The base id for the schema
1048
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1049
- * @param [idPrefix='root'] - The prefix to use for the id
1050
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
1051
- * @returns - The `IdSchema` object for the `schema`
1052
- */
1053
- toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1054
1055
  /** Generates an `PathSchema` object for the `schema`, recursively
1055
1056
  *
1056
1057
  * @param schema - The schema for which the display label flag is desired
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjsf/utils",
3
- "version": "6.0.0-beta.19",
3
+ "version": "6.0.0-beta.20",
4
4
  "main": "dist/index.js",
5
5
  "module": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
package/src/constants.ts CHANGED
@@ -26,6 +26,8 @@ export const REQUIRED_KEY = 'required';
26
26
  export const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
27
27
  export const REF_KEY = '$ref';
28
28
  export const SCHEMA_KEY = '$schema';
29
+ export const DEFAULT_ID_PREFIX = 'root';
30
+ export const DEFAULT_ID_SEPARATOR = '_';
29
31
  /** The path of the discriminator value returned by the schema endpoint.
30
32
  * The discriminator is the value in a `oneOf` that determines which option is selected.
31
33
  */
@@ -5,7 +5,6 @@ import {
5
5
  FormContextType,
6
6
  FoundFieldType,
7
7
  GlobalUISchemaOptions,
8
- IdSchema,
9
8
  PathSchema,
10
9
  RJSFSchema,
11
10
  SchemaUtilsType,
@@ -26,7 +25,6 @@ import {
26
25
  isSelect,
27
26
  retrieveSchema,
28
27
  sanitizeDataForNewSchema,
29
- toIdSchema,
30
28
  toPathSchema,
31
29
  } from './schema';
32
30
  import { makeAllReferencesAbsolute } from './findSchemaDefinition';
@@ -337,28 +335,6 @@ class SchemaUtils<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
337
335
  );
338
336
  }
339
337
 
340
- /** Generates an `IdSchema` object for the `schema`, recursively
341
- *
342
- * @param schema - The schema for which the display label flag is desired
343
- * @param [id] - The base id for the schema
344
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
345
- * @param [idPrefix='root'] - The prefix to use for the id
346
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
347
- * @returns - The `IdSchema` object for the `schema`
348
- */
349
- toIdSchema(schema: S, id?: string | null, formData?: T, idPrefix = 'root', idSeparator = '_'): IdSchema<T> {
350
- return toIdSchema<T, S, F>(
351
- this.validator,
352
- schema,
353
- id,
354
- this.rootSchema,
355
- formData,
356
- idPrefix,
357
- idSeparator,
358
- this.experimental_customMergeAllOf,
359
- );
360
- }
361
-
362
338
  /** Generates an `PathSchema` object for the `schema`, recursively
363
339
  *
364
340
  * @param schema - The schema for which the display label flag is desired
package/src/enums.ts CHANGED
@@ -63,7 +63,7 @@ export enum TranslatableString {
63
63
  InvalidObjectField = 'Invalid "%1" object field configuration: _%2_.',
64
64
  /** Unsupported field schema, used by UnsupportedField */
65
65
  UnsupportedField = 'Unsupported field schema.',
66
- /** Unsupported field schema, where %1 will be replaced by the idSchema.$id as provided by UnsupportedField.
66
+ /** Unsupported field schema, where %1 will be replaced by the FieldPathId.$id as provided by UnsupportedField.
67
67
  * NOTE: Use markdown notation rather than html tags.
68
68
  */
69
69
  UnsupportedFieldWithId = 'Unsupported field schema for field `%1`.',
@@ -71,8 +71,8 @@ export enum TranslatableString {
71
71
  * NOTE: Use markdown notation rather than html tags.
72
72
  */
73
73
  UnsupportedFieldWithReason = 'Unsupported field schema: _%1_.',
74
- /** Unsupported field schema, where %1 and %2 will be replaced by the idSchema.$id and reason strings, respectively,
75
- * as provided by UnsupportedField.
74
+ /** Unsupported field schema, where %1 and %2 will be replaced by the FieldPathId.$id and reason strings,
75
+ * respectively, as provided by UnsupportedField.
76
76
  * NOTE: Use markdown notation rather than html tags.
77
77
  */
78
78
  UnsupportedFieldWithIdAndReason = 'Unsupported field schema for field `%1`: _%2_.',
@@ -1,73 +1,73 @@
1
1
  import isString from 'lodash/isString';
2
2
 
3
- import { IdSchema } from './types';
3
+ import { FieldPathId } from './types';
4
4
  import { ID_KEY } from './constants';
5
5
 
6
6
  /** Generates a consistent `id` pattern for a given `id` and a `suffix`
7
7
  *
8
- * @param id - Either simple string id or an IdSchema from which to extract it
8
+ * @param id - Either simple string id or an FieldPathId from which to extract it
9
9
  * @param suffix - The suffix to append to the id
10
10
  */
11
- function idGenerator<T = any>(id: IdSchema<T> | string, suffix: string) {
11
+ function idGenerator(id: FieldPathId | string, suffix: string) {
12
12
  const theId = isString(id) ? id : id[ID_KEY];
13
13
  return `${theId}__${suffix}`;
14
14
  }
15
15
  /** Return a consistent `id` for the field description element
16
16
  *
17
- * @param id - Either simple string id or an IdSchema from which to extract it
17
+ * @param id - Either simple string id or an FieldPathId from which to extract it
18
18
  * @returns - The consistent id for the field description element from the given `id`
19
19
  */
20
- export function descriptionId<T = any>(id: IdSchema<T> | string) {
21
- return idGenerator<T>(id, 'description');
20
+ export function descriptionId(id: FieldPathId | string) {
21
+ return idGenerator(id, 'description');
22
22
  }
23
23
 
24
24
  /** Return a consistent `id` for the field error element
25
25
  *
26
- * @param id - Either simple string id or an IdSchema from which to extract it
26
+ * @param id - Either simple string id or an FieldPathId from which to extract it
27
27
  * @returns - The consistent id for the field error element from the given `id`
28
28
  */
29
- export function errorId<T = any>(id: IdSchema<T> | string) {
30
- return idGenerator<T>(id, 'error');
29
+ export function errorId(id: FieldPathId | string) {
30
+ return idGenerator(id, 'error');
31
31
  }
32
32
 
33
33
  /** Return a consistent `id` for the field examples element
34
34
  *
35
- * @param id - Either simple string id or an IdSchema from which to extract it
35
+ * @param id - Either simple string id or an FieldPathId from which to extract it
36
36
  * @returns - The consistent id for the field examples element from the given `id`
37
37
  */
38
- export function examplesId<T = any>(id: IdSchema<T> | string) {
39
- return idGenerator<T>(id, 'examples');
38
+ export function examplesId(id: FieldPathId | string) {
39
+ return idGenerator(id, 'examples');
40
40
  }
41
41
 
42
42
  /** Return a consistent `id` for the field help element
43
43
  *
44
- * @param id - Either simple string id or an IdSchema from which to extract it
44
+ * @param id - Either simple string id or an FieldPathId from which to extract it
45
45
  * @returns - The consistent id for the field help element from the given `id`
46
46
  */
47
- export function helpId<T = any>(id: IdSchema<T> | string) {
48
- return idGenerator<T>(id, 'help');
47
+ export function helpId(id: FieldPathId | string) {
48
+ return idGenerator(id, 'help');
49
49
  }
50
50
 
51
51
  /** Return a consistent `id` for the field title element
52
52
  *
53
- * @param id - Either simple string id or an IdSchema from which to extract it
53
+ * @param id - Either simple string id or an FieldPathId from which to extract it
54
54
  * @returns - The consistent id for the field title element from the given `id`
55
55
  */
56
- export function titleId<T = any>(id: IdSchema<T> | string) {
57
- return idGenerator<T>(id, 'title');
56
+ export function titleId(id: FieldPathId | string) {
57
+ return idGenerator(id, 'title');
58
58
  }
59
59
 
60
60
  /** Return a list of element ids that contain additional information about the field that can be used to as the aria
61
61
  * description of the field. This is correctly omitting `titleId` which would be "labeling" rather than "describing" the
62
62
  * element.
63
63
  *
64
- * @param id - Either simple string id or an IdSchema from which to extract it
64
+ * @param id - Either simple string id or an FieldPathId from which to extract it
65
65
  * @param [includeExamples=false] - Optional flag, if true, will add the `examplesId` into the list
66
66
  * @returns - The string containing the list of ids for use in an `aria-describedBy` attribute
67
67
  */
68
- export function ariaDescribedByIds<T = any>(id: IdSchema<T> | string, includeExamples = false) {
69
- const examples = includeExamples ? ` ${examplesId<T>(id)}` : '';
70
- return `${errorId<T>(id)} ${descriptionId<T>(id)} ${helpId<T>(id)}${examples}`;
68
+ export function ariaDescribedByIds(id: FieldPathId | string, includeExamples = false) {
69
+ const examples = includeExamples ? ` ${examplesId(id)}` : '';
70
+ return `${errorId(id)} ${descriptionId(id)} ${helpId(id)}${examples}`;
71
71
  }
72
72
 
73
73
  /** Return a consistent `id` for the `optionIndex`s of a `Radio` or `Checkboxes` widget
@@ -82,10 +82,10 @@ export function optionId(id: string, optionIndex: number) {
82
82
 
83
83
  /** Return a consistent `id` for the `btn` button element
84
84
  *
85
- * @param id - Either simple string id or an IdSchema from which to extract it
85
+ * @param id - Either simple string id or an FieldPathId from which to extract it
86
86
  * @param btn - The button type for which to generate the id
87
87
  * @returns - The consistent id for the button from the given `id` and `btn` type
88
88
  */
89
- export function buttonId<T = any>(id: IdSchema<T> | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove') {
90
- return idGenerator<T>(id, btn);
89
+ export function buttonId(id: FieldPathId | string, btn: 'add' | 'copy' | 'moveDown' | 'moveUp' | 'remove') {
90
+ return idGenerator(id, btn);
91
91
  }
package/src/index.ts CHANGED
@@ -59,6 +59,7 @@ import toConstant from './toConstant';
59
59
  import toDateString from './toDateString';
60
60
  import toErrorList from './toErrorList';
61
61
  import toErrorSchema from './toErrorSchema';
62
+ import toFieldPathId from './toFieldPathId';
62
63
  import unwrapErrorHandler from './unwrapErrorHandler';
63
64
  import utcToLocal from './utcToLocal';
64
65
  import validationDataMerge from './validationDataMerge';
@@ -139,6 +140,7 @@ export {
139
140
  toDateString,
140
141
  toErrorList,
141
142
  toErrorSchema,
143
+ toFieldPathId,
142
144
  unwrapErrorHandler,
143
145
  utcToLocal,
144
146
  validationDataMerge,
@@ -10,7 +10,6 @@ import isMultiSelect from './isMultiSelect';
10
10
  import isSelect from './isSelect';
11
11
  import retrieveSchema from './retrieveSchema';
12
12
  import sanitizeDataForNewSchema from './sanitizeDataForNewSchema';
13
- import toIdSchema from './toIdSchema';
14
13
  import toPathSchema from './toPathSchema';
15
14
 
16
15
  export {
@@ -26,6 +25,5 @@ export {
26
25
  isSelect,
27
26
  retrieveSchema,
28
27
  sanitizeDataForNewSchema,
29
- toIdSchema,
30
28
  toPathSchema,
31
29
  };
@@ -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
- /** Type describing an id used for a field in the `IdSchema` */
162
- export type FieldId = {
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 */
@@ -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 tree of unique ids for every child field */
279
- idSchema: IdSchema<T>;
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 tree of unique ids for every child field */
291
- idSchema: IdSchema<T>;
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
  };
@@ -400,13 +405,13 @@ export type GlobalUISchemaOptions = GenericObjectType & {
400
405
  */
401
406
  export type GlobalFormOptions = {
402
407
  /** To avoid collisions with existing ids in the DOM, it is possible to change the prefix used for ids;
403
- * Default is `root`. This prop is passed to the `toIdSchema()` function within the RJSF field implementations.
408
+ * Default is `root`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
404
409
  */
405
- readonly idPrefix?: string;
410
+ readonly idPrefix: string;
406
411
  /** To avoid using a path separator that is present in field names, it is possible to change the separator used for
407
- * ids; Default is `_`. This prop is passed to the `toIdSchema()` function within the RJSF field implementations.
412
+ * ids; Default is `_`. This prop is passed to the `toFilePathId()` function within the RJSF field implementations.
408
413
  */
409
- readonly idSeparator?: string;
414
+ readonly idSeparator: string;
410
415
  /** The component update strategy used by the Form and its fields for performance optimization */
411
416
  readonly experimental_componentUpdateStrategy?: 'customDeep' | 'shallow' | 'always';
412
417
  };
@@ -448,16 +453,16 @@ export interface FieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F
448
453
  extends GenericObjectType,
449
454
  RJSFBaseProps<T, S, F>,
450
455
  Pick<HTMLAttributes<HTMLElement>, Exclude<keyof HTMLAttributes<HTMLElement>, 'onBlur' | 'onFocus' | 'onChange'>> {
451
- /** The tree of unique ids for every child field */
452
- idSchema: IdSchema<T>;
456
+ /** The FieldPathId of the field in the hierarchy */
457
+ fieldPathId: FieldPathId;
453
458
  /** The data for this field */
454
459
  formData?: T;
455
460
  /** The tree of errors for this field and its children */
456
461
  errorSchema?: ErrorSchema<T>;
457
- /** The field change event handler; called with the updated field value, the optional change path for the value
462
+ /** The field change event handler; called with the updated field value, the change path for the value
458
463
  * (defaults to an empty array), an optional ErrorSchema and the optional id of the field being changed
459
464
  */
460
- onChange: (newValue: T | undefined, path?: (number | string)[], es?: ErrorSchema<T>, id?: string) => void;
465
+ onChange: (newValue: T | undefined, path: FieldPathList, es?: ErrorSchema<T>, id?: string) => void;
461
466
  /** The input blur event handler; call it with the field id and value */
462
467
  onBlur: (id: string, value: any) => void;
463
468
  /** The input focus event handler; call it with the field id and value */
@@ -548,8 +553,8 @@ export type UnsupportedFieldProps<
548
553
  S extends StrictRJSFSchema = RJSFSchema,
549
554
  F extends FormContextType = any,
550
555
  > = RJSFBaseProps<T, S, F> & {
551
- /** The tree of unique ids for every child field */
552
- idSchema?: IdSchema<T>;
556
+ /** The FieldPathId of the field in the hierarchy */
557
+ fieldPathId: FieldPathId;
553
558
  /** The reason why the schema field has an unsupported type */
554
559
  reason: string;
555
560
  };
@@ -588,8 +593,8 @@ export type ArrayFieldTitleProps<
588
593
  > = Omit<TitleFieldProps<T, S, F>, 'id' | 'title'> & {
589
594
  /** The title for the field being rendered */
590
595
  title?: string;
591
- /** The idSchema of the field in the hierarchy */
592
- idSchema: IdSchema<T>;
596
+ /** The FieldPathId of the field in the hierarchy */
597
+ fieldPathId: FieldPathId;
593
598
  };
594
599
 
595
600
  /** The properties that are passed to a `ArrayFieldDescriptionTemplate` implementation */
@@ -600,8 +605,8 @@ export type ArrayFieldDescriptionProps<
600
605
  > = Omit<DescriptionFieldProps<T, S, F>, 'id' | 'description'> & {
601
606
  /** The description of the field being rendered */
602
607
  description?: string | ReactElement;
603
- /** The idSchema of the field in the hierarchy */
604
- idSchema: IdSchema<T>;
608
+ /** An object containing the id and path for this field */
609
+ fieldPathId: FieldPathId;
605
610
  };
606
611
 
607
612
  /** The properties of the buttons to render for each element in the ArrayFieldTemplateProps.items array */
@@ -610,8 +615,8 @@ export type ArrayFieldItemButtonsTemplateType<
610
615
  S extends StrictRJSFSchema = RJSFSchema,
611
616
  F extends FormContextType = any,
612
617
  > = RJSFBaseProps<T, S, F> & {
613
- /** The idSchema of the item for which buttons are being rendered */
614
- idSchema: IdSchema<T>;
618
+ /** The FieldPathId of the item for which buttons are being rendered */
619
+ fieldPathId: FieldPathId;
615
620
  /** The className string */
616
621
  className?: string;
617
622
  /** Any optional style attributes */
@@ -691,8 +696,8 @@ export type ArrayFieldTemplateProps<
691
696
  className?: string;
692
697
  /** A boolean value stating if the array is disabled */
693
698
  disabled?: boolean;
694
- /** An object containing the id for this object & ids for its properties */
695
- idSchema: IdSchema<T>;
699
+ /** The FieldPathId of the field in the hierarchy */
700
+ fieldPathId: FieldPathId;
696
701
  /** An array of objects representing the items in the array */
697
702
  items: ArrayFieldItemTemplateType<T, S, F>[];
698
703
  /** A function that adds a new item to the array */
@@ -749,8 +754,8 @@ export type ObjectFieldTemplateProps<
749
754
  required?: boolean;
750
755
  /** A boolean value stating if the field is hiding its errors */
751
756
  hideError?: boolean;
752
- /** An object containing the id for this object & ids for its properties */
753
- idSchema: IdSchema<T>;
757
+ /** The FieldPathId of the field in the hierarchy */
758
+ fieldPathId: FieldPathId;
754
759
  /** The optional validation errors in the form of an `ErrorSchema` */
755
760
  errorSchema?: ErrorSchema<T>;
756
761
  /** The form data for the object */
@@ -1025,7 +1030,10 @@ export type UiSchema<
1025
1030
  * Registry for use everywhere.
1026
1031
  */
1027
1032
  'ui:globalOptions'?: GlobalUISchemaOptions;
1028
- /** 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
+ */
1029
1037
  'ui:rootFieldId'?: string;
1030
1038
  /** By default, any field that is rendered for an `anyOf`/`oneOf` schema will be wrapped inside the `AnyOfField` or
1031
1039
  * `OneOfField` component. This default behavior may be undesirable if your custom field already handles behavior
@@ -1282,16 +1290,6 @@ export interface SchemaUtilsType<T = any, S extends StrictRJSFSchema = RJSFSchem
1282
1290
  * to `undefined`. Will return `undefined` if the new schema is not an object containing properties.
1283
1291
  */
1284
1292
  sanitizeDataForNewSchema(newSchema?: S, oldSchema?: S, data?: any): T;
1285
- /** Generates an `IdSchema` object for the `schema`, recursively
1286
- *
1287
- * @param schema - The schema for which the display label flag is desired
1288
- * @param [id] - The base id for the schema
1289
- * @param [formData] - The current formData, if any, onto which to provide any missing defaults
1290
- * @param [idPrefix='root'] - The prefix to use for the id
1291
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
1292
- * @returns - The `IdSchema` object for the `schema`
1293
- */
1294
- toIdSchema(schema: S, id?: string, formData?: T, idPrefix?: string, idSeparator?: string): IdSchema<T>;
1295
1293
  /** Generates an `PathSchema` object for the `schema`, recursively
1296
1294
  *
1297
1295
  * @param schema - The schema for which the display label flag is desired
@@ -1,14 +0,0 @@
1
- import { Experimental_CustomMergeAllOf, FormContextType, IdSchema, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
2
- /** Generates an `IdSchema` object for the `schema`, recursively
3
- *
4
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
5
- * @param schema - The schema for which the `IdSchema` is desired
6
- * @param [id] - The base id for the schema
7
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
8
- * @param [formData] - The current formData, if any, to assist retrieving a schema
9
- * @param [idPrefix='root'] - The prefix to use for the id
10
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
11
- * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
12
- * @returns - The `IdSchema` object for the `schema`
13
- */
14
- export default function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, id?: string | null, rootSchema?: S, formData?: T, idPrefix?: string, idSeparator?: string, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): IdSchema<T>;