@jsonforms/angular 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 (82) hide show
  1. package/README.md +41 -42
  2. package/lib/cjs/abstract-control.d.ts +2 -2
  3. package/lib/cjs/abstract-control.js +6 -7
  4. package/lib/cjs/abstract-control.js.map +1 -1
  5. package/lib/cjs/abstract-control.metadata.json +1 -1
  6. package/lib/cjs/array-control.d.ts +1 -1
  7. package/lib/cjs/array-control.js.map +1 -1
  8. package/lib/cjs/base.renderer.js +1 -1
  9. package/lib/cjs/base.renderer.js.map +1 -1
  10. package/lib/cjs/control.d.ts +1 -1
  11. package/lib/cjs/control.js.map +1 -1
  12. package/lib/cjs/control.metadata.json +1 -1
  13. package/lib/cjs/jsonforms-root.component.d.ts +2 -2
  14. package/lib/cjs/jsonforms-root.component.js +11 -5
  15. package/lib/cjs/jsonforms-root.component.js.map +1 -1
  16. package/lib/cjs/jsonforms-root.component.metadata.json +1 -1
  17. package/lib/cjs/jsonforms.component.js +15 -12
  18. package/lib/cjs/jsonforms.component.js.map +1 -1
  19. package/lib/cjs/jsonforms.component.metadata.json +1 -1
  20. package/lib/cjs/jsonforms.module.js +1 -1
  21. package/lib/cjs/jsonforms.service.d.ts +3 -2
  22. package/lib/cjs/jsonforms.service.js +26 -6
  23. package/lib/cjs/jsonforms.service.js.map +1 -1
  24. package/lib/cjs/unknown.component.js +1 -1
  25. package/lib/esm/abstract-control.d.ts +2 -2
  26. package/lib/esm/abstract-control.js +8 -9
  27. package/lib/esm/abstract-control.js.map +1 -1
  28. package/lib/esm/abstract-control.metadata.json +1 -1
  29. package/lib/esm/array-control.d.ts +1 -1
  30. package/lib/esm/array-control.js +1 -1
  31. package/lib/esm/array-control.js.map +1 -1
  32. package/lib/esm/base.renderer.js +1 -1
  33. package/lib/esm/base.renderer.js.map +1 -1
  34. package/lib/esm/control.d.ts +1 -1
  35. package/lib/esm/control.js +1 -1
  36. package/lib/esm/control.js.map +1 -1
  37. package/lib/esm/control.metadata.json +1 -1
  38. package/lib/esm/jsonforms-root.component.d.ts +2 -2
  39. package/lib/esm/jsonforms-root.component.js +13 -7
  40. package/lib/esm/jsonforms-root.component.js.map +1 -1
  41. package/lib/esm/jsonforms-root.component.metadata.json +1 -1
  42. package/lib/esm/jsonforms.component.js +17 -14
  43. package/lib/esm/jsonforms.component.js.map +1 -1
  44. package/lib/esm/jsonforms.component.metadata.json +1 -1
  45. package/lib/esm/jsonforms.module.js +1 -1
  46. package/lib/esm/jsonforms.service.d.ts +3 -2
  47. package/lib/esm/jsonforms.service.js +27 -7
  48. package/lib/esm/jsonforms.service.js.map +1 -1
  49. package/lib/esm/unknown.component.js +1 -1
  50. package/package.json +21 -6
  51. package/src/abstract-control.ts +15 -13
  52. package/src/array-control.ts +4 -3
  53. package/src/base.renderer.ts +3 -3
  54. package/src/control.ts +6 -4
  55. package/src/jsonforms-root.component.ts +158 -130
  56. package/src/jsonforms.component.ts +36 -21
  57. package/src/jsonforms.module.ts +1 -1
  58. package/src/jsonforms.service.ts +247 -175
  59. package/src/unknown.component.ts +1 -1
  60. package/docs/assets/css/main.css +0 -1
  61. package/docs/assets/images/icons.png +0 -0
  62. package/docs/assets/images/icons@2x.png +0 -0
  63. package/docs/assets/images/widgets.png +0 -0
  64. package/docs/assets/images/widgets@2x.png +0 -0
  65. package/docs/assets/js/main.js +0 -51
  66. package/docs/assets/js/search.json +0 -1
  67. package/docs/classes/jsonforms.html +0 -552
  68. package/docs/classes/jsonformsabstractcontrol.html +0 -772
  69. package/docs/classes/jsonformsangularservice.html +0 -937
  70. package/docs/classes/jsonformsarraycontrol.html +0 -782
  71. package/docs/classes/jsonformsbaserenderer.html +0 -268
  72. package/docs/classes/jsonformscontrol.html +0 -782
  73. package/docs/classes/jsonformscontrolwithdetail.html +0 -782
  74. package/docs/classes/jsonformsmodule.html +0 -164
  75. package/docs/classes/jsonformsoutlet.html +0 -483
  76. package/docs/classes/unknownrenderer.html +0 -164
  77. package/docs/globals.html +0 -225
  78. package/docs/index.html +0 -293
  79. package/test/dummy.test.ts +0 -26
  80. package/test/tsconfig.test.json +0 -18
  81. package/tsconfig.cjs.json +0 -9
  82. package/tsconfig.json +0 -16
