@ethlete/cdk 5.0.0-next.38 → 5.0.0-next.39

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ethlete/cdk
2
2
 
3
+ ## 5.0.0-next.39
4
+
5
+ ### Patch Changes
6
+
7
+ - Keep a form control's value in `et-combobox` while async options load and when the loaded options do not contain it, instead of overwriting it with `null`.
8
+
3
9
  ## 5.0.0-next.38
4
10
 
5
11
  ### Minor Changes
@@ -15042,6 +15042,9 @@ class ActiveSelectionModel {
15042
15042
  }
15043
15043
 
15044
15044
  class SelectionModel {
15045
+ get isSyncingSelectionFromValue() {
15046
+ return this._isSyncingSelectionFromValue;
15047
+ }
15045
15048
  get selection$() {
15046
15049
  return this._selection$.asObservable();
15047
15050
  }
@@ -15093,6 +15096,7 @@ class SelectionModel {
15093
15096
  constructor() {
15094
15097
  this._destroy$ = createDestroy();
15095
15098
  this._lastSelectionSetSubscription = null;
15099
+ this._isSyncingSelectionFromValue = false;
15096
15100
  this._selection$ = new BehaviorSubject([]);
15097
15101
  this._options$ = new BehaviorSubject([]);
15098
15102
  this.optionsSignal = toSignal(this.options$);
@@ -15137,19 +15141,22 @@ class SelectionModel {
15137
15141
  }
15138
15142
  else {
15139
15143
  const selection = this.getOptionByValue(value);
15140
- if (selection !== undefined) {
15141
- this.setSelection(selection);
15142
- }
15143
- else {
15144
- this.clearSelectedOptions();
15145
- }
15144
+ this.setSelection(selection !== undefined ? selection : []);
15146
15145
  }
15147
15146
  }
15147
+ /**
15148
+ * Applies `value` once options are available. Until then, and while applying it, `isSyncingSelectionFromValue` is `true`.
15149
+ * Any user selection change cancels a pending sync.
15150
+ */
15148
15151
  setSelectionFromValue$(value) {
15149
- this._lastSelectionSetSubscription?.unsubscribe();
15152
+ this._cancelPendingSelectionFromValue();
15153
+ this._isSyncingSelectionFromValue = true;
15150
15154
  this._lastSelectionSetSubscription = this.options$
15151
- .pipe(takeUntil(this._destroy$), filter((o) => !!o.length), tap(() => this.setSelectionFromValue(value)), take(1))
15152
- .subscribe();
15155
+ .pipe(takeUntil(this._destroy$), filter((o) => !!o.length), take(1))
15156
+ .subscribe(() => {
15157
+ this.setSelectionFromValue(value);
15158
+ this._isSyncingSelectionFromValue = false;
15159
+ });
15153
15160
  }
15154
15161
  setValueBinding(fnOrPropertyPath) {
15155
15162
  this._valueBinding$.next(fnOrPropertyPath);
@@ -15365,6 +15372,7 @@ class SelectionModel {
15365
15372
  });
15366
15373
  }
15367
15374
  addSelectedOption(option) {
15375
+ this._cancelPendingSelectionFromValue();
15368
15376
  if (this.allowMultiple) {
15369
15377
  if (this.isSelected(option))
15370
15378
  return;
@@ -15375,6 +15383,7 @@ class SelectionModel {
15375
15383
  }
15376
15384
  }
15377
15385
  removeSelectedOption(option) {
15386
+ this._cancelPendingSelectionFromValue();
15378
15387
  const optionKey = this.execFnOrGetOptionProperty(option, this.keyBinding);
15379
15388
  if (!this.isSelected(option))
15380
15389
  return;
@@ -15384,6 +15393,7 @@ class SelectionModel {
15384
15393
  }));
15385
15394
  }
15386
15395
  clearSelectedOptions() {
15396
+ this._cancelPendingSelectionFromValue();
15387
15397
  this._selection$.next([]);
15388
15398
  }
15389
15399
  toggleSelectedOption(option) {
@@ -15396,6 +15406,7 @@ class SelectionModel {
15396
15406
  }
15397
15407
  // FIXME: Toggle should respect disabled binding if it exists
15398
15408
  toggleAllSelectedOptions() {
15409
+ this._cancelPendingSelectionFromValue();
15399
15410
  const filteredOptions = this.getFilteredOptions();
15400
15411
  const unselectedOptions = filteredOptions.filter((option) => !this.isSelected(option));
15401
15412
  if (unselectedOptions.length) {
@@ -15407,6 +15418,11 @@ class SelectionModel {
15407
15418
  this._selection$.next(selection);
15408
15419
  }
15409
15420
  }
15421
+ _cancelPendingSelectionFromValue() {
15422
+ this._lastSelectionSetSubscription?.unsubscribe();
15423
+ this._lastSelectionSetSubscription = null;
15424
+ this._isSyncingSelectionFromValue = false;
15425
+ }
15410
15426
  }
15411
15427
 
15412
15428
  /**
@@ -15894,6 +15910,7 @@ class ComboboxDirective {
15894
15910
  this._comboboxConfig = inject(COMBOBOX_CONFIG_TOKEN, { optional: true });
15895
15911
  this.colorProvider = inject(COLOR_PROVIDER, { optional: true });
15896
15912
  this._initialValue$ = new BehaviorSubject(null);
15913
+ this._hasReceivedSelectionValue = false;
15897
15914
  this._filterInternal$ = new BehaviorSubject(false);
15898
15915
  this._loading$ = new BehaviorSubject(false);
15899
15916
  this.loading$ = this._loading$.asObservable();
@@ -16002,9 +16019,15 @@ class ComboboxDirective {
16002
16019
  this._debugValidateOptionAndInitialValueSchema();
16003
16020
  }
16004
16021
  this._selectionModel.setSelectionFromValue$(this._input.value);
16022
+ const hasInitialControlValue = this._input.value !== null && this._input.value !== undefined;
16005
16023
  this._selectionModel.value$
16006
16024
  .pipe(takeUntil(this._destroy$), tap((value) => {
16007
- this._input._updateValue(value);
16025
+ const isInitialEmission = !this._hasReceivedSelectionValue;
16026
+ this._hasReceivedSelectionValue = true;
16027
+ const keepsControlValue = this._selectionModel.isSyncingSelectionFromValue || (isInitialEmission && hasInitialControlValue);
16028
+ if (!keepsControlValue) {
16029
+ this._input._updateValue(value);
16030
+ }
16008
16031
  this._setFilterFromInputValue();
16009
16032
  }))
16010
16033
  .subscribe();