@jsonforms/core 3.0.0-beta.0 → 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 (91) hide show
  1. package/docs/assets/js/search.json +1 -1
  2. package/docs/globals.html +318 -209
  3. package/docs/index.html +13 -4
  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/arraycontrolprops.html +21 -21
  8. package/docs/interfaces/arraylayoutprops.html +21 -21
  9. package/docs/interfaces/cellprops.html +12 -12
  10. package/docs/interfaces/combinatorrendererprops.html +143 -36
  11. package/docs/interfaces/controlprops.html +16 -16
  12. package/docs/interfaces/controlstate.html +2 -2
  13. package/docs/interfaces/controlwithdetailprops.html +17 -17
  14. package/docs/interfaces/dispatchcellprops.html +10 -10
  15. package/docs/interfaces/dispatchcellstateprops.html +10 -10
  16. package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
  17. package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
  18. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
  19. package/docs/interfaces/enumcellprops.html +13 -13
  20. package/docs/interfaces/enumoption.html +2 -2
  21. package/docs/interfaces/initactionoptions.html +14 -0
  22. package/docs/interfaces/jsonformscore.html +17 -3
  23. package/docs/interfaces/jsonformsprops.html +9 -9
  24. package/docs/interfaces/layoutprops.html +10 -10
  25. package/docs/interfaces/ownpropsofcell.html +9 -9
  26. package/docs/interfaces/ownpropsofcontrol.html +9 -12
  27. package/docs/interfaces/ownpropsofenum.html +1 -1
  28. package/docs/interfaces/ownpropsofenumcell.html +10 -10
  29. package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
  30. package/docs/interfaces/ownpropsoflayout.html +9 -9
  31. package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
  32. package/docs/interfaces/ownpropsofrenderer.html +8 -8
  33. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  34. package/docs/interfaces/removecellrendereraction.html +3 -3
  35. package/docs/interfaces/removerendereraction.html +3 -3
  36. package/docs/interfaces/removeuischemaaction.html +2 -2
  37. package/docs/interfaces/rendererprops.html +9 -9
  38. package/docs/interfaces/setajvaction.html +2 -2
  39. package/docs/interfaces/setconfigaction.html +2 -2
  40. package/docs/interfaces/setlocaleaction.html +2 -2
  41. package/docs/interfaces/setschemaaction.html +2 -2
  42. package/docs/interfaces/settranslatoraction.html +3 -3
  43. package/docs/interfaces/setuischemaaction.html +2 -2
  44. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  45. package/docs/interfaces/statepropsofarraycontrol.html +17 -17
  46. package/docs/interfaces/statepropsofarraylayout.html +17 -17
  47. package/docs/interfaces/statepropsofcell.html +11 -11
  48. package/docs/interfaces/statepropsofcombinator.html +147 -40
  49. package/docs/interfaces/statepropsofcontrol.html +18 -15
  50. package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
  51. package/docs/interfaces/statepropsofenumcell.html +12 -12
  52. package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
  53. package/docs/interfaces/statepropsoflayout.html +10 -10
  54. package/docs/interfaces/statepropsofmasteritem.html +7 -7
  55. package/docs/interfaces/statepropsofrenderer.html +9 -9
  56. package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
  57. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  58. package/docs/interfaces/updatei18naction.html +4 -4
  59. package/docs/interfaces/withclassname.html +1 -1
  60. package/lib/actions/actions.d.ts +1 -0
  61. package/lib/jsonforms-core.cjs.js +191 -176
  62. package/lib/jsonforms-core.cjs.js.map +1 -1
  63. package/lib/jsonforms-core.esm.js +174 -164
  64. package/lib/jsonforms-core.esm.js.map +1 -1
  65. package/lib/reducers/core.d.ts +1 -0
  66. package/lib/reducers/reducers.d.ts +2 -2
  67. package/lib/testers/testers.d.ts +8 -7
  68. package/lib/util/combinators.d.ts +0 -1
  69. package/lib/util/path.d.ts +10 -0
  70. package/lib/util/renderer.d.ts +2 -2
  71. package/lib/util/resolvers.d.ts +1 -1
  72. package/lib/util/util.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/src/actions/actions.ts +1 -0
  75. package/src/generators/uischema.ts +4 -4
  76. package/src/i18n/i18nUtil.ts +5 -5
  77. package/src/reducers/core.ts +30 -3
  78. package/src/reducers/reducers.ts +12 -4
  79. package/src/testers/testers.ts +60 -33
  80. package/src/util/combinators.ts +17 -32
  81. package/src/util/label.ts +2 -2
  82. package/src/util/path.ts +18 -6
  83. package/src/util/renderer.ts +20 -32
  84. package/src/util/resolvers.ts +57 -68
  85. package/src/util/util.ts +1 -1
  86. package/stats.html +1 -1
  87. package/test/generators/uischema.test.ts +18 -0
  88. package/test/reducers/core.test.ts +203 -1
  89. package/test/testers.test.ts +208 -120
  90. package/test/util/path.test.ts +37 -20
  91. package/test/util/resolvers.test.ts +99 -8
