@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.
Files changed (53) hide show
  1. package/README.md +41 -42
  2. package/lib/cjs/abstract-control.d.ts +1 -1
  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.js.map +1 -1
  7. package/lib/cjs/base.renderer.js +1 -1
  8. package/lib/cjs/base.renderer.js.map +1 -1
  9. package/lib/cjs/control.js.map +1 -1
  10. package/lib/cjs/control.metadata.json +1 -1
  11. package/lib/cjs/jsonforms-root.component.d.ts +2 -2
  12. package/lib/cjs/jsonforms-root.component.js +11 -5
  13. package/lib/cjs/jsonforms-root.component.js.map +1 -1
  14. package/lib/cjs/jsonforms-root.component.metadata.json +1 -1
  15. package/lib/cjs/jsonforms.component.js +15 -12
  16. package/lib/cjs/jsonforms.component.js.map +1 -1
  17. package/lib/cjs/jsonforms.component.metadata.json +1 -1
  18. package/lib/cjs/jsonforms.module.js +1 -1
  19. package/lib/cjs/jsonforms.service.js +26 -6
  20. package/lib/cjs/jsonforms.service.js.map +1 -1
  21. package/lib/cjs/unknown.component.js +1 -1
  22. package/lib/esm/abstract-control.d.ts +1 -1
  23. package/lib/esm/abstract-control.js +8 -9
  24. package/lib/esm/abstract-control.js.map +1 -1
  25. package/lib/esm/abstract-control.metadata.json +1 -1
  26. package/lib/esm/array-control.js +1 -1
  27. package/lib/esm/array-control.js.map +1 -1
  28. package/lib/esm/base.renderer.js +1 -1
  29. package/lib/esm/base.renderer.js.map +1 -1
  30. package/lib/esm/control.js +1 -1
  31. package/lib/esm/control.js.map +1 -1
  32. package/lib/esm/control.metadata.json +1 -1
  33. package/lib/esm/jsonforms-root.component.d.ts +2 -2
  34. package/lib/esm/jsonforms-root.component.js +13 -7
  35. package/lib/esm/jsonforms-root.component.js.map +1 -1
  36. package/lib/esm/jsonforms-root.component.metadata.json +1 -1
  37. package/lib/esm/jsonforms.component.js +17 -14
  38. package/lib/esm/jsonforms.component.js.map +1 -1
  39. package/lib/esm/jsonforms.component.metadata.json +1 -1
  40. package/lib/esm/jsonforms.module.js +1 -1
  41. package/lib/esm/jsonforms.service.js +27 -7
  42. package/lib/esm/jsonforms.service.js.map +1 -1
  43. package/lib/esm/unknown.component.js +1 -1
  44. package/package.json +17 -6
  45. package/src/abstract-control.ts +14 -12
  46. package/src/array-control.ts +3 -2
  47. package/src/base.renderer.ts +3 -3
  48. package/src/control.ts +5 -3
  49. package/src/jsonforms-root.component.ts +158 -130
  50. package/src/jsonforms.component.ts +35 -20
  51. package/src/jsonforms.module.ts +1 -1
  52. package/src/jsonforms.service.ts +244 -173
  53. package/src/unknown.component.ts +1 -1
