@yuuvis/client-framework 2.3.23 → 2.3.25

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.
@@ -1942,6 +1942,7 @@ class CatalogComponent extends AbstractMatFormField {
1942
1942
  super(...arguments);
1943
1943
  this.#system = inject(SystemService);
1944
1944
  this.#dRef = inject(DestroyRef);
1945
+ this.translate = inject(TranslateService);
1945
1946
  this.readonly = input(false);
1946
1947
  this.multiple = input(false);
1947
1948
  this._options = signal([]);
@@ -1959,8 +1960,13 @@ class CatalogComponent extends AbstractMatFormField {
1959
1960
  const cls = this.classifications();
1960
1961
  untracked(() => {
1961
1962
  const ce = this.#system.getClassifications(cls).get(Classification.STRING_CATALOG);
1963
+ const ceTranslate = this.#system.getClassifications(cls).get(Classification.STRING_CATALOG_I18N);
1962
1964
  if (ce && ce.options) {
1963
- this._options.set(ce.options);
1965
+ this.#setOptions(ce.options, false);
1966
+ }
1967
+ // i18n catalog
1968
+ if (ceTranslate && ceTranslate.options) {
1969
+ this.#setOptions(ceTranslate.options, true);
1964
1970
  }
1965
1971
  });
1966
1972
  });
@@ -1981,6 +1987,14 @@ class CatalogComponent extends AbstractMatFormField {
1981
1987
  this.value = val;
1982
1988
  this.propagateChange(this.value);
1983
1989
  }
1990
+ #setOptions(options, translate) {
1991
+ if (translate) {
1992
+ this._options.set(options.map((o) => this.translate.instant(o)));
1993
+ }
1994
+ else {
1995
+ this._options.set(options);
1996
+ }
1997
+ }
1984
1998
  writeValue(value) {
1985
1999
  this.value = value;
1986
2000
  }
@@ -2020,6 +2034,113 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
2020
2034
  args: [{ selector: 'yuv-catalog', imports: [CommonModule, MatSelectModule, ReactiveFormsModule], providers: [{ provide: MatFormFieldControl, useExisting: CatalogComponent }], template: "<mat-select [multiple]=\"multiple()\" [disabled]=\"readonly()\" [formControl]=\"fc\">\n @for (o of _options(); track o) {\n <mat-option [value]=\"o\">{{ o }}</mat-option>\n }\n</mat-select>\n" }]
2021
2035
  }] });
2022
2036
 
