@jsonforms/core 3.1.0-alpha.0 → 3.1.0-alpha.2

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