@jsonforms/core 3.0.0-alpha.0 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +1 -1
  2. package/docs/assets/js/search.json +1 -1
  3. package/docs/enums/ruleeffect.html +4 -4
  4. package/docs/globals.html +1095 -703
  5. package/docs/index.html +70 -43
  6. package/docs/interfaces/addcellrendereraction.html +3 -3
  7. package/docs/interfaces/addrendereraction.html +3 -3
  8. package/docs/interfaces/adduischemaaction.html +3 -3
  9. package/docs/interfaces/andcondition.html +2 -2
  10. package/docs/interfaces/arraycontrolprops.html +22 -22
  11. package/docs/interfaces/arraylayoutprops.html +22 -22
  12. package/docs/interfaces/categorization.html +5 -5
  13. package/docs/interfaces/category.html +5 -5
  14. package/docs/interfaces/cellprops.html +14 -14
  15. package/docs/interfaces/combinatorrendererprops.html +13 -13
  16. package/docs/interfaces/combinatorsubschemarenderinfo.html +3 -3
  17. package/docs/interfaces/composablecondition.html +2 -2
  18. package/docs/interfaces/condition.html +1 -1
  19. package/docs/interfaces/controlelement.html +5 -5
  20. package/docs/interfaces/controlprops.html +17 -17
  21. package/docs/interfaces/controlstate.html +2 -2
  22. package/docs/interfaces/controlwithdetailprops.html +18 -18
  23. package/docs/interfaces/dispatchcellprops.html +13 -13
  24. package/docs/interfaces/dispatchcellstateprops.html +13 -13
  25. package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
  26. package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
  27. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
  28. package/docs/interfaces/enumcellprops.html +15 -15
  29. package/docs/interfaces/enumoption.html +2 -2
  30. package/docs/interfaces/formatted.html +2 -2
  31. package/docs/interfaces/grouplayout.html +5 -5
  32. package/docs/interfaces/horizontallayout.html +4 -4
  33. package/docs/interfaces/initaction.html +6 -6
  34. package/docs/interfaces/initactionoptions.html +3 -3
  35. package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
  36. package/docs/interfaces/jsonformscore.html +7 -7
  37. package/docs/interfaces/jsonformsdefaultdataregistryentry.html +2 -2
  38. package/docs/interfaces/jsonformsextendedstate.html +1 -1
  39. package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
  40. package/docs/interfaces/jsonformsprops.html +9 -9
  41. package/docs/interfaces/jsonformsrendererregistryentry.html +2 -2
  42. package/docs/interfaces/jsonformsstate.html +1 -1
  43. package/docs/interfaces/jsonformsstore.html +5 -5
  44. package/docs/interfaces/jsonformssubstates.html +18 -8
  45. package/docs/interfaces/jsonformsuischemaregistryentry.html +2 -2
  46. package/docs/interfaces/labeldescription.html +2 -2
  47. package/docs/interfaces/labelelement.html +4 -4
  48. package/docs/interfaces/layout.html +4 -4
  49. package/docs/interfaces/layoutprops.html +10 -10
  50. package/docs/interfaces/leafcondition.html +3 -3
  51. package/docs/interfaces/orcondition.html +2 -2
  52. package/docs/interfaces/ownpropsofcell.html +10 -10
  53. package/docs/interfaces/ownpropsofcontrol.html +9 -9
  54. package/docs/interfaces/ownpropsofenum.html +1 -1
  55. package/docs/interfaces/ownpropsofenumcell.html +11 -11
  56. package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
  57. package/docs/interfaces/ownpropsoflayout.html +9 -9
  58. package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
  59. package/docs/interfaces/ownpropsofrenderer.html +8 -8
  60. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  61. package/docs/interfaces/removecellrendereraction.html +3 -3
  62. package/docs/interfaces/removerendereraction.html +3 -3
  63. package/docs/interfaces/removeuischemaaction.html +2 -2
  64. package/docs/interfaces/rendererprops.html +9 -9
  65. package/docs/interfaces/rule.html +2 -2
  66. package/docs/interfaces/schemabasedcondition.html +3 -3
  67. package/docs/interfaces/scopable.html +1 -1
  68. package/docs/interfaces/setajvaction.html +3 -3
  69. package/docs/interfaces/setconfigaction.html +2 -2
  70. package/docs/interfaces/setlocaleaction.html +3 -3
  71. package/docs/interfaces/setschemaaction.html +2 -2
  72. package/docs/interfaces/{setlocalizedschemasaction.html → settranslatoraction.html} +29 -15
  73. package/docs/interfaces/setuischemaaction.html +2 -2
  74. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  75. package/docs/interfaces/statepropsofarraycontrol.html +18 -18
  76. package/docs/interfaces/statepropsofarraylayout.html +18 -18
  77. package/docs/interfaces/statepropsofcell.html +13 -13
  78. package/docs/interfaces/statepropsofcombinator.html +12 -12
  79. package/docs/interfaces/statepropsofcontrol.html +16 -16
  80. package/docs/interfaces/statepropsofcontrolwithdetail.html +17 -17
  81. package/docs/interfaces/statepropsofenumcell.html +14 -14
  82. package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
  83. package/docs/interfaces/statepropsoflayout.html +10 -10
  84. package/docs/interfaces/statepropsofmasteritem.html +7 -7
  85. package/docs/interfaces/statepropsofrenderer.html +9 -9
  86. package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
  87. package/docs/interfaces/uischemaelement.html +3 -3
  88. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  89. package/docs/interfaces/updateaction.html +3 -3
  90. package/docs/interfaces/updatecoreaction.html +6 -6
  91. package/docs/interfaces/updateerrorsaction.html +2 -2
  92. package/docs/interfaces/{setlocalizeduischemasaction.html → updatei18naction.html} +43 -15
  93. package/docs/interfaces/verticallayout.html +4 -4
  94. package/docs/interfaces/withclassname.html +1 -1
  95. package/lib/Helpers.d.ts +5 -0
  96. package/lib/actions/actions.d.ts +181 -0
  97. package/lib/actions/index.d.ts +1 -178
  98. package/lib/configDefault.d.ts +6 -6
  99. package/lib/generators/Generate.d.ts +6 -0
  100. package/lib/generators/index.d.ts +3 -10
  101. package/lib/generators/schema.d.ts +8 -8
  102. package/lib/generators/uischema.d.ts +12 -13
  103. package/lib/i18n/i18nTypes.d.ts +15 -0
  104. package/lib/i18n/i18nUtil.d.ts +18 -0
  105. package/lib/i18n/index.d.ts +2 -0
  106. package/lib/index.d.ts +11 -23
  107. package/lib/jsonforms-core.cjs.js +2445 -0
  108. package/lib/jsonforms-core.cjs.js.map +1 -0
  109. package/lib/jsonforms-core.esm.js +2164 -0
  110. package/lib/jsonforms-core.esm.js.map +1 -0
  111. package/lib/models/draft4.d.ts +198 -198
  112. package/lib/models/index.d.ts +5 -0
  113. package/lib/models/jsonSchema.d.ts +3 -3
  114. package/lib/models/jsonSchema4.d.ts +110 -110
  115. package/lib/models/jsonSchema7.d.ts +119 -119
  116. package/lib/models/uischema.d.ts +201 -201
  117. package/lib/reducers/cells.d.ts +11 -11
  118. package/lib/reducers/config.d.ts +3 -3
  119. package/lib/reducers/core.d.ts +24 -23
  120. package/lib/reducers/default-data.d.ts +10 -10
  121. package/lib/reducers/i18n.d.ts +8 -11
  122. package/lib/reducers/index.d.ts +9 -47
  123. package/lib/reducers/reducers.d.ts +29 -0
  124. package/lib/reducers/renderers.d.ts +10 -10
  125. package/lib/reducers/selectors.d.ts +15 -0
  126. package/lib/reducers/uischemas.d.ts +10 -10
  127. package/lib/store.d.ts +53 -56
  128. package/lib/testers/index.d.ts +1 -204
  129. package/lib/testers/testers.d.ts +203 -0
  130. package/lib/util/Formatted.d.ts +19 -19
  131. package/lib/util/array.d.ts +3 -3
  132. package/lib/util/cell.d.ts +79 -79
  133. package/lib/util/combinators.d.ts +10 -11
  134. package/lib/util/ids.d.ts +3 -3
  135. package/lib/util/index.d.ts +15 -49
  136. package/lib/util/label.d.ts +9 -10
  137. package/lib/util/path.d.ts +25 -24
  138. package/lib/util/renderer.d.ts +398 -395
  139. package/lib/util/resolvers.d.ts +25 -25
  140. package/lib/util/runtime.d.ts +18 -19
  141. package/lib/util/schema.d.ts +1 -1
  142. package/lib/util/type.d.ts +174 -174
  143. package/lib/util/uischema.d.ts +5 -5
  144. package/lib/util/util.d.ts +31 -0
  145. package/lib/util/validator.d.ts +3 -2
  146. package/package.json +18 -14
  147. package/rollup.config.js +44 -0
  148. package/{lib/models/jsonSchema4.js → src/Helpers.ts} +16 -8
  149. package/src/actions/actions.ts +345 -0
  150. package/src/actions/index.ts +1 -310
  151. package/src/configDefault.ts +1 -0
  152. package/{lib/util/validator.js → src/generators/Generate.ts} +18 -11
  153. package/src/generators/index.ts +3 -21
  154. package/src/generators/schema.ts +1 -1
  155. package/src/generators/uischema.ts +4 -4
  156. package/src/i18n/i18nTypes.ts +17 -0
  157. package/src/i18n/i18nUtil.ts +105 -0
  158. package/src/i18n/index.ts +2 -0
  159. package/src/index.ts +7 -31
  160. package/src/models/draft4.ts +1 -0
  161. package/{lib/util/type.js → src/models/index.ts} +10 -7
  162. package/src/models/jsonSchema.ts +1 -0
  163. package/src/models/uischema.ts +1 -0
  164. package/src/reducers/cells.ts +2 -1
  165. package/src/reducers/config.ts +2 -1
  166. package/src/reducers/core.ts +74 -52
  167. package/src/reducers/default-data.ts +2 -1
  168. package/src/reducers/i18n.ts +42 -35
  169. package/src/reducers/index.ts +9 -154
  170. package/src/reducers/reducers.ts +128 -0
  171. package/src/reducers/renderers.ts +2 -1
  172. package/src/reducers/selectors.ts +65 -0
  173. package/src/reducers/uischemas.ts +4 -2
  174. package/src/store.ts +11 -8
  175. package/src/testers/index.ts +1 -516
  176. package/src/testers/testers.ts +547 -0
  177. package/src/util/Formatted.ts +1 -0
  178. package/src/util/array.ts +25 -0
  179. package/src/util/cell.ts +45 -10
  180. package/src/util/combinators.ts +2 -4
  181. package/src/util/ids.ts +1 -0
  182. package/src/util/index.ts +11 -123
  183. package/src/util/label.ts +2 -2
  184. package/src/util/path.ts +4 -1
  185. package/src/util/renderer.ts +139 -66
  186. package/src/util/resolvers.ts +2 -1
  187. package/src/util/runtime.ts +3 -2
  188. package/src/util/schema.ts +26 -1
  189. package/src/util/uischema.ts +2 -1
  190. package/src/util/util.ts +127 -0
  191. package/src/util/validator.ts +5 -8
  192. package/stats.html +3279 -0
  193. package/{lib/configDefault.js → test/i18n/i18nUtil.test.ts} +25 -24
  194. package/test/reducers/core.test.ts +31 -44
  195. package/test/util/cell.test.ts +2 -2
  196. package/test/util/renderer.test.ts +543 -31
  197. package/docs/interfaces/labels.html +0 -157
  198. package/lib/actions/index.js +0 -125
  199. package/lib/actions/index.js.map +0 -1
  200. package/lib/configDefault.js.map +0 -1
  201. package/lib/generators/index.js +0 -12
  202. package/lib/generators/index.js.map +0 -1
  203. package/lib/generators/schema.js +0 -152
  204. package/lib/generators/schema.js.map +0 -1
  205. package/lib/generators/uischema.js +0 -167
  206. package/lib/generators/uischema.js.map +0 -1
  207. package/lib/index.js +0 -45
  208. package/lib/index.js.map +0 -1
  209. package/lib/jsonforms-core.js +0 -19
  210. package/lib/jsonforms-core.js.map +0 -1
  211. package/lib/models/draft4.js +0 -173
  212. package/lib/models/draft4.js.map +0 -1
  213. package/lib/models/jsonSchema.js +0 -3
  214. package/lib/models/jsonSchema.js.map +0 -1
  215. package/lib/models/jsonSchema4.js.map +0 -1
  216. package/lib/models/jsonSchema7.js +0 -30
  217. package/lib/models/jsonSchema7.js.map +0 -1
  218. package/lib/models/uischema.js +0 -31
  219. package/lib/models/uischema.js.map +0 -1
  220. package/lib/reducers/cells.js +0 -16
  221. package/lib/reducers/cells.js.map +0 -1
  222. package/lib/reducers/config.js +0 -44
  223. package/lib/reducers/config.js.map +0 -1
  224. package/lib/reducers/core.js +0 -259
  225. package/lib/reducers/core.js.map +0 -1
  226. package/lib/reducers/default-data.js +0 -42
  227. package/lib/reducers/default-data.js.map +0 -1
  228. package/lib/reducers/i18n.js +0 -66
  229. package/lib/reducers/i18n.js.map +0 -1
  230. package/lib/reducers/index.js +0 -92
  231. package/lib/reducers/index.js.map +0 -1
  232. package/lib/reducers/renderers.js +0 -17
  233. package/lib/reducers/renderers.js.map +0 -1
  234. package/lib/reducers/uischemas.js +0 -57
  235. package/lib/reducers/uischemas.js.map +0 -1
  236. package/lib/store.js +0 -3
  237. package/lib/store.js.map +0 -1
  238. package/lib/testers/index.js +0 -402
  239. package/lib/testers/index.js.map +0 -1
  240. package/lib/util/Formatted.js +0 -3
  241. package/lib/util/Formatted.js.map +0 -1
  242. package/lib/util/array.js +0 -19
  243. package/lib/util/array.js.map +0 -1
  244. package/lib/util/cell.js +0 -133
  245. package/lib/util/cell.js.map +0 -1
  246. package/lib/util/combinators.js +0 -56
  247. package/lib/util/combinators.js.map +0 -1
  248. package/lib/util/ids.js +0 -50
  249. package/lib/util/ids.js.map +0 -1
  250. package/lib/util/index.js +0 -132
  251. package/lib/util/index.js.map +0 -1
  252. package/lib/util/label.js +0 -70
  253. package/lib/util/label.js.map +0 -1
  254. package/lib/util/path.js +0 -84
  255. package/lib/util/path.js.map +0 -1
  256. package/lib/util/renderer.js +0 -447
  257. package/lib/util/renderer.js.map +0 -1
  258. package/lib/util/resolvers.js +0 -165
  259. package/lib/util/resolvers.js.map +0 -1
  260. package/lib/util/runtime.js +0 -159
  261. package/lib/util/runtime.js.map +0 -1
  262. package/lib/util/schema.js +0 -16
  263. package/lib/util/schema.js.map +0 -1
  264. package/lib/util/type.js.map +0 -1
  265. package/lib/util/uischema.js +0 -52
  266. package/lib/util/uischema.js.map +0 -1
  267. package/lib/util/validator.js.map +0 -1
  268. package/webpack.build.js +0 -13
