@rjsf/utils 6.6.1 → 6.7.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.
- package/LICENSE.md +201 -0
- package/dist/index.cjs +534 -376
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +534 -376
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +561 -400
- package/lib/ErrorSchemaBuilder.d.ts +1 -1
- package/lib/SelectedOptionDescription.d.ts +4 -0
- package/lib/SelectedOptionDescription.js +24 -0
- package/lib/SelectedOptionDescription.js.map +1 -0
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -0
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js +2 -0
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +1 -1
- package/lib/constIsAjvDataReference.d.ts +1 -1
- package/lib/constants.d.ts +8 -5
- package/lib/constants.js +10 -7
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -6
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +1 -1
- package/lib/createSchemaUtils.js +3 -1
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js +3 -3
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +8 -7
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/enumOptionSelectedValue.d.ts +1 -1
- package/lib/enumOptionValueDecoder.d.ts +1 -1
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -2
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +4 -0
- package/lib/enums.js +4 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +1 -1
- package/lib/findSchemaDefinition.js +15 -15
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.js +4 -6
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +3 -3
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +10 -11
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +1 -1
- package/lib/getSchemaType.d.ts +1 -1
- package/lib/getSchemaType.js +2 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +1 -1
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTestIds.d.ts +1 -1
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -1
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +4 -4
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.js +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hashForSchema.d.ts +3 -1
- package/lib/hashForSchema.js +11 -4
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +1 -1
- package/lib/index.d.ts +14 -7
- package/lib/index.js +5 -2
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +3 -3
- package/lib/isFixedItems.js +3 -3
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isRootSchema.d.ts +1 -1
- package/lib/isRootSchema.js +2 -3
- package/lib/isRootSchema.js.map +1 -1
- package/lib/labelValue.d.ts +1 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts +9 -0
- package/lib/logUnsupportedDefaultForEnum.js +18 -0
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -0
- package/lib/lookupFromFormContext.d.ts +1 -1
- package/lib/mergeDefaultsWithFormData.js +6 -5
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +4 -2
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +4 -2
- package/lib/mergeSchemas.js +13 -6
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +1 -1
- package/lib/optionsList.d.ts +1 -1
- package/lib/optionsList.js +22 -21
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js +3 -3
- package/lib/orderProperties.js.map +1 -1
- package/lib/pad.js +1 -1
- package/lib/pad.js.map +1 -1
- package/lib/parseDateString.d.ts +1 -1
- package/lib/parseDateString.js +1 -1
- package/lib/parseDateString.js.map +1 -1
- package/lib/parser/ParserValidator.d.ts +2 -4
- package/lib/parser/ParserValidator.js +2 -0
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +7 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +1 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/removeOptionalEmptyObjects.d.ts +1 -1
- package/lib/removeOptionalEmptyObjects.js +6 -8
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/resolveUiSchema.d.ts +1 -1
- package/lib/resolveUiSchema.js +16 -16
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.js +1 -3
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +1 -1
- package/lib/schema/getClosestMatchingOption.js +6 -9
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +4 -4
- package/lib/schema/getDefaultFormState.js +81 -43
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +1 -1
- package/lib/schema/getDisplayLabel.js +2 -3
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +2 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +1 -1
- package/lib/schema/index.js +9 -3
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +1 -1
- package/lib/schema/isMultiSelect.d.ts +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +1 -1
- package/lib/schema/isSelect.js +1 -1
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +1 -1
- package/lib/schema/omitExtraData.js +66 -52
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +7 -3
- package/lib/schema/retrieveSchema.js +83 -56
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +1 -1
- package/lib/schema/sanitizeDataForNewSchema.js +48 -7
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +1 -1
- package/lib/schema/toPathSchema.js +9 -5
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js +4 -3
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.js +2 -2
- package/lib/shallowEquals.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +3 -3
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toFieldPathId.d.ts +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +63 -57
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +7 -9
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +6 -6
- package/lib/useAltDateWidgetProps.js +3 -3
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +2 -2
- package/lib/useFileWidgetProps.js +3 -3
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +12 -12
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +19 -19
- package/src/ErrorSchemaBuilder.ts +1 -1
- package/src/SelectedOptionDescription.tsx +48 -0
- package/src/allowAdditionalItems.ts +2 -1
- package/src/asNumber.ts +2 -0
- package/src/canExpand.ts +1 -1
- package/src/constIsAjvDataReference.ts +2 -2
- package/src/constants.ts +10 -7
- package/src/createErrorHandler.ts +6 -7
- package/src/createSchemaUtils.ts +4 -2
- package/src/dataURItoBlob.ts +3 -3
- package/src/dateRangeOptions.ts +9 -7
- package/src/englishStringTranslator.ts +1 -1
- package/src/enumOptionSelectedValue.ts +1 -1
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +1 -1
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +1 -1
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +2 -2
- package/src/enums.ts +4 -0
- package/src/findSchemaDefinition.ts +18 -17
- package/src/getChangedFields.ts +5 -5
- package/src/getDateElementProps.ts +3 -3
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +1 -1
- package/src/getOptionMatchingSimpleDiscriminator.ts +11 -15
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +1 -1
- package/src/getUiOptions.ts +10 -2
- package/src/getWidget.tsx +5 -6
- package/src/guessType.ts +1 -1
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +12 -5
- package/src/idGenerators.ts +1 -1
- package/src/index.ts +16 -5
- package/src/isConstant.ts +1 -1
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +4 -4
- package/src/isRootSchema.ts +3 -5
- package/src/labelValue.ts +1 -1
- package/src/logUnsupportedDefaultForEnum.ts +28 -0
- package/src/lookupFromFormContext.ts +1 -1
- package/src/mergeDefaultsWithFormData.ts +8 -7
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +14 -7
- package/src/nameGenerators.ts +1 -1
- package/src/optionsList.ts +21 -23
- package/src/orderProperties.ts +4 -4
- package/src/pad.ts +1 -1
- package/src/parseDateString.ts +2 -2
- package/src/parser/ParserValidator.ts +4 -4
- package/src/parser/index.ts +1 -1
- package/src/parser/schemaParser.ts +10 -9
- package/src/rangeSpec.ts +1 -2
- package/src/removeOptionalEmptyObjects.ts +8 -11
- package/src/resolveUiSchema.ts +32 -25
- package/src/schema/findFieldInSchema.ts +1 -1
- package/src/schema/findSelectedOptionInXxxOf.ts +17 -7
- package/src/schema/getClosestMatchingOption.ts +17 -11
- package/src/schema/getDefaultFormState.ts +104 -43
- package/src/schema/getDisplayLabel.ts +4 -5
- package/src/schema/getFirstMatchingOption.ts +3 -3
- package/src/schema/getFromSchema.ts +1 -1
- package/src/schema/index.ts +3 -0
- package/src/schema/isFilesArray.ts +1 -1
- package/src/schema/isMultiSelect.ts +7 -1
- package/src/schema/isSelect.ts +8 -2
- package/src/schema/omitExtraData.ts +73 -60
- package/src/schema/retrieveSchema.ts +131 -83
- package/src/schema/sanitizeDataForNewSchema.ts +57 -8
- package/src/schema/toPathSchema.ts +11 -7
- package/src/schemaRequiresTrueValue.ts +4 -4
- package/src/shallowEquals.ts +2 -2
- package/src/shouldRenderOptionalField.ts +1 -1
- package/src/toConstant.ts +1 -1
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +4 -4
- package/src/toErrorSchema.ts +1 -1
- package/src/toFieldPathId.ts +1 -1
- package/src/types.ts +92 -63
- package/src/unwrapErrorHandler.ts +11 -12
- package/src/useAltDateWidgetProps.tsx +10 -8
- package/src/useFileWidgetProps.ts +7 -7
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +12 -12
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
|
|
3
3
|
import { PROPERTIES_KEY } from './constants';
|
|
4
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
4
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
5
5
|
|
|
6
6
|
/** Compares the value of `discriminatorField` within `formData` against the value of `discriminatorField` within schema for each `option`.
|
|
7
7
|
* Returns index of first `option` whose discriminator matches formData. Returns `undefined` if there is no match.
|
|
@@ -22,26 +22,22 @@ export default function getOptionMatchingSimpleDiscriminator<T = any, S extends
|
|
|
22
22
|
const value = get(formData, discriminatorField);
|
|
23
23
|
|
|
24
24
|
if (value === undefined) {
|
|
25
|
-
return;
|
|
25
|
+
return undefined;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
for (let i = 0; i < options.length; i
|
|
28
|
+
for (let i = 0; i < options.length; i += 1) {
|
|
29
29
|
const option = options[i];
|
|
30
30
|
const discriminator: S = get(option, [PROPERTIES_KEY, discriminatorField], {}) as S;
|
|
31
31
|
|
|
32
|
-
if (discriminator.type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (discriminator.enum?.includes(value)) {
|
|
41
|
-
return i;
|
|
32
|
+
if (discriminator.type !== 'object' && discriminator.type !== 'array') {
|
|
33
|
+
if (discriminator.const === value) {
|
|
34
|
+
return i;
|
|
35
|
+
}
|
|
36
|
+
if (discriminator.enum?.includes(value)) {
|
|
37
|
+
return i;
|
|
38
|
+
}
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
|
|
46
|
-
return;
|
|
42
|
+
return undefined;
|
|
47
43
|
}
|
package/src/getSchemaType.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import guessType from './guessType';
|
|
2
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Gets the type of a given `schema`. If the type is not explicitly defined, then an attempt is made to infer it from
|
|
5
5
|
* other elements of the schema as follows:
|
|
@@ -32,8 +32,9 @@ export default function getSchemaType<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
32
32
|
|
|
33
33
|
if (Array.isArray(type)) {
|
|
34
34
|
if (type.length === 2 && type.includes('null')) {
|
|
35
|
-
type = type.find((
|
|
35
|
+
type = type.find((t) => t !== 'null');
|
|
36
36
|
} else {
|
|
37
|
+
// oxlint-disable-next-line prefer-destructuring
|
|
37
38
|
type = type[0];
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SUBMIT_BTN_OPTIONS_KEY } from './constants';
|
|
2
2
|
import getUiOptions from './getUiOptions';
|
|
3
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, UISchemaSubmitButtonOptions } from './types';
|
|
3
|
+
import type { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema, UISchemaSubmitButtonOptions } from './types';
|
|
4
4
|
|
|
5
5
|
/** The default submit button options, exported for testing purposes
|
|
6
6
|
*/
|
|
@@ -23,8 +23,8 @@ export default function getSubmitButtonOptions<
|
|
|
23
23
|
F extends FormContextType = any,
|
|
24
24
|
>(uiSchema: UiSchema<T, S, F> = {}): UISchemaSubmitButtonOptions {
|
|
25
25
|
const uiOptions = getUiOptions<T, S, F>(uiSchema);
|
|
26
|
-
if (uiOptions
|
|
27
|
-
const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY]
|
|
26
|
+
if (uiOptions?.[SUBMIT_BTN_OPTIONS_KEY]) {
|
|
27
|
+
const options = uiOptions[SUBMIT_BTN_OPTIONS_KEY];
|
|
28
28
|
return { ...DEFAULT_OPTIONS, ...options };
|
|
29
29
|
}
|
|
30
30
|
|
package/src/getTemplate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormContextType, TemplatesType, Registry, UIOptionsType, StrictRJSFSchema, RJSFSchema } from './types';
|
|
1
|
+
import type { FormContextType, TemplatesType, Registry, UIOptionsType, StrictRJSFSchema, RJSFSchema } from './types';
|
|
2
2
|
|
|
3
3
|
/** Returns the template with the given `name` from either the `uiSchema` if it is defined or from the `registry`
|
|
4
4
|
* otherwise. NOTE, since `ButtonTemplates` are not overridden in `uiSchema` only those in the `registry` are returned.
|
package/src/getTestIds.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import uniqueId from 'lodash/uniqueId';
|
|
3
3
|
|
|
4
|
-
import { TestIdShape } from './types';
|
|
4
|
+
import type { TestIdShape } from './types';
|
|
5
5
|
|
|
6
6
|
/** Returns an object of test IDs that can only be used in test mode. If the function is called in a test environment
|
|
7
7
|
* (`NODE_ENV === 'test'`, this is set by vitest) then a Proxy object will be returned. If a key within the returned
|
package/src/getUiOptions.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { UI_OPTIONS_KEY, UI_WIDGET_KEY } from './constants';
|
|
2
2
|
import isObject from './isObject';
|
|
3
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
FormContextType,
|
|
5
|
+
GlobalUISchemaOptions,
|
|
6
|
+
RJSFSchema,
|
|
7
|
+
StrictRJSFSchema,
|
|
8
|
+
UIOptionsType,
|
|
9
|
+
UiSchema,
|
|
10
|
+
} from './types';
|
|
4
11
|
|
|
5
12
|
/** Get all passed options from ui:options, and ui:<optionName>, returning them in an object with the `ui:`
|
|
6
13
|
* stripped off. Any `globalOptions` will always be returned, unless they are overridden by options in the `uiSchema`.
|
|
@@ -18,11 +25,12 @@ export default function getUiOptions<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
18
25
|
return { ...globalOptions };
|
|
19
26
|
}
|
|
20
27
|
return Object.keys(uiSchema)
|
|
21
|
-
.filter((key) => key.
|
|
28
|
+
.filter((key) => key.startsWith('ui:'))
|
|
22
29
|
.reduce(
|
|
23
30
|
(options, key) => {
|
|
24
31
|
const value = uiSchema[key];
|
|
25
32
|
if (key === UI_WIDGET_KEY && isObject(value)) {
|
|
33
|
+
// oxlint-disable-next-line no-console
|
|
26
34
|
console.error('Setting options via ui:widget object is no longer supported, use ui:options instead');
|
|
27
35
|
return options;
|
|
28
36
|
}
|
package/src/getWidget.tsx
CHANGED
|
@@ -4,11 +4,11 @@ import set from 'lodash/set';
|
|
|
4
4
|
import ReactIs from 'react-is';
|
|
5
5
|
|
|
6
6
|
import getSchemaType from './getSchemaType';
|
|
7
|
-
import { FormContextType, RJSFSchema, Widget, RegistryWidgetsType, StrictRJSFSchema } from './types';
|
|
7
|
+
import type { FormContextType, RJSFSchema, Widget, RegistryWidgetsType, StrictRJSFSchema } from './types';
|
|
8
8
|
|
|
9
9
|
/** The map of schema types to widget type to widget name
|
|
10
10
|
*/
|
|
11
|
-
const widgetMap:
|
|
11
|
+
const widgetMap: Record<string, Record<string, string>> = {
|
|
12
12
|
boolean: {
|
|
13
13
|
checkbox: 'CheckboxWidget',
|
|
14
14
|
radio: 'RadioWidget',
|
|
@@ -74,10 +74,9 @@ function mergeWidgetOptions<T = any, S extends StrictRJSFSchema = RJSFSchema, F
|
|
|
74
74
|
let MergedWidget: Widget<T, S, F> | undefined = get(AWidget, 'MergedWidget');
|
|
75
75
|
// cache return value as property of widget for proper react reconciliation
|
|
76
76
|
if (!MergedWidget) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
};
|
|
77
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
78
|
+
const defaultOptions = AWidget.defaultProps?.options || {};
|
|
79
|
+
MergedWidget = ({ options, ...props }) => <AWidget options={{ ...defaultOptions, ...options }} {...props} />;
|
|
81
80
|
set(AWidget, 'MergedWidget', MergedWidget);
|
|
82
81
|
}
|
|
83
82
|
return MergedWidget;
|
package/src/guessType.ts
CHANGED
package/src/hasWidget.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getWidget from './getWidget';
|
|
2
|
-
import { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema, Widget } from './types';
|
|
2
|
+
import type { FormContextType, RegistryWidgetsType, RJSFSchema, StrictRJSFSchema, Widget } from './types';
|
|
3
3
|
|
|
4
4
|
/** Detects whether the `widget` exists for the `schema` with the associated `registryWidgets` and returns true if it
|
|
5
5
|
* does, or false if it doesn't.
|
package/src/hashForSchema.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
2
|
|
|
3
3
|
/** Hashes a string using the algorithm based on Java's hashing function.
|
|
4
4
|
* JS has no built-in hashing function, so rolling our own
|
|
@@ -10,10 +10,12 @@ import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
|
10
10
|
*/
|
|
11
11
|
export function hashString(string: string): string {
|
|
12
12
|
let hash = 0;
|
|
13
|
-
for (let i = 0; i < string.length; i
|
|
13
|
+
for (let i = 0; i < string.length; i++) {
|
|
14
14
|
const chr = string.charCodeAt(i);
|
|
15
|
+
// oxlint-disable-next-line no-bitwise
|
|
15
16
|
hash = (hash << 5) - hash + chr;
|
|
16
|
-
|
|
17
|
+
// oxlint-disable-next-line no-bitwise
|
|
18
|
+
hash &= hash; // Convert to 32bit integer
|
|
17
19
|
}
|
|
18
20
|
return hash.toString(16);
|
|
19
21
|
}
|
|
@@ -26,7 +28,10 @@ export function hashString(string: string): string {
|
|
|
26
28
|
export function sortedJSONStringify(object: unknown): string {
|
|
27
29
|
const allKeys = new Set<string>();
|
|
28
30
|
// solution source: https://stackoverflow.com/questions/16167581/sort-object-properties-and-json-stringify/53593328#53593328
|
|
29
|
-
JSON.stringify(object, (key, value) =>
|
|
31
|
+
JSON.stringify(object, (key, value) => {
|
|
32
|
+
allKeys.add(key);
|
|
33
|
+
return value;
|
|
34
|
+
});
|
|
30
35
|
return JSON.stringify(object, Array.from(allKeys).sort());
|
|
31
36
|
}
|
|
32
37
|
|
|
@@ -42,10 +47,12 @@ export function hashObject(object: unknown): string {
|
|
|
42
47
|
|
|
43
48
|
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
|
|
44
49
|
* in consistent order before stringify to prevent different hash ids for the same schema.
|
|
50
|
+
* Symbol-keyed properties (RJSF_REF_KEY, RJSF_REF_CYCLE_KEY, ADDITIONAL_PROPERTY_FLAG) are
|
|
51
|
+
* automatically excluded by JSON.stringify, so no special filtering is needed.
|
|
45
52
|
*
|
|
46
53
|
* @param schema - The schema for which the hash is desired
|
|
47
54
|
* @returns - The string obtained from the hash of the stringified schema
|
|
48
55
|
*/
|
|
49
56
|
export default function hashForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
|
|
50
|
-
return
|
|
57
|
+
return hashString(sortedJSONStringify(schema));
|
|
51
58
|
}
|
package/src/idGenerators.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -18,7 +18,8 @@ import enumOptionValueEncoder from './enumOptionValueEncoder';
|
|
|
18
18
|
import ErrorSchemaBuilder from './ErrorSchemaBuilder';
|
|
19
19
|
import findSchemaDefinition from './findSchemaDefinition';
|
|
20
20
|
import getChangedFields from './getChangedFields';
|
|
21
|
-
import
|
|
21
|
+
import type { DateElementFormat, DateElementProp } from './getDateElementProps';
|
|
22
|
+
import getDateElementProps from './getDateElementProps';
|
|
22
23
|
import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema';
|
|
23
24
|
import getInputProps from './getInputProps';
|
|
24
25
|
import getOptionMatchingSimpleDiscriminator from './getOptionMatchingSimpleDiscriminator';
|
|
@@ -51,6 +52,7 @@ import isObject from './isObject';
|
|
|
51
52
|
import isRootSchema from './isRootSchema';
|
|
52
53
|
import labelValue from './labelValue';
|
|
53
54
|
import localToUTC from './localToUTC';
|
|
55
|
+
import logUnsupportedDefaultForEnum from './logUnsupportedDefaultForEnum';
|
|
54
56
|
import lookupFromFormContext from './lookupFromFormContext';
|
|
55
57
|
import mergeDefaultsWithFormData from './mergeDefaultsWithFormData';
|
|
56
58
|
import mergeObjects from './mergeObjects';
|
|
@@ -65,8 +67,11 @@ import removeOptionalEmptyObjects from './removeOptionalEmptyObjects';
|
|
|
65
67
|
import replaceStringParameters from './replaceStringParameters';
|
|
66
68
|
import resolveUiSchema from './resolveUiSchema';
|
|
67
69
|
import schemaRequiresTrueValue from './schemaRequiresTrueValue';
|
|
70
|
+
import SelectedOptionDescription from './SelectedOptionDescription';
|
|
71
|
+
import type { SelectedOptionDescriptionProps } from './SelectedOptionDescription';
|
|
68
72
|
import shallowEquals from './shallowEquals';
|
|
69
|
-
import
|
|
73
|
+
import type { ComponentUpdateStrategy } from './shouldRender';
|
|
74
|
+
import shouldRender from './shouldRender';
|
|
70
75
|
import shouldRenderOptionalField from './shouldRenderOptionalField';
|
|
71
76
|
import toConstant from './toConstant';
|
|
72
77
|
import toDateString from './toDateString';
|
|
@@ -74,14 +79,16 @@ import toErrorList from './toErrorList';
|
|
|
74
79
|
import toErrorSchema from './toErrorSchema';
|
|
75
80
|
import toFieldPathId from './toFieldPathId';
|
|
76
81
|
import unwrapErrorHandler from './unwrapErrorHandler';
|
|
77
|
-
import
|
|
82
|
+
import type { DateElementProps, UseAltDateWidgetResult } from './useAltDateWidgetProps';
|
|
83
|
+
import useAltDateWidgetProps, { DateElement } from './useAltDateWidgetProps';
|
|
78
84
|
import useDeepCompareMemo from './useDeepCompareMemo';
|
|
79
|
-
import
|
|
85
|
+
import type { FileInfoType, UseFileWidgetPropsResult } from './useFileWidgetProps';
|
|
86
|
+
import useFileWidgetProps from './useFileWidgetProps';
|
|
80
87
|
import utcToLocal from './utcToLocal';
|
|
81
88
|
import validationDataMerge from './validationDataMerge';
|
|
82
89
|
import withIdRefPrefix from './withIdRefPrefix';
|
|
83
90
|
|
|
84
|
-
export * from './types';
|
|
91
|
+
export type * from './types';
|
|
85
92
|
export * from './enums';
|
|
86
93
|
|
|
87
94
|
export * from './constants';
|
|
@@ -94,6 +101,7 @@ export type {
|
|
|
94
101
|
DateElementProp,
|
|
95
102
|
DateElementProps,
|
|
96
103
|
FileInfoType,
|
|
104
|
+
SelectedOptionDescriptionProps,
|
|
97
105
|
UseAltDateWidgetResult,
|
|
98
106
|
UseFileWidgetPropsResult,
|
|
99
107
|
};
|
|
@@ -150,6 +158,7 @@ export {
|
|
|
150
158
|
isRootSchema,
|
|
151
159
|
labelValue,
|
|
152
160
|
localToUTC,
|
|
161
|
+
logUnsupportedDefaultForEnum,
|
|
153
162
|
lookupFromFormContext,
|
|
154
163
|
mergeDefaultsWithFormData,
|
|
155
164
|
mergeObjects,
|
|
@@ -161,10 +170,12 @@ export {
|
|
|
161
170
|
pad,
|
|
162
171
|
parseDateString,
|
|
163
172
|
rangeSpec,
|
|
173
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
164
174
|
removeOptionalEmptyObjects,
|
|
165
175
|
replaceStringParameters,
|
|
166
176
|
resolveUiSchema,
|
|
167
177
|
schemaRequiresTrueValue,
|
|
178
|
+
SelectedOptionDescription,
|
|
168
179
|
shallowEquals,
|
|
169
180
|
shouldRender,
|
|
170
181
|
shouldRenderOptionalField,
|
package/src/isConstant.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CONST_KEY } from './constants';
|
|
2
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** This function checks if the given `schema` matches a single constant value. This happens when either the schema has
|
|
5
5
|
* an `enum` array with a single value or there is a `const` defined.
|
package/src/isCustomWidget.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getUiOptions from './getUiOptions';
|
|
2
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
|
|
2
|
+
import type { FormContextType, RJSFSchema, StrictRJSFSchema, UiSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Checks to see if the `uiSchema` contains the `widget` field and that the widget is not `hidden`
|
|
5
5
|
*
|
|
@@ -14,6 +14,6 @@ export default function isCustomWidget<
|
|
|
14
14
|
return (
|
|
15
15
|
// TODO: Remove the `&& uiSchema['ui:widget'] !== 'hidden'` once we support hidden widgets for arrays.
|
|
16
16
|
// https://rjsf-team.github.io/react-jsonschema-form/docs/usage/widgets/#hidden-widgets
|
|
17
|
-
'widget' in getUiOptions<T, S, F>(uiSchema) && getUiOptions<T, S, F>(uiSchema)
|
|
17
|
+
'widget' in getUiOptions<T, S, F>(uiSchema) && getUiOptions<T, S, F>(uiSchema).widget !== 'hidden'
|
|
18
18
|
);
|
|
19
19
|
}
|
package/src/isFixedItems.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import isObject from './isObject';
|
|
2
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
|
-
/** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is
|
|
5
|
-
*
|
|
4
|
+
/** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is an array that only
|
|
5
|
+
* contains objects.
|
|
6
6
|
*
|
|
7
7
|
* @param schema - The schema in which to check for fixed items
|
|
8
8
|
* @returns - True if there are fixed items in the schema, false otherwise
|
|
9
9
|
*/
|
|
10
10
|
export default function isFixedItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
|
|
11
|
-
return Array.isArray(schema.items) && schema.items.
|
|
11
|
+
return Array.isArray(schema.items) && schema.items.every((item) => isObject(item));
|
|
12
12
|
}
|
package/src/isRootSchema.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { REF_KEY, RJSF_REF_KEY } from './constants';
|
|
1
|
+
import { REF_KEY } from './constants';
|
|
4
2
|
import deepEquals from './deepEquals';
|
|
5
|
-
import { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
|
+
import type { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types';
|
|
6
4
|
|
|
7
5
|
/** Helper to check whether a JSON schema object is the root schema. The schema is a root schema with root `properties`
|
|
8
6
|
* key or a root `$ref` key. If the `schemaToCompare` has a root `oneOf` property, the function will
|
|
@@ -25,7 +23,7 @@ export default function isRootSchema<T = any, S extends StrictRJSFSchema = RJSFS
|
|
|
25
23
|
}
|
|
26
24
|
if (REF_KEY in rootSchema) {
|
|
27
25
|
const resolvedSchema = schemaUtils.retrieveSchema(rootSchema);
|
|
28
|
-
return deepEquals(schemaToCompare,
|
|
26
|
+
return deepEquals(schemaToCompare, resolvedSchema);
|
|
29
27
|
}
|
|
30
28
|
return false;
|
|
31
29
|
}
|
package/src/labelValue.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
2
|
|
|
3
3
|
/** Helper function that will return the value to use for a widget `label` based on `hideLabel`. The `fallback` is used
|
|
4
4
|
* as the return value from the function when `hideLabel` is true. Due to the implementation of theme components, it
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import enumOptionsIndexForValue from './enumOptionsIndexForValue';
|
|
2
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
|
+
|
|
4
|
+
/** Logs a warning when a single-select enum widget has a schema default that is not one of its enum options.
|
|
5
|
+
*
|
|
6
|
+
* @param id - The field id used in the warning message
|
|
7
|
+
* @param schema - The schema whose default value is checked
|
|
8
|
+
* @param enumOptions - The enum options available to the widget
|
|
9
|
+
* @param multiple - Whether the widget allows multiple selections
|
|
10
|
+
*/
|
|
11
|
+
export default function logUnsupportedDefaultForEnum<S extends StrictRJSFSchema = RJSFSchema>(
|
|
12
|
+
id: string,
|
|
13
|
+
schema: S,
|
|
14
|
+
enumOptions?: EnumOptionsType<S>[],
|
|
15
|
+
multiple = false,
|
|
16
|
+
) {
|
|
17
|
+
if (
|
|
18
|
+
!multiple &&
|
|
19
|
+
Array.isArray(enumOptions) &&
|
|
20
|
+
schema.default !== undefined &&
|
|
21
|
+
enumOptionsIndexForValue<S>(schema.default, enumOptions, multiple) === undefined
|
|
22
|
+
) {
|
|
23
|
+
// oxlint-disable-next-line no-console
|
|
24
|
+
console.error(
|
|
25
|
+
`The schema default value "${schema.default}" is not one of the values in the enum options for "${id}"`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -2,7 +2,7 @@ import get from 'lodash/get';
|
|
|
2
2
|
import has from 'lodash/has';
|
|
3
3
|
|
|
4
4
|
import { FORM_CONTEXT_NAME, LOOKUP_MAP_NAME } from './constants';
|
|
5
|
-
import { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types';
|
|
5
|
+
import type { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types';
|
|
6
6
|
|
|
7
7
|
/** Given a React JSON Schema Form registry or formContext object, return the value associated with `toLookup`. This
|
|
8
8
|
* might be contained within the lookup map in the formContext. If no such value exists, return the `fallback`
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import get from 'lodash/get';
|
|
2
2
|
import isNil from 'lodash/isNil';
|
|
3
3
|
|
|
4
|
-
import { GenericObjectType } from '../src';
|
|
4
|
+
import type { GenericObjectType } from '../src';
|
|
5
5
|
import isObject from './isObject';
|
|
6
6
|
|
|
7
7
|
/** Merges the `defaults` object of type `T` into the `formData` of type `T`
|
|
@@ -43,7 +43,7 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
43
43
|
const mapped = overrideArray.map((value, idx) => {
|
|
44
44
|
// We want to explicitly make sure that the value is NOT undefined since null, 0 and empty space are valid values
|
|
45
45
|
if (overrideOppositeArray[idx] !== undefined) {
|
|
46
|
-
return mergeDefaultsWithFormData
|
|
46
|
+
return mergeDefaultsWithFormData(
|
|
47
47
|
defaultsArray[idx],
|
|
48
48
|
formData[idx],
|
|
49
49
|
mergeExtraArrayDefaults,
|
|
@@ -62,8 +62,9 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
62
62
|
return mapped as unknown as T;
|
|
63
63
|
}
|
|
64
64
|
if (isObject(formData)) {
|
|
65
|
+
// oxlint-disable-next-line prefer-object-spread -- spread loses T type, Object.assign preserves it
|
|
65
66
|
const acc: { [key in keyof T]: any } = Object.assign({}, defaults); // Prevent mutation of source object.
|
|
66
|
-
return Object.keys(formData as GenericObjectType).reduce((
|
|
67
|
+
return Object.keys(formData as GenericObjectType).reduce((accumulator, key) => {
|
|
67
68
|
const keyValue = get(formData, key);
|
|
68
69
|
const keyExistsInDefaults = isObject(defaults) && key in (defaults as GenericObjectType);
|
|
69
70
|
const keyExistsInFormData = key in (formData as GenericObjectType);
|
|
@@ -75,14 +76,14 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
75
76
|
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
76
77
|
|
|
77
78
|
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueIsNestedObject) {
|
|
78
|
-
|
|
79
|
+
accumulator[key as keyof T] = {
|
|
79
80
|
...get(defaults, key),
|
|
80
81
|
...keyValue,
|
|
81
82
|
};
|
|
82
|
-
return
|
|
83
|
+
return accumulator;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
accumulator[key as keyof T] = mergeDefaultsWithFormData<T>(
|
|
86
87
|
get(defaults, key),
|
|
87
88
|
keyValue,
|
|
88
89
|
mergeExtraArrayDefaults,
|
|
@@ -103,7 +104,7 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
103
104
|
*/
|
|
104
105
|
if (
|
|
105
106
|
(defaultSupercedesUndefined &&
|
|
106
|
-
((!(defaults === undefined) && isNil(formData)) || (typeof formData === 'number' && isNaN(formData)))) ||
|
|
107
|
+
((!(defaults === undefined) && isNil(formData)) || (typeof formData === 'number' && Number.isNaN(formData)))) ||
|
|
107
108
|
(overrideFormDataWithDefaults && !isNil(formData))
|
|
108
109
|
) {
|
|
109
110
|
return defaults;
|
package/src/mergeObjects.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import isObject from './isObject';
|
|
2
|
-
import { GenericObjectType } from './types';
|
|
2
|
+
import type { GenericObjectType } from './types';
|
|
3
3
|
|
|
4
4
|
/** Recursively merge deeply nested objects.
|
|
5
5
|
*
|
|
@@ -37,6 +37,6 @@ export default function mergeObjects(
|
|
|
37
37
|
}
|
|
38
38
|
return acc;
|
|
39
39
|
},
|
|
40
|
-
|
|
40
|
+
{ ...obj1 },
|
|
41
41
|
); // Prevent mutation of source object.
|
|
42
42
|
}
|
package/src/mergeSchemas.ts
CHANGED
|
@@ -3,7 +3,7 @@ import union from 'lodash/union';
|
|
|
3
3
|
import { REQUIRED_KEY } from './constants';
|
|
4
4
|
import getSchemaType from './getSchemaType';
|
|
5
5
|
import isObject from './isObject';
|
|
6
|
-
import { GenericObjectType } from './types';
|
|
6
|
+
import type { GenericObjectType, GenericSymbolObjectType } from './types';
|
|
7
7
|
|
|
8
8
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
9
9
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
@@ -14,12 +14,12 @@ import { GenericObjectType } from './types';
|
|
|
14
14
|
* @returns - The merged schema object
|
|
15
15
|
*/
|
|
16
16
|
export default function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjectType) {
|
|
17
|
-
const acc =
|
|
18
|
-
|
|
17
|
+
const acc = { ...obj1 }; // Prevent mutation of source object.
|
|
18
|
+
const result = Object.keys(obj2).reduce((accumulator, key) => {
|
|
19
19
|
const left = obj1 ? obj1[key] : {},
|
|
20
20
|
right = obj2[key];
|
|
21
21
|
if (obj1 && key in obj1 && isObject(right)) {
|
|
22
|
-
|
|
22
|
+
accumulator[key] = mergeSchemas(left, right);
|
|
23
23
|
} else if (
|
|
24
24
|
obj1 &&
|
|
25
25
|
obj2 &&
|
|
@@ -29,10 +29,17 @@ export default function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjec
|
|
|
29
29
|
Array.isArray(right)
|
|
30
30
|
) {
|
|
31
31
|
// Don't include duplicate values when merging 'required' fields.
|
|
32
|
-
|
|
32
|
+
accumulator[key] = union(left, right);
|
|
33
33
|
} else {
|
|
34
|
-
|
|
34
|
+
accumulator[key] = right;
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return accumulator;
|
|
37
37
|
}, acc);
|
|
38
|
+
// Copy own Symbol-keyed properties from obj2 (Object.keys skips them).
|
|
39
|
+
for (const sym of Object.getOwnPropertySymbols(obj2)) {
|
|
40
|
+
// To avoid issues with symbols, we cast them to GenericSymbolObjectType. If we make the mergeSchema function take
|
|
41
|
+
// in GenericSymbolObjectType rather than GenericObjectType, it causes a bunch of type errors downstream
|
|
42
|
+
(result as GenericSymbolObjectType)[sym] = (obj2 as GenericSymbolObjectType)[sym];
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
38
45
|
}
|
package/src/nameGenerators.ts
CHANGED
package/src/optionsList.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from './constants';
|
|
|
4
4
|
import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema';
|
|
5
5
|
import getUiOptions from './getUiOptions';
|
|
6
6
|
import toConstant from './toConstant';
|
|
7
|
-
import { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types';
|
|
7
|
+
import type { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types';
|
|
8
8
|
|
|
9
9
|
/** Reorders `options` according to `order`, which may contain a `'*'` wildcard representing all
|
|
10
10
|
* remaining options in their original order. Options not listed in `order` (and not covered by
|
|
@@ -79,26 +79,24 @@ export default function optionsList<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
79
79
|
const { optionsSchemaSelector = selectorField } = getUiOptions<T, S, F>(uiSchema);
|
|
80
80
|
selectorField = optionsSchemaSelector;
|
|
81
81
|
}
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
})
|
|
103
|
-
);
|
|
82
|
+
return altSchemas?.map((aSchemaDef, index) => {
|
|
83
|
+
const { title } = getUiOptions<T, S, F>(altUiSchemas?.[index]);
|
|
84
|
+
const aSchema = aSchemaDef as S;
|
|
85
|
+
let value: EnumOptionsType<S>['value'];
|
|
86
|
+
let label = title;
|
|
87
|
+
if (selectorField) {
|
|
88
|
+
const innerSchema: S = get(aSchema, [PROPERTIES_KEY, selectorField], {}) as S;
|
|
89
|
+
value = get(innerSchema, DEFAULT_KEY, get(innerSchema, CONST_KEY));
|
|
90
|
+
// Use nullish coalescing so that an explicitly empty string title is preserved
|
|
91
|
+
label = label ?? innerSchema?.title ?? aSchema.title ?? String(value);
|
|
92
|
+
} else {
|
|
93
|
+
value = toConstant(aSchema);
|
|
94
|
+
label = label ?? aSchema.title ?? String(value);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
schema: aSchema,
|
|
98
|
+
label,
|
|
99
|
+
value,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
104
102
|
}
|
package/src/orderProperties.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericObjectType } from './types';
|
|
1
|
+
import type { GenericObjectType } from './types';
|
|
2
2
|
|
|
3
3
|
/** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
|
|
4
4
|
* If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
|
|
@@ -16,9 +16,9 @@ export default function orderProperties(properties: string[], order?: string[]):
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const arrayToHash = (arr: string[]) =>
|
|
19
|
-
arr.reduce((
|
|
20
|
-
|
|
21
|
-
return
|
|
19
|
+
arr.reduce((acc: GenericObjectType, curr) => {
|
|
20
|
+
acc[curr] = true;
|
|
21
|
+
return acc;
|
|
22
22
|
}, {});
|
|
23
23
|
const errorPropList = (arr: string[]) =>
|
|
24
24
|
arr.length > 1 ? `properties '${arr.join("', '")}'` : `property '${arr[0]}'`;
|