@jsonforms/angular-material 3.7.0 → 3.8.0-alpha.0
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/lib/fesm2022/jsonforms-angular-material.mjs +141 -112
- package/lib/fesm2022/jsonforms-angular-material.mjs.map +1 -1
- package/lib/library/controls/autocomplete.renderer.d.ts +14 -31
- package/lib/library/controls/autocomplete.renderer.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/library/controls/autocomplete.renderer.ts +94 -44
|
@@ -1,49 +1,32 @@
|
|
|
1
1
|
import { OnInit } from '@angular/core';
|
|
2
2
|
import type { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
|
3
3
|
import { JsonFormsAngularService, JsonFormsControl } from '@jsonforms/angular';
|
|
4
|
-
import { OwnPropsOfControl, RankedTester } from '@jsonforms/core';
|
|
4
|
+
import { EnumOption, JsonFormsState, OwnPropsOfControl, OwnPropsOfEnum, RankedTester, StatePropsOfControl } from '@jsonforms/core';
|
|
5
5
|
import type { Observable } from 'rxjs';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
|
-
/**
|
|
8
|
-
* To use this component you will need to add your own tester:
|
|
9
|
-
* <pre><code>
|
|
10
|
-
* ...
|
|
11
|
-
* export const AutocompleteControlRendererTester: RankedTester = rankWith(2, isEnumControl);
|
|
12
|
-
* ...
|
|
13
|
-
* </code></pre>
|
|
14
|
-
* Add the tester and renderer to JSONForms registry:
|
|
15
|
-
* <pre><code>
|
|
16
|
-
* ...
|
|
17
|
-
* { tester: AutocompleteControlRendererTester, renderer: AutocompleteControlRenderer },
|
|
18
|
-
* ...
|
|
19
|
-
* </code></pre>
|
|
20
|
-
* Furthermore you need to update your module.
|
|
21
|
-
* <pre><code>
|
|
22
|
-
* ...
|
|
23
|
-
* imports: [JsonFormsAngularMaterialModule, MatAutocompleteModule],
|
|
24
|
-
* declarations: [AutocompleteControlRenderer]
|
|
25
|
-
* ...
|
|
26
|
-
* </code></pre>
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
7
|
export declare class AutocompleteControlRenderer extends JsonFormsControl implements OnInit {
|
|
30
|
-
options
|
|
31
|
-
|
|
8
|
+
options?: EnumOption[] | string[];
|
|
9
|
+
valuesToTranslatedOptions?: Map<string, EnumOption>;
|
|
10
|
+
filteredOptions: Observable<EnumOption[]>;
|
|
32
11
|
shouldFilter: boolean;
|
|
33
12
|
focused: boolean;
|
|
34
13
|
constructor(jsonformsService: JsonFormsAngularService);
|
|
14
|
+
protected mapToProps(state: JsonFormsState): StatePropsOfControl & OwnPropsOfEnum;
|
|
35
15
|
getEventValue: (event: any) => any;
|
|
16
|
+
onChange(ev: any): void;
|
|
36
17
|
ngOnInit(): void;
|
|
18
|
+
mapAdditionalProps(_props: StatePropsOfControl & OwnPropsOfEnum): void;
|
|
37
19
|
updateFilter(event: any): void;
|
|
38
20
|
onSelect(ev: MatAutocompleteSelectedEvent): void;
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
displayFn: (option?: string | EnumOption) => string;
|
|
22
|
+
filter(val: string | EnumOption | undefined): EnumOption[];
|
|
23
|
+
protected getOwnProps(): OwnPropsOfControl & OwnPropsOfEnum;
|
|
24
|
+
/**
|
|
25
|
+
* For {@link options} input backwards compatibility
|
|
26
|
+
*/
|
|
27
|
+
protected stringOptionsToEnumOptions(options: typeof this.options): EnumOption[] | undefined;
|
|
41
28
|
static ɵfac: i0.ɵɵFactoryDeclaration<AutocompleteControlRenderer, never>;
|
|
42
29
|
static ɵcmp: i0.ɵɵComponentDeclaration<AutocompleteControlRenderer, "AutocompleteControlRenderer", never, { "options": { "alias": "options"; "required": false; }; }, {}, never, never, true, never>;
|
|
43
30
|
}
|
|
44
31
|
export declare const enumControlTester: RankedTester;
|
|
45
|
-
interface OwnPropsOfAutoComplete extends OwnPropsOfControl {
|
|
46
|
-
options: string[];
|
|
47
|
-
}
|
|
48
|
-
export {};
|
|
49
32
|
//# sourceMappingURL=autocomplete.renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.renderer.d.ts","sourceRoot":"","sources":["../../../src/library/controls/autocomplete.renderer.ts"],"names":[],"mappings":"AAwBA,OAAO,EAIL,MAAM,EACP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"autocomplete.renderer.d.ts","sourceRoot":"","sources":["../../../src/library/controls/autocomplete.renderer.ts"],"names":[],"mappings":"AAwBA,OAAO,EAIL,MAAM,EACP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAIL,UAAU,EAEV,cAAc,EAEd,iBAAiB,EACjB,cAAc,EACd,YAAY,EAEZ,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;;AAQvC,qBAsDa,2BACX,SAAQ,gBACR,YAAW,MAAM;IAER,OAAO,CAAC,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,CAAC;IAC3C,yBAAyB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpD,eAAe,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;IAC1C,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,UAAS;gBAEJ,gBAAgB,EAAE,uBAAuB;cAIlC,UAAU,CAC3B,KAAK,EAAE,cAAc,GACpB,mBAAmB,GAAG,cAAc;IAIvC,aAAa,UAAW,GAAG,SAAwB;IAE1C,QAAQ,CAAC,EAAE,EAAE,GAAG;IAgBzB,QAAQ;IASC,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc;IAMxE,YAAY,CAAC,KAAK,EAAE,GAAG;IASvB,QAAQ,CAAC,EAAE,EAAE,4BAA4B;IASzC,SAAS,YAAa,MAAM,GAAG,UAAU,KAAG,MAAM,CAehD;IAEF,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,EAAE;IAY1D,SAAS,CAAC,WAAW,IAAI,iBAAiB,GAAG,cAAc;IAO3D;;OAEG;IACH,SAAS,CAAC,0BAA0B,CAClC,OAAO,EAAE,OAAO,IAAI,CAAC,OAAO,GAC3B,UAAU,EAAE,GAAG,SAAS;yCAhHhB,2BAA2B;2CAA3B,2BAA2B;CA8HvC;AAED,eAAO,MAAM,iBAAiB,EAAE,YAAyC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonforms/angular-material",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0-alpha.0",
|
|
4
4
|
"description": "Material Renderer Set for Angular module of JSON Forms",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@angular/material": "^19.0.0 || ^20.0.0 || ^21.0.0",
|
|
56
56
|
"@angular/platform-browser": "^19.0.0 || ^20.0.0 || ^21.0.0",
|
|
57
57
|
"@angular/router": "^19.0.0 || ^20.0.0 || ^21.0.0",
|
|
58
|
-
"@jsonforms/angular": "3.
|
|
59
|
-
"@jsonforms/core": "3.
|
|
58
|
+
"@jsonforms/angular": "3.8.0-alpha.0",
|
|
59
|
+
"@jsonforms/core": "3.8.0-alpha.0",
|
|
60
60
|
"dayjs": "^1.11.10",
|
|
61
61
|
"rxjs": "^6.6.0 || ^7.4.0"
|
|
62
62
|
},
|
|
@@ -123,9 +123,9 @@
|
|
|
123
123
|
"webpack": "^5.78.0",
|
|
124
124
|
"yargs": "^17.7.2",
|
|
125
125
|
"zone.js": "~0.15.0",
|
|
126
|
-
"@jsonforms/angular": "3.
|
|
127
|
-
"@jsonforms/
|
|
128
|
-
"@jsonforms/
|
|
126
|
+
"@jsonforms/angular": "3.8.0-alpha.0",
|
|
127
|
+
"@jsonforms/examples": "3.8.0-alpha.0",
|
|
128
|
+
"@jsonforms/core": "3.8.0-alpha.0"
|
|
129
129
|
},
|
|
130
130
|
"scripts": {
|
|
131
131
|
"build": "ng build",
|
|
@@ -34,10 +34,15 @@ import {
|
|
|
34
34
|
Actions,
|
|
35
35
|
composeWithUi,
|
|
36
36
|
ControlElement,
|
|
37
|
+
EnumOption,
|
|
37
38
|
isEnumControl,
|
|
39
|
+
JsonFormsState,
|
|
40
|
+
mapStateToEnumControlProps,
|
|
38
41
|
OwnPropsOfControl,
|
|
42
|
+
OwnPropsOfEnum,
|
|
39
43
|
RankedTester,
|
|
40
44
|
rankWith,
|
|
45
|
+
StatePropsOfControl,
|
|
41
46
|
} from '@jsonforms/core';
|
|
42
47
|
import type { Observable } from 'rxjs';
|
|
43
48
|
import { map, startWith } from 'rxjs/operators';
|
|
@@ -47,28 +52,6 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
|
|
47
52
|
import { MatInputModule } from '@angular/material/input';
|
|
48
53
|
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
|
49
54
|
|
|
50
|
-
/**
|
|
51
|
-
* To use this component you will need to add your own tester:
|
|
52
|
-
* <pre><code>
|
|
53
|
-
* ...
|
|
54
|
-
* export const AutocompleteControlRendererTester: RankedTester = rankWith(2, isEnumControl);
|
|
55
|
-
* ...
|
|
56
|
-
* </code></pre>
|
|
57
|
-
* Add the tester and renderer to JSONForms registry:
|
|
58
|
-
* <pre><code>
|
|
59
|
-
* ...
|
|
60
|
-
* { tester: AutocompleteControlRendererTester, renderer: AutocompleteControlRenderer },
|
|
61
|
-
* ...
|
|
62
|
-
* </code></pre>
|
|
63
|
-
* Furthermore you need to update your module.
|
|
64
|
-
* <pre><code>
|
|
65
|
-
* ...
|
|
66
|
-
* imports: [JsonFormsAngularMaterialModule, MatAutocompleteModule],
|
|
67
|
-
* declarations: [AutocompleteControlRenderer]
|
|
68
|
-
* ...
|
|
69
|
-
* </code></pre>
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
55
|
@Component({
|
|
73
56
|
selector: 'AutocompleteControlRenderer',
|
|
74
57
|
template: `
|
|
@@ -89,13 +72,13 @@ import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
|
|
89
72
|
autoActiveFirstOption
|
|
90
73
|
#auto="matAutocomplete"
|
|
91
74
|
(optionSelected)="onSelect($event)"
|
|
75
|
+
[displayWith]="displayFn"
|
|
92
76
|
>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
>
|
|
97
|
-
{{ option }}
|
|
77
|
+
@for (option of filteredOptions | async; track option.value) {
|
|
78
|
+
<mat-option [value]="option">
|
|
79
|
+
{{ option.label }}
|
|
98
80
|
</mat-option>
|
|
81
|
+
}
|
|
99
82
|
</mat-autocomplete>
|
|
100
83
|
<mat-hint *ngIf="shouldShowUnfocusedDescription() || focused">{{
|
|
101
84
|
description
|
|
@@ -127,16 +110,40 @@ export class AutocompleteControlRenderer
|
|
|
127
110
|
extends JsonFormsControl
|
|
128
111
|
implements OnInit
|
|
129
112
|
{
|
|
130
|
-
@Input() options
|
|
131
|
-
|
|
113
|
+
@Input() options?: EnumOption[] | string[];
|
|
114
|
+
valuesToTranslatedOptions?: Map<string, EnumOption>;
|
|
115
|
+
filteredOptions: Observable<EnumOption[]>;
|
|
132
116
|
shouldFilter: boolean;
|
|
133
117
|
focused = false;
|
|
134
118
|
|
|
135
119
|
constructor(jsonformsService: JsonFormsAngularService) {
|
|
136
120
|
super(jsonformsService);
|
|
137
121
|
}
|
|
122
|
+
|
|
123
|
+
protected override mapToProps(
|
|
124
|
+
state: JsonFormsState
|
|
125
|
+
): StatePropsOfControl & OwnPropsOfEnum {
|
|
126
|
+
return mapStateToEnumControlProps(state, this.getOwnProps());
|
|
127
|
+
}
|
|
128
|
+
|
|
138
129
|
getEventValue = (event: any) => event.target.value;
|
|
139
130
|
|
|
131
|
+
override onChange(ev: any) {
|
|
132
|
+
const eventValue = this.getEventValue(ev);
|
|
133
|
+
const option = Array.from(
|
|
134
|
+
this.valuesToTranslatedOptions?.values() ?? []
|
|
135
|
+
).find((option) => option.label === eventValue);
|
|
136
|
+
if (!option) {
|
|
137
|
+
super.onChange(ev);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.jsonFormsService.updateCore(
|
|
142
|
+
Actions.update(this.propsPath, () => option.value)
|
|
143
|
+
);
|
|
144
|
+
this.triggerValidation();
|
|
145
|
+
}
|
|
146
|
+
|
|
140
147
|
ngOnInit() {
|
|
141
148
|
super.ngOnInit();
|
|
142
149
|
this.shouldFilter = false;
|
|
@@ -146,6 +153,12 @@ export class AutocompleteControlRenderer
|
|
|
146
153
|
);
|
|
147
154
|
}
|
|
148
155
|
|
|
156
|
+
override mapAdditionalProps(_props: StatePropsOfControl & OwnPropsOfEnum) {
|
|
157
|
+
this.valuesToTranslatedOptions = new Map(
|
|
158
|
+
(_props.options ?? []).map((option) => [option.value, option])
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
149
162
|
updateFilter(event: any) {
|
|
150
163
|
// ENTER
|
|
151
164
|
if (event.keyCode === 13) {
|
|
@@ -158,30 +171,67 @@ export class AutocompleteControlRenderer
|
|
|
158
171
|
onSelect(ev: MatAutocompleteSelectedEvent) {
|
|
159
172
|
const path = composeWithUi(this.uischema as ControlElement, this.path);
|
|
160
173
|
this.shouldFilter = false;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
174
|
+
const option: EnumOption = ev.option.value;
|
|
175
|
+
this.jsonFormsService.updateCore(Actions.update(path, () => option.value));
|
|
164
176
|
this.triggerValidation();
|
|
165
177
|
}
|
|
166
178
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
179
|
+
// use arrow function to bind "this" reference
|
|
180
|
+
displayFn = (option?: string | EnumOption): string => {
|
|
181
|
+
if (!option) {
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (typeof option === 'string') {
|
|
186
|
+
if (!this.valuesToTranslatedOptions) {
|
|
187
|
+
return option; // show raw value until translations are ready
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// if no option matches, it is a manual input
|
|
191
|
+
return this.valuesToTranslatedOptions.get(option)?.label ?? option;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return option?.label ?? '';
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
filter(val: string | EnumOption | undefined): EnumOption[] {
|
|
198
|
+
const options = Array.from(this.valuesToTranslatedOptions?.values() || []);
|
|
199
|
+
|
|
200
|
+
if (!val || !this.shouldFilter) {
|
|
201
|
+
return options;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const label = typeof val === 'string' ? val : val.label;
|
|
205
|
+
return options.filter((option) =>
|
|
206
|
+
option.label.toLowerCase().startsWith(label.toLowerCase())
|
|
173
207
|
);
|
|
174
208
|
}
|
|
175
|
-
protected getOwnProps():
|
|
209
|
+
protected getOwnProps(): OwnPropsOfControl & OwnPropsOfEnum {
|
|
176
210
|
return {
|
|
177
211
|
...super.getOwnProps(),
|
|
178
|
-
options: this.options,
|
|
212
|
+
options: this.stringOptionsToEnumOptions(this.options),
|
|
179
213
|
};
|
|
180
214
|
}
|
|
181
|
-
}
|
|
182
215
|
|
|
183
|
-
|
|
216
|
+
/**
|
|
217
|
+
* For {@link options} input backwards compatibility
|
|
218
|
+
*/
|
|
219
|
+
protected stringOptionsToEnumOptions(
|
|
220
|
+
options: typeof this.options
|
|
221
|
+
): EnumOption[] | undefined {
|
|
222
|
+
if (!options) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
184
225
|
|
|
185
|
-
|
|
186
|
-
|
|
226
|
+
return options.every((item) => typeof item === 'string')
|
|
227
|
+
? options.map((str) => {
|
|
228
|
+
return {
|
|
229
|
+
label: str,
|
|
230
|
+
value: str,
|
|
231
|
+
} satisfies EnumOption;
|
|
232
|
+
})
|
|
233
|
+
: options;
|
|
234
|
+
}
|
|
187
235
|
}
|
|
236
|
+
|
|
237
|
+
export const enumControlTester: RankedTester = rankWith(2, isEnumControl);
|