ag-grid-url-sync 0.5.0 → 0.5.1

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.
Files changed (58) hide show
  1. package/README.md +110 -55
  2. package/dist/core/ag-grid-url-sync.d.ts +10 -9
  3. package/dist/core/ag-grid-url-sync.js +23 -19
  4. package/dist/core/ag-grid-url-sync.js.map +1 -1
  5. package/dist/core/grid-integration.d.ts +27 -1
  6. package/dist/core/grid-integration.js +161 -129
  7. package/dist/core/grid-integration.js.map +1 -1
  8. package/dist/core/index.d.ts +2 -1
  9. package/dist/core/index.js +2 -1
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/core/individual-params.d.ts +12 -5
  12. package/dist/core/individual-params.js +38 -62
  13. package/dist/core/individual-params.js.map +1 -1
  14. package/dist/core/issue-columns.d.ts +2 -0
  15. package/dist/core/issue-columns.js +11 -0
  16. package/dist/core/issue-columns.js.map +1 -0
  17. package/dist/core/issues.d.ts +34 -0
  18. package/dist/core/issues.js +58 -0
  19. package/dist/core/issues.js.map +1 -0
  20. package/dist/core/operators.d.ts +189 -0
  21. package/dist/core/operators.js +60 -0
  22. package/dist/core/operators.js.map +1 -0
  23. package/dist/core/options.d.ts +21 -0
  24. package/dist/core/options.js +21 -0
  25. package/dist/core/options.js.map +1 -0
  26. package/dist/core/schemas.d.ts +51 -0
  27. package/dist/core/schemas.js +59 -0
  28. package/dist/core/schemas.js.map +1 -0
  29. package/dist/core/serialization/formats.d.ts +7 -7
  30. package/dist/core/serialization/formats.js +34 -28
  31. package/dist/core/serialization/formats.js.map +1 -1
  32. package/dist/core/serialization/grouped.d.ts +9 -12
  33. package/dist/core/serialization/grouped.js +24 -17
  34. package/dist/core/serialization/grouped.js.map +1 -1
  35. package/dist/core/to-error.d.ts +5 -0
  36. package/dist/core/to-error.js +4 -0
  37. package/dist/core/to-error.js.map +1 -0
  38. package/dist/core/types.d.ts +149 -43
  39. package/dist/core/types.js +35 -108
  40. package/dist/core/types.js.map +1 -1
  41. package/dist/core/url-generator.d.ts +4 -4
  42. package/dist/core/url-generator.js +9 -7
  43. package/dist/core/url-generator.js.map +1 -1
  44. package/dist/core/url-parser.d.ts +4 -4
  45. package/dist/core/url-parser.js +6 -4
  46. package/dist/core/url-parser.js.map +1 -1
  47. package/dist/core/validation.d.ts +21 -14
  48. package/dist/core/validation.js +58 -54
  49. package/dist/core/validation.js.map +1 -1
  50. package/dist/core/view-storage.js +21 -19
  51. package/dist/core/view-storage.js.map +1 -1
  52. package/dist/index.d.ts +2 -1
  53. package/dist/index.js +2 -1
  54. package/dist/index.js.map +1 -1
  55. package/dist/react/types.d.ts +31 -12
  56. package/dist/react/use-ag-grid-url-sync.js +148 -87
  57. package/dist/react/use-ag-grid-url-sync.js.map +1 -1
  58. package/package.json +22 -15
