@elderbyte/ngx-starter 13.7.3 → 13.7.6

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.
@@ -2156,7 +2156,7 @@ class CollectionUtil {
2156
2156
  return false;
2157
2157
  }
2158
2158
  /**
2159
- * Moves the given item up in the given array - if not already at the bottom
2159
+ * Moves the given item up in the given array - if not already at the top
2160
2160
  * @param items
2161
2161
  * @param toMove
2162
2162
  */
@@ -3822,7 +3822,7 @@ class MatTableDataContextBinding {
3822
3822
  }
3823
3823
  }
3824
3824
  bindDataContextToMatSortsUntil(matSorts$, destroy$) {
3825
- const dcSorts$ = this._dataContext$.pipe(switchMap(dc => dc.sort.sorts));
3825
+ const dcSorts$ = this._dataContext$.pipe(filter(dc => !!dc), switchMap(dc => dc.sort.sorts));
3826
3826
  combineLatest([dcSorts$, matSorts$]).pipe(takeUntil(destroy$)).subscribe(([dcSorts, matSorts]) => {
3827
3827
  if (dcSorts.length >= 1) {
3828
3828
  // At least one sort active
@@ -3859,19 +3859,23 @@ class MatTableDataContextBinding {
3859
3859
  return new Sort(matSort.active, this.fromMatDirection(matSort.direction));
3860
3860
  }));
3861
3861
  combineLatest([this._dataContext$, sortChanges$]).pipe(takeUntil(destroy$)).subscribe(([dc, sortRequest]) => {
3862
- dc.sort.updateSort(sortRequest);
3862
+ if (dc) {
3863
+ dc.sort.updateSort(sortRequest);
3864
+ }
3863
3865
  });
3864
3866
  }
3865
3867
  bindPaginatorUntil(paginator$, destroy$) {
3866
3868
  const pageRequest$ = paginator$.pipe(filter(paginator => !!paginator), switchMap(paginator => paginator.page), map(pageEvent => new PageRequest(pageEvent.pageIndex, pageEvent.pageSize)));
3867
3869
  combineLatest([this._dataContext$, pageRequest$]).pipe(takeUntil(destroy$)).subscribe(([dc, pageRequest]) => {
3868
- if (isActivePagedDataContext(dc)) {
3869
- const pagedDc = dc;
3870
- pagedDc.setActivePage(pageRequest);
3871
- }
3872
- else {
3873
- this.logger.warn('Can not bind the given paginator to the given data-context,' +
3874
- ' as the datacontext does not support pagination!', dc);
3870
+ if (dc) {
3871
+ if (isActivePagedDataContext(dc)) {
3872
+ const pagedDc = dc;
3873
+ pagedDc.setActivePage(pageRequest);
3874
+ }
3875
+ else {
3876
+ this.logger.warn('Can not bind the given paginator to the given data-context,' +
3877
+ ' as the datacontext does not support pagination!', dc);
3878
+ }
3875
3879
  }
3876
3880
  });
3877
3881
  }
@@ -5260,7 +5264,7 @@ class ValueAccessorBase {
5260
5264
  * except the initial value which is skipped.
5261
5265
  */
5262
5266
  get valueChange() {
5263
- return this._value$.pipe(skip(1) // Skip the initial NULL value
5267
+ return this._value$.pipe(skip(1) // Skip the current / initial value
5264
5268
  );
5265
5269
  }
5266
5270
  /**
@@ -20244,6 +20248,7 @@ class ElderSelectBase extends FormFieldBaseComponent {
20244
20248
  **************************************************************************/
20245
20249
  this._logger = LoggerFactory.getLogger(this.constructor.name);
20246
20250
  this._filterContext = new FilterContext();
20251
+ this.timeoutAfterMs = 5000;
20247
20252
  /**
20248
20253
  * Define if elder-select should clean up the
20249
20254
  * data-context resources for you.
@@ -20894,16 +20899,19 @@ class ElderSelectComponent extends ElderSelectBase {
20894
20899
  * String to display for the 'nothing' / null value.
20895
20900
  */
20896
20901
  this.nullDisplay = '-';
20897
- this.entity$ = new BehaviorSubject(undefined);
20902
+ this._entity$ = new BehaviorSubject(undefined);
20898
20903
  this._autocomplete = false;
20899
20904
  this.unsubscribe$ = new Subject();
20900
20905
  this.entityIdChange = this.valueChange.pipe(map(v => this.entityIdFromValue(v)));
20901
- this.entityChange = this.entity$.pipe(skip(1) // Skip the initial NULL value
20906
+ this.entityChange = this._entity$.pipe(skip(1) // Skip the initial or current value
20902
20907
  );
20903
20908
  this.entityIdUpdated = this.valueUpdated.pipe(map(value => this.entityIdFromValue(value)));
20904
- this.entityUpdated = combineLatest([this.entityIdUpdated, this.entity$]).pipe(filter(([updatedId, entity]) => this.getEntityId(entity) === updatedId), map(([updatedId, entity]) => entity));
20909
+ this.entityUpdated = this.entityIdUpdated.pipe(switchMap(entityId => this.awaitEntityWithId(entityId, this.timeoutAfterMs)), catchError(err => {
20910
+ this.logger.warn(`awaitEntityWithId -> timed out after: ${this.timeoutAfterMs}`, err);
20911
+ return EMPTY;
20912
+ }));
20905
20913
  this.entityWrapped$ = combineLatest([
20906
- this.entity$,
20914
+ this._entity$,
20907
20915
  this.displayPropertyResolver$,
20908
20916
  this.hintPropertyResolver$
20909
20917
  ]).pipe(map(([value, dPR, hPR]) => new EntityContext(value, hPR(value), dPR(value))));
@@ -20954,11 +20962,17 @@ class ElderSelectComponent extends ElderSelectBase {
20954
20962
  * *
20955
20963
  **************************************************************************/
20956
20964
  set entity(entity) {
20957
- this.entity$.next(entity);
20965
+ this._entity$.next(entity);
20958
20966
  this.writeValueInternal(this.entityToValue(entity));
20959
20967
  }
20960
20968
  get entity() {
20961
- return this.entity$.getValue();
20969
+ return this._entity$.getValue();
20970
+ }
20971
+ /**
20972
+ * Gets the current entity as observable stream. (BehaviourSubject)
20973
+ */
20974
+ get entity$() {
20975
+ return this._entity$.asObservable();
20962
20976
  }
20963
20977
  set entityId(id) {
20964
20978
  if (this.valueAsId) {
@@ -21086,6 +21100,9 @@ class ElderSelectComponent extends ElderSelectBase {
21086
21100
  valuesEquals(a, b) {
21087
21101
  return this.entityIdFromValue(a) === this.entityIdFromValue(b);
21088
21102
  }
21103
+ awaitEntityWithId(entityId, timeoutMs) {
21104
+ return this.entity$.pipe(filter(entity => this.getEntityId(entity) === entityId), take(1), timeout(timeoutMs));
21105
+ }
21089
21106
  isEntitySelected(entity) {
21090
21107
  return this.getEntityId(entity) === this.entityId;
21091
21108
  }
@@ -21163,7 +21180,7 @@ class ElderSelectComponent extends ElderSelectBase {
21163
21180
  const newEntity = value;
21164
21181
  this.logger.debug('writeToControl: value was written as entity: ' + JSON.stringify(newEntity), value);
21165
21182
  if (!this.isEqual(currentEntity, newEntity)) {
21166
- this.entity$.next(newEntity);
21183
+ this._entity$.next(newEntity);
21167
21184
  }
21168
21185
  else {
21169
21186
  this.logger.warn('Ignored written entity as it is already set to entity$!');
@@ -21189,7 +21206,7 @@ class ElderSelectComponent extends ElderSelectBase {
21189
21206
  }
21190
21207
  }
21191
21208
  ElderSelectComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.1", ngImport: i0, type: ElderSelectComponent, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
21192
- ElderSelectComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: ElderSelectComponent, selector: "elder-select", inputs: { nullDisplay: "nullDisplay", autocomplete: "autocomplete", allowNull: "allowNull", entity: "entity", entityId: "entityId", hintProperty: "hintProperty", hintPropertyResolver: "hintPropertyResolver" }, outputs: { entityIdChange: "entityIdChange", entityChange: "entityChange", entityIdUpdated: "entityIdUpdated", entityUpdated: "entityUpdated" }, providers: [
21209
+ ElderSelectComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.1", type: ElderSelectComponent, selector: "elder-select", inputs: { nullDisplay: "nullDisplay", autocomplete: "autocomplete", allowNull: "allowNull", entity: "entity", entityId: "entityId", hintProperty: "hintProperty", hintPropertyResolver: "hintPropertyResolver" }, outputs: { entityIdChange: "entityIdChange", entityIdUpdated: "entityIdUpdated", entityChange: "entityChange", entityUpdated: "entityUpdated" }, providers: [
21193
21210
  {
21194
21211
  provide: ELDER_SELECT_BASE,
21195
21212
  useExisting: forwardRef(() => ElderSelectComponent)
@@ -21209,10 +21226,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.1", ngImpor
21209
21226
  type: Input
21210
21227
  }], entityIdChange: [{
21211
21228
  type: Output
21212
- }], entityChange: [{
21213
- type: Output
21214
21229
  }], entityIdUpdated: [{
21215
21230
  type: Output
21231
+ }], entityChange: [{
21232
+ type: Output
21216
21233
  }], entityUpdated: [{
21217
21234
  type: Output
21218
21235
  }], autocomplete: [{
@@ -21297,7 +21314,13 @@ class ElderMultiSelectBase extends ElderSelectBase {
21297
21314
  this.entities$ = new BehaviorSubject([]);
21298
21315
  this.entityIdsChange = this.valueChange.pipe(map(values => this.entityIdsFromValues(values)));
21299
21316
  this.entityIdsUpdated = this.valueUpdated.pipe(map(values => this.entityIdsFromValues(values)));
21300
- this.entitiesUpdated = combineLatest([this.entityIdsUpdated, this.entities$]).pipe(filter(([updatedIds, entities]) => this.equalIds(this.getEntityIds(entities), updatedIds)), map(([updatedIds, entities]) => entities));
21317
+ this.entitiesUpdated = this.entityIdsUpdated.pipe(switchMap(entityId => this.awaitEntitiesWithId(entityId, this.timeoutAfterMs)), catchError(err => {
21318
+ this.logger.warn(`awaitEntitiesWithId -> timed out after: ${this.timeoutAfterMs}`, err);
21319
+ return EMPTY;
21320
+ }));
21321
+ }
21322
+ awaitEntitiesWithId(entityIds, timeoutMs) {
21323
+ return this.entities$.pipe(filter(entities => this.equalIds(this.getEntityIds(entities), entityIds)), take(1), timeout(timeoutMs));
21301
21324
  }
21302
21325
  /***************************************************************************
21303
21326
  * *
@@ -21371,7 +21394,10 @@ class ElderMultiSelectBase extends ElderSelectBase {
21371
21394
  * *
21372
21395
  **************************************************************************/
21373
21396
  entityIdsFromValues(values) {
21374
- return values?.map(v => this.entityIdFromValue(v));
21397
+ if (values) {
21398
+ return values.map(v => this.entityIdFromValue(v));
21399
+ }
21400
+ return null;
21375
21401
  }
21376
21402
  entityIdFromValue(value) {
21377
21403
  if (this.valueAsId) {
@@ -21383,7 +21409,10 @@ class ElderMultiSelectBase extends ElderSelectBase {
21383
21409
  }
21384
21410
  }
21385
21411
  entitiesToValues(entities) {
21386
- return entities?.map(e => this.entityToValue(e));
21412
+ if (entities) {
21413
+ return entities.map(e => this.entityToValue(e));
21414
+ }
21415
+ return null;
21387
21416
  }
21388
21417
  entityToValue(entity) {
21389
21418
  if (this.valueAsId) {
@@ -21395,7 +21424,10 @@ class ElderMultiSelectBase extends ElderSelectBase {
21395
21424
  }
21396
21425
  }
21397
21426
  getEntityIds(values) {
21398
- return values?.map(v => this.getEntityId(v));
21427
+ if (values) {
21428
+ return values.map(v => this.getEntityId(v));
21429
+ }
21430
+ return null;
21399
21431
  }
21400
21432
  equalIds(idsA, idsB) {
21401
21433
  return Sets.equalContent(idsA, idsB);