@firestitch/filter 9.8.8 → 9.9.4

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.
@@ -45,6 +45,7 @@ export declare class FilterComponent implements OnInit, AfterViewInit, OnDestroy
45
45
  get filterParamsQuery(): Record<string, unknown>;
46
46
  get items(): BaseItem<import("../../interfaces/config.interface").IFilterConfigItem>[];
47
47
  get visibleItems(): BaseItem<import("../../interfaces/config.interface").IFilterConfigItem>[];
48
+ get itemsReady$(): Observable<boolean>;
48
49
  get hasFilterChips$(): Observable<boolean>;
49
50
  get hasVisibleItemOrSorting(): boolean;
50
51
  get hasKeyword(): boolean;
@@ -1,7 +1,9 @@
1
+ import { Observable } from 'rxjs';
1
2
  import { ItemType } from '../../enums/item-type.enum';
2
3
  import { BaseItem } from '../../models/items/base-item';
3
4
  export declare type FilterConfigDateType = ItemType.Date | ItemType.DateTime | ItemType.DateRange | ItemType.DateTimeRange;
4
5
  export declare type FilterDateRangeType = ItemType.DateRange | ItemType.DateTimeRange;
6
+ export declare type IFilterDefaultFn = () => Observable<unknown>;
5
7
  export interface IFilterConfigBaseItem<T = ItemType, U = string> {
6
8
  name: string;
7
9
  type: T;
@@ -11,7 +13,7 @@ export interface IFilterConfigBaseItem<T = ItemType, U = string> {
11
13
  disable?: boolean;
12
14
  values?: any;
13
15
  primary?: boolean;
14
- default?: unknown;
16
+ default?: IFilterDefaultFn | any;
15
17
  change?: (item: BaseItem<any>) => void;
16
18
  clear?: boolean;
17
19
  disablePersist?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { BehaviorSubject, Observable, Subject } from 'rxjs';
2
- import { IFilterConfigBaseItem } from '../../interfaces/items/base.interface';
2
+ import { IFilterConfigBaseItem, IFilterDefaultFn } from '../../interfaces/items/base.interface';
3
3
  import { IFilterItemDefaultRange } from '../../interfaces/items/range.interface';
4
4
  export declare abstract class BaseItem<T extends IFilterConfigBaseItem> {
5
5
  protected _additionalConfig: unknown;
@@ -8,6 +8,7 @@ export declare abstract class BaseItem<T extends IFilterConfigBaseItem> {
8
8
  chipLabel: string | string[];
9
9
  hide: boolean;
10
10
  defaultValue: any | IFilterItemDefaultRange;
11
+ defaultValueFn: IFilterDefaultFn;
11
12
  persistedValue: unknown;
12
13
  clearAllowed: boolean;
13
14
  persistanceDisabled: boolean;
@@ -15,8 +16,8 @@ export declare abstract class BaseItem<T extends IFilterConfigBaseItem> {
15
16
  change: (item: BaseItem<T>) => void;
16
17
  protected readonly _type: T['type'];
17
18
  protected _model: any;
18
- protected _initialized: boolean;
19
19
  protected _pendingValues: boolean;
20
+ protected _pendingDefaultValue: boolean;
20
21
  protected _loading$: BehaviorSubject<boolean>;
21
22
  protected _value$: BehaviorSubject<any>;
22
23
  protected _valueChange$: Subject<void>;
@@ -41,6 +42,7 @@ export declare abstract class BaseItem<T extends IFilterConfigBaseItem> {
41
42
  get destroy$(): Observable<void>;
42
43
  get type(): T['type'];
43
44
  get hasPendingValues(): boolean;
45
+ get hasPendingDefaultValue(): boolean;
44
46
  get model(): any;
45
47
  set model(value: any);
46
48
  set values(values: any);
@@ -53,9 +55,11 @@ export declare abstract class BaseItem<T extends IFilterConfigBaseItem> {
53
55
  get loading$(): Observable<boolean>;
54
56
  get loading(): boolean;
55
57
  set loading(value: boolean);
58
+ protected get _initialized(): boolean;
56
59
  valueChanged(): void;
57
60
  get queryObject(): Record<string, unknown>;
58
61
  get persistanceObject(): Record<string, unknown>;
62
+ loadDefaultValue(): Observable<any>;
59
63
  initValues(persistedValue: unknown): void;
60
64
  loadAsyncValues(reload?: boolean): void;
61
65
  clear(defaultValue?: unknown): void;
@@ -15,6 +15,7 @@ export declare class FsFilterItemsStore implements OnDestroy {
15
15
  sortByItem: BaseItem<IFilterConfigItem>;
16
16
  sortDirectionItem: BaseItem<IFilterConfigItem>;
17
17
  keywordItem: TextItem;
18
+ private _ready$;
18
19
  private _items;
19
20
  private _visibleItems$;
20
21
  private _itemsByName;
@@ -22,6 +23,7 @@ export declare class FsFilterItemsStore implements OnDestroy {
22
23
  private _hasKeyword;
23
24
  private _config;
24
25
  private _itemsChange$;
26
+ private _destroy$;
25
27
  constructor();
26
28
  get items(): BaseItem<IFilterConfigItem>[];
27
29
  get visibleItems(): BaseItem<IFilterConfigItem>[];
@@ -29,12 +31,14 @@ export declare class FsFilterItemsStore implements OnDestroy {
29
31
  set visibleItems(items: BaseItem<IFilterConfigItem>[]);
30
32
  get hasKeyword(): boolean;
31
33
  get itemsChange$(): Observable<unknown>;
34
+ get ready$(): Observable<boolean>;
32
35
  ngOnDestroy(): void;
33
36
  setConfig(config: any): void;
34
37
  getItemByName(name: string): BaseItem<IFilterConfigBaseItem>;
35
38
  initItems(items: IFilterConfigItem[]): void;
36
39
  filtersClear(): void;
37
40
  loadAsyncValues(): void;
41
+ loadAsyncDefaults(): void;
38
42
  getSort(): FilterSort;
39
43
  getSortByValue(): any;
40
44
  getSortDirectionValue(): any;
@@ -51,6 +55,7 @@ export declare class FsFilterItemsStore implements OnDestroy {
51
55
  updateVisibleItems(): void;
52
56
  private _createItems;
53
57
  private _subscribeToItemsChanges;
58
+ private _lazyInit;
54
59
  private _createSortingItems;
55
60
  private _setKeywordItem;
56
61
  }
@@ -254,8 +254,9 @@
254
254
  var BaseItem = /** @class */ (function () {
255
255
  function BaseItem(itemConfig, _additionalConfig) {
256
256
  this._additionalConfig = _additionalConfig;
257
- this._initialized = false;
257
+ // protected _initialized = false;
258
258
  this._pendingValues = false;
259
+ this._pendingDefaultValue = false;
259
260
  this._loading$ = new rxjs.BehaviorSubject(false);
260
261
  this._value$ = new rxjs.BehaviorSubject(null);
261
262
  this._valueChange$ = new rxjs.Subject();
@@ -372,6 +373,13 @@
372
373
  enumerable: true,
373
374
  configurable: true
374
375
  });
376
+ Object.defineProperty(BaseItem.prototype, "hasPendingDefaultValue", {
377
+ get: function () {
378
+ return this._pendingDefaultValue;
379
+ },
380
+ enumerable: true,
381
+ configurable: true
382
+ });
375
383
  Object.defineProperty(BaseItem.prototype, "model", {
376
384
  get: function () {
377
385
  return this._model;
@@ -445,6 +453,13 @@
445
453
  enumerable: true,
446
454
  configurable: true
447
455
  });
456
+ Object.defineProperty(BaseItem.prototype, "_initialized", {
457
+ get: function () {
458
+ return !this._pendingDefaultValue && !this._pendingValues;
459
+ },
460
+ enumerable: true,
461
+ configurable: true
462
+ });
448
463
  BaseItem.prototype.valueChanged = function () {
449
464
  this._value$.next(this.value);
450
465
  if (this.change) {
@@ -477,8 +492,19 @@
477
492
  enumerable: true,
478
493
  configurable: true
479
494
  });
495
+ BaseItem.prototype.loadDefaultValue = function () {
496
+ var _this = this;
497
+ this._pendingDefaultValue = true;
498
+ return this.defaultValueFn()
499
+ .pipe(operators.tap(function (value) {
500
+ _this.defaultValue = value;
501
+ _this._initDefaultModel();
502
+ }), operators.finalize(function () {
503
+ _this._pendingDefaultValue = false;
504
+ }));
505
+ };
480
506
  BaseItem.prototype.initValues = function (persistedValue) {
481
- this._initialized = false;
507
+ // this._initialized = false;
482
508
  this.persistedValue = persistedValue;
483
509
  this._initDefaultModel();
484
510
  var isAutocomplete = this.type === exports.ItemType.AutoComplete || this.type === exports.ItemType.AutoCompleteChips;
@@ -491,12 +517,12 @@
491
517
  this.values = valuesResult;
492
518
  // Move to some other place
493
519
  this._init();
494
- this._initialized = true;
520
+ // this._initialized = true;
495
521
  }
496
522
  }
497
523
  else {
498
524
  this._init();
499
- this._initialized = true;
525
+ // this._initialized = true;
500
526
  }
501
527
  };
502
528
  BaseItem.prototype.loadAsyncValues = function (reload) {
@@ -512,7 +538,7 @@
512
538
  _this.loading = false;
513
539
  _this._init();
514
540
  _this._validateModel();
515
- _this._initialized = true;
541
+ // this._initialized = true;
516
542
  });
517
543
  }
518
544
  };
@@ -540,7 +566,12 @@
540
566
  this.name = item.name;
541
567
  this.label = item.label;
542
568
  this.chipLabel = item.chipLabel;
543
- this.defaultValue = item.default;
569
+ if (typeof item.default === 'function') {
570
+ this.defaultValueFn = item.default;
571
+ }
572
+ else {
573
+ this.defaultValue = item.default;
574
+ }
544
575
  this.change = item.change;
545
576
  this.hide = item.hide;
546
577
  this.clearAllowed = (_a = item.clear) !== null && _a !== void 0 ? _a : true;
@@ -1724,12 +1755,15 @@
1724
1755
  this.sortByItem = null;
1725
1756
  this.sortDirectionItem = null;
1726
1757
  this.keywordItem = null;
1758
+ this._ready$ = new rxjs.BehaviorSubject(false);
1727
1759
  this._items = [];
1728
1760
  this._visibleItems$ = new rxjs.BehaviorSubject([]);
1729
1761
  this._itemsByName = new Map();
1730
1762
  this._itemsValuesLoaded = false;
1731
1763
  this._hasKeyword = false;
1732
1764
  this._itemsChange$ = new rxjs.Subject();
1765
+ this._destroy$ = new rxjs.Subject();
1766
+ this._lazyInit();
1733
1767
  }
1734
1768
  Object.defineProperty(FsFilterItemsStore.prototype, "items", {
1735
1769
  get: function () {
@@ -1769,8 +1803,17 @@
1769
1803
  enumerable: true,
1770
1804
  configurable: true
1771
1805
  });
1806
+ Object.defineProperty(FsFilterItemsStore.prototype, "ready$", {
1807
+ get: function () {
1808
+ return this._ready$.asObservable();
1809
+ },
1810
+ enumerable: true,
1811
+ configurable: true
1812
+ });
1772
1813
  FsFilterItemsStore.prototype.ngOnDestroy = function () {
1773
1814
  this.destroyItems();
1815
+ this._destroy$.next();
1816
+ this._destroy$.complete();
1774
1817
  };
1775
1818
  FsFilterItemsStore.prototype.setConfig = function (config) {
1776
1819
  this._itemsByName.clear();
@@ -1784,8 +1827,6 @@
1784
1827
  this._itemsValuesLoaded = false;
1785
1828
  if (Array.isArray(items)) {
1786
1829
  this._createItems(items);
1787
- this.updateVisibleItems();
1788
- this._setKeywordItem();
1789
1830
  }
1790
1831
  };
1791
1832
  FsFilterItemsStore.prototype.filtersClear = function () {
@@ -1824,6 +1865,25 @@
1824
1865
  .filter(function (item) { return item.hasPendingValues; })
1825
1866
  .forEach(function (item) { return item.loadAsyncValues(); });
1826
1867
  };
1868
+ FsFilterItemsStore.prototype.loadAsyncDefaults = function () {
1869
+ var _this = this;
1870
+ var pendingItems = this.items
1871
+ .filter(function (item) {
1872
+ return item.defaultValueFn
1873
+ && (item.persistedValue === null || item.persistedValue === undefined);
1874
+ });
1875
+ if (pendingItems.length > 0) {
1876
+ rxjs.forkJoin(pendingItems
1877
+ .map(function (item) { return item.loadDefaultValue(); }))
1878
+ .pipe(operators.finalize(function () {
1879
+ _this._ready$.next(true);
1880
+ }), operators.takeUntil(this._destroy$))
1881
+ .subscribe();
1882
+ }
1883
+ else {
1884
+ this._ready$.next(true);
1885
+ }
1886
+ };
1827
1887
  FsFilterItemsStore.prototype.getSort = function () {
1828
1888
  var sortBy = this.getSortByValue();
1829
1889
  sortBy = sortBy === '__all' ? null : sortBy;
@@ -1880,6 +1940,7 @@
1880
1940
  item.initValues(p[item.name]);
1881
1941
  });
1882
1942
  this._createSortingItems(p);
1943
+ this.loadAsyncDefaults();
1883
1944
  this._subscribeToItemsChanges();
1884
1945
  };
1885
1946
  FsFilterItemsStore.prototype.updateItemsWithValues = function (values) {
@@ -1968,6 +2029,15 @@
1968
2029
  });
1969
2030
  }
1970
2031
  };
2032
+ FsFilterItemsStore.prototype._lazyInit = function () {
2033
+ var _this = this;
2034
+ this.ready$
2035
+ .pipe(operators.filter(function (state) { return state; }), operators.takeUntil(this._destroy$))
2036
+ .subscribe(function () {
2037
+ _this.updateVisibleItems();
2038
+ _this._setKeywordItem();
2039
+ });
2040
+ };
1971
2041
  FsFilterItemsStore.prototype._createSortingItems = function (p) {
1972
2042
  var _a;
1973
2043
  if (((_a = this._config.sortValues) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -2622,6 +2692,12 @@
2622
2692
  };
2623
2693
  ExternalParamsController.prototype._listenItemsChange = function () {
2624
2694
  var _this = this;
2695
+ this._itemsStore.ready$
2696
+ .pipe(operators.filter(function (v) { return v; }), operators.take(1), operators.takeUntil(this._destroy$))
2697
+ .subscribe(function () {
2698
+ _this._saveQueryParams();
2699
+ _this._savePersistedParams();
2700
+ });
2625
2701
  this._itemsStore
2626
2702
  .itemsChange$
2627
2703
  .pipe(operators.takeUntil(this._destroy$))
@@ -3425,6 +3501,13 @@
3425
3501
  enumerable: true,
3426
3502
  configurable: true
3427
3503
  });
3504
+ Object.defineProperty(FilterComponent.prototype, "itemsReady$", {
3505
+ get: function () {
3506
+ return this._filterItems.ready$;
3507
+ },
3508
+ enumerable: true,
3509
+ configurable: true
3510
+ });
3428
3511
  Object.defineProperty(FilterComponent.prototype, "hasFilterChips$", {
3429
3512
  get: function () {
3430
3513
  return this._hasFilterChips$.asObservable();
@@ -3489,21 +3572,6 @@
3489
3572
  _this.focus();
3490
3573
  }
3491
3574
  });
3492
- if (this.config.init) {
3493
- if (this._externalParams.pending) {
3494
- this._externalParams
3495
- .pending$
3496
- .pipe(operators.filter(function (pending) {
3497
- return !pending;
3498
- }), operators.takeUntil(this._destroy$))
3499
- .subscribe(function () {
3500
- _this.init();
3501
- });
3502
- }
3503
- else {
3504
- this.init();
3505
- }
3506
- }
3507
3575
  this._listenInternalItemsChange();
3508
3576
  this._initOverlay();
3509
3577
  };
@@ -3904,10 +3972,18 @@
3904
3972
  // We may need some time to recieve external params and after that ready can be emitted
3905
3973
  FilterComponent.prototype._listenWhenFilterReady = function () {
3906
3974
  var _this = this;
3907
- this._externalParams
3908
- .pending$
3909
- .pipe(operators.filter(function (value) { return !value; }), operators.takeUntil(this._destroy$))
3975
+ rxjs.combineLatest([
3976
+ this._externalParams.pending$,
3977
+ this.itemsReady$,
3978
+ ])
3979
+ .pipe(operators.filter(function (_a) {
3980
+ var _b = __read(_a, 2), pendingParams = _b[0], itemsReady = _b[1];
3981
+ return !pendingParams && itemsReady;
3982
+ }), operators.takeUntil(this._destroy$))
3910
3983
  .subscribe(function () {
3984
+ if (_this.config.init) {
3985
+ _this.init();
3986
+ }
3911
3987
  _this.ready.emit();
3912
3988
  });
3913
3989
  };
@@ -3983,7 +4059,7 @@
3983
4059
  FilterComponent = __decorate([
3984
4060
  core.Component({
3985
4061
  selector: 'fs-filter',
3986
- template: "<ng-container *ngIf=\"hasKeyword; else noKeywordFilter\">\n <div class=\"filter-search-container\">\n <div class=\"filter-input-field\">\n <form autocomplete=\"off\" role=\"presentation\" *ngIf=\"keywordVisible$ | async\">\n <mat-form-field floatLabel=\"never\">\n <span matPrefix>\n <mat-icon matPrefix>search</mat-icon>\n </span>\n\n <input\n #searchTextInput\n matInput\n [formControl]=\"searchText\"\n [placeholder]=\"searchPlaceholder\"\n name=\"filter-input\"\n (click)=\"filterInputEvent($event)\"\n class=\"filter-input\">\n\n <a matSuffix\n *ngIf=\"searchText.value && showFilterInput && config.clear\"\n (click)=\"clearSearchText($event)\"\n href=\"javascript:void(0)\"\n class=\"clear\">\n <mat-icon>clear</mat-icon>\n </a>\n\n <a matSuffix\n (click)=\"reload($event)\"\n class=\"reload\"\n *ngIf=\"config.reload\">\n <mat-icon>refresh</mat-icon>\n </a>\n </mat-form-field>\n </form>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n <div class=\"status-actions\" *ngIf=\"keywordVisible$ | async\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n</ng-container>\n\n<ng-template #noKeywordFilter>\n <div class=\"filter-searchless-container\">\n <div class=\"status-actions\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n</ng-template>\n\n\n<ng-template #filterActions>\n <div class=\"filter-actions\">\n <ng-container *ngIf=\"hasVisibleItemOrSorting && filtersBtnVisible$ | async \">\n <button\n mat-button\n class=\"filters-button\"\n [ngClass]=\"{\n 'mat-raised-button': config.button.style == 'raised',\n 'mat-button': config.button.style == 'basic',\n 'mat-icon-button': config.button.style == 'icon'\n }\"\n (click)=\"changeVisibilityClick(!showFilterMenu, $event)\"\n type=\"button\"\n [color]=\"config.button.color\">\n <mat-icon *ngIf=\"config.button.icon\">{{config.button.icon}}</mat-icon>\n {{ config.button.label }}\n </button>\n </ng-container>\n\n <fs-filter-actions\n *ngIf=\"actionsVisible$ | async\"\n [actions]=\"actions$ | async\"\n [kebabActions]=\"menuActions$ | async\">\n </fs-filter-actions>\n </div>\n</ng-template>\n\n<ng-template #filterChips>\n <fs-filter-chips\n *ngIf=\"config.chips && hasFilterChips$ | async\"\n class=\"filter-chips\"\n [filters]=\"items\">\n </fs-filter-chips>\n</ng-template>\n\n<ng-template #statusBarContainer>\n <div class=\"status-bar\" *ngIf=\"statusBar\">\n <small><ng-container *ngTemplateOutlet=\"statusBar\"></ng-container></small>\n </div>\n</ng-template>\n",
4062
+ template: "<ng-container *ngIf=\"hasKeyword; else noKeywordFilter\">\n <div class=\"filter-search-container\">\n <div class=\"filter-input-field\">\n <form autocomplete=\"off\" role=\"presentation\" *ngIf=\"keywordVisible$ | async\">\n <mat-form-field floatLabel=\"never\">\n <span matPrefix>\n <mat-icon matPrefix>search</mat-icon>\n </span>\n\n <input\n #searchTextInput\n matInput\n [formControl]=\"searchText\"\n [placeholder]=\"searchPlaceholder\"\n name=\"filter-input\"\n (click)=\"filterInputEvent($event)\"\n class=\"filter-input\">\n\n <a matSuffix\n *ngIf=\"searchText.value && showFilterInput && config.clear\"\n (click)=\"clearSearchText($event)\"\n href=\"javascript:void(0)\"\n class=\"clear\">\n <mat-icon>clear</mat-icon>\n </a>\n\n <a matSuffix\n (click)=\"reload($event)\"\n class=\"reload\"\n *ngIf=\"config.reload\">\n <mat-icon>refresh</mat-icon>\n </a>\n </mat-form-field>\n </form>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n <div class=\"status-actions\" *ngIf=\"keywordVisible$ | async\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n</ng-container>\n\n<ng-template #noKeywordFilter>\n <div class=\"filter-searchless-container\">\n <div class=\"status-actions\">\n <ng-container *ngTemplateOutlet=\"statusBarContainer\"></ng-container>\n <ng-container *ngTemplateOutlet=\"filterChips\"></ng-container>\n </div>\n <ng-container *ngTemplateOutlet=\"filterActions\"></ng-container>\n </div>\n</ng-template>\n\n\n<ng-template #filterActions>\n <div class=\"filter-actions\">\n <ng-container *ngIf=\"hasVisibleItemOrSorting && filtersBtnVisible$ | async\">\n <button\n mat-button\n class=\"filters-button\"\n [ngClass]=\"{\n 'mat-raised-button': config.button.style == 'raised',\n 'mat-button': config.button.style == 'basic',\n 'mat-icon-button': config.button.style == 'icon'\n }\"\n (click)=\"changeVisibilityClick(!showFilterMenu, $event)\"\n type=\"button\"\n [color]=\"config.button.color\">\n <mat-icon *ngIf=\"config.button.icon\">{{config.button.icon}}</mat-icon>\n {{ config.button.label }}\n </button>\n </ng-container>\n\n <fs-filter-actions\n *ngIf=\"actionsVisible$ | async\"\n [actions]=\"actions$ | async\"\n [kebabActions]=\"menuActions$ | async\">\n </fs-filter-actions>\n </div>\n</ng-template>\n\n<ng-template #filterChips>\n <fs-filter-chips\n *ngIf=\"config.chips && hasFilterChips$ | async\"\n class=\"filter-chips\"\n [filters]=\"items\">\n </fs-filter-chips>\n</ng-template>\n\n<ng-template #statusBarContainer>\n <div class=\"status-bar\" *ngIf=\"statusBar\">\n <small><ng-container *ngTemplateOutlet=\"statusBar\"></ng-container></small>\n </div>\n</ng-template>\n",
3987
4063
  encapsulation: core.ViewEncapsulation.None,
3988
4064
  providers: [
3989
4065
  FsFilterOverlayService,