package/README.md CHANGED
@@ -195,16 +195,13 @@ import type {
195
195
 
196
196
  ```typescript
197
197
  import { parseUrlFilters } from 'ag-grid-url-sync/url-parser'
198
- import { DEFAULT_CONFIG } from 'ag-grid-url-sync/validation'
199
- import type { FilterState, ParseConfig } from 'ag-grid-url-sync/types'
198
+ import type { FilterState } from 'ag-grid-url-sync/types'
200
199
 
201
200
  function getFiltersFromUrl(url: string): FilterState {
202
- const config: ParseConfig = {
203
- ...DEFAULT_CONFIG, // gridApi is not needed for parsing
201
+ // Options that you leave out get their defaults. No grid is needed.
202
+ return parseUrlFilters(url, {
204
203
  onParseError: error => console.error('Parse error:', error)
205
- }
206
-
207
- return parseUrlFilters(url, config)
204
+ })
208
205
  }
209
206
  ```
210
207
 
@@ -227,19 +224,27 @@ function getFiltersFromUrl(url: string): FilterState {
227
224
 
228
225
  ```typescript
229
226
  import { generateUrl } from 'ag-grid-url-sync/url-generator'
230
- import { DEFAULT_CONFIG } from 'ag-grid-url-sync/validation'
231
- import type { FilterState, ParseConfig } from 'ag-grid-url-sync/types'
227
+ import type { FilterState } from 'ag-grid-url-sync/types'
232
228
 
233
229
  function createShareableUrl(filters: FilterState, baseUrl: string): string {
234
- const config: ParseConfig = {
235
- ...DEFAULT_CONFIG, // gridApi is not needed for generation
236
- maxValueLength: 500
237
- }
238
-
239
- return generateUrl(baseUrl, filters, config)
230
+ return generateUrl(baseUrl, filters, { maxValueLength: 500 })
240
231
  }
241
232
  ```
242
233
 
234
+ #### Example: Read and Write the Grid Filters
235
+
236
+ ```typescript
237
+ import {
238
+ getFilterModel,
239
+ applyFilterModel
240
+ } from 'ag-grid-url-sync/grid-integration'
241
+
242
+ const filters = getFilterModel(gridApi, { onParseError: console.warn })
243
+ applyFilterModel(filters, otherGridApi)
244
+ ```
245
+
246
+ The config form (`getFilterModel({ ...DEFAULT_CONFIG, gridApi })`) still works, but it is deprecated.
247
+
243
248
  **💡 Pro Tip**: Use granular imports in libraries and applications where bundle size matters. All existing import patterns remain fully supported for backward compatibility.
244
249
 
245
250
  ### Basic Example
@@ -435,38 +440,80 @@ import {
435
440
 
436
441
  ---
437
442
 
438
- ### Error Handling for Grouped Serialization
443
+ ### Error Handling
444
+
445
+ The library never writes to the console. Each problem goes to one callback, and each error that the library makes has a `code` that you can switch on:
446
+
447
+ | Code | Meaning | Callback |
448
+ | ------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
449
+ | `INVALID_PARAM` | A param name that is not valid, or an unknown operation | `onParseError` |
450
+ | `INVALID_NUMBER` | A value that is not a number, or that would be rounded | `onParseError` |
451
+ | `INVALID_DATE` | A date that does not exist, or a date range in the wrong order | `onParseError` |
452
+ | `VALUE_TOO_LONG` | A text value over `maxValueLength` | `onParseError` |
453
+ | `INVALID_GROUPED` | A grouped value that does not decode (bad JSON or base64) | `onParseError` |
454
+ | `TYPE_MISMATCH` | A number or date filter on a column of another type | `onParseError` |
455
+ | `INVALID_URL` | A URL that the parser cannot read | Thrown by `parseUrlFilters` and `applyFromUrl`. The React hook catches it and sends it to `onParseError` |
456
+ | `GRID_ERROR` | The AG Grid API threw | `onParseError` in the core, `onError` in the React hook |
457
+ | `NOT_READY` | A hook operation called before the grid is ready | `onError` (React) |
458
+ | `VIEW_NOT_FOUND`, `VIEW_NAME_REQUIRED` | A saved view operation that cannot run | `onError` (React) |
459
+ | `STORAGE_UNAVAILABLE`, `STORAGE_FULL`, `STORAGE_WRITE_FAILED` | Browser storage for saved views failed | `onError` (React) |
460
+
461
+ The codes in the first seven rows are data issues: a filter that is dropped or is not valid. The library skips that filter and keeps the others. When the library knows the column, it is in `error.column`. `onParseError` is typed with `Error`, so check `instanceof URLSyncError` before you read `code` or `column`.
439
462
 
440
- You can provide a custom error handler to gracefully handle malformed grouped parameters or serialization errors. In grouped mode, `onParseError` receives an `InvalidSerializationError` for invalid formats:
463
+ Every error is a `URLSyncError`. The classes from earlier versions (`InvalidFilterError`, `InvalidDateError`, `InvalidURLError`, `InvalidSerializationError`) are subclasses of it, so an `instanceof` check still works.
441
464
 
442
465
  ```typescript
443
- import { InvalidSerializationError } from 'ag-grid-url-sync/types'
466
+ import { createUrlSync, URLSyncError } from 'ag-grid-url-sync'
444
467
 
445
468
  const urlSync = createUrlSync(gridApi, {
446
- serialization: 'grouped',
447
- format: 'json',
448
469
  onParseError: error => {
449
- if (error instanceof InvalidSerializationError) {
450
- // Handle grouped serialization error
451
- alert('Invalid filter data in URL!')
452
- } else {
453
- // Handle other errors
454
- console.error(error)
470
+ if (error instanceof URLSyncError && error.code === 'VALUE_TOO_LONG') {
471
+ showToast(`The link leaves out the filter on ${error.column}`)
455
472
  }
456
473
  }
457
474
  })
458
475
  ```
459
476
 
477
+ In grouped mode, an error that comes from the grouped URL value is an `InvalidSerializationError`, and the original error is in `error.cause`. When the original error is an issue with one filter (for example a value over `maxValueLength`), the wrapper has the same `code` and `column`. So a check on `error.code` works the same in both modes. `INVALID_GROUPED` means that the grouped value itself does not decode.
478
+
460
479
  In every grouped format (`querystring`, `json`, `base64`), a text value over `maxValueLength` (default 200) is dropped and reported through `onParseError`, both when the URL is generated and when it is parsed.
461
480
 
462
- In grouped mode, an error that comes from the grouped URL value is an `InvalidSerializationError`. This includes an error for one bad parameter inside a grouped querystring value, such as a value over `maxValueLength`. The original error is in `error.cause`. In individual mode, the same failure arrives as the original error, with no wrapper. To handle a specific error in both modes, check the error and its cause:
481
+ #### Dropped Filters in the Result
482
+
483
+ A caller does not need a callback to see dropped filters. `getUrlState()` and the apply methods return the issues of each call. They are the same objects that `onParseError` gets.
463
484
 
464
485
  ```typescript
465
- import { InvalidFilterError } from 'ag-grid-url-sync/types'
486
+ const { url, hasFilters, issues } = urlSync.getUrlState()
487
+
488
+ if (issues.length > 0) {
489
+ // The link leaves out these filters, so the recipient sees other rows
490
+ showToast(`The link leaves out ${issues.length} filter(s)`)
491
+ }
492
+
493
+ const { issues: urlIssues } = urlSync.applyFromUrl()
494
+ ```
495
+
496
+ In React, the hook returns `issues`: the issues of the latest URL apply (`applyUrlFilters`, `applyFilters`, auto-apply), followed by the issues of the latest URL write. The apply issues stay until the next apply, `clearFilters` or `loadView`. Operation failures (`onError`) are not in the list:
497
+
498
+ ```tsx
499
+ const { shareUrl, issues } = useAGGridUrlSync(gridApi)
466
500
 
467
- const isFilterError = (error: Error) =>
468
- error instanceof InvalidFilterError ||
469
- error.cause instanceof InvalidFilterError
501
+ return issues.length > 0 ? (
502
+ <Warning>The link leaves out a filter</Warning>
503
+ ) : null
504
+ ```
505
+
506
+ #### `throwOnError`
507
+
508
+ Like TanStack Query, the library can throw an issue instead of reporting it. Set `throwOnError: true` to throw every issue, or give a function that picks issues. In the core, a thrown issue does not go to `onParseError`, and the first one stops the call. In React, the hook keeps reporting each issue to `onParseError` one time, and then throws the picked issue during render, so an error boundary catches it. The default is `false`.
509
+
510
+ The library does not change the address bar. Before an error boundary resets, remove the bad param from the URL (or the filter from the grid), or the same issue is thrown again.
511
+
512
+ ```tsx
513
+ useAGGridUrlSync(gridApi, {
514
+ // Throw only when a link would leave out a filter
515
+ throwOnError: issue => issue.code === 'VALUE_TOO_LONG'
516
+ })
470
517
  ```
471
518
 
472
519
  ### Exports
@@ -587,6 +634,7 @@ const {
587
634
  isReady,
588
635
  currentUrl,
589
636
  hasFilters,
637
+ issues,
590
638
  parseUrlFilters,
591
639
  applyFilters,
592
640
  getFiltersAsFormat,
@@ -602,11 +650,12 @@ interface UseAGGridUrlSyncOptions {
602
650
  paramPrefix?: string // Default: 'f_'
603
651
  maxValueLength?: number // Default: 200
604
652
  onParseError?: (error: Error) => void
653
+ throwOnError?: boolean | ((issue: URLSyncError) => boolean) // Default: false
605
654
 
606
655
  // React-specific options
607
656
  autoApplyOnMount?: boolean // Default: false
608
657
  enabledWhenReady?: boolean // Default: true
609
- onError?: (error: Error, context: string) => void // Advanced error handling
658
+ onError?: (error: Error, context: string) => void // Operation failures (see Error Handling)
610
659
 
611
660
  // Saved views: setting a key enables the feature and namespaces its storage
612
661
  storageKey?: string // Default: undefined (saved views disabled)
@@ -615,19 +664,20 @@ interface UseAGGridUrlSyncOptions {
615
664
 
616
665
  #### Hook Return Values
617
666
 
618
- | Property | Type | Description |
619
- | -------------------- | -------------------------------- | ----------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- |
620
- | `shareUrl` | `(baseUrl?: string) => string` | Generate shareable URL with current filters |
621
- | `getQueryParams` | `() => string` | Get filter state as query parameters |
622
- | `applyUrlFilters` | `(url?: string) => void` | Apply filters from URL to grid |
623
- | `clearFilters` | `() => void` | Clear all text filters |
624
- | `isReady` | `boolean` | Whether grid API is available and hook is ready |
625
- | `currentUrl` | `string` | Current URL with filters applied |
626
- | `hasFilters` | `boolean` | Whether the grid has supported filters |
627
- | `parseUrlFilters` | `(url: string) => FilterState` | Parse filters from URL without applying |
628
- | `applyFilters` | `(filters: FilterState) => void` | Apply filter state object to grid |
629
- | `getFiltersAsFormat` | `(format: 'querystring' | 'json' | 'base64') => string` | Serialize filters to any supported format (for sharing/export) |
630
- | `getCurrentFormat` | `() => 'individual' | 'grouped'` | Get the current serialization mode (individual or grouped) |
667
+ | Property | Type | Description |
668
+ | -------------------- | --------------------------------------------------------- | --------------------------------------------------------------------------- |
669
+ | `shareUrl` | `(baseUrl?: string) => string` | Generate shareable URL with current filters |
670
+ | `getQueryParams` | `() => string` | Get filter state as query parameters |
671
+ | `applyUrlFilters` | `(url?: string) => void` | Apply filters from URL to grid |
672
+ | `clearFilters` | `() => void` | Clear all text filters |
673
+ | `isReady` | `boolean` | Whether grid API is available and hook is ready |
674
+ | `currentUrl` | `string` | Current URL with filters applied |
675
+ | `hasFilters` | `boolean` | Whether the grid has supported filters |
676
+ | `issues` | `readonly URLSyncError[]` | Filters that the latest URL apply or URL write dropped (see Error Handling) |
677
+ | `parseUrlFilters` | `(url: string) => FilterState` | Parse filters from URL without applying |
678
+ | `applyFilters` | `(filters: FilterState) => void` | Apply filter state object to grid |
679
+ | `getFiltersAsFormat` | `(format: 'querystring' \| 'json' \| 'base64') => string` | Serialize filters to any supported format (for sharing/export) |
680
+ | `getCurrentFormat` | `() => 'individual' \| 'grouped'` | Get the current serialization mode (individual or grouped) |
631
681
 
632
682
  Saved views (inert unless `storageKey` is set):
633
683
 
@@ -721,8 +771,9 @@ store.saveView('Engineering', gridApi.getFilterModel())
721
771
  - **🔄 Automatic State Management**: Tracks grid state and filter changes automatically
722
772
  - **⚡ Ready State**: `isReady` indicates when the grid API is available
723
773
  - **🎯 Auto-Apply**: `autoApplyOnMount` applies URL filters when component mounts.
724
- It is attempted once per grid: a failure is reported through `onError` and
725
- `onParseError` and is not retried on later renders
774
+ It is attempted once per grid: a failure is reported one time (a bad filter
775
+ through `onParseError`, any other failure through `onError`) and is not
776
+ retried on later renders
726
777
  - **🧹 Cleanup**: Automatically cleans up resources when component unmounts
727
778
  - **🛡️ Error Boundaries**: Graceful error handling with configurable callbacks
728
779
  - **📊 Filter Status**: `hasFilters` tracks whether any filters are active
@@ -918,7 +969,7 @@ const url = urlSync.generateUrl('https://app.com/page')
918
969
  // https://app.com/page?f_name_contains=john
919
970
  ```
920
971
 
921
- ##### `getUrlState(baseUrl?: string): { url: string; hasFilters: boolean }`
972
+ ##### `getUrlState(baseUrl?: string): { url: string; hasFilters: boolean; issues: readonly URLSyncError[] }`
922
973
 
923
974
  Generates the same URL as `generateUrl`, and tells if the grid has filters that the library supports. It reads the grid one time for both values. `hasFilters` comes from the filter state, not from the URL, because the URL also keeps the page's own params.
924
975
 
@@ -927,6 +978,8 @@ const { url, hasFilters } = urlSync.getUrlState('https://app.com/page?tab=1')
927
978
  // url: https://app.com/page?tab=1 (no filters), hasFilters: false
928
979
  ```
929
980
 
981
+ `issues` holds the filters that this call dropped, for example a text value over `maxValueLength`.
982
+
930
983
  ##### `getQueryParams(): string`
931
984
 
932
985
  Gets the current filter state as URL query parameters.
@@ -936,17 +989,17 @@ const params = urlSync.getQueryParams()
936
989
  // ?f_name_contains=john
937
990
  ```
938
991
 
939
- ##### `applyFromUrl(url?: string): void`
992
+ ##### `applyFromUrl(url?: string): { issues: readonly URLSyncError[] }`
940
993
 
941
- Applies filters from a URL to the grid.
994
+ Applies filters from a URL to the grid, and returns the filters in the URL that were dropped.
942
995
 
943
996
  ```typescript
944
997
  urlSync.applyFromUrl('https://app.com/page?f_name_contains=john')
945
998
  ```
946
999
 
947
- ##### `applyFilters(filterState: FilterState): void`
1000
+ ##### `applyFilters(filterState: FilterState): { issues: readonly URLSyncError[] }`
948
1001
 
949
- Applies a filter state object to the grid.
1002
+ Applies a filter state object to the grid, and returns the filters that were dropped (for example a number filter on a text column).
950
1003
 
951
1004
  ```typescript
952
1005
  urlSync.applyFilters({
@@ -958,7 +1011,7 @@ urlSync.applyFilters({
958
1011
  })
959
1012
  ```
960
1013
 
961
- ##### `clearFilters(): void`
1014
+ ##### `clearFilters(): { issues: readonly URLSyncError[] }`
962
1015
 
963
1016
  Clears all text filters from the grid.
964
1017
 
@@ -992,8 +1045,10 @@ interface AGGridUrlSyncConfig {
992
1045
  // Parameter name for grouped mode (default: 'grid_filters')
993
1046
  groupedParam?: string
994
1047
 
995
- // Prefix for URL parameters (default: 'f_')
996
- // In grouped mode, this affects individual parameter names within the group
1048
+ // Prefix for URL parameters in individual mode (default: 'f_')
1049
+ // A prefix without a trailing '_' gets one ('filter' -> 'filter_name_contains').
1050
+ // An empty prefix means the default. Grouped mode always uses 'f_' inside the
1051
+ // grouped value, so grouped URLs do not change with this option.
997
1052
  paramPrefix?: string
998
1053
 
999
1054
  // Maximum length for filter values (default: 200)
@@ -1,10 +1,11 @@
1
1
  import type { GridApi } from 'ag-grid-community';
2
- import type { AGGridUrlSyncConfig, FilterState, SerializationFormat, SerializationMode } from './types.js';
2
+ import type { AGGridUrlSyncConfig, FilterState, ApplyResult, SerializationFormat, SerializationMode, UrlState } from './types.js';
3
3
  /**
4
4
  * AGGridUrlSync class for synchronizing AG Grid text filters with URL parameters
5
5
  */
6
6
  export declare class AGGridUrlSync {
7
- private config;
7
+ private readonly gridApi;
8
+ private readonly options;
8
9
  /**
9
10
  * Creates a new instance of AGGridUrlSync
10
11
  * @param gridApi - AG Grid API instance
@@ -26,10 +27,7 @@ export declare class AGGridUrlSync {
26
27
  * also keeps the page's own params (#215).
27
28
  * @param baseUrl - Optional base URL (defaults to current URL)
28
29
  */
29
- getUrlState(baseUrl?: string): {
30
- url: string;
31
- hasFilters: boolean;
32
- };
30
+ getUrlState(baseUrl?: string): UrlState;
33
31
  /**
34
32
  * Gets the current filter state as URL query parameters
35
33
  * @returns Query parameter string
@@ -38,17 +36,20 @@ export declare class AGGridUrlSync {
38
36
  /**
39
37
  * Applies filters from a URL to the grid
40
38
  * @param url - Optional URL to parse (defaults to current URL)
39
+ * @returns The issues of this call: filters in the URL that were dropped
41
40
  */
42
- applyFromUrl(url?: string): void;
41
+ applyFromUrl(url?: string): ApplyResult;
43
42
  /**
44
43
  * Applies a filter state object to the grid
45
44
  * @param filterState - Filter state to apply
45
+ * @returns The issues of this call: filters that were dropped
46
46
  */
47
- applyFilters(filterState: FilterState): void;
47
+ applyFilters(filterState: FilterState): ApplyResult;
48
48
  /**
49
49
  * Clears all text filters from the grid
50
+ * @returns The issues of this call
50
51
  */
51
- clearFilters(): void;
52
+ clearFilters(): ApplyResult;
52
53
  /**
53
54
  * Cleans up any resources or event listeners
54
55
  */
@@ -1,27 +1,27 @@
1
- import { DEFAULT_CONFIG } from './validation.js';
1
+ import { resolveOptions } from './options.js';
2
+ import { collectIssues } from './issues.js';
2
3
  import { parseUrlFilters } from './url-parser.js';
3
4
  import { generateUrl } from './url-generator.js';
4
5
  import { getFilterModel, applyFilterModel } from './grid-integration.js';
5
6
  import { serializeGrouped } from './serialization/grouped.js';
6
7
  export class AGGridUrlSync {
7
- config;
8
+ gridApi;
9
+ options;
8
10
  constructor(gridApi, config = {}) {
9
- const definedConfig = Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined));
10
- this.config = {
11
- gridApi,
12
- ...DEFAULT_CONFIG,
13
- ...definedConfig
14
- };
11
+ this.gridApi = gridApi;
12
+ this.options = resolveOptions(config);
15
13
  }
16
14
  generateUrl(baseUrl) {
17
15
  return this.getUrlState(baseUrl).url;
18
16
  }
19
17
  getUrlState(baseUrl) {
20
- const filterState = getFilterModel(this.config);
18
+ const { options, issues } = collectIssues(this.options);
19
+ const filterState = getFilterModel(this.gridApi, options);
21
20
  const url = baseUrl ?? window.location.href;
22
21
  return {
23
- url: generateUrl(url, filterState, this.config),
24
- hasFilters: Object.keys(filterState).length > 0
22
+ url: generateUrl(url, filterState, options),
23
+ hasFilters: Object.keys(filterState).length > 0,
24
+ issues
25
25
  };
26
26
  }
27
27
  getQueryParams() {
@@ -30,28 +30,32 @@ export class AGGridUrlSync {
30
30
  return urlObj.search;
31
31
  }
32
32
  applyFromUrl(url) {
33
+ const { options, issues } = collectIssues(this.options);
33
34
  const urlToParse = url ?? window.location.href;
34
- const filterState = parseUrlFilters(urlToParse, this.config);
35
- this.applyFilters(filterState);
35
+ const filterState = parseUrlFilters(urlToParse, options);
36
+ const applied = this.applyFilters(filterState);
37
+ return { issues: [...issues, ...(applied?.issues ?? [])] };
36
38
  }
37
39
  applyFilters(filterState) {
38
- applyFilterModel(filterState, this.config);
40
+ const { options, issues } = collectIssues(this.options);
41
+ applyFilterModel(filterState, this.gridApi, options);
42
+ return { issues };
39
43
  }
40
44
  clearFilters() {
41
- this.applyFilters({});
45
+ return this.applyFilters({});
42
46
  }
43
47
  destroy() {
44
48
  }
45
49
  getSerializationMode() {
46
- return this.config.serialization;
50
+ return this.options.serialization;
47
51
  }
48
52
  getCurrentFormat() {
49
- return this.config.format;
53
+ return this.options.format;
50
54
  }
51
55
  getFiltersAsFormat(format) {
52
- const filterState = getFilterModel(this.config);
56
+ const filterState = getFilterModel(this.gridApi, this.options);
53
57
  const tempConfig = {
54
- ...this.config,
58
+ ...this.options,
55
59
  format,
56
60
  serialization: 'grouped'
57
61
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ag-grid-url-sync.js","sourceRoot":"","sources":["../../src/core/ag-grid-url-sync.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAK7D,MAAM,OAAO,aAAa;IAChB,MAAM,CAAgB;IAO9B,YAAY,OAAgB,EAAE,MAAM,GAAwB,EAAE;QAI5D,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CACtC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAC3C,CAAA;QAExB,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO;YACP,GAAG,cAAc;YACjB,GAAG,aAAa;SACjB,CAAA;IACH,CAAC;IAOD,WAAW,CAA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AM,EAAE,CAAA;IACnB,CAAC;IAMD,YAAY;QACV,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAKD,OAAO;IAEP,CAAC;IAMD,oBAAoB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAA;IACnC,CAAC;IAMD,gBAAgB;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;IAC5B,CAAC;IAKD,kBAAkB,CAAC,MAA2B;QAC5C,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAG9D,MAAM,UAAU,GAAG;YACjB,GAAG,IAAI,CAAC,OAAO;YACf,MAAM;YACN,aAAa,EAAE,SAAkB;SAClC,CAAA;QAGD,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAExD,OAAO,MAAM,CAAC,KAAK,CAAA;IACrB,CAAC;CACF;AAQD,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,MAA4B;IAE5B,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAC3C,CAAC"}
@@ -1,14 +1,40 @@
1
- import type { FilterState, InternalConfig } from './types.js';
1
+ import type { AGGridUrlSyncConfig, FilterState, InternalConfig } from './types.js';
2
2
  import type { GridApi } from 'ag-grid-community';
3
3
  /**
4
4
  * Detects the expected filter type for a column based on AG Grid configuration
5
5
  */
6
6
  export declare function detectColumnFilterType(gridApi: GridApi, columnId: string): 'text' | 'number' | 'date';
7
+ /**
8
+ * Gets the current filter model from AG Grid as a filter state. Filter types
9
+ * that the library does not support are skipped, and a filter that is not
10
+ * valid is reported through `options.onParseError`.
11
+ *
12
+ * @param gridApi - AG Grid API instance
13
+ * @param options - Optional options. Only `onParseError` is read.
14
+ */
15
+ export declare function getFilterModel(gridApi: GridApi, options?: AGGridUrlSyncConfig): FilterState;
7
16
  /**
8
17
  * Gets the current filter model from AG Grid
18
+ *
19
+ * @deprecated Give the grid API as an argument:
20
+ * `getFilterModel(gridApi, options)`. This form will be removed in 0.6.0.
9
21
  */
10
22
  export declare function getFilterModel(config: InternalConfig): FilterState;
23
+ /**
24
+ * Applies a filter state to AG Grid. A filter whose type does not match the
25
+ * column is skipped with a warning. An error from the grid is reported
26
+ * through `options.onParseError`.
27
+ *
28
+ * @param filterState - Filter state to apply
29
+ * @param gridApi - AG Grid API instance
30
+ * @param options - Optional options. Only `onParseError` is read.
31
+ */
32
+ export declare function applyFilterModel(filterState: FilterState, gridApi: GridApi, options?: AGGridUrlSyncConfig): void;
11
33
  /**
12
34
  * Applies a filter state to AG Grid
35
+ *
36
+ * @deprecated Give the grid API as an argument:
37
+ * `applyFilterModel(filterState, gridApi, options)`. This form will be
38
+ * removed in 0.6.0.
13
39
  */
14
40
  export declare function applyFilterModel(filterState: FilterState, config: InternalConfig): void;