@rjsf/utils 6.0.0-alpha.0 → 6.0.0-beta.10
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/dist/index.js +1347 -642
- package/dist/index.js.map +4 -4
- package/dist/utils.esm.js +1324 -619
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +1266 -590
- package/lib/ErrorSchemaBuilder.d.ts +8 -4
- package/lib/ErrorSchemaBuilder.js +10 -8
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +1 -1
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +2 -2
- package/lib/canExpand.js +2 -2
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +9 -0
- package/lib/constIsAjvDataReference.js +15 -0
- package/lib/constIsAjvDataReference.js.map +1 -0
- package/lib/constants.d.ts +15 -3
- package/lib/constants.js +15 -3
- package/lib/constants.js.map +1 -1
- package/lib/createErrorHandler.d.ts +1 -1
- package/lib/createErrorHandler.js +2 -2
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +3 -2
- package/lib/createSchemaUtils.js +56 -46
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +1 -1
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.js +1 -1
- package/lib/deepEquals.js.map +1 -1
- package/lib/englishStringTranslator.d.ts +1 -1
- package/lib/englishStringTranslator.js +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +1 -1
- package/lib/enumOptionsDeselectValue.js +4 -4
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +1 -1
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +1 -1
- package/lib/enumOptionsIsSelected.js +3 -3
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +1 -1
- package/lib/enumOptionsSelectValue.js +2 -2
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +1 -1
- package/lib/enumOptionsValueForIndex.js.map +1 -1
- package/lib/enums.d.ts +2 -0
- package/lib/enums.js +2 -0
- package/lib/enums.js.map +1 -1
- package/lib/findSchemaDefinition.d.ts +5 -3
- package/lib/findSchemaDefinition.js +54 -11
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +17 -0
- package/lib/getChangedFields.js +42 -0
- package/lib/getChangedFields.js.map +1 -0
- package/lib/getDateElementProps.d.ts +1 -1
- package/lib/getDateElementProps.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +1 -1
- package/lib/getDiscriminatorFieldFromSchema.js +4 -3
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +1 -1
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.js +2 -2
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.js +3 -2
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +1 -1
- package/lib/getSubmitButtonOptions.js +2 -2
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +1 -1
- package/lib/getTemplate.js +9 -0
- package/lib/getTemplate.js.map +1 -1
- package/lib/getTestIds.d.ts +17 -0
- package/lib/getTestIds.js +34 -0
- package/lib/getTestIds.js.map +1 -0
- package/lib/getUiOptions.d.ts +1 -1
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +1 -1
- package/lib/getWidget.js +3 -3
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +1 -1
- package/lib/guessType.js.map +1 -1
- package/lib/hasWidget.d.ts +1 -1
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +23 -1
- package/lib/hashForSchema.js +24 -6
- package/lib/hashForSchema.js.map +1 -1
- package/lib/idGenerators.d.ts +8 -1
- package/lib/idGenerators.js +11 -2
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +63 -60
- package/lib/index.js +63 -60
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +1 -1
- package/lib/isConstant.js +1 -1
- package/lib/isCustomWidget.d.ts +1 -1
- package/lib/isCustomWidget.js +1 -1
- package/lib/isFixedItems.d.ts +1 -1
- package/lib/isFixedItems.js +1 -1
- package/lib/isObject.d.ts +2 -2
- package/lib/isObject.js +11 -4
- package/lib/isObject.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +11 -0
- package/lib/lookupFromFormContext.js +20 -0
- package/lib/lookupFromFormContext.js.map +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts +8 -2
- package/lib/mergeDefaultsWithFormData.js +39 -10
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +1 -1
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +1 -1
- package/lib/mergeSchemas.js +4 -4
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/optionsList.d.ts +9 -7
- package/lib/optionsList.js +30 -19
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.js.map +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 +1 -1
- package/lib/parser/ParserValidator.js +6 -6
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +2 -2
- package/lib/parser/index.js +1 -1
- package/lib/parser/schemaParser.d.ts +2 -2
- package/lib/parser/schemaParser.js +6 -6
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/rangeSpec.d.ts +2 -2
- package/lib/rangeSpec.js.map +1 -1
- package/lib/replaceStringParameters.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +19 -0
- package/lib/schema/findFieldInSchema.js +61 -0
- package/lib/schema/findFieldInSchema.js.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +16 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +34 -0
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -0
- package/lib/schema/getClosestMatchingOption.d.ts +5 -3
- package/lib/schema/getClosestMatchingOption.js +28 -20
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +60 -13
- package/lib/schema/getDefaultFormState.js +316 -167
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +3 -2
- package/lib/schema/getDisplayLabel.js +10 -9
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +1 -1
- package/lib/schema/getFirstMatchingOption.js +70 -2
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +14 -0
- package/lib/schema/getFromSchema.js +39 -0
- package/lib/schema/getFromSchema.js.map +1 -0
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.js +15 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +3 -2
- package/lib/schema/isFilesArray.js +5 -4
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +3 -2
- package/lib/schema/isMultiSelect.js +4 -3
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +3 -2
- package/lib/schema/isSelect.js +5 -4
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +30 -12
- package/lib/schema/retrieveSchema.js +153 -70
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +3 -2
- package/lib/schema/sanitizeDataForNewSchema.js +12 -11
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/toIdSchema.d.ts +3 -2
- package/lib/schema/toIdSchema.js +30 -27
- package/lib/schema/toIdSchema.js.map +1 -1
- package/lib/schema/toPathSchema.d.ts +3 -2
- package/lib/schema/toPathSchema.js +22 -20
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +1 -1
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shouldRender.js +1 -1
- package/lib/toConstant.d.ts +1 -1
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +1 -1
- package/lib/toErrorList.d.ts +1 -1
- package/lib/toErrorList.js +2 -2
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +1 -1
- package/lib/toErrorSchema.js +2 -2
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types.d.ts +172 -142
- package/lib/unwrapErrorHandler.d.ts +1 -1
- package/lib/unwrapErrorHandler.js +1 -1
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +1 -1
- package/lib/validationDataMerge.js +3 -3
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +1 -1
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +37 -26
- package/src/ErrorSchemaBuilder.ts +15 -8
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +17 -0
- package/src/constants.ts +17 -3
- package/src/createSchemaUtils.ts +140 -50
- package/src/dataURItoBlob.ts +1 -1
- package/src/dateRangeOptions.ts +1 -1
- package/src/enumOptionsDeselectValue.ts +4 -5
- package/src/enumOptionsIndexForValue.ts +1 -1
- package/src/enumOptionsIsSelected.ts +4 -5
- package/src/enumOptionsSelectValue.ts +1 -1
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/enums.ts +2 -0
- package/src/findSchemaDefinition.ts +55 -10
- package/src/getChangedFields.ts +40 -0
- package/src/getDateElementProps.ts +2 -2
- package/src/getDiscriminatorFieldFromSchema.ts +2 -1
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +2 -2
- package/src/getSchemaType.ts +3 -2
- package/src/getSubmitButtonOptions.ts +1 -1
- package/src/getTemplate.ts +12 -1
- package/src/getTestIds.ts +40 -0
- package/src/getUiOptions.ts +2 -2
- package/src/getWidget.tsx +2 -2
- package/src/hasWidget.ts +1 -1
- package/src/hashForSchema.ts +26 -6
- package/src/idGenerators.ts +10 -0
- package/src/index.ts +21 -2
- package/src/isCustomWidget.ts +1 -1
- package/src/isObject.ts +12 -5
- package/src/labelValue.ts +2 -2
- package/src/lookupFromFormContext.ts +26 -0
- package/src/mergeDefaultsWithFormData.ts +54 -9
- package/src/mergeObjects.ts +24 -21
- package/src/optionsList.ts +31 -22
- package/src/parser/ParserValidator.ts +5 -5
- package/src/parser/schemaParser.ts +6 -6
- package/src/schema/findFieldInSchema.ts +138 -0
- package/src/schema/findSelectedOptionInXxxOf.ts +53 -0
- package/src/schema/getClosestMatchingOption.ts +38 -11
- package/src/schema/getDefaultFormState.ts +461 -193
- package/src/schema/getDisplayLabel.ts +7 -4
- package/src/schema/getFirstMatchingOption.ts +79 -4
- package/src/schema/getFromSchema.ts +100 -0
- package/src/schema/index.ts +6 -4
- package/src/schema/isFilesArray.ts +18 -3
- package/src/schema/isMultiSelect.ts +10 -4
- package/src/schema/isSelect.ts +5 -3
- package/src/schema/retrieveSchema.ts +268 -78
- package/src/schema/sanitizeDataForNewSchema.ts +52 -11
- package/src/schema/toIdSchema.ts +69 -43
- package/src/schema/toPathSchema.ts +49 -16
- package/src/toErrorList.ts +2 -2
- package/src/types.ts +278 -184
- package/src/validationDataMerge.ts +1 -1
- package/src/withIdRefPrefix.ts +1 -1
- package/LICENSE.md +0 -201
- package/lib/schema/getMatchingOption.d.ts +0 -14
- package/lib/schema/getMatchingOption.js +0 -85
- package/lib/schema/getMatchingOption.js.map +0 -1
- package/lib/schema/mergeValidationData.d.ts +0 -14
- package/lib/schema/mergeValidationData.js +0 -28
- package/lib/schema/mergeValidationData.js.map +0 -1
- package/src/schema/getMatchingOption.ts +0 -103
- package/src/schema/mergeValidationData.ts +0 -38
package/lib/isFixedItems.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import { RJSFSchema, StrictRJSFSchema } from './types.js';
|
|
2
2
|
/** Detects whether the given `schema` contains fixed items. This is the case when `schema.items` is a non-empty array
|
|
3
3
|
* that only contains objects.
|
|
4
4
|
*
|
package/lib/isFixedItems.js
CHANGED
package/lib/isObject.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** Determines whether a `thing` is an object for the purposes of
|
|
1
|
+
/** Determines whether a `thing` is an object for the purposes of RJSF. In this case, `thing` is an object if it has
|
|
2
2
|
* the type `object` but is NOT null, an array or a File.
|
|
3
3
|
*
|
|
4
4
|
* @param thing - The thing to check to see whether it is an object
|
|
5
5
|
* @returns - True if it is a non-null, non-array, non-File object
|
|
6
6
|
*/
|
|
7
|
-
export default function isObject(thing: any):
|
|
7
|
+
export default function isObject(thing: any): thing is object;
|
package/lib/isObject.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
/** Determines whether a `thing` is an object for the purposes of
|
|
1
|
+
/** Determines whether a `thing` is an object for the purposes of RJSF. In this case, `thing` is an object if it has
|
|
2
2
|
* the type `object` but is NOT null, an array or a File.
|
|
3
3
|
*
|
|
4
4
|
* @param thing - The thing to check to see whether it is an object
|
|
5
5
|
* @returns - True if it is a non-null, non-array, non-File object
|
|
6
6
|
*/
|
|
7
7
|
export default function isObject(thing) {
|
|
8
|
-
if (typeof
|
|
8
|
+
if (typeof thing !== 'object' || thing === null) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
// lastModified is guaranteed to be a number on a File instance
|
|
12
|
+
// as per https://w3c.github.io/FileAPI/#dfn-lastModified
|
|
13
|
+
if (typeof thing.lastModified === 'number' && typeof File !== 'undefined' && thing instanceof File) {
|
|
12
14
|
return false;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
// getMonth is guaranteed to be a method on a Date instance
|
|
17
|
+
// as per https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth
|
|
18
|
+
if (typeof thing.getMonth === 'function' && typeof Date !== 'undefined' && thing instanceof Date) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return !Array.isArray(thing);
|
|
15
22
|
}
|
|
16
23
|
//# sourceMappingURL=isObject.js.map
|
package/lib/isObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../src/isObject.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAU;IACzC,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"isObject.js","sourceRoot":"","sources":["../src/isObject.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,KAAU;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,+DAA+D;IAC/D,yDAAyD;IACzD,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACnG,OAAO,KAAK,CAAC;IACf,CAAC;IACD,2DAA2D;IAC3D,8FAA8F;IAC9F,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACjG,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types.js';
|
|
2
|
+
/** Given a React JSON Schema Form registry or formContext object, return the value associated with `toLookup`. This
|
|
3
|
+
* might be contained within the lookup map in the formContext. If no such value exists, return the `fallback`
|
|
4
|
+
* value.
|
|
5
|
+
*
|
|
6
|
+
* @param regOrFc - The @rjsf registry or form context in which the lookup will occur
|
|
7
|
+
* @param toLookup - The name of the field in the lookup map in the form context to get the value for
|
|
8
|
+
* @param [fallback] - The fallback value to use if the form context does not contain a value for `toLookup`
|
|
9
|
+
* @returns - The value associated with `toLookup` in the form context or `fallback`
|
|
10
|
+
*/
|
|
11
|
+
export default function lookupFromFormContext<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(regOrFc: Registry<T, S, F> | Registry<T, S, F>['formContext'], toLookup: string, fallback?: unknown): any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import has from 'lodash-es/has.js';
|
|
3
|
+
import { FORM_CONTEXT_NAME, LOOKUP_MAP_NAME } from './constants.js';
|
|
4
|
+
/** Given a React JSON Schema Form registry or formContext object, return the value associated with `toLookup`. This
|
|
5
|
+
* might be contained within the lookup map in the formContext. If no such value exists, return the `fallback`
|
|
6
|
+
* value.
|
|
7
|
+
*
|
|
8
|
+
* @param regOrFc - The @rjsf registry or form context in which the lookup will occur
|
|
9
|
+
* @param toLookup - The name of the field in the lookup map in the form context to get the value for
|
|
10
|
+
* @param [fallback] - The fallback value to use if the form context does not contain a value for `toLookup`
|
|
11
|
+
* @returns - The value associated with `toLookup` in the form context or `fallback`
|
|
12
|
+
*/
|
|
13
|
+
export default function lookupFromFormContext(regOrFc, toLookup, fallback) {
|
|
14
|
+
const lookupPath = [LOOKUP_MAP_NAME];
|
|
15
|
+
if (has(regOrFc, FORM_CONTEXT_NAME)) {
|
|
16
|
+
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
17
|
+
}
|
|
18
|
+
return get(regOrFc, [...lookupPath, toLookup], fallback);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=lookupFromFormContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookupFromFormContext.js","sourceRoot":"","sources":["../src/lookupFromFormContext.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAC7B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGjE;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAI3C,OAA6D,EAAE,QAAgB,EAAE,QAAkB;IACnG,MAAM,UAAU,GAAG,CAAC,eAAe,CAAC,CAAC;IACrC,IAAI,GAAG,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,CAAC;QACpC,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -7,11 +7,17 @@
|
|
|
7
7
|
* are deeply merged; additional entries from the defaults are ignored unless `mergeExtraArrayDefaults` is true, in
|
|
8
8
|
* which case the extras are appended onto the end of the form data
|
|
9
9
|
* - when the array is not set in form data, the default is copied over
|
|
10
|
-
* - scalars are overwritten/set by form data
|
|
10
|
+
* - scalars are overwritten/set by form data unless undefined and there is a default AND `defaultSupercedesUndefined`
|
|
11
|
+
* is true
|
|
11
12
|
*
|
|
12
13
|
* @param [defaults] - The defaults to merge
|
|
13
14
|
* @param [formData] - The form data into which the defaults will be merged
|
|
14
15
|
* @param [mergeExtraArrayDefaults=false] - If true, any additional default array entries are appended onto the formData
|
|
16
|
+
* @param [defaultSupercedesUndefined=false] - If true, an explicit undefined value will be overwritten by the default value
|
|
17
|
+
* @param [overrideFormDataWithDefaults=false] - If true, the default value will overwrite the form data value. If the value
|
|
18
|
+
* doesn't exist in the default, we take it from formData and in the case where the value is set to undefined in formData.
|
|
19
|
+
* This is useful when we have already merged formData with defaults and want to add an additional field from formData
|
|
20
|
+
* that does not exist in defaults.
|
|
15
21
|
* @returns - The resulting merged form data with defaults
|
|
16
22
|
*/
|
|
17
|
-
export default function mergeDefaultsWithFormData<T = any>(defaults?: T, formData?: T, mergeExtraArrayDefaults?: boolean): T | undefined;
|
|
23
|
+
export default function mergeDefaultsWithFormData<T = any>(defaults?: T, formData?: T, mergeExtraArrayDefaults?: boolean, defaultSupercedesUndefined?: boolean, overrideFormDataWithDefaults?: boolean): T | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import isObject from './isObject';
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import isObject from './isObject.js';
|
|
3
|
+
import isNil from 'lodash-es/isNil.js';
|
|
3
4
|
/** Merges the `defaults` object of type `T` into the `formData` of type `T`
|
|
4
5
|
*
|
|
5
6
|
* When merging defaults and form data, we want to merge in this specific way:
|
|
@@ -9,35 +10,63 @@ import isObject from './isObject';
|
|
|
9
10
|
* are deeply merged; additional entries from the defaults are ignored unless `mergeExtraArrayDefaults` is true, in
|
|
10
11
|
* which case the extras are appended onto the end of the form data
|
|
11
12
|
* - when the array is not set in form data, the default is copied over
|
|
12
|
-
* - scalars are overwritten/set by form data
|
|
13
|
+
* - scalars are overwritten/set by form data unless undefined and there is a default AND `defaultSupercedesUndefined`
|
|
14
|
+
* is true
|
|
13
15
|
*
|
|
14
16
|
* @param [defaults] - The defaults to merge
|
|
15
17
|
* @param [formData] - The form data into which the defaults will be merged
|
|
16
18
|
* @param [mergeExtraArrayDefaults=false] - If true, any additional default array entries are appended onto the formData
|
|
19
|
+
* @param [defaultSupercedesUndefined=false] - If true, an explicit undefined value will be overwritten by the default value
|
|
20
|
+
* @param [overrideFormDataWithDefaults=false] - If true, the default value will overwrite the form data value. If the value
|
|
21
|
+
* doesn't exist in the default, we take it from formData and in the case where the value is set to undefined in formData.
|
|
22
|
+
* This is useful when we have already merged formData with defaults and want to add an additional field from formData
|
|
23
|
+
* that does not exist in defaults.
|
|
17
24
|
* @returns - The resulting merged form data with defaults
|
|
18
25
|
*/
|
|
19
|
-
export default function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false) {
|
|
26
|
+
export default function mergeDefaultsWithFormData(defaults, formData, mergeExtraArrayDefaults = false, defaultSupercedesUndefined = false, overrideFormDataWithDefaults = false) {
|
|
20
27
|
if (Array.isArray(formData)) {
|
|
21
28
|
const defaultsArray = Array.isArray(defaults) ? defaults : [];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
// If overrideFormDataWithDefaults is true, we want to override the formData with the defaults
|
|
30
|
+
const overrideArray = overrideFormDataWithDefaults ? defaultsArray : formData;
|
|
31
|
+
const overrideOppositeArray = overrideFormDataWithDefaults ? formData : defaultsArray;
|
|
32
|
+
const mapped = overrideArray.map((value, idx) => {
|
|
33
|
+
// We want to explicitly make sure that the value is NOT undefined since null, 0 and empty space are valid values
|
|
34
|
+
if (overrideOppositeArray[idx] !== undefined) {
|
|
35
|
+
return mergeDefaultsWithFormData(defaultsArray[idx], formData[idx], mergeExtraArrayDefaults, defaultSupercedesUndefined, overrideFormDataWithDefaults);
|
|
25
36
|
}
|
|
26
37
|
return value;
|
|
27
38
|
});
|
|
28
39
|
// Merge any extra defaults when mergeExtraArrayDefaults is true
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
// Or when overrideFormDataWithDefaults is true and the default array is shorter than the formData array
|
|
41
|
+
if ((mergeExtraArrayDefaults || overrideFormDataWithDefaults) && mapped.length < overrideOppositeArray.length) {
|
|
42
|
+
mapped.push(...overrideOppositeArray.slice(mapped.length));
|
|
31
43
|
}
|
|
32
44
|
return mapped;
|
|
33
45
|
}
|
|
34
46
|
if (isObject(formData)) {
|
|
35
47
|
const acc = Object.assign({}, defaults); // Prevent mutation of source object.
|
|
36
48
|
return Object.keys(formData).reduce((acc, key) => {
|
|
37
|
-
|
|
49
|
+
const keyValue = get(formData, key);
|
|
50
|
+
const keyExistsInDefaults = isObject(defaults) && key in defaults;
|
|
51
|
+
const keyExistsInFormData = key in formData;
|
|
52
|
+
acc[key] = mergeDefaultsWithFormData(defaults ? get(defaults, key) : {}, keyValue, mergeExtraArrayDefaults, defaultSupercedesUndefined,
|
|
53
|
+
// overrideFormDataWithDefaults can be true only when the key value exists in defaults
|
|
54
|
+
// Or if the key value doesn't exist in formData
|
|
55
|
+
overrideFormDataWithDefaults && (keyExistsInDefaults || !keyExistsInFormData));
|
|
38
56
|
return acc;
|
|
39
57
|
}, acc);
|
|
40
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* If the defaultSupercedesUndefined flag is true
|
|
61
|
+
* And formData is set to undefined or null and defaults are defined
|
|
62
|
+
* Or if formData is a number and is NaN return defaults
|
|
63
|
+
* Or if overrideFormDataWithDefaults flag is true and formData is set to not undefined/null return defaults
|
|
64
|
+
*/
|
|
65
|
+
if ((defaultSupercedesUndefined &&
|
|
66
|
+
((!isNil(defaults) && isNil(formData)) || (typeof formData === 'number' && isNaN(formData)))) ||
|
|
67
|
+
(overrideFormDataWithDefaults && !isNil(formData))) {
|
|
68
|
+
return defaults;
|
|
69
|
+
}
|
|
41
70
|
return formData;
|
|
42
71
|
}
|
|
43
72
|
//# sourceMappingURL=mergeDefaultsWithFormData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDefaultsWithFormData.js","sourceRoot":"","sources":["../src/mergeDefaultsWithFormData.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,QAAQ,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"mergeDefaultsWithFormData.js","sourceRoot":"","sources":["../src/mergeDefaultsWithFormData.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,QAAY,EACZ,QAAY,EACZ,uBAAuB,GAAG,KAAK,EAC/B,0BAA0B,GAAG,KAAK,EAClC,4BAA4B,GAAG,KAAK;IAEpC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAE9D,8FAA8F;QAC9F,MAAM,aAAa,GAAG,4BAA4B,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC9E,MAAM,qBAAqB,GAAG,4BAA4B,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC;QAEtF,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,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;YAChD,4BAA4B,IAAI,CAAC,mBAAmB,IAAI,CAAC,mBAAmB,CAAC,CAC9E,CAAC;YACF,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;IAED;;;;;OAKG;IACH,IACE,CAAC,0BAA0B;QACzB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC/F,CAAC,4BAA4B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAClD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/lib/mergeObjects.d.ts
CHANGED
package/lib/mergeObjects.js
CHANGED
package/lib/mergeObjects.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeObjects.js","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,IAAuB,EACvB,IAAuB,EACvB,eAA8C,KAAK;IAEnD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"mergeObjects.js","sourceRoot":"","sources":["../src/mergeObjects.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,IAAuB,EACvB,IAAuB,EACvB,eAA8C,KAAK;IAEnD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAC7B,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAChC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC;QACrD,CAAC;aAAM,IAAI,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvE,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,YAAY,KAAK,mBAAmB,EAAE,CAAC;gBACzC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;oBACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACrB,CAAC;oBACD,OAAO,MAAM,CAAC;gBAChB,CAAC,EAAE,EAAE,CAAC,CAAC;YACT,CAAC;YACD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EACD,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CACxB,CAAC,CAAC,qCAAqC;AAC1C,CAAC"}
|
package/lib/mergeSchemas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericObjectType } from './types';
|
|
1
|
+
import { GenericObjectType } from './types.js';
|
|
2
2
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
3
3
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
4
4
|
* duplicate values.
|
package/lib/mergeSchemas.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import union from 'lodash/union';
|
|
2
|
-
import { REQUIRED_KEY } from './constants';
|
|
3
|
-
import getSchemaType from './getSchemaType';
|
|
4
|
-
import isObject from './isObject';
|
|
1
|
+
import union from 'lodash-es/union.js';
|
|
2
|
+
import { REQUIRED_KEY } from './constants.js';
|
|
3
|
+
import getSchemaType from './getSchemaType.js';
|
|
4
|
+
import isObject from './isObject.js';
|
|
5
5
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
6
6
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
7
7
|
* duplicate values.
|
package/lib/mergeSchemas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeSchemas.js","sourceRoot":"","sources":["../src/mergeSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAGlC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAuB,EAAE,IAAuB;IACnF,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,qCAAqC;IAC1E,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE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AAiE;YACjE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC"}
|
package/lib/optionsList.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { RJSFSchema, EnumOptionsType, StrictRJSFSchema, FormContextType, UiSchema } from './types';
|
|
1
|
+
import { RJSFSchema, EnumOptionsType, StrictRJSFSchema, FormContextType, UiSchema } from './types.js';
|
|
2
2
|
/** Gets the list of options from the `schema`. If the schema has an enum list, then those enum values are returned. The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
3
|
+
* label will be the same as the `value`.
|
|
4
|
+
*
|
|
5
|
+
* If the schema has a `oneOf` or `anyOf`, then the value is the list of either:
|
|
6
|
+
* - The `const` values from the schema if present
|
|
7
|
+
* - If the schema has a discriminator and the label using either the `schema.title` or the value. If a `uiSchema` is
|
|
8
|
+
* provided, and it has the `ui:enumNames` matched with `enum` or it has an associated `oneOf` or `anyOf` with a list of
|
|
9
|
+
* objects containing `ui:title` then the UI schema values will replace the values from the schema.
|
|
8
10
|
*
|
|
9
11
|
* @param schema - The schema from which to extract the options list
|
|
10
12
|
* @param [uiSchema] - The optional uiSchema from which to get alternate labels for the options
|
|
11
13
|
* @returns - The list of options from the schema
|
|
12
14
|
*/
|
|
13
|
-
export default function optionsList<S extends StrictRJSFSchema = RJSFSchema,
|
|
15
|
+
export default function optionsList<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: S, uiSchema?: UiSchema<T, S, F>): EnumOptionsType<S>[] | undefined;
|
package/lib/optionsList.js
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import { CONST_KEY, DEFAULT_KEY, PROPERTIES_KEY } from './constants.js';
|
|
3
|
+
import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema.js';
|
|
4
|
+
import getUiOptions from './getUiOptions.js';
|
|
5
|
+
import toConstant from './toConstant.js';
|
|
3
6
|
/** Gets the list of options from the `schema`. If the schema has an enum list, then those enum values are returned. The
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* label will be the same as the `value`.
|
|
8
|
+
*
|
|
9
|
+
* If the schema has a `oneOf` or `anyOf`, then the value is the list of either:
|
|
10
|
+
* - The `const` values from the schema if present
|
|
11
|
+
* - If the schema has a discriminator and the label using either the `schema.title` or the value. If a `uiSchema` is
|
|
12
|
+
* provided, and it has the `ui:enumNames` matched with `enum` or it has an associated `oneOf` or `anyOf` with a list of
|
|
13
|
+
* objects containing `ui:title` then the UI schema values will replace the values from the schema.
|
|
9
14
|
*
|
|
10
15
|
* @param schema - The schema from which to extract the options list
|
|
11
16
|
* @param [uiSchema] - The optional uiSchema from which to get alternate labels for the options
|
|
12
17
|
* @returns - The list of options from the schema
|
|
13
18
|
*/
|
|
14
19
|
export default function optionsList(schema, uiSchema) {
|
|
15
|
-
// TODO flip generics to move T first in v6
|
|
16
|
-
const schemaWithEnumNames = schema;
|
|
17
20
|
if (schema.enum) {
|
|
18
21
|
let enumNames;
|
|
19
22
|
if (uiSchema) {
|
|
20
23
|
const { enumNames: uiEnumNames } = getUiOptions(uiSchema);
|
|
21
24
|
enumNames = uiEnumNames;
|
|
22
25
|
}
|
|
23
|
-
if (!enumNames && schemaWithEnumNames.enumNames) {
|
|
24
|
-
// enumNames was deprecated in v5 and is intentionally omitted from the RJSFSchema type.
|
|
25
|
-
// Cast the type to include enumNames so the feature still works.
|
|
26
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
27
|
-
console.warn('The "enumNames" property in the schema is deprecated and will be removed in a future major release. Use the "ui:enumNames" property in the uiSchema instead.');
|
|
28
|
-
}
|
|
29
|
-
enumNames = schemaWithEnumNames.enumNames;
|
|
30
|
-
}
|
|
31
26
|
return schema.enum.map((value, i) => {
|
|
32
27
|
const label = (enumNames === null || enumNames === void 0 ? void 0 : enumNames[i]) || String(value);
|
|
33
28
|
return { label, value };
|
|
@@ -43,12 +38,28 @@ export default function optionsList(schema, uiSchema) {
|
|
|
43
38
|
altSchemas = schema.oneOf;
|
|
44
39
|
altUiSchemas = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.oneOf;
|
|
45
40
|
}
|
|
41
|
+
// See if there is a discriminator path specified in the schema, and if so, use it as the selectorField, otherwise
|
|
42
|
+
// pull one from the uiSchema
|
|
43
|
+
let selectorField = getDiscriminatorFieldFromSchema(schema);
|
|
44
|
+
if (uiSchema) {
|
|
45
|
+
const { optionsSchemaSelector = selectorField } = getUiOptions(uiSchema);
|
|
46
|
+
selectorField = optionsSchemaSelector;
|
|
47
|
+
}
|
|
46
48
|
return (altSchemas &&
|
|
47
49
|
altSchemas.map((aSchemaDef, index) => {
|
|
48
50
|
const { title } = getUiOptions(altUiSchemas === null || altUiSchemas === void 0 ? void 0 : altUiSchemas[index]);
|
|
49
51
|
const aSchema = aSchemaDef;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
let value;
|
|
53
|
+
let label = title;
|
|
54
|
+
if (selectorField) {
|
|
55
|
+
const innerSchema = get(aSchema, [PROPERTIES_KEY, selectorField], {});
|
|
56
|
+
value = get(innerSchema, DEFAULT_KEY, get(innerSchema, CONST_KEY));
|
|
57
|
+
label = label || (innerSchema === null || innerSchema === void 0 ? void 0 : innerSchema.title) || aSchema.title || String(value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
value = toConstant(aSchema);
|
|
61
|
+
label = label || aSchema.title || String(value);
|
|
62
|
+
}
|
|
52
63
|
return {
|
|
53
64
|
schema: aSchema,
|
|
54
65
|
label,
|
package/lib/optionsList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optionsList.js","sourceRoot":"","sources":["../src/optionsList.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"optionsList.js","sourceRoot":"","sources":["../src/optionsList.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,+BAA+B,MAAM,mCAAmC,CAAC;AAChF,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,UAAU,MAAM,cAAc,CAAC;AAGtC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,MAAS,EACT,QAA4B;IAE5B,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,IAAI,SAA+B,CAAC;QACpC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,CAAU,QAAQ,CAAC,CAAC;YACnE,SAAS,GAAG,WAAW,CAAC;QAC1B,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YAClC,MAAM,KAAK,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,CAAC,CAAC,KAAI,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IACD,IAAI,UAAU,GAA4B,SAAS,CAAC;IACpD,IAAI,YAAY,GAAkC,SAAS,CAAC;IAC5D,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,YAAY,GAAG,Q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,KAAK,GAAG,KAAK,IAAI,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;YAClD,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,KAAK;gBACL,KAAK;aACN,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orderProperties.js","sourceRoot":"","sources":["../src/orderProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAoB,EAAE,KAAgB;IAC5E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"orderProperties.js","sourceRoot":"","sources":["../src/orderProperties.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAoB,EAAE,KAAgB;IAC5E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,GAAa,EAAE,EAAE,CACpC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAuB,EAAE,IAAI,EAAE,EAAE;QAC3C,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,MAAM,aAAa,GAAG,CAAC,GAAa,EAAE,EAAE,CACtC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC/E,MAAM,YAAY,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;IACjF,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAE7C,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjF,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,IAAI,SAAS,KAAK,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,GAAG,aAAa,CAAC,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IACvC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/lib/pad.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pad.js","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,GAAG,CAAC,GAAW,EAAE,KAAa;IACpD,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC,MAAM,GAAG,KAAK,EAAE;
|
|
1
|
+
{"version":3,"file":"pad.js","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,GAAG,CAAC,GAAW,EAAE,KAAa;IACpD,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QACxB,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/lib/parseDateString.d.ts
CHANGED
package/lib/parseDateString.js
CHANGED
|
@@ -22,7 +22,7 @@ export default function parseDateString(dateString, includeTime = true) {
|
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
year: date.getUTCFullYear(),
|
|
25
|
-
month: date.getUTCMonth() + 1,
|
|
25
|
+
month: date.getUTCMonth() + 1, // oh you, javascript.
|
|
26
26
|
day: date.getUTCDate(),
|
|
27
27
|
hour: includeTime ? date.getUTCHours() : 0,
|
|
28
28
|
minute: includeTime ? date.getUTCMinutes() : 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDateString.js","sourceRoot":"","sources":["../src/parseDateString.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAmB,EAAE,WAAW,GAAG,IAAI;IAC7E,IAAI,CAAC,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"parseDateString.js","sourceRoot":"","sources":["../src/parseDateString.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAmB,EAAE,WAAW,GAAG,IAAI;IAC7E,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;YACL,IAAI,EAAE,CAAC,CAAC;YACR,KAAK,EAAE,CAAC,CAAC;YACT,GAAG,EAAE,CAAC,CAAC;YACP,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7B,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;IAClC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,UAAU,CAAC,CAAC;IACxD,CAAC;IACD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE;QAC3B,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,sBAAsB;QACrD,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE;QACtB,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomValidator, ErrorSchema, ErrorTransformer, FormContextType, RJSFSchema, RJSFValidationError, StrictRJSFSchema, UiSchema, ValidationData, ValidatorType } from '../types';
|
|
1
|
+
import { CustomValidator, ErrorSchema, ErrorTransformer, FormContextType, RJSFSchema, RJSFValidationError, StrictRJSFSchema, UiSchema, ValidationData, ValidatorType } from '../types.js';
|
|
2
2
|
/** The type of the map of schema hash to schema
|
|
3
3
|
*/
|
|
4
4
|
export type SchemaMap<S extends StrictRJSFSchema = RJSFSchema> = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import get from 'lodash/get';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import get from 'lodash-es/get.js';
|
|
2
|
+
import { ID_KEY } from '../constants.js';
|
|
3
|
+
import hashForSchema from '../hashForSchema.js';
|
|
4
|
+
import deepEquals from '../deepEquals.js';
|
|
5
5
|
/** An implementation of the `ValidatorType` interface that is designed for use in capturing schemas used by the
|
|
6
6
|
* `isValid()` function. The rest of the implementation of the interface throws errors when it is attempted to be used.
|
|
7
7
|
* An instance of the object allows the caller to capture the schemas used in calls to the `isValid()` function. These
|
|
@@ -40,7 +40,7 @@ export default class ParserValidator {
|
|
|
40
40
|
if (!existing) {
|
|
41
41
|
this.schemaMap[key] = identifiedSchema;
|
|
42
42
|
}
|
|
43
|
-
else if (!
|
|
43
|
+
else if (!deepEquals(existing, identifiedSchema)) {
|
|
44
44
|
console.error('existing schema:', JSON.stringify(existing, null, 2));
|
|
45
45
|
console.error('new schema:', JSON.stringify(identifiedSchema, null, 2));
|
|
46
46
|
throw new Error(`Two different schemas exist with the same key ${key}! What a bad coincidence. If possible, try adding an $id to one of the schemas`);
|
|
@@ -60,7 +60,7 @@ export default class ParserValidator {
|
|
|
60
60
|
* @throws - Error when the given `rootSchema` differs from the root schema provided during construction
|
|
61
61
|
*/
|
|
62
62
|
isValid(schema, _formData, rootSchema) {
|
|
63
|
-
if (!
|
|
63
|
+
if (!deepEquals(rootSchema, this.rootSchema)) {
|
|
64
64
|
throw new Error('Unexpectedly calling isValid() with a rootSchema that differs from the construction rootSchema');
|
|
65
65
|
}
|
|
66
66
|
this.addSchema(schema, hashForSchema(schema));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParserValidator.js","sourceRoot":"","sources":["../../src/parser/ParserValidator.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ParserValidator.js","sourceRoot":"","sources":["../../src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AAC,CAAC;YACxE,MAAM,IAAI,KAAK,CACb,iDAAiD,GAAG,gFAAgF,CACrI,CAAC;QACJ,CAAC;IACH,CAAC;IAED;OACG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,MAAS,EAAE,SAAY,EAAE,UAAa;QAC5C,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,gGAAgG,CAAC,CAAC;QACpH,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,CAAI,MAAM,CAAC,CAAC,CAAC;QAEjD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAe,OAAU,EAAE,SAAa;QACnD,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;IAC7F,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,YAA6B,EAAE,UAAqB;QAC9D,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC3F,CAAC;IAED;;;;;;;;OAQG;IACH,gBAAgB,CACd,SAAY,EACZ,OAAU,EACV,eAA0C,EAC1C,gBAA4C,EAC5C,SAA6B;QAE7B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAChG,CAAC;CACF"}
|
package/lib/parser/index.d.ts
CHANGED
package/lib/parser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types';
|
|
2
|
-
import { SchemaMap } from './ParserValidator';
|
|
1
|
+
import { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types.js';
|
|
2
|
+
import { SchemaMap } from './ParserValidator.js';
|
|
3
3
|
/** Parses the given `rootSchema` to extract out all the sub-schemas that maybe contained within it. Returns a map of
|
|
4
4
|
* the hash of the schema to schema/sub-schema.
|
|
5
5
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import forEach from 'lodash/forEach';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import forEach from 'lodash-es/forEach.js';
|
|
2
|
+
import { ITEMS_KEY, PROPERTIES_KEY } from '../constants.js';
|
|
3
|
+
import ParserValidator from './ParserValidator.js';
|
|
4
|
+
import { resolveAnyOrOneOfSchemas, retrieveSchemaInternal } from '../schema/retrieveSchema.js';
|
|
5
|
+
import deepEquals from '../deepEquals.js';
|
|
6
6
|
/** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
|
|
7
7
|
* capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
|
|
8
8
|
* `retrieveSchemaInternal()`, the `resolveAnyOrOneOfSchemas()` function is called. For each of the schemas returned
|
|
@@ -16,7 +16,7 @@ import { retrieveSchemaInternal, resolveAnyOrOneOfSchemas } from '../schema/retr
|
|
|
16
16
|
function parseSchema(validator, recurseList, rootSchema, schema) {
|
|
17
17
|
const schemas = retrieveSchemaInternal(validator, schema, rootSchema, undefined, true);
|
|
18
18
|
schemas.forEach((schema) => {
|
|
19
|
-
const sameSchemaIndex = recurseList.findIndex((item) =>
|
|
19
|
+
const sameSchemaIndex = recurseList.findIndex((item) => deepEquals(item, schema));
|
|
20
20
|
if (sameSchemaIndex === -1) {
|
|
21
21
|
recurseList.push(schema);
|
|
22
22
|
const allOptions = resolveAnyOrOneOfSchemas(validator, schema, rootSchema, true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaParser.js","sourceRoot":"","sources":["../../src/parser/schemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"schemaParser.js","sourceRoot":"","sources":["../../src/parser/schemaParser.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAGrC,OAA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CAAC;gBAC7F,WAAW,CAAU,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAC,KAAU,CAAC,CAAC;YAC9E,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,UAAa;IAEb,MAAM,SAAS,GAAG,IAAI,eAAe,CAAU,UAAU,CAAC,CAAC;IAC3D,MAAM,WAAW,GAAQ,EAAE,CAAC;IAE5B,WAAW,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;IAE5D,OAAO,SAAS,CAAC,YAAY,EAAE,CAAC;AAClC,CAAC"}
|
package/lib/rangeSpec.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RangeSpecType, StrictRJSFSchema } from './types';
|
|
2
|
-
import { RJSFSchema } from './types';
|
|
1
|
+
import { RangeSpecType, StrictRJSFSchema } from './types.js';
|
|
2
|
+
import { RJSFSchema } from './types.js';
|
|
3
3
|
/** Extracts the range spec information `{ step?: number, min?: number, max?: number }` that can be spread onto an HTML
|
|
4
4
|
* input from the range analog in the schema `{ multipleOf?: number, minimum?: number, maximum?: number }`.
|
|
5
5
|
*
|
package/lib/rangeSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rangeSpec.js","sourceRoot":"","sources":["../src/rangeSpec.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAA0C,MAAS;IAClF,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,IAAI,MAAM,CAAC,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"rangeSpec.js","sourceRoot":"","sources":["../src/rangeSpec.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAA0C,MAAS;IAClF,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC;IAChC,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceStringParameters.js","sourceRoot":"","sources":["../src/replaceStringParameters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,WAAmB,EAAE,MAAiB;IACpF,IAAI,MAAM,GAAG,WAAW,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"replaceStringParameters.js","sourceRoot":"","sources":["../src/replaceStringParameters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAAC,WAAmB,EAAE,MAAiB;IACpF,IAAI,MAAM,GAAG,WAAW,CAAC;IACzB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;YACtE,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;gBACnB,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Experimental_CustomMergeAllOf, FormContextType, FoundFieldType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '../types.js';
|
|
2
|
+
/** Unique schema that represents no schema was found, exported for testing purposes */
|
|
3
|
+
export declare const NOT_FOUND_SCHEMA: {
|
|
4
|
+
title: string;
|
|
5
|
+
};
|
|
6
|
+
/** Finds the field specified by the `path` within the root or recursed `schema`. If there is no field for the specified
|
|
7
|
+
* `path`, then the default `{ field: undefined, isRequired: undefined }` is returned. It determines whether a leaf
|
|
8
|
+
* field is in the `required` list for its parent and if so, it is marked as required on return.
|
|
9
|
+
*
|
|
10
|
+
* @param validator - An implementation of the `ValidatorType` interface that will be forwarded to all the APIs
|
|
11
|
+
* @param rootSchema - The root schema that will be forwarded to all the APIs
|
|
12
|
+
* @param schema - The node within the JSON schema in which to search
|
|
13
|
+
* @param path - The keys in the path to the desired field
|
|
14
|
+
* @param [formData={}] - The form data that is used to determine which anyOf/oneOf option to descend
|
|
15
|
+
* @param [experimental_customMergeAllOf] - Optional function that allows for custom merging of `allOf` schemas
|
|
16
|
+
* @returns - An object that contains the field and its required state. If no field can be found then
|
|
17
|
+
* `{ field: undefined, isRequired: undefined }` is returned.
|
|
18
|
+
*/
|
|
19
|
+
export default function findFieldInSchema<T = undefined, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rootSchema: S, schema: S, path: string | string[], formData?: T, experimental_customMergeAllOf?: Experimental_CustomMergeAllOf<S>): FoundFieldType<S>;
|