@jsonforms/core 3.1.0-alpha.0 → 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/Helpers.d.ts +1 -1
- package/lib/actions/actions.d.ts +27 -26
- package/lib/generators/Generate.d.ts +1 -1
- package/lib/generators/schema.d.ts +1 -1
- package/lib/i18n/arrayTranslations.d.ts +24 -0
- package/lib/i18n/i18nTypes.d.ts +3 -2
- package/lib/i18n/i18nUtil.d.ts +5 -2
- package/lib/i18n/index.d.ts +1 -0
- package/lib/jsonforms-core.cjs.js +428 -259
- 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/models/jsonSchema.d.ts +2 -2
- package/lib/models/uischema.d.ts +1 -1
- package/lib/reducers/cells.d.ts +2 -2
- package/lib/reducers/config.d.ts +1 -1
- package/lib/reducers/core.d.ts +3 -2
- package/lib/reducers/default-data.d.ts +1 -1
- package/lib/reducers/i18n.d.ts +1 -1
- package/lib/reducers/reducers.d.ts +4 -4
- package/lib/reducers/renderers.d.ts +2 -2
- package/lib/reducers/selectors.d.ts +6 -6
- package/lib/reducers/uischemas.d.ts +2 -2
- package/lib/store.d.ts +3 -3
- package/lib/testers/testers.d.ts +1 -1
- package/lib/util/cell.d.ts +3 -4
- package/lib/util/combinators.d.ts +1 -1
- package/lib/util/label.d.ts +1 -1
- package/lib/util/path.d.ts +6 -3
- package/lib/util/renderer.d.ts +11 -7
- package/lib/util/resolvers.d.ts +1 -1
- package/lib/util/runtime.d.ts +2 -2
- package/lib/util/util.d.ts +2 -2
- package/lib/util/validator.d.ts +1 -1
- package/package.json +16 -5
- package/src/Helpers.ts +2 -2
- package/src/actions/actions.ts +59 -61
- package/src/configDefault.ts +1 -1
- package/src/generators/Generate.ts +4 -2
- package/src/generators/schema.ts +30 -26
- package/src/generators/uischema.ts +7 -6
- package/src/i18n/arrayTranslations.ts +54 -0
- package/src/i18n/i18nTypes.ts +12 -7
- package/src/i18n/i18nUtil.ts +66 -16
- package/src/i18n/index.ts +1 -0
- package/src/models/draft4.ts +33 -33
- package/src/models/jsonSchema.ts +2 -2
- package/src/models/uischema.ts +18 -7
- package/src/reducers/cells.ts +10 -9
- package/src/reducers/config.ts +1 -1
- package/src/reducers/core.ts +115 -75
- package/src/reducers/default-data.ts +8 -8
- package/src/reducers/i18n.ts +22 -10
- package/src/reducers/reducers.ts +24 -34
- package/src/reducers/renderers.ts +9 -9
- package/src/reducers/selectors.ts +10 -11
- package/src/reducers/uischemas.ts +27 -26
- package/src/store.ts +4 -4
- package/src/testers/testers.ts +200 -147
- package/src/util/cell.ts +27 -29
- package/src/util/combinators.ts +6 -4
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +15 -8
- package/src/util/renderer.ts +123 -72
- package/src/util/resolvers.ts +16 -14
- package/src/util/runtime.ts +4 -4
- 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 +54 -54
- package/src/util/validator.ts +2 -2
- package/.nycrc +0 -6
- package/docs/assets/css/main.css +0 -1
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -51
- package/docs/assets/js/search.json +0 -1
- package/docs/classes/gen.html +0 -406
- package/docs/enums/ruleeffect.html +0 -214
- package/docs/globals.html +0 -10568
- package/docs/index.html +0 -1297
- package/docs/interfaces/action.html +0 -166
- package/docs/interfaces/addcellrendereraction.html +0 -181
- package/docs/interfaces/addrendereraction.html +0 -181
- package/docs/interfaces/adduischemaaction.html +0 -181
- package/docs/interfaces/andcondition.html +0 -181
- package/docs/interfaces/anyaction.html +0 -189
- package/docs/interfaces/arraycontrolprops.html +0 -653
- package/docs/interfaces/arraylayoutprops.html +0 -648
- package/docs/interfaces/categorization.html +0 -281
- package/docs/interfaces/category.html +0 -279
- package/docs/interfaces/cellprops.html +0 -452
- package/docs/interfaces/combinatorrendererprops.html +0 -503
- package/docs/interfaces/combinatorsubschemarenderinfo.html +0 -181
- package/docs/interfaces/composablecondition.html +0 -193
- package/docs/interfaces/condition.html +0 -176
- package/docs/interfaces/controlelement.html +0 -280
- package/docs/interfaces/controlprops.html +0 -497
- package/docs/interfaces/controlstate.html +0 -184
- package/docs/interfaces/controlwithdetailprops.html +0 -501
- package/docs/interfaces/dispatchcellprops.html +0 -388
- package/docs/interfaces/dispatchcellstateprops.html +0 -408
- package/docs/interfaces/dispatchpropsofarraycontrol.html +0 -322
- package/docs/interfaces/dispatchpropsofcontrol.html +0 -204
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +0 -215
- package/docs/interfaces/enumcellprops.html +0 -467
- package/docs/interfaces/enumoption.html +0 -167
- package/docs/interfaces/formatted.html +0 -226
- package/docs/interfaces/grouplayout.html +0 -284
- package/docs/interfaces/horizontallayout.html +0 -234
- package/docs/interfaces/initaction.html +0 -209
- package/docs/interfaces/initactionoptions.html +0 -181
- package/docs/interfaces/internationalizable.html +0 -170
- package/docs/interfaces/jsonformscellrendererregistryentry.html +0 -167
- package/docs/interfaces/jsonformscore.html +0 -251
- package/docs/interfaces/jsonformsdefaultdataregistryentry.html +0 -167
- package/docs/interfaces/jsonformsextendedstate.html +0 -175
- package/docs/interfaces/jsonformsi18nstate.html +0 -181
- package/docs/interfaces/jsonformsprops.html +0 -321
- package/docs/interfaces/jsonformsrendererregistryentry.html +0 -167
- package/docs/interfaces/jsonformsstate.html +0 -170
- package/docs/interfaces/jsonformsstore.html +0 -376
- package/docs/interfaces/jsonformssubstates.html +0 -276
- package/docs/interfaces/jsonformsuischemaregistryentry.html +0 -167
- package/docs/interfaces/jsonschema4.html +0 -758
- package/docs/interfaces/jsonschema7.html +0 -884
- package/docs/interfaces/labelable.html +0 -184
- package/docs/interfaces/labeldescription.html +0 -184
- package/docs/interfaces/labeled.html +0 -182
- package/docs/interfaces/labelelement.html +0 -251
- package/docs/interfaces/labelprops.html +0 -339
- package/docs/interfaces/layout.html +0 -253
- package/docs/interfaces/layoutprops.html +0 -359
- package/docs/interfaces/leafcondition.html +0 -209
- package/docs/interfaces/orcondition.html +0 -181
- package/docs/interfaces/ownpropsofcell.html +0 -321
- package/docs/interfaces/ownpropsofcontrol.html +0 -305
- package/docs/interfaces/ownpropsofenum.html +0 -161
- package/docs/interfaces/ownpropsofenumcell.html +0 -335
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +0 -296
- package/docs/interfaces/ownpropsoflabel.html +0 -286
- package/docs/interfaces/ownpropsoflayout.html +0 -305
- package/docs/interfaces/ownpropsofmasterlistitem.html +0 -289
- package/docs/interfaces/ownpropsofrenderer.html +0 -292
- package/docs/interfaces/referenceschemamap.html +0 -138
- package/docs/interfaces/registerdefaultdataaction.html +0 -181
- package/docs/interfaces/removecellrendereraction.html +0 -181
- package/docs/interfaces/removerendereraction.html +0 -181
- package/docs/interfaces/removeuischemaaction.html +0 -167
- package/docs/interfaces/rendererprops.html +0 -331
- package/docs/interfaces/rule.html +0 -185
- package/docs/interfaces/schemabasedcondition.html +0 -202
- package/docs/interfaces/scopable.html +0 -171
- package/docs/interfaces/scoped.html +0 -183
- package/docs/interfaces/setajvaction.html +0 -167
- package/docs/interfaces/setconfigaction.html +0 -167
- package/docs/interfaces/setlocaleaction.html +0 -167
- package/docs/interfaces/setschemaaction.html +0 -167
- package/docs/interfaces/settranslatoraction.html +0 -181
- package/docs/interfaces/setuischemaaction.html +0 -167
- package/docs/interfaces/setvalidationmodeaction.html +0 -167
- package/docs/interfaces/statepropsofarraycontrol.html +0 -474
- package/docs/interfaces/statepropsofarraylayout.html +0 -461
- package/docs/interfaces/statepropsofcell.html +0 -408
- package/docs/interfaces/statepropsofcombinator.html +0 -449
- package/docs/interfaces/statepropsofcontrol.html +0 -451
- package/docs/interfaces/statepropsofcontrolwithdetail.html +0 -463
- package/docs/interfaces/statepropsofenumcell.html +0 -422
- package/docs/interfaces/statepropsofjsonformsrenderer.html +0 -324
- package/docs/interfaces/statepropsoflabel.html +0 -343
- package/docs/interfaces/statepropsoflayout.html +0 -369
- package/docs/interfaces/statepropsofmasteritem.html +0 -309
- package/docs/interfaces/statepropsofrenderer.html +0 -331
- package/docs/interfaces/statepropsofscopedrenderer.html +0 -391
- package/docs/interfaces/store.html +0 -386
- package/docs/interfaces/testercontext.html +0 -184
- package/docs/interfaces/uischemaelement.html +0 -225
- package/docs/interfaces/unregisterdefaultdataaction.html +0 -167
- package/docs/interfaces/updateaction.html +0 -202
- package/docs/interfaces/updatecoreaction.html +0 -209
- package/docs/interfaces/updateerrorsaction.html +0 -167
- package/docs/interfaces/updatei18naction.html +0 -195
- package/docs/interfaces/verticallayout.html +0 -234
- package/docs/interfaces/withclassname.html +0 -153
- package/rollup.config.js +0 -44
- package/stats.html +0 -3279
- package/test/actions/actions.test.ts +0 -93
- package/test/generators/schema.test.ts +0 -224
- package/test/generators/uischema.test.ts +0 -576
- package/test/i18n/i18nUtil.test.ts +0 -88
- package/test/reducers/core.test.ts +0 -1682
- package/test/reducers/uischemas.test.ts +0 -173
- package/test/testers.test.ts +0 -948
- package/test/util/array.test.ts +0 -28
- package/test/util/cell.test.ts +0 -354
- package/test/util/derivetype.test.ts +0 -101
- package/test/util/label.test.ts +0 -364
- package/test/util/path.test.ts +0 -259
- package/test/util/renderer.test.ts +0 -1830
- package/test/util/resolvers.test.ts +0 -157
- package/test/util/runtime.test.ts +0 -779
- package/tsconfig.json +0 -13
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import get from 'lodash/get';
|
|
27
|
-
import Ajv from 'ajv';
|
|
28
|
-
import { JsonFormsState } from '../store';
|
|
29
|
-
import { JsonSchema, UISchemaElement } from '../models';
|
|
27
|
+
import type Ajv from 'ajv';
|
|
28
|
+
import type { JsonFormsState } from '../store';
|
|
29
|
+
import type { JsonSchema, UISchemaElement } from '../models';
|
|
30
30
|
import {
|
|
31
31
|
extractAjv,
|
|
32
32
|
extractData,
|
|
@@ -35,11 +35,11 @@ import {
|
|
|
35
35
|
} from './core';
|
|
36
36
|
import {
|
|
37
37
|
extractDefaultData,
|
|
38
|
-
JsonFormsDefaultDataRegistryEntry
|
|
38
|
+
JsonFormsDefaultDataRegistryEntry,
|
|
39
39
|
} from './default-data';
|
|
40
|
-
import { JsonFormsRendererRegistryEntry } from './renderers';
|
|
41
|
-
import { JsonFormsCellRendererRegistryEntry } from './cells';
|
|
42
|
-
import { JsonFormsUISchemaRegistryEntry } from './uischemas';
|
|
40
|
+
import type { JsonFormsRendererRegistryEntry } from './renderers';
|
|
41
|
+
import type { JsonFormsCellRendererRegistryEntry } from './cells';
|
|
42
|
+
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
|
|
43
43
|
|
|
44
44
|
export const getData = (state: JsonFormsState) =>
|
|
45
45
|
extractData(get(state, 'jsonforms.core'));
|
|
@@ -47,9 +47,8 @@ export const getSchema = (state: JsonFormsState): JsonSchema =>
|
|
|
47
47
|
extractSchema(get(state, 'jsonforms.core'));
|
|
48
48
|
export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
|
|
49
49
|
extractUiSchema(get(state, 'jsonforms.core'));
|
|
50
|
-
export const getAjv = (
|
|
51
|
-
state
|
|
52
|
-
): Ajv => extractAjv(get(state, 'jsonforms.core'));
|
|
50
|
+
export const getAjv = (state: JsonFormsState): Ajv =>
|
|
51
|
+
extractAjv(get(state, 'jsonforms.core'));
|
|
53
52
|
export const getDefaultData = (
|
|
54
53
|
state: JsonFormsState
|
|
55
54
|
): JsonFormsDefaultDataRegistryEntry[] =>
|
|
@@ -62,4 +61,4 @@ export const getCells = (
|
|
|
62
61
|
): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
|
|
63
62
|
export const getUISchemas = (
|
|
64
63
|
state: JsonFormsState
|
|
65
|
-
): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas')
|
|
64
|
+
): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas');
|
|
@@ -27,8 +27,8 @@ import maxBy from 'lodash/maxBy';
|
|
|
27
27
|
import remove from 'lodash/remove';
|
|
28
28
|
import { ADD_UI_SCHEMA, REMOVE_UI_SCHEMA, UISchemaActions } from '../actions';
|
|
29
29
|
import { NOT_APPLICABLE } from '../testers';
|
|
30
|
-
import { JsonSchema, UISchemaElement } from '../models';
|
|
31
|
-
import { Reducer } from '../util';
|
|
30
|
+
import type { JsonSchema, UISchemaElement } from '../models';
|
|
31
|
+
import type { Reducer } from '../util';
|
|
32
32
|
|
|
33
33
|
export type UISchemaTester = (
|
|
34
34
|
schema: JsonSchema,
|
|
@@ -41,39 +41,40 @@ export interface JsonFormsUISchemaRegistryEntry {
|
|
|
41
41
|
uischema: UISchemaElement;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export const uischemaRegistryReducer: Reducer<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
) => {
|
|
44
|
+
export const uischemaRegistryReducer: Reducer<
|
|
45
|
+
JsonFormsUISchemaRegistryEntry[],
|
|
46
|
+
UISchemaActions
|
|
47
|
+
> = (state = [], action) => {
|
|
48
48
|
switch (action.type) {
|
|
49
49
|
case ADD_UI_SCHEMA:
|
|
50
50
|
return state
|
|
51
51
|
.slice()
|
|
52
52
|
.concat({ tester: action.tester, uischema: action.uischema });
|
|
53
|
-
case REMOVE_UI_SCHEMA:
|
|
53
|
+
case REMOVE_UI_SCHEMA: {
|
|
54
54
|
const copy = state.slice();
|
|
55
|
-
remove(copy, entry => entry.tester === action.tester);
|
|
55
|
+
remove(copy, (entry) => entry.tester === action.tester);
|
|
56
56
|
return copy;
|
|
57
|
+
}
|
|
57
58
|
default:
|
|
58
59
|
return state;
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
|
|
62
|
-
export const findMatchingUISchema =
|
|
63
|
-
state: JsonFormsUISchemaRegistryEntry[]
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
): UISchemaElement => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
63
|
+
export const findMatchingUISchema =
|
|
64
|
+
(state: JsonFormsUISchemaRegistryEntry[]) =>
|
|
65
|
+
(
|
|
66
|
+
jsonSchema: JsonSchema,
|
|
67
|
+
schemaPath: string,
|
|
68
|
+
path: string
|
|
69
|
+
): UISchemaElement => {
|
|
70
|
+
const match = maxBy(state, (entry) =>
|
|
71
|
+
entry.tester(jsonSchema, schemaPath, path)
|
|
72
|
+
);
|
|
73
|
+
if (
|
|
74
|
+
match !== undefined &&
|
|
75
|
+
match.tester(jsonSchema, schemaPath, path) !== NOT_APPLICABLE
|
|
76
|
+
) {
|
|
77
|
+
return match.uischema;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
package/src/store.ts
CHANGED
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import { Store } from './util';
|
|
27
|
-
import {
|
|
26
|
+
import type { Store } from './util';
|
|
27
|
+
import type {
|
|
28
28
|
JsonFormsCore,
|
|
29
29
|
JsonFormsCellRendererRegistryEntry,
|
|
30
30
|
JsonFormsRendererRegistryEntry,
|
|
31
|
-
JsonFormsUISchemaRegistryEntry
|
|
31
|
+
JsonFormsUISchemaRegistryEntry,
|
|
32
32
|
} from './reducers';
|
|
33
|
-
import { JsonFormsI18nState } from './i18n';
|
|
33
|
+
import type { JsonFormsI18nState } from './i18n';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* JSONForms store.
|
package/src/testers/testers.ts
CHANGED
|
@@ -31,11 +31,11 @@ import isArray from 'lodash/isArray';
|
|
|
31
31
|
import reduce from 'lodash/reduce';
|
|
32
32
|
import toPairs from 'lodash/toPairs';
|
|
33
33
|
import includes from 'lodash/includes';
|
|
34
|
-
import {
|
|
34
|
+
import type {
|
|
35
35
|
Categorization,
|
|
36
36
|
ControlElement,
|
|
37
37
|
JsonSchema,
|
|
38
|
-
UISchemaElement
|
|
38
|
+
UISchemaElement,
|
|
39
39
|
} from '../models';
|
|
40
40
|
import { deriveTypes, hasType, resolveSchema } from '../util';
|
|
41
41
|
|
|
@@ -49,7 +49,11 @@ export const NOT_APPLICABLE = -1;
|
|
|
49
49
|
* A tester is a function that receives an UI schema and a JSON schema and returns a boolean.
|
|
50
50
|
* The rootSchema is handed over as context. Can be used to resolve references.
|
|
51
51
|
*/
|
|
52
|
-
export type Tester = (
|
|
52
|
+
export type Tester = (
|
|
53
|
+
uischema: UISchemaElement,
|
|
54
|
+
schema: JsonSchema,
|
|
55
|
+
context: TesterContext
|
|
56
|
+
) => boolean;
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* A ranked tester associates a tester with a number.
|
|
@@ -83,50 +87,70 @@ export const isControl = (uischema: any): uischema is ControlElement =>
|
|
|
83
87
|
* @param {(JsonSchema) => boolean} predicate the predicate that should be
|
|
84
88
|
* applied to the resolved sub-schema
|
|
85
89
|
*/
|
|
86
|
-
export const schemaMatches =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
export const schemaMatches =
|
|
91
|
+
(
|
|
92
|
+
predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean
|
|
93
|
+
): Tester =>
|
|
94
|
+
(
|
|
95
|
+
uischema: UISchemaElement,
|
|
96
|
+
schema: JsonSchema,
|
|
97
|
+
context: TesterContext
|
|
98
|
+
): boolean => {
|
|
99
|
+
if (isEmpty(uischema) || !isControl(uischema)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (isEmpty(schema)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const schemaPath = uischema.scope;
|
|
106
|
+
if (isEmpty(schemaPath)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
let currentDataSchema = schema;
|
|
110
|
+
if (hasType(schema, 'object')) {
|
|
111
|
+
currentDataSchema = resolveSchema(
|
|
112
|
+
schema,
|
|
113
|
+
schemaPath,
|
|
114
|
+
context?.rootSchema
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
if (currentDataSchema === undefined) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
109
120
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
return predicate(currentDataSchema, context?.rootSchema);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const schemaSubPathMatches =
|
|
125
|
+
(
|
|
126
|
+
subPath: string,
|
|
127
|
+
predicate: (schema: JsonSchema, rootSchema: JsonSchema) => boolean
|
|
128
|
+
): Tester =>
|
|
129
|
+
(
|
|
130
|
+
uischema: UISchemaElement,
|
|
131
|
+
schema: JsonSchema,
|
|
132
|
+
context: TesterContext
|
|
133
|
+
): boolean => {
|
|
134
|
+
if (isEmpty(uischema) || !isControl(uischema)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
const schemaPath = uischema.scope;
|
|
138
|
+
let currentDataSchema: JsonSchema = schema;
|
|
139
|
+
if (hasType(schema, 'object')) {
|
|
140
|
+
currentDataSchema = resolveSchema(
|
|
141
|
+
schema,
|
|
142
|
+
schemaPath,
|
|
143
|
+
context?.rootSchema
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
currentDataSchema = get(currentDataSchema, subPath);
|
|
123
147
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
148
|
+
if (currentDataSchema === undefined) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
127
151
|
|
|
128
|
-
|
|
129
|
-
};
|
|
152
|
+
return predicate(currentDataSchema, context?.rootSchema);
|
|
153
|
+
};
|
|
130
154
|
|
|
131
155
|
/**
|
|
132
156
|
* Only applicable for Controls.
|
|
@@ -138,7 +162,7 @@ export const schemaSubPathMatches = (
|
|
|
138
162
|
* @param {string} expectedType the expected type of the resolved sub-schema
|
|
139
163
|
*/
|
|
140
164
|
export const schemaTypeIs = (expectedType: string): Tester =>
|
|
141
|
-
schemaMatches(schema => !isEmpty(schema) && hasType(schema, expectedType));
|
|
165
|
+
schemaMatches((schema) => !isEmpty(schema) && hasType(schema, expectedType));
|
|
142
166
|
|
|
143
167
|
/**
|
|
144
168
|
* Only applicable for Controls.
|
|
@@ -151,7 +175,7 @@ export const schemaTypeIs = (expectedType: string): Tester =>
|
|
|
151
175
|
*/
|
|
152
176
|
export const formatIs = (expectedFormat: string): Tester =>
|
|
153
177
|
schemaMatches(
|
|
154
|
-
schema =>
|
|
178
|
+
(schema) =>
|
|
155
179
|
!isEmpty(schema) &&
|
|
156
180
|
schema.format === expectedFormat &&
|
|
157
181
|
hasType(schema, 'string')
|
|
@@ -162,9 +186,10 @@ export const formatIs = (expectedFormat: string): Tester =>
|
|
|
162
186
|
*
|
|
163
187
|
* @param {string} expected the expected UI schema type
|
|
164
188
|
*/
|
|
165
|
-
export const uiTypeIs =
|
|
166
|
-
|
|
167
|
-
): boolean =>
|
|
189
|
+
export const uiTypeIs =
|
|
190
|
+
(expected: string): Tester =>
|
|
191
|
+
(uischema: UISchemaElement): boolean =>
|
|
192
|
+
!isEmpty(uischema) && uischema.type === expected;
|
|
168
193
|
|
|
169
194
|
/**
|
|
170
195
|
* Checks whether the given UI schema has an option with the given
|
|
@@ -174,16 +199,16 @@ export const uiTypeIs = (expected: string): Tester => (
|
|
|
174
199
|
* @param {string} optionName the name of the option to check
|
|
175
200
|
* @param {any} optionValue the expected value of the option
|
|
176
201
|
*/
|
|
177
|
-
export const optionIs =
|
|
178
|
-
|
|
179
|
-
): boolean => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
202
|
+
export const optionIs =
|
|
203
|
+
(optionName: string, optionValue: any): Tester =>
|
|
204
|
+
(uischema: UISchemaElement): boolean => {
|
|
205
|
+
if (isEmpty(uischema)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
183
208
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
209
|
+
const options = uischema.options;
|
|
210
|
+
return !isEmpty(options) && options[optionName] === optionValue;
|
|
211
|
+
};
|
|
187
212
|
|
|
188
213
|
/**
|
|
189
214
|
* Only applicable for Controls.
|
|
@@ -192,15 +217,15 @@ export const optionIs = (optionName: string, optionValue: any): Tester => (
|
|
|
192
217
|
*
|
|
193
218
|
* @param {string} expected the expected ending of the reference
|
|
194
219
|
*/
|
|
195
|
-
export const scopeEndsWith =
|
|
196
|
-
|
|
197
|
-
): boolean => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
220
|
+
export const scopeEndsWith =
|
|
221
|
+
(expected: string): Tester =>
|
|
222
|
+
(uischema: UISchemaElement): boolean => {
|
|
223
|
+
if (isEmpty(expected) || !isControl(uischema)) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
201
226
|
|
|
202
|
-
|
|
203
|
-
};
|
|
227
|
+
return endsWith(uischema.scope, expected);
|
|
228
|
+
};
|
|
204
229
|
|
|
205
230
|
/**
|
|
206
231
|
* Only applicable for Controls.
|
|
@@ -209,38 +234,42 @@ export const scopeEndsWith = (expected: string): Tester => (
|
|
|
209
234
|
*
|
|
210
235
|
* @param {string} expected the expected ending of the reference
|
|
211
236
|
*/
|
|
212
|
-
export const scopeEndIs =
|
|
213
|
-
|
|
214
|
-
): boolean => {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
237
|
+
export const scopeEndIs =
|
|
238
|
+
(expected: string): Tester =>
|
|
239
|
+
(uischema: UISchemaElement): boolean => {
|
|
240
|
+
if (isEmpty(expected) || !isControl(uischema)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const schemaPath = uischema.scope;
|
|
219
244
|
|
|
220
|
-
|
|
221
|
-
};
|
|
245
|
+
return !isEmpty(schemaPath) && last(schemaPath.split('/')) === expected;
|
|
246
|
+
};
|
|
222
247
|
|
|
223
248
|
/**
|
|
224
249
|
* A tester that allow composing other testers by && them.
|
|
225
250
|
*
|
|
226
251
|
* @param {Array<Tester>} testers the testers to be composed
|
|
227
252
|
*/
|
|
228
|
-
export const and =
|
|
229
|
-
|
|
230
|
-
schema: JsonSchema,
|
|
231
|
-
|
|
232
|
-
|
|
253
|
+
export const and =
|
|
254
|
+
(...testers: Tester[]): Tester =>
|
|
255
|
+
(uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) =>
|
|
256
|
+
testers.reduce(
|
|
257
|
+
(acc, tester) => acc && tester(uischema, schema, context),
|
|
258
|
+
true
|
|
259
|
+
);
|
|
233
260
|
|
|
234
261
|
/**
|
|
235
262
|
* A tester that allow composing other testers by || them.
|
|
236
263
|
*
|
|
237
264
|
* @param {Array<Tester>} testers the testers to be composed
|
|
238
265
|
*/
|
|
239
|
-
export const or =
|
|
240
|
-
|
|
241
|
-
schema: JsonSchema,
|
|
242
|
-
|
|
243
|
-
|
|
266
|
+
export const or =
|
|
267
|
+
(...testers: Tester[]): Tester =>
|
|
268
|
+
(uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) =>
|
|
269
|
+
testers.reduce(
|
|
270
|
+
(acc, tester) => acc || tester(uischema, schema, context),
|
|
271
|
+
false
|
|
272
|
+
);
|
|
244
273
|
/**
|
|
245
274
|
* Create a ranked tester that will associate a number with a given tester, if the
|
|
246
275
|
* latter returns true.
|
|
@@ -248,30 +277,34 @@ export const or = (...testers: Tester[]): Tester => (
|
|
|
248
277
|
* @param {number} rank the rank to be returned in case the tester returns true
|
|
249
278
|
* @param {Tester} tester a tester
|
|
250
279
|
*/
|
|
251
|
-
export const rankWith =
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
};
|
|
280
|
+
export const rankWith =
|
|
281
|
+
(rank: number, tester: Tester) =>
|
|
282
|
+
(
|
|
283
|
+
uischema: UISchemaElement,
|
|
284
|
+
schema: JsonSchema,
|
|
285
|
+
context: TesterContext
|
|
286
|
+
): number => {
|
|
287
|
+
if (tester(uischema, schema, context)) {
|
|
288
|
+
return rank;
|
|
289
|
+
}
|
|
262
290
|
|
|
263
|
-
export const withIncreasedRank = (by: number, rankedTester: RankedTester) => (
|
|
264
|
-
uischema: UISchemaElement,
|
|
265
|
-
schema: JsonSchema,
|
|
266
|
-
context: TesterContext
|
|
267
|
-
): number => {
|
|
268
|
-
const rank = rankedTester(uischema, schema, context);
|
|
269
|
-
if (rank === NOT_APPLICABLE) {
|
|
270
291
|
return NOT_APPLICABLE;
|
|
271
|
-
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const withIncreasedRank =
|
|
295
|
+
(by: number, rankedTester: RankedTester) =>
|
|
296
|
+
(
|
|
297
|
+
uischema: UISchemaElement,
|
|
298
|
+
schema: JsonSchema,
|
|
299
|
+
context: TesterContext
|
|
300
|
+
): number => {
|
|
301
|
+
const rank = rankedTester(uischema, schema, context);
|
|
302
|
+
if (rank === NOT_APPLICABLE) {
|
|
303
|
+
return NOT_APPLICABLE;
|
|
304
|
+
}
|
|
272
305
|
|
|
273
|
-
|
|
274
|
-
};
|
|
306
|
+
return rank + by;
|
|
307
|
+
};
|
|
275
308
|
|
|
276
309
|
/**
|
|
277
310
|
* Default tester for boolean.
|
|
@@ -287,17 +320,17 @@ export const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));
|
|
|
287
320
|
|
|
288
321
|
export const isAllOfControl = and(
|
|
289
322
|
uiTypeIs('Control'),
|
|
290
|
-
schemaMatches(schema => schema.hasOwnProperty('allOf'))
|
|
323
|
+
schemaMatches((schema) => schema.hasOwnProperty('allOf'))
|
|
291
324
|
);
|
|
292
325
|
|
|
293
326
|
export const isAnyOfControl = and(
|
|
294
327
|
uiTypeIs('Control'),
|
|
295
|
-
schemaMatches(schema => schema.hasOwnProperty('anyOf'))
|
|
328
|
+
schemaMatches((schema) => schema.hasOwnProperty('anyOf'))
|
|
296
329
|
);
|
|
297
330
|
|
|
298
331
|
export const isOneOfControl = and(
|
|
299
332
|
uiTypeIs('Control'),
|
|
300
|
-
schemaMatches(schema => schema.hasOwnProperty('oneOf'))
|
|
333
|
+
schemaMatches((schema) => schema.hasOwnProperty('oneOf'))
|
|
301
334
|
);
|
|
302
335
|
|
|
303
336
|
/**
|
|
@@ -308,8 +341,8 @@ export const isOneOfControl = and(
|
|
|
308
341
|
export const isEnumControl = and(
|
|
309
342
|
uiTypeIs('Control'),
|
|
310
343
|
or(
|
|
311
|
-
schemaMatches(schema => schema.hasOwnProperty('enum')),
|
|
312
|
-
schemaMatches(schema => schema.hasOwnProperty('const'))
|
|
344
|
+
schemaMatches((schema) => schema.hasOwnProperty('enum')),
|
|
345
|
+
schemaMatches((schema) => schema.hasOwnProperty('const'))
|
|
313
346
|
)
|
|
314
347
|
);
|
|
315
348
|
|
|
@@ -320,9 +353,10 @@ export const isEnumControl = and(
|
|
|
320
353
|
*/
|
|
321
354
|
export const isOneOfEnumControl = and(
|
|
322
355
|
uiTypeIs('Control'),
|
|
323
|
-
schemaMatches(
|
|
324
|
-
schema
|
|
325
|
-
|
|
356
|
+
schemaMatches(
|
|
357
|
+
(schema) =>
|
|
358
|
+
schema.hasOwnProperty('oneOf') &&
|
|
359
|
+
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined)
|
|
326
360
|
)
|
|
327
361
|
);
|
|
328
362
|
|
|
@@ -396,11 +430,15 @@ export const isDateTimeControl = and(
|
|
|
396
430
|
*/
|
|
397
431
|
export const isObjectArray = and(
|
|
398
432
|
schemaMatches(
|
|
399
|
-
(schema, rootSchema) =>
|
|
433
|
+
(schema, rootSchema) =>
|
|
434
|
+
hasType(schema, 'array') &&
|
|
435
|
+
!Array.isArray(resolveSchema(schema, 'items', rootSchema)) // we don't care about tuples
|
|
400
436
|
),
|
|
401
437
|
schemaSubPathMatches('items', (schema, rootSchema) => {
|
|
402
|
-
const resolvedSchema = schema.$ref
|
|
403
|
-
|
|
438
|
+
const resolvedSchema = schema.$ref
|
|
439
|
+
? resolveSchema(rootSchema, schema.$ref, rootSchema)
|
|
440
|
+
: schema;
|
|
441
|
+
return hasType(resolvedSchema, 'object');
|
|
404
442
|
})
|
|
405
443
|
);
|
|
406
444
|
|
|
@@ -417,7 +455,11 @@ const traverse = (
|
|
|
417
455
|
rootSchema: JsonSchema
|
|
418
456
|
): boolean => {
|
|
419
457
|
if (isArray(any)) {
|
|
420
|
-
return reduce(
|
|
458
|
+
return reduce(
|
|
459
|
+
any,
|
|
460
|
+
(acc, el) => acc || traverse(el, pred, rootSchema),
|
|
461
|
+
false
|
|
462
|
+
);
|
|
421
463
|
}
|
|
422
464
|
|
|
423
465
|
if (pred(any)) {
|
|
@@ -454,32 +496,43 @@ export const isObjectArrayWithNesting = (
|
|
|
454
496
|
return false;
|
|
455
497
|
}
|
|
456
498
|
const schemaPath = (uischema as ControlElement).scope;
|
|
457
|
-
const resolvedSchema = resolveSchema(
|
|
499
|
+
const resolvedSchema = resolveSchema(
|
|
500
|
+
schema,
|
|
501
|
+
schemaPath,
|
|
502
|
+
context?.rootSchema ?? schema
|
|
503
|
+
);
|
|
458
504
|
let objectDepth = 0;
|
|
459
505
|
if (resolvedSchema !== undefined && resolvedSchema.items !== undefined) {
|
|
460
506
|
// check if nested arrays
|
|
461
507
|
if (
|
|
462
|
-
traverse(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (hasType(val, 'object')) {
|
|
473
|
-
objectDepth++;
|
|
474
|
-
if (objectDepth === 2) {
|
|
508
|
+
traverse(
|
|
509
|
+
resolvedSchema.items,
|
|
510
|
+
(val) => {
|
|
511
|
+
if (val === schema) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
if (val.$ref !== undefined) {
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
if (val.anyOf || val.allOf) {
|
|
475
518
|
return true;
|
|
476
519
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
520
|
+
if (val.oneOf && !isOneOfEnumControl(uischema, val, context)) {
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
if (hasType(val, 'object')) {
|
|
524
|
+
objectDepth++;
|
|
525
|
+
if (objectDepth === 2) {
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (hasType(val, 'array')) {
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
533
|
+
},
|
|
534
|
+
context?.rootSchema
|
|
535
|
+
)
|
|
483
536
|
) {
|
|
484
537
|
return true;
|
|
485
538
|
}
|
|
@@ -516,7 +569,9 @@ export const isPrimitiveArrayControl = and(
|
|
|
516
569
|
!Array.isArray(resolveSchema(schema, 'items', rootSchema)) // we don't care about tuples
|
|
517
570
|
),
|
|
518
571
|
schemaSubPathMatches('items', (schema, rootSchema) => {
|
|
519
|
-
const resolvedSchema = schema.$ref
|
|
572
|
+
const resolvedSchema = schema.$ref
|
|
573
|
+
? resolveSchema(rootSchema, schema.$ref, rootSchema)
|
|
574
|
+
: schema;
|
|
520
575
|
const types = deriveTypes(resolvedSchema);
|
|
521
576
|
return (
|
|
522
577
|
types.length === 1 &&
|
|
@@ -535,7 +590,7 @@ export const isRangeControl = and(
|
|
|
535
590
|
uiTypeIs('Control'),
|
|
536
591
|
or(schemaTypeIs('number'), schemaTypeIs('integer')),
|
|
537
592
|
schemaMatches(
|
|
538
|
-
schema =>
|
|
593
|
+
(schema) =>
|
|
539
594
|
schema.hasOwnProperty('maximum') &&
|
|
540
595
|
schema.hasOwnProperty('minimum') &&
|
|
541
596
|
schema.hasOwnProperty('default')
|
|
@@ -567,7 +622,7 @@ export const hasCategory = (categorization: Categorization): boolean => {
|
|
|
567
622
|
}
|
|
568
623
|
// all children of the categorization have to be categories
|
|
569
624
|
return categorization.elements
|
|
570
|
-
.map(elem =>
|
|
625
|
+
.map((elem) =>
|
|
571
626
|
isCategorization(elem) ? hasCategory(elem) : isCategory(elem)
|
|
572
627
|
)
|
|
573
628
|
.reduce((prev, curr) => prev && curr, true);
|
|
@@ -576,9 +631,7 @@ export const hasCategory = (categorization: Categorization): boolean => {
|
|
|
576
631
|
export const categorizationHasCategory = (uischema: UISchemaElement) =>
|
|
577
632
|
hasCategory(uischema as Categorization);
|
|
578
633
|
|
|
579
|
-
export const not =
|
|
580
|
-
|
|
581
|
-
schema: JsonSchema,
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
) => !tester(uischema, schema, context);
|
|
634
|
+
export const not =
|
|
635
|
+
(tester: Tester): Tester =>
|
|
636
|
+
(uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) =>
|
|
637
|
+
!tester(uischema, schema, context);
|