@rjsf/utils 6.8.0 → 6.10.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/dist/index.cjs +509 -419
- package/dist/index.cjs.map +4 -4
- package/dist/utils.esm.js +508 -418
- package/dist/utils.esm.js.map +4 -4
- package/dist/utils.umd.js +567 -327
- package/lib/ErrorSchemaBuilder.d.ts +8 -7
- package/lib/ErrorSchemaBuilder.d.ts.map +1 -0
- package/lib/ErrorSchemaBuilder.js +29 -27
- package/lib/ErrorSchemaBuilder.js.map +1 -1
- package/lib/SelectedOptionDescription.d.ts +2 -1
- package/lib/SelectedOptionDescription.d.ts.map +1 -0
- package/lib/SelectedOptionDescription.js +6 -7
- package/lib/SelectedOptionDescription.js.map +1 -1
- package/lib/allowAdditionalItems.d.ts +2 -1
- package/lib/allowAdditionalItems.d.ts.map +1 -0
- package/lib/allowAdditionalItems.js +1 -1
- package/lib/allowAdditionalItems.js.map +1 -1
- package/lib/asNumber.d.ts +1 -0
- package/lib/asNumber.d.ts.map +1 -0
- package/lib/asNumber.js +1 -1
- package/lib/asNumber.js.map +1 -1
- package/lib/canExpand.d.ts +2 -1
- package/lib/canExpand.d.ts.map +1 -0
- package/lib/canExpand.js +1 -1
- package/lib/canExpand.js.map +1 -1
- package/lib/constIsAjvDataReference.d.ts +2 -1
- package/lib/constIsAjvDataReference.d.ts.map +1 -0
- package/lib/constIsAjvDataReference.js +2 -3
- package/lib/constIsAjvDataReference.js.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/createErrorHandler.d.ts +2 -1
- package/lib/createErrorHandler.d.ts.map +1 -0
- package/lib/createErrorHandler.js +3 -4
- package/lib/createErrorHandler.js.map +1 -1
- package/lib/createSchemaUtils.d.ts +2 -1
- package/lib/createSchemaUtils.d.ts.map +1 -0
- package/lib/createSchemaUtils.js +10 -7
- package/lib/createSchemaUtils.js.map +1 -1
- package/lib/dataURItoBlob.d.ts +1 -0
- package/lib/dataURItoBlob.d.ts.map +1 -0
- package/lib/dataURItoBlob.js +1 -2
- package/lib/dataURItoBlob.js.map +1 -1
- package/lib/dateRangeOptions.d.ts +2 -1
- package/lib/dateRangeOptions.d.ts.map +1 -0
- package/lib/dateRangeOptions.js +1 -1
- package/lib/dateRangeOptions.js.map +1 -1
- package/lib/deepEquals.d.ts +1 -0
- package/lib/deepEquals.d.ts.map +1 -0
- package/lib/englishStringTranslator.d.ts +2 -1
- package/lib/englishStringTranslator.d.ts.map +1 -0
- package/lib/englishStringTranslator.js +1 -1
- package/lib/englishStringTranslator.js.map +1 -1
- package/lib/enumOptionSelectedValue.d.ts +2 -1
- package/lib/enumOptionSelectedValue.d.ts.map +1 -0
- package/lib/enumOptionSelectedValue.js +1 -1
- package/lib/enumOptionSelectedValue.js.map +1 -1
- package/lib/enumOptionValueDecoder.d.ts +2 -1
- package/lib/enumOptionValueDecoder.d.ts.map +1 -0
- package/lib/enumOptionValueDecoder.js +1 -1
- package/lib/enumOptionValueDecoder.js.map +1 -1
- package/lib/enumOptionValueEncoder.d.ts +2 -1
- package/lib/enumOptionValueEncoder.d.ts.map +1 -0
- package/lib/enumOptionValueEncoder.js +1 -2
- package/lib/enumOptionValueEncoder.js.map +1 -1
- package/lib/enumOptionsDeselectValue.d.ts +2 -1
- package/lib/enumOptionsDeselectValue.d.ts.map +1 -0
- package/lib/enumOptionsDeselectValue.js +2 -2
- package/lib/enumOptionsDeselectValue.js.map +1 -1
- package/lib/enumOptionsIndexForValue.d.ts +2 -1
- package/lib/enumOptionsIndexForValue.d.ts.map +1 -0
- package/lib/enumOptionsIndexForValue.js +1 -1
- package/lib/enumOptionsIndexForValue.js.map +1 -1
- package/lib/enumOptionsIsSelected.d.ts +2 -1
- package/lib/enumOptionsIsSelected.d.ts.map +1 -0
- package/lib/enumOptionsIsSelected.js +1 -1
- package/lib/enumOptionsIsSelected.js.map +1 -1
- package/lib/enumOptionsSelectValue.d.ts +2 -1
- package/lib/enumOptionsSelectValue.d.ts.map +1 -0
- package/lib/enumOptionsSelectValue.js +2 -3
- package/lib/enumOptionsSelectValue.js.map +1 -1
- package/lib/enumOptionsValueForIndex.d.ts +2 -1
- package/lib/enumOptionsValueForIndex.d.ts.map +1 -0
- package/lib/enums.d.ts +1 -0
- package/lib/enums.d.ts.map +1 -0
- package/lib/findSchemaDefinition.d.ts +2 -1
- package/lib/findSchemaDefinition.d.ts.map +1 -0
- package/lib/findSchemaDefinition.js +7 -11
- package/lib/findSchemaDefinition.js.map +1 -1
- package/lib/getChangedFields.d.ts +11 -2
- package/lib/getChangedFields.d.ts.map +1 -0
- package/lib/getChangedFields.js +57 -18
- package/lib/getChangedFields.js.map +1 -1
- package/lib/getDateElementProps.d.ts +2 -1
- package/lib/getDateElementProps.d.ts.map +1 -0
- package/lib/getDecimalSeparator.d.ts +1 -0
- package/lib/getDecimalSeparator.d.ts.map +1 -0
- package/lib/getDecimalSeparator.js +1 -2
- package/lib/getDecimalSeparator.js.map +1 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts +2 -1
- package/lib/getDiscriminatorFieldFromSchema.d.ts.map +1 -0
- package/lib/getDiscriminatorFieldFromSchema.js +4 -5
- package/lib/getDiscriminatorFieldFromSchema.js.map +1 -1
- package/lib/getInputProps.d.ts +2 -1
- package/lib/getInputProps.d.ts.map +1 -0
- package/lib/getInputProps.js +4 -1
- package/lib/getInputProps.js.map +1 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts +2 -1
- package/lib/getOptionMatchingSimpleDiscriminator.d.ts.map +1 -0
- package/lib/getOptionMatchingSimpleDiscriminator.js +6 -6
- package/lib/getOptionMatchingSimpleDiscriminator.js.map +1 -1
- package/lib/getOptionValueFormat.d.ts +2 -1
- package/lib/getOptionValueFormat.d.ts.map +1 -0
- package/lib/getOptionValueFormat.js +1 -2
- package/lib/getOptionValueFormat.js.map +1 -1
- package/lib/getPropertySchema.d.ts +12 -0
- package/lib/getPropertySchema.d.ts.map +1 -0
- package/lib/getPropertySchema.js +14 -0
- package/lib/getPropertySchema.js.map +1 -0
- package/lib/getSchemaType.d.ts +2 -1
- package/lib/getSchemaType.d.ts.map +1 -0
- package/lib/getSchemaType.js +1 -1
- package/lib/getSchemaType.js.map +1 -1
- package/lib/getSubmitButtonOptions.d.ts +2 -1
- package/lib/getSubmitButtonOptions.d.ts.map +1 -0
- package/lib/getSubmitButtonOptions.js +3 -3
- package/lib/getSubmitButtonOptions.js.map +1 -1
- package/lib/getTemplate.d.ts +2 -1
- package/lib/getTemplate.d.ts.map +1 -0
- package/lib/getTestIds.d.ts +2 -1
- package/lib/getTestIds.d.ts.map +1 -0
- package/lib/getTestIds.js +6 -5
- package/lib/getTestIds.js.map +1 -1
- package/lib/getUiOptions.d.ts +2 -1
- package/lib/getUiOptions.d.ts.map +1 -0
- package/lib/getUiOptions.js +2 -2
- package/lib/getUiOptions.js.map +1 -1
- package/lib/getWidget.d.ts +2 -1
- package/lib/getWidget.d.ts.map +1 -0
- package/lib/getWidget.js +6 -7
- package/lib/getWidget.js.map +1 -1
- package/lib/guessType.d.ts +2 -1
- package/lib/guessType.d.ts.map +1 -0
- package/lib/hasWidget.d.ts +2 -1
- package/lib/hasWidget.d.ts.map +1 -0
- package/lib/hasWidget.js +1 -1
- package/lib/hasWidget.js.map +1 -1
- package/lib/hashForSchema.d.ts +2 -1
- package/lib/hashForSchema.d.ts.map +1 -0
- package/lib/idGenerators.d.ts +2 -1
- package/lib/idGenerators.d.ts.map +1 -0
- package/lib/idGenerators.js +2 -3
- package/lib/idGenerators.js.map +1 -1
- package/lib/index.d.ts +93 -87
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +85 -81
- package/lib/index.js.map +1 -1
- package/lib/isConstant.d.ts +2 -1
- package/lib/isConstant.d.ts.map +1 -0
- package/lib/isConstant.js +1 -1
- package/lib/isConstant.js.map +1 -1
- package/lib/isCustomWidget.d.ts +2 -1
- package/lib/isCustomWidget.d.ts.map +1 -0
- package/lib/isCustomWidget.js +1 -1
- package/lib/isCustomWidget.js.map +1 -1
- package/lib/isFixedItems.d.ts +2 -1
- package/lib/isFixedItems.d.ts.map +1 -0
- package/lib/isFixedItems.js +1 -1
- package/lib/isFixedItems.js.map +1 -1
- package/lib/isFormDataAvailable.d.ts +1 -0
- package/lib/isFormDataAvailable.d.ts.map +1 -0
- package/lib/isFormDataAvailable.js +7 -4
- package/lib/isFormDataAvailable.js.map +1 -1
- package/lib/isObject.d.ts +3 -1
- package/lib/isObject.d.ts.map +1 -0
- package/lib/isObject.js +8 -2
- package/lib/isObject.js.map +1 -1
- package/lib/isPlainObject.d.ts +9 -0
- package/lib/isPlainObject.d.ts.map +1 -0
- package/lib/isPlainObject.js +15 -0
- package/lib/isPlainObject.js.map +1 -0
- package/lib/isRootSchema.d.ts +2 -1
- package/lib/isRootSchema.d.ts.map +1 -0
- package/lib/isRootSchema.js +2 -2
- package/lib/isRootSchema.js.map +1 -1
- package/lib/jsonSchemaAugmentation.d.ts +1 -0
- package/lib/jsonSchemaAugmentation.d.ts.map +1 -0
- package/lib/labelValue.d.ts +1 -0
- package/lib/labelValue.d.ts.map +1 -0
- package/lib/localToUTC.d.ts +1 -0
- package/lib/localToUTC.d.ts.map +1 -0
- package/lib/logUnsupportedDefaultForEnum.d.ts +2 -1
- package/lib/logUnsupportedDefaultForEnum.d.ts.map +1 -0
- package/lib/logUnsupportedDefaultForEnum.js +1 -1
- package/lib/logUnsupportedDefaultForEnum.js.map +1 -1
- package/lib/lookupFromFormContext.d.ts +3 -2
- package/lib/lookupFromFormContext.d.ts.map +1 -0
- package/lib/lookupFromFormContext.js +4 -5
- package/lib/lookupFromFormContext.js.map +1 -1
- package/lib/mergeDefaultsWithFormData.d.ts +1 -0
- package/lib/mergeDefaultsWithFormData.d.ts.map +1 -0
- package/lib/mergeDefaultsWithFormData.js +20 -16
- package/lib/mergeDefaultsWithFormData.js.map +1 -1
- package/lib/mergeObjects.d.ts +2 -1
- package/lib/mergeObjects.d.ts.map +1 -0
- package/lib/mergeObjects.js +1 -1
- package/lib/mergeObjects.js.map +1 -1
- package/lib/mergeSchemas.d.ts +2 -1
- package/lib/mergeSchemas.d.ts.map +1 -0
- package/lib/mergeSchemas.js +4 -5
- package/lib/mergeSchemas.js.map +1 -1
- package/lib/nameGenerators.d.ts +2 -1
- package/lib/nameGenerators.d.ts.map +1 -0
- package/lib/noop.d.ts +5 -0
- package/lib/noop.d.ts.map +1 -0
- package/lib/noop.js +5 -0
- package/lib/noop.js.map +1 -0
- package/lib/optionsList.d.ts +2 -1
- package/lib/optionsList.d.ts.map +1 -0
- package/lib/optionsList.js +15 -15
- package/lib/optionsList.js.map +1 -1
- package/lib/orderProperties.d.ts +1 -0
- package/lib/orderProperties.d.ts.map +1 -0
- package/lib/pad.d.ts +1 -0
- package/lib/pad.d.ts.map +1 -0
- package/lib/parseDateString.d.ts +2 -1
- package/lib/parseDateString.d.ts.map +1 -0
- package/lib/parser/ParserValidator.d.ts +2 -1
- package/lib/parser/ParserValidator.d.ts.map +1 -0
- package/lib/parser/ParserValidator.js +8 -7
- package/lib/parser/ParserValidator.js.map +1 -1
- package/lib/parser/index.d.ts +3 -2
- package/lib/parser/index.d.ts.map +1 -0
- package/lib/parser/index.js +1 -1
- package/lib/parser/index.js.map +1 -1
- package/lib/parser/schemaParser.d.ts +3 -2
- package/lib/parser/schemaParser.d.ts.map +1 -0
- package/lib/parser/schemaParser.js +6 -7
- package/lib/parser/schemaParser.js.map +1 -1
- package/lib/pathUtils.d.ts +77 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +192 -0
- package/lib/pathUtils.js.map +1 -0
- package/lib/rangeSpec.d.ts +2 -1
- package/lib/rangeSpec.d.ts.map +1 -0
- package/lib/removeOptionalEmptyObjects.d.ts +2 -1
- package/lib/removeOptionalEmptyObjects.d.ts.map +1 -0
- package/lib/removeOptionalEmptyObjects.js +2 -2
- package/lib/removeOptionalEmptyObjects.js.map +1 -1
- package/lib/replaceStringParameters.d.ts +1 -0
- package/lib/replaceStringParameters.d.ts.map +1 -0
- package/lib/resolveUiSchema.d.ts +2 -1
- package/lib/resolveUiSchema.d.ts.map +1 -0
- package/lib/resolveUiSchema.js +6 -8
- package/lib/resolveUiSchema.js.map +1 -1
- package/lib/schema/findFieldInSchema.d.ts +2 -1
- package/lib/schema/findFieldInSchema.d.ts.map +1 -0
- package/lib/schema/findFieldInSchema.js +10 -11
- package/lib/schema/findFieldInSchema.js.map +1 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts +2 -1
- package/lib/schema/findSelectedOptionInXxxOf.d.ts.map +1 -0
- package/lib/schema/findSelectedOptionInXxxOf.js +7 -7
- package/lib/schema/findSelectedOptionInXxxOf.js.map +1 -1
- package/lib/schema/getClosestMatchingOption.d.ts +2 -1
- package/lib/schema/getClosestMatchingOption.d.ts.map +1 -0
- package/lib/schema/getClosestMatchingOption.js +18 -23
- package/lib/schema/getClosestMatchingOption.js.map +1 -1
- package/lib/schema/getDefaultFormState.d.ts +2 -1
- package/lib/schema/getDefaultFormState.d.ts.map +1 -0
- package/lib/schema/getDefaultFormState.js +78 -56
- package/lib/schema/getDefaultFormState.js.map +1 -1
- package/lib/schema/getDisplayLabel.d.ts +2 -1
- package/lib/schema/getDisplayLabel.d.ts.map +1 -0
- package/lib/schema/getDisplayLabel.js +7 -7
- package/lib/schema/getDisplayLabel.js.map +1 -1
- package/lib/schema/getFirstMatchingOption.d.ts +2 -1
- package/lib/schema/getFirstMatchingOption.d.ts.map +1 -0
- package/lib/schema/getFirstMatchingOption.js +9 -9
- package/lib/schema/getFirstMatchingOption.js.map +1 -1
- package/lib/schema/getFromSchema.d.ts +3 -2
- package/lib/schema/getFromSchema.d.ts.map +1 -0
- package/lib/schema/getFromSchema.js +10 -11
- package/lib/schema/getFromSchema.js.map +1 -1
- package/lib/schema/index.d.ts +15 -14
- package/lib/schema/index.d.ts.map +1 -0
- package/lib/schema/index.js +14 -14
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/isFilesArray.d.ts +2 -1
- package/lib/schema/isFilesArray.d.ts.map +1 -0
- package/lib/schema/isFilesArray.js +2 -2
- package/lib/schema/isFilesArray.js.map +1 -1
- package/lib/schema/isMultiSelect.d.ts +2 -1
- package/lib/schema/isMultiSelect.d.ts.map +1 -0
- package/lib/schema/isMultiSelect.js +1 -1
- package/lib/schema/isMultiSelect.js.map +1 -1
- package/lib/schema/isSelect.d.ts +2 -1
- package/lib/schema/isSelect.d.ts.map +1 -0
- package/lib/schema/isSelect.js +2 -2
- package/lib/schema/isSelect.js.map +1 -1
- package/lib/schema/omitExtraData.d.ts +2 -1
- package/lib/schema/omitExtraData.d.ts.map +1 -0
- package/lib/schema/omitExtraData.js +100 -64
- package/lib/schema/omitExtraData.js.map +1 -1
- package/lib/schema/retrieveSchema.d.ts +2 -1
- package/lib/schema/retrieveSchema.d.ts.map +1 -0
- package/lib/schema/retrieveSchema.js +32 -40
- package/lib/schema/retrieveSchema.js.map +1 -1
- package/lib/schema/sanitizeDataForNewSchema.d.ts +4 -3
- package/lib/schema/sanitizeDataForNewSchema.d.ts.map +1 -0
- package/lib/schema/sanitizeDataForNewSchema.js +41 -39
- package/lib/schema/sanitizeDataForNewSchema.js.map +1 -1
- package/lib/schema/shallowAllOfMerge.d.ts +1 -0
- package/lib/schema/shallowAllOfMerge.d.ts.map +1 -0
- package/lib/schema/toPathSchema.d.ts +2 -1
- package/lib/schema/toPathSchema.d.ts.map +1 -0
- package/lib/schema/toPathSchema.js +14 -14
- package/lib/schema/toPathSchema.js.map +1 -1
- package/lib/schemaRequiresTrueValue.d.ts +2 -1
- package/lib/schemaRequiresTrueValue.d.ts.map +1 -0
- package/lib/schemaRequiresTrueValue.js +3 -4
- package/lib/schemaRequiresTrueValue.js.map +1 -1
- package/lib/shallowEquals.d.ts +1 -0
- package/lib/shallowEquals.d.ts.map +1 -0
- package/lib/shouldRender.d.ts +2 -1
- package/lib/shouldRender.d.ts.map +1 -0
- package/lib/shouldRender.js +2 -2
- package/lib/shouldRender.js.map +1 -1
- package/lib/shouldRenderOptionalField.d.ts +2 -1
- package/lib/shouldRenderOptionalField.d.ts.map +1 -0
- package/lib/shouldRenderOptionalField.js +11 -10
- package/lib/shouldRenderOptionalField.js.map +1 -1
- package/lib/toConstant.d.ts +2 -1
- package/lib/toConstant.d.ts.map +1 -0
- package/lib/toConstant.js +1 -1
- package/lib/toConstant.js.map +1 -1
- package/lib/toDateString.d.ts +2 -1
- package/lib/toDateString.d.ts.map +1 -0
- package/lib/toErrorList.d.ts +2 -1
- package/lib/toErrorList.d.ts.map +1 -0
- package/lib/toErrorList.js +20 -21
- package/lib/toErrorList.js.map +1 -1
- package/lib/toErrorSchema.d.ts +2 -1
- package/lib/toErrorSchema.d.ts.map +1 -0
- package/lib/toErrorSchema.js +4 -9
- package/lib/toErrorSchema.js.map +1 -1
- package/lib/toFieldPathId.d.ts +2 -1
- package/lib/toFieldPathId.d.ts.map +1 -0
- package/lib/toFieldPathId.js +2 -2
- package/lib/toFieldPathId.js.map +1 -1
- package/lib/types.d.ts +15 -5
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/unwrapErrorHandler.d.ts +2 -1
- package/lib/unwrapErrorHandler.d.ts.map +1 -0
- package/lib/unwrapErrorHandler.js +13 -4
- package/lib/unwrapErrorHandler.js.map +1 -1
- package/lib/useAltDateWidgetProps.d.ts +3 -2
- package/lib/useAltDateWidgetProps.d.ts.map +1 -0
- package/lib/useAltDateWidgetProps.js +5 -5
- package/lib/useAltDateWidgetProps.js.map +1 -1
- package/lib/useDeepCompareMemo.d.ts +1 -0
- package/lib/useDeepCompareMemo.d.ts.map +1 -0
- package/lib/useDeepCompareMemo.js +1 -1
- package/lib/useDeepCompareMemo.js.map +1 -1
- package/lib/useFileWidgetProps.d.ts +1 -0
- package/lib/useFileWidgetProps.d.ts.map +1 -0
- package/lib/useFileWidgetProps.js +3 -4
- package/lib/useFileWidgetProps.js.map +1 -1
- package/lib/utcToLocal.d.ts +1 -0
- package/lib/utcToLocal.d.ts.map +1 -0
- package/lib/utcToLocal.js +1 -1
- package/lib/utcToLocal.js.map +1 -1
- package/lib/validationDataMerge.d.ts +2 -1
- package/lib/validationDataMerge.d.ts.map +1 -0
- package/lib/validationDataMerge.js +3 -4
- package/lib/validationDataMerge.js.map +1 -1
- package/lib/withIdRefPrefix.d.ts +2 -1
- package/lib/withIdRefPrefix.d.ts.map +1 -0
- package/lib/withIdRefPrefix.js +2 -2
- package/lib/withIdRefPrefix.js.map +1 -1
- package/package.json +5 -6
- package/src/ErrorSchemaBuilder.ts +25 -24
- package/src/SelectedOptionDescription.tsx +5 -5
- package/src/allowAdditionalItems.ts +2 -2
- package/src/asNumber.ts +1 -1
- package/src/canExpand.ts +2 -2
- package/src/constIsAjvDataReference.ts +5 -4
- package/src/createErrorHandler.ts +5 -7
- package/src/createSchemaUtils.ts +8 -10
- package/src/dateRangeOptions.ts +2 -2
- package/src/englishStringTranslator.ts +2 -2
- package/src/enumOptionSelectedValue.ts +2 -2
- package/src/enumOptionValueDecoder.ts +2 -2
- package/src/enumOptionValueEncoder.ts +2 -4
- package/src/enumOptionsDeselectValue.ts +3 -3
- package/src/enumOptionsIndexForValue.ts +2 -2
- package/src/enumOptionsIsSelected.ts +2 -2
- package/src/enumOptionsSelectValue.ts +3 -5
- package/src/enumOptionsValueForIndex.ts +1 -1
- package/src/findSchemaDefinition.ts +8 -12
- package/src/getChangedFields.ts +57 -18
- package/src/getDateElementProps.ts +1 -1
- package/src/getDiscriminatorFieldFromSchema.ts +5 -7
- package/src/getInputProps.ts +6 -2
- package/src/getOptionMatchingSimpleDiscriminator.ts +7 -7
- package/src/getOptionValueFormat.ts +1 -1
- package/src/getPropertySchema.ts +18 -0
- package/src/getSchemaType.ts +2 -2
- package/src/getSubmitButtonOptions.ts +3 -3
- package/src/getTemplate.ts +1 -1
- package/src/getTestIds.ts +7 -6
- package/src/getUiOptions.ts +3 -3
- package/src/getWidget.tsx +6 -6
- package/src/hasWidget.ts +2 -2
- package/src/hashForSchema.ts +1 -1
- package/src/idGenerators.ts +3 -5
- package/src/index.ts +99 -85
- package/src/isConstant.ts +2 -2
- package/src/isCustomWidget.ts +2 -2
- package/src/isFixedItems.ts +2 -2
- package/src/isFormDataAvailable.ts +7 -5
- package/src/isObject.ts +15 -3
- package/src/isPlainObject.ts +14 -0
- package/src/isRootSchema.ts +3 -3
- package/src/logUnsupportedDefaultForEnum.ts +2 -2
- package/src/lookupFromFormContext.ts +7 -8
- package/src/mergeDefaultsWithFormData.ts +22 -18
- package/src/mergeObjects.ts +2 -2
- package/src/mergeSchemas.ts +5 -7
- package/src/nameGenerators.ts +1 -1
- package/src/noop.ts +4 -0
- package/src/optionsList.ts +9 -9
- package/src/orderProperties.ts +1 -1
- package/src/parseDateString.ts +1 -1
- package/src/parser/ParserValidator.ts +5 -7
- package/src/parser/index.ts +2 -2
- package/src/parser/schemaParser.ts +8 -10
- package/src/pathUtils.ts +203 -0
- package/src/rangeSpec.ts +1 -1
- package/src/removeOptionalEmptyObjects.ts +3 -3
- package/src/resolveUiSchema.ts +5 -7
- package/src/schema/findFieldInSchema.ts +11 -13
- package/src/schema/findSelectedOptionInXxxOf.ts +9 -10
- package/src/schema/getClosestMatchingOption.ts +73 -83
- package/src/schema/getDefaultFormState.ts +62 -34
- package/src/schema/getDisplayLabel.ts +7 -7
- package/src/schema/getFirstMatchingOption.ts +10 -11
- package/src/schema/getFromSchema.ts +12 -14
- package/src/schema/index.ts +14 -14
- package/src/schema/isFilesArray.ts +3 -3
- package/src/schema/isMultiSelect.ts +2 -2
- package/src/schema/isSelect.ts +3 -3
- package/src/schema/omitExtraData.ts +104 -68
- package/src/schema/retrieveSchema.ts +47 -60
- package/src/schema/sanitizeDataForNewSchema.ts +42 -41
- package/src/schema/toPathSchema.ts +14 -14
- package/src/schemaRequiresTrueValue.ts +1 -1
- package/src/shouldRender.ts +3 -3
- package/src/shouldRenderOptionalField.ts +14 -14
- package/src/toConstant.ts +2 -2
- package/src/toDateString.ts +1 -1
- package/src/toErrorList.ts +22 -25
- package/src/toErrorSchema.ts +5 -11
- package/src/toFieldPathId.ts +2 -2
- package/src/types.ts +14 -5
- package/src/unwrapErrorHandler.ts +15 -6
- package/src/useAltDateWidgetProps.tsx +7 -7
- package/src/useDeepCompareMemo.ts +1 -1
- package/src/useFileWidgetProps.ts +1 -1
- package/src/utcToLocal.ts +1 -1
- package/src/validationDataMerge.ts +4 -6
- package/src/withIdRefPrefix.ts +3 -4
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/tsconfig.json +0 -9
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import isEmpty from 'lodash/isEmpty';
|
|
2
|
-
import isNil from 'lodash/isNil';
|
|
3
|
-
import isObject from 'lodash/isObject';
|
|
4
|
-
|
|
5
1
|
/** Determines whether the given `formData` represents valid form data, such as a primitive type, an array, or a
|
|
6
2
|
* non-empty object.
|
|
7
3
|
*
|
|
@@ -9,5 +5,11 @@ import isObject from 'lodash/isObject';
|
|
|
9
5
|
* @returns - True if `formData` is not undefined, null, a primitive type or an array or an empty object
|
|
10
6
|
*/
|
|
11
7
|
export default function isFormDataAvailable<T = any>(formData?: T): boolean {
|
|
12
|
-
|
|
8
|
+
if (formData === undefined || formData === null) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (typeof formData !== 'object' || Array.isArray(formData)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return Object.keys(formData).length > 0;
|
|
13
15
|
}
|
package/src/isObject.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
|
+
import type { GenericObjectType } from './types.ts';
|
|
2
|
+
|
|
1
3
|
/** Determines whether a `thing` is an object for the purposes of RJSF. In this case, `thing` is an object if it has
|
|
2
4
|
* the type `object` but is NOT null, an array or a File.
|
|
3
5
|
*
|
|
4
6
|
* @param thing - The thing to check to see whether it is an object
|
|
5
7
|
* @returns - True if it is a non-null, non-array, non-File object
|
|
6
8
|
*/
|
|
7
|
-
export default function isObject(thing:
|
|
9
|
+
export default function isObject(thing: unknown): thing is GenericObjectType {
|
|
8
10
|
if (typeof thing !== 'object' || thing === null) {
|
|
9
11
|
return false;
|
|
10
12
|
}
|
|
11
13
|
// lastModified is guaranteed to be a number on a File instance
|
|
12
14
|
// as per https://w3c.github.io/FileAPI/#dfn-lastModified
|
|
13
|
-
if (
|
|
15
|
+
if (
|
|
16
|
+
'lastModified' in thing &&
|
|
17
|
+
typeof thing.lastModified === 'number' &&
|
|
18
|
+
typeof File !== 'undefined' &&
|
|
19
|
+
thing instanceof File
|
|
20
|
+
) {
|
|
14
21
|
return false;
|
|
15
22
|
}
|
|
16
23
|
// getMonth is guaranteed to be a method on a Date instance
|
|
17
24
|
// as per https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.getmonth
|
|
18
|
-
if (
|
|
25
|
+
if (
|
|
26
|
+
'getMonth' in thing &&
|
|
27
|
+
typeof thing.getMonth === 'function' &&
|
|
28
|
+
typeof Date !== 'undefined' &&
|
|
29
|
+
thing instanceof Date
|
|
30
|
+
) {
|
|
19
31
|
return false;
|
|
20
32
|
}
|
|
21
33
|
return !Array.isArray(thing);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Determines whether `thing` is a plain object, i.e. one created by the `Object` constructor or with a `null`
|
|
2
|
+
* prototype. Unlike `isObject()`, class instances such as `Error` are not plain objects, which matters when
|
|
3
|
+
* recursively walking a structure whose nested values are expected to be plain data.
|
|
4
|
+
*
|
|
5
|
+
* @param thing - The thing to check to see whether it is a plain object
|
|
6
|
+
* @returns - True if it is a plain object, otherwise false
|
|
7
|
+
*/
|
|
8
|
+
export default function isPlainObject(thing: unknown): thing is Record<string, unknown> {
|
|
9
|
+
if (typeof thing !== 'object' || thing === null) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const proto = Object.getPrototypeOf(thing);
|
|
13
|
+
return proto === null || proto === Object.prototype;
|
|
14
|
+
}
|
package/src/isRootSchema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { REF_KEY } from './constants';
|
|
2
|
-
import deepEquals from './deepEquals';
|
|
3
|
-
import type { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import { REF_KEY } from './constants.ts';
|
|
2
|
+
import deepEquals from './deepEquals.ts';
|
|
3
|
+
import type { FormContextType, Registry, RJSFSchema, StrictRJSFSchema } from './types.ts';
|
|
4
4
|
|
|
5
5
|
/** Helper to check whether a JSON schema object is the root schema. The schema is a root schema with root `properties`
|
|
6
6
|
* key or a root `$ref` key. If the `schemaToCompare` has a root `oneOf` property, the function will
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import enumOptionsIndexForValue from './enumOptionsIndexForValue';
|
|
2
|
-
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import enumOptionsIndexForValue from './enumOptionsIndexForValue.ts';
|
|
2
|
+
import type { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types.ts';
|
|
3
3
|
|
|
4
4
|
/** Logs a warning when a single-select enum widget has a schema default that is not one of its enum options.
|
|
5
5
|
*
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { FORM_CONTEXT_NAME, LOOKUP_MAP_NAME } from './constants';
|
|
5
|
-
import type { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types';
|
|
1
|
+
import { FORM_CONTEXT_NAME, LOOKUP_MAP_NAME } from './constants.ts';
|
|
2
|
+
import { getByPath, hasByPath } from './pathUtils.ts';
|
|
3
|
+
import type { FormContextType, RJSFSchema, Registry, StrictRJSFSchema } from './types.ts';
|
|
6
4
|
|
|
7
5
|
/** Given a React JSON Schema Form registry or formContext object, return the value associated with `toLookup`. This
|
|
8
6
|
* might be contained within the lookup map in the formContext. If no such value exists, return the `fallback`
|
|
@@ -17,10 +15,11 @@ export default function lookupFromFormContext<
|
|
|
17
15
|
T = any,
|
|
18
16
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
19
17
|
F extends FormContextType = any,
|
|
20
|
-
|
|
18
|
+
R = unknown,
|
|
19
|
+
>(regOrFc: Registry<T, S, F> | Registry<T, S, F>['formContext'], toLookup: string, fallback?: R): R {
|
|
21
20
|
const lookupPath = [LOOKUP_MAP_NAME];
|
|
22
|
-
if (
|
|
21
|
+
if (hasByPath(regOrFc, FORM_CONTEXT_NAME)) {
|
|
23
22
|
lookupPath.unshift(FORM_CONTEXT_NAME);
|
|
24
23
|
}
|
|
25
|
-
return
|
|
24
|
+
return getByPath<R>(regOrFc, [...lookupPath, toLookup], fallback);
|
|
26
25
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import type { GenericObjectType } from '../src';
|
|
5
|
-
import isObject from './isObject';
|
|
1
|
+
import type { GenericObjectType } from './index.ts';
|
|
2
|
+
import isObject from './isObject.ts';
|
|
6
3
|
|
|
7
4
|
/** Merges the `defaults` object of type `T` into the `formData` of type `T`
|
|
8
5
|
*
|
|
@@ -64,27 +61,34 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
64
61
|
if (isObject(formData)) {
|
|
65
62
|
// oxlint-disable-next-line prefer-object-spread -- spread loses T type, Object.assign preserves it
|
|
66
63
|
const acc: { [key in keyof T]: any } = Object.assign({}, defaults); // Prevent mutation of source object.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
64
|
+
const formDataObj: GenericObjectType = formData;
|
|
65
|
+
const defaultsObj: GenericObjectType | undefined = isObject(defaults) ? defaults : undefined;
|
|
66
|
+
return Object.keys(formDataObj).reduce((accumulator, key) => {
|
|
67
|
+
const keyValue = formDataObj[key];
|
|
68
|
+
const keyExistsInDefaults = defaultsObj !== undefined && key in defaultsObj;
|
|
69
|
+
const keyExistsInFormData = key in formDataObj;
|
|
70
|
+
const keyDefault = defaultsObj?.[key] ?? {};
|
|
71
|
+
// If any direct child of this key's default is itself an object or array,
|
|
72
|
+
// the shallow spread below would bypass its merge rules. Route those cases
|
|
73
|
+
// to the recursive path; the recursive call repeats this check one level deeper.
|
|
74
|
+
const defaultValueNeedsDeepMerge =
|
|
75
|
+
keyExistsInDefaults &&
|
|
76
|
+
isObject(keyDefault) &&
|
|
77
|
+
Object.values(keyDefault).some((v) => isObject(v) || Array.isArray(v));
|
|
74
78
|
|
|
75
|
-
const keyDefaultIsObject = keyExistsInDefaults && isObject(
|
|
79
|
+
const keyDefaultIsObject = keyExistsInDefaults && isObject(defaultsObj?.[key]);
|
|
76
80
|
const keyHasFormDataObject = keyExistsInFormData && isObject(keyValue);
|
|
77
81
|
|
|
78
|
-
if (keyDefaultIsObject && keyHasFormDataObject && !
|
|
82
|
+
if (keyDefaultIsObject && keyHasFormDataObject && !defaultValueNeedsDeepMerge) {
|
|
79
83
|
accumulator[key as keyof T] = {
|
|
80
|
-
...
|
|
84
|
+
...defaultsObj?.[key],
|
|
81
85
|
...keyValue,
|
|
82
86
|
};
|
|
83
87
|
return accumulator;
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
accumulator[key as keyof T] = mergeDefaultsWithFormData<T>(
|
|
87
|
-
|
|
91
|
+
defaultsObj?.[key],
|
|
88
92
|
keyValue,
|
|
89
93
|
mergeExtraArrayDefaults,
|
|
90
94
|
defaultSupercedesUndefined,
|
|
@@ -104,8 +108,8 @@ export default function mergeDefaultsWithFormData<T = any>(
|
|
|
104
108
|
*/
|
|
105
109
|
if (
|
|
106
110
|
(defaultSupercedesUndefined &&
|
|
107
|
-
((!(defaults === undefined) &&
|
|
108
|
-
(overrideFormDataWithDefaults &&
|
|
111
|
+
((!(defaults === undefined) && formData == null) || (typeof formData === 'number' && Number.isNaN(formData)))) ||
|
|
112
|
+
(overrideFormDataWithDefaults && formData != null)
|
|
109
113
|
) {
|
|
110
114
|
return defaults;
|
|
111
115
|
}
|
package/src/mergeObjects.ts
CHANGED
package/src/mergeSchemas.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import isObject from './isObject';
|
|
6
|
-
import type { GenericObjectType, GenericSymbolObjectType } from './types';
|
|
1
|
+
import { REQUIRED_KEY } from './constants.ts';
|
|
2
|
+
import getSchemaType from './getSchemaType.ts';
|
|
3
|
+
import isObject from './isObject.ts';
|
|
4
|
+
import type { GenericObjectType, GenericSymbolObjectType } from './types.ts';
|
|
7
5
|
|
|
8
6
|
/** Recursively merge deeply nested schemas. The difference between `mergeSchemas` and `mergeObjects` is that
|
|
9
7
|
* `mergeSchemas` only concats arrays for values under the 'required' keyword, and when it does, it doesn't include
|
|
@@ -29,7 +27,7 @@ export default function mergeSchemas(obj1: GenericObjectType, obj2: GenericObjec
|
|
|
29
27
|
Array.isArray(right)
|
|
30
28
|
) {
|
|
31
29
|
// Don't include duplicate values when merging 'required' fields.
|
|
32
|
-
accumulator[key] =
|
|
30
|
+
accumulator[key] = [...new Set([...left, ...right])];
|
|
33
31
|
} else {
|
|
34
32
|
accumulator[key] = right;
|
|
35
33
|
}
|
package/src/nameGenerators.ts
CHANGED
package/src/noop.ts
ADDED
package/src/optionsList.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import toConstant from './toConstant';
|
|
7
|
-
import type { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types';
|
|
1
|
+
import { CONST_KEY, DEFAULT_KEY } from './constants.ts';
|
|
2
|
+
import getDiscriminatorFieldFromSchema from './getDiscriminatorFieldFromSchema.ts';
|
|
3
|
+
import getPropertySchema from './getPropertySchema.ts';
|
|
4
|
+
import getUiOptions from './getUiOptions.ts';
|
|
5
|
+
import { getByPath } from './pathUtils.ts';
|
|
6
|
+
import toConstant from './toConstant.ts';
|
|
7
|
+
import type { RJSFSchema, EnumOptionsType, EnumValue, StrictRJSFSchema, FormContextType, UiSchema } from './types.ts';
|
|
8
8
|
|
|
9
9
|
/** Reorders `options` according to `order`, which may contain a `'*'` wildcard representing all
|
|
10
10
|
* remaining options in their original order. Options not listed in `order` (and not covered by
|
|
@@ -85,8 +85,8 @@ export default function optionsList<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
85
85
|
let value: EnumOptionsType<S>['value'];
|
|
86
86
|
let label = title;
|
|
87
87
|
if (selectorField) {
|
|
88
|
-
const innerSchema
|
|
89
|
-
value =
|
|
88
|
+
const innerSchema = getPropertySchema<S>(aSchema, selectorField);
|
|
89
|
+
value = getByPath(innerSchema, DEFAULT_KEY, getByPath(innerSchema, CONST_KEY));
|
|
90
90
|
// Use nullish coalescing so that an explicitly empty string title is preserved
|
|
91
91
|
label = label ?? innerSchema?.title ?? aSchema.title ?? String(value);
|
|
92
92
|
} else {
|
package/src/orderProperties.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GenericObjectType } from './types';
|
|
1
|
+
import type { GenericObjectType } from './types.ts';
|
|
2
2
|
|
|
3
3
|
/** Given a list of `properties` and an `order` list, returns a list that contains the `properties` ordered correctly.
|
|
4
4
|
* If `order` is not an array, then the untouched `properties` list is returned. Otherwise `properties` is ordered per
|
package/src/parseDateString.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import deepEquals from '../deepEquals';
|
|
5
|
-
import hashForSchema from '../hashForSchema';
|
|
1
|
+
import { ID_KEY } from '../constants.ts';
|
|
2
|
+
import deepEquals from '../deepEquals.ts';
|
|
3
|
+
import hashForSchema from '../hashForSchema.ts';
|
|
6
4
|
import type {
|
|
7
5
|
CustomValidator,
|
|
8
6
|
ErrorSchema,
|
|
@@ -14,7 +12,7 @@ import type {
|
|
|
14
12
|
UiSchema,
|
|
15
13
|
ValidationData,
|
|
16
14
|
ValidatorType,
|
|
17
|
-
} from '../types';
|
|
15
|
+
} from '../types.ts';
|
|
18
16
|
|
|
19
17
|
/** The type of the map of schema hash to schema
|
|
20
18
|
*/
|
|
@@ -62,7 +60,7 @@ export default class ParserValidator<
|
|
|
62
60
|
* @param hash - The hash value at which to map the schema
|
|
63
61
|
*/
|
|
64
62
|
addSchema(schema: S, hash: string) {
|
|
65
|
-
const key =
|
|
63
|
+
const key = schema[ID_KEY] ?? hash;
|
|
66
64
|
const identifiedSchema = { ...schema, [ID_KEY]: key };
|
|
67
65
|
const existing = this.schemaMap[key];
|
|
68
66
|
if (!existing) {
|
package/src/parser/index.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import type { SchemaMap } from './ParserValidator';
|
|
8
|
-
import ParserValidator from './ParserValidator';
|
|
1
|
+
import { ITEMS_KEY, PROPERTIES_KEY } from '../constants.ts';
|
|
2
|
+
import deepEquals from '../deepEquals.ts';
|
|
3
|
+
import { resolveAnyOrOneOfSchemas, retrieveSchemaInternal } from '../schema/retrieveSchema.ts';
|
|
4
|
+
import type { FormContextType, RJSFSchema, StrictRJSFSchema } from '../types.ts';
|
|
5
|
+
import type { SchemaMap } from './ParserValidator.ts';
|
|
6
|
+
import ParserValidator from './ParserValidator.ts';
|
|
9
7
|
|
|
10
8
|
/** Recursive function used to parse the given `schema` belonging to the `rootSchema`. The `validator` is used to
|
|
11
9
|
* capture the sub-schemas that the `isValid()` function is called with. For each schema returned by the
|
|
@@ -31,9 +29,9 @@ function parseSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
|
|
|
31
29
|
const allOptions = resolveAnyOrOneOfSchemas<T, S, F>(validator, localSchema, rootSchema, true);
|
|
32
30
|
allOptions.forEach((s) => {
|
|
33
31
|
if (PROPERTIES_KEY in s && s[PROPERTIES_KEY]) {
|
|
34
|
-
|
|
32
|
+
for (const value of Object.values(localSchema[PROPERTIES_KEY] ?? {})) {
|
|
35
33
|
parseSchema<T, S, F>(validator, recurseList, rootSchema, value as S);
|
|
36
|
-
}
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
36
|
});
|
|
39
37
|
if (ITEMS_KEY in localSchema && !Array.isArray(localSchema.items) && typeof localSchema.items !== 'boolean') {
|
package/src/pathUtils.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import type { FieldPathList } from './types.ts';
|
|
2
|
+
|
|
3
|
+
/** A path into an object: either a list of path segments or a single property key (string or number).
|
|
4
|
+
* A bare string is ALWAYS treated as one literal key — `'a.b'` is the key `'a.b'`, not a deep path. To
|
|
5
|
+
* traverse a dotted path string, convert it explicitly with {@link toPath}
|
|
6
|
+
*/
|
|
7
|
+
export type ObjectPath = string | number | FieldPathList;
|
|
8
|
+
|
|
9
|
+
/** Matches unsigned integer strings that represent valid array indexes */
|
|
10
|
+
const reIsIndex = /^(?:0|[1-9]\d*)$/;
|
|
11
|
+
|
|
12
|
+
/** Converts a dotted path string, such as produced for validation error properties, into its list of
|
|
13
|
+
* path segments. Array indexes may be written bracketed (`'a[0].b'`) or dotted (`'a.0.b'`), and empty
|
|
14
|
+
* segments — from a leading `.`, a trailing `.` or a `..` run — are dropped.
|
|
15
|
+
*
|
|
16
|
+
* Only the grammar RJSF itself produces is supported: dots and brackets are always separators, so
|
|
17
|
+
* quoted keys are not recognized and keys containing dots must be addressed with a segment list
|
|
18
|
+
* instead of a string.
|
|
19
|
+
*
|
|
20
|
+
* @param path - The string path to convert, such as `'.level1.level2[2].level3'`
|
|
21
|
+
* @returns - The list of path segments, such as `['level1', 'level2', '2', 'level3']`
|
|
22
|
+
*/
|
|
23
|
+
export function toPath(path: string): string[] {
|
|
24
|
+
return path.split(/[.[\]]+/).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Normalizes an `ObjectPath` into a list of path segments, wrapping a single key into a one-element list */
|
|
28
|
+
function normalizePath(path: ObjectPath): FieldPathList {
|
|
29
|
+
return Array.isArray(path) ? path : [path];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Determines whether a path segment could mutate the prototype chain. Only `__proto__` can: assigning to it
|
|
33
|
+
* invokes the prototype setter rather than creating an own property. `constructor` and `prototype` are safe
|
|
34
|
+
* here — and are legal JSON Schema property names — because both reads and writes below are own-property-only,
|
|
35
|
+
* so `['constructor', 'prototype', 'polluted']` shadows `constructor` with a fresh object instead of walking
|
|
36
|
+
* into `Object.prototype`. Only writes need this check; reads are already own-property-only
|
|
37
|
+
*/
|
|
38
|
+
function isUnsafeSegment(segment: string | number): boolean {
|
|
39
|
+
return segment === '__proto__';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Determines whether a path segment represents a valid array index */
|
|
43
|
+
function isIndex(segment: string | number): boolean {
|
|
44
|
+
return typeof segment === 'number' ? Number.isInteger(segment) && segment >= 0 : reIsIndex.test(segment);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Determines whether `value` can hold properties, i.e. is an object (arrays included) or a function */
|
|
48
|
+
function isSettable(value: unknown): value is Record<PropertyKey, unknown> {
|
|
49
|
+
return value != null && (typeof value === 'object' || typeof value === 'function');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Gets the value at `path` of `obj`, returning `defaultValue` when the resolved value is `undefined`
|
|
53
|
+
*
|
|
54
|
+
* Every segment must be an OWN property, matching {@link hasByPath}, so the two can be used as a
|
|
55
|
+
* guard/read pair. Inherited members are never resolved: `getByPath({}, 'toString')` returns
|
|
56
|
+
* `defaultValue`, not `Function.prototype.toString`. For the plain form data and schemas RJSF navigates,
|
|
57
|
+
* an inherited member is never data, and the own-property rule also makes prototype internals such as
|
|
58
|
+
* `__proto__` unreachable unless they are genuine own data keys
|
|
59
|
+
*
|
|
60
|
+
* An empty segment list resolves to nothing, so `defaultValue` is returned. This matches {@link hasByPath},
|
|
61
|
+
* which is `false` for an empty path, and keeps a computed-but-empty path (`toPath('')` for a root-level
|
|
62
|
+
* validation error, say) from resolving to the whole object
|
|
63
|
+
*
|
|
64
|
+
* The value at a runtime-computed path cannot be known statically, so `R` is the CALLER'S declaration of
|
|
65
|
+
* the expected type (like `Map.get()`); it defaults to `unknown`, which forces narrowing when no type is given
|
|
66
|
+
*
|
|
67
|
+
* @param obj - The object to query
|
|
68
|
+
* @param path - The single key or list of path segments at which to get the value
|
|
69
|
+
* @param [defaultValue] - The value returned when the resolved value is `undefined`
|
|
70
|
+
* @returns - The resolved value, otherwise `defaultValue`
|
|
71
|
+
*/
|
|
72
|
+
export function getByPath<R = unknown>(obj: unknown, path: ObjectPath, defaultValue?: R): R {
|
|
73
|
+
let current: unknown;
|
|
74
|
+
if (!Array.isArray(path)) {
|
|
75
|
+
// Fast path for the most common call shape, a single constant key, avoiding the segment-list allocation
|
|
76
|
+
current = isSettable(obj) && Object.hasOwn(obj, path) ? obj[path] : undefined;
|
|
77
|
+
} else if (path.length === 0) {
|
|
78
|
+
// An empty path resolves to nothing, mirroring `hasByPath()`
|
|
79
|
+
current = undefined;
|
|
80
|
+
} else {
|
|
81
|
+
current = obj;
|
|
82
|
+
for (let i = 0; i < path.length; i++) {
|
|
83
|
+
const segment = path[i];
|
|
84
|
+
// Only own data keys resolve, so inherited members and prototype internals are never read
|
|
85
|
+
if (!isSettable(current) || !Object.hasOwn(current, segment)) {
|
|
86
|
+
current = undefined;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
current = current[segment];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// The single deliberate cast in these utilities: the resolved value is trusted to be the `R` the caller declared
|
|
93
|
+
return (current === undefined ? defaultValue : current) as R;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Sets `value` at `path` of `obj`, mutating and returning `obj`. Missing intermediate containers are
|
|
97
|
+
* created: arrays when the next segment is a valid array index, plain objects otherwise (or always plain
|
|
98
|
+
* objects when `createIntermediateObjects` is true)
|
|
99
|
+
*
|
|
100
|
+
* A `__proto__` segment is refused in any position — assigning to it would mutate the prototype chain rather
|
|
101
|
+
* than create an own property — and the write is silently skipped. Every other key, `constructor` and
|
|
102
|
+
* `prototype` included, is written as an own property
|
|
103
|
+
*
|
|
104
|
+
* @param obj - The object to modify
|
|
105
|
+
* @param path - The single key or list of path segments at which to set the value
|
|
106
|
+
* @param value - The value to set
|
|
107
|
+
* @param [createIntermediateObjects] - When true, always create plain objects for missing intermediate
|
|
108
|
+
* containers, even for numeric path segments
|
|
109
|
+
* @returns - The mutated `obj`
|
|
110
|
+
*/
|
|
111
|
+
export function setByPath<O>(obj: O, path: ObjectPath, value: unknown, createIntermediateObjects = false): O {
|
|
112
|
+
if (!isSettable(obj)) {
|
|
113
|
+
return obj;
|
|
114
|
+
}
|
|
115
|
+
// Fast path for a single constant key, avoiding the segment-list allocation
|
|
116
|
+
if (!Array.isArray(path)) {
|
|
117
|
+
// Refuse a segment that could mutate the prototype chain (prototype pollution)
|
|
118
|
+
if (!isUnsafeSegment(path)) {
|
|
119
|
+
const target: Record<PropertyKey, unknown> = obj;
|
|
120
|
+
target[path] = value;
|
|
121
|
+
}
|
|
122
|
+
return obj;
|
|
123
|
+
}
|
|
124
|
+
const segments = path;
|
|
125
|
+
// Refuse paths that could mutate the prototype chain (prototype pollution)
|
|
126
|
+
if (segments.some(isUnsafeSegment)) {
|
|
127
|
+
return obj;
|
|
128
|
+
}
|
|
129
|
+
let current: Record<PropertyKey, unknown> = obj;
|
|
130
|
+
for (let i = 0; i < segments.length; i++) {
|
|
131
|
+
const segment = segments[i];
|
|
132
|
+
if (i === segments.length - 1) {
|
|
133
|
+
current[segment] = value;
|
|
134
|
+
} else {
|
|
135
|
+
// Own properties only, so an inherited member is never traversed into
|
|
136
|
+
const existing = Object.hasOwn(current, segment) ? current[segment] : undefined;
|
|
137
|
+
if (isSettable(existing)) {
|
|
138
|
+
current = existing;
|
|
139
|
+
} else {
|
|
140
|
+
const next = createIntermediateObjects || !isIndex(segments[i + 1]) ? {} : [];
|
|
141
|
+
current[segment] = next;
|
|
142
|
+
/* v8 ignore next -- a fresh {} or [] is always settable; the guard exists only to narrow the type */
|
|
143
|
+
if (isSettable(next)) {
|
|
144
|
+
current = next;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Determines whether `obj` has an own property at `path`
|
|
153
|
+
*
|
|
154
|
+
* Every segment is checked with `Object.hasOwn()`, so inherited properties report `false` —
|
|
155
|
+
* `hasByPath({}, 'toString')` is `false`. {@link getByPath} applies the same own-property rule, so the
|
|
156
|
+
* two can be used as a guard/read pair
|
|
157
|
+
*
|
|
158
|
+
* @param obj - The object to query
|
|
159
|
+
* @param path - The single key or list of path segments to check for
|
|
160
|
+
* @returns - True if the own property exists at `path`, otherwise false
|
|
161
|
+
*/
|
|
162
|
+
export function hasByPath(obj: unknown, path: ObjectPath): boolean {
|
|
163
|
+
// Fast path for a single constant key, avoiding the segment-list allocation
|
|
164
|
+
if (!Array.isArray(path)) {
|
|
165
|
+
return isSettable(obj) && Object.hasOwn(obj, path);
|
|
166
|
+
}
|
|
167
|
+
let current: unknown = obj;
|
|
168
|
+
for (let i = 0; i < path.length; i++) {
|
|
169
|
+
if (!isSettable(current) || !Object.hasOwn(current, path[i])) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
current = current[path[i]];
|
|
173
|
+
}
|
|
174
|
+
return path.length > 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Removes the own property at `path` of `obj`, mutating `obj`
|
|
178
|
+
*
|
|
179
|
+
* Both the parent lookup and the delete are own-property-only, so no segment can reach the prototype chain and
|
|
180
|
+
* no `UNSAFE_SEGMENTS`-style guard is needed: deleting a `__proto__` that is not an own property is a no-op
|
|
181
|
+
*
|
|
182
|
+
* @param obj - The object to modify
|
|
183
|
+
* @param path - The single key or list of path segments at which to remove the property
|
|
184
|
+
* @returns - True if the property was removed or did not exist, otherwise false
|
|
185
|
+
*/
|
|
186
|
+
export function unsetByPath(obj: unknown, path: ObjectPath): boolean {
|
|
187
|
+
const segments = normalizePath(path);
|
|
188
|
+
// An empty path names no property, so there is nothing to remove
|
|
189
|
+
if (segments.length === 0) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const parent = segments.length > 1 ? getByPath(obj, segments.slice(0, -1)) : obj;
|
|
193
|
+
if (parent == null) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
// Returns false for a non-configurable property instead of throwing like `delete` in strict mode
|
|
198
|
+
return Reflect.deleteProperty(parent, segments[segments.length - 1]);
|
|
199
|
+
} catch {
|
|
200
|
+
// Reflect.deleteProperty throws when the target is a primitive
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
package/src/rangeSpec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types';
|
|
1
|
+
import type { RangeSpecType, RJSFSchema, StrictRJSFSchema } from './types.ts';
|
|
2
2
|
|
|
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 }`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import isObject from './isObject';
|
|
2
|
-
import { isValueEmpty, retrieveSchema } from './schema';
|
|
3
|
-
import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types';
|
|
1
|
+
import isObject from './isObject.ts';
|
|
2
|
+
import { isValueEmpty, retrieveSchema } from './schema/index.ts';
|
|
3
|
+
import type { FormContextType, GenericObjectType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types.ts';
|
|
4
4
|
|
|
5
5
|
/** Recursively removes optional objects from the `formData` that are empty (i.e., all their fields
|
|
6
6
|
* are undefined, null, empty strings, or themselves empty optional objects). This solves the problem
|
package/src/resolveUiSchema.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import findSchemaDefinition from './findSchemaDefinition';
|
|
5
|
-
import mergeObjects from './mergeObjects';
|
|
1
|
+
import { ANY_OF_KEY, ONE_OF_KEY, REF_KEY, RJSF_REF_KEY } from './constants.ts';
|
|
2
|
+
import findSchemaDefinition from './findSchemaDefinition.ts';
|
|
3
|
+
import mergeObjects from './mergeObjects.ts';
|
|
6
4
|
import type {
|
|
7
5
|
FormContextType,
|
|
8
6
|
GenericObjectType,
|
|
@@ -11,7 +9,7 @@ import type {
|
|
|
11
9
|
RJSFSchema,
|
|
12
10
|
StrictRJSFSchema,
|
|
13
11
|
UiSchema,
|
|
14
|
-
} from './types';
|
|
12
|
+
} from './types.ts';
|
|
15
13
|
|
|
16
14
|
/** Resolves the uiSchema for a given schema, considering `ui:definitions` stored in the registry.
|
|
17
15
|
*
|
|
@@ -41,7 +39,7 @@ export default function resolveUiSchema<
|
|
|
41
39
|
let result: UiSchema<T, S, F>;
|
|
42
40
|
if (!definitionUiSchema) {
|
|
43
41
|
result = localUiSchema || {};
|
|
44
|
-
} else if (!localUiSchema ||
|
|
42
|
+
} else if (!localUiSchema || Object.keys(localUiSchema).length === 0) {
|
|
45
43
|
result = { ...definitionUiSchema };
|
|
46
44
|
} else {
|
|
47
45
|
result = mergeObjects(definitionUiSchema as GenericObjectType, localUiSchema as GenericObjectType) as UiSchema<
|