@firestitch/filter 13.0.2 → 13.0.3

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.
@@ -59,16 +59,6 @@ import * as i1$6 from '@angular/cdk/overlay';
59
59
  import { OverlayConfig } from '@angular/cdk/overlay';
60
60
  import * as i1$7 from '@angular/cdk/layout';
61
61
 
62
- const QUERY_PARAM_DELIMITER = ':';
63
-
64
- function filterToQueryParam(value, name) {
65
- return `${encodeURIComponent(value)}${QUERY_PARAM_DELIMITER}${encodeURIComponent(name)}`;
66
- }
67
- function filterFromQueryParam(param) {
68
- const parts = param.split(QUERY_PARAM_DELIMITER);
69
- return [decodeURIComponent(parts[0]), decodeURIComponent(parts[1])];
70
- }
71
-
72
62
  function objectsAreEquals(obj1, obj2) {
73
63
  const oldKeys = Object.keys(obj1);
74
64
  const currKeys = Object.keys(obj2);
@@ -476,8 +466,19 @@ class MultipleSelectItem extends BaseSelectItem {
476
466
  }
477
467
  }
478
468
 
469
+ const QUERY_PARAM_DELIMITER = ':';
470
+
471
+ function filterToQueryParam(value, name) {
472
+ return `${encodeURIComponent(value)}${QUERY_PARAM_DELIMITER}${encodeURIComponent(name)}`;
473
+ }
474
+ function filterFromQueryParam(param) {
475
+ const parts = param.split(QUERY_PARAM_DELIMITER);
476
+ return [decodeURIComponent(parts[0]), decodeURIComponent(parts[1])];
477
+ }
478
+
479
479
  function buildQueryParams(flattenedParams, items) {
480
- items.forEach(filterItem => {
480
+ items
481
+ .forEach((filterItem) => {
481
482
  if (filterItem instanceof MultipleSelectItem && filterItem.isolate) {
482
483
  if (filterItem.multiple && filterItem.value) {
483
484
  const isolated = list(filterItem.values, 'value').sort();
@@ -1911,23 +1912,9 @@ class QueryParamsController {
1911
1912
  }
1912
1913
  }
1913
1914
  writeStateToQueryParams(params) {
1914
- if (!this._enabled) {
1915
- return;
1915
+ if (this._enabled) {
1916
+ this._replaceState(params);
1916
1917
  }
1917
- this._location.replaceState(this._router.createUrlTree([], {
1918
- relativeTo: this._route,
1919
- queryParams: params,
1920
- queryParamsHandling: 'merge',
1921
- preserveFragment: true,
1922
- }).toString());
1923
- // Trying replacing the URL without triggering an Angular navigation change
1924
- // // Update query
1925
- // this._router.navigate([], {
1926
- // replaceUrl: true,
1927
- // relativeTo: this._route,
1928
- // queryParams: params,
1929
- // queryParamsHandling: 'merge',
1930
- // }).then(() => {});
1931
1918
  }
1932
1919
  /**
1933
1920
  * Parse query and update filter values
@@ -1940,6 +1927,15 @@ class QueryParamsController {
1940
1927
  ].filter((item) => !!item);
1941
1928
  this._fetchedParams = restoreItems(this._route.snapshot.queryParams, items, this._paramsCase);
1942
1929
  }
1930
+ _replaceState(data) {
1931
+ const url = new URL(window.location.href);
1932
+ Object.keys(data)
1933
+ .filter((name) => data[name] !== undefined && data[name] !== null)
1934
+ .forEach((name) => {
1935
+ url.searchParams.set(name, data[name]);
1936
+ });
1937
+ history.replaceState({}, null, url.search);
1938
+ }
1943
1939
  }
1944
1940
  QueryParamsController.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: QueryParamsController, deps: [{ token: i1$1.Router }, { token: i1$1.ActivatedRoute }, { token: i3.Location }, { token: FsFilterItemsStore }], target: i0.ɵɵFactoryTarget.Injectable });
1945
1941
  QueryParamsController.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.4.0", ngImport: i0, type: QueryParamsController });