@@ -22,520 +22,5 @@
22
22
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
23
  THE SOFTWARE.
24
24
  */
25
- import isEmpty from 'lodash/isEmpty';
26
- import get from 'lodash/get';
27
- import endsWith from 'lodash/endsWith';
28
- import last from 'lodash/last';
29
- import isArray from 'lodash/isArray';
30
- import reduce from 'lodash/reduce';
31
- import toPairs from 'lodash/toPairs';
32
- import includes from 'lodash/includes';
33
- import { JsonSchema } from '../models/jsonSchema';
34
- import {
35
- Categorization,
36
- ControlElement,
37
- UISchemaElement
38
- } from '../models/uischema';
39
- import { resolveSchema } from '../util/resolvers';
40
- import { deriveTypes, hasType } from '../util';
41
25
 
42
- /**
43
- * Constant that indicates that a tester is not capable of handling
44
- * a combination of schema/data.
45
- * @type {number}
46
- */
47
- export const NOT_APPLICABLE = -1;
48
- /**
49
- * A tester is a function that receives an UI schema and a JSON schema and returns a boolean.
50
- */
51
- export type Tester = (uischema: UISchemaElement, schema: JsonSchema) => boolean;
52
-
53
- /**
54
- * A ranked tester associates a tester with a number.
55
- */
56
- export type RankedTester = (
57
- uischema: UISchemaElement,
58
- schema: JsonSchema
59
- ) => number;
60
-
61
- export const isControl = (uischema: any): uischema is ControlElement =>
62
- !isEmpty(uischema) && uischema.scope !== undefined;
63
-
64
- /**
65
- * Only applicable for Controls.
66
- *
67
- * This function checks whether the given UI schema is of type Control
68
- * and if so, resolves the sub-schema referenced by the control and applies
69
- * the given predicate
70
- *
71
- * @param {(JsonSchema) => boolean} predicate the predicate that should be
72
- * applied to the resolved sub-schema
73
- */
74
- export const schemaMatches = (
75
- predicate: (schema: JsonSchema) => boolean
76
- ): Tester => (uischema: UISchemaElement, schema: JsonSchema): boolean => {
77
- if (isEmpty(uischema) || !isControl(uischema)) {
78
- return false;
79
- }
80
- if (isEmpty(schema)) {
81
- return false;
82
- }
83
- const schemaPath = uischema.scope;
84
- if (isEmpty(schemaPath)) {
85
- return false;
86
- }
87
- let currentDataSchema = schema;
88
- if (hasType(schema, 'object')) {
89
- currentDataSchema = resolveSchema(schema, schemaPath);
90
- }
91
- if (currentDataSchema === undefined) {
92
- return false;
93
- }
94
-
95
- return predicate(currentDataSchema);
96
- };
97
-
98
- export const schemaSubPathMatches = (
99
- subPath: string,
100
- predicate: (schema: JsonSchema) => boolean
101
- ): Tester => (uischema: UISchemaElement, schema: JsonSchema): boolean => {
102
- if (isEmpty(uischema) || !isControl(uischema)) {
103
- return false;
104
- }
105
- const schemaPath = uischema.scope;
106
- let currentDataSchema: JsonSchema = schema;
107
- if (hasType(schema, 'object')) {
108
- currentDataSchema = resolveSchema(schema, schemaPath);
109
- }
110
- currentDataSchema = get(currentDataSchema, subPath);
111
-
112
- if (currentDataSchema === undefined) {
113
- return false;
114
- }
115
-
116
- return predicate(currentDataSchema);
117
- };
118
-
119
- /**
120
- * Only applicable for Controls.
121
- *
122
- * This function checks whether the given UI schema is of type Control
123
- * and if so, resolves the sub-schema referenced by the control and checks
124
- * whether the type of the sub-schema matches the expected one.
125
- *
126
- * @param {string} expectedType the expected type of the resolved sub-schema
127
- */
128
- export const schemaTypeIs = (expectedType: string): Tester =>
129
- schemaMatches(schema => !isEmpty(schema) && hasType(schema, expectedType));
130
-
131
- /**
132
- * Only applicable for Controls.
133
- *
134
- * This function checks whether the given UI schema is of type Control
135
- * and if so, resolves the sub-schema referenced by the control and checks
136
- * whether the format of the sub-schema matches the expected one.
137
- *
138
- * @param {string} expectedFormat the expected format of the resolved sub-schema
139
- */
140
- export const formatIs = (expectedFormat: string): Tester =>
141
- schemaMatches(
142
- schema =>
143
- !isEmpty(schema) &&
144
- schema.format === expectedFormat &&
145
- schema.type === 'string'
146
- );
147
-
148
- /**
149
- * Checks whether the given UI schema has the expected type.
150
- *
151
- * @param {string} expected the expected UI schema type
152
- */
153
- export const uiTypeIs = (expected: string): Tester => (
154
- uischema: UISchemaElement
155
- ): boolean => !isEmpty(uischema) && uischema.type === expected;
156
-
157
- /**
158
- * Checks whether the given UI schema has an option with the given
159
- * name and whether it has the expected value. If no options property
160
- * is set, returns false.
161
- *
162
- * @param {string} optionName the name of the option to check
163
- * @param {any} optionValue the expected value of the option
164
- */
165
- export const optionIs = (optionName: string, optionValue: any): Tester => (
166
- uischema: UISchemaElement
167
- ): boolean => {
168
- if (isEmpty(uischema)) {
169
- return false;
170
- }
171
-
172
- const options = uischema.options;
173
- return !isEmpty(options) && options[optionName] === optionValue;
174
- };
175
-
176
- /**
177
- * Only applicable for Controls.
178
- *
179
- * Checks whether the scope of a control ends with the expected string.
180
- *
181
- * @param {string} expected the expected ending of the reference
182
- */
183
- export const scopeEndsWith = (expected: string): Tester => (
184
- uischema: UISchemaElement
185
- ): boolean => {
186
- if (isEmpty(expected) || !isControl(uischema)) {
187
- return false;
188
- }
189
-
190
- return endsWith(uischema.scope, expected);
191
- };
192
-
193
- /**
194
- * Only applicable for Controls.
195
- *
196
- * Checks whether the last segment of the scope matches the expected string.
197
- *
198
- * @param {string} expected the expected ending of the reference
199
- */
200
- export const scopeEndIs = (expected: string): Tester => (
201
- uischema: UISchemaElement
202
- ): boolean => {
203
- if (isEmpty(expected) || !isControl(uischema)) {
204
- return false;
205
- }
206
- const schemaPath = uischema.scope;
207
-
208
- return !isEmpty(schemaPath) && last(schemaPath.split('/')) === expected;
209
- };
210
-
211
- /**
212
- * A tester that allow composing other testers by && them.
213
- *
214
- * @param {Array<Tester>} testers the testers to be composed
215
- */
216
- export const and = (...testers: Tester[]): Tester => (
217
- uischema: UISchemaElement,
218
- schema: JsonSchema
219
- ) => testers.reduce((acc, tester) => acc && tester(uischema, schema), true);
220
-
221
- /**
222
- * A tester that allow composing other testers by || them.
223
- *
224
- * @param {Array<Tester>} testers the testers to be composed
225
- */
226
- export const or = (...testers: Tester[]): Tester => (
227
- uischema: UISchemaElement,
228
- schema: JsonSchema
229
- ) => testers.reduce((acc, tester) => acc || tester(uischema, schema), false);
230
- /**
231
- * Create a ranked tester that will associate a number with a given tester, if the
232
- * latter returns true.
233
- *
234
- * @param {number} rank the rank to be returned in case the tester returns true
235
- * @param {Tester} tester a tester
236
- */
237
- export const rankWith = (rank: number, tester: Tester) => (
238
- uischema: UISchemaElement,
239
- schema: JsonSchema
240
- ): number => {
241
- if (tester(uischema, schema)) {
242
- return rank;
243
- }
244
-
245
- return NOT_APPLICABLE;
246
- };
247
-
248
- export const withIncreasedRank = (by: number, rankedTester: RankedTester) => (
249
- uischema: UISchemaElement,
250
- schema: JsonSchema
251
- ): number => {
252
- const rank = rankedTester(uischema, schema);
253
- if (rank === NOT_APPLICABLE) {
254
- return NOT_APPLICABLE;
255
- }
256
-
257
- return rank + by;
258
- };
259
-
260
- /**
261
- * Default tester for boolean.
262
- * @type {RankedTester}
263
- */
264
- export const isBooleanControl = and(
265
- uiTypeIs('Control'),
266
- schemaTypeIs('boolean')
267
- );
268
-
269
- // TODO: rather check for properties property
270
- export const isObjectControl = and(uiTypeIs('Control'), schemaTypeIs('object'));
271
-
272
- export const isAllOfControl = and(
273
- uiTypeIs('Control'),
274
- schemaMatches(schema => schema.hasOwnProperty('allOf'))
275
- );
276
-
277
- export const isAnyOfControl = and(
278
- uiTypeIs('Control'),
279
- schemaMatches(schema => schema.hasOwnProperty('anyOf'))
280
- );
281
-
282
- export const isOneOfControl = and(
283
- uiTypeIs('Control'),
284
- schemaMatches(schema => schema.hasOwnProperty('oneOf'))
285
- );
286
-
287
- /**
288
- * Tests whether the given UI schema is of type Control and if the schema
289
- * has a 'date' format.
290
- * @type {Tester}
291
- */
292
- export const isDateControl = and(uiTypeIs('Control'), formatIs('date'));
293
-
294
- /**
295
- * Tests whether the given UI schema is of type Control and if the schema
296
- * has an enum.
297
- * @type {Tester}
298
- */
299
- export const isEnumControl = and(
300
- uiTypeIs('Control'),
301
- or(
302
- schemaMatches(schema => schema.hasOwnProperty('enum')),
303
- schemaMatches(schema => schema.hasOwnProperty('const'))
304
- )
305
- );
306
-
307
- /**
308
- * Tests whether the given UI schema is of type Control and if the schema
309
- * has an enum based on oneOf.
310
- * @type {Tester}
311
- */
312
- export const isOneOfEnumControl = and(
313
- uiTypeIs('Control'),
314
- schemaMatches(schema =>
315
- schema.hasOwnProperty('oneOf') &&
316
- (schema.oneOf as JsonSchema[]).every(s => s.const !== undefined)
317
- )
318
- );
319
-
320
- /**
321
- * Tests whether the given UI schema is of type Control and if the schema
322
- * is of type integer
323
- * @type {Tester}
324
- */
325
- export const isIntegerControl = and(
326
- uiTypeIs('Control'),
327
- schemaTypeIs('integer')
328
- );
329
-
330
- /**
331
- * Tests whether the given UI schema is of type Control and if the schema
332
- * is of type number
333
- * @type {Tester}
334
- */
335
- export const isNumberControl = and(uiTypeIs('Control'), schemaTypeIs('number'));
336
-
337
- /**
338
- * Tests whether the given UI schema is of type Control and if the schema
339
- * is of type string
340
- * @type {Tester}
341
- */
342
- export const isStringControl = and(uiTypeIs('Control'), schemaTypeIs('string'));
343
-
344
- /**
345
- * Tests whether the given UI schema is of type Control and if is has
346
- * a 'multi' option.
347
- * @type {Tester}
348
- */
349
- export const isMultiLineControl = and(
350
- uiTypeIs('Control'),
351
- optionIs('multi', true)
352
- );
353
-
354
- /**
355
- * Tests whether the given UI schema is of type Control and if the schema
356
- * has a 'time' format.
357
- * @type {Tester}
358
- */
359
- export const isTimeControl = and(uiTypeIs('Control'), formatIs('time'));
360
-
361
- /**
362
- * Tests whether the given UI schema is of type Control and if the schema
363
- * has a 'date-time' format.
364
- * @type {Tester}
365
- */
366
- export const isDateTimeControl = and(
367
- uiTypeIs('Control'),
368
- formatIs('date-time')
369
- );
370
-
371
- /**
372
- * Tests whether the given schema is an array of objects.
373
- * @type {Tester}
374
- */
375
- export const isObjectArray = and(
376
- schemaMatches(
377
- schema => hasType(schema, 'array') && !Array.isArray(schema.items) // we don't care about tuples
378
- ),
379
- schemaSubPathMatches('items', schema => hasType(schema, 'object'))
380
- );
381
-
382
- /**
383
- * Tests whether the given UI schema is of type Control and if the schema
384
- * is an array of objects.
385
- * @type {Tester}
386
- */
387
- export const isObjectArrayControl = and(uiTypeIs('Control'), isObjectArray);
388
-
389
- const traverse = (
390
- any: JsonSchema | JsonSchema[],
391
- pred: (obj: JsonSchema) => boolean
392
- ): boolean => {
393
- if (isArray(any)) {
394
- return reduce(any, (acc, el) => acc || traverse(el, pred), false);
395
- }
396
-
397
- if (pred(any)) {
398
- return true;
399
- }
400
- if (any.items) {
401
- return traverse(any.items, pred);
402
- }
403
- if (any.properties) {
404
- return reduce(
405
- toPairs(any.properties),
406
- (acc, [_key, val]) => acc || traverse(val, pred),
407
- false
408
- );
409
- }
410
-
411
- return false;
412
- };
413
-
414
- export const isObjectArrayWithNesting = (
415
- uischema: UISchemaElement,
416
- schema: JsonSchema
417
- ): boolean => {
418
- if (!uiTypeIs('Control')(uischema, schema)) {
419
- return false;
420
- }
421
- const schemaPath = (uischema as ControlElement).scope;
422
- const resolvedSchema = resolveSchema(schema, schemaPath);
423
- const wantedNestingByType: { [key: string]: number } = {
424
- object: 2,
425
- array: 1
426
- };
427
- if (resolvedSchema !== undefined && resolvedSchema.items !== undefined) {
428
- // check if nested arrays
429
- if (
430
- traverse(resolvedSchema.items, val => {
431
- if (val === schema) {
432
- return false;
433
- }
434
- // we don't support multiple types
435
- if (typeof val.type !== 'string') {
436
- return true;
437
- }
438
- const typeCount = wantedNestingByType[val.type];
439
- if (typeCount === undefined) {
440
- return false;
441
- }
442
- wantedNestingByType[val.type] = typeCount - 1;
443
- return wantedNestingByType[val.type] === 0;
444
- })
445
- ) {
446
- return true;
447
- }
448
- // check if uischema options detail is set
449
- if (uischema.options && uischema.options.detail) {
450
- if (typeof uischema.options.detail === 'string') {
451
- return uischema.options.detail.toUpperCase() !== 'DEFAULT';
452
- } else if (
453
- typeof uischema.options.detail === 'object' &&
454
- uischema.options.detail.type
455
- ) {
456
- return true;
457
- }
458
- }
459
- }
460
- return false;
461
- };
462
-
463
- /**
464
- * Synonym for isObjectArrayControl
465
- */
466
- export const isArrayObjectControl = isObjectArrayControl;
467
-
468
- /**
469
- * Tests whether the given UI schema is of type Control and if the schema
470
- * is an array of a primitive type.
471
- * @type {Tester}
472
- */
473
- export const isPrimitiveArrayControl = and(
474
- uiTypeIs('Control'),
475
- schemaMatches(
476
- schema => deriveTypes(schema).length !== 0 && !Array.isArray(schema.items) // we don't care about tuples
477
- ),
478
- schemaSubPathMatches('items', schema => {
479
- const types = deriveTypes(schema);
480
- return (
481
- types.length === 1 &&
482
- includes(['integer', 'number', 'boolean', 'string'], types[0])
483
- );
484
- })
485
- );
486
-
487
- /**
488
- * Tests whether a given UI schema is of type Control,
489
- * if the schema is of type number or integer and
490
- * whether the schema defines a numerical range with a default value.
491
- * @type {Tester}
492
- */
493
- export const isRangeControl = and(
494
- uiTypeIs('Control'),
495
- or(schemaTypeIs('number'), schemaTypeIs('integer')),
496
- schemaMatches(
497
- schema =>
498
- schema.hasOwnProperty('maximum') &&
499
- schema.hasOwnProperty('minimum') &&
500
- schema.hasOwnProperty('default')
501
- ),
502
- optionIs('slider', true)
503
- );
504
-
505
- /**
506
- * Tests whether the given UI schema is of type Control, if the schema
507
- * is of type string and has option format
508
- * @type {Tester}
509
- */
510
- export const isNumberFormatControl = and(
511
- uiTypeIs('Control'),
512
- schemaTypeIs('integer'),
513
- optionIs('format', true)
514
- );
515
-
516
- export const isCategorization = (
517
- category: UISchemaElement
518
- ): category is Categorization => category.type === 'Categorization';
519
-
520
- export const isCategory = (uischema: UISchemaElement): boolean =>
521
- uischema.type === 'Category';
522
-
523
- export const hasCategory = (categorization: Categorization): boolean => {
524
- if (isEmpty(categorization.elements)) {
525
- return false;
526
- }
527
- // all children of the categorization have to be categories
528
- return categorization.elements
529
- .map(elem =>
530
- isCategorization(elem) ? hasCategory(elem) : isCategory(elem)
531
- )
532
- .reduce((prev, curr) => prev && curr, true);
533
- };
534
-
535
- export const categorizationHasCategory = (uischema: UISchemaElement) =>
536
- hasCategory(uischema as Categorization);
537
-
538
- export const not = (tester: Tester): Tester => (
539
- uischema: UISchemaElement,
540
- schema: JsonSchema
541
- ) => !tester(uischema, schema);
26
+ export * from './testers';