@jsonforms/core 3.1.0 → 3.1.1-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.
- package/lib/i18n/combinatorTranslations.d.ts +14 -0
- package/lib/i18n/i18nUtil.d.ts +2 -0
- package/lib/i18n/index.d.ts +1 -0
- package/lib/jsonforms-core.cjs.js +45 -3
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +43 -3
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/util/renderer.d.ts +2 -1
- package/package.json +8 -7
- package/src/i18n/combinatorTranslations.ts +28 -0
- package/src/i18n/i18nUtil.ts +18 -0
- package/src/i18n/index.ts +1 -0
- package/src/reducers/core.ts +14 -5
- package/src/util/renderer.ts +16 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CombinatorDefaultTranslation {
|
|
2
|
+
key: CombinatorTranslationEnum;
|
|
3
|
+
default: (variable?: string) => string;
|
|
4
|
+
}
|
|
5
|
+
export declare enum CombinatorTranslationEnum {
|
|
6
|
+
clearDialogTitle = "clearDialogTitle",
|
|
7
|
+
clearDialogMessage = "clearDialogMessage",
|
|
8
|
+
clearDialogAccept = "clearDialogAccept",
|
|
9
|
+
clearDialogDecline = "clearDialogDecline"
|
|
10
|
+
}
|
|
11
|
+
export declare type CombinatorTranslations = {
|
|
12
|
+
[key in CombinatorTranslationEnum]?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const combinatorDefaultTranslations: CombinatorDefaultTranslation[];
|
package/lib/i18n/i18nUtil.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ErrorObject } from 'ajv';
|
|
|
2
2
|
import { Labelable, UISchemaElement } from '../models';
|
|
3
3
|
import type { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
|
|
4
4
|
import { ArrayDefaultTranslation, ArrayTranslations } from './arrayTranslations';
|
|
5
|
+
import { CombinatorDefaultTranslation, CombinatorTranslations } from './combinatorTranslations';
|
|
5
6
|
export declare const getI18nKeyPrefixBySchema: (schema: i18nJsonSchema | undefined, uischema: unknown | undefined) => string | undefined;
|
|
6
7
|
/**
|
|
7
8
|
* Transforms a given path to a prefix which can be used for i18n keys.
|
|
@@ -24,3 +25,4 @@ export declare const getCombinedErrorMessage: (errors: ErrorObject[], et: ErrorT
|
|
|
24
25
|
*/
|
|
25
26
|
export declare const deriveLabelForUISchemaElement: (uischema: Labelable<boolean>, t: Translator) => string | undefined;
|
|
26
27
|
export declare const getArrayTranslations: (t: Translator, defaultTranslations: ArrayDefaultTranslation[], i18nKeyPrefix: string, label: string) => ArrayTranslations;
|
|
28
|
+
export declare const getCombinatorTranslations: (t: Translator, defaultTranslations: CombinatorDefaultTranslation[], i18nKeyPrefix: string, label: string) => CombinatorTranslations;
|
package/lib/i18n/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ var keys = require('lodash/keys');
|
|
|
8
8
|
var merge = require('lodash/merge');
|
|
9
9
|
var cloneDeep = require('lodash/cloneDeep');
|
|
10
10
|
var setFp = require('lodash/fp/set');
|
|
11
|
+
var unsetFp = require('lodash/fp/unset');
|
|
11
12
|
var get = require('lodash/get');
|
|
12
13
|
var filter = require('lodash/filter');
|
|
13
14
|
var isEqual = require('lodash/isEqual');
|
|
@@ -34,6 +35,7 @@ var keys__default = /*#__PURE__*/_interopDefaultLegacy(keys);
|
|
|
34
35
|
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
|
|
35
36
|
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
|
|
36
37
|
var setFp__default = /*#__PURE__*/_interopDefaultLegacy(setFp);
|
|
38
|
+
var unsetFp__default = /*#__PURE__*/_interopDefaultLegacy(unsetFp);
|
|
37
39
|
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
|
|
38
40
|
var filter__default = /*#__PURE__*/_interopDefaultLegacy(filter);
|
|
39
41
|
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
@@ -599,7 +601,13 @@ var coreReducer = function (state, action) {
|
|
|
599
601
|
else {
|
|
600
602
|
var oldData = get__default["default"](state.data, action.path);
|
|
601
603
|
var newData = action.updater(cloneDeep__default["default"](oldData));
|
|
602
|
-
var newState =
|
|
604
|
+
var newState = void 0;
|
|
605
|
+
if (newData !== undefined) {
|
|
606
|
+
newState = setFp__default["default"](action.path, newData, state.data === undefined ? {} : state.data);
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
newState = unsetFp__default["default"](action.path, state.data === undefined ? {} : state.data);
|
|
610
|
+
}
|
|
603
611
|
var errors = validate(state.validator, newState);
|
|
604
612
|
return __assign(__assign({}, state), { data: newState, errors: errors });
|
|
605
613
|
}
|
|
@@ -803,6 +811,14 @@ var getArrayTranslations = function (t, defaultTranslations, i18nKeyPrefix, labe
|
|
|
803
811
|
});
|
|
804
812
|
return translations;
|
|
805
813
|
};
|
|
814
|
+
var getCombinatorTranslations = function (t, defaultTranslations, i18nKeyPrefix, label) {
|
|
815
|
+
var translations = {};
|
|
816
|
+
defaultTranslations.forEach(function (controlElement) {
|
|
817
|
+
var key = addI18nKeyToPrefix(i18nKeyPrefix, controlElement.key);
|
|
818
|
+
translations[controlElement.key] = t(key, controlElement.default(label));
|
|
819
|
+
});
|
|
820
|
+
return translations;
|
|
821
|
+
};
|
|
806
822
|
|
|
807
823
|
exports.ArrayTranslationEnum = void 0;
|
|
808
824
|
(function (ArrayTranslationEnum) {
|
|
@@ -850,6 +866,26 @@ var arrayDefaultTranslations = [
|
|
|
850
866
|
{ key: exports.ArrayTranslationEnum.deleteDialogDecline, default: function () { return 'No'; } },
|
|
851
867
|
];
|
|
852
868
|
|
|
869
|
+
exports.CombinatorTranslationEnum = void 0;
|
|
870
|
+
(function (CombinatorTranslationEnum) {
|
|
871
|
+
CombinatorTranslationEnum["clearDialogTitle"] = "clearDialogTitle";
|
|
872
|
+
CombinatorTranslationEnum["clearDialogMessage"] = "clearDialogMessage";
|
|
873
|
+
CombinatorTranslationEnum["clearDialogAccept"] = "clearDialogAccept";
|
|
874
|
+
CombinatorTranslationEnum["clearDialogDecline"] = "clearDialogDecline";
|
|
875
|
+
})(exports.CombinatorTranslationEnum || (exports.CombinatorTranslationEnum = {}));
|
|
876
|
+
var combinatorDefaultTranslations = [
|
|
877
|
+
{
|
|
878
|
+
key: exports.CombinatorTranslationEnum.clearDialogTitle,
|
|
879
|
+
default: function () { return 'Clear form?'; },
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
key: exports.CombinatorTranslationEnum.clearDialogMessage,
|
|
883
|
+
default: function () { return 'Your data will be cleared. Do you want to proceed?'; },
|
|
884
|
+
},
|
|
885
|
+
{ key: exports.CombinatorTranslationEnum.clearDialogAccept, default: function () { return 'Yes'; } },
|
|
886
|
+
{ key: exports.CombinatorTranslationEnum.clearDialogDecline, default: function () { return 'No'; } },
|
|
887
|
+
];
|
|
888
|
+
|
|
853
889
|
var defaultJsonFormsI18nState = {
|
|
854
890
|
locale: 'en',
|
|
855
891
|
translate: defaultTranslator,
|
|
@@ -1968,8 +2004,10 @@ var mapStateToJsonFormsRendererProps = function (state, ownProps) {
|
|
|
1968
2004
|
var controlDefaultProps = __assign(__assign({}, layoutDefaultProps), { errors: [] });
|
|
1969
2005
|
var mapStateToCombinatorRendererProps = function (state, ownProps, keyword) {
|
|
1970
2006
|
var _a;
|
|
1971
|
-
var _b = mapStateToControlProps(state, ownProps), data = _b.data, schema = _b.schema, rootSchema = _b.rootSchema, props = __rest(_b, ["data", "schema", "rootSchema"]);
|
|
2007
|
+
var _b = mapStateToControlProps(state, ownProps), data = _b.data, schema = _b.schema, rootSchema = _b.rootSchema, i18nKeyPrefix = _b.i18nKeyPrefix, label = _b.label, props = __rest(_b, ["data", "schema", "rootSchema", "i18nKeyPrefix", "label"]);
|
|
1972
2008
|
var ajv = state.jsonforms.core.ajv;
|
|
2009
|
+
var t = getTranslator()(state);
|
|
2010
|
+
var translations = getCombinatorTranslations(t, combinatorDefaultTranslations, i18nKeyPrefix, label);
|
|
1973
2011
|
var structuralKeywords = [
|
|
1974
2012
|
'required',
|
|
1975
2013
|
'additionalProperties',
|
|
@@ -2002,7 +2040,9 @@ var mapStateToCombinatorRendererProps = function (state, ownProps, keyword) {
|
|
|
2002
2040
|
}
|
|
2003
2041
|
return __assign(__assign({ data: data,
|
|
2004
2042
|
schema: schema,
|
|
2005
|
-
rootSchema: rootSchema }, props), {
|
|
2043
|
+
rootSchema: rootSchema }, props), { i18nKeyPrefix: i18nKeyPrefix,
|
|
2044
|
+
label: label,
|
|
2045
|
+
indexOfFittingSchema: indexOfFittingSchema, uischemas: getUISchemas(state), translations: translations });
|
|
2006
2046
|
};
|
|
2007
2047
|
var mapStateToAllOfProps = function (state, ownProps) {
|
|
2008
2048
|
return mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
|
|
@@ -2523,6 +2563,7 @@ exports.arrayDefaultTranslations = arrayDefaultTranslations;
|
|
|
2523
2563
|
exports.categorizationHasCategory = categorizationHasCategory;
|
|
2524
2564
|
exports.cellReducer = cellReducer;
|
|
2525
2565
|
exports.clearAllIds = clearAllIds;
|
|
2566
|
+
exports.combinatorDefaultTranslations = combinatorDefaultTranslations;
|
|
2526
2567
|
exports.compose = compose;
|
|
2527
2568
|
exports.composePaths = compose;
|
|
2528
2569
|
exports.composeWithUi = composeWithUi;
|
|
@@ -2571,6 +2612,7 @@ exports.generateJsonSchema = generateJsonSchema;
|
|
|
2571
2612
|
exports.getAjv = getAjv;
|
|
2572
2613
|
exports.getArrayTranslations = getArrayTranslations;
|
|
2573
2614
|
exports.getCells = getCells;
|
|
2615
|
+
exports.getCombinatorTranslations = getCombinatorTranslations;
|
|
2574
2616
|
exports.getCombinedErrorMessage = getCombinedErrorMessage;
|
|
2575
2617
|
exports.getConfig = getConfig;
|
|
2576
2618
|
exports.getControlPath = getControlPath;
|