@jsonforms/core 3.0.0-beta.4 → 3.0.0-rc.1
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/docs/assets/js/search.json +1 -1
- package/docs/enums/ruleeffect.html +4 -4
- package/docs/globals.html +335 -110
- package/docs/index.html +43 -4
- package/docs/interfaces/andcondition.html +2 -2
- package/docs/interfaces/arraycontrolprops.html +21 -21
- package/docs/interfaces/arraylayoutprops.html +21 -21
- package/docs/interfaces/categorization.html +24 -16
- package/docs/interfaces/category.html +24 -16
- package/docs/interfaces/cellprops.html +12 -12
- package/docs/interfaces/combinatorrendererprops.html +18 -18
- package/docs/interfaces/composablecondition.html +2 -2
- package/docs/interfaces/condition.html +1 -1
- package/docs/interfaces/controlelement.html +21 -16
- package/docs/interfaces/controlprops.html +16 -16
- package/docs/interfaces/controlstate.html +2 -2
- package/docs/interfaces/controlwithdetailprops.html +17 -17
- package/docs/interfaces/dispatchcellprops.html +10 -10
- package/docs/interfaces/dispatchcellstateprops.html +10 -10
- package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
- package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
- package/docs/interfaces/enumcellprops.html +13 -13
- package/docs/interfaces/enumoption.html +2 -2
- package/docs/interfaces/grouplayout.html +24 -12
- package/docs/interfaces/horizontallayout.html +4 -4
- package/docs/interfaces/internationalizable.html +4 -10
- package/docs/interfaces/jsonformsprops.html +24 -9
- package/docs/interfaces/labelable.html +184 -0
- package/docs/interfaces/labeldescription.html +2 -2
- package/docs/interfaces/labeled.html +182 -0
- package/docs/interfaces/labelelement.html +22 -4
- package/docs/interfaces/labelprops.html +339 -0
- package/docs/interfaces/layout.html +4 -4
- package/docs/interfaces/layoutprops.html +25 -10
- package/docs/interfaces/leafcondition.html +9 -8
- package/docs/interfaces/orcondition.html +2 -2
- package/docs/interfaces/ownpropsofcell.html +9 -9
- package/docs/interfaces/ownpropsofcontrol.html +9 -9
- package/docs/interfaces/ownpropsofenum.html +1 -1
- package/docs/interfaces/ownpropsofenumcell.html +10 -10
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
- package/docs/interfaces/ownpropsoflabel.html +286 -0
- package/docs/interfaces/ownpropsoflayout.html +9 -9
- package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
- package/docs/interfaces/ownpropsofrenderer.html +11 -8
- package/docs/interfaces/rendererprops.html +9 -9
- package/docs/interfaces/rule.html +2 -2
- package/docs/interfaces/schemabasedcondition.html +9 -8
- package/docs/interfaces/scopable.html +3 -9
- package/docs/interfaces/scoped.html +183 -0
- package/docs/interfaces/statepropsofarraycontrol.html +17 -17
- package/docs/interfaces/statepropsofarraylayout.html +17 -17
- package/docs/interfaces/statepropsofcell.html +11 -11
- package/docs/interfaces/statepropsofcombinator.html +17 -17
- package/docs/interfaces/statepropsofcontrol.html +15 -15
- package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
- package/docs/interfaces/statepropsofenumcell.html +12 -12
- package/docs/interfaces/statepropsofjsonformsrenderer.html +23 -9
- package/docs/interfaces/statepropsoflabel.html +343 -0
- package/docs/interfaces/statepropsoflayout.html +24 -10
- package/docs/interfaces/statepropsofmasteritem.html +7 -7
- package/docs/interfaces/statepropsofrenderer.html +12 -9
- package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
- package/docs/interfaces/testercontext.html +184 -0
- package/docs/interfaces/uischemaelement.html +3 -3
- package/docs/interfaces/verticallayout.html +4 -4
- package/docs/interfaces/withclassname.html +1 -1
- package/lib/i18n/i18nUtil.d.ts +9 -4
- package/lib/jsonforms-core.cjs.js +103 -49
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +89 -52
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/models/uischema.d.ts +35 -27
- package/lib/reducers/i18n.d.ts +1 -1
- package/lib/testers/testers.d.ts +15 -6
- package/lib/util/renderer.d.ts +18 -1
- package/lib/util/runtime.d.ts +1 -2
- package/lib/util/util.d.ts +6 -6
- package/package.json +2 -2
- package/src/i18n/i18nUtil.ts +24 -7
- package/src/models/uischema.ts +50 -27
- package/src/reducers/i18n.ts +1 -1
- package/src/testers/testers.ts +44 -34
- package/src/util/path.ts +9 -5
- package/src/util/renderer.ts +61 -28
- package/src/util/runtime.ts +1 -1
- package/src/util/util.ts +8 -8
- package/stats.html +1 -1
- package/test/testers.test.ts +95 -23
- package/test/util/renderer.test.ts +105 -7
package/lib/models/uischema.d.ts
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
1
|
import { JsonSchema } from './jsonSchema';
|
|
2
2
|
/**
|
|
3
3
|
* Interface for describing an UI schema element that is referencing
|
|
4
|
-
* a subschema. The value of the scope
|
|
4
|
+
* a subschema. The value of the scope may be a JSON Pointer.
|
|
5
5
|
*/
|
|
6
6
|
export interface Scopable {
|
|
7
|
+
/**
|
|
8
|
+
* The scope that determines to which part this element should be bound to.
|
|
9
|
+
*/
|
|
10
|
+
scope?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Interface for describing an UI schema element that is referencing
|
|
14
|
+
* a subschema. The value of the scope must be a JSON Pointer.
|
|
15
|
+
*/
|
|
16
|
+
export interface Scoped extends Scopable {
|
|
7
17
|
/**
|
|
8
18
|
* The scope that determines to which part this element should be bound to.
|
|
9
19
|
*/
|
|
10
20
|
scope: string;
|
|
11
21
|
}
|
|
12
22
|
/**
|
|
13
|
-
* Interface for describing an UI schema element that
|
|
14
|
-
* If defined, this key is suffixed to derive applicable message keys for the UI schema element.
|
|
15
|
-
* For example, such suffixes are `.label` or `.description` to derive the corresponding message keys for a control element.
|
|
23
|
+
* Interface for describing an UI schema element that may be labeled.
|
|
16
24
|
*/
|
|
25
|
+
export interface Labelable<T = string> {
|
|
26
|
+
/**
|
|
27
|
+
* Label for UI schema element.
|
|
28
|
+
*/
|
|
29
|
+
label?: string | T;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Interface for describing an UI schema element that is labeled.
|
|
33
|
+
*/
|
|
34
|
+
export interface Labeled<T = string> extends Labelable<T> {
|
|
35
|
+
label: string | T;
|
|
36
|
+
}
|
|
17
37
|
export interface Internationalizable {
|
|
18
38
|
i18n?: string;
|
|
19
39
|
}
|
|
@@ -64,14 +84,14 @@ export interface Condition {
|
|
|
64
84
|
/**
|
|
65
85
|
* A leaf condition.
|
|
66
86
|
*/
|
|
67
|
-
export interface LeafCondition extends Condition,
|
|
87
|
+
export interface LeafCondition extends Condition, Scoped {
|
|
68
88
|
type: 'LEAF';
|
|
69
89
|
/**
|
|
70
90
|
* The expected value when evaluating the condition
|
|
71
91
|
*/
|
|
72
92
|
expectedValue: any;
|
|
73
93
|
}
|
|
74
|
-
export interface SchemaBasedCondition extends Condition,
|
|
94
|
+
export interface SchemaBasedCondition extends Condition, Scoped {
|
|
75
95
|
schema: JsonSchema;
|
|
76
96
|
}
|
|
77
97
|
/**
|
|
@@ -137,12 +157,8 @@ export interface HorizontalLayout extends Layout {
|
|
|
137
157
|
* A group resembles a vertical layout, but additionally might have a label.
|
|
138
158
|
* This layout is useful when grouping different elements by a certain criteria.
|
|
139
159
|
*/
|
|
140
|
-
export interface GroupLayout extends Layout {
|
|
160
|
+
export interface GroupLayout extends Layout, Labelable {
|
|
141
161
|
type: 'Group';
|
|
142
|
-
/**
|
|
143
|
-
* The label of this group layout.
|
|
144
|
-
*/
|
|
145
|
-
label?: string;
|
|
146
162
|
}
|
|
147
163
|
/**
|
|
148
164
|
* Represents an object that can be used to configure a label.
|
|
@@ -160,7 +176,7 @@ export interface LabelDescription {
|
|
|
160
176
|
/**
|
|
161
177
|
* A label element.
|
|
162
178
|
*/
|
|
163
|
-
export interface LabelElement extends UISchemaElement {
|
|
179
|
+
export interface LabelElement extends UISchemaElement, Internationalizable {
|
|
164
180
|
type: 'Label';
|
|
165
181
|
/**
|
|
166
182
|
* The text of label.
|
|
@@ -171,34 +187,22 @@ export interface LabelElement extends UISchemaElement {
|
|
|
171
187
|
* A control element. The scope property of the control determines
|
|
172
188
|
* to which part of the schema the control should be bound.
|
|
173
189
|
*/
|
|
174
|
-
export interface ControlElement extends UISchemaElement,
|
|
190
|
+
export interface ControlElement extends UISchemaElement, Scoped, Labelable<string | boolean | LabelDescription>, Internationalizable {
|
|
175
191
|
type: 'Control';
|
|
176
|
-
/**
|
|
177
|
-
* An optional label that will be associated with the control
|
|
178
|
-
*/
|
|
179
|
-
label?: string | boolean | LabelDescription;
|
|
180
192
|
}
|
|
181
193
|
/**
|
|
182
194
|
* The category layout.
|
|
183
195
|
*/
|
|
184
|
-
export interface Category extends Layout {
|
|
196
|
+
export interface Category extends Layout, Labeled {
|
|
185
197
|
type: 'Category';
|
|
186
|
-
/**
|
|
187
|
-
* The label associated with this category layout.
|
|
188
|
-
*/
|
|
189
|
-
label: string;
|
|
190
198
|
}
|
|
191
199
|
/**
|
|
192
200
|
* The categorization element, which may have children elements.
|
|
193
201
|
* A child element may either be itself a Categorization or a Category, hence
|
|
194
202
|
* the categorization element can be used to represent recursive structures like trees.
|
|
195
203
|
*/
|
|
196
|
-
export interface Categorization extends UISchemaElement {
|
|
204
|
+
export interface Categorization extends UISchemaElement, Labeled {
|
|
197
205
|
type: 'Categorization';
|
|
198
|
-
/**
|
|
199
|
-
* The label of this categorization.
|
|
200
|
-
*/
|
|
201
|
-
label: string;
|
|
202
206
|
/**
|
|
203
207
|
* The child elements of this categorization which are either of type
|
|
204
208
|
* {@link Category} or {@link Categorization}.
|
|
@@ -208,3 +212,7 @@ export interface Categorization extends UISchemaElement {
|
|
|
208
212
|
export declare const isInternationalized: (element: unknown) => element is Required<Internationalizable>;
|
|
209
213
|
export declare const isGroup: (layout: Layout) => layout is GroupLayout;
|
|
210
214
|
export declare const isLayout: (uischema: UISchemaElement) => uischema is Layout;
|
|
215
|
+
export declare const isScopable: (obj: unknown) => obj is Scopable;
|
|
216
|
+
export declare const isScoped: (obj: unknown) => obj is Scoped;
|
|
217
|
+
export declare const isLabelable: (obj: unknown) => obj is Labelable<string>;
|
|
218
|
+
export declare const isLabeled: <T = never>(obj: unknown) => obj is Labeled<T>;
|
package/lib/reducers/i18n.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonFormsI18nState } from '../i18n';
|
|
2
2
|
import { I18nActions } from '../actions';
|
|
3
3
|
import { Reducer } from '../util';
|
|
4
|
-
export declare const defaultJsonFormsI18nState: JsonFormsI18nState
|
|
4
|
+
export declare const defaultJsonFormsI18nState: Required<JsonFormsI18nState>;
|
|
5
5
|
export declare const i18nReducer: Reducer<JsonFormsI18nState, I18nActions>;
|
|
6
6
|
export declare const fetchLocale: (state?: JsonFormsI18nState) => string;
|
|
7
7
|
export declare const fetchTranslator: (state?: JsonFormsI18nState) => import("../i18n").Translator;
|
package/lib/testers/testers.d.ts
CHANGED
|
@@ -9,11 +9,20 @@ export declare const NOT_APPLICABLE = -1;
|
|
|
9
9
|
* A tester is a function that receives an UI schema and a JSON schema and returns a boolean.
|
|
10
10
|
* The rootSchema is handed over as context. Can be used to resolve references.
|
|
11
11
|
*/
|
|
12
|
-
export declare type Tester = (uischema: UISchemaElement, schema: JsonSchema,
|
|
12
|
+
export declare type Tester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
|
|
13
13
|
/**
|
|
14
14
|
* A ranked tester associates a tester with a number.
|
|
15
15
|
*/
|
|
16
|
-
export declare type RankedTester = (uischema: UISchemaElement, schema: JsonSchema,
|
|
16
|
+
export declare type RankedTester = (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Additional context given to a tester in addition to UISchema and JsonSchema.
|
|
19
|
+
*/
|
|
20
|
+
export interface TesterContext {
|
|
21
|
+
/** The root JsonSchema of the form. Can be used to resolve references. */
|
|
22
|
+
rootSchema: JsonSchema;
|
|
23
|
+
/** The form wide configuration object given to JsonForms. */
|
|
24
|
+
config: any;
|
|
25
|
+
}
|
|
17
26
|
export declare const isControl: (uischema: any) => uischema is ControlElement;
|
|
18
27
|
/**
|
|
19
28
|
* Only applicable for Controls.
|
|
@@ -97,8 +106,8 @@ export declare const or: (...testers: Tester[]) => Tester;
|
|
|
97
106
|
* @param {number} rank the rank to be returned in case the tester returns true
|
|
98
107
|
* @param {Tester} tester a tester
|
|
99
108
|
*/
|
|
100
|
-
export declare const rankWith: (rank: number, tester: Tester) => (uischema: UISchemaElement, schema: JsonSchema,
|
|
101
|
-
export declare const withIncreasedRank: (by: number, rankedTester: RankedTester) => (uischema: UISchemaElement, schema: JsonSchema,
|
|
109
|
+
export declare const rankWith: (rank: number, tester: Tester) => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
|
|
110
|
+
export declare const withIncreasedRank: (by: number, rankedTester: RankedTester) => (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => number;
|
|
102
111
|
/**
|
|
103
112
|
* Default tester for boolean.
|
|
104
113
|
* @type {RankedTester}
|
|
@@ -173,7 +182,7 @@ export declare const isObjectArray: Tester;
|
|
|
173
182
|
* @type {Tester}
|
|
174
183
|
*/
|
|
175
184
|
export declare const isObjectArrayControl: Tester;
|
|
176
|
-
export declare const isObjectArrayWithNesting: (uischema: UISchemaElement, schema: JsonSchema,
|
|
185
|
+
export declare const isObjectArrayWithNesting: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
|
|
177
186
|
/**
|
|
178
187
|
* Synonym for isObjectArrayControl
|
|
179
188
|
*/
|
|
@@ -193,7 +202,7 @@ export declare const isPrimitiveArrayControl: Tester;
|
|
|
193
202
|
export declare const isRangeControl: Tester;
|
|
194
203
|
/**
|
|
195
204
|
* Tests whether the given UI schema is of type Control, if the schema
|
|
196
|
-
* is of type
|
|
205
|
+
* is of type integer and has option format
|
|
197
206
|
* @type {Tester}
|
|
198
207
|
*/
|
|
199
208
|
export declare const isNumberFormatControl: Tester;
|
package/lib/util/renderer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControlElement, JsonSchema, UISchemaElement } from '../models';
|
|
1
|
+
import { ControlElement, JsonSchema, LabelElement, UISchemaElement } from '../models';
|
|
2
2
|
import { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry } from '../reducers';
|
|
3
3
|
import { JsonFormsUISchemaRegistryEntry } from '../reducers';
|
|
4
4
|
import { RankedTester } from '../testers';
|
|
@@ -82,6 +82,9 @@ export interface OwnPropsOfControl extends OwnPropsOfRenderer {
|
|
|
82
82
|
id?: string;
|
|
83
83
|
uischema?: ControlElement;
|
|
84
84
|
}
|
|
85
|
+
export interface OwnPropsOfLabel extends OwnPropsOfRenderer {
|
|
86
|
+
uischema?: LabelElement;
|
|
87
|
+
}
|
|
85
88
|
export interface OwnPropsOfEnum {
|
|
86
89
|
options?: EnumOption[];
|
|
87
90
|
}
|
|
@@ -202,6 +205,7 @@ export interface StatePropsOfLayout extends StatePropsOfRenderer {
|
|
|
202
205
|
* Direction for the layout to flow
|
|
203
206
|
*/
|
|
204
207
|
direction: 'row' | 'column';
|
|
208
|
+
label?: string;
|
|
205
209
|
}
|
|
206
210
|
export interface LayoutProps extends StatePropsOfLayout {
|
|
207
211
|
}
|
|
@@ -348,6 +352,7 @@ export interface OwnPropsOfJsonFormsRenderer extends OwnPropsOfRenderer {
|
|
|
348
352
|
}
|
|
349
353
|
export interface StatePropsOfJsonFormsRenderer extends OwnPropsOfJsonFormsRenderer {
|
|
350
354
|
rootSchema: JsonSchema;
|
|
355
|
+
config: any;
|
|
351
356
|
}
|
|
352
357
|
export interface JsonFormsProps extends StatePropsOfJsonFormsRenderer {
|
|
353
358
|
}
|
|
@@ -396,3 +401,15 @@ export declare const mapStateToArrayLayoutProps: (state: JsonFormsState, ownProp
|
|
|
396
401
|
*/
|
|
397
402
|
export interface ArrayLayoutProps extends StatePropsOfArrayLayout, DispatchPropsOfArrayControl {
|
|
398
403
|
}
|
|
404
|
+
export interface StatePropsOfLabel extends StatePropsOfRenderer {
|
|
405
|
+
text?: string;
|
|
406
|
+
}
|
|
407
|
+
export interface LabelProps extends StatePropsOfLabel {
|
|
408
|
+
}
|
|
409
|
+
export declare const mapStateToLabelProps: (state: JsonFormsState, props: OwnPropsOfLabel) => {
|
|
410
|
+
text: string;
|
|
411
|
+
visible: boolean;
|
|
412
|
+
config: any;
|
|
413
|
+
renderers: JsonFormsRendererRegistryEntry[];
|
|
414
|
+
cells: JsonFormsCellRendererRegistryEntry[];
|
|
415
|
+
};
|
package/lib/util/runtime.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { UISchemaElement } from '../models';
|
|
1
|
+
import { JsonSchema, UISchemaElement } from '../models';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import { JsonFormsState } from '../store';
|
|
4
|
-
import { JsonSchema } from '../models/jsonSchema';
|
|
5
4
|
export declare const evalVisibility: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
|
|
6
5
|
export declare const evalEnablement: (uischema: UISchemaElement, data: any, path: string, ajv: Ajv) => boolean;
|
|
7
6
|
export declare const hasShowRule: (uischema: UISchemaElement) => boolean;
|
package/lib/util/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema,
|
|
1
|
+
import { JsonSchema, Scoped, UISchemaElement } from '..';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
/**
|
|
4
4
|
* Escape the given string such that it can be used as a class name,
|
|
@@ -11,19 +11,19 @@ export declare const convertToValidClassName: (s: string) => string;
|
|
|
11
11
|
export declare const formatErrorMessage: (errors: string[]) => string;
|
|
12
12
|
export declare const hasType: (jsonSchema: JsonSchema, expected: string) => boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Derives the type of the jsonSchema element
|
|
15
|
-
*/
|
|
14
|
+
* Derives the type of the jsonSchema element
|
|
15
|
+
*/
|
|
16
16
|
export declare const deriveTypes: (jsonSchema: JsonSchema) => string[];
|
|
17
17
|
/**
|
|
18
|
-
* Convenience wrapper around resolveData and resolveSchema.
|
|
19
|
-
*/
|
|
18
|
+
* Convenience wrapper around resolveData and resolveSchema.
|
|
19
|
+
*/
|
|
20
20
|
export declare const Resolve: {
|
|
21
21
|
schema(schema: JsonSchema, schemaPath: string, rootSchema: JsonSchema): JsonSchema;
|
|
22
22
|
data(data: any, path: string): any;
|
|
23
23
|
};
|
|
24
24
|
export declare const Paths: {
|
|
25
25
|
compose: (path1: string, path2: string) => string;
|
|
26
|
-
|
|
26
|
+
fromScoped: (scopable: Scoped) => string;
|
|
27
27
|
};
|
|
28
28
|
export declare const Runtime: {
|
|
29
29
|
isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonforms/core",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"description": "Core module of JSON Forms",
|
|
5
5
|
"repository": "https://github.com/eclipsesource/jsonforms",
|
|
6
6
|
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"typedoc": "^0.19.2",
|
|
89
89
|
"typescript": "4.2.3"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "852057ca1706007bee24bcb1b53b88c7231628a0"
|
|
92
92
|
}
|
package/src/i18n/i18nUtil.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ErrorObject } from 'ajv';
|
|
2
|
-
import { isInternationalized, UISchemaElement } from '../models';
|
|
2
|
+
import { isInternationalized, Labelable, UISchemaElement } from '../models';
|
|
3
3
|
import { getControlPath } from '../reducers';
|
|
4
4
|
import { formatErrorMessage } from '../util';
|
|
5
5
|
import { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
|
|
6
6
|
|
|
7
7
|
export const getI18nKeyPrefixBySchema = (
|
|
8
8
|
schema: i18nJsonSchema | undefined,
|
|
9
|
-
uischema:
|
|
9
|
+
uischema: unknown | undefined
|
|
10
10
|
): string | undefined => {
|
|
11
11
|
if (isInternationalized(uischema)) {
|
|
12
12
|
return uischema.i18n;
|
|
@@ -18,7 +18,7 @@ export const getI18nKeyPrefixBySchema = (
|
|
|
18
18
|
* Transforms a given path to a prefix which can be used for i18n keys.
|
|
19
19
|
* Returns 'root' for empty paths and removes array indices
|
|
20
20
|
*/
|
|
21
|
-
export const transformPathToI18nPrefix = (path: string) => {
|
|
21
|
+
export const transformPathToI18nPrefix = (path: string): string => {
|
|
22
22
|
return (
|
|
23
23
|
path
|
|
24
24
|
?.split('.')
|
|
@@ -29,9 +29,9 @@ export const transformPathToI18nPrefix = (path: string) => {
|
|
|
29
29
|
|
|
30
30
|
export const getI18nKeyPrefix = (
|
|
31
31
|
schema: i18nJsonSchema | undefined,
|
|
32
|
-
uischema:
|
|
32
|
+
uischema: unknown | undefined,
|
|
33
33
|
path: string | undefined
|
|
34
|
-
): string
|
|
34
|
+
): string => {
|
|
35
35
|
return (
|
|
36
36
|
getI18nKeyPrefixBySchema(schema, uischema) ??
|
|
37
37
|
transformPathToI18nPrefix(path)
|
|
@@ -40,10 +40,10 @@ export const getI18nKeyPrefix = (
|
|
|
40
40
|
|
|
41
41
|
export const getI18nKey = (
|
|
42
42
|
schema: i18nJsonSchema | undefined,
|
|
43
|
-
uischema:
|
|
43
|
+
uischema: unknown | undefined,
|
|
44
44
|
path: string | undefined,
|
|
45
45
|
key: string
|
|
46
|
-
): string
|
|
46
|
+
): string => {
|
|
47
47
|
return `${getI18nKeyPrefix(schema, uischema, path)}.${key}`;
|
|
48
48
|
};
|
|
49
49
|
|
|
@@ -106,3 +106,20 @@ export const getCombinedErrorMessage = (
|
|
|
106
106
|
errors.map(error => et(error, t, uischema))
|
|
107
107
|
);
|
|
108
108
|
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* This can be used to internationalize the label of the given Labelable (e.g. UI Schema elements).
|
|
112
|
+
* This should not be used for controls as there we have additional context in the form of the JSON Schema available.
|
|
113
|
+
*/
|
|
114
|
+
export const deriveLabelForUISchemaElement = (uischema: Labelable<boolean>, t: Translator): string | undefined => {
|
|
115
|
+
if (uischema.label === false) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
if ((uischema.label === undefined || uischema.label === null || uischema.label === true) && !isInternationalized(uischema)) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
const stringifiedLabel = typeof uischema.label === 'string' ? uischema.label : JSON.stringify(uischema.label);
|
|
122
|
+
const i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
|
|
123
|
+
const i18nKey = typeof i18nKeyPrefix === 'string' ? `${i18nKeyPrefix}.label` : stringifiedLabel;
|
|
124
|
+
return t(i18nKey, stringifiedLabel, { uischema: uischema });
|
|
125
|
+
}
|
package/src/models/uischema.ts
CHANGED
|
@@ -27,9 +27,20 @@ import { JsonSchema } from './jsonSchema';
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Interface for describing an UI schema element that is referencing
|
|
30
|
-
* a subschema. The value of the scope
|
|
30
|
+
* a subschema. The value of the scope may be a JSON Pointer.
|
|
31
31
|
*/
|
|
32
32
|
export interface Scopable {
|
|
33
|
+
/**
|
|
34
|
+
* The scope that determines to which part this element should be bound to.
|
|
35
|
+
*/
|
|
36
|
+
scope?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Interface for describing an UI schema element that is referencing
|
|
41
|
+
* a subschema. The value of the scope must be a JSON Pointer.
|
|
42
|
+
*/
|
|
43
|
+
export interface Scoped extends Scopable {
|
|
33
44
|
/**
|
|
34
45
|
* The scope that determines to which part this element should be bound to.
|
|
35
46
|
*/
|
|
@@ -37,6 +48,23 @@ export interface Scopable {
|
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
/**
|
|
51
|
+
* Interface for describing an UI schema element that may be labeled.
|
|
52
|
+
*/
|
|
53
|
+
export interface Labelable<T = string> {
|
|
54
|
+
/**
|
|
55
|
+
* Label for UI schema element.
|
|
56
|
+
*/
|
|
57
|
+
label?: string|T;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Interface for describing an UI schema element that is labeled.
|
|
62
|
+
*/
|
|
63
|
+
export interface Labeled<T = string> extends Labelable<T> {
|
|
64
|
+
label: string | T;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*
|
|
40
68
|
* Interface for describing an UI schema element that can provide an internationalization base key.
|
|
41
69
|
* If defined, this key is suffixed to derive applicable message keys for the UI schema element.
|
|
42
70
|
* For example, such suffixes are `.label` or `.description` to derive the corresponding message keys for a control element.
|
|
@@ -96,7 +124,7 @@ export interface Condition {
|
|
|
96
124
|
/**
|
|
97
125
|
* A leaf condition.
|
|
98
126
|
*/
|
|
99
|
-
export interface LeafCondition extends Condition,
|
|
127
|
+
export interface LeafCondition extends Condition, Scoped {
|
|
100
128
|
type: 'LEAF';
|
|
101
129
|
|
|
102
130
|
/**
|
|
@@ -105,7 +133,7 @@ export interface LeafCondition extends Condition, Scopable {
|
|
|
105
133
|
expectedValue: any;
|
|
106
134
|
}
|
|
107
135
|
|
|
108
|
-
export interface SchemaBasedCondition extends Condition,
|
|
136
|
+
export interface SchemaBasedCondition extends Condition, Scoped {
|
|
109
137
|
schema: JsonSchema;
|
|
110
138
|
}
|
|
111
139
|
|
|
@@ -179,12 +207,8 @@ export interface HorizontalLayout extends Layout {
|
|
|
179
207
|
* A group resembles a vertical layout, but additionally might have a label.
|
|
180
208
|
* This layout is useful when grouping different elements by a certain criteria.
|
|
181
209
|
*/
|
|
182
|
-
export interface GroupLayout extends Layout {
|
|
210
|
+
export interface GroupLayout extends Layout, Labelable {
|
|
183
211
|
type: 'Group';
|
|
184
|
-
/**
|
|
185
|
-
* The label of this group layout.
|
|
186
|
-
*/
|
|
187
|
-
label?: string;
|
|
188
212
|
}
|
|
189
213
|
|
|
190
214
|
/**
|
|
@@ -204,7 +228,7 @@ export interface LabelDescription {
|
|
|
204
228
|
/**
|
|
205
229
|
* A label element.
|
|
206
230
|
*/
|
|
207
|
-
export interface LabelElement extends UISchemaElement {
|
|
231
|
+
export interface LabelElement extends UISchemaElement, Internationalizable {
|
|
208
232
|
type: 'Label';
|
|
209
233
|
/**
|
|
210
234
|
* The text of label.
|
|
@@ -216,23 +240,15 @@ export interface LabelElement extends UISchemaElement {
|
|
|
216
240
|
* A control element. The scope property of the control determines
|
|
217
241
|
* to which part of the schema the control should be bound.
|
|
218
242
|
*/
|
|
219
|
-
export interface ControlElement extends UISchemaElement,
|
|
243
|
+
export interface ControlElement extends UISchemaElement, Scoped, Labelable<string | boolean | LabelDescription>, Internationalizable {
|
|
220
244
|
type: 'Control';
|
|
221
|
-
/**
|
|
222
|
-
* An optional label that will be associated with the control
|
|
223
|
-
*/
|
|
224
|
-
label?: string | boolean | LabelDescription;
|
|
225
245
|
}
|
|
226
246
|
|
|
227
247
|
/**
|
|
228
248
|
* The category layout.
|
|
229
249
|
*/
|
|
230
|
-
export interface Category extends Layout {
|
|
250
|
+
export interface Category extends Layout, Labeled {
|
|
231
251
|
type: 'Category';
|
|
232
|
-
/**
|
|
233
|
-
* The label associated with this category layout.
|
|
234
|
-
*/
|
|
235
|
-
label: string;
|
|
236
252
|
}
|
|
237
253
|
|
|
238
254
|
/**
|
|
@@ -240,12 +256,8 @@ export interface Category extends Layout {
|
|
|
240
256
|
* A child element may either be itself a Categorization or a Category, hence
|
|
241
257
|
* the categorization element can be used to represent recursive structures like trees.
|
|
242
258
|
*/
|
|
243
|
-
export interface Categorization extends UISchemaElement {
|
|
259
|
+
export interface Categorization extends UISchemaElement, Labeled {
|
|
244
260
|
type: 'Categorization';
|
|
245
|
-
/**
|
|
246
|
-
* The label of this categorization.
|
|
247
|
-
*/
|
|
248
|
-
label: string;
|
|
249
261
|
/**
|
|
250
262
|
* The child elements of this categorization which are either of type
|
|
251
263
|
* {@link Category} or {@link Categorization}.
|
|
@@ -253,12 +265,23 @@ export interface Categorization extends UISchemaElement {
|
|
|
253
265
|
elements: (Category | Categorization)[];
|
|
254
266
|
}
|
|
255
267
|
|
|
256
|
-
export const isInternationalized = (element: unknown): element is Required<Internationalizable> =>
|
|
257
|
-
|
|
258
|
-
}
|
|
268
|
+
export const isInternationalized = (element: unknown): element is Required<Internationalizable> =>
|
|
269
|
+
typeof element === 'object' && element !== null && typeof (element as Internationalizable).i18n === 'string';
|
|
259
270
|
|
|
260
271
|
export const isGroup = (layout: Layout): layout is GroupLayout =>
|
|
261
272
|
layout.type === 'Group';
|
|
262
273
|
|
|
263
274
|
export const isLayout = (uischema: UISchemaElement): uischema is Layout =>
|
|
264
275
|
(uischema as Layout).elements !== undefined;
|
|
276
|
+
|
|
277
|
+
export const isScopable = (obj: unknown): obj is Scopable =>
|
|
278
|
+
obj && typeof obj === 'object';
|
|
279
|
+
|
|
280
|
+
export const isScoped = (obj: unknown): obj is Scoped =>
|
|
281
|
+
isScopable(obj) && typeof obj.scope === 'string';
|
|
282
|
+
|
|
283
|
+
export const isLabelable = (obj: unknown): obj is Labelable =>
|
|
284
|
+
obj && typeof obj === 'object';
|
|
285
|
+
|
|
286
|
+
export const isLabeled = <T = never>(obj: unknown): obj is Labeled<T> =>
|
|
287
|
+
isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);
|
package/src/reducers/i18n.ts
CHANGED
|
@@ -27,7 +27,7 @@ import { defaultErrorTranslator, defaultTranslator, JsonFormsI18nState } from '.
|
|
|
27
27
|
import { I18nActions, SET_LOCALE, SET_TRANSLATOR, UPDATE_I18N } from '../actions';
|
|
28
28
|
import { Reducer } from '../util';
|
|
29
29
|
|
|
30
|
-
export const defaultJsonFormsI18nState: JsonFormsI18nState = {
|
|
30
|
+
export const defaultJsonFormsI18nState: Required<JsonFormsI18nState> = {
|
|
31
31
|
locale: 'en',
|
|
32
32
|
translate: defaultTranslator,
|
|
33
33
|
translateError: defaultErrorTranslator
|