@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.21

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.
Files changed (114) hide show
  1. package/dist/core.umd.js +705 -471
  2. package/dist/{index.js → index.cjs} +1094 -844
  3. package/dist/index.cjs.map +7 -0
  4. package/dist/index.esm.js +1053 -774
  5. package/dist/index.esm.js.map +4 -4
  6. package/lib/components/Form.d.ts +88 -23
  7. package/lib/components/Form.d.ts.map +1 -1
  8. package/lib/components/Form.js +213 -151
  9. package/lib/components/fields/ArrayField.d.ts +17 -7
  10. package/lib/components/fields/ArrayField.d.ts.map +1 -1
  11. package/lib/components/fields/ArrayField.js +116 -70
  12. package/lib/components/fields/BooleanField.d.ts.map +1 -1
  13. package/lib/components/fields/BooleanField.js +7 -2
  14. package/lib/components/fields/LayoutGridField.d.ts +27 -25
  15. package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
  16. package/lib/components/fields/LayoutGridField.js +83 -59
  17. package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
  18. package/lib/components/fields/LayoutHeaderField.js +3 -3
  19. package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
  20. package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
  21. package/lib/components/fields/MultiSchemaField.js +13 -9
  22. package/lib/components/fields/NullField.js +3 -3
  23. package/lib/components/fields/NumberField.d.ts.map +1 -1
  24. package/lib/components/fields/NumberField.js +3 -3
  25. package/lib/components/fields/ObjectField.d.ts +3 -3
  26. package/lib/components/fields/ObjectField.d.ts.map +1 -1
  27. package/lib/components/fields/ObjectField.js +34 -34
  28. package/lib/components/fields/OptionalDataControlsField.d.ts +8 -0
  29. package/lib/components/fields/OptionalDataControlsField.d.ts.map +1 -0
  30. package/lib/components/fields/OptionalDataControlsField.js +43 -0
  31. package/lib/components/fields/SchemaField.d.ts.map +1 -1
  32. package/lib/components/fields/SchemaField.js +17 -17
  33. package/lib/components/fields/StringField.d.ts.map +1 -1
  34. package/lib/components/fields/StringField.js +7 -2
  35. package/lib/components/fields/index.d.ts.map +1 -1
  36. package/lib/components/fields/index.js +2 -0
  37. package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
  38. package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
  39. package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
  40. package/lib/components/templates/ArrayFieldTemplate.d.ts.map +1 -1
  41. package/lib/components/templates/ArrayFieldTemplate.js +4 -3
  42. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
  43. package/lib/components/templates/ArrayFieldTitleTemplate.d.ts.map +1 -1
  44. package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
  45. package/lib/components/templates/ButtonTemplates/AddButton.d.ts +1 -1
  46. package/lib/components/templates/ButtonTemplates/AddButton.d.ts.map +1 -1
  47. package/lib/components/templates/ButtonTemplates/AddButton.js +2 -2
  48. package/lib/components/templates/FieldErrorTemplate.js +2 -2
  49. package/lib/components/templates/FieldHelpTemplate.js +2 -2
  50. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
  51. package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
  52. package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
  53. package/lib/components/templates/ObjectFieldTemplate.d.ts.map +1 -1
  54. package/lib/components/templates/ObjectFieldTemplate.js +3 -2
  55. package/lib/components/templates/OptionalDataControlsTemplate.d.ts +11 -0
  56. package/lib/components/templates/OptionalDataControlsTemplate.d.ts.map +1 -0
  57. package/lib/components/templates/OptionalDataControlsTemplate.js +20 -0
  58. package/lib/components/templates/TitleField.d.ts.map +1 -1
  59. package/lib/components/templates/TitleField.js +2 -2
  60. package/lib/components/templates/UnsupportedField.js +3 -3
  61. package/lib/components/templates/index.d.ts.map +1 -1
  62. package/lib/components/templates/index.js +4 -0
  63. package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
  64. package/lib/components/widgets/AltDateWidget.js +15 -18
  65. package/lib/components/widgets/CheckboxesWidget.js +2 -2
  66. package/lib/getDefaultRegistry.d.ts.map +1 -1
  67. package/lib/getDefaultRegistry.js +2 -1
  68. package/lib/getTestRegistry.d.ts +5 -0
  69. package/lib/getTestRegistry.d.ts.map +1 -0
  70. package/lib/getTestRegistry.js +19 -0
  71. package/lib/index.d.ts +2 -1
  72. package/lib/index.d.ts.map +1 -1
  73. package/lib/index.js +2 -1
  74. package/lib/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +18 -19
  76. package/src/components/Form.tsx +306 -177
  77. package/src/components/fields/ArrayField.tsx +127 -80
  78. package/src/components/fields/BooleanField.tsx +12 -3
  79. package/src/components/fields/LayoutGridField.tsx +95 -88
  80. package/src/components/fields/LayoutHeaderField.tsx +3 -3
  81. package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
  82. package/src/components/fields/MultiSchemaField.tsx +51 -35
  83. package/src/components/fields/NullField.tsx +3 -3
  84. package/src/components/fields/NumberField.tsx +11 -3
  85. package/src/components/fields/ObjectField.tsx +47 -53
  86. package/src/components/fields/OptionalDataControlsField.tsx +84 -0
  87. package/src/components/fields/SchemaField.tsx +24 -30
  88. package/src/components/fields/StringField.tsx +12 -3
  89. package/src/components/fields/index.ts +2 -0
  90. package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
  91. package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
  92. package/src/components/templates/ArrayFieldTemplate.tsx +9 -5
  93. package/src/components/templates/ArrayFieldTitleTemplate.tsx +4 -3
  94. package/src/components/templates/BaseInputTemplate.tsx +3 -3
  95. package/src/components/templates/ButtonTemplates/AddButton.tsx +2 -0
  96. package/src/components/templates/FieldErrorTemplate.tsx +2 -2
  97. package/src/components/templates/FieldHelpTemplate.tsx +2 -2
  98. package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
  99. package/src/components/templates/ObjectFieldTemplate.tsx +10 -5
  100. package/src/components/templates/OptionalDataControlsTemplate.tsx +43 -0
  101. package/src/components/templates/TitleField.tsx +6 -1
  102. package/src/components/templates/UnsupportedField.tsx +3 -3
  103. package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
  104. package/src/components/templates/index.ts +4 -0
  105. package/src/components/widgets/AltDateWidget.tsx +21 -23
  106. package/src/components/widgets/CheckboxWidget.tsx +2 -2
  107. package/src/components/widgets/CheckboxesWidget.tsx +3 -3
  108. package/src/components/widgets/RadioWidget.tsx +1 -1
  109. package/src/components/widgets/SelectWidget.tsx +1 -1
  110. package/src/components/widgets/TextareaWidget.tsx +1 -1
  111. package/src/getDefaultRegistry.ts +10 -1
  112. package/src/getTestRegistry.tsx +34 -0
  113. package/src/index.ts +2 -1
  114. package/dist/index.js.map +0 -7