2037
+ /**
2038
+ * Form element for selecting one or multiple i18n catalog values.
2039
+ * Having a classification of `i18n:catalog[one, two, three]` configured on the metadata field
2040
+ * will automatically populate the options from the catalog. The options will be translated
2041
+ * using the catalogs static values adding a prefix, the property name an the value itself.
2042
+ * E.g. for property name `status` and option value `open` the label key will be `catalog:status:open_label`.
2043
+ */
2044
+ class I18nCatalogComponent extends AbstractMatFormField {
2045
+ #system;
2046
+ #dRef;
2047
+ #optionsEffect;
2048
+ #classificationEffect;
2049
+ constructor() {
2050
+ super();
2051
+ this.#system = inject(SystemService);
2052
+ this.#dRef = inject(DestroyRef);
2053
+ this.translate = inject(TranslateService);
2054
+ this.readonly = input(false);
2055
+ this.multiple = input(false);
2056
+ this.propertyName = input(undefined);
2057
+ this._options = signal([]);
2058
+ this.options = input([]);
2059
+ this.#optionsEffect = effect(() => {
2060
+ untracked(() => {
2061
+ this.#setOptions(this.options());
2062
+ });
2063
+ });
2064
+ /**
2065
+ * Additional semantics for the form element.
2066
+ */
2067
+ this.classifications = input([]);
2068
+ this.#classificationEffect = effect(() => {
2069
+ const cls = this.classifications();
2070
+ untracked(() => {
2071
+ const ce = this.#system.getClassifications(cls).get(Classification.STRING_CATALOG_I18N);
2072
+ if (ce && ce.options) {
2073
+ this.#setOptions(ce.options);
2074
+ }
2075
+ });
2076
+ });
2077
+ /**
2078
+ * Possibles values are `EDIT` (default),`SEARCH`,`CREATE`. In search situation validation of the form element will be turned off, so you are able to enter search terms that do not meet the elements validators.
2079
+ */
2080
+ this.situation = input();
2081
+ this.ngControl = injectNgControl(this);
2082
+ this.fc = new FormControl(undefined);
2083
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2084
+ this.propagateChange = (_) => { };
2085
+ this.translate.onLangChange.pipe(takeUntilDestroyed()).subscribe(() => {
2086
+ // re-apply options to trigger translation
2087
+ this.#setOptions(this.options());
2088
+ });
2089
+ }
2090
+ #onValueChange(val) {
2091
+ this.value = val;
2092
+ this.propagateChange(this.value);
2093
+ }
2094
+ #setOptions(options) {
2095
+ this._options.set(options.map((o) => ({
2096
+ label: this.#translateOption(o),
2097
+ value: o
2098
+ })));
2099
+ }
2100
+ #translateOption(option) {
2101
+ // labelkey: 'catalog:status:open_label' for option 'open'
2102
+ // This will be derived fom a prefix the property name if available and this option itself
2103
+ return this.#system.getLocalizedLabel(`catalog:${this.propertyName() || ''}:${option}`) || option;
2104
+ }
2105
+ writeValue(value) {
2106
+ this.value = value;
2107
+ }
2108
+ registerOnChange(fn) {
2109
+ this.propagateChange = fn;
2110
+ }
2111
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
2112
+ registerOnTouched(fn) { }
2113
+ setDisabledState(isDisabled) {
2114
+ if (isDisabled) {
2115
+ this.fc.disable();
2116
+ }
2117
+ else {
2118
+ this.fc.enable();
2119
+ }
2120
+ }
2121
+ ngOnInit() {
2122
+ if (this.required)
2123
+ this.fc.setValidators(Validators.required);
2124
+ this.fc.statusChanges.pipe(takeUntilDestroyed(this.#dRef)).subscribe((v) => {
2125
+ this.errorState = FormUtils.getErrorState(this.fc);
2126
+ if (this.ngControl?.control) {
2127
+ this.ngControl.control.setErrors(this.fc.errors);
2128
+ }
2129
+ });
2130
+ this.fc.updateValueAndValidity();
2131
+ this.fc.valueChanges.pipe(takeUntilDestroyed(this.#dRef)).subscribe((v) => this.#onValueChange(v));
2132
+ }
2133
+ ngOnDestroy() {
2134
+ super.onNgOnDestroy();
2135
+ }
2136
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: I18nCatalogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2137
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.15", type: I18nCatalogComponent, isStandalone: true, selector: "yuv-i18n-catalog", inputs: { readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, multiple: { classPropertyName: "multiple", publicName: "multiple", isSignal: true, isRequired: false, transformFunction: null }, propertyName: { classPropertyName: "propertyName", publicName: "propertyName", isSignal: true, isRequired: false, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null }, classifications: { classPropertyName: "classifications", publicName: "classifications", isSignal: true, isRequired: false, transformFunction: null }, situation: { classPropertyName: "situation", publicName: "situation", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: MatFormFieldControl, useExisting: I18nCatalogComponent }], usesInheritance: true, ngImport: i0, template: "<mat-select [multiple]=\"multiple()\" [disabled]=\"readonly()\" [formControl]=\"fc\">\n @for (o of _options(); track o) {\n <mat-option [value]=\"o.value\">{{ o.label }}</mat-option>\n }\n</mat-select>", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: MatSelectModule }, { kind: "component", type: i1$1.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth", "canSelectNullableOptions"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "component", type: i1$1.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] }); }
2138
+ }
2139
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: I18nCatalogComponent, decorators: [{
2140
+ type: Component,
2141
+ args: [{ selector: 'yuv-i18n-catalog', imports: [CommonModule, MatSelectModule, ReactiveFormsModule], providers: [{ provide: MatFormFieldControl, useExisting: I18nCatalogComponent }], template: "<mat-select [multiple]=\"multiple()\" [disabled]=\"readonly()\" [formControl]=\"fc\">\n @for (o of _options(); track o) {\n <mat-option [value]=\"o.value\">{{ o.label }}</mat-option>\n }\n</mat-select>" }]
2142
+ }], ctorParameters: () => [] });
2143
+
2023
2144
  const formElementCmps = [
2024
2145
  StringComponent,
2025
2146
  NumberComponent,
@@ -2028,7 +2149,8 @@ const formElementCmps = [
2028
2149
  DatetimeRangeComponent,
2029
2150
  OrganizationComponent,
2030
2151
  StringComponent,
2031
- CatalogComponent
2152
+ CatalogComponent,
2153
+ I18nCatalogComponent
2032
2154
  ];
2033
2155
  /**
2034
2156
  * Module for the forms library.
@@ -2042,14 +2164,16 @@ class YuvFormsModule {
2042
2164
  DatetimeRangeComponent,
2043
2165
  OrganizationComponent,
2044
2166
  StringComponent,
2045
- CatalogComponent], exports: [StringComponent,
2167
+ CatalogComponent,
2168
+ I18nCatalogComponent], exports: [StringComponent,
2046
2169
  NumberComponent,
2047
2170
  NumberRangeComponent,
2048
2171
  DatetimeComponent,
2049
2172
  DatetimeRangeComponent,
2050
2173
  OrganizationComponent,
2051
2174
  StringComponent,
2052
- CatalogComponent] }); }
2175
+ CatalogComponent,
2176
+ I18nCatalogComponent] }); }
2053
2177
  static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: YuvFormsModule, imports: [formElementCmps] }); }
2054
2178
  }
2055
2179
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: YuvFormsModule, decorators: [{
@@ -2064,5 +2188,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
2064
2188
  * Generated bundle index. Do not edit.
2065
2189
  */
2066
2190
 
2067
- export { CatalogComponent, DataGridComponent, DatetimeComponent, DatetimeRangeComponent, FormUtils, NumberComponent, NumberRangeComponent, OrganizationComponent, OrganizationSetComponent, RangeSelectDateComponent, RangeSelectFilesizeComponent, StringComponent, YuvFormsModule };
2191
+ export { CatalogComponent, DataGridComponent, DatetimeComponent, DatetimeRangeComponent, FormUtils, I18nCatalogComponent, NumberComponent, NumberRangeComponent, OrganizationComponent, OrganizationSetComponent, RangeSelectDateComponent, RangeSelectFilesizeComponent, StringComponent, YuvFormsModule };
2068
2192
  //# sourceMappingURL=yuuvis-client-framework-forms.mjs.map