@rjsf/utils 6.0.0-beta.8 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/{index.js → index.cjs} +563 -200
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/utils.esm.js +562 -199
  4. package/dist/utils.esm.js.map +4 -4
  5. package/dist/utils.umd.js +533 -193
  6. package/lib/ErrorSchemaBuilder.d.ts +2 -2
  7. package/lib/constants.d.ts +3 -0
  8. package/lib/constants.js +3 -0
  9. package/lib/constants.js.map +1 -1
  10. package/lib/createSchemaUtils.js +25 -18
  11. package/lib/createSchemaUtils.js.map +1 -1
  12. package/lib/enums.d.ts +13 -3
  13. package/lib/enums.js +13 -3
  14. package/lib/enums.js.map +1 -1
  15. package/lib/findSchemaDefinition.d.ts +6 -0
  16. package/lib/findSchemaDefinition.js +44 -3
  17. package/lib/findSchemaDefinition.js.map +1 -1
  18. package/lib/getDateElementProps.d.ts +1 -2
  19. package/lib/getTestIds.js +2 -2
  20. package/lib/getTestIds.js.map +1 -1
  21. package/lib/getUiOptions.js +4 -0
  22. package/lib/getUiOptions.js.map +1 -1
  23. package/lib/getWidget.js +3 -3
  24. package/lib/getWidget.js.map +1 -1
  25. package/lib/guessType.d.ts +1 -1
  26. package/lib/idGenerators.d.ts +22 -15
  27. package/lib/idGenerators.js +17 -8
  28. package/lib/idGenerators.js.map +1 -1
  29. package/lib/index.d.ts +16 -6
  30. package/lib/index.js +13 -4
  31. package/lib/index.js.map +1 -1
  32. package/lib/isFormDataAvailable.d.ts +7 -0
  33. package/lib/isFormDataAvailable.js +13 -0
  34. package/lib/isFormDataAvailable.js.map +1 -0
  35. package/lib/isRootSchema.d.ts +13 -0
  36. package/lib/isRootSchema.js +25 -0
  37. package/lib/isRootSchema.js.map +1 -0
  38. package/lib/mergeDefaultsWithFormData.js +14 -2
  39. package/lib/mergeDefaultsWithFormData.js.map +1 -1
  40. package/lib/nameGenerators.d.ts +13 -0
  41. package/lib/nameGenerators.js +30 -0
  42. package/lib/nameGenerators.js.map +1 -0
  43. package/lib/schema/getDefaultFormState.d.ts +17 -3
  44. package/lib/schema/getDefaultFormState.js +66 -26
  45. package/lib/schema/getDefaultFormState.js.map +1 -1
  46. package/lib/schema/getDisplayLabel.js +2 -2
  47. package/lib/schema/getDisplayLabel.js.map +1 -1
  48. package/lib/schema/index.d.ts +1 -2
  49. package/lib/schema/index.js +1 -2
  50. package/lib/schema/index.js.map +1 -1
  51. package/lib/schema/retrieveSchema.d.ts +10 -5
  52. package/lib/schema/retrieveSchema.js +40 -17
  53. package/lib/schema/retrieveSchema.js.map +1 -1
  54. package/lib/shallowEquals.d.ts +8 -0
  55. package/lib/shallowEquals.js +36 -0
  56. package/lib/shallowEquals.js.map +1 -0
  57. package/lib/shouldRender.d.ts +8 -2
  58. package/lib/shouldRender.js +17 -2
  59. package/lib/shouldRender.js.map +1 -1
  60. package/lib/shouldRenderOptionalField.d.ts +18 -0
  61. package/lib/shouldRenderOptionalField.js +47 -0
  62. package/lib/shouldRenderOptionalField.js.map +1 -0
  63. package/lib/toFieldPathId.d.ts +14 -0
  64. package/lib/toFieldPathId.js +26 -0
  65. package/lib/toFieldPathId.js.map +1 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/types.d.ts +196 -105
  68. package/lib/useAltDateWidgetProps.d.ts +39 -0
  69. package/lib/useAltDateWidgetProps.js +71 -0
  70. package/lib/useAltDateWidgetProps.js.map +1 -0
  71. package/lib/useDeepCompareMemo.d.ts +8 -0
  72. package/lib/useDeepCompareMemo.js +17 -0
  73. package/lib/useDeepCompareMemo.js.map +1 -0
  74. package/lib/useFileWidgetProps.d.ts +29 -0
  75. package/lib/useFileWidgetProps.js +119 -0
  76. package/lib/useFileWidgetProps.js.map +1 -0
  77. package/lib/validationDataMerge.d.ts +2 -1
  78. package/lib/validationDataMerge.js +3 -2
  79. package/lib/validationDataMerge.js.map +1 -1
  80. package/package.json +13 -14
  81. package/src/ErrorSchemaBuilder.ts +2 -2
  82. package/src/constants.ts +3 -0
  83. package/src/createSchemaUtils.ts +25 -26
  84. package/src/enums.ts +13 -3
  85. package/src/findSchemaDefinition.ts +51 -3
  86. package/src/getDateElementProps.ts +1 -1
  87. package/src/getTestIds.ts +2 -2
  88. package/src/getUiOptions.ts +4 -0
  89. package/src/getWidget.tsx +3 -3
  90. package/src/idGenerators.ts +35 -25
  91. package/src/index.ts +36 -5
  92. package/src/isFormDataAvailable.ts +13 -0
  93. package/src/isRootSchema.ts +30 -0
  94. package/src/mergeDefaultsWithFormData.ts +16 -2
  95. package/src/nameGenerators.ts +43 -0
  96. package/src/schema/getDefaultFormState.ts +87 -31
  97. package/src/schema/getDisplayLabel.ts +2 -2
  98. package/src/schema/index.ts +0 -2
  99. package/src/schema/retrieveSchema.ts +43 -7
  100. package/src/shallowEquals.ts +41 -0
  101. package/src/shouldRender.ts +27 -2
  102. package/src/shouldRenderOptionalField.ts +56 -0
  103. package/src/toFieldPathId.ts +34 -0
  104. package/src/types.ts +229 -113
  105. package/src/useAltDateWidgetProps.tsx +163 -0
  106. package/src/useDeepCompareMemo.ts +17 -0
  107. package/src/useFileWidgetProps.ts +155 -0
  108. package/src/validationDataMerge.ts +7 -1
  109. package/dist/index.js.map +0 -7
  110. package/lib/schema/toIdSchema.d.ts +0 -14
  111. package/lib/schema/toIdSchema.js +0 -62
  112. package/lib/schema/toIdSchema.js.map +0 -1
  113. package/src/schema/toIdSchema.ts +0 -131