@@ -29,7 +29,7 @@ var UnknownRenderer = /** @class */ (function () {
29
29
  UnknownRenderer.decorators = [
30
30
  { type: Component, args: [{
31
31
  selector: 'unknown.renderer',
32
- template: 'No applicable renderer found!'
32
+ template: 'No applicable renderer found!',
33
33
  },] }
34
34
  ];
35
35
  return UnknownRenderer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/angular",
3
- "version": "3.1.0-alpha.0",
3
+ "version": "3.1.0-alpha.2",
4
4
  "description": "Angular module of JSON Forms",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -13,6 +13,10 @@
13
13
  "src": "src",
14
14
  "test": "test"
15
15
  },
16
+ "files": [
17
+ "lib",
18
+ "src"
19
+ ],
16
20
  "keywords": [
17
21
  "angular",
18
22
  "form",
@@ -35,7 +39,8 @@
35
39
  "scripts": {
36
40
  "build": "ngc && ngc -p tsconfig.cjs.json",
37
41
  "clean": "rimraf lib coverage dist .nyc_output 2> /dev/null",
38
- "lint": "tslint --project tsconfig.json --exclude src/models/jsonSchema.ts",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint --fix .",
39
44
  "report": "nyc report --reporter=html",
40
45
  "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} ava",
41
46
  "test-cov": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} nyc ava",
@@ -63,23 +68,33 @@
63
68
  "peerDependencies": {
64
69
  "@angular/core": "^12.0.0 || ^13.0.0 || ^14.0.0",
65
70
  "@angular/forms": "^12.0.0 || ^13.0.0 || ^14.0.0",
66
- "@jsonforms/core": "3.1.0-alpha.0",
71
+ "@jsonforms/core": "3.1.0-alpha.2",
67
72
  "rxjs": "^6.5.3 || ^7.4.0"
68
73
  },
69
74
  "devDependencies": {
75
+ "@angular-eslint/eslint-plugin": "^12.0.0",
76
+ "@angular-eslint/eslint-plugin-template": "^12.0.0",
77
+ "@angular-eslint/schematics": "^12.0.0",
78
+ "@angular-eslint/template-parser": "^12.0.0",
70
79
  "@angular/compiler": "^12.0.0",
71
80
  "@angular/compiler-cli": "^12.0.0",
72
81
  "@angular/core": "^12.0.0",
73
82
  "@angular/forms": "^12.0.0",
74
- "@jsonforms/core": "^3.1.0-alpha.0",
83
+ "@jsonforms/core": "^3.1.0-alpha.2",
84
+ "@typescript-eslint/eslint-plugin": "^5.54.1",
85
+ "@typescript-eslint/parser": "^5.54.1",
75
86
  "ava": "~2.4.0",
76
87
  "copy-webpack-plugin": "^5.0.5",
77
88
  "cross-env": "^7.0.2",
89
+ "eslint": "^7.32.0",
90
+ "eslint-config-prettier": "^8.7.0",
91
+ "eslint-plugin-import": "^2.27.5",
92
+ "eslint-plugin-prettier": "^4.2.1",
78
93
  "nyc": "^15.1.0",
94
+ "prettier": "^2.8.4",
79
95
  "rimraf": "^3.0.2",
80
96
  "rxjs": "^6.5.3",
81
- "tslint": "^5.20.1",
82
97
  "typedoc": "^0.19.2"
83
98
  },
84
- "gitHead": "91f351daa7b7ae4bb0f0dffd47f00bb6cf682ec1"
99
+ "gitHead": "1e1ccad5f7ebfaf80412c8af3e422faebb12d0d5"
85
100
  }
@@ -29,26 +29,29 @@ import {
29
29
  JsonFormsState,
30
30
  JsonSchema,
31
31
  OwnPropsOfControl,
32
- StatePropsOfControl
32
+ StatePropsOfControl,
33
33
  } from '@jsonforms/core';
34
34
  import { Component, Input, OnDestroy, OnInit } from '@angular/core';
35
35
  import {
36
36
  AbstractControl,
37
37
  FormControl,
38
38
  ValidationErrors,
39
- ValidatorFn
39
+ ValidatorFn,
40
40
  } from '@angular/forms';
41
- import { Subscription } from 'rxjs';
41
+ import type { Subscription } from 'rxjs';
42
42
 
43
43
  import { JsonFormsBaseRenderer } from './base.renderer';
44
44
  import { JsonFormsAngularService } from './jsonforms.service';
45
45
  import merge from 'lodash/merge';
46
46
  @Component({
47
- template: ''
47
+ template: '',
48
48
  })
49
49
  export abstract class JsonFormsAbstractControl<
50
- Props extends StatePropsOfControl
51
- > extends JsonFormsBaseRenderer<ControlElement> implements OnInit, OnDestroy {
50
+ Props extends StatePropsOfControl
51
+ >
52
+ extends JsonFormsBaseRenderer<ControlElement>
53
+ implements OnInit, OnDestroy
54
+ {
52
55
  @Input() id: string;
53
56
  @Input() disabled: boolean;
54
57
  @Input() visible: boolean;
@@ -70,11 +73,11 @@ export abstract class JsonFormsAbstractControl<
70
73
  this.form = new FormControl(
71
74
  {
72
75
  value: '',
73
- disabled: true
76
+ disabled: true,
74
77
  },
75
78
  {
76
79
  updateOn: 'change',
77
- validators: this.validator.bind(this)
80
+ validators: this.validator.bind(this),
78
81
  }
79
82
  );
80
83
  }
@@ -108,7 +111,7 @@ export abstract class JsonFormsAbstractControl<
108
111
  rootSchema,
109
112
  visible,
110
113
  path,
111
- config
114
+ config,
112
115
  } = props;
113
116
  this.label = computeLabel(
114
117
  label,
@@ -128,7 +131,7 @@ export abstract class JsonFormsAbstractControl<
128
131
  this.form.setValue(data);
129
132
  this.propsPath = path;
130
133
  this.mapAdditionalProps(props);
131
- }
134
+ },
132
135
  });
