@jsonforms/core 3.1.0-alpha.1 → 3.1.0-alpha.2
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/README.md +3 -3
- package/lib/actions/actions.d.ts +21 -21
- package/lib/i18n/arrayTranslations.d.ts +24 -0
- package/lib/i18n/i18nUtil.d.ts +3 -0
- package/lib/i18n/index.d.ts +1 -0
- package/lib/jsonforms-core.cjs.js +427 -258
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +313 -200
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/util/cell.d.ts +0 -1
- package/lib/util/renderer.d.ts +6 -2
- package/package.json +11 -4
- package/src/Helpers.ts +1 -1
- package/src/actions/actions.ts +52 -55
- package/src/configDefault.ts +1 -1
- package/src/generators/Generate.ts +3 -1
- package/src/generators/schema.ts +29 -25
- package/src/generators/uischema.ts +7 -6
- package/src/i18n/arrayTranslations.ts +54 -0
- package/src/i18n/i18nTypes.ts +10 -6
- package/src/i18n/i18nUtil.ts +64 -14
- package/src/i18n/index.ts +1 -0
- package/src/models/draft4.ts +33 -33
- package/src/models/uischema.ts +17 -6
- package/src/reducers/cells.ts +8 -7
- package/src/reducers/core.ts +112 -73
- package/src/reducers/default-data.ts +7 -7
- package/src/reducers/i18n.ts +21 -9
- package/src/reducers/reducers.ts +20 -30
- package/src/reducers/renderers.ts +7 -7
- package/src/reducers/selectors.ts +4 -5
- package/src/reducers/uischemas.ts +25 -24
- package/src/store.ts +1 -1
- package/src/testers/testers.ts +199 -146
- package/src/util/cell.ts +24 -26
- package/src/util/combinators.ts +5 -3
- package/src/util/label.ts +1 -1
- package/src/util/path.ts +11 -7
- package/src/util/renderer.ts +118 -67
- package/src/util/resolvers.ts +15 -13
- package/src/util/runtime.ts +2 -2
- package/src/util/schema.ts +1 -1
- package/src/util/type.ts +5 -3
- package/src/util/uischema.ts +9 -9
- package/src/util/util.ts +52 -52
- package/src/util/validator.ts +1 -1
package/src/util/path.ts
CHANGED
|
@@ -65,14 +65,16 @@ export const toDataPathSegments = (schemaPath: string): string[] => {
|
|
|
65
65
|
|
|
66
66
|
const startFromRoot = decodedSegments[0] === '#' || decodedSegments[0] === '';
|
|
67
67
|
const startIndex = startFromRoot ? 2 : 1;
|
|
68
|
-
return range(startIndex, decodedSegments.length, 2).map(
|
|
68
|
+
return range(startIndex, decodedSegments.length, 2).map(
|
|
69
|
+
(idx) => decodedSegments[idx]
|
|
70
|
+
);
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
/**
|
|
72
74
|
* Convert a schema path (i.e. JSON pointer) to a data path.
|
|
73
|
-
*
|
|
75
|
+
*
|
|
74
76
|
* Data paths can be used in field change event handlers like handleChange.
|
|
75
|
-
*
|
|
77
|
+
*
|
|
76
78
|
* @example
|
|
77
79
|
* toDataPath('#/properties/foo/properties/bar') === 'foo.bar')
|
|
78
80
|
*
|
|
@@ -81,7 +83,7 @@ export const toDataPathSegments = (schemaPath: string): string[] => {
|
|
|
81
83
|
*/
|
|
82
84
|
export const toDataPath = (schemaPath: string): string => {
|
|
83
85
|
return toDataPathSegments(schemaPath).join('.');
|
|
84
|
-
|
|
86
|
+
};
|
|
85
87
|
|
|
86
88
|
export const composeWithUi = (scopableUi: Scopable, path: string): string => {
|
|
87
89
|
if (!isScoped(scopableUi)) {
|
|
@@ -99,11 +101,13 @@ export const composeWithUi = (scopableUi: Scopable, path: string): string => {
|
|
|
99
101
|
|
|
100
102
|
/**
|
|
101
103
|
* Encodes the given segment to be used as part of a JSON Pointer
|
|
102
|
-
*
|
|
104
|
+
*
|
|
103
105
|
* JSON Pointer has special meaning for "/" and "~", therefore these must be encoded
|
|
104
106
|
*/
|
|
105
|
-
export const encode = (segment: string) =>
|
|
107
|
+
export const encode = (segment: string) =>
|
|
108
|
+
segment?.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
106
109
|
/**
|
|
107
110
|
* Decodes a given JSON Pointer segment to its "normal" representation
|
|
108
111
|
*/
|
|
109
|
-
export const decode = (pointerSegment: string) =>
|
|
112
|
+
export const decode = (pointerSegment: string) =>
|
|
113
|
+
pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
|
package/src/util/renderer.ts
CHANGED
|
@@ -24,14 +24,16 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import get from 'lodash/get';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
ControlElement,
|
|
29
|
+
isLabelable,
|
|
30
|
+
JsonSchema,
|
|
31
|
+
LabelElement,
|
|
32
|
+
UISchemaElement,
|
|
33
|
+
} from '../models';
|
|
28
34
|
import find from 'lodash/find';
|
|
29
35
|
import {
|
|
30
36
|
getUISchemas,
|
|
31
|
-
JsonFormsCellRendererRegistryEntry,
|
|
32
|
-
JsonFormsRendererRegistryEntry,
|
|
33
|
-
} from '../reducers';
|
|
34
|
-
import {
|
|
35
37
|
getAjv,
|
|
36
38
|
getCells,
|
|
37
39
|
getConfig,
|
|
@@ -43,6 +45,10 @@ import {
|
|
|
43
45
|
getSubErrorsAt,
|
|
44
46
|
getTranslator,
|
|
45
47
|
getUiSchema,
|
|
48
|
+
} from '../reducers';
|
|
49
|
+
import type {
|
|
50
|
+
JsonFormsCellRendererRegistryEntry,
|
|
51
|
+
JsonFormsRendererRegistryEntry,
|
|
46
52
|
JsonFormsUISchemaRegistryEntry,
|
|
47
53
|
} from '../reducers';
|
|
48
54
|
import type { RankedTester } from '../testers';
|
|
@@ -56,7 +62,19 @@ import { composePaths, composeWithUi } from './path';
|
|
|
56
62
|
import { CoreActions, update } from '../actions';
|
|
57
63
|
import type { ErrorObject } from 'ajv';
|
|
58
64
|
import type { JsonFormsState } from '../store';
|
|
59
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
deriveLabelForUISchemaElement,
|
|
67
|
+
getCombinedErrorMessage,
|
|
68
|
+
getI18nKey,
|
|
69
|
+
getI18nKeyPrefix,
|
|
70
|
+
getI18nKeyPrefixBySchema,
|
|
71
|
+
getArrayTranslations,
|
|
72
|
+
Translator,
|
|
73
|
+
} from '../i18n';
|
|
74
|
+
import {
|
|
75
|
+
arrayDefaultTranslations,
|
|
76
|
+
ArrayTranslations,
|
|
77
|
+
} from '../i18n/arrayTranslations';
|
|
60
78
|
|
|
61
79
|
const isRequired = (
|
|
62
80
|
schema: JsonSchema,
|
|
@@ -98,7 +116,7 @@ export const computeLabel = (
|
|
|
98
116
|
required: boolean,
|
|
99
117
|
hideRequiredAsterisk: boolean
|
|
100
118
|
): string => {
|
|
101
|
-
return `${label ?? ''}${
|
|
119
|
+
return `${label ?? ''}${required && !hideRequiredAsterisk ? '*' : ''}`;
|
|
102
120
|
};
|
|
103
121
|
|
|
104
122
|
/**
|
|
@@ -108,7 +126,7 @@ export const computeLabel = (
|
|
|
108
126
|
* @param {boolean} hideRequiredAsterisk applied UI Schema option
|
|
109
127
|
* @returns {boolean} should the field be marked as required
|
|
110
128
|
*/
|
|
111
|
-
|
|
129
|
+
export const showAsRequired = (
|
|
112
130
|
required: boolean,
|
|
113
131
|
hideRequiredAsterisk: boolean
|
|
114
132
|
): boolean => {
|
|
@@ -370,6 +388,8 @@ export interface StatePropsOfControl extends StatePropsOfScopedRenderer {
|
|
|
370
388
|
*/
|
|
371
389
|
required?: boolean;
|
|
372
390
|
|
|
391
|
+
i18nKeyPrefix?: string;
|
|
392
|
+
|
|
373
393
|
// TODO: renderers?
|
|
374
394
|
}
|
|
375
395
|
|
|
@@ -450,7 +470,7 @@ export const mapStateToControlProps = (
|
|
|
450
470
|
rootSchema
|
|
451
471
|
);
|
|
452
472
|
const errors = getErrorAt(path, resolvedSchema)(state);
|
|
453
|
-
|
|
473
|
+
|
|
454
474
|
const description =
|
|
455
475
|
resolvedSchema !== undefined ? resolvedSchema.description : '';
|
|
456
476
|
const data = Resolve.data(rootData, path);
|
|
@@ -469,9 +489,26 @@ export const mapStateToControlProps = (
|
|
|
469
489
|
const schema = resolvedSchema ?? rootSchema;
|
|
470
490
|
const t = getTranslator()(state);
|
|
471
491
|
const te = getErrorTranslator()(state);
|
|
472
|
-
const
|
|
473
|
-
const
|
|
474
|
-
|
|
492
|
+
const i18nKeyPrefix = getI18nKeyPrefix(schema, uischema, path);
|
|
493
|
+
const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label, {
|
|
494
|
+
schema,
|
|
495
|
+
uischema,
|
|
496
|
+
path,
|
|
497
|
+
errors,
|
|
498
|
+
});
|
|
499
|
+
const i18nDescription = t(
|
|
500
|
+
getI18nKey(schema, uischema, path, 'description'),
|
|
501
|
+
description,
|
|
502
|
+
{ schema, uischema, path, errors }
|
|
503
|
+
);
|
|
504
|
+
const i18nErrorMessage = getCombinedErrorMessage(
|
|
505
|
+
errors,
|
|
506
|
+
te,
|
|
507
|
+
t,
|
|
508
|
+
schema,
|
|
509
|
+
uischema,
|
|
510
|
+
path
|
|
511
|
+
);
|
|
475
512
|
|
|
476
513
|
return {
|
|
477
514
|
data,
|
|
@@ -487,7 +524,8 @@ export const mapStateToControlProps = (
|
|
|
487
524
|
schema,
|
|
488
525
|
config: getConfig(state),
|
|
489
526
|
cells: ownProps.cells || state.jsonforms.cells,
|
|
490
|
-
rootSchema
|
|
527
|
+
rootSchema,
|
|
528
|
+
i18nKeyPrefix,
|
|
491
529
|
};
|
|
492
530
|
};
|
|
493
531
|
|
|
@@ -503,7 +541,7 @@ export const mapDispatchToControlProps = (
|
|
|
503
541
|
): DispatchPropsOfControl => ({
|
|
504
542
|
handleChange(path, value) {
|
|
505
543
|
dispatch(update(path, () => value));
|
|
506
|
-
}
|
|
544
|
+
},
|
|
507
545
|
});
|
|
508
546
|
|
|
509
547
|
/**
|
|
@@ -519,7 +557,7 @@ export const mapStateToEnumControlProps = (
|
|
|
519
557
|
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
|
|
520
558
|
const options: EnumOption[] =
|
|
521
559
|
ownProps.options ||
|
|
522
|
-
props.schema.enum?.map(e =>
|
|
560
|
+
props.schema.enum?.map((e) =>
|
|
523
561
|
enumToEnumOptionMapper(
|
|
524
562
|
e,
|
|
525
563
|
getTranslator()(state),
|
|
@@ -531,11 +569,11 @@ export const mapStateToEnumControlProps = (
|
|
|
531
569
|
props.schema.const,
|
|
532
570
|
getTranslator()(state),
|
|
533
571
|
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
534
|
-
)
|
|
572
|
+
),
|
|
535
573
|
]);
|
|
536
574
|
return {
|
|
537
575
|
...props,
|
|
538
|
-
options
|
|
576
|
+
options,
|
|
539
577
|
};
|
|
540
578
|
};
|
|
541
579
|
|
|
@@ -552,7 +590,7 @@ export const mapStateToOneOfEnumControlProps = (
|
|
|
552
590
|
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
|
|
553
591
|
const options: EnumOption[] =
|
|
554
592
|
ownProps.options ||
|
|
555
|
-
(props.schema.oneOf as JsonSchema[])?.map(oneOfSubSchema =>
|
|
593
|
+
(props.schema.oneOf as JsonSchema[])?.map((oneOfSubSchema) =>
|
|
556
594
|
oneOfToEnumOptionMapper(
|
|
557
595
|
oneOfSubSchema,
|
|
558
596
|
getTranslator()(state),
|
|
@@ -561,7 +599,7 @@ export const mapStateToOneOfEnumControlProps = (
|
|
|
561
599
|
);
|
|
562
600
|
return {
|
|
563
601
|
...props,
|
|
564
|
-
options
|
|
602
|
+
options,
|
|
565
603
|
};
|
|
566
604
|
};
|
|
567
605
|
|
|
@@ -580,14 +618,14 @@ export const mapStateToMultiEnumControlProps = (
|
|
|
580
618
|
const options: EnumOption[] =
|
|
581
619
|
ownProps.options ||
|
|
582
620
|
(items?.oneOf &&
|
|
583
|
-
(items.oneOf as JsonSchema[]).map(oneOfSubSchema =>
|
|
621
|
+
(items.oneOf as JsonSchema[]).map((oneOfSubSchema) =>
|
|
584
622
|
oneOfToEnumOptionMapper(
|
|
585
623
|
oneOfSubSchema,
|
|
586
624
|
state.jsonforms.i18n?.translate,
|
|
587
625
|
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
588
626
|
)
|
|
589
627
|
)) ||
|
|
590
|
-
items?.enum?.map(e =>
|
|
628
|
+
items?.enum?.map((e) =>
|
|
591
629
|
enumToEnumOptionMapper(
|
|
592
630
|
e,
|
|
593
631
|
state.jsonforms.i18n?.translate,
|
|
@@ -596,7 +634,7 @@ export const mapStateToMultiEnumControlProps = (
|
|
|
596
634
|
);
|
|
597
635
|
return {
|
|
598
636
|
...props,
|
|
599
|
-
options
|
|
637
|
+
options,
|
|
600
638
|
};
|
|
601
639
|
};
|
|
602
640
|
|
|
@@ -612,7 +650,7 @@ export const mapStateToMasterListItemProps = (
|
|
|
612
650
|
): StatePropsOfMasterItem => {
|
|
613
651
|
const { schema, path, index } = ownProps;
|
|
614
652
|
const firstPrimitiveProp = schema.properties
|
|
615
|
-
? find(Object.keys(schema.properties), propName => {
|
|
653
|
+
? find(Object.keys(schema.properties), (propName) => {
|
|
616
654
|
const prop = schema.properties[propName];
|
|
617
655
|
return (
|
|
618
656
|
prop.type === 'string' ||
|
|
@@ -627,7 +665,7 @@ export const mapStateToMasterListItemProps = (
|
|
|
627
665
|
|
|
628
666
|
return {
|
|
629
667
|
...ownProps,
|
|
630
|
-
childLabel
|
|
668
|
+
childLabel,
|
|
631
669
|
};
|
|
632
670
|
};
|
|
633
671
|
|
|
@@ -647,6 +685,7 @@ export interface OwnPropsOfMasterListItem {
|
|
|
647
685
|
schema: JsonSchema;
|
|
648
686
|
handleSelect(index: number): () => void;
|
|
649
687
|
removeItem(path: string, value: number): () => void;
|
|
688
|
+
translations: ArrayTranslations;
|
|
650
689
|
}
|
|
651
690
|
|
|
652
691
|
export interface StatePropsOfMasterItem extends OwnPropsOfMasterListItem {
|
|
@@ -668,7 +707,7 @@ export const mapStateToControlWithDetailProps = (
|
|
|
668
707
|
|
|
669
708
|
return {
|
|
670
709
|
...props,
|
|
671
|
-
uischemas: state.jsonforms.uischemas
|
|
710
|
+
uischemas: state.jsonforms.uischemas,
|
|
672
711
|
};
|
|
673
712
|
};
|
|
674
713
|
|
|
@@ -681,6 +720,7 @@ export interface ControlWithDetailProps
|
|
|
681
720
|
*/
|
|
682
721
|
export interface StatePropsOfArrayControl
|
|
683
722
|
extends StatePropsOfControlWithDetail {
|
|
723
|
+
translations: ArrayTranslations;
|
|
684
724
|
childErrors?: ErrorObject[];
|
|
685
725
|
}
|
|
686
726
|
|
|
@@ -695,22 +735,28 @@ export const mapStateToArrayControlProps = (
|
|
|
695
735
|
state: JsonFormsState,
|
|
696
736
|
ownProps: OwnPropsOfControl
|
|
697
737
|
): StatePropsOfArrayControl => {
|
|
698
|
-
const { path, schema, uischema, ...props } =
|
|
699
|
-
state,
|
|
700
|
-
ownProps
|
|
701
|
-
);
|
|
738
|
+
const { path, schema, uischema, i18nKeyPrefix, label, ...props } =
|
|
739
|
+
mapStateToControlWithDetailProps(state, ownProps);
|
|
702
740
|
|
|
703
741
|
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
|
|
704
742
|
const childErrors = getSubErrorsAt(path, resolvedSchema)(state);
|
|
743
|
+
const t = getTranslator()(state);
|
|
705
744
|
|
|
706
745
|
return {
|
|
707
746
|
...props,
|
|
747
|
+
label,
|
|
708
748
|
path,
|
|
709
749
|
uischema,
|
|
710
750
|
schema: resolvedSchema,
|
|
711
751
|
childErrors,
|
|
712
752
|
renderers: ownProps.renderers || getRenderers(state),
|
|
713
|
-
cells: ownProps.cells || getCells(state)
|
|
753
|
+
cells: ownProps.cells || getCells(state),
|
|
754
|
+
translations: getArrayTranslations(
|
|
755
|
+
t,
|
|
756
|
+
arrayDefaultTranslations,
|
|
757
|
+
i18nKeyPrefix,
|
|
758
|
+
label
|
|
759
|
+
),
|
|
714
760
|
};
|
|
715
761
|
};
|
|
716
762
|
|
|
@@ -735,7 +781,7 @@ export const mapDispatchToArrayControlProps = (
|
|
|
735
781
|
): DispatchPropsOfArrayControl => ({
|
|
736
782
|
addItem: (path: string, value: any) => () => {
|
|
737
783
|
dispatch(
|
|
738
|
-
update(path, array => {
|
|
784
|
+
update(path, (array) => {
|
|
739
785
|
if (array === undefined || array === null) {
|
|
740
786
|
return [value];
|
|
741
787
|
}
|
|
@@ -747,18 +793,18 @@ export const mapDispatchToArrayControlProps = (
|
|
|
747
793
|
},
|
|
748
794
|
removeItems: (path: string, toDelete: number[]) => () => {
|
|
749
795
|
dispatch(
|
|
750
|
-
update(path, array => {
|
|
796
|
+
update(path, (array) => {
|
|
751
797
|
toDelete
|
|
752
798
|
.sort()
|
|
753
799
|
.reverse()
|
|
754
|
-
.forEach(s => array.splice(s, 1));
|
|
800
|
+
.forEach((s) => array.splice(s, 1));
|
|
755
801
|
return array;
|
|
756
802
|
})
|
|
757
803
|
);
|
|
758
804
|
},
|
|
759
805
|
moveUp: (path, toMove: number) => () => {
|
|
760
806
|
dispatch(
|
|
761
|
-
update(path, array => {
|
|
807
|
+
update(path, (array) => {
|
|
762
808
|
moveUp(array, toMove);
|
|
763
809
|
return array;
|
|
764
810
|
})
|
|
@@ -766,12 +812,12 @@ export const mapDispatchToArrayControlProps = (
|
|
|
766
812
|
},
|
|
767
813
|
moveDown: (path, toMove: number) => () => {
|
|
768
814
|
dispatch(
|
|
769
|
-
update(path, array => {
|
|
815
|
+
update(path, (array) => {
|
|
770
816
|
moveDown(array, toMove);
|
|
771
817
|
return array;
|
|
772
818
|
})
|
|
773
819
|
);
|
|
774
|
-
}
|
|
820
|
+
},
|
|
775
821
|
});
|
|
776
822
|
|
|
777
823
|
export interface DispatchPropsOfMultiEnumControl {
|
|
@@ -784,7 +830,7 @@ export const mapDispatchToMultiEnumProps = (
|
|
|
784
830
|
): DispatchPropsOfMultiEnumControl => ({
|
|
785
831
|
addItem: (path: string, value: any) => {
|
|
786
832
|
dispatch(
|
|
787
|
-
update(path, data => {
|
|
833
|
+
update(path, (data) => {
|
|
788
834
|
if (data === undefined || data === null) {
|
|
789
835
|
return [value];
|
|
790
836
|
}
|
|
@@ -795,13 +841,13 @@ export const mapDispatchToMultiEnumProps = (
|
|
|
795
841
|
},
|
|
796
842
|
removeItem: (path: string, toDelete: any) => {
|
|
797
843
|
dispatch(
|
|
798
|
-
update(path, data => {
|
|
844
|
+
update(path, (data) => {
|
|
799
845
|
const indexInData = data.indexOf(toDelete);
|
|
800
846
|
data.splice(indexInData, 1);
|
|
801
847
|
return data;
|
|
802
848
|
})
|
|
803
849
|
);
|
|
804
|
-
}
|
|
850
|
+
},
|
|
805
851
|
});
|
|
806
852
|
|
|
807
853
|
/**
|
|
@@ -820,7 +866,7 @@ export const layoutDefaultProps: {
|
|
|
820
866
|
visible: true,
|
|
821
867
|
enabled: true,
|
|
822
868
|
path: '',
|
|
823
|
-
direction: 'column'
|
|
869
|
+
direction: 'column',
|
|
824
870
|
};
|
|
825
871
|
|
|
826
872
|
const getDirection = (uischema: UISchemaElement) => {
|
|
@@ -863,7 +909,9 @@ export const mapStateToLayoutProps = (
|
|
|
863
909
|
|
|
864
910
|
// some layouts have labels which might need to be translated
|
|
865
911
|
const t = getTranslator()(state);
|
|
866
|
-
const label = isLabelable(uischema)
|
|
912
|
+
const label = isLabelable(uischema)
|
|
913
|
+
? deriveLabelForUISchemaElement(uischema, t)
|
|
914
|
+
: undefined;
|
|
867
915
|
|
|
868
916
|
return {
|
|
869
917
|
...layoutDefaultProps,
|
|
@@ -877,7 +925,7 @@ export const mapStateToLayoutProps = (
|
|
|
877
925
|
schema: ownProps.schema,
|
|
878
926
|
direction: ownProps.direction ?? getDirection(uischema),
|
|
879
927
|
config,
|
|
880
|
-
label
|
|
928
|
+
label,
|
|
881
929
|
};
|
|
882
930
|
};
|
|
883
931
|
|
|
@@ -905,13 +953,13 @@ export const mapStateToJsonFormsRendererProps = (
|
|
|
905
953
|
uischema: ownProps.uischema || getUiSchema(state),
|
|
906
954
|
path: ownProps.path,
|
|
907
955
|
enabled: ownProps.enabled,
|
|
908
|
-
config: getConfig(state)
|
|
956
|
+
config: getConfig(state),
|
|
909
957
|
};
|
|
910
958
|
};
|
|
911
959
|
|
|
912
960
|
export const controlDefaultProps = {
|
|
913
961
|
...layoutDefaultProps,
|
|
914
|
-
errors: [] as string[]
|
|
962
|
+
errors: [] as string[],
|
|
915
963
|
};
|
|
916
964
|
|
|
917
965
|
export interface StatePropsOfCombinator extends StatePropsOfControl {
|
|
@@ -930,7 +978,7 @@ export const mapStateToCombinatorRendererProps = (
|
|
|
930
978
|
): StatePropsOfCombinator => {
|
|
931
979
|
const { data, schema, rootSchema, ...props } = mapStateToControlProps(
|
|
932
980
|
state,
|
|
933
|
-
ownProps
|
|
981
|
+
ownProps
|
|
934
982
|
);
|
|
935
983
|
|
|
936
984
|
const ajv = state.jsonforms.core.ajv;
|
|
@@ -939,13 +987,13 @@ export const mapStateToCombinatorRendererProps = (
|
|
|
939
987
|
'additionalProperties',
|
|
940
988
|
'type',
|
|
941
989
|
'enum',
|
|
942
|
-
'const'
|
|
990
|
+
'const',
|
|
943
991
|
];
|
|
944
992
|
const dataIsValid = (errors: ErrorObject[]): boolean => {
|
|
945
993
|
return (
|
|
946
994
|
!errors ||
|
|
947
995
|
errors.length === 0 ||
|
|
948
|
-
!errors.find(e => structuralKeywords.indexOf(e.keyword) !== -1)
|
|
996
|
+
!errors.find((e) => structuralKeywords.indexOf(e.keyword) !== -1)
|
|
949
997
|
);
|
|
950
998
|
};
|
|
951
999
|
let indexOfFittingSchema: number;
|
|
@@ -955,9 +1003,8 @@ export const mapStateToCombinatorRendererProps = (
|
|
|
955
1003
|
for (let i = 0; i < schema[keyword]?.length; i++) {
|
|
956
1004
|
try {
|
|
957
1005
|
let _schema = schema[keyword][i];
|
|
958
|
-
if(_schema.$ref){
|
|
959
|
-
_schema = Resolve.schema(
|
|
960
|
-
);
|
|
1006
|
+
if (_schema.$ref) {
|
|
1007
|
+
_schema = Resolve.schema(rootSchema, _schema.$ref, rootSchema);
|
|
961
1008
|
}
|
|
962
1009
|
const valFn = ajv.compile(_schema);
|
|
963
1010
|
valFn(data);
|
|
@@ -966,7 +1013,9 @@ export const mapStateToCombinatorRendererProps = (
|
|
|
966
1013
|
break;
|
|
967
1014
|
}
|
|
968
1015
|
} catch (error) {
|
|
969
|
-
console.debug(
|
|
1016
|
+
console.debug(
|
|
1017
|
+
"Combinator subschema is not self contained, can't hand it over to AJV"
|
|
1018
|
+
);
|
|
970
1019
|
}
|
|
971
1020
|
}
|
|
972
1021
|
|
|
@@ -976,7 +1025,7 @@ export const mapStateToCombinatorRendererProps = (
|
|
|
976
1025
|
rootSchema,
|
|
977
1026
|
...props,
|
|
978
1027
|
indexOfFittingSchema,
|
|
979
|
-
uischemas: getUISchemas(state)
|
|
1028
|
+
uischemas: getUISchemas(state),
|
|
980
1029
|
};
|
|
981
1030
|
};
|
|
982
1031
|
|
|
@@ -1011,6 +1060,7 @@ export const mapStateToOneOfProps = (
|
|
|
1011
1060
|
|
|
1012
1061
|
export interface StatePropsOfArrayLayout extends StatePropsOfControlWithDetail {
|
|
1013
1062
|
data: number;
|
|
1063
|
+
translations: ArrayTranslations;
|
|
1014
1064
|
minItems?: number;
|
|
1015
1065
|
}
|
|
1016
1066
|
/**
|
|
@@ -1024,21 +1074,16 @@ export const mapStateToArrayLayoutProps = (
|
|
|
1024
1074
|
state: JsonFormsState,
|
|
1025
1075
|
ownProps: OwnPropsOfControl
|
|
1026
1076
|
): StatePropsOfArrayLayout => {
|
|
1027
|
-
const {
|
|
1028
|
-
|
|
1029
|
-
schema,
|
|
1030
|
-
uischema,
|
|
1031
|
-
errors,
|
|
1032
|
-
...props
|
|
1033
|
-
} = mapStateToControlWithDetailProps(state, ownProps);
|
|
1077
|
+
const { path, schema, uischema, errors, i18nKeyPrefix, label, ...props } =
|
|
1078
|
+
mapStateToControlWithDetailProps(state, ownProps);
|
|
1034
1079
|
|
|
1035
1080
|
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
|
|
1036
|
-
|
|
1081
|
+
const t = getTranslator()(state);
|
|
1037
1082
|
// TODO Does not consider 'i18n' keys which are specified in the ui schemas of the sub errors
|
|
1038
1083
|
const childErrors = getCombinedErrorMessage(
|
|
1039
1084
|
getSubErrorsAt(path, resolvedSchema)(state),
|
|
1040
1085
|
getErrorTranslator()(state),
|
|
1041
|
-
|
|
1086
|
+
t,
|
|
1042
1087
|
undefined,
|
|
1043
1088
|
undefined,
|
|
1044
1089
|
undefined
|
|
@@ -1050,12 +1095,19 @@ export const mapStateToArrayLayoutProps = (
|
|
|
1050
1095
|
childErrors;
|
|
1051
1096
|
return {
|
|
1052
1097
|
...props,
|
|
1098
|
+
label,
|
|
1053
1099
|
path,
|
|
1054
1100
|
uischema,
|
|
1055
1101
|
schema: resolvedSchema,
|
|
1056
1102
|
data: props.data ? props.data.length : 0,
|
|
1057
1103
|
errors: allErrors,
|
|
1058
|
-
minItems: schema.minItems
|
|
1104
|
+
minItems: schema.minItems,
|
|
1105
|
+
translations: getArrayTranslations(
|
|
1106
|
+
t,
|
|
1107
|
+
arrayDefaultTranslations,
|
|
1108
|
+
i18nKeyPrefix,
|
|
1109
|
+
label
|
|
1110
|
+
),
|
|
1059
1111
|
};
|
|
1060
1112
|
};
|
|
1061
1113
|
|
|
@@ -1069,8 +1121,7 @@ export interface ArrayLayoutProps
|
|
|
1069
1121
|
export interface StatePropsOfLabel extends StatePropsOfRenderer {
|
|
1070
1122
|
text?: string;
|
|
1071
1123
|
}
|
|
1072
|
-
export interface LabelProps extends StatePropsOfLabel{
|
|
1073
|
-
}
|
|
1124
|
+
export interface LabelProps extends StatePropsOfLabel {}
|
|
1074
1125
|
|
|
1075
1126
|
export const mapStateToLabelProps = (
|
|
1076
1127
|
state: JsonFormsState,
|
|
@@ -1088,12 +1139,12 @@ export const mapStateToLabelProps = (
|
|
|
1088
1139
|
const i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
|
|
1089
1140
|
const i18nKey = i18nKeyPrefix ? `${i18nKeyPrefix}.text` : text ?? '';
|
|
1090
1141
|
const i18nText = t(i18nKey, text, { uischema });
|
|
1091
|
-
|
|
1142
|
+
|
|
1092
1143
|
return {
|
|
1093
1144
|
text: i18nText,
|
|
1094
1145
|
visible,
|
|
1095
1146
|
config: getConfig(state),
|
|
1096
1147
|
renderers: props.renderers || getRenderers(state),
|
|
1097
1148
|
cells: props.cells || getCells(state),
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1149
|
+
};
|
|
1150
|
+
};
|
package/src/util/resolvers.ts
CHANGED
|
@@ -48,15 +48,13 @@ export const resolveData = (instance: any, dataPath: string): any => {
|
|
|
48
48
|
}
|
|
49
49
|
const dataPathSegments = dataPath.split('.');
|
|
50
50
|
|
|
51
|
-
return dataPathSegments
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
51
|
+
return dataPathSegments.reduce((curInstance, decodedSegment) => {
|
|
52
|
+
if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
return curInstance[decodedSegment];
|
|
57
|
+
}, instance);
|
|
60
58
|
};
|
|
61
59
|
|
|
62
60
|
/**
|
|
@@ -73,7 +71,7 @@ export const findAllRefs = (
|
|
|
73
71
|
resolveTuples = false
|
|
74
72
|
): ReferenceSchemaMap => {
|
|
75
73
|
if (isObjectSchema(schema)) {
|
|
76
|
-
Object.keys(schema.properties).forEach(key =>
|
|
74
|
+
Object.keys(schema.properties).forEach((key) =>
|
|
77
75
|
findAllRefs(schema.properties[key], result)
|
|
78
76
|
);
|
|
79
77
|
}
|
|
@@ -81,7 +79,7 @@ export const findAllRefs = (
|
|
|
81
79
|
if (Array.isArray(schema.items)) {
|
|
82
80
|
if (resolveTuples) {
|
|
83
81
|
const items: JsonSchema[] = schema.items;
|
|
84
|
-
items.forEach(child => findAllRefs(child, result));
|
|
82
|
+
items.forEach((child) => findAllRefs(child, result));
|
|
85
83
|
}
|
|
86
84
|
} else {
|
|
87
85
|
findAllRefs(schema.items, result);
|
|
@@ -89,7 +87,7 @@ export const findAllRefs = (
|
|
|
89
87
|
}
|
|
90
88
|
if (Array.isArray(schema.anyOf)) {
|
|
91
89
|
const anyOf: JsonSchema[] = schema.anyOf;
|
|
92
|
-
anyOf.forEach(child => findAllRefs(child, result));
|
|
90
|
+
anyOf.forEach((child) => findAllRefs(child, result));
|
|
93
91
|
}
|
|
94
92
|
if (schema.$ref !== undefined) {
|
|
95
93
|
result[schema.$ref] = schema;
|
|
@@ -142,7 +140,11 @@ const resolveSchemaWithSegments = (
|
|
|
142
140
|
|
|
143
141
|
const singleSegmentResolveSchema = get(schema, segment);
|
|
144
142
|
|
|
145
|
-
const resolvedSchema = resolveSchemaWithSegments(
|
|
143
|
+
const resolvedSchema = resolveSchemaWithSegments(
|
|
144
|
+
singleSegmentResolveSchema,
|
|
145
|
+
remainingSegments,
|
|
146
|
+
rootSchema
|
|
147
|
+
);
|
|
146
148
|
if (resolvedSchema) {
|
|
147
149
|
return resolvedSchema;
|
|
148
150
|
}
|
|
@@ -175,4 +177,4 @@ const resolveSchemaWithSegments = (
|
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
return undefined;
|
|
178
|
-
}
|
|
180
|
+
};
|
package/src/util/runtime.ts
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
RuleEffect,
|
|
34
34
|
SchemaBasedCondition,
|
|
35
35
|
Scopable,
|
|
36
|
-
UISchemaElement
|
|
36
|
+
UISchemaElement,
|
|
37
37
|
} from '../models';
|
|
38
38
|
import { resolveData } from './resolvers';
|
|
39
39
|
import { composeWithUi } from './path';
|
|
@@ -191,7 +191,7 @@ export const isInherentlyEnabled = (
|
|
|
191
191
|
state: JsonFormsState,
|
|
192
192
|
ownProps: any,
|
|
193
193
|
uischema: UISchemaElement,
|
|
194
|
-
schema: JsonSchema & { readOnly?: boolean } | undefined,
|
|
194
|
+
schema: (JsonSchema & { readOnly?: boolean }) | undefined,
|
|
195
195
|
rootData: any,
|
|
196
196
|
config: any
|
|
197
197
|
) => {
|
package/src/util/schema.ts
CHANGED
|
@@ -27,7 +27,7 @@ import find from 'lodash/find';
|
|
|
27
27
|
|
|
28
28
|
export const getFirstPrimitiveProp = (schema: any) => {
|
|
29
29
|
if (schema.properties) {
|
|
30
|
-
return find(Object.keys(schema.properties), propName => {
|
|
30
|
+
return find(Object.keys(schema.properties), (propName) => {
|
|
31
31
|
const prop = schema.properties[propName];
|
|
32
32
|
return (
|
|
33
33
|
prop.type === 'string' ||
|
package/src/util/type.ts
CHANGED
|
@@ -62,7 +62,9 @@ export interface AnyAction extends Action {
|
|
|
62
62
|
* @template A The type of things (actions or otherwise) which may be
|
|
63
63
|
* dispatched.
|
|
64
64
|
*/
|
|
65
|
-
export type Dispatch<A extends Action = AnyAction> = <T extends A>(
|
|
65
|
+
export type Dispatch<A extends Action = AnyAction> = <T extends A>(
|
|
66
|
+
action: T
|
|
67
|
+
) => T;
|
|
66
68
|
|
|
67
69
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
|
|
68
70
|
/**
|
|
@@ -171,7 +173,7 @@ export type Observable<T> = {
|
|
|
171
173
|
* emission of values from the observable.
|
|
172
174
|
*/
|
|
173
175
|
subscribe(observer: Observer<T>): { unsubscribe: Unsubscribe };
|
|
174
|
-
[Symbol.observable](): Observable<T
|
|
176
|
+
[Symbol.observable](): Observable<T>;
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
|
|
@@ -180,7 +182,7 @@ export type Observable<T> = {
|
|
|
180
182
|
* an argument to subscribe.
|
|
181
183
|
*/
|
|
182
184
|
export type Observer<T> = {
|
|
183
|
-
next?(value: T): void
|
|
185
|
+
next?(value: T): void;
|
|
184
186
|
};
|
|
185
187
|
|
|
186
188
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/reducers.ts
|