@jsb188/mday-web 1.1.10 → 1.1.12

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 (38) hide show
  1. package/package.json +36 -24
  2. package/src/libs/route-metadata.server.ts +67 -0
  3. package/src/modules/Grids.filters.ts +36 -0
  4. package/src/modules/Grids.tsx +610 -0
  5. package/src/modules/RouteShell.tsx +76 -0
  6. package/src/schemas/organization.ts +128 -0
  7. package/src/utils/email.ts +117 -0
  8. package/src/utils/list-web.ts +17 -0
  9. package/src/utils/log-web.helpers.ts +99 -0
  10. package/src/utils/log-web.icons.ts +184 -0
  11. package/src/utils/log-web.ts +74 -364
  12. package/src/utils/operation-pages.ts +154 -0
  13. package/src/utils/org-web.ts +35 -8
  14. package/src/utils/route-helpers.ts +837 -596
  15. package/src/utils/workflow-web.ts +72 -0
  16. package/tests/log-web.test.ts +134 -0
  17. package/tests/route-helpers.test.ts +17 -0
  18. package/tsconfig.json +11 -11
  19. package/src/modules/DataTable-ContextMenu.tsx +0 -169
  20. package/src/modules/DataTable-InboundContact.tsx +0 -523
  21. package/src/modules/DataTable.tsx +0 -5060
  22. package/src/modules/Sheet-ContextMenu.tsx +0 -161
  23. package/src/modules/Sheet.tsx +0 -28
  24. package/src/modules/cell-save-beacon.ts +0 -67
  25. package/src/modules/dataTable-interaction-state.ts +0 -276
  26. package/src/modules/dataTable-shortcuts.ts +0 -192
  27. package/src/modules/dataTable-viewport.ts +0 -89
  28. package/src/modules/grid-cell-render.ts +0 -72
  29. package/src/modules/grid-context-menu.ts +0 -112
  30. package/src/modules/grid-keyboard.ts +0 -267
  31. package/src/modules/grid-render-store.ts +0 -103
  32. package/src/modules/grid-runtime.ts +0 -178
  33. package/src/modules/grid-selection.ts +0 -336
  34. package/src/modules/grid-viewport.ts +0 -57
  35. package/src/modules/use-dataTable-states.ts +0 -529
  36. package/src/modules/use-debounced-cell-save-batch.ts +0 -160
  37. package/tests/DataTable.test.tsx +0 -4466
  38. package/tests/dataTable-interaction-state.test.ts +0 -127
