@jsonforms/core 3.1.0-alpha.1 → 3.1.0-alpha.3

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 (47) hide show
  1. package/README.md +3 -3
  2. package/lib/actions/actions.d.ts +21 -21
  3. package/lib/i18n/arrayTranslations.d.ts +24 -0
  4. package/lib/i18n/i18nUtil.d.ts +3 -0
  5. package/lib/i18n/index.d.ts +1 -0
  6. package/lib/jsonforms-core.cjs.js +436 -262
  7. package/lib/jsonforms-core.cjs.js.map +1 -1
  8. package/lib/jsonforms-core.esm.js +318 -201
  9. package/lib/jsonforms-core.esm.js.map +1 -1
  10. package/lib/util/cell.d.ts +0 -1
  11. package/lib/util/renderer.d.ts +6 -2
  12. package/lib/util/schema.d.ts +5 -0
  13. package/package.json +11 -4
  14. package/src/Helpers.ts +1 -1
  15. package/src/actions/actions.ts +52 -55
  16. package/src/configDefault.ts +1 -1
  17. package/src/generators/Generate.ts +3 -1
  18. package/src/generators/schema.ts +29 -25
  19. package/src/generators/uischema.ts +7 -6
  20. package/src/i18n/arrayTranslations.ts +54 -0
  21. package/src/i18n/i18nTypes.ts +10 -6
  22. package/src/i18n/i18nUtil.ts +64 -14
  23. package/src/i18n/index.ts +1 -0
  24. package/src/models/draft4.ts +33 -33
  25. package/src/models/uischema.ts +17 -6
  26. package/src/reducers/cells.ts +8 -7
  27. package/src/reducers/core.ts +119 -75
  28. package/src/reducers/default-data.ts +7 -7
  29. package/src/reducers/i18n.ts +21 -9
  30. package/src/reducers/reducers.ts +20 -30
  31. package/src/reducers/renderers.ts +7 -7
  32. package/src/reducers/selectors.ts +4 -5
  33. package/src/reducers/uischemas.ts +25 -24
  34. package/src/store.ts +1 -1
  35. package/src/testers/testers.ts +202 -148
  36. package/src/util/cell.ts +24 -26
  37. package/src/util/combinators.ts +5 -3
  38. package/src/util/label.ts +1 -1
  39. package/src/util/path.ts +11 -7
  40. package/src/util/renderer.ts +118 -67
  41. package/src/util/resolvers.ts +15 -13
  42. package/src/util/runtime.ts +2 -2
  43. package/src/util/schema.ts +10 -1
  44. package/src/util/type.ts +5 -3
  45. package/src/util/uischema.ts +9 -9
  46. package/src/util/util.ts +52 -52
  47. package/src/util/validator.ts +1 -1
@@ -3,7 +3,6 @@ import type { AnyAction, Dispatch } from './type';
3
3
  import { DispatchPropsOfControl, OwnPropsOfControl, OwnPropsOfEnum, StatePropsOfScopedRenderer } from './renderer';
4
4
  import type { JsonFormsState } from '../store';
5
5
  import type { JsonSchema } from '../models';
6
- export type { JsonFormsCellRendererRegistryEntry };
7
6
  export interface OwnPropsOfCell extends OwnPropsOfControl {
8
7
  data?: any;
9
8
  }
@@ -1,6 +1,5 @@
1
1
  import { ControlElement, JsonSchema, LabelElement, UISchemaElement } from '../models';
2
- import { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry } from '../reducers';
3
- import { JsonFormsUISchemaRegistryEntry } from '../reducers';
2
+ import type { JsonFormsCellRendererRegistryEntry, JsonFormsRendererRegistryEntry, JsonFormsUISchemaRegistryEntry } from '../reducers';
4
3
  import type { RankedTester } from '../testers';
5
4
  import type { CombinatorKeyword } from './combinators';
6
5
  import type { AnyAction, Dispatch } from './type';
@@ -8,6 +7,7 @@ import { CoreActions } from '../actions';
8
7
  import type { ErrorObject } from 'ajv';
9
8
  import type { JsonFormsState } from '../store';
10
9
  import { Translator } from '../i18n';