133
136
  this.triggerValidation();
134
137
  }
@@ -137,8 +140,7 @@ export abstract class JsonFormsAbstractControl<
137
140
  return this.error ? { error: this.error } : null;
138
141
  };
139
142
 
140
- // @ts-ignore
141
- mapAdditionalProps(props: Props) {
143
+ mapAdditionalProps(_props: Props) {
142
144
  // do nothing by default
143
145
  }
144
146
 
@@ -157,7 +159,7 @@ export abstract class JsonFormsAbstractControl<
157
159
  uischema: this.uischema,
158
160
  schema: this.schema,
159
161
  path: this.path,
160
- id: this.id
162
+ id: this.id,
161
163
  };
162
164
  if (this.disabled !== undefined) {
163
165
  props.enabled = !this.disabled;
@@ -25,14 +25,15 @@
25
25
  import {
26
26
  JsonFormsState,
27
27
  mapStateToArrayControlProps,
28
- StatePropsOfArrayControl
28
+ StatePropsOfArrayControl,
29
29
  } from '@jsonforms/core';
30
- import { OnDestroy, OnInit } from '@angular/core';
30
+ import type { OnDestroy, OnInit } from '@angular/core';
31
31
  import { JsonFormsAbstractControl } from './abstract-control';
32
32
 
33
33
  export class JsonFormsArrayControl
34
34
  extends JsonFormsAbstractControl<StatePropsOfArrayControl>
35
- implements OnInit, OnDestroy {
35
+ implements OnInit, OnDestroy
36
+ {
36
37
  protected mapToProps(state: JsonFormsState): StatePropsOfArrayControl {
37
38
  const props = mapStateToArrayControlProps(state, this.getOwnProps());
38
39
  return { ...props };
@@ -22,11 +22,11 @@
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 { Directive, Input } from '@angular/core';
25
+ import { Directive, Input } from '@angular/core';
26
26
  import {
27
27
  JsonSchema,
28
28
  OwnPropsOfRenderer,
29
- UISchemaElement
29
+ UISchemaElement,
30
30
  } from '@jsonforms/core';
31
31
 
32
32
  @Directive()
@@ -39,7 +39,7 @@ export class JsonFormsBaseRenderer<T extends UISchemaElement> {
39
39
  return {
40
40
  uischema: this.uischema,
41
41
  schema: this.schema,
42
- path: this.path
42
+ path: this.path,
43
43
  };
44
44
  }
45
45
  }
package/src/control.ts CHANGED
@@ -27,14 +27,15 @@ import {
27
27
  mapStateToControlProps,
28
28
  mapStateToControlWithDetailProps,
29
29
  StatePropsOfControl,
30
- StatePropsOfControlWithDetail
30
+ StatePropsOfControlWithDetail,
31
31
  } from '@jsonforms/core';
32
- import { OnDestroy, OnInit } from '@angular/core';
32
+ import type { OnDestroy, OnInit } from '@angular/core';
33
33
  import { JsonFormsAbstractControl } from './abstract-control';
34
34
 
35
35
  export class JsonFormsControl
36
36
  extends JsonFormsAbstractControl<StatePropsOfControl>
37
- implements OnInit, OnDestroy {
37
+ implements OnInit, OnDestroy
38
+ {
38
39
  protected mapToProps(state: JsonFormsState): StatePropsOfControl {
39
40
  const props = mapStateToControlProps(state, this.getOwnProps());
40
41
  return { ...props };
@@ -43,7 +44,8 @@ export class JsonFormsControl
43
44
 
44
45
  export class JsonFormsControlWithDetail
45
46
  extends JsonFormsAbstractControl<StatePropsOfControlWithDetail>
46
- implements OnInit, OnDestroy {
47
+ implements OnInit, OnDestroy
48
+ {
47
49
  protected mapToProps(state: JsonFormsState): StatePropsOfControlWithDetail {
48
50
  const props = mapStateToControlWithDetailProps(state, this.getOwnProps());
49
51
  return { ...props };
@@ -23,146 +23,174 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
  import {
26
- Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges
26
+ Component,
27
+ DoCheck,
28
+ EventEmitter,
29
+ Input,
30
+ OnChanges,
31
+ OnInit,
32
+ Output,
33
+ SimpleChanges,
27
34
  } from '@angular/core';
28
- import { Actions, JsonFormsI18nState, JsonFormsRendererRegistryEntry, JsonSchema, UISchemaElement, UISchemaTester, ValidationMode } from '@jsonforms/core';
35
+ import {
36
+ Actions,
37
+ JsonFormsI18nState,
38
+ JsonFormsRendererRegistryEntry,
39
+ JsonSchema,
40
+ UISchemaElement,
41
+ UISchemaTester,
42
+ ValidationMode,
43
+ } from '@jsonforms/core';
29
44
  import Ajv, { ErrorObject } from 'ajv';
30
45
  import { JsonFormsAngularService, USE_STATE_VALUE } from './jsonforms.service';
46
+
47
+ // TODO Can this be rewritten to not use DoCheck and OnChanges?
48
+ /* eslint-disable @angular-eslint/no-conflicting-lifecycle */
31
49
  @Component({
32
- selector: 'jsonforms',
33
- template: '<jsonforms-outlet></jsonforms-outlet>',
34
- providers: [JsonFormsAngularService]
50
+ selector: 'jsonforms',
51
+ template: '<jsonforms-outlet></jsonforms-outlet>',
52
+ providers: [JsonFormsAngularService],
35
53
  })
36
- export class JsonForms implements OnChanges, OnInit {
37
-
38
- @Input() uischema: UISchemaElement;
39
- @Input() schema: JsonSchema;
40
- @Input() data: any;
41
- @Input() renderers: JsonFormsRendererRegistryEntry[];
42
- @Input() uischemas: { tester: UISchemaTester; uischema: UISchemaElement; }[];
43
- @Output() dataChange = new EventEmitter<any>();
44
- @Input() readonly: boolean;
45
- @Input() validationMode: ValidationMode;
46
- @Input() ajv: Ajv;
47
- @Input() config: any;
48
- @Input() i18n: JsonFormsI18nState;
49
- @Input() additionalErrors: ErrorObject[];
50
- @Output() errors = new EventEmitter<ErrorObject[]>();
51
-
52
- private previousData:any;
53
- private previousErrors:ErrorObject[];
54
-
55
- private initialized = false;
56
- oldI18N: JsonFormsI18nState;
57
-
58
- constructor(private jsonformsService: JsonFormsAngularService) {
54
+ export class JsonForms implements DoCheck, OnChanges, OnInit {
55
+ @Input() uischema: UISchemaElement;
56
+ @Input() schema: JsonSchema;
57
+ @Input() data: any;
58
+ @Input() renderers: JsonFormsRendererRegistryEntry[];
59
+ @Input() uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[];
60
+ @Output() dataChange = new EventEmitter<any>();
61
+ @Input() readonly: boolean;
62
+ @Input() validationMode: ValidationMode;
63
+ @Input() ajv: Ajv;
64
+ @Input() config: any;
65
+ @Input() i18n: JsonFormsI18nState;
66
+ @Input() additionalErrors: ErrorObject[];
67
+ @Output() errors = new EventEmitter<ErrorObject[]>();
68
+
69
+ private previousData: any;
70
+ private previousErrors: ErrorObject[];
71
+
72
+ private initialized = false;
73
+ oldI18N: JsonFormsI18nState;
74
+
75
+ constructor(private jsonformsService: JsonFormsAngularService) {}
76
+
77
+ ngOnInit(): void {
78
+ this.jsonformsService.init({
79
+ core: {
80
+ data: this.data,
81
+ uischema: this.uischema,
82
+ schema: this.schema,
83
+ ajv: this.ajv,
84
+ validationMode: this.validationMode,
85
+ additionalErrors: this.additionalErrors,
86
+ },
87
+ uischemas: this.uischemas,
88
+ i18n: this.i18n,
89
+ renderers: this.renderers,
90
+ config: this.config,
91
+ readonly: this.readonly,
92
+ });
93
+ this.jsonformsService.$state.subscribe((state) => {
94
+ const data = state?.jsonforms?.core?.data;
95
+ const errors = state?.jsonforms?.core?.errors;
96
+ if (this.previousData !== data) {
97
+ this.previousData = data;
98
+ this.dataChange.emit(data);
99
+ }
100
+ if (this.previousErrors !== errors) {
101
+ this.previousErrors = errors;
102
+ this.errors.emit(errors);
103
+ }
104
+ });
105
+ this.oldI18N = this.i18n;
106
+ this.initialized = true;
107
+ }
108
+
109
+ ngDoCheck(): void {
110
+ // we can't use ngOnChanges as then nested i18n changes will not be detected
111
+ // the update will result in a no-op when the parameters did not change
112
+ if (
113
+ this.oldI18N?.locale !== this.i18n?.locale ||
114
+ this.oldI18N?.translate !== this.i18n?.translate ||
115
+ this.oldI18N?.translateError !== this.i18n?.translateError
116
+ ) {
117
+ this.jsonformsService.updateI18n(
118
+ Actions.updateI18n(
119
+ this.oldI18N?.locale === this.i18n?.locale
120
+ ? this.jsonformsService.getState().jsonforms.i18n.locale
121
+ : this.i18n?.locale,
122
+ this.oldI18N?.translate === this.i18n?.translate
123
+ ? this.jsonformsService.getState().jsonforms.i18n.translate
124
+ : this.i18n?.translate,
125
+ this.oldI18N?.translateError === this.i18n?.translateError
126
+ ? this.jsonformsService.getState().jsonforms.i18n.translateError
127
+ : this.i18n?.translateError
128
+ )
129
+ );
130
+ this.oldI18N = this.i18n;
131
+ }
132
+ }
133
+
134
+ ngOnChanges(changes: SimpleChanges): void {
135
+ if (!this.initialized) {
136
+ return;
137
+ }
138
+ const newData = changes.data;
139
+ const newSchema = changes.schema;
140
+ const newUiSchema = changes.uischema;
141
+ const newRenderers = changes.renderers;
142
+ const newUischemas = changes.uischemas;
143
+ const newI18n = changes.i18n;
144
+ const newReadonly = changes.readonly;
145
+ const newValidationMode = changes.validationMode;
146
+ const newAjv = changes.ajv;
147
+ const newConfig = changes.config;
148
+ const newAdditionalErrors = changes.additionalErrors;
149
+
150
+ if (
151
+ newData ||
152
+ newSchema ||
153
+ newUiSchema ||
154
+ newValidationMode ||
155
+ newAjv ||
156
+ newAdditionalErrors
157
+ ) {
158
+ this.jsonformsService.updateCoreState(
159
+ newData ? newData.currentValue : USE_STATE_VALUE,
160
+ newSchema ? newSchema.currentValue : USE_STATE_VALUE,
161
+ newUiSchema ? newUiSchema.currentValue : USE_STATE_VALUE,
162
+ newAjv ? newAjv.currentValue : USE_STATE_VALUE,
163
+ newValidationMode ? newValidationMode.currentValue : USE_STATE_VALUE,
164
+ newAdditionalErrors ? newAdditionalErrors.currentValue : USE_STATE_VALUE
165
+ );
166
+ }
167
+
168
+ if (newRenderers && !newRenderers.isFirstChange()) {
169
+ this.jsonformsService.setRenderers(newRenderers.currentValue);
170
+ }
171
+
172
+ if (newUischemas && !newUischemas.isFirstChange()) {
173
+ this.jsonformsService.setUiSchemas(newUischemas.currentValue);
59
174
  }
60
175
 
61
- ngOnInit(): void {
62
- this.jsonformsService.init({
63
- core: {
64
- data: this.data,
65
- uischema: this.uischema,
66
- schema: this.schema,
67
- ajv: this.ajv,
68
- validationMode: this.validationMode,
69
- additionalErrors: this.additionalErrors
70
- },
71
- uischemas: this.uischemas,
72
- i18n: this.i18n,
73
- renderers: this.renderers,
74
- config: this.config,
75
- readonly: this.readonly
76
- });
77
- this.jsonformsService.$state.subscribe(state => {
78
- const data = state?.jsonforms?.core?.data;
79
- const errors = state?.jsonforms?.core?.errors;
80
- if(this.previousData !== data) {
81
- this.previousData = data;
82
- this.dataChange.emit(data);
83
- }
84
- if(this.previousErrors !== errors) {
85
- this.previousErrors = errors;
86
- this.errors.emit(errors);
87
- }
88
- });
89
- this.oldI18N = this.i18n;
90
- this.initialized = true;
176
+ if (newI18n && !newI18n.isFirstChange()) {
177
+ this.jsonformsService.updateI18n(
178
+ Actions.updateI18n(
179
+ newI18n.currentValue?.locale,
180
+ newI18n.currentValue?.translate,
181
+ newI18n.currentValue?.translateError
182
+ )
183
+ );
91
184
  }
92
185
 
93
- ngDoCheck(): void {
94
- // we can't use ngOnChanges as then nested i18n changes will not be detected
95
- // the update will result in a no-op when the parameters did not change
96
- if (
97
- this.oldI18N?.locale !== this.i18n?.locale ||
98
- this.oldI18N?.translate !== this.i18n?.translate ||
99
- this.oldI18N?.translateError !== this.i18n?.translateError
100
- ) {
101
- this.jsonformsService.updateI18n(
102
- Actions.updateI18n(
103
- this.oldI18N?.locale === this.i18n?.locale
104
- ? this.jsonformsService.getState().jsonforms.i18n.locale
105
- : this.i18n?.locale,
106
- this.oldI18N?.translate === this.i18n?.translate
107
- ? this.jsonformsService.getState().jsonforms.i18n.translate
108
- : this.i18n?.translate,
109
- this.oldI18N?.translateError === this.i18n?.translateError
110
- ? this.jsonformsService.getState().jsonforms.i18n.translateError
111
- : this.i18n?.translateError
112
- )
113
- );
114
- this.oldI18N = this.i18n;
115
- }
186
+ if (newReadonly && !newReadonly.isFirstChange()) {
187
+ this.jsonformsService.setReadonly(newReadonly.currentValue);
116
188
  }
117
189
 
118
- // tslint:disable-next-line: cyclomatic-complexity
119
- ngOnChanges(changes: SimpleChanges): void {
120
- if (!this.initialized) {
121
- return;
122
- }
123
- const newData = changes.data;
124
- const newSchema = changes.schema;
125
- const newUiSchema = changes.uischema;
126
- const newRenderers = changes.renderers;
127
- const newUischemas = changes.uischemas;
128
- const newI18n = changes.i18n;
129
- const newReadonly = changes.readonly;
130
- const newValidationMode = changes.validationMode;
131
- const newAjv = changes.ajv;
132
- const newConfig = changes.config;
133
- const newAdditionalErrors = changes.additionalErrors;
134
-
135
- if (newData || newSchema || newUiSchema || newValidationMode || newAjv || newAdditionalErrors) {
136
- this.jsonformsService.updateCoreState(
137
- newData ? newData.currentValue : USE_STATE_VALUE,
138
- newSchema ? newSchema.currentValue : USE_STATE_VALUE,
139
- newUiSchema ? newUiSchema.currentValue : USE_STATE_VALUE,
140
- newAjv ? newAjv.currentValue : USE_STATE_VALUE,
141
- newValidationMode ? newValidationMode.currentValue : USE_STATE_VALUE,
142
- newAdditionalErrors ? newAdditionalErrors.currentValue : USE_STATE_VALUE
143
- );
144
- }
145
-
146
- if (newRenderers && !newRenderers.isFirstChange()) {
147
- this.jsonformsService.setRenderers(newRenderers.currentValue);
148
- }
149
-
150
- if (newUischemas && !newUischemas.isFirstChange()) {
151
- this.jsonformsService.setUiSchemas(newUischemas.currentValue);
152
- }
153
-
154
- if (newI18n && !newI18n.isFirstChange()) {
155
- this.jsonformsService.updateI18n(
156
- Actions.updateI18n(newI18n.currentValue?.locale, newI18n.currentValue?.translate, newI18n.currentValue?.translateError)
157
- );
158
- }
159
-
160
- if (newReadonly && !newReadonly.isFirstChange()) {
161
- this.jsonformsService.setReadonly(newReadonly.currentValue);
162
- }
163
-
164
- if (newConfig && !newConfig.isFirstChange()) {
165
- this.jsonformsService.updateConfig(Actions.setConfig(newConfig.currentValue));
166
- }
190
+ if (newConfig && !newConfig.isFirstChange()) {
191
+ this.jsonformsService.updateConfig(
192
+ Actions.setConfig(newConfig.currentValue)
193
+ );
167
194
  }
195
+ }
168
196
  }
@@ -30,7 +30,7 @@ import {
30
30
  OnDestroy,
31
31
  OnInit,
32
32
  Type,
33
- ViewContainerRef
33
+ ViewContainerRef,
34
34
  } from '@angular/core';
35
35
  import {
36
36
  createId,
@@ -42,30 +42,37 @@ import {
42
42
  mapStateToJsonFormsRendererProps,
43
43
  OwnPropsOfRenderer,
44
44
  StatePropsOfJsonFormsRenderer,
45
- UISchemaElement
45
+ UISchemaElement,
46
46
  } from '@jsonforms/core';
47
47
  import { UnknownRenderer } from './unknown.component';
48
48
  import { JsonFormsBaseRenderer } from './base.renderer';
49
- import { Subscription } from 'rxjs';
49
+ import type { Subscription } from 'rxjs';
50
50
  import { JsonFormsControl } from './control';
51
51
  import { JsonFormsAngularService } from './jsonforms.service';
52
52
 
53
53
  import { get, isEqual } from 'lodash';
54
54
 
55
- const areEqual = (prevProps: StatePropsOfJsonFormsRenderer, nextProps: StatePropsOfJsonFormsRenderer) => {
56
- return get(prevProps, 'renderers.length') === get(nextProps, 'renderers.length')
57
- && get(prevProps, 'cells.length') === get(nextProps, 'cells.length')
58
- && get(prevProps, 'uischemas.length') === get(nextProps, 'uischemas.length')
59
- && get(prevProps, 'schema') === get(nextProps, 'schema')
60
- && isEqual(get(prevProps, 'uischema'), get(nextProps, 'uischema'))
61
- && get(prevProps, 'path') === get(nextProps, 'path');
55
+ const areEqual = (
56
+ prevProps: StatePropsOfJsonFormsRenderer,
57
+ nextProps: StatePropsOfJsonFormsRenderer
58
+ ) => {
59
+ return (
60
+ get(prevProps, 'renderers.length') === get(nextProps, 'renderers.length') &&
61
+ get(prevProps, 'cells.length') === get(nextProps, 'cells.length') &&
62
+ get(prevProps, 'uischemas.length') === get(nextProps, 'uischemas.length') &&
63
+ get(prevProps, 'schema') === get(nextProps, 'schema') &&
64
+ isEqual(get(prevProps, 'uischema'), get(nextProps, 'uischema')) &&
65
+ get(prevProps, 'path') === get(nextProps, 'path')
66
+ );
62
67
  };
63
68
 
64
69
  @Directive({
65
- selector: 'jsonforms-outlet'
70
+ selector: 'jsonforms-outlet',
66
71
  })
67
- export class JsonFormsOutlet extends JsonFormsBaseRenderer<UISchemaElement>
68
- implements OnInit, OnDestroy {
72
+ export class JsonFormsOutlet
73
+ extends JsonFormsBaseRenderer<UISchemaElement>
74
+ implements OnInit, OnDestroy
75
+ {
69
76
  private subscription: Subscription;
70
77
  private previousProps: StatePropsOfJsonFormsRenderer;
71
78
 
@@ -87,7 +94,7 @@ export class JsonFormsOutlet extends JsonFormsBaseRenderer<UISchemaElement>
87
94
 
88
95
  ngOnInit(): void {
89
96
  this.subscription = this.jsonformsService.$state.subscribe({
90
- next: (state: JsonFormsState) => this.update(state)
97
+ next: (state: JsonFormsState) => this.update(state),
91
98
  });
92
99
  }
93
100
 
@@ -95,7 +102,7 @@ export class JsonFormsOutlet extends JsonFormsBaseRenderer<UISchemaElement>
95
102
  const props = mapStateToJsonFormsRendererProps(state, {
96
103
  schema: this.schema,
97
104
  uischema: this.uischema,
98
- path: this.path
105
+ path: this.path,
99
106
  });
100
107
  if (areEqual(this.previousProps, props)) {
101
108
  return;
@@ -107,21 +114,29 @@ export class JsonFormsOutlet extends JsonFormsBaseRenderer<UISchemaElement>
107
114
  const uischema = this.uischema || props.uischema;
108
115
  const testerContext = {
109
116
  rootSchema: props.rootSchema,
110
- config: getConfig(state)
117
+ config: getConfig(state),
111
118
  };
112
119
 
113
- const renderer = maxBy(renderers, r => r.tester(uischema, schema, testerContext));
120
+ const renderer = maxBy(renderers, (r) =>
121
+ r.tester(uischema, schema, testerContext)
122
+ );
114
123
  let bestComponent: Type<any> = UnknownRenderer;
115
- if (renderer !== undefined && renderer.tester(uischema, schema, testerContext) !== -1) {
124
+ if (
125
+ renderer !== undefined &&
126
+ renderer.tester(uischema, schema, testerContext) !== -1
127
+ ) {
116
128
  bestComponent = renderer.renderer;
117
129
  }
118
130
 
119
- const componentFactory = this.componentFactoryResolver.resolveComponentFactory(bestComponent);
131
+ const componentFactory =
132
+ this.componentFactoryResolver.resolveComponentFactory(bestComponent);
120
133
  this.viewContainerRef.clear();
121
- const currentComponentRef = this.viewContainerRef.createComponent(componentFactory);
134
+ const currentComponentRef =
135
+ this.viewContainerRef.createComponent(componentFactory);
122
136
 
123
137
  if (currentComponentRef.instance instanceof JsonFormsBaseRenderer) {
124
- const instance = currentComponentRef.instance as JsonFormsBaseRenderer<UISchemaElement>;
138
+ const instance =
139
+ currentComponentRef.instance as JsonFormsBaseRenderer<UISchemaElement>;
125
140
  instance.uischema = uischema;
126
141
  instance.schema = schema;
127
142
  instance.path = this.path;
@@ -30,6 +30,6 @@ import { UnknownRenderer } from './unknown.component';
30
30
  @NgModule({
31
31
  declarations: [JsonFormsOutlet, UnknownRenderer, JsonForms],
32
32
  entryComponents: [UnknownRenderer],
33
- exports: [JsonFormsOutlet, JsonForms]
33
+ exports: [JsonFormsOutlet, JsonForms],
34
34
  })
35
35
  export class JsonFormsModule {}