@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rjsf/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -42,20 +42,6 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=20"
|
|
44
44
|
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
|
|
47
|
-
"build:ts": "npm run compileReplacer && rimraf ./lib && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
48
|
-
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.cjs --sourcemap --packages=external --format=cjs",
|
|
49
|
-
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/utils.esm.js --sourcemap --packages=external --format=esm",
|
|
50
|
-
"build:umd": "rollup dist/utils.esm.js --format=umd --file=dist/utils.umd.js --name=@rjsf/utils",
|
|
51
|
-
"build": "npm run build:ts && npm run build:cjs && npm run build:esm && npm run build:umd",
|
|
52
|
-
"cs-check": "oxfmt --check \"{src,test}/**/*.{ts,tsx}\"",
|
|
53
|
-
"cs-format": "oxfmt \"{src,test}/**/*.{ts,tsx}\"",
|
|
54
|
-
"lint": "oxlint src test",
|
|
55
|
-
"precommit": "lint-staged",
|
|
56
|
-
"test": "vitest run",
|
|
57
|
-
"test:debug": "node --inspect-brk ../../node_modules/.bin/vitest --pool=forks"
|
|
58
|
-
},
|
|
59
45
|
"lint-staged": {
|
|
60
46
|
"{src,test}/**/*.{ts,tsx}": [
|
|
61
47
|
"oxlint --fix",
|
|
@@ -68,7 +54,7 @@
|
|
|
68
54
|
"dependencies": {
|
|
69
55
|
"@x0k/json-schema-merge": "^1.0.3",
|
|
70
56
|
"fast-equals": "^6.0.0",
|
|
71
|
-
"fast-uri": "^
|
|
57
|
+
"fast-uri": "^4.0.0",
|
|
72
58
|
"jsonpointer": "^5.0.1",
|
|
73
59
|
"lodash": "^4.18.1",
|
|
74
60
|
"lodash-es": "^4.18.1",
|
|
@@ -77,7 +63,7 @@
|
|
|
77
63
|
"devDependencies": {
|
|
78
64
|
"@types/json-schema": "^7.0.15",
|
|
79
65
|
"@types/react-is": "^18.3.1",
|
|
80
|
-
"deep-freeze-es6": "^
|
|
66
|
+
"deep-freeze-es6": "^5.0.0"
|
|
81
67
|
},
|
|
82
68
|
"publishConfig": {
|
|
83
69
|
"access": "public"
|
|
@@ -96,5 +82,19 @@
|
|
|
96
82
|
"type": "git",
|
|
97
83
|
"url": "git+https://github.com/rjsf-team/react-jsonschema-form.git"
|
|
98
84
|
},
|
|
99
|
-
"license": "Apache-2.0"
|
|
100
|
-
|
|
85
|
+
"license": "Apache-2.0",
|
|
86
|
+
"scripts": {
|
|
87
|
+
"compileReplacer": "tsc -p tsconfig.replacer.json && move-file lodashReplacer.js lodashReplacer.cjs",
|
|
88
|
+
"build:ts": "pnpm run compileReplacer && rimraf ./lib && tsc -b tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
89
|
+
"build:cjs": "esbuild ./src/index.ts --bundle --outfile=dist/index.cjs --sourcemap --packages=external --format=cjs",
|
|
90
|
+
"build:esm": "esbuild ./src/index.ts --bundle --outfile=dist/utils.esm.js --sourcemap --packages=external --format=esm",
|
|
91
|
+
"build:umd": "rollup dist/utils.esm.js --format=umd --file=dist/utils.umd.js --name=@rjsf/utils",
|
|
92
|
+
"build": "pnpm run build:ts && pnpm run build:cjs && pnpm run build:esm && pnpm run build:umd",
|
|
93
|
+
"cs-check": "oxfmt --check \"{src,test}/**/*.{ts,tsx}\"",
|
|
94
|
+
"cs-format": "oxfmt \"{src,test}/**/*.{ts,tsx}\"",
|
|
95
|
+
"lint": "oxlint src test",
|
|
96
|
+
"precommit": "lint-staged",
|
|
97
|
+
"test": "vitest run",
|
|
98
|
+
"test:debug": "node --inspect-brk ../../node_modules/.bin/vitest --pool=forks"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -4,7 +4,7 @@ import set from 'lodash/set';
|
|
|
4
4
|
import setWith from 'lodash/setWith';
|
|
5
5
|
|
|
6
6
|
import { ERRORS_KEY } from './constants';
|
|
7
|
-
import { ErrorSchema, FieldPathList } from './types';
|
|
7
|
+
import type { ErrorSchema, FieldPathList } from './types';
|
|
8
8
|
|
|
9
9
|
/** Represents the type of the path which can be a string of dotted path values or a list of string or numbers where
|
|
10
10
|
* numbers represent array indexes/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import enumOptionsIsSelected from './enumOptionsIsSelected';
|
|
2
|
+
import getTemplate from './getTemplate';
|
|
3
|
+
import getUiOptions from './getUiOptions';
|
|
4
|
+
import { descriptionId } from './idGenerators';
|
|
5
|
+
import type { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from './types';
|
|
6
|
+
|
|
7
|
+
export type SelectedOptionDescriptionProps<
|
|
8
|
+
T = any,
|
|
9
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
10
|
+
F extends FormContextType = any,
|
|
11
|
+
> = Pick<WidgetProps<T, S, F>, 'id' | 'multiple' | 'options' | 'registry' | 'uiSchema' | 'value' | 'hideLabel'>;
|
|
12
|
+
|
|
13
|
+
/** Renders the description associated with the selected oneOf or anyOf option in a single-select widget. */
|
|
14
|
+
export default function SelectedOptionDescription<
|
|
15
|
+
T = any,
|
|
16
|
+
S extends StrictRJSFSchema = RJSFSchema,
|
|
17
|
+
F extends FormContextType = any,
|
|
18
|
+
>({ hideLabel, id, multiple, options, registry, uiSchema, value }: SelectedOptionDescriptionProps<T, S, F>) {
|
|
19
|
+
if (multiple || hideLabel) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const { label = true } = getUiOptions<T, S, F>(uiSchema, registry.globalUiOptions);
|
|
24
|
+
if (!label) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const option = options.enumOptions?.find(({ value: enumValue }) => enumOptionsIsSelected(enumValue, value));
|
|
29
|
+
const description = option?.schema?.description;
|
|
30
|
+
if (!description) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
|
|
35
|
+
'DescriptionFieldTemplate',
|
|
36
|
+
registry,
|
|
37
|
+
options,
|
|
38
|
+
);
|
|
39
|
+
return (
|
|
40
|
+
<DescriptionFieldTemplate
|
|
41
|
+
id={descriptionId(id)}
|
|
42
|
+
description={description}
|
|
43
|
+
schema={option.schema!}
|
|
44
|
+
uiSchema={uiSchema}
|
|
45
|
+
registry={registry}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import isObject from './isObject';
|
|
2
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Checks the schema to see if it is allowing additional items, by verifying that `schema.additionalItems` is an
|
|
5
5
|
* object. The user is warned in the console if `schema.additionalItems` has the value `true`.
|
|
@@ -9,6 +9,7 @@ import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
|
9
9
|
*/
|
|
10
10
|
export default function allowAdditionalItems<S extends StrictRJSFSchema = RJSFSchema>(schema: S) {
|
|
11
11
|
if (schema.additionalItems === true) {
|
|
12
|
+
// oxlint-disable-next-line no-console
|
|
12
13
|
console.warn('additionalItems=true is currently not supported');
|
|
13
14
|
}
|
|
14
15
|
return isObject(schema.additionalItems);
|
package/src/asNumber.ts
CHANGED
|
@@ -14,11 +14,13 @@ export default function asNumber(value: string | null) {
|
|
|
14
14
|
if (value === null) {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
+
// oxlint-disable-next-line typescript/prefer-string-starts-ends-with -- regex test() coerces undefined to "undefined" safely; endsWith() throws on undefined values passed at runtime
|
|
17
18
|
if (/\.$/.test(value)) {
|
|
18
19
|
// '3.' can't really be considered a number even if it parses in js. The
|
|
19
20
|
// user is most likely entering a float.
|
|
20
21
|
return value;
|
|
21
22
|
}
|
|
23
|
+
// oxlint-disable-next-line typescript/prefer-string-starts-ends-with -- same as above
|
|
22
24
|
if (/\.0$/.test(value)) {
|
|
23
25
|
// we need to return this as a string here, to allow for input like 3.07
|
|
24
26
|
return value;
|
package/src/canExpand.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 whether the field described by `schema`, having the `uiSchema` and `formData` supports expanding. The UI for
|
|
5
5
|
* the field can expand if it has additional properties, is not forced as non-expandable by the `uiSchema` and the
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { JSONSchema7Type } from 'json-schema';
|
|
1
|
+
import type { JSONSchema7Type } from 'json-schema';
|
|
2
2
|
import isString from 'lodash/isString';
|
|
3
3
|
|
|
4
4
|
import { CONST_KEY, getSchemaType, isObject } from './';
|
|
5
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
5
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Checks if the schema const property value is an AJV $data reference
|
package/src/constants.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** Below are the list of all the keys into various elements of a RJSFSchema or UiSchema that are used by the various
|
|
2
|
-
* utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG
|
|
3
|
-
* `
|
|
4
|
-
* utility.
|
|
2
|
+
* utility functions. In addition to those keys, there are the special `ADDITIONAL_PROPERTY_FLAG`,
|
|
3
|
+
* `RJSF_REF_KEY`, and `RJSF_REF_CYCLE_KEY` Symbols that are added to a schema under certain conditions by the
|
|
4
|
+
* `retrieveSchema()` utility. Using Symbols keeps these internal markers invisible to JSON serialisation and
|
|
5
|
+
* JSON Schema validators (AJV, ATA, etc.), which only enumerate string-keyed properties.
|
|
5
6
|
*/
|
|
6
|
-
export const ADDITIONAL_PROPERTY_FLAG = '__additional_property';
|
|
7
|
+
export const ADDITIONAL_PROPERTY_FLAG = Symbol('__additional_property');
|
|
7
8
|
export const ADDITIONAL_PROPERTIES_KEY = 'additionalProperties';
|
|
8
9
|
export const ALL_OF_KEY = 'allOf';
|
|
9
10
|
export const ANY_OF_KEY = 'anyOf';
|
|
@@ -25,7 +26,8 @@ export const READONLY_KEY = 'readonly';
|
|
|
25
26
|
export const REQUIRED_KEY = 'required';
|
|
26
27
|
export const SUBMIT_BTN_OPTIONS_KEY = 'submitButtonOptions';
|
|
27
28
|
export const REF_KEY = '$ref';
|
|
28
|
-
export const RJSF_REF_KEY = '__rjsf_ref';
|
|
29
|
+
export const RJSF_REF_KEY = Symbol('__rjsf_ref');
|
|
30
|
+
export const RJSF_REF_CYCLE_KEY = Symbol('__rjsf_ref_cycle');
|
|
29
31
|
export const SCHEMA_KEY = '$schema';
|
|
30
32
|
export const DEFAULT_ID_PREFIX = 'root';
|
|
31
33
|
export const DEFAULT_ID_SEPARATOR = '_';
|
|
@@ -40,8 +42,9 @@ export const FORM_CONTEXT_NAME = 'formContext';
|
|
|
40
42
|
/** The name of the `layoutGridLookupMap` attribute in the form context
|
|
41
43
|
*/
|
|
42
44
|
export const LOOKUP_MAP_NAME = 'layoutGridLookupMap';
|
|
43
|
-
export const
|
|
44
|
-
export const
|
|
45
|
+
export const RJSF_PREFIX_KEY = '__rjsf';
|
|
46
|
+
export const RJSF_ADDITIONAL_PROPERTIES_FLAG = `${RJSF_PREFIX_KEY}_additionalProperties`;
|
|
47
|
+
export const ROOT_SCHEMA_PREFIX = `${RJSF_PREFIX_KEY}_rootSchema`;
|
|
45
48
|
export const UI_FIELD_KEY = 'ui:field';
|
|
46
49
|
export const UI_WIDGET_KEY = 'ui:widget';
|
|
47
50
|
export const UI_OPTIONS_KEY = 'ui:options';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isPlainObject from 'lodash/isPlainObject';
|
|
2
2
|
|
|
3
3
|
import { ERRORS_KEY } from './constants';
|
|
4
|
-
import { FieldValidation, FormValidation, GenericObjectType } from './types';
|
|
4
|
+
import type { FieldValidation, FormValidation, GenericObjectType } from './types';
|
|
5
5
|
|
|
6
6
|
/** Given a `formData` object, recursively creates a `FormValidation` error handling structure around it
|
|
7
7
|
*
|
|
@@ -19,15 +19,14 @@ export default function createErrorHandler<T = any>(formData: T): FormValidation
|
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
21
|
if (Array.isArray(formData)) {
|
|
22
|
-
return formData.reduce((acc, value, key) => {
|
|
23
|
-
return { ...acc, [key]: createErrorHandler(value) };
|
|
24
|
-
}, handler);
|
|
22
|
+
return formData.reduce((acc, value, key) => ({ ...acc, [key]: createErrorHandler(value) }), handler);
|
|
25
23
|
}
|
|
26
24
|
if (isPlainObject(formData)) {
|
|
27
25
|
const formObject: GenericObjectType = formData as GenericObjectType;
|
|
28
|
-
return Object.keys(formObject).reduce(
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
return Object.keys(formObject).reduce(
|
|
27
|
+
(acc, key) => ({ ...acc, [key]: createErrorHandler(formObject[key]) }),
|
|
28
|
+
handler as FormValidation<T>,
|
|
29
|
+
);
|
|
31
30
|
}
|
|
32
31
|
return handler as FormValidation<T>;
|
|
33
32
|
}
|
package/src/createSchemaUtils.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
sanitizeDataForNewSchema,
|
|
20
20
|
toPathSchema,
|
|
21
21
|
} from './schema';
|
|
22
|
-
import {
|
|
22
|
+
import type {
|
|
23
23
|
Experimental_CustomMergeAllOf,
|
|
24
24
|
Experimental_DefaultFormStateBehavior,
|
|
25
25
|
FormContextType,
|
|
@@ -63,7 +63,7 @@ class SchemaUtils<
|
|
|
63
63
|
experimental_defaultFormStateBehavior: Experimental_DefaultFormStateBehavior,
|
|
64
64
|
experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>,
|
|
65
65
|
) {
|
|
66
|
-
if (rootSchema
|
|
66
|
+
if (rootSchema?.[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
67
67
|
this.rootSchema = makeAllReferencesAbsolute(rootSchema, get(rootSchema, ID_KEY, '#'));
|
|
68
68
|
} else {
|
|
69
69
|
this.rootSchema = rootSchema;
|
|
@@ -364,7 +364,9 @@ class SchemaUtils<
|
|
|
364
364
|
* @param [formData] - The current formData, if any, onto which to provide any missing defaults
|
|
365
365
|
* @returns - The `PathSchema` object for the `schema`
|
|
366
366
|
*/
|
|
367
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
367
368
|
toPathSchema(schema: S, name?: string, formData?: T): PathSchema<T> {
|
|
369
|
+
// oxlint-disable-next-line typescript/no-deprecated
|
|
368
370
|
return toPathSchema<T, S, F>(
|
|
369
371
|
this.validator,
|
|
370
372
|
schema,
|
package/src/dataURItoBlob.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export default function dataURItoBlob(dataURILike: string) {
|
|
8
8
|
// check if is dataURI
|
|
9
|
-
if (dataURILike.
|
|
9
|
+
if (!dataURILike.includes('data:')) {
|
|
10
10
|
throw new Error('File is invalid: URI must be a dataURI');
|
|
11
11
|
}
|
|
12
12
|
const dataURI = dataURILike.slice(5);
|
|
@@ -32,7 +32,7 @@ export default function dataURItoBlob(dataURILike: string) {
|
|
|
32
32
|
try {
|
|
33
33
|
const binary = atob(base64);
|
|
34
34
|
const array = new Array(binary.length);
|
|
35
|
-
for (let i = 0; i < binary.length; i
|
|
35
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
36
36
|
array[i] = binary.charCodeAt(i);
|
|
37
37
|
}
|
|
38
38
|
// Create the blob object
|
|
@@ -40,6 +40,6 @@ export default function dataURItoBlob(dataURILike: string) {
|
|
|
40
40
|
|
|
41
41
|
return { blob, name };
|
|
42
42
|
} catch (error) {
|
|
43
|
-
throw new Error(
|
|
43
|
+
throw new Error(`File is invalid: ${(error as Error).message}`);
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/dateRangeOptions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pad from './pad';
|
|
2
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Returns a list of options for a date range between `start` and `stop`. If the start date is greater than the end
|
|
5
5
|
* date, then the date range is reversed. If `start` and `stop` are negative numbers (or zero), then they will be
|
|
@@ -14,17 +14,19 @@ export default function dateRangeOptions<S extends StrictRJSFSchema = RJSFSchema
|
|
|
14
14
|
start: number,
|
|
15
15
|
stop: number,
|
|
16
16
|
): EnumOptionsType<S>[] {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else if (start < 0 || stop < 0) {
|
|
17
|
+
const bothRelative = start <= 0 && stop <= 0;
|
|
18
|
+
const eitherNegative = start < 0 || stop < 0;
|
|
19
|
+
if (!bothRelative && eitherNegative) {
|
|
21
20
|
throw new Error(`Both start (${start}) and stop (${stop}) must both be <= 0 or > 0, got one of each`);
|
|
22
21
|
}
|
|
23
|
-
|
|
22
|
+
const currentYear = new Date().getFullYear();
|
|
23
|
+
const resolvedStart = bothRelative ? currentYear + start : start;
|
|
24
|
+
const resolvedStop = bothRelative ? currentYear + stop : stop;
|
|
25
|
+
if (resolvedStart > resolvedStop) {
|
|
24
26
|
return dateRangeOptions<S>(stop, start).reverse();
|
|
25
27
|
}
|
|
26
28
|
const options: EnumOptionsType<S>[] = [];
|
|
27
|
-
for (let i =
|
|
29
|
+
for (let i = resolvedStart; i <= resolvedStop; i += 1) {
|
|
28
30
|
options.push({ value: i, label: pad(i, 2) });
|
|
29
31
|
}
|
|
30
32
|
return options;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TranslatableString } from './enums';
|
|
1
|
+
import type { TranslatableString } from './enums';
|
|
2
2
|
import replaceStringParameters from './replaceStringParameters';
|
|
3
3
|
|
|
4
4
|
/** Translates a `TranslatableString` value `stringToTranslate` into english. When a `params` array is provided, each
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import enumOptionsIndexForValue from './enumOptionsIndexForValue';
|
|
2
|
-
import { EnumOptionsType, OptionValueFormat, StrictRJSFSchema, RJSFSchema } from './types';
|
|
2
|
+
import type { EnumOptionsType, OptionValueFormat, StrictRJSFSchema, RJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Computes the value to pass to a select element's `value` attribute.
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import enumOptionsValueForIndex from './enumOptionsValueForIndex';
|
|
2
|
-
import { EnumOptionsType, OptionValueFormat, StrictRJSFSchema, RJSFSchema } from './types';
|
|
2
|
+
import type { EnumOptionsType, OptionValueFormat, StrictRJSFSchema, RJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Resolves a single DOM value string back to its typed enum value in `'realValue'` mode.
|
|
5
5
|
*
|
|
@@ -27,7 +27,7 @@ function decodeSingle<S extends StrictRJSFSchema = RJSFSchema>(
|
|
|
27
27
|
}
|
|
28
28
|
// Fallback: value might be an index (for object/array enum values)
|
|
29
29
|
const index = Number(value);
|
|
30
|
-
if (!isNaN(index) && index >= 0 && index < enumOptions.length) {
|
|
30
|
+
if (!Number.isNaN(index) && index >= 0 && index < enumOptions.length) {
|
|
31
31
|
return enumOptions[index].value;
|
|
32
32
|
}
|
|
33
33
|
return emptyValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import deepEquals from './deepEquals';
|
|
2
2
|
import enumOptionsValueForIndex from './enumOptionsValueForIndex';
|
|
3
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
4
4
|
|
|
5
5
|
/** Removes the enum option value at the `valueIndex` from the currently `selected` (list of) value(s). If `selected` is
|
|
6
6
|
* a list, then that list is updated to remove the enum option value with the `valueIndex` in `allEnumOptions`. If it is
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import enumOptionsIsSelected from './enumOptionsIsSelected';
|
|
2
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Returns the index(es) of the options in `allEnumOptions` whose value(s) match the ones in `value`. All the
|
|
5
5
|
* `enumOptions` are filtered based on whether they are a "selected" `value` and the index of each selected one is then
|
|
@@ -19,7 +19,7 @@ export default function enumOptionsIndexForValue<S extends StrictRJSFSchema = RJ
|
|
|
19
19
|
): string | string[] | undefined {
|
|
20
20
|
const selectedIndexes: string[] = allEnumOptions
|
|
21
21
|
.map((opt, index) => (enumOptionsIsSelected(opt.value, value) ? String(index) : undefined))
|
|
22
|
-
.filter((opt) => typeof opt !== 'undefined')
|
|
22
|
+
.filter((opt) => typeof opt !== 'undefined');
|
|
23
23
|
if (!multiple) {
|
|
24
24
|
return selectedIndexes[0];
|
|
25
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import deepEquals from './deepEquals';
|
|
2
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
3
3
|
|
|
4
4
|
/** Determines whether the given `value` is (one of) the `selected` value(s).
|
|
5
5
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import isNil from 'lodash/isNil';
|
|
2
2
|
|
|
3
3
|
import enumOptionsValueForIndex from './enumOptionsValueForIndex';
|
|
4
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
4
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
5
5
|
|
|
6
6
|
/** Add the enum option value at the `valueIndex` to the list of `selected` values in the proper order as defined by
|
|
7
7
|
* `allEnumOptions`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
2
2
|
|
|
3
3
|
/** Returns the value(s) from `allEnumOptions` at the index(es) provided by `valueIndex`. If `valueIndex` is not an
|
|
4
4
|
* array AND the index is not valid for `allEnumOptions`, `emptyValue` is returned. If `valueIndex` is an array, AND it
|
|
@@ -12,7 +12,7 @@ import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
|
12
12
|
* `emptyValue` or an empty list.
|
|
13
13
|
*/
|
|
14
14
|
export default function enumOptionsValueForIndex<S extends StrictRJSFSchema = RJSFSchema>(
|
|
15
|
-
valueIndex: string | number |
|
|
15
|
+
valueIndex: string | number | (string | number)[],
|
|
16
16
|
allEnumOptions: EnumOptionsType<S>[] = [],
|
|
17
17
|
emptyValue?: EnumOptionsType<S>['value'],
|
|
18
18
|
): EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][] | undefined {
|
package/src/enums.ts
CHANGED
|
@@ -27,6 +27,8 @@ export enum TranslatableString {
|
|
|
27
27
|
AddItemButton = 'Add Item',
|
|
28
28
|
/** Copy button title, used by IconButton */
|
|
29
29
|
CopyButton = 'Copy',
|
|
30
|
+
/** Expand cycle button title */
|
|
31
|
+
ExpandButton = 'Expand Cycle',
|
|
30
32
|
/** Move down button title, used by IconButton */
|
|
31
33
|
MoveDownButton = 'Move down',
|
|
32
34
|
/** Move up button title, used by IconButton */
|
|
@@ -70,6 +72,8 @@ export enum TranslatableString {
|
|
|
70
72
|
KeyLabel = '%1 Key',
|
|
71
73
|
/** Deprecated label, where %1 will be replaced by the label as provided by SchemaField */
|
|
72
74
|
DeprecatedLabel = '%1 (deprecated)',
|
|
75
|
+
/** Cyclic schema message */
|
|
76
|
+
CycleDetected = 'Circular reference ($ref cycle) detected for field "%1". You may choose to expand to the next cycle break',
|
|
73
77
|
// Strings with replaceable parameters AND/OR that support markdown and html
|
|
74
78
|
/** Invalid object field configuration as provided by the ObjectField.
|
|
75
79
|
* NOTE: Use markdown notation rather than html tags.
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
REF_KEY,
|
|
14
14
|
SCHEMA_KEY,
|
|
15
15
|
} from './constants';
|
|
16
|
-
import { GenericObjectType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
16
|
+
import type { GenericObjectType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
17
17
|
|
|
18
18
|
/** Looks for the `$id` pointed by `ref` in the schema definitions embedded in
|
|
19
19
|
* a JSON Schema bundle
|
|
@@ -32,14 +32,14 @@ function findEmbeddedSchemaRecursive<S extends StrictRJSFSchema = RJSFSchema>(sc
|
|
|
32
32
|
if (isObject(item)) {
|
|
33
33
|
const result = findEmbeddedSchemaRecursive<S>(item as S, ref);
|
|
34
34
|
if (result !== undefined) {
|
|
35
|
-
return result
|
|
35
|
+
return result;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
} else if (isObject(subSchema)) {
|
|
40
40
|
const result = findEmbeddedSchemaRecursive<S>(subSchema as S, ref);
|
|
41
41
|
if (result !== undefined) {
|
|
42
|
-
return result
|
|
42
|
+
return result;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -53,22 +53,23 @@ function findEmbeddedSchemaRecursive<S extends StrictRJSFSchema = RJSFSchema>(sc
|
|
|
53
53
|
*/
|
|
54
54
|
export function makeAllReferencesAbsolute<S extends StrictRJSFSchema = RJSFSchema>(schema: S, baseURI: string): S {
|
|
55
55
|
const currentURI = get(schema, ID_KEY, baseURI);
|
|
56
|
+
let result = schema;
|
|
56
57
|
// Make all other references absolute
|
|
57
|
-
if (REF_KEY in
|
|
58
|
-
|
|
58
|
+
if (REF_KEY in result) {
|
|
59
|
+
result = { ...result, [REF_KEY]: UriResolver.resolve(currentURI, result[REF_KEY]!) };
|
|
59
60
|
}
|
|
60
61
|
// Look for references in nested subschemas
|
|
61
|
-
for (const [key, subSchema] of Object.entries(
|
|
62
|
+
for (const [key, subSchema] of Object.entries(result)) {
|
|
62
63
|
if (Array.isArray(subSchema)) {
|
|
63
|
-
|
|
64
|
-
...
|
|
64
|
+
result = {
|
|
65
|
+
...result,
|
|
65
66
|
[key]: subSchema.map((item) => (isObject(item) ? makeAllReferencesAbsolute(item as S, currentURI) : item)),
|
|
66
67
|
};
|
|
67
68
|
} else if (isObject(subSchema)) {
|
|
68
|
-
|
|
69
|
+
result = { ...result, [key]: makeAllReferencesAbsolute(subSchema as S, currentURI) };
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
return
|
|
72
|
+
return result;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/** Splits out the value at the `key` in `object` from the `object`, returning an array that contains in the first
|
|
@@ -105,23 +106,24 @@ export function findSchemaDefinitionRecursive<S extends StrictRJSFSchema = RJSFS
|
|
|
105
106
|
): S {
|
|
106
107
|
const ref = $ref || '';
|
|
107
108
|
let current: S | undefined = undefined;
|
|
109
|
+
let currentBaseURI = baseURI;
|
|
108
110
|
if (ref.startsWith('#')) {
|
|
109
111
|
// Decode URI fragment representation.
|
|
110
112
|
const decodedRef = decodeURIComponent(ref.substring(1));
|
|
111
|
-
if (
|
|
113
|
+
if (currentBaseURI === undefined || (ID_KEY in rootSchema && rootSchema[ID_KEY] === currentBaseURI)) {
|
|
112
114
|
current = jsonpointer.get(rootSchema, decodedRef);
|
|
113
115
|
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
114
|
-
current = findEmbeddedSchemaRecursive<S>(rootSchema,
|
|
116
|
+
current = findEmbeddedSchemaRecursive<S>(rootSchema, currentBaseURI.replace(/\/$/, ''));
|
|
115
117
|
if (current !== undefined) {
|
|
116
118
|
current = jsonpointer.get(current, decodedRef);
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
} else if (rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12) {
|
|
120
|
-
const resolvedRef =
|
|
122
|
+
const resolvedRef = currentBaseURI ? UriResolver.resolve(currentBaseURI, ref) : ref;
|
|
121
123
|
const [refId, ...refAnchor] = resolvedRef.replace(/#\/?$/, '').split('#');
|
|
122
124
|
current = findEmbeddedSchemaRecursive<S>(rootSchema, refId.replace(/\/$/, ''));
|
|
123
125
|
if (current !== undefined) {
|
|
124
|
-
|
|
126
|
+
currentBaseURI = current[ID_KEY];
|
|
125
127
|
if (!isEmpty(refAnchor)) {
|
|
126
128
|
current = jsonpointer.get(current, decodeURIComponent(refAnchor.join('#')));
|
|
127
129
|
}
|
|
@@ -142,16 +144,15 @@ export function findSchemaDefinitionRecursive<S extends StrictRJSFSchema = RJSFS
|
|
|
142
144
|
throw new Error(`Definition for ${firstRef} contains a circular reference through ${circularPath}`);
|
|
143
145
|
}
|
|
144
146
|
const [remaining, theRef] = splitKeyElementFromObject(REF_KEY, current);
|
|
145
|
-
const subSchema = findSchemaDefinitionRecursive<S>(theRef, rootSchema, [...recurseList, ref],
|
|
147
|
+
const subSchema = findSchemaDefinitionRecursive<S>(theRef, rootSchema, [...recurseList, ref], currentBaseURI);
|
|
146
148
|
if (Object.keys(remaining).length > 0) {
|
|
147
149
|
if (
|
|
148
150
|
rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2019_09 ||
|
|
149
151
|
rootSchema[SCHEMA_KEY] === JSON_SCHEMA_DRAFT_2020_12
|
|
150
152
|
) {
|
|
151
153
|
return { [ALL_OF_KEY]: [remaining, subSchema] } as S;
|
|
152
|
-
} else {
|
|
153
|
-
return { ...remaining, ...subSchema };
|
|
154
154
|
}
|
|
155
|
+
return { ...remaining, ...subSchema };
|
|
155
156
|
}
|
|
156
157
|
return subSchema;
|
|
157
158
|
}
|
package/src/getChangedFields.ts
CHANGED
|
@@ -31,11 +31,11 @@ export default function getChangedFields(a: unknown, b: unknown): string[] {
|
|
|
31
31
|
}
|
|
32
32
|
if (aIsPlainObject && !bIsPlainObject) {
|
|
33
33
|
return keys(a);
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
|
+
if (!aIsPlainObject && bIsPlainObject) {
|
|
35
36
|
return keys(b);
|
|
36
|
-
} else {
|
|
37
|
-
const unequalFields = keys(pickBy(a as object, (value, key) => !deepEquals(value, get(b, key))));
|
|
38
|
-
const diffFields = difference(keys(b), keys(a));
|
|
39
|
-
return [...unequalFields, ...diffFields];
|
|
40
37
|
}
|
|
38
|
+
const unequalFields = keys(pickBy(a as object, (value, key) => !deepEquals(value, get(b, key))));
|
|
39
|
+
const diffFields = difference(keys(b), keys(a));
|
|
40
|
+
return [...unequalFields, ...diffFields];
|
|
41
41
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DateObject } from './types';
|
|
2
2
|
|
|
3
3
|
/** Available options for re-ordering date input element */
|
|
4
4
|
export type DateElementFormat = 'DMY' | 'MDY' | 'YMD';
|
|
5
5
|
|
|
6
6
|
/** Type describing format of DateElement prop */
|
|
7
|
-
export
|
|
7
|
+
export interface DateElementProp {
|
|
8
8
|
type: string;
|
|
9
9
|
range: [number, number];
|
|
10
10
|
value: number | undefined;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
/** Given date & time information with optional yearRange & format, returns props for DateElement
|
|
14
14
|
*
|
|
@@ -2,7 +2,7 @@ import get from 'lodash/get';
|
|
|
2
2
|
import isString from 'lodash/isString';
|
|
3
3
|
|
|
4
4
|
import { DISCRIMINATOR_PATH } from './constants';
|
|
5
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
5
|
+
import type { RJSFSchema, StrictRJSFSchema } from './types';
|
|
6
6
|
|
|
7
7
|
/** Returns the `discriminator.propertyName` when defined in the `schema` if it is a string. A warning is generated when
|
|
8
8
|
* it is not a string. Returns `undefined` when a valid discriminator is not present.
|
|
@@ -16,6 +16,7 @@ export default function getDiscriminatorFieldFromSchema<S extends StrictRJSFSche
|
|
|
16
16
|
if (isString(maybeString)) {
|
|
17
17
|
discriminator = maybeString;
|
|
18
18
|
} else if (maybeString !== undefined) {
|
|
19
|
+
// oxlint-disable-next-line no-console
|
|
19
20
|
console.warn(`Expecting discriminator to be a string, got "${typeof maybeString}" instead`);
|
|
20
21
|
}
|
|
21
22
|
return discriminator;
|
package/src/getInputProps.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import rangeSpec from './rangeSpec';
|
|
2
|
-
import { FormContextType, InputPropsType, RJSFSchema, StrictRJSFSchema, UIOptionsType } from './types';
|
|
2
|
+
import type { FormContextType, InputPropsType, RJSFSchema, StrictRJSFSchema, UIOptionsType } from './types';
|
|
3
3
|
|
|
4
4
|
/** Using the `schema`, `defaultType` and `options`, extract out the props for the <input> element that make sense.
|
|
5
5
|
*
|