10
+ import { ArrayTranslations } from '../i18n/arrayTranslations';
11
11
  /**
12
12
  * Adds an asterisk to the given label string based
13
13
  * on the required parameter.
@@ -179,6 +179,7 @@ export interface StatePropsOfControl extends StatePropsOfScopedRenderer {
179
179
  * Whether the rendered data is required.
180
180
  */
181
181
  required?: boolean;
182
+ i18nKeyPrefix?: string;
182
183
  }
183
184
  /**
184
185
  * Dispatch-based props of a Control.
@@ -280,6 +281,7 @@ export interface OwnPropsOfMasterListItem {
280
281
  schema: JsonSchema;
281
282
  handleSelect(index: number): () => void;
282
283
  removeItem(path: string, value: number): () => void;
284
+ translations: ArrayTranslations;
283
285
  }
284
286
  export interface StatePropsOfMasterItem extends OwnPropsOfMasterListItem {
285
287
  childLabel: string;
@@ -298,6 +300,7 @@ export interface ControlWithDetailProps extends StatePropsOfControlWithDetail, D
298
300
  * State-based props of a table control.
299
301
  */
300
302
  export interface StatePropsOfArrayControl extends StatePropsOfControlWithDetail {
303
+ translations: ArrayTranslations;
301
304
  childErrors?: ErrorObject[];
302
305
  }
303
306
  /**
@@ -386,6 +389,7 @@ export declare const mapStateToAnyOfProps: (state: JsonFormsState, ownProps: Own
386
389
  export declare const mapStateToOneOfProps: (state: JsonFormsState, ownProps: OwnPropsOfControl) => StatePropsOfCombinator;
387
390
  export interface StatePropsOfArrayLayout extends StatePropsOfControlWithDetail {
388
391
  data: number;
392
+ translations: ArrayTranslations;
389
393
  minItems?: number;
390
394
  }
391
395
  /**
@@ -1 +1,6 @@
1
+ import { JsonSchema } from '../models';
1
2
  export declare const getFirstPrimitiveProp: (schema: any) => string;
3
+ /**
4
+ * Tests whether the schema has an enum based on oneOf.
5
+ */
6
+ export declare const isOneOfEnumSchema: (schema: JsonSchema) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/core",
3
- "version": "3.1.0-alpha.1",
3
+ "version": "3.1.0-alpha.3",
4
4
  "description": "Core module of JSON Forms",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -39,7 +39,8 @@
39
39
  "scripts": {
40
40
  "build": "rollup -c rollup.config.js",
41
41
  "clean": "rimraf -rf lib coverage dist .nyc_output 2> /dev/null",
42
- "lint": "tslint --project tsconfig.json --exclude src/models/jsonSchema.ts",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint --fix .",
43
44
  "report": "nyc report --reporter=html",
44
45
  "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\",\\\"target\\\":\\\"es5\\\"} ava",
45
46
  "test-cov": "rimraf -rf .nyc_output && cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\",\\\"target\\\":\\\"es5\\\"} nyc ava",
@@ -73,12 +74,19 @@
73
74
  "devDependencies": {
74
75
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
75
76
  "@types/redux-mock-store": "^1.0.1",
77
+ "@typescript-eslint/eslint-plugin": "^5.54.1",
78
+ "@typescript-eslint/parser": "^5.54.1",
76
79
  "ava": "~2.4.0",
77
80
  "cross-env": "^7.0.2",
78
81
  "document-register-element": "^1.14.3",
82
+ "eslint": "^7.32.0",
83
+ "eslint-config-prettier": "^8.7.0",
84
+ "eslint-plugin-import": "^2.27.5",
85
+ "eslint-plugin-prettier": "^4.2.1",
79
86
  "jsdom": "^15.2.1",
80
87
  "jsdom-global": "^3.0.2",
81
88
  "nyc": "^15.1.0",
89
+ "prettier": "^2.8.4",
82
90
  "redux": "^4.0.4",
83
91
  "redux-mock-store": "1.5.3",
84
92
  "rimraf": "^3.0.2",
@@ -88,9 +96,8 @@
88
96
  "rollup-plugin-visualizer": "^5.4.1",
89
97
  "source-map-support": "0.5.16",
90
98
  "ts-node": "^10.4.0",
91
- "tslint": "^5.20.1",
92
99
  "typedoc": "^0.19.2",
93
100
  "typescript": "4.2.3"
94
101
  },
95
- "gitHead": "386174994eabc41758450b8d551e1c859498a468"
102
+ "gitHead": "f8ea38f9f9dd3d46cbfde269ec43e9eb1632e428"
96
103
  }
