@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/jsonforms.service.ts
CHANGED
|
@@ -23,27 +23,27 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
Actions,
|
|
27
|
+
configReducer,
|
|
28
|
+
CoreActions,
|
|
29
|
+
coreReducer,
|
|
30
|
+
generateDefaultUISchema,
|
|
31
|
+
generateJsonSchema,
|
|
32
|
+
i18nReducer,
|
|
33
|
+
JsonFormsRendererRegistryEntry,
|
|
34
|
+
JsonFormsState,
|
|
35
|
+
JsonFormsSubStates,
|
|
36
|
+
JsonSchema,
|
|
37
|
+
I18nActions,
|
|
38
|
+
RankedTester,
|
|
39
|
+
setConfig,
|
|
40
|
+
SetConfigAction,
|
|
41
|
+
UISchemaActions,
|
|
42
|
+
UISchemaElement,
|
|
43
|
+
uischemaRegistryReducer,
|
|
44
|
+
UISchemaTester,
|
|
45
|
+
ValidationMode,
|
|
46
|
+
updateI18n,
|
|
47
47
|
} from '@jsonforms/core';
|
|
48
48
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
49
49
|
import type { JsonFormsBaseRenderer } from './base.renderer';
|
|
@@ -54,186 +54,257 @@ import type { ErrorObject } from 'ajv';
|
|
|
54
54
|
|
|
55
55
|
export const USE_STATE_VALUE = Symbol('Marker to use state value');
|
|
56
56
|
export class JsonFormsAngularService {
|
|
57
|
+
private _state: JsonFormsSubStates;
|
|
58
|
+
private state: BehaviorSubject<JsonFormsState>;
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const schema = initialState.core.schema ?? generateJsonSchema(data);
|
|
68
|
-
const uischema = initialState.core.uischema ?? generateDefaultUISchema(schema);
|
|
69
|
-
this.updateCore(Actions.init(data, schema, uischema));
|
|
60
|
+
init(
|
|
61
|
+
initialState: JsonFormsSubStates = {
|
|
62
|
+
core: {
|
|
63
|
+
data: undefined,
|
|
64
|
+
schema: undefined,
|
|
65
|
+
uischema: undefined,
|
|
66
|
+
validationMode: 'ValidateAndShow',
|
|
67
|
+
additionalErrors: undefined,
|
|
68
|
+
},
|
|
70
69
|
}
|
|
70
|
+
) {
|
|
71
|
+
this._state = initialState;
|
|
72
|
+
this._state.config = configReducer(
|
|
73
|
+
undefined,
|
|
74
|
+
setConfig(this._state.config)
|
|
75
|
+
);
|
|
76
|
+
this._state.i18n = i18nReducer(
|
|
77
|
+
this._state.i18n,
|
|
78
|
+
updateI18n(
|
|
79
|
+
this._state.i18n?.locale,
|
|
80
|
+
this._state.i18n?.translate,
|
|
81
|
+
this._state.i18n?.translateError
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
this.state = new BehaviorSubject({ jsonforms: this._state });
|
|
85
|
+
const data = initialState.core.data;
|
|
86
|
+
const schema = initialState.core.schema ?? generateJsonSchema(data);
|
|
87
|
+
const uischema =
|
|
88
|
+
initialState.core.uischema ?? generateDefaultUISchema(schema);
|
|
89
|
+
this.updateCore(Actions.init(data, schema, uischema));
|
|
90
|
+
}
|
|
71
91
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
return this.state.asObservable();
|
|
92
|
+
get $state(): Observable<JsonFormsState> {
|
|
93
|
+
if (!this.state) {
|
|
94
|
+
throw new Error('Please call init first!');
|
|
77
95
|
}
|
|
96
|
+
return this.state.asObservable();
|
|
97
|
+
}
|
|
78
98
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
/**
|
|
100
|
+
* @deprecated use {@link JsonFormsAngularService.addRenderer}
|
|
101
|
+
*/
|
|
102
|
+
registerRenderer(
|
|
103
|
+
renderer: JsonFormsBaseRenderer<UISchemaElement>,
|
|
104
|
+
tester: RankedTester
|
|
105
|
+
): void {
|
|
106
|
+
this.addRenderer(renderer, tester);
|
|
107
|
+
}
|
|
108
|
+
addRenderer(
|
|
109
|
+
renderer: JsonFormsBaseRenderer<UISchemaElement>,
|
|
110
|
+
tester: RankedTester
|
|
111
|
+
): void {
|
|
112
|
+
this._state.renderers.push({ renderer, tester });
|
|
113
|
+
this.updateSubject();
|
|
114
|
+
}
|
|
89
115
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated use {@link JsonFormsAngularService.setRenderer}
|
|
118
|
+
*/
|
|
119
|
+
registerRenderers(renderers: JsonFormsRendererRegistryEntry[]): void {
|
|
120
|
+
this.setRenderers(renderers);
|
|
121
|
+
}
|
|
122
|
+
setRenderers(renderers: JsonFormsRendererRegistryEntry[]): void {
|
|
123
|
+
this._state.renderers = renderers;
|
|
124
|
+
this.updateSubject();
|
|
125
|
+
}
|
|
100
126
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this._state.renderers = renderers;
|
|
114
|
-
this.updateSubject();
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated use {@link JsonFormsAngularService.removeRenderer}
|
|
129
|
+
*/
|
|
130
|
+
unregisterRenderer(tester: RankedTester): void {
|
|
131
|
+
this.removeRenderer(tester);
|
|
132
|
+
}
|
|
133
|
+
removeRenderer(tester: RankedTester): void {
|
|
134
|
+
const findIndex = this._state.renderers.findIndex(
|
|
135
|
+
(v) => v.tester === tester
|
|
136
|
+
);
|
|
137
|
+
if (findIndex === -1) {
|
|
138
|
+
return;
|
|
115
139
|
}
|
|
140
|
+
const renderers = this._state.renderers.filter((v) => v.tester !== tester);
|
|
141
|
+
this._state.renderers = renderers;
|
|
142
|
+
this.updateSubject();
|
|
143
|
+
}
|
|
116
144
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (i18nState !== this._state.i18n) {
|
|
126
|
-
this._state.i18n = i18nState;
|
|
127
|
-
this.updateSubject();
|
|
128
|
-
}
|
|
129
|
-
return i18nAction;
|
|
130
|
-
}
|
|
145
|
+
updateValidationMode(validationMode: ValidationMode): void {
|
|
146
|
+
const coreState = coreReducer(
|
|
147
|
+
this._state.core,
|
|
148
|
+
Actions.setValidationMode(validationMode)
|
|
149
|
+
);
|
|
150
|
+
this._state.core = coreState;
|
|
151
|
+
this.updateSubject();
|
|
152
|
+
}
|
|
131
153
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return coreAction;
|
|
154
|
+
updateI18n<T extends I18nActions>(i18nAction: T): T {
|
|
155
|
+
const i18nState = i18nReducer(this._state.i18n, i18nAction);
|
|
156
|
+
if (i18nState !== this._state.i18n) {
|
|
157
|
+
this._state.i18n = i18nState;
|
|
158
|
+
this.updateSubject();
|
|
139
159
|
}
|
|
160
|
+
return i18nAction;
|
|
161
|
+
}
|
|
140
162
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this._state.uischemas = uischemaState;
|
|
147
|
-
this.updateSubject();
|
|
148
|
-
return uischemaAction;
|
|
163
|
+
updateCore<T extends CoreActions>(coreAction: T): T {
|
|
164
|
+
const coreState = coreReducer(this._state.core, coreAction);
|
|
165
|
+
if (coreState !== this._state.core) {
|
|
166
|
+
this._state.core = coreState;
|
|
167
|
+
this.updateSubject();
|
|
149
168
|
}
|
|
169
|
+
return coreAction;
|
|
170
|
+
}
|
|
150
171
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
172
|
+
/**
|
|
173
|
+
* @deprecated use {@link JsonFormsAngularService.setUiSchemas}
|
|
174
|
+
*/
|
|
175
|
+
updateUiSchema<T extends UISchemaActions>(uischemaAction: T): T {
|
|
176
|
+
const uischemaState = uischemaRegistryReducer(
|
|
177
|
+
this._state.uischemas,
|
|
178
|
+
uischemaAction
|
|
179
|
+
);
|
|
180
|
+
this._state.uischemas = uischemaState;
|
|
181
|
+
this.updateSubject();
|
|
182
|
+
return uischemaAction;
|
|
183
|
+
}
|
|
155
184
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
185
|
+
setUiSchemas(
|
|
186
|
+
uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[]
|
|
187
|
+
): void {
|
|
188
|
+
this._state.uischemas = uischemas;
|
|
189
|
+
this.updateSubject();
|
|
190
|
+
}
|
|
162
191
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
192
|
+
updateConfig<T extends SetConfigAction>(setConfigAction: T): T {
|
|
193
|
+
const configState = configReducer(this._state.config, setConfigAction);
|
|
194
|
+
this._state.config = configState;
|
|
195
|
+
this.updateSubject();
|
|
196
|
+
return setConfigAction;
|
|
197
|
+
}
|
|
171
198
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
199
|
+
setUiSchema(uischema: UISchemaElement | undefined): void {
|
|
200
|
+
const newUiSchema =
|
|
201
|
+
uischema ?? generateDefaultUISchema(this._state.core.schema);
|
|
202
|
+
const coreState = coreReducer(
|
|
203
|
+
this._state.core,
|
|
204
|
+
Actions.updateCore(
|
|
205
|
+
this._state.core.data,
|
|
206
|
+
this._state.core.schema,
|
|
207
|
+
newUiSchema
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
if (coreState !== this._state.core) {
|
|
211
|
+
this._state.core = coreState;
|
|
212
|
+
this.updateSubject();
|
|
180
213
|
}
|
|
214
|
+
}
|
|
181
215
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
setSchema(schema: JsonSchema | undefined): void {
|
|
217
|
+
const coreState = coreReducer(
|
|
218
|
+
this._state.core,
|
|
219
|
+
Actions.updateCore(
|
|
220
|
+
this._state.core.data,
|
|
221
|
+
schema ?? generateJsonSchema(this._state.core.data),
|
|
222
|
+
this._state.core.uischema
|
|
223
|
+
)
|
|
224
|
+
);
|
|
225
|
+
if (coreState !== this._state.core) {
|
|
226
|
+
this._state.core = coreState;
|
|
227
|
+
this.updateSubject();
|
|
188
228
|
}
|
|
229
|
+
}
|
|
189
230
|
|
|
190
|
-
|
|
191
|
-
|
|
231
|
+
setData(data: any): void {
|
|
232
|
+
const coreState = coreReducer(
|
|
233
|
+
this._state.core,
|
|
234
|
+
Actions.updateCore(
|
|
235
|
+
data,
|
|
236
|
+
this._state.core.schema,
|
|
237
|
+
this._state.core.uischema
|
|
238
|
+
)
|
|
239
|
+
);
|
|
240
|
+
if (coreState !== this._state.core) {
|
|
241
|
+
this._state.core = coreState;
|
|
242
|
+
this.updateSubject();
|
|
192
243
|
}
|
|
244
|
+
}
|
|
193
245
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
246
|
+
getLocale(): string | undefined {
|
|
247
|
+
return this._state.i18n?.locale;
|
|
248
|
+
}
|
|
198
249
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
250
|
+
setLocale(locale: string): void {
|
|
251
|
+
this._state.i18n.locale = locale;
|
|
252
|
+
this.updateSubject();
|
|
253
|
+
}
|
|
203
254
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
255
|
+
setReadonly(readonly: boolean): void {
|
|
256
|
+
this._state.readonly = readonly;
|
|
257
|
+
this.updateSubject();
|
|
258
|
+
}
|
|
207
259
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
260
|
+
getState(): JsonFormsState {
|
|
261
|
+
return cloneDeep({ jsonforms: this._state });
|
|
262
|
+
}
|
|
211
263
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
264
|
+
getConfig(): any {
|
|
265
|
+
return cloneDeep(this._state.config);
|
|
266
|
+
}
|
|
215
267
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
uischema: UISchemaElement | typeof USE_STATE_VALUE,
|
|
220
|
-
ajv: Ajv | typeof USE_STATE_VALUE,
|
|
221
|
-
validationMode: ValidationMode | typeof USE_STATE_VALUE,
|
|
222
|
-
additionalErrors: ErrorObject[] | typeof USE_STATE_VALUE,
|
|
223
|
-
): void {
|
|
224
|
-
const newData = data === USE_STATE_VALUE ? this._state.core.data : data;
|
|
225
|
-
const newSchema = schema === USE_STATE_VALUE ? this._state.core.schema : schema ?? generateJsonSchema(newData);
|
|
226
|
-
const newUischema = uischema === USE_STATE_VALUE ? this._state.core.uischema : uischema ?? generateDefaultUISchema(newSchema);
|
|
227
|
-
const newAjv = ajv === USE_STATE_VALUE ? this._state.core.ajv : ajv;
|
|
228
|
-
const newValidationMode = validationMode === USE_STATE_VALUE ? this._state.core.validationMode : validationMode;
|
|
229
|
-
const newAdditionalErrors = additionalErrors === USE_STATE_VALUE ? this._state.core.additionalErrors : additionalErrors;
|
|
230
|
-
this.updateCore(
|
|
231
|
-
Actions.updateCore(newData, newSchema, newUischema, {ajv: newAjv, validationMode: newValidationMode, additionalErrors: newAdditionalErrors})
|
|
232
|
-
);
|
|
233
|
-
}
|
|
268
|
+
refresh(): void {
|
|
269
|
+
this.updateSubject();
|
|
270
|
+
}
|
|
234
271
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
272
|
+
updateCoreState(
|
|
273
|
+
data: any | typeof USE_STATE_VALUE,
|
|
274
|
+
schema: JsonSchema | typeof USE_STATE_VALUE,
|
|
275
|
+
uischema: UISchemaElement | typeof USE_STATE_VALUE,
|
|
276
|
+
ajv: Ajv | typeof USE_STATE_VALUE,
|
|
277
|
+
validationMode: ValidationMode | typeof USE_STATE_VALUE,
|
|
278
|
+
additionalErrors: ErrorObject[] | typeof USE_STATE_VALUE
|
|
279
|
+
): void {
|
|
280
|
+
const newData = data === USE_STATE_VALUE ? this._state.core.data : data;
|
|
281
|
+
const newSchema =
|
|
282
|
+
schema === USE_STATE_VALUE
|
|
283
|
+
? this._state.core.schema
|
|
284
|
+
: schema ?? generateJsonSchema(newData);
|
|
285
|
+
const newUischema =
|
|
286
|
+
uischema === USE_STATE_VALUE
|
|
287
|
+
? this._state.core.uischema
|
|
288
|
+
: uischema ?? generateDefaultUISchema(newSchema);
|
|
289
|
+
const newAjv = ajv === USE_STATE_VALUE ? this._state.core.ajv : ajv;
|
|
290
|
+
const newValidationMode =
|
|
291
|
+
validationMode === USE_STATE_VALUE
|
|
292
|
+
? this._state.core.validationMode
|
|
293
|
+
: validationMode;
|
|
294
|
+
const newAdditionalErrors =
|
|
295
|
+
additionalErrors === USE_STATE_VALUE
|
|
296
|
+
? this._state.core.additionalErrors
|
|
297
|
+
: additionalErrors;
|
|
298
|
+
this.updateCore(
|
|
299
|
+
Actions.updateCore(newData, newSchema, newUischema, {
|
|
300
|
+
ajv: newAjv,
|
|
301
|
+
validationMode: newValidationMode,
|
|
302
|
+
additionalErrors: newAdditionalErrors,
|
|
303
|
+
})
|
|
304
|
+
);
|
|
305
|
+
}
|
|
238
306
|
|
|
307
|
+
private updateSubject(): void {
|
|
308
|
+
this.state.next({ jsonforms: this._state });
|
|
309
|
+
}
|
|
239
310
|
}
|
package/src/unknown.component.ts
CHANGED