ag-grid-url-sync 0.5.0 → 0.5.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/README.md +339 -66
- package/dist/core/ag-grid-url-sync.d.ts +16 -9
- package/dist/core/ag-grid-url-sync.js +23 -19
- package/dist/core/ag-grid-url-sync.js.map +1 -1
- package/dist/core/codecs.d.ts +28 -0
- package/dist/core/codecs.js +39 -0
- package/dist/core/codecs.js.map +1 -0
- package/dist/core/data-issue-codes.d.ts +3 -0
- package/dist/core/data-issue-codes.js +10 -0
- package/dist/core/data-issue-codes.js.map +1 -0
- package/dist/core/grid-integration.d.ts +38 -2
- package/dist/core/grid-integration.js +169 -128
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/grid-url-sync.d.ts +62 -0
- package/dist/core/grid-url-sync.js +738 -0
- package/dist/core/grid-url-sync.js.map +1 -0
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/individual-params.d.ts +12 -5
- package/dist/core/individual-params.js +38 -62
- package/dist/core/individual-params.js.map +1 -1
- package/dist/core/issue-columns.d.ts +2 -0
- package/dist/core/issue-columns.js +11 -0
- package/dist/core/issue-columns.js.map +1 -0
- package/dist/core/issues.d.ts +34 -0
- package/dist/core/issues.js +51 -0
- package/dist/core/issues.js.map +1 -0
- package/dist/core/operators.d.ts +189 -0
- package/dist/core/operators.js +60 -0
- package/dist/core/operators.js.map +1 -0
- package/dist/core/options.d.ts +21 -0
- package/dist/core/options.js +21 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/own-write.d.ts +138 -0
- package/dist/core/own-write.js +133 -0
- package/dist/core/own-write.js.map +1 -0
- package/dist/core/schemas.d.ts +51 -0
- package/dist/core/schemas.js +59 -0
- package/dist/core/schemas.js.map +1 -0
- package/dist/core/serialization/formats.d.ts +7 -7
- package/dist/core/serialization/formats.js +34 -28
- package/dist/core/serialization/formats.js.map +1 -1
- package/dist/core/serialization/grouped.d.ts +9 -12
- package/dist/core/serialization/grouped.js +24 -17
- package/dist/core/serialization/grouped.js.map +1 -1
- package/dist/core/to-error.d.ts +5 -0
- package/dist/core/to-error.js +4 -0
- package/dist/core/to-error.js.map +1 -0
- package/dist/core/types.d.ts +296 -43
- package/dist/core/types.js +39 -108
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.d.ts +4 -4
- package/dist/core/url-generator.js +9 -7
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.d.ts +4 -4
- package/dist/core/url-parser.js +6 -4
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +21 -14
- package/dist/core/validation.js +58 -54
- package/dist/core/validation.js.map +1 -1
- package/dist/core/view-storage.js +21 -19
- package/dist/core/view-storage.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/sync-holder.d.ts +22 -0
- package/dist/react/sync-holder.js +68 -0
- package/dist/react/sync-holder.js.map +1 -0
- package/dist/react/sync-options.d.ts +17 -0
- package/dist/react/sync-options.js +22 -0
- package/dist/react/sync-options.js.map +1 -0
- package/dist/react/types.d.ts +101 -14
- package/dist/react/use-ag-grid-url-sync.d.ts +3 -0
- package/dist/react/use-ag-grid-url-sync.js +344 -499
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/dist/react/use-grid-url-sync.d.ts +14 -0
- package/dist/react/use-grid-url-sync.js +206 -0
- package/dist/react/use-grid-url-sync.js.map +1 -0
- package/package.json +35 -15
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { IDLE_SNAPSHOT } from '../core/grid-url-sync.js';
|
|
2
|
+
function sameViews(a, b) {
|
|
3
|
+
return a.length === b.length && JSON.stringify(a) === JSON.stringify(b);
|
|
4
|
+
}
|
|
5
|
+
export function createSyncHolder() {
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
let current = null;
|
|
8
|
+
let stopForwarding = null;
|
|
9
|
+
let idle = IDLE_SNAPSHOT;
|
|
10
|
+
let carried = [];
|
|
11
|
+
let merged = null;
|
|
12
|
+
const withCarried = (from) => {
|
|
13
|
+
if (merged?.from === from && merged.carried === carried) {
|
|
14
|
+
return merged.snapshot;
|
|
15
|
+
}
|
|
16
|
+
const issues = merged?.from.issues === from.issues && merged.carried === carried
|
|
17
|
+
? merged.snapshot.issues
|
|
18
|
+
: Object.freeze([...carried, ...from.issues]);
|
|
19
|
+
merged = { from, carried, snapshot: Object.freeze({ ...from, issues }) };
|
|
20
|
+
return merged.snapshot;
|
|
21
|
+
};
|
|
22
|
+
const notify = () => {
|
|
23
|
+
for (const listener of Array.from(listeners))
|
|
24
|
+
listener();
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
set(sync) {
|
|
28
|
+
if (sync === current)
|
|
29
|
+
return;
|
|
30
|
+
stopForwarding?.();
|
|
31
|
+
stopForwarding = null;
|
|
32
|
+
current = sync;
|
|
33
|
+
if (sync)
|
|
34
|
+
stopForwarding = sync.subscribe(notify);
|
|
35
|
+
notify();
|
|
36
|
+
},
|
|
37
|
+
get: () => current,
|
|
38
|
+
setIdleViews(views) {
|
|
39
|
+
if (sameViews(idle.views, views))
|
|
40
|
+
return;
|
|
41
|
+
idle = views.length
|
|
42
|
+
? Object.freeze({ ...IDLE_SNAPSHOT, views: Object.freeze([...views]) })
|
|
43
|
+
: IDLE_SNAPSHOT;
|
|
44
|
+
if (!current)
|
|
45
|
+
notify();
|
|
46
|
+
},
|
|
47
|
+
setCarriedIssues(issues) {
|
|
48
|
+
if (issues === carried)
|
|
49
|
+
return;
|
|
50
|
+
carried = issues;
|
|
51
|
+
if (current)
|
|
52
|
+
notify();
|
|
53
|
+
},
|
|
54
|
+
subscribe(listener) {
|
|
55
|
+
listeners.add(listener);
|
|
56
|
+
return () => {
|
|
57
|
+
listeners.delete(listener);
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
getSnapshot() {
|
|
61
|
+
if (!current)
|
|
62
|
+
return idle;
|
|
63
|
+
const snapshot = current.getSnapshot();
|
|
64
|
+
return carried.length ? withCarried(snapshot) : snapshot;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=sync-holder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-holder.js","sourceRoot":"","sources":["../../src/react/sync-holder.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GridApi } from 'ag-grid-community';
|
|
2
|
+
import type { AGGridUrlSyncConfig, GridUrlSyncOptions, HistoryMode, IssueEvent } from '../core/types.js';
|
|
3
|
+
import type { ViewStore } from '../core/view-storage.js';
|
|
4
|
+
/** The address-bar options of the hook's sync (#270) */
|
|
5
|
+
export interface AddressBarOptions {
|
|
6
|
+
history: HistoryMode;
|
|
7
|
+
popstate: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
/** The default: the sync never writes history and never follows popstate */
|
|
10
|
+
export declare const NO_ADDRESS_BAR: AddressBarOptions;
|
|
11
|
+
/**
|
|
12
|
+
* The createGridUrlSync options for the hook. The hook's sync never throws.
|
|
13
|
+
* It writes history and follows popstate only with the hook's options
|
|
14
|
+
* (#270). It applies the URL on create only when the hook asks for it
|
|
15
|
+
* (auto-apply with saved views, #223).
|
|
16
|
+
*/
|
|
17
|
+
export declare function gridUrlSyncOptions(api: GridApi, options: AGGridUrlSyncConfig, onIssue: (event: IssueEvent) => void, views?: ViewStore, applyUrlOnCreate?: boolean, addressBar?: AddressBarOptions): GridUrlSyncOptions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { codecFromOptions } from '../core/codecs.js';
|
|
2
|
+
import { resolveOptions } from '../core/options.js';
|
|
3
|
+
export const NO_ADDRESS_BAR = {
|
|
4
|
+
history: 'none',
|
|
5
|
+
popstate: false
|
|
6
|
+
};
|
|
7
|
+
export function gridUrlSyncOptions(api, options, onIssue, views, applyUrlOnCreate = false, addressBar = NO_ADDRESS_BAR) {
|
|
8
|
+
const resolved = resolveOptions(options);
|
|
9
|
+
const codec = codecFromOptions(resolved);
|
|
10
|
+
return {
|
|
11
|
+
api,
|
|
12
|
+
codec,
|
|
13
|
+
maxValueLength: resolved.maxValueLength,
|
|
14
|
+
history: addressBar.history,
|
|
15
|
+
popstate: addressBar.popstate,
|
|
16
|
+
applyUrlOnCreate,
|
|
17
|
+
throwOnError: false,
|
|
18
|
+
onIssue,
|
|
19
|
+
views
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=sync-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync-options.js","sourceRoot":"","sources":["../../src/react/sync-options.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAYnD,MAAM,CAAC,MAAM,cAAc,GAAsB;IAC/C,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE,KAAK;CAChB,CAAA;AAQD,MAAM,UAAU,kBAAkB,CAChC,GAAY,EACZ,OAA4B,EAC5B,OAAoC,EACpC,KAAiB,EACjB,gBAAgB,GAAG,KAAK,EACxB,UAAU,GAAsB,cAAc;IAE9C,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IAIxC,MAAM,KAAK,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAExC,OAAO;QACL,GAAG;QACH,KAAK;QACL,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,gBAAgB;QAChB,YAAY,EAAE,KAAK;QACnB,OAAO;QACP,KAAK;KACN,CAAA;AACH,CAAC"}
|
package/dist/react/types.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GridApi } from 'ag-grid-community';
|
|
2
|
+
import type { AGGridUrlSyncConfig, ApplyResult, FilterState, GridUrlSyncOptions, GridUrlSyncSnapshot, HistoryMode, SerializationFormat, SerializationMode, URLSyncError } from '../core/types.js';
|
|
2
3
|
import type { GridView } from '../core/view-storage.js';
|
|
3
4
|
/**
|
|
4
5
|
* Configuration options for the React hook
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use `useGridUrlSync` and its types. Removed in 0.6.0.
|
|
5
8
|
*/
|
|
6
9
|
export interface UseAGGridUrlSyncOptions extends AGGridUrlSyncConfig {
|
|
7
10
|
/**
|
|
@@ -13,7 +16,7 @@ export interface UseAGGridUrlSyncOptions extends AGGridUrlSyncConfig {
|
|
|
13
16
|
*
|
|
14
17
|
* @example 'employee-grid'
|
|
15
18
|
*/
|
|
16
|
-
storageKey?: string;
|
|
19
|
+
storageKey?: string | undefined;
|
|
17
20
|
/**
|
|
18
21
|
* Automatically apply URL filters when the component mounts and grid API becomes ready
|
|
19
22
|
*
|
|
@@ -21,13 +24,14 @@ export interface UseAGGridUrlSyncOptions extends AGGridUrlSyncConfig {
|
|
|
21
24
|
* take precedence: a shared link should show the sender's filters rather than
|
|
22
25
|
* the recipient's stored view.
|
|
23
26
|
*
|
|
24
|
-
* Attempted once per grid. A failed attempt is reported
|
|
25
|
-
* `onParseError
|
|
26
|
-
*
|
|
27
|
+
* Attempted once per grid. A failed attempt is reported one time (a bad
|
|
28
|
+
* filter through `onParseError`, any other failure through `onError`) and is
|
|
29
|
+
* not retried on later renders; pass a new `gridApi`, or call
|
|
30
|
+
* `applyUrlFilters`, to try again.
|
|
27
31
|
*
|
|
28
32
|
* Default: false
|
|
29
33
|
*/
|
|
30
|
-
autoApplyOnMount?: boolean;
|
|
34
|
+
autoApplyOnMount?: boolean | undefined;
|
|
31
35
|
/**
|
|
32
36
|
* Whether the hook should be enabled when the grid API is ready
|
|
33
37
|
*
|
|
@@ -38,15 +42,41 @@ export interface UseAGGridUrlSyncOptions extends AGGridUrlSyncConfig {
|
|
|
38
42
|
*
|
|
39
43
|
* Default: true
|
|
40
44
|
*/
|
|
41
|
-
enabledWhenReady?: boolean;
|
|
45
|
+
enabledWhenReady?: boolean | undefined;
|
|
42
46
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
47
|
+
* How a filter change goes to the address bar, as in `createGridUrlSync`
|
|
48
|
+
* (#270). A user edit, a view load, `applyFilters` and `clearFilters`
|
|
49
|
+
* write the URL. A URL apply (auto-apply, `applyUrlFilters`, the back
|
|
50
|
+
* button) writes nothing, because the URL holds those filters already.
|
|
51
|
+
* `'replace'` and `'push'` use `window.history`. A function gets the URL,
|
|
52
|
+
* for a router: a new function on a later render is used, and makes no
|
|
53
|
+
* new sync.
|
|
54
|
+
*
|
|
55
|
+
* Default: 'none'
|
|
56
|
+
*/
|
|
57
|
+
history?: HistoryMode | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Apply the URL when the browser's back or forward button changes it.
|
|
60
|
+
*
|
|
61
|
+
* Default: true when `history` is `'push'`, else false
|
|
62
|
+
*/
|
|
63
|
+
popstate?: boolean | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Optional handler for operation failures: an operation called before the
|
|
66
|
+
* grid is ready (`NOT_READY`), a grid API error (`GRID_ERROR`), a saved view
|
|
67
|
+
* that is not found or cannot be stored (`VIEW_*`, `STORAGE_*`). `context`
|
|
68
|
+
* names the operation, for example `'apply-url-filters'`.
|
|
69
|
+
*
|
|
70
|
+
* Each failure reaches one callback only (#220). A filter that is dropped or
|
|
71
|
+
* not valid goes to `onParseError`, not here. The hook never writes to the
|
|
72
|
+
* console, so a failure with no handler is silent.
|
|
45
73
|
*/
|
|
46
|
-
onError?: (error: Error, context: string) => void;
|
|
74
|
+
onError?: ((error: Error, context: string) => void) | undefined;
|
|
47
75
|
}
|
|
48
76
|
/**
|
|
49
77
|
* Return type for the useAGGridUrlSync hook
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use `useGridUrlSync` and its types. Removed in 0.6.0.
|
|
50
80
|
*/
|
|
51
81
|
export interface UseAGGridUrlSyncReturn {
|
|
52
82
|
/**
|
|
@@ -83,10 +113,22 @@ export interface UseAGGridUrlSyncReturn {
|
|
|
83
113
|
* Comes from the grid's filter state, not from the URL, because the URL also
|
|
84
114
|
* keeps the page's own params. A filter that the URL cannot carry (for
|
|
85
115
|
* example a text value over `maxValueLength`) still counts, so a "clear
|
|
86
|
-
* filters" button stays enabled. The URL leaves that filter out
|
|
87
|
-
* it
|
|
116
|
+
* filters" button stays enabled. The URL leaves that filter out, reports it
|
|
117
|
+
* through `onParseError`, and puts it in `issues`.
|
|
88
118
|
*/
|
|
89
119
|
hasFilters: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* The filters that were dropped (#229): the data issues of the latest URL
|
|
122
|
+
* apply (`applyUrlFilters`, `applyFilters`, auto-apply), and of the latest
|
|
123
|
+
* URL write (each filter change). Each one is a `URLSyncError` with a
|
|
124
|
+
* `code` and, when it is known, a `column`. The apply issues stay until the
|
|
125
|
+
* next apply, `clearFilters` or `loadView`.
|
|
126
|
+
*
|
|
127
|
+
* The array keeps its identity while its content does not change. Operation
|
|
128
|
+
* failures (`NOT_READY`, `GRID_ERROR`, storage) go to `onError` and are not
|
|
129
|
+
* here. With `throwOnError`, the hook throws a picked issue during render.
|
|
130
|
+
*/
|
|
131
|
+
issues: readonly URLSyncError[];
|
|
90
132
|
/**
|
|
91
133
|
* Parse filters from a URL without applying them
|
|
92
134
|
* @param url - URL to parse
|
|
@@ -105,8 +147,13 @@ export interface UseAGGridUrlSyncReturn {
|
|
|
105
147
|
*/
|
|
106
148
|
getFiltersAsFormat: (format: SerializationFormat) => string;
|
|
107
149
|
/**
|
|
108
|
-
*
|
|
109
|
-
|
|
150
|
+
* The serialization mode of the URL: `'individual'` or `'grouped'`
|
|
151
|
+
*/
|
|
152
|
+
getSerializationMode: () => SerializationMode;
|
|
153
|
+
/**
|
|
154
|
+
* The serialization mode of the URL. The name is wrong: it returns the
|
|
155
|
+
* mode, not the format.
|
|
156
|
+
* @deprecated Use `getSerializationMode`. Removed in 0.6.0.
|
|
110
157
|
*/
|
|
111
158
|
getCurrentFormat: () => SerializationMode;
|
|
112
159
|
/**
|
|
@@ -180,3 +227,43 @@ export interface UseAGGridUrlSyncReturn {
|
|
|
180
227
|
*/
|
|
181
228
|
deleteView: (id: string) => void;
|
|
182
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* The options of `useGridUrlSync`: the options of `createGridUrlSync`, with
|
|
232
|
+
* the grid's `api` that can be null while the grid starts, and the React
|
|
233
|
+
* options. An option can change after mount.
|
|
234
|
+
*/
|
|
235
|
+
export interface UseGridUrlSyncOptions extends Omit<GridUrlSyncOptions, 'api' | 'views'> {
|
|
236
|
+
/** The AG Grid API, or null while the grid starts */
|
|
237
|
+
api: GridApi | null | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Enables saved views, kept in localStorage under this key. Two grids on
|
|
240
|
+
* the same origin need two keys. With no key, `views` is empty and the
|
|
241
|
+
* view methods do nothing.
|
|
242
|
+
*/
|
|
243
|
+
storageKey?: string | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* With `false`, the hook makes no sync: the state is idle, and a method
|
|
246
|
+
* reports `NOT_READY`. `views` still shows what is in storage.
|
|
247
|
+
* @default true
|
|
248
|
+
*/
|
|
249
|
+
enabled?: boolean | undefined;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The result of `useGridUrlSync`: the sync's snapshot and its methods. The
|
|
253
|
+
* object stays the same until a snapshot value changes, and the methods
|
|
254
|
+
* never change.
|
|
255
|
+
*/
|
|
256
|
+
export interface UseGridUrlSyncResult extends GridUrlSyncSnapshot {
|
|
257
|
+
/** Applies the filters of a URL (default: the address bar) to the grid */
|
|
258
|
+
applyUrl: (url?: string) => ApplyResult;
|
|
259
|
+
/** Applies filters to the grid, as the app's own write */
|
|
260
|
+
applyFilters: (filters: FilterState) => ApplyResult;
|
|
261
|
+
/** The URL with the grid's filters (default base: the address bar) */
|
|
262
|
+
getUrl: (baseUrl?: string) => string;
|
|
263
|
+
/** Saves the grid's filters as a view, and makes it active */
|
|
264
|
+
saveView: (name: string) => GridView | null;
|
|
265
|
+
/** Loads a saved view. `null` clears the filters. */
|
|
266
|
+
loadView: (id: string | null) => void;
|
|
267
|
+
/** Deletes a saved view */
|
|
268
|
+
deleteView: (id: string) => void;
|
|
269
|
+
}
|
|
@@ -3,6 +3,9 @@ import type { UseAGGridUrlSyncOptions, UseAGGridUrlSyncReturn } from './types.js
|
|
|
3
3
|
/**
|
|
4
4
|
* React hook for AG Grid URL synchronization
|
|
5
5
|
*
|
|
6
|
+
* @deprecated Use `useGridUrlSync({ api, ...options })` (#271). This hook
|
|
7
|
+
* will be removed in 0.6.0.
|
|
8
|
+
*
|
|
6
9
|
* @param gridApi - AG Grid API instance (can be null during initialization)
|
|
7
10
|
* @param options - Configuration options for the hook
|
|
8
11
|
* @returns Hook API for URL synchronization
|