@cauca-911/datagrid 21.3.0 → 21.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cauca-911/datagrid",
3
- "version": "21.3.0",
3
+ "version": "21.3.2",
4
4
  "peerDependencies": {
5
5
  "@angular/common": ">=21.2.0",
6
6
  "@angular/core": ">=21.2.0",
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { OnDestroy, OnInit, EventEmitter, AfterContentInit, OnChanges, QueryList, SimpleChanges, AfterViewInit, TemplateRef, ModelSignal, InputSignal, Type, InjectionToken, Provider, EnvironmentProviders } from '@angular/core';
2
+ import { OnDestroy, OnInit, EventEmitter, AfterContentInit, OnChanges, QueryList, SimpleChanges, AfterViewInit, TemplateRef, EnvironmentProviders, ModelSignal, InputSignal, Type, InjectionToken, Provider } from '@angular/core';
3
3
  import { MatTable, MatColumnDef, MatCellDef, MatHeaderCellDef, MatFooterCellDef, MatHeaderRowDef, MatFooterRowDef, MatRowDef, MatNoDataRow, MatTableDataSource } from '@angular/material/table';
4
4
  import { CdkDragDrop } from '@angular/cdk/drag-drop';
5
5
  import { MatPaginator } from '@angular/material/paginator';
@@ -9,6 +9,7 @@ import { MatSort } from '@angular/material/sort';
9
9
  import { TranslateService } from '@ngx-translate/core';
10
10
  import { ODataDataSource, ODataFilter } from 'odata-data-source';
11
11
  import { HttpClient } from '@angular/common/http';
12
+ import { Params, ParamMap } from '@angular/router';
12
13
 
13
14
  declare class DataGridRowDropEvent {
14
15
  item: unknown;
@@ -226,9 +227,13 @@ declare class OdataListingService<T = any> {
226
227
  static ɵprov: i0.ɵɵInjectableDeclaration<OdataListingService<any>>;
227
228
  }
228
229
 
229
- declare class OdataGridComponent extends BaseDataGridComponent implements OnChanges, OnDestroy {
230
+ declare class OdataGridComponent extends BaseDataGridComponent implements OnChanges, OnDestroy, AfterViewInit {
230
231
  readonly listing: OdataListingService;
231
232
  showTableHeader: i0.InputSignal<boolean>;
233
+ /** Master switch: when true, the grid's filter/sort/page are synced with the URL query params and restored when returning from a detail page. Off by default. */
234
+ persistState: i0.InputSignal<boolean>;
235
+ /** Optional prefix for the persisted query params, so two independent grids on the same route don't collide (e.g. "alerts" -> "alertsFilter"). */
236
+ stateKey: i0.InputSignal<string>;
232
237
  baseSort?: string[];
233
238
  filterPredicate?: (filter: string) => ODataFilter[];
234
239
  showHeader: boolean;
@@ -240,8 +245,16 @@ declare class OdataGridComponent extends BaseDataGridComponent implements OnChan
240
245
  rowDetailTemplate: TemplateRef<any>;
241
246
  paginator: MatPaginator;
242
247
  private readonly baseUrl;
248
+ private readonly router;
249
+ private readonly route;
250
+ private readonly destroyRef;
251
+ private defaultPageSize?;
252
+ private pendingRestoredFilter?;
253
+ private lastWrittenParams;
254
+ private restoredState?;
243
255
  constructor(translateService: TranslateService, listing: OdataListingService);
244
256
  ngOnDestroy(): void;
257
+ ngAfterViewInit(): void;
245
258
  refreshData(): void;
246
259
  ngOnChanges(changes: SimpleChanges): void;
247
260
  getData(): unknown[];
@@ -254,9 +267,62 @@ declare class OdataGridComponent extends BaseDataGridComponent implements OnChan
254
267
  protected updateDataWhenNeeded(_changes: SimpleChanges): void;
255
268
  protected onColumnsChanged(columns: string[]): void;
256
269
  protected showColumnsWhenTableOptionsIsFalse(): void;
270
+ private canPersistState;
271
+ private restoreStateBeforeInitialLoad;
272
+ private setUpUrlStatePersistence;
273
+ private applySortAndPage;
274
+ private currentUrlState;
275
+ private writeCurrentUrlState;
276
+ private reactToExternalUrlStateChange;
277
+ private applyUrlStateToGrid;
278
+ private hasRestoredState;
257
279
  static ɵfac: i0.ɵɵFactoryDeclaration<OdataGridComponent, never>;
258
- static ɵcmp: i0.ɵɵComponentDeclaration<OdataGridComponent, "cauca-odata-grid", never, { "showTableHeader": { "alias": "showTableHeader"; "required": false; "isSignal": true; }; "baseSort": { "alias": "baseSort"; "required": false; }; "filterPredicate": { "alias": "filterPredicate"; "required": false; }; "showHeader": { "alias": "showHeader"; "required": false; }; "selectedRowId": { "alias": "selectedRowId"; "required": false; }; "idField": { "alias": "idField"; "required": false; }; "showRefreshButton": { "alias": "showRefreshButton"; "required": false; }; }, { "itemClick": "itemClick"; "refreshRequested": "refreshRequested"; }, ["rowDetailTemplate"], ["[filterRow]", "[customHeader]", "[customFilter]", "*"], true, never>;
280
+ static ɵcmp: i0.ɵɵComponentDeclaration<OdataGridComponent, "cauca-odata-grid", never, { "showTableHeader": { "alias": "showTableHeader"; "required": false; "isSignal": true; }; "persistState": { "alias": "persistState"; "required": false; "isSignal": true; }; "stateKey": { "alias": "stateKey"; "required": false; "isSignal": true; }; "baseSort": { "alias": "baseSort"; "required": false; }; "filterPredicate": { "alias": "filterPredicate"; "required": false; }; "showHeader": { "alias": "showHeader"; "required": false; }; "selectedRowId": { "alias": "selectedRowId"; "required": false; }; "idField": { "alias": "idField"; "required": false; }; "showRefreshButton": { "alias": "showRefreshButton"; "required": false; }; }, { "itemClick": "itemClick"; "refreshRequested": "refreshRequested"; }, ["rowDetailTemplate"], ["[filterRow]", "[customHeader]", "[customFilter]", "*"], true, never>;
281
+ }
282
+
283
+ interface GridUrlState {
284
+ filter?: string;
285
+ sort?: string;
286
+ direction?: 'asc' | 'desc' | '';
287
+ pageIndex?: number;
288
+ pageSize?: number;
259
289
  }
290
+ declare function toQueryParams(state: GridUrlState, key?: string): Params;
291
+ declare function fromQueryParams(map: ParamMap, key?: string): GridUrlState;
292
+ /**
293
+ * Returns a Params object with every grid-state param name mapped to `null` for the given key.
294
+ * Combined with `queryParamsHandling: 'merge'`, this lets the grid explicitly clear stale
295
+ * params (e.g. a previously-set filter) instead of leaving them stuck in the URL.
296
+ */
297
+ declare function emptyQueryParams(key?: string): Params;
298
+ declare function paramsEqual(a: Params, b: Params): boolean;
299
+
300
+ /**
301
+ * Re-injects a list page's remembered grid query params (filter/sort/page, written by
302
+ * `OdataGridComponent` when `persistState` is enabled) when the user navigates back to that
303
+ * list page from one of its own descendant (detail) routes. Any other way of reaching the
304
+ * list page (menu, bookmark, direct link, refresh) leaves it clean, because the previous URL
305
+ * won't be a descendant of the list path.
306
+ */
307
+ declare class GridStateRestorationService {
308
+ private readonly router;
309
+ private readonly rememberedParamsByPath;
310
+ private previousPath;
311
+ constructor();
312
+ private onNavigationEnd;
313
+ private restoreIfReturningFromDescendant;
314
+ private pathOnly;
315
+ private parseParams;
316
+ static ɵfac: i0.ɵɵFactoryDeclaration<GridStateRestorationService, never>;
317
+ static ɵprov: i0.ɵɵInjectableDeclaration<GridStateRestorationService>;
318
+ }
319
+
320
+ /**
321
+ * Activates the grid list-state restoration feature for the whole application. Add this once
322
+ * in the app's root providers; it has no effect on pages whose grids don't opt in via
323
+ * `[persistState]="true"`.
324
+ */
325
+ declare function provideGridStateRestoration(): EnvironmentProviders;
260
326
 
261
327
  declare class ColorDataGridColumnComponent extends BaseGridColumnComponent implements OnDestroy, OnInit {
262
328
  readonly odata: OdataGridComponent;
@@ -408,5 +474,5 @@ interface CaucaGridOptions {
408
474
  declare const PREFERENCE_SERVICE_TOKEN: InjectionToken<BasePreferenceService>;
409
475
  declare function provideCaucaGrid(options?: CaucaGridOptions): (Provider | EnvironmentProviders);
410
476
 
411
- export { BaseGridColumnComponent, ColorDataGridColumnComponent, DataGridCheckColumnComponent, DataGridColumnComponent, DataGridCommandIconColumnComponent, DataGridCommandsColumnComponent, DataGridComponent, DataGridHeaderComponent, DataGridIconColumnComponent, DataGridMenuColumnComponent, DataGridRowDropEvent, DateGridColumnComponent, Density, GridConfiguration, OdataGridComponent, OdataListingService, PREFERENCE_SERVICE_TOKEN, Preference, SortableDataGridCheckColumnComponent, SortableDataGridColumnComponent, TimeSpanDataGridColumnComponent, TranslationGridColumnComponent, provideCaucaGrid };
412
- export type { BasePreferenceService, CaucaGridOptions, Paginator, Sort };
477
+ export { BaseGridColumnComponent, ColorDataGridColumnComponent, DataGridCheckColumnComponent, DataGridColumnComponent, DataGridCommandIconColumnComponent, DataGridCommandsColumnComponent, DataGridComponent, DataGridHeaderComponent, DataGridIconColumnComponent, DataGridMenuColumnComponent, DataGridRowDropEvent, DateGridColumnComponent, Density, GridConfiguration, GridStateRestorationService, OdataGridComponent, OdataListingService, PREFERENCE_SERVICE_TOKEN, Preference, SortableDataGridCheckColumnComponent, SortableDataGridColumnComponent, TimeSpanDataGridColumnComponent, TranslationGridColumnComponent, emptyQueryParams, fromQueryParams, paramsEqual, provideCaucaGrid, provideGridStateRestoration, toQueryParams };
478
+ export type { BasePreferenceService, CaucaGridOptions, GridUrlState, Paginator, Sort };