@@ -1,529 +0,0 @@
1
- import type { DataTableCellGQL, DataTableDesignGQL, DataTableRowGQL } from '@jsb188/mday/types/dataTable.d.ts';
2
- import type { SetFloatingMessage } from '@jsb188/react-web/modules/Layout';
3
- import { clampSheetColumnWidth, getSheetCellKey } from '@jsb188/react-web/ui/SheetUI';
4
- import { useEffect, useRef, useState } from 'react';
5
-
6
- export type DataTableRowsState = {
7
- hasMoreRows: boolean;
8
- rowIds: string[];
9
- rowsById: Record<string, DataTableRowGQL>;
10
- rowSignaturesById: Record<string, string>;
11
- sourceKey: string;
12
- };
13
-
14
- export type DataTableDesignPatchInput = {
15
- cells?: Array<{
16
- format?: string | null;
17
- humanLabel?: string | null;
18
- key: string;
19
- width?: number | null;
20
- }>;
21
- cellsOrder?: string[];
22
- views?: Array<{
23
- id: string;
24
- columnsOrder?: string[] | null;
25
- }>;
26
- };
27
-
28
- type DataTableDesignCellPatchInput = NonNullable<DataTableDesignPatchInput['cells']>[number];
29
-
30
- type DataTableDesignReducerState = {
31
- localPatch: DataTableDesignPatchInput | null;
32
- serverDesign: DataTableDesignGQL;
33
- dataTableId: string;
34
- };
35
-
36
- type DataTableDesignReducerAction =
37
- | {
38
- design: DataTableDesignGQL;
39
- dataTableId: string;
40
- type: 'server_design_received';
41
- }
42
- | {
43
- patch: DataTableDesignPatchInput;
44
- type: 'local_patch_queued';
45
- };
46
-
47
- type DataTableOptimisticCellValues = Record<string, string | null>;
48
-
49
- type DataTableCellValueReducerAction =
50
- | {
51
- type: 'reset';
52
- }
53
- | {
54
- confirmedKeys: string[];
55
- type: 'server_values_received';
56
- }
57
- | {
58
- cellKey: string;
59
- rowId: string;
60
- type: 'local_value_reverted';
61
- }
62
- | {
63
- cellKey: string;
64
- rowId: string;
65
- type: 'local_value_queued';
66
- value: string | null;
67
- };
68
-
69
- /*
70
- * Build an empty row collection state for one dataTable.
71
- */
72
-
73
- export function getInitialDataTableRowsState(sourceKey: string): DataTableRowsState {
74
- return {
75
- hasMoreRows: true,
76
- rowIds: [],
77
- rowsById: {},
78
- rowSignaturesById: {},
79
- sourceKey,
80
- };
81
- }
82
-
83
- /*
84
- * Return the identity for the current dataTable row source.
85
- */
86
-
87
- export function getDataTableRowsSourceKey(dataTableId: string, viewId?: string | null) {
88
- return `${dataTableId}:${viewId || 'master'}`;
89
- }
90
-
91
- /*
92
- * Show a refresh floating message when dataTable row queries receive reset-only updates.
93
- */
94
-
95
- export function useFloatingMessageForDataTableRowsReset(
96
- resetOnlyTime: string | undefined,
97
- setFloatingMessage?: SetFloatingMessage,
98
- ) {
99
- const lastUpdateTime = useRef<string | undefined>(resetOnlyTime);
100
-
101
- useEffect(() => {
102
- if (!resetOnlyTime) {
103
- return;
104
- }
105
-
106
- if (resetOnlyTime !== lastUpdateTime.current && setFloatingMessage) {
107
- setFloatingMessage({
108
- type: 'REFRESH',
109
- });
110
- }
111
-
112
- lastUpdateTime.current = resetOnlyTime;
113
- }, [resetOnlyTime, setFloatingMessage]);
114
- }
115
-
116
- /*
117
- * Return a stable comparison key for one dataTable cell payload.
118
- */
119
-
120
- function getDataTableCellStateKey(cell: DataTableCellGQL) {
121
- return [
122
- cell.id,
123
- cell.cellKey,
124
- cell.iconName ?? '',
125
- cell.value ?? '',
126
- cell.textValue ?? '',
127
- cell.numberValue ?? '',
128
- cell.booleanValue === undefined || cell.booleanValue === null ? '' : String(cell.booleanValue),
129
- cell.dateValue ?? '',
130
- cell.datetimeValue ?? '',
131
- cell.updatedAt ?? '',
132
- ].join('\u0000');
133
- }
134
-
135
- /*
136
- * Return a stable comparison key for one dataTable row payload.
137
- */
138
-
139
- function getDataTableRowStateKey(row: DataTableRowGQL) {
140
- return [
141
- row.id,
142
- row.position,
143
- row.cursor ?? '',
144
- row.updatedAt ?? '',
145
- ...(row.cells || []).map(getDataTableCellStateKey).sort(),
146
- ].join('\u0000');
147
- }
148
-
149
- /*
150
- * Return whether two ordered row id collections have the same contents.
151
- */
152
-
153
- function areDataTableRowIdsEqual(a: string[], b: string[]) {
154
- return a.length === b.length && a.every((rowId, index) => rowId === b[index]);
155
- }
156
-
157
- /*
158
- * Merge fetched row ids while preserving the server's visual query order.
159
- */
160
-
161
- function mergeDataTableRowIds(
162
- currentRowIds: string[],
163
- rows: DataTableRowGQL[],
164
- appendRows: boolean,
165
- ) {
166
- const nextRowIds = Array.from(new Set(rows.map((row) => row.id)));
167
-
168
- if (appendRows) {
169
- const existingIds = new Set(currentRowIds);
170
-
171
- return currentRowIds.concat(nextRowIds.filter((rowId) => !existingIds.has(rowId)));
172
- }
173
-
174
- return nextRowIds;
175
- }
176
-
177
- /*
178
- * Merge one fetched page of rows into the loaded row collection.
179
- */
180
-
181
- export function mergeDataTableRowsState(
182
- currentState: DataTableRowsState,
183
- sourceKey: string,
184
- rows: DataTableRowGQL[],
185
- limit: number,
186
- appendRows = false,
187
- ): DataTableRowsState {
188
- const baseState = currentState.sourceKey === sourceKey ? currentState : getInitialDataTableRowsState(sourceKey);
189
- let rowsById = baseState.rowsById;
190
- let rowSignaturesById = baseState.rowSignaturesById;
191
- let changedRows = baseState !== currentState;
192
-
193
- rows.forEach((row) => {
194
- const rowSignature = getDataTableRowStateKey(row);
195
-
196
- if (rowSignaturesById[row.id] === rowSignature) {
197
- return;
198
- }
199
-
200
- if (rowsById === baseState.rowsById) {
201
- rowsById = { ...baseState.rowsById };
202
- rowSignaturesById = { ...baseState.rowSignaturesById };
203
- }
204
-
205
- rowsById[row.id] = row;
206
- rowSignaturesById[row.id] = rowSignature;
207
- changedRows = true;
208
- });
209
-
210
- const hasMoreRows = rows.length < limit ? false : baseState.hasMoreRows;
211
- const rowIds = mergeDataTableRowIds(baseState.rowIds, rows, appendRows);
212
- const changedRowIds = !areDataTableRowIdsEqual(baseState.rowIds, rowIds);
213
-
214
- if (
215
- currentState.sourceKey === sourceKey &&
216
- currentState.hasMoreRows === hasMoreRows &&
217
- !changedRows &&
218
- !changedRowIds
219
- ) {
220
- return currentState;
221
- }
222
-
223
- return {
224
- hasMoreRows,
225
- rowIds,
226
- rowsById,
227
- rowSignaturesById,
228
- sourceKey,
229
- };
230
- }
231
-
232
- /*
233
- * Return whether two optional ordered dataTable design key lists are identical.
234
- */
235
-
236
- function areDataTableDesignCellsOrdersEqual(a?: string[] | null, b?: string[] | null) {
237
- const aOrder = a || [];
238
- const bOrder = b || [];
239
-
240
- return aOrder.length === bOrder.length && aOrder.every((key, index) => key === bOrder[index]);
241
- }
242
-
243
- /*
244
- * Return whether two optional ordered dataTable view key lists are identical.
245
- */
246
-
247
- function areDataTableDesignViewOrdersEqual(a?: string[] | null, b?: string[] | null) {
248
- return areDataTableDesignCellsOrdersEqual(a, b);
249
- }
250
-
251
- /*
252
- * Merge two sparse dataTable design patches while keeping the newest cell patch per key.
253
- */
254
-
255
- export function mergeDataTableDesignPatch(
256
- currentPatch: DataTableDesignPatchInput | null,
257
- nextPatch: DataTableDesignPatchInput,
258
- ): DataTableDesignPatchInput {
259
- const mergedPatch: DataTableDesignPatchInput = {
260
- ...(currentPatch || {}),
261
- };
262
-
263
- if (nextPatch.cells) {
264
- const cellsByKey = new Map((mergedPatch.cells || []).map((cell) => [cell.key, cell]));
265
-
266
- nextPatch.cells.forEach((cell) => {
267
- cellsByKey.set(cell.key, {
268
- ...cellsByKey.get(cell.key),
269
- ...cell,
270
- });
271
- });
272
-
273
- mergedPatch.cells = Array.from(cellsByKey.values());
274
- }
275
-
276
- if (nextPatch.cellsOrder) {
277
- mergedPatch.cellsOrder = nextPatch.cellsOrder.slice(0);
278
- }
279
-
280
- if (nextPatch.views) {
281
- const viewsById = new Map((mergedPatch.views || []).map((view) => [view.id, view]));
282
-
283
- nextPatch.views.forEach((view) => {
284
- viewsById.set(view.id, {
285
- ...viewsById.get(view.id),
286
- ...view,
287
- columnsOrder: view.columnsOrder ? view.columnsOrder.slice(0) : view.columnsOrder,
288
- });
289
- });
290
-
291
- mergedPatch.views = Array.from(viewsById.values());
292
- }
293
-
294
- return mergedPatch;
295
- }
296
-
297
- /*
298
- * Merge local dataTable design edits over the latest GraphQL design baseline.
299
- */
300
-
301
- export function mergeDataTableDesignWithPatch(
302
- serverDesign: DataTableDesignGQL,
303
- localPatch: DataTableDesignPatchInput | null,
304
- ): DataTableDesignGQL {
305
- if (!localPatch) {
306
- return serverDesign;
307
- }
308
-
309
- let cells = serverDesign.cells;
310
- let views = serverDesign.views;
311
-
312
- if (localPatch.cells?.length) {
313
- const patchCellsByKey = new Map(localPatch.cells.map((cell) => [cell.key, cell]));
314
- const patchedKeys = new Set<string>();
315
-
316
- cells = serverDesign.cells.map((cell) => {
317
- const patchCell = patchCellsByKey.get(cell.key);
318
-
319
- if (!patchCell || patchedKeys.has(cell.key)) {
320
- return cell;
321
- }
322
-
323
- patchedKeys.add(cell.key);
324
-
325
- return {
326
- ...cell,
327
- ...patchCell,
328
- };
329
- });
330
- }
331
-
332
- if (localPatch.views?.length && views?.length) {
333
- const patchViewsById = new Map(localPatch.views.map((view) => [view.id, view]));
334
-
335
- views = views.map((view) => {
336
- const patchView = patchViewsById.get(view.id);
337
-
338
- if (!patchView) {
339
- return view;
340
- }
341
-
342
- return {
343
- ...view,
344
- columnsOrder: patchView.columnsOrder || view.columnsOrder,
345
- };
346
- });
347
- }
348
-
349
- return {
350
- ...serverDesign,
351
- cells,
352
- cellsOrder: localPatch.cellsOrder || serverDesign.cellsOrder,
353
- views,
354
- };
355
- }
356
-
357
- /*
358
- * Drop local dataTable design edits once the refreshed server design contains them.
359
- */
360
-
361
- function removeConfirmedDataTableDesignPatchValues(
362
- localPatch: DataTableDesignPatchInput | null,
363
- serverDesign: DataTableDesignGQL,
364
- ) {
365
- if (!localPatch) {
366
- return null;
367
- }
368
-
369
- let nextPatch: DataTableDesignPatchInput | null = null;
370
- const serverCellsByKey = new Map<string, DataTableDesignGQL['cells'][number]>();
371
-
372
- serverDesign.cells.forEach((cell) => {
373
- if (!serverCellsByKey.has(cell.key)) {
374
- serverCellsByKey.set(cell.key, cell);
375
- }
376
- });
377
-
378
- localPatch.cells?.forEach((patchCell) => {
379
- const serverCell = serverCellsByKey.get(patchCell.key);
380
- const nextCell: DataTableDesignCellPatchInput = {
381
- key: patchCell.key,
382
- };
383
-
384
- if (patchCell.width !== undefined) {
385
- const serverWidth = serverCell?.width === undefined || serverCell.width === null
386
- ? null
387
- : clampSheetColumnWidth(Number(serverCell.width));
388
- const patchWidth = patchCell.width === null ? null : clampSheetColumnWidth(Number(patchCell.width));
389
-
390
- if (serverWidth !== patchWidth) {
391
- nextCell.width = patchCell.width;
392
- }
393
- }
394
-
395
- if (patchCell.humanLabel !== undefined && (serverCell?.humanLabel || null) !== patchCell.humanLabel) {
396
- nextCell.humanLabel = patchCell.humanLabel;
397
- }
398
-
399
- if (patchCell.format !== undefined && (serverCell?.format || null) !== patchCell.format) {
400
- nextCell.format = patchCell.format;
401
- }
402
-
403
- if (nextCell.width !== undefined || nextCell.humanLabel !== undefined || nextCell.format !== undefined) {
404
- nextPatch = mergeDataTableDesignPatch(nextPatch, {
405
- cells: [nextCell],
406
- });
407
- }
408
- });
409
-
410
- if (localPatch.cellsOrder && !areDataTableDesignCellsOrdersEqual(localPatch.cellsOrder, serverDesign.cellsOrder)) {
411
- nextPatch = mergeDataTableDesignPatch(nextPatch, {
412
- cellsOrder: localPatch.cellsOrder,
413
- });
414
- }
415
-
416
- localPatch.views?.forEach((patchView) => {
417
- const serverView = serverDesign.views?.find((view) => view.id === patchView.id);
418
-
419
- if (patchView.columnsOrder && !areDataTableDesignViewOrdersEqual(patchView.columnsOrder, serverView?.columnsOrder)) {
420
- nextPatch = mergeDataTableDesignPatch(nextPatch, {
421
- views: [{
422
- id: patchView.id,
423
- columnsOrder: patchView.columnsOrder,
424
- }],
425
- });
426
- }
427
- });
428
-
429
- return nextPatch;
430
- }
431
-
432
- /*
433
- * Keep the dataTable design reducer initialized for one dataTable id.
434
- */
435
-
436
- export function getInitialDataTableDesignReducerState(dataTableId: string, serverDesign: DataTableDesignGQL): DataTableDesignReducerState {
437
- return {
438
- localPatch: null,
439
- serverDesign,
440
- dataTableId,
441
- };
442
- }
443
-
444
- /*
445
- * Own the local dataTable design overlay that should survive GraphQL refreshes.
446
- */
447
-
448
- export function dataTableDesignReducer(
449
- state: DataTableDesignReducerState,
450
- action: DataTableDesignReducerAction,
451
- ): DataTableDesignReducerState {
452
- if (action.type === 'server_design_received') {
453
- if (state.dataTableId !== action.dataTableId) {
454
- return getInitialDataTableDesignReducerState(action.dataTableId, action.design);
455
- }
456
-
457
- return {
458
- ...state,
459
- localPatch: removeConfirmedDataTableDesignPatchValues(state.localPatch, action.design),
460
- serverDesign: action.design,
461
- };
462
- }
463
-
464
- return {
465
- ...state,
466
- localPatch: mergeDataTableDesignPatch(state.localPatch, action.patch),
467
- };
468
- }
469
-
470
- /*
471
- * Keep local dataTable cell edits visible until refreshed server data confirms them.
472
- */
473
-
474
- export function dataTableCellValueReducer(
475
- state: DataTableOptimisticCellValues,
476
- action: DataTableCellValueReducerAction,
477
- ): DataTableOptimisticCellValues {
478
- if (action.type === 'reset') {
479
- return {};
480
- }
481
-
482
- if (action.type === 'server_values_received') {
483
- if (!action.confirmedKeys.length) {
484
- return state;
485
- }
486
-
487
- let nextState = state;
488
-
489
- action.confirmedKeys.forEach((key) => {
490
- if (!Object.prototype.hasOwnProperty.call(nextState, key)) {
491
- return;
492
- }
493
-
494
- if (nextState === state) {
495
- nextState = {
496
- ...state,
497
- };
498
- }
499
-
500
- delete nextState[key];
501
- });
502
-
503
- return nextState;
504
- }
505
-
506
- if (action.type === 'local_value_reverted') {
507
- const optimisticKey = getSheetCellKey(action.rowId, action.cellKey);
508
- if (!Object.prototype.hasOwnProperty.call(state, optimisticKey)) {
509
- return state;
510
- }
511
-
512
- const nextState = {
513
- ...state,
514
- };
515
- delete nextState[optimisticKey];
516
-
517
- return nextState;
518
- }
519
-
520
- const optimisticKey = getSheetCellKey(action.rowId, action.cellKey);
521
- if (state[optimisticKey] === action.value) {
522
- return state;
523
- }
524
-
525
- return {
526
- ...state,
527
- [optimisticKey]: action.value,
528
- };
529
- }
@@ -1,160 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
-
3
- export const CELL_SAVE_BATCH_DELAY_MS = 2500;
4
-
5
- type CellSaveTargetId = string | number | bigint | null | undefined;
6
-
7
- export type GroupedCellSaveItems<T> = {
8
- items: T[];
9
- organizationId: CellSaveTargetId;
10
- targetId: CellSaveTargetId;
11
- };
12
-
13
- /*
14
- * Return a stable grouping key for cell saves that target the same backend resource.
15
- */
16
-
17
- function getCellSaveTargetGroupKey(organizationId: CellSaveTargetId, targetId: CellSaveTargetId) {
18
- return `${organizationId ?? ''}:${targetId ?? ''}`;
19
- }
20
-
21
- /*
22
- * Group pending cell saves by organization and resource id.
23
- */
24
-
25
- export function groupCellSaveItemsByTarget<T>(
26
- items: T[],
27
- getTarget: (item: T) => Pick<GroupedCellSaveItems<T>, 'organizationId' | 'targetId'>,
28
- ) {
29
- const groupedItemsByKey = new Map<string, GroupedCellSaveItems<T>>();
30
-
31
- for (const item of items) {
32
- const target = getTarget(item);
33
- const groupKey = getCellSaveTargetGroupKey(target.organizationId, target.targetId);
34
- const group = groupedItemsByKey.get(groupKey);
35
-
36
- if (group) {
37
- group.items.push(item);
38
- continue;
39
- }
40
-
41
- groupedItemsByKey.set(groupKey, {
42
- items: [item],
43
- organizationId: target.organizationId,
44
- targetId: target.targetId,
45
- });
46
- }
47
-
48
- return Array.from(groupedItemsByKey.values());
49
- }
50
-
51
- /*
52
- * Return whether every grouped cell save batch was accepted by its sender.
53
- */
54
-
55
- export function sendGroupedCellSaveItems<T>(
56
- groups: GroupedCellSaveItems<T>[],
57
- sendGroup: (group: GroupedCellSaveItems<T>) => boolean,
58
- ) {
59
- return groups.every(sendGroup);
60
- }
61
-
62
- /*
63
- * Queue keyed cell edits and flush the latest value for each key after a delay.
64
- */
65
-
66
- export function useDebouncedCellSaveBatch<T>(params: {
67
- delayMs?: number;
68
- getKey: (item: T) => string;
69
- onBeaconFlush?: (items: T[]) => boolean;
70
- onError?: (items: T[], error: unknown) => void;
71
- onFlush: (items: T[]) => Promise<void> | void;
72
- }) {
73
- const paramsRef = useRef(params);
74
- const pendingItemsRef = useRef(new Map<string, T>());
75
- const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
76
-
77
- paramsRef.current = params;
78
-
79
- const clearTimer = useCallback(() => {
80
- if (timerRef.current) {
81
- clearTimeout(timerRef.current);
82
- timerRef.current = null;
83
- }
84
- }, []);
85
-
86
- const flush = useCallback(() => {
87
- clearTimer();
88
-
89
- const items = Array.from(pendingItemsRef.current.values());
90
- pendingItemsRef.current.clear();
91
-
92
- if (!items.length) {
93
- return;
94
- }
95
-
96
- void (async () => {
97
- try {
98
- await paramsRef.current.onFlush(items);
99
- } catch (error) {
100
- paramsRef.current.onError?.(items, error);
101
- }
102
- })();
103
- }, [clearTimer]);
104
-
105
- const flushWithBeacon = useCallback(() => {
106
- clearTimer();
107
-
108
- const items = Array.from(pendingItemsRef.current.values());
109
- if (!items.length) {
110
- return;
111
- }
112
-
113
- if (paramsRef.current.onBeaconFlush?.(items)) {
114
- pendingItemsRef.current.clear();
115
- return;
116
- }
117
-
118
- flush();
119
- }, [clearTimer, flush]);
120
-
121
- const queue = useCallback((item: T) => {
122
- pendingItemsRef.current.set(paramsRef.current.getKey(item), item);
123
- clearTimer();
124
- timerRef.current = setTimeout(flush, paramsRef.current.delayMs ?? CELL_SAVE_BATCH_DELAY_MS);
125
- }, [clearTimer, flush]);
126
-
127
- useEffect(() => {
128
- return () => {
129
- flush();
130
- };
131
- }, [flush]);
132
-
133
- useEffect(() => {
134
- if (typeof globalThis.addEventListener !== 'function' || typeof document === 'undefined') {
135
- return;
136
- }
137
-
138
- const flushBeforePageLeaves = () => {
139
- flushWithBeacon();
140
- };
141
- const flushWhenPageHidden = () => {
142
- if (document.visibilityState === 'hidden') {
143
- flushWithBeacon();
144
- }
145
- };
146
-
147
- globalThis.addEventListener('pagehide', flushBeforePageLeaves);
148
- document.addEventListener('visibilitychange', flushWhenPageHidden);
149
-
150
- return () => {
151
- globalThis.removeEventListener('pagehide', flushBeforePageLeaves);
152
- document.removeEventListener('visibilitychange', flushWhenPageHidden);
153
- };
154
- }, [flushWithBeacon]);
155
-
156
- return {
157
- flush,
158
- queue,
159
- };
160
- }