@messaia/cdk 22.0.1-rc.12 → 22.0.1-rc.14

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.
@@ -16130,7 +16130,7 @@ class AbstractSelectFormField extends AbstractMatFormField {
16130
16130
  /**
16131
16131
  * @property _endpoint
16132
16132
  * @description The API endpoint or a function returning the endpoint URL.
16133
- * @type {string | Function | undefined}
16133
+ * @type {string | URL | Function | undefined}
16134
16134
  */
16135
16135
  _endpoint;
16136
16136
  /**
@@ -16157,6 +16157,12 @@ class AbstractSelectFormField extends AbstractMatFormField {
16157
16157
  * @type {Function | undefined}
16158
16158
  */
16159
16159
  _enumFilter;
16160
+ /**
16161
+ * @property _default
16162
+ * @description A predicate that identifies default option(s) after options are loaded.
16163
+ * @type {((x: any) => boolean) | undefined}
16164
+ */
16165
+ _default;
16160
16166
  /**
16161
16167
  * @property _compareWith
16162
16168
  * @description A function to compare option values with the selected values.
@@ -16303,7 +16309,7 @@ class AbstractSelectFormField extends AbstractMatFormField {
16303
16309
  /**
16304
16310
  * @property endpoint
16305
16311
  * @description The API endpoint or a function returning the endpoint URL.
16306
- * @type {string | Function | undefined}
16312
+ * @type {string | URL | Function | undefined}
16307
16313
  */
16308
16314
  get endpoint() { return this._endpoint; }
16309
16315
  set endpoint(endpoint) { this._endpoint = endpoint; this.endpointChanged(); }
@@ -16349,6 +16355,16 @@ class AbstractSelectFormField extends AbstractMatFormField {
16349
16355
  */
16350
16356
  get enumFilter() { return this._enumFilter; }
16351
16357
  set enumFilter(enumFilter) { this._enumFilter = enumFilter; this.enumChanged(); }
16358
+ /**
16359
+ * @property default
16360
+ * @description A predicate used to select default option(s) from loaded options.
16361
+ * @type {((x: any) => boolean) | undefined}
16362
+ */
16363
+ get default() { return this._default; }
16364
+ set default(defaultFn) {
16365
+ this._default = defaultFn;
16366
+ this.applyDefaultSelection();
16367
+ }
16352
16368
  /**
16353
16369
  * @property disabled
16354
16370
  * @description Whether the control is disabled.
@@ -16440,7 +16456,8 @@ class AbstractSelectFormField extends AbstractMatFormField {
16440
16456
  */
16441
16457
  ngOnInit() {
16442
16458
  /* Keep filtered options aligned with the initial options input. */
16443
- this.filteredOptions = this.options;
16459
+ this.filteredOptions = Array.isArray(this.options) ? this.options : [];
16460
+ this.applyDefaultSelection();
16444
16461
  if (this.enum) {
16445
16462
  /* Build initial enum options before wiring reactive refresh subscriptions. */
16446
16463
  this.rebuildEnumOptions();
@@ -16474,12 +16491,15 @@ class AbstractSelectFormField extends AbstractMatFormField {
16474
16491
  }
16475
16492
  /* Get endpoint */
16476
16493
  let endpoint = typeof this.endpoint === 'function' ? this.endpoint(this) : this.endpoint;
16494
+ endpoint = endpoint instanceof URL ? endpoint.toString() : endpoint;
16477
16495
  if (this._http && endpoint && this.loadData) {
16478
16496
  /* Resolve remote options and keep emitted item payloads in sync. */
16479
16497
  this._http.get(endpoint, { params: params, headers: headers })
16480
16498
  .pipe(map((x) => this.mapper ? this.mapper(x) : x))
16481
16499
  .subscribe(x => {
16482
- this.filteredOptions = this.options = x;
16500
+ this.filteredOptions = this.options = this.normalizeOptions(x);
16501
+ /* Auto-select option(s) marked as default when no value is set. */
16502
+ this.applyDefaultSelection();
16483
16503
  /* Select the first option by default if applicable */
16484
16504
  if (this.selectFirst && !this.value && this.options?.length > 0) {
16485
16505
  this.value = this.multiple ? [this.options[0]] : this.options[0][this.optionValueProperty];
@@ -16531,12 +16551,13 @@ class AbstractSelectFormField extends AbstractMatFormField {
16531
16551
  * @param value
16532
16552
  */
16533
16553
  handleItemSelected(value) {
16554
+ const options = this.normalizeOptions(this.options);
16534
16555
  /* Map selected primitive values back to option model objects. */
16535
16556
  if (this.multiple) {
16536
- this.onItemSelected.emit(this.options.filter((x) => (value || []).includes(x[this.optionValueProperty])));
16557
+ this.onItemSelected.emit(options.filter((x) => (value || []).includes(x[this.optionValueProperty])));
16537
16558
  }
16538
16559
  else {
16539
- this.onItemSelected.emit(this.options.filter((x) => x[this.optionValueProperty] == value)[0]);
16560
+ this.onItemSelected.emit(options.filter((x) => x[this.optionValueProperty] == value)[0]);
16540
16561
  }
16541
16562
  }
16542
16563
  /**
@@ -16544,12 +16565,13 @@ class AbstractSelectFormField extends AbstractMatFormField {
16544
16565
  * @param value
16545
16566
  */
16546
16567
  handleItemChange(value) {
16568
+ const options = this.normalizeOptions(this.options);
16547
16569
  /* Emit changed option model objects to keep consumers decoupled from raw ids. */
16548
16570
  if (this.multiple) {
16549
- this.onItemChange.emit(this.options.filter((x) => (value || []).includes(x[this.optionValueProperty])));
16571
+ this.onItemChange.emit(options.filter((x) => (value || []).includes(x[this.optionValueProperty])));
16550
16572
  }
16551
16573
  else {
16552
- this.onItemChange.emit(this.options.filter((x) => x[this.optionValueProperty] == value)[0]);
16574
+ this.onItemChange.emit(options.filter((x) => x[this.optionValueProperty] == value)[0]);
16553
16575
  }
16554
16576
  }
16555
16577
  /**
@@ -16557,13 +16579,14 @@ class AbstractSelectFormField extends AbstractMatFormField {
16557
16579
  * @param $event
16558
16580
  */
16559
16581
  handleFilter($event) {
16582
+ const options = this.normalizeOptions(this.options);
16560
16583
  /* Normalize search text and apply the configured option text projection. */
16561
16584
  let searchText = $event?.target?.value ?? '';
16562
16585
  if (this.searchField) {
16563
- this.filteredOptions = this.options.filter((x) => this.searchField(x)?.toLowerCase().search(searchText.toLowerCase()) > -1);
16586
+ this.filteredOptions = options.filter((x) => this.searchField(x)?.toLowerCase().search(searchText.toLowerCase()) > -1);
16564
16587
  }
16565
16588
  else {
16566
- this.filteredOptions = this.options.filter((x) => x[this.optionTextProperty]?.toLowerCase().search(searchText.toLowerCase()) > -1);
16589
+ this.filteredOptions = options.filter((x) => x[this.optionTextProperty]?.toLowerCase().search(searchText.toLowerCase()) > -1);
16567
16590
  }
16568
16591
  }
16569
16592
  /**
@@ -16572,13 +16595,69 @@ class AbstractSelectFormField extends AbstractMatFormField {
16572
16595
  * @returns An array of filtered options that match the given value.
16573
16596
  */
16574
16597
  filterValue(value) {
16598
+ const options = this.normalizeOptions(this.options);
16575
16599
  /* Check if a comparison function is defined */
16576
16600
  if (this.compareWith) {
16577
16601
  /* Return options that match any of the provided values using the compareWith function */
16578
- return this.options?.filter((option) => (value || []).some(val => this.compareWith(option, val)));
16602
+ return options.filter((option) => (value || []).some(val => this.compareWith(option, val)));
16579
16603
  }
16580
16604
  /* If no comparison function is defined, return options that are included in the provided values */
16581
- return this.options?.filter((option) => (value || []).includes(option[this.optionValueProperty]));
16605
+ return options.filter((option) => (value || []).includes(option[this.optionValueProperty]));
16606
+ }
16607
+ /**
16608
+ * @description Normalizes endpoint payloads to a safe array for template iteration.
16609
+ * @param source Raw payload from endpoint or mapper.
16610
+ * @returns {any[]} Iterable options array.
16611
+ */
16612
+ normalizeOptions(source) {
16613
+ /* Handle different types of source payloads */
16614
+ if (Array.isArray(source)) {
16615
+ return source;
16616
+ }
16617
+ /* If the source is null or undefined, return an empty array immediately */
16618
+ if (source && typeof source === 'object') {
16619
+ /* Attempt to extract a collection from common array-containing properties */
16620
+ const collection = [source.items, source.results, source.data, source.values, source.content, source.rows, source.printers]
16621
+ .find((x) => Array.isArray(x));
16622
+ /* If a collection was found, return it */
16623
+ if (Array.isArray(collection)) {
16624
+ return collection;
16625
+ }
16626
+ /* If the source object contains the option value or text properties, wrap it in an array and return it */
16627
+ if (this.optionValueProperty in source || this.optionTextProperty in source) {
16628
+ return [source];
16629
+ }
16630
+ }
16631
+ return [];
16632
+ }
16633
+ /**
16634
+ * @description Applies default option selection when a default predicate is configured.
16635
+ * @returns {void}
16636
+ */
16637
+ applyDefaultSelection() {
16638
+ /* Skip default selection if no default predicate is defined or a value is already set */
16639
+ if (!this._default || this.value) {
16640
+ return;
16641
+ }
16642
+ /* Normalize the available options before applying default selection */
16643
+ const options = this.normalizeOptions(this.options);
16644
+ if (!options.length) {
16645
+ return;
16646
+ }
16647
+ /* Apply default selection for multiple selection scenario if applicable */
16648
+ if (this.multiple) {
16649
+ this.value = options
16650
+ .filter((option) => this._default(option))
16651
+ .map((option) => option[this.optionValueProperty]);
16652
+ }
16653
+ /* Handle single selection scenario */
16654
+ else {
16655
+ /* Apply default selection for single selection scenario if applicable */
16656
+ const selected = options.filter((option) => this._default(option))[0];
16657
+ if (selected) {
16658
+ this.value = selected[this.optionValueProperty];
16659
+ }
16660
+ }
16582
16661
  }
16583
16662
  /**
16584
16663
  * Trigger endpoint changed
@@ -16603,7 +16682,7 @@ class AbstractSelectFormField extends AbstractMatFormField {
16603
16682
  this.filterable = this.enumMetadata != null;
16604
16683
  /* Rebuild enum options from metadata so dynamic hide and disable callbacks re-run. */
16605
16684
  this.options = this.enumMetadata
16606
- ? EnumService.applyMetadata(this.enum, this.enumMetadata, this.getEnumContext())
16685
+ ? EnumService.applyMetadata(this.enum, this.enumMetadata, this.context)
16607
16686
  : EnumService.toArray(this.enum, this.prefix);
16608
16687
  /* Apply optional enum-level filter after metadata transformation. */
16609
16688
  if (this._enumFilter && this.options) {
@@ -16611,40 +16690,8 @@ class AbstractSelectFormField extends AbstractMatFormField {
16611
16690
  }
16612
16691
  /* Keep filtered list synchronized with rebuilt options. */
16613
16692
  this.filteredOptions = this.options;
16614
- }
16615
- /**
16616
- * @description Creates an enriched metadata context containing the latest form state.
16617
- * @returns {any} Metadata context used by EnumMetadata hide and disable callbacks.
16618
- */
16619
- getEnumContext() {
16620
- /* Resolve root form state so metadata callbacks can evaluate against current values. */
16621
- const rootControl = this.ngControl?.control?.root;
16622
- const formValue = rootControl?.getRawValue?.() ?? rootControl?.value;
16623
- /* Fall back to original context when form state or context is unavailable. */
16624
- if (this.context == null || formValue == null) {
16625
- return this.context;
16626
- }
16627
- /* For primitive contexts, create an explicit wrapper payload with form information. */
16628
- if (typeof this.context !== 'object' && typeof this.context !== 'function') {
16629
- return {
16630
- context: this.context,
16631
- data: this.context,
16632
- entity: formValue,
16633
- formValue: formValue,
16634
- formGroup: rootControl
16635
- };
16636
- }
16637
- /* Preserve prototype access to context methods while attaching fresh runtime fields. */
16638
- const enumContext = Object.create(this.context);
16639
- /* Define own properties to avoid writing to getter-only members on inherited contexts. */
16640
- Object.defineProperties(enumContext, {
16641
- context: { value: this.context, enumerable: true, configurable: true, writable: true },
16642
- data: { value: this.context?.data ?? this.context, enumerable: true, configurable: true, writable: true },
16643
- entity: { value: formValue, enumerable: true, configurable: true, writable: true },
16644
- formValue: { value: formValue, enumerable: true, configurable: true, writable: true },
16645
- formGroup: { value: rootControl, enumerable: true, configurable: true, writable: true }
16646
- });
16647
- return enumContext;
16693
+ /* Apply default selection for enum-based option sources as well. */
16694
+ this.applyDefaultSelection();
16648
16695
  }
16649
16696
  /**
16650
16697
  * Log to console
@@ -16655,7 +16702,7 @@ class AbstractSelectFormField extends AbstractMatFormField {
16655
16702
  console.log(message, optionalParams);
16656
16703
  }
16657
16704
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: AbstractSelectFormField, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
16658
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.7", type: AbstractSelectFormField, isStandalone: true, inputs: { enum: "enum", enumMetadata: "enumMetadata", textPrefix: "textPrefix", optionTextProperty: "optionTextProperty", optionValueProperty: "optionValueProperty", matIconKey: "matIconKey", svgIconKey: "svgIconKey", fontSet: "fontSet", prefix: "prefix", options: "options", filteredOptions: "filteredOptions", filterable: "filterable", cache: "cache", selectFirst: "selectFirst", sortBy: "sortBy", mapper: "mapper", optionIcon: "optionIcon", defaultOption: "defaultOption", multiple: "multiple", sorted: "sorted", endpoint: "endpoint", params: "params", projection: "projection", loadData: "loadData", enumFilter: "enumFilter", disabled: "disabled", context: "context", compareWith: "compareWith", searchField: "searchField" }, outputs: { onValueChange: "change", onItemChange: "itemChange", onSelected: "selected", onItemSelected: "itemSelected", onLaunch: "launch" }, usesInheritance: true, ngImport: i0 });
16705
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.7", type: AbstractSelectFormField, isStandalone: true, inputs: { enum: "enum", enumMetadata: "enumMetadata", textPrefix: "textPrefix", optionTextProperty: "optionTextProperty", optionValueProperty: "optionValueProperty", matIconKey: "matIconKey", svgIconKey: "svgIconKey", fontSet: "fontSet", prefix: "prefix", options: "options", filteredOptions: "filteredOptions", filterable: "filterable", cache: "cache", selectFirst: "selectFirst", sortBy: "sortBy", mapper: "mapper", optionIcon: "optionIcon", defaultOption: "defaultOption", multiple: "multiple", sorted: "sorted", endpoint: "endpoint", params: "params", projection: "projection", loadData: "loadData", enumFilter: "enumFilter", default: "default", disabled: "disabled", context: "context", compareWith: "compareWith", searchField: "searchField" }, outputs: { onValueChange: "change", onItemChange: "itemChange", onSelected: "selected", onItemSelected: "itemSelected", onLaunch: "launch" }, usesInheritance: true, ngImport: i0 });
16659
16706
  }
16660
16707
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: AbstractSelectFormField, decorators: [{
16661
16708
  type: Directive
@@ -16709,6 +16756,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
16709
16756
  type: Input
16710
16757
  }], enumFilter: [{
16711
16758
  type: Input
16759
+ }], default: [{
16760
+ type: Input
16712
16761
  }], disabled: [{
16713
16762
  type: Input
16714
16763
  }], context: [{
@@ -24349,6 +24398,11 @@ class FormFieldDefinition {
24349
24398
  * Defaults to true.
24350
24399
  */
24351
24400
  defaultOption = true;
24401
+ /**
24402
+ * Predicate used to resolve the default option(s) from loaded options.
24403
+ * Return true for the option(s) that should be preselected.
24404
+ */
24405
+ default;
24352
24406
  /**
24353
24407
  * Template function for rendering options in the selection.
24354
24408
  * @param x The current property value.
@@ -25732,6 +25786,7 @@ class MsaGenericFormMsaListFieldComponent extends MsaGenericFormFieldBaseCompone
25732
25786
  [loadData]="field.fetchCondition | func:formValue:formGroup:context"
25733
25787
  [optionValueProperty]="field.optionValueProperty"
25734
25788
  [optionTextProperty]="field.optionTextProperty"
25789
+ [default]="field.default"
25735
25790
  [multiple]="field.multiple"
25736
25791
  [readonly]="(readonly || (field.readonly && field.readonly(formValue, formGroup, context)))??false"
25737
25792
  (itemSelected)="field.itemSelect && field.itemSelect($event, formValue, formGroup, context);"
@@ -25770,6 +25825,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
25770
25825
  [loadData]="field.fetchCondition | func:formValue:formGroup:context"
25771
25826
  [optionValueProperty]="field.optionValueProperty"
25772
25827
  [optionTextProperty]="field.optionTextProperty"
25828
+ [default]="field.default"
25773
25829
  [multiple]="field.multiple"
25774
25830
  [readonly]="(readonly || (field.readonly && field.readonly(formValue, formGroup, context)))??false"
25775
25831
  (itemSelected)="field.itemSelect && field.itemSelect($event, formValue, formGroup, context);"
@@ -25846,6 +25902,7 @@ class MsaGenericFormMsaSelectFieldComponent extends MsaGenericFormFieldBaseCompo
25846
25902
  [optionValueProperty]="field.optionValueProperty"
25847
25903
  [optionTextProperty]="field.optionTextProperty"
25848
25904
  [defaultOption]="field.defaultOption??true"
25905
+ [default]="field.default"
25849
25906
  [matIconKey]="field.optionMatIconProperty"
25850
25907
  [svgIconKey]="field.optionSvgIconProperty"
25851
25908
  [fontSet]="field.optionIconFontSet"
@@ -25945,6 +26002,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
25945
26002
  [optionValueProperty]="field.optionValueProperty"
25946
26003
  [optionTextProperty]="field.optionTextProperty"
25947
26004
  [defaultOption]="field.defaultOption??true"
26005
+ [default]="field.default"
25948
26006
  [matIconKey]="field.optionMatIconProperty"
25949
26007
  [svgIconKey]="field.optionSvgIconProperty"
25950
26008
  [fontSet]="field.optionIconFontSet"