package/src/Helpers.ts CHANGED
@@ -34,5 +34,5 @@ export const Helpers: {
34
34
  convertToValidClassName(s: string): string;
35
35
  } = {
36
36
  createLabelDescriptionFrom,
37
- convertToValidClassName
37
+ convertToValidClassName,
38
38
  };
@@ -32,34 +32,29 @@ import type { RankedTester } from '../testers';
32
32
  import type { UISchemaTester, ValidationMode } from '../reducers';
33
33
  import type { ErrorTranslator, Translator } from '../i18n';
34
34
 
35
- export const INIT: 'jsonforms/INIT' = 'jsonforms/INIT';
36
- export const UPDATE_CORE: 'jsonforms/UPDATE_CORE' = `jsonforms/UPDATE_CORE`;
37
- export const SET_AJV: 'jsonforms/SET_AJV' = 'jsonforms/SET_AJV';
38
- export const UPDATE_DATA: 'jsonforms/UPDATE' = 'jsonforms/UPDATE';
39
- export const UPDATE_ERRORS: 'jsonforms/UPDATE_ERRORS' =
40
- 'jsonforms/UPDATE_ERRORS';
41
- export const VALIDATE: 'jsonforms/VALIDATE' = 'jsonforms/VALIDATE';
42
- export const ADD_RENDERER: 'jsonforms/ADD_RENDERER' = 'jsonforms/ADD_RENDERER';
43
- export const REMOVE_RENDERER: 'jsonforms/REMOVE_RENDERER' =
44
- 'jsonforms/REMOVE_RENDERER';
45
- export const ADD_CELL: 'jsonforms/ADD_CELL' = 'jsonforms/ADD_CELL';
46
- export const REMOVE_CELL: 'jsonforms/REMOVE_CELL' = 'jsonforms/REMOVE_CELL';
47
- export const SET_CONFIG: 'jsonforms/SET_CONFIG' = 'jsonforms/SET_CONFIG';
48
- export const ADD_UI_SCHEMA: 'jsonforms/ADD_UI_SCHEMA' = `jsonforms/ADD_UI_SCHEMA`;
49
- export const REMOVE_UI_SCHEMA: 'jsonforms/REMOVE_UI_SCHEMA' = `jsonforms/REMOVE_UI_SCHEMA`;
50
- export const SET_SCHEMA: 'jsonforms/SET_SCHEMA' = `jsonforms/SET_SCHEMA`;
51
- export const SET_UISCHEMA: 'jsonforms/SET_UISCHEMA' = `jsonforms/SET_UISCHEMA`;
52
- export const SET_VALIDATION_MODE: 'jsonforms/SET_VALIDATION_MODE' =
53
- 'jsonforms/SET_VALIDATION_MODE';
54
-
55
- export const SET_LOCALE: 'jsonforms/SET_LOCALE' = `jsonforms/SET_LOCALE`;
56
- export const SET_TRANSLATOR: 'jsonforms/SET_TRANSLATOR' =
57
- 'jsonforms/SET_TRANSLATOR';
58
- export const UPDATE_I18N: 'jsonforms/UPDATE_I18N' =
59
- 'jsonforms/UPDATE_I18N';
60
-
61
- export const ADD_DEFAULT_DATA: 'jsonforms/ADD_DEFAULT_DATA' = `jsonforms/ADD_DEFAULT_DATA`;
62
- export const REMOVE_DEFAULT_DATA: 'jsonforms/REMOVE_DEFAULT_DATA' = `jsonforms/REMOVE_DEFAULT_DATA`;
35
+ export const INIT = 'jsonforms/INIT' as const;
36
+ export const UPDATE_CORE = 'jsonforms/UPDATE_CORE' as const;
37
+ export const SET_AJV = 'jsonforms/SET_AJV' as const;
38
+ export const UPDATE_DATA = 'jsonforms/UPDATE' as const;
39
+ export const UPDATE_ERRORS = 'jsonforms/UPDATE_ERRORS' as const;
40
+ export const VALIDATE = 'jsonforms/VALIDATE' as const;
41
+ export const ADD_RENDERER = 'jsonforms/ADD_RENDERER' as const;
42
+ export const REMOVE_RENDERER = 'jsonforms/REMOVE_RENDERER' as const;
43
+ export const ADD_CELL = 'jsonforms/ADD_CELL' as const;
44
+ export const REMOVE_CELL = 'jsonforms/REMOVE_CELL' as const;
45
+ export const SET_CONFIG = 'jsonforms/SET_CONFIG' as const;
46
+ export const ADD_UI_SCHEMA = 'jsonforms/ADD_UI_SCHEMA' as const;
47
+ export const REMOVE_UI_SCHEMA = 'jsonforms/REMOVE_UI_SCHEMA' as const;
48
+ export const SET_SCHEMA = 'jsonforms/SET_SCHEMA' as const;
49
+ export const SET_UISCHEMA = 'jsonforms/SET_UISCHEMA' as const;
50
+ export const SET_VALIDATION_MODE = 'jsonforms/SET_VALIDATION_MODE' as const;
51
+
52
+ export const SET_LOCALE = 'jsonforms/SET_LOCALE' as const;
53
+ export const SET_TRANSLATOR = 'jsonforms/SET_TRANSLATOR' as const;
54
+ export const UPDATE_I18N = 'jsonforms/UPDATE_I18N' as const;
55
+
56
+ export const ADD_DEFAULT_DATA = 'jsonforms/ADD_DEFAULT_DATA' as const;
57
+ export const REMOVE_DEFAULT_DATA = 'jsonforms/REMOVE_DEFAULT_DATA' as const;
63
58
 
