@jsonforms/core 3.1.0 → 3.2.0-alpha.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.
@@ -4,6 +4,7 @@ import keys from 'lodash/keys';
4
4
  import merge from 'lodash/merge';
5
5
  import cloneDeep from 'lodash/cloneDeep';
6
6
  import setFp from 'lodash/fp/set';
7
+ import unsetFp from 'lodash/fp/unset';
7
8
  import get from 'lodash/get';
8
9
  import filter from 'lodash/filter';
9
10
  import isEqual from 'lodash/isEqual';
@@ -529,7 +530,13 @@ const coreReducer = (state = initState, action) => {
529
530
  else {
530
531
  const oldData = get(state.data, action.path);
531
532
  const newData = action.updater(cloneDeep(oldData));
532
- const newState = setFp(action.path, newData, state.data === undefined ? {} : state.data);
533
+ let newState;
534
+ if (newData !== undefined) {
535
+ newState = setFp(action.path, newData, state.data === undefined ? {} : state.data);
536
+ }
537
+ else {
538
+ newState = unsetFp(action.path, state.data === undefined ? {} : state.data);
539
+ }
533
540
  const errors = validate(state.validator, newState);
534
541
  return {
535
542
  ...state,
@@ -740,6 +747,14 @@ const getArrayTranslations = (t, defaultTranslations, i18nKeyPrefix, label) => {
740
747
  });
741
748
  return translations;
742
749
  };
750
+ const getCombinatorTranslations = (t, defaultTranslations, i18nKeyPrefix, label) => {
751
+ const translations = {};
752
+ defaultTranslations.forEach((controlElement) => {
753
+ const key = addI18nKeyToPrefix(i18nKeyPrefix, controlElement.key);
754
+ translations[controlElement.key] = t(key, controlElement.default(label));
755
+ });
756
+ return translations;
757
+ };
743
758
 
744
759
  var ArrayTranslationEnum;
745
760
  (function (ArrayTranslationEnum) {
@@ -787,6 +802,26 @@ const arrayDefaultTranslations = [
787
802
  { key: ArrayTranslationEnum.deleteDialogDecline, default: () => 'No' },
788
803
  ];
789
804
 
805
+ var CombinatorTranslationEnum;
806
+ (function (CombinatorTranslationEnum) {
807
+ CombinatorTranslationEnum["clearDialogTitle"] = "clearDialogTitle";
808
+ CombinatorTranslationEnum["clearDialogMessage"] = "clearDialogMessage";
809
+ CombinatorTranslationEnum["clearDialogAccept"] = "clearDialogAccept";
810
+ CombinatorTranslationEnum["clearDialogDecline"] = "clearDialogDecline";
811
+ })(CombinatorTranslationEnum || (CombinatorTranslationEnum = {}));
812
+ const combinatorDefaultTranslations = [
813
+ {
814
+ key: CombinatorTranslationEnum.clearDialogTitle,
815
+ default: () => 'Clear form?',
816
+ },
817
+ {
818
+ key: CombinatorTranslationEnum.clearDialogMessage,
819
+ default: () => 'Your data will be cleared. Do you want to proceed?',
820
+ },
821
+ { key: CombinatorTranslationEnum.clearDialogAccept, default: () => 'Yes' },
822
+ { key: CombinatorTranslationEnum.clearDialogDecline, default: () => 'No' },
823
+ ];
824
+
790
825
  const defaultJsonFormsI18nState = {
791
826
  locale: 'en',
792
827
  translate: defaultTranslator,
@@ -1315,6 +1350,9 @@ const evaluateCondition = (data, condition, path, ajv) => {
1315
1350
  }
1316
1351
  else if (isSchemaCondition(condition)) {
1317
1352
  const value = resolveData(data, getConditionScope(condition, path));
1353
+ if (condition.failWhenUndefined && value === undefined) {
1354
+ return false;
1355
+ }
1318
1356
  return ajv.validate(condition.schema, value);
1319
1357
  }
1320
1358
  else {
@@ -1709,7 +1747,7 @@ const mapDispatchToArrayControlProps = (dispatch) => ({
1709
1747
  removeItems: (path, toDelete) => () => {
1710
1748
  dispatch(update(path, (array) => {
1711
1749
  toDelete
1712
- .sort()
1750
+ .sort((a, b) => a - b)
1713
1751
  .reverse()
1714
1752
  .forEach((s) => array.splice(s, 1));
1715
1753
  return array;
@@ -1807,8 +1845,10 @@ const controlDefaultProps = {
1807
1845
  errors: [],
1808
1846
  };
1809
1847
  const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
1810
- const { data, schema, rootSchema, ...props } = mapStateToControlProps(state, ownProps);
1848
+ const { data, schema, rootSchema, i18nKeyPrefix, label, ...props } = mapStateToControlProps(state, ownProps);
1811
1849
  const ajv = state.jsonforms.core.ajv;
1850
+ const t = getTranslator()(state);
1851
+ const translations = getCombinatorTranslations(t, combinatorDefaultTranslations, i18nKeyPrefix, label);
1812
1852
  const structuralKeywords = [
1813
1853
  'required',
1814
1854
  'additionalProperties',
@@ -1844,8 +1884,11 @@ const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
1844
1884
  schema,
1845
1885
  rootSchema,
1846
1886
  ...props,
1887
+ i18nKeyPrefix,
1888
+ label,
1847
1889
  indexOfFittingSchema,
1848
1890
  uischemas: getUISchemas(state),
1891
+ translations,
1849
1892
  };
1850
1893
  };
1851
1894
  const mapStateToAllOfProps = (state, ownProps) => mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
@@ -1971,22 +2014,15 @@ const defaultMapDispatchToControlProps =
1971
2014
  };
1972
2015
  };
1973
2016
 
1974
- const createLabel = (subSchema, subSchemaIndex, keyword) => {
1975
- if (subSchema.title) {
1976
- return subSchema.title;
1977
- }
1978
- else {
1979
- return keyword + '-' + subSchemaIndex;
1980
- }
1981
- };
1982
2017
  const createCombinatorRenderInfos = (combinatorSubSchemas, rootSchema, keyword, control, path, uischemas) => combinatorSubSchemas.map((subSchema, subSchemaIndex) => {
1983
- const schema = subSchema.$ref
1984
- ? Resolve.schema(rootSchema, subSchema.$ref, rootSchema)
1985
- : subSchema;
2018
+ const resolvedSubSchema = subSchema.$ref && Resolve.schema(rootSchema, subSchema.$ref, rootSchema);
2019
+ const schema = resolvedSubSchema ?? subSchema;
1986
2020
  return {
1987
2021
  schema,
1988
2022
  uischema: findUISchema(uischemas, schema, control.scope, path, undefined, control, rootSchema),
1989
- label: createLabel(subSchema, subSchemaIndex, keyword),
2023
+ label: subSchema.title ??
2024
+ resolvedSubSchema?.title ??
2025
+ `${keyword}-${subSchemaIndex}`,
1990
2026
  };
1991
2027
  });
1992
2028
 
@@ -2330,5 +2366,5 @@ const Helpers = {
2330
2366
  convertToValidClassName,
2331
2367
  };
2332
2368
 
2333
- export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, ArrayTranslationEnum, Draft4, Generate, Helpers, INIT, NOT_APPLICABLE, Paths, REMOVE_CELL, REMOVE_DEFAULT_DATA, REMOVE_RENDERER, REMOVE_UI_SCHEMA, Resolve, RuleEffect, Runtime, SET_AJV, SET_CONFIG, SET_LOCALE, SET_SCHEMA, SET_TRANSLATOR, SET_UISCHEMA, SET_VALIDATION_MODE, index$1 as Test, UPDATE_CORE, UPDATE_DATA, UPDATE_ERRORS, UPDATE_I18N, VALIDATE, addI18nKeyToPrefix, and, arrayDefaultTranslations, categorizationHasCategory, cellReducer, clearAllIds, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, decode, defaultDataReducer, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultTranslator, deriveLabelForUISchemaElement, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, getArrayTranslations, getCells, getCombinedErrorMessage, getConfig, getControlPath, getData, getDefaultData, getErrorAt, getErrorTranslator, getFirstPrimitiveProp, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, getLocale, getRenderers, getSchema, getSubErrorsAt, getTranslator, getUISchemas, getUiSchema, hasCategory, hasEnableRule, hasShowRule, hasType, i18nReducer, init, isAllOfControl, isAnyOfControl, isArrayObjectControl, isBooleanControl, isCategorization, isCategory, isControl, isDateControl, isDateTimeControl, isDescriptionHidden, isEnabled, isEnumControl, isGroup, isInherentlyEnabled, isIntegerControl, isInternationalized, isLabelable, isLabeled, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isOneOfEnumSchema, isPrimitiveArrayControl, isRangeControl, isScopable, isScoped, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, schemaMatches, schemaSubPathMatches, schemaTypeIs, scopeEndIs, scopeEndsWith, setAjv, setConfig, setLocale, setReadonly, setSchema, setTranslator, setUISchema, setValidationMode, showAsRequired, subErrorsAt, toDataPath, toDataPathSegments, transformPathToI18nPrefix, uiTypeIs, uischemaRegistryReducer, unregisterCell, unregisterDefaultData, unregisterRenderer, unregisterUISchema, unsetReadonly, update, updateCore, updateErrors, updateI18n, validate, withIncreasedRank };
2369
+ export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, ArrayTranslationEnum, CombinatorTranslationEnum, Draft4, Generate, Helpers, INIT, NOT_APPLICABLE, Paths, REMOVE_CELL, REMOVE_DEFAULT_DATA, REMOVE_RENDERER, REMOVE_UI_SCHEMA, Resolve, RuleEffect, Runtime, SET_AJV, SET_CONFIG, SET_LOCALE, SET_SCHEMA, SET_TRANSLATOR, SET_UISCHEMA, SET_VALIDATION_MODE, index$1 as Test, UPDATE_CORE, UPDATE_DATA, UPDATE_ERRORS, UPDATE_I18N, VALIDATE, addI18nKeyToPrefix, and, arrayDefaultTranslations, categorizationHasCategory, cellReducer, clearAllIds, combinatorDefaultTranslations, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, decode, defaultDataReducer, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultTranslator, deriveLabelForUISchemaElement, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, getArrayTranslations, getCells, getCombinatorTranslations, getCombinedErrorMessage, getConfig, getControlPath, getData, getDefaultData, getErrorAt, getErrorTranslator, getFirstPrimitiveProp, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, getLocale, getRenderers, getSchema, getSubErrorsAt, getTranslator, getUISchemas, getUiSchema, hasCategory, hasEnableRule, hasShowRule, hasType, i18nReducer, init, isAllOfControl, isAnyOfControl, isArrayObjectControl, isBooleanControl, isCategorization, isCategory, isControl, isDateControl, isDateTimeControl, isDescriptionHidden, isEnabled, isEnumControl, isGroup, isInherentlyEnabled, isIntegerControl, isInternationalized, isLabelable, isLabeled, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isOneOfEnumSchema, isPrimitiveArrayControl, isRangeControl, isScopable, isScoped, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, schemaMatches, schemaSubPathMatches, schemaTypeIs, scopeEndIs, scopeEndsWith, setAjv, setConfig, setLocale, setReadonly, setSchema, setTranslator, setUISchema, setValidationMode, showAsRequired, subErrorsAt, toDataPath, toDataPathSegments, transformPathToI18nPrefix, uiTypeIs, uischemaRegistryReducer, unregisterCell, unregisterDefaultData, unregisterRenderer, unregisterUISchema, unsetReadonly, update, updateCore, updateErrors, updateI18n, validate, withIncreasedRank };
2334
2370
  //# sourceMappingURL=jsonforms-core.esm.js.map