@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.
- 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 +59 -17
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +52 -16
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/models/uischema.d.ts +12 -0
- package/lib/util/renderer.d.ts +2 -1
- package/package.json +11 -11
- package/src/i18n/combinatorTranslations.ts +28 -0
- package/src/i18n/i18nUtil.ts +18 -0
- package/src/i18n/index.ts +1 -0
- package/src/models/uischema.ts +13 -0
- package/src/reducers/core.ts +14 -5
- package/src/util/combinators.ts +9 -16
- package/src/util/renderer.ts +17 -5
- package/src/util/runtime.ts +3 -0
|
@@ -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);
|
|
@@ -414,7 +416,12 @@ function __spreadArray(to, from, pack) {
|
|
|
414
416
|
}
|
|
415
417
|
}
|
|
416
418
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
417
|
-
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
422
|
+
var e = new Error(message);
|
|
423
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
424
|
+
};
|
|
418
425
|
|
|
419
426
|
var cellReducer = function (state, _a) {
|
|
420
427
|
if (state === void 0) { state = []; }
|
|
@@ -599,7 +606,13 @@ var coreReducer = function (state, action) {
|
|
|
599
606
|
else {
|
|
600
607
|
var oldData = get__default["default"](state.data, action.path);
|
|
601
608
|
var newData = action.updater(cloneDeep__default["default"](oldData));
|
|
602
|
-
var newState =
|
|
609
|
+
var newState = void 0;
|
|
610
|
+
if (newData !== undefined) {
|
|
611
|
+
newState = setFp__default["default"](action.path, newData, state.data === undefined ? {} : state.data);
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
newState = unsetFp__default["default"](action.path, state.data === undefined ? {} : state.data);
|
|
615
|
+
}
|
|
603
616
|
var errors = validate(state.validator, newState);
|
|
604
617
|
return __assign(__assign({}, state), { data: newState, errors: errors });
|
|
605
618
|
}
|
|
@@ -803,6 +816,14 @@ var getArrayTranslations = function (t, defaultTranslations, i18nKeyPrefix, labe
|
|
|
803
816
|
});
|
|
804
817
|
return translations;
|
|
805
818
|
};
|
|
819
|
+
var getCombinatorTranslations = function (t, defaultTranslations, i18nKeyPrefix, label) {
|
|
820
|
+
var translations = {};
|
|
821
|
+
defaultTranslations.forEach(function (controlElement) {
|
|
822
|
+
var key = addI18nKeyToPrefix(i18nKeyPrefix, controlElement.key);
|
|
823
|
+
translations[controlElement.key] = t(key, controlElement.default(label));
|
|
824
|
+
});
|
|
825
|
+
return translations;
|
|
826
|
+
};
|
|
806
827
|
|
|
807
828
|
exports.ArrayTranslationEnum = void 0;
|
|
808
829
|
(function (ArrayTranslationEnum) {
|
|
@@ -850,6 +871,26 @@ var arrayDefaultTranslations = [
|
|
|
850
871
|
{ key: exports.ArrayTranslationEnum.deleteDialogDecline, default: function () { return 'No'; } },
|
|
851
872
|
];
|
|
852
873
|
|
|
874
|
+
exports.CombinatorTranslationEnum = void 0;
|
|
875
|
+
(function (CombinatorTranslationEnum) {
|
|
876
|
+
CombinatorTranslationEnum["clearDialogTitle"] = "clearDialogTitle";
|
|
877
|
+
CombinatorTranslationEnum["clearDialogMessage"] = "clearDialogMessage";
|
|
878
|
+
CombinatorTranslationEnum["clearDialogAccept"] = "clearDialogAccept";
|
|
879
|
+
CombinatorTranslationEnum["clearDialogDecline"] = "clearDialogDecline";
|
|
880
|
+
})(exports.CombinatorTranslationEnum || (exports.CombinatorTranslationEnum = {}));
|
|
881
|
+
var combinatorDefaultTranslations = [
|
|
882
|
+
{
|
|
883
|
+
key: exports.CombinatorTranslationEnum.clearDialogTitle,
|
|
884
|
+
default: function () { return 'Clear form?'; },
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
key: exports.CombinatorTranslationEnum.clearDialogMessage,
|
|
888
|
+
default: function () { return 'Your data will be cleared. Do you want to proceed?'; },
|
|
889
|
+
},
|
|
890
|
+
{ key: exports.CombinatorTranslationEnum.clearDialogAccept, default: function () { return 'Yes'; } },
|
|
891
|
+
{ key: exports.CombinatorTranslationEnum.clearDialogDecline, default: function () { return 'No'; } },
|
|
892
|
+
];
|
|
893
|
+
|
|
853
894
|
var defaultJsonFormsI18nState = {
|
|
854
895
|
locale: 'en',
|
|
855
896
|
translate: defaultTranslator,
|
|
@@ -1489,6 +1530,9 @@ var evaluateCondition = function (data, condition, path, ajv) {
|
|
|
1489
1530
|
}
|
|
1490
1531
|
else if (isSchemaCondition(condition)) {
|
|
1491
1532
|
var value = resolveData(data, getConditionScope(condition, path));
|
|
1533
|
+
if (condition.failWhenUndefined && value === undefined) {
|
|
1534
|
+
return false;
|
|
1535
|
+
}
|
|
1492
1536
|
return ajv.validate(condition.schema, value);
|
|
1493
1537
|
}
|
|
1494
1538
|
else {
|
|
@@ -1882,7 +1926,7 @@ var mapDispatchToArrayControlProps = function (dispatch) { return ({
|
|
|
1882
1926
|
removeItems: function (path, toDelete) { return function () {
|
|
1883
1927
|
dispatch(update(path, function (array) {
|
|
1884
1928
|
toDelete
|
|
1885
|
-
.sort()
|
|
1929
|
+
.sort(function (a, b) { return a - b; })
|
|
1886
1930
|
.reverse()
|
|
1887
1931
|
.forEach(function (s) { return array.splice(s, 1); });
|
|
1888
1932
|
return array;
|
|
@@ -1968,8 +2012,10 @@ var mapStateToJsonFormsRendererProps = function (state, ownProps) {
|
|
|
1968
2012
|
var controlDefaultProps = __assign(__assign({}, layoutDefaultProps), { errors: [] });
|
|
1969
2013
|
var mapStateToCombinatorRendererProps = function (state, ownProps, keyword) {
|
|
1970
2014
|
var _a;
|
|
1971
|
-
var _b = mapStateToControlProps(state, ownProps), data = _b.data, schema = _b.schema, rootSchema = _b.rootSchema, props = __rest(_b, ["data", "schema", "rootSchema"]);
|
|
2015
|
+
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
2016
|
var ajv = state.jsonforms.core.ajv;
|
|
2017
|
+
var t = getTranslator()(state);
|
|
2018
|
+
var translations = getCombinatorTranslations(t, combinatorDefaultTranslations, i18nKeyPrefix, label);
|
|
1973
2019
|
var structuralKeywords = [
|
|
1974
2020
|
'required',
|
|
1975
2021
|
'additionalProperties',
|
|
@@ -2002,7 +2048,9 @@ var mapStateToCombinatorRendererProps = function (state, ownProps, keyword) {
|
|
|
2002
2048
|
}
|
|
2003
2049
|
return __assign(__assign({ data: data,
|
|
2004
2050
|
schema: schema,
|
|
2005
|
-
rootSchema: rootSchema }, props), {
|
|
2051
|
+
rootSchema: rootSchema }, props), { i18nKeyPrefix: i18nKeyPrefix,
|
|
2052
|
+
label: label,
|
|
2053
|
+
indexOfFittingSchema: indexOfFittingSchema, uischemas: getUISchemas(state), translations: translations });
|
|
2006
2054
|
};
|
|
2007
2055
|
var mapStateToAllOfProps = function (state, ownProps) {
|
|
2008
2056
|
return mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
|
|
@@ -2117,23 +2165,15 @@ function (dispatch, ownProps) {
|
|
|
2117
2165
|
};
|
|
2118
2166
|
};
|
|
2119
2167
|
|
|
2120
|
-
var createLabel = function (subSchema, subSchemaIndex, keyword) {
|
|
2121
|
-
if (subSchema.title) {
|
|
2122
|
-
return subSchema.title;
|
|
2123
|
-
}
|
|
2124
|
-
else {
|
|
2125
|
-
return keyword + '-' + subSchemaIndex;
|
|
2126
|
-
}
|
|
2127
|
-
};
|
|
2128
2168
|
var createCombinatorRenderInfos = function (combinatorSubSchemas, rootSchema, keyword, control, path, uischemas) {
|
|
2129
2169
|
return combinatorSubSchemas.map(function (subSchema, subSchemaIndex) {
|
|
2130
|
-
var
|
|
2131
|
-
|
|
2132
|
-
|
|
2170
|
+
var _a, _b;
|
|
2171
|
+
var resolvedSubSchema = subSchema.$ref && Resolve.schema(rootSchema, subSchema.$ref, rootSchema);
|
|
2172
|
+
var schema = resolvedSubSchema !== null && resolvedSubSchema !== void 0 ? resolvedSubSchema : subSchema;
|
|
2133
2173
|
return {
|
|
2134
2174
|
schema: schema,
|
|
2135
2175
|
uischema: findUISchema(uischemas, schema, control.scope, path, undefined, control, rootSchema),
|
|
2136
|
-
label:
|
|
2176
|
+
label: (_b = (_a = subSchema.title) !== null && _a !== void 0 ? _a : resolvedSubSchema === null || resolvedSubSchema === void 0 ? void 0 : resolvedSubSchema.title) !== null && _b !== void 0 ? _b : keyword + "-" + subSchemaIndex,
|
|
2137
2177
|
};
|
|
2138
2178
|
});
|
|
2139
2179
|
};
|
|
@@ -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;
|