@@ -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>;
@@ -1,62 +0,0 @@
1
- import get from 'lodash-es/get.js';
2
- import { ALL_OF_KEY, DEPENDENCIES_KEY, ID_KEY, ITEMS_KEY, PROPERTIES_KEY, REF_KEY } from '../constants.js';
3
- import retrieveSchema from './retrieveSchema.js';
4
- import getSchemaType from '../getSchemaType.js';
5
- import deepEquals from '../deepEquals.js';
6
- /** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
7
- * infinite recursion
8
- *
9
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
10
- * @param schema - The schema for which the `IdSchema` is desired
11
- * @param idPrefix - The prefix to use for the id
12
- * @param idSeparator - The separator to use for the path segments in the id
13
- * @param [id] - The base id for the schema
14
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
15
- * @param [formData] - The current formData, if any, to assist retrieving a schema
16
- * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
17
- * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
18
- * @returns - The `IdSchema` object for the `schema`
19
- */
20
- function toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList = [], experimental_customMergeAllOf) {
21
- const $id = id || idPrefix;
22
- const idSchema = { $id };
23
- if (typeof schema === 'object') {
24
- if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
25
- const _schema = retrieveSchema(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
26
- const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
27
- if (sameSchemaIndex === -1) {
28
- return toIdSchemaInternal(validator, _schema, idPrefix, idSeparator, id, rootSchema, formData, _recurseList.concat(_schema), experimental_customMergeAllOf);
29
- }
30
- }
31
- if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
32
- return toIdSchemaInternal(validator, get(schema, ITEMS_KEY), idPrefix, idSeparator, id, rootSchema, formData, _recurseList, experimental_customMergeAllOf);
33
- }
34
- if (getSchemaType(schema) === 'object' && PROPERTIES_KEY in schema) {
35
- for (const name in schema.properties) {
36
- const field = schema[PROPERTIES_KEY][name];
37
- const fieldId = idSchema[ID_KEY] + idSeparator + name;
38
- idSchema[name] = toIdSchemaInternal(validator, field, idPrefix, idSeparator, fieldId, rootSchema,
39
- // It's possible that formData is not an object -- this can happen if an
40
- // array item has just been added, but not populated with data yet
41
- get(formData, [name]), _recurseList, experimental_customMergeAllOf);
42
- }
43
- }
44
- }
45
- return idSchema;
46
- }
47
- /** Generates an `IdSchema` object for the `schema`, recursively
48
- *
49
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
50
- * @param schema - The schema for which the `IdSchema` is desired
51
- * @param [id] - The base id for the schema
52
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
53
- * @param [formData] - The current formData, if any, to assist retrieving a schema
54
- * @param [idPrefix='root'] - The prefix to use for the id
55
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
56
- * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
57
- * @returns - The `IdSchema` object for the `schema`
58
- */
59
- export default function toIdSchema(validator, schema, id, rootSchema, formData, idPrefix = 'root', idSeparator = '_', experimental_customMergeAllOf) {
60
- return toIdSchemaInternal(validator, schema, idPrefix, idSeparator, id, rootSchema, formData, undefined, experimental_customMergeAllOf);
61
- }
62
- //# sourceMappingURL=toIdSchema.js.map
@@ -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CAAC;AACJ,CAAC"}
@@ -1,131 +0,0 @@
1
- import get from 'lodash/get';
2
-
3
- import { ALL_OF_KEY, DEPENDENCIES_KEY, ID_KEY, ITEMS_KEY, PROPERTIES_KEY, REF_KEY } from '../constants';
4
- import {
5
- Experimental_CustomMergeAllOf,
6
- FormContextType,
7
- GenericObjectType,
8
- IdSchema,
9
- RJSFSchema,
10
- StrictRJSFSchema,
11
- ValidatorType,
12
- } from '../types';
13
- import retrieveSchema from './retrieveSchema';
14
- import getSchemaType from '../getSchemaType';
15
- import deepEquals from '../deepEquals';
16
-
17
- /** An internal helper that generates an `IdSchema` object for the `schema`, recursively with protection against
18
- * infinite recursion
19
- *
20
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
21
- * @param schema - The schema for which the `IdSchema` is desired
22
- * @param idPrefix - The prefix to use for the id
23
- * @param idSeparator - The separator to use for the path segments in the id
24
- * @param [id] - The base id for the schema
25
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
26
- * @param [formData] - The current formData, if any, to assist retrieving a schema
27
- * @param [_recurseList=[]] - The list of retrieved schemas currently being recursed, used to prevent infinite recursion
28
- * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
29
- * @returns - The `IdSchema` object for the `schema`
30
- */
31
- function toIdSchemaInternal<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
32
- validator: ValidatorType<T, S, F>,
33
- schema: S,
34
- idPrefix: string,
35
- idSeparator: string,
36
- id?: string | null,
37
- rootSchema?: S,
38
- formData?: T,
39
- _recurseList: S[] = [],
40
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
41
- ): IdSchema<T> {
42
- const $id = id || idPrefix;
43
- const idSchema: IdSchema<T> = { $id } as IdSchema<T>;
44
- if (typeof schema === 'object') {
45
- if (REF_KEY in schema || DEPENDENCIES_KEY in schema || ALL_OF_KEY in schema) {
46
- const _schema = retrieveSchema<T, S, F>(validator, schema, rootSchema, formData, experimental_customMergeAllOf);
47
- const sameSchemaIndex = _recurseList.findIndex((item) => deepEquals(item, _schema));
48
- if (sameSchemaIndex === -1) {
49
- return toIdSchemaInternal<T, S, F>(
50
- validator,
51
- _schema,
52
- idPrefix,
53
- idSeparator,
54
- id,
55
- rootSchema,
56
- formData,
57
- _recurseList.concat(_schema),
58
- experimental_customMergeAllOf,
59
- );
60
- }
61
- }
62
- if (ITEMS_KEY in schema && !get(schema, [ITEMS_KEY, REF_KEY])) {
63
- return toIdSchemaInternal<T, S, F>(
64
- validator,
65
- get(schema, ITEMS_KEY) as S,
66
- idPrefix,
67
- idSeparator,
68
- id,
69
- rootSchema,
70
- formData,
71
- _recurseList,
72
- experimental_customMergeAllOf,
73
- );
74
- }
75
- if (getSchemaType<S>(schema) === 'object' && PROPERTIES_KEY in schema) {
76
- for (const name in schema.properties) {
77
- const field: S = schema[PROPERTIES_KEY][name] as S;
78
- const fieldId = idSchema[ID_KEY] + idSeparator + name;
79
- (idSchema as IdSchema<GenericObjectType>)[name] = toIdSchemaInternal<T, S, F>(
80
- validator,
81
- field,
82
- idPrefix,
83
- idSeparator,
84
- fieldId,
85
- rootSchema,
86
- // It's possible that formData is not an object -- this can happen if an
87
- // array item has just been added, but not populated with data yet
88
- get(formData, [name]),
89
- _recurseList,
90
- experimental_customMergeAllOf,
91
- );
92
- }
93
- }
94
- }
95
- return idSchema;
96
- }
97
-
98
- /** Generates an `IdSchema` object for the `schema`, recursively
99
- *
100
- * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary
101
- * @param schema - The schema for which the `IdSchema` is desired
102
- * @param [id] - The base id for the schema
103
- * @param [rootSchema] - The root schema, used to primarily to look up `$ref`s
104
- * @param [formData] - The current formData, if any, to assist retrieving a schema
105
- * @param [idPrefix='root'] - The prefix to use for the id
106
- * @param [idSeparator='_'] - The separator to use for the path segments in the id
107
- * @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
108
- * @returns - The `IdSchema` object for the `schema`
109
- */
110
- export default function toIdSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
111
- validator: ValidatorType<T, S, F>,
112
- schema: S,
113
- id?: string | null,
114
- rootSchema?: S,
115
- formData?: T,
116
- idPrefix = 'root',
117
- idSeparator = '_',
118
- experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
119
- ): IdSchema<T> {
120
- return toIdSchemaInternal<T, S, F>(
121
- validator,
122
- schema,
123
- idPrefix,
124
- idSeparator,
125
- id,
126
- rootSchema,
127
- formData,
128
- undefined,
129
- experimental_customMergeAllOf,
130
- );
131
- }