@@ -1,8 +1,7 @@
1
1
  import { createElement as _createElement } from "react";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { PureComponent } from 'react';
4
- import { ANY_OF_KEY, getDiscriminatorFieldFromSchema, getTemplate, getTestIds, getUiOptions, hashObject, ID_KEY, lookupFromFormContext, mergeObjects, ONE_OF_KEY, PROPERTIES_KEY, READONLY_KEY, UI_OPTIONS_KEY, } from '@rjsf/utils';
5
- import cloneDeep from 'lodash-es/cloneDeep.js';
4
+ import { ANY_OF_KEY, getDiscriminatorFieldFromSchema, getTemplate, getTestIds, getUiOptions, hashObject, ID_KEY, lookupFromFormContext, ONE_OF_KEY, PROPERTIES_KEY, READONLY_KEY, toFieldPathId, UI_OPTIONS_KEY, UI_GLOBAL_OPTIONS_KEY, ITEMS_KEY, } from '@rjsf/utils';
6
5
  import each from 'lodash-es/each.js';
7
6
  import flatten from 'lodash-es/flatten.js';
8
7
  import get from 'lodash-es/get.js';
@@ -16,6 +15,7 @@ import isObject from 'lodash-es/isObject.js';
16
15
  import isPlainObject from 'lodash-es/isPlainObject.js';
17
16
  import isString from 'lodash-es/isString.js';
18
17
  import isUndefined from 'lodash-es/isUndefined.js';
18
+ import last from 'lodash-es/last.js';
19
19
  import set from 'lodash-es/set.js';
20
20
  /** The enumeration of the three different Layout GridTemplate type values
21
21
  */
@@ -43,9 +43,6 @@ export const LAYOUT_GRID_UI_OPTION = 'layoutGrid';
43
43
  /** The constant representing the main layout grid schema option name in the `uiSchema`
44
44
  */
45
45
  export const LAYOUT_GRID_OPTION = `ui:${LAYOUT_GRID_UI_OPTION}`;
46
- /** The constant representing the global UI Options object potentially contained within the `uiSchema`
47
- */
48
- export const UI_GLOBAL_OPTIONS = 'ui:global_options';
49
46
  /** Returns either the `value` if it is non-nullish or the fallback
50
47
  *
51
48
  * @param [value] - The potential value to return if it is non-nullish
@@ -55,6 +52,14 @@ export const UI_GLOBAL_OPTIONS = 'ui:global_options';
55
52
  function getNonNullishValue(value, fallback) {
56
53
  return value ?? fallback;
57
54
  }
55
+ /** Detects if a `str` is made up entirely of numeric characters
56
+ *
57
+ * @param str - The string to check to see if it is a numeric index
58
+ * @return - True if the string consists entirely of numeric characters
59
+ */
60
+ function isNumericIndex(str) {
61
+ return /^\d+?$/.test(str); // Matches positive integers
62
+ }
58
63
  /** The `LayoutGridField` will render a schema, uiSchema and formData combination out into a GridTemplate in the shape
59
64
  * described in the uiSchema. To define the grid to use to render the elements within a field in the schema, provide in
60
65
  * the uiSchema for that field the object contained under a `ui:layoutGrid` element. E.g. (as a JSON object):
@@ -297,7 +302,7 @@ export default class LayoutGridField extends PureComponent {
297
302
  * @param [forceReadonly] - Optional flag indicating whether the Form itself is in readonly mode
298
303
  */
299
304
  static computeFieldUiSchema(field, uiProps, uiSchema, schemaReadonly, forceReadonly) {
300
- const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS], {});
305
+ const globalUiOptions = get(uiSchema, [UI_GLOBAL_OPTIONS_KEY], {});
301
306
  const localUiSchema = get(uiSchema, field);
302
307
  const localUiOptions = { ...get(localUiSchema, [UI_OPTIONS_KEY], {}), ...uiProps, ...globalUiOptions };
303
308
  const fieldUiSchema = { ...localUiSchema };
@@ -306,7 +311,7 @@ export default class LayoutGridField extends PureComponent {
306
311
  }
307
312
  if (!isEmpty(globalUiOptions)) {
308
313
  // pass the global uiOptions down to the field uiSchema so that they can be applied to all nested fields
309
- set(fieldUiSchema, [UI_GLOBAL_OPTIONS], globalUiOptions);
314
+ set(fieldUiSchema, [UI_GLOBAL_OPTIONS_KEY], globalUiOptions);
310
315
  }
311
316
  let { readonly: uiReadonly } = getUiOptions(fieldUiSchema);
312
317
  if (forceReadonly === true || (isUndefined(uiReadonly) && schemaReadonly === true)) {
@@ -384,37 +389,59 @@ export default class LayoutGridField extends PureComponent {
384
389
  }
385
390
  return { children: children, gridProps };
386
391
  }
387
- /** Generates an idSchema for the `schema` using `@rjsf`'s `toIdSchema` util, passing the `baseIdSchema`'s `$id` value
388
- * as the id prefix.
392
+ /** Computes the `rawSchema` and `fieldPathId` for a `schema` and a `potentialIndex`. If the `schema` is of type array,
393
+ * has an `ITEMS_KEY` element and `potentialIndex` represents a numeric value, the element at `ITEMS_KEY` is checked
394
+ * to see if it is an array. If it is AND the `potentialIndex`th element is available, it is used as the `rawSchema`,
395
+ * otherwise the last value of the element is used. If it is not, then the element is used as the `rawSchema`. In
396
+ * either case, an `fieldPathId` is computed for the array index. If the `schema` does not represent an array or the
397
+ * `potentialIndex` is not a numeric value, then `rawSchema` is returned as undefined and given `fieldPathId` is returned
398
+ * as is.
389
399
  *
390
- * @param schemaUtils - The `SchemaUtilsType` used to call `toIdSchema`
391
- * @param schema - The schema to generate the idSchema for
392
- * @param baseIdSchema - The IdSchema for the base
393
- * @param formData - The formData to pass the `toIdSchema`
394
- * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
395
- * @returns - The generated `idSchema` for the `schema`
400
+ * @param schema - The schema to generate the fieldPathId for
401
+ * @param fieldPathId - The FieldPathId for the schema
402
+ * @param potentialIndex - A string containing a potential index
403
+ * @returns - An object containing the `rawSchema` and `fieldPathId` of an array item, otherwise an undefined `rawSchema`
396
404
  */