@@ -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
  }
@@ -731,7 +753,7 @@ const rendererReducer = (state = [], action) => {
731
753
 
732
754
  const NOT_APPLICABLE = -1;
733
755
  const isControl = (uischema) => !isEmpty(uischema) && uischema.scope !== undefined;
734
- const schemaMatches = (predicate) => (uischema, schema) => {
756
+ const schemaMatches = (predicate) => (uischema, schema, rootSchema) => {
735
757
  if (isEmpty(uischema) || !isControl(uischema)) {
736
758
  return false;
737
759
  }
@@ -744,27 +766,27 @@ const schemaMatches = (predicate) => (uischema, schema) => {
744
766
  }
745
767
  let currentDataSchema = schema;
746
768
  if (hasType(schema, 'object')) {
747
- currentDataSchema = resolveSchema(schema, schemaPath);
769
+ currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
748
770
  }
749
771
  if (currentDataSchema === undefined) {
750
772
  return false;
751
773
  }
752
- return predicate(currentDataSchema);
774
+ return predicate(currentDataSchema, rootSchema);
753
775
  };
754
- const schemaSubPathMatches = (subPath, predicate) => (uischema, schema) => {
776
+ const schemaSubPathMatches = (subPath, predicate) => (uischema, schema, rootSchema) => {
755
777
  if (isEmpty(uischema) || !isControl(uischema)) {
756
778
  return false;
757
779
  }
758
780
  const schemaPath = uischema.scope;
759
781
  let currentDataSchema = schema;
760
782
  if (hasType(schema, 'object')) {
761
- currentDataSchema = resolveSchema(schema, schemaPath);
783
+ currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
762
784
  }
763
785
  currentDataSchema = get(currentDataSchema, subPath);
764
786
  if (currentDataSchema === undefined) {
765
787
  return false;
766
788
  }
767
- return predicate(currentDataSchema);
789
+ return predicate(currentDataSchema, rootSchema);
768
790
  };
769
791
  const schemaTypeIs = (expectedType) => schemaMatches(schema => !isEmpty(schema) && hasType(schema, expectedType));
770
792
  const formatIs = (expectedFormat) => schemaMatches(schema => !isEmpty(schema) &&
@@ -791,16 +813,16 @@ const scopeEndIs = (expected) => (uischema) => {
791
813
  const schemaPath = uischema.scope;
792
814
  return !isEmpty(schemaPath) && last(schemaPath.split('/')) === expected;
793
815
  };
794
- const and = (...testers) => (uischema, schema) => testers.reduce((acc, tester) => acc && tester(uischema, schema), true);
795
- const or = (...testers) => (uischema, schema) => testers.reduce((acc, tester) => acc || tester(uischema, schema), false);
796
- const rankWith = (rank, tester) => (uischema, schema) => {
797
- if (tester(uischema, schema)) {
816
+ const and = (...testers) => (uischema, schema, rootSchema) => testers.reduce((acc, tester) => acc && tester(uischema, schema, rootSchema), true);
817
+ const or = (...testers) => (uischema, schema, rootSchema) => testers.reduce((acc, tester) => acc || tester(uischema, schema, rootSchema), false);
818
+ const rankWith = (rank, tester) => (uischema, schema, rootSchema) => {
819
+ if (tester(uischema, schema, rootSchema)) {
798
820
  return rank;
799
821
  }
800
822
  return NOT_APPLICABLE;
801
823
  };
802
- const withIncreasedRank = (by, rankedTester) => (uischema, schema) => {
803
- const rank = rankedTester(uischema, schema);
824
+ const withIncreasedRank = (by, rankedTester) => (uischema, schema, rootSchema) => {
825
+ const rank = rankedTester(uischema, schema, rootSchema);
804
826
  if (rank === NOT_APPLICABLE) {
805
827
  return NOT_APPLICABLE;
806
828
  }
@@ -821,30 +843,39 @@ const isMultiLineControl = and(uiTypeIs('Control'), optionIs('multi', true));
821
843
  const isDateControl = and(uiTypeIs('Control'), or(formatIs('date'), optionIs('format', 'date')));
822
844
  const isTimeControl = and(uiTypeIs('Control'), or(formatIs('time'), optionIs('format', 'time')));
823
845
  const isDateTimeControl = and(uiTypeIs('Control'), or(formatIs('date-time'), optionIs('format', 'date-time')));
824
- const isObjectArray = and(schemaMatches(schema => hasType(schema, 'array') && !Array.isArray(schema.items)
825
- ), schemaSubPathMatches('items', schema => hasType(schema, 'object')));
846
+ const isObjectArray = and(schemaMatches((schema, rootSchema) => hasType(schema, 'array') && !Array.isArray(resolveSchema(schema, 'items', rootSchema))
847
+ ), schemaSubPathMatches('items', (schema, rootSchema) => {
848
+ const resolvedSchema = schema.$ref ? resolveSchema(rootSchema, schema.$ref, rootSchema) : schema;
849
+ return hasType(resolvedSchema, 'object');
850
+ }));
826
851
  const isObjectArrayControl = and(uiTypeIs('Control'), isObjectArray);
827
- const traverse = (any, pred) => {
852
+ const traverse = (any, pred, rootSchema) => {
828
853
  if (isArray(any)) {
829
- return reduce(any, (acc, el) => acc || traverse(el, pred), false);
854
+ return reduce(any, (acc, el) => acc || traverse(el, pred, rootSchema), false);
830
855
  }
831
856
  if (pred(any)) {
832
857
  return true;
833
858
  }
859
+ if (any.$ref) {
860
+ const toTraverse = resolveSchema(rootSchema, any.$ref, rootSchema);
861
+ if (toTraverse && !toTraverse.$ref) {
862
+ return traverse(toTraverse, pred, rootSchema);
863
+ }
864
+ }
834
865
  if (any.items) {
835
- return traverse(any.items, pred);
866
+ return traverse(any.items, pred, rootSchema);
836
867
  }
837
868
  if (any.properties) {
838
- return reduce(toPairs(any.properties), (acc, [_key, val]) => acc || traverse(val, pred), false);
869
+ return reduce(toPairs(any.properties), (acc, [_key, val]) => acc || traverse(val, pred, rootSchema), false);
839
870
  }
840
871
  return false;
841
872
  };
842
- const isObjectArrayWithNesting = (uischema, schema) => {
843
- if (!uiTypeIs('Control')(uischema, schema)) {
873
+ const isObjectArrayWithNesting = (uischema, schema, rootSchema) => {
874
+ if (!uiTypeIs('Control')(uischema, schema, rootSchema)) {
844
875
  return false;
845
876
  }
846
877
  const schemaPath = uischema.scope;
847
- const resolvedSchema = resolveSchema(schema, schemaPath);
878
+ const resolvedSchema = resolveSchema(schema, schemaPath, rootSchema ?? schema);
848
879
  const wantedNestingByType = {
849
880
  object: 2,
850
881
  array: 1
@@ -854,6 +885,9 @@ const isObjectArrayWithNesting = (uischema, schema) => {
854
885
  if (val === schema) {
855
886
  return false;
856
887
  }
888
+ if (val.$ref !== undefined) {
889
+ return false;
890
+ }
857
891
  if (typeof val.type !== 'string') {
858
892
  return true;
859
893
  }
@@ -863,7 +897,7 @@ const isObjectArrayWithNesting = (uischema, schema) => {
863
897
  }
864
898
  wantedNestingByType[val.type] = typeCount - 1;
865
899
  return wantedNestingByType[val.type] === 0;
866
- })) {
900
+ }, rootSchema)) {
867
901
  return true;
868
902
  }
869
903
  if (uischema.options && uischema.options.detail) {
@@ -879,9 +913,11 @@ const isObjectArrayWithNesting = (uischema, schema) => {
879
913
  return false;
880
914
  };
881
915
  const isArrayObjectControl = isObjectArrayControl;
882
- const isPrimitiveArrayControl = and(uiTypeIs('Control'), schemaMatches(schema => deriveTypes(schema).length !== 0 && !Array.isArray(schema.items)
883
- ), schemaSubPathMatches('items', schema => {
884
- const types = deriveTypes(schema);
916
+ const isPrimitiveArrayControl = and(uiTypeIs('Control'), schemaMatches((schema, rootSchema) => deriveTypes(schema).length !== 0 &&
917
+ !Array.isArray(resolveSchema(schema, 'items', rootSchema))
918
+ ), schemaSubPathMatches('items', (schema, rootSchema) => {
919
+ const resolvedSchema = schema.$ref ? resolveSchema(rootSchema, schema.$ref, rootSchema) : schema;
920
+ const types = deriveTypes(resolvedSchema);
885
921
  return (types.length === 1 &&
886
922
  includes(['integer', 'number', 'boolean', 'string'], types[0]));
887
923
  }));
@@ -900,7 +936,7 @@ const hasCategory = (categorization) => {
900
936
  .reduce((prev, curr) => prev && curr, true);
901
937
  };
902
938
  const categorizationHasCategory = (uischema) => hasCategory(uischema);
903
- const not = (tester) => (uischema, schema) => !tester(uischema, schema);
939
+ const not = (tester) => (uischema, schema, rootSchema) => !tester(uischema, schema, rootSchema);
904
940
 
905
941
  var index$1 = /*#__PURE__*/Object.freeze({
906
942
  __proto__: null,
@@ -978,11 +1014,14 @@ const jsonFormsReducerConfig = {
978
1014
  defaultData: defaultDataReducer,
979
1015
  i18n: i18nReducer,
980
1016
  };
981
- const findUISchema = (uischemas, schema, schemaPath, path, fallbackLayoutType = 'VerticalLayout', control, rootSchema) => {
1017
+ const findUISchema = (uischemas, schema, schemaPath, path, fallback = 'VerticalLayout', control, rootSchema) => {
982
1018
  if (control && control.options && control.options.detail) {
983
1019
  if (typeof control.options.detail === 'string') {
984
1020
  if (control.options.detail.toUpperCase() === 'GENERATE') {
985
- return Generate.uiSchema(schema, fallbackLayoutType);
1021
+ if (typeof fallback === "function") {
1022
+ return fallback();
1023
+ }
1024
+ return Generate.uiSchema(schema, fallback);
986
1025
  }
987
1026
  }
988
1027
  else if (typeof control.options.detail === 'object') {
@@ -994,7 +1033,10 @@ const findUISchema = (uischemas, schema, schemaPath, path, fallbackLayoutType =
994
1033
  }
995
1034
  const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
996
1035
  if (uiSchema === undefined) {
997
- return Generate.uiSchema(schema, fallbackLayoutType, '#', rootSchema);
1036
+ if (typeof fallback === 'function') {
1037
+ return fallback();
1038
+ }
1039
+ return Generate.uiSchema(schema, fallback, '#', rootSchema);
998
1040
  }
999
1041
  return uiSchema;
1000
1042
  };
@@ -1016,6 +1058,44 @@ const getRenderers = (state) => get(state, 'jsonforms.renderers');
1016
1058
  const getCells = (state) => get(state, 'jsonforms.cells');
1017
1059
  const getUISchemas = (state) => get(state, 'jsonforms.uischemas');
1018
1060
 
1061
+ const compose = (path1, path2) => {
1062
+ let p1 = path1;
1063
+ if (!isEmpty(path1) && !isEmpty(path2) && !path2.startsWith('[')) {
1064
+ p1 = path1 + '.';
1065
+ }
1066
+ if (isEmpty(p1)) {
1067
+ return path2;
1068
+ }
1069
+ else if (isEmpty(path2)) {
1070
+ return p1;
1071
+ }
1072
+ else {
1073
+ return `${p1}${path2}`;
1074
+ }
1075
+ };
1076
+ const toDataPathSegments = (schemaPath) => {
1077
+ const s = schemaPath
1078
+ .replace(/(anyOf|allOf|oneOf)\/[\d]\//g, '')
1079
+ .replace(/(then|else)\//g, '');
1080
+ const segments = s.split('/');
1081
+ const decodedSegments = segments.map(decode);
1082
+ const startFromRoot = decodedSegments[0] === '#' || decodedSegments[0] === '';
1083
+ const startIndex = startFromRoot ? 2 : 1;
1084
+ return range(startIndex, decodedSegments.length, 2).map(idx => decodedSegments[idx]);
1085
+ };
1086
+ const toDataPath = (schemaPath) => {
1087
+ return toDataPathSegments(schemaPath).join('.');
1088
+ };
1089
+ const composeWithUi = (scopableUi, path) => {
1090
+ const segments = toDataPathSegments(scopableUi.scope);
1091
+ if (isEmpty(segments) && path === undefined) {
1092
+ return '';
1093
+ }
1094
+ return isEmpty(segments) ? path : compose(path, segments.join('.'));
1095
+ };
1096
+ const encode = (segment) => segment?.replace(/~/g, '~0').replace(/\//g, '~1');
1097
+ const decode = (pointerSegment) => pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
1098
+
1019
1099
  const isObjectSchema = (schema) => {
1020
1100
  return schema.properties !== undefined;
1021
1101
  };
@@ -1062,90 +1142,40 @@ const findAllRefs = (schema, result = {}, resolveTuples = false) => {
1062
1142
  };
1063
1143
  const invalidSegment = (pathSegment) => pathSegment === '#' || pathSegment === undefined || pathSegment === '';
1064
1144
  const resolveSchema = (schema, schemaPath, rootSchema) => {
1145
+ const segments = schemaPath?.split('/').map(decode);
1146
+ return resolveSchemaWithSegments(schema, segments, rootSchema);
1147
+ };
1148
+ const resolveSchemaWithSegments = (schema, pathSegments, rootSchema) => {
1065
1149
  if (isEmpty(schema)) {
1066
1150
  return undefined;
1067
1151
  }
1068
- const validPathSegments = schemaPath.split('/');
1069
- let resultSchema = schema;
1070
- for (let i = 0; i < validPathSegments.length; i++) {
1071
- let pathSegment = validPathSegments[i];
1072
- resultSchema =
1073
- resultSchema === undefined || resultSchema.$ref === undefined
1074
- ? resultSchema
1075
- : resolveSchema(schema, resultSchema.$ref);
1076
- if (invalidSegment(pathSegment)) {
1077
- continue;
1078
- }
1079
- let curSchema = get(resultSchema, pathSegment);
1080
- if (!curSchema) {
1081
- const schemas = [].concat(resultSchema?.oneOf ?? [], resultSchema?.allOf ?? [], resultSchema?.anyOf ?? []);
1082
- for (let item of schemas) {
1083
- curSchema = resolveSchema(item, validPathSegments.slice(i).join('/'));
1084
- if (curSchema) {
1085
- break;
1086
- }
1087
- }
1088
- if (curSchema) {
1089
- resultSchema = curSchema;
1090
- break;
1091
- }
1092
- }
1093
- resultSchema = curSchema;
1094
- }
1095
- if (resultSchema !== undefined && resultSchema.$ref !== undefined) {
1096
- try {
1097
- return retrieveResolvableSchema(schema, resultSchema.$ref);
1098
- }
1099
- catch (e) {
1100
- return retrieveResolvableSchema(rootSchema, resultSchema.$ref);
1101
- }
1102
- }
1103
- return resultSchema;
1104
- };
1105
- function retrieveResolvableSchema(full, reference) {
1106
- const child = resolveSchema(full, reference);
1107
- const allRefs = findAllRefs(child);
1108
- const innerSelfReference = allRefs[reference];
1109
- if (innerSelfReference !== undefined) {
1110
- innerSelfReference.$ref = '#';
1111
- }
1112
- return child;
1113
- }
1114
-
1115
- const compose = (path1, path2) => {
1116
- let p1 = path1;
1117
- if (!isEmpty(path1) && !isEmpty(path2) && !path2.startsWith('[')) {
1118
- p1 = path1 + '.';
1152
+ if (schema.$ref) {
1153
+ schema = resolveSchema(rootSchema, schema.$ref, rootSchema);
1119
1154
  }
1120
- if (isEmpty(p1)) {
1121
- return path2;
1155
+ if (!pathSegments || pathSegments.length === 0) {
1156
+ return schema;
1122
1157
  }
1123
- else if (isEmpty(path2)) {
1124
- return p1;
1158
+ const [segment, ...remainingSegments] = pathSegments;
1159
+ if (invalidSegment(segment)) {
1160
+ return resolveSchemaWithSegments(schema, remainingSegments, rootSchema);
1125
1161
  }
1126
- else {
1127
- return `${p1}${path2}`;
1162
+ const singleSegmentResolveSchema = get(schema, segment);
1163
+ const resolvedSchema = resolveSchemaWithSegments(singleSegmentResolveSchema, remainingSegments, rootSchema);
1164
+ if (resolvedSchema) {
1165
+ return resolvedSchema;
1128
1166
  }
1129
- };
1130
- const toDataPathSegments = (schemaPath) => {
1131
- const s = schemaPath
1132
- .replace(/anyOf\/[\d]\//g, '')
1133
- .replace(/allOf\/[\d]\//g, '')
1134
- .replace(/oneOf\/[\d]\//g, '');
1135
- const segments = s.split('/');
1136
- const startFromRoot = segments[0] === '#' || segments[0] === '';
1137
- const startIndex = startFromRoot ? 2 : 1;
1138
- return range(startIndex, segments.length, 2).map(idx => segments[idx]);
1139
- };
1140
- const toDataPath = (schemaPath) => {
1141
- return toDataPathSegments(schemaPath).join('.');
1142
- };
1143
- const composeWithUi = (scopableUi, path) => {
1144
- const segments = toDataPathSegments(scopableUi.scope);
1145
- if (isEmpty(segments) && path === undefined) {
1146
- return '';
1167
+ if (segment === 'properties' || segment === 'items') {
1168
+ let alternativeResolveResult = undefined;
1169
+ const subSchemas = [].concat(schema.oneOf ?? [], schema.allOf ?? [], schema.anyOf ?? [], schema.then ?? [], schema.else ?? []);
1170
+ for (const subSchema of subSchemas) {
1171
+ alternativeResolveResult = resolveSchemaWithSegments(subSchema, [segment, ...remainingSegments], rootSchema);
1172
+ if (alternativeResolveResult) {
1173
+ break;
1174
+ }
1175
+ }
1176
+ return alternativeResolveResult;
1147
1177
  }
1148
- return isEmpty(segments) ? path : compose(path, segments.join('.'));
1178
+ return undefined;
1149
1179
  };
1150
1180
 
1151
1181
  const isOrCondition = (condition) => condition.type === 'OR';
@@ -1315,7 +1345,7 @@ const deriveLabel = (controlElement, schemaElement) => {
1315
1345
  }
1316
1346
  if (typeof controlElement.scope === 'string') {
1317
1347
  const ref = controlElement.scope;
1318
- const label = ref.substr(ref.lastIndexOf('/') + 1);
1348
+ const label = decode(ref.substr(ref.lastIndexOf('/') + 1));
1319
1349
  return startCase(label);
1320
1350
  }
1321
1351
  return '';
@@ -1345,30 +1375,6 @@ const labelDescription = (text, show) => ({
1345
1375
  show: show
1346
1376
  });
1347
1377
 
1348
- const createLabel = (subSchema, subSchemaIndex, keyword) => {
1349
- if (subSchema.title) {
1350
- return subSchema.title;
1351
- }
1352
- else {
1353
- return keyword + '-' + subSchemaIndex;
1354
- }
1355
- };
1356
- const resolveSubSchemas = (schema, rootSchema, keyword) => {
1357
- const schemas = schema[keyword];
1358
- if (schemas.findIndex(e => e.$ref !== undefined) !== -1) {
1359
- return {
1360
- ...schema,
1361
- [keyword]: schema[keyword].map(e => e.$ref ? resolveSchema(rootSchema, e.$ref) : e)
1362
- };
1363
- }
1364
- return schema;
1365
- };
1366
- const createCombinatorRenderInfos = (combinatorSubSchemas, rootSchema, keyword, control, path, uischemas) => combinatorSubSchemas.map((subSchema, subSchemaIndex) => ({
1367
- schema: subSchema,
1368
- uischema: findUISchema(uischemas, subSchema, control.scope, path, undefined, control, rootSchema),
1369
- label: createLabel(subSchema, subSchemaIndex, keyword)
1370
- }));
1371
-
1372
1378
  const isRequired = (schema, schemaPath, rootSchema) => {
1373
1379
  const pathSegments = schemaPath.split('/');
1374
1380
  const lastSegment = pathSegments[pathSegments.length - 1];
@@ -1466,8 +1472,8 @@ const mapStateToControlProps = (state, ownProps) => {
1466
1472
  const schema = resolvedSchema ?? rootSchema;
1467
1473
  const t = getTranslator()(state);
1468
1474
  const te = getErrorTranslator()(state);
1469
- const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
1470
- 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 });
1471
1477
  const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
1472
1478
  return {
1473
1479
  data,
@@ -1648,14 +1654,15 @@ const mapStateToLayoutProps = (state, ownProps) => {
1648
1654
  data,
1649
1655
  uischema: ownProps.uischema,
1650
1656
  schema: ownProps.schema,
1651
- direction: ownProps.direction ?? getDirection(uischema)
1657
+ direction: ownProps.direction ?? getDirection(uischema),
1658
+ config
1652
1659
  };
1653
1660
  };
1654
1661
  const mapStateToJsonFormsRendererProps = (state, ownProps) => {
1655
1662
  let uischema = ownProps.uischema;
1656
1663
  if (uischema === undefined) {
1657
1664
  if (ownProps.schema) {
1658
- 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);
1659
1666
  }
1660
1667
  else {
1661
1668
  uischema = getUiSchema(state);
@@ -1675,18 +1682,8 @@ const controlDefaultProps = {
1675
1682
  errors: []
1676
1683
  };
1677
1684
  const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
1678
- const { uischema } = ownProps;
1679
- const path = composeWithUi(uischema, ownProps.path);
1680
- const rootSchema = getSchema(state);
1681
- const resolvedSchema = Resolve.schema(ownProps.schema || rootSchema, uischema.scope, rootSchema);
1682
- const visible = ownProps.visible === undefined || hasShowRule(uischema)
1683
- ? isVisible(uischema, getData(state), ownProps.path, getAjv(state))
1684
- : ownProps.visible;
1685
- const id = ownProps.id;
1686
- const data = Resolve.data(getData(state), path);
1685
+ const { data, schema, ...props } = mapStateToControlProps(state, ownProps);
1687
1686
  const ajv = state.jsonforms.core.ajv;
1688
- const schema = resolvedSchema || rootSchema;
1689
- const _schema = resolveSubSchemas(schema, rootSchema, keyword);
1690
1687
  const structuralKeywords = [
1691
1688
  'required',
1692
1689
  'additionalProperties',
@@ -1700,9 +1697,9 @@ const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
1700
1697
  !errors.find(e => structuralKeywords.indexOf(e.keyword) !== -1));
1701
1698
  };
1702
1699
  let indexOfFittingSchema;
1703
- for (let i = 0; i < _schema[keyword].length; i++) {
1700
+ for (let i = 0; i < schema[keyword]?.length; i++) {
1704
1701
  try {
1705
- const valFn = ajv.compile(_schema[keyword][i]);
1702
+ const valFn = ajv.compile(schema[keyword][i]);
1706
1703
  valFn(data);
1707
1704
  if (dataIsValid(valFn.errors)) {
1708
1705
  indexOfFittingSchema = i;
@@ -1715,14 +1712,10 @@ const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
1715
1712
  }
1716
1713
  return {
1717
1714
  data,
1718
- path,
1719
1715
  schema,
1720
- rootSchema,
1721
- visible,
1722
- id,
1716
+ ...props,
1723
1717
  indexOfFittingSchema,
1724
- uischemas: state.jsonforms.uischemas,
1725
- uischema
1718
+ uischemas: getUISchemas(state)
1726
1719
  };
1727
1720
  };
1728
1721
  const mapStateToAllOfProps = (state, ownProps) => mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
@@ -1825,6 +1818,23 @@ const defaultMapDispatchToControlProps =
1825
1818
  };
1826
1819
  };
1827
1820
 
1821
+ const createLabel = (subSchema, subSchemaIndex, keyword) => {
1822
+ if (subSchema.title) {
1823
+ return subSchema.title;
1824
+ }
1825
+ else {
1826
+ return keyword + '-' + subSchemaIndex;
1827
+ }
1828
+ };
1829
+ const createCombinatorRenderInfos = (combinatorSubSchemas, rootSchema, keyword, control, path, uischemas) => combinatorSubSchemas.map((subSchema, subSchemaIndex) => {
1830
+ const schema = subSchema.$ref ? Resolve.schema(rootSchema, subSchema.$ref, rootSchema) : subSchema;
1831
+ return {
1832
+ schema,
1833
+ uischema: findUISchema(uischemas, schema, control.scope, path, undefined, control, rootSchema),
1834
+ label: createLabel(subSchema, subSchemaIndex, keyword)
1835
+ };
1836
+ });
1837
+
1828
1838
  const usedIds = new Set();
1829
1839
  const makeId = (idBase, iteration) => iteration <= 1 ? idBase : idBase + iteration.toString();
1830
1840
  const isUniqueId = (idBase, iteration) => {
@@ -1931,7 +1941,7 @@ const isCombinator = (jsonSchema) => {
1931
1941
  };
1932
1942
  const generateUISchema = (jsonSchema, schemaElements, currentRef, schemaName, layoutType, rootSchema) => {
1933
1943
  if (!isEmpty(jsonSchema) && jsonSchema.$ref !== undefined) {
1934
- return generateUISchema(resolveSchema(rootSchema, jsonSchema.$ref), schemaElements, currentRef, schemaName, layoutType, rootSchema);
1944
+ return generateUISchema(resolveSchema(rootSchema, jsonSchema.$ref, rootSchema), schemaElements, currentRef, schemaName, layoutType, rootSchema);
1935
1945
  }
1936
1946
  if (isCombinator(jsonSchema)) {
1937
1947
  const controlObject = createControlElement(currentRef);
@@ -1957,9 +1967,9 @@ const generateUISchema = (jsonSchema, schemaElements, currentRef, schemaName, la
1957
1967
  const nextRef = currentRef + '/properties';
1958
1968
  Object.keys(jsonSchema.properties).map(propName => {
1959
1969
  let value = jsonSchema.properties[propName];
1960
- const ref = `${nextRef}/${propName}`;
1970
+ const ref = `${nextRef}/${encode(propName)}`;
1961
1971
  if (value.$ref !== undefined) {
1962
- value = resolveSchema(rootSchema, value.$ref);
1972
+ value = resolveSchema(rootSchema, value.$ref, rootSchema);
1963
1973
  }
1964
1974
  generateUISchema(value, layout.elements, ref, propName, layoutType, rootSchema);
1965
1975
  });
@@ -2160,5 +2170,5 @@ const Helpers = {
2160
2170
  convertToValidClassName
2161
2171
  };
2162
2172
 
2163
- export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, 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, and, categorizationHasCategory, cellReducer, clearAllIds, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, defaultDataReducer, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultTranslator, deriveTypes, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, 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, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isPrimitiveArrayControl, isRangeControl, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, resolveSubSchemas, 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 };
2173
+ export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, 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, and, 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, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, 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, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isPrimitiveArrayControl, isRangeControl, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, 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 };
2164
2174
  //# sourceMappingURL=jsonforms-core.esm.js.map