@jsonforms/core 3.0.0-beta.2 → 3.0.0-beta.3

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.
Files changed (38) hide show
  1. package/docs/assets/js/search.json +1 -1
  2. package/docs/globals.html +122 -55
  3. package/docs/index.html +6 -0
  4. package/docs/interfaces/addcellrendereraction.html +3 -3
  5. package/docs/interfaces/addrendereraction.html +3 -3
  6. package/docs/interfaces/adduischemaaction.html +3 -3
  7. package/docs/interfaces/arraylayoutprops.html +2 -2
  8. package/docs/interfaces/combinatorrendererprops.html +6 -6
  9. package/docs/interfaces/initactionoptions.html +14 -0
  10. package/docs/interfaces/jsonformscore.html +17 -3
  11. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  12. package/docs/interfaces/removecellrendereraction.html +3 -3
  13. package/docs/interfaces/removerendereraction.html +3 -3
  14. package/docs/interfaces/removeuischemaaction.html +2 -2
  15. package/docs/interfaces/setajvaction.html +2 -2
  16. package/docs/interfaces/setconfigaction.html +2 -2
  17. package/docs/interfaces/setlocaleaction.html +2 -2
  18. package/docs/interfaces/setschemaaction.html +2 -2
  19. package/docs/interfaces/settranslatoraction.html +3 -3
  20. package/docs/interfaces/setuischemaaction.html +2 -2
  21. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  22. package/docs/interfaces/statepropsofarraylayout.html +2 -2
  23. package/docs/interfaces/statepropsofcombinator.html +6 -6
  24. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  25. package/docs/interfaces/updatei18naction.html +4 -4
  26. package/lib/actions/actions.d.ts +1 -0
  27. package/lib/jsonforms-core.cjs.js +31 -12
  28. package/lib/jsonforms-core.cjs.js.map +1 -1
  29. package/lib/jsonforms-core.esm.js +32 -10
  30. package/lib/jsonforms-core.esm.js.map +1 -1
  31. package/lib/reducers/core.d.ts +1 -0
  32. package/package.json +2 -2
  33. package/src/actions/actions.ts +1 -0
  34. package/src/i18n/i18nUtil.ts +5 -5
  35. package/src/reducers/core.ts +30 -3
  36. package/src/util/renderer.ts +6 -3
  37. package/stats.html +1 -1
  38. package/test/reducers/core.test.ts +203 -1
@@ -356,6 +356,7 @@ const initState = {
356
356
  validator: undefined,
357
357
  ajv: undefined,
358
358
  validationMode: 'ValidateAndShow',
359
+ additionalErrors: []
359
360
  };
