@jsonforms/angular 3.1.0-alpha.1 → 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.
- package/README.md +41 -42
- package/lib/cjs/abstract-control.d.ts +1 -1
- package/lib/cjs/abstract-control.js +6 -7
- package/lib/cjs/abstract-control.js.map +1 -1
- package/lib/cjs/abstract-control.metadata.json +1 -1
- package/lib/cjs/array-control.js.map +1 -1
- package/lib/cjs/base.renderer.js +1 -1
- package/lib/cjs/base.renderer.js.map +1 -1
- package/lib/cjs/control.js.map +1 -1
- package/lib/cjs/control.metadata.json +1 -1
- package/lib/cjs/jsonforms-root.component.d.ts +2 -2
- package/lib/cjs/jsonforms-root.component.js +11 -5
- package/lib/cjs/jsonforms-root.component.js.map +1 -1
- package/lib/cjs/jsonforms-root.component.metadata.json +1 -1
- package/lib/cjs/jsonforms.component.js +15 -12
- package/lib/cjs/jsonforms.component.js.map +1 -1
- package/lib/cjs/jsonforms.component.metadata.json +1 -1
- package/lib/cjs/jsonforms.module.js +1 -1
- package/lib/cjs/jsonforms.service.js +26 -6
- package/lib/cjs/jsonforms.service.js.map +1 -1
- package/lib/cjs/unknown.component.js +1 -1
- package/lib/esm/abstract-control.d.ts +1 -1
- package/lib/esm/abstract-control.js +8 -9
- package/lib/esm/abstract-control.js.map +1 -1
- package/lib/esm/abstract-control.metadata.json +1 -1
- package/lib/esm/array-control.js +1 -1
- package/lib/esm/array-control.js.map +1 -1
- package/lib/esm/base.renderer.js +1 -1
- package/lib/esm/base.renderer.js.map +1 -1
- package/lib/esm/control.js +1 -1
- package/lib/esm/control.js.map +1 -1
- package/lib/esm/control.metadata.json +1 -1
- package/lib/esm/jsonforms-root.component.d.ts +2 -2
- package/lib/esm/jsonforms-root.component.js +13 -7
- package/lib/esm/jsonforms-root.component.js.map +1 -1
- package/lib/esm/jsonforms-root.component.metadata.json +1 -1
- package/lib/esm/jsonforms.component.js +17 -14
- package/lib/esm/jsonforms.component.js.map +1 -1
- package/lib/esm/jsonforms.component.metadata.json +1 -1
- package/lib/esm/jsonforms.module.js +1 -1
- package/lib/esm/jsonforms.service.js +27 -7
- package/lib/esm/jsonforms.service.js.map +1 -1
- package/lib/esm/unknown.component.js +1 -1
- package/package.json +17 -6
- package/src/abstract-control.ts +14 -12
- package/src/array-control.ts +3 -2
- package/src/base.renderer.ts +3 -3
- package/src/control.ts +5 -3
- package/src/jsonforms-root.component.ts +158 -130
- package/src/jsonforms.component.ts +35 -20
- package/src/jsonforms.module.ts +1 -1
- package/src/jsonforms.service.ts +244 -173
- package/src/unknown.component.ts +1 -1
package/src/abstract-control.ts
CHANGED
|
@@ -29,14 +29,14 @@ 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
41
|
import type { Subscription } from 'rxjs';
|
|
42
42
|
|
|
@@ -44,11 +44,14 @@ 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
|
-
|
|
51
|
-
>
|
|
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
|
-
|
|
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;
|
package/src/array-control.ts
CHANGED
|
@@ -25,14 +25,15 @@
|
|
|
25
25
|
import {
|
|
26
26
|
JsonFormsState,
|
|
27
27
|
mapStateToArrayControlProps,
|
|
28
|
-
StatePropsOfArrayControl
|
|
28
|
+
StatePropsOfArrayControl,
|
|
29
29
|
} from '@jsonforms/core';
|
|
30
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 };
|
package/src/base.renderer.ts
CHANGED
|
@@ -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 {
|
|
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
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
|
-
|
|
26
|
+
Component,
|
|
27
|
+
DoCheck,
|
|
28
|
+
EventEmitter,
|
|
29
|
+
Input,
|
|
30
|
+
OnChanges,
|
|
31
|
+
OnInit,
|
|
32
|
+
Output,
|
|
33
|
+
SimpleChanges,
|
|
27
34
|
} from '@angular/core';
|
|
28
|
-
import {
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
selector: 'jsonforms',
|
|
51
|
+
template: '<jsonforms-outlet></jsonforms-outlet>',
|
|
52
|
+
providers: [JsonFormsAngularService],
|
|
35
53
|
})
|
|
36
|
-
export class JsonForms implements OnChanges, OnInit {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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,7 +42,7 @@ 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';
|
|
@@ -52,20 +52,27 @@ import { JsonFormsAngularService } from './jsonforms.service';
|
|
|
52
52
|
|
|
53
53
|
import { get, isEqual } from 'lodash';
|
|
54
54
|
|
|
55
|
-
const areEqual = (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
|
68
|
-
|
|
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 =>
|
|
120
|
+
const renderer = maxBy(renderers, (r) =>
|
|
121
|
+
r.tester(uischema, schema, testerContext)
|
|
122
|
+
);
|
|
114
123
|
let bestComponent: Type<any> = UnknownRenderer;
|
|
115
|
-
if (
|
|
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 =
|
|
131
|
+
const componentFactory =
|
|
132
|
+
this.componentFactoryResolver.resolveComponentFactory(bestComponent);
|
|
120
133
|
this.viewContainerRef.clear();
|
|
121
|
-
const currentComponentRef =
|
|
134
|
+
const currentComponentRef =
|
|
135
|
+
this.viewContainerRef.createComponent(componentFactory);
|
|
122
136
|
|
|
123
137
|
if (currentComponentRef.instance instanceof JsonFormsBaseRenderer) {
|
|
124
|
-
const instance =
|
|
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;
|
package/src/jsonforms.module.ts
CHANGED
|
@@ -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 {}
|