397
- static getIdSchema(schemaUtils, baseIdSchema, formData, schema = {}, idSeparator) {
398
- const baseId = get(baseIdSchema, ID_KEY);
399
- return schemaUtils.toIdSchema(schema, baseId, formData, baseId, idSeparator);
405
+ static computeArraySchemasIfPresent(schema, fieldPathId, potentialIndex) {
406
+ let rawSchema;
407
+ if (isNumericIndex(potentialIndex) && schema && schema?.type === 'array' && has(schema, ITEMS_KEY)) {
408
+ const index = Number(potentialIndex);
409
+ const items = schema[ITEMS_KEY];
410
+ if (Array.isArray(items)) {
411
+ if (index > items.length) {
412
+ rawSchema = last(items);
413
+ }
414
+ else {
415
+ rawSchema = items[index];
416
+ }
417
+ }
418
+ else {
419
+ rawSchema = items;
420
+ }
421
+ fieldPathId = {
422
+ [ID_KEY]: fieldPathId[ID_KEY],
423
+ path: [...fieldPathId.path.slice(0, fieldPathId.path.length - 1), index],
424
+ };
425
+ }
426
+ return { rawSchema, fieldPathId };
400
427
  }
401
428
  /** Given a `dottedPath` to a field in the `initialSchema`, iterate through each individual path in the schema until
402
429
  * the leaf path is found and returned (along with whether that leaf path `isRequired`) OR no schema exists for an
403
430
  * element in the path. If the leaf schema element happens to be a oneOf/anyOf then also return the oneOf/anyOf as
404
431
  * `options`.
405
432
  *
406
- * @param schemaUtils - The `SchemaUtilsType` used to call `retrieveSchema`
433
+ * @param registry - The registry
407
434
  * @param dottedPath - The dotted-path to the field for which to get the schema
408
435
  * @param initialSchema - The initial schema to start the search from
409
436
  * @param formData - The formData, useful for resolving a oneOf/anyOf selection in the path hierarchy
410
- * @param initialIdSchema - The initial idSchema to start the search from
411
- * @param [idSeparator] - The param to pass into the `toIdSchema` util which will use it to join the `idSchema` paths
437
+ * @param initialFieldIdPath - The initial fieldPathId to start the search from
412
438
  * @returns - An object containing the destination schema, isRequired and isReadonly flags for the field and options
413
439
  * info if a oneOf/anyOf
414
440
  */
415
- static getSchemaDetailsForField(schemaUtils, dottedPath, initialSchema, formData, initialIdSchema, idSeparator) {
441
+ static getSchemaDetailsForField(registry, dottedPath, initialSchema, formData, initialFieldIdPath) {
442
+ const { schemaUtils, globalFormOptions } = registry;
416
443
  let rawSchema = initialSchema;
417
- let idSchema = initialIdSchema;
444
+ let fieldPathId = initialFieldIdPath;
418
445
  const parts = dottedPath.split('.');
419
446
  const leafPath = parts.pop(); // pop off the last element in the list as the leaf
420
447
  let schema = schemaUtils.retrieveSchema(rawSchema, formData); // always returns an object
@@ -423,20 +450,20 @@ export default class LayoutGridField extends PureComponent {
423
450
  // For all the remaining path parts
424
451
  parts.forEach((part) => {
425
452
  // dive into the properties of the current schema (when it exists) and get the schema for the next part
453
+ fieldPathId = toFieldPathId(part, globalFormOptions, fieldPathId);
426
454
  if (has(schema, PROPERTIES_KEY)) {
427
455
  rawSchema = get(schema, [PROPERTIES_KEY, part], {});
428
- idSchema = get(idSchema, part, {});
429
456
  }
430
457
  else if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
431
458
  const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
432
459
  // When the schema represents a oneOf/anyOf, find the selected schema for it and grab the inner part
433
460
  const selectedSchema = schemaUtils.findSelectedOptionInXxxOf(schema, part, xxx, innerData);
434
- const selectedIdSchema = LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, selectedSchema, idSeparator);
435
461
  rawSchema = get(selectedSchema, [PROPERTIES_KEY, part], {});
436
- idSchema = get(selectedIdSchema, part, {});
437
462
  }
438
463
  else {
439
- rawSchema = {};
464
+ const result = LayoutGridField.computeArraySchemasIfPresent(schema, fieldPathId, part);
465
+ rawSchema = result.rawSchema ?? {};
466
+ fieldPathId = result.fieldPathId;
440
467
  }
441
468
  // Now drill into the innerData for the part, returning an empty object by default if it doesn't exist
442
469
  innerData = get(innerData, part, {});
@@ -456,16 +483,20 @@ export default class LayoutGridField extends PureComponent {
456
483
  const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
457
484
  // Grab the selected schema for the oneOf/anyOf value for the leafPath using the innerData
458
485
  schema = schemaUtils.findSelectedOptionInXxxOf(schema, leafPath, xxx, innerData);
459
- // Generate the idSchema for the oneOf/anyOf value then merge with the existing `idSchema`
460
- const rawIdSchema = LayoutGridField.getIdSchema(schemaUtils, idSchema, formData, schema, idSeparator);
461
- idSchema = mergeObjects(rawIdSchema, idSchema);
462
486
  }
487
+ fieldPathId = toFieldPathId(leafPath, globalFormOptions, fieldPathId);
463
488
  isRequired = schema !== undefined && Array.isArray(schema.required) && includes(schema.required, leafPath);
464
- // Now grab the schema from the leafPath of the current schema properties
465
- schema = get(schema, [PROPERTIES_KEY, leafPath]);
466
- // Resolve any `$ref`s for the current schema
467
- schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
468
- idSchema = get(idSchema, leafPath, {});
489
+ const result = LayoutGridField.computeArraySchemasIfPresent(schema, fieldPathId, leafPath);
490
+ if (result.rawSchema) {
491
+ schema = result.rawSchema;
492
+ fieldPathId = result.fieldPathId;
493
+ }
494
+ else {
495
+ // Now grab the schema from the leafPath of the current schema properties
496
+ schema = get(schema, [PROPERTIES_KEY, leafPath]);
497
+ // Resolve any `$ref`s for the current schema
498
+ schema = schema ? schemaUtils.retrieveSchema(schema) : schema;
499
+ }
469
500
  isReadonly = getNonNullishValue(schema?.readOnly, isReadonly);
470
501
  if (schema && (has(schema, ONE_OF_KEY) || has(schema, ANY_OF_KEY))) {
471
502
  const xxx = has(schema, ONE_OF_KEY) ? ONE_OF_KEY : ANY_OF_KEY;
@@ -474,7 +505,7 @@ export default class LayoutGridField extends PureComponent {
474
505
  optionsInfo = { options: schema[xxx], hasDiscriminator: !!discriminator };
475
506
  }
476
507
  }
477
- return { schema, isRequired, isReadonly, optionsInfo, idSchema };
508
+ return { schema, isRequired, isReadonly, optionsInfo, fieldPathId };
478
509
  }
479
510
  /** Gets the custom render component from the `render`, by either determining that it is either already a function or
480
511
  * it is a non-function value that can be used to look up the function in the registry. If no function can be found,
@@ -511,7 +542,7 @@ export default class LayoutGridField extends PureComponent {
511
542
  name = gridSchema ?? '';
512
543
  }
513
544
  else {
514
- const { name: innerName, render, ...innerProps } = gridSchema;
545
+ const { name: innerName = '', render, ...innerProps } = gridSchema;
515
546
  name = innerName;
516
547
  uiProps = innerProps;
517
548
  if (!isEmpty(uiProps)) {
@@ -545,19 +576,12 @@ export default class LayoutGridField extends PureComponent {
545
576
  * elements, they will then be passed on to the `onChange` handler of the `LayoutFieldGrid`.
546
577
  *
547
578
  * @param dottedPath - The dotted-path to the field for which to generate the onChange handler
548
- * @returns - The `onChange` handling function for the `dottedPath` field
579
+ * @returns - The `onChange` handling function for the `dottedPath` field of the `schemaType` type
549
580
  */
550
581
  onFieldChange = (dottedPath) => {
551
- return (value, errSchema, id) => {
552
- const { onChange, errorSchema, formData } = this.props;
553
- const newFormData = cloneDeep(formData || {});
554
- let newErrorSchema = errorSchema;
555
- if (errSchema && errorSchema) {
556
- newErrorSchema = cloneDeep(errorSchema);
557
- set(newErrorSchema, dottedPath, errSchema);
558
- }
559
- set(newFormData, dottedPath, value);
560
- onChange(newFormData, newErrorSchema, id);
582
+ return (value, path, errSchema, id) => {
583
+ const { onChange } = this.props;
584
+ onChange(value, path, errSchema, id);
561
585
  };
562
586
  };
563
587
  /** Renders the `children` of the `GridType.CONDITION` if it passes. The `layoutGridSchema` for the
@@ -620,20 +644,20 @@ export default class LayoutGridField extends PureComponent {
620
644
  const GridTemplate = getTemplate('GridTemplate', registry, uiOptions);
621
645
  return (_jsx(GridTemplate, { ...gridProps, "data-testid": LayoutGridField.TEST_IDS.row, children: this.renderChildren(children) }));
622
646
  }
623
- /** Iterates through all the `childrenLayoutGridSchema`, rendering a nested `LayoutGridField` for each item in the
647
+ /** Iterates through all the `childrenLayoutGrfieldPathId`, rendering a nested `LayoutGridField` for each item in the
624
648
  * list, passing all the props for the current `LayoutGridField` along, updating the `schema` by calling
625
649
  * `retrieveSchema()` on it to resolve any `$ref`s. In addition to the updated `schema`, each item in
626
- * `childrenLayoutGridSchema` is passed as `layoutGridSchema`.
650
+ * `childrenLayoutGrfieldPathId` is passed as `layoutGridSchema`.
627
651
  *
628
- * @param childrenLayoutGridSchema - The list of strings or objects that represents the configurations for the
652
+ * @param childrenLayoutGrfieldPathId - The list of strings or objects that represents the configurations for the
629
653
  * children fields
630
654
  * @returns - The nested `LayoutGridField`s
631
655
  */
632
- renderChildren(childrenLayoutGridSchema) {
656
+ renderChildren(childrenLayoutGrfieldPathId) {
633
657
  const { registry, schema: rawSchema, formData } = this.props;
634
658
  const { schemaUtils } = registry;
635
659
  const schema = schemaUtils.retrieveSchema(rawSchema, formData);
636
- return childrenLayoutGridSchema.map((layoutGridSchema) => (_createElement(LayoutGridField, { ...this.props, key: `layoutGrid-${hashObject(layoutGridSchema)}`, schema: schema, layoutGridSchema: layoutGridSchema })));
660
+ return childrenLayoutGrfieldPathId.map((layoutGridSchema) => (_createElement(LayoutGridField, { ...this.props, key: `layoutGrid-${hashObject(layoutGridSchema)}`, schema: schema, layoutGridSchema: layoutGridSchema })));
637
661
  }
638
662
  /** Renders the field described by `gridSchema`. If `gridSchema` is not an object, then is will be assumed
639
663
  * to be the dotted-path to the field in the schema. Otherwise, we extract the `name`, and optional `render` and all
@@ -641,7 +665,7 @@ export default class LayoutGridField extends PureComponent {
641
665
  * specified props for that component. If `name` exists, we take the name, the initial & root schemas and the formData
642
666
  * and get the destination schema, is required state and optional oneOf/anyOf options for it. If the destination
643
667
  * schema was located along with oneOf/anyOf options then a `LayoutMultiSchemaField` will be rendered with the
644
- * `uiSchema`, `errorSchema`, `idSchema` and `formData` drilled down to the dotted-path field, spreading any other
668
+ * `uiSchema`, `errorSchema`, `fieldPathId` and `formData` drilled down to the dotted-path field, spreading any other
645
669
  * props from `gridSchema` into the `ui:options`. If the destination schema located without any oneOf/anyOf options,
646
670
  * then a `SchemaField` will be rendered with the same props as mentioned in the previous sentence. If no destination
647
671
  * schema was located, but a custom render component was found, then it will be rendered with many of the non-event
@@ -651,16 +675,16 @@ export default class LayoutGridField extends PureComponent {
651
675
  * @returns - One of `LayoutMultiSchemaField`, `SchemaField`, a custom render component or null, depending
652
676
  */
653
677
  renderField(gridSchema) {
654
- const { schema: initialSchema, uiSchema, errorSchema, idSchema, onBlur, onFocus, formData, readonly, registry, idSeparator, layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
678
+ const { schema: initialSchema, uiSchema, errorSchema, fieldPathId, onBlur, onFocus, formData, readonly, registry, layoutGridSchema, // Used to pull this out of otherProps since we don't want to pass it through
655
679
  ...otherProps } = this.props;
656
- const { fields, schemaUtils } = registry;
680
+ const { fields } = registry;
657
681
  const { SchemaField, LayoutMultiSchemaField } = fields;
658
682
  const uiComponentProps = LayoutGridField.computeUIComponentPropsFromGridSchema(registry, gridSchema);
659
683
  if (uiComponentProps.rendered) {
660
684
  return uiComponentProps.rendered;
661
685
  }
662
686
  const { name, UIComponent, uiProps } = uiComponentProps;
663
- const { schema, isRequired, isReadonly, optionsInfo, idSchema: fieldIdSchema, } = LayoutGridField.getSchemaDetailsForField(schemaUtils, name, initialSchema, formData, idSchema, idSeparator);
687
+ const { schema, isRequired, isReadonly, optionsInfo, fieldPathId: fieldIdSchema, } = LayoutGridField.getSchemaDetailsForField(registry, name, initialSchema, formData, fieldPathId);
664
688
  if (schema) {
665
689
  const Field = optionsInfo?.hasDiscriminator ? LayoutMultiSchemaField : SchemaField;
666
690
  // Call this function to get the appropriate UISchema, which will always have its `readonly` state matching the
@@ -671,10 +695,10 @@ export default class LayoutGridField extends PureComponent {
671
695
  const { fieldUiSchema, uiReadonly } = LayoutGridField.computeFieldUiSchema(name, uiProps, uiSchema, isReadonly, readonly);
672
696
  return (_jsx(Field, { "data-testid": optionsInfo?.hasDiscriminator
673
697
  ? LayoutGridField.TEST_IDS.layoutMultiSchemaField
674
- : LayoutGridField.TEST_IDS.field, ...otherProps, name: name, required: isRequired, readonly: uiReadonly, schema: schema, uiSchema: fieldUiSchema, errorSchema: get(errorSchema, name), idSchema: fieldIdSchema, idSeparator: idSeparator, formData: get(formData, name), onChange: this.onFieldChange(name), onBlur: onBlur, onFocus: onFocus, options: optionsInfo?.options, registry: registry }));
698
+ : LayoutGridField.TEST_IDS.field, ...otherProps, name: name, required: isRequired, readonly: uiReadonly, schema: schema, uiSchema: fieldUiSchema, errorSchema: get(errorSchema, name), fieldPathId: fieldIdSchema, formData: get(formData, name), onChange: this.onFieldChange(name), onBlur: onBlur, onFocus: onFocus, options: optionsInfo?.options, registry: registry }));
675
699
  }
676
700
  if (UIComponent) {
677
- return (_jsx(UIComponent, { "data-testid": LayoutGridField.TEST_IDS.uiComponent, ...otherProps, name: name, required: isRequired, formData: formData, readOnly: !!isReadonly || readonly, errorSchema: errorSchema, uiSchema: uiSchema, schema: initialSchema, idSchema: idSchema, idSeparator: idSeparator, onBlur: onBlur, onFocus: onFocus, registry: registry, ...uiProps }));
701
+ return (_jsx(UIComponent, { "data-testid": LayoutGridField.TEST_IDS.uiComponent, ...otherProps, name: name, required: isRequired, formData: formData, readOnly: !!isReadonly || readonly, errorSchema: errorSchema, uiSchema: uiSchema, schema: initialSchema, fieldPathId: fieldPathId, onBlur: onBlur, onFocus: onFocus, registry: registry, ...uiProps }));
678
702
  }
679
703
  return null;
680
704
  }
@@ -1,5 +1,5 @@
1
1
  import { FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
- /** The `LayoutHeaderField` component renders a `TitleFieldTemplate` with an `id` derived from the `idSchema`
2
+ /** The `LayoutHeaderField` component renders a `TitleFieldTemplate` with an `id` derived from the `fieldPathId`
3
3
  * and whether it is `required` from the props. The `title` is derived from the props as follows:
4
4
  * - If there is a title in the `uiSchema`, it is displayed
5
5
  * - Else, if there is an explicit `title` passed in the props, it is displayed
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { getTemplate, getUiOptions, titleId, } from '@rjsf/utils';
3
- /** The `LayoutHeaderField` component renders a `TitleFieldTemplate` with an `id` derived from the `idSchema`
3
+ /** The `LayoutHeaderField` component renders a `TitleFieldTemplate` with an `id` derived from the `fieldPathId`
4
4
  * and whether it is `required` from the props. The `title` is derived from the props as follows:
5
5
  * - If there is a title in the `uiSchema`, it is displayed
6
6
  * - Else, if there is an explicit `title` passed in the props, it is displayed
@@ -10,7 +10,7 @@ import { getTemplate, getUiOptions, titleId, } from '@rjsf/utils';
10
10
  * @param props - The `LayoutHeaderField` for the component
11
11
  */
12
12
  export default function LayoutHeaderField(props) {
13
- const { idSchema, title, schema, uiSchema, required, registry, name } = props;
13
+ const { fieldPathId, title, schema, uiSchema, required, registry, name } = props;
14
14
  const options = getUiOptions(uiSchema, registry.globalUiOptions);
15
15
  const { title: uiTitle } = options;
16
16
  const { title: schemaTitle } = schema;
@@ -19,5 +19,5 @@ export default function LayoutHeaderField(props) {
19
19
  return null;
20
20
  }
21
21
  const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, options);
22
- return (_jsx(TitleFieldTemplate, { id: titleId(idSchema), title: fieldTitle, required: required, schema: schema, uiSchema: uiSchema, registry: registry }));
22
+ return (_jsx(TitleFieldTemplate, { id: titleId(fieldPathId), title: fieldTitle, required: required, schema: schema, uiSchema: uiSchema, registry: registry }));
23
23
  }
@@ -55,10 +55,10 @@ export function computeEnumOptions(schema, options, schemaUtils, uiSchema, formD
55
55
  * is active. If no `selectorField` is specified, then an error is thrown.
56
56
  */
57
57
  export default function LayoutMultiSchemaField(props) {
58
- const { name, baseType, disabled = false, formData, idSchema, onBlur, onChange, options, onFocus, registry, uiSchema, schema, formContext, autofocus, readonly, required, errorSchema, hideError = false, } = props;
58
+ const { name, baseType, disabled = false, formData, fieldPathId, onBlur, onChange, options, onFocus, registry, uiSchema, schema, formContext, autofocus, readonly, required, errorSchema, hideError = false, } = props;
59
59
  const { widgets, schemaUtils, globalUiOptions } = registry;
60
60
  const [enumOptions, setEnumOptions] = useState(computeEnumOptions(schema, options, schemaUtils, uiSchema, formData));
61
- const id = get(idSchema, ID_KEY);
61
+ const id = get(fieldPathId, ID_KEY);
62
62
  const discriminator = getDiscriminatorFieldFromSchema(schema);
63
63
  const FieldErrorTemplate = getTemplate('FieldErrorTemplate', registry, options);
64
64
  const FieldTemplate = getTemplate('FieldTemplate', registry, options);
@@ -104,11 +104,12 @@ export default function LayoutMultiSchemaField(props) {
104
104
  if (newFormData) {
105
105
  set(newFormData, selectorField, opt);
106
106
  }
107
- onChange(newFormData, undefined, id);
107
+ // Pass the component name in the path
108
+ onChange(newFormData, fieldPathId.path, undefined, id);
108
109
  };
109
110
  // filtering the options based on the type of widget because `selectField` does not recognize the `convertOther` prop
110
111
  const widgetOptions = { enumOptions, ...uiOptions };
111
- const errors = !hideFieldError && rawErrors.length > 0 ? (_jsx(FieldErrorTemplate, { idSchema: idSchema, schema: schema, errors: rawErrors, registry: registry })) : undefined;
112
+ const errors = !hideFieldError && rawErrors.length > 0 ? (_jsx(FieldErrorTemplate, { fieldPathId: fieldPathId, schema: schema, errors: rawErrors, registry: registry })) : undefined;
112
113
  const ignored = (value) => noop;
113
- return (_jsx(FieldTemplate, { id: id, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, formContext: formContext, required: required, readonly: !!readonly, registry: registry, displayLabel: displayLabel, errors: errors, onChange: onChange, onDropPropertyClick: ignored, onKeyChange: ignored, children: _jsx(Widget, { id: id, name: name, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, formContext: formContext, autofocus: autofocus, readonly: readonly, required: required, registry: registry, multiple: false, rawErrors: rawErrors, hideError: hideFieldError, hideLabel: !displayLabel, errorSchema: fieldErrorSchema, placeholder: placeholder, onChange: onOptionChange, onBlur: onBlur, onFocus: onFocus, value: selectedOption, options: widgetOptions }) }));
114
+ return (_jsx(FieldTemplate, { id: id, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, required: required, readonly: !!readonly, registry: registry, displayLabel: displayLabel, errors: errors, onChange: onChange, onDropPropertyClick: ignored, onKeyChange: ignored, children: _jsx(Widget, { id: id, name: name, schema: schema, label: (title || schema.title) ?? '', disabled: disabled || (Array.isArray(enumOptions) && isEmpty(enumOptions)), uiSchema: uiSchema, formContext: formContext, autofocus: autofocus, readonly: readonly, required: required, registry: registry, multiple: false, rawErrors: rawErrors, hideError: hideFieldError, hideLabel: !displayLabel, errorSchema: fieldErrorSchema, placeholder: placeholder, onChange: onOptionChange, onBlur: onBlur, onFocus: onFocus, value: selectedOption, options: widgetOptions }) }));
114
115
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAIL,UAAU,EACV,eAAe,EAMf,UAAU,EACV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAErB,4DAA4D;AAC5D,KAAK,eAAe,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,IAAI;IAC9D,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,EAAE,CAAC,EAAE,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,cAAM,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACnH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,eAAe,CAAC,CAAC,CAAC,CACnB;IACC;;;OAGG;gBACS,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAiBtC;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC;IAyBjG;;;;;OAKG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;IAW/E;;;;;OAKG;IACH,cAAc,GAAI,SAAS,MAAM,UAqB/B;IAEF,UAAU;IAKV;OACG;IACH,MAAM;CA0GP;AAED,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"MultiSchemaField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/MultiSchemaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,EAIL,UAAU,EACV,eAAe,EAOf,UAAU,EACV,gBAAgB,EAGjB,MAAM,aAAa,CAAC;AAErB,4DAA4D;AAC5D,KAAK,eAAe,CAAC,CAAC,SAAS,gBAAgB,GAAG,UAAU,IAAI;IAC9D,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,EAAE,CAAC,EAAE,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,cAAM,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACnH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,eAAe,CAAC,CAAC,CAAC,CACnB;IACC;;;OAGG;gBACS,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAiBtC;;;;;OAKG;IACH,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC;IAyBjG;;;;;OAKG;IACH,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;IAW/E;;;;;OAKG;IACH,cAAc,GAAI,SAAS,MAAM,UAqB/B;IAEF,UAAU;IAKV;OACG;IACH,MAAM;CAyHP;AAED,eAAe,UAAU,CAAC"}
@@ -1,9 +1,9 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Component } from 'react';
3
3
  import get from 'lodash-es/get.js';
4
4
  import isEmpty from 'lodash-es/isEmpty.js';
5
5
  import omit from 'lodash-es/omit.js';
6
- import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getUiOptions, getWidget, mergeSchemas, ONE_OF_KEY, TranslatableString, } from '@rjsf/utils';
6
+ import { ANY_OF_KEY, deepEquals, ERRORS_KEY, getDiscriminatorFieldFromSchema, getTemplate, getUiOptions, getWidget, mergeSchemas, ONE_OF_KEY, TranslatableString, } from '@rjsf/utils';
7
7
  /** The `AnyOfField` component is used to render a field in the schema that is an `anyOf`, `allOf` or `oneOf`. It tracks
8
8
  * the currently selected option and cleans up any irrelevant data in `formData`.
9
9
  *
@@ -31,7 +31,7 @@ class AnyOfField extends Component {
31
31
  * @param prevState - The previous `AnyOfFieldState` for this template
32
32
  */
33
33
  componentDidUpdate(prevProps, prevState) {
34
- const { formData, options, idSchema } = this.props;
34
+ const { formData, options, fieldPathId } = this.props;
35
35
  const { selectedOption } = this.state;
36
36
  let newState = this.state;
37
37
  if (!deepEquals(prevProps.options, options)) {
@@ -40,7 +40,7 @@ class AnyOfField extends Component {
40
40
  const retrievedOptions = options.map((opt) => schemaUtils.retrieveSchema(opt, formData));
41
41
  newState = { selectedOption, retrievedOptions };
42
42
  }
43
- if (!deepEquals(formData, prevProps.formData) && idSchema.$id === prevProps.idSchema.$id) {
43
+ if (!deepEquals(formData, prevProps.formData) && fieldPathId.$id === prevProps.fieldPathId.$id) {
44
44
  const { retrievedOptions } = newState;
45
45
  const matchingOption = this.getMatchingOption(selectedOption, formData, retrievedOptions);
46
46
  if (prevState && matchingOption !== selectedOption) {
@@ -71,7 +71,7 @@ class AnyOfField extends Component {
71
71
  */
72
72
  onOptionChange = (option) => {
73
73
  const { selectedOption, retrievedOptions } = this.state;
74
- const { formData, onChange, registry } = this.props;
74
+ const { formData, onChange, registry, fieldPathId } = this.props;
75
75
  const { schemaUtils } = registry;
76
76
  const intOption = option !== undefined ? parseInt(option, 10) : -1;
77
77
  if (intOption === selectedOption) {
@@ -86,12 +86,12 @@ class AnyOfField extends Component {
86
86
  newFormData = schemaUtils.getDefaultFormState(newOption, newFormData, 'excludeObjectChildren');
87
87
  }
88
88
  this.setState({ selectedOption: intOption }, () => {
89
- onChange(newFormData, undefined, this.getFieldId());
89
+ onChange(newFormData, fieldPathId.path, undefined, this.getFieldId());
90
90
  });
91
91
  };
92
92
  getFieldId() {
93
- const { idSchema, schema } = this.props;
94
- return `${idSchema.$id}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`;
93
+ const { fieldPathId, schema } = this.props;
94
+ return `${fieldPathId.$id}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`;
95
95
  }
96
96
  /** Renders the `AnyOfField` selector along with a `SchemaField` for the value of the `formData`
97
97
  */
@@ -99,6 +99,7 @@ class AnyOfField extends Component {
99
99
  const { name, disabled = false, errorSchema = {}, formContext, onBlur, onFocus, readonly, registry, schema, uiSchema, } = this.props;
100
100
  const { widgets, fields, translateString, globalUiOptions, schemaUtils } = registry;
101
101
  const { SchemaField: _SchemaField } = fields;
102
+ const MultiSchemaFieldTemplate = getTemplate('MultiSchemaFieldTemplate', registry, globalUiOptions);
102
103
  const { selectedOption, retrievedOptions } = this.state;
103
104
  const { widget = 'select', placeholder, autofocus, autocomplete, title = schema.title, ...uiOptions } = getUiOptions(uiSchema, globalUiOptions);
104
105
  const Widget = getWidget({ type: 'number' }, widget, widgets);
@@ -148,7 +149,10 @@ class AnyOfField extends Component {
148
149
  value: index,
149
150
  };
150
151
  });
151
- return (_jsxs("div", { className: 'panel panel-default panel-body', children: [_jsx("div", { className: 'form-group', children: _jsx(Widget, { id: this.getFieldId(), name: `${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`, schema: { type: 'number', default: 0 }, onChange: this.onOptionChange, onBlur: onBlur, onFocus: onFocus, disabled: disabled || isEmpty(enumOptions), multiple: false, rawErrors: rawErrors, errorSchema: fieldErrorSchema, value: selectedOption >= 0 ? selectedOption : undefined, options: { enumOptions, ...uiOptions }, registry: registry, formContext: formContext, placeholder: placeholder, autocomplete: autocomplete, autofocus: autofocus, label: title ?? name, hideLabel: !displayLabel, readonly: readonly }) }), optionSchema && optionSchema.type !== 'null' && (_jsx(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema }))] }));
152
+ const selector = (_jsx(Widget, { id: this.getFieldId(), name: `${name}${schema.oneOf ? '__oneof_select' : '__anyof_select'}`, schema: { type: 'number', default: 0 }, onChange: this.onOptionChange, onBlur: onBlur, onFocus: onFocus, disabled: disabled || isEmpty(enumOptions), multiple: false, rawErrors: rawErrors, errorSchema: fieldErrorSchema, value: selectedOption >= 0 ? selectedOption : undefined, options: { enumOptions, ...uiOptions }, registry: registry, formContext: formContext, placeholder: placeholder, autocomplete: autocomplete, autofocus: autofocus, label: title ?? name, hideLabel: !displayLabel, readonly: readonly }));
153
+ const optionsSchemaField = (optionSchema && optionSchema.type !== 'null' && (_jsx(_SchemaField, { ...this.props, schema: optionSchema, uiSchema: optionUiSchema }))) ||
154
+ null;
155
+ return (_jsx(MultiSchemaFieldTemplate, { schema: schema, registry: registry, uiSchema: uiSchema, selector: selector, optionSchemaField: optionsSchemaField }));
152
156
  }
153
157
  }
154
158
  export default AnyOfField;
@@ -5,12 +5,12 @@ import { useEffect } from 'react';
5
5
  * @param props - The `FieldProps` for this template
6
6
  */
7
7
  function NullField(props) {
8
- const { formData, onChange } = props;
8
+ const { formData, onChange, fieldPathId } = props;
9
9
  useEffect(() => {
10
10
  if (formData === undefined) {
11
- onChange(null);
11
+ onChange(null, fieldPathId.path);
12
12
  }
13
- }, [formData, onChange]);
13
+ }, [fieldPathId, formData, onChange]);
14
14
  return null;
15
15
  }
16
16
  export default NullField;
@@ -1 +1 @@
1
- {"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NumberField.tsx"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAc/G;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACpG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAkD3B;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/NumberField.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAcrB;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAS,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,EACpG,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,2CAkD3B;AAED,eAAe,WAAW,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState, useCallback } from 'react';
3
- import { asNumber } from '@rjsf/utils';
3
+ import { asNumber, } from '@rjsf/utils';
4
4
  // Matches a string that ends in a . character, optionally followed by a sequence of
5
5
  // digits followed by any number of 0 characters up until the end of the line.
6
6
  // Ensuring that there is at least one prefixed character is important so that
@@ -37,7 +37,7 @@ function NumberField(props) {
37
37
  *
38
38
  * @param value - The current value for the change occurring
39
39
  */
40
- const handleChange = useCallback((value, errorSchema, id) => {
40
+ const handleChange = useCallback((value, path, errorSchema, id) => {
41
41
  // Cache the original value in component state
42
42
  setLastValue(value);
43
43
  // Normalize decimals that don't start with a zero character in advance so
@@ -51,7 +51,7 @@ function NumberField(props) {
51
51
  const processed = typeof value === 'string' && value.match(trailingCharMatcherWithPrefix)
52
52
  ? asNumber(value.replace(trailingCharMatcher, ''))
53
53
  : asNumber(value);
54
- onChange(processed, errorSchema, id);
54
+ onChange(processed, path, errorSchema, id);
55
55
  }, [onChange]);
56
56
  if (typeof lastValue === 'string' && typeof value === 'number') {
57
57
  // Construct a regular expression that checks for a string that consists
@@ -1,5 +1,5 @@
1
1
  import { Component } from 'react';
2
- import { ErrorSchema, FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
2
+ import { ErrorSchema, FieldPathList, FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils';
3
3
  /** Type used for the state of the `ObjectField` component */
4
4
  type ObjectFieldState = {
5
5
  /** Flag indicating whether an additional property key was modified */
@@ -32,7 +32,7 @@ declare class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
32
32
  * @param addedByAdditionalProperties - Flag indicating whether this property is an additional property
33
33
  * @returns - The onPropertyChange callback for the `name` property
34
34
  */
35
- onPropertyChange: (name: string, addedByAdditionalProperties?: boolean) => (value: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
35
+ onPropertyChange: (name: string, addedByAdditionalProperties?: boolean) => (value: T | undefined, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => void;
36
36
  /** Returns a callback to handle the onDropPropertyClick event for the given `key` which removes the old `key` data
37
37
  * and calls the `onChange` callback with it
38
38
  *
@@ -54,7 +54,7 @@ declare class ObjectField<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
54
54
  * @param oldValue - The old value of a field
55
55
  * @returns - The key change callback function
56
56
  */
57
- onKeyChange: (oldValue: any) => (value: any, newErrorSchema: ErrorSchema<T>) => void;
57
+ onKeyChange: (oldValue: any) => (value: any) => void;
58
58
  /** Returns a default value to be used for a new additional schema property of the given `type`
59
59
  *
60
60
  * @param type - The type of the new additional schema property
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAIL,WAAW,EACX,UAAU,EACV,eAAe,EAGf,UAAU,EACV,gBAAgB,EAOjB,MAAM,aAAa,CAAC;AAQrB,6DAA6D;AAC7D,KAAK,gBAAgB,GAAG;IACtB,sEAAsE;IACtE,sBAAsB,EAAE,OAAO,CAAC;IAChC,uCAAuC;IACvC,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,cAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACpH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,gBAAgB,CACjB;IACC,+BAA+B;IAC/B,KAAK;;;MAGH;IAEF;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;IAKvB;;;;;;;OAOG;IACH,gBAAgB,GAAI,MAAM,MAAM,EAAE,qCAAmC,MAC3D,OAAO,CAAC,GAAG,SAAS,EAAE,iBAAiB,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,UAuB1E;IAEF;;;;;OAKG;IACH,mBAAmB,GAAI,KAAK,MAAM,MACxB,OAAO,SAAS,UAOxB;IAEF;;;;;;OAMG;IACH,eAAe,GAAI,cAAc,MAAM,EAAE,WAAW,CAAC,YAUnD;IAEF;;;;;OAKG;IACH,WAAW,GAAI,UAAU,GAAG,MAClB,OAAO,GAAG,EAAE,gBAAgB,WAAW,CAAC,CAAC,CAAC,UA4BlD;IAEF;;;OAGG;IACH,eAAe,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC;IAsBzC;;;;OAIG;IACH,cAAc,GAAI,QAAQ,CAAC,gBAqCzB;IAEF;OACG;IACH,MAAM;CAuGP;AAED,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAML,WAAW,EACX,aAAa,EACb,UAAU,EACV,eAAe,EAEf,UAAU,EACV,gBAAgB,EAQjB,MAAM,aAAa,CAAC;AAQrB,6DAA6D;AAC7D,KAAK,gBAAgB,GAAG;IACtB,sEAAsE;IACtE,sBAAsB,EAAE,OAAO,CAAC;IAChC,uCAAuC;IACvC,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,cAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,gBAAgB,GAAG,UAAU,EAAE,CAAC,SAAS,eAAe,GAAG,GAAG,CAAE,SAAQ,SAAS,CACpH,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnB,gBAAgB,CACjB;IACC,+BAA+B;IAC/B,KAAK;;;MAGH;IAEF;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;IAKvB;;;;;;;OAOG;IACH,gBAAgB,GAAI,MAAM,MAAM,EAAE,qCAAmC,MAC3D,OAAO,CAAC,GAAG,SAAS,EAAE,MAAM,aAAa,EAAE,iBAAiB,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,UAc/F;IAEF;;;;;OAKG;IACH,mBAAmB,GAAI,KAAK,MAAM,MACxB,OAAO,SAAS,UAQxB;IAEF;;;;;;OAMG;IACH,eAAe,GAAI,cAAc,MAAM,EAAE,WAAW,CAAC,YAUnD;IAEF;;;;;OAKG;IACH,WAAW,GAAI,UAAU,GAAG,MAClB,OAAO,GAAG,UAqBlB;IAEF;;;OAGG;IACH,eAAe,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC;IAsBzC;;;;OAIG;IACH,cAAc,GAAI,QAAQ,CAAC,gBAsCzB;IAEF;OACG;IACH,MAAM;CA4GP;AAED,eAAe,WAAW,CAAC"}