360
361
  const reuseAjvForSchema = (ajv, schema) => {
361
362
  if (schema.hasOwnProperty('id') || schema.hasOwnProperty('$id')) {
@@ -399,6 +400,18 @@ const hasValidationModeOption = (option) => {
399
400
  }
400
401
  return false;
401
402
  };
403
+ const hasAdditionalErrorsOption = (option) => {
404
+ if (option) {
405
+ return option.additionalErrors !== undefined;
406
+ }
407
+ return false;
408
+ };
409
+ const getAdditionalErrors = (state, action) => {
410
+ if (action && hasAdditionalErrorsOption(action.options)) {
411
+ return action.options.additionalErrors;
412
+ }
413
+ return state.additionalErrors;
414
+ };
402
415
  const coreReducer = (state = initState, action) => {
403
416
  switch (action.type) {
404
417
  case INIT: {
@@ -406,11 +419,13 @@ const coreReducer = (state = initState, action) => {
406
419
  const validationMode = getValidationMode(state, action);
407
420
  const v = validationMode === 'NoValidation' ? undefined : thisAjv.compile(action.schema);
408
421
  const e = validate(v, action.data);
422
+ const additionalErrors = getAdditionalErrors(state, action);
409
423
  return {
410
424
  ...state,
411
425
  data: action.data,
412
426
  schema: action.schema,
413
427
  uischema: action.uischema,
428
+ additionalErrors,
414
429
  errors: e,
415
430
  validator: v,
416
431
  ajv: thisAjv,
@@ -434,13 +449,15 @@ const coreReducer = (state = initState, action) => {
434
449
  else if (state.data !== action.data) {
435
450
  errors = validate(validator, action.data);
436
451
  }
452
+ const additionalErrors = getAdditionalErrors(state, action);
437
453
  const stateChanged = state.data !== action.data ||
438
454
  state.schema !== action.schema ||
439
455
  state.uischema !== action.uischema ||
440
456
  state.ajv !== thisAjv ||
441
457
  state.errors !== errors ||
442
458
  state.validator !== validator ||
443
- state.validationMode !== validationMode;
459
+ state.validationMode !== validationMode ||
460
+ state.additionalErrors !== additionalErrors;
444
461
  return stateChanged
445
462
  ? {
446
463
  ...state,
@@ -451,6 +468,7 @@ const coreReducer = (state = initState, action) => {
451
468
  errors: isEqual(errors, state.errors) ? state.errors : errors,
452
469
  validator: validator,
453
470
  validationMode: validationMode,
471
+ additionalErrors
454
472
  }
455
473
  : state;
456
474
  }
@@ -594,7 +612,11 @@ const isObjectSchema$1 = (schema) => {
594
612
  return schema?.type === 'object' || !!schema?.properties;
595
613
  };
596
614
  const filteredErrorKeywords = ['additionalProperties', 'allOf', 'anyOf', 'oneOf'];
597
- const getErrorsAt = (instancePath, schema, matchPath) => (state) => errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide' ? [] : state.errors);
615
+ const getErrorsAt = (instancePath, schema, matchPath) => (state) => {
616
+ const errors = state.errors ?? [];
617
+ const additionalErrors = state.additionalErrors ?? [];
618
+ return errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide' ? additionalErrors : [...errors, ...additionalErrors]);
619
+ };
598
620
  const errorAt = (instancePath, schema) => getErrorsAt(instancePath, schema, path => path === instancePath);
599
621
  const subErrorsAt = (instancePath, schema) => getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
600
622
 
@@ -631,27 +653,27 @@ const getI18nKey = (schema, uischema, path, key) => {
631
653
  const defaultTranslator = (_id, defaultMessage) => defaultMessage;
632
654
  const defaultErrorTranslator = (error, t, uischema) => {
633
655
  const i18nKey = getI18nKey(error.parentSchema, uischema, getControlPath(error), `error.${error.keyword}`);
634
- const specializedKeywordMessage = t(i18nKey, undefined);
656
+ const specializedKeywordMessage = t(i18nKey, undefined, { error });
635
657
  if (specializedKeywordMessage !== undefined) {
636
658
  return specializedKeywordMessage;
637
659
  }
638
- const genericKeywordMessage = t(`error.${error.keyword}`, undefined);
660
+ const genericKeywordMessage = t(`error.${error.keyword}`, undefined, { error });
639
661
  if (genericKeywordMessage !== undefined) {
640
662
  return genericKeywordMessage;
641
663
  }
642
- const messageCustomization = t(error.message, undefined);
664
+ const messageCustomization = t(error.message, undefined, { error });
643
665
  if (messageCustomization !== undefined) {
644
666
  return messageCustomization;
645
667
  }
646
668
  if (error.keyword === 'required' && error.message?.startsWith('must have required property')) {
647
- return t('is a required property', 'is a required property');
669
+ return t('is a required property', 'is a required property', { error });
648
670
  }
649
671
  return error.message;
650
672
  };
651
673
  const getCombinedErrorMessage = (errors, et, t, schema, uischema, path) => {
652
674
  if (errors.length > 0 && t) {
653
675
  const customErrorKey = getI18nKey(schema, uischema, path, 'error.custom');
654
- const specializedErrorMessage = t(customErrorKey, undefined);
676
+ const specializedErrorMessage = t(customErrorKey, undefined, { schema, uischema, path, errors });
655
677
  if (specializedErrorMessage !== undefined) {
656
678
  return specializedErrorMessage;
657
679
  }
@@ -1450,8 +1472,8 @@ const mapStateToControlProps = (state, ownProps) => {
1450
1472
  const schema = resolvedSchema ?? rootSchema;
1451
1473
  const t = getTranslator()(state);
1452
1474
  const te = getErrorTranslator()(state);
1453
- const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
1454
- const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description);
1475
+ const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label, { schema, uischema, path, errors });
1476
+ const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description, { schema, uischema, path, errors });
1455
1477
  const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
1456
1478
  return {
1457
1479
  data,
@@ -1640,7 +1662,7 @@ const mapStateToJsonFormsRendererProps = (state, ownProps) => {
1640
1662
  let uischema = ownProps.uischema;
1641
1663
  if (uischema === undefined) {
1642
1664
  if (ownProps.schema) {
1643
- uischema = findUISchema(state.jsonforms.uischemas, ownProps.schema, undefined, ownProps.path);
1665
+ uischema = findUISchema(state.jsonforms.uischemas, ownProps.schema, undefined, ownProps.path, undefined, undefined, state.jsonforms.core.schema);
1644
1666
  }
1645
1667
  else {
1646
1668
  uischema = getUiSchema(state);