@@ -23,27 +23,27 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
  import {
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
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
- private _state: JsonFormsSubStates;
59
- private state: BehaviorSubject<JsonFormsState>;
60
-
61
- init(initialState: JsonFormsSubStates = { core: { data: undefined, schema: undefined, uischema: undefined, validationMode: 'ValidateAndShow', additionalErrors: undefined } }) {
62
- this._state = initialState;
63
- this._state.config = configReducer(undefined, setConfig(this._state.config));
64
- this._state.i18n = i18nReducer(this._state.i18n, updateI18n(this._state.i18n?.locale, this._state.i18n?.translate, this._state.i18n?.translateError));
65
- this.state = new BehaviorSubject({ jsonforms: this._state });
66
- const data = initialState.core.data;
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
- get $state(): Observable<JsonFormsState> {
73
- if (!this.state) {
74
- throw new Error('Please call init first!');
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
- * @deprecated use {@link JsonFormsAngularService.addRenderer}
81
- */
82
- registerRenderer(renderer: JsonFormsBaseRenderer<UISchemaElement>, tester: RankedTester): void {
83
- this.addRenderer(renderer, tester);
84
- }
85
- addRenderer(renderer: JsonFormsBaseRenderer<UISchemaElement>, tester: RankedTester): void {
86
- this._state.renderers.push({ renderer, tester });
87
- this.updateSubject();
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
- * @deprecated use {@link JsonFormsAngularService.setRenderer}
92
- */
93
- registerRenderers(renderers: JsonFormsRendererRegistryEntry[]): void {
94
- this.setRenderers(renderers);
95
- }
96
- setRenderers(renderers: JsonFormsRendererRegistryEntry[]): void {
97
- this._state.renderers = renderers;
98
- this.updateSubject();
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
- * @deprecated use {@link JsonFormsAngularService.removeRenderer}
103
- */
104
- unregisterRenderer(tester: RankedTester): void {
105
- this.removeRenderer(tester);
106
- }
107
- removeRenderer(tester: RankedTester): void {
108
- const findIndex = this._state.renderers.findIndex(v => v.tester === tester);
109
- if (findIndex === -1) {
110
- return;
111
- }
112
- const renderers = this._state.renderers.filter(v => v.tester !== tester);
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
- updateValidationMode(validationMode: ValidationMode): void {
118
- const coreState = coreReducer(this._state.core, Actions.setValidationMode(validationMode));
119
- this._state.core = coreState;
120
- this.updateSubject();
121
- }
122
-
123
- updateI18n<T extends I18nActions>(i18nAction: T): T {
124
- const i18nState = i18nReducer(this._state.i18n, i18nAction);
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
- updateCore<T extends CoreActions>(coreAction: T): T {
133
- const coreState = coreReducer(this._state.core, coreAction);
134
- if (coreState !== this._state.core) {
135
- this._state.core = coreState;
136
- this.updateSubject();
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
- * @deprecated use {@link JsonFormsAngularService.setUiSchemas}
143
- */
144
- updateUiSchema<T extends UISchemaActions>(uischemaAction: T): T {
145
- const uischemaState = uischemaRegistryReducer(this._state.uischemas, uischemaAction);
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
- setUiSchemas(uischemas: { tester: UISchemaTester; uischema: UISchemaElement; }[]): void {
152
- this._state.uischemas = uischemas;
153
- this.updateSubject();
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
- updateConfig<T extends SetConfigAction>(setConfigAction: T): T {
157
- const configState = configReducer(this._state.config, setConfigAction);
158
- this._state.config = configState;
159
- this.updateSubject();
160
- return setConfigAction;
161
- }
185
+ setUiSchemas(
186
+ uischemas: { tester: UISchemaTester; uischema: UISchemaElement }[]
187
+ ): void {
188
+ this._state.uischemas = uischemas;
189
+ this.updateSubject();
190
+ }
162
191
 
163
- setUiSchema(uischema: UISchemaElement | undefined): void {
164
- const newUiSchema = uischema ?? generateDefaultUISchema(this._state.core.schema);
165
- const coreState = coreReducer(this._state.core, Actions.updateCore(this._state.core.data, this._state.core.schema, newUiSchema));
166
- if(coreState !== this._state.core) {
167
- this._state.core = coreState;
168
- this.updateSubject();
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
- setSchema(schema: JsonSchema | undefined): void {
173
- const coreState = coreReducer(this._state.core,
174
- Actions.updateCore(this._state.core.data, schema ?? generateJsonSchema(this._state.core.data), this._state.core.uischema)
175
- );
176
- if(coreState !== this._state.core) {
177
- this._state.core = coreState;
178
- this.updateSubject();
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
- setData(data: any): void {
183
- const coreState = coreReducer(this._state.core, Actions.updateCore(data, this._state.core.schema, this._state.core.uischema));
184
- if(coreState !== this._state.core) {
185
- this._state.core = coreState;
186
- this.updateSubject();
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
- getLocale(): string | undefined {
191
- return this._state.i18n?.locale;
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
- setLocale(locale: string): void {
195
- this._state.i18n.locale = locale;
196
- this.updateSubject();
197
- }
246
+ getLocale(): string | undefined {
247
+ return this._state.i18n?.locale;
248
+ }
198
249
 
199
- setReadonly(readonly: boolean): void {
200
- this._state.readonly = readonly;
201
- this.updateSubject();
202
- }
250
+ setLocale(locale: string): void {
251
+ this._state.i18n.locale = locale;
252
+ this.updateSubject();
253
+ }
203
254
 
204
- getState(): JsonFormsState {
205
- return cloneDeep({ jsonforms: this._state });
206
- }
255
+ setReadonly(readonly: boolean): void {
256
+ this._state.readonly = readonly;
257
+ this.updateSubject();
258
+ }
207
259
 
208
- getConfig(): any {
209
- return cloneDeep(this._state.config)
210
- }
260
+ getState(): JsonFormsState {
261
+ return cloneDeep({ jsonforms: this._state });
262
+ }
211
263
 
212
- refresh(): void {
213
- this.updateSubject();
214
- }
264
+ getConfig(): any {
265
+ return cloneDeep(this._state.config);
266
+ }
215
267
 
216
- updateCoreState(
217
- data: any | typeof USE_STATE_VALUE,
218
- schema: JsonSchema | typeof USE_STATE_VALUE,
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
- private updateSubject(): void {
236
- this.state.next({ jsonforms: this._state });
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
  }
@@ -25,6 +25,6 @@
25
25
  import { Component } from '@angular/core';
26
26
  @Component({
27
27
  selector: 'unknown.renderer',
28
- template: 'No applicable renderer found!'
28
+ template: 'No applicable renderer found!',
29
29
  })
30
30
  export class UnknownRenderer {}