@jsonforms/core 3.0.0-alpha.3 → 3.0.0-beta.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/docs/assets/js/search.json +1 -1
- package/docs/globals.html +207 -165
- package/docs/index.html +7 -4
- package/docs/interfaces/arraycontrolprops.html +21 -21
- package/docs/interfaces/arraylayoutprops.html +21 -21
- package/docs/interfaces/cellprops.html +12 -12
- package/docs/interfaces/combinatorrendererprops.html +143 -36
- 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/jsonformsprops.html +9 -9
- package/docs/interfaces/layoutprops.html +10 -10
- package/docs/interfaces/ownpropsofcell.html +9 -9
- package/docs/interfaces/ownpropsofcontrol.html +9 -12
- package/docs/interfaces/ownpropsofenum.html +1 -1
- package/docs/interfaces/ownpropsofenumcell.html +10 -10
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
- package/docs/interfaces/ownpropsoflayout.html +9 -9
- package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
- package/docs/interfaces/ownpropsofrenderer.html +8 -8
- package/docs/interfaces/rendererprops.html +9 -9
- 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 +147 -40
- package/docs/interfaces/statepropsofcontrol.html +18 -15
- package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
- package/docs/interfaces/statepropsofenumcell.html +12 -12
- package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
- package/docs/interfaces/statepropsoflayout.html +10 -10
- package/docs/interfaces/statepropsofmasteritem.html +7 -7
- package/docs/interfaces/statepropsofrenderer.html +9 -9
- package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
- package/docs/interfaces/withclassname.html +1 -1
- package/lib/Helpers.d.ts +5 -5
- package/lib/actions/actions.d.ts +181 -181
- package/lib/actions/index.d.ts +1 -1
- package/lib/configDefault.d.ts +6 -6
- package/lib/generators/Generate.d.ts +6 -6
- package/lib/generators/index.d.ts +3 -3
- package/lib/generators/schema.d.ts +8 -8
- package/lib/generators/uischema.d.ts +12 -12
- package/lib/i18n/i18nTypes.d.ts +15 -15
- package/lib/i18n/i18nUtil.d.ts +18 -18
- package/lib/i18n/index.d.ts +2 -2
- package/lib/index.d.ts +11 -11
- package/lib/jsonforms-core.cjs.js +2441 -0
- package/lib/jsonforms-core.cjs.js.map +1 -0
- package/lib/jsonforms-core.esm.js +2152 -0
- package/lib/jsonforms-core.esm.js.map +1 -0
- package/lib/models/draft4.d.ts +198 -198
- package/lib/models/index.d.ts +5 -5
- package/lib/models/jsonSchema.d.ts +3 -3
- package/lib/models/jsonSchema4.d.ts +110 -110
- package/lib/models/jsonSchema7.d.ts +119 -119
- package/lib/models/uischema.d.ts +201 -201
- package/lib/reducers/cells.d.ts +11 -11
- package/lib/reducers/config.d.ts +3 -3
- package/lib/reducers/core.d.ts +24 -24
- package/lib/reducers/default-data.d.ts +10 -10
- package/lib/reducers/i18n.d.ts +8 -8
- package/lib/reducers/index.d.ts +9 -9
- package/lib/reducers/reducers.d.ts +29 -29
- package/lib/reducers/renderers.d.ts +10 -10
- package/lib/reducers/selectors.d.ts +15 -15
- package/lib/reducers/uischemas.d.ts +10 -10
- package/lib/store.d.ts +53 -53
- package/lib/testers/index.d.ts +1 -1
- package/lib/testers/testers.d.ts +204 -203
- package/lib/util/Formatted.d.ts +19 -19
- package/lib/util/array.d.ts +3 -3
- package/lib/util/cell.d.ts +79 -79
- package/lib/util/combinators.d.ts +9 -10
- package/lib/util/ids.d.ts +3 -3
- package/lib/util/index.d.ts +15 -15
- package/lib/util/label.d.ts +9 -9
- package/lib/util/path.d.ts +35 -25
- package/lib/util/renderer.d.ts +398 -397
- package/lib/util/resolvers.d.ts +25 -25
- package/lib/util/runtime.d.ts +18 -18
- package/lib/util/schema.d.ts +1 -1
- package/lib/util/type.d.ts +174 -174
- package/lib/util/uischema.d.ts +5 -5
- package/lib/util/util.d.ts +31 -31
- package/lib/util/validator.d.ts +3 -3
- package/package.json +16 -13
- package/rollup.config.js +44 -0
- package/src/generators/uischema.ts +4 -4
- package/src/reducers/reducers.ts +14 -6
- package/src/testers/testers.ts +60 -33
- package/src/util/cell.ts +4 -4
- package/src/util/combinators.ts +17 -32
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +18 -6
- package/src/util/renderer.ts +22 -36
- package/src/util/resolvers.ts +57 -68
- package/src/util/util.ts +1 -1
- package/stats.html +3279 -0
- package/test/generators/uischema.test.ts +18 -0
- package/test/testers.test.ts +208 -120
- package/test/util/path.test.ts +37 -20
- package/test/util/resolvers.test.ts +99 -8
- package/lib/Helpers.js +0 -33
- package/lib/Helpers.js.map +0 -1
- package/lib/actions/actions.js +0 -173
- package/lib/actions/actions.js.map +0 -1
- package/lib/actions/index.js +0 -29
- package/lib/actions/index.js.map +0 -1
- package/lib/configDefault.js +0 -48
- package/lib/configDefault.js.map +0 -1
- package/lib/generators/Generate.js +0 -35
- package/lib/generators/Generate.js.map +0 -1
- package/lib/generators/index.js +0 -31
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/schema.js +0 -154
- package/lib/generators/schema.js.map +0 -1
- package/lib/generators/uischema.js +0 -169
- package/lib/generators/uischema.js.map +0 -1
- package/lib/i18n/i18nTypes.js +0 -3
- package/lib/i18n/i18nTypes.js.map +0 -1
- package/lib/i18n/i18nUtil.js +0 -71
- package/lib/i18n/i18nUtil.js.map +0 -1
- package/lib/i18n/index.js +0 -6
- package/lib/i18n/index.js.map +0 -1
- package/lib/index.js +0 -40
- package/lib/index.js.map +0 -1
- package/lib/jsonforms-core.js +0 -25
- package/lib/jsonforms-core.js.map +0 -1
- package/lib/models/draft4.js +0 -174
- package/lib/models/draft4.js.map +0 -1
- package/lib/models/index.js +0 -33
- package/lib/models/index.js.map +0 -1
- package/lib/models/jsonSchema.js +0 -27
- package/lib/models/jsonSchema.js.map +0 -1
- package/lib/models/jsonSchema4.js +0 -30
- package/lib/models/jsonSchema4.js.map +0 -1
- package/lib/models/jsonSchema7.js +0 -30
- package/lib/models/jsonSchema7.js.map +0 -1
- package/lib/models/uischema.js +0 -58
- package/lib/models/uischema.js.map +0 -1
- package/lib/reducers/cells.js +0 -42
- package/lib/reducers/cells.js.map +0 -1
- package/lib/reducers/config.js +0 -46
- package/lib/reducers/config.js.map +0 -1
- package/lib/reducers/core.js +0 -294
- package/lib/reducers/core.js.map +0 -1
- package/lib/reducers/default-data.js +0 -45
- package/lib/reducers/default-data.js.map +0 -1
- package/lib/reducers/i18n.js +0 -83
- package/lib/reducers/i18n.js.map +0 -1
- package/lib/reducers/index.js +0 -37
- package/lib/reducers/index.js.map +0 -1
- package/lib/reducers/reducers.js +0 -98
- package/lib/reducers/reducers.js.map +0 -1
- package/lib/reducers/renderers.js +0 -43
- package/lib/reducers/renderers.js.map +0 -1
- package/lib/reducers/selectors.js +0 -56
- package/lib/reducers/selectors.js.map +0 -1
- package/lib/reducers/uischemas.js +0 -60
- package/lib/reducers/uischemas.js.map +0 -1
- package/lib/store.js +0 -27
- package/lib/store.js.map +0 -1
- package/lib/testers/index.js +0 -29
- package/lib/testers/index.js.map +0 -1
- package/lib/testers/testers.js +0 -421
- package/lib/testers/testers.js.map +0 -1
- package/lib/util/Formatted.js +0 -27
- package/lib/util/Formatted.js.map +0 -1
- package/lib/util/array.js +0 -44
- package/lib/util/array.js.map +0 -1
- package/lib/util/cell.js +0 -148
- package/lib/util/cell.js.map +0 -1
- package/lib/util/combinators.js +0 -59
- package/lib/util/combinators.js.map +0 -1
- package/lib/util/ids.js +0 -54
- package/lib/util/ids.js.map +0 -1
- package/lib/util/index.js +0 -43
- package/lib/util/index.js.map +0 -1
- package/lib/util/label.js +0 -73
- package/lib/util/label.js.map +0 -1
- package/lib/util/path.js +0 -90
- package/lib/util/path.js.map +0 -1
- package/lib/util/renderer.js +0 -530
- package/lib/util/renderer.js.map +0 -1
- package/lib/util/resolvers.js +0 -169
- package/lib/util/resolvers.js.map +0 -1
- package/lib/util/runtime.js +0 -167
- package/lib/util/runtime.js.map +0 -1
- package/lib/util/schema.js +0 -42
- package/lib/util/schema.js.map +0 -1
- package/lib/util/type.js +0 -27
- package/lib/util/type.js.map +0 -1
- package/lib/util/uischema.js +0 -56
- package/lib/util/uischema.js.map +0 -1
- package/lib/util/util.js +0 -112
- package/lib/util/util.js.map +0 -1
- package/lib/util/validator.js +0 -37
- package/lib/util/validator.js.map +0 -1
- package/webpack.build.js +0 -13
|
@@ -0,0 +1,2152 @@
|
|
|
1
|
+
import isEmpty from 'lodash/isEmpty';
|
|
2
|
+
import startCase from 'lodash/startCase';
|
|
3
|
+
import keys from 'lodash/keys';
|
|
4
|
+
import union from 'lodash/union';
|
|
5
|
+
import merge from 'lodash/merge';
|
|
6
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
7
|
+
import setFp from 'lodash/fp/set';
|
|
8
|
+
import get from 'lodash/get';
|
|
9
|
+
import filter from 'lodash/filter';
|
|
10
|
+
import isEqual from 'lodash/isEqual';
|
|
11
|
+
import isFunction from 'lodash/isFunction';
|
|
12
|
+
import maxBy from 'lodash/maxBy';
|
|
13
|
+
import remove from 'lodash/remove';
|
|
14
|
+
import endsWith from 'lodash/endsWith';
|
|
15
|
+
import last from 'lodash/last';
|
|
16
|
+
import isArray from 'lodash/isArray';
|
|
17
|
+
import reduce from 'lodash/reduce';
|
|
18
|
+
import toPairs from 'lodash/toPairs';
|
|
19
|
+
import includes from 'lodash/includes';
|
|
20
|
+
import find from 'lodash/find';
|
|
21
|
+
import range from 'lodash/range';
|
|
22
|
+
import has from 'lodash/has';
|
|
23
|
+
import Ajv from 'ajv';
|
|
24
|
+
import addFormats from 'ajv-formats';
|
|
25
|
+
|
|
26
|
+
const ADDITIONAL_PROPERTIES = 'additionalProperties';
|
|
27
|
+
const REQUIRED_PROPERTIES = 'required';
|
|
28
|
+
const distinct = (properties, discriminator) => {
|
|
29
|
+
const known = {};
|
|
30
|
+
return properties.filter(item => {
|
|
31
|
+
const discriminatorValue = discriminator(item);
|
|
32
|
+
if (known.hasOwnProperty(discriminatorValue)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
known[discriminatorValue] = true;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
class Gen {
|
|
42
|
+
constructor(findOption) {
|
|
43
|
+
this.findOption = findOption;
|
|
44
|
+
this.schemaObject = (data) => {
|
|
45
|
+
const props = this.properties(data);
|
|
46
|
+
const schema = {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: props,
|
|
49
|
+
additionalProperties: this.findOption(props)(ADDITIONAL_PROPERTIES)
|
|
50
|
+
};
|
|
51
|
+
const required = this.findOption(props)(REQUIRED_PROPERTIES);
|
|
52
|
+
if (required.length > 0) {
|
|
53
|
+
schema.required = required;
|
|
54
|
+
}
|
|
55
|
+
return schema;
|
|
56
|
+
};
|
|
57
|
+
this.properties = (data) => {
|
|
58
|
+
const emptyProps = {};
|
|
59
|
+
return Object.keys(data).reduce((acc, propName) => {
|
|
60
|
+
acc[propName] = this.property(data[propName]);
|
|
61
|
+
return acc;
|
|
62
|
+
}, emptyProps);
|
|
63
|
+
};
|
|
64
|
+
this.property = (data) => {
|
|
65
|
+
switch (typeof data) {
|
|
66
|
+
case 'string':
|
|
67
|
+
return { type: 'string' };
|
|
68
|
+
case 'boolean':
|
|
69
|
+
return { type: 'boolean' };
|
|
70
|
+
case 'number':
|
|
71
|
+
if (Number.isInteger(data)) {
|
|
72
|
+
return { type: 'integer' };
|
|
73
|
+
}
|
|
74
|
+
return { type: 'number' };
|
|
75
|
+
case 'object':
|
|
76
|
+
if (data == null) {
|
|
77
|
+
return { type: 'null' };
|
|
78
|
+
}
|
|
79
|
+
return this.schemaObjectOrArray(data);
|
|
80
|
+
default:
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.schemaObjectOrArray = (data) => {
|
|
85
|
+
if (data instanceof Array) {
|
|
86
|
+
return this.schemaArray(data);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return this.schemaObject(data);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
this.schemaArray = (data) => {
|
|
93
|
+
if (data.length > 0) {
|
|
94
|
+
const allProperties = data.map(this.property);
|
|
95
|
+
const uniqueProperties = distinct(allProperties, prop => JSON.stringify(prop));
|
|
96
|
+
if (uniqueProperties.length === 1) {
|
|
97
|
+
return {
|
|
98
|
+
type: 'array',
|
|
99
|
+
items: uniqueProperties[0]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return {
|
|
104
|
+
type: 'array',
|
|
105
|
+
items: {
|
|
106
|
+
oneOf: uniqueProperties
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return {
|
|
113
|
+
type: 'array',
|
|
114
|
+
items: {}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const generateJsonSchema = (instance, options = {}) => {
|
|
121
|
+
const findOption = (props) => (optionName) => {
|
|
122
|
+
switch (optionName) {
|
|
123
|
+
case ADDITIONAL_PROPERTIES:
|
|
124
|
+
if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
|
|
125
|
+
return options[ADDITIONAL_PROPERTIES];
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
case REQUIRED_PROPERTIES:
|
|
129
|
+
if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
|
|
130
|
+
return options[REQUIRED_PROPERTIES](props);
|
|
131
|
+
}
|
|
132
|
+
return Object.keys(props);
|
|
133
|
+
default:
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const gen = new Gen(findOption);
|
|
138
|
+
return gen.schemaObject(instance);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const Draft4 = {
|
|
142
|
+
id: 'http://json-schema.org/draft-04/schema#',
|
|
143
|
+
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
144
|
+
description: 'Core schema meta-schema',
|
|
145
|
+
definitions: {
|
|
146
|
+
schemaArray: {
|
|
147
|
+
type: 'array',
|
|
148
|
+
minItems: 1,
|
|
149
|
+
items: { $ref: '#' }
|
|
150
|
+
},
|
|
151
|
+
positiveInteger: {
|
|
152
|
+
type: 'integer',
|
|
153
|
+
minimum: 0
|
|
154
|
+
},
|
|
155
|
+
positiveIntegerDefault0: {
|
|
156
|
+
allOf: [{ $ref: '#/definitions/positiveInteger' }, { default: 0 }]
|
|
157
|
+
},
|
|
158
|
+
simpleTypes: {
|
|
159
|
+
enum: [
|
|
160
|
+
'array',
|
|
161
|
+
'boolean',
|
|
162
|
+
'integer',
|
|
163
|
+
'null',
|
|
164
|
+
'number',
|
|
165
|
+
'object',
|
|
166
|
+
'string'
|
|
167
|
+
]
|
|
168
|
+
},
|
|
169
|
+
stringArray: {
|
|
170
|
+
type: 'array',
|
|
171
|
+
items: { type: 'string' },
|
|
172
|
+
minItems: 1,
|
|
173
|
+
uniqueItems: true
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
type: 'object',
|
|
177
|
+
properties: {
|
|
178
|
+
id: {
|
|
179
|
+
type: 'string',
|
|
180
|
+
format: 'uri'
|
|
181
|
+
},
|
|
182
|
+
$schema: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
format: 'uri'
|
|
185
|
+
},
|
|
186
|
+
title: {
|
|
187
|
+
type: 'string'
|
|
188
|
+
},
|
|
189
|
+
description: {
|
|
190
|
+
type: 'string'
|
|
191
|
+
},
|
|
192
|
+
default: {},
|
|
193
|
+
multipleOf: {
|
|
194
|
+
type: 'number',
|
|
195
|
+
minimum: 0,
|
|
196
|
+
exclusiveMinimum: true
|
|
197
|
+
},
|
|
198
|
+
maximum: {
|
|
199
|
+
type: 'number'
|
|
200
|
+
},
|
|
201
|
+
exclusiveMaximum: {
|
|
202
|
+
type: 'boolean',
|
|
203
|
+
default: false
|
|
204
|
+
},
|
|
205
|
+
minimum: {
|
|
206
|
+
type: 'number'
|
|
207
|
+
},
|
|
208
|
+
exclusiveMinimum: {
|
|
209
|
+
type: 'boolean',
|
|
210
|
+
default: false
|
|
211
|
+
},
|
|
212
|
+
maxLength: { $ref: '#/definitions/positiveInteger' },
|
|
213
|
+
minLength: { $ref: '#/definitions/positiveIntegerDefault0' },
|
|
214
|
+
pattern: {
|
|
215
|
+
type: 'string',
|
|
216
|
+
format: 'regex'
|
|
217
|
+
},
|
|
218
|
+
additionalItems: {
|
|
219
|
+
anyOf: [{ type: 'boolean' }, { $ref: '#' }],
|
|
220
|
+
default: {}
|
|
221
|
+
},
|
|
222
|
+
items: {
|
|
223
|
+
anyOf: [{ $ref: '#' }, { $ref: '#/definitions/schemaArray' }],
|
|
224
|
+
default: {}
|
|
225
|
+
},
|
|
226
|
+
maxItems: { $ref: '#/definitions/positiveInteger' },
|
|
227
|
+
minItems: { $ref: '#/definitions/positiveIntegerDefault0' },
|
|
228
|
+
uniqueItems: {
|
|
229
|
+
type: 'boolean',
|
|
230
|
+
default: false
|
|
231
|
+
},
|
|
232
|
+
maxProperties: { $ref: '#/definitions/positiveInteger' },
|
|
233
|
+
minProperties: { $ref: '#/definitions/positiveIntegerDefault0' },
|
|
234
|
+
required: { $ref: '#/definitions/stringArray' },
|
|
235
|
+
additionalProperties: {
|
|
236
|
+
anyOf: [{ type: 'boolean' }, { $ref: '#' }],
|
|
237
|
+
default: {}
|
|
238
|
+
},
|
|
239
|
+
definitions: {
|
|
240
|
+
type: 'object',
|
|
241
|
+
additionalProperties: { $ref: '#' },
|
|
242
|
+
default: {}
|
|
243
|
+
},
|
|
244
|
+
properties: {
|
|
245
|
+
type: 'object',
|
|
246
|
+
additionalProperties: { $ref: '#' },
|
|
247
|
+
default: {}
|
|
248
|
+
},
|
|
249
|
+
patternProperties: {
|
|
250
|
+
type: 'object',
|
|
251
|
+
additionalProperties: { $ref: '#' },
|
|
252
|
+
default: {}
|
|
253
|
+
},
|
|
254
|
+
dependencies: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
additionalProperties: {
|
|
257
|
+
anyOf: [{ $ref: '#' }, { $ref: '#/definitions/stringArray' }]
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
enum: {
|
|
261
|
+
type: 'array',
|
|
262
|
+
minItems: 1,
|
|
263
|
+
uniqueItems: true
|
|
264
|
+
},
|
|
265
|
+
type: {
|
|
266
|
+
anyOf: [
|
|
267
|
+
{ $ref: '#/definitions/simpleTypes' },
|
|
268
|
+
{
|
|
269
|
+
type: 'array',
|
|
270
|
+
items: { $ref: '#/definitions/simpleTypes' },
|
|
271
|
+
minItems: 1,
|
|
272
|
+
uniqueItems: true
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
},
|
|
276
|
+
allOf: { $ref: '#/definitions/schemaArray' },
|
|
277
|
+
anyOf: { $ref: '#/definitions/schemaArray' },
|
|
278
|
+
oneOf: { $ref: '#/definitions/schemaArray' },
|
|
279
|
+
not: { $ref: '#' }
|
|
280
|
+
},
|
|
281
|
+
dependencies: {
|
|
282
|
+
exclusiveMaximum: ['maximum'],
|
|
283
|
+
exclusiveMinimum: ['minimum']
|
|
284
|
+
},
|
|
285
|
+
default: {}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
var RuleEffect;
|
|
289
|
+
(function (RuleEffect) {
|
|
290
|
+
RuleEffect["HIDE"] = "HIDE";
|
|
291
|
+
RuleEffect["SHOW"] = "SHOW";
|
|
292
|
+
RuleEffect["ENABLE"] = "ENABLE";
|
|
293
|
+
RuleEffect["DISABLE"] = "DISABLE";
|
|
294
|
+
})(RuleEffect || (RuleEffect = {}));
|
|
295
|
+
const isGroup = (layout) => layout.type === 'Group';
|
|
296
|
+
const isLayout = (uischema) => uischema.elements !== undefined;
|
|
297
|
+
|
|
298
|
+
const move = (array, index, delta) => {
|
|
299
|
+
const newIndex = index + delta;
|
|
300
|
+
if (newIndex < 0 || newIndex >= array.length) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const indexes = [index, newIndex].sort((a, b) => a - b);
|
|
304
|
+
array.splice(indexes[0], 2, array[indexes[1]], array[indexes[0]]);
|
|
305
|
+
};
|
|
306
|
+
const moveUp = (array, toMove) => {
|
|
307
|
+
move(array, toMove, -1);
|
|
308
|
+
};
|
|
309
|
+
const moveDown = (array, toMove) => {
|
|
310
|
+
move(array, toMove, 1);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const cellReducer = (state = [], { type, tester, cell }) => {
|
|
314
|
+
switch (type) {
|
|
315
|
+
case ADD_CELL:
|
|
316
|
+
return state.concat([{ tester, cell }]);
|
|
317
|
+
case REMOVE_CELL:
|
|
318
|
+
return state.filter(t => t.tester !== tester);
|
|
319
|
+
default:
|
|
320
|
+
return state;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const configDefault = {
|
|
325
|
+
restrict: false,
|
|
326
|
+
trim: false,
|
|
327
|
+
showUnfocusedDescription: false,
|
|
328
|
+
hideRequiredAsterisk: false
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const applyDefaultConfiguration = (config = {}) => merge({}, configDefault, config);
|
|
332
|
+
const configReducer = (state = applyDefaultConfiguration(), action) => {
|
|
333
|
+
switch (action.type) {
|
|
334
|
+
case SET_CONFIG:
|
|
335
|
+
return applyDefaultConfiguration(action.config);
|
|
336
|
+
default:
|
|
337
|
+
return state;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const validate = (validator, data) => {
|
|
342
|
+
if (validator === undefined) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
const valid = validator(data);
|
|
346
|
+
if (valid) {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
return validator.errors;
|
|
350
|
+
};
|
|
351
|
+
const initState = {
|
|
352
|
+
data: {},
|
|
353
|
+
schema: {},
|
|
354
|
+
uischema: undefined,
|
|
355
|
+
errors: [],
|
|
356
|
+
validator: undefined,
|
|
357
|
+
ajv: undefined,
|
|
358
|
+
validationMode: 'ValidateAndShow',
|
|
359
|
+
};
|
|
360
|
+
const reuseAjvForSchema = (ajv, schema) => {
|
|
361
|
+
if (schema.hasOwnProperty('id') || schema.hasOwnProperty('$id')) {
|
|
362
|
+
ajv.removeSchema(schema);
|
|
363
|
+
}
|
|
364
|
+
return ajv;
|
|
365
|
+
};
|
|
366
|
+
const getOrCreateAjv = (state, action) => {
|
|
367
|
+
if (action) {
|
|
368
|
+
if (hasAjvOption(action.options)) {
|
|
369
|
+
return action.options.ajv;
|
|
370
|
+
}
|
|
371
|
+
else if (action.options !== undefined) {
|
|
372
|
+
if (isFunction(action.options.compile)) {
|
|
373
|
+
return action.options;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (state.ajv) {
|
|
378
|
+
return action?.schema
|
|
379
|
+
? reuseAjvForSchema(state.ajv, action.schema)
|
|
380
|
+
: state.ajv;
|
|
381
|
+
}
|
|
382
|
+
return createAjv();
|
|
383
|
+
};
|
|
384
|
+
const hasAjvOption = (option) => {
|
|
385
|
+
if (option) {
|
|
386
|
+
return option.ajv !== undefined;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
};
|
|
390
|
+
const getValidationMode = (state, action) => {
|
|
391
|
+
if (action && hasValidationModeOption(action.options)) {
|
|
392
|
+
return action.options.validationMode;
|
|
393
|
+
}
|
|
394
|
+
return state.validationMode;
|
|
395
|
+
};
|
|
396
|
+
const hasValidationModeOption = (option) => {
|
|
397
|
+
if (option) {
|
|
398
|
+
return option.validationMode !== undefined;
|
|
399
|
+
}
|
|
400
|
+
return false;
|
|
401
|
+
};
|
|
402
|
+
const coreReducer = (state = initState, action) => {
|
|
403
|
+
switch (action.type) {
|
|
404
|
+
case INIT: {
|
|
405
|
+
const thisAjv = getOrCreateAjv(state, action);
|
|
406
|
+
const validationMode = getValidationMode(state, action);
|
|
407
|
+
const v = validationMode === 'NoValidation' ? undefined : thisAjv.compile(action.schema);
|
|
408
|
+
const e = validate(v, action.data);
|
|
409
|
+
return {
|
|
410
|
+
...state,
|
|
411
|
+
data: action.data,
|
|
412
|
+
schema: action.schema,
|
|
413
|
+
uischema: action.uischema,
|
|
414
|
+
errors: e,
|
|
415
|
+
validator: v,
|
|
416
|
+
ajv: thisAjv,
|
|
417
|
+
validationMode,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
case UPDATE_CORE: {
|
|
421
|
+
const thisAjv = getOrCreateAjv(state, action);
|
|
422
|
+
const validationMode = getValidationMode(state, action);
|
|
423
|
+
let validator = state.validator;
|
|
424
|
+
let errors = state.errors;
|
|
425
|
+
if (state.schema !== action.schema ||
|
|
426
|
+
state.validationMode !== validationMode ||
|
|
427
|
+
state.ajv !== thisAjv) {
|
|
428
|
+
validator =
|
|
429
|
+
validationMode === 'NoValidation'
|
|
430
|
+
? undefined
|
|
431
|
+
: thisAjv.compile(action.schema);
|
|
432
|
+
errors = validate(validator, action.data);
|
|
433
|
+
}
|
|
434
|
+
else if (state.data !== action.data) {
|
|
435
|
+
errors = validate(validator, action.data);
|
|
436
|
+
}
|
|
437
|
+
const stateChanged = state.data !== action.data ||
|
|
438
|
+
state.schema !== action.schema ||
|
|
439
|
+
state.uischema !== action.uischema ||
|
|
440
|
+
state.ajv !== thisAjv ||
|
|
441
|
+
state.errors !== errors ||
|
|
442
|
+
state.validator !== validator ||
|
|
443
|
+
state.validationMode !== validationMode;
|
|
444
|
+
return stateChanged
|
|
445
|
+
? {
|
|
446
|
+
...state,
|
|
447
|
+
data: action.data,
|
|
448
|
+
schema: action.schema,
|
|
449
|
+
uischema: action.uischema,
|
|
450
|
+
ajv: thisAjv,
|
|
451
|
+
errors: isEqual(errors, state.errors) ? state.errors : errors,
|
|
452
|
+
validator: validator,
|
|
453
|
+
validationMode: validationMode,
|
|
454
|
+
}
|
|
455
|
+
: state;
|
|
456
|
+
}
|
|
457
|
+
case SET_AJV: {
|
|
458
|
+
const currentAjv = action.ajv;
|
|
459
|
+
const validator = state.validationMode === 'NoValidation' ? undefined : currentAjv.compile(state.schema);
|
|
460
|
+
const errors = validate(validator, state.data);
|
|
461
|
+
return {
|
|
462
|
+
...state,
|
|
463
|
+
validator,
|
|
464
|
+
errors
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
case SET_SCHEMA: {
|
|
468
|
+
const needsNewValidator = action.schema && state.ajv && state.validationMode !== 'NoValidation';
|
|
469
|
+
const v = needsNewValidator
|
|
470
|
+
? reuseAjvForSchema(state.ajv, action.schema).compile(action.schema)
|
|
471
|
+
: state.validator;
|
|
472
|
+
const errors = validate(v, state.data);
|
|
473
|
+
return {
|
|
474
|
+
...state,
|
|
475
|
+
validator: v,
|
|
476
|
+
schema: action.schema,
|
|
477
|
+
errors
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
case SET_UISCHEMA: {
|
|
481
|
+
return {
|
|
482
|
+
...state,
|
|
483
|
+
uischema: action.uischema
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
case UPDATE_DATA: {
|
|
487
|
+
if (action.path === undefined || action.path === null) {
|
|
488
|
+
return state;
|
|
489
|
+
}
|
|
490
|
+
else if (action.path === '') {
|
|
491
|
+
const result = action.updater(cloneDeep(state.data));
|
|
492
|
+
const errors = validate(state.validator, result);
|
|
493
|
+
return {
|
|
494
|
+
...state,
|
|
495
|
+
data: result,
|
|
496
|
+
errors
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
const oldData = get(state.data, action.path);
|
|
501
|
+
const newData = action.updater(cloneDeep(oldData));
|
|
502
|
+
const newState = setFp(action.path, newData, state.data === undefined ? {} : state.data);
|
|
503
|
+
const errors = validate(state.validator, newState);
|
|
504
|
+
return {
|
|
505
|
+
...state,
|
|
506
|
+
data: newState,
|
|
507
|
+
errors
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
case UPDATE_ERRORS: {
|
|
512
|
+
return {
|
|
513
|
+
...state,
|
|
514
|
+
errors: action.errors
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
case SET_VALIDATION_MODE: {
|
|
518
|
+
if (state.validationMode === action.validationMode) {
|
|
519
|
+
return state;
|
|
520
|
+
}
|
|
521
|
+
if (action.validationMode === 'NoValidation') {
|
|
522
|
+
const errors = validate(undefined, state.data);
|
|
523
|
+
return {
|
|
524
|
+
...state,
|
|
525
|
+
errors,
|
|
526
|
+
validationMode: action.validationMode
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
if (state.validationMode === 'NoValidation') {
|
|
530
|
+
const validator = reuseAjvForSchema(state.ajv, state.schema).compile(state.schema);
|
|
531
|
+
const errors = validate(validator, state.data);
|
|
532
|
+
return {
|
|
533
|
+
...state,
|
|
534
|
+
validator,
|
|
535
|
+
errors,
|
|
536
|
+
validationMode: action.validationMode
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
return {
|
|
540
|
+
...state,
|
|
541
|
+
validationMode: action.validationMode
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
default:
|
|
545
|
+
return state;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
const extractData = (state) => get(state, 'data');
|
|
549
|
+
const extractSchema = (state) => get(state, 'schema');
|
|
550
|
+
const extractUiSchema = (state) => get(state, 'uischema');
|
|
551
|
+
const extractAjv = (state) => get(state, 'ajv');
|
|
552
|
+
const getInvalidProperty = (error) => {
|
|
553
|
+
switch (error.keyword) {
|
|
554
|
+
case 'required':
|
|
555
|
+
case 'dependencies':
|
|
556
|
+
return error.params.missingProperty;
|
|
557
|
+
case 'additionalProperties':
|
|
558
|
+
return error.params.additionalProperty;
|
|
559
|
+
default:
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
const getControlPath = (error) => {
|
|
564
|
+
const dataPath = error.dataPath;
|
|
565
|
+
if (dataPath) {
|
|
566
|
+
return dataPath.replace(/\//g, '.').substr(1);
|
|
567
|
+
}
|
|
568
|
+
var controlPath = error.instancePath;
|
|
569
|
+
controlPath = controlPath.replace(/\//g, '.');
|
|
570
|
+
const invalidProperty = getInvalidProperty(error);
|
|
571
|
+
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
|
|
572
|
+
controlPath = `${controlPath}.${invalidProperty}`;
|
|
573
|
+
}
|
|
574
|
+
controlPath = controlPath.replace(/^./, '');
|
|
575
|
+
return controlPath;
|
|
576
|
+
};
|
|
577
|
+
const errorsAt = (instancePath, schema, matchPath) => (errors) => {
|
|
578
|
+
const combinatorPaths = filter(errors, error => error.keyword === 'oneOf' || error.keyword === 'anyOf').map(error => getControlPath(error));
|
|
579
|
+
return filter(errors, error => {
|
|
580
|
+
if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
const controlPath = getControlPath(error);
|
|
584
|
+
let result = matchPath(controlPath);
|
|
585
|
+
const parentSchema = error.parentSchema;
|
|
586
|
+
if (result && !isObjectSchema$1(parentSchema)
|
|
587
|
+
&& combinatorPaths.findIndex(p => instancePath.startsWith(p)) !== -1) {
|
|
588
|
+
result = result && isEqual(parentSchema, schema);
|
|
589
|
+
}
|
|
590
|
+
return result;
|
|
591
|
+
});
|
|
592
|
+
};
|
|
593
|
+
const isObjectSchema$1 = (schema) => {
|
|
594
|
+
return schema?.type === 'object' || !!schema?.properties;
|
|
595
|
+
};
|
|
596
|
+
const filteredErrorKeywords = ['additionalProperties', 'allOf', 'anyOf', 'oneOf'];
|
|
597
|
+
const getErrorsAt = (instancePath, schema, matchPath) => (state) => errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide' ? [] : state.errors);
|
|
598
|
+
const errorAt = (instancePath, schema) => getErrorsAt(instancePath, schema, path => path === instancePath);
|
|
599
|
+
const subErrorsAt = (instancePath, schema) => getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
|
|
600
|
+
|
|
601
|
+
const defaultDataReducer = (state = [], action) => {
|
|
602
|
+
switch (action.type) {
|
|
603
|
+
case ADD_DEFAULT_DATA:
|
|
604
|
+
return state.concat([
|
|
605
|
+
{ schemaPath: action.schemaPath, data: action.data }
|
|
606
|
+
]);
|
|
607
|
+
case REMOVE_DEFAULT_DATA:
|
|
608
|
+
return state.filter(t => t.schemaPath !== action.schemaPath);
|
|
609
|
+
default:
|
|
610
|
+
return state;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
const extractDefaultData = (state) => state;
|
|
614
|
+
|
|
615
|
+
const getI18nKeyPrefixBySchema = (schema, uischema) => {
|
|
616
|
+
return uischema?.options?.i18n ?? schema?.i18n ?? undefined;
|
|
617
|
+
};
|
|
618
|
+
const transformPathToI18nPrefix = (path) => {
|
|
619
|
+
return (path
|
|
620
|
+
?.split('.')
|
|
621
|
+
.filter(segment => !/^\d+$/.test(segment))
|
|
622
|
+
.join('.') || 'root');
|
|
623
|
+
};
|
|
624
|
+
const getI18nKeyPrefix = (schema, uischema, path) => {
|
|
625
|
+
return (getI18nKeyPrefixBySchema(schema, uischema) ??
|
|
626
|
+
transformPathToI18nPrefix(path));
|
|
627
|
+
};
|
|
628
|
+
const getI18nKey = (schema, uischema, path, key) => {
|
|
629
|
+
return `${getI18nKeyPrefix(schema, uischema, path)}.${key}`;
|
|
630
|
+
};
|
|
631
|
+
const defaultTranslator = (_id, defaultMessage) => defaultMessage;
|
|
632
|
+
const defaultErrorTranslator = (error, t, uischema) => {
|
|
633
|
+
const i18nKey = getI18nKey(error.parentSchema, uischema, getControlPath(error), `error.${error.keyword}`);
|
|
634
|
+
const specializedKeywordMessage = t(i18nKey, undefined);
|
|
635
|
+
if (specializedKeywordMessage !== undefined) {
|
|
636
|
+
return specializedKeywordMessage;
|
|
637
|
+
}
|
|
638
|
+
const genericKeywordMessage = t(`error.${error.keyword}`, undefined);
|
|
639
|
+
if (genericKeywordMessage !== undefined) {
|
|
640
|
+
return genericKeywordMessage;
|
|
641
|
+
}
|
|
642
|
+
const messageCustomization = t(error.message, undefined);
|
|
643
|
+
if (messageCustomization !== undefined) {
|
|
644
|
+
return messageCustomization;
|
|
645
|
+
}
|
|
646
|
+
if (error.keyword === 'required' && error.message?.startsWith('must have required property')) {
|
|
647
|
+
return t('is a required property', 'is a required property');
|
|
648
|
+
}
|
|
649
|
+
return error.message;
|
|
650
|
+
};
|
|
651
|
+
const getCombinedErrorMessage = (errors, et, t, schema, uischema, path) => {
|
|
652
|
+
if (errors.length > 0 && t) {
|
|
653
|
+
const customErrorKey = getI18nKey(schema, uischema, path, 'error.custom');
|
|
654
|
+
const specializedErrorMessage = t(customErrorKey, undefined);
|
|
655
|
+
if (specializedErrorMessage !== undefined) {
|
|
656
|
+
return specializedErrorMessage;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return formatErrorMessage(errors.map(error => et(error, t, uischema)));
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
const defaultJsonFormsI18nState = {
|
|
663
|
+
locale: 'en',
|
|
664
|
+
translate: defaultTranslator,
|
|
665
|
+
translateError: defaultErrorTranslator
|
|
666
|
+
};
|
|
667
|
+
const i18nReducer = (state = defaultJsonFormsI18nState, action) => {
|
|
668
|
+
switch (action.type) {
|
|
669
|
+
case UPDATE_I18N: {
|
|
670
|
+
const locale = action.locale ?? defaultJsonFormsI18nState.locale;
|
|
671
|
+
const translate = action.translator ?? defaultJsonFormsI18nState.translate;
|
|
672
|
+
const translateError = action.errorTranslator ?? defaultJsonFormsI18nState.translateError;
|
|
673
|
+
if (locale !== state.locale ||
|
|
674
|
+
translate !== state.translate ||
|
|
675
|
+
translateError !== state.translateError) {
|
|
676
|
+
return {
|
|
677
|
+
...state,
|
|
678
|
+
locale,
|
|
679
|
+
translate,
|
|
680
|
+
translateError
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
return state;
|
|
684
|
+
}
|
|
685
|
+
case SET_TRANSLATOR:
|
|
686
|
+
return {
|
|
687
|
+
...state,
|
|
688
|
+
translate: action.translator ?? defaultTranslator,
|
|
689
|
+
translateError: action.errorTranslator ?? defaultErrorTranslator
|
|
690
|
+
};
|
|
691
|
+
case SET_LOCALE:
|
|
692
|
+
return {
|
|
693
|
+
...state,
|
|
694
|
+
locale: action.locale ?? navigator.languages[0]
|
|
695
|
+
};
|
|
696
|
+
default:
|
|
697
|
+
return state;
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
const fetchLocale = (state) => {
|
|
701
|
+
if (state === undefined) {
|
|
702
|
+
return undefined;
|
|
703
|
+
}
|
|
704
|
+
return state.locale;
|
|
705
|
+
};
|
|
706
|
+
const fetchTranslator = (state) => {
|
|
707
|
+
if (state === undefined) {
|
|
708
|
+
return defaultTranslator;
|
|
709
|
+
}
|
|
710
|
+
return state.translate;
|
|
711
|
+
};
|
|
712
|
+
const fetchErrorTranslator = (state) => {
|
|
713
|
+
if (state === undefined) {
|
|
714
|
+
return defaultErrorTranslator;
|
|
715
|
+
}
|
|
716
|
+
return state.translateError;
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
const rendererReducer = (state = [], action) => {
|
|
720
|
+
switch (action.type) {
|
|
721
|
+
case ADD_RENDERER:
|
|
722
|
+
return state.concat([
|
|
723
|
+
{ tester: action.tester, renderer: action.renderer }
|
|
724
|
+
]);
|
|
725
|
+
case REMOVE_RENDERER:
|
|
726
|
+
return state.filter(t => t.tester !== action.tester);
|
|
727
|
+
default:
|
|
728
|
+
return state;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
const NOT_APPLICABLE = -1;
|
|
733
|
+
const isControl = (uischema) => !isEmpty(uischema) && uischema.scope !== undefined;
|
|
734
|
+
const schemaMatches = (predicate) => (uischema, schema, rootSchema) => {
|
|
735
|
+
if (isEmpty(uischema) || !isControl(uischema)) {
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
if (isEmpty(schema)) {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
const schemaPath = uischema.scope;
|
|
742
|
+
if (isEmpty(schemaPath)) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
let currentDataSchema = schema;
|
|
746
|
+
if (hasType(schema, 'object')) {
|
|
747
|
+
currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
|
|
748
|
+
}
|
|
749
|
+
if (currentDataSchema === undefined) {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
return predicate(currentDataSchema, rootSchema);
|
|
753
|
+
};
|
|
754
|
+
const schemaSubPathMatches = (subPath, predicate) => (uischema, schema, rootSchema) => {
|
|
755
|
+
if (isEmpty(uischema) || !isControl(uischema)) {
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
const schemaPath = uischema.scope;
|
|
759
|
+
let currentDataSchema = schema;
|
|
760
|
+
if (hasType(schema, 'object')) {
|
|
761
|
+
currentDataSchema = resolveSchema(schema, schemaPath, rootSchema);
|
|
762
|
+
}
|
|
763
|
+
currentDataSchema = get(currentDataSchema, subPath);
|
|
764
|
+
if (currentDataSchema === undefined) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
return predicate(currentDataSchema, rootSchema);
|
|
768
|
+
};
|
|
769
|
+
const schemaTypeIs = (expectedType) => schemaMatches(schema => !isEmpty(schema) && hasType(schema, expectedType));
|
|
770
|
+
const formatIs = (expectedFormat) => schemaMatches(schema => !isEmpty(schema) &&
|
|
771
|
+
schema.format === expectedFormat &&
|
|
772
|
+
schema.type === 'string');
|
|
773
|
+
const uiTypeIs = (expected) => (uischema) => !isEmpty(uischema) && uischema.type === expected;
|
|
774
|
+
const optionIs = (optionName, optionValue) => (uischema) => {
|
|
775
|
+
if (isEmpty(uischema)) {
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
const options = uischema.options;
|
|
779
|
+
return !isEmpty(options) && options[optionName] === optionValue;
|
|
780
|
+
};
|
|
781
|
+
const scopeEndsWith = (expected) => (uischema) => {
|
|
782
|
+
if (isEmpty(expected) || !isControl(uischema)) {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
return endsWith(uischema.scope, expected);
|
|
786
|
+
};
|
|
787
|
+
const scopeEndIs = (expected) => (uischema) => {
|
|
788
|
+
if (isEmpty(expected) || !isControl(uischema)) {
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
const schemaPath = uischema.scope;
|
|
792
|
+
return !isEmpty(schemaPath) && last(schemaPath.split('/')) === expected;
|
|
793
|
+
};
|
|
794
|
+
const and = (...testers) => (uischema, schema, rootSchema) => testers.reduce((acc, tester) => acc && tester(uischema, schema, rootSchema), true);
|
|
795
|
+
const or = (...testers) => (uischema, schema, rootSchema) => testers.reduce((acc, tester) => acc || tester(uischema, schema, rootSchema), false);
|
|
796
|
+
const rankWith = (rank, tester) => (uischema, schema, rootSchema) => {
|
|
797
|
+
if (tester(uischema, schema, rootSchema)) {
|
|
798
|
+
return rank;
|
|
799
|
+
}
|
|
800
|
+
return NOT_APPLICABLE;
|
|
801
|
+
};
|
|
802
|
+
const withIncreasedRank = (by, rankedTester) => (uischema, schema, rootSchema) => {
|
|
803
|
+
const rank = rankedTester(uischema, schema, rootSchema);
|
|
804
|
+
if (rank === NOT_APPLICABLE) {
|
|
805
|
+
return NOT_APPLICABLE;
|
|
806
|
+
}
|
|
807
|
+
return rank + by;
|
|
808
|
+
};
|
|
809
|
+
const isBooleanControl = and(uiTypeIs('Control'), schemaTypeIs('boolean'));
|
|
810
|
+
const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));
|
|
811
|
+
const isAllOfControl = and(uiTypeIs('Control'), schemaMatches(schema => schema.hasOwnProperty('allOf')));
|
|
812
|
+
const isAnyOfControl = and(uiTypeIs('Control'), schemaMatches(schema => schema.hasOwnProperty('anyOf')));
|
|
813
|
+
const isOneOfControl = and(uiTypeIs('Control'), schemaMatches(schema => schema.hasOwnProperty('oneOf')));
|
|
814
|
+
const isEnumControl = and(uiTypeIs('Control'), or(schemaMatches(schema => schema.hasOwnProperty('enum')), schemaMatches(schema => schema.hasOwnProperty('const'))));
|
|
815
|
+
const isOneOfEnumControl = and(uiTypeIs('Control'), schemaMatches(schema => schema.hasOwnProperty('oneOf') &&
|
|
816
|
+
schema.oneOf.every(s => s.const !== undefined)));
|
|
817
|
+
const isIntegerControl = and(uiTypeIs('Control'), schemaTypeIs('integer'));
|
|
818
|
+
const isNumberControl = and(uiTypeIs('Control'), schemaTypeIs('number'));
|
|
819
|
+
const isStringControl = and(uiTypeIs('Control'), schemaTypeIs('string'));
|
|
820
|
+
const isMultiLineControl = and(uiTypeIs('Control'), optionIs('multi', true));
|
|
821
|
+
const isDateControl = and(uiTypeIs('Control'), or(formatIs('date'), optionIs('format', 'date')));
|
|
822
|
+
const isTimeControl = and(uiTypeIs('Control'), or(formatIs('time'), optionIs('format', 'time')));
|
|
823
|
+
const isDateTimeControl = and(uiTypeIs('Control'), or(formatIs('date-time'), optionIs('format', 'date-time')));
|
|
824
|
+
const isObjectArray = and(schemaMatches((schema, rootSchema) => hasType(schema, 'array') && !Array.isArray(resolveSchema(schema, 'items', rootSchema))
|
|
825
|
+
), schemaSubPathMatches('items', (schema, rootSchema) => {
|
|
826
|
+
const resolvedSchema = schema.$ref ? resolveSchema(rootSchema, schema.$ref, rootSchema) : schema;
|
|
827
|
+
return hasType(resolvedSchema, 'object');
|
|
828
|
+
}));
|
|
829
|
+
const isObjectArrayControl = and(uiTypeIs('Control'), isObjectArray);
|
|
830
|
+
const traverse = (any, pred, rootSchema) => {
|
|
831
|
+
if (isArray(any)) {
|
|
832
|
+
return reduce(any, (acc, el) => acc || traverse(el, pred, rootSchema), false);
|
|
833
|
+
}
|
|
834
|
+
if (pred(any)) {
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
if (any.$ref) {
|
|
838
|
+
const toTraverse = resolveSchema(rootSchema, any.$ref, rootSchema);
|
|
839
|
+
if (toTraverse && !toTraverse.$ref) {
|
|
840
|
+
return traverse(toTraverse, pred, rootSchema);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (any.items) {
|
|
844
|
+
return traverse(any.items, pred, rootSchema);
|
|
845
|
+
}
|
|
846
|
+
if (any.properties) {
|
|
847
|
+
return reduce(toPairs(any.properties), (acc, [_key, val]) => acc || traverse(val, pred, rootSchema), false);
|
|
848
|
+
}
|
|
849
|
+
return false;
|
|
850
|
+
};
|
|
851
|
+
const isObjectArrayWithNesting = (uischema, schema, rootSchema) => {
|
|
852
|
+
if (!uiTypeIs('Control')(uischema, schema, rootSchema)) {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
const schemaPath = uischema.scope;
|
|
856
|
+
const resolvedSchema = resolveSchema(schema, schemaPath, rootSchema ?? schema);
|
|
857
|
+
const wantedNestingByType = {
|
|
858
|
+
object: 2,
|
|
859
|
+
array: 1
|
|
860
|
+
};
|
|
861
|
+
if (resolvedSchema !== undefined && resolvedSchema.items !== undefined) {
|
|
862
|
+
if (traverse(resolvedSchema.items, val => {
|
|
863
|
+
if (val === schema) {
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
if (val.$ref !== undefined) {
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
if (typeof val.type !== 'string') {
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
const typeCount = wantedNestingByType[val.type];
|
|
873
|
+
if (typeCount === undefined) {
|
|
874
|
+
return false;
|
|
875
|
+
}
|
|
876
|
+
wantedNestingByType[val.type] = typeCount - 1;
|
|
877
|
+
return wantedNestingByType[val.type] === 0;
|
|
878
|
+
}, rootSchema)) {
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
if (uischema.options && uischema.options.detail) {
|
|
882
|
+
if (typeof uischema.options.detail === 'string') {
|
|
883
|
+
return uischema.options.detail.toUpperCase() !== 'DEFAULT';
|
|
884
|
+
}
|
|
885
|
+
else if (typeof uischema.options.detail === 'object' &&
|
|
886
|
+
uischema.options.detail.type) {
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
return false;
|
|
892
|
+
};
|
|
893
|
+
const isArrayObjectControl = isObjectArrayControl;
|
|
894
|
+
const isPrimitiveArrayControl = and(uiTypeIs('Control'), schemaMatches((schema, rootSchema) => deriveTypes(schema).length !== 0 &&
|
|
895
|
+
!Array.isArray(resolveSchema(schema, 'items', rootSchema))
|
|
896
|
+
), schemaSubPathMatches('items', (schema, rootSchema) => {
|
|
897
|
+
const resolvedSchema = schema.$ref ? resolveSchema(rootSchema, schema.$ref, rootSchema) : schema;
|
|
898
|
+
const types = deriveTypes(resolvedSchema);
|
|
899
|
+
return (types.length === 1 &&
|
|
900
|
+
includes(['integer', 'number', 'boolean', 'string'], types[0]));
|
|
901
|
+
}));
|
|
902
|
+
const isRangeControl = and(uiTypeIs('Control'), or(schemaTypeIs('number'), schemaTypeIs('integer')), schemaMatches(schema => schema.hasOwnProperty('maximum') &&
|
|
903
|
+
schema.hasOwnProperty('minimum') &&
|
|
904
|
+
schema.hasOwnProperty('default')), optionIs('slider', true));
|
|
905
|
+
const isNumberFormatControl = and(uiTypeIs('Control'), schemaTypeIs('integer'), optionIs('format', true));
|
|
906
|
+
const isCategorization = (category) => category.type === 'Categorization';
|
|
907
|
+
const isCategory = (uischema) => uischema.type === 'Category';
|
|
908
|
+
const hasCategory = (categorization) => {
|
|
909
|
+
if (isEmpty(categorization.elements)) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
return categorization.elements
|
|
913
|
+
.map(elem => isCategorization(elem) ? hasCategory(elem) : isCategory(elem))
|
|
914
|
+
.reduce((prev, curr) => prev && curr, true);
|
|
915
|
+
};
|
|
916
|
+
const categorizationHasCategory = (uischema) => hasCategory(uischema);
|
|
917
|
+
const not = (tester) => (uischema, schema, rootSchema) => !tester(uischema, schema, rootSchema);
|
|
918
|
+
|
|
919
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
920
|
+
__proto__: null,
|
|
921
|
+
NOT_APPLICABLE: NOT_APPLICABLE,
|
|
922
|
+
isControl: isControl,
|
|
923
|
+
schemaMatches: schemaMatches,
|
|
924
|
+
schemaSubPathMatches: schemaSubPathMatches,
|
|
925
|
+
schemaTypeIs: schemaTypeIs,
|
|
926
|
+
formatIs: formatIs,
|
|
927
|
+
uiTypeIs: uiTypeIs,
|
|
928
|
+
optionIs: optionIs,
|
|
929
|
+
scopeEndsWith: scopeEndsWith,
|
|
930
|
+
scopeEndIs: scopeEndIs,
|
|
931
|
+
and: and,
|
|
932
|
+
or: or,
|
|
933
|
+
rankWith: rankWith,
|
|
934
|
+
withIncreasedRank: withIncreasedRank,
|
|
935
|
+
isBooleanControl: isBooleanControl,
|
|
936
|
+
isObjectControl: isObjectControl,
|
|
937
|
+
isAllOfControl: isAllOfControl,
|
|
938
|
+
isAnyOfControl: isAnyOfControl,
|
|
939
|
+
isOneOfControl: isOneOfControl,
|
|
940
|
+
isEnumControl: isEnumControl,
|
|
941
|
+
isOneOfEnumControl: isOneOfEnumControl,
|
|
942
|
+
isIntegerControl: isIntegerControl,
|
|
943
|
+
isNumberControl: isNumberControl,
|
|
944
|
+
isStringControl: isStringControl,
|
|
945
|
+
isMultiLineControl: isMultiLineControl,
|
|
946
|
+
isDateControl: isDateControl,
|
|
947
|
+
isTimeControl: isTimeControl,
|
|
948
|
+
isDateTimeControl: isDateTimeControl,
|
|
949
|
+
isObjectArray: isObjectArray,
|
|
950
|
+
isObjectArrayControl: isObjectArrayControl,
|
|
951
|
+
isObjectArrayWithNesting: isObjectArrayWithNesting,
|
|
952
|
+
isArrayObjectControl: isArrayObjectControl,
|
|
953
|
+
isPrimitiveArrayControl: isPrimitiveArrayControl,
|
|
954
|
+
isRangeControl: isRangeControl,
|
|
955
|
+
isNumberFormatControl: isNumberFormatControl,
|
|
956
|
+
isCategorization: isCategorization,
|
|
957
|
+
isCategory: isCategory,
|
|
958
|
+
hasCategory: hasCategory,
|
|
959
|
+
categorizationHasCategory: categorizationHasCategory,
|
|
960
|
+
not: not
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
const uischemaRegistryReducer = (state = [], action) => {
|
|
964
|
+
switch (action.type) {
|
|
965
|
+
case ADD_UI_SCHEMA:
|
|
966
|
+
return state
|
|
967
|
+
.slice()
|
|
968
|
+
.concat({ tester: action.tester, uischema: action.uischema });
|
|
969
|
+
case REMOVE_UI_SCHEMA:
|
|
970
|
+
const copy = state.slice();
|
|
971
|
+
remove(copy, entry => entry.tester === action.tester);
|
|
972
|
+
return copy;
|
|
973
|
+
default:
|
|
974
|
+
return state;
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
const findMatchingUISchema = (state) => (jsonSchema, schemaPath, path) => {
|
|
978
|
+
const match = maxBy(state, entry => entry.tester(jsonSchema, schemaPath, path));
|
|
979
|
+
if (match !== undefined &&
|
|
980
|
+
match.tester(jsonSchema, schemaPath, path) !== NOT_APPLICABLE) {
|
|
981
|
+
return match.uischema;
|
|
982
|
+
}
|
|
983
|
+
return undefined;
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
const jsonFormsReducerConfig = {
|
|
987
|
+
core: coreReducer,
|
|
988
|
+
renderers: rendererReducer,
|
|
989
|
+
cells: cellReducer,
|
|
990
|
+
config: configReducer,
|
|
991
|
+
uischemas: uischemaRegistryReducer,
|
|
992
|
+
defaultData: defaultDataReducer,
|
|
993
|
+
i18n: i18nReducer,
|
|
994
|
+
};
|
|
995
|
+
const findUISchema = (uischemas, schema, schemaPath, path, fallback = 'VerticalLayout', control, rootSchema) => {
|
|
996
|
+
if (control && control.options && control.options.detail) {
|
|
997
|
+
if (typeof control.options.detail === 'string') {
|
|
998
|
+
if (control.options.detail.toUpperCase() === 'GENERATE') {
|
|
999
|
+
if (typeof fallback === "function") {
|
|
1000
|
+
return fallback();
|
|
1001
|
+
}
|
|
1002
|
+
return Generate.uiSchema(schema, fallback);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
else if (typeof control.options.detail === 'object') {
|
|
1006
|
+
if (control.options.detail.type &&
|
|
1007
|
+
typeof control.options.detail.type === 'string') {
|
|
1008
|
+
return control.options.detail;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
|
|
1013
|
+
if (uiSchema === undefined) {
|
|
1014
|
+
if (typeof fallback === 'function') {
|
|
1015
|
+
return fallback();
|
|
1016
|
+
}
|
|
1017
|
+
return Generate.uiSchema(schema, fallback, '#', rootSchema);
|
|
1018
|
+
}
|
|
1019
|
+
return uiSchema;
|
|
1020
|
+
};
|
|
1021
|
+
const getErrorAt = (instancePath, schema) => (state) => {
|
|
1022
|
+
return errorAt(instancePath, schema)(state.jsonforms.core);
|
|
1023
|
+
};
|
|
1024
|
+
const getSubErrorsAt = (instancePath, schema) => (state) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
|
|
1025
|
+
const getConfig = (state) => state.jsonforms.config;
|
|
1026
|
+
const getLocale = (state) => fetchLocale(get(state, 'jsonforms.i18n'));
|
|
1027
|
+
const getTranslator = () => (state) => fetchTranslator(get(state, 'jsonforms.i18n'));
|
|
1028
|
+
const getErrorTranslator = () => (state) => fetchErrorTranslator(get(state, 'jsonforms.i18n'));
|
|
1029
|
+
|
|
1030
|
+
const getData = (state) => extractData(get(state, 'jsonforms.core'));
|
|
1031
|
+
const getSchema = (state) => extractSchema(get(state, 'jsonforms.core'));
|
|
1032
|
+
const getUiSchema = (state) => extractUiSchema(get(state, 'jsonforms.core'));
|
|
1033
|
+
const getAjv = (state) => extractAjv(get(state, 'jsonforms.core'));
|
|
1034
|
+
const getDefaultData = (state) => extractDefaultData(get(state, 'jsonforms.defaultData'));
|
|
1035
|
+
const getRenderers = (state) => get(state, 'jsonforms.renderers');
|
|
1036
|
+
const getCells = (state) => get(state, 'jsonforms.cells');
|
|
1037
|
+
const getUISchemas = (state) => get(state, 'jsonforms.uischemas');
|
|
1038
|
+
|
|
1039
|
+
const compose = (path1, path2) => {
|
|
1040
|
+
let p1 = path1;
|
|
1041
|
+
if (!isEmpty(path1) && !isEmpty(path2) && !path2.startsWith('[')) {
|
|
1042
|
+
p1 = path1 + '.';
|
|
1043
|
+
}
|
|
1044
|
+
if (isEmpty(p1)) {
|
|
1045
|
+
return path2;
|
|
1046
|
+
}
|
|
1047
|
+
else if (isEmpty(path2)) {
|
|
1048
|
+
return p1;
|
|
1049
|
+
}
|
|
1050
|
+
else {
|
|
1051
|
+
return `${p1}${path2}`;
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
const toDataPathSegments = (schemaPath) => {
|
|
1055
|
+
const s = schemaPath
|
|
1056
|
+
.replace(/(anyOf|allOf|oneOf)\/[\d]\//g, '')
|
|
1057
|
+
.replace(/(then|else)\//g, '');
|
|
1058
|
+
const segments = s.split('/');
|
|
1059
|
+
const decodedSegments = segments.map(decode);
|
|
1060
|
+
const startFromRoot = decodedSegments[0] === '#' || decodedSegments[0] === '';
|
|
1061
|
+
const startIndex = startFromRoot ? 2 : 1;
|
|
1062
|
+
return range(startIndex, decodedSegments.length, 2).map(idx => decodedSegments[idx]);
|
|
1063
|
+
};
|
|
1064
|
+
const toDataPath = (schemaPath) => {
|
|
1065
|
+
return toDataPathSegments(schemaPath).join('.');
|
|
1066
|
+
};
|
|
1067
|
+
const composeWithUi = (scopableUi, path) => {
|
|
1068
|
+
const segments = toDataPathSegments(scopableUi.scope);
|
|
1069
|
+
if (isEmpty(segments) && path === undefined) {
|
|
1070
|
+
return '';
|
|
1071
|
+
}
|
|
1072
|
+
return isEmpty(segments) ? path : compose(path, segments.join('.'));
|
|
1073
|
+
};
|
|
1074
|
+
const encode = (segment) => segment?.replace(/~/g, '~0').replace(/\//g, '~1');
|
|
1075
|
+
const decode = (pointerSegment) => pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
|
|
1076
|
+
|
|
1077
|
+
const isObjectSchema = (schema) => {
|
|
1078
|
+
return schema.properties !== undefined;
|
|
1079
|
+
};
|
|
1080
|
+
const isArraySchema = (schema) => {
|
|
1081
|
+
return schema.type === 'array' && schema.items !== undefined;
|
|
1082
|
+
};
|
|
1083
|
+
const resolveData = (instance, dataPath) => {
|
|
1084
|
+
if (isEmpty(dataPath)) {
|
|
1085
|
+
return instance;
|
|
1086
|
+
}
|
|
1087
|
+
const dataPathSegments = dataPath.split('.');
|
|
1088
|
+
return dataPathSegments
|
|
1089
|
+
.map(segment => decodeURIComponent(segment))
|
|
1090
|
+
.reduce((curInstance, decodedSegment) => {
|
|
1091
|
+
if (!curInstance || !curInstance.hasOwnProperty(decodedSegment)) {
|
|
1092
|
+
return undefined;
|
|
1093
|
+
}
|
|
1094
|
+
return curInstance[decodedSegment];
|
|
1095
|
+
}, instance);
|
|
1096
|
+
};
|
|
1097
|
+
const findAllRefs = (schema, result = {}, resolveTuples = false) => {
|
|
1098
|
+
if (isObjectSchema(schema)) {
|
|
1099
|
+
Object.keys(schema.properties).forEach(key => findAllRefs(schema.properties[key], result));
|
|
1100
|
+
}
|
|
1101
|
+
if (isArraySchema(schema)) {
|
|
1102
|
+
if (Array.isArray(schema.items)) {
|
|
1103
|
+
if (resolveTuples) {
|
|
1104
|
+
const items = schema.items;
|
|
1105
|
+
items.forEach(child => findAllRefs(child, result));
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
findAllRefs(schema.items, result);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
if (Array.isArray(schema.anyOf)) {
|
|
1113
|
+
const anyOf = schema.anyOf;
|
|
1114
|
+
anyOf.forEach(child => findAllRefs(child, result));
|
|
1115
|
+
}
|
|
1116
|
+
if (schema.$ref !== undefined) {
|
|
1117
|
+
result[schema.$ref] = schema;
|
|
1118
|
+
}
|
|
1119
|
+
return result;
|
|
1120
|
+
};
|
|
1121
|
+
const invalidSegment = (pathSegment) => pathSegment === '#' || pathSegment === undefined || pathSegment === '';
|
|
1122
|
+
const resolveSchema = (schema, schemaPath, rootSchema) => {
|
|
1123
|
+
const segments = schemaPath?.split('/').map(decode);
|
|
1124
|
+
return resolveSchemaWithSegments(schema, segments, rootSchema);
|
|
1125
|
+
};
|
|
1126
|
+
const resolveSchemaWithSegments = (schema, pathSegments, rootSchema) => {
|
|
1127
|
+
if (isEmpty(schema)) {
|
|
1128
|
+
return undefined;
|
|
1129
|
+
}
|
|
1130
|
+
if (schema.$ref) {
|
|
1131
|
+
schema = resolveSchema(rootSchema, schema.$ref, rootSchema);
|
|
1132
|
+
}
|
|
1133
|
+
if (!pathSegments || pathSegments.length === 0) {
|
|
1134
|
+
return schema;
|
|
1135
|
+
}
|
|
1136
|
+
const [segment, ...remainingSegments] = pathSegments;
|
|
1137
|
+
if (invalidSegment(segment)) {
|
|
1138
|
+
return resolveSchemaWithSegments(schema, remainingSegments, rootSchema);
|
|
1139
|
+
}
|
|
1140
|
+
const singleSegmentResolveSchema = get(schema, segment);
|
|
1141
|
+
const resolvedSchema = resolveSchemaWithSegments(singleSegmentResolveSchema, remainingSegments, rootSchema);
|
|
1142
|
+
if (resolvedSchema) {
|
|
1143
|
+
return resolvedSchema;
|
|
1144
|
+
}
|
|
1145
|
+
if (segment === 'properties' || segment === 'items') {
|
|
1146
|
+
let alternativeResolveResult = undefined;
|
|
1147
|
+
const subSchemas = [].concat(schema.oneOf ?? [], schema.allOf ?? [], schema.anyOf ?? [], schema.then ?? [], schema.else ?? []);
|
|
1148
|
+
for (const subSchema of subSchemas) {
|
|
1149
|
+
alternativeResolveResult = resolveSchemaWithSegments(subSchema, [segment, ...remainingSegments], rootSchema);
|
|
1150
|
+
if (alternativeResolveResult) {
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return alternativeResolveResult;
|
|
1155
|
+
}
|
|
1156
|
+
return undefined;
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
const isOrCondition = (condition) => condition.type === 'OR';
|
|
1160
|
+
const isAndCondition = (condition) => condition.type === 'AND';
|
|
1161
|
+
const isLeafCondition = (condition) => condition.type === 'LEAF';
|
|
1162
|
+
const isSchemaCondition = (condition) => has(condition, 'schema');
|
|
1163
|
+
const getConditionScope = (condition, path) => {
|
|
1164
|
+
return composeWithUi(condition, path);
|
|
1165
|
+
};
|
|
1166
|
+
const evaluateCondition = (data, condition, path, ajv) => {
|
|
1167
|
+
if (isAndCondition(condition)) {
|
|
1168
|
+
return condition.conditions.reduce((acc, cur) => acc && evaluateCondition(data, cur, path, ajv), true);
|
|
1169
|
+
}
|
|
1170
|
+
else if (isOrCondition(condition)) {
|
|
1171
|
+
return condition.conditions.reduce((acc, cur) => acc || evaluateCondition(data, cur, path, ajv), false);
|
|
1172
|
+
}
|
|
1173
|
+
else if (isLeafCondition(condition)) {
|
|
1174
|
+
const value = resolveData(data, getConditionScope(condition, path));
|
|
1175
|
+
return value === condition.expectedValue;
|
|
1176
|
+
}
|
|
1177
|
+
else if (isSchemaCondition(condition)) {
|
|
1178
|
+
const value = resolveData(data, getConditionScope(condition, path));
|
|
1179
|
+
return ajv.validate(condition.schema, value);
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
const isRuleFulfilled = (uischema, data, path, ajv) => {
|
|
1186
|
+
const condition = uischema.rule.condition;
|
|
1187
|
+
return evaluateCondition(data, condition, path, ajv);
|
|
1188
|
+
};
|
|
1189
|
+
const evalVisibility = (uischema, data, path = undefined, ajv) => {
|
|
1190
|
+
const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
|
|
1191
|
+
switch (uischema.rule.effect) {
|
|
1192
|
+
case RuleEffect.HIDE:
|
|
1193
|
+
return !fulfilled;
|
|
1194
|
+
case RuleEffect.SHOW:
|
|
1195
|
+
return fulfilled;
|
|
1196
|
+
default:
|
|
1197
|
+
return true;
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
const evalEnablement = (uischema, data, path = undefined, ajv) => {
|
|
1201
|
+
const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
|
|
1202
|
+
switch (uischema.rule.effect) {
|
|
1203
|
+
case RuleEffect.DISABLE:
|
|
1204
|
+
return !fulfilled;
|
|
1205
|
+
case RuleEffect.ENABLE:
|
|
1206
|
+
return fulfilled;
|
|
1207
|
+
default:
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
const hasShowRule = (uischema) => {
|
|
1212
|
+
if (uischema.rule &&
|
|
1213
|
+
(uischema.rule.effect === RuleEffect.SHOW ||
|
|
1214
|
+
uischema.rule.effect === RuleEffect.HIDE)) {
|
|
1215
|
+
return true;
|
|
1216
|
+
}
|
|
1217
|
+
return false;
|
|
1218
|
+
};
|
|
1219
|
+
const hasEnableRule = (uischema) => {
|
|
1220
|
+
if (uischema.rule &&
|
|
1221
|
+
(uischema.rule.effect === RuleEffect.ENABLE ||
|
|
1222
|
+
uischema.rule.effect === RuleEffect.DISABLE)) {
|
|
1223
|
+
return true;
|
|
1224
|
+
}
|
|
1225
|
+
return false;
|
|
1226
|
+
};
|
|
1227
|
+
const isVisible = (uischema, data, path = undefined, ajv) => {
|
|
1228
|
+
if (uischema.rule) {
|
|
1229
|
+
return evalVisibility(uischema, data, path, ajv);
|
|
1230
|
+
}
|
|
1231
|
+
return true;
|
|
1232
|
+
};
|
|
1233
|
+
const isEnabled = (uischema, data, path = undefined, ajv) => {
|
|
1234
|
+
if (uischema.rule) {
|
|
1235
|
+
return evalEnablement(uischema, data, path, ajv);
|
|
1236
|
+
}
|
|
1237
|
+
return true;
|
|
1238
|
+
};
|
|
1239
|
+
const isInherentlyEnabled = (state, ownProps, uischema, schema, rootData, config) => {
|
|
1240
|
+
if (state?.jsonforms?.readonly) {
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
if (uischema && hasEnableRule(uischema)) {
|
|
1244
|
+
return isEnabled(uischema, rootData, ownProps?.path, getAjv(state));
|
|
1245
|
+
}
|
|
1246
|
+
if (typeof uischema?.options?.readonly === 'boolean') {
|
|
1247
|
+
return !uischema.options.readonly;
|
|
1248
|
+
}
|
|
1249
|
+
if (typeof uischema?.options?.readOnly === 'boolean') {
|
|
1250
|
+
return !uischema.options.readOnly;
|
|
1251
|
+
}
|
|
1252
|
+
if (typeof config?.readonly === 'boolean') {
|
|
1253
|
+
return !config.readonly;
|
|
1254
|
+
}
|
|
1255
|
+
if (typeof config?.readOnly === 'boolean') {
|
|
1256
|
+
return !config.readOnly;
|
|
1257
|
+
}
|
|
1258
|
+
if (schema?.readOnly === true) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
if (typeof ownProps?.enabled === 'boolean') {
|
|
1262
|
+
return ownProps.enabled;
|
|
1263
|
+
}
|
|
1264
|
+
return true;
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
const convertToValidClassName = (s) => s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
|
|
1268
|
+
const formatErrorMessage = (errors) => {
|
|
1269
|
+
if (errors === undefined || errors === null) {
|
|
1270
|
+
return '';
|
|
1271
|
+
}
|
|
1272
|
+
return errors.join('\n');
|
|
1273
|
+
};
|
|
1274
|
+
const hasType = (jsonSchema, expected) => {
|
|
1275
|
+
return includes(deriveTypes(jsonSchema), expected);
|
|
1276
|
+
};
|
|
1277
|
+
const deriveTypes = (jsonSchema) => {
|
|
1278
|
+
if (isEmpty(jsonSchema)) {
|
|
1279
|
+
return [];
|
|
1280
|
+
}
|
|
1281
|
+
if (!isEmpty(jsonSchema.type) && typeof jsonSchema.type === 'string') {
|
|
1282
|
+
return [jsonSchema.type];
|
|
1283
|
+
}
|
|
1284
|
+
if (isArray(jsonSchema.type)) {
|
|
1285
|
+
return jsonSchema.type;
|
|
1286
|
+
}
|
|
1287
|
+
if (!isEmpty(jsonSchema.properties) ||
|
|
1288
|
+
!isEmpty(jsonSchema.additionalProperties)) {
|
|
1289
|
+
return ['object'];
|
|
1290
|
+
}
|
|
1291
|
+
if (!isEmpty(jsonSchema.items)) {
|
|
1292
|
+
return ['array'];
|
|
1293
|
+
}
|
|
1294
|
+
if (!isEmpty(jsonSchema.allOf)) {
|
|
1295
|
+
const allOfType = find(jsonSchema.allOf, (schema) => deriveTypes(schema).length !== 0);
|
|
1296
|
+
if (allOfType) {
|
|
1297
|
+
return deriveTypes(allOfType);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return [];
|
|
1301
|
+
};
|
|
1302
|
+
const Resolve = {
|
|
1303
|
+
schema: resolveSchema,
|
|
1304
|
+
data: resolveData
|
|
1305
|
+
};
|
|
1306
|
+
const fromScopable = (scopable) => toDataPathSegments(scopable.scope).join('.');
|
|
1307
|
+
const Paths = {
|
|
1308
|
+
compose: compose,
|
|
1309
|
+
fromScopable
|
|
1310
|
+
};
|
|
1311
|
+
const Runtime = {
|
|
1312
|
+
isEnabled(uischema, data, ajv) {
|
|
1313
|
+
return isEnabled(uischema, data, undefined, ajv);
|
|
1314
|
+
},
|
|
1315
|
+
isVisible(uischema, data, ajv) {
|
|
1316
|
+
return isVisible(uischema, data, undefined, ajv);
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
const deriveLabel = (controlElement, schemaElement) => {
|
|
1321
|
+
if (schemaElement && typeof schemaElement.title === 'string') {
|
|
1322
|
+
return schemaElement.title;
|
|
1323
|
+
}
|
|
1324
|
+
if (typeof controlElement.scope === 'string') {
|
|
1325
|
+
const ref = controlElement.scope;
|
|
1326
|
+
const label = decode(ref.substr(ref.lastIndexOf('/') + 1));
|
|
1327
|
+
return startCase(label);
|
|
1328
|
+
}
|
|
1329
|
+
return '';
|
|
1330
|
+
};
|
|
1331
|
+
const createCleanLabel = (label) => {
|
|
1332
|
+
return startCase(label.replace('_', ' '));
|
|
1333
|
+
};
|
|
1334
|
+
const createLabelDescriptionFrom = (withLabel, schema) => {
|
|
1335
|
+
const labelProperty = withLabel.label;
|
|
1336
|
+
if (typeof labelProperty === 'boolean') {
|
|
1337
|
+
return labelDescription(deriveLabel(withLabel, schema), labelProperty);
|
|
1338
|
+
}
|
|
1339
|
+
if (typeof labelProperty === 'string') {
|
|
1340
|
+
return labelDescription(labelProperty, true);
|
|
1341
|
+
}
|
|
1342
|
+
if (typeof labelProperty === 'object') {
|
|
1343
|
+
const label = typeof labelProperty.text === 'string'
|
|
1344
|
+
? labelProperty.text
|
|
1345
|
+
: deriveLabel(withLabel, schema);
|
|
1346
|
+
const show = typeof labelProperty.show === 'boolean' ? labelProperty.show : true;
|
|
1347
|
+
return labelDescription(label, show);
|
|
1348
|
+
}
|
|
1349
|
+
return labelDescription(deriveLabel(withLabel, schema), true);
|
|
1350
|
+
};
|
|
1351
|
+
const labelDescription = (text, show) => ({
|
|
1352
|
+
text: text,
|
|
1353
|
+
show: show
|
|
1354
|
+
});
|
|
1355
|
+
|
|
1356
|
+
const isRequired = (schema, schemaPath, rootSchema) => {
|
|
1357
|
+
const pathSegments = schemaPath.split('/');
|
|
1358
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
1359
|
+
const nextHigherSchemaSegments = pathSegments.slice(0, pathSegments.length - 2);
|
|
1360
|
+
const nextHigherSchemaPath = nextHigherSchemaSegments.join('/');
|
|
1361
|
+
const nextHigherSchema = Resolve.schema(schema, nextHigherSchemaPath, rootSchema);
|
|
1362
|
+
return (nextHigherSchema !== undefined &&
|
|
1363
|
+
nextHigherSchema.required !== undefined &&
|
|
1364
|
+
nextHigherSchema.required.indexOf(lastSegment) !== -1);
|
|
1365
|
+
};
|
|
1366
|
+
const computeLabel = (label, required, hideRequiredAsterisk) => {
|
|
1367
|
+
return `${label ?? ''}${required && !hideRequiredAsterisk ? '*' : ''}`;
|
|
1368
|
+
};
|
|
1369
|
+
const showAsRequired = (required, hideRequiredAsterisk) => {
|
|
1370
|
+
return required && !hideRequiredAsterisk;
|
|
1371
|
+
};
|
|
1372
|
+
const createDefaultValue = (schema) => {
|
|
1373
|
+
switch (schema.type) {
|
|
1374
|
+
case 'string':
|
|
1375
|
+
if (schema.format === 'date-time' ||
|
|
1376
|
+
schema.format === 'date' ||
|
|
1377
|
+
schema.format === 'time') {
|
|
1378
|
+
return new Date();
|
|
1379
|
+
}
|
|
1380
|
+
return '';
|
|
1381
|
+
case 'integer':
|
|
1382
|
+
case 'number':
|
|
1383
|
+
return 0;
|
|
1384
|
+
case 'boolean':
|
|
1385
|
+
return false;
|
|
1386
|
+
case 'array':
|
|
1387
|
+
return [];
|
|
1388
|
+
case 'null':
|
|
1389
|
+
return null;
|
|
1390
|
+
default:
|
|
1391
|
+
return {};
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
const isDescriptionHidden = (visible, description, isFocused, showUnfocusedDescription) => {
|
|
1395
|
+
return (description === undefined ||
|
|
1396
|
+
(description !== undefined && !visible) ||
|
|
1397
|
+
(!showUnfocusedDescription && !isFocused));
|
|
1398
|
+
};
|
|
1399
|
+
const enumToEnumOptionMapper = (e, t, i18nKey) => {
|
|
1400
|
+
let label = typeof e === 'string' ? e : JSON.stringify(e);
|
|
1401
|
+
if (t) {
|
|
1402
|
+
if (i18nKey) {
|
|
1403
|
+
label = t(`${i18nKey}.${label}`, label);
|
|
1404
|
+
}
|
|
1405
|
+
else {
|
|
1406
|
+
label = t(label, label);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
return { label, value: e };
|
|
1410
|
+
};
|
|
1411
|
+
const oneOfToEnumOptionMapper = (e, t, fallbackI18nKey) => {
|
|
1412
|
+
let label = e.title ??
|
|
1413
|
+
(typeof e.const === 'string' ? e.const : JSON.stringify(e.const));
|
|
1414
|
+
if (t) {
|
|
1415
|
+
if (e.i18n) {
|
|
1416
|
+
label = t(e.i18n, label);
|
|
1417
|
+
}
|
|
1418
|
+
else if (fallbackI18nKey) {
|
|
1419
|
+
label = t(`${fallbackI18nKey}.${label}`, label);
|
|
1420
|
+
}
|
|
1421
|
+
else {
|
|
1422
|
+
label = t(label, label);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return {
|
|
1426
|
+
label,
|
|
1427
|
+
value: e.const,
|
|
1428
|
+
};
|
|
1429
|
+
};
|
|
1430
|
+
const mapStateToControlProps = (state, ownProps) => {
|
|
1431
|
+
const { uischema } = ownProps;
|
|
1432
|
+
const rootData = getData(state);
|
|
1433
|
+
const path = composeWithUi(uischema, ownProps.path);
|
|
1434
|
+
const visible = ownProps.visible === undefined || hasShowRule(uischema)
|
|
1435
|
+
? isVisible(uischema, rootData, ownProps.path, getAjv(state))
|
|
1436
|
+
: ownProps.visible;
|
|
1437
|
+
const controlElement = uischema;
|
|
1438
|
+
const id = ownProps.id;
|
|
1439
|
+
const rootSchema = getSchema(state);
|
|
1440
|
+
const required = controlElement.scope !== undefined &&
|
|
1441
|
+
isRequired(ownProps.schema, controlElement.scope, rootSchema);
|
|
1442
|
+
const resolvedSchema = Resolve.schema(ownProps.schema || rootSchema, controlElement.scope, rootSchema);
|
|
1443
|
+
const errors = getErrorAt(path, resolvedSchema)(state);
|
|
1444
|
+
const description = resolvedSchema !== undefined ? resolvedSchema.description : '';
|
|
1445
|
+
const data = Resolve.data(rootData, path);
|
|
1446
|
+
const labelDesc = createLabelDescriptionFrom(uischema, resolvedSchema);
|
|
1447
|
+
const label = labelDesc.show ? labelDesc.text : '';
|
|
1448
|
+
const config = getConfig(state);
|
|
1449
|
+
const enabled = isInherentlyEnabled(state, ownProps, uischema, resolvedSchema || rootSchema, rootData, config);
|
|
1450
|
+
const schema = resolvedSchema ?? rootSchema;
|
|
1451
|
+
const t = getTranslator()(state);
|
|
1452
|
+
const te = getErrorTranslator()(state);
|
|
1453
|
+
const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
|
|
1454
|
+
const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description);
|
|
1455
|
+
const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
|
|
1456
|
+
return {
|
|
1457
|
+
data,
|
|
1458
|
+
description: i18nDescription,
|
|
1459
|
+
errors: i18nErrorMessage,
|
|
1460
|
+
label: i18nLabel,
|
|
1461
|
+
visible,
|
|
1462
|
+
enabled,
|
|
1463
|
+
id,
|
|
1464
|
+
path,
|
|
1465
|
+
required,
|
|
1466
|
+
uischema,
|
|
1467
|
+
schema,
|
|
1468
|
+
config: getConfig(state),
|
|
1469
|
+
cells: ownProps.cells || state.jsonforms.cells,
|
|
1470
|
+
rootSchema
|
|
1471
|
+
};
|
|
1472
|
+
};
|
|
1473
|
+
const mapDispatchToControlProps = (dispatch) => ({
|
|
1474
|
+
handleChange(path, value) {
|
|
1475
|
+
dispatch(update(path, () => value));
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
const mapStateToEnumControlProps = (state, ownProps) => {
|
|
1479
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1480
|
+
const options = ownProps.options ||
|
|
1481
|
+
props.schema.enum?.map(e => enumToEnumOptionMapper(e, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path))) ||
|
|
1482
|
+
(props.schema.const && [
|
|
1483
|
+
enumToEnumOptionMapper(props.schema.const, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path))
|
|
1484
|
+
]);
|
|
1485
|
+
return {
|
|
1486
|
+
...props,
|
|
1487
|
+
options
|
|
1488
|
+
};
|
|
1489
|
+
};
|
|
1490
|
+
const mapStateToOneOfEnumControlProps = (state, ownProps) => {
|
|
1491
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1492
|
+
const options = ownProps.options ||
|
|
1493
|
+
props.schema.oneOf?.map(oneOfSubSchema => oneOfToEnumOptionMapper(oneOfSubSchema, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path)));
|
|
1494
|
+
return {
|
|
1495
|
+
...props,
|
|
1496
|
+
options
|
|
1497
|
+
};
|
|
1498
|
+
};
|
|
1499
|
+
const mapStateToMultiEnumControlProps = (state, ownProps) => {
|
|
1500
|
+
const props = mapStateToControlProps(state, ownProps);
|
|
1501
|
+
const items = props.schema.items;
|
|
1502
|
+
const options = ownProps.options ||
|
|
1503
|
+
(items?.oneOf &&
|
|
1504
|
+
items.oneOf.map(oneOfSubSchema => oneOfToEnumOptionMapper(oneOfSubSchema, state.jsonforms.i18n?.translate, getI18nKeyPrefix(props.schema, props.uischema, props.path)))) ||
|
|
1505
|
+
items?.enum?.map(e => enumToEnumOptionMapper(e, state.jsonforms.i18n?.translate, getI18nKeyPrefix(props.schema, props.uischema, props.path)));
|
|
1506
|
+
return {
|
|
1507
|
+
...props,
|
|
1508
|
+
options
|
|
1509
|
+
};
|
|
1510
|
+
};
|
|
1511
|
+
const mapStateToMasterListItemProps = (state, ownProps) => {
|
|
1512
|
+
const { schema, path, index } = ownProps;
|
|
1513
|
+
const firstPrimitiveProp = schema.properties
|
|
1514
|
+
? find(Object.keys(schema.properties), propName => {
|
|
1515
|
+
const prop = schema.properties[propName];
|
|
1516
|
+
return (prop.type === 'string' ||
|
|
1517
|
+
prop.type === 'number' ||
|
|
1518
|
+
prop.type === 'integer');
|
|
1519
|
+
})
|
|
1520
|
+
: undefined;
|
|
1521
|
+
const childPath = compose(path, `${index}`);
|
|
1522
|
+
const childData = Resolve.data(getData(state), childPath);
|
|
1523
|
+
const childLabel = firstPrimitiveProp ? childData[firstPrimitiveProp] : '';
|
|
1524
|
+
return {
|
|
1525
|
+
...ownProps,
|
|
1526
|
+
childLabel
|
|
1527
|
+
};
|
|
1528
|
+
};
|
|
1529
|
+
const mapStateToControlWithDetailProps = (state, ownProps) => {
|
|
1530
|
+
const { ...props } = mapStateToControlProps(state, ownProps);
|
|
1531
|
+
return {
|
|
1532
|
+
...props,
|
|
1533
|
+
uischemas: state.jsonforms.uischemas
|
|
1534
|
+
};
|
|
1535
|
+
};
|
|
1536
|
+
const mapStateToArrayControlProps = (state, ownProps) => {
|
|
1537
|
+
const { path, schema, uischema, ...props } = mapStateToControlWithDetailProps(state, ownProps);
|
|
1538
|
+
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
|
|
1539
|
+
const childErrors = getSubErrorsAt(path, resolvedSchema)(state);
|
|
1540
|
+
return {
|
|
1541
|
+
...props,
|
|
1542
|
+
path,
|
|
1543
|
+
uischema,
|
|
1544
|
+
schema: resolvedSchema,
|
|
1545
|
+
childErrors,
|
|
1546
|
+
renderers: ownProps.renderers || getRenderers(state),
|
|
1547
|
+
cells: ownProps.cells || getCells(state)
|
|
1548
|
+
};
|
|
1549
|
+
};
|
|
1550
|
+
const mapDispatchToArrayControlProps = (dispatch) => ({
|
|
1551
|
+
addItem: (path, value) => () => {
|
|
1552
|
+
dispatch(update(path, array => {
|
|
1553
|
+
if (array === undefined || array === null) {
|
|
1554
|
+
return [value];
|
|
1555
|
+
}
|
|
1556
|
+
array.push(value);
|
|
1557
|
+
return array;
|
|
1558
|
+
}));
|
|
1559
|
+
},
|
|
1560
|
+
removeItems: (path, toDelete) => () => {
|
|
1561
|
+
dispatch(update(path, array => {
|
|
1562
|
+
toDelete
|
|
1563
|
+
.sort()
|
|
1564
|
+
.reverse()
|
|
1565
|
+
.forEach(s => array.splice(s, 1));
|
|
1566
|
+
return array;
|
|
1567
|
+
}));
|
|
1568
|
+
},
|
|
1569
|
+
moveUp: (path, toMove) => () => {
|
|
1570
|
+
dispatch(update(path, array => {
|
|
1571
|
+
moveUp(array, toMove);
|
|
1572
|
+
return array;
|
|
1573
|
+
}));
|
|
1574
|
+
},
|
|
1575
|
+
moveDown: (path, toMove) => () => {
|
|
1576
|
+
dispatch(update(path, array => {
|
|
1577
|
+
moveDown(array, toMove);
|
|
1578
|
+
return array;
|
|
1579
|
+
}));
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
const mapDispatchToMultiEnumProps = (dispatch) => ({
|
|
1583
|
+
addItem: (path, value) => {
|
|
1584
|
+
dispatch(update(path, data => {
|
|
1585
|
+
if (data === undefined || data === null) {
|
|
1586
|
+
return [value];
|
|
1587
|
+
}
|
|
1588
|
+
data.push(value);
|
|
1589
|
+
return data;
|
|
1590
|
+
}));
|
|
1591
|
+
},
|
|
1592
|
+
removeItem: (path, toDelete) => {
|
|
1593
|
+
dispatch(update(path, data => {
|
|
1594
|
+
const indexInData = data.indexOf(toDelete);
|
|
1595
|
+
data.splice(indexInData, 1);
|
|
1596
|
+
return data;
|
|
1597
|
+
}));
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
const layoutDefaultProps = {
|
|
1601
|
+
visible: true,
|
|
1602
|
+
enabled: true,
|
|
1603
|
+
path: '',
|
|
1604
|
+
direction: 'column'
|
|
1605
|
+
};
|
|
1606
|
+
const getDirection = (uischema) => {
|
|
1607
|
+
if (uischema.type === 'HorizontalLayout') {
|
|
1608
|
+
return 'row';
|
|
1609
|
+
}
|
|
1610
|
+
if (uischema.type === 'VerticalLayout') {
|
|
1611
|
+
return 'column';
|
|
1612
|
+
}
|
|
1613
|
+
return layoutDefaultProps.direction;
|
|
1614
|
+
};
|
|
1615
|
+
const mapStateToLayoutProps = (state, ownProps) => {
|
|
1616
|
+
const rootData = getData(state);
|
|
1617
|
+
const { uischema } = ownProps;
|
|
1618
|
+
const visible = ownProps.visible === undefined || hasShowRule(uischema)
|
|
1619
|
+
? isVisible(ownProps.uischema, rootData, ownProps.path, getAjv(state))
|
|
1620
|
+
: ownProps.visible;
|
|
1621
|
+
const data = Resolve.data(rootData, ownProps.path);
|
|
1622
|
+
const config = getConfig(state);
|
|
1623
|
+
const enabled = isInherentlyEnabled(state, ownProps, uischema, undefined,
|
|
1624
|
+
rootData, config);
|
|
1625
|
+
return {
|
|
1626
|
+
...layoutDefaultProps,
|
|
1627
|
+
renderers: ownProps.renderers || getRenderers(state),
|
|
1628
|
+
cells: ownProps.cells || getCells(state),
|
|
1629
|
+
visible,
|
|
1630
|
+
enabled,
|
|
1631
|
+
path: ownProps.path,
|
|
1632
|
+
data,
|
|
1633
|
+
uischema: ownProps.uischema,
|
|
1634
|
+
schema: ownProps.schema,
|
|
1635
|
+
direction: ownProps.direction ?? getDirection(uischema),
|
|
1636
|
+
config
|
|
1637
|
+
};
|
|
1638
|
+
};
|
|
1639
|
+
const mapStateToJsonFormsRendererProps = (state, ownProps) => {
|
|
1640
|
+
let uischema = ownProps.uischema;
|
|
1641
|
+
if (uischema === undefined) {
|
|
1642
|
+
if (ownProps.schema) {
|
|
1643
|
+
uischema = findUISchema(state.jsonforms.uischemas, ownProps.schema, undefined, ownProps.path);
|
|
1644
|
+
}
|
|
1645
|
+
else {
|
|
1646
|
+
uischema = getUiSchema(state);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
return {
|
|
1650
|
+
renderers: ownProps.renderers || get(state.jsonforms, 'renderers') || [],
|
|
1651
|
+
cells: ownProps.cells || get(state.jsonforms, 'cells') || [],
|
|
1652
|
+
schema: ownProps.schema || getSchema(state),
|
|
1653
|
+
rootSchema: getSchema(state),
|
|
1654
|
+
uischema: uischema,
|
|
1655
|
+
path: ownProps.path
|
|
1656
|
+
};
|
|
1657
|
+
};
|
|
1658
|
+
const controlDefaultProps = {
|
|
1659
|
+
...layoutDefaultProps,
|
|
1660
|
+
errors: []
|
|
1661
|
+
};
|
|
1662
|
+
const mapStateToCombinatorRendererProps = (state, ownProps, keyword) => {
|
|
1663
|
+
const { data, schema, ...props } = mapStateToControlProps(state, ownProps);
|
|
1664
|
+
const ajv = state.jsonforms.core.ajv;
|
|
1665
|
+
const structuralKeywords = [
|
|
1666
|
+
'required',
|
|
1667
|
+
'additionalProperties',
|
|
1668
|
+
'type',
|
|
1669
|
+
'enum',
|
|
1670
|
+
'const'
|
|
1671
|
+
];
|
|
1672
|
+
const dataIsValid = (errors) => {
|
|
1673
|
+
return (!errors ||
|
|
1674
|
+
errors.length === 0 ||
|
|
1675
|
+
!errors.find(e => structuralKeywords.indexOf(e.keyword) !== -1));
|
|
1676
|
+
};
|
|
1677
|
+
let indexOfFittingSchema;
|
|
1678
|
+
for (let i = 0; i < schema[keyword]?.length; i++) {
|
|
1679
|
+
try {
|
|
1680
|
+
const valFn = ajv.compile(schema[keyword][i]);
|
|
1681
|
+
valFn(data);
|
|
1682
|
+
if (dataIsValid(valFn.errors)) {
|
|
1683
|
+
indexOfFittingSchema = i;
|
|
1684
|
+
break;
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
catch (error) {
|
|
1688
|
+
console.debug("Combinator subschema is not self contained, can't hand it over to AJV");
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
return {
|
|
1692
|
+
data,
|
|
1693
|
+
schema,
|
|
1694
|
+
...props,
|
|
1695
|
+
indexOfFittingSchema,
|
|
1696
|
+
uischemas: getUISchemas(state)
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
const mapStateToAllOfProps = (state, ownProps) => mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
|
|
1700
|
+
const mapStateToAnyOfProps = (state, ownProps) => {
|
|
1701
|
+
return mapStateToCombinatorRendererProps(state, ownProps, 'anyOf');
|
|
1702
|
+
};
|
|
1703
|
+
const mapStateToOneOfProps = (state, ownProps) => {
|
|
1704
|
+
return mapStateToCombinatorRendererProps(state, ownProps, 'oneOf');
|
|
1705
|
+
};
|
|
1706
|
+
const mapStateToArrayLayoutProps = (state, ownProps) => {
|
|
1707
|
+
const { path, schema, uischema, errors, ...props } = mapStateToControlWithDetailProps(state, ownProps);
|
|
1708
|
+
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
|
|
1709
|
+
const childErrors = getCombinedErrorMessage(getSubErrorsAt(path, resolvedSchema)(state), getErrorTranslator()(state), getTranslator()(state), undefined, undefined, undefined);
|
|
1710
|
+
const allErrors = errors +
|
|
1711
|
+
(errors.length > 0 && childErrors.length > 0 ? '\n' : '') +
|
|
1712
|
+
childErrors;
|
|
1713
|
+
return {
|
|
1714
|
+
...props,
|
|
1715
|
+
path,
|
|
1716
|
+
uischema,
|
|
1717
|
+
schema: resolvedSchema,
|
|
1718
|
+
data: props.data ? props.data.length : 0,
|
|
1719
|
+
errors: allErrors,
|
|
1720
|
+
minItems: schema.minItems
|
|
1721
|
+
};
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
const mapStateToCellProps = (state, ownProps) => {
|
|
1725
|
+
const { id, schema, path, uischema, renderers, cells } = ownProps;
|
|
1726
|
+
const rootData = getData(state);
|
|
1727
|
+
const visible = ownProps.visible !== undefined
|
|
1728
|
+
? ownProps.visible
|
|
1729
|
+
: isVisible(uischema, rootData, undefined, getAjv(state));
|
|
1730
|
+
const rootSchema = getSchema(state);
|
|
1731
|
+
const config = getConfig(state);
|
|
1732
|
+
let enabled;
|
|
1733
|
+
if (state.jsonforms.readonly === true) {
|
|
1734
|
+
enabled = false;
|
|
1735
|
+
}
|
|
1736
|
+
else if (typeof ownProps.enabled === 'boolean') {
|
|
1737
|
+
enabled = ownProps.enabled;
|
|
1738
|
+
}
|
|
1739
|
+
else {
|
|
1740
|
+
enabled = isInherentlyEnabled(state, ownProps, uischema, schema || rootSchema, rootData, config);
|
|
1741
|
+
}
|
|
1742
|
+
const errors = formatErrorMessage(union(getErrorAt(path, schema)(state).map(error => error.message)));
|
|
1743
|
+
const isValid = isEmpty(errors);
|
|
1744
|
+
return {
|
|
1745
|
+
data: Resolve.data(rootData, path),
|
|
1746
|
+
visible,
|
|
1747
|
+
enabled,
|
|
1748
|
+
id,
|
|
1749
|
+
path,
|
|
1750
|
+
errors,
|
|
1751
|
+
isValid,
|
|
1752
|
+
schema,
|
|
1753
|
+
uischema,
|
|
1754
|
+
config: getConfig(state),
|
|
1755
|
+
rootSchema,
|
|
1756
|
+
renderers,
|
|
1757
|
+
cells
|
|
1758
|
+
};
|
|
1759
|
+
};
|
|
1760
|
+
const mapStateToDispatchCellProps = (state, ownProps) => {
|
|
1761
|
+
const props = mapStateToCellProps(state, ownProps);
|
|
1762
|
+
const { renderers, cells, ...otherOwnProps } = ownProps;
|
|
1763
|
+
return {
|
|
1764
|
+
...props,
|
|
1765
|
+
...otherOwnProps,
|
|
1766
|
+
cells: cells || state.jsonforms.cells || []
|
|
1767
|
+
};
|
|
1768
|
+
};
|
|
1769
|
+
const defaultMapStateToEnumCellProps = (state, ownProps) => {
|
|
1770
|
+
const props = mapStateToCellProps(state, ownProps);
|
|
1771
|
+
const options = ownProps.options ||
|
|
1772
|
+
props.schema.enum?.map(e => enumToEnumOptionMapper(e, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path))) ||
|
|
1773
|
+
(props.schema.const && [
|
|
1774
|
+
enumToEnumOptionMapper(props.schema.const, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path))
|
|
1775
|
+
]);
|
|
1776
|
+
return {
|
|
1777
|
+
...props,
|
|
1778
|
+
options
|
|
1779
|
+
};
|
|
1780
|
+
};
|
|
1781
|
+
const mapStateToOneOfEnumCellProps = (state, ownProps) => {
|
|
1782
|
+
const props = mapStateToCellProps(state, ownProps);
|
|
1783
|
+
const options = ownProps.options ||
|
|
1784
|
+
props.schema.oneOf?.map(oneOfSubSchema => oneOfToEnumOptionMapper(oneOfSubSchema, getTranslator()(state), getI18nKeyPrefix(props.schema, props.uischema, props.path)));
|
|
1785
|
+
return {
|
|
1786
|
+
...props,
|
|
1787
|
+
options
|
|
1788
|
+
};
|
|
1789
|
+
};
|
|
1790
|
+
const mapDispatchToCellProps = mapDispatchToControlProps;
|
|
1791
|
+
const defaultMapDispatchToControlProps =
|
|
1792
|
+
(dispatch, ownProps) => {
|
|
1793
|
+
const { handleChange } = mapDispatchToCellProps(dispatch);
|
|
1794
|
+
return {
|
|
1795
|
+
handleChange: ownProps.handleChange || handleChange
|
|
1796
|
+
};
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
const createLabel = (subSchema, subSchemaIndex, keyword) => {
|
|
1800
|
+
if (subSchema.title) {
|
|
1801
|
+
return subSchema.title;
|
|
1802
|
+
}
|
|
1803
|
+
else {
|
|
1804
|
+
return keyword + '-' + subSchemaIndex;
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
const createCombinatorRenderInfos = (combinatorSubSchemas, rootSchema, keyword, control, path, uischemas) => combinatorSubSchemas.map((subSchema, subSchemaIndex) => {
|
|
1808
|
+
const schema = subSchema.$ref ? Resolve.schema(rootSchema, subSchema.$ref, rootSchema) : subSchema;
|
|
1809
|
+
return {
|
|
1810
|
+
schema,
|
|
1811
|
+
uischema: findUISchema(uischemas, schema, control.scope, path, undefined, control, rootSchema),
|
|
1812
|
+
label: createLabel(subSchema, subSchemaIndex, keyword)
|
|
1813
|
+
};
|
|
1814
|
+
});
|
|
1815
|
+
|
|
1816
|
+
const usedIds = new Set();
|
|
1817
|
+
const makeId = (idBase, iteration) => iteration <= 1 ? idBase : idBase + iteration.toString();
|
|
1818
|
+
const isUniqueId = (idBase, iteration) => {
|
|
1819
|
+
const newID = makeId(idBase, iteration);
|
|
1820
|
+
return !usedIds.has(newID);
|
|
1821
|
+
};
|
|
1822
|
+
const createId = (proposedId) => {
|
|
1823
|
+
if (proposedId === undefined) {
|
|
1824
|
+
proposedId = 'undefined';
|
|
1825
|
+
}
|
|
1826
|
+
let tries = 0;
|
|
1827
|
+
while (!isUniqueId(proposedId, tries)) {
|
|
1828
|
+
tries++;
|
|
1829
|
+
}
|
|
1830
|
+
const newID = makeId(proposedId, tries);
|
|
1831
|
+
usedIds.add(newID);
|
|
1832
|
+
return newID;
|
|
1833
|
+
};
|
|
1834
|
+
const removeId = (id) => usedIds.delete(id);
|
|
1835
|
+
const clearAllIds = () => usedIds.clear();
|
|
1836
|
+
|
|
1837
|
+
const getFirstPrimitiveProp = (schema) => {
|
|
1838
|
+
if (schema.properties) {
|
|
1839
|
+
return find(Object.keys(schema.properties), propName => {
|
|
1840
|
+
const prop = schema.properties[propName];
|
|
1841
|
+
return (prop.type === 'string' ||
|
|
1842
|
+
prop.type === 'number' ||
|
|
1843
|
+
prop.type === 'integer');
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
return undefined;
|
|
1847
|
+
};
|
|
1848
|
+
|
|
1849
|
+
const setReadonlyPropertyValue = (value) => (child) => {
|
|
1850
|
+
if (!child.options) {
|
|
1851
|
+
child.options = {};
|
|
1852
|
+
}
|
|
1853
|
+
child.options.readonly = value;
|
|
1854
|
+
};
|
|
1855
|
+
const setReadonly = (uischema) => {
|
|
1856
|
+
iterateSchema(uischema, setReadonlyPropertyValue(true));
|
|
1857
|
+
};
|
|
1858
|
+
const unsetReadonly = (uischema) => {
|
|
1859
|
+
iterateSchema(uischema, setReadonlyPropertyValue(false));
|
|
1860
|
+
};
|
|
1861
|
+
const iterateSchema = (uischema, toApply) => {
|
|
1862
|
+
if (isEmpty(uischema)) {
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
if (isLayout(uischema)) {
|
|
1866
|
+
uischema.elements.forEach(child => iterateSchema(child, toApply));
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
toApply(uischema);
|
|
1870
|
+
};
|
|
1871
|
+
|
|
1872
|
+
const createAjv = (options) => {
|
|
1873
|
+
const ajv = new Ajv({
|
|
1874
|
+
allErrors: true,
|
|
1875
|
+
verbose: true,
|
|
1876
|
+
strict: false,
|
|
1877
|
+
...options
|
|
1878
|
+
});
|
|
1879
|
+
addFormats(ajv);
|
|
1880
|
+
return ajv;
|
|
1881
|
+
};
|
|
1882
|
+
|
|
1883
|
+
const createLayout = (layoutType) => ({
|
|
1884
|
+
type: layoutType,
|
|
1885
|
+
elements: []
|
|
1886
|
+
});
|
|
1887
|
+
const createControlElement = (ref) => ({
|
|
1888
|
+
type: 'Control',
|
|
1889
|
+
scope: ref
|
|
1890
|
+
});
|
|
1891
|
+
const wrapInLayoutIfNecessary = (uischema, layoutType) => {
|
|
1892
|
+
if (!isEmpty(uischema) && !isLayout(uischema)) {
|
|
1893
|
+
const verticalLayout = createLayout(layoutType);
|
|
1894
|
+
verticalLayout.elements.push(uischema);
|
|
1895
|
+
return verticalLayout;
|
|
1896
|
+
}
|
|
1897
|
+
return uischema;
|
|
1898
|
+
};
|
|
1899
|
+
const addLabel = (layout, labelName) => {
|
|
1900
|
+
if (!isEmpty(labelName)) {
|
|
1901
|
+
const fixedLabel = startCase(labelName);
|
|
1902
|
+
if (isGroup(layout)) {
|
|
1903
|
+
layout.label = fixedLabel;
|
|
1904
|
+
}
|
|
1905
|
+
else {
|
|
1906
|
+
const label = {
|
|
1907
|
+
type: 'Label',
|
|
1908
|
+
text: fixedLabel
|
|
1909
|
+
};
|
|
1910
|
+
layout.elements.push(label);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
const isCombinator = (jsonSchema) => {
|
|
1915
|
+
return (!isEmpty(jsonSchema) &&
|
|
1916
|
+
(!isEmpty(jsonSchema.oneOf) ||
|
|
1917
|
+
!isEmpty(jsonSchema.anyOf) ||
|
|
1918
|
+
!isEmpty(jsonSchema.allOf)));
|
|
1919
|
+
};
|
|
1920
|
+
const generateUISchema = (jsonSchema, schemaElements, currentRef, schemaName, layoutType, rootSchema) => {
|
|
1921
|
+
if (!isEmpty(jsonSchema) && jsonSchema.$ref !== undefined) {
|
|
1922
|
+
return generateUISchema(resolveSchema(rootSchema, jsonSchema.$ref, rootSchema), schemaElements, currentRef, schemaName, layoutType, rootSchema);
|
|
1923
|
+
}
|
|
1924
|
+
if (isCombinator(jsonSchema)) {
|
|
1925
|
+
const controlObject = createControlElement(currentRef);
|
|
1926
|
+
schemaElements.push(controlObject);
|
|
1927
|
+
return controlObject;
|
|
1928
|
+
}
|
|
1929
|
+
const types = deriveTypes(jsonSchema);
|
|
1930
|
+
if (types.length === 0) {
|
|
1931
|
+
return null;
|
|
1932
|
+
}
|
|
1933
|
+
if (types.length > 1) {
|
|
1934
|
+
const controlObject = createControlElement(currentRef);
|
|
1935
|
+
schemaElements.push(controlObject);
|
|
1936
|
+
return controlObject;
|
|
1937
|
+
}
|
|
1938
|
+
if (currentRef === '#' && types[0] === 'object') {
|
|
1939
|
+
const layout = createLayout(layoutType);
|
|
1940
|
+
schemaElements.push(layout);
|
|
1941
|
+
if (jsonSchema.properties && keys(jsonSchema.properties).length > 1) {
|
|
1942
|
+
addLabel(layout, schemaName);
|
|
1943
|
+
}
|
|
1944
|
+
if (!isEmpty(jsonSchema.properties)) {
|
|
1945
|
+
const nextRef = currentRef + '/properties';
|
|
1946
|
+
Object.keys(jsonSchema.properties).map(propName => {
|
|
1947
|
+
let value = jsonSchema.properties[propName];
|
|
1948
|
+
const ref = `${nextRef}/${encode(propName)}`;
|
|
1949
|
+
if (value.$ref !== undefined) {
|
|
1950
|
+
value = resolveSchema(rootSchema, value.$ref, rootSchema);
|
|
1951
|
+
}
|
|
1952
|
+
generateUISchema(value, layout.elements, ref, propName, layoutType, rootSchema);
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
return layout;
|
|
1956
|
+
}
|
|
1957
|
+
switch (types[0]) {
|
|
1958
|
+
case 'object':
|
|
1959
|
+
case 'array':
|
|
1960
|
+
case 'string':
|
|
1961
|
+
case 'number':
|
|
1962
|
+
case 'integer':
|
|
1963
|
+
case 'boolean':
|
|
1964
|
+
const controlObject = createControlElement(currentRef);
|
|
1965
|
+
schemaElements.push(controlObject);
|
|
1966
|
+
return controlObject;
|
|
1967
|
+
default:
|
|
1968
|
+
throw new Error('Unknown type: ' + JSON.stringify(jsonSchema));
|
|
1969
|
+
}
|
|
1970
|
+
};
|
|
1971
|
+
const generateDefaultUISchema = (jsonSchema, layoutType = 'VerticalLayout', prefix = '#', rootSchema = jsonSchema) => wrapInLayoutIfNecessary(generateUISchema(jsonSchema, [], prefix, '', layoutType, rootSchema), layoutType);
|
|
1972
|
+
|
|
1973
|
+
const Generate = {
|
|
1974
|
+
jsonSchema: generateJsonSchema,
|
|
1975
|
+
uiSchema: generateDefaultUISchema,
|
|
1976
|
+
controlElement: createControlElement
|
|
1977
|
+
};
|
|
1978
|
+
|
|
1979
|
+
const INIT = 'jsonforms/INIT';
|
|
1980
|
+
const UPDATE_CORE = `jsonforms/UPDATE_CORE`;
|
|
1981
|
+
const SET_AJV = 'jsonforms/SET_AJV';
|
|
1982
|
+
const UPDATE_DATA = 'jsonforms/UPDATE';
|
|
1983
|
+
const UPDATE_ERRORS = 'jsonforms/UPDATE_ERRORS';
|
|
1984
|
+
const VALIDATE = 'jsonforms/VALIDATE';
|
|
1985
|
+
const ADD_RENDERER = 'jsonforms/ADD_RENDERER';
|
|
1986
|
+
const REMOVE_RENDERER = 'jsonforms/REMOVE_RENDERER';
|
|
1987
|
+
const ADD_CELL = 'jsonforms/ADD_CELL';
|
|
1988
|
+
const REMOVE_CELL = 'jsonforms/REMOVE_CELL';
|
|
1989
|
+
const SET_CONFIG = 'jsonforms/SET_CONFIG';
|
|
1990
|
+
const ADD_UI_SCHEMA = `jsonforms/ADD_UI_SCHEMA`;
|
|
1991
|
+
const REMOVE_UI_SCHEMA = `jsonforms/REMOVE_UI_SCHEMA`;
|
|
1992
|
+
const SET_SCHEMA = `jsonforms/SET_SCHEMA`;
|
|
1993
|
+
const SET_UISCHEMA = `jsonforms/SET_UISCHEMA`;
|
|
1994
|
+
const SET_VALIDATION_MODE = 'jsonforms/SET_VALIDATION_MODE';
|
|
1995
|
+
const SET_LOCALE = `jsonforms/SET_LOCALE`;
|
|
1996
|
+
const SET_TRANSLATOR = 'jsonforms/SET_TRANSLATOR';
|
|
1997
|
+
const UPDATE_I18N = 'jsonforms/UPDATE_I18N';
|
|
1998
|
+
const ADD_DEFAULT_DATA = `jsonforms/ADD_DEFAULT_DATA`;
|
|
1999
|
+
const REMOVE_DEFAULT_DATA = `jsonforms/REMOVE_DEFAULT_DATA`;
|
|
2000
|
+
const init = (data, schema = generateJsonSchema(data), uischema, options) => ({
|
|
2001
|
+
type: INIT,
|
|
2002
|
+
data,
|
|
2003
|
+
schema,
|
|
2004
|
+
uischema: typeof uischema === 'object' ? uischema : generateDefaultUISchema(schema),
|
|
2005
|
+
options
|
|
2006
|
+
});
|
|
2007
|
+
const updateCore = (data, schema, uischema, options) => ({
|
|
2008
|
+
type: UPDATE_CORE,
|
|
2009
|
+
data,
|
|
2010
|
+
schema,
|
|
2011
|
+
uischema,
|
|
2012
|
+
options
|
|
2013
|
+
});
|
|
2014
|
+
const registerDefaultData = (schemaPath, data) => ({
|
|
2015
|
+
type: ADD_DEFAULT_DATA,
|
|
2016
|
+
schemaPath,
|
|
2017
|
+
data
|
|
2018
|
+
});
|
|
2019
|
+
const unregisterDefaultData = (schemaPath) => ({
|
|
2020
|
+
type: REMOVE_DEFAULT_DATA,
|
|
2021
|
+
schemaPath
|
|
2022
|
+
});
|
|
2023
|
+
const setAjv = (ajv) => ({
|
|
2024
|
+
type: SET_AJV,
|
|
2025
|
+
ajv
|
|
2026
|
+
});
|
|
2027
|
+
const update = (path, updater) => ({
|
|
2028
|
+
type: UPDATE_DATA,
|
|
2029
|
+
path,
|
|
2030
|
+
updater
|
|
2031
|
+
});
|
|
2032
|
+
const updateErrors = (errors) => ({
|
|
2033
|
+
type: UPDATE_ERRORS,
|
|
2034
|
+
errors
|
|
2035
|
+
});
|
|
2036
|
+
const registerRenderer = (tester, renderer) => ({
|
|
2037
|
+
type: ADD_RENDERER,
|
|
2038
|
+
tester,
|
|
2039
|
+
renderer
|
|
2040
|
+
});
|
|
2041
|
+
const registerCell = (tester, cell) => ({
|
|
2042
|
+
type: ADD_CELL,
|
|
2043
|
+
tester,
|
|
2044
|
+
cell
|
|
2045
|
+
});
|
|
2046
|
+
const unregisterCell = (tester, cell) => ({
|
|
2047
|
+
type: REMOVE_CELL,
|
|
2048
|
+
tester,
|
|
2049
|
+
cell
|
|
2050
|
+
});
|
|
2051
|
+
const unregisterRenderer = (tester, renderer) => ({
|
|
2052
|
+
type: REMOVE_RENDERER,
|
|
2053
|
+
tester,
|
|
2054
|
+
renderer
|
|
2055
|
+
});
|
|
2056
|
+
const setConfig = (config) => ({
|
|
2057
|
+
type: SET_CONFIG,
|
|
2058
|
+
config
|
|
2059
|
+
});
|
|
2060
|
+
const setValidationMode = (validationMode) => ({
|
|
2061
|
+
type: SET_VALIDATION_MODE,
|
|
2062
|
+
validationMode
|
|
2063
|
+
});
|
|
2064
|
+
const registerUISchema = (tester, uischema) => {
|
|
2065
|
+
return {
|
|
2066
|
+
type: ADD_UI_SCHEMA,
|
|
2067
|
+
tester,
|
|
2068
|
+
uischema
|
|
2069
|
+
};
|
|
2070
|
+
};
|
|
2071
|
+
const unregisterUISchema = (tester) => {
|
|
2072
|
+
return {
|
|
2073
|
+
type: REMOVE_UI_SCHEMA,
|
|
2074
|
+
tester
|
|
2075
|
+
};
|
|
2076
|
+
};
|
|
2077
|
+
const setLocale = (locale) => ({
|
|
2078
|
+
type: SET_LOCALE,
|
|
2079
|
+
locale
|
|
2080
|
+
});
|
|
2081
|
+
const setSchema = (schema) => ({
|
|
2082
|
+
type: SET_SCHEMA,
|
|
2083
|
+
schema
|
|
2084
|
+
});
|
|
2085
|
+
const setTranslator = (translator, errorTranslator) => ({
|
|
2086
|
+
type: SET_TRANSLATOR,
|
|
2087
|
+
translator,
|
|
2088
|
+
errorTranslator
|
|
2089
|
+
});
|
|
2090
|
+
const updateI18n = (locale, translator, errorTranslator) => ({
|
|
2091
|
+
type: UPDATE_I18N,
|
|
2092
|
+
locale,
|
|
2093
|
+
translator,
|
|
2094
|
+
errorTranslator
|
|
2095
|
+
});
|
|
2096
|
+
const setUISchema = (uischema) => ({
|
|
2097
|
+
type: SET_UISCHEMA,
|
|
2098
|
+
uischema
|
|
2099
|
+
});
|
|
2100
|
+
|
|
2101
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
2102
|
+
__proto__: null,
|
|
2103
|
+
INIT: INIT,
|
|
2104
|
+
UPDATE_CORE: UPDATE_CORE,
|
|
2105
|
+
SET_AJV: SET_AJV,
|
|
2106
|
+
UPDATE_DATA: UPDATE_DATA,
|
|
2107
|
+
UPDATE_ERRORS: UPDATE_ERRORS,
|
|
2108
|
+
VALIDATE: VALIDATE,
|
|
2109
|
+
ADD_RENDERER: ADD_RENDERER,
|
|
2110
|
+
REMOVE_RENDERER: REMOVE_RENDERER,
|
|
2111
|
+
ADD_CELL: ADD_CELL,
|
|
2112
|
+
REMOVE_CELL: REMOVE_CELL,
|
|
2113
|
+
SET_CONFIG: SET_CONFIG,
|
|
2114
|
+
ADD_UI_SCHEMA: ADD_UI_SCHEMA,
|
|
2115
|
+
REMOVE_UI_SCHEMA: REMOVE_UI_SCHEMA,
|
|
2116
|
+
SET_SCHEMA: SET_SCHEMA,
|
|
2117
|
+
SET_UISCHEMA: SET_UISCHEMA,
|
|
2118
|
+
SET_VALIDATION_MODE: SET_VALIDATION_MODE,
|
|
2119
|
+
SET_LOCALE: SET_LOCALE,
|
|
2120
|
+
SET_TRANSLATOR: SET_TRANSLATOR,
|
|
2121
|
+
UPDATE_I18N: UPDATE_I18N,
|
|
2122
|
+
ADD_DEFAULT_DATA: ADD_DEFAULT_DATA,
|
|
2123
|
+
REMOVE_DEFAULT_DATA: REMOVE_DEFAULT_DATA,
|
|
2124
|
+
init: init,
|
|
2125
|
+
updateCore: updateCore,
|
|
2126
|
+
registerDefaultData: registerDefaultData,
|
|
2127
|
+
unregisterDefaultData: unregisterDefaultData,
|
|
2128
|
+
setAjv: setAjv,
|
|
2129
|
+
update: update,
|
|
2130
|
+
updateErrors: updateErrors,
|
|
2131
|
+
registerRenderer: registerRenderer,
|
|
2132
|
+
registerCell: registerCell,
|
|
2133
|
+
unregisterCell: unregisterCell,
|
|
2134
|
+
unregisterRenderer: unregisterRenderer,
|
|
2135
|
+
setConfig: setConfig,
|
|
2136
|
+
setValidationMode: setValidationMode,
|
|
2137
|
+
registerUISchema: registerUISchema,
|
|
2138
|
+
unregisterUISchema: unregisterUISchema,
|
|
2139
|
+
setLocale: setLocale,
|
|
2140
|
+
setSchema: setSchema,
|
|
2141
|
+
setTranslator: setTranslator,
|
|
2142
|
+
updateI18n: updateI18n,
|
|
2143
|
+
setUISchema: setUISchema
|
|
2144
|
+
});
|
|
2145
|
+
|
|
2146
|
+
const Helpers = {
|
|
2147
|
+
createLabelDescriptionFrom,
|
|
2148
|
+
convertToValidClassName
|
|
2149
|
+
};
|
|
2150
|
+
|
|
2151
|
+
export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, Draft4, Generate, Helpers, INIT, NOT_APPLICABLE, Paths, REMOVE_CELL, REMOVE_DEFAULT_DATA, REMOVE_RENDERER, REMOVE_UI_SCHEMA, Resolve, RuleEffect, Runtime, SET_AJV, SET_CONFIG, SET_LOCALE, SET_SCHEMA, SET_TRANSLATOR, SET_UISCHEMA, SET_VALIDATION_MODE, index$1 as Test, UPDATE_CORE, UPDATE_DATA, UPDATE_ERRORS, UPDATE_I18N, VALIDATE, and, categorizationHasCategory, cellReducer, clearAllIds, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, decode, defaultDataReducer, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultTranslator, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, getCells, getCombinedErrorMessage, getConfig, getControlPath, getData, getDefaultData, getErrorAt, getErrorTranslator, getFirstPrimitiveProp, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, getLocale, getRenderers, getSchema, getSubErrorsAt, getTranslator, getUISchemas, getUiSchema, hasCategory, hasEnableRule, hasShowRule, hasType, i18nReducer, init, isAllOfControl, isAnyOfControl, isArrayObjectControl, isBooleanControl, isCategorization, isCategory, isControl, isDateControl, isDateTimeControl, isDescriptionHidden, isEnabled, isEnumControl, isGroup, isInherentlyEnabled, isIntegerControl, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isPrimitiveArrayControl, isRangeControl, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, schemaMatches, schemaSubPathMatches, schemaTypeIs, scopeEndIs, scopeEndsWith, setAjv, setConfig, setLocale, setReadonly, setSchema, setTranslator, setUISchema, setValidationMode, showAsRequired, subErrorsAt, toDataPath, toDataPathSegments, transformPathToI18nPrefix, uiTypeIs, uischemaRegistryReducer, unregisterCell, unregisterDefaultData, unregisterRenderer, unregisterUISchema, unsetReadonly, update, updateCore, updateErrors, updateI18n, validate, withIncreasedRank };
|
|
2152
|
+
//# sourceMappingURL=jsonforms-core.esm.js.map
|