64
59
  export type CoreActions =
65
60
  | InitAction
@@ -105,8 +100,8 @@ export interface InitActionOptions {
105
100
  }
106
101
 
107
102
  export interface SetValidationModeAction {
108
- type: 'jsonforms/SET_VALIDATION_MODE'
109
- validationMode: ValidationMode
103
+ type: 'jsonforms/SET_VALIDATION_MODE';
104
+ validationMode: ValidationMode;
110
105
  }
111
106
 
112
107
  export const init = (
@@ -120,7 +115,7 @@ export const init = (
120
115
  schema,
121
116
  uischema:
122
117
  typeof uischema === 'object' ? uischema : generateDefaultUISchema(schema),
123
- options
118
+ options,
124
119
  });
125
120
 
126
121
  export const updateCore = (
@@ -133,7 +128,7 @@ export const updateCore = (
133
128
  data,
134
129
  schema,
135
130
  uischema,
136
- options
131
+ options,
137
132
  });
138
133
 
139
134
  export interface RegisterDefaultDataAction {
@@ -145,7 +140,7 @@ export interface RegisterDefaultDataAction {
145
140
  export const registerDefaultData = (schemaPath: string, data: any) => ({
146
141
  type: ADD_DEFAULT_DATA,
147
142
  schemaPath,
148
- data
143
+ data,
149
144
  });
150
145
 
151
146
  export interface UnregisterDefaultDataAction {
@@ -155,7 +150,7 @@ export interface UnregisterDefaultDataAction {
155
150
 
156
151
  export const unregisterDefaultData = (schemaPath: string) => ({
157
152
  type: REMOVE_DEFAULT_DATA,
158
- schemaPath
153
+ schemaPath,
159
154
  });
160
155
 
161
156
  export interface SetAjvAction {
@@ -165,7 +160,7 @@ export interface SetAjvAction {
165
160
 
166
161
  export const setAjv = (ajv: AJV) => ({
167
162
  type: SET_AJV,
168
- ajv
163
+ ajv,
169
164
  });
170
165
 
171
166
  export const update = (
@@ -174,12 +169,12 @@ export const update = (
174
169
  ): UpdateAction => ({
175
170
  type: UPDATE_DATA,
176
171
  path,
177
- updater
172
+ updater,
178
173
  });
179
174
 
180
175
  export const updateErrors = (errors: ErrorObject[]): UpdateErrorsAction => ({
181
176
  type: UPDATE_ERRORS,
182
- errors
177
+ errors,
183
178
  });
184
179
 
185
180
  export interface AddRendererAction {
@@ -191,7 +186,7 @@ export interface AddRendererAction {
191
186
  export const registerRenderer = (tester: RankedTester, renderer: any) => ({
192
187
  type: ADD_RENDERER,
193
188
  tester,
194
- renderer
189
+ renderer,
195
190
  });
196
191
 
197
192
  export interface AddCellRendererAction {
@@ -203,7 +198,7 @@ export interface AddCellRendererAction {
203
198
  export const registerCell = (tester: RankedTester, cell: any) => ({
204
199
  type: ADD_CELL,
205
200
  tester,
206
- cell
201
+ cell,
207
202
  });
208
203
 
209
204
  export interface RemoveCellRendererAction {
@@ -215,7 +210,7 @@ export interface RemoveCellRendererAction {
215
210
  export const unregisterCell = (tester: RankedTester, cell: any) => ({
216
211
  type: REMOVE_CELL,
217
212
  tester,
218
- cell
213
+ cell,
219
214
  });
220
215
 
221
216
  export interface RemoveRendererAction {
@@ -227,7 +222,7 @@ export interface RemoveRendererAction {
227
222
  export const unregisterRenderer = (tester: RankedTester, renderer: any) => ({
228
223
  type: REMOVE_RENDERER,
229
224
  tester,
230
- renderer
225
+ renderer,
231
226
  });
232
227
 
233
228
  export interface SetConfigAction {
@@ -237,13 +232,15 @@ export interface SetConfigAction {
237
232
 
238
233
  export const setConfig = (config: any): SetConfigAction => ({
239
234
  type: SET_CONFIG,
240
- config
235
+ config,
241
236
  });
242
237
 
243
- export const setValidationMode = (validationMode: ValidationMode): SetValidationModeAction => ({
238
+ export const setValidationMode = (
239
+ validationMode: ValidationMode
240
+ ): SetValidationModeAction => ({
244
241
  type: SET_VALIDATION_MODE,
245
- validationMode
246
- })
242
+ validationMode,
243
+ });
247
244
 
248
245
  export type UISchemaActions = AddUISchemaAction | RemoveUISchemaAction;
249
246
 
@@ -260,7 +257,7 @@ export const registerUISchema = (
260
257
  return {
261
258
  type: ADD_UI_SCHEMA,
262
259
  tester,
263
- uischema
260
+ uischema,
264
261
  };
265
262
  };
266
263
 
@@ -274,14 +271,14 @@ export const unregisterUISchema = (
274
271
  ): RemoveUISchemaAction => {
275
272
  return {
276
273
  type: REMOVE_UI_SCHEMA,
277
- tester
274
+ tester,
278
275
  };
279
276
  };
280
277
 
281
278
  export type I18nActions =
282
279
  | SetLocaleAction
283
280
  | SetTranslatorAction
284
- | UpdateI18nAction
281
+ | UpdateI18nAction;
285
282
 
286
283
  export interface SetLocaleAction {
287
284
  type: 'jsonforms/SET_LOCALE';
@@ -290,7 +287,7 @@ export interface SetLocaleAction {
290
287
 
291
288
  export const setLocale = (locale: string | undefined): SetLocaleAction => ({
292
289
  type: SET_LOCALE,
293
- locale
290
+ locale,
294
291
  });
295
292
 
296
293
  export interface SetSchemaAction {
@@ -300,13 +297,13 @@ export interface SetSchemaAction {
300
297
 
301
298
  export const setSchema = (schema: JsonSchema): SetSchemaAction => ({
302
299
  type: SET_SCHEMA,
303
- schema
300
+ schema,
304
301
  });
305
302
 
306
303
  export interface SetTranslatorAction {
307
304
  type: 'jsonforms/SET_TRANSLATOR';
308
305
  translator?: Translator;
309
- errorTranslator?: ErrorTranslator;
306
+ errorTranslator?: ErrorTranslator;
310
307
  }
311
308
 
312
309
  export const setTranslator = (
@@ -315,14 +312,14 @@ export const setTranslator = (
315
312
  ): SetTranslatorAction => ({
316
313
  type: SET_TRANSLATOR,
317
314
  translator,
318
- errorTranslator
315
+ errorTranslator,
319
316
  });
320
317
 
321
318
  export interface UpdateI18nAction {
322
319
  type: 'jsonforms/UPDATE_I18N';
323
320
  locale: string | undefined;
324
321
  translator: Translator | undefined;
325
- errorTranslator: ErrorTranslator | undefined;
322
+ errorTranslator: ErrorTranslator | undefined;
326
323
  }
327
324
 
328
325
  export const updateI18n = (
@@ -333,7 +330,7 @@ export const updateI18n = (
333
330
  type: UPDATE_I18N,
334
331
  locale,
335
332
  translator,
336
- errorTranslator
333
+ errorTranslator,
337
334
  });
338
335
 
339
336
  export interface SetUISchemaAction {
@@ -343,5 +340,5 @@ export interface SetUISchemaAction {
343
340
 
344
341
  export const setUISchema = (uischema: UISchemaElement): SetUISchemaAction => ({
345
342
  type: SET_UISCHEMA,
346
- uischema
343
+ uischema,
347
344
  });
@@ -44,5 +44,5 @@ export const configDefault = {
44
44
  /*
45
45
  * [text] if asterisks in labels for required fields should be hidden
46
46
  */
47
- hideRequiredAsterisk: false
47
+ hideRequiredAsterisk: false,
48
48
  };
@@ -28,6 +28,8 @@ import { createControlElement, generateDefaultUISchema } from './uischema';
28
28
  import type { ControlElement, JsonSchema, UISchemaElement } from '../';
29
29
 
30
30
  export const Generate: {
31
+ // TODO fix @typescript-eslint/ban-types
32
+ // eslint-disable-next-line @typescript-eslint/ban-types
31
33
  jsonSchema(instance: Object, options?: any): JsonSchema;
32
34
  uiSchema(
33
35
  jsonSchema: JsonSchema,
@@ -39,5 +41,5 @@ export const Generate: {
39
41
  } = {
40
42
  jsonSchema: generateJsonSchema,
41
43
  uiSchema: generateDefaultUISchema,
42
- controlElement: createControlElement
44
+ controlElement: createControlElement,
43
45
  };
@@ -36,7 +36,7 @@ const distinct = (
36
36
  ): JsonSchema4[] => {
37
37
  const known: { [property: string]: boolean } = {};
38
38
 
39
- return properties.filter(item => {
39
+ return properties.filter((item) => {
40
40
  const discriminatorValue = discriminator(item);
41
41
  if (known.hasOwnProperty(discriminatorValue)) {
42
42
  return false;
@@ -52,12 +52,14 @@ class Gen {
52
52
  private findOption: (props: Properties) => (optionName: string) => any
53
53
  ) {}
54
54
 
55
+ // TODO fix @typescript-eslint/ban-types
56
+ // eslint-disable-next-line @typescript-eslint/ban-types
55
57
  schemaObject = (data: Object): JsonSchema4 => {
56
58
  const props: Properties = this.properties(data);
57
59
  const schema: JsonSchema4 = {
58
60
  type: 'object',
59
61
  properties: props,
60
- additionalProperties: this.findOption(props)(ADDITIONAL_PROPERTIES)
62
+ additionalProperties: this.findOption(props)(ADDITIONAL_PROPERTIES),
61
63
  };
62
64
  const required = this.findOption(props)(REQUIRED_PROPERTIES);
63
65
  if (required.length > 0) {
@@ -111,26 +113,26 @@ class Gen {
111
113
  schemaArray = (data: any[]): JsonSchema4 => {
112
114
  if (data.length > 0) {
113
115
  const allProperties: JsonSchema4[] = data.map(this.property);
114
- const uniqueProperties = distinct(allProperties, prop =>
116
+ const uniqueProperties = distinct(allProperties, (prop) =>
115
117
  JSON.stringify(prop)
116
118
  );
117
119
  if (uniqueProperties.length === 1) {
118
120
  return {
119
121
  type: 'array',
120
- items: uniqueProperties[0]
122
+ items: uniqueProperties[0],
121
123
  };
122
124
  } else {
123
125
  return {
124
126
  type: 'array',
125
127
  items: {
126
- oneOf: uniqueProperties
127
- }
128
+ oneOf: uniqueProperties,
129
+ },
128
130
  };
129
131
  }
130
132
  } else {
131
133
  return {
132
134
  type: 'array',
133
- items: {}
135
+ items: {},
134
136
  };
135
137
  }
136
138
  };
@@ -143,29 +145,31 @@ class Gen {
143
145
  * @returns {JsonSchema} the generated schema
144
146
  */
145
147
  export const generateJsonSchema = (
148
+ // TODO fix @typescript-eslint/ban-types
149
+ // eslint-disable-next-line @typescript-eslint/ban-types
146
150
  instance: Object,
147
151
  options: any = {}
148
152
  ): JsonSchema4 => {
149
- const findOption = (props: Properties) => (
150
- optionName: string
151
- ): boolean | string[] => {
152
- switch (optionName) {
153
- case ADDITIONAL_PROPERTIES:
154
- if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
155
- return options[ADDITIONAL_PROPERTIES];
156
- }
153
+ const findOption =
154
+ (props: Properties) =>
155
+ (optionName: string): boolean | string[] => {
156
+ switch (optionName) {
157
+ case ADDITIONAL_PROPERTIES:
158
+ if (options.hasOwnProperty(ADDITIONAL_PROPERTIES)) {
159
+ return options[ADDITIONAL_PROPERTIES];
160
+ }
157
161
 
158
- return true;
159
- case REQUIRED_PROPERTIES:
160
- if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
161
- return options[REQUIRED_PROPERTIES](props);
162
- }
162
+ return true;
163
+ case REQUIRED_PROPERTIES:
164
+ if (options.hasOwnProperty(REQUIRED_PROPERTIES)) {
165
+ return options[REQUIRED_PROPERTIES](props);
166
+ }
163
167
 
164
- return Object.keys(props);
165
- default:
166
- return;
167
- }
168
- };
168
+ return Object.keys(props);
169
+ default:
170
+ return;
171
+ }
172
+ };
169
173
 
170
174
  const gen = new Gen(findOption);
171
175
 
@@ -33,7 +33,7 @@ import {
33
33
  JsonSchema,
34
34
  LabelElement,
35
35
  Layout,
36
- UISchemaElement
36
+ UISchemaElement,
37
37
  } from '../models';
38
38
  import { deriveTypes, encode, resolveSchema } from '../util';
39
39
 
@@ -44,7 +44,7 @@ import { deriveTypes, encode, resolveSchema } from '../util';
44
44
  */
45
45
  const createLayout = (layoutType: string): Layout => ({
46
46
  type: layoutType,
47
- elements: []
47
+ elements: [],
48
48
  });
49
49
 
50
50
  /**
@@ -52,7 +52,7 @@ const createLayout = (layoutType: string): Layout => ({
52
52
  */
53
53
  export const createControlElement = (ref: string): ControlElement => ({
54
54
  type: 'Control',
55
- scope: ref
55
+ scope: ref,
56
56
  });
57
57
 
58
58
  /**
@@ -91,7 +91,7 @@ const addLabel = (layout: Layout, labelName: string) => {
91
91
  // add label with name
92
92
  const label: LabelElement = {
93
93
  type: 'Label',
94
- text: fixedLabel
94
+ text: fixedLabel,
95
95
  };
96
96
  layout.elements.push(label);
97
97
  }
@@ -160,7 +160,7 @@ const generateUISchema = (
160
160
  if (!isEmpty(jsonSchema.properties)) {
161
161
  // traverse properties
162
162
  const nextRef: string = currentRef + '/properties';
163
- Object.keys(jsonSchema.properties).map(propName => {
163
+ Object.keys(jsonSchema.properties).map((propName) => {
164
164
  let value = jsonSchema.properties[propName];
165
165
  const ref = `${nextRef}/${encode(propName)}`;
166
166
  if (value.$ref !== undefined) {
@@ -191,11 +191,12 @@ const generateUISchema = (
191
191
  /* falls through */
192
192
  case 'integer':
193
193
  /* falls through */
194
- case 'boolean':
194
+ case 'boolean': {
195
195
  const controlObject: ControlElement = createControlElement(currentRef);
196
196
  schemaElements.push(controlObject);
197
197
 
198
198
  return controlObject;
199
+ }
199
200
  default:
200
201
  throw new Error('Unknown type: ' + JSON.stringify(jsonSchema));
201
202
  }
@@ -0,0 +1,54 @@
1
+ export interface ArrayDefaultTranslation {
2
+ key: ArrayTranslationEnum;
3
+ default: (variable?: string) => string;
4
+ }
5
+
6
+ export enum ArrayTranslationEnum {
7
+ addTooltip = 'addTooltip',
8
+ addAriaLabel = 'addAriaLabel',
9
+ removeTooltip = 'removeTooltip',
10
+ upAriaLabel = 'upAriaLabel',
11
+ downAriaLabel = 'downAriaLabel',
12
+ noSelection = 'noSelection',
13
+ removeAriaLabel = 'removeAriaLabel',
14
+ noDataMessage = 'noDataMessage',
15
+ deleteDialogTitle = 'deleteDialogTitle',
16
+ deleteDialogMessage = 'deleteDialogMessage',
17
+ deleteDialogAccept = 'deleteDialogAccept',
18
+ deleteDialogDecline = 'deleteDialogDecline',
19
+ up = 'up',
20
+ down = 'down',
21
+ }
22
+
23
+ export type ArrayTranslations = {
24
+ [key in ArrayTranslationEnum]?: string;
25
+ };
26
+
27
+ export const arrayDefaultTranslations: ArrayDefaultTranslation[] = [
28
+ {
29
+ key: ArrayTranslationEnum.addTooltip,
30
+ default: (input) => (input ? `Add to ${input}` : 'Add'),
31
+ },
32
+ {
33
+ key: ArrayTranslationEnum.addAriaLabel,
34
+ default: (input) => (input ? `Add to ${input} button` : 'Add button'),
35
+ },
36
+ { key: ArrayTranslationEnum.removeTooltip, default: () => 'Delete' },
37
+ { key: ArrayTranslationEnum.removeAriaLabel, default: () => 'Delete button' },
38
+ { key: ArrayTranslationEnum.upAriaLabel, default: () => `Move item up` },
39
+ { key: ArrayTranslationEnum.up, default: () => 'Up' },
40
+ { key: ArrayTranslationEnum.down, default: () => 'Down' },
41
+ { key: ArrayTranslationEnum.downAriaLabel, default: () => `Move item down` },
42
+ { key: ArrayTranslationEnum.noDataMessage, default: () => 'No data' },
43
+ { key: ArrayTranslationEnum.noSelection, default: () => 'No selection' },
44
+ {
45
+ key: ArrayTranslationEnum.deleteDialogTitle,
46
+ default: () => 'Confirm Deletion',
47
+ },
48
+ {
49
+ key: ArrayTranslationEnum.deleteDialogMessage,
50
+ default: () => 'Are you sure you want to delete the selected entry?',
51
+ },
52
+ { key: ArrayTranslationEnum.deleteDialogAccept, default: () => 'Yes' },
53
+ { key: ArrayTranslationEnum.deleteDialogDecline, default: () => 'No' },
54
+ ];
@@ -2,12 +2,16 @@ import type { ErrorObject } from 'ajv';
2
2
  import type { JsonSchema, UISchemaElement } from '../models';
3
3
 
4
4
  export type Translator = {
5
- (id: string, defaultMessage: string, values?: any): string;
6
- (id: string, defaultMessage: undefined, values?: any): string | undefined;
7
- (id: string, defaultMessage?: string, values?: any): string | undefined;
8
- }
5
+ (id: string, defaultMessage: string, values?: any): string;
6
+ (id: string, defaultMessage: undefined, values?: any): string | undefined;
7
+ (id: string, defaultMessage?: string, values?: any): string | undefined;
8
+ };
9
9
 
10
- export type ErrorTranslator = (error: ErrorObject, translate: Translator, uischema?: UISchemaElement) => string;
10
+ export type ErrorTranslator = (
11
+ error: ErrorObject,
12
+ translate: Translator,
13
+ uischema?: UISchemaElement
14
+ ) => string;
11
15
 
12
16
  export interface JsonFormsI18nState {
13
17
  locale?: string;
@@ -15,4 +19,4 @@ export interface JsonFormsI18nState {
15
19
  translateError?: ErrorTranslator;
16
20
  }
17
21
 
18
- export type i18nJsonSchema = JsonSchema & {i18n?: string};
22
+ export type i18nJsonSchema = JsonSchema & { i18n?: string };